@seanhogg/builderforce-webcontainers-core 2026.10.2 → 2026.10.3
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/dist/build.d.ts +42 -0
- package/dist/build.d.ts.map +1 -0
- package/dist/build.js +65 -0
- package/dist/build.js.map +1 -0
- package/dist/buildHost.d.ts +31 -0
- package/dist/buildHost.d.ts.map +1 -0
- package/dist/buildHost.js +125 -0
- package/dist/buildHost.js.map +1 -0
- package/dist/buildHtml.d.ts +28 -0
- package/dist/buildHtml.d.ts.map +1 -0
- package/dist/buildHtml.js +74 -0
- package/dist/buildHtml.js.map +1 -0
- package/dist/bundler.d.ts +129 -0
- package/dist/bundler.d.ts.map +1 -0
- package/dist/bundler.js +79 -0
- package/dist/bundler.js.map +1 -0
- package/dist/check/acquire.d.ts +46 -0
- package/dist/check/acquire.d.ts.map +1 -0
- package/dist/check/acquire.js +179 -0
- package/dist/check/acquire.js.map +1 -0
- package/dist/check/compilerHost.d.ts +22 -0
- package/dist/check/compilerHost.d.ts.map +1 -0
- package/dist/check/compilerHost.js +128 -0
- package/dist/check/compilerHost.js.map +1 -0
- package/dist/check/diagnostics.d.ts +23 -0
- package/dist/check/diagnostics.d.ts.map +1 -0
- package/dist/check/diagnostics.js +28 -0
- package/dist/check/diagnostics.js.map +1 -0
- package/dist/check/index.d.ts +19 -0
- package/dist/check/index.d.ts.map +1 -0
- package/dist/check/index.js +13 -0
- package/dist/check/index.js.map +1 -0
- package/dist/check/projects.d.ts +26 -0
- package/dist/check/projects.d.ts.map +1 -0
- package/dist/check/projects.js +124 -0
- package/dist/check/projects.js.map +1 -0
- package/dist/check/shims.d.ts +29 -0
- package/dist/check/shims.d.ts.map +1 -0
- package/dist/check/shims.js +76 -0
- package/dist/check/shims.js.map +1 -0
- package/dist/check/typeStore.d.ts +57 -0
- package/dist/check/typeStore.d.ts.map +1 -0
- package/dist/check/typeStore.js +89 -0
- package/dist/check/typeStore.js.map +1 -0
- package/dist/check/typecheck.d.ts +29 -0
- package/dist/check/typecheck.d.ts.map +1 -0
- package/dist/check/typecheck.js +91 -0
- package/dist/check/typecheck.js.map +1 -0
- package/dist/compileComponent.d.ts +8 -0
- package/dist/compileComponent.d.ts.map +1 -0
- package/dist/compileComponent.js +22 -0
- package/dist/compileComponent.js.map +1 -0
- package/dist/compileScript.d.ts +19 -4
- package/dist/compileScript.d.ts.map +1 -1
- package/dist/compileScript.js +37 -12
- package/dist/compileScript.js.map +1 -1
- package/dist/components.d.ts +41 -0
- package/dist/components.d.ts.map +1 -0
- package/dist/components.js +14 -0
- package/dist/components.js.map +1 -0
- package/dist/detectProject.d.ts +3 -0
- package/dist/detectProject.d.ts.map +1 -1
- package/dist/detectProject.js +16 -6
- package/dist/detectProject.js.map +1 -1
- package/dist/devServer.d.ts +5 -2
- package/dist/devServer.d.ts.map +1 -1
- package/dist/devServer.js +10 -6
- package/dist/devServer.js.map +1 -1
- package/dist/hash.d.ts +2 -0
- package/dist/hash.d.ts.map +1 -0
- package/dist/hash.js +22 -0
- package/dist/hash.js.map +1 -0
- package/dist/index.d.ts +24 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -3
- package/dist/index.js.map +1 -1
- package/dist/installer/bins.d.ts +24 -0
- package/dist/installer/bins.d.ts.map +1 -0
- package/dist/installer/bins.js +56 -0
- package/dist/installer/bins.js.map +1 -0
- package/dist/installer/index.d.ts +14 -0
- package/dist/installer/index.d.ts.map +1 -0
- package/dist/installer/index.js +9 -0
- package/dist/installer/index.js.map +1 -0
- package/dist/installer/install.d.ts +46 -0
- package/dist/installer/install.d.ts.map +1 -0
- package/dist/installer/install.js +245 -0
- package/dist/installer/install.js.map +1 -0
- package/dist/installer/lockfile.d.ts +49 -0
- package/dist/installer/lockfile.d.ts.map +1 -0
- package/dist/installer/lockfile.js +110 -0
- package/dist/installer/lockfile.js.map +1 -0
- package/dist/installer/registry.d.ts +84 -0
- package/dist/installer/registry.d.ts.map +1 -0
- package/dist/installer/registry.js +130 -0
- package/dist/installer/registry.js.map +1 -0
- package/dist/installer/semver.d.ts +38 -0
- package/dist/installer/semver.d.ts.map +1 -0
- package/dist/installer/semver.js +187 -0
- package/dist/installer/semver.js.map +1 -0
- package/dist/installer/spec.d.ts +30 -0
- package/dist/installer/spec.d.ts.map +1 -0
- package/dist/installer/spec.js +30 -0
- package/dist/installer/spec.js.map +1 -0
- package/dist/installer/tar.d.ts +17 -0
- package/dist/installer/tar.d.ts.map +1 -0
- package/dist/installer/tar.js +150 -0
- package/dist/installer/tar.js.map +1 -0
- package/dist/installer/tree.d.ts +48 -0
- package/dist/installer/tree.d.ts.map +1 -0
- package/dist/installer/tree.js +179 -0
- package/dist/installer/tree.js.map +1 -0
- package/dist/node/assert.d.ts +15 -0
- package/dist/node/assert.d.ts.map +1 -0
- package/dist/node/assert.js +137 -0
- package/dist/node/assert.js.map +1 -0
- package/dist/node/buffer.d.ts +84 -0
- package/dist/node/buffer.d.ts.map +1 -0
- package/dist/node/buffer.js +304 -0
- package/dist/node/buffer.js.map +1 -0
- package/dist/node/builtins.d.ts +25 -0
- package/dist/node/builtins.d.ts.map +1 -0
- package/dist/node/builtins.js +101 -0
- package/dist/node/builtins.js.map +1 -0
- package/dist/node/callable.d.ts +13 -0
- package/dist/node/callable.d.ts.map +1 -0
- package/dist/node/callable.js +26 -0
- package/dist/node/callable.js.map +1 -0
- package/dist/node/childProcess.d.ts +13 -0
- package/dist/node/childProcess.d.ts.map +1 -0
- package/dist/node/childProcess.js +143 -0
- package/dist/node/childProcess.js.map +1 -0
- package/dist/node/crypto.d.ts +3 -0
- package/dist/node/crypto.d.ts.map +1 -0
- package/dist/node/crypto.js +180 -0
- package/dist/node/crypto.js.map +1 -0
- package/dist/node/esm.d.ts +9 -0
- package/dist/node/esm.d.ts.map +1 -0
- package/dist/node/esm.js +202 -0
- package/dist/node/esm.js.map +1 -0
- package/dist/node/events.d.ts +40 -0
- package/dist/node/events.d.ts.map +1 -0
- package/dist/node/events.js +160 -0
- package/dist/node/events.js.map +1 -0
- package/dist/node/fs/index.d.ts +7 -0
- package/dist/node/fs/index.d.ts.map +1 -0
- package/dist/node/fs/index.js +270 -0
- package/dist/node/fs/index.js.map +1 -0
- package/dist/node/fs/stats.d.ts +93 -0
- package/dist/node/fs/stats.d.ts.map +1 -0
- package/dist/node/fs/stats.js +104 -0
- package/dist/node/fs/stats.js.map +1 -0
- package/dist/node/fs/sync.d.ts +98 -0
- package/dist/node/fs/sync.d.ts.map +1 -0
- package/dist/node/fs/sync.js +348 -0
- package/dist/node/fs/sync.js.map +1 -0
- package/dist/node/hashes.d.ts +15 -0
- package/dist/node/hashes.d.ts.map +1 -0
- package/dist/node/hashes.js +195 -0
- package/dist/node/hashes.js.map +1 -0
- package/dist/node/http/client.d.ts +35 -0
- package/dist/node/http/client.d.ts.map +1 -0
- package/dist/node/http/client.js +161 -0
- package/dist/node/http/client.js.map +1 -0
- package/dist/node/http/index.d.ts +5 -0
- package/dist/node/http/index.d.ts.map +1 -0
- package/dist/node/http/index.js +125 -0
- package/dist/node/http/index.js.map +1 -0
- package/dist/node/http/server.d.ts +135 -0
- package/dist/node/http/server.d.ts.map +1 -0
- package/dist/node/http/server.js +308 -0
- package/dist/node/http/server.js.map +1 -0
- package/dist/node/http/status.d.ts +3 -0
- package/dist/node/http/status.d.ts.map +1 -0
- package/dist/node/http/status.js +13 -0
- package/dist/node/http/status.js.map +1 -0
- package/dist/node/inspect.d.ts +22 -0
- package/dist/node/inspect.d.ts.map +1 -0
- package/dist/node/inspect.js +172 -0
- package/dist/node/inspect.js.map +1 -0
- package/dist/node/loader.d.ts +91 -0
- package/dist/node/loader.d.ts.map +1 -0
- package/dist/node/loader.js +265 -0
- package/dist/node/loader.js.map +1 -0
- package/dist/node/loop.d.ts +71 -0
- package/dist/node/loop.d.ts.map +1 -0
- package/dist/node/loop.js +189 -0
- package/dist/node/loop.js.map +1 -0
- package/dist/node/misc.d.ts +10 -0
- package/dist/node/misc.d.ts.map +1 -0
- package/dist/node/misc.js +256 -0
- package/dist/node/misc.js.map +1 -0
- package/dist/node/path.d.ts +14 -0
- package/dist/node/path.d.ts.map +1 -0
- package/dist/node/path.js +128 -0
- package/dist/node/path.js.map +1 -0
- package/dist/node/process.d.ts +31 -0
- package/dist/node/process.d.ts.map +1 -0
- package/dist/node/process.js +309 -0
- package/dist/node/process.js.map +1 -0
- package/dist/node/program.d.ts +19 -0
- package/dist/node/program.d.ts.map +1 -0
- package/dist/node/program.js +165 -0
- package/dist/node/program.js.map +1 -0
- package/dist/node/readline.d.ts +2 -0
- package/dist/node/readline.d.ts.map +1 -0
- package/dist/node/readline.js +155 -0
- package/dist/node/readline.js.map +1 -0
- package/dist/node/resolve.d.ts +45 -0
- package/dist/node/resolve.d.ts.map +1 -0
- package/dist/node/resolve.js +206 -0
- package/dist/node/resolve.js.map +1 -0
- package/dist/node/runtime.d.ts +40 -0
- package/dist/node/runtime.d.ts.map +1 -0
- package/dist/node/runtime.js +149 -0
- package/dist/node/runtime.js.map +1 -0
- package/dist/node/stream/index.d.ts +52 -0
- package/dist/node/stream/index.d.ts.map +1 -0
- package/dist/node/stream/index.js +184 -0
- package/dist/node/stream/index.js.map +1 -0
- package/dist/node/stream/readable.d.ts +83 -0
- package/dist/node/stream/readable.d.ts.map +1 -0
- package/dist/node/stream/readable.js +325 -0
- package/dist/node/stream/readable.js.map +1 -0
- package/dist/node/stream/writable.d.ts +80 -0
- package/dist/node/stream/writable.d.ts.map +1 -0
- package/dist/node/stream/writable.js +224 -0
- package/dist/node/stream/writable.js.map +1 -0
- package/dist/node/urlqs.d.ts +22 -0
- package/dist/node/urlqs.d.ts.map +1 -0
- package/dist/node/urlqs.js +165 -0
- package/dist/node/urlqs.js.map +1 -0
- package/dist/node/util.d.ts +37 -0
- package/dist/node/util.d.ts.map +1 -0
- package/dist/node/util.js +160 -0
- package/dist/node/util.js.map +1 -0
- package/dist/node/zlib.d.ts +2 -0
- package/dist/node/zlib.d.ts.map +1 -0
- package/dist/node/zlib.js +133 -0
- package/dist/node/zlib.js.map +1 -0
- package/dist/packageCdn.d.ts +12 -0
- package/dist/packageCdn.d.ts.map +1 -1
- package/dist/packageCdn.js +3 -1
- package/dist/packageCdn.js.map +1 -1
- package/dist/projectConfig.d.ts +6 -2
- package/dist/projectConfig.d.ts.map +1 -1
- package/dist/projectConfig.js +32 -8
- package/dist/projectConfig.js.map +1 -1
- package/dist/shell/builtins.d.ts +23 -0
- package/dist/shell/builtins.d.ts.map +1 -0
- package/dist/shell/builtins.js +131 -0
- package/dist/shell/builtins.js.map +1 -0
- package/dist/shell/context.d.ts +41 -0
- package/dist/shell/context.d.ts.map +1 -0
- package/dist/shell/context.js +65 -0
- package/dist/shell/context.js.map +1 -0
- package/dist/shell/devHandoff.d.ts +18 -0
- package/dist/shell/devHandoff.d.ts.map +1 -0
- package/dist/shell/devHandoff.js +36 -0
- package/dist/shell/devHandoff.js.map +1 -0
- package/dist/shell/exec.d.ts +67 -0
- package/dist/shell/exec.d.ts.map +1 -0
- package/dist/shell/exec.js +247 -0
- package/dist/shell/exec.js.map +1 -0
- package/dist/shell/expand.d.ts +28 -0
- package/dist/shell/expand.d.ts.map +1 -0
- package/dist/shell/expand.js +149 -0
- package/dist/shell/expand.js.map +1 -0
- package/dist/shell/fileCommands.d.ts +10 -0
- package/dist/shell/fileCommands.d.ts.map +1 -0
- package/dist/shell/fileCommands.js +208 -0
- package/dist/shell/fileCommands.js.map +1 -0
- package/dist/shell/lineEditor.d.ts +43 -0
- package/dist/shell/lineEditor.d.ts.map +1 -0
- package/dist/shell/lineEditor.js +234 -0
- package/dist/shell/lineEditor.js.map +1 -0
- package/dist/shell/npm.d.ts +6 -0
- package/dist/shell/npm.d.ts.map +1 -0
- package/dist/shell/npm.js +234 -0
- package/dist/shell/npm.js.map +1 -0
- package/dist/shell/parse.d.ts +73 -0
- package/dist/shell/parse.d.ts.map +1 -0
- package/dist/shell/parse.js +300 -0
- package/dist/shell/parse.js.map +1 -0
- package/dist/shell/program.d.ts +12 -0
- package/dist/shell/program.d.ts.map +1 -0
- package/dist/shell/program.js +219 -0
- package/dist/shell/program.js.map +1 -0
- package/dist/shell/textCommands.d.ts +15 -0
- package/dist/shell/textCommands.d.ts.map +1 -0
- package/dist/shell/textCommands.js +185 -0
- package/dist/shell/textCommands.js.map +1 -0
- package/dist/styleModules.d.ts +6 -0
- package/dist/styleModules.d.ts.map +1 -1
- package/dist/styleModules.js +14 -4
- package/dist/styleModules.js.map +1 -1
- package/dist/svelteCompiler.d.ts +28 -0
- package/dist/svelteCompiler.d.ts.map +1 -0
- package/dist/svelteCompiler.js +13 -0
- package/dist/svelteCompiler.js.map +1 -0
- package/dist/system/commands.d.ts +26 -0
- package/dist/system/commands.d.ts.map +1 -0
- package/dist/system/commands.js +53 -0
- package/dist/system/commands.js.map +1 -0
- package/dist/system/index.d.ts +23 -0
- package/dist/system/index.d.ts.map +1 -0
- package/dist/system/index.js +16 -0
- package/dist/system/index.js.map +1 -0
- package/dist/system/kernel.d.ts +54 -0
- package/dist/system/kernel.d.ts.map +1 -0
- package/dist/system/kernel.js +81 -0
- package/dist/system/kernel.js.map +1 -0
- package/dist/system/ports.d.ts +32 -0
- package/dist/system/ports.d.ts.map +1 -0
- package/dist/system/ports.js +57 -0
- package/dist/system/ports.js.map +1 -0
- package/dist/system/process.d.ts +32 -0
- package/dist/system/process.d.ts.map +1 -0
- package/dist/system/process.js +130 -0
- package/dist/system/process.js.map +1 -0
- package/dist/system/programs.d.ts +10 -0
- package/dist/system/programs.d.ts.map +1 -0
- package/dist/system/programs.js +22 -0
- package/dist/system/programs.js.map +1 -0
- package/dist/system/terminal.d.ts +45 -0
- package/dist/system/terminal.d.ts.map +1 -0
- package/dist/system/terminal.js +127 -0
- package/dist/system/terminal.js.map +1 -0
- package/dist/system/types.d.ts +100 -0
- package/dist/system/types.d.ts.map +1 -0
- package/dist/system/types.js +2 -0
- package/dist/system/types.js.map +1 -0
- package/dist/vfs.d.ts +28 -4
- package/dist/vfs.d.ts.map +1 -1
- package/dist/vfs.js +95 -32
- package/dist/vfs.js.map +1 -1
- package/dist/vueCompiler.d.ts +75 -0
- package/dist/vueCompiler.d.ts.map +1 -0
- package/dist/vueCompiler.js +67 -0
- package/dist/vueCompiler.js.map +1 -0
- package/package.json +18 -2
- package/src/build.ts +105 -0
- package/src/buildHost.ts +154 -0
- package/src/buildHtml.ts +101 -0
- package/src/bundler.ts +190 -0
- package/src/check/acquire.ts +212 -0
- package/src/check/compilerHost.ts +138 -0
- package/src/check/diagnostics.ts +48 -0
- package/src/check/index.ts +28 -0
- package/src/check/projects.ts +149 -0
- package/src/check/shims.ts +88 -0
- package/src/check/typeStore.ts +103 -0
- package/src/check/typecheck.ts +134 -0
- package/src/compileComponent.ts +21 -0
- package/src/compileScript.ts +42 -13
- package/src/components.ts +59 -0
- package/src/detectProject.ts +18 -6
- package/src/devServer.ts +13 -8
- package/src/hash.ts +22 -0
- package/src/index.ts +35 -6
- package/src/installer/bins.ts +64 -0
- package/src/installer/index.ts +13 -0
- package/src/installer/install.ts +275 -0
- package/src/installer/lockfile.ts +146 -0
- package/src/installer/registry.ts +175 -0
- package/src/installer/semver.ts +190 -0
- package/src/installer/spec.ts +53 -0
- package/src/installer/tar.ts +155 -0
- package/src/installer/tree.ts +236 -0
- package/src/node/assert.ts +127 -0
- package/src/node/buffer.ts +304 -0
- package/src/node/builtins.ts +123 -0
- package/src/node/callable.ts +25 -0
- package/src/node/childProcess.ts +164 -0
- package/src/node/crypto.ts +187 -0
- package/src/node/esm.ts +196 -0
- package/src/node/events.ts +176 -0
- package/src/node/fs/index.ts +277 -0
- package/src/node/fs/stats.ts +110 -0
- package/src/node/fs/sync.ts +335 -0
- package/src/node/hashes.ts +171 -0
- package/src/node/http/client.ts +173 -0
- package/src/node/http/index.ts +122 -0
- package/src/node/http/server.ts +308 -0
- package/src/node/http/status.ts +13 -0
- package/src/node/inspect.ts +166 -0
- package/src/node/loader.ts +293 -0
- package/src/node/loop.ts +193 -0
- package/src/node/misc.ts +250 -0
- package/src/node/path.ts +135 -0
- package/src/node/process.ts +324 -0
- package/src/node/program.ts +170 -0
- package/src/node/readline.ts +157 -0
- package/src/node/resolve.ts +216 -0
- package/src/node/runtime.ts +184 -0
- package/src/node/stream/index.ts +196 -0
- package/src/node/stream/readable.ts +345 -0
- package/src/node/stream/writable.ts +244 -0
- package/src/node/urlqs.ts +162 -0
- package/src/node/util.ts +145 -0
- package/src/node/zlib.ts +145 -0
- package/src/packageCdn.ts +11 -1
- package/src/projectConfig.ts +34 -7
- package/src/shell/builtins.ts +141 -0
- package/src/shell/context.ts +89 -0
- package/src/shell/devHandoff.ts +49 -0
- package/src/shell/exec.ts +268 -0
- package/src/shell/expand.ts +145 -0
- package/src/shell/fileCommands.ts +206 -0
- package/src/shell/lineEditor.ts +233 -0
- package/src/shell/npm.ts +229 -0
- package/src/shell/parse.ts +295 -0
- package/src/shell/program.ts +223 -0
- package/src/shell/textCommands.ts +177 -0
- package/src/styleModules.ts +15 -4
- package/src/svelteCompiler.ts +31 -0
- package/src/system/commands.ts +72 -0
- package/src/system/index.ts +22 -0
- package/src/system/kernel.ts +106 -0
- package/src/system/ports.ts +73 -0
- package/src/system/process.ts +158 -0
- package/src/system/programs.ts +31 -0
- package/src/system/terminal.ts +135 -0
- package/src/system/types.ts +103 -0
- package/src/vfs.ts +92 -28
- package/src/vueCompiler.ts +121 -0
package/src/node/misc.ts
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The small builtins: os, tty, timers (+promises), string_decoder, perf_hooks,
|
|
3
|
+
* async_hooks, worker_threads, vm, dns, v8, diagnostics_channel and stubs for
|
|
4
|
+
* the ones with nothing to offer in a browser (cluster, inspector). Each exists
|
|
5
|
+
* so `require` succeeds and the common calls behave plausibly.
|
|
6
|
+
*/
|
|
7
|
+
import { EventEmitterBase } from './events.js';
|
|
8
|
+
import type { EventLoop } from './loop.js';
|
|
9
|
+
import { decode } from './buffer.js';
|
|
10
|
+
import { callable } from './callable.js';
|
|
11
|
+
|
|
12
|
+
export function createOsModule(env: () => Record<string, string | undefined>): Record<string, unknown> {
|
|
13
|
+
const cpus = Array.from({ length: Math.max(1, Math.min(16, globalThis.navigator?.hardwareConcurrency ?? 4)) }, () => ({
|
|
14
|
+
model: 'Browser CPU',
|
|
15
|
+
speed: 2400,
|
|
16
|
+
times: { user: 0, nice: 0, sys: 0, idle: 0, irq: 0 },
|
|
17
|
+
}));
|
|
18
|
+
return {
|
|
19
|
+
EOL: '\n',
|
|
20
|
+
devNull: '/dev/null',
|
|
21
|
+
platform: () => 'linux',
|
|
22
|
+
type: () => 'Linux',
|
|
23
|
+
release: () => '6.1.0-bfwc',
|
|
24
|
+
version: () => '#1 SMP BuilderForce WebContainers',
|
|
25
|
+
machine: () => 'x86_64',
|
|
26
|
+
arch: () => 'x64',
|
|
27
|
+
hostname: () => 'localhost',
|
|
28
|
+
homedir: () => env().HOME ?? '/home/user',
|
|
29
|
+
tmpdir: () => env().TMPDIR ?? '/tmp',
|
|
30
|
+
userInfo: () => ({ uid: 1000, gid: 1000, username: env().USER ?? 'user', homedir: env().HOME ?? '/home/user', shell: '/bin/jsh' }),
|
|
31
|
+
cpus: () => cpus,
|
|
32
|
+
availableParallelism: () => cpus.length,
|
|
33
|
+
totalmem: () => 4 * 1024 ** 3,
|
|
34
|
+
freemem: () => 2 * 1024 ** 3,
|
|
35
|
+
loadavg: () => [0, 0, 0],
|
|
36
|
+
uptime: () => Math.floor(performance.now() / 1000),
|
|
37
|
+
networkInterfaces: () => ({ lo: [{ address: '127.0.0.1', netmask: '255.0.0.0', family: 'IPv4', mac: '00:00:00:00:00:00', internal: true, cidr: '127.0.0.1/8' }] }),
|
|
38
|
+
endianness: () => 'LE',
|
|
39
|
+
getPriority: () => 0,
|
|
40
|
+
setPriority: () => undefined,
|
|
41
|
+
constants: { signals: { SIGHUP: 1, SIGINT: 2, SIGQUIT: 3, SIGKILL: 9, SIGTERM: 15 }, errno: {}, priority: {} },
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function createTtyModule(isTerminal: boolean): Record<string, unknown> {
|
|
46
|
+
return {
|
|
47
|
+
isatty: (fd: number) => isTerminal && fd >= 0 && fd <= 2,
|
|
48
|
+
ReadStream: class extends EventEmitterBase {},
|
|
49
|
+
WriteStream: class extends EventEmitterBase {},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function createTimersModule(loop: EventLoop): Record<string, unknown> {
|
|
54
|
+
const promises = {
|
|
55
|
+
setTimeout: (ms?: number, value?: unknown, options?: { signal?: AbortSignal }) =>
|
|
56
|
+
new Promise((resolve, reject) => {
|
|
57
|
+
const t = loop.setTimeout(() => resolve(value), ms);
|
|
58
|
+
options?.signal?.addEventListener('abort', () => {
|
|
59
|
+
loop.clearTimeout(t);
|
|
60
|
+
reject(Object.assign(new Error('The operation was aborted'), { name: 'AbortError', code: 'ABORT_ERR' }));
|
|
61
|
+
});
|
|
62
|
+
}),
|
|
63
|
+
setImmediate: (value?: unknown) => new Promise((resolve) => loop.setImmediate(() => resolve(value))),
|
|
64
|
+
async *setInterval(ms?: number, value?: unknown) {
|
|
65
|
+
while (true) {
|
|
66
|
+
await new Promise((resolve) => loop.setTimeout(resolve, ms));
|
|
67
|
+
yield value;
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
scheduler: { wait: (ms: number) => new Promise((resolve) => loop.setTimeout(resolve, ms)), yield: () => new Promise((resolve) => loop.setImmediate(resolve)) },
|
|
71
|
+
};
|
|
72
|
+
return {
|
|
73
|
+
setTimeout: loop.setTimeout,
|
|
74
|
+
clearTimeout: loop.clearTimeout,
|
|
75
|
+
setInterval: loop.setInterval,
|
|
76
|
+
clearInterval: loop.clearInterval,
|
|
77
|
+
setImmediate: loop.setImmediate,
|
|
78
|
+
clearImmediate: loop.clearImmediate,
|
|
79
|
+
promises,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function createStringDecoderModule(): Record<string, unknown> {
|
|
84
|
+
const init = (self: { encoding: string; utf8?: TextDecoder }, encoding?: string) => {
|
|
85
|
+
self.encoding = (encoding ?? 'utf8').toLowerCase().replace('-', '');
|
|
86
|
+
if (self.encoding === 'utf8') self.utf8 = new TextDecoder('utf-8');
|
|
87
|
+
};
|
|
88
|
+
class StringDecoderBase {
|
|
89
|
+
declare encoding: string;
|
|
90
|
+
declare utf8?: TextDecoder;
|
|
91
|
+
constructor(encoding?: string) {
|
|
92
|
+
init(this, encoding);
|
|
93
|
+
}
|
|
94
|
+
write(chunk: Uint8Array | string): string {
|
|
95
|
+
if (typeof chunk === 'string') return chunk;
|
|
96
|
+
return this.utf8 ? this.utf8.decode(chunk, { stream: true }) : decode(chunk, this.encoding);
|
|
97
|
+
}
|
|
98
|
+
end(chunk?: Uint8Array | string): string {
|
|
99
|
+
const head = chunk === undefined ? '' : this.write(chunk);
|
|
100
|
+
return head + (this.utf8 ? this.utf8.decode() : '');
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
// iconv-lite (body-parser) subclasses it the pre-ES2015 way: StringDecoder.call(this, enc).
|
|
104
|
+
return { StringDecoder: callable(StringDecoderBase, init) };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function createAsyncHooksModule(): Record<string, unknown> {
|
|
108
|
+
/**
|
|
109
|
+
* Context does not propagate across awaits here (that needs engine support);
|
|
110
|
+
* `run` scopes the store for synchronous code and whatever reads it in the
|
|
111
|
+
* same tick, which is how most request-scoped loggers use it.
|
|
112
|
+
*/
|
|
113
|
+
class AsyncLocalStorage<T> {
|
|
114
|
+
private store: T | undefined;
|
|
115
|
+
getStore(): T | undefined {
|
|
116
|
+
return this.store;
|
|
117
|
+
}
|
|
118
|
+
run<R>(store: T, fn: (...args: unknown[]) => R, ...args: unknown[]): R {
|
|
119
|
+
const previous = this.store;
|
|
120
|
+
this.store = store;
|
|
121
|
+
try {
|
|
122
|
+
return fn(...args);
|
|
123
|
+
} finally {
|
|
124
|
+
this.store = previous;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
enterWith(store: T): void {
|
|
128
|
+
this.store = store;
|
|
129
|
+
}
|
|
130
|
+
exit<R>(fn: (...args: unknown[]) => R, ...args: unknown[]): R {
|
|
131
|
+
return this.run(undefined as T, fn, ...args);
|
|
132
|
+
}
|
|
133
|
+
disable(): void {
|
|
134
|
+
this.store = undefined;
|
|
135
|
+
}
|
|
136
|
+
static bind<F>(fn: F): F {
|
|
137
|
+
return fn;
|
|
138
|
+
}
|
|
139
|
+
static snapshot() {
|
|
140
|
+
return <R>(fn: (...args: unknown[]) => R, ...args: unknown[]) => fn(...args);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
class AsyncResource {
|
|
144
|
+
constructor(readonly type: string) {}
|
|
145
|
+
runInAsyncScope<R>(fn: (...args: unknown[]) => R, thisArg?: unknown, ...args: unknown[]): R {
|
|
146
|
+
return fn.apply(thisArg, args);
|
|
147
|
+
}
|
|
148
|
+
bind<F>(fn: F): F {
|
|
149
|
+
return fn;
|
|
150
|
+
}
|
|
151
|
+
static bind<F>(fn: F): F {
|
|
152
|
+
return fn;
|
|
153
|
+
}
|
|
154
|
+
emitDestroy(): this {
|
|
155
|
+
return this;
|
|
156
|
+
}
|
|
157
|
+
asyncId(): number {
|
|
158
|
+
return 1;
|
|
159
|
+
}
|
|
160
|
+
triggerAsyncId(): number {
|
|
161
|
+
return 0;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return {
|
|
165
|
+
AsyncLocalStorage,
|
|
166
|
+
AsyncResource,
|
|
167
|
+
createHook: () => ({ enable() { return this; }, disable() { return this; } }),
|
|
168
|
+
executionAsyncId: () => 1,
|
|
169
|
+
triggerAsyncId: () => 0,
|
|
170
|
+
executionAsyncResource: () => ({}),
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export function createVmModule(): Record<string, unknown> {
|
|
175
|
+
const run = (code: string, context: Record<string, unknown> = {}) => {
|
|
176
|
+
const names = Object.keys(context).filter((k) => /^[A-Za-z_$][\w$]*$/.test(k));
|
|
177
|
+
return new Function(...names, `return eval(${JSON.stringify(code)})`)(...names.map((n) => context[n]));
|
|
178
|
+
};
|
|
179
|
+
class Script {
|
|
180
|
+
constructor(private readonly code: string) {}
|
|
181
|
+
runInThisContext(): unknown {
|
|
182
|
+
return (0, eval)(this.code);
|
|
183
|
+
}
|
|
184
|
+
runInNewContext(context?: Record<string, unknown>): unknown {
|
|
185
|
+
return run(this.code, context);
|
|
186
|
+
}
|
|
187
|
+
runInContext(context: Record<string, unknown>): unknown {
|
|
188
|
+
return run(this.code, context);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return {
|
|
192
|
+
Script,
|
|
193
|
+
runInThisContext: (code: string) => (0, eval)(code),
|
|
194
|
+
runInNewContext: run,
|
|
195
|
+
runInContext: run,
|
|
196
|
+
createContext: (context: Record<string, unknown> = {}) => context,
|
|
197
|
+
isContext: () => true,
|
|
198
|
+
compileFunction: (code: string, params: string[] = []) => new Function(...params, code),
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export function createDiagnosticsChannelModule(): Record<string, unknown> {
|
|
203
|
+
const channels = new Map<string, { subscribers: Set<(message: unknown, name: string) => void>; name: string }>();
|
|
204
|
+
const channel = (name: string) => {
|
|
205
|
+
let c = channels.get(name);
|
|
206
|
+
if (!c) {
|
|
207
|
+
const subscribers = new Set<(message: unknown, name: string) => void>();
|
|
208
|
+
c = Object.assign({ subscribers, name }, {
|
|
209
|
+
get hasSubscribers() { return subscribers.size > 0; },
|
|
210
|
+
publish: (message: unknown) => subscribers.forEach((s) => s(message, name)),
|
|
211
|
+
subscribe: (fn: (message: unknown, name: string) => void) => void subscribers.add(fn),
|
|
212
|
+
unsubscribe: (fn: (message: unknown, name: string) => void) => subscribers.delete(fn),
|
|
213
|
+
});
|
|
214
|
+
channels.set(name, c);
|
|
215
|
+
}
|
|
216
|
+
return c;
|
|
217
|
+
};
|
|
218
|
+
return {
|
|
219
|
+
channel,
|
|
220
|
+
hasSubscribers: (name: string) => (channels.get(name)?.subscribers.size ?? 0) > 0,
|
|
221
|
+
subscribe: (name: string, fn: (m: unknown, n: string) => void) => channel(name).subscribers.add(fn),
|
|
222
|
+
unsubscribe: (name: string, fn: (m: unknown, n: string) => void) => channel(name).subscribers.delete(fn),
|
|
223
|
+
tracingChannel: (name: string) => ({ start: channel(`tracing:${name}:start`), end: channel(`tracing:${name}:end`), error: channel(`tracing:${name}:error`), traceSync: <R>(fn: () => R) => fn(), tracePromise: <R>(fn: () => R) => fn() }),
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const unavailable = (name: string) => () => {
|
|
228
|
+
throw Object.assign(new Error(`${name} is not available in the browser runtime`), { code: 'ERR_FEATURE_UNAVAILABLE_ON_PLATFORM' });
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
export function createStubModules(): Record<string, Record<string, unknown>> {
|
|
232
|
+
return {
|
|
233
|
+
perf_hooks: { performance: globalThis.performance, PerformanceObserver: class { observe() {} disconnect() {} }, monitorEventLoopDelay: () => ({ enable() {}, disable() {}, percentile: () => 0, mean: 0, max: 0, min: 0 }), constants: {} },
|
|
234
|
+
worker_threads: { isMainThread: true, parentPort: null, workerData: null, threadId: 0, resourceLimits: {}, Worker: unavailable('worker_threads.Worker'), MessageChannel, MessagePort: globalThis.MessagePort, BroadcastChannel: globalThis.BroadcastChannel, markAsUntransferable: () => undefined, SHARE_ENV: Symbol('SHARE_ENV') },
|
|
235
|
+
dns: { lookup: (host: string, options: unknown, cb?: (e: Error | null, address: string, family: number) => void) => queueMicrotask(() => ((typeof options === 'function' ? options : cb) as NonNullable<typeof cb>)(null, host === 'localhost' ? '127.0.0.1' : host, 4)), resolve: unavailable('dns.resolve'), promises: { lookup: async (host: string) => ({ address: host === 'localhost' ? '127.0.0.1' : host, family: 4 }) }, setDefaultResultOrder: () => undefined },
|
|
236
|
+
v8: { getHeapStatistics: () => ({ total_heap_size: 30e6, used_heap_size: 20e6, heap_size_limit: 2e9 }), getHeapSpaceStatistics: () => [], serialize: (v: unknown) => new TextEncoder().encode(JSON.stringify(v)), deserialize: (b: Uint8Array) => JSON.parse(new TextDecoder().decode(b)), setFlagsFromString: () => undefined, cachedDataVersionTag: () => 0 },
|
|
237
|
+
cluster: { isMaster: true, isPrimary: true, isWorker: false, workers: {}, fork: unavailable('cluster.fork'), on: () => undefined, settings: {} },
|
|
238
|
+
inspector: { open: () => undefined, close: () => undefined, url: () => undefined, Session: class { connect() {} post() {} disconnect() {} }, console: globalThis.console },
|
|
239
|
+
punycode: { toASCII: (s: string) => new URL(`http://${s}`).hostname, toUnicode: (s: string) => s, encode: (s: string) => s, decode: (s: string) => s, ucs2: { decode: (s: string) => Array.from(s, (c) => c.codePointAt(0)!), encode: (a: number[]) => String.fromCodePoint(...a) } },
|
|
240
|
+
tls: { connect: unavailable('tls.connect'), createServer: unavailable('tls.createServer'), createSecureContext: () => ({}), DEFAULT_MIN_VERSION: 'TLSv1.2', DEFAULT_MAX_VERSION: 'TLSv1.3', rootCertificates: [] },
|
|
241
|
+
dgram: { createSocket: unavailable('dgram.createSocket') },
|
|
242
|
+
http2: { connect: unavailable('http2.connect'), createServer: unavailable('http2.createServer'), createSecureServer: unavailable('http2.createSecureServer'), constants: {} },
|
|
243
|
+
trace_events: { createTracing: () => ({ enable() {}, disable() {} }), getEnabledCategories: () => '' },
|
|
244
|
+
sqlite: { DatabaseSync: unavailable('sqlite.DatabaseSync') },
|
|
245
|
+
test: { test: unavailable('node:test'), describe: unavailable('node:test'), it: unavailable('node:test') },
|
|
246
|
+
wasi: { WASI: unavailable('wasi.WASI') },
|
|
247
|
+
repl: { start: unavailable('repl.start') },
|
|
248
|
+
domain: { create: () => Object.assign(new EventEmitterBase(), { run: (fn: () => unknown) => fn(), add() {}, remove() {}, bind: <F>(fn: F) => fn, intercept: <F>(fn: F) => fn, enter() {}, exit() {}, dispose() {} }) },
|
|
249
|
+
};
|
|
250
|
+
}
|
package/src/node/path.ts
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node's `path` module, POSIX flavour — the runtime reports `platform: 'linux'`,
|
|
3
|
+
* so `path.win32` is the same object (Windows paths never occur in the VFS).
|
|
4
|
+
* `resolve` needs a cwd, so the module is created per process.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export interface ParsedPath {
|
|
8
|
+
root: string;
|
|
9
|
+
dir: string;
|
|
10
|
+
base: string;
|
|
11
|
+
ext: string;
|
|
12
|
+
name: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function normalizeString(path: string, allowAboveRoot: boolean): string {
|
|
16
|
+
const out: string[] = [];
|
|
17
|
+
for (const segment of path.split('/')) {
|
|
18
|
+
if (!segment || segment === '.') continue;
|
|
19
|
+
if (segment === '..') {
|
|
20
|
+
if (out.length && out[out.length - 1] !== '..') out.pop();
|
|
21
|
+
else if (allowAboveRoot) out.push('..');
|
|
22
|
+
} else out.push(segment);
|
|
23
|
+
}
|
|
24
|
+
return out.join('/');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function createPathModule(cwd: () => string) {
|
|
28
|
+
const assertPath = (p: unknown) => {
|
|
29
|
+
if (typeof p !== 'string') throw new TypeError(`The "path" argument must be of type string. Received ${typeof p}`);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const path = {
|
|
33
|
+
sep: '/',
|
|
34
|
+
delimiter: ':',
|
|
35
|
+
|
|
36
|
+
normalize(p: string): string {
|
|
37
|
+
assertPath(p);
|
|
38
|
+
if (!p) return '.';
|
|
39
|
+
const absolute = p.startsWith('/');
|
|
40
|
+
const trailing = p.endsWith('/');
|
|
41
|
+
let out = normalizeString(p, !absolute);
|
|
42
|
+
if (!out && !absolute) out = '.';
|
|
43
|
+
if (out && trailing) out += '/';
|
|
44
|
+
return absolute ? '/' + out : out;
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
join(...parts: string[]): string {
|
|
48
|
+
parts.forEach(assertPath);
|
|
49
|
+
const joined = parts.filter(Boolean).join('/');
|
|
50
|
+
return joined ? path.normalize(joined) : '.';
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
resolve(...parts: string[]): string {
|
|
54
|
+
let resolved = '';
|
|
55
|
+
for (let i = parts.length - 1; i >= -1 && !resolved.startsWith('/'); i--) {
|
|
56
|
+
const part = i >= 0 ? parts[i]! : cwd();
|
|
57
|
+
assertPath(part);
|
|
58
|
+
if (part) resolved = resolved ? `${part}/${resolved}` : part;
|
|
59
|
+
}
|
|
60
|
+
const out = normalizeString(resolved, false);
|
|
61
|
+
return '/' + out;
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
isAbsolute(p: string): boolean {
|
|
65
|
+
assertPath(p);
|
|
66
|
+
return p.startsWith('/');
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
relative(from: string, to: string): string {
|
|
70
|
+
const a = path.resolve(from).split('/').filter(Boolean);
|
|
71
|
+
const b = path.resolve(to).split('/').filter(Boolean);
|
|
72
|
+
let i = 0;
|
|
73
|
+
while (i < a.length && i < b.length && a[i] === b[i]) i++;
|
|
74
|
+
return [...a.slice(i).map(() => '..'), ...b.slice(i)].join('/');
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
dirname(p: string): string {
|
|
78
|
+
assertPath(p);
|
|
79
|
+
if (!p) return '.';
|
|
80
|
+
const trimmed = p.length > 1 ? p.replace(/\/+$/, '') : p;
|
|
81
|
+
const cut = trimmed.lastIndexOf('/');
|
|
82
|
+
if (cut < 0) return '.';
|
|
83
|
+
if (cut === 0) return '/';
|
|
84
|
+
return trimmed.slice(0, cut);
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
basename(p: string, ext?: string): string {
|
|
88
|
+
assertPath(p);
|
|
89
|
+
const trimmed = p.length > 1 ? p.replace(/\/+$/, '') : p;
|
|
90
|
+
let base = trimmed.slice(trimmed.lastIndexOf('/') + 1);
|
|
91
|
+
if (ext && base.endsWith(ext) && base !== ext) base = base.slice(0, -ext.length);
|
|
92
|
+
return base;
|
|
93
|
+
},
|
|
94
|
+
|
|
95
|
+
extname(p: string): string {
|
|
96
|
+
const base = path.basename(p);
|
|
97
|
+
const dot = base.lastIndexOf('.');
|
|
98
|
+
return dot <= 0 ? '' : base.slice(dot);
|
|
99
|
+
},
|
|
100
|
+
|
|
101
|
+
parse(p: string): ParsedPath {
|
|
102
|
+
const root = p.startsWith('/') ? '/' : '';
|
|
103
|
+
const base = path.basename(p);
|
|
104
|
+
const ext = path.extname(p);
|
|
105
|
+
const dirname = path.dirname(p);
|
|
106
|
+
const dir = dirname === '.' && !p.includes('/') ? '' : dirname;
|
|
107
|
+
return { root, dir, base, ext, name: ext ? base.slice(0, -ext.length) : base };
|
|
108
|
+
},
|
|
109
|
+
|
|
110
|
+
format(parts: Partial<ParsedPath>): string {
|
|
111
|
+
const dir = parts.dir ?? parts.root ?? '';
|
|
112
|
+
const base = parts.base ?? `${parts.name ?? ''}${parts.ext ?? ''}`;
|
|
113
|
+
if (!dir) return base;
|
|
114
|
+
return dir === parts.root ? `${dir}${base}` : `${dir}/${base}`;
|
|
115
|
+
},
|
|
116
|
+
|
|
117
|
+
toNamespacedPath(p: string): string {
|
|
118
|
+
return p;
|
|
119
|
+
},
|
|
120
|
+
|
|
121
|
+
matchesGlob(p: string, pattern: string): boolean {
|
|
122
|
+
const source = pattern
|
|
123
|
+
.replace(/[.+^${}()|[\]\\]/g, '\\$&')
|
|
124
|
+
.replace(/\*\*\/?/g, '\u0000')
|
|
125
|
+
.replace(/\*/g, '[^/]*')
|
|
126
|
+
.replace(/\?/g, '[^/]')
|
|
127
|
+
.replace(/\u0000/g, '(?:.*/)?');
|
|
128
|
+
return new RegExp(`^${source}$`).test(p);
|
|
129
|
+
},
|
|
130
|
+
} as Record<string, any>;
|
|
131
|
+
|
|
132
|
+
path.posix = path;
|
|
133
|
+
path.win32 = path;
|
|
134
|
+
return path;
|
|
135
|
+
}
|