Basically wrote the whole thing.
This commit is contained in:
32
README.md
32
README.md
@@ -6,31 +6,51 @@ A web application for sorting and organizing images using swipe gestures, simila
|
||||
|
||||
- **Swipe Interface**: Swipe images in four directions (left, right, up, down) to categorize them
|
||||
- **Full-size Image View**: Click on any image to view it in full resolution with metadata
|
||||
- **History Page**: View all your past selections with filtering options
|
||||
- **History Page**: View all your past selections with rich filtering and sort options
|
||||
- **NSFW Filtering**: Toggle to include/exclude NSFW images on both the main swiper and history pages
|
||||
- **NSFW Blur**: Optional blur for NSFW thumbnails on the history page with a toolbar toggle
|
||||
- **Orientation & Action Filters**: Filter results by orientation (portrait/landscape/square) and by action taken
|
||||
- **Database Storage**: All selections are saved in a SQLite database
|
||||
- **Reset Functionality**: Option to clear all selections and start fresh
|
||||
|
||||
## File Structure
|
||||
|
||||
- `app.py`: Python server that handles API requests and serves files
|
||||
- `server.py`: Entry point that starts the HTTP server
|
||||
- `handler.py`: HTTP request handler implementing all API endpoints
|
||||
- `database.py`: SQLite helpers (initialisation, queries, sync)
|
||||
- `config.py`: Centralised constants (paths, port)
|
||||
- `index.html`: Main page with the swipe interface
|
||||
- `history.html`: Page to view and manage past selections
|
||||
- `script.js`: JavaScript for the swipe functionality and UI interactions
|
||||
- `js/`: Front-end JavaScript (`main.js`, `utils.js`, etc.)
|
||||
- `styles.css`: CSS styling for the application
|
||||
- `update_nsfw_flags.py`: Utility script to (re)calculate NSFW flags for existing images after changing keyword lists
|
||||
|
||||
## How to Use
|
||||
|
||||
1. Run the server: `python app.py`
|
||||
1. Run the server: `python server.py`
|
||||
2. Open a web browser and navigate to `http://localhost:8000`
|
||||
3. Swipe images or use the buttons to categorize them:
|
||||
3. Use the on-screen buttons or swipe gestures to categorize images:
|
||||
- Left: Discard
|
||||
- Right: Keep
|
||||
- Up: Favorite
|
||||
- Down: Review Later
|
||||
4. Click on an image to view it in full resolution
|
||||
5. Use the "View History" link to see all your selections
|
||||
5. Use the "View History" link to see all your selections. The toolbar lets you:
|
||||
- Filter by action/orientation/NSFW status
|
||||
- Toggle blur of NSFW thumbnails
|
||||
- Sort by creation date, swipe date or resolution
|
||||
6. Use the "Reset Database" button in the history page to clear all selections
|
||||
|
||||
## NSFW Detection & Maintenance
|
||||
|
||||
NSFW status is inferred from prompt keywords defined in `config.py` (`NSFW_KEYWORDS`).
|
||||
|
||||
After changing the keyword list or adding new images you can refresh the database flags:
|
||||
```bash
|
||||
python update_nsfw_flags.py
|
||||
```
|
||||
This will reset and recalculate all `nsfw` flags so that the new filters work correctly.
|
||||
|
||||
## Requirements
|
||||
|
||||
- Python 3.x
|
||||
|
||||
756
app.py
756
app.py
@@ -1,756 +0,0 @@
|
||||
from http.server import HTTPServer, BaseHTTPRequestHandler
|
||||
import os
|
||||
import json
|
||||
import random
|
||||
import mimetypes
|
||||
import urllib.parse
|
||||
import sqlite3
|
||||
import time
|
||||
import datetime
|
||||
import zipfile
|
||||
import io
|
||||
from PIL import Image
|
||||
|
||||
# Path to the image directory
|
||||
IMAGE_DIR = "/mnt/secret-items/sd-outputs/Sorted/Images"
|
||||
|
||||
# Database file path
|
||||
DB_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "image_selections.db")
|
||||
|
||||
# NOTE: We no longer delete the database on each run.
|
||||
# If schema changes are needed, run a one-time migration script instead.
|
||||
|
||||
# Initialize the database
|
||||
def init_db():
|
||||
conn = sqlite3.connect(DB_PATH)
|
||||
cursor = conn.cursor()
|
||||
|
||||
# Create image_selections table
|
||||
cursor.execute('''
|
||||
CREATE TABLE IF NOT EXISTS image_selections (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
image_path TEXT NOT NULL UNIQUE,
|
||||
action TEXT NOT NULL,
|
||||
timestamp INTEGER NOT NULL
|
||||
)
|
||||
''')
|
||||
|
||||
# (Re)create image_metadata table with new schema
|
||||
cursor.execute('''
|
||||
CREATE TABLE IF NOT EXISTS image_metadata (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
path TEXT NOT NULL UNIQUE,
|
||||
resolution_x INTEGER NOT NULL,
|
||||
resolution_y INTEGER NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
orientation TEXT NOT NULL,
|
||||
creation_date INTEGER NOT NULL,
|
||||
prompt_data TEXT
|
||||
)
|
||||
''')
|
||||
|
||||
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
print(f"Database initialized at {DB_PATH}")
|
||||
|
||||
# Add a selection to the database
|
||||
def add_selection(image_path, action):
|
||||
conn = sqlite3.connect(DB_PATH)
|
||||
cursor = conn.cursor()
|
||||
|
||||
# Use REPLACE INTO to handle potential duplicates gracefully
|
||||
cursor.execute('''
|
||||
REPLACE INTO image_selections (image_path, action, timestamp)
|
||||
VALUES (?, ?, ?)
|
||||
''', (image_path, action, int(time.time())))
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
# Get all selections from the database
|
||||
def get_selections():
|
||||
print("DEBUG: get_selections() called")
|
||||
try:
|
||||
conn = sqlite3.connect(DB_PATH)
|
||||
conn.row_factory = sqlite3.Row # This enables column access by name
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute('''
|
||||
SELECT sel.id, sel.image_path, sel.action, sel.timestamp,
|
||||
meta.resolution_x, meta.resolution_y, meta.orientation,
|
||||
meta.creation_date, meta.prompt_data, meta.name
|
||||
FROM image_selections sel
|
||||
LEFT JOIN image_metadata meta ON sel.image_path = meta.path
|
||||
ORDER BY sel.timestamp DESC
|
||||
''')
|
||||
|
||||
rows = cursor.fetchall()
|
||||
print(f"DEBUG: Fetched {len(rows)} rows from database")
|
||||
|
||||
# Properly convert SQLite Row objects to dictionaries
|
||||
results = []
|
||||
for row in rows:
|
||||
item = {}
|
||||
for key in row.keys():
|
||||
item[key] = row[key]
|
||||
|
||||
# Ensure resolution exists
|
||||
if 'resolution' not in item or not item['resolution']:
|
||||
# derive resolution from path e.g. 2048x2048
|
||||
try:
|
||||
path_part = item['image_path']
|
||||
if path_part.startswith('/images/'):
|
||||
path_part = path_part[8:]
|
||||
res = path_part.split('/')[0]
|
||||
item['resolution'] = res
|
||||
except Exception:
|
||||
item['resolution'] = "unknown"
|
||||
|
||||
# Ensure orientation exists
|
||||
if 'orientation' not in item or not item['orientation']:
|
||||
try:
|
||||
# Try to determine orientation if not in database
|
||||
image_path = item['image_path']
|
||||
if image_path.startswith('/images/'):
|
||||
image_path = image_path[8:]
|
||||
full_path = os.path.join(IMAGE_DIR, image_path)
|
||||
with Image.open(full_path) as img:
|
||||
width, height = img.size
|
||||
item['orientation'] = "portrait" if height > width else "landscape" if width > height else "square"
|
||||
except Exception as e:
|
||||
print(f"DEBUG ERROR determining missing orientation: {str(e)}")
|
||||
item['orientation'] = "unknown"
|
||||
|
||||
results.append(item)
|
||||
|
||||
print(f"DEBUG: Converted {len(results)} rows to dictionaries")
|
||||
print(f"DEBUG: First result (if any): {results[0] if results else 'None'}")
|
||||
|
||||
conn.close()
|
||||
return results
|
||||
except Exception as e:
|
||||
print(f"DEBUG ERROR in get_selections(): {str(e)}")
|
||||
# Return empty list on error to prevent client from hanging
|
||||
return []
|
||||
|
||||
# Get a list of all image paths that have already been actioned
|
||||
def sync_image_database():
|
||||
"""Scans the image directory and adds any new images to the metadata table."""
|
||||
print("Syncing image database...")
|
||||
from PIL import Image
|
||||
conn = sqlite3.connect(DB_PATH)
|
||||
cursor = conn.cursor()
|
||||
|
||||
# Get all image paths already in the database
|
||||
cursor.execute("SELECT path FROM image_metadata")
|
||||
db_images = {row[0] for row in cursor.fetchall()}
|
||||
print(f"Found {len(db_images)} images in the database.")
|
||||
|
||||
# Find all images on the filesystem
|
||||
disk_images = set()
|
||||
resolutions = [d for d in os.listdir(IMAGE_DIR) if os.path.isdir(os.path.join(IMAGE_DIR, d))]
|
||||
for res in resolutions:
|
||||
res_dir = os.path.join(IMAGE_DIR, res)
|
||||
for img_name in os.listdir(res_dir):
|
||||
if img_name.lower().endswith(('.png', '.jpg', '.jpeg')):
|
||||
disk_images.add(f"{res}/{img_name}")
|
||||
print(f"Found {len(disk_images)} images on disk.")
|
||||
|
||||
# Determine which images are new
|
||||
new_images = disk_images - db_images
|
||||
print(f"Found {len(new_images)} new images to add to the database.")
|
||||
|
||||
if not new_images:
|
||||
print("Database is already up-to-date.")
|
||||
conn.close()
|
||||
return
|
||||
|
||||
# Process and add new images to the database
|
||||
images_to_add = []
|
||||
total_new_images = len(new_images)
|
||||
processed_count = 0
|
||||
for image_path in new_images:
|
||||
res, img_name = image_path.split('/', 1)
|
||||
full_path = os.path.join(IMAGE_DIR, image_path)
|
||||
try:
|
||||
with Image.open(full_path) as img:
|
||||
width, height = img.size
|
||||
orientation = 'square' if width == height else ('landscape' if width > height else 'portrait')
|
||||
# Attempt to read prompt info from PNG metadata (PNG only)
|
||||
prompt_text = None
|
||||
if img.format == 'PNG':
|
||||
prompt_text = img.info.get('parameters') or img.info.get('Parameters')
|
||||
creation_ts = int(os.path.getmtime(full_path))
|
||||
images_to_add.append((image_path, width, height, img_name, orientation, creation_ts, prompt_text))
|
||||
processed_count += 1
|
||||
if processed_count % 100 == 0 or processed_count == total_new_images:
|
||||
percentage = (processed_count / total_new_images) * 100
|
||||
print(f"Processed {processed_count} of {total_new_images} images ({percentage:.2f}%)...", flush=True)
|
||||
except Exception as e:
|
||||
print(f"Could not process image {full_path}: {e}")
|
||||
|
||||
if images_to_add:
|
||||
cursor.executemany('''
|
||||
INSERT INTO image_metadata (path, resolution_x, resolution_y, name, orientation, creation_date, prompt_data)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||
''', images_to_add)
|
||||
conn.commit()
|
||||
print(f"Successfully added {len(images_to_add)} new images to the database.")
|
||||
|
||||
conn.close()
|
||||
|
||||
# Update a selection in the database
|
||||
def update_selection(selection_id, action):
|
||||
conn = sqlite3.connect(DB_PATH)
|
||||
cursor = conn.cursor()
|
||||
|
||||
# Update the selection
|
||||
cursor.execute('''
|
||||
UPDATE image_selections SET action = ?, timestamp = ? WHERE id = ?
|
||||
''', (action, int(time.time()), selection_id))
|
||||
|
||||
# Check if a row was affected
|
||||
rows_affected = cursor.rowcount
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
return rows_affected > 0
|
||||
|
||||
# Delete a selection from the database
|
||||
def delete_selection(selection_id):
|
||||
conn = sqlite3.connect(DB_PATH)
|
||||
cursor = conn.cursor()
|
||||
|
||||
# Delete the selection
|
||||
cursor.execute('''
|
||||
DELETE FROM image_selections WHERE id = ?
|
||||
''', (selection_id,))
|
||||
|
||||
# Check if a row was affected
|
||||
rows_affected = cursor.rowcount
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
return rows_affected > 0
|
||||
|
||||
# Reset the database by deleting all selections
|
||||
def reset_database():
|
||||
print("DEBUG: Resetting database - deleting all selections")
|
||||
conn = sqlite3.connect(DB_PATH)
|
||||
cursor = conn.cursor()
|
||||
|
||||
# Delete all selections
|
||||
cursor.execute('''
|
||||
DELETE FROM image_selections
|
||||
''')
|
||||
|
||||
# Get the number of rows affected
|
||||
rows_affected = cursor.rowcount
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
print(f"DEBUG: Reset database - deleted {rows_affected} selections")
|
||||
return rows_affected
|
||||
|
||||
|
||||
|
||||
class ImageSwipeHandler(BaseHTTPRequestHandler):
|
||||
# Set response headers for CORS
|
||||
def _set_cors_headers(self):
|
||||
self.send_header('Access-Control-Allow-Origin', '*')
|
||||
self.send_header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS')
|
||||
self.send_header('Access-Control-Allow-Headers', 'Content-Type')
|
||||
def do_GET(self):
|
||||
# Parse the URL
|
||||
parsed_url = urllib.parse.urlparse(self.path)
|
||||
path = parsed_url.path
|
||||
|
||||
# Handle different paths
|
||||
if path == '/':
|
||||
self.serve_file('index.html', 'text/html')
|
||||
elif path == '/history':
|
||||
self.serve_file('history.html', 'text/html')
|
||||
elif path == '/styles.css':
|
||||
self.serve_file('styles.css', 'text/css')
|
||||
elif path == '/script.js':
|
||||
self.serve_file('script.js', 'application/javascript')
|
||||
elif path == '/random-image':
|
||||
self.serve_random_image()
|
||||
elif path == '/selections':
|
||||
self.serve_selections()
|
||||
elif path.startswith('/images/'):
|
||||
self.serve_image(path[8:])
|
||||
elif path == '/favicon.ico':
|
||||
# Silently ignore favicon requests
|
||||
self.send_response(204)
|
||||
self.end_headers()
|
||||
elif path.startswith('/download-selected'):
|
||||
self.handle_download_selected()
|
||||
else:
|
||||
# Try to serve as a static file
|
||||
if path.startswith('/'):
|
||||
path = path[1:] # Remove leading slash
|
||||
try:
|
||||
self.serve_file(path)
|
||||
except:
|
||||
self.send_error(404, "File not found")
|
||||
|
||||
def do_POST(self):
|
||||
parsed_url = urllib.parse.urlparse(self.path)
|
||||
path = parsed_url.path
|
||||
|
||||
# Debug: log every POST path
|
||||
print(f"DEBUG: do_POST received path='{path}'")
|
||||
# Accept /selection paths
|
||||
if path.startswith('/selection'):
|
||||
try:
|
||||
content_length = int(self.headers['Content-Length'])
|
||||
post_data = self.rfile.read(content_length)
|
||||
data = json.loads(post_data)
|
||||
|
||||
print(f"DEBUG: Received selection POST: {data}")
|
||||
add_selection(data['image_path'], data['action'])
|
||||
|
||||
self.send_response(200)
|
||||
self.send_header('Content-type', 'application/json')
|
||||
self._set_cors_headers()
|
||||
self.end_headers()
|
||||
self.wfile.write(json.dumps({'status': 'success'}).encode())
|
||||
except Exception as e:
|
||||
print(f"ERROR in do_POST /selection: {e}")
|
||||
self.send_error(500, f"Server error processing selection: {e}")
|
||||
else:
|
||||
print(f"DEBUG: Unknown POST path '{path}'")
|
||||
self.send_error(404, "Endpoint not found")
|
||||
|
||||
def do_OPTIONS(self):
|
||||
self.send_response(204)
|
||||
self._set_cors_headers()
|
||||
self.end_headers()
|
||||
|
||||
def serve_file(self, file_path, content_type=None):
|
||||
try:
|
||||
with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), file_path), 'rb') as file:
|
||||
content = file.read()
|
||||
|
||||
self.send_response(200)
|
||||
|
||||
# Set the content type based on parameter or guess from file extension
|
||||
if not content_type:
|
||||
content_type, _ = mimetypes.guess_type(file_path)
|
||||
|
||||
if content_type:
|
||||
self.send_header('Content-type', content_type)
|
||||
else:
|
||||
self.send_header('Content-type', 'application/octet-stream')
|
||||
|
||||
self._set_cors_headers()
|
||||
self.send_header('Content-length', len(content))
|
||||
self.end_headers()
|
||||
self.wfile.write(content)
|
||||
except FileNotFoundError:
|
||||
self.send_error(404, f"File not found: {file_path}")
|
||||
|
||||
def serve_image(self, image_path):
|
||||
try:
|
||||
# Decode URL-encoded path
|
||||
image_path = urllib.parse.unquote(image_path)
|
||||
full_path = os.path.join(IMAGE_DIR, image_path)
|
||||
|
||||
with open(full_path, 'rb') as file:
|
||||
content = file.read()
|
||||
|
||||
self.send_response(200)
|
||||
|
||||
# Set the content type based on file extension
|
||||
content_type, _ = mimetypes.guess_type(full_path)
|
||||
if content_type:
|
||||
self.send_header('Content-type', content_type)
|
||||
else:
|
||||
self.send_header('Content-type', 'application/octet-stream')
|
||||
|
||||
self._set_cors_headers()
|
||||
self.send_header('Content-length', len(content))
|
||||
self.end_headers()
|
||||
self.wfile.write(content)
|
||||
except FileNotFoundError:
|
||||
self.send_error(404, f"Image not found: {image_path}")
|
||||
|
||||
def serve_random_image(self):
|
||||
try:
|
||||
parsed_url = urllib.parse.urlparse(self.path)
|
||||
query_params = urllib.parse.parse_qs(parsed_url.query)
|
||||
orientation_filter = query_params.get('orientation', ['all'])[0]
|
||||
|
||||
conn = sqlite3.connect(DB_PATH)
|
||||
cursor = conn.cursor()
|
||||
|
||||
# Base query to get unactioned images
|
||||
query = """
|
||||
SELECT meta.path, meta.resolution_x, meta.resolution_y, meta.name, meta.orientation, meta.creation_date, meta.prompt_data
|
||||
FROM image_metadata meta
|
||||
LEFT JOIN image_selections sel ON meta.path = sel.image_path
|
||||
WHERE sel.image_path IS NULL
|
||||
"""
|
||||
|
||||
# Add orientation filter if specified
|
||||
params = ()
|
||||
if orientation_filter != 'all':
|
||||
query += " AND meta.orientation = ?"
|
||||
params = (orientation_filter,)
|
||||
|
||||
cursor.execute(query, params)
|
||||
possible_images = cursor.fetchall()
|
||||
conn.close()
|
||||
|
||||
if not possible_images:
|
||||
print("DEBUG: No matching unactioned images found.")
|
||||
response = {'message': 'No more images available for this filter.'}
|
||||
self.send_response(200)
|
||||
self.send_header('Content-type', 'application/json')
|
||||
self._set_cors_headers()
|
||||
self.end_headers()
|
||||
self.wfile.write(json.dumps(response).encode())
|
||||
return
|
||||
|
||||
# Choose one random image from the filtered list
|
||||
chosen_image_row = random.choice(possible_images)
|
||||
image_path = chosen_image_row[0]
|
||||
resolution_x = chosen_image_row[1]
|
||||
resolution_y = chosen_image_row[2]
|
||||
image_name = chosen_image_row[3]
|
||||
orientation = chosen_image_row[4]
|
||||
creation_ts = chosen_image_row[5]
|
||||
prompt_data = chosen_image_row[6]
|
||||
full_image_path = os.path.join(IMAGE_DIR, image_path)
|
||||
|
||||
print(f"DEBUG: Serving image: {image_path}")
|
||||
|
||||
|
||||
|
||||
# Return the image path as JSON
|
||||
response = {
|
||||
'path': f"/images/{image_path}",
|
||||
'resolution_x': resolution_x,
|
||||
'resolution_y': resolution_y,
|
||||
'resolution': f"{resolution_x}x{resolution_y}",
|
||||
'filename': image_name,
|
||||
'creation_date': datetime.datetime.fromtimestamp(creation_ts).strftime('%Y-%m-%d %H:%M:%S'),
|
||||
'prompt_data': prompt_data,
|
||||
'orientation': orientation
|
||||
}
|
||||
|
||||
self.send_response(200)
|
||||
self.send_header('Content-type', 'application/json')
|
||||
self._set_cors_headers()
|
||||
self.end_headers()
|
||||
self.wfile.write(json.dumps(response).encode())
|
||||
except Exception as e:
|
||||
print(f"FATAL ERROR in serve_random_image: {e}")
|
||||
self.send_error(500, f"Error serving random image: {str(e)}")
|
||||
|
||||
def serve_resolutions(self):
|
||||
try:
|
||||
# Get all resolution directories
|
||||
resolutions = [d for d in os.listdir(IMAGE_DIR) if os.path.isdir(os.path.join(IMAGE_DIR, d))]
|
||||
|
||||
# Return the resolutions as JSON
|
||||
response = {
|
||||
'resolutions': resolutions
|
||||
}
|
||||
|
||||
self.send_response(200)
|
||||
self.send_header('Content-type', 'application/json')
|
||||
self._set_cors_headers()
|
||||
self.end_headers()
|
||||
self.wfile.write(json.dumps(response).encode())
|
||||
except Exception as e:
|
||||
self.send_error(500, f"Error serving resolutions: {str(e)}")
|
||||
|
||||
def serve_selections(self):
|
||||
print("DEBUG: serve_selections() called")
|
||||
try:
|
||||
# Get all selections from the database
|
||||
selections = get_selections()
|
||||
|
||||
# Return the selections as JSON
|
||||
response = {
|
||||
'selections': selections
|
||||
}
|
||||
|
||||
# Debug the response before sending
|
||||
print(f"DEBUG: Response has {len(selections)} selections")
|
||||
|
||||
# Try to serialize to JSON to catch any serialization errors
|
||||
try:
|
||||
response_json = json.dumps(response)
|
||||
print(f"DEBUG: JSON serialization successful, length: {len(response_json)}")
|
||||
except Exception as json_err:
|
||||
print(f"DEBUG ERROR in JSON serialization: {str(json_err)}")
|
||||
# If there's an error in serialization, send a simpler response
|
||||
response = {'selections': [], 'error': 'JSON serialization error'}
|
||||
response_json = json.dumps(response)
|
||||
|
||||
self.send_response(200)
|
||||
self.send_header('Content-type', 'application/json')
|
||||
self._set_cors_headers()
|
||||
self.end_headers()
|
||||
self.wfile.write(response_json.encode())
|
||||
print("DEBUG: Response sent successfully")
|
||||
except Exception as e:
|
||||
print(f"DEBUG ERROR in serve_selections(): {str(e)}")
|
||||
self.send_error(500, f"Error serving selections: {str(e)}")
|
||||
|
||||
def do_POST(self):
|
||||
# Parse the URL path
|
||||
parsed_path = urllib.parse.urlparse(self.path)
|
||||
path = parsed_path.path
|
||||
|
||||
if path == "/selection":
|
||||
self.handle_selection()
|
||||
elif path == "/record-selection":
|
||||
self.handle_record_selection()
|
||||
elif path == "/update-selection":
|
||||
self.handle_update_selection()
|
||||
elif path == "/delete-selection":
|
||||
self.handle_delete_selection()
|
||||
elif self.path == '/reset-database':
|
||||
self.handle_reset_database()
|
||||
return
|
||||
elif self.path.startswith('/download-selected'):
|
||||
self.handle_download_selected()
|
||||
return
|
||||
else:
|
||||
self.send_error(404, "Not found")
|
||||
|
||||
def handle_selection(self):
|
||||
"""Handle legacy /selection POST with image_path and action"""
|
||||
try:
|
||||
content_length = int(self.headers['Content-Length'])
|
||||
post_data = self.rfile.read(content_length)
|
||||
data = json.loads(post_data)
|
||||
|
||||
image_path = data.get('image_path')
|
||||
action = data.get('action')
|
||||
if not image_path or not action:
|
||||
self.send_error(400, "Missing required fields")
|
||||
return
|
||||
|
||||
add_selection(image_path, action)
|
||||
self.send_response(200)
|
||||
self.send_header('Content-type', 'application/json')
|
||||
self._set_cors_headers()
|
||||
self.end_headers()
|
||||
self.wfile.write(json.dumps({'status': 'success'}).encode())
|
||||
except Exception as e:
|
||||
print(f"ERROR in handle_selection: {e}")
|
||||
self.send_error(500, f"Server error: {e}")
|
||||
|
||||
def handle_record_selection(self):
|
||||
try:
|
||||
# Get the content length
|
||||
content_length = int(self.headers['Content-Length'])
|
||||
|
||||
# Read the request body
|
||||
post_data = self.rfile.read(content_length).decode('utf-8')
|
||||
data = json.loads(post_data)
|
||||
|
||||
# Extract the required fields
|
||||
image_path = data.get('path', '').replace('/images/', '')
|
||||
resolution = data.get('resolution', '')
|
||||
action = data.get('action', '')
|
||||
|
||||
# Validate the data
|
||||
if not image_path or not action:
|
||||
self.send_error(400, "Missing required fields")
|
||||
return
|
||||
|
||||
# Store only image_path & action for compatibility
|
||||
add_selection(image_path, action)
|
||||
|
||||
# Return success response
|
||||
response = {
|
||||
'success': True,
|
||||
'message': f"Selection recorded: {action} for {image_path}"
|
||||
}
|
||||
|
||||
self.send_response(200)
|
||||
self.send_header('Content-type', 'application/json')
|
||||
self._set_cors_headers()
|
||||
self.end_headers()
|
||||
self.wfile.write(json.dumps(response).encode())
|
||||
except Exception as e:
|
||||
self.send_error(500, f"Error recording selection: {str(e)}")
|
||||
|
||||
def handle_update_selection(self):
|
||||
try:
|
||||
# Get the content length
|
||||
content_length = int(self.headers['Content-Length'])
|
||||
|
||||
# Read the request body
|
||||
post_data = self.rfile.read(content_length).decode('utf-8')
|
||||
data = json.loads(post_data)
|
||||
|
||||
# Extract the required fields
|
||||
selection_id = data.get('id')
|
||||
action = data.get('action', '')
|
||||
|
||||
# Validate the data
|
||||
if not selection_id or not action:
|
||||
self.send_error(400, "Missing required fields")
|
||||
return
|
||||
|
||||
# Update the selection in the database
|
||||
success = update_selection(selection_id, action)
|
||||
|
||||
if not success:
|
||||
self.send_error(404, f"Selection with ID {selection_id} not found")
|
||||
return
|
||||
|
||||
# Return success response
|
||||
response = {
|
||||
'success': True,
|
||||
'message': f"Selection updated: ID {selection_id} to {action}"
|
||||
}
|
||||
|
||||
self.send_response(200)
|
||||
self.send_header('Content-type', 'application/json')
|
||||
self._set_cors_headers()
|
||||
self.end_headers()
|
||||
self.wfile.write(json.dumps(response).encode())
|
||||
except Exception as e:
|
||||
self.send_error(500, f"Error updating selection: {str(e)}")
|
||||
|
||||
def handle_delete_selection(self):
|
||||
try:
|
||||
# Get the content length
|
||||
content_length = int(self.headers['Content-Length'])
|
||||
|
||||
# Read the request body
|
||||
post_data = self.rfile.read(content_length).decode('utf-8')
|
||||
data = json.loads(post_data)
|
||||
|
||||
# Extract the required fields
|
||||
selection_id = data.get('id')
|
||||
|
||||
# Validate the data
|
||||
if not selection_id:
|
||||
self.send_error(400, "Missing selection ID")
|
||||
return
|
||||
|
||||
# Delete the selection from the database
|
||||
success = delete_selection(selection_id)
|
||||
|
||||
if not success:
|
||||
self.send_error(404, f"Selection with ID {selection_id} not found")
|
||||
return
|
||||
|
||||
# Return success response
|
||||
response = {
|
||||
'success': True,
|
||||
'message': f"Selection deleted: ID {selection_id}"
|
||||
}
|
||||
|
||||
self.send_response(200)
|
||||
self.send_header('Content-type', 'application/json')
|
||||
self._set_cors_headers()
|
||||
self.end_headers()
|
||||
self.wfile.write(json.dumps(response).encode())
|
||||
except Exception as e:
|
||||
print(f"DEBUG ERROR in handle_delete_selection(): {str(e)}")
|
||||
self.send_error(500, f"Error deleting selection: {str(e)}")
|
||||
|
||||
def handle_reset_database(self):
|
||||
try:
|
||||
reset_database()
|
||||
self.send_response(200)
|
||||
self.send_header('Content-type', 'application/json')
|
||||
self.send_header('Access-Control-Allow-Origin', '*')
|
||||
self.end_headers()
|
||||
self.wfile.write(json.dumps({'success': True, 'message': 'Database reset successfully'}).encode())
|
||||
except Exception as e:
|
||||
print(f"DEBUG ERROR in handle_reset_database: {str(e)}")
|
||||
self.send_response(500)
|
||||
self.send_header('Content-type', 'application/json')
|
||||
self.send_header('Access-Control-Allow-Origin', '*')
|
||||
self.end_headers()
|
||||
self.wfile.write(json.dumps({'success': False, 'message': f'Error: {str(e)}'}).encode())
|
||||
|
||||
def handle_download_selected(self):
|
||||
try:
|
||||
# Parse the query parameters to get the selected image paths
|
||||
query_components = urllib.parse.parse_qs(urllib.parse.urlparse(self.path).query)
|
||||
image_paths = query_components.get('paths', [])
|
||||
|
||||
if not image_paths:
|
||||
self.send_response(400)
|
||||
self.send_header('Content-type', 'application/json')
|
||||
self.send_header('Access-Control-Allow-Origin', '*')
|
||||
self.end_headers()
|
||||
self.wfile.write(json.dumps({'success': False, 'message': 'No image paths provided'}).encode())
|
||||
return
|
||||
|
||||
# Create a zip file in memory
|
||||
zip_buffer = io.BytesIO()
|
||||
with zipfile.ZipFile(zip_buffer, 'a', zipfile.ZIP_DEFLATED, False) as zip_file:
|
||||
for path in image_paths:
|
||||
# Remove the /images/ prefix
|
||||
if path.startswith('/images/'):
|
||||
path = path[8:]
|
||||
|
||||
full_path = os.path.join(IMAGE_DIR, path)
|
||||
if os.path.exists(full_path):
|
||||
# Add the file to the zip with just the filename (no directory structure)
|
||||
filename = os.path.basename(path)
|
||||
zip_file.write(full_path, filename)
|
||||
|
||||
# Seek to the beginning of the buffer
|
||||
zip_buffer.seek(0)
|
||||
|
||||
# Send the zip file as a response
|
||||
self.send_response(200)
|
||||
self.send_header('Content-type', 'application/zip')
|
||||
self.send_header('Content-Disposition', 'attachment; filename="selected_images.zip"')
|
||||
self.send_header('Access-Control-Allow-Origin', '*')
|
||||
self.end_headers()
|
||||
self.wfile.write(zip_buffer.getvalue())
|
||||
|
||||
except Exception as e:
|
||||
print(f"DEBUG ERROR in handle_download_selected: {str(e)}")
|
||||
self.send_response(500)
|
||||
self.send_header('Content-type', 'application/json')
|
||||
self.send_header('Access-Control-Allow-Origin', '*')
|
||||
self.end_headers()
|
||||
self.wfile.write(json.dumps({'success': False, 'message': f'Error: {str(e)}'}).encode())
|
||||
|
||||
def do_OPTIONS(self):
|
||||
# Handle preflight requests for CORS
|
||||
self.send_response(200)
|
||||
self._set_cors_headers()
|
||||
self.end_headers()
|
||||
|
||||
def run(server_class=HTTPServer, handler_class=ImageSwipeHandler, port=8000):
|
||||
# Initialize the database
|
||||
init_db()
|
||||
|
||||
# Ensure the 'images' directory exists
|
||||
if not os.path.exists(IMAGE_DIR):
|
||||
os.makedirs(IMAGE_DIR)
|
||||
|
||||
# Sync the image database on startup
|
||||
sync_image_database()
|
||||
|
||||
server_address = ('', port)
|
||||
httpd = server_class(server_address, handler_class)
|
||||
print(f"Starting server on port {port}...")
|
||||
print(f"Image directory: {IMAGE_DIR}")
|
||||
print(f"Database: {DB_PATH}")
|
||||
httpd.serve_forever()
|
||||
|
||||
if __name__ == "__main__":
|
||||
run()
|
||||
74
config.py
Normal file
74
config.py
Normal file
@@ -0,0 +1,74 @@
|
||||
import os
|
||||
|
||||
# Configuration constants for the SWIPER application
|
||||
# --------------------------------------------------
|
||||
# Centralising these values avoids circular imports
|
||||
# and makes it easy to update paths / ports later
|
||||
|
||||
# Base directory of the repo (this file lives in the project root)
|
||||
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
# Paths to the folders that contain source images. Add as many as you like.
|
||||
IMAGE_DIRS = [
|
||||
"/mnt/secret-items/sd-outputs/Sorted/Images/Portrait",
|
||||
"/mnt/secret-items/sd-outputs/Sorted/Images/Landscape",
|
||||
]
|
||||
|
||||
# Backwards-compatibility: first directory
|
||||
IMAGE_DIR = IMAGE_DIRS[0]
|
||||
|
||||
from typing import Optional
|
||||
|
||||
# SQLite database file that stores selections & metadata
|
||||
DB_PATH = os.path.join(BASE_DIR, "image_selections.db")
|
||||
|
||||
# Default port for the HTTP server
|
||||
PORT = 8000
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# NSFW detection configuration
|
||||
# ---------------------------------------------------------------------------
|
||||
# List of keywords that, if present in an image's prompt data, should mark the
|
||||
# image as NSFW. Feel free to customise this list as appropriate for your own
|
||||
# needs.
|
||||
NSFW_KEYWORDS = [
|
||||
"nude",
|
||||
"nudity",
|
||||
"porn",
|
||||
"explicit",
|
||||
"sexual",
|
||||
"sex",
|
||||
"boobs",
|
||||
"nipples",
|
||||
"penis",
|
||||
"vagina",
|
||||
"pussy",
|
||||
"cum",
|
||||
"fellatio",
|
||||
"blowjob",
|
||||
"cunnilingus",
|
||||
"paizuri",
|
||||
"rape",
|
||||
"handjob",
|
||||
"lingerie",
|
||||
"bikini",
|
||||
"latex",
|
||||
"saliva",
|
||||
"ass",
|
||||
"condom",
|
||||
]
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Utility helpers
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def find_image_file(rel_path: str) -> Optional[str]:
|
||||
"""Return absolute path to `rel_path` by searching all IMAGE_DIRS.
|
||||
|
||||
Returns None if file is not found in any configured directory.
|
||||
"""
|
||||
for base in IMAGE_DIRS:
|
||||
abs_path = os.path.join(base, rel_path)
|
||||
if os.path.exists(abs_path):
|
||||
return abs_path
|
||||
return None
|
||||
527
database.py
Normal file
527
database.py
Normal file
@@ -0,0 +1,527 @@
|
||||
"""Database helper functions for SWIPER.
|
||||
All DB reads / writes are centralised here so the rest of the
|
||||
codebase never needs to know SQL details.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import sqlite3
|
||||
import json
|
||||
import time
|
||||
from typing import List, Dict, Any
|
||||
|
||||
# Optional progress bar
|
||||
try:
|
||||
from tqdm import tqdm # type: ignore
|
||||
except ImportError: # pragma: no cover
|
||||
tqdm = None
|
||||
|
||||
from PIL import Image
|
||||
|
||||
from config import DB_PATH, IMAGE_DIRS, find_image_file, NSFW_KEYWORDS
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Core helpers
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def _get_conn() -> sqlite3.Connection:
|
||||
"""Return a new connection with row access by column name."""
|
||||
conn = sqlite3.connect(DB_PATH)
|
||||
conn.row_factory = sqlite3.Row
|
||||
return conn
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Schema setup & sync helpers
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def init_db() -> None:
|
||||
"""Create missing tables and perform schema migrations if necessary."""
|
||||
conn = _get_conn()
|
||||
cur = conn.cursor()
|
||||
|
||||
# Ensure image_selections table exists
|
||||
cur.execute(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS image_selections (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
image_path TEXT NOT NULL UNIQUE,
|
||||
action TEXT NOT NULL,
|
||||
timestamp INTEGER NOT NULL
|
||||
)
|
||||
"""
|
||||
)
|
||||
|
||||
# Ensure image_metadata table exists
|
||||
cur.execute(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS image_metadata (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
path TEXT NOT NULL UNIQUE,
|
||||
resolution_x INTEGER NOT NULL,
|
||||
resolution_y INTEGER NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
orientation TEXT NOT NULL,
|
||||
creation_date INTEGER NOT NULL,
|
||||
prompt_data TEXT,
|
||||
actioned TEXT DEFAULT NULL,
|
||||
nsfw INTEGER NOT NULL DEFAULT 0
|
||||
)
|
||||
"""
|
||||
)
|
||||
|
||||
# Ensure prompt_details table exists and new columns
|
||||
cur.execute(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS prompt_details (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
image_path TEXT NOT NULL UNIQUE,
|
||||
model_name TEXT,
|
||||
positive_prompt TEXT,
|
||||
negative_prompt TEXT,
|
||||
sampler TEXT,
|
||||
steps INTEGER,
|
||||
cfg_scale REAL,
|
||||
seed INTEGER,
|
||||
clip_skip INTEGER,
|
||||
loras TEXT,
|
||||
textual_inversions TEXT,
|
||||
other_parameters TEXT,
|
||||
FOREIGN KEY (image_path) REFERENCES image_metadata (path)
|
||||
)
|
||||
"""
|
||||
)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Ensure newer optional columns exist / are migrated for prompt_details
|
||||
# ------------------------------------------------------------------
|
||||
cur.execute("PRAGMA table_info(prompt_details)")
|
||||
pd_columns = {row['name'] for row in cur.fetchall()}
|
||||
if 'loras' not in pd_columns:
|
||||
cur.execute('ALTER TABLE prompt_details ADD COLUMN loras TEXT')
|
||||
if 'textual_inversions' not in pd_columns:
|
||||
cur.execute('ALTER TABLE prompt_details ADD COLUMN textual_inversions TEXT')
|
||||
|
||||
# Check and migrate the 'actioned' column
|
||||
cur.execute("PRAGMA table_info(image_metadata)")
|
||||
columns = {row['name']: row['type'] for row in cur.fetchall()}
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Ensure newer optional columns exist / are migrated
|
||||
# ------------------------------------------------------------------
|
||||
if 'actioned' not in columns:
|
||||
# Add the column if it doesn't exist
|
||||
cur.execute('ALTER TABLE image_metadata ADD COLUMN actioned TEXT DEFAULT NULL')
|
||||
elif columns.get('actioned') != 'TEXT':
|
||||
# Migrate the column if it has the wrong type (e.g., INTEGER)
|
||||
print("Migrating 'actioned' column to TEXT type...")
|
||||
cur.execute('ALTER TABLE image_metadata RENAME TO image_metadata_old')
|
||||
cur.execute(
|
||||
"""
|
||||
CREATE TABLE image_metadata (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
path TEXT NOT NULL UNIQUE,
|
||||
resolution_x INTEGER NOT NULL,
|
||||
resolution_y INTEGER NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
orientation TEXT NOT NULL,
|
||||
creation_date INTEGER NOT NULL,
|
||||
prompt_data TEXT,
|
||||
actioned TEXT DEFAULT NULL,
|
||||
nsfw INTEGER DEFAULT 0
|
||||
)
|
||||
"""
|
||||
)
|
||||
# Copy data, omitting the old 'actioned' column
|
||||
cur.execute(
|
||||
"""
|
||||
INSERT INTO image_metadata (id, path, resolution_x, resolution_y, name, orientation, creation_date, prompt_data, nsfw)
|
||||
SELECT id, path, resolution_x, resolution_y, name, orientation, creation_date, prompt_data, 0
|
||||
FROM image_metadata_old
|
||||
"""
|
||||
)
|
||||
cur.execute('DROP TABLE image_metadata_old')
|
||||
print("Migration complete.")
|
||||
|
||||
# Ensure nsfw column exists for older installations
|
||||
if 'nsfw' not in columns:
|
||||
cur.execute('ALTER TABLE image_metadata ADD COLUMN nsfw INTEGER DEFAULT 0')
|
||||
# Migrate the column if it has the wrong type (e.g., INTEGER)
|
||||
print("Migrating 'actioned' column to TEXT type...")
|
||||
cur.execute('ALTER TABLE image_metadata RENAME TO image_metadata_old')
|
||||
cur.execute(
|
||||
"""
|
||||
CREATE TABLE image_metadata (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
path TEXT NOT NULL UNIQUE,
|
||||
resolution_x INTEGER NOT NULL,
|
||||
resolution_y INTEGER NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
orientation TEXT NOT NULL,
|
||||
creation_date INTEGER NOT NULL,
|
||||
prompt_data TEXT,
|
||||
actioned TEXT DEFAULT NULL,
|
||||
nsfw INTEGER DEFAULT 0
|
||||
)
|
||||
"""
|
||||
)
|
||||
# Copy data, omitting the old 'actioned' column
|
||||
cur.execute(
|
||||
"""
|
||||
INSERT INTO image_metadata (id, path, resolution_x, resolution_y, name, orientation, creation_date, prompt_data)
|
||||
SELECT id, path, resolution_x, resolution_y, name, orientation, creation_date, prompt_data
|
||||
FROM image_metadata_old
|
||||
"""
|
||||
)
|
||||
cur.execute('DROP TABLE image_metadata_old')
|
||||
print("Migration complete.")
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
|
||||
def parse_and_store_prompt_details(image_path: str, prompt_data: str) -> None:
|
||||
"""Parse prompt data and store it in the prompt_details table."""
|
||||
if not prompt_data:
|
||||
return
|
||||
|
||||
conn = _get_conn()
|
||||
cur = conn.cursor()
|
||||
|
||||
# Simple parsing logic, can be expanded
|
||||
details = {
|
||||
"image_path": image_path,
|
||||
"positive_prompt": "",
|
||||
"negative_prompt": "",
|
||||
"model_name": None,
|
||||
"sampler": None,
|
||||
"steps": None,
|
||||
"cfg_scale": None,
|
||||
"seed": None,
|
||||
"clip_skip": None,
|
||||
"loras": None,
|
||||
"textual_inversions": None,
|
||||
"other_parameters": "{}"
|
||||
}
|
||||
|
||||
try:
|
||||
import re
|
||||
text = prompt_data
|
||||
|
||||
# Positive & negative prompt
|
||||
neg_match = re.search(r"Negative prompt:\s*(.*?)\s*(Steps:|Sampler:|Schedule type:|CFG scale:|Seed:|Size:|Model hash:|Model:|Lora hashes:|TI:|Version:|$)", text, re.S)
|
||||
if neg_match:
|
||||
details["negative_prompt"] = neg_match.group(1).strip()
|
||||
details["positive_prompt"] = text[:neg_match.start()].strip().rstrip(',')
|
||||
else:
|
||||
details["positive_prompt"] = text.split("Steps:")[0].strip()
|
||||
|
||||
# Key–value param pairs (e.g. "Steps: 20," )
|
||||
for key, val in re.findall(r"(\w[\w ]*?):\s*([^,\n]+)", text):
|
||||
val = val.strip().rstrip(',')
|
||||
if key == "Model":
|
||||
details["model_name"] = val
|
||||
elif key == "Sampler":
|
||||
details["sampler"] = val
|
||||
elif key == "Steps":
|
||||
details["steps"] = int(val or 0)
|
||||
elif key == "CFG scale":
|
||||
details["cfg_scale"] = float(val or 0)
|
||||
elif key == "Seed":
|
||||
details["seed"] = int(val or 0)
|
||||
elif key == "CLIP skip":
|
||||
details["clip_skip"] = int(val or 0)
|
||||
|
||||
# Store other params as JSON
|
||||
std_keys = {"Model", "Sampler", "Steps", "CFG scale", "Seed", "CLIP skip"}
|
||||
other_params = {k: v.strip().rstrip(',') for k, v in re.findall(r"(\w[\w ]*?):\s*([^,\n]+)", text) if k not in std_keys}
|
||||
details["other_parameters"] = json.dumps(other_params)
|
||||
|
||||
# Extract Loras and Textual Inversions (TIs)
|
||||
lora_match = re.search(r"Lora hashes:\s*\"?([^\"]+)\"?", text, re.I)
|
||||
if lora_match:
|
||||
details["loras"] = lora_match.group(1).strip()
|
||||
|
||||
ti_match = re.search(r"TI:\s*\"?([^\"]+)\"?", text, re.I)
|
||||
if ti_match:
|
||||
details["textual_inversions"] = ti_match.group(1).strip()
|
||||
|
||||
# Fallback: look for <lora:...> tags if no explicit Lora hashes line
|
||||
if not details.get("loras"):
|
||||
tag_matches = re.findall(r"<lora:([^>]+)>", text, re.I)
|
||||
if tag_matches:
|
||||
details["loras"] = ", ".join(tag_matches)
|
||||
|
||||
# Extract TI keywords (<token> patterns) if still empty
|
||||
if not details.get("textual_inversions"):
|
||||
ti_tokens = re.findall(r"<([\w-]{3,32})>", details["positive_prompt"]) # crude heuristic
|
||||
if ti_tokens:
|
||||
details["textual_inversions"] = ", ".join(sorted(set(ti_tokens)))
|
||||
|
||||
# Final clean-up
|
||||
if details.get("textual_inversions"):
|
||||
details["textual_inversions"] = details["textual_inversions"].strip().strip('"').rstrip(',').strip()
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error parsing prompt for {image_path}: {e}")
|
||||
# still insert with what we have
|
||||
|
||||
cur.execute(
|
||||
"""
|
||||
INSERT OR REPLACE INTO prompt_details (image_path, model_name, positive_prompt, negative_prompt, sampler, steps, cfg_scale, seed, clip_skip, loras, textual_inversions, other_parameters)
|
||||
VALUES (:image_path, :model_name, :positive_prompt, :negative_prompt, :sampler, :steps, :cfg_scale, :seed, :clip_skip, :loras, :textual_inversions, :other_parameters)
|
||||
""",
|
||||
details
|
||||
)
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
|
||||
def sync_image_database() -> None:
|
||||
"""Scan the image folder and ensure every image is present in image_metadata."""
|
||||
|
||||
print("Syncing image database…", flush=True)
|
||||
conn = _get_conn()
|
||||
cur = conn.cursor()
|
||||
|
||||
# Already-known images
|
||||
cur.execute("SELECT path FROM image_metadata")
|
||||
known = {row[0] for row in cur.fetchall()}
|
||||
|
||||
# Images on disk (expects <resolution>/<filename>) across all configured dirs
|
||||
disk_images: set[str] = set()
|
||||
for base in IMAGE_DIRS:
|
||||
for res in [d for d in os.listdir(base) if os.path.isdir(os.path.join(base, d))]:
|
||||
res_dir = os.path.join(base, res)
|
||||
for file in os.listdir(res_dir):
|
||||
if file.lower().endswith((".png", ".jpg", ".jpeg")):
|
||||
disk_images.add(f"{res}/{file}")
|
||||
|
||||
new_images = disk_images - known
|
||||
if not new_images:
|
||||
print("Database already up to date.")
|
||||
conn.close()
|
||||
return
|
||||
|
||||
total_new_images = len(new_images)
|
||||
|
||||
# Choose iterator with progress bar if available
|
||||
image_iter = (
|
||||
tqdm(sorted(new_images), desc="Syncing images") if tqdm else sorted(new_images)
|
||||
)
|
||||
|
||||
processed_count = 0
|
||||
rows = []
|
||||
for rel_path in image_iter:
|
||||
res, filename = rel_path.split("/", 1)
|
||||
abs_path = find_image_file(rel_path)
|
||||
if not abs_path:
|
||||
processed_count += 1
|
||||
if not tqdm and (processed_count % 100 == 0 or processed_count == total_new_images):
|
||||
percentage = (processed_count / total_new_images) * 100
|
||||
print(
|
||||
f"Processed {processed_count} / {total_new_images} images ({percentage:.2f}%)",
|
||||
flush=True,
|
||||
)
|
||||
continue
|
||||
try:
|
||||
with Image.open(abs_path) as img:
|
||||
w, h = img.size
|
||||
orient = (
|
||||
"square" if w == h else "landscape" if w > h else "portrait"
|
||||
)
|
||||
prompt = None
|
||||
if img.format == "PNG":
|
||||
prompt = img.info.get("parameters") or img.info.get("Parameters")
|
||||
ts = int(os.path.getmtime(abs_path))
|
||||
# Detect NSFW based on prompt keywords
|
||||
nsfw_flag = 0
|
||||
if prompt:
|
||||
lower_prompt = prompt.lower()
|
||||
nsfw_flag = 1 if any(k.lower() in lower_prompt for k in NSFW_KEYWORDS) else 0
|
||||
rows.append((rel_path, w, h, filename, orient, ts, prompt, nsfw_flag))
|
||||
except Exception as exc:
|
||||
print(f"Failed reading {abs_path}: {exc}")
|
||||
|
||||
if rows:
|
||||
cur.executemany(
|
||||
"""
|
||||
INSERT INTO image_metadata (path, resolution_x, resolution_y, name, orientation, creation_date, prompt_data, nsfw)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
||||
""",
|
||||
rows,
|
||||
)
|
||||
conn.commit()
|
||||
print(f"Inserted {len(rows)} new images.")
|
||||
|
||||
# Now, parse and store prompt details for the new images
|
||||
for row in rows:
|
||||
rel_path, _, _, _, _, _, prompt = row
|
||||
if prompt:
|
||||
parse_and_store_prompt_details(rel_path, prompt)
|
||||
|
||||
conn.close()
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Selection helpers
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def add_selection(image_path: str, action: str) -> None:
|
||||
"""Add or update a selection and the metadata actioned status."""
|
||||
conn = _get_conn()
|
||||
cur = conn.cursor()
|
||||
timestamp = int(time.time())
|
||||
|
||||
# Upsert the selection
|
||||
cur.execute(
|
||||
"""
|
||||
INSERT INTO image_selections (image_path, action, timestamp)
|
||||
VALUES (?, ?, ?)
|
||||
ON CONFLICT(image_path) DO UPDATE SET
|
||||
action = excluded.action,
|
||||
timestamp = excluded.timestamp
|
||||
""",
|
||||
(image_path, action, timestamp),
|
||||
)
|
||||
|
||||
# Update the metadata table with the action name
|
||||
cur.execute(
|
||||
"UPDATE image_metadata SET actioned = ? WHERE path = ?", (action, image_path)
|
||||
)
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
|
||||
def get_selections() -> List[Dict[str, Any]]:
|
||||
"""Return selection list with metadata and parsed prompt details."""
|
||||
conn = _get_conn()
|
||||
cur = conn.cursor()
|
||||
cur.execute(
|
||||
"""
|
||||
SELECT
|
||||
sel.id, sel.image_path, sel.action, sel.timestamp,
|
||||
meta.resolution_x, meta.resolution_y, meta.orientation,
|
||||
meta.nsfw,
|
||||
meta.creation_date, meta.prompt_data, meta.name,
|
||||
pd.model_name, pd.positive_prompt, pd.negative_prompt,
|
||||
pd.sampler, pd.steps, pd.cfg_scale, pd.seed, pd.clip_skip,
|
||||
pd.loras, pd.textual_inversions,
|
||||
pd.other_parameters
|
||||
FROM image_selections sel
|
||||
LEFT JOIN image_metadata meta ON sel.image_path = meta.path
|
||||
LEFT JOIN prompt_details pd ON sel.image_path = pd.image_path
|
||||
ORDER BY sel.timestamp DESC
|
||||
"""
|
||||
)
|
||||
rows = cur.fetchall()
|
||||
conn.close()
|
||||
|
||||
results: List[Dict[str, Any]] = []
|
||||
for row in rows:
|
||||
item: Dict[str, Any] = {k: row[k] for k in row.keys()}
|
||||
|
||||
# Parse other_parameters if it exists and is a string
|
||||
other_params_str = item.get("other_parameters")
|
||||
if isinstance(other_params_str, str):
|
||||
try:
|
||||
item["other_parameters"] = json.loads(other_params_str)
|
||||
except json.JSONDecodeError:
|
||||
item["other_parameters"] = {}
|
||||
|
||||
# Derive resolution & orientation if missing (back-compat)
|
||||
if not item.get("resolution"):
|
||||
try:
|
||||
path_part = item["image_path"].lstrip("/images/")
|
||||
item["resolution"] = path_part.split("/")[0]
|
||||
except Exception:
|
||||
item["resolution"] = "unknown"
|
||||
if not item.get("orientation"):
|
||||
try:
|
||||
abs_path = find_image_file(item["image_path"].lstrip("/images/"))
|
||||
if abs_path:
|
||||
with Image.open(abs_path) as img:
|
||||
w, h = img.size
|
||||
item["orientation"] = (
|
||||
"square" if w == h else "landscape" if w > h else "portrait"
|
||||
)
|
||||
except Exception:
|
||||
item["orientation"] = "unknown"
|
||||
results.append(item)
|
||||
return results
|
||||
|
||||
|
||||
def update_selection(selection_id: int, action: str) -> bool:
|
||||
"""Update an existing selection and the corresponding metadata."""
|
||||
conn = _get_conn()
|
||||
cur = conn.cursor()
|
||||
|
||||
# First, get the image_path for the given selection_id
|
||||
cur.execute("SELECT image_path FROM image_selections WHERE id = ?", (selection_id,))
|
||||
row = cur.fetchone()
|
||||
if not row:
|
||||
conn.close()
|
||||
return False
|
||||
|
||||
image_path = row['image_path']
|
||||
|
||||
# Update the action in the image_selections table
|
||||
cur.execute(
|
||||
"UPDATE image_selections SET action = ?, timestamp = ? WHERE id = ?",
|
||||
(action, int(time.time()), selection_id),
|
||||
)
|
||||
changed = cur.rowcount > 0
|
||||
|
||||
if changed:
|
||||
# Also update the actioned column in the image_metadata table
|
||||
cur.execute(
|
||||
"UPDATE image_metadata SET actioned = ? WHERE path = ?", (action, image_path)
|
||||
)
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return changed
|
||||
|
||||
|
||||
def delete_selection(selection_id: int) -> None:
|
||||
"""Delete a selection and reset the metadata actioned link."""
|
||||
conn = _get_conn()
|
||||
cur = conn.cursor()
|
||||
|
||||
# Find the image path before deleting
|
||||
cur.execute("SELECT image_path FROM image_selections WHERE id = ?", (selection_id,))
|
||||
row = cur.fetchone()
|
||||
if not row:
|
||||
conn.close()
|
||||
return # Or raise error
|
||||
|
||||
image_path = row['image_path']
|
||||
|
||||
# Delete the selection
|
||||
cur.execute("DELETE FROM image_selections WHERE id = ?", (selection_id,))
|
||||
|
||||
# Update the metadata table
|
||||
cur.execute("UPDATE image_metadata SET actioned = NULL WHERE path = ?", (image_path,))
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
|
||||
def reset_database() -> None:
|
||||
"""Clear all selections and reset all actioned links in metadata."""
|
||||
conn = _get_conn()
|
||||
cur = conn.cursor()
|
||||
cur.execute("DELETE FROM image_selections")
|
||||
cur.execute("UPDATE image_metadata SET actioned = NULL")
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
|
||||
def reset_database() -> None:
|
||||
"""Clear all selections and reset all actioned links in metadata."""
|
||||
conn = _get_conn()
|
||||
cur = conn.cursor()
|
||||
cur.execute("DELETE FROM image_selections")
|
||||
cur.execute("UPDATE image_metadata SET actioned = NULL")
|
||||
conn.commit()
|
||||
conn.close()
|
||||
361
handler.py
Normal file
361
handler.py
Normal file
@@ -0,0 +1,361 @@
|
||||
"""HTTP request handler for the SWIPER application.
|
||||
|
||||
All web-server endpoints are implemented in the `ImageSwipeHandler` class.
|
||||
It relies only on the `config` and `database` modules, avoiding direct
|
||||
knowledge of paths or SQL.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import datetime
|
||||
import io
|
||||
import json
|
||||
import mimetypes
|
||||
import os
|
||||
import random
|
||||
import sqlite3
|
||||
import urllib.parse
|
||||
import zipfile
|
||||
from http.server import BaseHTTPRequestHandler
|
||||
from typing import List
|
||||
|
||||
from PIL import Image
|
||||
|
||||
import config
|
||||
from config import IMAGE_DIRS, find_image_file
|
||||
from database import (
|
||||
add_selection,
|
||||
delete_selection,
|
||||
get_selections,
|
||||
reset_database,
|
||||
update_selection,
|
||||
)
|
||||
|
||||
# Keep first dir for legacy paths but prefer helper for lookups
|
||||
IMAGE_DIR = config.IMAGE_DIR
|
||||
DB_PATH = config.DB_PATH
|
||||
|
||||
|
||||
class ImageSwipeHandler(BaseHTTPRequestHandler):
|
||||
"""Implements all HTTP GET/POST endpoints for the front-end."""
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Helpers
|
||||
# ------------------------------------------------------------------
|
||||
def _set_cors_headers(self) -> None:
|
||||
self.send_header("Access-Control-Allow-Origin", "*")
|
||||
self.send_header("Access-Control-Allow-Methods", "GET, POST, OPTIONS")
|
||||
self.send_header("Access-Control-Allow-Headers", "Content-Type")
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# HTTP verbs
|
||||
# ------------------------------------------------------------------
|
||||
def do_GET(self) -> None: # noqa: N802 (method name required by BaseHTTPRequestHandler)
|
||||
parsed = urllib.parse.urlparse(self.path)
|
||||
path = parsed.path
|
||||
|
||||
if path == "/":
|
||||
self.serve_file("index.html", "text/html")
|
||||
elif path == "/history":
|
||||
self.serve_file("history.html", "text/html")
|
||||
elif path == "/styles.css":
|
||||
self.serve_file("styles.css", "text/css")
|
||||
elif path == "/script.js":
|
||||
self.serve_file("script.js", "application/javascript")
|
||||
elif path == "/random-image":
|
||||
self.serve_random_image()
|
||||
elif path == "/selections":
|
||||
self.serve_selections()
|
||||
elif path.startswith("/images/"):
|
||||
self.serve_image(path[8:])
|
||||
elif path == "/favicon.ico":
|
||||
self.send_response(204)
|
||||
self.end_headers()
|
||||
elif path.startswith("/download-selected"):
|
||||
self.handle_download_selected()
|
||||
else:
|
||||
# try static file
|
||||
local_path = path.lstrip("/")
|
||||
try:
|
||||
self.serve_file(local_path)
|
||||
except FileNotFoundError:
|
||||
self.send_error(404, "File not found")
|
||||
|
||||
def do_POST(self) -> None: # noqa: N802
|
||||
parsed = urllib.parse.urlparse(self.path)
|
||||
path = parsed.path
|
||||
|
||||
if path.startswith("/selection"):
|
||||
self.handle_selection_legacy()
|
||||
return
|
||||
if path == "/record-selection":
|
||||
self.handle_record_selection()
|
||||
return
|
||||
if path == "/update-selection":
|
||||
self.handle_update_selection()
|
||||
return
|
||||
if path == "/delete-selection":
|
||||
self.handle_delete_selection()
|
||||
return
|
||||
if path == "/reset-database":
|
||||
self.handle_reset_database()
|
||||
return
|
||||
if path.startswith("/download-selected"):
|
||||
self.handle_download_selected()
|
||||
return
|
||||
|
||||
self.send_error(404, "Endpoint not found")
|
||||
|
||||
def do_OPTIONS(self) -> None: # noqa: N802
|
||||
self.send_response(204)
|
||||
self._set_cors_headers()
|
||||
self.end_headers()
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Static helpers
|
||||
# ------------------------------------------------------------------
|
||||
def serve_file(self, file_path: str, content_type: str | None = None) -> None:
|
||||
abs_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), file_path)
|
||||
with open(abs_path, "rb") as fp:
|
||||
content = fp.read()
|
||||
self.send_response(200)
|
||||
if not content_type:
|
||||
content_type, _ = mimetypes.guess_type(file_path)
|
||||
self.send_header("Content-Type", content_type or "application/octet-stream")
|
||||
self._set_cors_headers()
|
||||
self.send_header("Content-Length", len(content))
|
||||
self.end_headers()
|
||||
self.wfile.write(content)
|
||||
|
||||
def serve_image(self, rel_path: str) -> None:
|
||||
abs_path = find_image_file(rel_path)
|
||||
if not abs_path:
|
||||
self.send_error(404, f"Image not found: {rel_path}")
|
||||
return
|
||||
try:
|
||||
with open(abs_path, "rb") as fp:
|
||||
content = fp.read()
|
||||
self.send_response(200)
|
||||
ctype, _ = mimetypes.guess_type(abs_path)
|
||||
self.send_header("Content-Type", ctype or "application/octet-stream")
|
||||
self._set_cors_headers()
|
||||
self.send_header("Content-Length", len(content))
|
||||
self.end_headers()
|
||||
self.wfile.write(content)
|
||||
except FileNotFoundError:
|
||||
self.send_error(404, f"Image not found: {rel_path}")
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# API helpers
|
||||
# ------------------------------------------------------------------
|
||||
def serve_random_image(self) -> None:
|
||||
parsed = urllib.parse.urlparse(self.path)
|
||||
query_params = urllib.parse.parse_qs(parsed.query)
|
||||
orientation_str = query_params.get("orientation", ["all"])[0]
|
||||
orientations = [o.strip() for o in orientation_str.split(',')]
|
||||
search_keywords_str = query_params.get("search", [""])[0].strip()
|
||||
allow_nsfw = query_params.get("allow_nsfw", ["0"])[0] == "1"
|
||||
search_keywords = [kw.strip() for kw in search_keywords_str.split(',') if kw.strip()]
|
||||
actions_str = query_params.get("actions", ["Unactioned"])[0]
|
||||
actions = [a.strip() for a in actions_str.split(',') if a.strip()]
|
||||
|
||||
conn = sqlite3.connect(DB_PATH)
|
||||
conn.row_factory = sqlite3.Row # Important to access columns by name
|
||||
cur = conn.cursor()
|
||||
query = """
|
||||
SELECT
|
||||
meta.path, meta.resolution_x, meta.resolution_y, meta.name,
|
||||
meta.orientation, meta.creation_date, meta.prompt_data,
|
||||
pd.model_name, pd.positive_prompt, pd.negative_prompt,
|
||||
pd.sampler, pd.steps, pd.cfg_scale, pd.seed, pd.clip_skip,
|
||||
pd.other_parameters
|
||||
FROM image_metadata meta
|
||||
LEFT JOIN prompt_details pd ON meta.path = pd.image_path
|
||||
"""
|
||||
params: List[str] = []
|
||||
where_clauses = ["(meta.actioned IS NULL OR meta.actioned != 'purged')"]
|
||||
|
||||
# Action filter
|
||||
action_conditions = []
|
||||
action_params = []
|
||||
if "Unactioned" in actions:
|
||||
action_conditions.append("meta.actioned IS NULL")
|
||||
actions.remove("Unactioned")
|
||||
if actions:
|
||||
placeholders = ", ".join("?" for _ in actions)
|
||||
action_conditions.append(f"meta.actioned IN ({placeholders})")
|
||||
action_params.extend(actions)
|
||||
|
||||
if action_conditions:
|
||||
where_clauses.append(f"({' OR '.join(action_conditions)})")
|
||||
params.extend(action_params)
|
||||
|
||||
# Orientation filter
|
||||
if "all" not in orientations and orientations:
|
||||
placeholders = ", ".join("?" for _ in orientations)
|
||||
where_clauses.append(f"meta.orientation IN ({placeholders})")
|
||||
params.extend(orientations)
|
||||
|
||||
# NSFW filter
|
||||
if not allow_nsfw:
|
||||
where_clauses.append("meta.nsfw = 0")
|
||||
|
||||
# Keyword filter
|
||||
if search_keywords:
|
||||
for keyword in search_keywords:
|
||||
# Search only the positive prompt (pd.positive_prompt)
|
||||
where_clauses.append("pd.positive_prompt LIKE ?")
|
||||
params.append(f"%{keyword}%")
|
||||
|
||||
if where_clauses:
|
||||
query += " WHERE " + " AND ".join(where_clauses)
|
||||
|
||||
cur.execute(query, params)
|
||||
rows = cur.fetchall()
|
||||
conn.close()
|
||||
|
||||
if not rows:
|
||||
self._json_response({"message": "No more images available for this filter."})
|
||||
return
|
||||
|
||||
row = random.choice(rows)
|
||||
# Convert row to a dictionary for easier access
|
||||
row_dict = dict(row)
|
||||
|
||||
other_params_str = row_dict.get("other_parameters")
|
||||
other_params = json.loads(other_params_str) if other_params_str and other_params_str != '{}' else {}
|
||||
|
||||
response = {
|
||||
"path": f"/images/{row_dict['path']}",
|
||||
"resolution_x": row_dict["resolution_x"],
|
||||
"resolution_y": row_dict["resolution_y"],
|
||||
"resolution": f"{row_dict['resolution_x']}x{row_dict['resolution_y']}",
|
||||
"filename": row_dict["name"],
|
||||
"orientation": row_dict["orientation"],
|
||||
"creation_date": datetime.datetime.fromtimestamp(row_dict["creation_date"]).strftime("%Y-%m-%d %H:%M:%S"),
|
||||
"prompt_data": row_dict["prompt_data"],
|
||||
"model_name": row_dict.get("model_name"),
|
||||
"positive_prompt": row_dict.get("positive_prompt"),
|
||||
"negative_prompt": row_dict.get("negative_prompt"),
|
||||
"sampler": row_dict.get("sampler"),
|
||||
"steps": row_dict.get("steps"),
|
||||
"cfg_scale": row_dict.get("cfg_scale"),
|
||||
"seed": row_dict.get("seed"),
|
||||
"clip_skip": row_dict.get("clip_skip"),
|
||||
"other_parameters": other_params,
|
||||
}
|
||||
self._json_response(response)
|
||||
|
||||
def serve_selections(self) -> None:
|
||||
data = {"selections": get_selections()}
|
||||
self._json_response(data)
|
||||
|
||||
def serve_resolutions(self) -> None:
|
||||
# Collect resolutions across all configured directories
|
||||
resolutions_set = set()
|
||||
for base in IMAGE_DIRS:
|
||||
for d in os.listdir(base):
|
||||
if os.path.isdir(os.path.join(base, d)):
|
||||
resolutions_set.add(d)
|
||||
resolutions = sorted(resolutions_set)
|
||||
self._json_response({"resolutions": resolutions})
|
||||
|
||||
def handle_selection_legacy(self) -> None:
|
||||
# legacy /selection endpoint keeps existing clients working
|
||||
try:
|
||||
length = int(self.headers["Content-Length"])
|
||||
body = json.loads(self.rfile.read(length))
|
||||
image_path = body.get("image_path", "")
|
||||
action = body.get("action")
|
||||
|
||||
if image_path.startswith("/images/"):
|
||||
image_path = image_path[len("/images/"):]
|
||||
|
||||
if not image_path or not action:
|
||||
self.send_error(400, "Missing image_path or action")
|
||||
return
|
||||
|
||||
add_selection(image_path, action)
|
||||
self._json_response({"status": "success"})
|
||||
except Exception as exc:
|
||||
self.send_error(500, f"Server error: {exc}")
|
||||
|
||||
def handle_record_selection(self) -> None:
|
||||
try:
|
||||
length = int(self.headers["Content-Length"])
|
||||
data = json.loads(self.rfile.read(length))
|
||||
image_path = data.get("path", "").replace("/images/", "")
|
||||
action = data.get("action", "")
|
||||
if not image_path or not action:
|
||||
self.send_error(400, "Missing required fields")
|
||||
return
|
||||
add_selection(image_path, action)
|
||||
self._json_response({"success": True, "message": "Selection recorded"})
|
||||
except Exception as exc:
|
||||
self.send_error(500, f"Error: {exc}")
|
||||
|
||||
def handle_update_selection(self) -> None:
|
||||
try:
|
||||
length = int(self.headers["Content-Length"])
|
||||
data = json.loads(self.rfile.read(length))
|
||||
if not update_selection(data.get("id"), data.get("action")):
|
||||
self.send_error(404, "Selection not found")
|
||||
return
|
||||
self._json_response({"success": True})
|
||||
except Exception as exc:
|
||||
self.send_error(500, f"Error: {exc}")
|
||||
|
||||
def handle_delete_selection(self) -> None:
|
||||
try:
|
||||
length = int(self.headers["Content-Length"])
|
||||
data = json.loads(self.rfile.read(length))
|
||||
if not delete_selection(data.get("id")):
|
||||
self.send_error(404, "Selection not found")
|
||||
return
|
||||
self._json_response({"success": True})
|
||||
except Exception as exc:
|
||||
self.send_error(500, f"Error: {exc}")
|
||||
|
||||
def handle_reset_database(self) -> None:
|
||||
reset_database()
|
||||
self._json_response({"status": "success", "message": "Database reset successfully"})
|
||||
|
||||
def handle_download_selected(self) -> None:
|
||||
try:
|
||||
parsed = urllib.parse.urlparse(self.path)
|
||||
q = urllib.parse.parse_qs(parsed.query)
|
||||
image_paths = q.get("paths", [])
|
||||
if not image_paths:
|
||||
self.send_error(400, "Missing paths param")
|
||||
return
|
||||
|
||||
buf = io.BytesIO()
|
||||
with zipfile.ZipFile(buf, "a", zipfile.ZIP_DEFLATED, False) as zf:
|
||||
for p in image_paths:
|
||||
if p.startswith("/images/"):
|
||||
p = p[8:]
|
||||
full = find_image_file(p)
|
||||
if full and os.path.exists(full):
|
||||
zf.write(full, os.path.basename(p))
|
||||
buf.seek(0)
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Type", "application/zip")
|
||||
self.send_header(
|
||||
"Content-Disposition", "attachment; filename=selected_images.zip"
|
||||
)
|
||||
self._set_cors_headers()
|
||||
self.end_headers()
|
||||
self.wfile.write(buf.getvalue())
|
||||
except Exception as exc:
|
||||
self.send_error(500, f"Error: {exc}")
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Utilities
|
||||
# ------------------------------------------------------------------
|
||||
def _json_response(self, data: dict) -> None:
|
||||
payload = json.dumps(data).encode()
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Type", "application/json")
|
||||
self._set_cors_headers()
|
||||
self.send_header("Content-Length", len(payload))
|
||||
self.end_headers()
|
||||
self.wfile.write(payload)
|
||||
92
history.html
92
history.html
@@ -29,6 +29,27 @@
|
||||
padding: 10px;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
/* Sort section */
|
||||
.sort-section {
|
||||
margin-bottom: 15px;
|
||||
margin-top: 10px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
.sort-select {
|
||||
padding: 6px 10px;
|
||||
border-radius: var(--border-radius);
|
||||
}
|
||||
.sort-dir-btn {
|
||||
background: var(--primary-color);
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: var(--border-radius);
|
||||
padding: 6px 10px;
|
||||
cursor: pointer;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@@ -63,19 +84,24 @@
|
||||
|
||||
<div class="container">
|
||||
<header class="header">
|
||||
<h1 class="app-title"><img src="static/logo.png" alt="Swaipu logo" class="logo logo-half"> Swaipu History</h1>
|
||||
<a href="/" class="history-link">Back to Swipe</a>
|
||||
<h1 class="app-title"><a href="/" aria-label="Home"><img src="static/logo.png" alt="Swaipu logo" class="logo logo-wide"></a></h1>
|
||||
</header>
|
||||
|
||||
<div class="filter-container">
|
||||
<div class="search-section" style="display:flex;gap:8px;align-items:center;margin-bottom:15px;">
|
||||
<input type="text" id="search-input" placeholder="Add keywords..." class="search-input">
|
||||
<button id="search-button" class="action-btn search-btn" title="Add keyword"><img src="static/icons/add.svg" alt="Add" class="btn-icon"></button>
|
||||
<div class="keyword-pills-container"></div>
|
||||
</div>
|
||||
|
||||
<div class="filter-container">
|
||||
<div class="filter-section">
|
||||
<h4>Action</h4>
|
||||
<div class="filter-buttons">
|
||||
<button class="filter-btn active" data-filter="all">All</button>
|
||||
<button class="filter-btn" data-filter="left">Discarded</button>
|
||||
<button class="filter-btn" data-filter="right">Kept</button>
|
||||
<button class="filter-btn" data-filter="up">Favorited</button>
|
||||
<button class="filter-btn" data-filter="down">Review</button>
|
||||
<button class="filter-btn active" data-filter="all"><img src="/static/icons/all.svg" alt="All" class="action-filter"></button>
|
||||
<button class="filter-btn" data-filter="Discarded"><img src="/static/icons/discard.svg" alt="Discarded" class="action-filter"></button>
|
||||
<button class="filter-btn" data-filter="Kept"><img src="/static/icons/keep.svg" alt="Kept" class="action-filter"></button>
|
||||
<button class="filter-btn" data-filter="Favourited"><img src="/static/icons/fav.svg" alt="Favourited" class="action-filter"></button>
|
||||
<button class="filter-btn" data-filter="Reviewing"><img src="/static/icons/review.svg" alt="Reviewing" class="action-filter"></button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="filter-section">
|
||||
@@ -87,26 +113,58 @@
|
||||
<button class="filter-btn" data-orientation="square">Square</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="filter-section">
|
||||
<h4>NSFW</h4>
|
||||
<div class="filter-buttons nsfw-filters">
|
||||
<button class="filter-btn active" data-nsfw="all">All</button>
|
||||
<button class="filter-btn" data-nsfw="sfw">SFW</button>
|
||||
<button class="filter-btn" data-nsfw="nsfw">NSFW</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="filter-section">
|
||||
<h4>Resolution</h4>
|
||||
<select id="resolution-filter" class="resolution-select">
|
||||
<option value="all">All Resolutions</option>
|
||||
<select id="resolution-select" class="resolution-select sort-select">
|
||||
<option value="all" selected>All Resolutions</option>
|
||||
</select>
|
||||
<div class="resolution-pills keyword-pills-container"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="action-buttons history-actions">
|
||||
<button id="reset-db" class="action-btn reset-btn"><i class="fa-solid fa-trash"></i><span class="label">Reset</span></button>
|
||||
<button id="select-all" class="action-btn select-btn"><i class="fa-solid fa-check-double"></i><span class="label">Select All</span></button>
|
||||
<button id="deselect-all" class="action-btn select-btn"><i class="fa-regular fa-square"></i><span class="label">Deselect All</span></button>
|
||||
<button id="download-selected" class="action-btn download-btn" disabled><i class="fa-solid fa-download"></i><span class="label">Download</span></button>
|
||||
</div>
|
||||
<!-- Sort controls -->
|
||||
<div class="sort-section">
|
||||
<label for="sort-field">Sort by:</label>
|
||||
<select id="sort-field" class="sort-select">
|
||||
<option value="swipe" selected>Swipe Date</option>
|
||||
<option value="created">Created Date</option>
|
||||
<option value="width">Width</option>
|
||||
<option value="height">Height</option>
|
||||
</select>
|
||||
<button id="sort-direction" class="sort-dir-btn" title="Toggle sort direction">▼</button>
|
||||
|
||||
<!-- action buttons beside sort -->
|
||||
<button id="toggle-blur" class="action-btn compact" title="Toggle NSFW Blur"><img src="static/icons/18.svg" class="btn-icon nsfw-icon" alt="Blur"></button>
|
||||
<button id="reset-db" class="action-btn reset-btn compact"><img src="static/icons/db-clear.svg" class="btn-icon" alt="Reset DB"></button>
|
||||
<button id="select-all" class="action-btn select-btn compact"><img src="static/icons/select-all.svg" class="btn-icon" alt="Select All"></button>
|
||||
<button id="deselect-all" class="action-btn select-btn compact"><img src="static/icons/select-none.svg" class="btn-icon" alt="Deselect"></button>
|
||||
<button id="download-selected" class="action-btn download-btn compact" disabled><img src="static/icons/zip.svg" class="btn-icon" alt="Download"><span class="count">0</span></button>
|
||||
</div>
|
||||
|
||||
<div id="selection-grid" class="selection-grid">
|
||||
<div class="no-selections">Loading selections...</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="view-modal" class="modal">
|
||||
<div class="modal-content">
|
||||
<img id="view-image" src="" alt="Full view" style="max-width:100%;height:auto;">
|
||||
<p id="view-filename"></p>
|
||||
<p id="view-resolution"></p>
|
||||
<p id="view-created"></p>
|
||||
<pre id="view-prompt" style="white-space:pre-wrap"></pre>
|
||||
<button id="close-view-modal" class="cancel-button">Close</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="js/history.js" type="module"></script>
|
||||
</body>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -580,6 +580,7 @@
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
|
||||
border: 4px solid transparent;
|
||||
}
|
||||
|
||||
.selection-item:hover {
|
||||
@@ -588,7 +589,9 @@
|
||||
}
|
||||
|
||||
.selection-item.selected {
|
||||
box-shadow: 0 0 0 3px var(--primary-color), var(--card-shadow-hover);
|
||||
border-width: 12px;
|
||||
/* keep existing border-color set by action */
|
||||
box-shadow: var(--card-shadow-hover);
|
||||
transform: translateY(-8px) scale(1.02);
|
||||
}
|
||||
|
||||
|
||||
47
index.html
47
index.html
@@ -12,8 +12,7 @@
|
||||
<div class="container">
|
||||
<header class="header">
|
||||
<h1 class="app-title"><img src="static/logo.png" alt="Swaipu logo" class="logo logo-wide"></h1>
|
||||
<a href="/history.html" class="history-link">View History</a>
|
||||
</header>
|
||||
</header>
|
||||
|
||||
<main class="main-section">
|
||||
<div class="swipe-container">
|
||||
@@ -31,32 +30,49 @@
|
||||
</div>
|
||||
|
||||
<aside class="side-panel">
|
||||
<div class="filter-controls">
|
||||
<div class="search-controls card">
|
||||
<input type="text" id="search-input" placeholder="Add keywords..." class="search-input">
|
||||
<button id="search-button" class="action-btn search-btn" title="Add keyword"><img src="static/icons/add.svg" alt="Add" class="btn-icon"></button>
|
||||
<div id="keyword-pills-container" class="keyword-pills-container"></div>
|
||||
</div>
|
||||
|
||||
<div class="filter-controls card">
|
||||
|
||||
<div class="filter-buttons orientation-filters">
|
||||
<button class="filter-btn active" data-orientation="all"><img src="static/icons/all-icon.png" alt="All" class="orientation-icon"></button>
|
||||
<button class="filter-btn" data-orientation="portrait"><img src="static/icons/portrait-icon.png" alt="Portrait" class="orientation-icon"></button>
|
||||
<button class="filter-btn" data-orientation="landscape"><img src="static/icons/landscape-icon.svg" alt="Landscape" class="orientation-icon"></button>
|
||||
<button class="filter-btn" data-orientation="square"><img src="static/icons/square-icon.png" alt="Square" class="orientation-icon"></button>
|
||||
<button class="filter-btn active" data-orientation="all"><img src="static/icons/all.svg" alt="All" class="orientation"></button>
|
||||
<button class="filter-btn" data-orientation="portrait"><img src="static/icons/portrait.svg" alt="Portrait" class="orientation"></button>
|
||||
<button class="filter-btn" data-orientation="landscape"><img src="static/icons/landscape.svg" alt="Landscape" class="orientation"></button>
|
||||
<button class="filter-btn" data-orientation="square"><img src="static/icons/square.svg" alt="Square" class="orientation"></button>
|
||||
<button class="filter-btn" id="toggle-nsfw" data-allow="0" title="Toggle NSFW"><img src="static/icons/18.svg" alt="NSFW" class="nsfw-icon"></button>
|
||||
</div>
|
||||
<div class="filter-buttons action-filters">
|
||||
<button class="filter-btn active" data-action="Unactioned"><img src="static/icons/unactioned.svg" alt="Unactioned" class="action-filter"></button>
|
||||
<button class="filter-btn" data-action="Kept"><img src="static/icons/keep.svg" alt="Kept" class="action-filter"></button>
|
||||
<button class="filter-btn" data-action="Discarded"><img src="static/icons/discard.svg" alt="Discarded" class="action-filter"></button>
|
||||
<button class="filter-btn" data-action="Favourited"><img src="static/icons/fav.svg" alt="Favourited" class="action-filter"></button>
|
||||
<button class="filter-btn" data-action="Reviewing"><img src="static/icons/review.svg" alt="Reviewing" class="action-filter"></button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="action-buttons">
|
||||
|
||||
<button id="btn-left" class="action-btn" aria-label="Discard">
|
||||
<img src="static/icons/discard-icon.svg" alt="Discard" class="action-icon">
|
||||
<img src="static/icons/discard.svg" alt="Discard" class="action">
|
||||
</button>
|
||||
<button id="btn-right" class="action-btn" aria-label="Keep">
|
||||
<img src="static/icons/keep-icon.svg" alt="Keep" class="action-icon">
|
||||
<img src="static/icons/keep.svg" alt="Keep" class="action">
|
||||
</button>
|
||||
<button id="btn-up" class="action-btn" aria-label="Favorite">
|
||||
<img src="static/icons/fav-icon.svg" alt="Favorite" class="action-icon">
|
||||
<img src="static/icons/fav.svg" alt="Favorite" class="action">
|
||||
</button>
|
||||
<button id="btn-down" class="action-btn" aria-label="Review">
|
||||
<img src="static/icons/review-icon.svg" alt="Review" class="action-icon">
|
||||
<img src="static/icons/review.svg" alt="Review" class="action">
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- History button -->
|
||||
<a href="/history.html" id="btn-history" class="action-btn" aria-label="History">
|
||||
<img src="static/icons/history.svg" alt="History" class="action">
|
||||
</a>
|
||||
<div class="status-area" aria-live="polite">
|
||||
|
||||
<p id="image-resolution">Resolution: Loading...</p>
|
||||
@@ -86,11 +102,18 @@
|
||||
<p id="modal-resolution">Resolution: </p>
|
||||
<p id="modal-filename">Filename: </p>
|
||||
<p id="modal-creation-date">Creation Date: </p>
|
||||
<p id="modal-prompt-data">Prompt: </p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="toast" class="toast" role="status" aria-live="polite"></div>
|
||||
|
||||
<!-- Ultra-wide mode toggle button -->
|
||||
<button id="fullscreen-toggle" class="fullscreen-toggle" aria-label="Toggle fullscreen Mode">
|
||||
<img src="static/icons/fullscreen.svg" class="btn-icon" alt="Fullscreen">
|
||||
</button>
|
||||
|
||||
<script src="js/main.js" type="module"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
361
js/history.js
361
js/history.js
@@ -1,12 +1,36 @@
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const selectionGrid = document.getElementById('selection-grid');
|
||||
// Unified filter state
|
||||
// Unified filter state supporting multi-selection for action and orientation
|
||||
const filterState = {
|
||||
action: 'all',
|
||||
orientation: 'all',
|
||||
resolution: 'all'
|
||||
actions: new Set(['all']), // Set of selected action filters
|
||||
orientations: new Set(['all']), // Set of selected orientation filters
|
||||
resolutions: new Set(['all']),
|
||||
nsfw: new Set(['all'])
|
||||
};
|
||||
// Blur state for NSFW thumbnails (on by default)
|
||||
let blurNsfw = true;
|
||||
const resolutionSelect = document.getElementById('resolution-select');
|
||||
// Search controls
|
||||
const searchInput = document.getElementById('search-input');
|
||||
const searchButton = document.getElementById('search-button');
|
||||
const keywordPillsContainer = document.querySelector('.keyword-pills-container');
|
||||
const resolutionPillsContainer = document.querySelector('.resolution-pills');
|
||||
const blurToggleBtn = document.getElementById('toggle-blur');
|
||||
// initialise button state
|
||||
blurToggleBtn.classList.toggle('active', blurNsfw);
|
||||
|
||||
|
||||
// Sorting controls
|
||||
const sortFieldSelect = document.getElementById('sort-field');
|
||||
const sortDirBtn = document.getElementById('sort-direction');
|
||||
|
||||
// Sort state
|
||||
const sortState = {
|
||||
// Keyword search state
|
||||
searchKeywords: [],
|
||||
field: 'swipe', // 'swipe' | 'created' | 'width' | 'height'
|
||||
desc: true,
|
||||
};
|
||||
const resolutionFilter = document.getElementById('resolution-filter');
|
||||
const selectAllBtn = document.getElementById('select-all');
|
||||
const deselectAllBtn = document.getElementById('deselect-all');
|
||||
const downloadSelectedBtn = document.getElementById('download-selected');
|
||||
@@ -18,15 +42,27 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
const modalMessage = document.getElementById('modal-message');
|
||||
|
||||
const resetBtn = document.getElementById('reset-db');
|
||||
// View modal elements
|
||||
const viewModal = document.getElementById('view-modal');
|
||||
const viewImg = document.getElementById('view-image');
|
||||
const viewFilename = document.getElementById('view-filename');
|
||||
const viewResolution = document.getElementById('view-resolution');
|
||||
const viewCreated = document.getElementById('view-created');
|
||||
const viewPrompt = document.getElementById('view-prompt');
|
||||
const closeViewModal = document.getElementById('close-view-modal');
|
||||
const resetModal = document.getElementById('reset-modal');
|
||||
const confirmResetBtn = document.getElementById('confirm-reset');
|
||||
const cancelResetBtn = document.getElementById('cancel-reset');
|
||||
const resetMessage = document.getElementById('reset-message');
|
||||
|
||||
let cachedSelections = [];
|
||||
// blurNsfw already defined above
|
||||
let selectedItems = [];
|
||||
let currentSelectionId = null;
|
||||
|
||||
// Helper to ensure correct /images/ prefix
|
||||
const ensureImagePath = (p) => p.startsWith('/images/') ? p : `/images/${p.replace(/^\/+/,'')}`;
|
||||
|
||||
const loadSelections = () => {
|
||||
selectionGrid.innerHTML = `<div class="no-selections">Loading selections...</div>`;
|
||||
|
||||
@@ -49,23 +85,58 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
|
||||
const populateResolutionFilter = (selections) => {
|
||||
const resolutions = [...new Set(selections.map(s => s.resolution))].sort();
|
||||
resolutionFilter.innerHTML = '<option value="all">All Resolutions</option>';
|
||||
resolutions.forEach(resolution => {
|
||||
const option = document.createElement('option');
|
||||
option.value = resolution;
|
||||
option.textContent = resolution;
|
||||
resolutionFilter.appendChild(option);
|
||||
// Populate select options (excluding duplicates)
|
||||
resolutionSelect.innerHTML = '<option value="all" selected>All Resolutions</option>';
|
||||
resolutions.forEach(res => {
|
||||
const opt = document.createElement('option');
|
||||
opt.value = res;
|
||||
opt.textContent = res;
|
||||
resolutionSelect.appendChild(opt);
|
||||
});
|
||||
};
|
||||
|
||||
const sortSelections = (arr) => {
|
||||
const { field, desc } = sortState;
|
||||
const dir = desc ? -1 : 1;
|
||||
return [...arr].sort((a, b) => {
|
||||
let va, vb;
|
||||
switch (field) {
|
||||
case 'swipe':
|
||||
va = a.timestamp || 0;
|
||||
vb = b.timestamp || 0;
|
||||
break;
|
||||
case 'created':
|
||||
va = a.creation_date || 0;
|
||||
vb = b.creation_date || 0;
|
||||
break;
|
||||
case 'width':
|
||||
va = a.resolution_x || 0;
|
||||
vb = b.resolution_x || 0;
|
||||
break;
|
||||
case 'height':
|
||||
va = a.resolution_y || 0;
|
||||
vb = b.resolution_y || 0;
|
||||
break;
|
||||
default:
|
||||
va = 0; vb = 0;
|
||||
}
|
||||
return va === vb ? 0 : (va > vb ? dir : -dir);
|
||||
});
|
||||
};
|
||||
|
||||
const renderSelections = () => {
|
||||
selectionGrid.innerHTML = '';
|
||||
const selections = cachedSelections;
|
||||
let selections = sortSelections(cachedSelections);
|
||||
|
||||
const filteredSelections = selections.filter(s =>
|
||||
(filterState.action === 'all' || s.action === filterState.action) &&
|
||||
(filterState.orientation === 'all' || s.orientation === filterState.orientation) &&
|
||||
(filterState.resolution === 'all' || s.resolution === filterState.resolution)
|
||||
(filterState.actions.has('all') || filterState.actions.has(s.action)) &&
|
||||
(filterState.orientations.has('all') || filterState.orientations.has(s.orientation)) &&
|
||||
(filterState.resolutions.has('all') || filterState.resolutions.has(s.resolution)) &&
|
||||
((filterState.nsfw.has('all')) || (filterState.nsfw.has('nsfw') && s.nsfw) || (filterState.nsfw.has('sfw') && !s.nsfw)) &&
|
||||
(sortState.searchKeywords.length === 0 || (() => {
|
||||
const haystack = `${s.image_path} ${(s.prompt_data || '')} ${(s.positive_prompt || '')} ${(s.negative_prompt || '')}`.toLowerCase();
|
||||
return sortState.searchKeywords.every(k => haystack.includes(k.toLowerCase()));
|
||||
})())
|
||||
);
|
||||
|
||||
if (filteredSelections.length === 0) {
|
||||
@@ -73,7 +144,14 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Ensure image path is absolute and prefixed with /images/
|
||||
const ensureImagePath = (p) => {
|
||||
if (p.startsWith('/images/')) return p;
|
||||
return `/images/${p.replace(/^\/+/, '')}`;
|
||||
};
|
||||
|
||||
filteredSelections.forEach(selection => {
|
||||
const blurClass = (blurNsfw && selection.nsfw) ? 'nsfw-blur' : '';
|
||||
const item = document.createElement('div');
|
||||
item.className = 'selection-item';
|
||||
item.dataset.id = selection.id;
|
||||
@@ -81,11 +159,12 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
<div class="selection-checkbox-container">
|
||||
<input type="checkbox" class="selection-checkbox">
|
||||
</div>
|
||||
<img src="${selection.image_path}" alt="Selected image" loading="lazy">
|
||||
<div class="selection-action action-${actionClass(selection.action)}">${selection.action}</div>
|
||||
<img src="${ensureImagePath(selection.image_path)}" alt="Selected image" loading="lazy" class="${blurClass}">
|
||||
<div class="selection-action action-${actionClass(selection.action)}"><img src="/static/icons/${actionIconMap[selection.action]}" alt="${selection.action}" class="selection-action"></div>
|
||||
<div class="selection-info">
|
||||
<p>${selection.image_path.split('/').pop()}</p>
|
||||
<p>Resolution: ${selection.resolution}</p>
|
||||
<p>Created: ${formatDate(selection.creation_date)}</p>
|
||||
</div>
|
||||
<div class="selection-controls">
|
||||
<button class="control-btn edit-btn">Change</button>
|
||||
@@ -94,17 +173,37 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
`;
|
||||
selectionGrid.appendChild(item);
|
||||
});
|
||||
};
|
||||
|
||||
// ---- NSFW Blur Toggle ----
|
||||
blurToggleBtn.addEventListener('click', () => {
|
||||
blurNsfw = !blurNsfw;
|
||||
blurToggleBtn.classList.toggle('active', blurNsfw);
|
||||
renderSelections();
|
||||
});
|
||||
|
||||
const actionClass = (action) => {
|
||||
const map = { 'Discarded':'discard', 'Kept':'keep', 'Favourited':'favorite', 'Reviewing':'review' };
|
||||
return map[action] || 'discard';
|
||||
};
|
||||
|
||||
const actionClass = (action) => {
|
||||
const map = { 'Discard':'discard', 'Keep':'keep', 'Favorite':'favorite', 'Review':'review' };
|
||||
return map[action] || 'discard';
|
||||
// Map action names to icon filenames for display
|
||||
const actionIconMap = {
|
||||
'Kept': 'keep.svg',
|
||||
'Discarded': 'discard.svg',
|
||||
'Favourited': 'fav.svg',
|
||||
'Reviewing': 'review.svg'
|
||||
};
|
||||
const getActionName = (action) => action;
|
||||
|
||||
const formatDate = (ts) => {
|
||||
if (!ts) return 'N/A';
|
||||
return new Date(ts * 1000).toLocaleDateString('en-GB'); // Day/Month/Year
|
||||
};
|
||||
|
||||
const updateDownloadButton = () => {
|
||||
downloadSelectedBtn.disabled = selectedItems.length === 0;
|
||||
downloadSelectedBtn.querySelector('.label').textContent = selectedItems.length > 0 ? `Download (${selectedItems.length})` : 'Download';
|
||||
downloadSelectedBtn.querySelector('.count').textContent = selectedItems.length > 0 ? selectedItems.length : '0';
|
||||
};
|
||||
|
||||
selectionGrid.addEventListener('click', (e) => {
|
||||
@@ -132,6 +231,17 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
if (confirm('Are you sure you want to delete this selection?')) {
|
||||
// Implement delete functionality
|
||||
}
|
||||
} else {
|
||||
// Open view modal when clicking elsewhere on the card/image
|
||||
const info = cachedSelections.find(s => String(s.id) === String(selectionId));
|
||||
if (info) {
|
||||
viewImg.src = ensureImagePath(info.image_path);
|
||||
viewFilename.textContent = `File: ${info.image_path.split('/').pop()}`;
|
||||
viewResolution.textContent = `Resolution: ${info.resolution}`;
|
||||
viewCreated.textContent = `Created: ${formatDate(info.creation_date)}`;
|
||||
viewPrompt.textContent = info.prompt_data || info.positive_prompt || info.negative_prompt || 'N/A';
|
||||
viewModal.style.display = 'flex';
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -141,22 +251,131 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
if (!btn) return;
|
||||
|
||||
// Determine filter type and value
|
||||
const { filter, orientation } = btn.dataset;
|
||||
const { filter, orientation, nsfw } = btn.dataset;
|
||||
// Action filters
|
||||
if (filter !== undefined) {
|
||||
filterState.action = filter;
|
||||
// update active classes within the same group
|
||||
btn.parentElement.querySelectorAll('.filter-btn').forEach(b => b.classList.remove('active'));
|
||||
toggleFilter(btn, 'actions', filter);
|
||||
}
|
||||
// Orientation filters
|
||||
if (orientation !== undefined) {
|
||||
filterState.orientation = orientation;
|
||||
btn.parentElement.querySelectorAll('.filter-btn').forEach(b => b.classList.remove('active'));
|
||||
toggleFilter(btn, 'orientations', orientation);
|
||||
}
|
||||
btn.classList.add('active');
|
||||
// NSFW filters
|
||||
if (nsfw !== undefined) {
|
||||
toggleFilter(btn, 'nsfw', nsfw);
|
||||
}
|
||||
|
||||
renderSelections();
|
||||
// Helper to toggle filter selections
|
||||
function toggleFilter(button, key, value) {
|
||||
const set = filterState[key];
|
||||
const groupButtons = button.parentElement.querySelectorAll('.filter-btn');
|
||||
if (value === 'all') {
|
||||
// Selecting 'all' clears other selections
|
||||
set.clear();
|
||||
set.add('all');
|
||||
} else {
|
||||
if (set.has('all')) set.delete('all');
|
||||
if (set.has(value)) {
|
||||
set.delete(value);
|
||||
} else {
|
||||
set.add(value);
|
||||
}
|
||||
if (set.size === 0) set.add('all');
|
||||
}
|
||||
// Update active classes
|
||||
groupButtons.forEach(b => {
|
||||
const v = b.dataset.filter || b.dataset.orientation || b.dataset.nsfw;
|
||||
b.classList.toggle('active', set.has(v));
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// ---------------- Search keyword handling ----------------
|
||||
const renderKeywordPills = () => {
|
||||
keywordPillsContainer.innerHTML = '';
|
||||
sortState.searchKeywords.forEach(keyword => {
|
||||
const pill = document.createElement('div');
|
||||
pill.className = 'keyword-pill';
|
||||
pill.textContent = keyword;
|
||||
|
||||
const removeBtn = document.createElement('button');
|
||||
removeBtn.className = 'remove-keyword';
|
||||
removeBtn.innerHTML = '×';
|
||||
removeBtn.dataset.keyword = keyword;
|
||||
pill.appendChild(removeBtn);
|
||||
|
||||
keywordPillsContainer.appendChild(pill);
|
||||
});
|
||||
};
|
||||
|
||||
const addSearchKeyword = () => {
|
||||
const newKeyword = searchInput.value.trim();
|
||||
if (newKeyword && !sortState.searchKeywords.includes(newKeyword)) {
|
||||
sortState.searchKeywords.push(newKeyword);
|
||||
renderKeywordPills();
|
||||
renderSelections();
|
||||
}
|
||||
searchInput.value = '';
|
||||
searchInput.focus();
|
||||
};
|
||||
|
||||
searchButton.addEventListener('click', addSearchKeyword);
|
||||
searchInput.addEventListener('keypress', (e) => {
|
||||
if (e.key === 'Enter') addSearchKeyword();
|
||||
});
|
||||
|
||||
keywordPillsContainer.addEventListener('click', (e) => {
|
||||
if (e.target.classList.contains('remove-keyword')) {
|
||||
const keywordToRemove = e.target.dataset.keyword;
|
||||
sortState.searchKeywords = sortState.searchKeywords.filter(k => k !== keywordToRemove);
|
||||
renderKeywordPills();
|
||||
renderSelections();
|
||||
}
|
||||
});
|
||||
|
||||
// ---------------- Resolution dropdown & pills ----------------
|
||||
const addResolutionPill = (value) => {
|
||||
const pill = document.createElement('span');
|
||||
pill.className = 'keyword-pill';
|
||||
pill.textContent = value;
|
||||
const x = document.createElement('span');
|
||||
x.className = 'remove-keyword';
|
||||
x.textContent = '×';
|
||||
pill.appendChild(x);
|
||||
resolutionPillsContainer.appendChild(pill);
|
||||
pill.addEventListener('click', () => {
|
||||
filterState.resolutions.delete(value);
|
||||
pill.remove();
|
||||
if (filterState.resolutions.size === 0) filterState.resolutions.add('all');
|
||||
renderSelections();
|
||||
});
|
||||
};
|
||||
|
||||
resolutionSelect.addEventListener('change', () => {
|
||||
const val = resolutionSelect.value;
|
||||
if (val === 'all') {
|
||||
filterState.resolutions.clear();
|
||||
filterState.resolutions.add('all');
|
||||
resolutionPillsContainer.innerHTML = '';
|
||||
} else if (!filterState.resolutions.has(val)) {
|
||||
if (filterState.resolutions.has('all')) filterState.resolutions.delete('all');
|
||||
filterState.resolutions.add(val);
|
||||
addResolutionPill(val);
|
||||
}
|
||||
resolutionSelect.value = 'all';
|
||||
renderSelections();
|
||||
});
|
||||
|
||||
resolutionFilter.addEventListener('change', function() {
|
||||
filterState.resolution = this.value;
|
||||
// ---------------- Sorting controls ----------------
|
||||
sortFieldSelect.addEventListener('change', () => {
|
||||
sortState.field = sortFieldSelect.value;
|
||||
renderSelections();
|
||||
});
|
||||
|
||||
sortDirBtn.addEventListener('click', () => {
|
||||
sortState.desc = !sortState.desc;
|
||||
sortDirBtn.innerHTML = sortState.desc ? '▼' : '▲';
|
||||
renderSelections();
|
||||
});
|
||||
|
||||
@@ -182,16 +401,90 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
|
||||
closeActionModal.addEventListener('click', () => actionModal.style.display = 'none');
|
||||
|
||||
actionButtons.forEach(button => button.addEventListener('click', function() {
|
||||
const action = this.dataset.action;
|
||||
// Implement update action functionality
|
||||
actionButtons.forEach(button => button.addEventListener('click', async function() {
|
||||
const direction = this.dataset.action;
|
||||
const actionMap = { left: 'Discarded', right: 'Kept', up: 'Favourited', down: 'Reviewing' };
|
||||
const actionName = actionMap[direction] || direction;
|
||||
if (!currentSelectionId) return;
|
||||
|
||||
// Show loading state
|
||||
modalMessage.textContent = 'Updating...';
|
||||
modalMessage.style.color = '#ffffff';
|
||||
|
||||
try {
|
||||
const response = await fetch('/update-selection', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ id: currentSelectionId, action: actionName })
|
||||
});
|
||||
const data = await response.json();
|
||||
if (response.ok && data.success) {
|
||||
// Update cached selection locally
|
||||
const sel = cachedSelections.find(s => String(s.id) === String(currentSelectionId));
|
||||
if (sel) sel.action = actionName;
|
||||
|
||||
// Refresh grid to reflect changes
|
||||
renderSelections();
|
||||
|
||||
// Success feedback
|
||||
modalMessage.textContent = 'Action updated!';
|
||||
modalMessage.style.color = '#2ecc71';
|
||||
|
||||
// Close modal after short delay
|
||||
setTimeout(() => {
|
||||
actionModal.style.display = 'none';
|
||||
modalMessage.textContent = '';
|
||||
}, 800);
|
||||
} else {
|
||||
throw new Error(data.message || 'Failed to update');
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Error updating action:', err);
|
||||
modalMessage.textContent = `Error: ${err.message}`;
|
||||
modalMessage.style.color = '#e74c3c';
|
||||
}
|
||||
}));
|
||||
|
||||
resetBtn.addEventListener('click', () => resetModal.style.display = 'flex');
|
||||
confirmResetBtn.addEventListener('click', () => {
|
||||
// Implement reset database functionality
|
||||
resetMessage.textContent = '';
|
||||
confirmResetBtn.disabled = true;
|
||||
fetch('/reset-database', {
|
||||
method: 'POST',
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.status === 'success') {
|
||||
resetMessage.textContent = 'Database reset successfully!';
|
||||
resetMessage.style.color = 'green';
|
||||
setTimeout(() => {
|
||||
resetModal.style.display = 'none';
|
||||
loadSelections();
|
||||
confirmResetBtn.disabled = false;
|
||||
}, 1500);
|
||||
} else {
|
||||
throw new Error(data.message || 'An unknown error occurred.');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error resetting database:', error);
|
||||
resetMessage.textContent = `Error: ${error.message}`;
|
||||
resetMessage.style.color = 'red';
|
||||
confirmResetBtn.disabled = false;
|
||||
});
|
||||
});
|
||||
cancelResetBtn.addEventListener('click', () => resetModal.style.display = 'none');
|
||||
|
||||
// ---- View modal close ----
|
||||
closeViewModal.addEventListener('click', () => viewModal.style.display = 'none');
|
||||
viewModal.addEventListener('click', (e) => {
|
||||
if (e.target === viewModal) viewModal.style.display = 'none';
|
||||
});
|
||||
document.addEventListener('keydown', e => {
|
||||
if (e.key === 'Escape' && viewModal.style.display === 'flex') {
|
||||
viewModal.style.display = 'none';
|
||||
}
|
||||
});
|
||||
|
||||
loadSelections();
|
||||
});
|
||||
|
||||
207
js/main.js
207
js/main.js
@@ -3,7 +3,11 @@ import { showToast, updateImageInfo } from './utils.js';
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const state = {
|
||||
currentImageInfo: null,
|
||||
currentOrientation: 'all',
|
||||
currentOrientation: ['all'],
|
||||
currentActions: ['Unactioned'],
|
||||
previousOrientation: ['all'],
|
||||
allowNsfw: false,
|
||||
searchKeywords: [],
|
||||
isLoading: false,
|
||||
isDragging: false,
|
||||
startX: 0,
|
||||
@@ -17,9 +21,14 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
const card = document.getElementById('current-card');
|
||||
const lastActionText = document.getElementById('last-action');
|
||||
const orientationFilters = document.querySelector('.orientation-filters');
|
||||
const actionFilters = document.querySelector('.action-filters');
|
||||
const modal = document.getElementById('fullscreen-modal');
|
||||
const fullscreenImage = document.getElementById('fullscreen-image');
|
||||
const closeModal = document.querySelector('.close-modal');
|
||||
const searchInput = document.getElementById('search-input');
|
||||
const nsfwToggleBtn = document.getElementById('toggle-nsfw');
|
||||
const searchButton = document.getElementById('search-button');
|
||||
const keywordPillsContainer = document.getElementById('keyword-pills-container');
|
||||
|
||||
const SWIPE_THRESHOLD = 100;
|
||||
|
||||
@@ -27,10 +36,10 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
if (!state.currentImageInfo) return;
|
||||
|
||||
card.classList.add(`swipe-${direction}`);
|
||||
const actionNameMap = { left: 'Discard', right: 'Keep', up: 'Favorite', down: 'Review' };
|
||||
const actionNameMap = { left: 'Discarded', right: 'Kept', up: 'Favourited', down: 'Reviewing' };
|
||||
const actionName = actionNameMap[direction] || direction;
|
||||
lastActionText.textContent = `Last action: ${actionName}`;
|
||||
const toastMap = { left: 'Discarded', right: 'Kept', up: 'Favorited', down: 'Marked for review' };
|
||||
const toastMap = { left: 'Discarded', right: 'Kept', up: 'Favourited', down: 'Reviewing' };
|
||||
showToast(toastMap[direction] || 'Action');
|
||||
|
||||
recordSelection(state.currentImageInfo, actionName);
|
||||
@@ -67,7 +76,23 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
state.isLoading = true;
|
||||
card.classList.add('loading');
|
||||
|
||||
fetch(`/random-image?orientation=${state.currentOrientation}&t=${new Date().getTime()}`)
|
||||
const params = new URLSearchParams({
|
||||
orientation: state.currentOrientation.join(','),
|
||||
t: new Date().getTime(),
|
||||
});
|
||||
|
||||
// NSFW param
|
||||
params.append('allow_nsfw', state.allowNsfw ? '1' : '0');
|
||||
|
||||
if (state.searchKeywords.length > 0) {
|
||||
params.append('search', state.searchKeywords.join(','));
|
||||
}
|
||||
|
||||
if (state.currentActions.length > 0) {
|
||||
params.append('actions', state.currentActions.join(','));
|
||||
}
|
||||
|
||||
fetch(`/random-image?${params.toString()}`)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
state.isLoading = false;
|
||||
@@ -170,11 +195,136 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
document.getElementById('btn-up').addEventListener('click', () => performSwipe('up'));
|
||||
document.getElementById('btn-down').addEventListener('click', () => performSwipe('down'));
|
||||
|
||||
document.addEventListener('keydown', (e) => {
|
||||
if (state.isLoading || document.activeElement === searchInput) return;
|
||||
|
||||
const keyMap = {
|
||||
ArrowLeft: 'left',
|
||||
ArrowRight: 'right',
|
||||
ArrowUp: 'up',
|
||||
ArrowDown: 'down',
|
||||
};
|
||||
|
||||
if (keyMap[e.key]) {
|
||||
e.preventDefault(); // Prevent scrolling
|
||||
performSwipe(keyMap[e.key]);
|
||||
}
|
||||
});
|
||||
|
||||
orientationFilters.addEventListener('click', (e) => {
|
||||
if (e.target.tagName === 'BUTTON' && !e.target.classList.contains('active')) {
|
||||
orientationFilters.querySelector('.active').classList.remove('active');
|
||||
e.target.classList.add('active');
|
||||
state.currentOrientation = e.target.dataset.orientation;
|
||||
const button = e.target.closest('button');
|
||||
if (!button) return;
|
||||
|
||||
const clickedOrientation = button.dataset.orientation;
|
||||
|
||||
if (clickedOrientation === 'all') {
|
||||
state.currentOrientation = ['all'];
|
||||
} else {
|
||||
// If 'all' was the only active filter, start a new selection
|
||||
if (state.currentOrientation.length === 1 && state.currentOrientation[0] === 'all') {
|
||||
state.currentOrientation = [];
|
||||
}
|
||||
|
||||
const index = state.currentOrientation.indexOf(clickedOrientation);
|
||||
if (index > -1) {
|
||||
// Already selected, so deselect
|
||||
state.currentOrientation.splice(index, 1);
|
||||
} else {
|
||||
// Not selected, so select
|
||||
state.currentOrientation.push(clickedOrientation);
|
||||
}
|
||||
}
|
||||
|
||||
// If no filters are selected after interaction, default to 'all'
|
||||
if (state.currentOrientation.length === 0) {
|
||||
state.currentOrientation = ['all'];
|
||||
}
|
||||
|
||||
// Update UI based on the state
|
||||
orientationFilters.querySelectorAll('button').forEach(btn => {
|
||||
if (state.currentOrientation.includes(btn.dataset.orientation)) {
|
||||
btn.classList.add('active');
|
||||
} else {
|
||||
btn.classList.remove('active');
|
||||
}
|
||||
});
|
||||
|
||||
loadNewImage();
|
||||
});
|
||||
|
||||
actionFilters.addEventListener('click', (e) => {
|
||||
const button = e.target.closest('button');
|
||||
if (!button) return;
|
||||
|
||||
const clickedAction = button.dataset.action;
|
||||
|
||||
if (state.currentActions.length === 1 && state.currentActions[0] === 'Unactioned' && clickedAction !== 'Unactioned') {
|
||||
state.currentActions = [];
|
||||
}
|
||||
|
||||
const index = state.currentActions.indexOf(clickedAction);
|
||||
if (index > -1) {
|
||||
state.currentActions.splice(index, 1);
|
||||
} else {
|
||||
state.currentActions.push(clickedAction);
|
||||
}
|
||||
|
||||
if (state.currentActions.length === 0) {
|
||||
state.currentActions = ['Unactioned'];
|
||||
}
|
||||
|
||||
actionFilters.querySelectorAll('button').forEach(btn => {
|
||||
if (state.currentActions.includes(btn.dataset.action)) {
|
||||
btn.classList.add('active');
|
||||
} else {
|
||||
btn.classList.remove('active');
|
||||
}
|
||||
});
|
||||
|
||||
loadNewImage();
|
||||
});
|
||||
|
||||
const renderKeywordPills = () => {
|
||||
keywordPillsContainer.innerHTML = '';
|
||||
state.searchKeywords.forEach(keyword => {
|
||||
const pill = document.createElement('div');
|
||||
pill.className = 'keyword-pill';
|
||||
pill.textContent = keyword;
|
||||
|
||||
const removeBtn = document.createElement('button');
|
||||
removeBtn.className = 'remove-keyword';
|
||||
removeBtn.innerHTML = '×';
|
||||
removeBtn.dataset.keyword = keyword;
|
||||
pill.appendChild(removeBtn);
|
||||
|
||||
keywordPillsContainer.appendChild(pill);
|
||||
});
|
||||
};
|
||||
|
||||
const addSearchKeyword = () => {
|
||||
const newKeyword = searchInput.value.trim();
|
||||
if (newKeyword && !state.searchKeywords.includes(newKeyword)) {
|
||||
state.searchKeywords.push(newKeyword);
|
||||
renderKeywordPills();
|
||||
loadNewImage();
|
||||
}
|
||||
searchInput.value = '';
|
||||
searchInput.focus();
|
||||
};
|
||||
|
||||
searchButton.addEventListener('click', addSearchKeyword);
|
||||
|
||||
searchInput.addEventListener('keypress', (e) => {
|
||||
if (e.key === 'Enter') {
|
||||
addSearchKeyword();
|
||||
}
|
||||
});
|
||||
|
||||
keywordPillsContainer.addEventListener('click', (e) => {
|
||||
if (e.target.classList.contains('remove-keyword')) {
|
||||
const keywordToRemove = e.target.dataset.keyword;
|
||||
state.searchKeywords = state.searchKeywords.filter(k => k !== keywordToRemove);
|
||||
renderKeywordPills();
|
||||
loadNewImage();
|
||||
}
|
||||
});
|
||||
@@ -185,6 +335,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
document.getElementById('modal-resolution').textContent = `Resolution: ${state.currentImageInfo.resolution}`;
|
||||
document.getElementById('modal-filename').textContent = `Filename: ${state.currentImageInfo.filename || 'N/A'}`;
|
||||
document.getElementById('modal-creation-date').textContent = `Creation Date: ${state.currentImageInfo.creation_date || 'N/A'}`;
|
||||
document.getElementById('modal-prompt-data').textContent = `Prompt: ${state.currentImageInfo.prompt_data || 'N/A'}`;
|
||||
modal.style.display = 'flex';
|
||||
}
|
||||
});
|
||||
@@ -211,5 +362,43 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
}
|
||||
});
|
||||
|
||||
loadNewImage();
|
||||
// --- Ultra-wide mode ---
|
||||
const fullscreenToggle = document.getElementById('fullscreen-toggle');
|
||||
fullscreenToggle.setAttribute('title', 'Toggle fullscreen Mode');
|
||||
|
||||
const setfullscreenMode = (isActive) => {
|
||||
if (isActive) {
|
||||
// Entering ultra-wide mode: just disable filter controls
|
||||
orientationFilters.style.pointerEvents = 'none';
|
||||
orientationFilters.style.opacity = '0.5';
|
||||
} else {
|
||||
// Exiting ultra-wide mode: re-enable filter controls
|
||||
orientationFilters.style.pointerEvents = 'auto';
|
||||
orientationFilters.style.opacity = '1';
|
||||
}
|
||||
};
|
||||
|
||||
fullscreenToggle.addEventListener('click', () => {
|
||||
const isActive = document.body.classList.toggle('fullscreen-mode');
|
||||
localStorage.setItem('fullscreenMode', isActive);
|
||||
showToast(isActive ? 'fullscreen mode enabled' : 'fullscreen mode disabled');
|
||||
setfullscreenMode(isActive);
|
||||
});
|
||||
|
||||
// Check for saved preference on load
|
||||
const isfullscreenModeOnLoad = localStorage.getItem('fullscreenMode') === 'true';
|
||||
if (isfullscreenModeOnLoad) {
|
||||
document.body.classList.add('fullscreen-mode');
|
||||
setfullscreenMode(true);
|
||||
}
|
||||
|
||||
// --- NSFW toggle ---
|
||||
nsfwToggleBtn.addEventListener('click', () => {
|
||||
state.allowNsfw = !state.allowNsfw;
|
||||
nsfwToggleBtn.dataset.allow = state.allowNsfw ? '1' : '0';
|
||||
nsfwToggleBtn.classList.toggle('active', state.allowNsfw);
|
||||
loadNewImage();
|
||||
});
|
||||
|
||||
loadNewImage(); // Always load an image on startup
|
||||
});
|
||||
|
||||
1
node_modules/.bin/detect-libc
generated
vendored
Symbolic link
1
node_modules/.bin/detect-libc
generated
vendored
Symbolic link
@@ -0,0 +1 @@
|
||||
../detect-libc/bin/detect-libc.js
|
||||
1
node_modules/.bin/sass
generated
vendored
Symbolic link
1
node_modules/.bin/sass
generated
vendored
Symbolic link
@@ -0,0 +1 @@
|
||||
../sass/sass.js
|
||||
258
node_modules/.package-lock.json
generated
vendored
258
node_modules/.package-lock.json
generated
vendored
@@ -3,6 +3,136 @@
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"node_modules/@parcel/watcher": {
|
||||
"version": "2.5.1",
|
||||
"resolved": "https://registry.npmjs.org/@parcel/watcher/-/watcher-2.5.1.tgz",
|
||||
"integrity": "sha512-dfUnCxiN9H4ap84DvD2ubjw+3vUNpstxa0TneY/Paat8a3R4uQZDLSvWjmznAY/DoahqTHl9V46HF/Zs3F29pg==",
|
||||
"dev": true,
|
||||
"hasInstallScript": true,
|
||||
"optional": true,
|
||||
"dependencies": {
|
||||
"detect-libc": "^1.0.3",
|
||||
"is-glob": "^4.0.3",
|
||||
"micromatch": "^4.0.5",
|
||||
"node-addon-api": "^7.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 10.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/parcel"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@parcel/watcher-android-arm64": "2.5.1",
|
||||
"@parcel/watcher-darwin-arm64": "2.5.1",
|
||||
"@parcel/watcher-darwin-x64": "2.5.1",
|
||||
"@parcel/watcher-freebsd-x64": "2.5.1",
|
||||
"@parcel/watcher-linux-arm-glibc": "2.5.1",
|
||||
"@parcel/watcher-linux-arm-musl": "2.5.1",
|
||||
"@parcel/watcher-linux-arm64-glibc": "2.5.1",
|
||||
"@parcel/watcher-linux-arm64-musl": "2.5.1",
|
||||
"@parcel/watcher-linux-x64-glibc": "2.5.1",
|
||||
"@parcel/watcher-linux-x64-musl": "2.5.1",
|
||||
"@parcel/watcher-win32-arm64": "2.5.1",
|
||||
"@parcel/watcher-win32-ia32": "2.5.1",
|
||||
"@parcel/watcher-win32-x64": "2.5.1"
|
||||
}
|
||||
},
|
||||
"node_modules/@parcel/watcher-linux-x64-glibc": {
|
||||
"version": "2.5.1",
|
||||
"resolved": "https://registry.npmjs.org/@parcel/watcher-linux-x64-glibc/-/watcher-linux-x64-glibc-2.5.1.tgz",
|
||||
"integrity": "sha512-GcESn8NZySmfwlTsIur+49yDqSny2IhPeZfXunQi48DMugKeZ7uy1FX83pO0X22sHntJ4Ub+9k34XQCX+oHt2A==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 10.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/parcel"
|
||||
}
|
||||
},
|
||||
"node_modules/@parcel/watcher-linux-x64-musl": {
|
||||
"version": "2.5.1",
|
||||
"resolved": "https://registry.npmjs.org/@parcel/watcher-linux-x64-musl/-/watcher-linux-x64-musl-2.5.1.tgz",
|
||||
"integrity": "sha512-n0E2EQbatQ3bXhcH2D1XIAANAcTZkQICBPVaxMeaCVBtOpBZpWJuf7LwyWPSBDITb7In8mqQgJ7gH8CILCURXg==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 10.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/parcel"
|
||||
}
|
||||
},
|
||||
"node_modules/braces": {
|
||||
"version": "3.0.3",
|
||||
"resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz",
|
||||
"integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==",
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"dependencies": {
|
||||
"fill-range": "^7.1.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/chokidar": {
|
||||
"version": "4.0.3",
|
||||
"resolved": "https://registry.npmjs.org/chokidar/-/chokidar-4.0.3.tgz",
|
||||
"integrity": "sha512-Qgzu8kfBvo+cA4962jnP1KkS6Dop5NS6g7R5LFYJr4b8Ub94PPQXUksCw9PvXoeXPRRddRNC5C1JQUR2SMGtnA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"readdirp": "^4.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 14.16.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://paulmillr.com/funding/"
|
||||
}
|
||||
},
|
||||
"node_modules/detect-libc": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-1.0.3.tgz",
|
||||
"integrity": "sha512-pGjwhsmsp4kL2RTz08wcOlGN83otlqHeD/Z5T8GXZB+/YcpQ/dgo+lbU8ZsGxV0HIvqqxo9l7mqYwyYMD9bKDg==",
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"bin": {
|
||||
"detect-libc": "bin/detect-libc.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.10"
|
||||
}
|
||||
},
|
||||
"node_modules/fill-range": {
|
||||
"version": "7.1.1",
|
||||
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz",
|
||||
"integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==",
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"dependencies": {
|
||||
"to-regex-range": "^5.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/framer-motion": {
|
||||
"version": "12.18.1",
|
||||
"resolved": "https://registry.npmjs.org/framer-motion/-/framer-motion-12.18.1.tgz",
|
||||
@@ -29,6 +159,45 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/immutable": {
|
||||
"version": "5.1.3",
|
||||
"resolved": "https://registry.npmjs.org/immutable/-/immutable-5.1.3.tgz",
|
||||
"integrity": "sha512-+chQdDfvscSF1SJqv2gn4SRO2ZyS3xL3r7IW/wWEEzrzLisnOlKiQu5ytC/BVNcS15C39WT2Hg/bjKjDMcu+zg==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/is-extglob": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz",
|
||||
"integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==",
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/is-glob": {
|
||||
"version": "4.0.3",
|
||||
"resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz",
|
||||
"integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==",
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"dependencies": {
|
||||
"is-extglob": "^2.1.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/is-number": {
|
||||
"version": "7.0.0",
|
||||
"resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz",
|
||||
"integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==",
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"engines": {
|
||||
"node": ">=0.12.0"
|
||||
}
|
||||
},
|
||||
"node_modules/lucide-react": {
|
||||
"version": "0.519.0",
|
||||
"resolved": "https://registry.npmjs.org/lucide-react/-/lucide-react-0.519.0.tgz",
|
||||
@@ -37,6 +206,20 @@
|
||||
"react": "^16.5.1 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/micromatch": {
|
||||
"version": "4.0.8",
|
||||
"resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz",
|
||||
"integrity": "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==",
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"dependencies": {
|
||||
"braces": "^3.0.3",
|
||||
"picomatch": "^2.3.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8.6"
|
||||
}
|
||||
},
|
||||
"node_modules/motion-dom": {
|
||||
"version": "12.18.1",
|
||||
"resolved": "https://registry.npmjs.org/motion-dom/-/motion-dom-12.18.1.tgz",
|
||||
@@ -50,6 +233,26 @@
|
||||
"resolved": "https://registry.npmjs.org/motion-utils/-/motion-utils-12.18.1.tgz",
|
||||
"integrity": "sha512-az26YDU4WoDP0ueAkUtABLk2BIxe28d8NH1qWT8jPGhPyf44XTdDUh8pDk9OPphaSrR9McgpcJlgwSOIw/sfkA=="
|
||||
},
|
||||
"node_modules/node-addon-api": {
|
||||
"version": "7.1.1",
|
||||
"resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-7.1.1.tgz",
|
||||
"integrity": "sha512-5m3bsyrjFWE1xf7nz7YXdN4udnVtXK6/Yfgn5qnahL6bCkf2yKt4k3nuTKAtT4r3IG8JNR2ncsIMdZuAzJjHQQ==",
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"node_modules/picomatch": {
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz",
|
||||
"integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==",
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"engines": {
|
||||
"node": ">=8.6"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/jonschlinkert"
|
||||
}
|
||||
},
|
||||
"node_modules/react": {
|
||||
"version": "19.1.0",
|
||||
"resolved": "https://registry.npmjs.org/react/-/react-19.1.0.tgz",
|
||||
@@ -59,6 +262,61 @@
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/readdirp": {
|
||||
"version": "4.1.2",
|
||||
"resolved": "https://registry.npmjs.org/readdirp/-/readdirp-4.1.2.tgz",
|
||||
"integrity": "sha512-GDhwkLfywWL2s6vEjyhri+eXmfH6j1L7JE27WhqLeYzoh/A3DBaYGEj2H/HFZCn/kMfim73FXxEJTw06WtxQwg==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">= 14.18.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "individual",
|
||||
"url": "https://paulmillr.com/funding/"
|
||||
}
|
||||
},
|
||||
"node_modules/sass": {
|
||||
"version": "1.89.2",
|
||||
"resolved": "https://registry.npmjs.org/sass/-/sass-1.89.2.tgz",
|
||||
"integrity": "sha512-xCmtksBKd/jdJ9Bt9p7nPKiuqrlBMBuuGkQlkhZjjQk3Ty48lv93k5Dq6OPkKt4XwxDJ7tvlfrTa1MPA9bf+QA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"chokidar": "^4.0.0",
|
||||
"immutable": "^5.0.2",
|
||||
"source-map-js": ">=0.6.2 <2.0.0"
|
||||
},
|
||||
"bin": {
|
||||
"sass": "sass.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14.0.0"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@parcel/watcher": "^2.4.1"
|
||||
}
|
||||
},
|
||||
"node_modules/source-map-js": {
|
||||
"version": "1.2.1",
|
||||
"resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.1.tgz",
|
||||
"integrity": "sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/to-regex-range": {
|
||||
"version": "5.0.1",
|
||||
"resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz",
|
||||
"integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==",
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"dependencies": {
|
||||
"is-number": "^7.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/tslib": {
|
||||
"version": "2.8.1",
|
||||
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz",
|
||||
|
||||
21
node_modules/@parcel/watcher-linux-x64-glibc/LICENSE
generated
vendored
Normal file
21
node_modules/@parcel/watcher-linux-x64-glibc/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017-present Devon Govett
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
1
node_modules/@parcel/watcher-linux-x64-glibc/README.md
generated
vendored
Normal file
1
node_modules/@parcel/watcher-linux-x64-glibc/README.md
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
This is the linux-x64-glibc build of @parcel/watcher. See https://github.com/parcel-bundler/watcher for details.
|
||||
33
node_modules/@parcel/watcher-linux-x64-glibc/package.json
generated
vendored
Normal file
33
node_modules/@parcel/watcher-linux-x64-glibc/package.json
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"name": "@parcel/watcher-linux-x64-glibc",
|
||||
"version": "2.5.1",
|
||||
"main": "watcher.node",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/parcel-bundler/watcher.git"
|
||||
},
|
||||
"description": "A native C++ Node module for querying and subscribing to filesystem events. Used by Parcel 2.",
|
||||
"license": "MIT",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/parcel"
|
||||
},
|
||||
"files": [
|
||||
"watcher.node"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 10.0.0"
|
||||
},
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"libc": [
|
||||
"glibc"
|
||||
]
|
||||
}
|
||||
BIN
node_modules/@parcel/watcher-linux-x64-glibc/watcher.node
generated
vendored
Normal file
BIN
node_modules/@parcel/watcher-linux-x64-glibc/watcher.node
generated
vendored
Normal file
Binary file not shown.
21
node_modules/@parcel/watcher-linux-x64-musl/LICENSE
generated
vendored
Normal file
21
node_modules/@parcel/watcher-linux-x64-musl/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017-present Devon Govett
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
1
node_modules/@parcel/watcher-linux-x64-musl/README.md
generated
vendored
Normal file
1
node_modules/@parcel/watcher-linux-x64-musl/README.md
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
This is the linux-x64-musl build of @parcel/watcher. See https://github.com/parcel-bundler/watcher for details.
|
||||
33
node_modules/@parcel/watcher-linux-x64-musl/package.json
generated
vendored
Normal file
33
node_modules/@parcel/watcher-linux-x64-musl/package.json
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"name": "@parcel/watcher-linux-x64-musl",
|
||||
"version": "2.5.1",
|
||||
"main": "watcher.node",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/parcel-bundler/watcher.git"
|
||||
},
|
||||
"description": "A native C++ Node module for querying and subscribing to filesystem events. Used by Parcel 2.",
|
||||
"license": "MIT",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/parcel"
|
||||
},
|
||||
"files": [
|
||||
"watcher.node"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 10.0.0"
|
||||
},
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"libc": [
|
||||
"musl"
|
||||
]
|
||||
}
|
||||
BIN
node_modules/@parcel/watcher-linux-x64-musl/watcher.node
generated
vendored
Normal file
BIN
node_modules/@parcel/watcher-linux-x64-musl/watcher.node
generated
vendored
Normal file
Binary file not shown.
21
node_modules/@parcel/watcher/LICENSE
generated
vendored
Normal file
21
node_modules/@parcel/watcher/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017-present Devon Govett
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
135
node_modules/@parcel/watcher/README.md
generated
vendored
Normal file
135
node_modules/@parcel/watcher/README.md
generated
vendored
Normal file
@@ -0,0 +1,135 @@
|
||||
# @parcel/watcher
|
||||
|
||||
A native C++ Node module for querying and subscribing to filesystem events. Used by [Parcel 2](https://github.com/parcel-bundler/parcel).
|
||||
|
||||
## Features
|
||||
|
||||
- **Watch** - subscribe to realtime recursive directory change notifications when files or directories are created, updated, or deleted.
|
||||
- **Query** - performantly query for historical change events in a directory, even when your program is not running.
|
||||
- **Native** - implemented in C++ for performance and low-level integration with the operating system.
|
||||
- **Cross platform** - includes backends for macOS, Linux, Windows, FreeBSD, and Watchman.
|
||||
- **Performant** - events are throttled in C++ so the JavaScript thread is not overwhelmed during large filesystem changes (e.g. `git checkout` or `npm install`).
|
||||
- **Scalable** - tens of thousands of files can be watched or queried at once with good performance.
|
||||
|
||||
## Example
|
||||
|
||||
```javascript
|
||||
const watcher = require('@parcel/watcher');
|
||||
const path = require('path');
|
||||
|
||||
// Subscribe to events
|
||||
let subscription = await watcher.subscribe(process.cwd(), (err, events) => {
|
||||
console.log(events);
|
||||
});
|
||||
|
||||
// later on...
|
||||
await subscription.unsubscribe();
|
||||
|
||||
// Get events since some saved snapshot in the past
|
||||
let snapshotPath = path.join(process.cwd(), 'snapshot.txt');
|
||||
let events = await watcher.getEventsSince(process.cwd(), snapshotPath);
|
||||
|
||||
// Save a snapshot for later
|
||||
await watcher.writeSnapshot(process.cwd(), snapshotPath);
|
||||
```
|
||||
|
||||
## Watching
|
||||
|
||||
`@parcel/watcher` supports subscribing to realtime notifications of changes in a directory. It works recursively, so changes in sub-directories will also be emitted.
|
||||
|
||||
Events are throttled and coalesced for performance during large changes like `git checkout` or `npm install`, and a single notification will be emitted with all of the events at the end.
|
||||
|
||||
Only one notification will be emitted per file. For example, if a file was both created and updated since the last event, you'll get only a `create` event. If a file is both created and deleted, you will not be notifed of that file. Renames cause two events: a `delete` for the old name, and a `create` for the new name.
|
||||
|
||||
```javascript
|
||||
let subscription = await watcher.subscribe(process.cwd(), (err, events) => {
|
||||
console.log(events);
|
||||
});
|
||||
```
|
||||
|
||||
Events have two properties:
|
||||
|
||||
- `type` - the event type: `create`, `update`, or `delete`.
|
||||
- `path` - the absolute path to the file or directory.
|
||||
|
||||
To unsubscribe from change notifications, call the `unsubscribe` method on the returned subscription object.
|
||||
|
||||
```javascript
|
||||
await subscription.unsubscribe();
|
||||
```
|
||||
|
||||
`@parcel/watcher` has the following watcher backends, listed in priority order:
|
||||
|
||||
- [FSEvents](https://developer.apple.com/documentation/coreservices/file_system_events) on macOS
|
||||
- [Watchman](https://facebook.github.io/watchman/) if installed
|
||||
- [inotify](http://man7.org/linux/man-pages/man7/inotify.7.html) on Linux
|
||||
- [ReadDirectoryChangesW](https://msdn.microsoft.com/en-us/library/windows/desktop/aa365465%28v%3Dvs.85%29.aspx) on Windows
|
||||
- [kqueue](https://man.freebsd.org/cgi/man.cgi?kqueue) on FreeBSD, or as an alternative to FSEvents on macOS
|
||||
|
||||
You can specify the exact backend you wish to use by passing the `backend` option. If that backend is not available on the current platform, the default backend will be used instead. See below for the list of backend names that can be passed to the options.
|
||||
|
||||
## Querying
|
||||
|
||||
`@parcel/watcher` also supports querying for historical changes made in a directory, even when your program is not running. This makes it easy to invalidate a cache and re-build only the files that have changed, for example. It can be **significantly** faster than traversing the entire filesystem to determine what files changed, depending on the platform.
|
||||
|
||||
In order to query for historical changes, you first need a previous snapshot to compare to. This can be saved to a file with the `writeSnapshot` function, e.g. just before your program exits.
|
||||
|
||||
```javascript
|
||||
await watcher.writeSnapshot(dirPath, snapshotPath);
|
||||
```
|
||||
|
||||
When your program starts up, you can query for changes that have occurred since that snapshot using the `getEventsSince` function.
|
||||
|
||||
```javascript
|
||||
let events = await watcher.getEventsSince(dirPath, snapshotPath);
|
||||
```
|
||||
|
||||
The events returned are exactly the same as the events that would be passed to the `subscribe` callback (see above).
|
||||
|
||||
`@parcel/watcher` has the following watcher backends, listed in priority order:
|
||||
|
||||
- [FSEvents](https://developer.apple.com/documentation/coreservices/file_system_events) on macOS
|
||||
- [Watchman](https://facebook.github.io/watchman/) if installed
|
||||
- [fts](http://man7.org/linux/man-pages/man3/fts.3.html) (brute force) on Linux and FreeBSD
|
||||
- [FindFirstFile](https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-findfirstfilea) (brute force) on Windows
|
||||
|
||||
The FSEvents (macOS) and Watchman backends are significantly more performant than the brute force backends used by default on Linux and Windows, for example returning results in miliseconds instead of seconds for large directory trees. This is because a background daemon monitoring filesystem changes on those platforms allows us to query cached data rather than traversing the filesystem manually (brute force).
|
||||
|
||||
macOS has good performance with FSEvents by default. For the best performance on other platforms, install [Watchman](https://facebook.github.io/watchman/) and it will be used by `@parcel/watcher` automatically.
|
||||
|
||||
You can specify the exact backend you wish to use by passing the `backend` option. If that backend is not available on the current platform, the default backend will be used instead. See below for the list of backend names that can be passed to the options.
|
||||
|
||||
## Options
|
||||
|
||||
All of the APIs in `@parcel/watcher` support the following options, which are passed as an object as the last function argument.
|
||||
|
||||
- `ignore` - an array of paths or glob patterns to ignore. uses [`is-glob`](https://github.com/micromatch/is-glob) to distinguish paths from globs. glob patterns are parsed with [`micromatch`](https://github.com/micromatch/micromatch) (see [features](https://github.com/micromatch/micromatch#matching-features)).
|
||||
- paths can be relative or absolute and can either be files or directories. No events will be emitted about these files or directories or their children.
|
||||
- glob patterns match on relative paths from the root that is watched. No events will be emitted for matching paths.
|
||||
- `backend` - the name of an explicitly chosen backend to use. Allowed options are `"fs-events"`, `"watchman"`, `"inotify"`, `"kqueue"`, `"windows"`, or `"brute-force"` (only for querying). If the specified backend is not available on the current platform, the default backend will be used instead.
|
||||
|
||||
## WASM
|
||||
|
||||
The `@parcel/watcher-wasm` package can be used in place of `@parcel/watcher` on unsupported platforms. It relies on the Node `fs` module, so in non-Node environments such as browsers, an `fs` polyfill will be needed.
|
||||
|
||||
**Note**: the WASM implementation is significantly less efficient than the native implementations because it must crawl the file system to watch each directory individually. Use the native `@parcel/watcher` package wherever possible.
|
||||
|
||||
```js
|
||||
import {subscribe} from '@parcel/watcher-wasm';
|
||||
|
||||
// Use the module as documented above.
|
||||
subscribe(/* ... */);
|
||||
```
|
||||
|
||||
## Who is using this?
|
||||
|
||||
- [Parcel 2](https://parceljs.org/)
|
||||
- [VSCode](https://code.visualstudio.com/updates/v1_62#_file-watching-changes)
|
||||
- [Tailwind CSS Intellisense](https://github.com/tailwindlabs/tailwindcss-intellisense)
|
||||
- [Gatsby Cloud](https://twitter.com/chatsidhartha/status/1435647412828196867)
|
||||
- [Nx](https://nx.dev)
|
||||
- [Nuxt](https://nuxt.com)
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
93
node_modules/@parcel/watcher/binding.gyp
generated
vendored
Normal file
93
node_modules/@parcel/watcher/binding.gyp
generated
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
{
|
||||
"targets": [
|
||||
{
|
||||
"target_name": "watcher",
|
||||
"defines": [ "NAPI_DISABLE_CPP_EXCEPTIONS" ],
|
||||
"sources": [ "src/binding.cc", "src/Watcher.cc", "src/Backend.cc", "src/DirTree.cc", "src/Glob.cc", "src/Debounce.cc" ],
|
||||
"include_dirs" : ["<!(node -p \"require('node-addon-api').include_dir\")"],
|
||||
'cflags!': [ '-fno-exceptions', '-std=c++17' ],
|
||||
'cflags_cc!': [ '-fno-exceptions', '-std=c++17' ],
|
||||
"conditions": [
|
||||
['OS=="mac"', {
|
||||
"sources": [
|
||||
"src/watchman/BSER.cc",
|
||||
"src/watchman/WatchmanBackend.cc",
|
||||
"src/shared/BruteForceBackend.cc",
|
||||
"src/unix/fts.cc",
|
||||
"src/macos/FSEventsBackend.cc",
|
||||
"src/kqueue/KqueueBackend.cc"
|
||||
],
|
||||
"link_settings": {
|
||||
"libraries": ["CoreServices.framework"]
|
||||
},
|
||||
"defines": [
|
||||
"WATCHMAN",
|
||||
"BRUTE_FORCE",
|
||||
"FS_EVENTS",
|
||||
"KQUEUE"
|
||||
],
|
||||
"xcode_settings": {
|
||||
"GCC_ENABLE_CPP_EXCEPTIONS": "YES"
|
||||
}
|
||||
}],
|
||||
['OS=="mac" and target_arch=="arm64"', {
|
||||
"xcode_settings": {
|
||||
"ARCHS": ["arm64"]
|
||||
}
|
||||
}],
|
||||
['OS=="linux" or OS=="android"', {
|
||||
"sources": [
|
||||
"src/watchman/BSER.cc",
|
||||
"src/watchman/WatchmanBackend.cc",
|
||||
"src/shared/BruteForceBackend.cc",
|
||||
"src/linux/InotifyBackend.cc",
|
||||
"src/unix/legacy.cc"
|
||||
],
|
||||
"defines": [
|
||||
"WATCHMAN",
|
||||
"INOTIFY",
|
||||
"BRUTE_FORCE"
|
||||
]
|
||||
}],
|
||||
['OS=="win"', {
|
||||
"sources": [
|
||||
"src/watchman/BSER.cc",
|
||||
"src/watchman/WatchmanBackend.cc",
|
||||
"src/shared/BruteForceBackend.cc",
|
||||
"src/windows/WindowsBackend.cc",
|
||||
"src/windows/win_utils.cc"
|
||||
],
|
||||
"defines": [
|
||||
"WATCHMAN",
|
||||
"WINDOWS",
|
||||
"BRUTE_FORCE"
|
||||
],
|
||||
"msvs_settings": {
|
||||
"VCCLCompilerTool": {
|
||||
"ExceptionHandling": 1, # /EHsc
|
||||
"AdditionalOptions": ['-std:c++17']
|
||||
}
|
||||
}
|
||||
}],
|
||||
['OS=="freebsd"', {
|
||||
"sources": [
|
||||
"src/watchman/BSER.cc",
|
||||
"src/watchman/WatchmanBackend.cc",
|
||||
"src/shared/BruteForceBackend.cc",
|
||||
"src/unix/fts.cc",
|
||||
"src/kqueue/KqueueBackend.cc"
|
||||
],
|
||||
"defines": [
|
||||
"WATCHMAN",
|
||||
"BRUTE_FORCE",
|
||||
"KQUEUE"
|
||||
]
|
||||
}]
|
||||
]
|
||||
}
|
||||
],
|
||||
"variables": {
|
||||
"openssl_fips": "",
|
||||
"node_use_dtrace": "false"
|
||||
}
|
||||
}
|
||||
49
node_modules/@parcel/watcher/index.d.ts
generated
vendored
Normal file
49
node_modules/@parcel/watcher/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
declare type FilePath = string;
|
||||
declare type GlobPattern = string;
|
||||
|
||||
declare namespace ParcelWatcher {
|
||||
export type BackendType =
|
||||
| 'fs-events'
|
||||
| 'watchman'
|
||||
| 'inotify'
|
||||
| 'windows'
|
||||
| 'brute-force';
|
||||
export type EventType = 'create' | 'update' | 'delete';
|
||||
export interface Options {
|
||||
ignore?: (FilePath|GlobPattern)[];
|
||||
backend?: BackendType;
|
||||
}
|
||||
export type SubscribeCallback = (
|
||||
err: Error | null,
|
||||
events: Event[]
|
||||
) => unknown;
|
||||
export interface AsyncSubscription {
|
||||
unsubscribe(): Promise<void>;
|
||||
}
|
||||
export interface Event {
|
||||
path: FilePath;
|
||||
type: EventType;
|
||||
}
|
||||
export function getEventsSince(
|
||||
dir: FilePath,
|
||||
snapshot: FilePath,
|
||||
opts?: Options
|
||||
): Promise<Event[]>;
|
||||
export function subscribe(
|
||||
dir: FilePath,
|
||||
fn: SubscribeCallback,
|
||||
opts?: Options
|
||||
): Promise<AsyncSubscription>;
|
||||
export function unsubscribe(
|
||||
dir: FilePath,
|
||||
fn: SubscribeCallback,
|
||||
opts?: Options
|
||||
): Promise<void>;
|
||||
export function writeSnapshot(
|
||||
dir: FilePath,
|
||||
snapshot: FilePath,
|
||||
opts?: Options
|
||||
): Promise<FilePath>;
|
||||
}
|
||||
|
||||
export = ParcelWatcher;
|
||||
41
node_modules/@parcel/watcher/index.js
generated
vendored
Normal file
41
node_modules/@parcel/watcher/index.js
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
const {createWrapper} = require('./wrapper');
|
||||
|
||||
let name = `@parcel/watcher-${process.platform}-${process.arch}`;
|
||||
if (process.platform === 'linux') {
|
||||
const { MUSL, family } = require('detect-libc');
|
||||
if (family === MUSL) {
|
||||
name += '-musl';
|
||||
} else {
|
||||
name += '-glibc';
|
||||
}
|
||||
}
|
||||
|
||||
let binding;
|
||||
try {
|
||||
binding = require(name);
|
||||
} catch (err) {
|
||||
handleError(err);
|
||||
try {
|
||||
binding = require('./build/Release/watcher.node');
|
||||
} catch (err) {
|
||||
handleError(err);
|
||||
try {
|
||||
binding = require('./build/Debug/watcher.node');
|
||||
} catch (err) {
|
||||
handleError(err);
|
||||
throw new Error(`No prebuild or local build of @parcel/watcher found. Tried ${name}. Please ensure it is installed (don't use --no-optional when installing with npm). Otherwise it is possible we don't support your platform yet. If this is the case, please report an issue to https://github.com/parcel-bundler/watcher.`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function handleError(err) {
|
||||
if (err?.code !== 'MODULE_NOT_FOUND') {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
const wrapper = createWrapper(binding);
|
||||
exports.writeSnapshot = wrapper.writeSnapshot;
|
||||
exports.getEventsSince = wrapper.getEventsSince;
|
||||
exports.subscribe = wrapper.subscribe;
|
||||
exports.unsubscribe = wrapper.unsubscribe;
|
||||
48
node_modules/@parcel/watcher/index.js.flow
generated
vendored
Normal file
48
node_modules/@parcel/watcher/index.js.flow
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
// @flow
|
||||
declare type FilePath = string;
|
||||
declare type GlobPattern = string;
|
||||
|
||||
export type BackendType =
|
||||
| 'fs-events'
|
||||
| 'watchman'
|
||||
| 'inotify'
|
||||
| 'windows'
|
||||
| 'brute-force';
|
||||
export type EventType = 'create' | 'update' | 'delete';
|
||||
export interface Options {
|
||||
ignore?: Array<FilePath | GlobPattern>,
|
||||
backend?: BackendType
|
||||
}
|
||||
export type SubscribeCallback = (
|
||||
err: ?Error,
|
||||
events: Array<Event>
|
||||
) => mixed;
|
||||
export interface AsyncSubscription {
|
||||
unsubscribe(): Promise<void>
|
||||
}
|
||||
export interface Event {
|
||||
path: FilePath,
|
||||
type: EventType
|
||||
}
|
||||
declare module.exports: {
|
||||
getEventsSince(
|
||||
dir: FilePath,
|
||||
snapshot: FilePath,
|
||||
opts?: Options
|
||||
): Promise<Array<Event>>,
|
||||
subscribe(
|
||||
dir: FilePath,
|
||||
fn: SubscribeCallback,
|
||||
opts?: Options
|
||||
): Promise<AsyncSubscription>,
|
||||
unsubscribe(
|
||||
dir: FilePath,
|
||||
fn: SubscribeCallback,
|
||||
opts?: Options
|
||||
): Promise<void>,
|
||||
writeSnapshot(
|
||||
dir: FilePath,
|
||||
snapshot: FilePath,
|
||||
opts?: Options
|
||||
): Promise<FilePath>
|
||||
}
|
||||
88
node_modules/@parcel/watcher/package.json
generated
vendored
Normal file
88
node_modules/@parcel/watcher/package.json
generated
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
{
|
||||
"name": "@parcel/watcher",
|
||||
"version": "2.5.1",
|
||||
"main": "index.js",
|
||||
"types": "index.d.ts",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/parcel-bundler/watcher.git"
|
||||
},
|
||||
"description": "A native C++ Node module for querying and subscribing to filesystem events. Used by Parcel 2.",
|
||||
"license": "MIT",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/parcel"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.js.flow",
|
||||
"index.d.ts",
|
||||
"wrapper.js",
|
||||
"package.json",
|
||||
"README.md",
|
||||
"LICENSE",
|
||||
"src",
|
||||
"scripts/build-from-source.js",
|
||||
"binding.gyp"
|
||||
],
|
||||
"scripts": {
|
||||
"prebuild": "prebuildify --napi --strip --tag-libc",
|
||||
"format": "prettier --write \"./**/*.{js,json,md}\"",
|
||||
"build": "node-gyp rebuild",
|
||||
"install": "node scripts/build-from-source.js",
|
||||
"test": "mocha"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 10.0.0"
|
||||
},
|
||||
"husky": {
|
||||
"hooks": {
|
||||
"pre-commit": "lint-staged"
|
||||
}
|
||||
},
|
||||
"lint-staged": {
|
||||
"*.{js,json,md}": [
|
||||
"prettier --write",
|
||||
"git add"
|
||||
]
|
||||
},
|
||||
"dependencies": {
|
||||
"detect-libc": "^1.0.3",
|
||||
"is-glob": "^4.0.3",
|
||||
"micromatch": "^4.0.5",
|
||||
"node-addon-api": "^7.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"esbuild": "^0.19.8",
|
||||
"fs-extra": "^10.0.0",
|
||||
"husky": "^7.0.2",
|
||||
"lint-staged": "^11.1.2",
|
||||
"mocha": "^9.1.1",
|
||||
"napi-wasm": "^1.1.0",
|
||||
"prebuildify": "^6.0.1",
|
||||
"prettier": "^2.3.2"
|
||||
},
|
||||
"binary": {
|
||||
"napi_versions": [
|
||||
3
|
||||
]
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@parcel/watcher-darwin-x64": "2.5.1",
|
||||
"@parcel/watcher-darwin-arm64": "2.5.1",
|
||||
"@parcel/watcher-win32-x64": "2.5.1",
|
||||
"@parcel/watcher-win32-arm64": "2.5.1",
|
||||
"@parcel/watcher-win32-ia32": "2.5.1",
|
||||
"@parcel/watcher-linux-x64-glibc": "2.5.1",
|
||||
"@parcel/watcher-linux-x64-musl": "2.5.1",
|
||||
"@parcel/watcher-linux-arm64-glibc": "2.5.1",
|
||||
"@parcel/watcher-linux-arm64-musl": "2.5.1",
|
||||
"@parcel/watcher-linux-arm-glibc": "2.5.1",
|
||||
"@parcel/watcher-linux-arm-musl": "2.5.1",
|
||||
"@parcel/watcher-android-arm64": "2.5.1",
|
||||
"@parcel/watcher-freebsd-x64": "2.5.1"
|
||||
}
|
||||
}
|
||||
13
node_modules/@parcel/watcher/scripts/build-from-source.js
generated
vendored
Normal file
13
node_modules/@parcel/watcher/scripts/build-from-source.js
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const {spawn} = require('child_process');
|
||||
|
||||
if (process.env.npm_config_build_from_source === 'true') {
|
||||
build();
|
||||
}
|
||||
|
||||
function build() {
|
||||
spawn('node-gyp', ['rebuild'], { stdio: 'inherit', shell: true }).on('exit', function (code) {
|
||||
process.exit(code);
|
||||
});
|
||||
}
|
||||
182
node_modules/@parcel/watcher/src/Backend.cc
generated
vendored
Normal file
182
node_modules/@parcel/watcher/src/Backend.cc
generated
vendored
Normal file
@@ -0,0 +1,182 @@
|
||||
#ifdef FS_EVENTS
|
||||
#include "macos/FSEventsBackend.hh"
|
||||
#endif
|
||||
#ifdef WATCHMAN
|
||||
#include "watchman/WatchmanBackend.hh"
|
||||
#endif
|
||||
#ifdef WINDOWS
|
||||
#include "windows/WindowsBackend.hh"
|
||||
#endif
|
||||
#ifdef INOTIFY
|
||||
#include "linux/InotifyBackend.hh"
|
||||
#endif
|
||||
#ifdef KQUEUE
|
||||
#include "kqueue/KqueueBackend.hh"
|
||||
#endif
|
||||
#ifdef __wasm32__
|
||||
#include "wasm/WasmBackend.hh"
|
||||
#endif
|
||||
#include "shared/BruteForceBackend.hh"
|
||||
|
||||
#include "Backend.hh"
|
||||
#include <unordered_map>
|
||||
|
||||
static std::unordered_map<std::string, std::shared_ptr<Backend>> sharedBackends;
|
||||
|
||||
std::shared_ptr<Backend> getBackend(std::string backend) {
|
||||
// Use FSEvents on macOS by default.
|
||||
// Use watchman by default if available on other platforms.
|
||||
// Fall back to brute force.
|
||||
#ifdef FS_EVENTS
|
||||
if (backend == "fs-events" || backend == "default") {
|
||||
return std::make_shared<FSEventsBackend>();
|
||||
}
|
||||
#endif
|
||||
#ifdef WATCHMAN
|
||||
if ((backend == "watchman" || backend == "default") && WatchmanBackend::checkAvailable()) {
|
||||
return std::make_shared<WatchmanBackend>();
|
||||
}
|
||||
#endif
|
||||
#ifdef WINDOWS
|
||||
if (backend == "windows" || backend == "default") {
|
||||
return std::make_shared<WindowsBackend>();
|
||||
}
|
||||
#endif
|
||||
#ifdef INOTIFY
|
||||
if (backend == "inotify" || backend == "default") {
|
||||
return std::make_shared<InotifyBackend>();
|
||||
}
|
||||
#endif
|
||||
#ifdef KQUEUE
|
||||
if (backend == "kqueue" || backend == "default") {
|
||||
return std::make_shared<KqueueBackend>();
|
||||
}
|
||||
#endif
|
||||
#ifdef __wasm32__
|
||||
if (backend == "wasm" || backend == "default") {
|
||||
return std::make_shared<WasmBackend>();
|
||||
}
|
||||
#endif
|
||||
if (backend == "brute-force" || backend == "default") {
|
||||
return std::make_shared<BruteForceBackend>();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<Backend> Backend::getShared(std::string backend) {
|
||||
auto found = sharedBackends.find(backend);
|
||||
if (found != sharedBackends.end()) {
|
||||
return found->second;
|
||||
}
|
||||
|
||||
auto result = getBackend(backend);
|
||||
if (!result) {
|
||||
return getShared("default");
|
||||
}
|
||||
|
||||
result->run();
|
||||
sharedBackends.emplace(backend, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
void removeShared(Backend *backend) {
|
||||
for (auto it = sharedBackends.begin(); it != sharedBackends.end(); it++) {
|
||||
if (it->second.get() == backend) {
|
||||
sharedBackends.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Free up memory.
|
||||
if (sharedBackends.size() == 0) {
|
||||
sharedBackends.rehash(0);
|
||||
}
|
||||
}
|
||||
|
||||
void Backend::run() {
|
||||
#ifndef __wasm32__
|
||||
mThread = std::thread([this] () {
|
||||
try {
|
||||
start();
|
||||
} catch (std::exception &err) {
|
||||
handleError(err);
|
||||
}
|
||||
});
|
||||
|
||||
if (mThread.joinable()) {
|
||||
mStartedSignal.wait();
|
||||
}
|
||||
#else
|
||||
try {
|
||||
start();
|
||||
} catch (std::exception &err) {
|
||||
handleError(err);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void Backend::notifyStarted() {
|
||||
mStartedSignal.notify();
|
||||
}
|
||||
|
||||
void Backend::start() {
|
||||
notifyStarted();
|
||||
}
|
||||
|
||||
Backend::~Backend() {
|
||||
#ifndef __wasm32__
|
||||
// Wait for thread to stop
|
||||
if (mThread.joinable()) {
|
||||
// If the backend is being destroyed from the thread itself, detach, otherwise join.
|
||||
if (mThread.get_id() == std::this_thread::get_id()) {
|
||||
mThread.detach();
|
||||
} else {
|
||||
mThread.join();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void Backend::watch(WatcherRef watcher) {
|
||||
std::unique_lock<std::mutex> lock(mMutex);
|
||||
auto res = mSubscriptions.find(watcher);
|
||||
if (res == mSubscriptions.end()) {
|
||||
try {
|
||||
this->subscribe(watcher);
|
||||
mSubscriptions.insert(watcher);
|
||||
} catch (std::exception &err) {
|
||||
unref();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Backend::unwatch(WatcherRef watcher) {
|
||||
std::unique_lock<std::mutex> lock(mMutex);
|
||||
size_t deleted = mSubscriptions.erase(watcher);
|
||||
if (deleted > 0) {
|
||||
this->unsubscribe(watcher);
|
||||
unref();
|
||||
}
|
||||
}
|
||||
|
||||
void Backend::unref() {
|
||||
if (mSubscriptions.size() == 0) {
|
||||
removeShared(this);
|
||||
}
|
||||
}
|
||||
|
||||
void Backend::handleWatcherError(WatcherError &err) {
|
||||
unwatch(err.mWatcher);
|
||||
err.mWatcher->notifyError(err);
|
||||
}
|
||||
|
||||
void Backend::handleError(std::exception &err) {
|
||||
std::unique_lock<std::mutex> lock(mMutex);
|
||||
for (auto it = mSubscriptions.begin(); it != mSubscriptions.end(); it++) {
|
||||
(*it)->notifyError(err);
|
||||
}
|
||||
|
||||
removeShared(this);
|
||||
}
|
||||
37
node_modules/@parcel/watcher/src/Backend.hh
generated
vendored
Normal file
37
node_modules/@parcel/watcher/src/Backend.hh
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
#ifndef BACKEND_H
|
||||
#define BACKEND_H
|
||||
|
||||
#include "Event.hh"
|
||||
#include "Watcher.hh"
|
||||
#include "Signal.hh"
|
||||
#include <thread>
|
||||
|
||||
class Backend {
|
||||
public:
|
||||
virtual ~Backend();
|
||||
void run();
|
||||
void notifyStarted();
|
||||
|
||||
virtual void start();
|
||||
virtual void writeSnapshot(WatcherRef watcher, std::string *snapshotPath) = 0;
|
||||
virtual void getEventsSince(WatcherRef watcher, std::string *snapshotPath) = 0;
|
||||
virtual void subscribe(WatcherRef watcher) = 0;
|
||||
virtual void unsubscribe(WatcherRef watcher) = 0;
|
||||
|
||||
static std::shared_ptr<Backend> getShared(std::string backend);
|
||||
|
||||
void watch(WatcherRef watcher);
|
||||
void unwatch(WatcherRef watcher);
|
||||
void unref();
|
||||
void handleWatcherError(WatcherError &err);
|
||||
|
||||
std::mutex mMutex;
|
||||
std::thread mThread;
|
||||
private:
|
||||
std::unordered_set<WatcherRef> mSubscriptions;
|
||||
Signal mStartedSignal;
|
||||
|
||||
void handleError(std::exception &err);
|
||||
};
|
||||
|
||||
#endif
|
||||
113
node_modules/@parcel/watcher/src/Debounce.cc
generated
vendored
Normal file
113
node_modules/@parcel/watcher/src/Debounce.cc
generated
vendored
Normal file
@@ -0,0 +1,113 @@
|
||||
#include "Debounce.hh"
|
||||
|
||||
#ifdef __wasm32__
|
||||
extern "C" void on_timeout(void *ctx) {
|
||||
Debounce *debounce = (Debounce *)ctx;
|
||||
debounce->notify();
|
||||
}
|
||||
#endif
|
||||
|
||||
std::shared_ptr<Debounce> Debounce::getShared() {
|
||||
static std::weak_ptr<Debounce> sharedInstance;
|
||||
std::shared_ptr<Debounce> shared = sharedInstance.lock();
|
||||
if (!shared) {
|
||||
shared = std::make_shared<Debounce>();
|
||||
sharedInstance = shared;
|
||||
}
|
||||
|
||||
return shared;
|
||||
}
|
||||
|
||||
Debounce::Debounce() {
|
||||
mRunning = true;
|
||||
#ifndef __wasm32__
|
||||
mThread = std::thread([this] () {
|
||||
loop();
|
||||
});
|
||||
#endif
|
||||
}
|
||||
|
||||
Debounce::~Debounce() {
|
||||
mRunning = false;
|
||||
#ifndef __wasm32__
|
||||
mWaitSignal.notify();
|
||||
mThread.join();
|
||||
#endif
|
||||
}
|
||||
|
||||
void Debounce::add(void *key, std::function<void()> cb) {
|
||||
std::unique_lock<std::mutex> lock(mMutex);
|
||||
mCallbacks.emplace(key, cb);
|
||||
}
|
||||
|
||||
void Debounce::remove(void *key) {
|
||||
std::unique_lock<std::mutex> lock(mMutex);
|
||||
mCallbacks.erase(key);
|
||||
}
|
||||
|
||||
void Debounce::trigger() {
|
||||
std::unique_lock<std::mutex> lock(mMutex);
|
||||
#ifdef __wasm32__
|
||||
notifyIfReady();
|
||||
#else
|
||||
mWaitSignal.notify();
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef __wasm32__
|
||||
void Debounce::loop() {
|
||||
while (mRunning) {
|
||||
mWaitSignal.wait();
|
||||
if (!mRunning) {
|
||||
break;
|
||||
}
|
||||
|
||||
notifyIfReady();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void Debounce::notifyIfReady() {
|
||||
if (!mRunning) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If we haven't seen an event in more than the maximum wait time, notify callbacks immediately
|
||||
// to ensure that we don't wait forever. Otherwise, wait for the minimum wait time and batch
|
||||
// subsequent fast changes. This also means the first file change in a batch is notified immediately,
|
||||
// separately from the rest of the batch. This seems like an acceptable tradeoff if the common case
|
||||
// is that only a single file was updated at a time.
|
||||
auto time = std::chrono::steady_clock::now();
|
||||
if ((time - mLastTime) > std::chrono::milliseconds(MAX_WAIT_TIME)) {
|
||||
mLastTime = time;
|
||||
notify();
|
||||
} else {
|
||||
wait();
|
||||
}
|
||||
}
|
||||
|
||||
void Debounce::wait() {
|
||||
#ifdef __wasm32__
|
||||
clear_timeout(mTimeout);
|
||||
mTimeout = set_timeout(MIN_WAIT_TIME, this);
|
||||
#else
|
||||
auto status = mWaitSignal.waitFor(std::chrono::milliseconds(MIN_WAIT_TIME));
|
||||
if (mRunning && (status == std::cv_status::timeout)) {
|
||||
notify();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void Debounce::notify() {
|
||||
std::unique_lock<std::mutex> lock(mMutex);
|
||||
|
||||
mLastTime = std::chrono::steady_clock::now();
|
||||
for (auto it = mCallbacks.begin(); it != mCallbacks.end(); it++) {
|
||||
auto cb = it->second;
|
||||
cb();
|
||||
}
|
||||
|
||||
#ifndef __wasm32__
|
||||
mWaitSignal.reset();
|
||||
#endif
|
||||
}
|
||||
49
node_modules/@parcel/watcher/src/Debounce.hh
generated
vendored
Normal file
49
node_modules/@parcel/watcher/src/Debounce.hh
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
#ifndef DEBOUNCE_H
|
||||
#define DEBOUNCE_H
|
||||
|
||||
#include <thread>
|
||||
#include <unordered_map>
|
||||
#include <functional>
|
||||
#include "Signal.hh"
|
||||
|
||||
#define MIN_WAIT_TIME 50
|
||||
#define MAX_WAIT_TIME 500
|
||||
|
||||
#ifdef __wasm32__
|
||||
extern "C" {
|
||||
int set_timeout(int ms, void *ctx);
|
||||
void clear_timeout(int timeout);
|
||||
void on_timeout(void *ctx);
|
||||
};
|
||||
#endif
|
||||
|
||||
class Debounce {
|
||||
public:
|
||||
static std::shared_ptr<Debounce> getShared();
|
||||
|
||||
Debounce();
|
||||
~Debounce();
|
||||
|
||||
void add(void *key, std::function<void()> cb);
|
||||
void remove(void *key);
|
||||
void trigger();
|
||||
void notify();
|
||||
|
||||
private:
|
||||
bool mRunning;
|
||||
std::mutex mMutex;
|
||||
#ifdef __wasm32__
|
||||
int mTimeout;
|
||||
#else
|
||||
Signal mWaitSignal;
|
||||
std::thread mThread;
|
||||
#endif
|
||||
std::unordered_map<void *, std::function<void()>> mCallbacks;
|
||||
std::chrono::time_point<std::chrono::steady_clock> mLastTime;
|
||||
|
||||
void loop();
|
||||
void notifyIfReady();
|
||||
void wait();
|
||||
};
|
||||
|
||||
#endif
|
||||
152
node_modules/@parcel/watcher/src/DirTree.cc
generated
vendored
Normal file
152
node_modules/@parcel/watcher/src/DirTree.cc
generated
vendored
Normal file
@@ -0,0 +1,152 @@
|
||||
#include "DirTree.hh"
|
||||
#include <inttypes.h>
|
||||
|
||||
static std::mutex mDirCacheMutex;
|
||||
static std::unordered_map<std::string, std::weak_ptr<DirTree>> dirTreeCache;
|
||||
|
||||
struct DirTreeDeleter {
|
||||
void operator()(DirTree *tree) {
|
||||
std::lock_guard<std::mutex> lock(mDirCacheMutex);
|
||||
dirTreeCache.erase(tree->root);
|
||||
delete tree;
|
||||
|
||||
// Free up memory.
|
||||
if (dirTreeCache.size() == 0) {
|
||||
dirTreeCache.rehash(0);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
std::shared_ptr<DirTree> DirTree::getCached(std::string root) {
|
||||
std::lock_guard<std::mutex> lock(mDirCacheMutex);
|
||||
|
||||
auto found = dirTreeCache.find(root);
|
||||
std::shared_ptr<DirTree> tree;
|
||||
|
||||
// Use cached tree, or create an empty one.
|
||||
if (found != dirTreeCache.end()) {
|
||||
tree = found->second.lock();
|
||||
} else {
|
||||
tree = std::shared_ptr<DirTree>(new DirTree(root), DirTreeDeleter());
|
||||
dirTreeCache.emplace(root, tree);
|
||||
}
|
||||
|
||||
return tree;
|
||||
}
|
||||
|
||||
DirTree::DirTree(std::string root, FILE *f) : root(root), isComplete(true) {
|
||||
size_t size;
|
||||
if (fscanf(f, "%zu", &size)) {
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
DirEntry entry(f);
|
||||
entries.emplace(entry.path, entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Internal find method that has no lock
|
||||
DirEntry *DirTree::_find(std::string path) {
|
||||
auto found = entries.find(path);
|
||||
if (found == entries.end()) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return &found->second;
|
||||
}
|
||||
|
||||
DirEntry *DirTree::add(std::string path, uint64_t mtime, bool isDir) {
|
||||
std::lock_guard<std::mutex> lock(mMutex);
|
||||
|
||||
DirEntry entry(path, mtime, isDir);
|
||||
auto it = entries.emplace(entry.path, entry);
|
||||
return &it.first->second;
|
||||
}
|
||||
|
||||
DirEntry *DirTree::find(std::string path) {
|
||||
std::lock_guard<std::mutex> lock(mMutex);
|
||||
return _find(path);
|
||||
}
|
||||
|
||||
DirEntry *DirTree::update(std::string path, uint64_t mtime) {
|
||||
std::lock_guard<std::mutex> lock(mMutex);
|
||||
|
||||
DirEntry *found = _find(path);
|
||||
if (found) {
|
||||
found->mtime = mtime;
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
void DirTree::remove(std::string path) {
|
||||
std::lock_guard<std::mutex> lock(mMutex);
|
||||
|
||||
DirEntry *found = _find(path);
|
||||
|
||||
// Remove all sub-entries if this is a directory
|
||||
if (found && found->isDir) {
|
||||
std::string pathStart = path + DIR_SEP;
|
||||
for (auto it = entries.begin(); it != entries.end();) {
|
||||
if (it->first.rfind(pathStart, 0) == 0) {
|
||||
it = entries.erase(it);
|
||||
} else {
|
||||
it++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
entries.erase(path);
|
||||
}
|
||||
|
||||
void DirTree::write(FILE *f) {
|
||||
std::lock_guard<std::mutex> lock(mMutex);
|
||||
|
||||
fprintf(f, "%zu\n", entries.size());
|
||||
for (auto it = entries.begin(); it != entries.end(); it++) {
|
||||
it->second.write(f);
|
||||
}
|
||||
}
|
||||
|
||||
void DirTree::getChanges(DirTree *snapshot, EventList &events) {
|
||||
std::lock_guard<std::mutex> lock(mMutex);
|
||||
std::lock_guard<std::mutex> snapshotLock(snapshot->mMutex);
|
||||
|
||||
for (auto it = entries.begin(); it != entries.end(); it++) {
|
||||
auto found = snapshot->entries.find(it->first);
|
||||
if (found == snapshot->entries.end()) {
|
||||
events.create(it->second.path);
|
||||
} else if (found->second.mtime != it->second.mtime && !found->second.isDir && !it->second.isDir) {
|
||||
events.update(it->second.path);
|
||||
}
|
||||
}
|
||||
|
||||
for (auto it = snapshot->entries.begin(); it != snapshot->entries.end(); it++) {
|
||||
size_t count = entries.count(it->first);
|
||||
if (count == 0) {
|
||||
events.remove(it->second.path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DirEntry::DirEntry(std::string p, uint64_t t, bool d) {
|
||||
path = p;
|
||||
mtime = t;
|
||||
isDir = d;
|
||||
state = NULL;
|
||||
}
|
||||
|
||||
DirEntry::DirEntry(FILE *f) {
|
||||
size_t size;
|
||||
if (fscanf(f, "%zu", &size)) {
|
||||
path.resize(size);
|
||||
if (fread(&path[0], sizeof(char), size, f)) {
|
||||
int d = 0;
|
||||
fscanf(f, "%" PRIu64 " %d\n", &mtime, &d);
|
||||
isDir = d == 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DirEntry::write(FILE *f) const {
|
||||
fprintf(f, "%zu%s%" PRIu64 " %d\n", path.size(), path.c_str(), mtime, isDir);
|
||||
}
|
||||
50
node_modules/@parcel/watcher/src/DirTree.hh
generated
vendored
Normal file
50
node_modules/@parcel/watcher/src/DirTree.hh
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
#ifndef DIR_TREE_H
|
||||
#define DIR_TREE_H
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <memory>
|
||||
#include "Event.hh"
|
||||
|
||||
#ifdef _WIN32
|
||||
#define DIR_SEP "\\"
|
||||
#else
|
||||
#define DIR_SEP "/"
|
||||
#endif
|
||||
|
||||
struct DirEntry {
|
||||
std::string path;
|
||||
uint64_t mtime;
|
||||
bool isDir;
|
||||
mutable void *state;
|
||||
|
||||
DirEntry(std::string p, uint64_t t, bool d);
|
||||
DirEntry(FILE *f);
|
||||
void write(FILE *f) const;
|
||||
bool operator==(const DirEntry &other) const {
|
||||
return path == other.path;
|
||||
}
|
||||
};
|
||||
|
||||
class DirTree {
|
||||
public:
|
||||
static std::shared_ptr<DirTree> getCached(std::string root);
|
||||
DirTree(std::string root) : root(root), isComplete(false) {}
|
||||
DirTree(std::string root, FILE *f);
|
||||
DirEntry *add(std::string path, uint64_t mtime, bool isDir);
|
||||
DirEntry *find(std::string path);
|
||||
DirEntry *update(std::string path, uint64_t mtime);
|
||||
void remove(std::string path);
|
||||
void write(FILE *f);
|
||||
void getChanges(DirTree *snapshot, EventList &events);
|
||||
|
||||
std::mutex mMutex;
|
||||
std::string root;
|
||||
bool isComplete;
|
||||
std::unordered_map<std::string, DirEntry> entries;
|
||||
|
||||
private:
|
||||
DirEntry *_find(std::string path);
|
||||
};
|
||||
|
||||
#endif
|
||||
109
node_modules/@parcel/watcher/src/Event.hh
generated
vendored
Normal file
109
node_modules/@parcel/watcher/src/Event.hh
generated
vendored
Normal file
@@ -0,0 +1,109 @@
|
||||
#ifndef EVENT_H
|
||||
#define EVENT_H
|
||||
|
||||
#include <string>
|
||||
#include <node_api.h>
|
||||
#include "wasm/include.h"
|
||||
#include <napi.h>
|
||||
#include <mutex>
|
||||
#include <map>
|
||||
#include <optional>
|
||||
|
||||
using namespace Napi;
|
||||
|
||||
struct Event {
|
||||
std::string path;
|
||||
bool isCreated;
|
||||
bool isDeleted;
|
||||
Event(std::string path) : path(path), isCreated(false), isDeleted(false) {}
|
||||
|
||||
Value toJS(const Env& env) {
|
||||
EscapableHandleScope scope(env);
|
||||
Object res = Object::New(env);
|
||||
std::string type = isCreated ? "create" : isDeleted ? "delete" : "update";
|
||||
res.Set(String::New(env, "path"), String::New(env, path.c_str()));
|
||||
res.Set(String::New(env, "type"), String::New(env, type.c_str()));
|
||||
return scope.Escape(res);
|
||||
}
|
||||
};
|
||||
|
||||
class EventList {
|
||||
public:
|
||||
void create(std::string path) {
|
||||
std::lock_guard<std::mutex> l(mMutex);
|
||||
Event *event = internalUpdate(path);
|
||||
if (event->isDeleted) {
|
||||
// Assume update event when rapidly removed and created
|
||||
// https://github.com/parcel-bundler/watcher/issues/72
|
||||
event->isDeleted = false;
|
||||
} else {
|
||||
event->isCreated = true;
|
||||
}
|
||||
}
|
||||
|
||||
Event *update(std::string path) {
|
||||
std::lock_guard<std::mutex> l(mMutex);
|
||||
return internalUpdate(path);
|
||||
}
|
||||
|
||||
void remove(std::string path) {
|
||||
std::lock_guard<std::mutex> l(mMutex);
|
||||
Event *event = internalUpdate(path);
|
||||
event->isDeleted = true;
|
||||
}
|
||||
|
||||
size_t size() {
|
||||
std::lock_guard<std::mutex> l(mMutex);
|
||||
return mEvents.size();
|
||||
}
|
||||
|
||||
std::vector<Event> getEvents() {
|
||||
std::lock_guard<std::mutex> l(mMutex);
|
||||
std::vector<Event> eventsCloneVector;
|
||||
for(auto it = mEvents.begin(); it != mEvents.end(); ++it) {
|
||||
if (!(it->second.isCreated && it->second.isDeleted)) {
|
||||
eventsCloneVector.push_back(it->second);
|
||||
}
|
||||
}
|
||||
return eventsCloneVector;
|
||||
}
|
||||
|
||||
void clear() {
|
||||
std::lock_guard<std::mutex> l(mMutex);
|
||||
mEvents.clear();
|
||||
mError.reset();
|
||||
}
|
||||
|
||||
void error(std::string err) {
|
||||
std::lock_guard<std::mutex> l(mMutex);
|
||||
if (!mError.has_value()) {
|
||||
mError.emplace(err);
|
||||
}
|
||||
}
|
||||
|
||||
bool hasError() {
|
||||
std::lock_guard<std::mutex> l(mMutex);
|
||||
return mError.has_value();
|
||||
}
|
||||
|
||||
std::string getError() {
|
||||
std::lock_guard<std::mutex> l(mMutex);
|
||||
return mError.value_or("");
|
||||
}
|
||||
|
||||
private:
|
||||
mutable std::mutex mMutex;
|
||||
std::map<std::string, Event> mEvents;
|
||||
std::optional<std::string> mError;
|
||||
Event *internalUpdate(std::string path) {
|
||||
auto found = mEvents.find(path);
|
||||
if (found == mEvents.end()) {
|
||||
auto it = mEvents.emplace(path, Event(path));
|
||||
return &it.first->second;
|
||||
}
|
||||
|
||||
return &found->second;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
22
node_modules/@parcel/watcher/src/Glob.cc
generated
vendored
Normal file
22
node_modules/@parcel/watcher/src/Glob.cc
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
#include "Glob.hh"
|
||||
|
||||
#ifdef __wasm32__
|
||||
extern "C" bool wasm_regex_match(const char *s, const char *regex);
|
||||
#endif
|
||||
|
||||
Glob::Glob(std::string raw) {
|
||||
mRaw = raw;
|
||||
mHash = std::hash<std::string>()(raw);
|
||||
#ifndef __wasm32__
|
||||
mRegex = std::regex(raw);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Glob::isIgnored(std::string relative_path) const {
|
||||
// Use native JS regex engine for wasm to reduce binary size.
|
||||
#ifdef __wasm32__
|
||||
return wasm_regex_match(relative_path.c_str(), mRaw.c_str());
|
||||
#else
|
||||
return std::regex_match(relative_path, mRegex);
|
||||
#endif
|
||||
}
|
||||
34
node_modules/@parcel/watcher/src/Glob.hh
generated
vendored
Normal file
34
node_modules/@parcel/watcher/src/Glob.hh
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef GLOB_H
|
||||
#define GLOB_H
|
||||
|
||||
#include <unordered_set>
|
||||
#include <regex>
|
||||
|
||||
struct Glob {
|
||||
std::size_t mHash;
|
||||
std::string mRaw;
|
||||
#ifndef __wasm32__
|
||||
std::regex mRegex;
|
||||
#endif
|
||||
|
||||
Glob(std::string raw);
|
||||
|
||||
bool operator==(const Glob &other) const {
|
||||
return mHash == other.mHash;
|
||||
}
|
||||
|
||||
bool isIgnored(std::string relative_path) const;
|
||||
};
|
||||
|
||||
namespace std
|
||||
{
|
||||
template <>
|
||||
struct hash<Glob>
|
||||
{
|
||||
size_t operator()(const Glob& g) const {
|
||||
return g.mHash;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
101
node_modules/@parcel/watcher/src/PromiseRunner.hh
generated
vendored
Normal file
101
node_modules/@parcel/watcher/src/PromiseRunner.hh
generated
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
#ifndef PROMISE_RUNNER_H
|
||||
#define PROMISE_RUNNER_H
|
||||
|
||||
#include <node_api.h>
|
||||
#include "wasm/include.h"
|
||||
#include <napi.h>
|
||||
|
||||
using namespace Napi;
|
||||
|
||||
class PromiseRunner {
|
||||
public:
|
||||
const Env env;
|
||||
Promise::Deferred deferred;
|
||||
|
||||
PromiseRunner(Env env) : env(env), deferred(Promise::Deferred::New(env)) {
|
||||
napi_status status = napi_create_async_work(env, nullptr, env.Undefined(),
|
||||
onExecute, onWorkComplete, this, &work);
|
||||
if (status != napi_ok) {
|
||||
work = nullptr;
|
||||
const napi_extended_error_info *error_info = 0;
|
||||
napi_get_last_error_info(env, &error_info);
|
||||
if (error_info->error_message) {
|
||||
Error::New(env, error_info->error_message).ThrowAsJavaScriptException();
|
||||
} else {
|
||||
Error::New(env).ThrowAsJavaScriptException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual ~PromiseRunner() {}
|
||||
|
||||
Value queue() {
|
||||
if (work) {
|
||||
napi_status status = napi_queue_async_work(env, work);
|
||||
if (status != napi_ok) {
|
||||
onError(Error::New(env));
|
||||
}
|
||||
}
|
||||
|
||||
return deferred.Promise();
|
||||
}
|
||||
|
||||
private:
|
||||
napi_async_work work;
|
||||
std::string error;
|
||||
|
||||
static void onExecute(napi_env env, void *this_pointer) {
|
||||
PromiseRunner* self = (PromiseRunner*) this_pointer;
|
||||
try {
|
||||
self->execute();
|
||||
} catch (std::exception &err) {
|
||||
self->error = err.what();
|
||||
}
|
||||
}
|
||||
|
||||
static void onWorkComplete(napi_env env, napi_status status, void *this_pointer) {
|
||||
PromiseRunner* self = (PromiseRunner*) this_pointer;
|
||||
if (status != napi_cancelled) {
|
||||
HandleScope scope(self->env);
|
||||
if (status == napi_ok) {
|
||||
status = napi_delete_async_work(self->env, self->work);
|
||||
if (status == napi_ok) {
|
||||
if (self->error.size() == 0) {
|
||||
self->onOK();
|
||||
} else {
|
||||
self->onError(Error::New(self->env, self->error));
|
||||
}
|
||||
delete self;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// fallthrough for error handling
|
||||
const napi_extended_error_info *error_info = 0;
|
||||
napi_get_last_error_info(env, &error_info);
|
||||
if (error_info->error_message){
|
||||
self->onError(Error::New(env, error_info->error_message));
|
||||
} else {
|
||||
self->onError(Error::New(env));
|
||||
}
|
||||
delete self;
|
||||
}
|
||||
|
||||
virtual void execute() {}
|
||||
virtual Value getResult() {
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
void onOK() {
|
||||
HandleScope scope(env);
|
||||
Value result = getResult();
|
||||
deferred.Resolve(result);
|
||||
}
|
||||
|
||||
void onError(const Error &e) {
|
||||
deferred.Reject(e.Value());
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
46
node_modules/@parcel/watcher/src/Signal.hh
generated
vendored
Normal file
46
node_modules/@parcel/watcher/src/Signal.hh
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
#ifndef SIGNAL_H
|
||||
#define SIGNAL_H
|
||||
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
|
||||
class Signal {
|
||||
public:
|
||||
Signal() : mFlag(false), mWaiting(false) {}
|
||||
void wait() {
|
||||
std::unique_lock<std::mutex> lock(mMutex);
|
||||
while (!mFlag) {
|
||||
mWaiting = true;
|
||||
mCond.wait(lock);
|
||||
}
|
||||
}
|
||||
|
||||
std::cv_status waitFor(std::chrono::milliseconds ms) {
|
||||
std::unique_lock<std::mutex> lock(mMutex);
|
||||
return mCond.wait_for(lock, ms);
|
||||
}
|
||||
|
||||
void notify() {
|
||||
std::unique_lock<std::mutex> lock(mMutex);
|
||||
mFlag = true;
|
||||
mCond.notify_all();
|
||||
}
|
||||
|
||||
void reset() {
|
||||
std::unique_lock<std::mutex> lock(mMutex);
|
||||
mFlag = false;
|
||||
mWaiting = false;
|
||||
}
|
||||
|
||||
bool isWaiting() {
|
||||
return mWaiting;
|
||||
}
|
||||
|
||||
private:
|
||||
bool mFlag;
|
||||
bool mWaiting;
|
||||
std::mutex mMutex;
|
||||
std::condition_variable mCond;
|
||||
};
|
||||
|
||||
#endif
|
||||
237
node_modules/@parcel/watcher/src/Watcher.cc
generated
vendored
Normal file
237
node_modules/@parcel/watcher/src/Watcher.cc
generated
vendored
Normal file
@@ -0,0 +1,237 @@
|
||||
#include "Watcher.hh"
|
||||
#include <unordered_set>
|
||||
|
||||
using namespace Napi;
|
||||
|
||||
struct WatcherHash {
|
||||
std::size_t operator() (WatcherRef const &k) const {
|
||||
return std::hash<std::string>()(k->mDir);
|
||||
}
|
||||
};
|
||||
|
||||
struct WatcherCompare {
|
||||
size_t operator() (WatcherRef const &a, WatcherRef const &b) const {
|
||||
return *a == *b;
|
||||
}
|
||||
};
|
||||
|
||||
static std::unordered_set<WatcherRef , WatcherHash, WatcherCompare> sharedWatchers;
|
||||
|
||||
WatcherRef Watcher::getShared(std::string dir, std::unordered_set<std::string> ignorePaths, std::unordered_set<Glob> ignoreGlobs) {
|
||||
WatcherRef watcher = std::make_shared<Watcher>(dir, ignorePaths, ignoreGlobs);
|
||||
auto found = sharedWatchers.find(watcher);
|
||||
if (found != sharedWatchers.end()) {
|
||||
return *found;
|
||||
}
|
||||
|
||||
sharedWatchers.insert(watcher);
|
||||
return watcher;
|
||||
}
|
||||
|
||||
void removeShared(Watcher *watcher) {
|
||||
for (auto it = sharedWatchers.begin(); it != sharedWatchers.end(); it++) {
|
||||
if (it->get() == watcher) {
|
||||
sharedWatchers.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Free up memory.
|
||||
if (sharedWatchers.size() == 0) {
|
||||
sharedWatchers.rehash(0);
|
||||
}
|
||||
}
|
||||
|
||||
Watcher::Watcher(std::string dir, std::unordered_set<std::string> ignorePaths, std::unordered_set<Glob> ignoreGlobs)
|
||||
: mDir(dir),
|
||||
mIgnorePaths(ignorePaths),
|
||||
mIgnoreGlobs(ignoreGlobs) {
|
||||
mDebounce = Debounce::getShared();
|
||||
mDebounce->add(this, [this] () {
|
||||
triggerCallbacks();
|
||||
});
|
||||
}
|
||||
|
||||
Watcher::~Watcher() {
|
||||
mDebounce->remove(this);
|
||||
}
|
||||
|
||||
void Watcher::wait() {
|
||||
std::unique_lock<std::mutex> lk(mMutex);
|
||||
mCond.wait(lk);
|
||||
}
|
||||
|
||||
void Watcher::notify() {
|
||||
std::unique_lock<std::mutex> lk(mMutex);
|
||||
mCond.notify_all();
|
||||
|
||||
if (mCallbacks.size() > 0 && mEvents.size() > 0) {
|
||||
// We must release our lock before calling into the debouncer
|
||||
// to avoid a deadlock: the debouncer thread itself will require
|
||||
// our lock from its thread when calling into `triggerCallbacks`
|
||||
// while holding its own debouncer lock.
|
||||
lk.unlock();
|
||||
mDebounce->trigger();
|
||||
}
|
||||
}
|
||||
|
||||
struct CallbackData {
|
||||
std::string error;
|
||||
std::vector<Event> events;
|
||||
CallbackData(std::string error, std::vector<Event> events) : error(error), events(events) {}
|
||||
};
|
||||
|
||||
Value callbackEventsToJS(const Env &env, std::vector<Event> &events) {
|
||||
EscapableHandleScope scope(env);
|
||||
Array arr = Array::New(env, events.size());
|
||||
size_t currentEventIndex = 0;
|
||||
for (auto eventIterator = events.begin(); eventIterator != events.end(); eventIterator++) {
|
||||
arr.Set(currentEventIndex++, eventIterator->toJS(env));
|
||||
}
|
||||
return scope.Escape(arr);
|
||||
}
|
||||
|
||||
void callJSFunction(Napi::Env env, Function jsCallback, CallbackData *data) {
|
||||
HandleScope scope(env);
|
||||
auto err = data->error.size() > 0 ? Error::New(env, data->error).Value() : env.Null();
|
||||
auto events = callbackEventsToJS(env, data->events);
|
||||
jsCallback.Call({err, events});
|
||||
delete data;
|
||||
|
||||
// Throw errors from the callback as fatal exceptions
|
||||
// If we don't handle these node segfaults...
|
||||
if (env.IsExceptionPending()) {
|
||||
Napi::Error err = env.GetAndClearPendingException();
|
||||
napi_fatal_exception(env, err.Value());
|
||||
}
|
||||
}
|
||||
|
||||
void Watcher::notifyError(std::exception &err) {
|
||||
std::unique_lock<std::mutex> lk(mMutex);
|
||||
for (auto it = mCallbacks.begin(); it != mCallbacks.end(); it++) {
|
||||
CallbackData *data = new CallbackData(err.what(), {});
|
||||
it->tsfn.BlockingCall(data, callJSFunction);
|
||||
}
|
||||
|
||||
clearCallbacks();
|
||||
}
|
||||
|
||||
// This function is called from the debounce thread.
|
||||
void Watcher::triggerCallbacks() {
|
||||
std::unique_lock<std::mutex> lk(mMutex);
|
||||
if (mCallbacks.size() > 0 && (mEvents.size() > 0 || mEvents.hasError())) {
|
||||
auto error = mEvents.getError();
|
||||
auto events = mEvents.getEvents();
|
||||
mEvents.clear();
|
||||
|
||||
for (auto it = mCallbacks.begin(); it != mCallbacks.end(); it++) {
|
||||
it->tsfn.BlockingCall(new CallbackData(error, events), callJSFunction);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This should be called from the JavaScript thread.
|
||||
bool Watcher::watch(Function callback) {
|
||||
std::unique_lock<std::mutex> lk(mMutex);
|
||||
|
||||
auto it = findCallback(callback);
|
||||
if (it != mCallbacks.end()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto tsfn = ThreadSafeFunction::New(
|
||||
callback.Env(),
|
||||
callback,
|
||||
"Watcher callback",
|
||||
0, // Unlimited queue
|
||||
1 // Initial thread count
|
||||
);
|
||||
|
||||
mCallbacks.push_back(Callback {
|
||||
tsfn,
|
||||
Napi::Persistent(callback),
|
||||
std::this_thread::get_id()
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// This should be called from the JavaScript thread.
|
||||
std::vector<Callback>::iterator Watcher::findCallback(Function callback) {
|
||||
for (auto it = mCallbacks.begin(); it != mCallbacks.end(); it++) {
|
||||
// Only consider callbacks created by the same thread, or V8 will panic.
|
||||
if (it->threadId == std::this_thread::get_id() && it->ref.Value() == callback) {
|
||||
return it;
|
||||
}
|
||||
}
|
||||
|
||||
return mCallbacks.end();
|
||||
}
|
||||
|
||||
// This should be called from the JavaScript thread.
|
||||
bool Watcher::unwatch(Function callback) {
|
||||
std::unique_lock<std::mutex> lk(mMutex);
|
||||
|
||||
bool removed = false;
|
||||
auto it = findCallback(callback);
|
||||
if (it != mCallbacks.end()) {
|
||||
it->tsfn.Release();
|
||||
it->ref.Unref();
|
||||
mCallbacks.erase(it);
|
||||
removed = true;
|
||||
}
|
||||
|
||||
if (removed && mCallbacks.size() == 0) {
|
||||
unref();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void Watcher::unref() {
|
||||
if (mCallbacks.size() == 0) {
|
||||
removeShared(this);
|
||||
}
|
||||
}
|
||||
|
||||
void Watcher::destroy() {
|
||||
std::unique_lock<std::mutex> lk(mMutex);
|
||||
clearCallbacks();
|
||||
}
|
||||
|
||||
// Private because it doesn't lock.
|
||||
void Watcher::clearCallbacks() {
|
||||
for (auto it = mCallbacks.begin(); it != mCallbacks.end(); it++) {
|
||||
it->tsfn.Release();
|
||||
it->ref.Unref();
|
||||
}
|
||||
|
||||
mCallbacks.clear();
|
||||
unref();
|
||||
}
|
||||
|
||||
bool Watcher::isIgnored(std::string path) {
|
||||
for (auto it = mIgnorePaths.begin(); it != mIgnorePaths.end(); it++) {
|
||||
auto dir = *it + DIR_SEP;
|
||||
if (*it == path || path.compare(0, dir.size(), dir) == 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
auto basePath = mDir + DIR_SEP;
|
||||
|
||||
if (path.rfind(basePath, 0) != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto relativePath = path.substr(basePath.size());
|
||||
|
||||
for (auto it = mIgnoreGlobs.begin(); it != mIgnoreGlobs.end(); it++) {
|
||||
if (it->isIgnored(relativePath)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
73
node_modules/@parcel/watcher/src/Watcher.hh
generated
vendored
Normal file
73
node_modules/@parcel/watcher/src/Watcher.hh
generated
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
#ifndef WATCHER_H
|
||||
#define WATCHER_H
|
||||
|
||||
#include <condition_variable>
|
||||
#include <unordered_set>
|
||||
#include <set>
|
||||
#include <node_api.h>
|
||||
#include "Glob.hh"
|
||||
#include "Event.hh"
|
||||
#include "Debounce.hh"
|
||||
#include "DirTree.hh"
|
||||
#include "Signal.hh"
|
||||
|
||||
using namespace Napi;
|
||||
|
||||
struct Watcher;
|
||||
using WatcherRef = std::shared_ptr<Watcher>;
|
||||
|
||||
struct Callback {
|
||||
Napi::ThreadSafeFunction tsfn;
|
||||
Napi::FunctionReference ref;
|
||||
std::thread::id threadId;
|
||||
};
|
||||
|
||||
class WatcherState {
|
||||
public:
|
||||
virtual ~WatcherState() = default;
|
||||
};
|
||||
|
||||
struct Watcher {
|
||||
std::string mDir;
|
||||
std::unordered_set<std::string> mIgnorePaths;
|
||||
std::unordered_set<Glob> mIgnoreGlobs;
|
||||
EventList mEvents;
|
||||
std::shared_ptr<WatcherState> state;
|
||||
|
||||
Watcher(std::string dir, std::unordered_set<std::string> ignorePaths, std::unordered_set<Glob> ignoreGlobs);
|
||||
~Watcher();
|
||||
|
||||
bool operator==(const Watcher &other) const {
|
||||
return mDir == other.mDir && mIgnorePaths == other.mIgnorePaths && mIgnoreGlobs == other.mIgnoreGlobs;
|
||||
}
|
||||
|
||||
void wait();
|
||||
void notify();
|
||||
void notifyError(std::exception &err);
|
||||
bool watch(Function callback);
|
||||
bool unwatch(Function callback);
|
||||
void unref();
|
||||
bool isIgnored(std::string path);
|
||||
void destroy();
|
||||
|
||||
static WatcherRef getShared(std::string dir, std::unordered_set<std::string> ignorePaths, std::unordered_set<Glob> ignoreGlobs);
|
||||
|
||||
private:
|
||||
std::mutex mMutex;
|
||||
std::condition_variable mCond;
|
||||
std::vector<Callback> mCallbacks;
|
||||
std::shared_ptr<Debounce> mDebounce;
|
||||
|
||||
std::vector<Callback>::iterator findCallback(Function callback);
|
||||
void clearCallbacks();
|
||||
void triggerCallbacks();
|
||||
};
|
||||
|
||||
class WatcherError : public std::runtime_error {
|
||||
public:
|
||||
WatcherRef mWatcher;
|
||||
WatcherError(std::string msg, WatcherRef watcher) : std::runtime_error(msg), mWatcher(watcher) {}
|
||||
WatcherError(const char *msg, WatcherRef watcher) : std::runtime_error(msg), mWatcher(watcher) {}
|
||||
};
|
||||
|
||||
#endif
|
||||
268
node_modules/@parcel/watcher/src/binding.cc
generated
vendored
Normal file
268
node_modules/@parcel/watcher/src/binding.cc
generated
vendored
Normal file
@@ -0,0 +1,268 @@
|
||||
#include <unordered_set>
|
||||
#include <node_api.h>
|
||||
#include "wasm/include.h"
|
||||
#include <napi.h>
|
||||
#include "Glob.hh"
|
||||
#include "Event.hh"
|
||||
#include "Backend.hh"
|
||||
#include "Watcher.hh"
|
||||
#include "PromiseRunner.hh"
|
||||
|
||||
using namespace Napi;
|
||||
|
||||
std::unordered_set<std::string> getIgnorePaths(Env env, Value opts) {
|
||||
std::unordered_set<std::string> result;
|
||||
|
||||
if (opts.IsObject()) {
|
||||
Value v = opts.As<Object>().Get(String::New(env, "ignorePaths"));
|
||||
if (v.IsArray()) {
|
||||
Array items = v.As<Array>();
|
||||
for (size_t i = 0; i < items.Length(); i++) {
|
||||
Value item = items.Get(Number::New(env, i));
|
||||
if (item.IsString()) {
|
||||
result.insert(std::string(item.As<String>().Utf8Value().c_str()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::unordered_set<Glob> getIgnoreGlobs(Env env, Value opts) {
|
||||
std::unordered_set<Glob> result;
|
||||
|
||||
if (opts.IsObject()) {
|
||||
Value v = opts.As<Object>().Get(String::New(env, "ignoreGlobs"));
|
||||
if (v.IsArray()) {
|
||||
Array items = v.As<Array>();
|
||||
for (size_t i = 0; i < items.Length(); i++) {
|
||||
Value item = items.Get(Number::New(env, i));
|
||||
if (item.IsString()) {
|
||||
auto key = item.As<String>().Utf8Value();
|
||||
try {
|
||||
result.emplace(key);
|
||||
} catch (const std::regex_error& e) {
|
||||
Error::New(env, e.what()).ThrowAsJavaScriptException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::shared_ptr<Backend> getBackend(Env env, Value opts) {
|
||||
Value b = opts.As<Object>().Get(String::New(env, "backend"));
|
||||
std::string backendName;
|
||||
if (b.IsString()) {
|
||||
backendName = std::string(b.As<String>().Utf8Value().c_str());
|
||||
}
|
||||
|
||||
return Backend::getShared(backendName);
|
||||
}
|
||||
|
||||
class WriteSnapshotRunner : public PromiseRunner {
|
||||
public:
|
||||
WriteSnapshotRunner(Env env, Value dir, Value snap, Value opts)
|
||||
: PromiseRunner(env),
|
||||
snapshotPath(std::string(snap.As<String>().Utf8Value().c_str())) {
|
||||
watcher = Watcher::getShared(
|
||||
std::string(dir.As<String>().Utf8Value().c_str()),
|
||||
getIgnorePaths(env, opts),
|
||||
getIgnoreGlobs(env, opts)
|
||||
);
|
||||
|
||||
backend = getBackend(env, opts);
|
||||
}
|
||||
|
||||
~WriteSnapshotRunner() {
|
||||
watcher->unref();
|
||||
backend->unref();
|
||||
}
|
||||
private:
|
||||
std::shared_ptr<Backend> backend;
|
||||
WatcherRef watcher;
|
||||
std::string snapshotPath;
|
||||
|
||||
void execute() override {
|
||||
backend->writeSnapshot(watcher, &snapshotPath);
|
||||
}
|
||||
};
|
||||
|
||||
class GetEventsSinceRunner : public PromiseRunner {
|
||||
public:
|
||||
GetEventsSinceRunner(Env env, Value dir, Value snap, Value opts)
|
||||
: PromiseRunner(env),
|
||||
snapshotPath(std::string(snap.As<String>().Utf8Value().c_str())) {
|
||||
watcher = std::make_shared<Watcher>(
|
||||
std::string(dir.As<String>().Utf8Value().c_str()),
|
||||
getIgnorePaths(env, opts),
|
||||
getIgnoreGlobs(env, opts)
|
||||
);
|
||||
|
||||
backend = getBackend(env, opts);
|
||||
}
|
||||
|
||||
~GetEventsSinceRunner() {
|
||||
watcher->unref();
|
||||
backend->unref();
|
||||
}
|
||||
private:
|
||||
std::shared_ptr<Backend> backend;
|
||||
WatcherRef watcher;
|
||||
std::string snapshotPath;
|
||||
|
||||
void execute() override {
|
||||
backend->getEventsSince(watcher, &snapshotPath);
|
||||
if (watcher->mEvents.hasError()) {
|
||||
throw std::runtime_error(watcher->mEvents.getError());
|
||||
}
|
||||
}
|
||||
|
||||
Value getResult() override {
|
||||
std::vector<Event> events = watcher->mEvents.getEvents();
|
||||
Array eventsArray = Array::New(env, events.size());
|
||||
size_t i = 0;
|
||||
for (auto it = events.begin(); it != events.end(); it++) {
|
||||
eventsArray.Set(i++, it->toJS(env));
|
||||
}
|
||||
return eventsArray;
|
||||
}
|
||||
};
|
||||
|
||||
template<class Runner>
|
||||
Value queueSnapshotWork(const CallbackInfo& info) {
|
||||
Env env = info.Env();
|
||||
if (info.Length() < 1 || !info[0].IsString()) {
|
||||
TypeError::New(env, "Expected a string").ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
if (info.Length() < 2 || !info[1].IsString()) {
|
||||
TypeError::New(env, "Expected a string").ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
if (info.Length() >= 3 && !info[2].IsObject()) {
|
||||
TypeError::New(env, "Expected an object").ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
Runner *runner = new Runner(info.Env(), info[0], info[1], info[2]);
|
||||
return runner->queue();
|
||||
}
|
||||
|
||||
Value writeSnapshot(const CallbackInfo& info) {
|
||||
return queueSnapshotWork<WriteSnapshotRunner>(info);
|
||||
}
|
||||
|
||||
Value getEventsSince(const CallbackInfo& info) {
|
||||
return queueSnapshotWork<GetEventsSinceRunner>(info);
|
||||
}
|
||||
|
||||
class SubscribeRunner : public PromiseRunner {
|
||||
public:
|
||||
SubscribeRunner(Env env, Value dir, Value fn, Value opts) : PromiseRunner(env) {
|
||||
watcher = Watcher::getShared(
|
||||
std::string(dir.As<String>().Utf8Value().c_str()),
|
||||
getIgnorePaths(env, opts),
|
||||
getIgnoreGlobs(env, opts)
|
||||
);
|
||||
|
||||
backend = getBackend(env, opts);
|
||||
watcher->watch(fn.As<Function>());
|
||||
}
|
||||
|
||||
private:
|
||||
WatcherRef watcher;
|
||||
std::shared_ptr<Backend> backend;
|
||||
FunctionReference callback;
|
||||
|
||||
void execute() override {
|
||||
try {
|
||||
backend->watch(watcher);
|
||||
} catch (std::exception &err) {
|
||||
watcher->destroy();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class UnsubscribeRunner : public PromiseRunner {
|
||||
public:
|
||||
UnsubscribeRunner(Env env, Value dir, Value fn, Value opts) : PromiseRunner(env) {
|
||||
watcher = Watcher::getShared(
|
||||
std::string(dir.As<String>().Utf8Value().c_str()),
|
||||
getIgnorePaths(env, opts),
|
||||
getIgnoreGlobs(env, opts)
|
||||
);
|
||||
|
||||
backend = getBackend(env, opts);
|
||||
shouldUnwatch = watcher->unwatch(fn.As<Function>());
|
||||
}
|
||||
|
||||
private:
|
||||
WatcherRef watcher;
|
||||
std::shared_ptr<Backend> backend;
|
||||
bool shouldUnwatch;
|
||||
|
||||
void execute() override {
|
||||
if (shouldUnwatch) {
|
||||
backend->unwatch(watcher);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<class Runner>
|
||||
Value queueSubscriptionWork(const CallbackInfo& info) {
|
||||
Env env = info.Env();
|
||||
if (info.Length() < 1 || !info[0].IsString()) {
|
||||
TypeError::New(env, "Expected a string").ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
if (info.Length() < 2 || !info[1].IsFunction()) {
|
||||
TypeError::New(env, "Expected a function").ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
if (info.Length() >= 3 && !info[2].IsObject()) {
|
||||
TypeError::New(env, "Expected an object").ThrowAsJavaScriptException();
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
Runner *runner = new Runner(info.Env(), info[0], info[1], info[2]);
|
||||
return runner->queue();
|
||||
}
|
||||
|
||||
Value subscribe(const CallbackInfo& info) {
|
||||
return queueSubscriptionWork<SubscribeRunner>(info);
|
||||
}
|
||||
|
||||
Value unsubscribe(const CallbackInfo& info) {
|
||||
return queueSubscriptionWork<UnsubscribeRunner>(info);
|
||||
}
|
||||
|
||||
Object Init(Env env, Object exports) {
|
||||
exports.Set(
|
||||
String::New(env, "writeSnapshot"),
|
||||
Function::New(env, writeSnapshot)
|
||||
);
|
||||
exports.Set(
|
||||
String::New(env, "getEventsSince"),
|
||||
Function::New(env, getEventsSince)
|
||||
);
|
||||
exports.Set(
|
||||
String::New(env, "subscribe"),
|
||||
Function::New(env, subscribe)
|
||||
);
|
||||
exports.Set(
|
||||
String::New(env, "unsubscribe"),
|
||||
Function::New(env, unsubscribe)
|
||||
);
|
||||
return exports;
|
||||
}
|
||||
|
||||
NODE_API_MODULE(watcher, Init)
|
||||
306
node_modules/@parcel/watcher/src/kqueue/KqueueBackend.cc
generated
vendored
Normal file
306
node_modules/@parcel/watcher/src/kqueue/KqueueBackend.cc
generated
vendored
Normal file
@@ -0,0 +1,306 @@
|
||||
#include <memory>
|
||||
#include <poll.h>
|
||||
#include <unistd.h>
|
||||
#include <libgen.h>
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include "KqueueBackend.hh"
|
||||
|
||||
#if __APPLE__
|
||||
#define st_mtim st_mtimespec
|
||||
#endif
|
||||
|
||||
#if !defined(O_EVTONLY)
|
||||
#define O_EVTONLY O_RDONLY
|
||||
#endif
|
||||
|
||||
#define CONVERT_TIME(ts) ((uint64_t)ts.tv_sec * 1000000000 + ts.tv_nsec)
|
||||
|
||||
void KqueueBackend::start() {
|
||||
if ((mKqueue = kqueue()) < 0) {
|
||||
throw std::runtime_error(std::string("Unable to open kqueue: ") + strerror(errno));
|
||||
}
|
||||
|
||||
// Create a pipe that we will write to when we want to end the thread.
|
||||
int err = pipe(mPipe);
|
||||
if (err == -1) {
|
||||
throw std::runtime_error(std::string("Unable to open pipe: ") + strerror(errno));
|
||||
}
|
||||
|
||||
// Subscribe kqueue to this pipe.
|
||||
struct kevent ev;
|
||||
EV_SET(
|
||||
&ev,
|
||||
mPipe[0],
|
||||
EVFILT_READ,
|
||||
EV_ADD | EV_CLEAR,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
);
|
||||
|
||||
if (kevent(mKqueue, &ev, 1, NULL, 0, 0)) {
|
||||
close(mPipe[0]);
|
||||
close(mPipe[1]);
|
||||
throw std::runtime_error(std::string("Unable to watch pipe: ") + strerror(errno));
|
||||
}
|
||||
|
||||
notifyStarted();
|
||||
|
||||
struct kevent events[128];
|
||||
|
||||
while (true) {
|
||||
int event_count = kevent(mKqueue, NULL, 0, events, 128, 0);
|
||||
if (event_count < 0 || events[0].flags == EV_ERROR) {
|
||||
throw std::runtime_error(std::string("kevent error: ") + strerror(errno));
|
||||
}
|
||||
|
||||
// Track all of the watchers that are touched so we can notify them at the end of the events.
|
||||
std::unordered_set<WatcherRef> watchers;
|
||||
|
||||
for (int i = 0; i < event_count; i++) {
|
||||
int flags = events[i].fflags;
|
||||
int fd = events[i].ident;
|
||||
if (fd == mPipe[0]) {
|
||||
// pipe was written to. break out of the loop.
|
||||
goto done;
|
||||
}
|
||||
|
||||
auto it = mFdToEntry.find(fd);
|
||||
if (it == mFdToEntry.end()) {
|
||||
// If fd wasn't in our map, we may have already stopped watching it. Ignore the event.
|
||||
continue;
|
||||
}
|
||||
|
||||
DirEntry *entry = it->second;
|
||||
|
||||
if (flags & NOTE_WRITE && entry && entry->isDir) {
|
||||
// If a write occurred on a directory, we have to diff the contents of that
|
||||
// directory to determine what file was added/deleted.
|
||||
compareDir(fd, entry->path, watchers);
|
||||
} else {
|
||||
std::vector<KqueueSubscription *> subs = findSubscriptions(entry->path);
|
||||
for (auto it = subs.begin(); it != subs.end(); it++) {
|
||||
KqueueSubscription *sub = *it;
|
||||
watchers.insert(sub->watcher);
|
||||
if (flags & (NOTE_DELETE | NOTE_RENAME | NOTE_REVOKE)) {
|
||||
sub->watcher->mEvents.remove(sub->path);
|
||||
sub->tree->remove(sub->path);
|
||||
mFdToEntry.erase((int)(size_t)entry->state);
|
||||
mSubscriptions.erase(sub->path);
|
||||
} else if (flags & (NOTE_WRITE | NOTE_ATTRIB | NOTE_EXTEND)) {
|
||||
struct stat st;
|
||||
lstat(sub->path.c_str(), &st);
|
||||
if (entry->mtime != CONVERT_TIME(st.st_mtim)) {
|
||||
entry->mtime = CONVERT_TIME(st.st_mtim);
|
||||
sub->watcher->mEvents.update(sub->path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (auto it = watchers.begin(); it != watchers.end(); it++) {
|
||||
(*it)->notify();
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
close(mPipe[0]);
|
||||
close(mPipe[1]);
|
||||
mEndedSignal.notify();
|
||||
}
|
||||
|
||||
KqueueBackend::~KqueueBackend() {
|
||||
write(mPipe[1], "X", 1);
|
||||
mEndedSignal.wait();
|
||||
}
|
||||
|
||||
void KqueueBackend::subscribe(WatcherRef watcher) {
|
||||
// Build a full directory tree recursively, and watch each directory.
|
||||
std::shared_ptr<DirTree> tree = getTree(watcher);
|
||||
|
||||
for (auto it = tree->entries.begin(); it != tree->entries.end(); it++) {
|
||||
bool success = watchDir(watcher, it->second.path, tree);
|
||||
if (!success) {
|
||||
throw WatcherError(std::string("error watching " + watcher->mDir + ": " + strerror(errno)), watcher);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool KqueueBackend::watchDir(WatcherRef watcher, std::string path, std::shared_ptr<DirTree> tree) {
|
||||
if (watcher->isIgnored(path)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
DirEntry *entry = tree->find(path);
|
||||
if (!entry) {
|
||||
return false;
|
||||
}
|
||||
|
||||
KqueueSubscription sub = {
|
||||
.watcher = watcher,
|
||||
.path = path,
|
||||
.tree = tree
|
||||
};
|
||||
|
||||
if (!entry->state) {
|
||||
int fd = open(path.c_str(), O_EVTONLY);
|
||||
if (fd <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
struct kevent event;
|
||||
EV_SET(
|
||||
&event,
|
||||
fd,
|
||||
EVFILT_VNODE,
|
||||
EV_ADD | EV_CLEAR | EV_ENABLE,
|
||||
NOTE_DELETE | NOTE_WRITE | NOTE_EXTEND | NOTE_ATTRIB | NOTE_RENAME | NOTE_REVOKE,
|
||||
0,
|
||||
0
|
||||
);
|
||||
|
||||
if (kevent(mKqueue, &event, 1, NULL, 0, 0)) {
|
||||
close(fd);
|
||||
return false;
|
||||
}
|
||||
|
||||
entry->state = (void *)(size_t)fd;
|
||||
mFdToEntry.emplace(fd, entry);
|
||||
}
|
||||
|
||||
sub.fd = (int)(size_t)entry->state;
|
||||
mSubscriptions.emplace(path, sub);
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<KqueueSubscription *> KqueueBackend::findSubscriptions(std::string &path) {
|
||||
// Find the subscriptions affected by this path.
|
||||
// Copy pointers to them into a vector so that modifying mSubscriptions doesn't invalidate the iterator.
|
||||
auto range = mSubscriptions.equal_range(path);
|
||||
std::vector<KqueueSubscription *> subs;
|
||||
for (auto it = range.first; it != range.second; it++) {
|
||||
subs.push_back(&it->second);
|
||||
}
|
||||
|
||||
return subs;
|
||||
}
|
||||
|
||||
bool KqueueBackend::compareDir(int fd, std::string &path, std::unordered_set<WatcherRef> &watchers) {
|
||||
// macOS doesn't support fdclosedir, so we have to duplicate the file descriptor
|
||||
// to ensure the closedir doesn't also stop watching.
|
||||
#if __APPLE__
|
||||
fd = dup(fd);
|
||||
#endif
|
||||
|
||||
DIR *dir = fdopendir(fd);
|
||||
if (dir == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// fdopendir doesn't rewind to the beginning.
|
||||
rewinddir(dir);
|
||||
|
||||
std::vector<KqueueSubscription *> subs = findSubscriptions(path);
|
||||
std::string dirStart = path + DIR_SEP;
|
||||
|
||||
std::unordered_set<std::shared_ptr<DirTree>> trees;
|
||||
for (auto it = subs.begin(); it != subs.end(); it++) {
|
||||
trees.emplace((*it)->tree);
|
||||
}
|
||||
|
||||
std::unordered_set<std::string> entries;
|
||||
struct dirent *entry;
|
||||
while ((entry = readdir(dir))) {
|
||||
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string fullpath = dirStart + entry->d_name;
|
||||
entries.emplace(fullpath);
|
||||
|
||||
for (auto it = trees.begin(); it != trees.end(); it++) {
|
||||
std::shared_ptr<DirTree> tree = *it;
|
||||
if (!tree->find(fullpath)) {
|
||||
struct stat st;
|
||||
fstatat(fd, entry->d_name, &st, AT_SYMLINK_NOFOLLOW);
|
||||
tree->add(fullpath, CONVERT_TIME(st.st_mtim), S_ISDIR(st.st_mode));
|
||||
|
||||
// Notify all watchers with the same tree.
|
||||
for (auto i = subs.begin(); i != subs.end(); i++) {
|
||||
KqueueSubscription *sub = *i;
|
||||
if (sub->tree == tree) {
|
||||
if (sub->watcher->isIgnored(fullpath)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
sub->watcher->mEvents.create(fullpath);
|
||||
watchers.emplace(sub->watcher);
|
||||
|
||||
bool success = watchDir(sub->watcher, fullpath, sub->tree);
|
||||
if (!success) {
|
||||
sub->tree->remove(fullpath);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (auto it = trees.begin(); it != trees.end(); it++) {
|
||||
std::shared_ptr<DirTree> tree = *it;
|
||||
for (auto entry = tree->entries.begin(); entry != tree->entries.end();) {
|
||||
|
||||
if (
|
||||
entry->first.rfind(dirStart, 0) == 0 &&
|
||||
entry->first.find(DIR_SEP, dirStart.length()) == std::string::npos &&
|
||||
entries.count(entry->first) == 0
|
||||
) {
|
||||
// Notify all watchers with the same tree.
|
||||
for (auto i = subs.begin(); i != subs.end(); i++) {
|
||||
if ((*i)->tree == tree) {
|
||||
KqueueSubscription *sub = *i;
|
||||
if (!sub->watcher->isIgnored(entry->first)) {
|
||||
sub->watcher->mEvents.remove(entry->first);
|
||||
watchers.emplace(sub->watcher);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mFdToEntry.erase((int)(size_t)entry->second.state);
|
||||
mSubscriptions.erase(entry->first);
|
||||
entry = tree->entries.erase(entry);
|
||||
} else {
|
||||
entry++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if __APPLE__
|
||||
closedir(dir);
|
||||
#else
|
||||
fdclosedir(dir);
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void KqueueBackend::unsubscribe(WatcherRef watcher) {
|
||||
// Find any subscriptions pointing to this watcher, and remove them.
|
||||
for (auto it = mSubscriptions.begin(); it != mSubscriptions.end();) {
|
||||
if (it->second.watcher.get() == watcher.get()) {
|
||||
if (mSubscriptions.count(it->first) == 1) {
|
||||
// Closing the file descriptor automatically unwatches it in the kqueue.
|
||||
close(it->second.fd);
|
||||
mFdToEntry.erase(it->second.fd);
|
||||
}
|
||||
|
||||
it = mSubscriptions.erase(it);
|
||||
} else {
|
||||
it++;
|
||||
}
|
||||
}
|
||||
}
|
||||
35
node_modules/@parcel/watcher/src/kqueue/KqueueBackend.hh
generated
vendored
Normal file
35
node_modules/@parcel/watcher/src/kqueue/KqueueBackend.hh
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
#ifndef KQUEUE_H
|
||||
#define KQUEUE_H
|
||||
|
||||
#include <unordered_map>
|
||||
#include <sys/event.h>
|
||||
#include "../shared/BruteForceBackend.hh"
|
||||
#include "../DirTree.hh"
|
||||
#include "../Signal.hh"
|
||||
|
||||
struct KqueueSubscription {
|
||||
WatcherRef watcher;
|
||||
std::string path;
|
||||
std::shared_ptr<DirTree> tree;
|
||||
int fd;
|
||||
};
|
||||
|
||||
class KqueueBackend : public BruteForceBackend {
|
||||
public:
|
||||
void start() override;
|
||||
~KqueueBackend();
|
||||
void subscribe(WatcherRef watcher) override;
|
||||
void unsubscribe(WatcherRef watcher) override;
|
||||
private:
|
||||
int mKqueue;
|
||||
int mPipe[2];
|
||||
std::unordered_multimap<std::string, KqueueSubscription> mSubscriptions;
|
||||
std::unordered_map<int, DirEntry *> mFdToEntry;
|
||||
Signal mEndedSignal;
|
||||
|
||||
bool watchDir(WatcherRef watcher, std::string path, std::shared_ptr<DirTree> tree);
|
||||
bool compareDir(int fd, std::string &dir, std::unordered_set<WatcherRef> &watchers);
|
||||
std::vector<KqueueSubscription *> findSubscriptions(std::string &path);
|
||||
};
|
||||
|
||||
#endif
|
||||
232
node_modules/@parcel/watcher/src/linux/InotifyBackend.cc
generated
vendored
Normal file
232
node_modules/@parcel/watcher/src/linux/InotifyBackend.cc
generated
vendored
Normal file
@@ -0,0 +1,232 @@
|
||||
#include <memory>
|
||||
#include <poll.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include "InotifyBackend.hh"
|
||||
|
||||
#define INOTIFY_MASK \
|
||||
IN_ATTRIB | IN_CREATE | IN_DELETE | \
|
||||
IN_DELETE_SELF | IN_MODIFY | IN_MOVE_SELF | IN_MOVED_FROM | \
|
||||
IN_MOVED_TO | IN_DONT_FOLLOW | IN_ONLYDIR | IN_EXCL_UNLINK
|
||||
#define BUFFER_SIZE 8192
|
||||
#define CONVERT_TIME(ts) ((uint64_t)ts.tv_sec * 1000000000 + ts.tv_nsec)
|
||||
|
||||
void InotifyBackend::start() {
|
||||
// Create a pipe that we will write to when we want to end the thread.
|
||||
int err = pipe2(mPipe, O_CLOEXEC | O_NONBLOCK);
|
||||
if (err == -1) {
|
||||
throw std::runtime_error(std::string("Unable to open pipe: ") + strerror(errno));
|
||||
}
|
||||
|
||||
// Init inotify file descriptor.
|
||||
mInotify = inotify_init1(IN_NONBLOCK | IN_CLOEXEC);
|
||||
if (mInotify == -1) {
|
||||
throw std::runtime_error(std::string("Unable to initialize inotify: ") + strerror(errno));
|
||||
}
|
||||
|
||||
pollfd pollfds[2];
|
||||
pollfds[0].fd = mPipe[0];
|
||||
pollfds[0].events = POLLIN;
|
||||
pollfds[0].revents = 0;
|
||||
pollfds[1].fd = mInotify;
|
||||
pollfds[1].events = POLLIN;
|
||||
pollfds[1].revents = 0;
|
||||
|
||||
notifyStarted();
|
||||
|
||||
// Loop until we get an event from the pipe.
|
||||
while (true) {
|
||||
int result = poll(pollfds, 2, 500);
|
||||
if (result < 0) {
|
||||
throw std::runtime_error(std::string("Unable to poll: ") + strerror(errno));
|
||||
}
|
||||
|
||||
if (pollfds[0].revents) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (pollfds[1].revents) {
|
||||
handleEvents();
|
||||
}
|
||||
}
|
||||
|
||||
close(mPipe[0]);
|
||||
close(mPipe[1]);
|
||||
close(mInotify);
|
||||
|
||||
mEndedSignal.notify();
|
||||
}
|
||||
|
||||
InotifyBackend::~InotifyBackend() {
|
||||
write(mPipe[1], "X", 1);
|
||||
mEndedSignal.wait();
|
||||
}
|
||||
|
||||
// This function is called by Backend::watch which takes a lock on mMutex
|
||||
void InotifyBackend::subscribe(WatcherRef watcher) {
|
||||
// Build a full directory tree recursively, and watch each directory.
|
||||
std::shared_ptr<DirTree> tree = getTree(watcher);
|
||||
|
||||
for (auto it = tree->entries.begin(); it != tree->entries.end(); it++) {
|
||||
if (it->second.isDir) {
|
||||
bool success = watchDir(watcher, it->second.path, tree);
|
||||
if (!success) {
|
||||
throw WatcherError(std::string("inotify_add_watch on '") + it->second.path + std::string("' failed: ") + strerror(errno), watcher);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool InotifyBackend::watchDir(WatcherRef watcher, std::string path, std::shared_ptr<DirTree> tree) {
|
||||
int wd = inotify_add_watch(mInotify, path.c_str(), INOTIFY_MASK);
|
||||
if (wd == -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::shared_ptr<InotifySubscription> sub = std::make_shared<InotifySubscription>();
|
||||
sub->tree = tree;
|
||||
sub->path = path;
|
||||
sub->watcher = watcher;
|
||||
mSubscriptions.emplace(wd, sub);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void InotifyBackend::handleEvents() {
|
||||
char buf[BUFFER_SIZE] __attribute__ ((aligned(__alignof__(struct inotify_event))));;
|
||||
struct inotify_event *event;
|
||||
|
||||
// Track all of the watchers that are touched so we can notify them at the end of the events.
|
||||
std::unordered_set<WatcherRef> watchers;
|
||||
|
||||
while (true) {
|
||||
int n = read(mInotify, &buf, BUFFER_SIZE);
|
||||
if (n < 0) {
|
||||
if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
||||
break;
|
||||
}
|
||||
|
||||
throw std::runtime_error(std::string("Error reading from inotify: ") + strerror(errno));
|
||||
}
|
||||
|
||||
if (n == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
for (char *ptr = buf; ptr < buf + n; ptr += sizeof(*event) + event->len) {
|
||||
event = (struct inotify_event *)ptr;
|
||||
|
||||
if ((event->mask & IN_Q_OVERFLOW) == IN_Q_OVERFLOW) {
|
||||
// overflow
|
||||
continue;
|
||||
}
|
||||
|
||||
handleEvent(event, watchers);
|
||||
}
|
||||
}
|
||||
|
||||
for (auto it = watchers.begin(); it != watchers.end(); it++) {
|
||||
(*it)->notify();
|
||||
}
|
||||
}
|
||||
|
||||
void InotifyBackend::handleEvent(struct inotify_event *event, std::unordered_set<WatcherRef> &watchers) {
|
||||
std::unique_lock<std::mutex> lock(mMutex);
|
||||
|
||||
// Find the subscriptions for this watch descriptor
|
||||
auto range = mSubscriptions.equal_range(event->wd);
|
||||
std::unordered_set<std::shared_ptr<InotifySubscription>> set;
|
||||
for (auto it = range.first; it != range.second; it++) {
|
||||
set.insert(it->second);
|
||||
}
|
||||
|
||||
for (auto it = set.begin(); it != set.end(); it++) {
|
||||
if (handleSubscription(event, *it)) {
|
||||
watchers.insert((*it)->watcher);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool InotifyBackend::handleSubscription(struct inotify_event *event, std::shared_ptr<InotifySubscription> sub) {
|
||||
// Build full path and check if its in our ignore list.
|
||||
std::shared_ptr<Watcher> watcher = sub->watcher;
|
||||
std::string path = std::string(sub->path);
|
||||
bool isDir = event->mask & IN_ISDIR;
|
||||
|
||||
if (event->len > 0) {
|
||||
path += "/" + std::string(event->name);
|
||||
}
|
||||
|
||||
if (watcher->isIgnored(path)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If this is a create, check if it's a directory and start watching if it is.
|
||||
// In any case, keep the directory tree up to date.
|
||||
if (event->mask & (IN_CREATE | IN_MOVED_TO)) {
|
||||
watcher->mEvents.create(path);
|
||||
|
||||
struct stat st;
|
||||
// Use lstat to avoid resolving symbolic links that we cannot watch anyway
|
||||
// https://github.com/parcel-bundler/watcher/issues/76
|
||||
lstat(path.c_str(), &st);
|
||||
DirEntry *entry = sub->tree->add(path, CONVERT_TIME(st.st_mtim), S_ISDIR(st.st_mode));
|
||||
|
||||
if (entry->isDir) {
|
||||
bool success = watchDir(watcher, path, sub->tree);
|
||||
if (!success) {
|
||||
sub->tree->remove(path);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else if (event->mask & (IN_MODIFY | IN_ATTRIB)) {
|
||||
watcher->mEvents.update(path);
|
||||
|
||||
struct stat st;
|
||||
stat(path.c_str(), &st);
|
||||
sub->tree->update(path, CONVERT_TIME(st.st_mtim));
|
||||
} else if (event->mask & (IN_DELETE | IN_DELETE_SELF | IN_MOVED_FROM | IN_MOVE_SELF)) {
|
||||
bool isSelfEvent = (event->mask & (IN_DELETE_SELF | IN_MOVE_SELF));
|
||||
// Ignore delete/move self events unless this is the recursive watch root
|
||||
if (isSelfEvent && path != watcher->mDir) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If the entry being deleted/moved is a directory, remove it from the list of subscriptions
|
||||
// XXX: self events don't have the IN_ISDIR mask
|
||||
if (isSelfEvent || isDir) {
|
||||
for (auto it = mSubscriptions.begin(); it != mSubscriptions.end();) {
|
||||
if (it->second->path == path) {
|
||||
it = mSubscriptions.erase(it);
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
watcher->mEvents.remove(path);
|
||||
sub->tree->remove(path);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// This function is called by Backend::unwatch which takes a lock on mMutex
|
||||
void InotifyBackend::unsubscribe(WatcherRef watcher) {
|
||||
// Find any subscriptions pointing to this watcher, and remove them.
|
||||
for (auto it = mSubscriptions.begin(); it != mSubscriptions.end();) {
|
||||
if (it->second->watcher.get() == watcher.get()) {
|
||||
if (mSubscriptions.count(it->first) == 1) {
|
||||
int err = inotify_rm_watch(mInotify, it->first);
|
||||
if (err == -1) {
|
||||
throw WatcherError(std::string("Unable to remove watcher: ") + strerror(errno), watcher);
|
||||
}
|
||||
}
|
||||
|
||||
it = mSubscriptions.erase(it);
|
||||
} else {
|
||||
it++;
|
||||
}
|
||||
}
|
||||
}
|
||||
34
node_modules/@parcel/watcher/src/linux/InotifyBackend.hh
generated
vendored
Normal file
34
node_modules/@parcel/watcher/src/linux/InotifyBackend.hh
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef INOTIFY_H
|
||||
#define INOTIFY_H
|
||||
|
||||
#include <unordered_map>
|
||||
#include <sys/inotify.h>
|
||||
#include "../shared/BruteForceBackend.hh"
|
||||
#include "../DirTree.hh"
|
||||
#include "../Signal.hh"
|
||||
|
||||
struct InotifySubscription {
|
||||
std::shared_ptr<DirTree> tree;
|
||||
std::string path;
|
||||
WatcherRef watcher;
|
||||
};
|
||||
|
||||
class InotifyBackend : public BruteForceBackend {
|
||||
public:
|
||||
void start() override;
|
||||
~InotifyBackend();
|
||||
void subscribe(WatcherRef watcher) override;
|
||||
void unsubscribe(WatcherRef watcher) override;
|
||||
private:
|
||||
int mPipe[2];
|
||||
int mInotify;
|
||||
std::unordered_multimap<int, std::shared_ptr<InotifySubscription>> mSubscriptions;
|
||||
Signal mEndedSignal;
|
||||
|
||||
bool watchDir(WatcherRef watcher, std::string path, std::shared_ptr<DirTree> tree);
|
||||
void handleEvents();
|
||||
void handleEvent(struct inotify_event *event, std::unordered_set<WatcherRef> &watchers);
|
||||
bool handleSubscription(struct inotify_event *event, std::shared_ptr<InotifySubscription> sub);
|
||||
};
|
||||
|
||||
#endif
|
||||
338
node_modules/@parcel/watcher/src/macos/FSEventsBackend.cc
generated
vendored
Normal file
338
node_modules/@parcel/watcher/src/macos/FSEventsBackend.cc
generated
vendored
Normal file
@@ -0,0 +1,338 @@
|
||||
#include <CoreServices/CoreServices.h>
|
||||
#include <sys/stat.h>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <unordered_set>
|
||||
#include "../Event.hh"
|
||||
#include "../Backend.hh"
|
||||
#include "./FSEventsBackend.hh"
|
||||
#include "../Watcher.hh"
|
||||
|
||||
#define CONVERT_TIME(ts) ((uint64_t)ts.tv_sec * 1000000000 + ts.tv_nsec)
|
||||
#define IGNORED_FLAGS (kFSEventStreamEventFlagItemIsHardlink | kFSEventStreamEventFlagItemIsLastHardlink | kFSEventStreamEventFlagItemIsSymlink | kFSEventStreamEventFlagItemIsDir | kFSEventStreamEventFlagItemIsFile)
|
||||
|
||||
void stopStream(FSEventStreamRef stream, CFRunLoopRef runLoop) {
|
||||
FSEventStreamStop(stream);
|
||||
FSEventStreamUnscheduleFromRunLoop(stream, runLoop, kCFRunLoopDefaultMode);
|
||||
FSEventStreamInvalidate(stream);
|
||||
FSEventStreamRelease(stream);
|
||||
}
|
||||
|
||||
// macOS has a case insensitive file system by default. In order to detect
|
||||
// file renames that only affect case, we need to get the canonical path
|
||||
// and compare it with the input path to determine if a file was created or deleted.
|
||||
bool pathExists(char *path) {
|
||||
int fd = open(path, O_RDONLY | O_SYMLINK);
|
||||
if (fd == -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
char buf[PATH_MAX];
|
||||
if (fcntl(fd, F_GETPATH, buf) == -1) {
|
||||
close(fd);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool res = strncmp(path, buf, PATH_MAX) == 0;
|
||||
close(fd);
|
||||
return res;
|
||||
}
|
||||
|
||||
class State: public WatcherState {
|
||||
public:
|
||||
FSEventStreamRef stream;
|
||||
std::shared_ptr<DirTree> tree;
|
||||
uint64_t since;
|
||||
};
|
||||
|
||||
void FSEventsCallback(
|
||||
ConstFSEventStreamRef streamRef,
|
||||
void *clientCallBackInfo,
|
||||
size_t numEvents,
|
||||
void *eventPaths,
|
||||
const FSEventStreamEventFlags eventFlags[],
|
||||
const FSEventStreamEventId eventIds[]
|
||||
) {
|
||||
char **paths = (char **)eventPaths;
|
||||
std::shared_ptr<Watcher>& watcher = *static_cast<std::shared_ptr<Watcher> *>(clientCallBackInfo);
|
||||
|
||||
EventList& list = watcher->mEvents;
|
||||
if (watcher->state == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto stateGuard = watcher->state;
|
||||
auto* state = static_cast<State*>(stateGuard.get());
|
||||
uint64_t since = state->since;
|
||||
bool deletedRoot = false;
|
||||
|
||||
for (size_t i = 0; i < numEvents; ++i) {
|
||||
bool isCreated = (eventFlags[i] & kFSEventStreamEventFlagItemCreated) == kFSEventStreamEventFlagItemCreated;
|
||||
bool isRemoved = (eventFlags[i] & kFSEventStreamEventFlagItemRemoved) == kFSEventStreamEventFlagItemRemoved;
|
||||
bool isModified = (eventFlags[i] & kFSEventStreamEventFlagItemModified) == kFSEventStreamEventFlagItemModified ||
|
||||
(eventFlags[i] & kFSEventStreamEventFlagItemInodeMetaMod) == kFSEventStreamEventFlagItemInodeMetaMod ||
|
||||
(eventFlags[i] & kFSEventStreamEventFlagItemFinderInfoMod) == kFSEventStreamEventFlagItemFinderInfoMod ||
|
||||
(eventFlags[i] & kFSEventStreamEventFlagItemChangeOwner) == kFSEventStreamEventFlagItemChangeOwner ||
|
||||
(eventFlags[i] & kFSEventStreamEventFlagItemXattrMod) == kFSEventStreamEventFlagItemXattrMod;
|
||||
bool isRenamed = (eventFlags[i] & kFSEventStreamEventFlagItemRenamed) == kFSEventStreamEventFlagItemRenamed;
|
||||
bool isDone = (eventFlags[i] & kFSEventStreamEventFlagHistoryDone) == kFSEventStreamEventFlagHistoryDone;
|
||||
bool isDir = (eventFlags[i] & kFSEventStreamEventFlagItemIsDir) == kFSEventStreamEventFlagItemIsDir;
|
||||
|
||||
|
||||
if (eventFlags[i] & kFSEventStreamEventFlagMustScanSubDirs) {
|
||||
if (eventFlags[i] & kFSEventStreamEventFlagUserDropped) {
|
||||
list.error("Events were dropped by the FSEvents client. File system must be re-scanned.");
|
||||
} else if (eventFlags[i] & kFSEventStreamEventFlagKernelDropped) {
|
||||
list.error("Events were dropped by the kernel. File system must be re-scanned.");
|
||||
} else {
|
||||
list.error("Too many events. File system must be re-scanned.");
|
||||
}
|
||||
}
|
||||
|
||||
if (isDone) {
|
||||
watcher->notify();
|
||||
break;
|
||||
}
|
||||
|
||||
auto ignoredFlags = IGNORED_FLAGS;
|
||||
if (__builtin_available(macOS 10.13, *)) {
|
||||
ignoredFlags |= kFSEventStreamEventFlagItemCloned;
|
||||
}
|
||||
|
||||
// If we don't care about any of the flags that are set, ignore this event.
|
||||
if ((eventFlags[i] & ~ignoredFlags) == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// FSEvents exclusion paths only apply to files, not directories.
|
||||
if (watcher->isIgnored(paths[i])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Handle unambiguous events first
|
||||
if (isCreated && !(isRemoved || isModified || isRenamed)) {
|
||||
state->tree->add(paths[i], 0, isDir);
|
||||
list.create(paths[i]);
|
||||
} else if (isRemoved && !(isCreated || isModified || isRenamed)) {
|
||||
state->tree->remove(paths[i]);
|
||||
list.remove(paths[i]);
|
||||
if (paths[i] == watcher->mDir) {
|
||||
deletedRoot = true;
|
||||
}
|
||||
} else if (isModified && !(isCreated || isRemoved || isRenamed)) {
|
||||
struct stat file;
|
||||
if (stat(paths[i], &file)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ignore if mtime is the same as the last event.
|
||||
// This prevents duplicate events from being emitted.
|
||||
// If tv_nsec is zero, the file system probably only has second-level
|
||||
// granularity so allow the even through in that case.
|
||||
uint64_t mtime = CONVERT_TIME(file.st_mtimespec);
|
||||
DirEntry *entry = state->tree->find(paths[i]);
|
||||
if (entry && mtime == entry->mtime && file.st_mtimespec.tv_nsec != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (entry) {
|
||||
// Update mtime.
|
||||
entry->mtime = mtime;
|
||||
} else {
|
||||
// Add to tree if this path has not been discovered yet.
|
||||
state->tree->add(paths[i], mtime, S_ISDIR(file.st_mode));
|
||||
}
|
||||
|
||||
list.update(paths[i]);
|
||||
} else {
|
||||
// If multiple flags were set, then we need to call `stat` to determine if the file really exists.
|
||||
// This helps disambiguate creates, updates, and deletes.
|
||||
struct stat file;
|
||||
if (stat(paths[i], &file) || !pathExists(paths[i])) {
|
||||
// File does not exist, so we have to assume it was removed. This is not exact since the
|
||||
// flags set by fsevents get coalesced together (e.g. created & deleted), so there is no way to
|
||||
// know whether the create and delete both happened since our snapshot (in which case
|
||||
// we'd rather ignore this event completely). This will result in some extra delete events
|
||||
// being emitted for files we don't know about, but that is the best we can do.
|
||||
state->tree->remove(paths[i]);
|
||||
list.remove(paths[i]);
|
||||
if (paths[i] == watcher->mDir) {
|
||||
deletedRoot = true;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// If the file was modified, and existed before, then this is an update, otherwise a create.
|
||||
uint64_t ctime = CONVERT_TIME(file.st_birthtimespec);
|
||||
uint64_t mtime = CONVERT_TIME(file.st_mtimespec);
|
||||
DirEntry *entry = !since ? state->tree->find(paths[i]) : NULL;
|
||||
if (entry && entry->mtime == mtime && file.st_mtimespec.tv_nsec != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Some mounted file systems report a creation time of 0/unix epoch which we special case.
|
||||
if (isModified && (entry || (ctime <= since && ctime != 0))) {
|
||||
state->tree->update(paths[i], mtime);
|
||||
list.update(paths[i]);
|
||||
} else {
|
||||
state->tree->add(paths[i], mtime, S_ISDIR(file.st_mode));
|
||||
list.create(paths[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!since) {
|
||||
watcher->notify();
|
||||
}
|
||||
|
||||
// Stop watching if the root directory was deleted.
|
||||
if (deletedRoot) {
|
||||
stopStream((FSEventStreamRef)streamRef, CFRunLoopGetCurrent());
|
||||
watcher->state = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void checkWatcher(WatcherRef watcher) {
|
||||
struct stat file;
|
||||
if (stat(watcher->mDir.c_str(), &file)) {
|
||||
throw WatcherError(strerror(errno), watcher);
|
||||
}
|
||||
|
||||
if (!S_ISDIR(file.st_mode)) {
|
||||
throw WatcherError(strerror(ENOTDIR), watcher);
|
||||
}
|
||||
}
|
||||
|
||||
void FSEventsBackend::startStream(WatcherRef watcher, FSEventStreamEventId id) {
|
||||
checkWatcher(watcher);
|
||||
|
||||
CFAbsoluteTime latency = 0.001;
|
||||
CFStringRef fileWatchPath = CFStringCreateWithCString(
|
||||
NULL,
|
||||
watcher->mDir.c_str(),
|
||||
kCFStringEncodingUTF8
|
||||
);
|
||||
|
||||
CFArrayRef pathsToWatch = CFArrayCreate(
|
||||
NULL,
|
||||
(const void **)&fileWatchPath,
|
||||
1,
|
||||
NULL
|
||||
);
|
||||
|
||||
// Make a watcher reference we can pass into the callback. This ensures bumped ref-count.
|
||||
std::shared_ptr<Watcher>* callbackWatcher = new std::shared_ptr<Watcher> (watcher);
|
||||
FSEventStreamContext callbackInfo {0, static_cast<void*> (callbackWatcher), nullptr, nullptr, nullptr};
|
||||
FSEventStreamRef stream = FSEventStreamCreate(
|
||||
NULL,
|
||||
&FSEventsCallback,
|
||||
&callbackInfo,
|
||||
pathsToWatch,
|
||||
id,
|
||||
latency,
|
||||
kFSEventStreamCreateFlagFileEvents
|
||||
);
|
||||
|
||||
CFMutableArrayRef exclusions = CFArrayCreateMutable(NULL, watcher->mIgnorePaths.size(), NULL);
|
||||
for (auto it = watcher->mIgnorePaths.begin(); it != watcher->mIgnorePaths.end(); it++) {
|
||||
CFStringRef path = CFStringCreateWithCString(
|
||||
NULL,
|
||||
it->c_str(),
|
||||
kCFStringEncodingUTF8
|
||||
);
|
||||
|
||||
CFArrayAppendValue(exclusions, (const void *)path);
|
||||
}
|
||||
|
||||
FSEventStreamSetExclusionPaths(stream, exclusions);
|
||||
|
||||
FSEventStreamScheduleWithRunLoop(stream, mRunLoop, kCFRunLoopDefaultMode);
|
||||
bool started = FSEventStreamStart(stream);
|
||||
|
||||
CFRelease(pathsToWatch);
|
||||
CFRelease(fileWatchPath);
|
||||
|
||||
if (!started) {
|
||||
FSEventStreamRelease(stream);
|
||||
throw WatcherError("Error starting FSEvents stream", watcher);
|
||||
}
|
||||
|
||||
auto stateGuard = watcher->state;
|
||||
State* s = static_cast<State*>(stateGuard.get());
|
||||
s->tree = std::make_shared<DirTree>(watcher->mDir);
|
||||
s->stream = stream;
|
||||
}
|
||||
|
||||
void FSEventsBackend::start() {
|
||||
mRunLoop = CFRunLoopGetCurrent();
|
||||
CFRetain(mRunLoop);
|
||||
|
||||
// Unlock once run loop has started.
|
||||
CFRunLoopPerformBlock(mRunLoop, kCFRunLoopDefaultMode, ^ {
|
||||
notifyStarted();
|
||||
});
|
||||
|
||||
CFRunLoopWakeUp(mRunLoop);
|
||||
CFRunLoopRun();
|
||||
}
|
||||
|
||||
FSEventsBackend::~FSEventsBackend() {
|
||||
std::unique_lock<std::mutex> lock(mMutex);
|
||||
CFRunLoopStop(mRunLoop);
|
||||
CFRelease(mRunLoop);
|
||||
}
|
||||
|
||||
void FSEventsBackend::writeSnapshot(WatcherRef watcher, std::string *snapshotPath) {
|
||||
std::unique_lock<std::mutex> lock(mMutex);
|
||||
checkWatcher(watcher);
|
||||
|
||||
FSEventStreamEventId id = FSEventsGetCurrentEventId();
|
||||
std::ofstream ofs(*snapshotPath);
|
||||
ofs << id;
|
||||
ofs << "\n";
|
||||
|
||||
struct timespec now;
|
||||
clock_gettime(CLOCK_REALTIME, &now);
|
||||
ofs << CONVERT_TIME(now);
|
||||
}
|
||||
|
||||
void FSEventsBackend::getEventsSince(WatcherRef watcher, std::string *snapshotPath) {
|
||||
std::unique_lock<std::mutex> lock(mMutex);
|
||||
std::ifstream ifs(*snapshotPath);
|
||||
if (ifs.fail()) {
|
||||
return;
|
||||
}
|
||||
|
||||
FSEventStreamEventId id;
|
||||
uint64_t since;
|
||||
ifs >> id;
|
||||
ifs >> since;
|
||||
|
||||
auto s = std::make_shared<State>();
|
||||
s->since = since;
|
||||
watcher->state = s;
|
||||
|
||||
startStream(watcher, id);
|
||||
watcher->wait();
|
||||
stopStream(s->stream, mRunLoop);
|
||||
|
||||
watcher->state = nullptr;
|
||||
}
|
||||
|
||||
// This function is called by Backend::watch which takes a lock on mMutex
|
||||
void FSEventsBackend::subscribe(WatcherRef watcher) {
|
||||
auto s = std::make_shared<State>();
|
||||
s->since = 0;
|
||||
watcher->state = s;
|
||||
startStream(watcher, kFSEventStreamEventIdSinceNow);
|
||||
}
|
||||
|
||||
// This function is called by Backend::unwatch which takes a lock on mMutex
|
||||
void FSEventsBackend::unsubscribe(WatcherRef watcher) {
|
||||
auto stateGuard = watcher->state;
|
||||
State* s = static_cast<State*>(stateGuard.get());
|
||||
if (s != nullptr) {
|
||||
stopStream(s->stream, mRunLoop);
|
||||
watcher->state = nullptr;
|
||||
}
|
||||
}
|
||||
20
node_modules/@parcel/watcher/src/macos/FSEventsBackend.hh
generated
vendored
Normal file
20
node_modules/@parcel/watcher/src/macos/FSEventsBackend.hh
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef FS_EVENTS_H
|
||||
#define FS_EVENTS_H
|
||||
|
||||
#include <CoreServices/CoreServices.h>
|
||||
#include "../Backend.hh"
|
||||
|
||||
class FSEventsBackend : public Backend {
|
||||
public:
|
||||
void start() override;
|
||||
~FSEventsBackend();
|
||||
void writeSnapshot(WatcherRef watcher, std::string *snapshotPath) override;
|
||||
void getEventsSince(WatcherRef watcher, std::string *snapshotPath) override;
|
||||
void subscribe(WatcherRef watcher) override;
|
||||
void unsubscribe(WatcherRef watcher) override;
|
||||
private:
|
||||
void startStream(WatcherRef watcher, FSEventStreamEventId id);
|
||||
CFRunLoopRef mRunLoop;
|
||||
};
|
||||
|
||||
#endif
|
||||
41
node_modules/@parcel/watcher/src/shared/BruteForceBackend.cc
generated
vendored
Normal file
41
node_modules/@parcel/watcher/src/shared/BruteForceBackend.cc
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
#include <string>
|
||||
#include "../DirTree.hh"
|
||||
#include "../Event.hh"
|
||||
#include "./BruteForceBackend.hh"
|
||||
|
||||
std::shared_ptr<DirTree> BruteForceBackend::getTree(WatcherRef watcher, bool shouldRead) {
|
||||
auto tree = DirTree::getCached(watcher->mDir);
|
||||
|
||||
// If the tree is not complete, read it if needed.
|
||||
if (!tree->isComplete && shouldRead) {
|
||||
readTree(watcher, tree);
|
||||
tree->isComplete = true;
|
||||
}
|
||||
|
||||
return tree;
|
||||
}
|
||||
|
||||
void BruteForceBackend::writeSnapshot(WatcherRef watcher, std::string *snapshotPath) {
|
||||
std::unique_lock<std::mutex> lock(mMutex);
|
||||
auto tree = getTree(watcher);
|
||||
FILE *f = fopen(snapshotPath->c_str(), "w");
|
||||
if (!f) {
|
||||
throw std::runtime_error(std::string("Unable to open snapshot file: ") + strerror(errno));
|
||||
}
|
||||
|
||||
tree->write(f);
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
void BruteForceBackend::getEventsSince(WatcherRef watcher, std::string *snapshotPath) {
|
||||
std::unique_lock<std::mutex> lock(mMutex);
|
||||
FILE *f = fopen(snapshotPath->c_str(), "r");
|
||||
if (!f) {
|
||||
throw std::runtime_error(std::string("Unable to open snapshot file: ") + strerror(errno));
|
||||
}
|
||||
|
||||
DirTree snapshot{watcher->mDir, f};
|
||||
auto now = getTree(watcher);
|
||||
now->getChanges(&snapshot, watcher->mEvents);
|
||||
fclose(f);
|
||||
}
|
||||
25
node_modules/@parcel/watcher/src/shared/BruteForceBackend.hh
generated
vendored
Normal file
25
node_modules/@parcel/watcher/src/shared/BruteForceBackend.hh
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef BRUTE_FORCE_H
|
||||
#define BRUTE_FORCE_H
|
||||
|
||||
#include "../Backend.hh"
|
||||
#include "../DirTree.hh"
|
||||
#include "../Watcher.hh"
|
||||
|
||||
class BruteForceBackend : public Backend {
|
||||
public:
|
||||
void writeSnapshot(WatcherRef watcher, std::string *snapshotPath) override;
|
||||
void getEventsSince(WatcherRef watcher, std::string *snapshotPath) override;
|
||||
void subscribe(WatcherRef watcher) override {
|
||||
throw "Brute force backend doesn't support subscriptions.";
|
||||
}
|
||||
|
||||
void unsubscribe(WatcherRef watcher) override {
|
||||
throw "Brute force backend doesn't support subscriptions.";
|
||||
}
|
||||
|
||||
std::shared_ptr<DirTree> getTree(WatcherRef watcher, bool shouldRead = true);
|
||||
private:
|
||||
void readTree(WatcherRef watcher, std::shared_ptr<DirTree> tree);
|
||||
};
|
||||
|
||||
#endif
|
||||
50
node_modules/@parcel/watcher/src/unix/fts.cc
generated
vendored
Normal file
50
node_modules/@parcel/watcher/src/unix/fts.cc
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
#include <string>
|
||||
|
||||
// weird error on linux
|
||||
#ifdef __THROW
|
||||
#undef __THROW
|
||||
#endif
|
||||
#define __THROW
|
||||
|
||||
#include <fts.h>
|
||||
#include <sys/stat.h>
|
||||
#include "../DirTree.hh"
|
||||
#include "../shared/BruteForceBackend.hh"
|
||||
|
||||
#define CONVERT_TIME(ts) ((uint64_t)ts.tv_sec * 1000000000 + ts.tv_nsec)
|
||||
#if __APPLE__
|
||||
#define st_mtim st_mtimespec
|
||||
#endif
|
||||
|
||||
void BruteForceBackend::readTree(WatcherRef watcher, std::shared_ptr<DirTree> tree) {
|
||||
char *paths[2] {(char *)watcher->mDir.c_str(), NULL};
|
||||
FTS *fts = fts_open(paths, FTS_NOCHDIR | FTS_PHYSICAL, NULL);
|
||||
if (!fts) {
|
||||
throw WatcherError(strerror(errno), watcher);
|
||||
}
|
||||
|
||||
FTSENT *node;
|
||||
bool isRoot = true;
|
||||
|
||||
while ((node = fts_read(fts)) != NULL) {
|
||||
if (node->fts_errno) {
|
||||
fts_close(fts);
|
||||
throw WatcherError(strerror(node->fts_errno), watcher);
|
||||
}
|
||||
|
||||
if (isRoot && !(node->fts_info & FTS_D)) {
|
||||
fts_close(fts);
|
||||
throw WatcherError(strerror(ENOTDIR), watcher);
|
||||
}
|
||||
|
||||
if (watcher->isIgnored(std::string(node->fts_path))) {
|
||||
fts_set(fts, node, FTS_SKIP);
|
||||
continue;
|
||||
}
|
||||
|
||||
tree->add(node->fts_path, CONVERT_TIME(node->fts_statp->st_mtim), (node->fts_info & FTS_D) == FTS_D);
|
||||
isRoot = false;
|
||||
}
|
||||
|
||||
fts_close(fts);
|
||||
}
|
||||
77
node_modules/@parcel/watcher/src/unix/legacy.cc
generated
vendored
Normal file
77
node_modules/@parcel/watcher/src/unix/legacy.cc
generated
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
#include <string>
|
||||
|
||||
// weird error on linux
|
||||
#ifdef __THROW
|
||||
#undef __THROW
|
||||
#endif
|
||||
#define __THROW
|
||||
|
||||
#ifdef _LIBC
|
||||
# include <include/sys/stat.h>
|
||||
#else
|
||||
# include <sys/stat.h>
|
||||
#endif
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "../DirTree.hh"
|
||||
#include "../shared/BruteForceBackend.hh"
|
||||
|
||||
#define CONVERT_TIME(ts) ((uint64_t)ts.tv_sec * 1000000000 + ts.tv_nsec)
|
||||
#if __APPLE__
|
||||
#define st_mtim st_mtimespec
|
||||
#endif
|
||||
#define ISDOT(a) (a[0] == '.' && (!a[1] || (a[1] == '.' && !a[2])))
|
||||
|
||||
void iterateDir(WatcherRef watcher, const std::shared_ptr <DirTree> tree, const char *relative, int parent_fd, const std::string &dirname) {
|
||||
int open_flags = (O_RDONLY | O_CLOEXEC | O_DIRECTORY | O_NOCTTY | O_NONBLOCK | O_NOFOLLOW);
|
||||
int new_fd = openat(parent_fd, relative, open_flags);
|
||||
if (new_fd == -1) {
|
||||
if (errno == EACCES) {
|
||||
return; // ignore insufficient permissions
|
||||
}
|
||||
|
||||
throw WatcherError(strerror(errno), watcher);
|
||||
}
|
||||
|
||||
struct stat rootAttributes;
|
||||
fstatat(new_fd, ".", &rootAttributes, AT_SYMLINK_NOFOLLOW);
|
||||
tree->add(dirname, CONVERT_TIME(rootAttributes.st_mtim), true);
|
||||
|
||||
if (DIR *dir = fdopendir(new_fd)) {
|
||||
while (struct dirent *ent = (errno = 0, readdir(dir))) {
|
||||
if (ISDOT(ent->d_name)) continue;
|
||||
|
||||
std::string fullPath = dirname + "/" + ent->d_name;
|
||||
|
||||
if (!watcher->isIgnored(fullPath)) {
|
||||
struct stat attrib;
|
||||
fstatat(new_fd, ent->d_name, &attrib, AT_SYMLINK_NOFOLLOW);
|
||||
bool isDir = ent->d_type == DT_DIR;
|
||||
|
||||
if (isDir) {
|
||||
iterateDir(watcher, tree, ent->d_name, new_fd, fullPath);
|
||||
} else {
|
||||
tree->add(fullPath, CONVERT_TIME(attrib.st_mtim), isDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
} else {
|
||||
close(new_fd);
|
||||
}
|
||||
|
||||
if (errno) {
|
||||
throw WatcherError(strerror(errno), watcher);
|
||||
}
|
||||
}
|
||||
|
||||
void BruteForceBackend::readTree(WatcherRef watcher, std::shared_ptr <DirTree> tree) {
|
||||
int fd = open(watcher->mDir.c_str(), O_RDONLY);
|
||||
if (fd) {
|
||||
iterateDir(watcher, tree, ".", fd, watcher->mDir);
|
||||
close(fd);
|
||||
}
|
||||
}
|
||||
132
node_modules/@parcel/watcher/src/wasm/WasmBackend.cc
generated
vendored
Normal file
132
node_modules/@parcel/watcher/src/wasm/WasmBackend.cc
generated
vendored
Normal file
@@ -0,0 +1,132 @@
|
||||
#include <sys/stat.h>
|
||||
#include "WasmBackend.hh"
|
||||
|
||||
#define CONVERT_TIME(ts) ((uint64_t)ts.tv_sec * 1000000000 + ts.tv_nsec)
|
||||
|
||||
void WasmBackend::start() {
|
||||
notifyStarted();
|
||||
}
|
||||
|
||||
void WasmBackend::subscribe(WatcherRef watcher) {
|
||||
// Build a full directory tree recursively, and watch each directory.
|
||||
std::shared_ptr<DirTree> tree = getTree(watcher);
|
||||
|
||||
for (auto it = tree->entries.begin(); it != tree->entries.end(); it++) {
|
||||
if (it->second.isDir) {
|
||||
watchDir(watcher, it->second.path, tree);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WasmBackend::watchDir(WatcherRef watcher, std::string path, std::shared_ptr<DirTree> tree) {
|
||||
int wd = wasm_backend_add_watch(path.c_str(), (void *)this);
|
||||
std::shared_ptr<WasmSubscription> sub = std::make_shared<WasmSubscription>();
|
||||
sub->tree = tree;
|
||||
sub->path = path;
|
||||
sub->watcher = watcher;
|
||||
mSubscriptions.emplace(wd, sub);
|
||||
}
|
||||
|
||||
extern "C" void wasm_backend_event_handler(void *backend, int wd, int type, char *filename) {
|
||||
WasmBackend *b = (WasmBackend *)(backend);
|
||||
b->handleEvent(wd, type, filename);
|
||||
}
|
||||
|
||||
void WasmBackend::handleEvent(int wd, int type, char *filename) {
|
||||
// Find the subscriptions for this watch descriptor
|
||||
auto range = mSubscriptions.equal_range(wd);
|
||||
std::unordered_set<std::shared_ptr<WasmSubscription>> set;
|
||||
for (auto it = range.first; it != range.second; it++) {
|
||||
set.insert(it->second);
|
||||
}
|
||||
|
||||
for (auto it = set.begin(); it != set.end(); it++) {
|
||||
if (handleSubscription(type, filename, *it)) {
|
||||
(*it)->watcher->notify();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool WasmBackend::handleSubscription(int type, char *filename, std::shared_ptr<WasmSubscription> sub) {
|
||||
// Build full path and check if its in our ignore list.
|
||||
WatcherRef watcher = sub->watcher;
|
||||
std::string path = std::string(sub->path);
|
||||
|
||||
if (filename[0] != '\0') {
|
||||
path += "/" + std::string(filename);
|
||||
}
|
||||
|
||||
if (watcher->isIgnored(path)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (type == 1) {
|
||||
struct stat st;
|
||||
stat(path.c_str(), &st);
|
||||
sub->tree->update(path, CONVERT_TIME(st.st_mtim));
|
||||
watcher->mEvents.update(path);
|
||||
} else if (type == 2) {
|
||||
// Determine if this is a create or delete depending on if the file exists or not.
|
||||
struct stat st;
|
||||
if (lstat(path.c_str(), &st)) {
|
||||
// If the entry being deleted/moved is a directory, remove it from the list of subscriptions
|
||||
DirEntry *entry = sub->tree->find(path);
|
||||
if (!entry) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (entry->isDir) {
|
||||
std::string pathStart = path + DIR_SEP;
|
||||
for (auto it = mSubscriptions.begin(); it != mSubscriptions.end();) {
|
||||
if (it->second->path == path || it->second->path.rfind(pathStart, 0) == 0) {
|
||||
wasm_backend_remove_watch(it->first);
|
||||
it = mSubscriptions.erase(it);
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove all sub-entries
|
||||
for (auto it = sub->tree->entries.begin(); it != sub->tree->entries.end();) {
|
||||
if (it->first.rfind(pathStart, 0) == 0) {
|
||||
watcher->mEvents.remove(it->first);
|
||||
it = sub->tree->entries.erase(it);
|
||||
} else {
|
||||
it++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
watcher->mEvents.remove(path);
|
||||
sub->tree->remove(path);
|
||||
} else if (sub->tree->find(path)) {
|
||||
sub->tree->update(path, CONVERT_TIME(st.st_mtim));
|
||||
watcher->mEvents.update(path);
|
||||
} else {
|
||||
watcher->mEvents.create(path);
|
||||
|
||||
// If this is a create, check if it's a directory and start watching if it is.
|
||||
DirEntry *entry = sub->tree->add(path, CONVERT_TIME(st.st_mtim), S_ISDIR(st.st_mode));
|
||||
if (entry->isDir) {
|
||||
watchDir(watcher, path, sub->tree);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void WasmBackend::unsubscribe(WatcherRef watcher) {
|
||||
// Find any subscriptions pointing to this watcher, and remove them.
|
||||
for (auto it = mSubscriptions.begin(); it != mSubscriptions.end();) {
|
||||
if (it->second->watcher.get() == watcher.get()) {
|
||||
if (mSubscriptions.count(it->first) == 1) {
|
||||
wasm_backend_remove_watch(it->first);
|
||||
}
|
||||
|
||||
it = mSubscriptions.erase(it);
|
||||
} else {
|
||||
it++;
|
||||
}
|
||||
}
|
||||
}
|
||||
34
node_modules/@parcel/watcher/src/wasm/WasmBackend.hh
generated
vendored
Normal file
34
node_modules/@parcel/watcher/src/wasm/WasmBackend.hh
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef WASM_H
|
||||
#define WASM_H
|
||||
|
||||
#include <unordered_map>
|
||||
#include "../shared/BruteForceBackend.hh"
|
||||
#include "../DirTree.hh"
|
||||
|
||||
extern "C" {
|
||||
int wasm_backend_add_watch(const char *filename, void *backend);
|
||||
void wasm_backend_remove_watch(int wd);
|
||||
void wasm_backend_event_handler(void *backend, int wd, int type, char *filename);
|
||||
};
|
||||
|
||||
struct WasmSubscription {
|
||||
std::shared_ptr<DirTree> tree;
|
||||
std::string path;
|
||||
WatcherRef watcher;
|
||||
};
|
||||
|
||||
class WasmBackend : public BruteForceBackend {
|
||||
public:
|
||||
void start() override;
|
||||
void subscribe(WatcherRef watcher) override;
|
||||
void unsubscribe(WatcherRef watcher) override;
|
||||
void handleEvent(int wd, int type, char *filename);
|
||||
private:
|
||||
int mWasm;
|
||||
std::unordered_multimap<int, std::shared_ptr<WasmSubscription>> mSubscriptions;
|
||||
|
||||
void watchDir(WatcherRef watcher, std::string path, std::shared_ptr<DirTree> tree);
|
||||
bool handleSubscription(int type, char *filename, std::shared_ptr<WasmSubscription> sub);
|
||||
};
|
||||
|
||||
#endif
|
||||
74
node_modules/@parcel/watcher/src/wasm/include.h
generated
vendored
Normal file
74
node_modules/@parcel/watcher/src/wasm/include.h
generated
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
Copyright Node.js contributors. All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to
|
||||
deal in the Software without restriction, including without limitation the
|
||||
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
// Node does not include the headers for these functions when compiling for WASM, so add them here.
|
||||
#ifdef __wasm32__
|
||||
extern "C" {
|
||||
NAPI_EXTERN napi_status NAPI_CDECL
|
||||
napi_create_threadsafe_function(napi_env env,
|
||||
napi_value func,
|
||||
napi_value async_resource,
|
||||
napi_value async_resource_name,
|
||||
size_t max_queue_size,
|
||||
size_t initial_thread_count,
|
||||
void* thread_finalize_data,
|
||||
napi_finalize thread_finalize_cb,
|
||||
void* context,
|
||||
napi_threadsafe_function_call_js call_js_cb,
|
||||
napi_threadsafe_function* result);
|
||||
|
||||
NAPI_EXTERN napi_status NAPI_CDECL napi_get_threadsafe_function_context(
|
||||
napi_threadsafe_function func, void** result);
|
||||
|
||||
NAPI_EXTERN napi_status NAPI_CDECL
|
||||
napi_call_threadsafe_function(napi_threadsafe_function func,
|
||||
void* data,
|
||||
napi_threadsafe_function_call_mode is_blocking);
|
||||
|
||||
NAPI_EXTERN napi_status NAPI_CDECL
|
||||
napi_acquire_threadsafe_function(napi_threadsafe_function func);
|
||||
|
||||
NAPI_EXTERN napi_status NAPI_CDECL napi_release_threadsafe_function(
|
||||
napi_threadsafe_function func, napi_threadsafe_function_release_mode mode);
|
||||
|
||||
NAPI_EXTERN napi_status NAPI_CDECL
|
||||
napi_unref_threadsafe_function(napi_env env, napi_threadsafe_function func);
|
||||
|
||||
NAPI_EXTERN napi_status NAPI_CDECL
|
||||
napi_ref_threadsafe_function(napi_env env, napi_threadsafe_function func);
|
||||
|
||||
NAPI_EXTERN napi_status NAPI_CDECL
|
||||
napi_create_async_work(napi_env env,
|
||||
napi_value async_resource,
|
||||
napi_value async_resource_name,
|
||||
napi_async_execute_callback execute,
|
||||
napi_async_complete_callback complete,
|
||||
void* data,
|
||||
napi_async_work* result);
|
||||
NAPI_EXTERN napi_status NAPI_CDECL napi_delete_async_work(napi_env env,
|
||||
napi_async_work work);
|
||||
NAPI_EXTERN napi_status NAPI_CDECL napi_queue_async_work(napi_env env,
|
||||
napi_async_work work);
|
||||
NAPI_EXTERN napi_status NAPI_CDECL napi_cancel_async_work(napi_env env,
|
||||
napi_async_work work);
|
||||
}
|
||||
#endif
|
||||
302
node_modules/@parcel/watcher/src/watchman/BSER.cc
generated
vendored
Normal file
302
node_modules/@parcel/watcher/src/watchman/BSER.cc
generated
vendored
Normal file
@@ -0,0 +1,302 @@
|
||||
#include <stdint.h>
|
||||
#include "./BSER.hh"
|
||||
|
||||
BSERType decodeType(std::istream &iss) {
|
||||
int8_t type;
|
||||
iss.read(reinterpret_cast<char*>(&type), sizeof(type));
|
||||
return (BSERType) type;
|
||||
}
|
||||
|
||||
void expectType(std::istream &iss, BSERType expected) {
|
||||
BSERType got = decodeType(iss);
|
||||
if (got != expected) {
|
||||
throw std::runtime_error("Unexpected BSER type");
|
||||
}
|
||||
}
|
||||
|
||||
void encodeType(std::ostream &oss, BSERType type) {
|
||||
int8_t t = (int8_t)type;
|
||||
oss.write(reinterpret_cast<char*>(&t), sizeof(t));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
class Value : public BSERValue {
|
||||
public:
|
||||
T value;
|
||||
Value(T val) {
|
||||
value = val;
|
||||
}
|
||||
|
||||
Value() {}
|
||||
};
|
||||
|
||||
class BSERInteger : public Value<int64_t> {
|
||||
public:
|
||||
BSERInteger(int64_t value) : Value(value) {}
|
||||
BSERInteger(std::istream &iss) {
|
||||
int8_t int8;
|
||||
int16_t int16;
|
||||
int32_t int32;
|
||||
int64_t int64;
|
||||
|
||||
BSERType type = decodeType(iss);
|
||||
|
||||
switch (type) {
|
||||
case BSER_INT8:
|
||||
iss.read(reinterpret_cast<char*>(&int8), sizeof(int8));
|
||||
value = int8;
|
||||
break;
|
||||
case BSER_INT16:
|
||||
iss.read(reinterpret_cast<char*>(&int16), sizeof(int16));
|
||||
value = int16;
|
||||
break;
|
||||
case BSER_INT32:
|
||||
iss.read(reinterpret_cast<char*>(&int32), sizeof(int32));
|
||||
value = int32;
|
||||
break;
|
||||
case BSER_INT64:
|
||||
iss.read(reinterpret_cast<char*>(&int64), sizeof(int64));
|
||||
value = int64;
|
||||
break;
|
||||
default:
|
||||
throw std::runtime_error("Invalid BSER int type");
|
||||
}
|
||||
}
|
||||
|
||||
int64_t intValue() override {
|
||||
return value;
|
||||
}
|
||||
|
||||
void encode(std::ostream &oss) override {
|
||||
if (value <= INT8_MAX) {
|
||||
encodeType(oss, BSER_INT8);
|
||||
int8_t v = (int8_t)value;
|
||||
oss.write(reinterpret_cast<char*>(&v), sizeof(v));
|
||||
} else if (value <= INT16_MAX) {
|
||||
encodeType(oss, BSER_INT16);
|
||||
int16_t v = (int16_t)value;
|
||||
oss.write(reinterpret_cast<char*>(&v), sizeof(v));
|
||||
} else if (value <= INT32_MAX) {
|
||||
encodeType(oss, BSER_INT32);
|
||||
int32_t v = (int32_t)value;
|
||||
oss.write(reinterpret_cast<char*>(&v), sizeof(v));
|
||||
} else {
|
||||
encodeType(oss, BSER_INT64);
|
||||
oss.write(reinterpret_cast<char*>(&value), sizeof(value));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class BSERArray : public Value<BSER::Array> {
|
||||
public:
|
||||
BSERArray() : Value() {}
|
||||
BSERArray(BSER::Array value) : Value(value) {}
|
||||
BSERArray(std::istream &iss) {
|
||||
expectType(iss, BSER_ARRAY);
|
||||
int64_t len = BSERInteger(iss).intValue();
|
||||
for (int64_t i = 0; i < len; i++) {
|
||||
value.push_back(BSER(iss));
|
||||
}
|
||||
}
|
||||
|
||||
BSER::Array arrayValue() override {
|
||||
return value;
|
||||
}
|
||||
|
||||
void encode(std::ostream &oss) override {
|
||||
encodeType(oss, BSER_ARRAY);
|
||||
BSERInteger(value.size()).encode(oss);
|
||||
for (auto it = value.begin(); it != value.end(); it++) {
|
||||
it->encode(oss);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class BSERString : public Value<std::string> {
|
||||
public:
|
||||
BSERString(std::string value) : Value(value) {}
|
||||
BSERString(std::istream &iss) {
|
||||
expectType(iss, BSER_STRING);
|
||||
int64_t len = BSERInteger(iss).intValue();
|
||||
value.resize(len);
|
||||
iss.read(&value[0], len);
|
||||
}
|
||||
|
||||
std::string stringValue() override {
|
||||
return value;
|
||||
}
|
||||
|
||||
void encode(std::ostream &oss) override {
|
||||
encodeType(oss, BSER_STRING);
|
||||
BSERInteger(value.size()).encode(oss);
|
||||
oss << value;
|
||||
}
|
||||
};
|
||||
|
||||
class BSERObject : public Value<BSER::Object> {
|
||||
public:
|
||||
BSERObject() : Value() {}
|
||||
BSERObject(BSER::Object value) : Value(value) {}
|
||||
BSERObject(std::istream &iss) {
|
||||
expectType(iss, BSER_OBJECT);
|
||||
int64_t len = BSERInteger(iss).intValue();
|
||||
for (int64_t i = 0; i < len; i++) {
|
||||
auto key = BSERString(iss).stringValue();
|
||||
auto val = BSER(iss);
|
||||
value.emplace(key, val);
|
||||
}
|
||||
}
|
||||
|
||||
BSER::Object objectValue() override {
|
||||
return value;
|
||||
}
|
||||
|
||||
void encode(std::ostream &oss) override {
|
||||
encodeType(oss, BSER_OBJECT);
|
||||
BSERInteger(value.size()).encode(oss);
|
||||
for (auto it = value.begin(); it != value.end(); it++) {
|
||||
BSERString(it->first).encode(oss);
|
||||
it->second.encode(oss);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class BSERDouble : public Value<double> {
|
||||
public:
|
||||
BSERDouble(double value) : Value(value) {}
|
||||
BSERDouble(std::istream &iss) {
|
||||
expectType(iss, BSER_REAL);
|
||||
iss.read(reinterpret_cast<char*>(&value), sizeof(value));
|
||||
}
|
||||
|
||||
double doubleValue() override {
|
||||
return value;
|
||||
}
|
||||
|
||||
void encode(std::ostream &oss) override {
|
||||
encodeType(oss, BSER_REAL);
|
||||
oss.write(reinterpret_cast<char*>(&value), sizeof(value));
|
||||
}
|
||||
};
|
||||
|
||||
class BSERBoolean : public Value<bool> {
|
||||
public:
|
||||
BSERBoolean(bool value) : Value(value) {}
|
||||
bool boolValue() override { return value; }
|
||||
void encode(std::ostream &oss) override {
|
||||
int8_t t = value == true ? BSER_BOOL_TRUE : BSER_BOOL_FALSE;
|
||||
oss.write(reinterpret_cast<char*>(&t), sizeof(t));
|
||||
}
|
||||
};
|
||||
|
||||
class BSERNull : public Value<bool> {
|
||||
public:
|
||||
BSERNull() : Value(false) {}
|
||||
void encode(std::ostream &oss) override {
|
||||
encodeType(oss, BSER_NULL);
|
||||
}
|
||||
};
|
||||
|
||||
std::shared_ptr<BSERArray> decodeTemplate(std::istream &iss) {
|
||||
expectType(iss, BSER_TEMPLATE);
|
||||
auto keys = BSERArray(iss).arrayValue();
|
||||
auto len = BSERInteger(iss).intValue();
|
||||
std::shared_ptr<BSERArray> arr = std::make_shared<BSERArray>();
|
||||
for (int64_t i = 0; i < len; i++) {
|
||||
BSER::Object obj;
|
||||
for (auto it = keys.begin(); it != keys.end(); it++) {
|
||||
if (iss.peek() == 0x0c) {
|
||||
iss.ignore(1);
|
||||
continue;
|
||||
}
|
||||
|
||||
auto val = BSER(iss);
|
||||
obj.emplace(it->stringValue(), val);
|
||||
}
|
||||
arr->value.push_back(obj);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
BSER::BSER(std::istream &iss) {
|
||||
BSERType type = decodeType(iss);
|
||||
iss.unget();
|
||||
|
||||
switch (type) {
|
||||
case BSER_ARRAY:
|
||||
m_ptr = std::make_shared<BSERArray>(iss);
|
||||
break;
|
||||
case BSER_OBJECT:
|
||||
m_ptr = std::make_shared<BSERObject>(iss);
|
||||
break;
|
||||
case BSER_STRING:
|
||||
m_ptr = std::make_shared<BSERString>(iss);
|
||||
break;
|
||||
case BSER_INT8:
|
||||
case BSER_INT16:
|
||||
case BSER_INT32:
|
||||
case BSER_INT64:
|
||||
m_ptr = std::make_shared<BSERInteger>(iss);
|
||||
break;
|
||||
case BSER_REAL:
|
||||
m_ptr = std::make_shared<BSERDouble>(iss);
|
||||
break;
|
||||
case BSER_BOOL_TRUE:
|
||||
iss.ignore(1);
|
||||
m_ptr = std::make_shared<BSERBoolean>(true);
|
||||
break;
|
||||
case BSER_BOOL_FALSE:
|
||||
iss.ignore(1);
|
||||
m_ptr = std::make_shared<BSERBoolean>(false);
|
||||
break;
|
||||
case BSER_NULL:
|
||||
iss.ignore(1);
|
||||
m_ptr = std::make_shared<BSERNull>();
|
||||
break;
|
||||
case BSER_TEMPLATE:
|
||||
m_ptr = decodeTemplate(iss);
|
||||
break;
|
||||
default:
|
||||
throw std::runtime_error("unknown BSER type");
|
||||
}
|
||||
}
|
||||
|
||||
BSER::BSER() : m_ptr(std::make_shared<BSERNull>()) {}
|
||||
BSER::BSER(BSER::Array value) : m_ptr(std::make_shared<BSERArray>(value)) {}
|
||||
BSER::BSER(BSER::Object value) : m_ptr(std::make_shared<BSERObject>(value)) {}
|
||||
BSER::BSER(const char *value) : m_ptr(std::make_shared<BSERString>(value)) {}
|
||||
BSER::BSER(std::string value) : m_ptr(std::make_shared<BSERString>(value)) {}
|
||||
BSER::BSER(int64_t value) : m_ptr(std::make_shared<BSERInteger>(value)) {}
|
||||
BSER::BSER(double value) : m_ptr(std::make_shared<BSERDouble>(value)) {}
|
||||
BSER::BSER(bool value) : m_ptr(std::make_shared<BSERBoolean>(value)) {}
|
||||
|
||||
BSER::Array BSER::arrayValue() { return m_ptr->arrayValue(); }
|
||||
BSER::Object BSER::objectValue() { return m_ptr->objectValue(); }
|
||||
std::string BSER::stringValue() { return m_ptr->stringValue(); }
|
||||
int64_t BSER::intValue() { return m_ptr->intValue(); }
|
||||
double BSER::doubleValue() { return m_ptr->doubleValue(); }
|
||||
bool BSER::boolValue() { return m_ptr->boolValue(); }
|
||||
void BSER::encode(std::ostream &oss) {
|
||||
m_ptr->encode(oss);
|
||||
}
|
||||
|
||||
int64_t BSER::decodeLength(std::istream &iss) {
|
||||
char pdu[2];
|
||||
if (!iss.read(pdu, 2) || pdu[0] != 0 || pdu[1] != 1) {
|
||||
throw std::runtime_error("Invalid BSER");
|
||||
}
|
||||
|
||||
return BSERInteger(iss).intValue();
|
||||
}
|
||||
|
||||
std::string BSER::encode() {
|
||||
std::ostringstream oss(std::ios_base::binary);
|
||||
encode(oss);
|
||||
|
||||
std::ostringstream res(std::ios_base::binary);
|
||||
res.write("\x00\x01", 2);
|
||||
|
||||
BSERInteger(oss.str().size()).encode(res);
|
||||
res << oss.str();
|
||||
return res.str();
|
||||
}
|
||||
69
node_modules/@parcel/watcher/src/watchman/BSER.hh
generated
vendored
Normal file
69
node_modules/@parcel/watcher/src/watchman/BSER.hh
generated
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
#ifndef BSER_H
|
||||
#define BSER_H
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include <memory>
|
||||
|
||||
enum BSERType {
|
||||
BSER_ARRAY = 0x00,
|
||||
BSER_OBJECT = 0x01,
|
||||
BSER_STRING = 0x02,
|
||||
BSER_INT8 = 0x03,
|
||||
BSER_INT16 = 0x04,
|
||||
BSER_INT32 = 0x05,
|
||||
BSER_INT64 = 0x06,
|
||||
BSER_REAL = 0x07,
|
||||
BSER_BOOL_TRUE = 0x08,
|
||||
BSER_BOOL_FALSE = 0x09,
|
||||
BSER_NULL = 0x0a,
|
||||
BSER_TEMPLATE = 0x0b
|
||||
};
|
||||
|
||||
class BSERValue;
|
||||
|
||||
class BSER {
|
||||
public:
|
||||
typedef std::vector<BSER> Array;
|
||||
typedef std::unordered_map<std::string, BSER> Object;
|
||||
|
||||
BSER();
|
||||
BSER(BSER::Array value);
|
||||
BSER(BSER::Object value);
|
||||
BSER(std::string value);
|
||||
BSER(const char *value);
|
||||
BSER(int64_t value);
|
||||
BSER(double value);
|
||||
BSER(bool value);
|
||||
BSER(std::istream &iss);
|
||||
|
||||
BSER::Array arrayValue();
|
||||
BSER::Object objectValue();
|
||||
std::string stringValue();
|
||||
int64_t intValue();
|
||||
double doubleValue();
|
||||
bool boolValue();
|
||||
void encode(std::ostream &oss);
|
||||
|
||||
static int64_t decodeLength(std::istream &iss);
|
||||
std::string encode();
|
||||
private:
|
||||
std::shared_ptr<BSERValue> m_ptr;
|
||||
};
|
||||
|
||||
class BSERValue {
|
||||
protected:
|
||||
friend class BSER;
|
||||
virtual BSER::Array arrayValue() { return BSER::Array(); }
|
||||
virtual BSER::Object objectValue() { return BSER::Object(); }
|
||||
virtual std::string stringValue() { return std::string(); }
|
||||
virtual int64_t intValue() { return 0; }
|
||||
virtual double doubleValue() { return 0; }
|
||||
virtual bool boolValue() { return false; }
|
||||
virtual void encode(std::ostream &oss) {}
|
||||
virtual ~BSERValue() {}
|
||||
};
|
||||
|
||||
#endif
|
||||
175
node_modules/@parcel/watcher/src/watchman/IPC.hh
generated
vendored
Normal file
175
node_modules/@parcel/watcher/src/watchman/IPC.hh
generated
vendored
Normal file
@@ -0,0 +1,175 @@
|
||||
#ifndef IPC_H
|
||||
#define IPC_H
|
||||
|
||||
#include <string>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <winsock2.h>
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#endif
|
||||
|
||||
class IPC {
|
||||
public:
|
||||
IPC(std::string path) {
|
||||
mStopped = false;
|
||||
#ifdef _WIN32
|
||||
while (true) {
|
||||
mPipe = CreateFile(
|
||||
path.data(), // pipe name
|
||||
GENERIC_READ | GENERIC_WRITE, // read and write access
|
||||
0, // no sharing
|
||||
NULL, // default security attributes
|
||||
OPEN_EXISTING, // opens existing pipe
|
||||
FILE_FLAG_OVERLAPPED, // attributes
|
||||
NULL // no template file
|
||||
);
|
||||
|
||||
if (mPipe != INVALID_HANDLE_VALUE) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (GetLastError() != ERROR_PIPE_BUSY) {
|
||||
throw std::runtime_error("Could not open pipe");
|
||||
}
|
||||
|
||||
// Wait for pipe to become available if it is busy
|
||||
if (!WaitNamedPipe(path.data(), 30000)) {
|
||||
throw std::runtime_error("Error waiting for pipe");
|
||||
}
|
||||
}
|
||||
|
||||
mReader = CreateEvent(NULL, true, false, NULL);
|
||||
mWriter = CreateEvent(NULL, true, false, NULL);
|
||||
#else
|
||||
struct sockaddr_un addr;
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
addr.sun_family = AF_UNIX;
|
||||
strncpy(addr.sun_path, path.c_str(), sizeof(addr.sun_path) - 1);
|
||||
|
||||
mSock = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (connect(mSock, (struct sockaddr *) &addr, sizeof(struct sockaddr_un))) {
|
||||
throw std::runtime_error("Error connecting to socket");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
~IPC() {
|
||||
mStopped = true;
|
||||
#ifdef _WIN32
|
||||
CancelIo(mPipe);
|
||||
CloseHandle(mPipe);
|
||||
CloseHandle(mReader);
|
||||
CloseHandle(mWriter);
|
||||
#else
|
||||
shutdown(mSock, SHUT_RDWR);
|
||||
#endif
|
||||
}
|
||||
|
||||
void write(std::string buf) {
|
||||
#ifdef _WIN32
|
||||
OVERLAPPED overlapped;
|
||||
overlapped.hEvent = mWriter;
|
||||
bool success = WriteFile(
|
||||
mPipe, // pipe handle
|
||||
buf.data(), // message
|
||||
buf.size(), // message length
|
||||
NULL, // bytes written
|
||||
&overlapped // overlapped
|
||||
);
|
||||
|
||||
if (mStopped) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!success) {
|
||||
if (GetLastError() != ERROR_IO_PENDING) {
|
||||
throw std::runtime_error("Write error");
|
||||
}
|
||||
}
|
||||
|
||||
DWORD written;
|
||||
success = GetOverlappedResult(mPipe, &overlapped, &written, true);
|
||||
if (!success) {
|
||||
throw std::runtime_error("GetOverlappedResult failed");
|
||||
}
|
||||
|
||||
if (written != buf.size()) {
|
||||
throw std::runtime_error("Wrong number of bytes written");
|
||||
}
|
||||
#else
|
||||
int r = 0;
|
||||
for (unsigned int i = 0; i != buf.size(); i += r) {
|
||||
r = ::write(mSock, &buf[i], buf.size() - i);
|
||||
if (r == -1) {
|
||||
if (errno == EAGAIN) {
|
||||
r = 0;
|
||||
} else if (mStopped) {
|
||||
return;
|
||||
} else {
|
||||
throw std::runtime_error("Write error");
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int read(char *buf, size_t len) {
|
||||
#ifdef _WIN32
|
||||
OVERLAPPED overlapped;
|
||||
overlapped.hEvent = mReader;
|
||||
bool success = ReadFile(
|
||||
mPipe, // pipe handle
|
||||
buf, // buffer to receive reply
|
||||
len, // size of buffer
|
||||
NULL, // number of bytes read
|
||||
&overlapped // overlapped
|
||||
);
|
||||
|
||||
if (!success && !mStopped) {
|
||||
if (GetLastError() != ERROR_IO_PENDING) {
|
||||
throw std::runtime_error("Read error");
|
||||
}
|
||||
}
|
||||
|
||||
DWORD read = 0;
|
||||
success = GetOverlappedResult(mPipe, &overlapped, &read, true);
|
||||
if (!success && !mStopped) {
|
||||
throw std::runtime_error("GetOverlappedResult failed");
|
||||
}
|
||||
|
||||
return read;
|
||||
#else
|
||||
int r = ::read(mSock, buf, len);
|
||||
if (r == 0 && !mStopped) {
|
||||
throw std::runtime_error("Socket ended unexpectedly");
|
||||
}
|
||||
|
||||
if (r < 0) {
|
||||
if (mStopped) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
throw std::runtime_error(strerror(errno));
|
||||
}
|
||||
|
||||
return r;
|
||||
#endif
|
||||
}
|
||||
|
||||
private:
|
||||
bool mStopped;
|
||||
#ifdef _WIN32
|
||||
HANDLE mPipe;
|
||||
HANDLE mReader;
|
||||
HANDLE mWriter;
|
||||
#else
|
||||
int mSock;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
||||
338
node_modules/@parcel/watcher/src/watchman/WatchmanBackend.cc
generated
vendored
Normal file
338
node_modules/@parcel/watcher/src/watchman/WatchmanBackend.cc
generated
vendored
Normal file
@@ -0,0 +1,338 @@
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <stdlib.h>
|
||||
#include <algorithm>
|
||||
#include "../DirTree.hh"
|
||||
#include "../Event.hh"
|
||||
#include "./BSER.hh"
|
||||
#include "./WatchmanBackend.hh"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "../windows/win_utils.hh"
|
||||
#define S_ISDIR(mode) ((mode & _S_IFDIR) == _S_IFDIR)
|
||||
#define popen _popen
|
||||
#define pclose _pclose
|
||||
#else
|
||||
#include <sys/stat.h>
|
||||
#define normalizePath(dir) dir
|
||||
#endif
|
||||
|
||||
template<typename T>
|
||||
BSER readBSER(T &&do_read) {
|
||||
std::stringstream oss;
|
||||
char buffer[256];
|
||||
int r;
|
||||
int64_t len = -1;
|
||||
do {
|
||||
// Start by reading a minimal amount of data in order to decode the length.
|
||||
// After that, attempt to read the remaining length, up to the buffer size.
|
||||
r = do_read(buffer, len == -1 ? 20 : (len < 256 ? len : 256));
|
||||
oss << std::string(buffer, r);
|
||||
|
||||
if (len == -1) {
|
||||
uint64_t l = BSER::decodeLength(oss);
|
||||
len = l + oss.tellg();
|
||||
}
|
||||
|
||||
len -= r;
|
||||
} while (len > 0);
|
||||
|
||||
return BSER(oss);
|
||||
}
|
||||
|
||||
std::string getSockPath() {
|
||||
auto var = getenv("WATCHMAN_SOCK");
|
||||
if (var && *var) {
|
||||
return std::string(var);
|
||||
}
|
||||
|
||||
FILE *fp = popen("watchman --output-encoding=bser get-sockname", "r");
|
||||
if (fp == NULL || errno == ECHILD) {
|
||||
throw std::runtime_error("Failed to execute watchman");
|
||||
}
|
||||
|
||||
BSER b = readBSER([fp] (char *buf, size_t len) {
|
||||
return fread(buf, sizeof(char), len, fp);
|
||||
});
|
||||
|
||||
pclose(fp);
|
||||
|
||||
auto objValue = b.objectValue();
|
||||
auto foundSockname = objValue.find("sockname");
|
||||
if (foundSockname == objValue.end()) {
|
||||
throw std::runtime_error("sockname not found");
|
||||
}
|
||||
return foundSockname->second.stringValue();
|
||||
}
|
||||
|
||||
std::unique_ptr<IPC> watchmanConnect() {
|
||||
std::string path = getSockPath();
|
||||
return std::unique_ptr<IPC>(new IPC(path));
|
||||
}
|
||||
|
||||
BSER watchmanRead(IPC *ipc) {
|
||||
return readBSER([ipc] (char *buf, size_t len) {
|
||||
return ipc->read(buf, len);
|
||||
});
|
||||
}
|
||||
|
||||
BSER::Object WatchmanBackend::watchmanRequest(BSER b) {
|
||||
std::string cmd = b.encode();
|
||||
mIPC->write(cmd);
|
||||
mRequestSignal.notify();
|
||||
|
||||
mResponseSignal.wait();
|
||||
mResponseSignal.reset();
|
||||
|
||||
if (!mError.empty()) {
|
||||
std::runtime_error err = std::runtime_error(mError);
|
||||
mError = std::string();
|
||||
throw err;
|
||||
}
|
||||
|
||||
return mResponse;
|
||||
}
|
||||
|
||||
void WatchmanBackend::watchmanWatch(std::string dir) {
|
||||
std::vector<BSER> cmd;
|
||||
cmd.push_back("watch");
|
||||
cmd.push_back(normalizePath(dir));
|
||||
watchmanRequest(cmd);
|
||||
}
|
||||
|
||||
bool WatchmanBackend::checkAvailable() {
|
||||
try {
|
||||
watchmanConnect();
|
||||
return true;
|
||||
} catch (std::exception &err) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void handleFiles(WatcherRef watcher, BSER::Object obj) {
|
||||
auto found = obj.find("files");
|
||||
if (found == obj.end()) {
|
||||
throw WatcherError("Error reading changes from watchman", watcher);
|
||||
}
|
||||
|
||||
auto files = found->second.arrayValue();
|
||||
for (auto it = files.begin(); it != files.end(); it++) {
|
||||
auto file = it->objectValue();
|
||||
auto name = file.find("name")->second.stringValue();
|
||||
#ifdef _WIN32
|
||||
std::replace(name.begin(), name.end(), '/', '\\');
|
||||
#endif
|
||||
auto mode = file.find("mode")->second.intValue();
|
||||
auto isNew = file.find("new")->second.boolValue();
|
||||
auto exists = file.find("exists")->second.boolValue();
|
||||
auto path = watcher->mDir + DIR_SEP + name;
|
||||
if (watcher->isIgnored(path)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isNew && exists) {
|
||||
watcher->mEvents.create(path);
|
||||
} else if (exists && !S_ISDIR(mode)) {
|
||||
watcher->mEvents.update(path);
|
||||
} else if (!isNew && !exists) {
|
||||
watcher->mEvents.remove(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WatchmanBackend::handleSubscription(BSER::Object obj) {
|
||||
std::unique_lock<std::mutex> lock(mMutex);
|
||||
auto subscription = obj.find("subscription")->second.stringValue();
|
||||
auto it = mSubscriptions.find(subscription);
|
||||
if (it == mSubscriptions.end()) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto watcher = it->second;
|
||||
try {
|
||||
handleFiles(watcher, obj);
|
||||
watcher->notify();
|
||||
} catch (WatcherError &err) {
|
||||
handleWatcherError(err);
|
||||
}
|
||||
}
|
||||
|
||||
void WatchmanBackend::start() {
|
||||
mIPC = watchmanConnect();
|
||||
notifyStarted();
|
||||
|
||||
while (true) {
|
||||
// If there are no subscriptions we are reading, wait for a request.
|
||||
if (mSubscriptions.size() == 0) {
|
||||
mRequestSignal.wait();
|
||||
mRequestSignal.reset();
|
||||
}
|
||||
|
||||
// Break out of loop if we are stopped.
|
||||
if (mStopped) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Attempt to read from the socket.
|
||||
// If there is an error and we are stopped, break.
|
||||
BSER b;
|
||||
try {
|
||||
b = watchmanRead(&*mIPC);
|
||||
} catch (std::exception &err) {
|
||||
if (mStopped) {
|
||||
break;
|
||||
} else if (mResponseSignal.isWaiting()) {
|
||||
mError = err.what();
|
||||
mResponseSignal.notify();
|
||||
} else {
|
||||
// Throwing causes the backend to be destroyed, but we never reach the code below to notify the signal
|
||||
mEndedSignal.notify();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
auto obj = b.objectValue();
|
||||
auto error = obj.find("error");
|
||||
if (error != obj.end()) {
|
||||
mError = error->second.stringValue();
|
||||
mResponseSignal.notify();
|
||||
continue;
|
||||
}
|
||||
|
||||
// If this message is for a subscription, handle it, otherwise notify the request.
|
||||
auto subscription = obj.find("subscription");
|
||||
if (subscription != obj.end()) {
|
||||
handleSubscription(obj);
|
||||
} else {
|
||||
mResponse = obj;
|
||||
mResponseSignal.notify();
|
||||
}
|
||||
}
|
||||
|
||||
mEndedSignal.notify();
|
||||
}
|
||||
|
||||
WatchmanBackend::~WatchmanBackend() {
|
||||
// Mark the watcher as stopped, close the socket, and trigger the lock.
|
||||
// This will cause the read loop to be broken and the thread to exit.
|
||||
mStopped = true;
|
||||
mIPC.reset();
|
||||
mRequestSignal.notify();
|
||||
|
||||
// If not ended yet, wait.
|
||||
mEndedSignal.wait();
|
||||
}
|
||||
|
||||
std::string WatchmanBackend::clock(WatcherRef watcher) {
|
||||
BSER::Array cmd;
|
||||
cmd.push_back("clock");
|
||||
cmd.push_back(normalizePath(watcher->mDir));
|
||||
|
||||
BSER::Object obj = watchmanRequest(cmd);
|
||||
auto found = obj.find("clock");
|
||||
if (found == obj.end()) {
|
||||
throw WatcherError("Error reading clock from watchman", watcher);
|
||||
}
|
||||
|
||||
return found->second.stringValue();
|
||||
}
|
||||
|
||||
void WatchmanBackend::writeSnapshot(WatcherRef watcher, std::string *snapshotPath) {
|
||||
std::unique_lock<std::mutex> lock(mMutex);
|
||||
watchmanWatch(watcher->mDir);
|
||||
|
||||
std::ofstream ofs(*snapshotPath);
|
||||
ofs << clock(watcher);
|
||||
}
|
||||
|
||||
void WatchmanBackend::getEventsSince(WatcherRef watcher, std::string *snapshotPath) {
|
||||
std::unique_lock<std::mutex> lock(mMutex);
|
||||
std::ifstream ifs(*snapshotPath);
|
||||
if (ifs.fail()) {
|
||||
return;
|
||||
}
|
||||
|
||||
watchmanWatch(watcher->mDir);
|
||||
|
||||
std::string clock;
|
||||
ifs >> clock;
|
||||
|
||||
BSER::Array cmd;
|
||||
cmd.push_back("since");
|
||||
cmd.push_back(normalizePath(watcher->mDir));
|
||||
cmd.push_back(clock);
|
||||
|
||||
BSER::Object obj = watchmanRequest(cmd);
|
||||
handleFiles(watcher, obj);
|
||||
}
|
||||
|
||||
std::string getId(WatcherRef watcher) {
|
||||
std::ostringstream id;
|
||||
id << "parcel-";
|
||||
id << static_cast<void*>(watcher.get());
|
||||
return id.str();
|
||||
}
|
||||
|
||||
// This function is called by Backend::watch which takes a lock on mMutex
|
||||
void WatchmanBackend::subscribe(WatcherRef watcher) {
|
||||
watchmanWatch(watcher->mDir);
|
||||
|
||||
std::string id = getId(watcher);
|
||||
BSER::Array cmd;
|
||||
cmd.push_back("subscribe");
|
||||
cmd.push_back(normalizePath(watcher->mDir));
|
||||
cmd.push_back(id);
|
||||
|
||||
BSER::Array fields;
|
||||
fields.push_back("name");
|
||||
fields.push_back("mode");
|
||||
fields.push_back("exists");
|
||||
fields.push_back("new");
|
||||
|
||||
BSER::Object opts;
|
||||
opts.emplace("fields", fields);
|
||||
opts.emplace("since", clock(watcher));
|
||||
|
||||
if (watcher->mIgnorePaths.size() > 0) {
|
||||
BSER::Array ignore;
|
||||
BSER::Array anyOf;
|
||||
anyOf.push_back("anyof");
|
||||
|
||||
for (auto it = watcher->mIgnorePaths.begin(); it != watcher->mIgnorePaths.end(); it++) {
|
||||
std::string pathStart = watcher->mDir + DIR_SEP;
|
||||
if (it->rfind(pathStart, 0) == 0) {
|
||||
auto relative = it->substr(pathStart.size());
|
||||
BSER::Array dirname;
|
||||
dirname.push_back("dirname");
|
||||
dirname.push_back(relative);
|
||||
anyOf.push_back(dirname);
|
||||
}
|
||||
}
|
||||
|
||||
ignore.push_back("not");
|
||||
ignore.push_back(anyOf);
|
||||
|
||||
opts.emplace("expression", ignore);
|
||||
}
|
||||
|
||||
cmd.push_back(opts);
|
||||
watchmanRequest(cmd);
|
||||
|
||||
mSubscriptions.emplace(id, watcher);
|
||||
mRequestSignal.notify();
|
||||
}
|
||||
|
||||
// This function is called by Backend::unwatch which takes a lock on mMutex
|
||||
void WatchmanBackend::unsubscribe(WatcherRef watcher) {
|
||||
std::string id = getId(watcher);
|
||||
auto erased = mSubscriptions.erase(id);
|
||||
|
||||
if (erased) {
|
||||
BSER::Array cmd;
|
||||
cmd.push_back("unsubscribe");
|
||||
cmd.push_back(normalizePath(watcher->mDir));
|
||||
cmd.push_back(id);
|
||||
|
||||
watchmanRequest(cmd);
|
||||
}
|
||||
}
|
||||
35
node_modules/@parcel/watcher/src/watchman/WatchmanBackend.hh
generated
vendored
Normal file
35
node_modules/@parcel/watcher/src/watchman/WatchmanBackend.hh
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
#ifndef WATCHMAN_H
|
||||
#define WATCHMAN_H
|
||||
|
||||
#include "../Backend.hh"
|
||||
#include "./BSER.hh"
|
||||
#include "../Signal.hh"
|
||||
#include "./IPC.hh"
|
||||
|
||||
class WatchmanBackend : public Backend {
|
||||
public:
|
||||
static bool checkAvailable();
|
||||
void start() override;
|
||||
WatchmanBackend() : mStopped(false) {};
|
||||
~WatchmanBackend();
|
||||
void writeSnapshot(WatcherRef watcher, std::string *snapshotPath) override;
|
||||
void getEventsSince(WatcherRef watcher, std::string *snapshotPath) override;
|
||||
void subscribe(WatcherRef watcher) override;
|
||||
void unsubscribe(WatcherRef watcher) override;
|
||||
private:
|
||||
std::unique_ptr<IPC> mIPC;
|
||||
Signal mRequestSignal;
|
||||
Signal mResponseSignal;
|
||||
BSER::Object mResponse;
|
||||
std::string mError;
|
||||
std::unordered_map<std::string, WatcherRef> mSubscriptions;
|
||||
bool mStopped;
|
||||
Signal mEndedSignal;
|
||||
|
||||
std::string clock(WatcherRef watcher);
|
||||
void watchmanWatch(std::string dir);
|
||||
BSER::Object watchmanRequest(BSER cmd);
|
||||
void handleSubscription(BSER::Object obj);
|
||||
};
|
||||
|
||||
#endif
|
||||
282
node_modules/@parcel/watcher/src/windows/WindowsBackend.cc
generated
vendored
Normal file
282
node_modules/@parcel/watcher/src/windows/WindowsBackend.cc
generated
vendored
Normal file
@@ -0,0 +1,282 @@
|
||||
#include <string>
|
||||
#include <stack>
|
||||
#include "../DirTree.hh"
|
||||
#include "../shared/BruteForceBackend.hh"
|
||||
#include "./WindowsBackend.hh"
|
||||
#include "./win_utils.hh"
|
||||
|
||||
#define DEFAULT_BUF_SIZE 1024 * 1024
|
||||
#define NETWORK_BUF_SIZE 64 * 1024
|
||||
#define CONVERT_TIME(ft) ULARGE_INTEGER{ft.dwLowDateTime, ft.dwHighDateTime}.QuadPart
|
||||
|
||||
void BruteForceBackend::readTree(WatcherRef watcher, std::shared_ptr<DirTree> tree) {
|
||||
std::stack<std::string> directories;
|
||||
|
||||
directories.push(watcher->mDir);
|
||||
|
||||
while (!directories.empty()) {
|
||||
HANDLE hFind = INVALID_HANDLE_VALUE;
|
||||
|
||||
std::string path = directories.top();
|
||||
std::string spec = path + "\\*";
|
||||
directories.pop();
|
||||
|
||||
WIN32_FIND_DATA ffd;
|
||||
hFind = FindFirstFile(spec.c_str(), &ffd);
|
||||
|
||||
if (hFind == INVALID_HANDLE_VALUE) {
|
||||
if (path == watcher->mDir) {
|
||||
FindClose(hFind);
|
||||
throw WatcherError("Error opening directory", watcher);
|
||||
}
|
||||
|
||||
tree->remove(path);
|
||||
continue;
|
||||
}
|
||||
|
||||
do {
|
||||
if (strcmp(ffd.cFileName, ".") != 0 && strcmp(ffd.cFileName, "..") != 0) {
|
||||
std::string fullPath = path + "\\" + ffd.cFileName;
|
||||
if (watcher->isIgnored(fullPath)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
tree->add(fullPath, CONVERT_TIME(ffd.ftLastWriteTime), ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
|
||||
if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
|
||||
directories.push(fullPath);
|
||||
}
|
||||
}
|
||||
} while (FindNextFile(hFind, &ffd) != 0);
|
||||
|
||||
FindClose(hFind);
|
||||
}
|
||||
}
|
||||
|
||||
void WindowsBackend::start() {
|
||||
mRunning = true;
|
||||
notifyStarted();
|
||||
|
||||
while (mRunning) {
|
||||
SleepEx(INFINITE, true);
|
||||
}
|
||||
}
|
||||
|
||||
WindowsBackend::~WindowsBackend() {
|
||||
// Mark as stopped, and queue a noop function in the thread to break the loop
|
||||
mRunning = false;
|
||||
QueueUserAPC([](__in ULONG_PTR) {}, mThread.native_handle(), (ULONG_PTR)this);
|
||||
}
|
||||
|
||||
class Subscription: public WatcherState {
|
||||
public:
|
||||
Subscription(WindowsBackend *backend, WatcherRef watcher, std::shared_ptr<DirTree> tree) {
|
||||
mRunning = true;
|
||||
mBackend = backend;
|
||||
mWatcher = watcher;
|
||||
mTree = tree;
|
||||
ZeroMemory(&mOverlapped, sizeof(OVERLAPPED));
|
||||
mOverlapped.hEvent = this;
|
||||
mReadBuffer.resize(DEFAULT_BUF_SIZE);
|
||||
mWriteBuffer.resize(DEFAULT_BUF_SIZE);
|
||||
|
||||
mDirectoryHandle = CreateFileW(
|
||||
utf8ToUtf16(watcher->mDir).data(),
|
||||
FILE_LIST_DIRECTORY,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
|
||||
NULL,
|
||||
OPEN_EXISTING,
|
||||
FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED,
|
||||
NULL
|
||||
);
|
||||
|
||||
if (mDirectoryHandle == INVALID_HANDLE_VALUE) {
|
||||
throw WatcherError("Invalid handle", mWatcher);
|
||||
}
|
||||
|
||||
// Ensure that the path is a directory
|
||||
BY_HANDLE_FILE_INFORMATION info;
|
||||
bool success = GetFileInformationByHandle(
|
||||
mDirectoryHandle,
|
||||
&info
|
||||
);
|
||||
|
||||
if (!success) {
|
||||
throw WatcherError("Could not get file information", mWatcher);
|
||||
}
|
||||
|
||||
if (!(info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
|
||||
throw WatcherError("Not a directory", mWatcher);
|
||||
}
|
||||
}
|
||||
|
||||
virtual ~Subscription() {
|
||||
stop();
|
||||
}
|
||||
|
||||
void run() {
|
||||
try {
|
||||
poll();
|
||||
} catch (WatcherError &err) {
|
||||
mBackend->handleWatcherError(err);
|
||||
}
|
||||
}
|
||||
|
||||
void stop() {
|
||||
if (mRunning) {
|
||||
mRunning = false;
|
||||
CancelIo(mDirectoryHandle);
|
||||
CloseHandle(mDirectoryHandle);
|
||||
}
|
||||
}
|
||||
|
||||
void poll() {
|
||||
if (!mRunning) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Asynchronously wait for changes.
|
||||
int success = ReadDirectoryChangesW(
|
||||
mDirectoryHandle,
|
||||
mWriteBuffer.data(),
|
||||
static_cast<DWORD>(mWriteBuffer.size()),
|
||||
TRUE, // recursive
|
||||
FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_DIR_NAME | FILE_NOTIFY_CHANGE_ATTRIBUTES
|
||||
| FILE_NOTIFY_CHANGE_SIZE | FILE_NOTIFY_CHANGE_LAST_WRITE,
|
||||
NULL,
|
||||
&mOverlapped,
|
||||
[](DWORD errorCode, DWORD numBytes, LPOVERLAPPED overlapped) {
|
||||
auto subscription = reinterpret_cast<Subscription *>(overlapped->hEvent);
|
||||
try {
|
||||
subscription->processEvents(errorCode);
|
||||
} catch (WatcherError &err) {
|
||||
subscription->mBackend->handleWatcherError(err);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
if (!success) {
|
||||
throw WatcherError("Failed to read changes", mWatcher);
|
||||
}
|
||||
}
|
||||
|
||||
void processEvents(DWORD errorCode) {
|
||||
if (!mRunning) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (errorCode) {
|
||||
case ERROR_OPERATION_ABORTED:
|
||||
return;
|
||||
case ERROR_INVALID_PARAMETER:
|
||||
// resize buffers to network size (64kb), and try again
|
||||
mReadBuffer.resize(NETWORK_BUF_SIZE);
|
||||
mWriteBuffer.resize(NETWORK_BUF_SIZE);
|
||||
poll();
|
||||
return;
|
||||
case ERROR_NOTIFY_ENUM_DIR:
|
||||
throw WatcherError("Buffer overflow. Some events may have been lost.", mWatcher);
|
||||
case ERROR_ACCESS_DENIED: {
|
||||
// This can happen if the watched directory is deleted. Check if that is the case,
|
||||
// and if so emit a delete event. Otherwise, fall through to default error case.
|
||||
DWORD attrs = GetFileAttributesW(utf8ToUtf16(mWatcher->mDir).data());
|
||||
bool isDir = attrs != INVALID_FILE_ATTRIBUTES && (attrs & FILE_ATTRIBUTE_DIRECTORY);
|
||||
if (!isDir) {
|
||||
mWatcher->mEvents.remove(mWatcher->mDir);
|
||||
mTree->remove(mWatcher->mDir);
|
||||
mWatcher->notify();
|
||||
stop();
|
||||
return;
|
||||
}
|
||||
}
|
||||
default:
|
||||
if (errorCode != ERROR_SUCCESS) {
|
||||
throw WatcherError("Unknown error", mWatcher);
|
||||
}
|
||||
}
|
||||
|
||||
// Swap read and write buffers, and poll again
|
||||
std::swap(mWriteBuffer, mReadBuffer);
|
||||
poll();
|
||||
|
||||
// Read change events
|
||||
BYTE *base = mReadBuffer.data();
|
||||
while (true) {
|
||||
PFILE_NOTIFY_INFORMATION info = (PFILE_NOTIFY_INFORMATION)base;
|
||||
processEvent(info);
|
||||
|
||||
if (info->NextEntryOffset == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
base += info->NextEntryOffset;
|
||||
}
|
||||
|
||||
mWatcher->notify();
|
||||
}
|
||||
|
||||
void processEvent(PFILE_NOTIFY_INFORMATION info) {
|
||||
std::string path = mWatcher->mDir + "\\" + utf16ToUtf8(info->FileName, info->FileNameLength / sizeof(WCHAR));
|
||||
if (mWatcher->isIgnored(path)) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (info->Action) {
|
||||
case FILE_ACTION_ADDED:
|
||||
case FILE_ACTION_RENAMED_NEW_NAME: {
|
||||
WIN32_FILE_ATTRIBUTE_DATA data;
|
||||
if (GetFileAttributesExW(utf8ToUtf16(path).data(), GetFileExInfoStandard, &data)) {
|
||||
mWatcher->mEvents.create(path);
|
||||
mTree->add(path, CONVERT_TIME(data.ftLastWriteTime), data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case FILE_ACTION_MODIFIED: {
|
||||
WIN32_FILE_ATTRIBUTE_DATA data;
|
||||
if (GetFileAttributesExW(utf8ToUtf16(path).data(), GetFileExInfoStandard, &data)) {
|
||||
mTree->update(path, CONVERT_TIME(data.ftLastWriteTime));
|
||||
if (!(data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
|
||||
mWatcher->mEvents.update(path);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case FILE_ACTION_REMOVED:
|
||||
case FILE_ACTION_RENAMED_OLD_NAME:
|
||||
mWatcher->mEvents.remove(path);
|
||||
mTree->remove(path);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
WindowsBackend *mBackend;
|
||||
std::shared_ptr<Watcher> mWatcher;
|
||||
std::shared_ptr<DirTree> mTree;
|
||||
bool mRunning;
|
||||
HANDLE mDirectoryHandle;
|
||||
std::vector<BYTE> mReadBuffer;
|
||||
std::vector<BYTE> mWriteBuffer;
|
||||
OVERLAPPED mOverlapped;
|
||||
};
|
||||
|
||||
// This function is called by Backend::watch which takes a lock on mMutex
|
||||
void WindowsBackend::subscribe(WatcherRef watcher) {
|
||||
// Create a subscription for this watcher
|
||||
auto sub = std::make_shared<Subscription>(this, watcher, getTree(watcher, false));
|
||||
watcher->state = sub;
|
||||
|
||||
// Queue polling for this subscription in the correct thread.
|
||||
bool success = QueueUserAPC([](__in ULONG_PTR ptr) {
|
||||
Subscription *sub = (Subscription *)ptr;
|
||||
sub->run();
|
||||
}, mThread.native_handle(), (ULONG_PTR)sub.get());
|
||||
|
||||
if (!success) {
|
||||
throw std::runtime_error("Unable to queue APC");
|
||||
}
|
||||
}
|
||||
|
||||
// This function is called by Backend::unwatch which takes a lock on mMutex
|
||||
void WindowsBackend::unsubscribe(WatcherRef watcher) {
|
||||
watcher->state = nullptr;
|
||||
}
|
||||
18
node_modules/@parcel/watcher/src/windows/WindowsBackend.hh
generated
vendored
Normal file
18
node_modules/@parcel/watcher/src/windows/WindowsBackend.hh
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef WINDOWS_H
|
||||
#define WINDOWS_H
|
||||
|
||||
#include <winsock2.h>
|
||||
#include <windows.h>
|
||||
#include "../shared/BruteForceBackend.hh"
|
||||
|
||||
class WindowsBackend : public BruteForceBackend {
|
||||
public:
|
||||
void start() override;
|
||||
~WindowsBackend();
|
||||
void subscribe(WatcherRef watcher) override;
|
||||
void unsubscribe(WatcherRef watcher) override;
|
||||
private:
|
||||
bool mRunning;
|
||||
};
|
||||
|
||||
#endif
|
||||
44
node_modules/@parcel/watcher/src/windows/win_utils.cc
generated
vendored
Normal file
44
node_modules/@parcel/watcher/src/windows/win_utils.cc
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
#include "./win_utils.hh"
|
||||
|
||||
std::wstring utf8ToUtf16(std::string input) {
|
||||
unsigned int len = MultiByteToWideChar(CP_UTF8, 0, input.c_str(), -1, NULL, 0);
|
||||
WCHAR *output = new WCHAR[len];
|
||||
MultiByteToWideChar(CP_UTF8, 0, input.c_str(), -1, output, len);
|
||||
std::wstring res(output);
|
||||
delete output;
|
||||
return res;
|
||||
}
|
||||
|
||||
std::string utf16ToUtf8(const WCHAR *input, size_t length) {
|
||||
unsigned int len = WideCharToMultiByte(CP_UTF8, 0, input, length, NULL, 0, NULL, NULL);
|
||||
char *output = new char[len + 1];
|
||||
WideCharToMultiByte(CP_UTF8, 0, input, length, output, len, NULL, NULL);
|
||||
output[len] = '\0';
|
||||
std::string res(output);
|
||||
delete output;
|
||||
return res;
|
||||
}
|
||||
|
||||
std::string normalizePath(std::string path) {
|
||||
// Prevent truncation to MAX_PATH characters by adding the \\?\ prefix
|
||||
std::wstring p = utf8ToUtf16("\\\\?\\" + path);
|
||||
|
||||
// Get the required length for the output
|
||||
unsigned int len = GetLongPathNameW(p.data(), NULL, 0);
|
||||
if (!len) {
|
||||
return path;
|
||||
}
|
||||
|
||||
// Allocate output array and get long path
|
||||
WCHAR *output = new WCHAR[len];
|
||||
len = GetLongPathNameW(p.data(), output, len);
|
||||
if (!len) {
|
||||
delete output;
|
||||
return path;
|
||||
}
|
||||
|
||||
// Convert back to utf8
|
||||
std::string res = utf16ToUtf8(output + 4, len - 4);
|
||||
delete output;
|
||||
return res;
|
||||
}
|
||||
11
node_modules/@parcel/watcher/src/windows/win_utils.hh
generated
vendored
Normal file
11
node_modules/@parcel/watcher/src/windows/win_utils.hh
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
#ifndef WIN_UTILS_H
|
||||
#define WIN_UTILS_H
|
||||
|
||||
#include <string>
|
||||
#include <windows.h>
|
||||
|
||||
std::wstring utf8ToUtf16(std::string input);
|
||||
std::string utf16ToUtf8(const WCHAR *input, size_t length);
|
||||
std::string normalizePath(std::string path);
|
||||
|
||||
#endif
|
||||
77
node_modules/@parcel/watcher/wrapper.js
generated
vendored
Normal file
77
node_modules/@parcel/watcher/wrapper.js
generated
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
const path = require('path');
|
||||
const micromatch = require('micromatch');
|
||||
const isGlob = require('is-glob');
|
||||
|
||||
function normalizeOptions(dir, opts = {}) {
|
||||
const { ignore, ...rest } = opts;
|
||||
|
||||
if (Array.isArray(ignore)) {
|
||||
opts = { ...rest };
|
||||
|
||||
for (const value of ignore) {
|
||||
if (isGlob(value)) {
|
||||
if (!opts.ignoreGlobs) {
|
||||
opts.ignoreGlobs = [];
|
||||
}
|
||||
|
||||
const regex = micromatch.makeRe(value, {
|
||||
// We set `dot: true` to workaround an issue with the
|
||||
// regular expression on Linux where the resulting
|
||||
// negative lookahead `(?!(\\/|^)` was never matching
|
||||
// in some cases. See also https://bit.ly/3UZlQDm
|
||||
dot: true,
|
||||
// C++ does not support lookbehind regex patterns, they
|
||||
// were only added later to JavaScript engines
|
||||
// (https://bit.ly/3V7S6UL)
|
||||
lookbehinds: false
|
||||
});
|
||||
opts.ignoreGlobs.push(regex.source);
|
||||
} else {
|
||||
if (!opts.ignorePaths) {
|
||||
opts.ignorePaths = [];
|
||||
}
|
||||
|
||||
opts.ignorePaths.push(path.resolve(dir, value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return opts;
|
||||
}
|
||||
|
||||
exports.createWrapper = (binding) => {
|
||||
return {
|
||||
writeSnapshot(dir, snapshot, opts) {
|
||||
return binding.writeSnapshot(
|
||||
path.resolve(dir),
|
||||
path.resolve(snapshot),
|
||||
normalizeOptions(dir, opts),
|
||||
);
|
||||
},
|
||||
getEventsSince(dir, snapshot, opts) {
|
||||
return binding.getEventsSince(
|
||||
path.resolve(dir),
|
||||
path.resolve(snapshot),
|
||||
normalizeOptions(dir, opts),
|
||||
);
|
||||
},
|
||||
async subscribe(dir, fn, opts) {
|
||||
dir = path.resolve(dir);
|
||||
opts = normalizeOptions(dir, opts);
|
||||
await binding.subscribe(dir, fn, opts);
|
||||
|
||||
return {
|
||||
unsubscribe() {
|
||||
return binding.unsubscribe(dir, fn, opts);
|
||||
},
|
||||
};
|
||||
},
|
||||
unsubscribe(dir, fn, opts) {
|
||||
return binding.unsubscribe(
|
||||
path.resolve(dir),
|
||||
fn,
|
||||
normalizeOptions(dir, opts),
|
||||
);
|
||||
}
|
||||
};
|
||||
};
|
||||
21
node_modules/braces/LICENSE
generated
vendored
Normal file
21
node_modules/braces/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014-present, Jon Schlinkert.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
586
node_modules/braces/README.md
generated
vendored
Normal file
586
node_modules/braces/README.md
generated
vendored
Normal file
@@ -0,0 +1,586 @@
|
||||
# braces [](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=W8YFZ425KND68) [](https://www.npmjs.com/package/braces) [](https://npmjs.org/package/braces) [](https://npmjs.org/package/braces) [](https://travis-ci.org/micromatch/braces)
|
||||
|
||||
> Bash-like brace expansion, implemented in JavaScript. Safer than other brace expansion libs, with complete support for the Bash 4.3 braces specification, without sacrificing speed.
|
||||
|
||||
Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.
|
||||
|
||||
## Install
|
||||
|
||||
Install with [npm](https://www.npmjs.com/):
|
||||
|
||||
```sh
|
||||
$ npm install --save braces
|
||||
```
|
||||
|
||||
## v3.0.0 Released!!
|
||||
|
||||
See the [changelog](CHANGELOG.md) for details.
|
||||
|
||||
## Why use braces?
|
||||
|
||||
Brace patterns make globs more powerful by adding the ability to match specific ranges and sequences of characters.
|
||||
|
||||
- **Accurate** - complete support for the [Bash 4.3 Brace Expansion](www.gnu.org/software/bash/) specification (passes all of the Bash braces tests)
|
||||
- **[fast and performant](#benchmarks)** - Starts fast, runs fast and [scales well](#performance) as patterns increase in complexity.
|
||||
- **Organized code base** - The parser and compiler are easy to maintain and update when edge cases crop up.
|
||||
- **Well-tested** - Thousands of test assertions, and passes all of the Bash, minimatch, and [brace-expansion](https://github.com/juliangruber/brace-expansion) unit tests (as of the date this was written).
|
||||
- **Safer** - You shouldn't have to worry about users defining aggressive or malicious brace patterns that can break your application. Braces takes measures to prevent malicious regex that can be used for DDoS attacks (see [catastrophic backtracking](https://www.regular-expressions.info/catastrophic.html)).
|
||||
- [Supports lists](#lists) - (aka "sets") `a/{b,c}/d` => `['a/b/d', 'a/c/d']`
|
||||
- [Supports sequences](#sequences) - (aka "ranges") `{01..03}` => `['01', '02', '03']`
|
||||
- [Supports steps](#steps) - (aka "increments") `{2..10..2}` => `['2', '4', '6', '8', '10']`
|
||||
- [Supports escaping](#escaping) - To prevent evaluation of special characters.
|
||||
|
||||
## Usage
|
||||
|
||||
The main export is a function that takes one or more brace `patterns` and `options`.
|
||||
|
||||
```js
|
||||
const braces = require('braces');
|
||||
// braces(patterns[, options]);
|
||||
|
||||
console.log(braces(['{01..05}', '{a..e}']));
|
||||
//=> ['(0[1-5])', '([a-e])']
|
||||
|
||||
console.log(braces(['{01..05}', '{a..e}'], { expand: true }));
|
||||
//=> ['01', '02', '03', '04', '05', 'a', 'b', 'c', 'd', 'e']
|
||||
```
|
||||
|
||||
### Brace Expansion vs. Compilation
|
||||
|
||||
By default, brace patterns are compiled into strings that are optimized for creating regular expressions and matching.
|
||||
|
||||
**Compiled**
|
||||
|
||||
```js
|
||||
console.log(braces('a/{x,y,z}/b'));
|
||||
//=> ['a/(x|y|z)/b']
|
||||
console.log(braces(['a/{01..20}/b', 'a/{1..5}/b']));
|
||||
//=> [ 'a/(0[1-9]|1[0-9]|20)/b', 'a/([1-5])/b' ]
|
||||
```
|
||||
|
||||
**Expanded**
|
||||
|
||||
Enable brace expansion by setting the `expand` option to true, or by using [braces.expand()](#expand) (returns an array similar to what you'd expect from Bash, or `echo {1..5}`, or [minimatch](https://github.com/isaacs/minimatch)):
|
||||
|
||||
```js
|
||||
console.log(braces('a/{x,y,z}/b', { expand: true }));
|
||||
//=> ['a/x/b', 'a/y/b', 'a/z/b']
|
||||
|
||||
console.log(braces.expand('{01..10}'));
|
||||
//=> ['01','02','03','04','05','06','07','08','09','10']
|
||||
```
|
||||
|
||||
### Lists
|
||||
|
||||
Expand lists (like Bash "sets"):
|
||||
|
||||
```js
|
||||
console.log(braces('a/{foo,bar,baz}/*.js'));
|
||||
//=> ['a/(foo|bar|baz)/*.js']
|
||||
|
||||
console.log(braces.expand('a/{foo,bar,baz}/*.js'));
|
||||
//=> ['a/foo/*.js', 'a/bar/*.js', 'a/baz/*.js']
|
||||
```
|
||||
|
||||
### Sequences
|
||||
|
||||
Expand ranges of characters (like Bash "sequences"):
|
||||
|
||||
```js
|
||||
console.log(braces.expand('{1..3}')); // ['1', '2', '3']
|
||||
console.log(braces.expand('a/{1..3}/b')); // ['a/1/b', 'a/2/b', 'a/3/b']
|
||||
console.log(braces('{a..c}', { expand: true })); // ['a', 'b', 'c']
|
||||
console.log(braces('foo/{a..c}', { expand: true })); // ['foo/a', 'foo/b', 'foo/c']
|
||||
|
||||
// supports zero-padded ranges
|
||||
console.log(braces('a/{01..03}/b')); //=> ['a/(0[1-3])/b']
|
||||
console.log(braces('a/{001..300}/b')); //=> ['a/(0{2}[1-9]|0[1-9][0-9]|[12][0-9]{2}|300)/b']
|
||||
```
|
||||
|
||||
See [fill-range](https://github.com/jonschlinkert/fill-range) for all available range-expansion options.
|
||||
|
||||
### Steppped ranges
|
||||
|
||||
Steps, or increments, may be used with ranges:
|
||||
|
||||
```js
|
||||
console.log(braces.expand('{2..10..2}'));
|
||||
//=> ['2', '4', '6', '8', '10']
|
||||
|
||||
console.log(braces('{2..10..2}'));
|
||||
//=> ['(2|4|6|8|10)']
|
||||
```
|
||||
|
||||
When the [.optimize](#optimize) method is used, or [options.optimize](#optionsoptimize) is set to true, sequences are passed to [to-regex-range](https://github.com/jonschlinkert/to-regex-range) for expansion.
|
||||
|
||||
### Nesting
|
||||
|
||||
Brace patterns may be nested. The results of each expanded string are not sorted, and left to right order is preserved.
|
||||
|
||||
**"Expanded" braces**
|
||||
|
||||
```js
|
||||
console.log(braces.expand('a{b,c,/{x,y}}/e'));
|
||||
//=> ['ab/e', 'ac/e', 'a/x/e', 'a/y/e']
|
||||
|
||||
console.log(braces.expand('a/{x,{1..5},y}/c'));
|
||||
//=> ['a/x/c', 'a/1/c', 'a/2/c', 'a/3/c', 'a/4/c', 'a/5/c', 'a/y/c']
|
||||
```
|
||||
|
||||
**"Optimized" braces**
|
||||
|
||||
```js
|
||||
console.log(braces('a{b,c,/{x,y}}/e'));
|
||||
//=> ['a(b|c|/(x|y))/e']
|
||||
|
||||
console.log(braces('a/{x,{1..5},y}/c'));
|
||||
//=> ['a/(x|([1-5])|y)/c']
|
||||
```
|
||||
|
||||
### Escaping
|
||||
|
||||
**Escaping braces**
|
||||
|
||||
A brace pattern will not be expanded or evaluted if _either the opening or closing brace is escaped_:
|
||||
|
||||
```js
|
||||
console.log(braces.expand('a\\{d,c,b}e'));
|
||||
//=> ['a{d,c,b}e']
|
||||
|
||||
console.log(braces.expand('a{d,c,b\\}e'));
|
||||
//=> ['a{d,c,b}e']
|
||||
```
|
||||
|
||||
**Escaping commas**
|
||||
|
||||
Commas inside braces may also be escaped:
|
||||
|
||||
```js
|
||||
console.log(braces.expand('a{b\\,c}d'));
|
||||
//=> ['a{b,c}d']
|
||||
|
||||
console.log(braces.expand('a{d\\,c,b}e'));
|
||||
//=> ['ad,ce', 'abe']
|
||||
```
|
||||
|
||||
**Single items**
|
||||
|
||||
Following bash conventions, a brace pattern is also not expanded when it contains a single character:
|
||||
|
||||
```js
|
||||
console.log(braces.expand('a{b}c'));
|
||||
//=> ['a{b}c']
|
||||
```
|
||||
|
||||
## Options
|
||||
|
||||
### options.maxLength
|
||||
|
||||
**Type**: `Number`
|
||||
|
||||
**Default**: `10,000`
|
||||
|
||||
**Description**: Limit the length of the input string. Useful when the input string is generated or your application allows users to pass a string, et cetera.
|
||||
|
||||
```js
|
||||
console.log(braces('a/{b,c}/d', { maxLength: 3 })); //=> throws an error
|
||||
```
|
||||
|
||||
### options.expand
|
||||
|
||||
**Type**: `Boolean`
|
||||
|
||||
**Default**: `undefined`
|
||||
|
||||
**Description**: Generate an "expanded" brace pattern (alternatively you can use the `braces.expand()` method, which does the same thing).
|
||||
|
||||
```js
|
||||
console.log(braces('a/{b,c}/d', { expand: true }));
|
||||
//=> [ 'a/b/d', 'a/c/d' ]
|
||||
```
|
||||
|
||||
### options.nodupes
|
||||
|
||||
**Type**: `Boolean`
|
||||
|
||||
**Default**: `undefined`
|
||||
|
||||
**Description**: Remove duplicates from the returned array.
|
||||
|
||||
### options.rangeLimit
|
||||
|
||||
**Type**: `Number`
|
||||
|
||||
**Default**: `1000`
|
||||
|
||||
**Description**: To prevent malicious patterns from being passed by users, an error is thrown when `braces.expand()` is used or `options.expand` is true and the generated range will exceed the `rangeLimit`.
|
||||
|
||||
You can customize `options.rangeLimit` or set it to `Inifinity` to disable this altogether.
|
||||
|
||||
**Examples**
|
||||
|
||||
```js
|
||||
// pattern exceeds the "rangeLimit", so it's optimized automatically
|
||||
console.log(braces.expand('{1..1000}'));
|
||||
//=> ['([1-9]|[1-9][0-9]{1,2}|1000)']
|
||||
|
||||
// pattern does not exceed "rangeLimit", so it's NOT optimized
|
||||
console.log(braces.expand('{1..100}'));
|
||||
//=> ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '40', '41', '42', '43', '44', '45', '46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60', '61', '62', '63', '64', '65', '66', '67', '68', '69', '70', '71', '72', '73', '74', '75', '76', '77', '78', '79', '80', '81', '82', '83', '84', '85', '86', '87', '88', '89', '90', '91', '92', '93', '94', '95', '96', '97', '98', '99', '100']
|
||||
```
|
||||
|
||||
### options.transform
|
||||
|
||||
**Type**: `Function`
|
||||
|
||||
**Default**: `undefined`
|
||||
|
||||
**Description**: Customize range expansion.
|
||||
|
||||
**Example: Transforming non-numeric values**
|
||||
|
||||
```js
|
||||
const alpha = braces.expand('x/{a..e}/y', {
|
||||
transform(value, index) {
|
||||
// When non-numeric values are passed, "value" is a character code.
|
||||
return 'foo/' + String.fromCharCode(value) + '-' + index;
|
||||
},
|
||||
});
|
||||
console.log(alpha);
|
||||
//=> [ 'x/foo/a-0/y', 'x/foo/b-1/y', 'x/foo/c-2/y', 'x/foo/d-3/y', 'x/foo/e-4/y' ]
|
||||
```
|
||||
|
||||
**Example: Transforming numeric values**
|
||||
|
||||
```js
|
||||
const numeric = braces.expand('{1..5}', {
|
||||
transform(value) {
|
||||
// when numeric values are passed, "value" is a number
|
||||
return 'foo/' + value * 2;
|
||||
},
|
||||
});
|
||||
console.log(numeric);
|
||||
//=> [ 'foo/2', 'foo/4', 'foo/6', 'foo/8', 'foo/10' ]
|
||||
```
|
||||
|
||||
### options.quantifiers
|
||||
|
||||
**Type**: `Boolean`
|
||||
|
||||
**Default**: `undefined`
|
||||
|
||||
**Description**: In regular expressions, quanitifiers can be used to specify how many times a token can be repeated. For example, `a{1,3}` will match the letter `a` one to three times.
|
||||
|
||||
Unfortunately, regex quantifiers happen to share the same syntax as [Bash lists](#lists)
|
||||
|
||||
The `quantifiers` option tells braces to detect when [regex quantifiers](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#quantifiers) are defined in the given pattern, and not to try to expand them as lists.
|
||||
|
||||
**Examples**
|
||||
|
||||
```js
|
||||
const braces = require('braces');
|
||||
console.log(braces('a/b{1,3}/{x,y,z}'));
|
||||
//=> [ 'a/b(1|3)/(x|y|z)' ]
|
||||
console.log(braces('a/b{1,3}/{x,y,z}', { quantifiers: true }));
|
||||
//=> [ 'a/b{1,3}/(x|y|z)' ]
|
||||
console.log(braces('a/b{1,3}/{x,y,z}', { quantifiers: true, expand: true }));
|
||||
//=> [ 'a/b{1,3}/x', 'a/b{1,3}/y', 'a/b{1,3}/z' ]
|
||||
```
|
||||
|
||||
### options.keepEscaping
|
||||
|
||||
**Type**: `Boolean`
|
||||
|
||||
**Default**: `undefined`
|
||||
|
||||
**Description**: Do not strip backslashes that were used for escaping from the result.
|
||||
|
||||
## What is "brace expansion"?
|
||||
|
||||
Brace expansion is a type of parameter expansion that was made popular by unix shells for generating lists of strings, as well as regex-like matching when used alongside wildcards (globs).
|
||||
|
||||
In addition to "expansion", braces are also used for matching. In other words:
|
||||
|
||||
- [brace expansion](#brace-expansion) is for generating new lists
|
||||
- [brace matching](#brace-matching) is for filtering existing lists
|
||||
|
||||
<details>
|
||||
<summary><strong>More about brace expansion</strong> (click to expand)</summary>
|
||||
|
||||
There are two main types of brace expansion:
|
||||
|
||||
1. **lists**: which are defined using comma-separated values inside curly braces: `{a,b,c}`
|
||||
2. **sequences**: which are defined using a starting value and an ending value, separated by two dots: `a{1..3}b`. Optionally, a third argument may be passed to define a "step" or increment to use: `a{1..100..10}b`. These are also sometimes referred to as "ranges".
|
||||
|
||||
Here are some example brace patterns to illustrate how they work:
|
||||
|
||||
**Sets**
|
||||
|
||||
```
|
||||
{a,b,c} => a b c
|
||||
{a,b,c}{1,2} => a1 a2 b1 b2 c1 c2
|
||||
```
|
||||
|
||||
**Sequences**
|
||||
|
||||
```
|
||||
{1..9} => 1 2 3 4 5 6 7 8 9
|
||||
{4..-4} => 4 3 2 1 0 -1 -2 -3 -4
|
||||
{1..20..3} => 1 4 7 10 13 16 19
|
||||
{a..j} => a b c d e f g h i j
|
||||
{j..a} => j i h g f e d c b a
|
||||
{a..z..3} => a d g j m p s v y
|
||||
```
|
||||
|
||||
**Combination**
|
||||
|
||||
Sets and sequences can be mixed together or used along with any other strings.
|
||||
|
||||
```
|
||||
{a,b,c}{1..3} => a1 a2 a3 b1 b2 b3 c1 c2 c3
|
||||
foo/{a,b,c}/bar => foo/a/bar foo/b/bar foo/c/bar
|
||||
```
|
||||
|
||||
The fact that braces can be "expanded" from relatively simple patterns makes them ideal for quickly generating test fixtures, file paths, and similar use cases.
|
||||
|
||||
## Brace matching
|
||||
|
||||
In addition to _expansion_, brace patterns are also useful for performing regular-expression-like matching.
|
||||
|
||||
For example, the pattern `foo/{1..3}/bar` would match any of following strings:
|
||||
|
||||
```
|
||||
foo/1/bar
|
||||
foo/2/bar
|
||||
foo/3/bar
|
||||
```
|
||||
|
||||
But not:
|
||||
|
||||
```
|
||||
baz/1/qux
|
||||
baz/2/qux
|
||||
baz/3/qux
|
||||
```
|
||||
|
||||
Braces can also be combined with [glob patterns](https://github.com/jonschlinkert/micromatch) to perform more advanced wildcard matching. For example, the pattern `*/{1..3}/*` would match any of following strings:
|
||||
|
||||
```
|
||||
foo/1/bar
|
||||
foo/2/bar
|
||||
foo/3/bar
|
||||
baz/1/qux
|
||||
baz/2/qux
|
||||
baz/3/qux
|
||||
```
|
||||
|
||||
## Brace matching pitfalls
|
||||
|
||||
Although brace patterns offer a user-friendly way of matching ranges or sets of strings, there are also some major disadvantages and potential risks you should be aware of.
|
||||
|
||||
### tldr
|
||||
|
||||
**"brace bombs"**
|
||||
|
||||
- brace expansion can eat up a huge amount of processing resources
|
||||
- as brace patterns increase _linearly in size_, the system resources required to expand the pattern increase exponentially
|
||||
- users can accidentally (or intentially) exhaust your system's resources resulting in the equivalent of a DoS attack (bonus: no programming knowledge is required!)
|
||||
|
||||
For a more detailed explanation with examples, see the [geometric complexity](#geometric-complexity) section.
|
||||
|
||||
### The solution
|
||||
|
||||
Jump to the [performance section](#performance) to see how Braces solves this problem in comparison to other libraries.
|
||||
|
||||
### Geometric complexity
|
||||
|
||||
At minimum, brace patterns with sets limited to two elements have quadradic or `O(n^2)` complexity. But the complexity of the algorithm increases exponentially as the number of sets, _and elements per set_, increases, which is `O(n^c)`.
|
||||
|
||||
For example, the following sets demonstrate quadratic (`O(n^2)`) complexity:
|
||||
|
||||
```
|
||||
{1,2}{3,4} => (2X2) => 13 14 23 24
|
||||
{1,2}{3,4}{5,6} => (2X2X2) => 135 136 145 146 235 236 245 246
|
||||
```
|
||||
|
||||
But add an element to a set, and we get a n-fold Cartesian product with `O(n^c)` complexity:
|
||||
|
||||
```
|
||||
{1,2,3}{4,5,6}{7,8,9} => (3X3X3) => 147 148 149 157 158 159 167 168 169 247 248
|
||||
249 257 258 259 267 268 269 347 348 349 357
|
||||
358 359 367 368 369
|
||||
```
|
||||
|
||||
Now, imagine how this complexity grows given that each element is a n-tuple:
|
||||
|
||||
```
|
||||
{1..100}{1..100} => (100X100) => 10,000 elements (38.4 kB)
|
||||
{1..100}{1..100}{1..100} => (100X100X100) => 1,000,000 elements (5.76 MB)
|
||||
```
|
||||
|
||||
Although these examples are clearly contrived, they demonstrate how brace patterns can quickly grow out of control.
|
||||
|
||||
**More information**
|
||||
|
||||
Interested in learning more about brace expansion?
|
||||
|
||||
- [linuxjournal/bash-brace-expansion](http://www.linuxjournal.com/content/bash-brace-expansion)
|
||||
- [rosettacode/Brace_expansion](https://rosettacode.org/wiki/Brace_expansion)
|
||||
- [cartesian product](https://en.wikipedia.org/wiki/Cartesian_product)
|
||||
|
||||
</details>
|
||||
|
||||
## Performance
|
||||
|
||||
Braces is not only screaming fast, it's also more accurate the other brace expansion libraries.
|
||||
|
||||
### Better algorithms
|
||||
|
||||
Fortunately there is a solution to the ["brace bomb" problem](#brace-matching-pitfalls): _don't expand brace patterns into an array when they're used for matching_.
|
||||
|
||||
Instead, convert the pattern into an optimized regular expression. This is easier said than done, and braces is the only library that does this currently.
|
||||
|
||||
**The proof is in the numbers**
|
||||
|
||||
Minimatch gets exponentially slower as patterns increase in complexity, braces does not. The following results were generated using `braces()` and `minimatch.braceExpand()`, respectively.
|
||||
|
||||
| **Pattern** | **braces** | **[minimatch][]** |
|
||||
| --------------------------- | ------------------- | ---------------------------- |
|
||||
| `{1..9007199254740991}`[^1] | `298 B` (5ms 459μs) | N/A (freezes) |
|
||||
| `{1..1000000000000000}` | `41 B` (1ms 15μs) | N/A (freezes) |
|
||||
| `{1..100000000000000}` | `40 B` (890μs) | N/A (freezes) |
|
||||
| `{1..10000000000000}` | `39 B` (2ms 49μs) | N/A (freezes) |
|
||||
| `{1..1000000000000}` | `38 B` (608μs) | N/A (freezes) |
|
||||
| `{1..100000000000}` | `37 B` (397μs) | N/A (freezes) |
|
||||
| `{1..10000000000}` | `35 B` (983μs) | N/A (freezes) |
|
||||
| `{1..1000000000}` | `34 B` (798μs) | N/A (freezes) |
|
||||
| `{1..100000000}` | `33 B` (733μs) | N/A (freezes) |
|
||||
| `{1..10000000}` | `32 B` (5ms 632μs) | `78.89 MB` (16s 388ms 569μs) |
|
||||
| `{1..1000000}` | `31 B` (1ms 381μs) | `6.89 MB` (1s 496ms 887μs) |
|
||||
| `{1..100000}` | `30 B` (950μs) | `588.89 kB` (146ms 921μs) |
|
||||
| `{1..10000}` | `29 B` (1ms 114μs) | `48.89 kB` (14ms 187μs) |
|
||||
| `{1..1000}` | `28 B` (760μs) | `3.89 kB` (1ms 453μs) |
|
||||
| `{1..100}` | `22 B` (345μs) | `291 B` (196μs) |
|
||||
| `{1..10}` | `10 B` (533μs) | `20 B` (37μs) |
|
||||
| `{1..3}` | `7 B` (190μs) | `5 B` (27μs) |
|
||||
|
||||
### Faster algorithms
|
||||
|
||||
When you need expansion, braces is still much faster.
|
||||
|
||||
_(the following results were generated using `braces.expand()` and `minimatch.braceExpand()`, respectively)_
|
||||
|
||||
| **Pattern** | **braces** | **[minimatch][]** |
|
||||
| --------------- | --------------------------- | ---------------------------- |
|
||||
| `{1..10000000}` | `78.89 MB` (2s 698ms 642μs) | `78.89 MB` (18s 601ms 974μs) |
|
||||
| `{1..1000000}` | `6.89 MB` (458ms 576μs) | `6.89 MB` (1s 491ms 621μs) |
|
||||
| `{1..100000}` | `588.89 kB` (20ms 728μs) | `588.89 kB` (156ms 919μs) |
|
||||
| `{1..10000}` | `48.89 kB` (2ms 202μs) | `48.89 kB` (13ms 641μs) |
|
||||
| `{1..1000}` | `3.89 kB` (1ms 796μs) | `3.89 kB` (1ms 958μs) |
|
||||
| `{1..100}` | `291 B` (424μs) | `291 B` (211μs) |
|
||||
| `{1..10}` | `20 B` (487μs) | `20 B` (72μs) |
|
||||
| `{1..3}` | `5 B` (166μs) | `5 B` (27μs) |
|
||||
|
||||
If you'd like to run these comparisons yourself, see [test/support/generate.js](test/support/generate.js).
|
||||
|
||||
## Benchmarks
|
||||
|
||||
### Running benchmarks
|
||||
|
||||
Install dev dependencies:
|
||||
|
||||
```bash
|
||||
npm i -d && npm benchmark
|
||||
```
|
||||
|
||||
### Latest results
|
||||
|
||||
Braces is more accurate, without sacrificing performance.
|
||||
|
||||
```bash
|
||||
● expand - range (expanded)
|
||||
braces x 53,167 ops/sec ±0.12% (102 runs sampled)
|
||||
minimatch x 11,378 ops/sec ±0.10% (102 runs sampled)
|
||||
● expand - range (optimized for regex)
|
||||
braces x 373,442 ops/sec ±0.04% (100 runs sampled)
|
||||
minimatch x 3,262 ops/sec ±0.18% (100 runs sampled)
|
||||
● expand - nested ranges (expanded)
|
||||
braces x 33,921 ops/sec ±0.09% (99 runs sampled)
|
||||
minimatch x 10,855 ops/sec ±0.28% (100 runs sampled)
|
||||
● expand - nested ranges (optimized for regex)
|
||||
braces x 287,479 ops/sec ±0.52% (98 runs sampled)
|
||||
minimatch x 3,219 ops/sec ±0.28% (101 runs sampled)
|
||||
● expand - set (expanded)
|
||||
braces x 238,243 ops/sec ±0.19% (97 runs sampled)
|
||||
minimatch x 538,268 ops/sec ±0.31% (96 runs sampled)
|
||||
● expand - set (optimized for regex)
|
||||
braces x 321,844 ops/sec ±0.10% (97 runs sampled)
|
||||
minimatch x 140,600 ops/sec ±0.15% (100 runs sampled)
|
||||
● expand - nested sets (expanded)
|
||||
braces x 165,371 ops/sec ±0.42% (96 runs sampled)
|
||||
minimatch x 337,720 ops/sec ±0.28% (100 runs sampled)
|
||||
● expand - nested sets (optimized for regex)
|
||||
braces x 242,948 ops/sec ±0.12% (99 runs sampled)
|
||||
minimatch x 87,403 ops/sec ±0.79% (96 runs sampled)
|
||||
```
|
||||
|
||||
## About
|
||||
|
||||
<details>
|
||||
<summary><strong>Contributing</strong></summary>
|
||||
|
||||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><strong>Running Tests</strong></summary>
|
||||
|
||||
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
|
||||
|
||||
```sh
|
||||
$ npm install && npm test
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><strong>Building docs</strong></summary>
|
||||
|
||||
_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
|
||||
|
||||
To generate the readme, run the following command:
|
||||
|
||||
```sh
|
||||
$ npm install -g verbose/verb#dev verb-generate-readme && verb
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
### Contributors
|
||||
|
||||
| **Commits** | **Contributor** |
|
||||
| ----------- | ------------------------------------------------------------- |
|
||||
| 197 | [jonschlinkert](https://github.com/jonschlinkert) |
|
||||
| 4 | [doowb](https://github.com/doowb) |
|
||||
| 1 | [es128](https://github.com/es128) |
|
||||
| 1 | [eush77](https://github.com/eush77) |
|
||||
| 1 | [hemanth](https://github.com/hemanth) |
|
||||
| 1 | [wtgtybhertgeghgtwtg](https://github.com/wtgtybhertgeghgtwtg) |
|
||||
|
||||
### Author
|
||||
|
||||
**Jon Schlinkert**
|
||||
|
||||
- [GitHub Profile](https://github.com/jonschlinkert)
|
||||
- [Twitter Profile](https://twitter.com/jonschlinkert)
|
||||
- [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)
|
||||
|
||||
### License
|
||||
|
||||
Copyright © 2019, [Jon Schlinkert](https://github.com/jonschlinkert).
|
||||
Released under the [MIT License](LICENSE).
|
||||
|
||||
---
|
||||
|
||||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on April 08, 2019._
|
||||
170
node_modules/braces/index.js
generated
vendored
Normal file
170
node_modules/braces/index.js
generated
vendored
Normal file
@@ -0,0 +1,170 @@
|
||||
'use strict';
|
||||
|
||||
const stringify = require('./lib/stringify');
|
||||
const compile = require('./lib/compile');
|
||||
const expand = require('./lib/expand');
|
||||
const parse = require('./lib/parse');
|
||||
|
||||
/**
|
||||
* Expand the given pattern or create a regex-compatible string.
|
||||
*
|
||||
* ```js
|
||||
* const braces = require('braces');
|
||||
* console.log(braces('{a,b,c}', { compile: true })); //=> ['(a|b|c)']
|
||||
* console.log(braces('{a,b,c}')); //=> ['a', 'b', 'c']
|
||||
* ```
|
||||
* @param {String} `str`
|
||||
* @param {Object} `options`
|
||||
* @return {String}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
const braces = (input, options = {}) => {
|
||||
let output = [];
|
||||
|
||||
if (Array.isArray(input)) {
|
||||
for (const pattern of input) {
|
||||
const result = braces.create(pattern, options);
|
||||
if (Array.isArray(result)) {
|
||||
output.push(...result);
|
||||
} else {
|
||||
output.push(result);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
output = [].concat(braces.create(input, options));
|
||||
}
|
||||
|
||||
if (options && options.expand === true && options.nodupes === true) {
|
||||
output = [...new Set(output)];
|
||||
}
|
||||
return output;
|
||||
};
|
||||
|
||||
/**
|
||||
* Parse the given `str` with the given `options`.
|
||||
*
|
||||
* ```js
|
||||
* // braces.parse(pattern, [, options]);
|
||||
* const ast = braces.parse('a/{b,c}/d');
|
||||
* console.log(ast);
|
||||
* ```
|
||||
* @param {String} pattern Brace pattern to parse
|
||||
* @param {Object} options
|
||||
* @return {Object} Returns an AST
|
||||
* @api public
|
||||
*/
|
||||
|
||||
braces.parse = (input, options = {}) => parse(input, options);
|
||||
|
||||
/**
|
||||
* Creates a braces string from an AST, or an AST node.
|
||||
*
|
||||
* ```js
|
||||
* const braces = require('braces');
|
||||
* let ast = braces.parse('foo/{a,b}/bar');
|
||||
* console.log(stringify(ast.nodes[2])); //=> '{a,b}'
|
||||
* ```
|
||||
* @param {String} `input` Brace pattern or AST.
|
||||
* @param {Object} `options`
|
||||
* @return {Array} Returns an array of expanded values.
|
||||
* @api public
|
||||
*/
|
||||
|
||||
braces.stringify = (input, options = {}) => {
|
||||
if (typeof input === 'string') {
|
||||
return stringify(braces.parse(input, options), options);
|
||||
}
|
||||
return stringify(input, options);
|
||||
};
|
||||
|
||||
/**
|
||||
* Compiles a brace pattern into a regex-compatible, optimized string.
|
||||
* This method is called by the main [braces](#braces) function by default.
|
||||
*
|
||||
* ```js
|
||||
* const braces = require('braces');
|
||||
* console.log(braces.compile('a/{b,c}/d'));
|
||||
* //=> ['a/(b|c)/d']
|
||||
* ```
|
||||
* @param {String} `input` Brace pattern or AST.
|
||||
* @param {Object} `options`
|
||||
* @return {Array} Returns an array of expanded values.
|
||||
* @api public
|
||||
*/
|
||||
|
||||
braces.compile = (input, options = {}) => {
|
||||
if (typeof input === 'string') {
|
||||
input = braces.parse(input, options);
|
||||
}
|
||||
return compile(input, options);
|
||||
};
|
||||
|
||||
/**
|
||||
* Expands a brace pattern into an array. This method is called by the
|
||||
* main [braces](#braces) function when `options.expand` is true. Before
|
||||
* using this method it's recommended that you read the [performance notes](#performance))
|
||||
* and advantages of using [.compile](#compile) instead.
|
||||
*
|
||||
* ```js
|
||||
* const braces = require('braces');
|
||||
* console.log(braces.expand('a/{b,c}/d'));
|
||||
* //=> ['a/b/d', 'a/c/d'];
|
||||
* ```
|
||||
* @param {String} `pattern` Brace pattern
|
||||
* @param {Object} `options`
|
||||
* @return {Array} Returns an array of expanded values.
|
||||
* @api public
|
||||
*/
|
||||
|
||||
braces.expand = (input, options = {}) => {
|
||||
if (typeof input === 'string') {
|
||||
input = braces.parse(input, options);
|
||||
}
|
||||
|
||||
let result = expand(input, options);
|
||||
|
||||
// filter out empty strings if specified
|
||||
if (options.noempty === true) {
|
||||
result = result.filter(Boolean);
|
||||
}
|
||||
|
||||
// filter out duplicates if specified
|
||||
if (options.nodupes === true) {
|
||||
result = [...new Set(result)];
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* Processes a brace pattern and returns either an expanded array
|
||||
* (if `options.expand` is true), a highly optimized regex-compatible string.
|
||||
* This method is called by the main [braces](#braces) function.
|
||||
*
|
||||
* ```js
|
||||
* const braces = require('braces');
|
||||
* console.log(braces.create('user-{200..300}/project-{a,b,c}-{1..10}'))
|
||||
* //=> 'user-(20[0-9]|2[1-9][0-9]|300)/project-(a|b|c)-([1-9]|10)'
|
||||
* ```
|
||||
* @param {String} `pattern` Brace pattern
|
||||
* @param {Object} `options`
|
||||
* @return {Array} Returns an array of expanded values.
|
||||
* @api public
|
||||
*/
|
||||
|
||||
braces.create = (input, options = {}) => {
|
||||
if (input === '' || input.length < 3) {
|
||||
return [input];
|
||||
}
|
||||
|
||||
return options.expand !== true
|
||||
? braces.compile(input, options)
|
||||
: braces.expand(input, options);
|
||||
};
|
||||
|
||||
/**
|
||||
* Expose "braces"
|
||||
*/
|
||||
|
||||
module.exports = braces;
|
||||
77
node_modules/braces/package.json
generated
vendored
Normal file
77
node_modules/braces/package.json
generated
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
{
|
||||
"name": "braces",
|
||||
"description": "Bash-like brace expansion, implemented in JavaScript. Safer than other brace expansion libs, with complete support for the Bash 4.3 braces specification, without sacrificing speed.",
|
||||
"version": "3.0.3",
|
||||
"homepage": "https://github.com/micromatch/braces",
|
||||
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
|
||||
"contributors": [
|
||||
"Brian Woodward (https://twitter.com/doowb)",
|
||||
"Elan Shanker (https://github.com/es128)",
|
||||
"Eugene Sharygin (https://github.com/eush77)",
|
||||
"hemanth.hm (http://h3manth.com)",
|
||||
"Jon Schlinkert (http://twitter.com/jonschlinkert)"
|
||||
],
|
||||
"repository": "micromatch/braces",
|
||||
"bugs": {
|
||||
"url": "https://github.com/micromatch/braces/issues"
|
||||
},
|
||||
"license": "MIT",
|
||||
"files": [
|
||||
"index.js",
|
||||
"lib"
|
||||
],
|
||||
"main": "index.js",
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha",
|
||||
"benchmark": "node benchmark"
|
||||
},
|
||||
"dependencies": {
|
||||
"fill-range": "^7.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ansi-colors": "^3.2.4",
|
||||
"bash-path": "^2.0.1",
|
||||
"gulp-format-md": "^2.0.0",
|
||||
"mocha": "^6.1.1"
|
||||
},
|
||||
"keywords": [
|
||||
"alpha",
|
||||
"alphabetical",
|
||||
"bash",
|
||||
"brace",
|
||||
"braces",
|
||||
"expand",
|
||||
"expansion",
|
||||
"filepath",
|
||||
"fill",
|
||||
"fs",
|
||||
"glob",
|
||||
"globbing",
|
||||
"letter",
|
||||
"match",
|
||||
"matches",
|
||||
"matching",
|
||||
"number",
|
||||
"numerical",
|
||||
"path",
|
||||
"range",
|
||||
"ranges",
|
||||
"sh"
|
||||
],
|
||||
"verb": {
|
||||
"toc": false,
|
||||
"layout": "default",
|
||||
"tasks": [
|
||||
"readme"
|
||||
],
|
||||
"lint": {
|
||||
"reflinks": true
|
||||
},
|
||||
"plugins": [
|
||||
"gulp-format-md"
|
||||
]
|
||||
}
|
||||
}
|
||||
21
node_modules/chokidar/LICENSE
generated
vendored
Normal file
21
node_modules/chokidar/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2012 Paul Miller (https://paulmillr.com), Elan Shanker
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the “Software”), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
305
node_modules/chokidar/README.md
generated
vendored
Normal file
305
node_modules/chokidar/README.md
generated
vendored
Normal file
@@ -0,0 +1,305 @@
|
||||
# Chokidar [](https://github.com/paulmillr/chokidar)
|
||||
|
||||
> Minimal and efficient cross-platform file watching library
|
||||
|
||||
## Why?
|
||||
|
||||
There are many reasons to prefer Chokidar to raw fs.watch / fs.watchFile in 2024:
|
||||
|
||||
- Events are properly reported
|
||||
- macOS events report filenames
|
||||
- events are not reported twice
|
||||
- changes are reported as add / change / unlink instead of useless `rename`
|
||||
- Atomic writes are supported, using `atomic` option
|
||||
- Some file editors use them
|
||||
- Chunked writes are supported, using `awaitWriteFinish` option
|
||||
- Large files are commonly written in chunks
|
||||
- File / dir filtering is supported
|
||||
- Symbolic links are supported
|
||||
- Recursive watching is always supported, instead of partial when using raw events
|
||||
- Includes a way to limit recursion depth
|
||||
|
||||
Chokidar relies on the Node.js core `fs` module, but when using
|
||||
`fs.watch` and `fs.watchFile` for watching, it normalizes the events it
|
||||
receives, often checking for truth by getting file stats and/or dir contents.
|
||||
The `fs.watch`-based implementation is the default, which
|
||||
avoids polling and keeps CPU usage down. Be advised that chokidar will initiate
|
||||
watchers recursively for everything within scope of the paths that have been
|
||||
specified, so be judicious about not wasting system resources by watching much
|
||||
more than needed. For some cases, `fs.watchFile`, which utilizes polling and uses more resources, is used.
|
||||
|
||||
Made for [Brunch](https://brunch.io/) in 2012,
|
||||
it is now used in [~30 million repositories](https://www.npmjs.com/browse/depended/chokidar) and
|
||||
has proven itself in production environments.
|
||||
|
||||
**Sep 2024 update:** v4 is out! It decreases dependency count from 13 to 1, removes
|
||||
support for globs, adds support for ESM / Common.js modules, and bumps minimum node.js version from v8 to v14.
|
||||
Check out [upgrading](#upgrading).
|
||||
|
||||
## Getting started
|
||||
|
||||
Install with npm:
|
||||
|
||||
```sh
|
||||
npm install chokidar
|
||||
```
|
||||
|
||||
Use it in your code:
|
||||
|
||||
```javascript
|
||||
import chokidar from 'chokidar';
|
||||
|
||||
// One-liner for current directory
|
||||
chokidar.watch('.').on('all', (event, path) => {
|
||||
console.log(event, path);
|
||||
});
|
||||
|
||||
|
||||
// Extended options
|
||||
// ----------------
|
||||
|
||||
// Initialize watcher.
|
||||
const watcher = chokidar.watch('file, dir, or array', {
|
||||
ignored: (path, stats) => stats?.isFile() && !path.endsWith('.js'), // only watch js files
|
||||
persistent: true
|
||||
});
|
||||
|
||||
// Something to use when events are received.
|
||||
const log = console.log.bind(console);
|
||||
// Add event listeners.
|
||||
watcher
|
||||
.on('add', path => log(`File ${path} has been added`))
|
||||
.on('change', path => log(`File ${path} has been changed`))
|
||||
.on('unlink', path => log(`File ${path} has been removed`));
|
||||
|
||||
// More possible events.
|
||||
watcher
|
||||
.on('addDir', path => log(`Directory ${path} has been added`))
|
||||
.on('unlinkDir', path => log(`Directory ${path} has been removed`))
|
||||
.on('error', error => log(`Watcher error: ${error}`))
|
||||
.on('ready', () => log('Initial scan complete. Ready for changes'))
|
||||
.on('raw', (event, path, details) => { // internal
|
||||
log('Raw event info:', event, path, details);
|
||||
});
|
||||
|
||||
// 'add', 'addDir' and 'change' events also receive stat() results as second
|
||||
// argument when available: https://nodejs.org/api/fs.html#fs_class_fs_stats
|
||||
watcher.on('change', (path, stats) => {
|
||||
if (stats) console.log(`File ${path} changed size to ${stats.size}`);
|
||||
});
|
||||
|
||||
// Watch new files.
|
||||
watcher.add('new-file');
|
||||
watcher.add(['new-file-2', 'new-file-3']);
|
||||
|
||||
// Get list of actual paths being watched on the filesystem
|
||||
let watchedPaths = watcher.getWatched();
|
||||
|
||||
// Un-watch some files.
|
||||
await watcher.unwatch('new-file');
|
||||
|
||||
// Stop watching. The method is async!
|
||||
await watcher.close().then(() => console.log('closed'));
|
||||
|
||||
// Full list of options. See below for descriptions.
|
||||
// Do not use this example!
|
||||
chokidar.watch('file', {
|
||||
persistent: true,
|
||||
|
||||
// ignore .txt files
|
||||
ignored: (file) => file.endsWith('.txt'),
|
||||
// watch only .txt files
|
||||
// ignored: (file, _stats) => _stats?.isFile() && !file.endsWith('.txt'),
|
||||
|
||||
awaitWriteFinish: true, // emit single event when chunked writes are completed
|
||||
atomic: true, // emit proper events when "atomic writes" (mv _tmp file) are used
|
||||
|
||||
// The options also allow specifying custom intervals in ms
|
||||
// awaitWriteFinish: {
|
||||
// stabilityThreshold: 2000,
|
||||
// pollInterval: 100
|
||||
// },
|
||||
// atomic: 100,
|
||||
|
||||
interval: 100,
|
||||
binaryInterval: 300,
|
||||
|
||||
cwd: '.',
|
||||
depth: 99,
|
||||
|
||||
followSymlinks: true,
|
||||
ignoreInitial: false,
|
||||
ignorePermissionErrors: false,
|
||||
usePolling: false,
|
||||
alwaysStat: false,
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
`chokidar.watch(paths, [options])`
|
||||
|
||||
* `paths` (string or array of strings). Paths to files, dirs to be watched
|
||||
recursively.
|
||||
* `options` (object) Options object as defined below:
|
||||
|
||||
#### Persistence
|
||||
|
||||
* `persistent` (default: `true`). Indicates whether the process
|
||||
should continue to run as long as files are being watched.
|
||||
|
||||
#### Path filtering
|
||||
|
||||
* `ignored` function, regex, or path. Defines files/paths to be ignored.
|
||||
The whole relative or absolute path is tested, not just filename. If a function with two arguments
|
||||
is provided, it gets called twice per path - once with a single argument (the path), second
|
||||
time with two arguments (the path and the
|
||||
[`fs.Stats`](https://nodejs.org/api/fs.html#fs_class_fs_stats)
|
||||
object of that path).
|
||||
* `ignoreInitial` (default: `false`). If set to `false` then `add`/`addDir` events are also emitted for matching paths while
|
||||
instantiating the watching as chokidar discovers these file paths (before the `ready` event).
|
||||
* `followSymlinks` (default: `true`). When `false`, only the
|
||||
symlinks themselves will be watched for changes instead of following
|
||||
the link references and bubbling events through the link's path.
|
||||
* `cwd` (no default). The base directory from which watch `paths` are to be
|
||||
derived. Paths emitted with events will be relative to this.
|
||||
|
||||
#### Performance
|
||||
|
||||
* `usePolling` (default: `false`).
|
||||
Whether to use fs.watchFile (backed by polling), or fs.watch. If polling
|
||||
leads to high CPU utilization, consider setting this to `false`. It is
|
||||
typically necessary to **set this to `true` to successfully watch files over
|
||||
a network**, and it may be necessary to successfully watch files in other
|
||||
non-standard situations. Setting to `true` explicitly on MacOS overrides the
|
||||
`useFsEvents` default. You may also set the CHOKIDAR_USEPOLLING env variable
|
||||
to true (1) or false (0) in order to override this option.
|
||||
* _Polling-specific settings_ (effective when `usePolling: true`)
|
||||
* `interval` (default: `100`). Interval of file system polling, in milliseconds. You may also
|
||||
set the CHOKIDAR_INTERVAL env variable to override this option.
|
||||
* `binaryInterval` (default: `300`). Interval of file system
|
||||
polling for binary files.
|
||||
([see list of binary extensions](https://github.com/sindresorhus/binary-extensions/blob/master/binary-extensions.json))
|
||||
* `alwaysStat` (default: `false`). If relying upon the
|
||||
[`fs.Stats`](https://nodejs.org/api/fs.html#fs_class_fs_stats)
|
||||
object that may get passed with `add`, `addDir`, and `change` events, set
|
||||
this to `true` to ensure it is provided even in cases where it wasn't
|
||||
already available from the underlying watch events.
|
||||
* `depth` (default: `undefined`). If set, limits how many levels of
|
||||
subdirectories will be traversed.
|
||||
* `awaitWriteFinish` (default: `false`).
|
||||
By default, the `add` event will fire when a file first appears on disk, before
|
||||
the entire file has been written. Furthermore, in some cases some `change`
|
||||
events will be emitted while the file is being written. In some cases,
|
||||
especially when watching for large files there will be a need to wait for the
|
||||
write operation to finish before responding to a file creation or modification.
|
||||
Setting `awaitWriteFinish` to `true` (or a truthy value) will poll file size,
|
||||
holding its `add` and `change` events until the size does not change for a
|
||||
configurable amount of time. The appropriate duration setting is heavily
|
||||
dependent on the OS and hardware. For accurate detection this parameter should
|
||||
be relatively high, making file watching much less responsive.
|
||||
Use with caution.
|
||||
* *`options.awaitWriteFinish` can be set to an object in order to adjust
|
||||
timing params:*
|
||||
* `awaitWriteFinish.stabilityThreshold` (default: 2000). Amount of time in
|
||||
milliseconds for a file size to remain constant before emitting its event.
|
||||
* `awaitWriteFinish.pollInterval` (default: 100). File size polling interval, in milliseconds.
|
||||
|
||||
#### Errors
|
||||
|
||||
* `ignorePermissionErrors` (default: `false`). Indicates whether to watch files
|
||||
that don't have read permissions if possible. If watching fails due to `EPERM`
|
||||
or `EACCES` with this set to `true`, the errors will be suppressed silently.
|
||||
* `atomic` (default: `true` if `useFsEvents` and `usePolling` are `false`).
|
||||
Automatically filters out artifacts that occur when using editors that use
|
||||
"atomic writes" instead of writing directly to the source file. If a file is
|
||||
re-added within 100 ms of being deleted, Chokidar emits a `change` event
|
||||
rather than `unlink` then `add`. If the default of 100 ms does not work well
|
||||
for you, you can override it by setting `atomic` to a custom value, in
|
||||
milliseconds.
|
||||
|
||||
### Methods & Events
|
||||
|
||||
`chokidar.watch()` produces an instance of `FSWatcher`. Methods of `FSWatcher`:
|
||||
|
||||
* `.add(path / paths)`: Add files, directories for tracking.
|
||||
Takes an array of strings or just one string.
|
||||
* `.on(event, callback)`: Listen for an FS event.
|
||||
Available events: `add`, `addDir`, `change`, `unlink`, `unlinkDir`, `ready`,
|
||||
`raw`, `error`.
|
||||
Additionally `all` is available which gets emitted with the underlying event
|
||||
name and path for every event other than `ready`, `raw`, and `error`. `raw` is internal, use it carefully.
|
||||
* `.unwatch(path / paths)`: Stop watching files or directories.
|
||||
Takes an array of strings or just one string.
|
||||
* `.close()`: **async** Removes all listeners from watched files. Asynchronous, returns Promise. Use with `await` to ensure bugs don't happen.
|
||||
* `.getWatched()`: Returns an object representing all the paths on the file
|
||||
system being watched by this `FSWatcher` instance. The object's keys are all the
|
||||
directories (using absolute paths unless the `cwd` option was used), and the
|
||||
values are arrays of the names of the items contained in each directory.
|
||||
|
||||
### CLI
|
||||
|
||||
Check out third party [chokidar-cli](https://github.com/open-cli-tools/chokidar-cli),
|
||||
which allows to execute a command on each change, or get a stdio stream of change events.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
Sometimes, Chokidar runs out of file handles, causing `EMFILE` and `ENOSP` errors:
|
||||
|
||||
* `bash: cannot set terminal process group (-1): Inappropriate ioctl for device bash: no job control in this shell`
|
||||
* `Error: watch /home/ ENOSPC`
|
||||
|
||||
There are two things that can cause it.
|
||||
|
||||
1. Exhausted file handles for generic fs operations
|
||||
- Can be solved by using [graceful-fs](https://www.npmjs.com/package/graceful-fs),
|
||||
which can monkey-patch native `fs` module used by chokidar: `let fs = require('fs'); let grfs = require('graceful-fs'); grfs.gracefulify(fs);`
|
||||
- Can also be solved by tuning OS: `echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p`.
|
||||
2. Exhausted file handles for `fs.watch`
|
||||
- Can't seem to be solved by graceful-fs or OS tuning
|
||||
- It's possible to start using `usePolling: true`, which will switch backend to resource-intensive `fs.watchFile`
|
||||
|
||||
All fsevents-related issues (`WARN optional dep failed`, `fsevents is not a constructor`) are solved by upgrading to v4+.
|
||||
|
||||
## Changelog
|
||||
|
||||
- **v4 (Sep 2024):** remove glob support and bundled fsevents. Decrease dependency count from 13 to 1. Rewrite in typescript. Bumps minimum node.js requirement to v14+
|
||||
- **v3 (Apr 2019):** massive CPU & RAM consumption improvements; reduces deps / package size by a factor of 17x and bumps Node.js requirement to v8.16+.
|
||||
- **v2 (Dec 2017):** globs are now posix-style-only. Tons of bugfixes.
|
||||
- **v1 (Apr 2015):** glob support, symlink support, tons of bugfixes. Node 0.8+ is supported
|
||||
- **v0.1 (Apr 2012):** Initial release, extracted from [Brunch](https://github.com/brunch/brunch/blob/9847a065aea300da99bd0753f90354cde9de1261/src/helpers.coffee#L66)
|
||||
|
||||
### Upgrading
|
||||
|
||||
If you've used globs before and want do replicate the functionality with v4:
|
||||
|
||||
```js
|
||||
// v3
|
||||
chok.watch('**/*.js');
|
||||
chok.watch("./directory/**/*");
|
||||
|
||||
// v4
|
||||
chok.watch('.', {
|
||||
ignored: (path, stats) => stats?.isFile() && !path.endsWith('.js'), // only watch js files
|
||||
});
|
||||
chok.watch('./directory');
|
||||
|
||||
// other way
|
||||
import { glob } from 'node:fs/promises';
|
||||
const watcher = watch(await Array.fromAsync(glob('**/*.js')));
|
||||
|
||||
// unwatching
|
||||
// v3
|
||||
chok.unwatch('**/*.js');
|
||||
// v4
|
||||
chok.unwatch(await glob('**/*.js'));
|
||||
```
|
||||
|
||||
## Also
|
||||
|
||||
Why was chokidar named this way? What's the meaning behind it?
|
||||
|
||||
>Chowkidar is a transliteration of a Hindi word meaning 'watchman, gatekeeper', चौकीदार. This ultimately comes from Sanskrit _ चतुष्क_ (crossway, quadrangle, consisting-of-four). This word is also used in other languages like Urdu as (چوکیدار) which is widely used in Pakistan and India.
|
||||
|
||||
## License
|
||||
|
||||
MIT (c) Paul Miller (<https://paulmillr.com>), see [LICENSE](LICENSE) file.
|
||||
90
node_modules/chokidar/esm/handler.d.ts
generated
vendored
Normal file
90
node_modules/chokidar/esm/handler.d.ts
generated
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
import type { WatchEventType, Stats, FSWatcher as NativeFsWatcher } from 'fs';
|
||||
import type { FSWatcher, WatchHelper, Throttler } from './index.js';
|
||||
import type { EntryInfo } from 'readdirp';
|
||||
export type Path = string;
|
||||
export declare const STR_DATA = "data";
|
||||
export declare const STR_END = "end";
|
||||
export declare const STR_CLOSE = "close";
|
||||
export declare const EMPTY_FN: () => void;
|
||||
export declare const IDENTITY_FN: (val: unknown) => unknown;
|
||||
export declare const isWindows: boolean;
|
||||
export declare const isMacos: boolean;
|
||||
export declare const isLinux: boolean;
|
||||
export declare const isFreeBSD: boolean;
|
||||
export declare const isIBMi: boolean;
|
||||
export declare const EVENTS: {
|
||||
readonly ALL: "all";
|
||||
readonly READY: "ready";
|
||||
readonly ADD: "add";
|
||||
readonly CHANGE: "change";
|
||||
readonly ADD_DIR: "addDir";
|
||||
readonly UNLINK: "unlink";
|
||||
readonly UNLINK_DIR: "unlinkDir";
|
||||
readonly RAW: "raw";
|
||||
readonly ERROR: "error";
|
||||
};
|
||||
export type EventName = (typeof EVENTS)[keyof typeof EVENTS];
|
||||
export type FsWatchContainer = {
|
||||
listeners: (path: string) => void | Set<any>;
|
||||
errHandlers: (err: unknown) => void | Set<any>;
|
||||
rawEmitters: (ev: WatchEventType, path: string, opts: unknown) => void | Set<any>;
|
||||
watcher: NativeFsWatcher;
|
||||
watcherUnusable?: boolean;
|
||||
};
|
||||
export interface WatchHandlers {
|
||||
listener: (path: string) => void;
|
||||
errHandler: (err: unknown) => void;
|
||||
rawEmitter: (ev: WatchEventType, path: string, opts: unknown) => void;
|
||||
}
|
||||
/**
|
||||
* @mixin
|
||||
*/
|
||||
export declare class NodeFsHandler {
|
||||
fsw: FSWatcher;
|
||||
_boundHandleError: (error: unknown) => void;
|
||||
constructor(fsW: FSWatcher);
|
||||
/**
|
||||
* Watch file for changes with fs_watchFile or fs_watch.
|
||||
* @param path to file or dir
|
||||
* @param listener on fs change
|
||||
* @returns closer for the watcher instance
|
||||
*/
|
||||
_watchWithNodeFs(path: string, listener: (path: string, newStats?: any) => void | Promise<void>): (() => void) | undefined;
|
||||
/**
|
||||
* Watch a file and emit add event if warranted.
|
||||
* @returns closer for the watcher instance
|
||||
*/
|
||||
_handleFile(file: Path, stats: Stats, initialAdd: boolean): (() => void) | undefined;
|
||||
/**
|
||||
* Handle symlinks encountered while reading a dir.
|
||||
* @param entry returned by readdirp
|
||||
* @param directory path of dir being read
|
||||
* @param path of this item
|
||||
* @param item basename of this item
|
||||
* @returns true if no more processing is needed for this entry.
|
||||
*/
|
||||
_handleSymlink(entry: EntryInfo, directory: string, path: Path, item: string): Promise<boolean | undefined>;
|
||||
_handleRead(directory: string, initialAdd: boolean, wh: WatchHelper, target: Path, dir: Path, depth: number, throttler: Throttler): Promise<unknown> | undefined;
|
||||
/**
|
||||
* Read directory to add / remove files from `@watched` list and re-read it on change.
|
||||
* @param dir fs path
|
||||
* @param stats
|
||||
* @param initialAdd
|
||||
* @param depth relative to user-supplied path
|
||||
* @param target child path targeted for watch
|
||||
* @param wh Common watch helpers for this path
|
||||
* @param realpath
|
||||
* @returns closer for the watcher instance.
|
||||
*/
|
||||
_handleDir(dir: string, stats: Stats, initialAdd: boolean, depth: number, target: string, wh: WatchHelper, realpath: string): Promise<(() => void) | undefined>;
|
||||
/**
|
||||
* Handle added file, directory, or glob pattern.
|
||||
* Delegates call to _handleFile / _handleDir after checks.
|
||||
* @param path to file or ir
|
||||
* @param initialAdd was the file added at watch instantiation?
|
||||
* @param priorWh depth relative to user-supplied path
|
||||
* @param depth Child path actually targeted for watch
|
||||
* @param target Child path actually targeted for watch
|
||||
*/
|
||||
_addToNodeFs(path: string, initialAdd: boolean, priorWh: WatchHelper | undefined, depth: number, target?: string): Promise<string | false | undefined>;
|
||||
}
|
||||
629
node_modules/chokidar/esm/handler.js
generated
vendored
Normal file
629
node_modules/chokidar/esm/handler.js
generated
vendored
Normal file
@@ -0,0 +1,629 @@
|
||||
import { watchFile, unwatchFile, watch as fs_watch } from 'fs';
|
||||
import { open, stat, lstat, realpath as fsrealpath } from 'fs/promises';
|
||||
import * as sysPath from 'path';
|
||||
import { type as osType } from 'os';
|
||||
export const STR_DATA = 'data';
|
||||
export const STR_END = 'end';
|
||||
export const STR_CLOSE = 'close';
|
||||
export const EMPTY_FN = () => { };
|
||||
export const IDENTITY_FN = (val) => val;
|
||||
const pl = process.platform;
|
||||
export const isWindows = pl === 'win32';
|
||||
export const isMacos = pl === 'darwin';
|
||||
export const isLinux = pl === 'linux';
|
||||
export const isFreeBSD = pl === 'freebsd';
|
||||
export const isIBMi = osType() === 'OS400';
|
||||
export const EVENTS = {
|
||||
ALL: 'all',
|
||||
READY: 'ready',
|
||||
ADD: 'add',
|
||||
CHANGE: 'change',
|
||||
ADD_DIR: 'addDir',
|
||||
UNLINK: 'unlink',
|
||||
UNLINK_DIR: 'unlinkDir',
|
||||
RAW: 'raw',
|
||||
ERROR: 'error',
|
||||
};
|
||||
const EV = EVENTS;
|
||||
const THROTTLE_MODE_WATCH = 'watch';
|
||||
const statMethods = { lstat, stat };
|
||||
const KEY_LISTENERS = 'listeners';
|
||||
const KEY_ERR = 'errHandlers';
|
||||
const KEY_RAW = 'rawEmitters';
|
||||
const HANDLER_KEYS = [KEY_LISTENERS, KEY_ERR, KEY_RAW];
|
||||
// prettier-ignore
|
||||
const binaryExtensions = new Set([
|
||||
'3dm', '3ds', '3g2', '3gp', '7z', 'a', 'aac', 'adp', 'afdesign', 'afphoto', 'afpub', 'ai',
|
||||
'aif', 'aiff', 'alz', 'ape', 'apk', 'appimage', 'ar', 'arj', 'asf', 'au', 'avi',
|
||||
'bak', 'baml', 'bh', 'bin', 'bk', 'bmp', 'btif', 'bz2', 'bzip2',
|
||||
'cab', 'caf', 'cgm', 'class', 'cmx', 'cpio', 'cr2', 'cur', 'dat', 'dcm', 'deb', 'dex', 'djvu',
|
||||
'dll', 'dmg', 'dng', 'doc', 'docm', 'docx', 'dot', 'dotm', 'dra', 'DS_Store', 'dsk', 'dts',
|
||||
'dtshd', 'dvb', 'dwg', 'dxf',
|
||||
'ecelp4800', 'ecelp7470', 'ecelp9600', 'egg', 'eol', 'eot', 'epub', 'exe',
|
||||
'f4v', 'fbs', 'fh', 'fla', 'flac', 'flatpak', 'fli', 'flv', 'fpx', 'fst', 'fvt',
|
||||
'g3', 'gh', 'gif', 'graffle', 'gz', 'gzip',
|
||||
'h261', 'h263', 'h264', 'icns', 'ico', 'ief', 'img', 'ipa', 'iso',
|
||||
'jar', 'jpeg', 'jpg', 'jpgv', 'jpm', 'jxr', 'key', 'ktx',
|
||||
'lha', 'lib', 'lvp', 'lz', 'lzh', 'lzma', 'lzo',
|
||||
'm3u', 'm4a', 'm4v', 'mar', 'mdi', 'mht', 'mid', 'midi', 'mj2', 'mka', 'mkv', 'mmr', 'mng',
|
||||
'mobi', 'mov', 'movie', 'mp3',
|
||||
'mp4', 'mp4a', 'mpeg', 'mpg', 'mpga', 'mxu',
|
||||
'nef', 'npx', 'numbers', 'nupkg',
|
||||
'o', 'odp', 'ods', 'odt', 'oga', 'ogg', 'ogv', 'otf', 'ott',
|
||||
'pages', 'pbm', 'pcx', 'pdb', 'pdf', 'pea', 'pgm', 'pic', 'png', 'pnm', 'pot', 'potm',
|
||||
'potx', 'ppa', 'ppam',
|
||||
'ppm', 'pps', 'ppsm', 'ppsx', 'ppt', 'pptm', 'pptx', 'psd', 'pya', 'pyc', 'pyo', 'pyv',
|
||||
'qt',
|
||||
'rar', 'ras', 'raw', 'resources', 'rgb', 'rip', 'rlc', 'rmf', 'rmvb', 'rpm', 'rtf', 'rz',
|
||||
's3m', 's7z', 'scpt', 'sgi', 'shar', 'snap', 'sil', 'sketch', 'slk', 'smv', 'snk', 'so',
|
||||
'stl', 'suo', 'sub', 'swf',
|
||||
'tar', 'tbz', 'tbz2', 'tga', 'tgz', 'thmx', 'tif', 'tiff', 'tlz', 'ttc', 'ttf', 'txz',
|
||||
'udf', 'uvh', 'uvi', 'uvm', 'uvp', 'uvs', 'uvu',
|
||||
'viv', 'vob',
|
||||
'war', 'wav', 'wax', 'wbmp', 'wdp', 'weba', 'webm', 'webp', 'whl', 'wim', 'wm', 'wma',
|
||||
'wmv', 'wmx', 'woff', 'woff2', 'wrm', 'wvx',
|
||||
'xbm', 'xif', 'xla', 'xlam', 'xls', 'xlsb', 'xlsm', 'xlsx', 'xlt', 'xltm', 'xltx', 'xm',
|
||||
'xmind', 'xpi', 'xpm', 'xwd', 'xz',
|
||||
'z', 'zip', 'zipx',
|
||||
]);
|
||||
const isBinaryPath = (filePath) => binaryExtensions.has(sysPath.extname(filePath).slice(1).toLowerCase());
|
||||
// TODO: emit errors properly. Example: EMFILE on Macos.
|
||||
const foreach = (val, fn) => {
|
||||
if (val instanceof Set) {
|
||||
val.forEach(fn);
|
||||
}
|
||||
else {
|
||||
fn(val);
|
||||
}
|
||||
};
|
||||
const addAndConvert = (main, prop, item) => {
|
||||
let container = main[prop];
|
||||
if (!(container instanceof Set)) {
|
||||
main[prop] = container = new Set([container]);
|
||||
}
|
||||
container.add(item);
|
||||
};
|
||||
const clearItem = (cont) => (key) => {
|
||||
const set = cont[key];
|
||||
if (set instanceof Set) {
|
||||
set.clear();
|
||||
}
|
||||
else {
|
||||
delete cont[key];
|
||||
}
|
||||
};
|
||||
const delFromSet = (main, prop, item) => {
|
||||
const container = main[prop];
|
||||
if (container instanceof Set) {
|
||||
container.delete(item);
|
||||
}
|
||||
else if (container === item) {
|
||||
delete main[prop];
|
||||
}
|
||||
};
|
||||
const isEmptySet = (val) => (val instanceof Set ? val.size === 0 : !val);
|
||||
const FsWatchInstances = new Map();
|
||||
/**
|
||||
* Instantiates the fs_watch interface
|
||||
* @param path to be watched
|
||||
* @param options to be passed to fs_watch
|
||||
* @param listener main event handler
|
||||
* @param errHandler emits info about errors
|
||||
* @param emitRaw emits raw event data
|
||||
* @returns {NativeFsWatcher}
|
||||
*/
|
||||
function createFsWatchInstance(path, options, listener, errHandler, emitRaw) {
|
||||
const handleEvent = (rawEvent, evPath) => {
|
||||
listener(path);
|
||||
emitRaw(rawEvent, evPath, { watchedPath: path });
|
||||
// emit based on events occurring for files from a directory's watcher in
|
||||
// case the file's watcher misses it (and rely on throttling to de-dupe)
|
||||
if (evPath && path !== evPath) {
|
||||
fsWatchBroadcast(sysPath.resolve(path, evPath), KEY_LISTENERS, sysPath.join(path, evPath));
|
||||
}
|
||||
};
|
||||
try {
|
||||
return fs_watch(path, {
|
||||
persistent: options.persistent,
|
||||
}, handleEvent);
|
||||
}
|
||||
catch (error) {
|
||||
errHandler(error);
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Helper for passing fs_watch event data to a collection of listeners
|
||||
* @param fullPath absolute path bound to fs_watch instance
|
||||
*/
|
||||
const fsWatchBroadcast = (fullPath, listenerType, val1, val2, val3) => {
|
||||
const cont = FsWatchInstances.get(fullPath);
|
||||
if (!cont)
|
||||
return;
|
||||
foreach(cont[listenerType], (listener) => {
|
||||
listener(val1, val2, val3);
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Instantiates the fs_watch interface or binds listeners
|
||||
* to an existing one covering the same file system entry
|
||||
* @param path
|
||||
* @param fullPath absolute path
|
||||
* @param options to be passed to fs_watch
|
||||
* @param handlers container for event listener functions
|
||||
*/
|
||||
const setFsWatchListener = (path, fullPath, options, handlers) => {
|
||||
const { listener, errHandler, rawEmitter } = handlers;
|
||||
let cont = FsWatchInstances.get(fullPath);
|
||||
let watcher;
|
||||
if (!options.persistent) {
|
||||
watcher = createFsWatchInstance(path, options, listener, errHandler, rawEmitter);
|
||||
if (!watcher)
|
||||
return;
|
||||
return watcher.close.bind(watcher);
|
||||
}
|
||||
if (cont) {
|
||||
addAndConvert(cont, KEY_LISTENERS, listener);
|
||||
addAndConvert(cont, KEY_ERR, errHandler);
|
||||
addAndConvert(cont, KEY_RAW, rawEmitter);
|
||||
}
|
||||
else {
|
||||
watcher = createFsWatchInstance(path, options, fsWatchBroadcast.bind(null, fullPath, KEY_LISTENERS), errHandler, // no need to use broadcast here
|
||||
fsWatchBroadcast.bind(null, fullPath, KEY_RAW));
|
||||
if (!watcher)
|
||||
return;
|
||||
watcher.on(EV.ERROR, async (error) => {
|
||||
const broadcastErr = fsWatchBroadcast.bind(null, fullPath, KEY_ERR);
|
||||
if (cont)
|
||||
cont.watcherUnusable = true; // documented since Node 10.4.1
|
||||
// Workaround for https://github.com/joyent/node/issues/4337
|
||||
if (isWindows && error.code === 'EPERM') {
|
||||
try {
|
||||
const fd = await open(path, 'r');
|
||||
await fd.close();
|
||||
broadcastErr(error);
|
||||
}
|
||||
catch (err) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
else {
|
||||
broadcastErr(error);
|
||||
}
|
||||
});
|
||||
cont = {
|
||||
listeners: listener,
|
||||
errHandlers: errHandler,
|
||||
rawEmitters: rawEmitter,
|
||||
watcher,
|
||||
};
|
||||
FsWatchInstances.set(fullPath, cont);
|
||||
}
|
||||
// const index = cont.listeners.indexOf(listener);
|
||||
// removes this instance's listeners and closes the underlying fs_watch
|
||||
// instance if there are no more listeners left
|
||||
return () => {
|
||||
delFromSet(cont, KEY_LISTENERS, listener);
|
||||
delFromSet(cont, KEY_ERR, errHandler);
|
||||
delFromSet(cont, KEY_RAW, rawEmitter);
|
||||
if (isEmptySet(cont.listeners)) {
|
||||
// Check to protect against issue gh-730.
|
||||
// if (cont.watcherUnusable) {
|
||||
cont.watcher.close();
|
||||
// }
|
||||
FsWatchInstances.delete(fullPath);
|
||||
HANDLER_KEYS.forEach(clearItem(cont));
|
||||
// @ts-ignore
|
||||
cont.watcher = undefined;
|
||||
Object.freeze(cont);
|
||||
}
|
||||
};
|
||||
};
|
||||
// fs_watchFile helpers
|
||||
// object to hold per-process fs_watchFile instances
|
||||
// (may be shared across chokidar FSWatcher instances)
|
||||
const FsWatchFileInstances = new Map();
|
||||
/**
|
||||
* Instantiates the fs_watchFile interface or binds listeners
|
||||
* to an existing one covering the same file system entry
|
||||
* @param path to be watched
|
||||
* @param fullPath absolute path
|
||||
* @param options options to be passed to fs_watchFile
|
||||
* @param handlers container for event listener functions
|
||||
* @returns closer
|
||||
*/
|
||||
const setFsWatchFileListener = (path, fullPath, options, handlers) => {
|
||||
const { listener, rawEmitter } = handlers;
|
||||
let cont = FsWatchFileInstances.get(fullPath);
|
||||
// let listeners = new Set();
|
||||
// let rawEmitters = new Set();
|
||||
const copts = cont && cont.options;
|
||||
if (copts && (copts.persistent < options.persistent || copts.interval > options.interval)) {
|
||||
// "Upgrade" the watcher to persistence or a quicker interval.
|
||||
// This creates some unlikely edge case issues if the user mixes
|
||||
// settings in a very weird way, but solving for those cases
|
||||
// doesn't seem worthwhile for the added complexity.
|
||||
// listeners = cont.listeners;
|
||||
// rawEmitters = cont.rawEmitters;
|
||||
unwatchFile(fullPath);
|
||||
cont = undefined;
|
||||
}
|
||||
if (cont) {
|
||||
addAndConvert(cont, KEY_LISTENERS, listener);
|
||||
addAndConvert(cont, KEY_RAW, rawEmitter);
|
||||
}
|
||||
else {
|
||||
// TODO
|
||||
// listeners.add(listener);
|
||||
// rawEmitters.add(rawEmitter);
|
||||
cont = {
|
||||
listeners: listener,
|
||||
rawEmitters: rawEmitter,
|
||||
options,
|
||||
watcher: watchFile(fullPath, options, (curr, prev) => {
|
||||
foreach(cont.rawEmitters, (rawEmitter) => {
|
||||
rawEmitter(EV.CHANGE, fullPath, { curr, prev });
|
||||
});
|
||||
const currmtime = curr.mtimeMs;
|
||||
if (curr.size !== prev.size || currmtime > prev.mtimeMs || currmtime === 0) {
|
||||
foreach(cont.listeners, (listener) => listener(path, curr));
|
||||
}
|
||||
}),
|
||||
};
|
||||
FsWatchFileInstances.set(fullPath, cont);
|
||||
}
|
||||
// const index = cont.listeners.indexOf(listener);
|
||||
// Removes this instance's listeners and closes the underlying fs_watchFile
|
||||
// instance if there are no more listeners left.
|
||||
return () => {
|
||||
delFromSet(cont, KEY_LISTENERS, listener);
|
||||
delFromSet(cont, KEY_RAW, rawEmitter);
|
||||
if (isEmptySet(cont.listeners)) {
|
||||
FsWatchFileInstances.delete(fullPath);
|
||||
unwatchFile(fullPath);
|
||||
cont.options = cont.watcher = undefined;
|
||||
Object.freeze(cont);
|
||||
}
|
||||
};
|
||||
};
|
||||
/**
|
||||
* @mixin
|
||||
*/
|
||||
export class NodeFsHandler {
|
||||
constructor(fsW) {
|
||||
this.fsw = fsW;
|
||||
this._boundHandleError = (error) => fsW._handleError(error);
|
||||
}
|
||||
/**
|
||||
* Watch file for changes with fs_watchFile or fs_watch.
|
||||
* @param path to file or dir
|
||||
* @param listener on fs change
|
||||
* @returns closer for the watcher instance
|
||||
*/
|
||||
_watchWithNodeFs(path, listener) {
|
||||
const opts = this.fsw.options;
|
||||
const directory = sysPath.dirname(path);
|
||||
const basename = sysPath.basename(path);
|
||||
const parent = this.fsw._getWatchedDir(directory);
|
||||
parent.add(basename);
|
||||
const absolutePath = sysPath.resolve(path);
|
||||
const options = {
|
||||
persistent: opts.persistent,
|
||||
};
|
||||
if (!listener)
|
||||
listener = EMPTY_FN;
|
||||
let closer;
|
||||
if (opts.usePolling) {
|
||||
const enableBin = opts.interval !== opts.binaryInterval;
|
||||
options.interval = enableBin && isBinaryPath(basename) ? opts.binaryInterval : opts.interval;
|
||||
closer = setFsWatchFileListener(path, absolutePath, options, {
|
||||
listener,
|
||||
rawEmitter: this.fsw._emitRaw,
|
||||
});
|
||||
}
|
||||
else {
|
||||
closer = setFsWatchListener(path, absolutePath, options, {
|
||||
listener,
|
||||
errHandler: this._boundHandleError,
|
||||
rawEmitter: this.fsw._emitRaw,
|
||||
});
|
||||
}
|
||||
return closer;
|
||||
}
|
||||
/**
|
||||
* Watch a file and emit add event if warranted.
|
||||
* @returns closer for the watcher instance
|
||||
*/
|
||||
_handleFile(file, stats, initialAdd) {
|
||||
if (this.fsw.closed) {
|
||||
return;
|
||||
}
|
||||
const dirname = sysPath.dirname(file);
|
||||
const basename = sysPath.basename(file);
|
||||
const parent = this.fsw._getWatchedDir(dirname);
|
||||
// stats is always present
|
||||
let prevStats = stats;
|
||||
// if the file is already being watched, do nothing
|
||||
if (parent.has(basename))
|
||||
return;
|
||||
const listener = async (path, newStats) => {
|
||||
if (!this.fsw._throttle(THROTTLE_MODE_WATCH, file, 5))
|
||||
return;
|
||||
if (!newStats || newStats.mtimeMs === 0) {
|
||||
try {
|
||||
const newStats = await stat(file);
|
||||
if (this.fsw.closed)
|
||||
return;
|
||||
// Check that change event was not fired because of changed only accessTime.
|
||||
const at = newStats.atimeMs;
|
||||
const mt = newStats.mtimeMs;
|
||||
if (!at || at <= mt || mt !== prevStats.mtimeMs) {
|
||||
this.fsw._emit(EV.CHANGE, file, newStats);
|
||||
}
|
||||
if ((isMacos || isLinux || isFreeBSD) && prevStats.ino !== newStats.ino) {
|
||||
this.fsw._closeFile(path);
|
||||
prevStats = newStats;
|
||||
const closer = this._watchWithNodeFs(file, listener);
|
||||
if (closer)
|
||||
this.fsw._addPathCloser(path, closer);
|
||||
}
|
||||
else {
|
||||
prevStats = newStats;
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
// Fix issues where mtime is null but file is still present
|
||||
this.fsw._remove(dirname, basename);
|
||||
}
|
||||
// add is about to be emitted if file not already tracked in parent
|
||||
}
|
||||
else if (parent.has(basename)) {
|
||||
// Check that change event was not fired because of changed only accessTime.
|
||||
const at = newStats.atimeMs;
|
||||
const mt = newStats.mtimeMs;
|
||||
if (!at || at <= mt || mt !== prevStats.mtimeMs) {
|
||||
this.fsw._emit(EV.CHANGE, file, newStats);
|
||||
}
|
||||
prevStats = newStats;
|
||||
}
|
||||
};
|
||||
// kick off the watcher
|
||||
const closer = this._watchWithNodeFs(file, listener);
|
||||
// emit an add event if we're supposed to
|
||||
if (!(initialAdd && this.fsw.options.ignoreInitial) && this.fsw._isntIgnored(file)) {
|
||||
if (!this.fsw._throttle(EV.ADD, file, 0))
|
||||
return;
|
||||
this.fsw._emit(EV.ADD, file, stats);
|
||||
}
|
||||
return closer;
|
||||
}
|
||||
/**
|
||||
* Handle symlinks encountered while reading a dir.
|
||||
* @param entry returned by readdirp
|
||||
* @param directory path of dir being read
|
||||
* @param path of this item
|
||||
* @param item basename of this item
|
||||
* @returns true if no more processing is needed for this entry.
|
||||
*/
|
||||
async _handleSymlink(entry, directory, path, item) {
|
||||
if (this.fsw.closed) {
|
||||
return;
|
||||
}
|
||||
const full = entry.fullPath;
|
||||
const dir = this.fsw._getWatchedDir(directory);
|
||||
if (!this.fsw.options.followSymlinks) {
|
||||
// watch symlink directly (don't follow) and detect changes
|
||||
this.fsw._incrReadyCount();
|
||||
let linkPath;
|
||||
try {
|
||||
linkPath = await fsrealpath(path);
|
||||
}
|
||||
catch (e) {
|
||||
this.fsw._emitReady();
|
||||
return true;
|
||||
}
|
||||
if (this.fsw.closed)
|
||||
return;
|
||||
if (dir.has(item)) {
|
||||
if (this.fsw._symlinkPaths.get(full) !== linkPath) {
|
||||
this.fsw._symlinkPaths.set(full, linkPath);
|
||||
this.fsw._emit(EV.CHANGE, path, entry.stats);
|
||||
}
|
||||
}
|
||||
else {
|
||||
dir.add(item);
|
||||
this.fsw._symlinkPaths.set(full, linkPath);
|
||||
this.fsw._emit(EV.ADD, path, entry.stats);
|
||||
}
|
||||
this.fsw._emitReady();
|
||||
return true;
|
||||
}
|
||||
// don't follow the same symlink more than once
|
||||
if (this.fsw._symlinkPaths.has(full)) {
|
||||
return true;
|
||||
}
|
||||
this.fsw._symlinkPaths.set(full, true);
|
||||
}
|
||||
_handleRead(directory, initialAdd, wh, target, dir, depth, throttler) {
|
||||
// Normalize the directory name on Windows
|
||||
directory = sysPath.join(directory, '');
|
||||
throttler = this.fsw._throttle('readdir', directory, 1000);
|
||||
if (!throttler)
|
||||
return;
|
||||
const previous = this.fsw._getWatchedDir(wh.path);
|
||||
const current = new Set();
|
||||
let stream = this.fsw._readdirp(directory, {
|
||||
fileFilter: (entry) => wh.filterPath(entry),
|
||||
directoryFilter: (entry) => wh.filterDir(entry),
|
||||
});
|
||||
if (!stream)
|
||||
return;
|
||||
stream
|
||||
.on(STR_DATA, async (entry) => {
|
||||
if (this.fsw.closed) {
|
||||
stream = undefined;
|
||||
return;
|
||||
}
|
||||
const item = entry.path;
|
||||
let path = sysPath.join(directory, item);
|
||||
current.add(item);
|
||||
if (entry.stats.isSymbolicLink() &&
|
||||
(await this._handleSymlink(entry, directory, path, item))) {
|
||||
return;
|
||||
}
|
||||
if (this.fsw.closed) {
|
||||
stream = undefined;
|
||||
return;
|
||||
}
|
||||
// Files that present in current directory snapshot
|
||||
// but absent in previous are added to watch list and
|
||||
// emit `add` event.
|
||||
if (item === target || (!target && !previous.has(item))) {
|
||||
this.fsw._incrReadyCount();
|
||||
// ensure relativeness of path is preserved in case of watcher reuse
|
||||
path = sysPath.join(dir, sysPath.relative(dir, path));
|
||||
this._addToNodeFs(path, initialAdd, wh, depth + 1);
|
||||
}
|
||||
})
|
||||
.on(EV.ERROR, this._boundHandleError);
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!stream)
|
||||
return reject();
|
||||
stream.once(STR_END, () => {
|
||||
if (this.fsw.closed) {
|
||||
stream = undefined;
|
||||
return;
|
||||
}
|
||||
const wasThrottled = throttler ? throttler.clear() : false;
|
||||
resolve(undefined);
|
||||
// Files that absent in current directory snapshot
|
||||
// but present in previous emit `remove` event
|
||||
// and are removed from @watched[directory].
|
||||
previous
|
||||
.getChildren()
|
||||
.filter((item) => {
|
||||
return item !== directory && !current.has(item);
|
||||
})
|
||||
.forEach((item) => {
|
||||
this.fsw._remove(directory, item);
|
||||
});
|
||||
stream = undefined;
|
||||
// one more time for any missed in case changes came in extremely quickly
|
||||
if (wasThrottled)
|
||||
this._handleRead(directory, false, wh, target, dir, depth, throttler);
|
||||
});
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Read directory to add / remove files from `@watched` list and re-read it on change.
|
||||
* @param dir fs path
|
||||
* @param stats
|
||||
* @param initialAdd
|
||||
* @param depth relative to user-supplied path
|
||||
* @param target child path targeted for watch
|
||||
* @param wh Common watch helpers for this path
|
||||
* @param realpath
|
||||
* @returns closer for the watcher instance.
|
||||
*/
|
||||
async _handleDir(dir, stats, initialAdd, depth, target, wh, realpath) {
|
||||
const parentDir = this.fsw._getWatchedDir(sysPath.dirname(dir));
|
||||
const tracked = parentDir.has(sysPath.basename(dir));
|
||||
if (!(initialAdd && this.fsw.options.ignoreInitial) && !target && !tracked) {
|
||||
this.fsw._emit(EV.ADD_DIR, dir, stats);
|
||||
}
|
||||
// ensure dir is tracked (harmless if redundant)
|
||||
parentDir.add(sysPath.basename(dir));
|
||||
this.fsw._getWatchedDir(dir);
|
||||
let throttler;
|
||||
let closer;
|
||||
const oDepth = this.fsw.options.depth;
|
||||
if ((oDepth == null || depth <= oDepth) && !this.fsw._symlinkPaths.has(realpath)) {
|
||||
if (!target) {
|
||||
await this._handleRead(dir, initialAdd, wh, target, dir, depth, throttler);
|
||||
if (this.fsw.closed)
|
||||
return;
|
||||
}
|
||||
closer = this._watchWithNodeFs(dir, (dirPath, stats) => {
|
||||
// if current directory is removed, do nothing
|
||||
if (stats && stats.mtimeMs === 0)
|
||||
return;
|
||||
this._handleRead(dirPath, false, wh, target, dir, depth, throttler);
|
||||
});
|
||||
}
|
||||
return closer;
|
||||
}
|
||||
/**
|
||||
* Handle added file, directory, or glob pattern.
|
||||
* Delegates call to _handleFile / _handleDir after checks.
|
||||
* @param path to file or ir
|
||||
* @param initialAdd was the file added at watch instantiation?
|
||||
* @param priorWh depth relative to user-supplied path
|
||||
* @param depth Child path actually targeted for watch
|
||||
* @param target Child path actually targeted for watch
|
||||
*/
|
||||
async _addToNodeFs(path, initialAdd, priorWh, depth, target) {
|
||||
const ready = this.fsw._emitReady;
|
||||
if (this.fsw._isIgnored(path) || this.fsw.closed) {
|
||||
ready();
|
||||
return false;
|
||||
}
|
||||
const wh = this.fsw._getWatchHelpers(path);
|
||||
if (priorWh) {
|
||||
wh.filterPath = (entry) => priorWh.filterPath(entry);
|
||||
wh.filterDir = (entry) => priorWh.filterDir(entry);
|
||||
}
|
||||
// evaluate what is at the path we're being asked to watch
|
||||
try {
|
||||
const stats = await statMethods[wh.statMethod](wh.watchPath);
|
||||
if (this.fsw.closed)
|
||||
return;
|
||||
if (this.fsw._isIgnored(wh.watchPath, stats)) {
|
||||
ready();
|
||||
return false;
|
||||
}
|
||||
const follow = this.fsw.options.followSymlinks;
|
||||
let closer;
|
||||
if (stats.isDirectory()) {
|
||||
const absPath = sysPath.resolve(path);
|
||||
const targetPath = follow ? await fsrealpath(path) : path;
|
||||
if (this.fsw.closed)
|
||||
return;
|
||||
closer = await this._handleDir(wh.watchPath, stats, initialAdd, depth, target, wh, targetPath);
|
||||
if (this.fsw.closed)
|
||||
return;
|
||||
// preserve this symlink's target path
|
||||
if (absPath !== targetPath && targetPath !== undefined) {
|
||||
this.fsw._symlinkPaths.set(absPath, targetPath);
|
||||
}
|
||||
}
|
||||
else if (stats.isSymbolicLink()) {
|
||||
const targetPath = follow ? await fsrealpath(path) : path;
|
||||
if (this.fsw.closed)
|
||||
return;
|
||||
const parent = sysPath.dirname(wh.watchPath);
|
||||
this.fsw._getWatchedDir(parent).add(wh.watchPath);
|
||||
this.fsw._emit(EV.ADD, wh.watchPath, stats);
|
||||
closer = await this._handleDir(parent, stats, initialAdd, depth, path, wh, targetPath);
|
||||
if (this.fsw.closed)
|
||||
return;
|
||||
// preserve this symlink's target path
|
||||
if (targetPath !== undefined) {
|
||||
this.fsw._symlinkPaths.set(sysPath.resolve(path), targetPath);
|
||||
}
|
||||
}
|
||||
else {
|
||||
closer = this._handleFile(wh.watchPath, stats, initialAdd);
|
||||
}
|
||||
ready();
|
||||
if (closer)
|
||||
this.fsw._addPathCloser(path, closer);
|
||||
return false;
|
||||
}
|
||||
catch (error) {
|
||||
if (this.fsw._handleError(error)) {
|
||||
ready();
|
||||
return path;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
215
node_modules/chokidar/esm/index.d.ts
generated
vendored
Normal file
215
node_modules/chokidar/esm/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,215 @@
|
||||
/*! chokidar - MIT License (c) 2012 Paul Miller (paulmillr.com) */
|
||||
import { Stats } from 'fs';
|
||||
import { EventEmitter } from 'events';
|
||||
import { ReaddirpStream, ReaddirpOptions, EntryInfo } from 'readdirp';
|
||||
import { NodeFsHandler, EventName, Path, EVENTS as EV, WatchHandlers } from './handler.js';
|
||||
type AWF = {
|
||||
stabilityThreshold: number;
|
||||
pollInterval: number;
|
||||
};
|
||||
type BasicOpts = {
|
||||
persistent: boolean;
|
||||
ignoreInitial: boolean;
|
||||
followSymlinks: boolean;
|
||||
cwd?: string;
|
||||
usePolling: boolean;
|
||||
interval: number;
|
||||
binaryInterval: number;
|
||||
alwaysStat?: boolean;
|
||||
depth?: number;
|
||||
ignorePermissionErrors: boolean;
|
||||
atomic: boolean | number;
|
||||
};
|
||||
export type Throttler = {
|
||||
timeoutObject: NodeJS.Timeout;
|
||||
clear: () => void;
|
||||
count: number;
|
||||
};
|
||||
export type ChokidarOptions = Partial<BasicOpts & {
|
||||
ignored: Matcher | Matcher[];
|
||||
awaitWriteFinish: boolean | Partial<AWF>;
|
||||
}>;
|
||||
export type FSWInstanceOptions = BasicOpts & {
|
||||
ignored: Matcher[];
|
||||
awaitWriteFinish: false | AWF;
|
||||
};
|
||||
export type ThrottleType = 'readdir' | 'watch' | 'add' | 'remove' | 'change';
|
||||
export type EmitArgs = [path: Path, stats?: Stats];
|
||||
export type EmitErrorArgs = [error: Error, stats?: Stats];
|
||||
export type EmitArgsWithName = [event: EventName, ...EmitArgs];
|
||||
export type MatchFunction = (val: string, stats?: Stats) => boolean;
|
||||
export interface MatcherObject {
|
||||
path: string;
|
||||
recursive?: boolean;
|
||||
}
|
||||
export type Matcher = string | RegExp | MatchFunction | MatcherObject;
|
||||
/**
|
||||
* Directory entry.
|
||||
*/
|
||||
declare class DirEntry {
|
||||
path: Path;
|
||||
_removeWatcher: (dir: string, base: string) => void;
|
||||
items: Set<Path>;
|
||||
constructor(dir: Path, removeWatcher: (dir: string, base: string) => void);
|
||||
add(item: string): void;
|
||||
remove(item: string): Promise<void>;
|
||||
has(item: string): boolean | undefined;
|
||||
getChildren(): string[];
|
||||
dispose(): void;
|
||||
}
|
||||
export declare class WatchHelper {
|
||||
fsw: FSWatcher;
|
||||
path: string;
|
||||
watchPath: string;
|
||||
fullWatchPath: string;
|
||||
dirParts: string[][];
|
||||
followSymlinks: boolean;
|
||||
statMethod: 'stat' | 'lstat';
|
||||
constructor(path: string, follow: boolean, fsw: FSWatcher);
|
||||
entryPath(entry: EntryInfo): Path;
|
||||
filterPath(entry: EntryInfo): boolean;
|
||||
filterDir(entry: EntryInfo): boolean;
|
||||
}
|
||||
export interface FSWatcherKnownEventMap {
|
||||
[EV.READY]: [];
|
||||
[EV.RAW]: Parameters<WatchHandlers['rawEmitter']>;
|
||||
[EV.ERROR]: Parameters<WatchHandlers['errHandler']>;
|
||||
[EV.ALL]: [event: EventName, ...EmitArgs];
|
||||
}
|
||||
export type FSWatcherEventMap = FSWatcherKnownEventMap & {
|
||||
[k in Exclude<EventName, keyof FSWatcherKnownEventMap>]: EmitArgs;
|
||||
};
|
||||
/**
|
||||
* Watches files & directories for changes. Emitted events:
|
||||
* `add`, `addDir`, `change`, `unlink`, `unlinkDir`, `all`, `error`
|
||||
*
|
||||
* new FSWatcher()
|
||||
* .add(directories)
|
||||
* .on('add', path => log('File', path, 'was added'))
|
||||
*/
|
||||
export declare class FSWatcher extends EventEmitter<FSWatcherEventMap> {
|
||||
closed: boolean;
|
||||
options: FSWInstanceOptions;
|
||||
_closers: Map<string, Array<any>>;
|
||||
_ignoredPaths: Set<Matcher>;
|
||||
_throttled: Map<ThrottleType, Map<any, any>>;
|
||||
_streams: Set<ReaddirpStream>;
|
||||
_symlinkPaths: Map<Path, string | boolean>;
|
||||
_watched: Map<string, DirEntry>;
|
||||
_pendingWrites: Map<string, any>;
|
||||
_pendingUnlinks: Map<string, EmitArgsWithName>;
|
||||
_readyCount: number;
|
||||
_emitReady: () => void;
|
||||
_closePromise?: Promise<void>;
|
||||
_userIgnored?: MatchFunction;
|
||||
_readyEmitted: boolean;
|
||||
_emitRaw: WatchHandlers['rawEmitter'];
|
||||
_boundRemove: (dir: string, item: string) => void;
|
||||
_nodeFsHandler: NodeFsHandler;
|
||||
constructor(_opts?: ChokidarOptions);
|
||||
_addIgnoredPath(matcher: Matcher): void;
|
||||
_removeIgnoredPath(matcher: Matcher): void;
|
||||
/**
|
||||
* Adds paths to be watched on an existing FSWatcher instance.
|
||||
* @param paths_ file or file list. Other arguments are unused
|
||||
*/
|
||||
add(paths_: Path | Path[], _origAdd?: string, _internal?: boolean): FSWatcher;
|
||||
/**
|
||||
* Close watchers or start ignoring events from specified paths.
|
||||
*/
|
||||
unwatch(paths_: Path | Path[]): FSWatcher;
|
||||
/**
|
||||
* Close watchers and remove all listeners from watched paths.
|
||||
*/
|
||||
close(): Promise<void>;
|
||||
/**
|
||||
* Expose list of watched paths
|
||||
* @returns for chaining
|
||||
*/
|
||||
getWatched(): Record<string, string[]>;
|
||||
emitWithAll(event: EventName, args: EmitArgs): void;
|
||||
/**
|
||||
* Normalize and emit events.
|
||||
* Calling _emit DOES NOT MEAN emit() would be called!
|
||||
* @param event Type of event
|
||||
* @param path File or directory path
|
||||
* @param stats arguments to be passed with event
|
||||
* @returns the error if defined, otherwise the value of the FSWatcher instance's `closed` flag
|
||||
*/
|
||||
_emit(event: EventName, path: Path, stats?: Stats): Promise<this | undefined>;
|
||||
/**
|
||||
* Common handler for errors
|
||||
* @returns The error if defined, otherwise the value of the FSWatcher instance's `closed` flag
|
||||
*/
|
||||
_handleError(error: Error): Error | boolean;
|
||||
/**
|
||||
* Helper utility for throttling
|
||||
* @param actionType type being throttled
|
||||
* @param path being acted upon
|
||||
* @param timeout duration of time to suppress duplicate actions
|
||||
* @returns tracking object or false if action should be suppressed
|
||||
*/
|
||||
_throttle(actionType: ThrottleType, path: Path, timeout: number): Throttler | false;
|
||||
_incrReadyCount(): number;
|
||||
/**
|
||||
* Awaits write operation to finish.
|
||||
* Polls a newly created file for size variations. When files size does not change for 'threshold' milliseconds calls callback.
|
||||
* @param path being acted upon
|
||||
* @param threshold Time in milliseconds a file size must be fixed before acknowledging write OP is finished
|
||||
* @param event
|
||||
* @param awfEmit Callback to be called when ready for event to be emitted.
|
||||
*/
|
||||
_awaitWriteFinish(path: Path, threshold: number, event: EventName, awfEmit: (err?: Error, stat?: Stats) => void): void;
|
||||
/**
|
||||
* Determines whether user has asked to ignore this path.
|
||||
*/
|
||||
_isIgnored(path: Path, stats?: Stats): boolean;
|
||||
_isntIgnored(path: Path, stat?: Stats): boolean;
|
||||
/**
|
||||
* Provides a set of common helpers and properties relating to symlink handling.
|
||||
* @param path file or directory pattern being watched
|
||||
*/
|
||||
_getWatchHelpers(path: Path): WatchHelper;
|
||||
/**
|
||||
* Provides directory tracking objects
|
||||
* @param directory path of the directory
|
||||
*/
|
||||
_getWatchedDir(directory: string): DirEntry;
|
||||
/**
|
||||
* Check for read permissions: https://stackoverflow.com/a/11781404/1358405
|
||||
*/
|
||||
_hasReadPermissions(stats: Stats): boolean;
|
||||
/**
|
||||
* Handles emitting unlink events for
|
||||
* files and directories, and via recursion, for
|
||||
* files and directories within directories that are unlinked
|
||||
* @param directory within which the following item is located
|
||||
* @param item base path of item/directory
|
||||
*/
|
||||
_remove(directory: string, item: string, isDirectory?: boolean): void;
|
||||
/**
|
||||
* Closes all watchers for a path
|
||||
*/
|
||||
_closePath(path: Path): void;
|
||||
/**
|
||||
* Closes only file-specific watchers
|
||||
*/
|
||||
_closeFile(path: Path): void;
|
||||
_addPathCloser(path: Path, closer: () => void): void;
|
||||
_readdirp(root: Path, opts?: Partial<ReaddirpOptions>): ReaddirpStream | undefined;
|
||||
}
|
||||
/**
|
||||
* Instantiates watcher with paths to be tracked.
|
||||
* @param paths file / directory paths
|
||||
* @param options opts, such as `atomic`, `awaitWriteFinish`, `ignored`, and others
|
||||
* @returns an instance of FSWatcher for chaining.
|
||||
* @example
|
||||
* const watcher = watch('.').on('all', (event, path) => { console.log(event, path); });
|
||||
* watch('.', { atomic: true, awaitWriteFinish: true, ignored: (f, stats) => stats?.isFile() && !f.endsWith('.js') })
|
||||
*/
|
||||
export declare function watch(paths: string | string[], options?: ChokidarOptions): FSWatcher;
|
||||
declare const _default: {
|
||||
watch: typeof watch;
|
||||
FSWatcher: typeof FSWatcher;
|
||||
};
|
||||
export default _default;
|
||||
798
node_modules/chokidar/esm/index.js
generated
vendored
Normal file
798
node_modules/chokidar/esm/index.js
generated
vendored
Normal file
@@ -0,0 +1,798 @@
|
||||
/*! chokidar - MIT License (c) 2012 Paul Miller (paulmillr.com) */
|
||||
import { stat as statcb } from 'fs';
|
||||
import { stat, readdir } from 'fs/promises';
|
||||
import { EventEmitter } from 'events';
|
||||
import * as sysPath from 'path';
|
||||
import { readdirp } from 'readdirp';
|
||||
import { NodeFsHandler, EVENTS as EV, isWindows, isIBMi, EMPTY_FN, STR_CLOSE, STR_END, } from './handler.js';
|
||||
const SLASH = '/';
|
||||
const SLASH_SLASH = '//';
|
||||
const ONE_DOT = '.';
|
||||
const TWO_DOTS = '..';
|
||||
const STRING_TYPE = 'string';
|
||||
const BACK_SLASH_RE = /\\/g;
|
||||
const DOUBLE_SLASH_RE = /\/\//;
|
||||
const DOT_RE = /\..*\.(sw[px])$|~$|\.subl.*\.tmp/;
|
||||
const REPLACER_RE = /^\.[/\\]/;
|
||||
function arrify(item) {
|
||||
return Array.isArray(item) ? item : [item];
|
||||
}
|
||||
const isMatcherObject = (matcher) => typeof matcher === 'object' && matcher !== null && !(matcher instanceof RegExp);
|
||||
function createPattern(matcher) {
|
||||
if (typeof matcher === 'function')
|
||||
return matcher;
|
||||
if (typeof matcher === 'string')
|
||||
return (string) => matcher === string;
|
||||
if (matcher instanceof RegExp)
|
||||
return (string) => matcher.test(string);
|
||||
if (typeof matcher === 'object' && matcher !== null) {
|
||||
return (string) => {
|
||||
if (matcher.path === string)
|
||||
return true;
|
||||
if (matcher.recursive) {
|
||||
const relative = sysPath.relative(matcher.path, string);
|
||||
if (!relative) {
|
||||
return false;
|
||||
}
|
||||
return !relative.startsWith('..') && !sysPath.isAbsolute(relative);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
}
|
||||
return () => false;
|
||||
}
|
||||
function normalizePath(path) {
|
||||
if (typeof path !== 'string')
|
||||
throw new Error('string expected');
|
||||
path = sysPath.normalize(path);
|
||||
path = path.replace(/\\/g, '/');
|
||||
let prepend = false;
|
||||
if (path.startsWith('//'))
|
||||
prepend = true;
|
||||
const DOUBLE_SLASH_RE = /\/\//;
|
||||
while (path.match(DOUBLE_SLASH_RE))
|
||||
path = path.replace(DOUBLE_SLASH_RE, '/');
|
||||
if (prepend)
|
||||
path = '/' + path;
|
||||
return path;
|
||||
}
|
||||
function matchPatterns(patterns, testString, stats) {
|
||||
const path = normalizePath(testString);
|
||||
for (let index = 0; index < patterns.length; index++) {
|
||||
const pattern = patterns[index];
|
||||
if (pattern(path, stats)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function anymatch(matchers, testString) {
|
||||
if (matchers == null) {
|
||||
throw new TypeError('anymatch: specify first argument');
|
||||
}
|
||||
// Early cache for matchers.
|
||||
const matchersArray = arrify(matchers);
|
||||
const patterns = matchersArray.map((matcher) => createPattern(matcher));
|
||||
if (testString == null) {
|
||||
return (testString, stats) => {
|
||||
return matchPatterns(patterns, testString, stats);
|
||||
};
|
||||
}
|
||||
return matchPatterns(patterns, testString);
|
||||
}
|
||||
const unifyPaths = (paths_) => {
|
||||
const paths = arrify(paths_).flat();
|
||||
if (!paths.every((p) => typeof p === STRING_TYPE)) {
|
||||
throw new TypeError(`Non-string provided as watch path: ${paths}`);
|
||||
}
|
||||
return paths.map(normalizePathToUnix);
|
||||
};
|
||||
// If SLASH_SLASH occurs at the beginning of path, it is not replaced
|
||||
// because "//StoragePC/DrivePool/Movies" is a valid network path
|
||||
const toUnix = (string) => {
|
||||
let str = string.replace(BACK_SLASH_RE, SLASH);
|
||||
let prepend = false;
|
||||
if (str.startsWith(SLASH_SLASH)) {
|
||||
prepend = true;
|
||||
}
|
||||
while (str.match(DOUBLE_SLASH_RE)) {
|
||||
str = str.replace(DOUBLE_SLASH_RE, SLASH);
|
||||
}
|
||||
if (prepend) {
|
||||
str = SLASH + str;
|
||||
}
|
||||
return str;
|
||||
};
|
||||
// Our version of upath.normalize
|
||||
// TODO: this is not equal to path-normalize module - investigate why
|
||||
const normalizePathToUnix = (path) => toUnix(sysPath.normalize(toUnix(path)));
|
||||
// TODO: refactor
|
||||
const normalizeIgnored = (cwd = '') => (path) => {
|
||||
if (typeof path === 'string') {
|
||||
return normalizePathToUnix(sysPath.isAbsolute(path) ? path : sysPath.join(cwd, path));
|
||||
}
|
||||
else {
|
||||
return path;
|
||||
}
|
||||
};
|
||||
const getAbsolutePath = (path, cwd) => {
|
||||
if (sysPath.isAbsolute(path)) {
|
||||
return path;
|
||||
}
|
||||
return sysPath.join(cwd, path);
|
||||
};
|
||||
const EMPTY_SET = Object.freeze(new Set());
|
||||
/**
|
||||
* Directory entry.
|
||||
*/
|
||||
class DirEntry {
|
||||
constructor(dir, removeWatcher) {
|
||||
this.path = dir;
|
||||
this._removeWatcher = removeWatcher;
|
||||
this.items = new Set();
|
||||
}
|
||||
add(item) {
|
||||
const { items } = this;
|
||||
if (!items)
|
||||
return;
|
||||
if (item !== ONE_DOT && item !== TWO_DOTS)
|
||||
items.add(item);
|
||||
}
|
||||
async remove(item) {
|
||||
const { items } = this;
|
||||
if (!items)
|
||||
return;
|
||||
items.delete(item);
|
||||
if (items.size > 0)
|
||||
return;
|
||||
const dir = this.path;
|
||||
try {
|
||||
await readdir(dir);
|
||||
}
|
||||
catch (err) {
|
||||
if (this._removeWatcher) {
|
||||
this._removeWatcher(sysPath.dirname(dir), sysPath.basename(dir));
|
||||
}
|
||||
}
|
||||
}
|
||||
has(item) {
|
||||
const { items } = this;
|
||||
if (!items)
|
||||
return;
|
||||
return items.has(item);
|
||||
}
|
||||
getChildren() {
|
||||
const { items } = this;
|
||||
if (!items)
|
||||
return [];
|
||||
return [...items.values()];
|
||||
}
|
||||
dispose() {
|
||||
this.items.clear();
|
||||
this.path = '';
|
||||
this._removeWatcher = EMPTY_FN;
|
||||
this.items = EMPTY_SET;
|
||||
Object.freeze(this);
|
||||
}
|
||||
}
|
||||
const STAT_METHOD_F = 'stat';
|
||||
const STAT_METHOD_L = 'lstat';
|
||||
export class WatchHelper {
|
||||
constructor(path, follow, fsw) {
|
||||
this.fsw = fsw;
|
||||
const watchPath = path;
|
||||
this.path = path = path.replace(REPLACER_RE, '');
|
||||
this.watchPath = watchPath;
|
||||
this.fullWatchPath = sysPath.resolve(watchPath);
|
||||
this.dirParts = [];
|
||||
this.dirParts.forEach((parts) => {
|
||||
if (parts.length > 1)
|
||||
parts.pop();
|
||||
});
|
||||
this.followSymlinks = follow;
|
||||
this.statMethod = follow ? STAT_METHOD_F : STAT_METHOD_L;
|
||||
}
|
||||
entryPath(entry) {
|
||||
return sysPath.join(this.watchPath, sysPath.relative(this.watchPath, entry.fullPath));
|
||||
}
|
||||
filterPath(entry) {
|
||||
const { stats } = entry;
|
||||
if (stats && stats.isSymbolicLink())
|
||||
return this.filterDir(entry);
|
||||
const resolvedPath = this.entryPath(entry);
|
||||
// TODO: what if stats is undefined? remove !
|
||||
return this.fsw._isntIgnored(resolvedPath, stats) && this.fsw._hasReadPermissions(stats);
|
||||
}
|
||||
filterDir(entry) {
|
||||
return this.fsw._isntIgnored(this.entryPath(entry), entry.stats);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Watches files & directories for changes. Emitted events:
|
||||
* `add`, `addDir`, `change`, `unlink`, `unlinkDir`, `all`, `error`
|
||||
*
|
||||
* new FSWatcher()
|
||||
* .add(directories)
|
||||
* .on('add', path => log('File', path, 'was added'))
|
||||
*/
|
||||
export class FSWatcher extends EventEmitter {
|
||||
// Not indenting methods for history sake; for now.
|
||||
constructor(_opts = {}) {
|
||||
super();
|
||||
this.closed = false;
|
||||
this._closers = new Map();
|
||||
this._ignoredPaths = new Set();
|
||||
this._throttled = new Map();
|
||||
this._streams = new Set();
|
||||
this._symlinkPaths = new Map();
|
||||
this._watched = new Map();
|
||||
this._pendingWrites = new Map();
|
||||
this._pendingUnlinks = new Map();
|
||||
this._readyCount = 0;
|
||||
this._readyEmitted = false;
|
||||
const awf = _opts.awaitWriteFinish;
|
||||
const DEF_AWF = { stabilityThreshold: 2000, pollInterval: 100 };
|
||||
const opts = {
|
||||
// Defaults
|
||||
persistent: true,
|
||||
ignoreInitial: false,
|
||||
ignorePermissionErrors: false,
|
||||
interval: 100,
|
||||
binaryInterval: 300,
|
||||
followSymlinks: true,
|
||||
usePolling: false,
|
||||
// useAsync: false,
|
||||
atomic: true, // NOTE: overwritten later (depends on usePolling)
|
||||
..._opts,
|
||||
// Change format
|
||||
ignored: _opts.ignored ? arrify(_opts.ignored) : arrify([]),
|
||||
awaitWriteFinish: awf === true ? DEF_AWF : typeof awf === 'object' ? { ...DEF_AWF, ...awf } : false,
|
||||
};
|
||||
// Always default to polling on IBM i because fs.watch() is not available on IBM i.
|
||||
if (isIBMi)
|
||||
opts.usePolling = true;
|
||||
// Editor atomic write normalization enabled by default with fs.watch
|
||||
if (opts.atomic === undefined)
|
||||
opts.atomic = !opts.usePolling;
|
||||
// opts.atomic = typeof _opts.atomic === 'number' ? _opts.atomic : 100;
|
||||
// Global override. Useful for developers, who need to force polling for all
|
||||
// instances of chokidar, regardless of usage / dependency depth
|
||||
const envPoll = process.env.CHOKIDAR_USEPOLLING;
|
||||
if (envPoll !== undefined) {
|
||||
const envLower = envPoll.toLowerCase();
|
||||
if (envLower === 'false' || envLower === '0')
|
||||
opts.usePolling = false;
|
||||
else if (envLower === 'true' || envLower === '1')
|
||||
opts.usePolling = true;
|
||||
else
|
||||
opts.usePolling = !!envLower;
|
||||
}
|
||||
const envInterval = process.env.CHOKIDAR_INTERVAL;
|
||||
if (envInterval)
|
||||
opts.interval = Number.parseInt(envInterval, 10);
|
||||
// This is done to emit ready only once, but each 'add' will increase that?
|
||||
let readyCalls = 0;
|
||||
this._emitReady = () => {
|
||||
readyCalls++;
|
||||
if (readyCalls >= this._readyCount) {
|
||||
this._emitReady = EMPTY_FN;
|
||||
this._readyEmitted = true;
|
||||
// use process.nextTick to allow time for listener to be bound
|
||||
process.nextTick(() => this.emit(EV.READY));
|
||||
}
|
||||
};
|
||||
this._emitRaw = (...args) => this.emit(EV.RAW, ...args);
|
||||
this._boundRemove = this._remove.bind(this);
|
||||
this.options = opts;
|
||||
this._nodeFsHandler = new NodeFsHandler(this);
|
||||
// You’re frozen when your heart’s not open.
|
||||
Object.freeze(opts);
|
||||
}
|
||||
_addIgnoredPath(matcher) {
|
||||
if (isMatcherObject(matcher)) {
|
||||
// return early if we already have a deeply equal matcher object
|
||||
for (const ignored of this._ignoredPaths) {
|
||||
if (isMatcherObject(ignored) &&
|
||||
ignored.path === matcher.path &&
|
||||
ignored.recursive === matcher.recursive) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
this._ignoredPaths.add(matcher);
|
||||
}
|
||||
_removeIgnoredPath(matcher) {
|
||||
this._ignoredPaths.delete(matcher);
|
||||
// now find any matcher objects with the matcher as path
|
||||
if (typeof matcher === 'string') {
|
||||
for (const ignored of this._ignoredPaths) {
|
||||
// TODO (43081j): make this more efficient.
|
||||
// probably just make a `this._ignoredDirectories` or some
|
||||
// such thing.
|
||||
if (isMatcherObject(ignored) && ignored.path === matcher) {
|
||||
this._ignoredPaths.delete(ignored);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Public methods
|
||||
/**
|
||||
* Adds paths to be watched on an existing FSWatcher instance.
|
||||
* @param paths_ file or file list. Other arguments are unused
|
||||
*/
|
||||
add(paths_, _origAdd, _internal) {
|
||||
const { cwd } = this.options;
|
||||
this.closed = false;
|
||||
this._closePromise = undefined;
|
||||
let paths = unifyPaths(paths_);
|
||||
if (cwd) {
|
||||
paths = paths.map((path) => {
|
||||
const absPath = getAbsolutePath(path, cwd);
|
||||
// Check `path` instead of `absPath` because the cwd portion can't be a glob
|
||||
return absPath;
|
||||
});
|
||||
}
|
||||
paths.forEach((path) => {
|
||||
this._removeIgnoredPath(path);
|
||||
});
|
||||
this._userIgnored = undefined;
|
||||
if (!this._readyCount)
|
||||
this._readyCount = 0;
|
||||
this._readyCount += paths.length;
|
||||
Promise.all(paths.map(async (path) => {
|
||||
const res = await this._nodeFsHandler._addToNodeFs(path, !_internal, undefined, 0, _origAdd);
|
||||
if (res)
|
||||
this._emitReady();
|
||||
return res;
|
||||
})).then((results) => {
|
||||
if (this.closed)
|
||||
return;
|
||||
results.forEach((item) => {
|
||||
if (item)
|
||||
this.add(sysPath.dirname(item), sysPath.basename(_origAdd || item));
|
||||
});
|
||||
});
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Close watchers or start ignoring events from specified paths.
|
||||
*/
|
||||
unwatch(paths_) {
|
||||
if (this.closed)
|
||||
return this;
|
||||
const paths = unifyPaths(paths_);
|
||||
const { cwd } = this.options;
|
||||
paths.forEach((path) => {
|
||||
// convert to absolute path unless relative path already matches
|
||||
if (!sysPath.isAbsolute(path) && !this._closers.has(path)) {
|
||||
if (cwd)
|
||||
path = sysPath.join(cwd, path);
|
||||
path = sysPath.resolve(path);
|
||||
}
|
||||
this._closePath(path);
|
||||
this._addIgnoredPath(path);
|
||||
if (this._watched.has(path)) {
|
||||
this._addIgnoredPath({
|
||||
path,
|
||||
recursive: true,
|
||||
});
|
||||
}
|
||||
// reset the cached userIgnored anymatch fn
|
||||
// to make ignoredPaths changes effective
|
||||
this._userIgnored = undefined;
|
||||
});
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Close watchers and remove all listeners from watched paths.
|
||||
*/
|
||||
close() {
|
||||
if (this._closePromise) {
|
||||
return this._closePromise;
|
||||
}
|
||||
this.closed = true;
|
||||
// Memory management.
|
||||
this.removeAllListeners();
|
||||
const closers = [];
|
||||
this._closers.forEach((closerList) => closerList.forEach((closer) => {
|
||||
const promise = closer();
|
||||
if (promise instanceof Promise)
|
||||
closers.push(promise);
|
||||
}));
|
||||
this._streams.forEach((stream) => stream.destroy());
|
||||
this._userIgnored = undefined;
|
||||
this._readyCount = 0;
|
||||
this._readyEmitted = false;
|
||||
this._watched.forEach((dirent) => dirent.dispose());
|
||||
this._closers.clear();
|
||||
this._watched.clear();
|
||||
this._streams.clear();
|
||||
this._symlinkPaths.clear();
|
||||
this._throttled.clear();
|
||||
this._closePromise = closers.length
|
||||
? Promise.all(closers).then(() => undefined)
|
||||
: Promise.resolve();
|
||||
return this._closePromise;
|
||||
}
|
||||
/**
|
||||
* Expose list of watched paths
|
||||
* @returns for chaining
|
||||
*/
|
||||
getWatched() {
|
||||
const watchList = {};
|
||||
this._watched.forEach((entry, dir) => {
|
||||
const key = this.options.cwd ? sysPath.relative(this.options.cwd, dir) : dir;
|
||||
const index = key || ONE_DOT;
|
||||
watchList[index] = entry.getChildren().sort();
|
||||
});
|
||||
return watchList;
|
||||
}
|
||||
emitWithAll(event, args) {
|
||||
this.emit(event, ...args);
|
||||
if (event !== EV.ERROR)
|
||||
this.emit(EV.ALL, event, ...args);
|
||||
}
|
||||
// Common helpers
|
||||
// --------------
|
||||
/**
|
||||
* Normalize and emit events.
|
||||
* Calling _emit DOES NOT MEAN emit() would be called!
|
||||
* @param event Type of event
|
||||
* @param path File or directory path
|
||||
* @param stats arguments to be passed with event
|
||||
* @returns the error if defined, otherwise the value of the FSWatcher instance's `closed` flag
|
||||
*/
|
||||
async _emit(event, path, stats) {
|
||||
if (this.closed)
|
||||
return;
|
||||
const opts = this.options;
|
||||
if (isWindows)
|
||||
path = sysPath.normalize(path);
|
||||
if (opts.cwd)
|
||||
path = sysPath.relative(opts.cwd, path);
|
||||
const args = [path];
|
||||
if (stats != null)
|
||||
args.push(stats);
|
||||
const awf = opts.awaitWriteFinish;
|
||||
let pw;
|
||||
if (awf && (pw = this._pendingWrites.get(path))) {
|
||||
pw.lastChange = new Date();
|
||||
return this;
|
||||
}
|
||||
if (opts.atomic) {
|
||||
if (event === EV.UNLINK) {
|
||||
this._pendingUnlinks.set(path, [event, ...args]);
|
||||
setTimeout(() => {
|
||||
this._pendingUnlinks.forEach((entry, path) => {
|
||||
this.emit(...entry);
|
||||
this.emit(EV.ALL, ...entry);
|
||||
this._pendingUnlinks.delete(path);
|
||||
});
|
||||
}, typeof opts.atomic === 'number' ? opts.atomic : 100);
|
||||
return this;
|
||||
}
|
||||
if (event === EV.ADD && this._pendingUnlinks.has(path)) {
|
||||
event = EV.CHANGE;
|
||||
this._pendingUnlinks.delete(path);
|
||||
}
|
||||
}
|
||||
if (awf && (event === EV.ADD || event === EV.CHANGE) && this._readyEmitted) {
|
||||
const awfEmit = (err, stats) => {
|
||||
if (err) {
|
||||
event = EV.ERROR;
|
||||
args[0] = err;
|
||||
this.emitWithAll(event, args);
|
||||
}
|
||||
else if (stats) {
|
||||
// if stats doesn't exist the file must have been deleted
|
||||
if (args.length > 1) {
|
||||
args[1] = stats;
|
||||
}
|
||||
else {
|
||||
args.push(stats);
|
||||
}
|
||||
this.emitWithAll(event, args);
|
||||
}
|
||||
};
|
||||
this._awaitWriteFinish(path, awf.stabilityThreshold, event, awfEmit);
|
||||
return this;
|
||||
}
|
||||
if (event === EV.CHANGE) {
|
||||
const isThrottled = !this._throttle(EV.CHANGE, path, 50);
|
||||
if (isThrottled)
|
||||
return this;
|
||||
}
|
||||
if (opts.alwaysStat &&
|
||||
stats === undefined &&
|
||||
(event === EV.ADD || event === EV.ADD_DIR || event === EV.CHANGE)) {
|
||||
const fullPath = opts.cwd ? sysPath.join(opts.cwd, path) : path;
|
||||
let stats;
|
||||
try {
|
||||
stats = await stat(fullPath);
|
||||
}
|
||||
catch (err) {
|
||||
// do nothing
|
||||
}
|
||||
// Suppress event when fs_stat fails, to avoid sending undefined 'stat'
|
||||
if (!stats || this.closed)
|
||||
return;
|
||||
args.push(stats);
|
||||
}
|
||||
this.emitWithAll(event, args);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Common handler for errors
|
||||
* @returns The error if defined, otherwise the value of the FSWatcher instance's `closed` flag
|
||||
*/
|
||||
_handleError(error) {
|
||||
const code = error && error.code;
|
||||
if (error &&
|
||||
code !== 'ENOENT' &&
|
||||
code !== 'ENOTDIR' &&
|
||||
(!this.options.ignorePermissionErrors || (code !== 'EPERM' && code !== 'EACCES'))) {
|
||||
this.emit(EV.ERROR, error);
|
||||
}
|
||||
return error || this.closed;
|
||||
}
|
||||
/**
|
||||
* Helper utility for throttling
|
||||
* @param actionType type being throttled
|
||||
* @param path being acted upon
|
||||
* @param timeout duration of time to suppress duplicate actions
|
||||
* @returns tracking object or false if action should be suppressed
|
||||
*/
|
||||
_throttle(actionType, path, timeout) {
|
||||
if (!this._throttled.has(actionType)) {
|
||||
this._throttled.set(actionType, new Map());
|
||||
}
|
||||
const action = this._throttled.get(actionType);
|
||||
if (!action)
|
||||
throw new Error('invalid throttle');
|
||||
const actionPath = action.get(path);
|
||||
if (actionPath) {
|
||||
actionPath.count++;
|
||||
return false;
|
||||
}
|
||||
// eslint-disable-next-line prefer-const
|
||||
let timeoutObject;
|
||||
const clear = () => {
|
||||
const item = action.get(path);
|
||||
const count = item ? item.count : 0;
|
||||
action.delete(path);
|
||||
clearTimeout(timeoutObject);
|
||||
if (item)
|
||||
clearTimeout(item.timeoutObject);
|
||||
return count;
|
||||
};
|
||||
timeoutObject = setTimeout(clear, timeout);
|
||||
const thr = { timeoutObject, clear, count: 0 };
|
||||
action.set(path, thr);
|
||||
return thr;
|
||||
}
|
||||
_incrReadyCount() {
|
||||
return this._readyCount++;
|
||||
}
|
||||
/**
|
||||
* Awaits write operation to finish.
|
||||
* Polls a newly created file for size variations. When files size does not change for 'threshold' milliseconds calls callback.
|
||||
* @param path being acted upon
|
||||
* @param threshold Time in milliseconds a file size must be fixed before acknowledging write OP is finished
|
||||
* @param event
|
||||
* @param awfEmit Callback to be called when ready for event to be emitted.
|
||||
*/
|
||||
_awaitWriteFinish(path, threshold, event, awfEmit) {
|
||||
const awf = this.options.awaitWriteFinish;
|
||||
if (typeof awf !== 'object')
|
||||
return;
|
||||
const pollInterval = awf.pollInterval;
|
||||
let timeoutHandler;
|
||||
let fullPath = path;
|
||||
if (this.options.cwd && !sysPath.isAbsolute(path)) {
|
||||
fullPath = sysPath.join(this.options.cwd, path);
|
||||
}
|
||||
const now = new Date();
|
||||
const writes = this._pendingWrites;
|
||||
function awaitWriteFinishFn(prevStat) {
|
||||
statcb(fullPath, (err, curStat) => {
|
||||
if (err || !writes.has(path)) {
|
||||
if (err && err.code !== 'ENOENT')
|
||||
awfEmit(err);
|
||||
return;
|
||||
}
|
||||
const now = Number(new Date());
|
||||
if (prevStat && curStat.size !== prevStat.size) {
|
||||
writes.get(path).lastChange = now;
|
||||
}
|
||||
const pw = writes.get(path);
|
||||
const df = now - pw.lastChange;
|
||||
if (df >= threshold) {
|
||||
writes.delete(path);
|
||||
awfEmit(undefined, curStat);
|
||||
}
|
||||
else {
|
||||
timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval, curStat);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (!writes.has(path)) {
|
||||
writes.set(path, {
|
||||
lastChange: now,
|
||||
cancelWait: () => {
|
||||
writes.delete(path);
|
||||
clearTimeout(timeoutHandler);
|
||||
return event;
|
||||
},
|
||||
});
|
||||
timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Determines whether user has asked to ignore this path.
|
||||
*/
|
||||
_isIgnored(path, stats) {
|
||||
if (this.options.atomic && DOT_RE.test(path))
|
||||
return true;
|
||||
if (!this._userIgnored) {
|
||||
const { cwd } = this.options;
|
||||
const ign = this.options.ignored;
|
||||
const ignored = (ign || []).map(normalizeIgnored(cwd));
|
||||
const ignoredPaths = [...this._ignoredPaths];
|
||||
const list = [...ignoredPaths.map(normalizeIgnored(cwd)), ...ignored];
|
||||
this._userIgnored = anymatch(list, undefined);
|
||||
}
|
||||
return this._userIgnored(path, stats);
|
||||
}
|
||||
_isntIgnored(path, stat) {
|
||||
return !this._isIgnored(path, stat);
|
||||
}
|
||||
/**
|
||||
* Provides a set of common helpers and properties relating to symlink handling.
|
||||
* @param path file or directory pattern being watched
|
||||
*/
|
||||
_getWatchHelpers(path) {
|
||||
return new WatchHelper(path, this.options.followSymlinks, this);
|
||||
}
|
||||
// Directory helpers
|
||||
// -----------------
|
||||
/**
|
||||
* Provides directory tracking objects
|
||||
* @param directory path of the directory
|
||||
*/
|
||||
_getWatchedDir(directory) {
|
||||
const dir = sysPath.resolve(directory);
|
||||
if (!this._watched.has(dir))
|
||||
this._watched.set(dir, new DirEntry(dir, this._boundRemove));
|
||||
return this._watched.get(dir);
|
||||
}
|
||||
// File helpers
|
||||
// ------------
|
||||
/**
|
||||
* Check for read permissions: https://stackoverflow.com/a/11781404/1358405
|
||||
*/
|
||||
_hasReadPermissions(stats) {
|
||||
if (this.options.ignorePermissionErrors)
|
||||
return true;
|
||||
return Boolean(Number(stats.mode) & 0o400);
|
||||
}
|
||||
/**
|
||||
* Handles emitting unlink events for
|
||||
* files and directories, and via recursion, for
|
||||
* files and directories within directories that are unlinked
|
||||
* @param directory within which the following item is located
|
||||
* @param item base path of item/directory
|
||||
*/
|
||||
_remove(directory, item, isDirectory) {
|
||||
// if what is being deleted is a directory, get that directory's paths
|
||||
// for recursive deleting and cleaning of watched object
|
||||
// if it is not a directory, nestedDirectoryChildren will be empty array
|
||||
const path = sysPath.join(directory, item);
|
||||
const fullPath = sysPath.resolve(path);
|
||||
isDirectory =
|
||||
isDirectory != null ? isDirectory : this._watched.has(path) || this._watched.has(fullPath);
|
||||
// prevent duplicate handling in case of arriving here nearly simultaneously
|
||||
// via multiple paths (such as _handleFile and _handleDir)
|
||||
if (!this._throttle('remove', path, 100))
|
||||
return;
|
||||
// if the only watched file is removed, watch for its return
|
||||
if (!isDirectory && this._watched.size === 1) {
|
||||
this.add(directory, item, true);
|
||||
}
|
||||
// This will create a new entry in the watched object in either case
|
||||
// so we got to do the directory check beforehand
|
||||
const wp = this._getWatchedDir(path);
|
||||
const nestedDirectoryChildren = wp.getChildren();
|
||||
// Recursively remove children directories / files.
|
||||
nestedDirectoryChildren.forEach((nested) => this._remove(path, nested));
|
||||
// Check if item was on the watched list and remove it
|
||||
const parent = this._getWatchedDir(directory);
|
||||
const wasTracked = parent.has(item);
|
||||
parent.remove(item);
|
||||
// Fixes issue #1042 -> Relative paths were detected and added as symlinks
|
||||
// (https://github.com/paulmillr/chokidar/blob/e1753ddbc9571bdc33b4a4af172d52cb6e611c10/lib/nodefs-handler.js#L612),
|
||||
// but never removed from the map in case the path was deleted.
|
||||
// This leads to an incorrect state if the path was recreated:
|
||||
// https://github.com/paulmillr/chokidar/blob/e1753ddbc9571bdc33b4a4af172d52cb6e611c10/lib/nodefs-handler.js#L553
|
||||
if (this._symlinkPaths.has(fullPath)) {
|
||||
this._symlinkPaths.delete(fullPath);
|
||||
}
|
||||
// If we wait for this file to be fully written, cancel the wait.
|
||||
let relPath = path;
|
||||
if (this.options.cwd)
|
||||
relPath = sysPath.relative(this.options.cwd, path);
|
||||
if (this.options.awaitWriteFinish && this._pendingWrites.has(relPath)) {
|
||||
const event = this._pendingWrites.get(relPath).cancelWait();
|
||||
if (event === EV.ADD)
|
||||
return;
|
||||
}
|
||||
// The Entry will either be a directory that just got removed
|
||||
// or a bogus entry to a file, in either case we have to remove it
|
||||
this._watched.delete(path);
|
||||
this._watched.delete(fullPath);
|
||||
const eventName = isDirectory ? EV.UNLINK_DIR : EV.UNLINK;
|
||||
if (wasTracked && !this._isIgnored(path))
|
||||
this._emit(eventName, path);
|
||||
// Avoid conflicts if we later create another file with the same name
|
||||
this._closePath(path);
|
||||
}
|
||||
/**
|
||||
* Closes all watchers for a path
|
||||
*/
|
||||
_closePath(path) {
|
||||
this._closeFile(path);
|
||||
const dir = sysPath.dirname(path);
|
||||
this._getWatchedDir(dir).remove(sysPath.basename(path));
|
||||
}
|
||||
/**
|
||||
* Closes only file-specific watchers
|
||||
*/
|
||||
_closeFile(path) {
|
||||
const closers = this._closers.get(path);
|
||||
if (!closers)
|
||||
return;
|
||||
closers.forEach((closer) => closer());
|
||||
this._closers.delete(path);
|
||||
}
|
||||
_addPathCloser(path, closer) {
|
||||
if (!closer)
|
||||
return;
|
||||
let list = this._closers.get(path);
|
||||
if (!list) {
|
||||
list = [];
|
||||
this._closers.set(path, list);
|
||||
}
|
||||
list.push(closer);
|
||||
}
|
||||
_readdirp(root, opts) {
|
||||
if (this.closed)
|
||||
return;
|
||||
const options = { type: EV.ALL, alwaysStat: true, lstat: true, ...opts, depth: 0 };
|
||||
let stream = readdirp(root, options);
|
||||
this._streams.add(stream);
|
||||
stream.once(STR_CLOSE, () => {
|
||||
stream = undefined;
|
||||
});
|
||||
stream.once(STR_END, () => {
|
||||
if (stream) {
|
||||
this._streams.delete(stream);
|
||||
stream = undefined;
|
||||
}
|
||||
});
|
||||
return stream;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Instantiates watcher with paths to be tracked.
|
||||
* @param paths file / directory paths
|
||||
* @param options opts, such as `atomic`, `awaitWriteFinish`, `ignored`, and others
|
||||
* @returns an instance of FSWatcher for chaining.
|
||||
* @example
|
||||
* const watcher = watch('.').on('all', (event, path) => { console.log(event, path); });
|
||||
* watch('.', { atomic: true, awaitWriteFinish: true, ignored: (f, stats) => stats?.isFile() && !f.endsWith('.js') })
|
||||
*/
|
||||
export function watch(paths, options = {}) {
|
||||
const watcher = new FSWatcher(options);
|
||||
watcher.add(paths);
|
||||
return watcher;
|
||||
}
|
||||
export default { watch, FSWatcher };
|
||||
1
node_modules/chokidar/esm/package.json
generated
vendored
Normal file
1
node_modules/chokidar/esm/package.json
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{ "type": "module", "sideEffects": false }
|
||||
90
node_modules/chokidar/handler.d.ts
generated
vendored
Normal file
90
node_modules/chokidar/handler.d.ts
generated
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
import type { WatchEventType, Stats, FSWatcher as NativeFsWatcher } from 'fs';
|
||||
import type { FSWatcher, WatchHelper, Throttler } from './index.js';
|
||||
import type { EntryInfo } from 'readdirp';
|
||||
export type Path = string;
|
||||
export declare const STR_DATA = "data";
|
||||
export declare const STR_END = "end";
|
||||
export declare const STR_CLOSE = "close";
|
||||
export declare const EMPTY_FN: () => void;
|
||||
export declare const IDENTITY_FN: (val: unknown) => unknown;
|
||||
export declare const isWindows: boolean;
|
||||
export declare const isMacos: boolean;
|
||||
export declare const isLinux: boolean;
|
||||
export declare const isFreeBSD: boolean;
|
||||
export declare const isIBMi: boolean;
|
||||
export declare const EVENTS: {
|
||||
readonly ALL: "all";
|
||||
readonly READY: "ready";
|
||||
readonly ADD: "add";
|
||||
readonly CHANGE: "change";
|
||||
readonly ADD_DIR: "addDir";
|
||||
readonly UNLINK: "unlink";
|
||||
readonly UNLINK_DIR: "unlinkDir";
|
||||
readonly RAW: "raw";
|
||||
readonly ERROR: "error";
|
||||
};
|
||||
export type EventName = (typeof EVENTS)[keyof typeof EVENTS];
|
||||
export type FsWatchContainer = {
|
||||
listeners: (path: string) => void | Set<any>;
|
||||
errHandlers: (err: unknown) => void | Set<any>;
|
||||
rawEmitters: (ev: WatchEventType, path: string, opts: unknown) => void | Set<any>;
|
||||
watcher: NativeFsWatcher;
|
||||
watcherUnusable?: boolean;
|
||||
};
|
||||
export interface WatchHandlers {
|
||||
listener: (path: string) => void;
|
||||
errHandler: (err: unknown) => void;
|
||||
rawEmitter: (ev: WatchEventType, path: string, opts: unknown) => void;
|
||||
}
|
||||
/**
|
||||
* @mixin
|
||||
*/
|
||||
export declare class NodeFsHandler {
|
||||
fsw: FSWatcher;
|
||||
_boundHandleError: (error: unknown) => void;
|
||||
constructor(fsW: FSWatcher);
|
||||
/**
|
||||
* Watch file for changes with fs_watchFile or fs_watch.
|
||||
* @param path to file or dir
|
||||
* @param listener on fs change
|
||||
* @returns closer for the watcher instance
|
||||
*/
|
||||
_watchWithNodeFs(path: string, listener: (path: string, newStats?: any) => void | Promise<void>): (() => void) | undefined;
|
||||
/**
|
||||
* Watch a file and emit add event if warranted.
|
||||
* @returns closer for the watcher instance
|
||||
*/
|
||||
_handleFile(file: Path, stats: Stats, initialAdd: boolean): (() => void) | undefined;
|
||||
/**
|
||||
* Handle symlinks encountered while reading a dir.
|
||||
* @param entry returned by readdirp
|
||||
* @param directory path of dir being read
|
||||
* @param path of this item
|
||||
* @param item basename of this item
|
||||
* @returns true if no more processing is needed for this entry.
|
||||
*/
|
||||
_handleSymlink(entry: EntryInfo, directory: string, path: Path, item: string): Promise<boolean | undefined>;
|
||||
_handleRead(directory: string, initialAdd: boolean, wh: WatchHelper, target: Path, dir: Path, depth: number, throttler: Throttler): Promise<unknown> | undefined;
|
||||
/**
|
||||
* Read directory to add / remove files from `@watched` list and re-read it on change.
|
||||
* @param dir fs path
|
||||
* @param stats
|
||||
* @param initialAdd
|
||||
* @param depth relative to user-supplied path
|
||||
* @param target child path targeted for watch
|
||||
* @param wh Common watch helpers for this path
|
||||
* @param realpath
|
||||
* @returns closer for the watcher instance.
|
||||
*/
|
||||
_handleDir(dir: string, stats: Stats, initialAdd: boolean, depth: number, target: string, wh: WatchHelper, realpath: string): Promise<(() => void) | undefined>;
|
||||
/**
|
||||
* Handle added file, directory, or glob pattern.
|
||||
* Delegates call to _handleFile / _handleDir after checks.
|
||||
* @param path to file or ir
|
||||
* @param initialAdd was the file added at watch instantiation?
|
||||
* @param priorWh depth relative to user-supplied path
|
||||
* @param depth Child path actually targeted for watch
|
||||
* @param target Child path actually targeted for watch
|
||||
*/
|
||||
_addToNodeFs(path: string, initialAdd: boolean, priorWh: WatchHelper | undefined, depth: number, target?: string): Promise<string | false | undefined>;
|
||||
}
|
||||
635
node_modules/chokidar/handler.js
generated
vendored
Normal file
635
node_modules/chokidar/handler.js
generated
vendored
Normal file
@@ -0,0 +1,635 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.NodeFsHandler = exports.EVENTS = exports.isIBMi = exports.isFreeBSD = exports.isLinux = exports.isMacos = exports.isWindows = exports.IDENTITY_FN = exports.EMPTY_FN = exports.STR_CLOSE = exports.STR_END = exports.STR_DATA = void 0;
|
||||
const fs_1 = require("fs");
|
||||
const promises_1 = require("fs/promises");
|
||||
const sysPath = require("path");
|
||||
const os_1 = require("os");
|
||||
exports.STR_DATA = 'data';
|
||||
exports.STR_END = 'end';
|
||||
exports.STR_CLOSE = 'close';
|
||||
const EMPTY_FN = () => { };
|
||||
exports.EMPTY_FN = EMPTY_FN;
|
||||
const IDENTITY_FN = (val) => val;
|
||||
exports.IDENTITY_FN = IDENTITY_FN;
|
||||
const pl = process.platform;
|
||||
exports.isWindows = pl === 'win32';
|
||||
exports.isMacos = pl === 'darwin';
|
||||
exports.isLinux = pl === 'linux';
|
||||
exports.isFreeBSD = pl === 'freebsd';
|
||||
exports.isIBMi = (0, os_1.type)() === 'OS400';
|
||||
exports.EVENTS = {
|
||||
ALL: 'all',
|
||||
READY: 'ready',
|
||||
ADD: 'add',
|
||||
CHANGE: 'change',
|
||||
ADD_DIR: 'addDir',
|
||||
UNLINK: 'unlink',
|
||||
UNLINK_DIR: 'unlinkDir',
|
||||
RAW: 'raw',
|
||||
ERROR: 'error',
|
||||
};
|
||||
const EV = exports.EVENTS;
|
||||
const THROTTLE_MODE_WATCH = 'watch';
|
||||
const statMethods = { lstat: promises_1.lstat, stat: promises_1.stat };
|
||||
const KEY_LISTENERS = 'listeners';
|
||||
const KEY_ERR = 'errHandlers';
|
||||
const KEY_RAW = 'rawEmitters';
|
||||
const HANDLER_KEYS = [KEY_LISTENERS, KEY_ERR, KEY_RAW];
|
||||
// prettier-ignore
|
||||
const binaryExtensions = new Set([
|
||||
'3dm', '3ds', '3g2', '3gp', '7z', 'a', 'aac', 'adp', 'afdesign', 'afphoto', 'afpub', 'ai',
|
||||
'aif', 'aiff', 'alz', 'ape', 'apk', 'appimage', 'ar', 'arj', 'asf', 'au', 'avi',
|
||||
'bak', 'baml', 'bh', 'bin', 'bk', 'bmp', 'btif', 'bz2', 'bzip2',
|
||||
'cab', 'caf', 'cgm', 'class', 'cmx', 'cpio', 'cr2', 'cur', 'dat', 'dcm', 'deb', 'dex', 'djvu',
|
||||
'dll', 'dmg', 'dng', 'doc', 'docm', 'docx', 'dot', 'dotm', 'dra', 'DS_Store', 'dsk', 'dts',
|
||||
'dtshd', 'dvb', 'dwg', 'dxf',
|
||||
'ecelp4800', 'ecelp7470', 'ecelp9600', 'egg', 'eol', 'eot', 'epub', 'exe',
|
||||
'f4v', 'fbs', 'fh', 'fla', 'flac', 'flatpak', 'fli', 'flv', 'fpx', 'fst', 'fvt',
|
||||
'g3', 'gh', 'gif', 'graffle', 'gz', 'gzip',
|
||||
'h261', 'h263', 'h264', 'icns', 'ico', 'ief', 'img', 'ipa', 'iso',
|
||||
'jar', 'jpeg', 'jpg', 'jpgv', 'jpm', 'jxr', 'key', 'ktx',
|
||||
'lha', 'lib', 'lvp', 'lz', 'lzh', 'lzma', 'lzo',
|
||||
'm3u', 'm4a', 'm4v', 'mar', 'mdi', 'mht', 'mid', 'midi', 'mj2', 'mka', 'mkv', 'mmr', 'mng',
|
||||
'mobi', 'mov', 'movie', 'mp3',
|
||||
'mp4', 'mp4a', 'mpeg', 'mpg', 'mpga', 'mxu',
|
||||
'nef', 'npx', 'numbers', 'nupkg',
|
||||
'o', 'odp', 'ods', 'odt', 'oga', 'ogg', 'ogv', 'otf', 'ott',
|
||||
'pages', 'pbm', 'pcx', 'pdb', 'pdf', 'pea', 'pgm', 'pic', 'png', 'pnm', 'pot', 'potm',
|
||||
'potx', 'ppa', 'ppam',
|
||||
'ppm', 'pps', 'ppsm', 'ppsx', 'ppt', 'pptm', 'pptx', 'psd', 'pya', 'pyc', 'pyo', 'pyv',
|
||||
'qt',
|
||||
'rar', 'ras', 'raw', 'resources', 'rgb', 'rip', 'rlc', 'rmf', 'rmvb', 'rpm', 'rtf', 'rz',
|
||||
's3m', 's7z', 'scpt', 'sgi', 'shar', 'snap', 'sil', 'sketch', 'slk', 'smv', 'snk', 'so',
|
||||
'stl', 'suo', 'sub', 'swf',
|
||||
'tar', 'tbz', 'tbz2', 'tga', 'tgz', 'thmx', 'tif', 'tiff', 'tlz', 'ttc', 'ttf', 'txz',
|
||||
'udf', 'uvh', 'uvi', 'uvm', 'uvp', 'uvs', 'uvu',
|
||||
'viv', 'vob',
|
||||
'war', 'wav', 'wax', 'wbmp', 'wdp', 'weba', 'webm', 'webp', 'whl', 'wim', 'wm', 'wma',
|
||||
'wmv', 'wmx', 'woff', 'woff2', 'wrm', 'wvx',
|
||||
'xbm', 'xif', 'xla', 'xlam', 'xls', 'xlsb', 'xlsm', 'xlsx', 'xlt', 'xltm', 'xltx', 'xm',
|
||||
'xmind', 'xpi', 'xpm', 'xwd', 'xz',
|
||||
'z', 'zip', 'zipx',
|
||||
]);
|
||||
const isBinaryPath = (filePath) => binaryExtensions.has(sysPath.extname(filePath).slice(1).toLowerCase());
|
||||
// TODO: emit errors properly. Example: EMFILE on Macos.
|
||||
const foreach = (val, fn) => {
|
||||
if (val instanceof Set) {
|
||||
val.forEach(fn);
|
||||
}
|
||||
else {
|
||||
fn(val);
|
||||
}
|
||||
};
|
||||
const addAndConvert = (main, prop, item) => {
|
||||
let container = main[prop];
|
||||
if (!(container instanceof Set)) {
|
||||
main[prop] = container = new Set([container]);
|
||||
}
|
||||
container.add(item);
|
||||
};
|
||||
const clearItem = (cont) => (key) => {
|
||||
const set = cont[key];
|
||||
if (set instanceof Set) {
|
||||
set.clear();
|
||||
}
|
||||
else {
|
||||
delete cont[key];
|
||||
}
|
||||
};
|
||||
const delFromSet = (main, prop, item) => {
|
||||
const container = main[prop];
|
||||
if (container instanceof Set) {
|
||||
container.delete(item);
|
||||
}
|
||||
else if (container === item) {
|
||||
delete main[prop];
|
||||
}
|
||||
};
|
||||
const isEmptySet = (val) => (val instanceof Set ? val.size === 0 : !val);
|
||||
const FsWatchInstances = new Map();
|
||||
/**
|
||||
* Instantiates the fs_watch interface
|
||||
* @param path to be watched
|
||||
* @param options to be passed to fs_watch
|
||||
* @param listener main event handler
|
||||
* @param errHandler emits info about errors
|
||||
* @param emitRaw emits raw event data
|
||||
* @returns {NativeFsWatcher}
|
||||
*/
|
||||
function createFsWatchInstance(path, options, listener, errHandler, emitRaw) {
|
||||
const handleEvent = (rawEvent, evPath) => {
|
||||
listener(path);
|
||||
emitRaw(rawEvent, evPath, { watchedPath: path });
|
||||
// emit based on events occurring for files from a directory's watcher in
|
||||
// case the file's watcher misses it (and rely on throttling to de-dupe)
|
||||
if (evPath && path !== evPath) {
|
||||
fsWatchBroadcast(sysPath.resolve(path, evPath), KEY_LISTENERS, sysPath.join(path, evPath));
|
||||
}
|
||||
};
|
||||
try {
|
||||
return (0, fs_1.watch)(path, {
|
||||
persistent: options.persistent,
|
||||
}, handleEvent);
|
||||
}
|
||||
catch (error) {
|
||||
errHandler(error);
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Helper for passing fs_watch event data to a collection of listeners
|
||||
* @param fullPath absolute path bound to fs_watch instance
|
||||
*/
|
||||
const fsWatchBroadcast = (fullPath, listenerType, val1, val2, val3) => {
|
||||
const cont = FsWatchInstances.get(fullPath);
|
||||
if (!cont)
|
||||
return;
|
||||
foreach(cont[listenerType], (listener) => {
|
||||
listener(val1, val2, val3);
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Instantiates the fs_watch interface or binds listeners
|
||||
* to an existing one covering the same file system entry
|
||||
* @param path
|
||||
* @param fullPath absolute path
|
||||
* @param options to be passed to fs_watch
|
||||
* @param handlers container for event listener functions
|
||||
*/
|
||||
const setFsWatchListener = (path, fullPath, options, handlers) => {
|
||||
const { listener, errHandler, rawEmitter } = handlers;
|
||||
let cont = FsWatchInstances.get(fullPath);
|
||||
let watcher;
|
||||
if (!options.persistent) {
|
||||
watcher = createFsWatchInstance(path, options, listener, errHandler, rawEmitter);
|
||||
if (!watcher)
|
||||
return;
|
||||
return watcher.close.bind(watcher);
|
||||
}
|
||||
if (cont) {
|
||||
addAndConvert(cont, KEY_LISTENERS, listener);
|
||||
addAndConvert(cont, KEY_ERR, errHandler);
|
||||
addAndConvert(cont, KEY_RAW, rawEmitter);
|
||||
}
|
||||
else {
|
||||
watcher = createFsWatchInstance(path, options, fsWatchBroadcast.bind(null, fullPath, KEY_LISTENERS), errHandler, // no need to use broadcast here
|
||||
fsWatchBroadcast.bind(null, fullPath, KEY_RAW));
|
||||
if (!watcher)
|
||||
return;
|
||||
watcher.on(EV.ERROR, async (error) => {
|
||||
const broadcastErr = fsWatchBroadcast.bind(null, fullPath, KEY_ERR);
|
||||
if (cont)
|
||||
cont.watcherUnusable = true; // documented since Node 10.4.1
|
||||
// Workaround for https://github.com/joyent/node/issues/4337
|
||||
if (exports.isWindows && error.code === 'EPERM') {
|
||||
try {
|
||||
const fd = await (0, promises_1.open)(path, 'r');
|
||||
await fd.close();
|
||||
broadcastErr(error);
|
||||
}
|
||||
catch (err) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
else {
|
||||
broadcastErr(error);
|
||||
}
|
||||
});
|
||||
cont = {
|
||||
listeners: listener,
|
||||
errHandlers: errHandler,
|
||||
rawEmitters: rawEmitter,
|
||||
watcher,
|
||||
};
|
||||
FsWatchInstances.set(fullPath, cont);
|
||||
}
|
||||
// const index = cont.listeners.indexOf(listener);
|
||||
// removes this instance's listeners and closes the underlying fs_watch
|
||||
// instance if there are no more listeners left
|
||||
return () => {
|
||||
delFromSet(cont, KEY_LISTENERS, listener);
|
||||
delFromSet(cont, KEY_ERR, errHandler);
|
||||
delFromSet(cont, KEY_RAW, rawEmitter);
|
||||
if (isEmptySet(cont.listeners)) {
|
||||
// Check to protect against issue gh-730.
|
||||
// if (cont.watcherUnusable) {
|
||||
cont.watcher.close();
|
||||
// }
|
||||
FsWatchInstances.delete(fullPath);
|
||||
HANDLER_KEYS.forEach(clearItem(cont));
|
||||
// @ts-ignore
|
||||
cont.watcher = undefined;
|
||||
Object.freeze(cont);
|
||||
}
|
||||
};
|
||||
};
|
||||
// fs_watchFile helpers
|
||||
// object to hold per-process fs_watchFile instances
|
||||
// (may be shared across chokidar FSWatcher instances)
|
||||
const FsWatchFileInstances = new Map();
|
||||
/**
|
||||
* Instantiates the fs_watchFile interface or binds listeners
|
||||
* to an existing one covering the same file system entry
|
||||
* @param path to be watched
|
||||
* @param fullPath absolute path
|
||||
* @param options options to be passed to fs_watchFile
|
||||
* @param handlers container for event listener functions
|
||||
* @returns closer
|
||||
*/
|
||||
const setFsWatchFileListener = (path, fullPath, options, handlers) => {
|
||||
const { listener, rawEmitter } = handlers;
|
||||
let cont = FsWatchFileInstances.get(fullPath);
|
||||
// let listeners = new Set();
|
||||
// let rawEmitters = new Set();
|
||||
const copts = cont && cont.options;
|
||||
if (copts && (copts.persistent < options.persistent || copts.interval > options.interval)) {
|
||||
// "Upgrade" the watcher to persistence or a quicker interval.
|
||||
// This creates some unlikely edge case issues if the user mixes
|
||||
// settings in a very weird way, but solving for those cases
|
||||
// doesn't seem worthwhile for the added complexity.
|
||||
// listeners = cont.listeners;
|
||||
// rawEmitters = cont.rawEmitters;
|
||||
(0, fs_1.unwatchFile)(fullPath);
|
||||
cont = undefined;
|
||||
}
|
||||
if (cont) {
|
||||
addAndConvert(cont, KEY_LISTENERS, listener);
|
||||
addAndConvert(cont, KEY_RAW, rawEmitter);
|
||||
}
|
||||
else {
|
||||
// TODO
|
||||
// listeners.add(listener);
|
||||
// rawEmitters.add(rawEmitter);
|
||||
cont = {
|
||||
listeners: listener,
|
||||
rawEmitters: rawEmitter,
|
||||
options,
|
||||
watcher: (0, fs_1.watchFile)(fullPath, options, (curr, prev) => {
|
||||
foreach(cont.rawEmitters, (rawEmitter) => {
|
||||
rawEmitter(EV.CHANGE, fullPath, { curr, prev });
|
||||
});
|
||||
const currmtime = curr.mtimeMs;
|
||||
if (curr.size !== prev.size || currmtime > prev.mtimeMs || currmtime === 0) {
|
||||
foreach(cont.listeners, (listener) => listener(path, curr));
|
||||
}
|
||||
}),
|
||||
};
|
||||
FsWatchFileInstances.set(fullPath, cont);
|
||||
}
|
||||
// const index = cont.listeners.indexOf(listener);
|
||||
// Removes this instance's listeners and closes the underlying fs_watchFile
|
||||
// instance if there are no more listeners left.
|
||||
return () => {
|
||||
delFromSet(cont, KEY_LISTENERS, listener);
|
||||
delFromSet(cont, KEY_RAW, rawEmitter);
|
||||
if (isEmptySet(cont.listeners)) {
|
||||
FsWatchFileInstances.delete(fullPath);
|
||||
(0, fs_1.unwatchFile)(fullPath);
|
||||
cont.options = cont.watcher = undefined;
|
||||
Object.freeze(cont);
|
||||
}
|
||||
};
|
||||
};
|
||||
/**
|
||||
* @mixin
|
||||
*/
|
||||
class NodeFsHandler {
|
||||
constructor(fsW) {
|
||||
this.fsw = fsW;
|
||||
this._boundHandleError = (error) => fsW._handleError(error);
|
||||
}
|
||||
/**
|
||||
* Watch file for changes with fs_watchFile or fs_watch.
|
||||
* @param path to file or dir
|
||||
* @param listener on fs change
|
||||
* @returns closer for the watcher instance
|
||||
*/
|
||||
_watchWithNodeFs(path, listener) {
|
||||
const opts = this.fsw.options;
|
||||
const directory = sysPath.dirname(path);
|
||||
const basename = sysPath.basename(path);
|
||||
const parent = this.fsw._getWatchedDir(directory);
|
||||
parent.add(basename);
|
||||
const absolutePath = sysPath.resolve(path);
|
||||
const options = {
|
||||
persistent: opts.persistent,
|
||||
};
|
||||
if (!listener)
|
||||
listener = exports.EMPTY_FN;
|
||||
let closer;
|
||||
if (opts.usePolling) {
|
||||
const enableBin = opts.interval !== opts.binaryInterval;
|
||||
options.interval = enableBin && isBinaryPath(basename) ? opts.binaryInterval : opts.interval;
|
||||
closer = setFsWatchFileListener(path, absolutePath, options, {
|
||||
listener,
|
||||
rawEmitter: this.fsw._emitRaw,
|
||||
});
|
||||
}
|
||||
else {
|
||||
closer = setFsWatchListener(path, absolutePath, options, {
|
||||
listener,
|
||||
errHandler: this._boundHandleError,
|
||||
rawEmitter: this.fsw._emitRaw,
|
||||
});
|
||||
}
|
||||
return closer;
|
||||
}
|
||||
/**
|
||||
* Watch a file and emit add event if warranted.
|
||||
* @returns closer for the watcher instance
|
||||
*/
|
||||
_handleFile(file, stats, initialAdd) {
|
||||
if (this.fsw.closed) {
|
||||
return;
|
||||
}
|
||||
const dirname = sysPath.dirname(file);
|
||||
const basename = sysPath.basename(file);
|
||||
const parent = this.fsw._getWatchedDir(dirname);
|
||||
// stats is always present
|
||||
let prevStats = stats;
|
||||
// if the file is already being watched, do nothing
|
||||
if (parent.has(basename))
|
||||
return;
|
||||
const listener = async (path, newStats) => {
|
||||
if (!this.fsw._throttle(THROTTLE_MODE_WATCH, file, 5))
|
||||
return;
|
||||
if (!newStats || newStats.mtimeMs === 0) {
|
||||
try {
|
||||
const newStats = await (0, promises_1.stat)(file);
|
||||
if (this.fsw.closed)
|
||||
return;
|
||||
// Check that change event was not fired because of changed only accessTime.
|
||||
const at = newStats.atimeMs;
|
||||
const mt = newStats.mtimeMs;
|
||||
if (!at || at <= mt || mt !== prevStats.mtimeMs) {
|
||||
this.fsw._emit(EV.CHANGE, file, newStats);
|
||||
}
|
||||
if ((exports.isMacos || exports.isLinux || exports.isFreeBSD) && prevStats.ino !== newStats.ino) {
|
||||
this.fsw._closeFile(path);
|
||||
prevStats = newStats;
|
||||
const closer = this._watchWithNodeFs(file, listener);
|
||||
if (closer)
|
||||
this.fsw._addPathCloser(path, closer);
|
||||
}
|
||||
else {
|
||||
prevStats = newStats;
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
// Fix issues where mtime is null but file is still present
|
||||
this.fsw._remove(dirname, basename);
|
||||
}
|
||||
// add is about to be emitted if file not already tracked in parent
|
||||
}
|
||||
else if (parent.has(basename)) {
|
||||
// Check that change event was not fired because of changed only accessTime.
|
||||
const at = newStats.atimeMs;
|
||||
const mt = newStats.mtimeMs;
|
||||
if (!at || at <= mt || mt !== prevStats.mtimeMs) {
|
||||
this.fsw._emit(EV.CHANGE, file, newStats);
|
||||
}
|
||||
prevStats = newStats;
|
||||
}
|
||||
};
|
||||
// kick off the watcher
|
||||
const closer = this._watchWithNodeFs(file, listener);
|
||||
// emit an add event if we're supposed to
|
||||
if (!(initialAdd && this.fsw.options.ignoreInitial) && this.fsw._isntIgnored(file)) {
|
||||
if (!this.fsw._throttle(EV.ADD, file, 0))
|
||||
return;
|
||||
this.fsw._emit(EV.ADD, file, stats);
|
||||
}
|
||||
return closer;
|
||||
}
|
||||
/**
|
||||
* Handle symlinks encountered while reading a dir.
|
||||
* @param entry returned by readdirp
|
||||
* @param directory path of dir being read
|
||||
* @param path of this item
|
||||
* @param item basename of this item
|
||||
* @returns true if no more processing is needed for this entry.
|
||||
*/
|
||||
async _handleSymlink(entry, directory, path, item) {
|
||||
if (this.fsw.closed) {
|
||||
return;
|
||||
}
|
||||
const full = entry.fullPath;
|
||||
const dir = this.fsw._getWatchedDir(directory);
|
||||
if (!this.fsw.options.followSymlinks) {
|
||||
// watch symlink directly (don't follow) and detect changes
|
||||
this.fsw._incrReadyCount();
|
||||
let linkPath;
|
||||
try {
|
||||
linkPath = await (0, promises_1.realpath)(path);
|
||||
}
|
||||
catch (e) {
|
||||
this.fsw._emitReady();
|
||||
return true;
|
||||
}
|
||||
if (this.fsw.closed)
|
||||
return;
|
||||
if (dir.has(item)) {
|
||||
if (this.fsw._symlinkPaths.get(full) !== linkPath) {
|
||||
this.fsw._symlinkPaths.set(full, linkPath);
|
||||
this.fsw._emit(EV.CHANGE, path, entry.stats);
|
||||
}
|
||||
}
|
||||
else {
|
||||
dir.add(item);
|
||||
this.fsw._symlinkPaths.set(full, linkPath);
|
||||
this.fsw._emit(EV.ADD, path, entry.stats);
|
||||
}
|
||||
this.fsw._emitReady();
|
||||
return true;
|
||||
}
|
||||
// don't follow the same symlink more than once
|
||||
if (this.fsw._symlinkPaths.has(full)) {
|
||||
return true;
|
||||
}
|
||||
this.fsw._symlinkPaths.set(full, true);
|
||||
}
|
||||
_handleRead(directory, initialAdd, wh, target, dir, depth, throttler) {
|
||||
// Normalize the directory name on Windows
|
||||
directory = sysPath.join(directory, '');
|
||||
throttler = this.fsw._throttle('readdir', directory, 1000);
|
||||
if (!throttler)
|
||||
return;
|
||||
const previous = this.fsw._getWatchedDir(wh.path);
|
||||
const current = new Set();
|
||||
let stream = this.fsw._readdirp(directory, {
|
||||
fileFilter: (entry) => wh.filterPath(entry),
|
||||
directoryFilter: (entry) => wh.filterDir(entry),
|
||||
});
|
||||
if (!stream)
|
||||
return;
|
||||
stream
|
||||
.on(exports.STR_DATA, async (entry) => {
|
||||
if (this.fsw.closed) {
|
||||
stream = undefined;
|
||||
return;
|
||||
}
|
||||
const item = entry.path;
|
||||
let path = sysPath.join(directory, item);
|
||||
current.add(item);
|
||||
if (entry.stats.isSymbolicLink() &&
|
||||
(await this._handleSymlink(entry, directory, path, item))) {
|
||||
return;
|
||||
}
|
||||
if (this.fsw.closed) {
|
||||
stream = undefined;
|
||||
return;
|
||||
}
|
||||
// Files that present in current directory snapshot
|
||||
// but absent in previous are added to watch list and
|
||||
// emit `add` event.
|
||||
if (item === target || (!target && !previous.has(item))) {
|
||||
this.fsw._incrReadyCount();
|
||||
// ensure relativeness of path is preserved in case of watcher reuse
|
||||
path = sysPath.join(dir, sysPath.relative(dir, path));
|
||||
this._addToNodeFs(path, initialAdd, wh, depth + 1);
|
||||
}
|
||||
})
|
||||
.on(EV.ERROR, this._boundHandleError);
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!stream)
|
||||
return reject();
|
||||
stream.once(exports.STR_END, () => {
|
||||
if (this.fsw.closed) {
|
||||
stream = undefined;
|
||||
return;
|
||||
}
|
||||
const wasThrottled = throttler ? throttler.clear() : false;
|
||||
resolve(undefined);
|
||||
// Files that absent in current directory snapshot
|
||||
// but present in previous emit `remove` event
|
||||
// and are removed from @watched[directory].
|
||||
previous
|
||||
.getChildren()
|
||||
.filter((item) => {
|
||||
return item !== directory && !current.has(item);
|
||||
})
|
||||
.forEach((item) => {
|
||||
this.fsw._remove(directory, item);
|
||||
});
|
||||
stream = undefined;
|
||||
// one more time for any missed in case changes came in extremely quickly
|
||||
if (wasThrottled)
|
||||
this._handleRead(directory, false, wh, target, dir, depth, throttler);
|
||||
});
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Read directory to add / remove files from `@watched` list and re-read it on change.
|
||||
* @param dir fs path
|
||||
* @param stats
|
||||
* @param initialAdd
|
||||
* @param depth relative to user-supplied path
|
||||
* @param target child path targeted for watch
|
||||
* @param wh Common watch helpers for this path
|
||||
* @param realpath
|
||||
* @returns closer for the watcher instance.
|
||||
*/
|
||||
async _handleDir(dir, stats, initialAdd, depth, target, wh, realpath) {
|
||||
const parentDir = this.fsw._getWatchedDir(sysPath.dirname(dir));
|
||||
const tracked = parentDir.has(sysPath.basename(dir));
|
||||
if (!(initialAdd && this.fsw.options.ignoreInitial) && !target && !tracked) {
|
||||
this.fsw._emit(EV.ADD_DIR, dir, stats);
|
||||
}
|
||||
// ensure dir is tracked (harmless if redundant)
|
||||
parentDir.add(sysPath.basename(dir));
|
||||
this.fsw._getWatchedDir(dir);
|
||||
let throttler;
|
||||
let closer;
|
||||
const oDepth = this.fsw.options.depth;
|
||||
if ((oDepth == null || depth <= oDepth) && !this.fsw._symlinkPaths.has(realpath)) {
|
||||
if (!target) {
|
||||
await this._handleRead(dir, initialAdd, wh, target, dir, depth, throttler);
|
||||
if (this.fsw.closed)
|
||||
return;
|
||||
}
|
||||
closer = this._watchWithNodeFs(dir, (dirPath, stats) => {
|
||||
// if current directory is removed, do nothing
|
||||
if (stats && stats.mtimeMs === 0)
|
||||
return;
|
||||
this._handleRead(dirPath, false, wh, target, dir, depth, throttler);
|
||||
});
|
||||
}
|
||||
return closer;
|
||||
}
|
||||
/**
|
||||
* Handle added file, directory, or glob pattern.
|
||||
* Delegates call to _handleFile / _handleDir after checks.
|
||||
* @param path to file or ir
|
||||
* @param initialAdd was the file added at watch instantiation?
|
||||
* @param priorWh depth relative to user-supplied path
|
||||
* @param depth Child path actually targeted for watch
|
||||
* @param target Child path actually targeted for watch
|
||||
*/
|
||||
async _addToNodeFs(path, initialAdd, priorWh, depth, target) {
|
||||
const ready = this.fsw._emitReady;
|
||||
if (this.fsw._isIgnored(path) || this.fsw.closed) {
|
||||
ready();
|
||||
return false;
|
||||
}
|
||||
const wh = this.fsw._getWatchHelpers(path);
|
||||
if (priorWh) {
|
||||
wh.filterPath = (entry) => priorWh.filterPath(entry);
|
||||
wh.filterDir = (entry) => priorWh.filterDir(entry);
|
||||
}
|
||||
// evaluate what is at the path we're being asked to watch
|
||||
try {
|
||||
const stats = await statMethods[wh.statMethod](wh.watchPath);
|
||||
if (this.fsw.closed)
|
||||
return;
|
||||
if (this.fsw._isIgnored(wh.watchPath, stats)) {
|
||||
ready();
|
||||
return false;
|
||||
}
|
||||
const follow = this.fsw.options.followSymlinks;
|
||||
let closer;
|
||||
if (stats.isDirectory()) {
|
||||
const absPath = sysPath.resolve(path);
|
||||
const targetPath = follow ? await (0, promises_1.realpath)(path) : path;
|
||||
if (this.fsw.closed)
|
||||
return;
|
||||
closer = await this._handleDir(wh.watchPath, stats, initialAdd, depth, target, wh, targetPath);
|
||||
if (this.fsw.closed)
|
||||
return;
|
||||
// preserve this symlink's target path
|
||||
if (absPath !== targetPath && targetPath !== undefined) {
|
||||
this.fsw._symlinkPaths.set(absPath, targetPath);
|
||||
}
|
||||
}
|
||||
else if (stats.isSymbolicLink()) {
|
||||
const targetPath = follow ? await (0, promises_1.realpath)(path) : path;
|
||||
if (this.fsw.closed)
|
||||
return;
|
||||
const parent = sysPath.dirname(wh.watchPath);
|
||||
this.fsw._getWatchedDir(parent).add(wh.watchPath);
|
||||
this.fsw._emit(EV.ADD, wh.watchPath, stats);
|
||||
closer = await this._handleDir(parent, stats, initialAdd, depth, path, wh, targetPath);
|
||||
if (this.fsw.closed)
|
||||
return;
|
||||
// preserve this symlink's target path
|
||||
if (targetPath !== undefined) {
|
||||
this.fsw._symlinkPaths.set(sysPath.resolve(path), targetPath);
|
||||
}
|
||||
}
|
||||
else {
|
||||
closer = this._handleFile(wh.watchPath, stats, initialAdd);
|
||||
}
|
||||
ready();
|
||||
if (closer)
|
||||
this.fsw._addPathCloser(path, closer);
|
||||
return false;
|
||||
}
|
||||
catch (error) {
|
||||
if (this.fsw._handleError(error)) {
|
||||
ready();
|
||||
return path;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.NodeFsHandler = NodeFsHandler;
|
||||
215
node_modules/chokidar/index.d.ts
generated
vendored
Normal file
215
node_modules/chokidar/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,215 @@
|
||||
/*! chokidar - MIT License (c) 2012 Paul Miller (paulmillr.com) */
|
||||
import { Stats } from 'fs';
|
||||
import { EventEmitter } from 'events';
|
||||
import { ReaddirpStream, ReaddirpOptions, EntryInfo } from 'readdirp';
|
||||
import { NodeFsHandler, EventName, Path, EVENTS as EV, WatchHandlers } from './handler.js';
|
||||
type AWF = {
|
||||
stabilityThreshold: number;
|
||||
pollInterval: number;
|
||||
};
|
||||
type BasicOpts = {
|
||||
persistent: boolean;
|
||||
ignoreInitial: boolean;
|
||||
followSymlinks: boolean;
|
||||
cwd?: string;
|
||||
usePolling: boolean;
|
||||
interval: number;
|
||||
binaryInterval: number;
|
||||
alwaysStat?: boolean;
|
||||
depth?: number;
|
||||
ignorePermissionErrors: boolean;
|
||||
atomic: boolean | number;
|
||||
};
|
||||
export type Throttler = {
|
||||
timeoutObject: NodeJS.Timeout;
|
||||
clear: () => void;
|
||||
count: number;
|
||||
};
|
||||
export type ChokidarOptions = Partial<BasicOpts & {
|
||||
ignored: Matcher | Matcher[];
|
||||
awaitWriteFinish: boolean | Partial<AWF>;
|
||||
}>;
|
||||
export type FSWInstanceOptions = BasicOpts & {
|
||||
ignored: Matcher[];
|
||||
awaitWriteFinish: false | AWF;
|
||||
};
|
||||
export type ThrottleType = 'readdir' | 'watch' | 'add' | 'remove' | 'change';
|
||||
export type EmitArgs = [path: Path, stats?: Stats];
|
||||
export type EmitErrorArgs = [error: Error, stats?: Stats];
|
||||
export type EmitArgsWithName = [event: EventName, ...EmitArgs];
|
||||
export type MatchFunction = (val: string, stats?: Stats) => boolean;
|
||||
export interface MatcherObject {
|
||||
path: string;
|
||||
recursive?: boolean;
|
||||
}
|
||||
export type Matcher = string | RegExp | MatchFunction | MatcherObject;
|
||||
/**
|
||||
* Directory entry.
|
||||
*/
|
||||
declare class DirEntry {
|
||||
path: Path;
|
||||
_removeWatcher: (dir: string, base: string) => void;
|
||||
items: Set<Path>;
|
||||
constructor(dir: Path, removeWatcher: (dir: string, base: string) => void);
|
||||
add(item: string): void;
|
||||
remove(item: string): Promise<void>;
|
||||
has(item: string): boolean | undefined;
|
||||
getChildren(): string[];
|
||||
dispose(): void;
|
||||
}
|
||||
export declare class WatchHelper {
|
||||
fsw: FSWatcher;
|
||||
path: string;
|
||||
watchPath: string;
|
||||
fullWatchPath: string;
|
||||
dirParts: string[][];
|
||||
followSymlinks: boolean;
|
||||
statMethod: 'stat' | 'lstat';
|
||||
constructor(path: string, follow: boolean, fsw: FSWatcher);
|
||||
entryPath(entry: EntryInfo): Path;
|
||||
filterPath(entry: EntryInfo): boolean;
|
||||
filterDir(entry: EntryInfo): boolean;
|
||||
}
|
||||
export interface FSWatcherKnownEventMap {
|
||||
[EV.READY]: [];
|
||||
[EV.RAW]: Parameters<WatchHandlers['rawEmitter']>;
|
||||
[EV.ERROR]: Parameters<WatchHandlers['errHandler']>;
|
||||
[EV.ALL]: [event: EventName, ...EmitArgs];
|
||||
}
|
||||
export type FSWatcherEventMap = FSWatcherKnownEventMap & {
|
||||
[k in Exclude<EventName, keyof FSWatcherKnownEventMap>]: EmitArgs;
|
||||
};
|
||||
/**
|
||||
* Watches files & directories for changes. Emitted events:
|
||||
* `add`, `addDir`, `change`, `unlink`, `unlinkDir`, `all`, `error`
|
||||
*
|
||||
* new FSWatcher()
|
||||
* .add(directories)
|
||||
* .on('add', path => log('File', path, 'was added'))
|
||||
*/
|
||||
export declare class FSWatcher extends EventEmitter<FSWatcherEventMap> {
|
||||
closed: boolean;
|
||||
options: FSWInstanceOptions;
|
||||
_closers: Map<string, Array<any>>;
|
||||
_ignoredPaths: Set<Matcher>;
|
||||
_throttled: Map<ThrottleType, Map<any, any>>;
|
||||
_streams: Set<ReaddirpStream>;
|
||||
_symlinkPaths: Map<Path, string | boolean>;
|
||||
_watched: Map<string, DirEntry>;
|
||||
_pendingWrites: Map<string, any>;
|
||||
_pendingUnlinks: Map<string, EmitArgsWithName>;
|
||||
_readyCount: number;
|
||||
_emitReady: () => void;
|
||||
_closePromise?: Promise<void>;
|
||||
_userIgnored?: MatchFunction;
|
||||
_readyEmitted: boolean;
|
||||
_emitRaw: WatchHandlers['rawEmitter'];
|
||||
_boundRemove: (dir: string, item: string) => void;
|
||||
_nodeFsHandler: NodeFsHandler;
|
||||
constructor(_opts?: ChokidarOptions);
|
||||
_addIgnoredPath(matcher: Matcher): void;
|
||||
_removeIgnoredPath(matcher: Matcher): void;
|
||||
/**
|
||||
* Adds paths to be watched on an existing FSWatcher instance.
|
||||
* @param paths_ file or file list. Other arguments are unused
|
||||
*/
|
||||
add(paths_: Path | Path[], _origAdd?: string, _internal?: boolean): FSWatcher;
|
||||
/**
|
||||
* Close watchers or start ignoring events from specified paths.
|
||||
*/
|
||||
unwatch(paths_: Path | Path[]): FSWatcher;
|
||||
/**
|
||||
* Close watchers and remove all listeners from watched paths.
|
||||
*/
|
||||
close(): Promise<void>;
|
||||
/**
|
||||
* Expose list of watched paths
|
||||
* @returns for chaining
|
||||
*/
|
||||
getWatched(): Record<string, string[]>;
|
||||
emitWithAll(event: EventName, args: EmitArgs): void;
|
||||
/**
|
||||
* Normalize and emit events.
|
||||
* Calling _emit DOES NOT MEAN emit() would be called!
|
||||
* @param event Type of event
|
||||
* @param path File or directory path
|
||||
* @param stats arguments to be passed with event
|
||||
* @returns the error if defined, otherwise the value of the FSWatcher instance's `closed` flag
|
||||
*/
|
||||
_emit(event: EventName, path: Path, stats?: Stats): Promise<this | undefined>;
|
||||
/**
|
||||
* Common handler for errors
|
||||
* @returns The error if defined, otherwise the value of the FSWatcher instance's `closed` flag
|
||||
*/
|
||||
_handleError(error: Error): Error | boolean;
|
||||
/**
|
||||
* Helper utility for throttling
|
||||
* @param actionType type being throttled
|
||||
* @param path being acted upon
|
||||
* @param timeout duration of time to suppress duplicate actions
|
||||
* @returns tracking object or false if action should be suppressed
|
||||
*/
|
||||
_throttle(actionType: ThrottleType, path: Path, timeout: number): Throttler | false;
|
||||
_incrReadyCount(): number;
|
||||
/**
|
||||
* Awaits write operation to finish.
|
||||
* Polls a newly created file for size variations. When files size does not change for 'threshold' milliseconds calls callback.
|
||||
* @param path being acted upon
|
||||
* @param threshold Time in milliseconds a file size must be fixed before acknowledging write OP is finished
|
||||
* @param event
|
||||
* @param awfEmit Callback to be called when ready for event to be emitted.
|
||||
*/
|
||||
_awaitWriteFinish(path: Path, threshold: number, event: EventName, awfEmit: (err?: Error, stat?: Stats) => void): void;
|
||||
/**
|
||||
* Determines whether user has asked to ignore this path.
|
||||
*/
|
||||
_isIgnored(path: Path, stats?: Stats): boolean;
|
||||
_isntIgnored(path: Path, stat?: Stats): boolean;
|
||||
/**
|
||||
* Provides a set of common helpers and properties relating to symlink handling.
|
||||
* @param path file or directory pattern being watched
|
||||
*/
|
||||
_getWatchHelpers(path: Path): WatchHelper;
|
||||
/**
|
||||
* Provides directory tracking objects
|
||||
* @param directory path of the directory
|
||||
*/
|
||||
_getWatchedDir(directory: string): DirEntry;
|
||||
/**
|
||||
* Check for read permissions: https://stackoverflow.com/a/11781404/1358405
|
||||
*/
|
||||
_hasReadPermissions(stats: Stats): boolean;
|
||||
/**
|
||||
* Handles emitting unlink events for
|
||||
* files and directories, and via recursion, for
|
||||
* files and directories within directories that are unlinked
|
||||
* @param directory within which the following item is located
|
||||
* @param item base path of item/directory
|
||||
*/
|
||||
_remove(directory: string, item: string, isDirectory?: boolean): void;
|
||||
/**
|
||||
* Closes all watchers for a path
|
||||
*/
|
||||
_closePath(path: Path): void;
|
||||
/**
|
||||
* Closes only file-specific watchers
|
||||
*/
|
||||
_closeFile(path: Path): void;
|
||||
_addPathCloser(path: Path, closer: () => void): void;
|
||||
_readdirp(root: Path, opts?: Partial<ReaddirpOptions>): ReaddirpStream | undefined;
|
||||
}
|
||||
/**
|
||||
* Instantiates watcher with paths to be tracked.
|
||||
* @param paths file / directory paths
|
||||
* @param options opts, such as `atomic`, `awaitWriteFinish`, `ignored`, and others
|
||||
* @returns an instance of FSWatcher for chaining.
|
||||
* @example
|
||||
* const watcher = watch('.').on('all', (event, path) => { console.log(event, path); });
|
||||
* watch('.', { atomic: true, awaitWriteFinish: true, ignored: (f, stats) => stats?.isFile() && !f.endsWith('.js') })
|
||||
*/
|
||||
export declare function watch(paths: string | string[], options?: ChokidarOptions): FSWatcher;
|
||||
declare const _default: {
|
||||
watch: typeof watch;
|
||||
FSWatcher: typeof FSWatcher;
|
||||
};
|
||||
export default _default;
|
||||
804
node_modules/chokidar/index.js
generated
vendored
Normal file
804
node_modules/chokidar/index.js
generated
vendored
Normal file
@@ -0,0 +1,804 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.FSWatcher = exports.WatchHelper = void 0;
|
||||
exports.watch = watch;
|
||||
/*! chokidar - MIT License (c) 2012 Paul Miller (paulmillr.com) */
|
||||
const fs_1 = require("fs");
|
||||
const promises_1 = require("fs/promises");
|
||||
const events_1 = require("events");
|
||||
const sysPath = require("path");
|
||||
const readdirp_1 = require("readdirp");
|
||||
const handler_js_1 = require("./handler.js");
|
||||
const SLASH = '/';
|
||||
const SLASH_SLASH = '//';
|
||||
const ONE_DOT = '.';
|
||||
const TWO_DOTS = '..';
|
||||
const STRING_TYPE = 'string';
|
||||
const BACK_SLASH_RE = /\\/g;
|
||||
const DOUBLE_SLASH_RE = /\/\//;
|
||||
const DOT_RE = /\..*\.(sw[px])$|~$|\.subl.*\.tmp/;
|
||||
const REPLACER_RE = /^\.[/\\]/;
|
||||
function arrify(item) {
|
||||
return Array.isArray(item) ? item : [item];
|
||||
}
|
||||
const isMatcherObject = (matcher) => typeof matcher === 'object' && matcher !== null && !(matcher instanceof RegExp);
|
||||
function createPattern(matcher) {
|
||||
if (typeof matcher === 'function')
|
||||
return matcher;
|
||||
if (typeof matcher === 'string')
|
||||
return (string) => matcher === string;
|
||||
if (matcher instanceof RegExp)
|
||||
return (string) => matcher.test(string);
|
||||
if (typeof matcher === 'object' && matcher !== null) {
|
||||
return (string) => {
|
||||
if (matcher.path === string)
|
||||
return true;
|
||||
if (matcher.recursive) {
|
||||
const relative = sysPath.relative(matcher.path, string);
|
||||
if (!relative) {
|
||||
return false;
|
||||
}
|
||||
return !relative.startsWith('..') && !sysPath.isAbsolute(relative);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
}
|
||||
return () => false;
|
||||
}
|
||||
function normalizePath(path) {
|
||||
if (typeof path !== 'string')
|
||||
throw new Error('string expected');
|
||||
path = sysPath.normalize(path);
|
||||
path = path.replace(/\\/g, '/');
|
||||
let prepend = false;
|
||||
if (path.startsWith('//'))
|
||||
prepend = true;
|
||||
const DOUBLE_SLASH_RE = /\/\//;
|
||||
while (path.match(DOUBLE_SLASH_RE))
|
||||
path = path.replace(DOUBLE_SLASH_RE, '/');
|
||||
if (prepend)
|
||||
path = '/' + path;
|
||||
return path;
|
||||
}
|
||||
function matchPatterns(patterns, testString, stats) {
|
||||
const path = normalizePath(testString);
|
||||
for (let index = 0; index < patterns.length; index++) {
|
||||
const pattern = patterns[index];
|
||||
if (pattern(path, stats)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function anymatch(matchers, testString) {
|
||||
if (matchers == null) {
|
||||
throw new TypeError('anymatch: specify first argument');
|
||||
}
|
||||
// Early cache for matchers.
|
||||
const matchersArray = arrify(matchers);
|
||||
const patterns = matchersArray.map((matcher) => createPattern(matcher));
|
||||
if (testString == null) {
|
||||
return (testString, stats) => {
|
||||
return matchPatterns(patterns, testString, stats);
|
||||
};
|
||||
}
|
||||
return matchPatterns(patterns, testString);
|
||||
}
|
||||
const unifyPaths = (paths_) => {
|
||||
const paths = arrify(paths_).flat();
|
||||
if (!paths.every((p) => typeof p === STRING_TYPE)) {
|
||||
throw new TypeError(`Non-string provided as watch path: ${paths}`);
|
||||
}
|
||||
return paths.map(normalizePathToUnix);
|
||||
};
|
||||
// If SLASH_SLASH occurs at the beginning of path, it is not replaced
|
||||
// because "//StoragePC/DrivePool/Movies" is a valid network path
|
||||
const toUnix = (string) => {
|
||||
let str = string.replace(BACK_SLASH_RE, SLASH);
|
||||
let prepend = false;
|
||||
if (str.startsWith(SLASH_SLASH)) {
|
||||
prepend = true;
|
||||
}
|
||||
while (str.match(DOUBLE_SLASH_RE)) {
|
||||
str = str.replace(DOUBLE_SLASH_RE, SLASH);
|
||||
}
|
||||
if (prepend) {
|
||||
str = SLASH + str;
|
||||
}
|
||||
return str;
|
||||
};
|
||||
// Our version of upath.normalize
|
||||
// TODO: this is not equal to path-normalize module - investigate why
|
||||
const normalizePathToUnix = (path) => toUnix(sysPath.normalize(toUnix(path)));
|
||||
// TODO: refactor
|
||||
const normalizeIgnored = (cwd = '') => (path) => {
|
||||
if (typeof path === 'string') {
|
||||
return normalizePathToUnix(sysPath.isAbsolute(path) ? path : sysPath.join(cwd, path));
|
||||
}
|
||||
else {
|
||||
return path;
|
||||
}
|
||||
};
|
||||
const getAbsolutePath = (path, cwd) => {
|
||||
if (sysPath.isAbsolute(path)) {
|
||||
return path;
|
||||
}
|
||||
return sysPath.join(cwd, path);
|
||||
};
|
||||
const EMPTY_SET = Object.freeze(new Set());
|
||||
/**
|
||||
* Directory entry.
|
||||
*/
|
||||
class DirEntry {
|
||||
constructor(dir, removeWatcher) {
|
||||
this.path = dir;
|
||||
this._removeWatcher = removeWatcher;
|
||||
this.items = new Set();
|
||||
}
|
||||
add(item) {
|
||||
const { items } = this;
|
||||
if (!items)
|
||||
return;
|
||||
if (item !== ONE_DOT && item !== TWO_DOTS)
|
||||
items.add(item);
|
||||
}
|
||||
async remove(item) {
|
||||
const { items } = this;
|
||||
if (!items)
|
||||
return;
|
||||
items.delete(item);
|
||||
if (items.size > 0)
|
||||
return;
|
||||
const dir = this.path;
|
||||
try {
|
||||
await (0, promises_1.readdir)(dir);
|
||||
}
|
||||
catch (err) {
|
||||
if (this._removeWatcher) {
|
||||
this._removeWatcher(sysPath.dirname(dir), sysPath.basename(dir));
|
||||
}
|
||||
}
|
||||
}
|
||||
has(item) {
|
||||
const { items } = this;
|
||||
if (!items)
|
||||
return;
|
||||
return items.has(item);
|
||||
}
|
||||
getChildren() {
|
||||
const { items } = this;
|
||||
if (!items)
|
||||
return [];
|
||||
return [...items.values()];
|
||||
}
|
||||
dispose() {
|
||||
this.items.clear();
|
||||
this.path = '';
|
||||
this._removeWatcher = handler_js_1.EMPTY_FN;
|
||||
this.items = EMPTY_SET;
|
||||
Object.freeze(this);
|
||||
}
|
||||
}
|
||||
const STAT_METHOD_F = 'stat';
|
||||
const STAT_METHOD_L = 'lstat';
|
||||
class WatchHelper {
|
||||
constructor(path, follow, fsw) {
|
||||
this.fsw = fsw;
|
||||
const watchPath = path;
|
||||
this.path = path = path.replace(REPLACER_RE, '');
|
||||
this.watchPath = watchPath;
|
||||
this.fullWatchPath = sysPath.resolve(watchPath);
|
||||
this.dirParts = [];
|
||||
this.dirParts.forEach((parts) => {
|
||||
if (parts.length > 1)
|
||||
parts.pop();
|
||||
});
|
||||
this.followSymlinks = follow;
|
||||
this.statMethod = follow ? STAT_METHOD_F : STAT_METHOD_L;
|
||||
}
|
||||
entryPath(entry) {
|
||||
return sysPath.join(this.watchPath, sysPath.relative(this.watchPath, entry.fullPath));
|
||||
}
|
||||
filterPath(entry) {
|
||||
const { stats } = entry;
|
||||
if (stats && stats.isSymbolicLink())
|
||||
return this.filterDir(entry);
|
||||
const resolvedPath = this.entryPath(entry);
|
||||
// TODO: what if stats is undefined? remove !
|
||||
return this.fsw._isntIgnored(resolvedPath, stats) && this.fsw._hasReadPermissions(stats);
|
||||
}
|
||||
filterDir(entry) {
|
||||
return this.fsw._isntIgnored(this.entryPath(entry), entry.stats);
|
||||
}
|
||||
}
|
||||
exports.WatchHelper = WatchHelper;
|
||||
/**
|
||||
* Watches files & directories for changes. Emitted events:
|
||||
* `add`, `addDir`, `change`, `unlink`, `unlinkDir`, `all`, `error`
|
||||
*
|
||||
* new FSWatcher()
|
||||
* .add(directories)
|
||||
* .on('add', path => log('File', path, 'was added'))
|
||||
*/
|
||||
class FSWatcher extends events_1.EventEmitter {
|
||||
// Not indenting methods for history sake; for now.
|
||||
constructor(_opts = {}) {
|
||||
super();
|
||||
this.closed = false;
|
||||
this._closers = new Map();
|
||||
this._ignoredPaths = new Set();
|
||||
this._throttled = new Map();
|
||||
this._streams = new Set();
|
||||
this._symlinkPaths = new Map();
|
||||
this._watched = new Map();
|
||||
this._pendingWrites = new Map();
|
||||
this._pendingUnlinks = new Map();
|
||||
this._readyCount = 0;
|
||||
this._readyEmitted = false;
|
||||
const awf = _opts.awaitWriteFinish;
|
||||
const DEF_AWF = { stabilityThreshold: 2000, pollInterval: 100 };
|
||||
const opts = {
|
||||
// Defaults
|
||||
persistent: true,
|
||||
ignoreInitial: false,
|
||||
ignorePermissionErrors: false,
|
||||
interval: 100,
|
||||
binaryInterval: 300,
|
||||
followSymlinks: true,
|
||||
usePolling: false,
|
||||
// useAsync: false,
|
||||
atomic: true, // NOTE: overwritten later (depends on usePolling)
|
||||
..._opts,
|
||||
// Change format
|
||||
ignored: _opts.ignored ? arrify(_opts.ignored) : arrify([]),
|
||||
awaitWriteFinish: awf === true ? DEF_AWF : typeof awf === 'object' ? { ...DEF_AWF, ...awf } : false,
|
||||
};
|
||||
// Always default to polling on IBM i because fs.watch() is not available on IBM i.
|
||||
if (handler_js_1.isIBMi)
|
||||
opts.usePolling = true;
|
||||
// Editor atomic write normalization enabled by default with fs.watch
|
||||
if (opts.atomic === undefined)
|
||||
opts.atomic = !opts.usePolling;
|
||||
// opts.atomic = typeof _opts.atomic === 'number' ? _opts.atomic : 100;
|
||||
// Global override. Useful for developers, who need to force polling for all
|
||||
// instances of chokidar, regardless of usage / dependency depth
|
||||
const envPoll = process.env.CHOKIDAR_USEPOLLING;
|
||||
if (envPoll !== undefined) {
|
||||
const envLower = envPoll.toLowerCase();
|
||||
if (envLower === 'false' || envLower === '0')
|
||||
opts.usePolling = false;
|
||||
else if (envLower === 'true' || envLower === '1')
|
||||
opts.usePolling = true;
|
||||
else
|
||||
opts.usePolling = !!envLower;
|
||||
}
|
||||
const envInterval = process.env.CHOKIDAR_INTERVAL;
|
||||
if (envInterval)
|
||||
opts.interval = Number.parseInt(envInterval, 10);
|
||||
// This is done to emit ready only once, but each 'add' will increase that?
|
||||
let readyCalls = 0;
|
||||
this._emitReady = () => {
|
||||
readyCalls++;
|
||||
if (readyCalls >= this._readyCount) {
|
||||
this._emitReady = handler_js_1.EMPTY_FN;
|
||||
this._readyEmitted = true;
|
||||
// use process.nextTick to allow time for listener to be bound
|
||||
process.nextTick(() => this.emit(handler_js_1.EVENTS.READY));
|
||||
}
|
||||
};
|
||||
this._emitRaw = (...args) => this.emit(handler_js_1.EVENTS.RAW, ...args);
|
||||
this._boundRemove = this._remove.bind(this);
|
||||
this.options = opts;
|
||||
this._nodeFsHandler = new handler_js_1.NodeFsHandler(this);
|
||||
// You’re frozen when your heart’s not open.
|
||||
Object.freeze(opts);
|
||||
}
|
||||
_addIgnoredPath(matcher) {
|
||||
if (isMatcherObject(matcher)) {
|
||||
// return early if we already have a deeply equal matcher object
|
||||
for (const ignored of this._ignoredPaths) {
|
||||
if (isMatcherObject(ignored) &&
|
||||
ignored.path === matcher.path &&
|
||||
ignored.recursive === matcher.recursive) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
this._ignoredPaths.add(matcher);
|
||||
}
|
||||
_removeIgnoredPath(matcher) {
|
||||
this._ignoredPaths.delete(matcher);
|
||||
// now find any matcher objects with the matcher as path
|
||||
if (typeof matcher === 'string') {
|
||||
for (const ignored of this._ignoredPaths) {
|
||||
// TODO (43081j): make this more efficient.
|
||||
// probably just make a `this._ignoredDirectories` or some
|
||||
// such thing.
|
||||
if (isMatcherObject(ignored) && ignored.path === matcher) {
|
||||
this._ignoredPaths.delete(ignored);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Public methods
|
||||
/**
|
||||
* Adds paths to be watched on an existing FSWatcher instance.
|
||||
* @param paths_ file or file list. Other arguments are unused
|
||||
*/
|
||||
add(paths_, _origAdd, _internal) {
|
||||
const { cwd } = this.options;
|
||||
this.closed = false;
|
||||
this._closePromise = undefined;
|
||||
let paths = unifyPaths(paths_);
|
||||
if (cwd) {
|
||||
paths = paths.map((path) => {
|
||||
const absPath = getAbsolutePath(path, cwd);
|
||||
// Check `path` instead of `absPath` because the cwd portion can't be a glob
|
||||
return absPath;
|
||||
});
|
||||
}
|
||||
paths.forEach((path) => {
|
||||
this._removeIgnoredPath(path);
|
||||
});
|
||||
this._userIgnored = undefined;
|
||||
if (!this._readyCount)
|
||||
this._readyCount = 0;
|
||||
this._readyCount += paths.length;
|
||||
Promise.all(paths.map(async (path) => {
|
||||
const res = await this._nodeFsHandler._addToNodeFs(path, !_internal, undefined, 0, _origAdd);
|
||||
if (res)
|
||||
this._emitReady();
|
||||
return res;
|
||||
})).then((results) => {
|
||||
if (this.closed)
|
||||
return;
|
||||
results.forEach((item) => {
|
||||
if (item)
|
||||
this.add(sysPath.dirname(item), sysPath.basename(_origAdd || item));
|
||||
});
|
||||
});
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Close watchers or start ignoring events from specified paths.
|
||||
*/
|
||||
unwatch(paths_) {
|
||||
if (this.closed)
|
||||
return this;
|
||||
const paths = unifyPaths(paths_);
|
||||
const { cwd } = this.options;
|
||||
paths.forEach((path) => {
|
||||
// convert to absolute path unless relative path already matches
|
||||
if (!sysPath.isAbsolute(path) && !this._closers.has(path)) {
|
||||
if (cwd)
|
||||
path = sysPath.join(cwd, path);
|
||||
path = sysPath.resolve(path);
|
||||
}
|
||||
this._closePath(path);
|
||||
this._addIgnoredPath(path);
|
||||
if (this._watched.has(path)) {
|
||||
this._addIgnoredPath({
|
||||
path,
|
||||
recursive: true,
|
||||
});
|
||||
}
|
||||
// reset the cached userIgnored anymatch fn
|
||||
// to make ignoredPaths changes effective
|
||||
this._userIgnored = undefined;
|
||||
});
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Close watchers and remove all listeners from watched paths.
|
||||
*/
|
||||
close() {
|
||||
if (this._closePromise) {
|
||||
return this._closePromise;
|
||||
}
|
||||
this.closed = true;
|
||||
// Memory management.
|
||||
this.removeAllListeners();
|
||||
const closers = [];
|
||||
this._closers.forEach((closerList) => closerList.forEach((closer) => {
|
||||
const promise = closer();
|
||||
if (promise instanceof Promise)
|
||||
closers.push(promise);
|
||||
}));
|
||||
this._streams.forEach((stream) => stream.destroy());
|
||||
this._userIgnored = undefined;
|
||||
this._readyCount = 0;
|
||||
this._readyEmitted = false;
|
||||
this._watched.forEach((dirent) => dirent.dispose());
|
||||
this._closers.clear();
|
||||
this._watched.clear();
|
||||
this._streams.clear();
|
||||
this._symlinkPaths.clear();
|
||||
this._throttled.clear();
|
||||
this._closePromise = closers.length
|
||||
? Promise.all(closers).then(() => undefined)
|
||||
: Promise.resolve();
|
||||
return this._closePromise;
|
||||
}
|
||||
/**
|
||||
* Expose list of watched paths
|
||||
* @returns for chaining
|
||||
*/
|
||||
getWatched() {
|
||||
const watchList = {};
|
||||
this._watched.forEach((entry, dir) => {
|
||||
const key = this.options.cwd ? sysPath.relative(this.options.cwd, dir) : dir;
|
||||
const index = key || ONE_DOT;
|
||||
watchList[index] = entry.getChildren().sort();
|
||||
});
|
||||
return watchList;
|
||||
}
|
||||
emitWithAll(event, args) {
|
||||
this.emit(event, ...args);
|
||||
if (event !== handler_js_1.EVENTS.ERROR)
|
||||
this.emit(handler_js_1.EVENTS.ALL, event, ...args);
|
||||
}
|
||||
// Common helpers
|
||||
// --------------
|
||||
/**
|
||||
* Normalize and emit events.
|
||||
* Calling _emit DOES NOT MEAN emit() would be called!
|
||||
* @param event Type of event
|
||||
* @param path File or directory path
|
||||
* @param stats arguments to be passed with event
|
||||
* @returns the error if defined, otherwise the value of the FSWatcher instance's `closed` flag
|
||||
*/
|
||||
async _emit(event, path, stats) {
|
||||
if (this.closed)
|
||||
return;
|
||||
const opts = this.options;
|
||||
if (handler_js_1.isWindows)
|
||||
path = sysPath.normalize(path);
|
||||
if (opts.cwd)
|
||||
path = sysPath.relative(opts.cwd, path);
|
||||
const args = [path];
|
||||
if (stats != null)
|
||||
args.push(stats);
|
||||
const awf = opts.awaitWriteFinish;
|
||||
let pw;
|
||||
if (awf && (pw = this._pendingWrites.get(path))) {
|
||||
pw.lastChange = new Date();
|
||||
return this;
|
||||
}
|
||||
if (opts.atomic) {
|
||||
if (event === handler_js_1.EVENTS.UNLINK) {
|
||||
this._pendingUnlinks.set(path, [event, ...args]);
|
||||
setTimeout(() => {
|
||||
this._pendingUnlinks.forEach((entry, path) => {
|
||||
this.emit(...entry);
|
||||
this.emit(handler_js_1.EVENTS.ALL, ...entry);
|
||||
this._pendingUnlinks.delete(path);
|
||||
});
|
||||
}, typeof opts.atomic === 'number' ? opts.atomic : 100);
|
||||
return this;
|
||||
}
|
||||
if (event === handler_js_1.EVENTS.ADD && this._pendingUnlinks.has(path)) {
|
||||
event = handler_js_1.EVENTS.CHANGE;
|
||||
this._pendingUnlinks.delete(path);
|
||||
}
|
||||
}
|
||||
if (awf && (event === handler_js_1.EVENTS.ADD || event === handler_js_1.EVENTS.CHANGE) && this._readyEmitted) {
|
||||
const awfEmit = (err, stats) => {
|
||||
if (err) {
|
||||
event = handler_js_1.EVENTS.ERROR;
|
||||
args[0] = err;
|
||||
this.emitWithAll(event, args);
|
||||
}
|
||||
else if (stats) {
|
||||
// if stats doesn't exist the file must have been deleted
|
||||
if (args.length > 1) {
|
||||
args[1] = stats;
|
||||
}
|
||||
else {
|
||||
args.push(stats);
|
||||
}
|
||||
this.emitWithAll(event, args);
|
||||
}
|
||||
};
|
||||
this._awaitWriteFinish(path, awf.stabilityThreshold, event, awfEmit);
|
||||
return this;
|
||||
}
|
||||
if (event === handler_js_1.EVENTS.CHANGE) {
|
||||
const isThrottled = !this._throttle(handler_js_1.EVENTS.CHANGE, path, 50);
|
||||
if (isThrottled)
|
||||
return this;
|
||||
}
|
||||
if (opts.alwaysStat &&
|
||||
stats === undefined &&
|
||||
(event === handler_js_1.EVENTS.ADD || event === handler_js_1.EVENTS.ADD_DIR || event === handler_js_1.EVENTS.CHANGE)) {
|
||||
const fullPath = opts.cwd ? sysPath.join(opts.cwd, path) : path;
|
||||
let stats;
|
||||
try {
|
||||
stats = await (0, promises_1.stat)(fullPath);
|
||||
}
|
||||
catch (err) {
|
||||
// do nothing
|
||||
}
|
||||
// Suppress event when fs_stat fails, to avoid sending undefined 'stat'
|
||||
if (!stats || this.closed)
|
||||
return;
|
||||
args.push(stats);
|
||||
}
|
||||
this.emitWithAll(event, args);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Common handler for errors
|
||||
* @returns The error if defined, otherwise the value of the FSWatcher instance's `closed` flag
|
||||
*/
|
||||
_handleError(error) {
|
||||
const code = error && error.code;
|
||||
if (error &&
|
||||
code !== 'ENOENT' &&
|
||||
code !== 'ENOTDIR' &&
|
||||
(!this.options.ignorePermissionErrors || (code !== 'EPERM' && code !== 'EACCES'))) {
|
||||
this.emit(handler_js_1.EVENTS.ERROR, error);
|
||||
}
|
||||
return error || this.closed;
|
||||
}
|
||||
/**
|
||||
* Helper utility for throttling
|
||||
* @param actionType type being throttled
|
||||
* @param path being acted upon
|
||||
* @param timeout duration of time to suppress duplicate actions
|
||||
* @returns tracking object or false if action should be suppressed
|
||||
*/
|
||||
_throttle(actionType, path, timeout) {
|
||||
if (!this._throttled.has(actionType)) {
|
||||
this._throttled.set(actionType, new Map());
|
||||
}
|
||||
const action = this._throttled.get(actionType);
|
||||
if (!action)
|
||||
throw new Error('invalid throttle');
|
||||
const actionPath = action.get(path);
|
||||
if (actionPath) {
|
||||
actionPath.count++;
|
||||
return false;
|
||||
}
|
||||
// eslint-disable-next-line prefer-const
|
||||
let timeoutObject;
|
||||
const clear = () => {
|
||||
const item = action.get(path);
|
||||
const count = item ? item.count : 0;
|
||||
action.delete(path);
|
||||
clearTimeout(timeoutObject);
|
||||
if (item)
|
||||
clearTimeout(item.timeoutObject);
|
||||
return count;
|
||||
};
|
||||
timeoutObject = setTimeout(clear, timeout);
|
||||
const thr = { timeoutObject, clear, count: 0 };
|
||||
action.set(path, thr);
|
||||
return thr;
|
||||
}
|
||||
_incrReadyCount() {
|
||||
return this._readyCount++;
|
||||
}
|
||||
/**
|
||||
* Awaits write operation to finish.
|
||||
* Polls a newly created file for size variations. When files size does not change for 'threshold' milliseconds calls callback.
|
||||
* @param path being acted upon
|
||||
* @param threshold Time in milliseconds a file size must be fixed before acknowledging write OP is finished
|
||||
* @param event
|
||||
* @param awfEmit Callback to be called when ready for event to be emitted.
|
||||
*/
|
||||
_awaitWriteFinish(path, threshold, event, awfEmit) {
|
||||
const awf = this.options.awaitWriteFinish;
|
||||
if (typeof awf !== 'object')
|
||||
return;
|
||||
const pollInterval = awf.pollInterval;
|
||||
let timeoutHandler;
|
||||
let fullPath = path;
|
||||
if (this.options.cwd && !sysPath.isAbsolute(path)) {
|
||||
fullPath = sysPath.join(this.options.cwd, path);
|
||||
}
|
||||
const now = new Date();
|
||||
const writes = this._pendingWrites;
|
||||
function awaitWriteFinishFn(prevStat) {
|
||||
(0, fs_1.stat)(fullPath, (err, curStat) => {
|
||||
if (err || !writes.has(path)) {
|
||||
if (err && err.code !== 'ENOENT')
|
||||
awfEmit(err);
|
||||
return;
|
||||
}
|
||||
const now = Number(new Date());
|
||||
if (prevStat && curStat.size !== prevStat.size) {
|
||||
writes.get(path).lastChange = now;
|
||||
}
|
||||
const pw = writes.get(path);
|
||||
const df = now - pw.lastChange;
|
||||
if (df >= threshold) {
|
||||
writes.delete(path);
|
||||
awfEmit(undefined, curStat);
|
||||
}
|
||||
else {
|
||||
timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval, curStat);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (!writes.has(path)) {
|
||||
writes.set(path, {
|
||||
lastChange: now,
|
||||
cancelWait: () => {
|
||||
writes.delete(path);
|
||||
clearTimeout(timeoutHandler);
|
||||
return event;
|
||||
},
|
||||
});
|
||||
timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Determines whether user has asked to ignore this path.
|
||||
*/
|
||||
_isIgnored(path, stats) {
|
||||
if (this.options.atomic && DOT_RE.test(path))
|
||||
return true;
|
||||
if (!this._userIgnored) {
|
||||
const { cwd } = this.options;
|
||||
const ign = this.options.ignored;
|
||||
const ignored = (ign || []).map(normalizeIgnored(cwd));
|
||||
const ignoredPaths = [...this._ignoredPaths];
|
||||
const list = [...ignoredPaths.map(normalizeIgnored(cwd)), ...ignored];
|
||||
this._userIgnored = anymatch(list, undefined);
|
||||
}
|
||||
return this._userIgnored(path, stats);
|
||||
}
|
||||
_isntIgnored(path, stat) {
|
||||
return !this._isIgnored(path, stat);
|
||||
}
|
||||
/**
|
||||
* Provides a set of common helpers and properties relating to symlink handling.
|
||||
* @param path file or directory pattern being watched
|
||||
*/
|
||||
_getWatchHelpers(path) {
|
||||
return new WatchHelper(path, this.options.followSymlinks, this);
|
||||
}
|
||||
// Directory helpers
|
||||
// -----------------
|
||||
/**
|
||||
* Provides directory tracking objects
|
||||
* @param directory path of the directory
|
||||
*/
|
||||
_getWatchedDir(directory) {
|
||||
const dir = sysPath.resolve(directory);
|
||||
if (!this._watched.has(dir))
|
||||
this._watched.set(dir, new DirEntry(dir, this._boundRemove));
|
||||
return this._watched.get(dir);
|
||||
}
|
||||
// File helpers
|
||||
// ------------
|
||||
/**
|
||||
* Check for read permissions: https://stackoverflow.com/a/11781404/1358405
|
||||
*/
|
||||
_hasReadPermissions(stats) {
|
||||
if (this.options.ignorePermissionErrors)
|
||||
return true;
|
||||
return Boolean(Number(stats.mode) & 0o400);
|
||||
}
|
||||
/**
|
||||
* Handles emitting unlink events for
|
||||
* files and directories, and via recursion, for
|
||||
* files and directories within directories that are unlinked
|
||||
* @param directory within which the following item is located
|
||||
* @param item base path of item/directory
|
||||
*/
|
||||
_remove(directory, item, isDirectory) {
|
||||
// if what is being deleted is a directory, get that directory's paths
|
||||
// for recursive deleting and cleaning of watched object
|
||||
// if it is not a directory, nestedDirectoryChildren will be empty array
|
||||
const path = sysPath.join(directory, item);
|
||||
const fullPath = sysPath.resolve(path);
|
||||
isDirectory =
|
||||
isDirectory != null ? isDirectory : this._watched.has(path) || this._watched.has(fullPath);
|
||||
// prevent duplicate handling in case of arriving here nearly simultaneously
|
||||
// via multiple paths (such as _handleFile and _handleDir)
|
||||
if (!this._throttle('remove', path, 100))
|
||||
return;
|
||||
// if the only watched file is removed, watch for its return
|
||||
if (!isDirectory && this._watched.size === 1) {
|
||||
this.add(directory, item, true);
|
||||
}
|
||||
// This will create a new entry in the watched object in either case
|
||||
// so we got to do the directory check beforehand
|
||||
const wp = this._getWatchedDir(path);
|
||||
const nestedDirectoryChildren = wp.getChildren();
|
||||
// Recursively remove children directories / files.
|
||||
nestedDirectoryChildren.forEach((nested) => this._remove(path, nested));
|
||||
// Check if item was on the watched list and remove it
|
||||
const parent = this._getWatchedDir(directory);
|
||||
const wasTracked = parent.has(item);
|
||||
parent.remove(item);
|
||||
// Fixes issue #1042 -> Relative paths were detected and added as symlinks
|
||||
// (https://github.com/paulmillr/chokidar/blob/e1753ddbc9571bdc33b4a4af172d52cb6e611c10/lib/nodefs-handler.js#L612),
|
||||
// but never removed from the map in case the path was deleted.
|
||||
// This leads to an incorrect state if the path was recreated:
|
||||
// https://github.com/paulmillr/chokidar/blob/e1753ddbc9571bdc33b4a4af172d52cb6e611c10/lib/nodefs-handler.js#L553
|
||||
if (this._symlinkPaths.has(fullPath)) {
|
||||
this._symlinkPaths.delete(fullPath);
|
||||
}
|
||||
// If we wait for this file to be fully written, cancel the wait.
|
||||
let relPath = path;
|
||||
if (this.options.cwd)
|
||||
relPath = sysPath.relative(this.options.cwd, path);
|
||||
if (this.options.awaitWriteFinish && this._pendingWrites.has(relPath)) {
|
||||
const event = this._pendingWrites.get(relPath).cancelWait();
|
||||
if (event === handler_js_1.EVENTS.ADD)
|
||||
return;
|
||||
}
|
||||
// The Entry will either be a directory that just got removed
|
||||
// or a bogus entry to a file, in either case we have to remove it
|
||||
this._watched.delete(path);
|
||||
this._watched.delete(fullPath);
|
||||
const eventName = isDirectory ? handler_js_1.EVENTS.UNLINK_DIR : handler_js_1.EVENTS.UNLINK;
|
||||
if (wasTracked && !this._isIgnored(path))
|
||||
this._emit(eventName, path);
|
||||
// Avoid conflicts if we later create another file with the same name
|
||||
this._closePath(path);
|
||||
}
|
||||
/**
|
||||
* Closes all watchers for a path
|
||||
*/
|
||||
_closePath(path) {
|
||||
this._closeFile(path);
|
||||
const dir = sysPath.dirname(path);
|
||||
this._getWatchedDir(dir).remove(sysPath.basename(path));
|
||||
}
|
||||
/**
|
||||
* Closes only file-specific watchers
|
||||
*/
|
||||
_closeFile(path) {
|
||||
const closers = this._closers.get(path);
|
||||
if (!closers)
|
||||
return;
|
||||
closers.forEach((closer) => closer());
|
||||
this._closers.delete(path);
|
||||
}
|
||||
_addPathCloser(path, closer) {
|
||||
if (!closer)
|
||||
return;
|
||||
let list = this._closers.get(path);
|
||||
if (!list) {
|
||||
list = [];
|
||||
this._closers.set(path, list);
|
||||
}
|
||||
list.push(closer);
|
||||
}
|
||||
_readdirp(root, opts) {
|
||||
if (this.closed)
|
||||
return;
|
||||
const options = { type: handler_js_1.EVENTS.ALL, alwaysStat: true, lstat: true, ...opts, depth: 0 };
|
||||
let stream = (0, readdirp_1.readdirp)(root, options);
|
||||
this._streams.add(stream);
|
||||
stream.once(handler_js_1.STR_CLOSE, () => {
|
||||
stream = undefined;
|
||||
});
|
||||
stream.once(handler_js_1.STR_END, () => {
|
||||
if (stream) {
|
||||
this._streams.delete(stream);
|
||||
stream = undefined;
|
||||
}
|
||||
});
|
||||
return stream;
|
||||
}
|
||||
}
|
||||
exports.FSWatcher = FSWatcher;
|
||||
/**
|
||||
* Instantiates watcher with paths to be tracked.
|
||||
* @param paths file / directory paths
|
||||
* @param options opts, such as `atomic`, `awaitWriteFinish`, `ignored`, and others
|
||||
* @returns an instance of FSWatcher for chaining.
|
||||
* @example
|
||||
* const watcher = watch('.').on('all', (event, path) => { console.log(event, path); });
|
||||
* watch('.', { atomic: true, awaitWriteFinish: true, ignored: (f, stats) => stats?.isFile() && !f.endsWith('.js') })
|
||||
*/
|
||||
function watch(paths, options = {}) {
|
||||
const watcher = new FSWatcher(options);
|
||||
watcher.add(paths);
|
||||
return watcher;
|
||||
}
|
||||
exports.default = { watch, FSWatcher };
|
||||
69
node_modules/chokidar/package.json
generated
vendored
Normal file
69
node_modules/chokidar/package.json
generated
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
{
|
||||
"name": "chokidar",
|
||||
"description": "Minimal and efficient cross-platform file watching library",
|
||||
"version": "4.0.3",
|
||||
"homepage": "https://github.com/paulmillr/chokidar",
|
||||
"author": "Paul Miller (https://paulmillr.com)",
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts",
|
||||
"handler.js",
|
||||
"handler.d.ts",
|
||||
"esm"
|
||||
],
|
||||
"main": "./index.js",
|
||||
"module": "./esm/index.js",
|
||||
"types": "./index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./esm/index.js",
|
||||
"require": "./index.js"
|
||||
},
|
||||
"./handler.js": {
|
||||
"import": "./esm/handler.js",
|
||||
"require": "./handler.js"
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"readdirp": "^4.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@paulmillr/jsbt": "0.2.1",
|
||||
"@types/node": "20.14.8",
|
||||
"chai": "4.3.4",
|
||||
"prettier": "3.1.1",
|
||||
"rimraf": "5.0.5",
|
||||
"sinon": "12.0.1",
|
||||
"sinon-chai": "3.7.0",
|
||||
"typescript": "5.5.2",
|
||||
"upath": "2.0.1"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"engines": {
|
||||
"node": ">= 14.16.0"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/paulmillr/chokidar.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/paulmillr/chokidar/issues"
|
||||
},
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"build": "tsc && tsc -p tsconfig.esm.json",
|
||||
"lint": "prettier --check src",
|
||||
"format": "prettier --write src",
|
||||
"test": "node --test"
|
||||
},
|
||||
"keywords": [
|
||||
"fs",
|
||||
"watch",
|
||||
"watchFile",
|
||||
"watcher",
|
||||
"watching",
|
||||
"file",
|
||||
"fsevents"
|
||||
],
|
||||
"funding": "https://paulmillr.com/funding/"
|
||||
}
|
||||
7
node_modules/detect-libc/.npmignore
generated
vendored
Normal file
7
node_modules/detect-libc/.npmignore
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
.nyc_output
|
||||
.travis.yml
|
||||
coverage
|
||||
test.js
|
||||
node_modules
|
||||
/.circleci
|
||||
/tests/integration
|
||||
201
node_modules/detect-libc/LICENSE
generated
vendored
Normal file
201
node_modules/detect-libc/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "{}"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright {yyyy} {name of copyright owner}
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
78
node_modules/detect-libc/README.md
generated
vendored
Normal file
78
node_modules/detect-libc/README.md
generated
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
# detect-libc
|
||||
|
||||
Node.js module to detect the C standard library (libc) implementation
|
||||
family and version in use on a given Linux system.
|
||||
|
||||
Provides a value suitable for use with the `LIBC` option of
|
||||
[prebuild](https://www.npmjs.com/package/prebuild),
|
||||
[prebuild-ci](https://www.npmjs.com/package/prebuild-ci) and
|
||||
[prebuild-install](https://www.npmjs.com/package/prebuild-install),
|
||||
therefore allowing build and provision of pre-compiled binaries
|
||||
for musl-based Linux e.g. Alpine as well as glibc-based.
|
||||
|
||||
Currently supports libc detection of `glibc` and `musl`.
|
||||
|
||||
## Install
|
||||
|
||||
```sh
|
||||
npm install detect-libc
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### API
|
||||
|
||||
```js
|
||||
const { GLIBC, MUSL, family, version, isNonGlibcLinux } = require('detect-libc');
|
||||
```
|
||||
|
||||
* `GLIBC` is a String containing the value "glibc" for comparison with `family`.
|
||||
* `MUSL` is a String containing the value "musl" for comparison with `family`.
|
||||
* `family` is a String representing the system libc family.
|
||||
* `version` is a String representing the system libc version number.
|
||||
* `isNonGlibcLinux` is a Boolean representing whether the system is a non-glibc Linux, e.g. Alpine.
|
||||
|
||||
### detect-libc command line tool
|
||||
|
||||
When run on a Linux system with a non-glibc libc,
|
||||
the child command will be run with the `LIBC` environment variable
|
||||
set to the relevant value.
|
||||
|
||||
On all other platforms will run the child command as-is.
|
||||
|
||||
The command line feature requires `spawnSync` provided by Node v0.12+.
|
||||
|
||||
```sh
|
||||
detect-libc child-command
|
||||
```
|
||||
|
||||
## Integrating with prebuild
|
||||
|
||||
```json
|
||||
"scripts": {
|
||||
"install": "detect-libc prebuild-install || node-gyp rebuild",
|
||||
"test": "mocha && detect-libc prebuild-ci"
|
||||
},
|
||||
"dependencies": {
|
||||
"detect-libc": "^1.0.2",
|
||||
"prebuild-install": "^2.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"prebuild": "^6.2.1",
|
||||
"prebuild-ci": "^2.2.3"
|
||||
}
|
||||
```
|
||||
|
||||
## Licence
|
||||
|
||||
Copyright 2017 Lovell Fuller
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0.html)
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
18
node_modules/detect-libc/bin/detect-libc.js
generated
vendored
Executable file
18
node_modules/detect-libc/bin/detect-libc.js
generated
vendored
Executable file
@@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
'use strict';
|
||||
|
||||
var spawnSync = require('child_process').spawnSync;
|
||||
var libc = require('../');
|
||||
|
||||
var spawnOptions = {
|
||||
env: process.env,
|
||||
shell: true,
|
||||
stdio: 'inherit'
|
||||
};
|
||||
|
||||
if (libc.isNonGlibcLinux) {
|
||||
spawnOptions.env.LIBC = process.env.LIBC || libc.family;
|
||||
}
|
||||
|
||||
process.exit(spawnSync(process.argv[2], process.argv.slice(3), spawnOptions).status);
|
||||
35
node_modules/detect-libc/package.json
generated
vendored
Normal file
35
node_modules/detect-libc/package.json
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"name": "detect-libc",
|
||||
"version": "1.0.3",
|
||||
"description": "Node.js module to detect the C standard library (libc) implementation family and version",
|
||||
"main": "lib/detect-libc.js",
|
||||
"bin": {
|
||||
"detect-libc": "./bin/detect-libc.js"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "semistandard && nyc --reporter=lcov ava"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/lovell/detect-libc"
|
||||
},
|
||||
"keywords": [
|
||||
"libc",
|
||||
"glibc",
|
||||
"musl"
|
||||
],
|
||||
"author": "Lovell Fuller <npm@lovell.info>",
|
||||
"contributors": [
|
||||
"Niklas Salmoukas <niklas@salmoukas.com>"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"devDependencies": {
|
||||
"ava": "^0.23.0",
|
||||
"nyc": "^11.3.0",
|
||||
"proxyquire": "^1.8.0",
|
||||
"semistandard": "^11.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.10"
|
||||
}
|
||||
}
|
||||
21
node_modules/fill-range/LICENSE
generated
vendored
Normal file
21
node_modules/fill-range/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014-present, Jon Schlinkert.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
237
node_modules/fill-range/README.md
generated
vendored
Normal file
237
node_modules/fill-range/README.md
generated
vendored
Normal file
@@ -0,0 +1,237 @@
|
||||
# fill-range [](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=W8YFZ425KND68) [](https://www.npmjs.com/package/fill-range) [](https://npmjs.org/package/fill-range) [](https://npmjs.org/package/fill-range) [](https://travis-ci.org/jonschlinkert/fill-range)
|
||||
|
||||
> Fill in a range of numbers or letters, optionally passing an increment or `step` to use, or create a regex-compatible range with `options.toRegex`
|
||||
|
||||
Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.
|
||||
|
||||
## Install
|
||||
|
||||
Install with [npm](https://www.npmjs.com/):
|
||||
|
||||
```sh
|
||||
$ npm install --save fill-range
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Expands numbers and letters, optionally using a `step` as the last argument. _(Numbers may be defined as JavaScript numbers or strings)_.
|
||||
|
||||
```js
|
||||
const fill = require('fill-range');
|
||||
// fill(from, to[, step, options]);
|
||||
|
||||
console.log(fill('1', '10')); //=> ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
|
||||
console.log(fill('1', '10', { toRegex: true })); //=> [1-9]|10
|
||||
```
|
||||
|
||||
**Params**
|
||||
|
||||
* `from`: **{String|Number}** the number or letter to start with
|
||||
* `to`: **{String|Number}** the number or letter to end with
|
||||
* `step`: **{String|Number|Object|Function}** Optionally pass a [step](#optionsstep) to use.
|
||||
* `options`: **{Object|Function}**: See all available [options](#options)
|
||||
|
||||
## Examples
|
||||
|
||||
By default, an array of values is returned.
|
||||
|
||||
**Alphabetical ranges**
|
||||
|
||||
```js
|
||||
console.log(fill('a', 'e')); //=> ['a', 'b', 'c', 'd', 'e']
|
||||
console.log(fill('A', 'E')); //=> [ 'A', 'B', 'C', 'D', 'E' ]
|
||||
```
|
||||
|
||||
**Numerical ranges**
|
||||
|
||||
Numbers can be defined as actual numbers or strings.
|
||||
|
||||
```js
|
||||
console.log(fill(1, 5)); //=> [ 1, 2, 3, 4, 5 ]
|
||||
console.log(fill('1', '5')); //=> [ 1, 2, 3, 4, 5 ]
|
||||
```
|
||||
|
||||
**Negative ranges**
|
||||
|
||||
Numbers can be defined as actual numbers or strings.
|
||||
|
||||
```js
|
||||
console.log(fill('-5', '-1')); //=> [ '-5', '-4', '-3', '-2', '-1' ]
|
||||
console.log(fill('-5', '5')); //=> [ '-5', '-4', '-3', '-2', '-1', '0', '1', '2', '3', '4', '5' ]
|
||||
```
|
||||
|
||||
**Steps (increments)**
|
||||
|
||||
```js
|
||||
// numerical ranges with increments
|
||||
console.log(fill('0', '25', 4)); //=> [ '0', '4', '8', '12', '16', '20', '24' ]
|
||||
console.log(fill('0', '25', 5)); //=> [ '0', '5', '10', '15', '20', '25' ]
|
||||
console.log(fill('0', '25', 6)); //=> [ '0', '6', '12', '18', '24' ]
|
||||
|
||||
// alphabetical ranges with increments
|
||||
console.log(fill('a', 'z', 4)); //=> [ 'a', 'e', 'i', 'm', 'q', 'u', 'y' ]
|
||||
console.log(fill('a', 'z', 5)); //=> [ 'a', 'f', 'k', 'p', 'u', 'z' ]
|
||||
console.log(fill('a', 'z', 6)); //=> [ 'a', 'g', 'm', 's', 'y' ]
|
||||
```
|
||||
|
||||
## Options
|
||||
|
||||
### options.step
|
||||
|
||||
**Type**: `number` (formatted as a string or number)
|
||||
|
||||
**Default**: `undefined`
|
||||
|
||||
**Description**: The increment to use for the range. Can be used with letters or numbers.
|
||||
|
||||
**Example(s)**
|
||||
|
||||
```js
|
||||
// numbers
|
||||
console.log(fill('1', '10', 2)); //=> [ '1', '3', '5', '7', '9' ]
|
||||
console.log(fill('1', '10', 3)); //=> [ '1', '4', '7', '10' ]
|
||||
console.log(fill('1', '10', 4)); //=> [ '1', '5', '9' ]
|
||||
|
||||
// letters
|
||||
console.log(fill('a', 'z', 5)); //=> [ 'a', 'f', 'k', 'p', 'u', 'z' ]
|
||||
console.log(fill('a', 'z', 7)); //=> [ 'a', 'h', 'o', 'v' ]
|
||||
console.log(fill('a', 'z', 9)); //=> [ 'a', 'j', 's' ]
|
||||
```
|
||||
|
||||
### options.strictRanges
|
||||
|
||||
**Type**: `boolean`
|
||||
|
||||
**Default**: `false`
|
||||
|
||||
**Description**: By default, `null` is returned when an invalid range is passed. Enable this option to throw a `RangeError` on invalid ranges.
|
||||
|
||||
**Example(s)**
|
||||
|
||||
The following are all invalid:
|
||||
|
||||
```js
|
||||
fill('1.1', '2'); // decimals not supported in ranges
|
||||
fill('a', '2'); // incompatible range values
|
||||
fill(1, 10, 'foo'); // invalid "step" argument
|
||||
```
|
||||
|
||||
### options.stringify
|
||||
|
||||
**Type**: `boolean`
|
||||
|
||||
**Default**: `undefined`
|
||||
|
||||
**Description**: Cast all returned values to strings. By default, integers are returned as numbers.
|
||||
|
||||
**Example(s)**
|
||||
|
||||
```js
|
||||
console.log(fill(1, 5)); //=> [ 1, 2, 3, 4, 5 ]
|
||||
console.log(fill(1, 5, { stringify: true })); //=> [ '1', '2', '3', '4', '5' ]
|
||||
```
|
||||
|
||||
### options.toRegex
|
||||
|
||||
**Type**: `boolean`
|
||||
|
||||
**Default**: `undefined`
|
||||
|
||||
**Description**: Create a regex-compatible source string, instead of expanding values to an array.
|
||||
|
||||
**Example(s)**
|
||||
|
||||
```js
|
||||
// alphabetical range
|
||||
console.log(fill('a', 'e', { toRegex: true })); //=> '[a-e]'
|
||||
// alphabetical with step
|
||||
console.log(fill('a', 'z', 3, { toRegex: true })); //=> 'a|d|g|j|m|p|s|v|y'
|
||||
// numerical range
|
||||
console.log(fill('1', '100', { toRegex: true })); //=> '[1-9]|[1-9][0-9]|100'
|
||||
// numerical range with zero padding
|
||||
console.log(fill('000001', '100000', { toRegex: true }));
|
||||
//=> '0{5}[1-9]|0{4}[1-9][0-9]|0{3}[1-9][0-9]{2}|0{2}[1-9][0-9]{3}|0[1-9][0-9]{4}|100000'
|
||||
```
|
||||
|
||||
### options.transform
|
||||
|
||||
**Type**: `function`
|
||||
|
||||
**Default**: `undefined`
|
||||
|
||||
**Description**: Customize each value in the returned array (or [string](#optionstoRegex)). _(you can also pass this function as the last argument to `fill()`)_.
|
||||
|
||||
**Example(s)**
|
||||
|
||||
```js
|
||||
// add zero padding
|
||||
console.log(fill(1, 5, value => String(value).padStart(4, '0')));
|
||||
//=> ['0001', '0002', '0003', '0004', '0005']
|
||||
```
|
||||
|
||||
## About
|
||||
|
||||
<details>
|
||||
<summary><strong>Contributing</strong></summary>
|
||||
|
||||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><strong>Running Tests</strong></summary>
|
||||
|
||||
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
|
||||
|
||||
```sh
|
||||
$ npm install && npm test
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><strong>Building docs</strong></summary>
|
||||
|
||||
_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
|
||||
|
||||
To generate the readme, run the following command:
|
||||
|
||||
```sh
|
||||
$ npm install -g verbose/verb#dev verb-generate-readme && verb
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
### Contributors
|
||||
|
||||
| **Commits** | **Contributor** |
|
||||
| --- | --- |
|
||||
| 116 | [jonschlinkert](https://github.com/jonschlinkert) |
|
||||
| 4 | [paulmillr](https://github.com/paulmillr) |
|
||||
| 2 | [realityking](https://github.com/realityking) |
|
||||
| 2 | [bluelovers](https://github.com/bluelovers) |
|
||||
| 1 | [edorivai](https://github.com/edorivai) |
|
||||
| 1 | [wtgtybhertgeghgtwtg](https://github.com/wtgtybhertgeghgtwtg) |
|
||||
|
||||
### Author
|
||||
|
||||
**Jon Schlinkert**
|
||||
|
||||
* [GitHub Profile](https://github.com/jonschlinkert)
|
||||
* [Twitter Profile](https://twitter.com/jonschlinkert)
|
||||
* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)
|
||||
|
||||
Please consider supporting me on Patreon, or [start your own Patreon page](https://patreon.com/invite/bxpbvm)!
|
||||
|
||||
<a href="https://www.patreon.com/jonschlinkert">
|
||||
<img src="https://c5.patreon.com/external/logo/become_a_patron_button@2x.png" height="50">
|
||||
</a>
|
||||
|
||||
### License
|
||||
|
||||
Copyright © 2019, [Jon Schlinkert](https://github.com/jonschlinkert).
|
||||
Released under the [MIT License](LICENSE).
|
||||
|
||||
***
|
||||
|
||||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on April 08, 2019._
|
||||
248
node_modules/fill-range/index.js
generated
vendored
Normal file
248
node_modules/fill-range/index.js
generated
vendored
Normal file
@@ -0,0 +1,248 @@
|
||||
/*!
|
||||
* fill-range <https://github.com/jonschlinkert/fill-range>
|
||||
*
|
||||
* Copyright (c) 2014-present, Jon Schlinkert.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const util = require('util');
|
||||
const toRegexRange = require('to-regex-range');
|
||||
|
||||
const isObject = val => val !== null && typeof val === 'object' && !Array.isArray(val);
|
||||
|
||||
const transform = toNumber => {
|
||||
return value => toNumber === true ? Number(value) : String(value);
|
||||
};
|
||||
|
||||
const isValidValue = value => {
|
||||
return typeof value === 'number' || (typeof value === 'string' && value !== '');
|
||||
};
|
||||
|
||||
const isNumber = num => Number.isInteger(+num);
|
||||
|
||||
const zeros = input => {
|
||||
let value = `${input}`;
|
||||
let index = -1;
|
||||
if (value[0] === '-') value = value.slice(1);
|
||||
if (value === '0') return false;
|
||||
while (value[++index] === '0');
|
||||
return index > 0;
|
||||
};
|
||||
|
||||
const stringify = (start, end, options) => {
|
||||
if (typeof start === 'string' || typeof end === 'string') {
|
||||
return true;
|
||||
}
|
||||
return options.stringify === true;
|
||||
};
|
||||
|
||||
const pad = (input, maxLength, toNumber) => {
|
||||
if (maxLength > 0) {
|
||||
let dash = input[0] === '-' ? '-' : '';
|
||||
if (dash) input = input.slice(1);
|
||||
input = (dash + input.padStart(dash ? maxLength - 1 : maxLength, '0'));
|
||||
}
|
||||
if (toNumber === false) {
|
||||
return String(input);
|
||||
}
|
||||
return input;
|
||||
};
|
||||
|
||||
const toMaxLen = (input, maxLength) => {
|
||||
let negative = input[0] === '-' ? '-' : '';
|
||||
if (negative) {
|
||||
input = input.slice(1);
|
||||
maxLength--;
|
||||
}
|
||||
while (input.length < maxLength) input = '0' + input;
|
||||
return negative ? ('-' + input) : input;
|
||||
};
|
||||
|
||||
const toSequence = (parts, options, maxLen) => {
|
||||
parts.negatives.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
||||
parts.positives.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
||||
|
||||
let prefix = options.capture ? '' : '?:';
|
||||
let positives = '';
|
||||
let negatives = '';
|
||||
let result;
|
||||
|
||||
if (parts.positives.length) {
|
||||
positives = parts.positives.map(v => toMaxLen(String(v), maxLen)).join('|');
|
||||
}
|
||||
|
||||
if (parts.negatives.length) {
|
||||
negatives = `-(${prefix}${parts.negatives.map(v => toMaxLen(String(v), maxLen)).join('|')})`;
|
||||
}
|
||||
|
||||
if (positives && negatives) {
|
||||
result = `${positives}|${negatives}`;
|
||||
} else {
|
||||
result = positives || negatives;
|
||||
}
|
||||
|
||||
if (options.wrap) {
|
||||
return `(${prefix}${result})`;
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
const toRange = (a, b, isNumbers, options) => {
|
||||
if (isNumbers) {
|
||||
return toRegexRange(a, b, { wrap: false, ...options });
|
||||
}
|
||||
|
||||
let start = String.fromCharCode(a);
|
||||
if (a === b) return start;
|
||||
|
||||
let stop = String.fromCharCode(b);
|
||||
return `[${start}-${stop}]`;
|
||||
};
|
||||
|
||||
const toRegex = (start, end, options) => {
|
||||
if (Array.isArray(start)) {
|
||||
let wrap = options.wrap === true;
|
||||
let prefix = options.capture ? '' : '?:';
|
||||
return wrap ? `(${prefix}${start.join('|')})` : start.join('|');
|
||||
}
|
||||
return toRegexRange(start, end, options);
|
||||
};
|
||||
|
||||
const rangeError = (...args) => {
|
||||
return new RangeError('Invalid range arguments: ' + util.inspect(...args));
|
||||
};
|
||||
|
||||
const invalidRange = (start, end, options) => {
|
||||
if (options.strictRanges === true) throw rangeError([start, end]);
|
||||
return [];
|
||||
};
|
||||
|
||||
const invalidStep = (step, options) => {
|
||||
if (options.strictRanges === true) {
|
||||
throw new TypeError(`Expected step "${step}" to be a number`);
|
||||
}
|
||||
return [];
|
||||
};
|
||||
|
||||
const fillNumbers = (start, end, step = 1, options = {}) => {
|
||||
let a = Number(start);
|
||||
let b = Number(end);
|
||||
|
||||
if (!Number.isInteger(a) || !Number.isInteger(b)) {
|
||||
if (options.strictRanges === true) throw rangeError([start, end]);
|
||||
return [];
|
||||
}
|
||||
|
||||
// fix negative zero
|
||||
if (a === 0) a = 0;
|
||||
if (b === 0) b = 0;
|
||||
|
||||
let descending = a > b;
|
||||
let startString = String(start);
|
||||
let endString = String(end);
|
||||
let stepString = String(step);
|
||||
step = Math.max(Math.abs(step), 1);
|
||||
|
||||
let padded = zeros(startString) || zeros(endString) || zeros(stepString);
|
||||
let maxLen = padded ? Math.max(startString.length, endString.length, stepString.length) : 0;
|
||||
let toNumber = padded === false && stringify(start, end, options) === false;
|
||||
let format = options.transform || transform(toNumber);
|
||||
|
||||
if (options.toRegex && step === 1) {
|
||||
return toRange(toMaxLen(start, maxLen), toMaxLen(end, maxLen), true, options);
|
||||
}
|
||||
|
||||
let parts = { negatives: [], positives: [] };
|
||||
let push = num => parts[num < 0 ? 'negatives' : 'positives'].push(Math.abs(num));
|
||||
let range = [];
|
||||
let index = 0;
|
||||
|
||||
while (descending ? a >= b : a <= b) {
|
||||
if (options.toRegex === true && step > 1) {
|
||||
push(a);
|
||||
} else {
|
||||
range.push(pad(format(a, index), maxLen, toNumber));
|
||||
}
|
||||
a = descending ? a - step : a + step;
|
||||
index++;
|
||||
}
|
||||
|
||||
if (options.toRegex === true) {
|
||||
return step > 1
|
||||
? toSequence(parts, options, maxLen)
|
||||
: toRegex(range, null, { wrap: false, ...options });
|
||||
}
|
||||
|
||||
return range;
|
||||
};
|
||||
|
||||
const fillLetters = (start, end, step = 1, options = {}) => {
|
||||
if ((!isNumber(start) && start.length > 1) || (!isNumber(end) && end.length > 1)) {
|
||||
return invalidRange(start, end, options);
|
||||
}
|
||||
|
||||
let format = options.transform || (val => String.fromCharCode(val));
|
||||
let a = `${start}`.charCodeAt(0);
|
||||
let b = `${end}`.charCodeAt(0);
|
||||
|
||||
let descending = a > b;
|
||||
let min = Math.min(a, b);
|
||||
let max = Math.max(a, b);
|
||||
|
||||
if (options.toRegex && step === 1) {
|
||||
return toRange(min, max, false, options);
|
||||
}
|
||||
|
||||
let range = [];
|
||||
let index = 0;
|
||||
|
||||
while (descending ? a >= b : a <= b) {
|
||||
range.push(format(a, index));
|
||||
a = descending ? a - step : a + step;
|
||||
index++;
|
||||
}
|
||||
|
||||
if (options.toRegex === true) {
|
||||
return toRegex(range, null, { wrap: false, options });
|
||||
}
|
||||
|
||||
return range;
|
||||
};
|
||||
|
||||
const fill = (start, end, step, options = {}) => {
|
||||
if (end == null && isValidValue(start)) {
|
||||
return [start];
|
||||
}
|
||||
|
||||
if (!isValidValue(start) || !isValidValue(end)) {
|
||||
return invalidRange(start, end, options);
|
||||
}
|
||||
|
||||
if (typeof step === 'function') {
|
||||
return fill(start, end, 1, { transform: step });
|
||||
}
|
||||
|
||||
if (isObject(step)) {
|
||||
return fill(start, end, 0, step);
|
||||
}
|
||||
|
||||
let opts = { ...options };
|
||||
if (opts.capture === true) opts.wrap = true;
|
||||
step = step || opts.step || 1;
|
||||
|
||||
if (!isNumber(step)) {
|
||||
if (step != null && !isObject(step)) return invalidStep(step, opts);
|
||||
return fill(start, end, 1, step);
|
||||
}
|
||||
|
||||
if (isNumber(start) && isNumber(end)) {
|
||||
return fillNumbers(start, end, step, opts);
|
||||
}
|
||||
|
||||
return fillLetters(start, end, Math.max(Math.abs(step), 1), opts);
|
||||
};
|
||||
|
||||
module.exports = fill;
|
||||
74
node_modules/fill-range/package.json
generated
vendored
Normal file
74
node_modules/fill-range/package.json
generated
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
{
|
||||
"name": "fill-range",
|
||||
"description": "Fill in a range of numbers or letters, optionally passing an increment or `step` to use, or create a regex-compatible range with `options.toRegex`",
|
||||
"version": "7.1.1",
|
||||
"homepage": "https://github.com/jonschlinkert/fill-range",
|
||||
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
|
||||
"contributors": [
|
||||
"Edo Rivai (edo.rivai.nl)",
|
||||
"Jon Schlinkert (http://twitter.com/jonschlinkert)",
|
||||
"Paul Miller (paulmillr.com)",
|
||||
"Rouven Weßling (www.rouvenwessling.de)",
|
||||
"(https://github.com/wtgtybhertgeghgtwtg)"
|
||||
],
|
||||
"repository": "jonschlinkert/fill-range",
|
||||
"bugs": {
|
||||
"url": "https://github.com/jonschlinkert/fill-range/issues"
|
||||
},
|
||||
"license": "MIT",
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"main": "index.js",
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "eslint --cache --cache-location node_modules/.cache/.eslintcache --report-unused-disable-directives --ignore-path .gitignore .",
|
||||
"mocha": "mocha --reporter dot",
|
||||
"test": "npm run lint && npm run mocha",
|
||||
"test:ci": "npm run test:cover",
|
||||
"test:cover": "nyc npm run mocha"
|
||||
},
|
||||
"dependencies": {
|
||||
"to-regex-range": "^5.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"gulp-format-md": "^2.0.0",
|
||||
"mocha": "^6.1.1",
|
||||
"nyc": "^15.1.0"
|
||||
},
|
||||
"keywords": [
|
||||
"alpha",
|
||||
"alphabetical",
|
||||
"array",
|
||||
"bash",
|
||||
"brace",
|
||||
"expand",
|
||||
"expansion",
|
||||
"fill",
|
||||
"glob",
|
||||
"match",
|
||||
"matches",
|
||||
"matching",
|
||||
"number",
|
||||
"numerical",
|
||||
"range",
|
||||
"ranges",
|
||||
"regex",
|
||||
"sh"
|
||||
],
|
||||
"verb": {
|
||||
"toc": false,
|
||||
"layout": "default",
|
||||
"tasks": [
|
||||
"readme"
|
||||
],
|
||||
"plugins": [
|
||||
"gulp-format-md"
|
||||
],
|
||||
"lint": {
|
||||
"reflinks": true
|
||||
}
|
||||
}
|
||||
}
|
||||
21
node_modules/immutable/LICENSE
generated
vendored
Normal file
21
node_modules/immutable/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2014-present, Lee Byron and other contributors.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
731
node_modules/immutable/README.md
generated
vendored
Normal file
731
node_modules/immutable/README.md
generated
vendored
Normal file
@@ -0,0 +1,731 @@
|
||||
# Immutable collections for JavaScript
|
||||
|
||||
[](https://github.com/immutable-js/immutable-js/actions/workflows/ci.yml?query=branch%3Amain) [Chat on slack](https://immutable-js.slack.com)
|
||||
|
||||
[Read the docs](https://immutable-js.com/docs/) and eat your vegetables.
|
||||
|
||||
Docs are automatically generated from [README.md][] and [immutable.d.ts][].
|
||||
Please contribute! Also, don't miss the [wiki][] which contains articles on
|
||||
additional specific topics. Can't find something? Open an [issue][].
|
||||
|
||||
**Table of contents:**
|
||||
|
||||
- [Introduction](#introduction)
|
||||
- [Getting started](#getting-started)
|
||||
- [The case for Immutability](#the-case-for-immutability)
|
||||
- [JavaScript-first API](#javascript-first-api)
|
||||
- [Nested Structures](#nested-structures)
|
||||
- [Equality treats Collections as Values](#equality-treats-collections-as-values)
|
||||
- [Batching Mutations](#batching-mutations)
|
||||
- [Lazy Seq](#lazy-seq)
|
||||
- [Additional Tools and Resources](#additional-tools-and-resources)
|
||||
- [Contributing](#contributing)
|
||||
|
||||
## Introduction
|
||||
|
||||
[Immutable][] data cannot be changed once created, leading to much simpler
|
||||
application development, no defensive copying, and enabling advanced memoization
|
||||
and change detection techniques with simple logic. [Persistent][] data presents
|
||||
a mutative API which does not update the data in-place, but instead always
|
||||
yields new updated data.
|
||||
|
||||
Immutable.js provides many Persistent Immutable data structures including:
|
||||
`List`, `Stack`, `Map`, `OrderedMap`, `Set`, `OrderedSet` and `Record`.
|
||||
|
||||
These data structures are highly efficient on modern JavaScript VMs by using
|
||||
structural sharing via [hash maps tries][] and [vector tries][] as popularized
|
||||
by Clojure and Scala, minimizing the need to copy or cache data.
|
||||
|
||||
Immutable.js also provides a lazy `Seq`, allowing efficient
|
||||
chaining of collection methods like `map` and `filter` without creating
|
||||
intermediate representations. Create some `Seq` with `Range` and `Repeat`.
|
||||
|
||||
Want to hear more? Watch the presentation about Immutable.js:
|
||||
|
||||
[](https://youtu.be/I7IdS-PbEgI)
|
||||
|
||||
[README.md]: https://github.com/immutable-js/immutable-js/blob/main/README.md
|
||||
[immutable.d.ts]: https://github.com/immutable-js/immutable-js/blob/main/type-definitions/immutable.d.ts
|
||||
[wiki]: https://github.com/immutable-js/immutable-js/wiki
|
||||
[issue]: https://github.com/immutable-js/immutable-js/issues
|
||||
[Persistent]: https://en.wikipedia.org/wiki/Persistent_data_structure
|
||||
[Immutable]: https://en.wikipedia.org/wiki/Immutable_object
|
||||
[hash maps tries]: https://en.wikipedia.org/wiki/Hash_array_mapped_trie
|
||||
[vector tries]: https://hypirion.com/musings/understanding-persistent-vector-pt-1
|
||||
|
||||
## Getting started
|
||||
|
||||
Install `immutable` using npm.
|
||||
|
||||
```shell
|
||||
# using npm
|
||||
npm install immutable
|
||||
|
||||
# using Yarn
|
||||
yarn add immutable
|
||||
|
||||
# using pnpm
|
||||
pnpm add immutable
|
||||
|
||||
# using Bun
|
||||
bun add immutable
|
||||
```
|
||||
|
||||
Then require it into any module.
|
||||
|
||||
```js
|
||||
import { Map } from 'immutable';
|
||||
const map1 = Map({ a: 1, b: 2, c: 3 });
|
||||
const map2 = map1.set('b', 50);
|
||||
map1.get('b') + ' vs. ' + map2.get('b'); // 2 vs. 50
|
||||
```
|
||||
|
||||
### Browser
|
||||
|
||||
Immutable.js has no dependencies, which makes it predictable to include in a Browser.
|
||||
|
||||
It's highly recommended to use a module bundler like [webpack](https://webpack.js.org/),
|
||||
[rollup](https://rollupjs.org/), or
|
||||
[browserify](https://browserify.org/). The `immutable` npm module works
|
||||
without any additional consideration. All examples throughout the documentation
|
||||
will assume use of this kind of tool.
|
||||
|
||||
Alternatively, Immutable.js may be directly included as a script tag. Download
|
||||
or link to a CDN such as [CDNJS](https://cdnjs.com/libraries/immutable)
|
||||
or [jsDelivr](https://www.jsdelivr.com/package/npm/immutable).
|
||||
|
||||
Use a script tag to directly add `Immutable` to the global scope:
|
||||
|
||||
```html
|
||||
<script src="immutable.min.js"></script>
|
||||
<script>
|
||||
var map1 = Immutable.Map({ a: 1, b: 2, c: 3 });
|
||||
var map2 = map1.set('b', 50);
|
||||
map1.get('b'); // 2
|
||||
map2.get('b'); // 50
|
||||
</script>
|
||||
```
|
||||
|
||||
Or use an AMD-style loader (such as [RequireJS](https://requirejs.org/)):
|
||||
|
||||
```js
|
||||
require(['./immutable.min.js'], function (Immutable) {
|
||||
var map1 = Immutable.Map({ a: 1, b: 2, c: 3 });
|
||||
var map2 = map1.set('b', 50);
|
||||
map1.get('b'); // 2
|
||||
map2.get('b'); // 50
|
||||
});
|
||||
```
|
||||
|
||||
### Flow & TypeScript
|
||||
|
||||
Use these Immutable collections and sequences as you would use native
|
||||
collections in your [Flowtype](https://flowtype.org/) or [TypeScript](https://typescriptlang.org) programs while still taking
|
||||
advantage of type generics, error detection, and auto-complete in your IDE.
|
||||
|
||||
Installing `immutable` via npm brings with it type definitions for Flow (v0.55.0 or higher)
|
||||
and TypeScript (v4.5 or higher), so you shouldn't need to do anything at all!
|
||||
|
||||
#### Using TypeScript with Immutable.js v4+
|
||||
|
||||
Immutable.js type definitions embrace ES2015. While Immutable.js itself supports
|
||||
legacy browsers and environments, its type definitions require TypeScript's 2015
|
||||
lib. Include either `"target": "es2015"` or `"lib": "es2015"` in your
|
||||
`tsconfig.json`, or provide `--target es2015` or `--lib es2015` to the
|
||||
`tsc` command.
|
||||
|
||||
```js
|
||||
import { Map } from 'immutable';
|
||||
const map1 = Map({ a: 1, b: 2, c: 3 });
|
||||
const map2 = map1.set('b', 50);
|
||||
map1.get('b') + ' vs. ' + map2.get('b'); // 2 vs. 50
|
||||
```
|
||||
|
||||
#### Using TypeScript with Immutable.js v3 and earlier:
|
||||
|
||||
Previous versions of Immutable.js include a reference file which you can include
|
||||
via relative path to the type definitions at the top of your file.
|
||||
|
||||
```js
|
||||
///<reference path='./node_modules/immutable/dist/immutable.d.ts'/>
|
||||
import { Map } from 'immutable';
|
||||
var map1: Map<string, number>;
|
||||
map1 = Map({ a: 1, b: 2, c: 3 });
|
||||
var map2 = map1.set('b', 50);
|
||||
map1.get('b'); // 2
|
||||
map2.get('b'); // 50
|
||||
```
|
||||
|
||||
## The case for Immutability
|
||||
|
||||
Much of what makes application development difficult is tracking mutation and
|
||||
maintaining state. Developing with immutable data encourages you to think
|
||||
differently about how data flows through your application.
|
||||
|
||||
Subscribing to data events throughout your application creates a huge overhead of
|
||||
book-keeping which can hurt performance, sometimes dramatically, and creates
|
||||
opportunities for areas of your application to get out of sync with each other
|
||||
due to easy to make programmer error. Since immutable data never changes,
|
||||
subscribing to changes throughout the model is a dead-end and new data can only
|
||||
ever be passed from above.
|
||||
|
||||
This model of data flow aligns well with the architecture of [React][]
|
||||
and especially well with an application designed using the ideas of [Flux][].
|
||||
|
||||
When data is passed from above rather than being subscribed to, and you're only
|
||||
interested in doing work when something has changed, you can use equality.
|
||||
|
||||
Immutable collections should be treated as _values_ rather than _objects_. While
|
||||
objects represent some thing which could change over time, a value represents
|
||||
the state of that thing at a particular instance of time. This principle is most
|
||||
important to understanding the appropriate use of immutable data. In order to
|
||||
treat Immutable.js collections as values, it's important to use the
|
||||
`Immutable.is()` function or `.equals()` method to determine _value equality_
|
||||
instead of the `===` operator which determines object _reference identity_.
|
||||
|
||||
```js
|
||||
import { Map } from 'immutable';
|
||||
const map1 = Map({ a: 1, b: 2, c: 3 });
|
||||
const map2 = Map({ a: 1, b: 2, c: 3 });
|
||||
map1.equals(map2); // true
|
||||
map1 === map2; // false
|
||||
```
|
||||
|
||||
Note: As a performance optimization Immutable.js attempts to return the existing
|
||||
collection when an operation would result in an identical collection, allowing
|
||||
for using `===` reference equality to determine if something definitely has not
|
||||
changed. This can be extremely useful when used within a memoization function
|
||||
which would prefer to re-run the function if a deeper equality check could
|
||||
potentially be more costly. The `===` equality check is also used internally by
|
||||
`Immutable.is` and `.equals()` as a performance optimization.
|
||||
|
||||
```js
|
||||
import { Map } from 'immutable';
|
||||
const map1 = Map({ a: 1, b: 2, c: 3 });
|
||||
const map2 = map1.set('b', 2); // Set to same value
|
||||
map1 === map2; // true
|
||||
```
|
||||
|
||||
If an object is immutable, it can be "copied" simply by making another reference
|
||||
to it instead of copying the entire object. Because a reference is much smaller
|
||||
than the object itself, this results in memory savings and a potential boost in
|
||||
execution speed for programs which rely on copies (such as an undo-stack).
|
||||
|
||||
```js
|
||||
import { Map } from 'immutable';
|
||||
const map = Map({ a: 1, b: 2, c: 3 });
|
||||
const mapCopy = map; // Look, "copies" are free!
|
||||
```
|
||||
|
||||
[React]: https://reactjs.org/
|
||||
[Flux]: https://facebook.github.io/flux/docs/in-depth-overview/
|
||||
|
||||
## JavaScript-first API
|
||||
|
||||
While Immutable.js is inspired by Clojure, Scala, Haskell and other functional
|
||||
programming environments, it's designed to bring these powerful concepts to
|
||||
JavaScript, and therefore has an Object-Oriented API that closely mirrors that
|
||||
of [ES2015][] [Array][], [Map][], and [Set][].
|
||||
|
||||
[es2015]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/New_in_JavaScript/ECMAScript_6_support_in_Mozilla
|
||||
[array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
|
||||
[map]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map
|
||||
[set]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
|
||||
|
||||
The difference for the immutable collections is that methods which would mutate
|
||||
the collection, like `push`, `set`, `unshift` or `splice`, instead return a new
|
||||
immutable collection. Methods which return new arrays, like `slice` or `concat`,
|
||||
instead return new immutable collections.
|
||||
|
||||
```js
|
||||
import { List } from 'immutable';
|
||||
const list1 = List([1, 2]);
|
||||
const list2 = list1.push(3, 4, 5);
|
||||
const list3 = list2.unshift(0);
|
||||
const list4 = list1.concat(list2, list3);
|
||||
assert.equal(list1.size, 2);
|
||||
assert.equal(list2.size, 5);
|
||||
assert.equal(list3.size, 6);
|
||||
assert.equal(list4.size, 13);
|
||||
assert.equal(list4.get(0), 1);
|
||||
```
|
||||
|
||||
Almost all of the methods on [Array][] will be found in similar form on
|
||||
`Immutable.List`, those of [Map][] found on `Immutable.Map`, and those of [Set][]
|
||||
found on `Immutable.Set`, including collection operations like `forEach()`
|
||||
and `map()`.
|
||||
|
||||
```js
|
||||
import { Map } from 'immutable';
|
||||
const alpha = Map({ a: 1, b: 2, c: 3, d: 4 });
|
||||
alpha.map((v, k) => k.toUpperCase()).join();
|
||||
// 'A,B,C,D'
|
||||
```
|
||||
|
||||
### Convert from raw JavaScript objects and arrays.
|
||||
|
||||
Designed to inter-operate with your existing JavaScript, Immutable.js
|
||||
accepts plain JavaScript Arrays and Objects anywhere a method expects a
|
||||
`Collection`.
|
||||
|
||||
```js
|
||||
import { Map, List } from 'immutable';
|
||||
const map1 = Map({ a: 1, b: 2, c: 3, d: 4 });
|
||||
const map2 = Map({ c: 10, a: 20, t: 30 });
|
||||
const obj = { d: 100, o: 200, g: 300 };
|
||||
const map3 = map1.merge(map2, obj);
|
||||
// Map { a: 20, b: 2, c: 10, d: 100, t: 30, o: 200, g: 300 }
|
||||
const list1 = List([1, 2, 3]);
|
||||
const list2 = List([4, 5, 6]);
|
||||
const array = [7, 8, 9];
|
||||
const list3 = list1.concat(list2, array);
|
||||
// List [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
|
||||
```
|
||||
|
||||
This is possible because Immutable.js can treat any JavaScript Array or Object
|
||||
as a Collection. You can take advantage of this in order to get sophisticated
|
||||
collection methods on JavaScript Objects, which otherwise have a very sparse
|
||||
native API. Because Seq evaluates lazily and does not cache intermediate
|
||||
results, these operations can be extremely efficient.
|
||||
|
||||
```js
|
||||
import { Seq } from 'immutable';
|
||||
const myObject = { a: 1, b: 2, c: 3 };
|
||||
Seq(myObject)
|
||||
.map((x) => x * x)
|
||||
.toObject();
|
||||
// { a: 1, b: 4, c: 9 }
|
||||
```
|
||||
|
||||
Keep in mind, when using JS objects to construct Immutable Maps, that
|
||||
JavaScript Object properties are always strings, even if written in a quote-less
|
||||
shorthand, while Immutable Maps accept keys of any type.
|
||||
|
||||
```js
|
||||
import { fromJS } from 'immutable';
|
||||
|
||||
const obj = { 1: 'one' };
|
||||
console.log(Object.keys(obj)); // [ "1" ]
|
||||
console.log(obj['1'], obj[1]); // "one", "one"
|
||||
|
||||
const map = fromJS(obj);
|
||||
console.log(map.get('1'), map.get(1)); // "one", undefined
|
||||
```
|
||||
|
||||
Property access for JavaScript Objects first converts the key to a string, but
|
||||
since Immutable Map keys can be of any type the argument to `get()` is
|
||||
not altered.
|
||||
|
||||
### Converts back to raw JavaScript objects.
|
||||
|
||||
All Immutable.js Collections can be converted to plain JavaScript Arrays and
|
||||
Objects shallowly with `toArray()` and `toObject()` or deeply with `toJS()`.
|
||||
All Immutable Collections also implement `toJSON()` allowing them to be passed
|
||||
to `JSON.stringify` directly. They also respect the custom `toJSON()` methods of
|
||||
nested objects.
|
||||
|
||||
```js
|
||||
import { Map, List } from 'immutable';
|
||||
const deep = Map({ a: 1, b: 2, c: List([3, 4, 5]) });
|
||||
console.log(deep.toObject()); // { a: 1, b: 2, c: List [ 3, 4, 5 ] }
|
||||
console.log(deep.toArray()); // [ 1, 2, List [ 3, 4, 5 ] ]
|
||||
console.log(deep.toJS()); // { a: 1, b: 2, c: [ 3, 4, 5 ] }
|
||||
JSON.stringify(deep); // '{"a":1,"b":2,"c":[3,4,5]}'
|
||||
```
|
||||
|
||||
### Embraces ES2015
|
||||
|
||||
Immutable.js supports all JavaScript environments, including legacy
|
||||
browsers (even IE11). However it also takes advantage of features added to
|
||||
JavaScript in [ES2015][], the latest standard version of JavaScript, including
|
||||
[Iterators][], [Arrow Functions][], [Classes][], and [Modules][]. It's inspired
|
||||
by the native [Map][] and [Set][] collections added to ES2015.
|
||||
|
||||
All examples in the Documentation are presented in ES2015. To run in all
|
||||
browsers, they need to be translated to ES5.
|
||||
|
||||
```js
|
||||
// ES2015
|
||||
const mapped = foo.map((x) => x * x);
|
||||
// ES5
|
||||
var mapped = foo.map(function (x) {
|
||||
return x * x;
|
||||
});
|
||||
```
|
||||
|
||||
All Immutable.js collections are [Iterable][iterators], which allows them to be
|
||||
used anywhere an Iterable is expected, such as when spreading into an Array.
|
||||
|
||||
```js
|
||||
import { List } from 'immutable';
|
||||
const aList = List([1, 2, 3]);
|
||||
const anArray = [0, ...aList, 4, 5]; // [ 0, 1, 2, 3, 4, 5 ]
|
||||
```
|
||||
|
||||
Note: A Collection is always iterated in the same order, however that order may
|
||||
not always be well defined, as is the case for the `Map` and `Set`.
|
||||
|
||||
[Iterators]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/The_Iterator_protocol
|
||||
[Arrow Functions]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions
|
||||
[Classes]: https://wiki.ecmascript.org/doku.php?id=strawman:maximally_minimal_classes
|
||||
[Modules]: https://www.2ality.com/2014/09/es6-modules-final.html
|
||||
|
||||
## Nested Structures
|
||||
|
||||
The collections in Immutable.js are intended to be nested, allowing for deep
|
||||
trees of data, similar to JSON.
|
||||
|
||||
```js
|
||||
import { fromJS } from 'immutable';
|
||||
const nested = fromJS({ a: { b: { c: [3, 4, 5] } } });
|
||||
// Map { a: Map { b: Map { c: List [ 3, 4, 5 ] } } }
|
||||
```
|
||||
|
||||
A few power-tools allow for reading and operating on nested data. The
|
||||
most useful are `mergeDeep`, `getIn`, `setIn`, and `updateIn`, found on `List`,
|
||||
`Map` and `OrderedMap`.
|
||||
|
||||
```js
|
||||
import { fromJS } from 'immutable';
|
||||
const nested = fromJS({ a: { b: { c: [3, 4, 5] } } });
|
||||
|
||||
const nested2 = nested.mergeDeep({ a: { b: { d: 6 } } });
|
||||
// Map { a: Map { b: Map { c: List [ 3, 4, 5 ], d: 6 } } }
|
||||
|
||||
console.log(nested2.getIn(['a', 'b', 'd'])); // 6
|
||||
|
||||
const nested3 = nested2.updateIn(['a', 'b', 'd'], (value) => value + 1);
|
||||
console.log(nested3);
|
||||
// Map { a: Map { b: Map { c: List [ 3, 4, 5 ], d: 7 } } }
|
||||
|
||||
const nested4 = nested3.updateIn(['a', 'b', 'c'], (list) => list.push(6));
|
||||
// Map { a: Map { b: Map { c: List [ 3, 4, 5, 6 ], d: 7 } } }
|
||||
```
|
||||
|
||||
## Equality treats Collections as Values
|
||||
|
||||
Immutable.js collections are treated as pure data _values_. Two immutable
|
||||
collections are considered _value equal_ (via `.equals()` or `is()`) if they
|
||||
represent the same collection of values. This differs from JavaScript's typical
|
||||
_reference equal_ (via `===` or `==`) for Objects and Arrays which only
|
||||
determines if two variables represent references to the same object instance.
|
||||
|
||||
Consider the example below where two identical `Map` instances are not
|
||||
_reference equal_ but are _value equal_.
|
||||
|
||||
```js
|
||||
// First consider:
|
||||
const obj1 = { a: 1, b: 2, c: 3 };
|
||||
const obj2 = { a: 1, b: 2, c: 3 };
|
||||
obj1 !== obj2; // two different instances are always not equal with ===
|
||||
|
||||
import { Map, is } from 'immutable';
|
||||
const map1 = Map({ a: 1, b: 2, c: 3 });
|
||||
const map2 = Map({ a: 1, b: 2, c: 3 });
|
||||
map1 !== map2; // two different instances are not reference-equal
|
||||
map1.equals(map2); // but are value-equal if they have the same values
|
||||
is(map1, map2); // alternatively can use the is() function
|
||||
```
|
||||
|
||||
Value equality allows Immutable.js collections to be used as keys in Maps or
|
||||
values in Sets, and retrieved with different but equivalent collections:
|
||||
|
||||
```js
|
||||
import { Map, Set } from 'immutable';
|
||||
const map1 = Map({ a: 1, b: 2, c: 3 });
|
||||
const map2 = Map({ a: 1, b: 2, c: 3 });
|
||||
const set = Set().add(map1);
|
||||
set.has(map2); // true because these are value-equal
|
||||
```
|
||||
|
||||
Note: `is()` uses the same measure of equality as [Object.is][] for scalar
|
||||
strings and numbers, but uses value equality for Immutable collections,
|
||||
determining if both are immutable and all keys and values are equal
|
||||
using the same measure of equality.
|
||||
|
||||
[object.is]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
|
||||
|
||||
#### Performance tradeoffs
|
||||
|
||||
While value equality is useful in many circumstances, it has different
|
||||
performance characteristics than reference equality. Understanding these
|
||||
tradeoffs may help you decide which to use in each case, especially when used
|
||||
to memoize some operation.
|
||||
|
||||
When comparing two collections, value equality may require considering every
|
||||
item in each collection, on an `O(N)` time complexity. For large collections of
|
||||
values, this could become a costly operation. Though if the two are not equal
|
||||
and hardly similar, the inequality is determined very quickly. In contrast, when
|
||||
comparing two collections with reference equality, only the initial references
|
||||
to memory need to be compared which is not based on the size of the collections,
|
||||
which has an `O(1)` time complexity. Checking reference equality is always very
|
||||
fast, however just because two collections are not reference-equal does not rule
|
||||
out the possibility that they may be value-equal.
|
||||
|
||||
#### Return self on no-op optimization
|
||||
|
||||
When possible, Immutable.js avoids creating new objects for updates where no
|
||||
change in _value_ occurred, to allow for efficient _reference equality_ checking
|
||||
to quickly determine if no change occurred.
|
||||
|
||||
```js
|
||||
import { Map } from 'immutable';
|
||||
const originalMap = Map({ a: 1, b: 2, c: 3 });
|
||||
const updatedMap = originalMap.set('b', 2);
|
||||
updatedMap === originalMap; // No-op .set() returned the original reference.
|
||||
```
|
||||
|
||||
However updates which do result in a change will return a new reference. Each
|
||||
of these operations occur independently, so two similar updates will not return
|
||||
the same reference:
|
||||
|
||||
```js
|
||||
import { Map } from 'immutable';
|
||||
const originalMap = Map({ a: 1, b: 2, c: 3 });
|
||||
const updatedMap = originalMap.set('b', 1000);
|
||||
// New instance, leaving the original immutable.
|
||||
updatedMap !== originalMap;
|
||||
const anotherUpdatedMap = originalMap.set('b', 1000);
|
||||
// Despite both the results of the same operation, each created a new reference.
|
||||
anotherUpdatedMap !== updatedMap;
|
||||
// However the two are value equal.
|
||||
anotherUpdatedMap.equals(updatedMap);
|
||||
```
|
||||
|
||||
## Batching Mutations
|
||||
|
||||
> If a tree falls in the woods, does it make a sound?
|
||||
>
|
||||
> If a pure function mutates some local data in order to produce an immutable
|
||||
> return value, is that ok?
|
||||
>
|
||||
> — Rich Hickey, Clojure
|
||||
|
||||
Applying a mutation to create a new immutable object results in some overhead,
|
||||
which can add up to a minor performance penalty. If you need to apply a series
|
||||
of mutations locally before returning, Immutable.js gives you the ability to
|
||||
create a temporary mutable (transient) copy of a collection and apply a batch of
|
||||
mutations in a performant manner by using `withMutations`. In fact, this is
|
||||
exactly how Immutable.js applies complex mutations itself.
|
||||
|
||||
As an example, building `list2` results in the creation of 1, not 3, new
|
||||
immutable Lists.
|
||||
|
||||
```js
|
||||
import { List } from 'immutable';
|
||||
const list1 = List([1, 2, 3]);
|
||||
const list2 = list1.withMutations(function (list) {
|
||||
list.push(4).push(5).push(6);
|
||||
});
|
||||
assert.equal(list1.size, 3);
|
||||
assert.equal(list2.size, 6);
|
||||
```
|
||||
|
||||
Note: Immutable.js also provides `asMutable` and `asImmutable`, but only
|
||||
encourages their use when `withMutations` will not suffice. Use caution to not
|
||||
return a mutable copy, which could result in undesired behavior.
|
||||
|
||||
_Important!_: Only a select few methods can be used in `withMutations` including
|
||||
`set`, `push` and `pop`. These methods can be applied directly against a
|
||||
persistent data-structure where other methods like `map`, `filter`, `sort`,
|
||||
and `splice` will always return new immutable data-structures and never mutate
|
||||
a mutable collection.
|
||||
|
||||
## Lazy Seq
|
||||
|
||||
`Seq` describes a lazy operation, allowing them to efficiently chain
|
||||
use of all the higher-order collection methods (such as `map` and `filter`)
|
||||
by not creating intermediate collections.
|
||||
|
||||
**Seq is immutable** — Once a Seq is created, it cannot be
|
||||
changed, appended to, rearranged or otherwise modified. Instead, any mutative
|
||||
method called on a `Seq` will return a new `Seq`.
|
||||
|
||||
**Seq is lazy** — `Seq` does as little work as necessary to respond to any
|
||||
method call. Values are often created during iteration, including implicit
|
||||
iteration when reducing or converting to a concrete data structure such as
|
||||
a `List` or JavaScript `Array`.
|
||||
|
||||
For example, the following performs no work, because the resulting
|
||||
`Seq`'s values are never iterated:
|
||||
|
||||
```js
|
||||
import { Seq } from 'immutable';
|
||||
const oddSquares = Seq([1, 2, 3, 4, 5, 6, 7, 8])
|
||||
.filter((x) => x % 2 !== 0)
|
||||
.map((x) => x * x);
|
||||
```
|
||||
|
||||
Once the `Seq` is used, it performs only the work necessary. In this
|
||||
example, no intermediate arrays are ever created, filter is called three
|
||||
times, and map is only called once:
|
||||
|
||||
```js
|
||||
oddSquares.get(1); // 9
|
||||
```
|
||||
|
||||
Any collection can be converted to a lazy Seq with `Seq()`.
|
||||
|
||||
```js
|
||||
import { Map, Seq } from 'immutable';
|
||||
const map = Map({ a: 1, b: 2, c: 3 });
|
||||
const lazySeq = Seq(map);
|
||||
```
|
||||
|
||||
`Seq` allows for the efficient chaining of operations, allowing for the
|
||||
expression of logic that can otherwise be very tedious:
|
||||
|
||||
```js
|
||||
lazySeq
|
||||
.flip()
|
||||
.map((key) => key.toUpperCase())
|
||||
.flip();
|
||||
// Seq { A: 1, B: 2, C: 3 }
|
||||
```
|
||||
|
||||
As well as expressing logic that would otherwise seem memory or time
|
||||
limited, for example `Range` is a special kind of Lazy sequence.
|
||||
|
||||
```js
|
||||
import { Range } from 'immutable';
|
||||
Range(1, Infinity)
|
||||
.skip(1000)
|
||||
.map((n) => -n)
|
||||
.filter((n) => n % 2 === 0)
|
||||
.take(2)
|
||||
.reduce((r, n) => r * n, 1);
|
||||
// 1006008
|
||||
```
|
||||
|
||||
## Comparison of filter(), groupBy(), and partition()
|
||||
|
||||
The `filter()`, `groupBy()`, and `partition()` methods are similar in that they
|
||||
all divide a collection into parts based on applying a function to each element.
|
||||
All three call the predicate or grouping function once for each item in the
|
||||
input collection. All three return zero or more collections of the same type as
|
||||
their input. The returned collections are always distinct from the input
|
||||
(according to `===`), even if the contents are identical.
|
||||
|
||||
Of these methods, `filter()` is the only one that is lazy and the only one which
|
||||
discards items from the input collection. It is the simplest to use, and the
|
||||
fact that it returns exactly one collection makes it easy to combine with other
|
||||
methods to form a pipeline of operations.
|
||||
|
||||
The `partition()` method is similar to an eager version of `filter()`, but it
|
||||
returns two collections; the first contains the items that would have been
|
||||
discarded by `filter()`, and the second contains the items that would have been
|
||||
kept. It always returns an array of exactly two collections, which can make it
|
||||
easier to use than `groupBy()`. Compared to making two separate calls to
|
||||
`filter()`, `partition()` makes half as many calls it the predicate passed to
|
||||
it.
|
||||
|
||||
The `groupBy()` method is a more generalized version of `partition()` that can
|
||||
group by an arbitrary function rather than just a predicate. It returns a map
|
||||
with zero or more entries, where the keys are the values returned by the
|
||||
grouping function, and the values are nonempty collections of the corresponding
|
||||
arguments. Although `groupBy()` is more powerful than `partition()`, it can be
|
||||
harder to use because it is not always possible predict in advance how many
|
||||
entries the returned map will have and what their keys will be.
|
||||
|
||||
| Summary | `filter` | `partition` | `groupBy` |
|
||||
| :---------------------------- | :------- | :---------- | :------------- |
|
||||
| ease of use | easiest | moderate | hardest |
|
||||
| generality | least | moderate | most |
|
||||
| laziness | lazy | eager | eager |
|
||||
| # of returned sub-collections | 1 | 2 | 0 or more |
|
||||
| sub-collections may be empty | yes | yes | no |
|
||||
| can discard items | yes | no | no |
|
||||
| wrapping container | none | array | Map/OrderedMap |
|
||||
|
||||
## Additional Tools and Resources
|
||||
|
||||
- [Atom-store](https://github.com/jameshopkins/atom-store/)
|
||||
|
||||
- A Clojure-inspired atom implementation in Javascript with configurability
|
||||
for external persistance.
|
||||
|
||||
- [Chai Immutable](https://github.com/astorije/chai-immutable)
|
||||
|
||||
- If you are using the [Chai Assertion Library](https://chaijs.com/), this
|
||||
provides a set of assertions to use against Immutable.js collections.
|
||||
|
||||
- [Fantasy-land](https://github.com/fantasyland/fantasy-land)
|
||||
|
||||
- Specification for interoperability of common algebraic structures in JavaScript.
|
||||
|
||||
- [Immutagen](https://github.com/pelotom/immutagen)
|
||||
|
||||
- A library for simulating immutable generators in JavaScript.
|
||||
|
||||
- [Immutable-cursor](https://github.com/redbadger/immutable-cursor)
|
||||
|
||||
- Immutable cursors incorporating the Immutable.js interface over
|
||||
Clojure-inspired atom.
|
||||
|
||||
- [Immutable-ext](https://github.com/DrBoolean/immutable-ext)
|
||||
|
||||
- Fantasyland extensions for immutablejs
|
||||
|
||||
- [Immutable-js-tools](https://github.com/madeinfree/immutable-js-tools)
|
||||
|
||||
- Util tools for immutable.js
|
||||
|
||||
- [Immutable-Redux](https://github.com/gajus/redux-immutable)
|
||||
|
||||
- redux-immutable is used to create an equivalent function of Redux
|
||||
combineReducers that works with Immutable.js state.
|
||||
|
||||
- [Immutable-Treeutils](https://github.com/lukasbuenger/immutable-treeutils)
|
||||
|
||||
- Functional tree traversal helpers for ImmutableJS data structures.
|
||||
|
||||
- [Irecord](https://github.com/ericelliott/irecord)
|
||||
|
||||
- An immutable store that exposes an RxJS observable. Great for React.
|
||||
|
||||
- [Mudash](https://github.com/brianneisler/mudash)
|
||||
|
||||
- Lodash wrapper providing Immutable.JS support.
|
||||
|
||||
- [React-Immutable-PropTypes](https://github.com/HurricaneJames/react-immutable-proptypes)
|
||||
|
||||
- PropType validators that work with Immutable.js.
|
||||
|
||||
- [Redux-Immutablejs](https://github.com/indexiatech/redux-immutablejs)
|
||||
|
||||
- Redux Immutable facilities.
|
||||
|
||||
- [Rxstate](https://github.com/yamalight/rxstate)
|
||||
|
||||
- Simple opinionated state management library based on RxJS and Immutable.js.
|
||||
|
||||
- [Transit-Immutable-js](https://github.com/glenjamin/transit-immutable-js)
|
||||
- Transit serialisation for Immutable.js.
|
||||
- See also: [Transit-js](https://github.com/cognitect/transit-js)
|
||||
|
||||
Have an additional tool designed to work with Immutable.js?
|
||||
Submit a PR to add it to this list in alphabetical order.
|
||||
|
||||
## Contributing
|
||||
|
||||
Use [Github issues](https://github.com/immutable-js/immutable-js/issues) for requests.
|
||||
|
||||
We actively welcome pull requests, learn how to [contribute](https://github.com/immutable-js/immutable-js/blob/main/.github/CONTRIBUTING.md).
|
||||
|
||||
Immutable.js is maintained within the [Contributor Covenant's Code of Conduct](https://www.contributor-covenant.org/version/2/0/code_of_conduct/).
|
||||
|
||||
### Changelog
|
||||
|
||||
Changes are tracked as [Github releases](https://github.com/immutable-js/immutable-js/releases).
|
||||
|
||||
### License
|
||||
|
||||
Immutable.js is [MIT-licensed](./LICENSE).
|
||||
|
||||
### Thanks
|
||||
|
||||
[Phil Bagwell](https://www.youtube.com/watch?v=K2NYwP90bNs), for his inspiration
|
||||
and research in persistent data structures.
|
||||
|
||||
[Hugh Jackson](https://github.com/hughfdjackson/), for providing the npm package
|
||||
name. If you're looking for his unsupported package, see [this repository](https://github.com/hughfdjackson/immutable).
|
||||
38
node_modules/immutable/package.json
generated
vendored
Normal file
38
node_modules/immutable/package.json
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"name": "immutable",
|
||||
"version": "5.1.3",
|
||||
"description": "Immutable Data Collections",
|
||||
"license": "MIT",
|
||||
"homepage": "https://immutable-js.com",
|
||||
"author": {
|
||||
"name": "Lee Byron",
|
||||
"url": "https://github.com/leebyron"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/immutable-js/immutable-js.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/immutable-js/immutable-js/issues"
|
||||
},
|
||||
"main": "dist/immutable.js",
|
||||
"module": "dist/immutable.es.js",
|
||||
"types": "dist/immutable.d.ts",
|
||||
"files": [
|
||||
"dist",
|
||||
"README.md",
|
||||
"LICENSE"
|
||||
],
|
||||
"keywords": [
|
||||
"immutable",
|
||||
"persistent",
|
||||
"lazy",
|
||||
"data",
|
||||
"datastructure",
|
||||
"functional",
|
||||
"collection",
|
||||
"stateless",
|
||||
"sequence",
|
||||
"iteration"
|
||||
]
|
||||
}
|
||||
21
node_modules/is-extglob/LICENSE
generated
vendored
Normal file
21
node_modules/is-extglob/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014-2016, Jon Schlinkert
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
107
node_modules/is-extglob/README.md
generated
vendored
Normal file
107
node_modules/is-extglob/README.md
generated
vendored
Normal file
@@ -0,0 +1,107 @@
|
||||
# is-extglob [](https://www.npmjs.com/package/is-extglob) [](https://npmjs.org/package/is-extglob) [](https://travis-ci.org/jonschlinkert/is-extglob)
|
||||
|
||||
> Returns true if a string has an extglob.
|
||||
|
||||
## Install
|
||||
|
||||
Install with [npm](https://www.npmjs.com/):
|
||||
|
||||
```sh
|
||||
$ npm install --save is-extglob
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
var isExtglob = require('is-extglob');
|
||||
```
|
||||
|
||||
**True**
|
||||
|
||||
```js
|
||||
isExtglob('?(abc)');
|
||||
isExtglob('@(abc)');
|
||||
isExtglob('!(abc)');
|
||||
isExtglob('*(abc)');
|
||||
isExtglob('+(abc)');
|
||||
```
|
||||
|
||||
**False**
|
||||
|
||||
Escaped extglobs:
|
||||
|
||||
```js
|
||||
isExtglob('\\?(abc)');
|
||||
isExtglob('\\@(abc)');
|
||||
isExtglob('\\!(abc)');
|
||||
isExtglob('\\*(abc)');
|
||||
isExtglob('\\+(abc)');
|
||||
```
|
||||
|
||||
Everything else...
|
||||
|
||||
```js
|
||||
isExtglob('foo.js');
|
||||
isExtglob('!foo.js');
|
||||
isExtglob('*.js');
|
||||
isExtglob('**/abc.js');
|
||||
isExtglob('abc/*.js');
|
||||
isExtglob('abc/(aaa|bbb).js');
|
||||
isExtglob('abc/[a-z].js');
|
||||
isExtglob('abc/{a,b}.js');
|
||||
isExtglob('abc/?.js');
|
||||
isExtglob('abc.js');
|
||||
isExtglob('abc/def/ghi.js');
|
||||
```
|
||||
|
||||
## History
|
||||
|
||||
**v2.0**
|
||||
|
||||
Adds support for escaping. Escaped exglobs no longer return true.
|
||||
|
||||
## About
|
||||
|
||||
### Related projects
|
||||
|
||||
* [has-glob](https://www.npmjs.com/package/has-glob): Returns `true` if an array has a glob pattern. | [homepage](https://github.com/jonschlinkert/has-glob "Returns `true` if an array has a glob pattern.")
|
||||
* [is-glob](https://www.npmjs.com/package/is-glob): Returns `true` if the given string looks like a glob pattern or an extglob pattern… [more](https://github.com/jonschlinkert/is-glob) | [homepage](https://github.com/jonschlinkert/is-glob "Returns `true` if the given string looks like a glob pattern or an extglob pattern. This makes it easy to create code that only uses external modules like node-glob when necessary, resulting in much faster code execution and initialization time, and a bet")
|
||||
* [micromatch](https://www.npmjs.com/package/micromatch): Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch and multimatch. | [homepage](https://github.com/jonschlinkert/micromatch "Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch and multimatch.")
|
||||
|
||||
### Contributing
|
||||
|
||||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
|
||||
|
||||
### Building docs
|
||||
|
||||
_(This document was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme) (a [verb](https://github.com/verbose/verb) generator), please don't edit the readme directly. Any changes to the readme must be made in [.verb.md](.verb.md).)_
|
||||
|
||||
To generate the readme and API documentation with [verb](https://github.com/verbose/verb):
|
||||
|
||||
```sh
|
||||
$ npm install -g verb verb-generate-readme && verb
|
||||
```
|
||||
|
||||
### Running tests
|
||||
|
||||
Install dev dependencies:
|
||||
|
||||
```sh
|
||||
$ npm install -d && npm test
|
||||
```
|
||||
|
||||
### Author
|
||||
|
||||
**Jon Schlinkert**
|
||||
|
||||
* [github/jonschlinkert](https://github.com/jonschlinkert)
|
||||
* [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
|
||||
|
||||
### License
|
||||
|
||||
Copyright © 2016, [Jon Schlinkert](https://github.com/jonschlinkert).
|
||||
Released under the [MIT license](https://github.com/jonschlinkert/is-extglob/blob/master/LICENSE).
|
||||
|
||||
***
|
||||
|
||||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.1.31, on October 12, 2016._
|
||||
20
node_modules/is-extglob/index.js
generated
vendored
Normal file
20
node_modules/is-extglob/index.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
/*!
|
||||
* is-extglob <https://github.com/jonschlinkert/is-extglob>
|
||||
*
|
||||
* Copyright (c) 2014-2016, Jon Schlinkert.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
module.exports = function isExtglob(str) {
|
||||
if (typeof str !== 'string' || str === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
var match;
|
||||
while ((match = /(\\).|([@?!+*]\(.*\))/g.exec(str))) {
|
||||
if (match[2]) return true;
|
||||
str = str.slice(match.index + match[0].length);
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
69
node_modules/is-extglob/package.json
generated
vendored
Normal file
69
node_modules/is-extglob/package.json
generated
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
{
|
||||
"name": "is-extglob",
|
||||
"description": "Returns true if a string has an extglob.",
|
||||
"version": "2.1.1",
|
||||
"homepage": "https://github.com/jonschlinkert/is-extglob",
|
||||
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
|
||||
"repository": "jonschlinkert/is-extglob",
|
||||
"bugs": {
|
||||
"url": "https://github.com/jonschlinkert/is-extglob/issues"
|
||||
},
|
||||
"license": "MIT",
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"main": "index.js",
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha"
|
||||
},
|
||||
"devDependencies": {
|
||||
"gulp-format-md": "^0.1.10",
|
||||
"mocha": "^3.0.2"
|
||||
},
|
||||
"keywords": [
|
||||
"bash",
|
||||
"braces",
|
||||
"check",
|
||||
"exec",
|
||||
"expression",
|
||||
"extglob",
|
||||
"glob",
|
||||
"globbing",
|
||||
"globstar",
|
||||
"is",
|
||||
"match",
|
||||
"matches",
|
||||
"pattern",
|
||||
"regex",
|
||||
"regular",
|
||||
"string",
|
||||
"test"
|
||||
],
|
||||
"verb": {
|
||||
"toc": false,
|
||||
"layout": "default",
|
||||
"tasks": [
|
||||
"readme"
|
||||
],
|
||||
"plugins": [
|
||||
"gulp-format-md"
|
||||
],
|
||||
"related": {
|
||||
"list": [
|
||||
"has-glob",
|
||||
"is-glob",
|
||||
"micromatch"
|
||||
]
|
||||
},
|
||||
"reflinks": [
|
||||
"verb",
|
||||
"verb-generate-readme"
|
||||
],
|
||||
"lint": {
|
||||
"reflinks": true
|
||||
}
|
||||
}
|
||||
}
|
||||
21
node_modules/is-glob/LICENSE
generated
vendored
Normal file
21
node_modules/is-glob/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014-2017, Jon Schlinkert.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
206
node_modules/is-glob/README.md
generated
vendored
Normal file
206
node_modules/is-glob/README.md
generated
vendored
Normal file
@@ -0,0 +1,206 @@
|
||||
# is-glob [](https://www.npmjs.com/package/is-glob) [](https://npmjs.org/package/is-glob) [](https://npmjs.org/package/is-glob) [](https://github.com/micromatch/is-glob/actions)
|
||||
|
||||
> Returns `true` if the given string looks like a glob pattern or an extglob pattern. This makes it easy to create code that only uses external modules like node-glob when necessary, resulting in much faster code execution and initialization time, and a better user experience.
|
||||
|
||||
Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.
|
||||
|
||||
## Install
|
||||
|
||||
Install with [npm](https://www.npmjs.com/):
|
||||
|
||||
```sh
|
||||
$ npm install --save is-glob
|
||||
```
|
||||
|
||||
You might also be interested in [is-valid-glob](https://github.com/jonschlinkert/is-valid-glob) and [has-glob](https://github.com/jonschlinkert/has-glob).
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
var isGlob = require('is-glob');
|
||||
```
|
||||
|
||||
### Default behavior
|
||||
|
||||
**True**
|
||||
|
||||
Patterns that have glob characters or regex patterns will return `true`:
|
||||
|
||||
```js
|
||||
isGlob('!foo.js');
|
||||
isGlob('*.js');
|
||||
isGlob('**/abc.js');
|
||||
isGlob('abc/*.js');
|
||||
isGlob('abc/(aaa|bbb).js');
|
||||
isGlob('abc/[a-z].js');
|
||||
isGlob('abc/{a,b}.js');
|
||||
//=> true
|
||||
```
|
||||
|
||||
Extglobs
|
||||
|
||||
```js
|
||||
isGlob('abc/@(a).js');
|
||||
isGlob('abc/!(a).js');
|
||||
isGlob('abc/+(a).js');
|
||||
isGlob('abc/*(a).js');
|
||||
isGlob('abc/?(a).js');
|
||||
//=> true
|
||||
```
|
||||
|
||||
**False**
|
||||
|
||||
Escaped globs or extglobs return `false`:
|
||||
|
||||
```js
|
||||
isGlob('abc/\\@(a).js');
|
||||
isGlob('abc/\\!(a).js');
|
||||
isGlob('abc/\\+(a).js');
|
||||
isGlob('abc/\\*(a).js');
|
||||
isGlob('abc/\\?(a).js');
|
||||
isGlob('\\!foo.js');
|
||||
isGlob('\\*.js');
|
||||
isGlob('\\*\\*/abc.js');
|
||||
isGlob('abc/\\*.js');
|
||||
isGlob('abc/\\(aaa|bbb).js');
|
||||
isGlob('abc/\\[a-z].js');
|
||||
isGlob('abc/\\{a,b}.js');
|
||||
//=> false
|
||||
```
|
||||
|
||||
Patterns that do not have glob patterns return `false`:
|
||||
|
||||
```js
|
||||
isGlob('abc.js');
|
||||
isGlob('abc/def/ghi.js');
|
||||
isGlob('foo.js');
|
||||
isGlob('abc/@.js');
|
||||
isGlob('abc/+.js');
|
||||
isGlob('abc/?.js');
|
||||
isGlob();
|
||||
isGlob(null);
|
||||
//=> false
|
||||
```
|
||||
|
||||
Arrays are also `false` (If you want to check if an array has a glob pattern, use [has-glob](https://github.com/jonschlinkert/has-glob)):
|
||||
|
||||
```js
|
||||
isGlob(['**/*.js']);
|
||||
isGlob(['foo.js']);
|
||||
//=> false
|
||||
```
|
||||
|
||||
### Option strict
|
||||
|
||||
When `options.strict === false` the behavior is less strict in determining if a pattern is a glob. Meaning that
|
||||
some patterns that would return `false` may return `true`. This is done so that matching libraries like [micromatch](https://github.com/micromatch/micromatch) have a chance at determining if the pattern is a glob or not.
|
||||
|
||||
**True**
|
||||
|
||||
Patterns that have glob characters or regex patterns will return `true`:
|
||||
|
||||
```js
|
||||
isGlob('!foo.js', {strict: false});
|
||||
isGlob('*.js', {strict: false});
|
||||
isGlob('**/abc.js', {strict: false});
|
||||
isGlob('abc/*.js', {strict: false});
|
||||
isGlob('abc/(aaa|bbb).js', {strict: false});
|
||||
isGlob('abc/[a-z].js', {strict: false});
|
||||
isGlob('abc/{a,b}.js', {strict: false});
|
||||
//=> true
|
||||
```
|
||||
|
||||
Extglobs
|
||||
|
||||
```js
|
||||
isGlob('abc/@(a).js', {strict: false});
|
||||
isGlob('abc/!(a).js', {strict: false});
|
||||
isGlob('abc/+(a).js', {strict: false});
|
||||
isGlob('abc/*(a).js', {strict: false});
|
||||
isGlob('abc/?(a).js', {strict: false});
|
||||
//=> true
|
||||
```
|
||||
|
||||
**False**
|
||||
|
||||
Escaped globs or extglobs return `false`:
|
||||
|
||||
```js
|
||||
isGlob('\\!foo.js', {strict: false});
|
||||
isGlob('\\*.js', {strict: false});
|
||||
isGlob('\\*\\*/abc.js', {strict: false});
|
||||
isGlob('abc/\\*.js', {strict: false});
|
||||
isGlob('abc/\\(aaa|bbb).js', {strict: false});
|
||||
isGlob('abc/\\[a-z].js', {strict: false});
|
||||
isGlob('abc/\\{a,b}.js', {strict: false});
|
||||
//=> false
|
||||
```
|
||||
|
||||
## About
|
||||
|
||||
<details>
|
||||
<summary><strong>Contributing</strong></summary>
|
||||
|
||||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><strong>Running Tests</strong></summary>
|
||||
|
||||
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
|
||||
|
||||
```sh
|
||||
$ npm install && npm test
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><strong>Building docs</strong></summary>
|
||||
|
||||
_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
|
||||
|
||||
To generate the readme, run the following command:
|
||||
|
||||
```sh
|
||||
$ npm install -g verbose/verb#dev verb-generate-readme && verb
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
### Related projects
|
||||
|
||||
You might also be interested in these projects:
|
||||
|
||||
* [assemble](https://www.npmjs.com/package/assemble): Get the rocks out of your socks! Assemble makes you fast at creating web projects… [more](https://github.com/assemble/assemble) | [homepage](https://github.com/assemble/assemble "Get the rocks out of your socks! Assemble makes you fast at creating web projects. Assemble is used by thousands of projects for rapid prototyping, creating themes, scaffolds, boilerplates, e-books, UI components, API documentation, blogs, building websit")
|
||||
* [base](https://www.npmjs.com/package/base): Framework for rapidly creating high quality, server-side node.js applications, using plugins like building blocks | [homepage](https://github.com/node-base/base "Framework for rapidly creating high quality, server-side node.js applications, using plugins like building blocks")
|
||||
* [update](https://www.npmjs.com/package/update): Be scalable! Update is a new, open source developer framework and CLI for automating updates… [more](https://github.com/update/update) | [homepage](https://github.com/update/update "Be scalable! Update is a new, open source developer framework and CLI for automating updates of any kind in code projects.")
|
||||
* [verb](https://www.npmjs.com/package/verb): Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used… [more](https://github.com/verbose/verb) | [homepage](https://github.com/verbose/verb "Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used on hundreds of projects of all sizes to generate everything from API docs to readmes.")
|
||||
|
||||
### Contributors
|
||||
|
||||
| **Commits** | **Contributor** |
|
||||
| --- | --- |
|
||||
| 47 | [jonschlinkert](https://github.com/jonschlinkert) |
|
||||
| 5 | [doowb](https://github.com/doowb) |
|
||||
| 1 | [phated](https://github.com/phated) |
|
||||
| 1 | [danhper](https://github.com/danhper) |
|
||||
| 1 | [paulmillr](https://github.com/paulmillr) |
|
||||
|
||||
### Author
|
||||
|
||||
**Jon Schlinkert**
|
||||
|
||||
* [GitHub Profile](https://github.com/jonschlinkert)
|
||||
* [Twitter Profile](https://twitter.com/jonschlinkert)
|
||||
* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)
|
||||
|
||||
### License
|
||||
|
||||
Copyright © 2019, [Jon Schlinkert](https://github.com/jonschlinkert).
|
||||
Released under the [MIT License](LICENSE).
|
||||
|
||||
***
|
||||
|
||||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on March 27, 2019._
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user