almostnode 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +731 -0
- package/dist/__sw__.js +394 -0
- package/dist/ai-chatbot-demo-entry.d.ts +6 -0
- package/dist/ai-chatbot-demo-entry.d.ts.map +1 -0
- package/dist/ai-chatbot-demo.d.ts +42 -0
- package/dist/ai-chatbot-demo.d.ts.map +1 -0
- package/dist/assets/runtime-worker-D9x_Ddwz.js +60543 -0
- package/dist/assets/runtime-worker-D9x_Ddwz.js.map +1 -0
- package/dist/convex-app-demo-entry.d.ts +6 -0
- package/dist/convex-app-demo-entry.d.ts.map +1 -0
- package/dist/convex-app-demo.d.ts +68 -0
- package/dist/convex-app-demo.d.ts.map +1 -0
- package/dist/cors-proxy.d.ts +46 -0
- package/dist/cors-proxy.d.ts.map +1 -0
- package/dist/create-runtime.d.ts +42 -0
- package/dist/create-runtime.d.ts.map +1 -0
- package/dist/demo.d.ts +6 -0
- package/dist/demo.d.ts.map +1 -0
- package/dist/dev-server.d.ts +97 -0
- package/dist/dev-server.d.ts.map +1 -0
- package/dist/frameworks/next-dev-server.d.ts +202 -0
- package/dist/frameworks/next-dev-server.d.ts.map +1 -0
- package/dist/frameworks/vite-dev-server.d.ts +85 -0
- package/dist/frameworks/vite-dev-server.d.ts.map +1 -0
- package/dist/index.cjs +14965 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +71 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +14867 -0
- package/dist/index.mjs.map +1 -0
- package/dist/next-demo.d.ts +49 -0
- package/dist/next-demo.d.ts.map +1 -0
- package/dist/npm/index.d.ts +71 -0
- package/dist/npm/index.d.ts.map +1 -0
- package/dist/npm/registry.d.ts +66 -0
- package/dist/npm/registry.d.ts.map +1 -0
- package/dist/npm/resolver.d.ts +52 -0
- package/dist/npm/resolver.d.ts.map +1 -0
- package/dist/npm/tarball.d.ts +29 -0
- package/dist/npm/tarball.d.ts.map +1 -0
- package/dist/runtime-interface.d.ts +90 -0
- package/dist/runtime-interface.d.ts.map +1 -0
- package/dist/runtime.d.ts +103 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/sandbox-helpers.d.ts +43 -0
- package/dist/sandbox-helpers.d.ts.map +1 -0
- package/dist/sandbox-runtime.d.ts +65 -0
- package/dist/sandbox-runtime.d.ts.map +1 -0
- package/dist/server-bridge.d.ts +89 -0
- package/dist/server-bridge.d.ts.map +1 -0
- package/dist/shims/assert.d.ts +51 -0
- package/dist/shims/assert.d.ts.map +1 -0
- package/dist/shims/async_hooks.d.ts +37 -0
- package/dist/shims/async_hooks.d.ts.map +1 -0
- package/dist/shims/buffer.d.ts +20 -0
- package/dist/shims/buffer.d.ts.map +1 -0
- package/dist/shims/child_process-browser.d.ts +92 -0
- package/dist/shims/child_process-browser.d.ts.map +1 -0
- package/dist/shims/child_process.d.ts +93 -0
- package/dist/shims/child_process.d.ts.map +1 -0
- package/dist/shims/chokidar.d.ts +55 -0
- package/dist/shims/chokidar.d.ts.map +1 -0
- package/dist/shims/cluster.d.ts +52 -0
- package/dist/shims/cluster.d.ts.map +1 -0
- package/dist/shims/crypto.d.ts +122 -0
- package/dist/shims/crypto.d.ts.map +1 -0
- package/dist/shims/dgram.d.ts +34 -0
- package/dist/shims/dgram.d.ts.map +1 -0
- package/dist/shims/diagnostics_channel.d.ts +80 -0
- package/dist/shims/diagnostics_channel.d.ts.map +1 -0
- package/dist/shims/dns.d.ts +87 -0
- package/dist/shims/dns.d.ts.map +1 -0
- package/dist/shims/domain.d.ts +25 -0
- package/dist/shims/domain.d.ts.map +1 -0
- package/dist/shims/esbuild.d.ts +105 -0
- package/dist/shims/esbuild.d.ts.map +1 -0
- package/dist/shims/events.d.ts +37 -0
- package/dist/shims/events.d.ts.map +1 -0
- package/dist/shims/fs.d.ts +115 -0
- package/dist/shims/fs.d.ts.map +1 -0
- package/dist/shims/fsevents.d.ts +67 -0
- package/dist/shims/fsevents.d.ts.map +1 -0
- package/dist/shims/http.d.ts +217 -0
- package/dist/shims/http.d.ts.map +1 -0
- package/dist/shims/http2.d.ts +81 -0
- package/dist/shims/http2.d.ts.map +1 -0
- package/dist/shims/https.d.ts +36 -0
- package/dist/shims/https.d.ts.map +1 -0
- package/dist/shims/inspector.d.ts +25 -0
- package/dist/shims/inspector.d.ts.map +1 -0
- package/dist/shims/module.d.ts +22 -0
- package/dist/shims/module.d.ts.map +1 -0
- package/dist/shims/net.d.ts +100 -0
- package/dist/shims/net.d.ts.map +1 -0
- package/dist/shims/os.d.ts +159 -0
- package/dist/shims/os.d.ts.map +1 -0
- package/dist/shims/path.d.ts +72 -0
- package/dist/shims/path.d.ts.map +1 -0
- package/dist/shims/perf_hooks.d.ts +50 -0
- package/dist/shims/perf_hooks.d.ts.map +1 -0
- package/dist/shims/process.d.ts +93 -0
- package/dist/shims/process.d.ts.map +1 -0
- package/dist/shims/querystring.d.ts +23 -0
- package/dist/shims/querystring.d.ts.map +1 -0
- package/dist/shims/readdirp.d.ts +52 -0
- package/dist/shims/readdirp.d.ts.map +1 -0
- package/dist/shims/readline.d.ts +62 -0
- package/dist/shims/readline.d.ts.map +1 -0
- package/dist/shims/rollup.d.ts +34 -0
- package/dist/shims/rollup.d.ts.map +1 -0
- package/dist/shims/sentry.d.ts +163 -0
- package/dist/shims/sentry.d.ts.map +1 -0
- package/dist/shims/stream.d.ts +181 -0
- package/dist/shims/stream.d.ts.map +1 -0
- package/dist/shims/tls.d.ts +53 -0
- package/dist/shims/tls.d.ts.map +1 -0
- package/dist/shims/tty.d.ts +30 -0
- package/dist/shims/tty.d.ts.map +1 -0
- package/dist/shims/url.d.ts +64 -0
- package/dist/shims/url.d.ts.map +1 -0
- package/dist/shims/util.d.ts +106 -0
- package/dist/shims/util.d.ts.map +1 -0
- package/dist/shims/v8.d.ts +73 -0
- package/dist/shims/v8.d.ts.map +1 -0
- package/dist/shims/vfs-adapter.d.ts +126 -0
- package/dist/shims/vfs-adapter.d.ts.map +1 -0
- package/dist/shims/vm.d.ts +45 -0
- package/dist/shims/vm.d.ts.map +1 -0
- package/dist/shims/worker_threads.d.ts +66 -0
- package/dist/shims/worker_threads.d.ts.map +1 -0
- package/dist/shims/ws.d.ts +66 -0
- package/dist/shims/ws.d.ts.map +1 -0
- package/dist/shims/zlib.d.ts +161 -0
- package/dist/shims/zlib.d.ts.map +1 -0
- package/dist/transform.d.ts +24 -0
- package/dist/transform.d.ts.map +1 -0
- package/dist/virtual-fs.d.ts +226 -0
- package/dist/virtual-fs.d.ts.map +1 -0
- package/dist/vite-demo.d.ts +35 -0
- package/dist/vite-demo.d.ts.map +1 -0
- package/dist/vite-sw.js +132 -0
- package/dist/worker/runtime-worker.d.ts +8 -0
- package/dist/worker/runtime-worker.d.ts.map +1 -0
- package/dist/worker-runtime.d.ts +50 -0
- package/dist/worker-runtime.d.ts.map +1 -0
- package/package.json +85 -0
- package/src/ai-chatbot-demo-entry.ts +244 -0
- package/src/ai-chatbot-demo.ts +509 -0
- package/src/convex-app-demo-entry.ts +1107 -0
- package/src/convex-app-demo.ts +1316 -0
- package/src/cors-proxy.ts +81 -0
- package/src/create-runtime.ts +147 -0
- package/src/demo.ts +304 -0
- package/src/dev-server.ts +274 -0
- package/src/frameworks/next-dev-server.ts +2224 -0
- package/src/frameworks/vite-dev-server.ts +702 -0
- package/src/index.ts +101 -0
- package/src/next-demo.ts +1784 -0
- package/src/npm/index.ts +347 -0
- package/src/npm/registry.ts +152 -0
- package/src/npm/resolver.ts +385 -0
- package/src/npm/tarball.ts +209 -0
- package/src/runtime-interface.ts +103 -0
- package/src/runtime.ts +1046 -0
- package/src/sandbox-helpers.ts +173 -0
- package/src/sandbox-runtime.ts +252 -0
- package/src/server-bridge.ts +426 -0
- package/src/shims/assert.ts +664 -0
- package/src/shims/async_hooks.ts +86 -0
- package/src/shims/buffer.ts +75 -0
- package/src/shims/child_process-browser.ts +217 -0
- package/src/shims/child_process.ts +463 -0
- package/src/shims/chokidar.ts +313 -0
- package/src/shims/cluster.ts +67 -0
- package/src/shims/crypto.ts +830 -0
- package/src/shims/dgram.ts +47 -0
- package/src/shims/diagnostics_channel.ts +196 -0
- package/src/shims/dns.ts +172 -0
- package/src/shims/domain.ts +58 -0
- package/src/shims/esbuild.ts +805 -0
- package/src/shims/events.ts +195 -0
- package/src/shims/fs.ts +803 -0
- package/src/shims/fsevents.ts +63 -0
- package/src/shims/http.ts +904 -0
- package/src/shims/http2.ts +96 -0
- package/src/shims/https.ts +86 -0
- package/src/shims/inspector.ts +30 -0
- package/src/shims/module.ts +82 -0
- package/src/shims/net.ts +359 -0
- package/src/shims/os.ts +195 -0
- package/src/shims/path.ts +199 -0
- package/src/shims/perf_hooks.ts +92 -0
- package/src/shims/process.ts +346 -0
- package/src/shims/querystring.ts +97 -0
- package/src/shims/readdirp.ts +228 -0
- package/src/shims/readline.ts +110 -0
- package/src/shims/rollup.ts +80 -0
- package/src/shims/sentry.ts +133 -0
- package/src/shims/stream.ts +1126 -0
- package/src/shims/tls.ts +95 -0
- package/src/shims/tty.ts +64 -0
- package/src/shims/url.ts +171 -0
- package/src/shims/util.ts +312 -0
- package/src/shims/v8.ts +113 -0
- package/src/shims/vfs-adapter.ts +402 -0
- package/src/shims/vm.ts +83 -0
- package/src/shims/worker_threads.ts +111 -0
- package/src/shims/ws.ts +382 -0
- package/src/shims/zlib.ts +289 -0
- package/src/transform.ts +313 -0
- package/src/types/external.d.ts +67 -0
- package/src/virtual-fs.ts +903 -0
- package/src/vite-demo.ts +577 -0
- package/src/worker/runtime-worker.ts +128 -0
- package/src/worker-runtime.ts +145 -0
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* chokidar shim - File watcher library used by Vite
|
|
3
|
+
* Wraps our VirtualFS watch implementation
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { EventEmitter } from './events';
|
|
7
|
+
import type { VirtualFS, FSWatcher as VFSWatcher, Stats } from '../virtual-fs';
|
|
8
|
+
|
|
9
|
+
// Global reference to VFS - set by runtime
|
|
10
|
+
let globalVFS: VirtualFS | null = null;
|
|
11
|
+
|
|
12
|
+
export function setVFS(vfs: VirtualFS): void {
|
|
13
|
+
globalVFS = vfs;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface ChokidarOptions {
|
|
17
|
+
persistent?: boolean;
|
|
18
|
+
ignored?: string | RegExp | ((path: string) => boolean) | Array<string | RegExp | ((path: string) => boolean)>;
|
|
19
|
+
ignoreInitial?: boolean;
|
|
20
|
+
followSymlinks?: boolean;
|
|
21
|
+
cwd?: string;
|
|
22
|
+
disableGlobbing?: boolean;
|
|
23
|
+
usePolling?: boolean;
|
|
24
|
+
interval?: number;
|
|
25
|
+
binaryInterval?: number;
|
|
26
|
+
alwaysStat?: boolean;
|
|
27
|
+
depth?: number;
|
|
28
|
+
awaitWriteFinish?: boolean | { stabilityThreshold?: number; pollInterval?: number };
|
|
29
|
+
ignorePermissionErrors?: boolean;
|
|
30
|
+
atomic?: boolean | number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export class FSWatcher extends EventEmitter {
|
|
34
|
+
private vfs: VirtualFS;
|
|
35
|
+
private watched = new Map<string, VFSWatcher>();
|
|
36
|
+
private options: ChokidarOptions;
|
|
37
|
+
private closed = false;
|
|
38
|
+
private ready = false;
|
|
39
|
+
private _eventCounts?: Map<string, number>;
|
|
40
|
+
|
|
41
|
+
constructor(options: ChokidarOptions = {}) {
|
|
42
|
+
super();
|
|
43
|
+
if (!globalVFS) {
|
|
44
|
+
throw new Error('chokidar: VirtualFS not initialized. Call setVFS first.');
|
|
45
|
+
}
|
|
46
|
+
this.vfs = globalVFS;
|
|
47
|
+
this.options = options;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
private shouldIgnore(path: string): boolean {
|
|
51
|
+
const { ignored } = this.options;
|
|
52
|
+
if (!ignored) return false;
|
|
53
|
+
|
|
54
|
+
const ignoreList = Array.isArray(ignored) ? ignored : [ignored];
|
|
55
|
+
|
|
56
|
+
for (const pattern of ignoreList) {
|
|
57
|
+
if (typeof pattern === 'string') {
|
|
58
|
+
if (path === pattern || path.startsWith(pattern + '/')) return true;
|
|
59
|
+
} else if (pattern instanceof RegExp) {
|
|
60
|
+
if (pattern.test(path)) return true;
|
|
61
|
+
} else if (typeof pattern === 'function') {
|
|
62
|
+
if (pattern(path)) return true;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
private normalizePath(path: string): string {
|
|
70
|
+
// Apply cwd if set
|
|
71
|
+
if (this.options.cwd && !path.startsWith('/')) {
|
|
72
|
+
path = this.options.cwd + '/' + path;
|
|
73
|
+
}
|
|
74
|
+
// Normalize path
|
|
75
|
+
if (!path.startsWith('/')) {
|
|
76
|
+
path = '/' + path;
|
|
77
|
+
}
|
|
78
|
+
return path;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
add(paths: string | readonly string[]): this {
|
|
82
|
+
if (this.closed) return this;
|
|
83
|
+
|
|
84
|
+
const pathArray = Array.isArray(paths) ? paths : [paths];
|
|
85
|
+
const pendingEmits: Array<() => void> = [];
|
|
86
|
+
console.log('[chokidar] add:', pathArray);
|
|
87
|
+
|
|
88
|
+
for (const p of pathArray) {
|
|
89
|
+
const normalized = this.normalizePath(p);
|
|
90
|
+
|
|
91
|
+
if (this.shouldIgnore(normalized)) continue;
|
|
92
|
+
if (this.watched.has(normalized)) continue;
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
// Check if path exists
|
|
96
|
+
if (!this.vfs.existsSync(normalized)) {
|
|
97
|
+
// Path doesn't exist yet - that's ok, we'll watch the parent
|
|
98
|
+
const parentPath = normalized.substring(0, normalized.lastIndexOf('/')) || '/';
|
|
99
|
+
if (this.vfs.existsSync(parentPath)) {
|
|
100
|
+
this.watchPath(parentPath, normalized);
|
|
101
|
+
}
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const stats = this.vfs.statSync(normalized);
|
|
106
|
+
|
|
107
|
+
// Emit initial 'add' events unless ignoreInitial is set
|
|
108
|
+
if (!this.options.ignoreInitial) {
|
|
109
|
+
if (stats.isDirectory()) {
|
|
110
|
+
this.collectDirContents(normalized, pendingEmits);
|
|
111
|
+
} else {
|
|
112
|
+
pendingEmits.push(() => this.emit('add', normalized, stats));
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Set up watching
|
|
117
|
+
this.watchPath(normalized);
|
|
118
|
+
|
|
119
|
+
// If directory, also watch contents recursively
|
|
120
|
+
if (stats.isDirectory()) {
|
|
121
|
+
this.watchDirRecursive(normalized);
|
|
122
|
+
}
|
|
123
|
+
} catch (err) {
|
|
124
|
+
this.emit('error', err);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Emit ready event and initial add events asynchronously
|
|
129
|
+
// so listeners can be attached after watch() is called
|
|
130
|
+
if (!this.ready) {
|
|
131
|
+
this.ready = true;
|
|
132
|
+
setTimeout(() => {
|
|
133
|
+
for (const emitFn of pendingEmits) {
|
|
134
|
+
emitFn();
|
|
135
|
+
}
|
|
136
|
+
this.emit('ready');
|
|
137
|
+
}, 0);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return this;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
private collectDirContents(dirPath: string, pendingEmits: Array<() => void>): void {
|
|
144
|
+
try {
|
|
145
|
+
const entries = this.vfs.readdirSync(dirPath);
|
|
146
|
+
for (const entry of entries) {
|
|
147
|
+
const fullPath = dirPath === '/' ? '/' + entry : dirPath + '/' + entry;
|
|
148
|
+
if (this.shouldIgnore(fullPath)) continue;
|
|
149
|
+
|
|
150
|
+
const stats = this.vfs.statSync(fullPath);
|
|
151
|
+
if (stats.isDirectory()) {
|
|
152
|
+
pendingEmits.push(() => this.emit('addDir', fullPath, stats));
|
|
153
|
+
this.collectDirContents(fullPath, pendingEmits);
|
|
154
|
+
} else {
|
|
155
|
+
pendingEmits.push(() => this.emit('add', fullPath, stats));
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
} catch {
|
|
159
|
+
// Ignore errors during initial scan
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
private watchPath(path: string, watchFor?: string): void {
|
|
164
|
+
if (this.watched.has(path)) return;
|
|
165
|
+
|
|
166
|
+
const watcher = this.vfs.watch(path, { recursive: true }, (eventType, filename) => {
|
|
167
|
+
if (this.closed) return;
|
|
168
|
+
|
|
169
|
+
let fullPath: string;
|
|
170
|
+
if (filename) {
|
|
171
|
+
fullPath = path === '/' ? '/' + filename : path + '/' + filename;
|
|
172
|
+
} else {
|
|
173
|
+
fullPath = path;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Debug: Track watch events per path to detect infinite loops
|
|
177
|
+
const eventKey = `${eventType}:${fullPath}`;
|
|
178
|
+
if (!this._eventCounts) this._eventCounts = new Map<string, number>();
|
|
179
|
+
const count = (this._eventCounts.get(eventKey) || 0) + 1;
|
|
180
|
+
this._eventCounts.set(eventKey, count);
|
|
181
|
+
if (count === 5) {
|
|
182
|
+
console.warn(`[chokidar] Repeated event: ${eventType} on ${fullPath} (${count}+ times)`);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
console.log('[chokidar] event:', eventType, fullPath);
|
|
186
|
+
|
|
187
|
+
// If we're watching for a specific path, only emit for that
|
|
188
|
+
if (watchFor && fullPath !== watchFor && !fullPath.startsWith(watchFor + '/')) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (this.shouldIgnore(fullPath)) {
|
|
193
|
+
console.log('[chokidar] ignored:', fullPath);
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (eventType === 'rename') {
|
|
198
|
+
// File was added or removed
|
|
199
|
+
if (this.vfs.existsSync(fullPath)) {
|
|
200
|
+
try {
|
|
201
|
+
const stats = this.vfs.statSync(fullPath);
|
|
202
|
+
if (stats.isDirectory()) {
|
|
203
|
+
console.log('[chokidar] emit addDir:', fullPath);
|
|
204
|
+
this.emit('addDir', fullPath, stats);
|
|
205
|
+
} else {
|
|
206
|
+
console.log('[chokidar] emit add:', fullPath);
|
|
207
|
+
this.emit('add', fullPath, stats);
|
|
208
|
+
}
|
|
209
|
+
} catch {
|
|
210
|
+
// Race condition - file may have been deleted
|
|
211
|
+
}
|
|
212
|
+
} else {
|
|
213
|
+
console.log('[chokidar] emit unlink:', fullPath);
|
|
214
|
+
this.emit('unlink', fullPath);
|
|
215
|
+
}
|
|
216
|
+
} else if (eventType === 'change') {
|
|
217
|
+
// File was modified
|
|
218
|
+
try {
|
|
219
|
+
const stats = this.vfs.statSync(fullPath);
|
|
220
|
+
console.log('[chokidar] emit change:', fullPath);
|
|
221
|
+
this.emit('change', fullPath, stats);
|
|
222
|
+
} catch {
|
|
223
|
+
// File may have been deleted
|
|
224
|
+
this.emit('unlink', fullPath);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
this.watched.set(path, watcher);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
private watchDirRecursive(dirPath: string, depth = 0): void {
|
|
233
|
+
if (this.options.depth !== undefined && depth > this.options.depth) return;
|
|
234
|
+
|
|
235
|
+
try {
|
|
236
|
+
const entries = this.vfs.readdirSync(dirPath);
|
|
237
|
+
for (const entry of entries) {
|
|
238
|
+
const fullPath = dirPath === '/' ? '/' + entry : dirPath + '/' + entry;
|
|
239
|
+
if (this.shouldIgnore(fullPath)) continue;
|
|
240
|
+
|
|
241
|
+
try {
|
|
242
|
+
const stats = this.vfs.statSync(fullPath);
|
|
243
|
+
if (stats.isDirectory()) {
|
|
244
|
+
this.watchPath(fullPath);
|
|
245
|
+
this.watchDirRecursive(fullPath, depth + 1);
|
|
246
|
+
}
|
|
247
|
+
} catch {
|
|
248
|
+
// Ignore errors
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
} catch {
|
|
252
|
+
// Ignore errors
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
unwatch(paths: string | readonly string[]): this {
|
|
257
|
+
const pathArray = Array.isArray(paths) ? paths : [paths];
|
|
258
|
+
|
|
259
|
+
for (const p of pathArray) {
|
|
260
|
+
const normalized = this.normalizePath(p);
|
|
261
|
+
const watcher = this.watched.get(normalized);
|
|
262
|
+
if (watcher) {
|
|
263
|
+
watcher.close();
|
|
264
|
+
this.watched.delete(normalized);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
return this;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
close(): Promise<void> {
|
|
272
|
+
this.closed = true;
|
|
273
|
+
|
|
274
|
+
for (const watcher of this.watched.values()) {
|
|
275
|
+
watcher.close();
|
|
276
|
+
}
|
|
277
|
+
this.watched.clear();
|
|
278
|
+
|
|
279
|
+
this.emit('close');
|
|
280
|
+
return Promise.resolve();
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
getWatched(): Record<string, string[]> {
|
|
284
|
+
const result: Record<string, string[]> = {};
|
|
285
|
+
|
|
286
|
+
for (const path of this.watched.keys()) {
|
|
287
|
+
const dir = path.substring(0, path.lastIndexOf('/')) || '/';
|
|
288
|
+
const basename = path.substring(path.lastIndexOf('/') + 1);
|
|
289
|
+
|
|
290
|
+
if (!result[dir]) {
|
|
291
|
+
result[dir] = [];
|
|
292
|
+
}
|
|
293
|
+
result[dir].push(basename);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
return result;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Watch files/directories for changes
|
|
303
|
+
*/
|
|
304
|
+
export function watch(
|
|
305
|
+
paths: string | readonly string[],
|
|
306
|
+
options?: ChokidarOptions
|
|
307
|
+
): FSWatcher {
|
|
308
|
+
const watcher = new FSWatcher(options);
|
|
309
|
+
watcher.add(paths);
|
|
310
|
+
return watcher;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
export default { watch, FSWatcher, setVFS };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cluster shim - Clustering is not available in browser
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { EventEmitter } from './events';
|
|
6
|
+
|
|
7
|
+
export const isMaster = true;
|
|
8
|
+
export const isPrimary = true;
|
|
9
|
+
export const isWorker = false;
|
|
10
|
+
|
|
11
|
+
export class Worker extends EventEmitter {
|
|
12
|
+
id = 0;
|
|
13
|
+
process = null;
|
|
14
|
+
send(_message: unknown, _callback?: (error: Error | null) => void): boolean {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
kill(_signal?: string): void {}
|
|
18
|
+
disconnect(): void {}
|
|
19
|
+
isDead(): boolean { return false; }
|
|
20
|
+
isConnected(): boolean { return false; }
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const worker: Worker | null = null;
|
|
24
|
+
export const workers: Record<number, Worker> = {};
|
|
25
|
+
|
|
26
|
+
export function fork(_env?: object): Worker {
|
|
27
|
+
return new Worker();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function disconnect(_callback?: () => void): void {
|
|
31
|
+
if (_callback) setTimeout(_callback, 0);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const settings = {};
|
|
35
|
+
export const SCHED_NONE = 1;
|
|
36
|
+
export const SCHED_RR = 2;
|
|
37
|
+
export let schedulingPolicy = SCHED_RR;
|
|
38
|
+
|
|
39
|
+
export function setupMaster(_settings?: object): void {}
|
|
40
|
+
export function setupPrimary(_settings?: object): void {}
|
|
41
|
+
|
|
42
|
+
const clusterEmitter = new EventEmitter();
|
|
43
|
+
export const on = clusterEmitter.on.bind(clusterEmitter);
|
|
44
|
+
export const once = clusterEmitter.once.bind(clusterEmitter);
|
|
45
|
+
export const emit = clusterEmitter.emit.bind(clusterEmitter);
|
|
46
|
+
export const removeListener = clusterEmitter.removeListener.bind(clusterEmitter);
|
|
47
|
+
|
|
48
|
+
export default {
|
|
49
|
+
isMaster,
|
|
50
|
+
isPrimary,
|
|
51
|
+
isWorker,
|
|
52
|
+
Worker,
|
|
53
|
+
worker,
|
|
54
|
+
workers,
|
|
55
|
+
fork,
|
|
56
|
+
disconnect,
|
|
57
|
+
settings,
|
|
58
|
+
SCHED_NONE,
|
|
59
|
+
SCHED_RR,
|
|
60
|
+
schedulingPolicy,
|
|
61
|
+
setupMaster,
|
|
62
|
+
setupPrimary,
|
|
63
|
+
on,
|
|
64
|
+
once,
|
|
65
|
+
emit,
|
|
66
|
+
removeListener,
|
|
67
|
+
};
|