@nimbus-sh/worker 0.10.0 → 0.11.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/NOTICE.md +5 -0
- package/README.md +10 -0
- package/dist/_shared/session-router.d.ts +7 -0
- package/dist/_shared/session-router.d.ts.map +1 -1
- package/dist/_shared/session-router.js +7 -0
- package/dist/bindings/body.d.ts +6 -0
- package/dist/bindings/body.d.ts.map +1 -0
- package/dist/bindings/body.js +37 -0
- package/dist/bindings/kv.d.ts +0 -2
- package/dist/bindings/kv.d.ts.map +1 -1
- package/dist/bindings/kv.js +3 -42
- package/dist/bindings/r2.d.ts +0 -2
- package/dist/bindings/r2.d.ts.map +1 -1
- package/dist/bindings/r2.js +4 -44
- package/dist/esbuild-cli-artifact.generated.d.ts +18 -0
- package/dist/esbuild-cli-artifact.generated.d.ts.map +1 -0
- package/dist/esbuild-cli-artifact.generated.js +17 -0
- package/dist/facets/cirrus-real.d.ts.map +1 -1
- package/dist/facets/cirrus-real.js +9 -4
- package/dist/facets/compose.d.ts +11 -7
- package/dist/facets/compose.d.ts.map +1 -1
- package/dist/facets/compose.js +8 -38
- package/dist/facets/data-plan.d.ts +79 -0
- package/dist/facets/data-plan.d.ts.map +1 -0
- package/dist/facets/data-plan.js +477 -0
- package/dist/facets/esbuild-transform.d.ts +36 -10
- package/dist/facets/esbuild-transform.d.ts.map +1 -1
- package/dist/facets/esbuild-transform.js +216 -20
- package/dist/facets/exec-telemetry.d.ts +7 -3
- package/dist/facets/exec-telemetry.d.ts.map +1 -1
- package/dist/facets/manager.d.ts +179 -78
- package/dist/facets/manager.d.ts.map +1 -1
- package/dist/facets/manager.js +1221 -649
- package/dist/facets/opencode-staging.d.ts +0 -2
- package/dist/facets/opencode-staging.d.ts.map +1 -1
- package/dist/facets/opencode-staging.js +5 -11
- package/dist/facets/process.d.ts +4 -0
- package/dist/facets/process.d.ts.map +1 -1
- package/dist/facets/process.js +3 -0
- package/dist/facets/read-profile.d.ts +149 -0
- package/dist/facets/read-profile.d.ts.map +1 -0
- package/dist/facets/read-profile.js +483 -0
- package/dist/facets/resident-identity.d.ts +0 -1
- package/dist/facets/resident-identity.d.ts.map +1 -1
- package/dist/facets/resident-identity.js +0 -3
- package/dist/facets/wasm-swap-registry.d.ts +34 -25
- package/dist/facets/wasm-swap-registry.d.ts.map +1 -1
- package/dist/facets/wasm-swap-registry.js +62 -56
- package/dist/facets/ws-terminal.d.ts +4 -4
- package/dist/facets/ws-terminal.d.ts.map +1 -1
- package/dist/facets/ws-terminal.js +4 -5
- package/dist/git/commands.d.ts +16 -9
- package/dist/git/commands.d.ts.map +1 -1
- package/dist/git/commands.js +1818 -188
- package/dist/git/network-facet.d.ts +10 -2
- package/dist/git/network-facet.d.ts.map +1 -1
- package/dist/git/network-facet.js +62 -16
- package/dist/git/unified-diff.d.ts +74 -0
- package/dist/git/unified-diff.d.ts.map +1 -0
- package/dist/git/unified-diff.js +676 -0
- package/dist/git-bundle.generated.d.ts +7 -11
- package/dist/git-bundle.generated.d.ts.map +1 -1
- package/dist/git-bundle.generated.js +7 -11
- package/dist/hosted/commands.d.ts.map +1 -1
- package/dist/hosted/commands.js +62 -243
- package/dist/hosted/runtime.d.ts +19 -13
- package/dist/hosted/runtime.d.ts.map +1 -1
- package/dist/hosted/runtime.js +71 -14
- package/dist/hosted/services.d.ts +6 -7
- package/dist/hosted/services.d.ts.map +1 -1
- package/dist/hosted/services.js +10 -14
- package/dist/hosted/session.d.ts +165 -0
- package/dist/hosted/session.d.ts.map +1 -0
- package/dist/hosted/session.js +132 -0
- package/dist/loaders/generated-workers.d.ts +5 -2
- package/dist/loaders/generated-workers.d.ts.map +1 -1
- package/dist/loaders/generated-workers.js +6 -3
- package/dist/loaders/npm-resolve-preamble.d.ts.map +1 -1
- package/dist/loaders/npm-resolve-preamble.js +0 -27
- package/dist/node-shims-artifact.generated.d.ts +13 -4
- package/dist/node-shims-artifact.generated.d.ts.map +1 -1
- package/dist/node-shims-artifact.generated.js +16 -7
- package/dist/npm/bin-links.d.ts +3 -1
- package/dist/npm/bin-links.d.ts.map +1 -1
- package/dist/npm/bin-links.js +32 -8
- package/dist/npm/cache.d.ts +5 -0
- package/dist/npm/cache.d.ts.map +1 -1
- package/dist/npm/cache.js +13 -1
- package/dist/npm/install-batch-facet.d.ts +2 -2
- package/dist/npm/install-batch-facet.js +3 -3
- package/dist/npm/installer.d.ts +17 -1
- package/dist/npm/installer.d.ts.map +1 -1
- package/dist/npm/installer.js +159 -20
- package/dist/npm/package-lock.d.ts +32 -0
- package/dist/npm/package-lock.d.ts.map +1 -0
- package/dist/npm/package-lock.js +65 -0
- package/dist/npm/pre-bundle-facet.d.ts +1 -30
- package/dist/npm/pre-bundle-facet.d.ts.map +1 -1
- package/dist/npm/pre-bundle-facet.js +3 -5
- package/dist/npm/r2-cache.d.ts +2 -0
- package/dist/npm/r2-cache.d.ts.map +1 -1
- package/dist/npm/r2-cache.js +2 -0
- package/dist/npm/resolve-one-facet.d.ts.map +1 -1
- package/dist/npm/resolve-one-facet.js +14 -3
- package/dist/npm/resolver.d.ts +0 -7
- package/dist/npm/resolver.d.ts.map +1 -1
- package/dist/npm/resolver.js +0 -22
- package/dist/opencode-artifact.generated.js +2 -2
- package/dist/replica/routing.d.ts +2 -38
- package/dist/replica/routing.d.ts.map +1 -1
- package/dist/replica/routing.js +3 -55
- package/dist/router/index.d.ts.map +1 -1
- package/dist/router/index.js +15 -2
- package/dist/router/public-directory.d.ts +18 -0
- package/dist/router/public-directory.d.ts.map +1 -1
- package/dist/router/public-directory.js +1 -1
- package/dist/router/remote-api.d.ts +3 -1
- package/dist/router/remote-api.d.ts.map +1 -1
- package/dist/router/remote-api.js +42 -79
- package/dist/runtime/bash-repl.js +2 -2
- package/dist/runtime/bun-repl.d.ts.map +1 -1
- package/dist/runtime/bun-repl.js +2 -13
- package/dist/runtime/esbuild-wasm-bytes.d.ts +17 -5
- package/dist/runtime/esbuild-wasm-bytes.d.ts.map +1 -1
- package/dist/runtime/esbuild-wasm-bytes.js +43 -94
- package/dist/runtime/git-bundle-artifact.d.ts +17 -0
- package/dist/runtime/git-bundle-artifact.d.ts.map +1 -0
- package/dist/runtime/git-bundle-artifact.js +25 -0
- package/dist/runtime/node-repl.d.ts.map +1 -1
- package/dist/runtime/node-repl.js +2 -13
- package/dist/runtime/node-shims-artifact.d.ts +22 -23
- package/dist/runtime/node-shims-artifact.d.ts.map +1 -1
- package/dist/runtime/node-shims-artifact.js +48 -78
- package/dist/runtime/node-shims.d.ts.map +1 -1
- package/dist/runtime/node-shims.js +1567 -864
- package/dist/runtime/opencode-artifact.d.ts.map +1 -1
- package/dist/runtime/opencode-artifact.js +17 -53
- package/dist/runtime/opencode-facet-runner.d.ts +3 -6
- package/dist/runtime/opencode-facet-runner.d.ts.map +1 -1
- package/dist/runtime/opencode-facet-runner.js +45 -10
- package/dist/runtime/opentui-wasm-bytes.d.ts.map +1 -1
- package/dist/runtime/opentui-wasm-bytes.js +16 -49
- package/dist/runtime/package-manager.d.ts +0 -2
- package/dist/runtime/package-manager.d.ts.map +1 -1
- package/dist/runtime/package-manager.js +0 -3
- package/dist/runtime/python-repl.d.ts.map +1 -1
- package/dist/runtime/python-repl.js +2 -2
- package/dist/runtime/repl-session.d.ts +10 -0
- package/dist/runtime/repl-session.d.ts.map +1 -1
- package/dist/runtime/repl-session.js +7 -0
- package/dist/runtime/ruby-repl.d.ts.map +1 -1
- package/dist/runtime/ruby-repl.js +2 -2
- package/dist/runtime/ruby-resident.d.ts.map +1 -1
- package/dist/runtime/ruby-resident.js +36 -35
- package/dist/runtime/runtime-catalog.d.ts +10 -3
- package/dist/runtime/runtime-catalog.d.ts.map +1 -1
- package/dist/runtime/runtime-catalog.js +125 -15
- package/dist/runtime/sqlite-wasm-bytes.d.ts +4 -4
- package/dist/runtime/sqlite-wasm-bytes.d.ts.map +1 -1
- package/dist/runtime/sqlite-wasm-bytes.js +21 -57
- package/dist/runtime/staged-source.d.ts +67 -0
- package/dist/runtime/staged-source.d.ts.map +1 -0
- package/dist/runtime/staged-source.js +113 -0
- package/dist/runtime/wasi/preamble.d.ts.map +1 -1
- package/dist/runtime/wasi/preamble.js +0 -24
- package/dist/runtime-catalog.generated.js +1 -1
- package/dist/session/agent.d.ts +14 -2
- package/dist/session/agent.d.ts.map +1 -1
- package/dist/session/agent.js +57 -19
- package/dist/session/ai.d.ts +0 -11
- package/dist/session/ai.d.ts.map +1 -1
- package/dist/session/ai.js +0 -4
- package/dist/session/fs-watch.d.ts +0 -11
- package/dist/session/fs-watch.d.ts.map +1 -1
- package/dist/session/fs-watch.js +0 -21
- package/dist/session/hibernation.d.ts +34 -11
- package/dist/session/hibernation.d.ts.map +1 -1
- package/dist/session/hibernation.js +46 -29
- package/dist/session/init-phases.d.ts +1 -2
- package/dist/session/init-phases.d.ts.map +1 -1
- package/dist/session/init-phases.js +1 -2
- package/dist/session/init.d.ts.map +1 -1
- package/dist/session/init.js +7 -20
- package/dist/session/keys.d.ts +0 -3
- package/dist/session/keys.d.ts.map +1 -1
- package/dist/session/keys.js +0 -3
- package/dist/session/legacy-reset.d.ts +11 -0
- package/dist/session/legacy-reset.d.ts.map +1 -0
- package/dist/session/legacy-reset.js +16 -0
- package/dist/session/nimbus-session.d.ts +41 -15
- package/dist/session/nimbus-session.d.ts.map +1 -1
- package/dist/session/nimbus-session.js +64 -70
- package/dist/session/npm-install-port.d.ts.map +1 -1
- package/dist/session/npm-install-port.js +1 -0
- package/dist/session/programmatic.d.ts +13 -18
- package/dist/session/programmatic.d.ts.map +1 -1
- package/dist/session/programmatic.js +53 -39
- package/dist/session/replica-routes.d.ts +2 -3
- package/dist/session/replica-routes.d.ts.map +1 -1
- package/dist/session/replica-routes.js +3 -10
- package/dist/session/routes.d.ts.map +1 -1
- package/dist/session/routes.js +7 -10
- package/dist/session/rpc.d.ts +104 -20
- package/dist/session/rpc.d.ts.map +1 -1
- package/dist/session/rpc.js +184 -37
- package/dist/session/start-real-vite.js +2 -2
- package/dist/session/state-store.d.ts +1 -17
- package/dist/session/state-store.d.ts.map +1 -1
- package/dist/session/state-store.js +3 -53
- package/dist/session/supervisor-op.d.ts +7 -0
- package/dist/session/supervisor-op.d.ts.map +1 -1
- package/dist/session/supervisor-op.js +6 -1
- package/dist/session/supervisor-rpc.d.ts +104 -15
- package/dist/session/supervisor-rpc.d.ts.map +1 -1
- package/dist/session/supervisor-rpc.js +188 -71
- package/dist/session/vite-command.d.ts.map +1 -1
- package/dist/session/vite-command.js +17 -14
- package/dist/session/ws.d.ts.map +1 -1
- package/dist/session/ws.js +20 -8
- package/dist/shell/npm-bin-entrypoints.d.ts.map +1 -1
- package/dist/shell/npm-bin-entrypoints.js +30 -5
- package/dist/vfs/facet-resident-limits.d.ts +33 -0
- package/dist/vfs/facet-resident-limits.d.ts.map +1 -0
- package/dist/vfs/facet-resident-limits.js +33 -0
- package/dist/vfs/facet-resident-store.d.ts +2 -10
- package/dist/vfs/facet-resident-store.d.ts.map +1 -1
- package/dist/vfs/facet-resident-store.js +1594 -219
- package/dist/workspace-host.d.ts +2 -0
- package/dist/workspace-host.d.ts.map +1 -1
- package/dist/workspace-host.js +2 -0
- package/dist/wrangler/nimbus-wrangler.d.ts +0 -2
- package/dist/wrangler/nimbus-wrangler.d.ts.map +1 -1
- package/dist/wrangler/nimbus-wrangler.js +5 -22
- package/package.json +8 -7
- package/public/_assets/opencode/1.16.2/index-attach.js +2 -2
- package/public/_assets/runtime/esbuild-cli-c4fda380d52befc1.js +6892 -0
- package/public/_assets/runtime/git-de3e60c9f3ff006a.js +103 -0
- package/public/_assets/runtime/{node-shims-7b4dd7a76d95d21e.js → node-shims-06565b121555c194.js} +2089 -861
- package/public/_assets/runtime/resident-store-6ffb1939c53d982f.js +2264 -0
- package/public/_assets/runtime/vfs-write-ledger-e501e8fc793bc2c1.js +889 -0
- package/scripts/build-opencode-attach-entry.mjs +51 -1
- package/scripts/bundle-facet-workers.mjs +114 -3
- package/scripts/bundle-git.mjs +88 -27
- package/scripts/bundle-node-shims.mjs +72 -46
- package/scripts/bundle-runtime.mjs +18 -421
- package/scripts/cf-git-patch.mjs +137 -0
- package/scripts/patch-install-deps.mjs +49 -96
- package/scripts/runtime-specs.mjs +435 -0
- package/vendor/git-http.generated.d.ts +82 -0
- package/vendor/git-upstream.generated.d.ts +4378 -0
- package/vendor/git.LICENSE +7 -0
- package/vendor/git.generated.d.mts +21 -0
- package/vendor/git.generated.mjs +103 -0
- package/dist/replica/suspension.d.ts +0 -36
- package/dist/replica/suspension.d.ts.map +0 -1
- package/dist/replica/suspension.js +0 -49
- package/dist/runtime/static-server.d.ts +0 -3
- package/dist/runtime/static-server.d.ts.map +0 -1
- package/dist/runtime/static-server.js +0 -133
- package/scripts/clean-dist.mjs +0 -7
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which file contents a resident node process holds from its first
|
|
3
|
+
* instruction, besides its module map.
|
|
4
|
+
*
|
|
5
|
+
* A synchronous read cannot wait for bytes, so whatever a process reads
|
|
6
|
+
* synchronously has to be in its facet before it runs; the namespace (every
|
|
7
|
+
* name and stat) is always there, content is not. This decides content by
|
|
8
|
+
* rule, from the namespace and the module closure, without reading file
|
|
9
|
+
* contents except a few package.json files:
|
|
10
|
+
*
|
|
11
|
+
* package-json every package.json
|
|
12
|
+
* project the working tree, minus dependency, VCS and build-cache dirs
|
|
13
|
+
* convention config and lockfile names in the working dir and above it
|
|
14
|
+
* package-data non-code files under 256 KiB in every package the closure uses
|
|
15
|
+
* home $HOME's dot entries (tool config, skills), minus caches
|
|
16
|
+
* typescript when the closure has typescript: its lib .d.ts, @types/**,
|
|
17
|
+
* and the declaration files of the packages @types depends on
|
|
18
|
+
* static what the closure's own code names by a foldable path
|
|
19
|
+
* (static-fs-refs.ts), resolved against the namespace:
|
|
20
|
+
* under 256 KiB, or any size when the code reads it with
|
|
21
|
+
* readFileSync (or a read-only openSync) by that path,
|
|
22
|
+
* through any symlinks on it
|
|
23
|
+
* learned paths earlier launches of the same package versions missed
|
|
24
|
+
*
|
|
25
|
+
* Code the closure loads is in the module map already; the store adopts it,
|
|
26
|
+
* so it is readable as data too.
|
|
27
|
+
*/
|
|
28
|
+
import type { StaticFsRefs } from '@nimbus-sh/core/runtime/static-fs-refs.js';
|
|
29
|
+
export interface DataPlanEntry {
|
|
30
|
+
path: string;
|
|
31
|
+
kind: string;
|
|
32
|
+
size: number;
|
|
33
|
+
linkTarget?: string;
|
|
34
|
+
}
|
|
35
|
+
export interface DataPlanSource {
|
|
36
|
+
/** One page of the namespace in path order; `next === null` ends it. */
|
|
37
|
+
list(after: string | null): Promise<{
|
|
38
|
+
entries: DataPlanEntry[];
|
|
39
|
+
next: string | null;
|
|
40
|
+
}>;
|
|
41
|
+
/** A file's text, or null when it cannot be read. */
|
|
42
|
+
readText(path: string): Promise<string | null>;
|
|
43
|
+
/** A symlink's target as stored, or null when the path is not a symlink. */
|
|
44
|
+
readlink(path: string): Promise<string | null>;
|
|
45
|
+
/** What is at a path, following symlinks, or null. */
|
|
46
|
+
stat(path: string): Promise<{
|
|
47
|
+
kind: string;
|
|
48
|
+
size: number;
|
|
49
|
+
} | null>;
|
|
50
|
+
}
|
|
51
|
+
export interface DataPlanInput {
|
|
52
|
+
cwd: string;
|
|
53
|
+
home: string;
|
|
54
|
+
/** Module map paths. */
|
|
55
|
+
closure: Iterable<string>;
|
|
56
|
+
refs: readonly StaticFsRefs[];
|
|
57
|
+
/** Paths learned from earlier misses (absolute or keys). */
|
|
58
|
+
learned?: Iterable<string>;
|
|
59
|
+
/** Called with the bytes of each listed page, to pace a long walk. */
|
|
60
|
+
spend?: (units: number) => Promise<void>;
|
|
61
|
+
}
|
|
62
|
+
export type DataPlanRule = 'package-json' | 'project' | 'convention' | 'package-data' | 'home' | 'typescript' | 'static' | 'learned';
|
|
63
|
+
export interface DataPlan {
|
|
64
|
+
paths: string[];
|
|
65
|
+
bytes: number;
|
|
66
|
+
rules: Record<DataPlanRule, {
|
|
67
|
+
files: number;
|
|
68
|
+
bytes: number;
|
|
69
|
+
}>;
|
|
70
|
+
}
|
|
71
|
+
/** Package data this size or larger is a bundle or a binary, not configuration. */
|
|
72
|
+
export declare const PACKAGE_DATA_MAX_BYTES: number;
|
|
73
|
+
/** The package directory a path sits in: up to the name after its last node_modules. */
|
|
74
|
+
export declare function packageRootOf(k: string): string | null;
|
|
75
|
+
/**
|
|
76
|
+
* The plan for one launch. Walks the namespace once, in pages.
|
|
77
|
+
*/
|
|
78
|
+
export declare function planFacetData(source: DataPlanSource, input: DataPlanInput): Promise<DataPlan>;
|
|
79
|
+
//# sourceMappingURL=data-plan.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-plan.d.ts","sourceRoot":"","sources":["../../src/facets/data-plan.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2CAA2C,CAAC;AAE9E,MAAM,WAAW,aAAa;IAAG,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE;AAEhG,MAAM,WAAW,cAAc;IAC7B,wEAAwE;IACxE,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,aAAa,EAAE,CAAC;QAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC,CAAC;IACvF,qDAAqD;IACrD,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC/C,4EAA4E;IAC5E,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC/C,sDAAsD;IACtD,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC,CAAC;CACpE;AAED,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,wBAAwB;IACxB,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC1B,IAAI,EAAE,SAAS,YAAY,EAAE,CAAC;IAC9B,4DAA4D;IAC5D,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC3B,sEAAsE;IACtE,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1C;AAED,MAAM,MAAM,YAAY,GACpB,cAAc,GAAG,SAAS,GAAG,YAAY,GAAG,cAAc,GAAG,MAAM,GAAG,YAAY,GAAG,QAAQ,GAAG,SAAS,CAAC;AAE9G,MAAM,WAAW,QAAQ;IACvB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC,YAAY,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAC/D;AAED,mFAAmF;AACnF,eAAO,MAAM,sBAAsB,QAAa,CAAC;AAkCjD,wFAAwF;AACxF,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAOtD;AA0GD;;GAEG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE,cAAc,EAAE,KAAK,EAAE,aAAa,GAAG,OAAO,CAAC,QAAQ,CAAC,CAiQnG"}
|
|
@@ -0,0 +1,477 @@
|
|
|
1
|
+
/** Package data this size or larger is a bundle or a binary, not configuration. */
|
|
2
|
+
export const PACKAGE_DATA_MAX_BYTES = 256 * 1024;
|
|
3
|
+
const CODE_FILE = /\.(?:c|m)?(?:j|t)sx?$|\.map$|\.d\.(?:c|m)?ts$|\.node$|\.wasm$/;
|
|
4
|
+
const DECLARATION_FILE = /\.d\.(?:c|m)?ts$/;
|
|
5
|
+
/** Directory names whose contents are dependencies, VCS state or regenerable caches. */
|
|
6
|
+
const PROJECT_EXCLUDED = new Set([
|
|
7
|
+
'node_modules', '.git', '.hg', '.svn', '.nimbus', '.next', '.nuxt', '.output', '.astro',
|
|
8
|
+
'.svelte-kit', '.turbo', '.cache', '.parcel-cache', '.vite', '.vercel', '.wrangler', 'coverage',
|
|
9
|
+
]);
|
|
10
|
+
/** $HOME-relative caches: package stores and regenerable state, not configuration. */
|
|
11
|
+
const HOME_EXCLUDED = [
|
|
12
|
+
'.cache/', '.npm/', '.bun/install/', '.nimbus/', '.pnpm-store/', '.yarn/cache/', '.yarn/berry/', '.node-gyp/',
|
|
13
|
+
'.local/share/pnpm/', '.local/state/',
|
|
14
|
+
];
|
|
15
|
+
const CONVENTION = [
|
|
16
|
+
/^package\.json$/, /^(?:ts|js)config(?:\..*)?\.json$/, /^\.env(?:\..*)?$/, /^\.npmrc$/, /^\.nvmrc$/,
|
|
17
|
+
/\.config\.(?:c|m)?(?:j|t)s$/, /\.config\.json$/, /^\.[\w-]+rc(?:\.(?:json|js|cjs|mjs|ya?ml|toml))?$/,
|
|
18
|
+
/^(?:package-lock\.json|pnpm-lock\.yaml|pnpm-workspace\.yaml|yarn\.lock|bun\.lockb?|\.package-lock\.json|\.modules\.yaml)$/,
|
|
19
|
+
/^\.browserslistrc$/, /^\.editorconfig$/, /^\.gitignore$/,
|
|
20
|
+
];
|
|
21
|
+
function key(path) {
|
|
22
|
+
return path.replace(/^\/+/, '').replace(/\/+$/, '');
|
|
23
|
+
}
|
|
24
|
+
function parentOf(k) {
|
|
25
|
+
const i = k.lastIndexOf('/');
|
|
26
|
+
return i < 0 ? '' : k.slice(0, i);
|
|
27
|
+
}
|
|
28
|
+
function baseOf(k) {
|
|
29
|
+
return k.slice(k.lastIndexOf('/') + 1);
|
|
30
|
+
}
|
|
31
|
+
/** The package directory a path sits in: up to the name after its last node_modules. */
|
|
32
|
+
export function packageRootOf(k) {
|
|
33
|
+
const at = k.lastIndexOf('node_modules/');
|
|
34
|
+
if (at < 0)
|
|
35
|
+
return null;
|
|
36
|
+
const rest = k.slice(at + 'node_modules/'.length).split('/');
|
|
37
|
+
const take = rest[0]?.startsWith('@') ? 2 : 1;
|
|
38
|
+
if (rest.length <= take)
|
|
39
|
+
return null;
|
|
40
|
+
return k.slice(0, at) + 'node_modules/' + rest.slice(0, take).join('/');
|
|
41
|
+
}
|
|
42
|
+
function joinKey(base, rel) {
|
|
43
|
+
const out = base ? base.split('/') : [];
|
|
44
|
+
for (const seg of rel.split('/')) {
|
|
45
|
+
if (seg === '' || seg === '.')
|
|
46
|
+
continue;
|
|
47
|
+
if (seg === '..')
|
|
48
|
+
out.pop();
|
|
49
|
+
else
|
|
50
|
+
out.push(seg);
|
|
51
|
+
}
|
|
52
|
+
return out.join('/');
|
|
53
|
+
}
|
|
54
|
+
/** One `exports` target: a string, or the first usable branch of a conditions object. */
|
|
55
|
+
function exportTarget(value) {
|
|
56
|
+
if (typeof value === 'string')
|
|
57
|
+
return value;
|
|
58
|
+
if (Array.isArray(value)) {
|
|
59
|
+
for (const v of value) {
|
|
60
|
+
const t = exportTarget(v);
|
|
61
|
+
if (t)
|
|
62
|
+
return t;
|
|
63
|
+
}
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
if (value && typeof value === 'object') {
|
|
67
|
+
for (const cond of ['node', 'import', 'module', 'default', 'require']) {
|
|
68
|
+
if (cond in value) {
|
|
69
|
+
const t = exportTarget(value[cond]);
|
|
70
|
+
if (t)
|
|
71
|
+
return t;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
/** Map `./sub` through a package.json `exports` field; null when it does not export it. */
|
|
78
|
+
function mapExports(exportsField, sub) {
|
|
79
|
+
if (typeof exportsField !== 'object' || exportsField === null || Array.isArray(exportsField)) {
|
|
80
|
+
return sub === '.' ? exportTarget(exportsField) : null;
|
|
81
|
+
}
|
|
82
|
+
const table = exportsField;
|
|
83
|
+
if (!Object.keys(table).some((k) => k.startsWith('.')))
|
|
84
|
+
return sub === '.' ? exportTarget(table) : null;
|
|
85
|
+
if (sub in table)
|
|
86
|
+
return exportTarget(table[sub]);
|
|
87
|
+
let best = null;
|
|
88
|
+
for (const [pattern, target] of Object.entries(table)) {
|
|
89
|
+
const star = pattern.indexOf('*');
|
|
90
|
+
if (star < 0)
|
|
91
|
+
continue;
|
|
92
|
+
const prefix = pattern.slice(0, star);
|
|
93
|
+
const suffix = pattern.slice(star + 1);
|
|
94
|
+
if (!sub.startsWith(prefix) || !sub.endsWith(suffix) || sub.length < prefix.length + suffix.length)
|
|
95
|
+
continue;
|
|
96
|
+
if (!best || prefix.length > best.prefix.length)
|
|
97
|
+
best = { prefix, suffix, target };
|
|
98
|
+
}
|
|
99
|
+
if (!best)
|
|
100
|
+
return null;
|
|
101
|
+
const t = exportTarget(best.target);
|
|
102
|
+
if (!t)
|
|
103
|
+
return null;
|
|
104
|
+
return t.replaceAll('*', sub.slice(best.prefix.length, sub.length - best.suffix.length));
|
|
105
|
+
}
|
|
106
|
+
async function resolveSpecifier(source, fromDir, spec, manifests) {
|
|
107
|
+
const parts = spec.split('/');
|
|
108
|
+
const nameLen = spec.startsWith('@') ? 2 : 1;
|
|
109
|
+
if (parts.length < nameLen)
|
|
110
|
+
return null;
|
|
111
|
+
const name = parts.slice(0, nameLen).join('/');
|
|
112
|
+
const sub = parts.slice(nameLen).join('/');
|
|
113
|
+
for (let dir = fromDir;; dir = parentOf(dir)) {
|
|
114
|
+
if (baseOf(dir) !== 'node_modules') {
|
|
115
|
+
const pkgDir = joinKey(dir, 'node_modules/' + name);
|
|
116
|
+
let manifest = manifests.get(pkgDir);
|
|
117
|
+
if (manifest === undefined) {
|
|
118
|
+
const text = await source.readText(pkgDir + '/package.json');
|
|
119
|
+
try {
|
|
120
|
+
manifest = text === null ? null : JSON.parse(text);
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
manifest = null;
|
|
124
|
+
}
|
|
125
|
+
manifests.set(pkgDir, manifest);
|
|
126
|
+
}
|
|
127
|
+
if (manifest) {
|
|
128
|
+
const mapped = manifest.exports !== undefined ? mapExports(manifest.exports, sub ? './' + sub : '.') : null;
|
|
129
|
+
if (mapped)
|
|
130
|
+
return joinKey(pkgDir, mapped);
|
|
131
|
+
return sub ? joinKey(pkgDir, sub) : null;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (dir === '')
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/** Symlinks a lookup follows before it gives up (Linux's MAXSYMLINKS). */
|
|
139
|
+
const MAX_LINK_HOPS = 40;
|
|
140
|
+
/**
|
|
141
|
+
* A key with every symlink along it replaced by its target, as a lookup
|
|
142
|
+
* resolves it, asking the source one component at a time; null past
|
|
143
|
+
* MAX_LINK_HOPS (ELOOP).
|
|
144
|
+
*/
|
|
145
|
+
async function throughLinks(source, k) {
|
|
146
|
+
let path = k;
|
|
147
|
+
for (let hops = 0; hops <= MAX_LINK_HOPS; hops++) {
|
|
148
|
+
const segs = path.split('/');
|
|
149
|
+
let followed = false;
|
|
150
|
+
for (let i = 1; i <= segs.length; i++) {
|
|
151
|
+
const at = segs.slice(0, i).join('/');
|
|
152
|
+
const target = await source.readlink('/' + at);
|
|
153
|
+
if (target === null)
|
|
154
|
+
continue;
|
|
155
|
+
const base = target.startsWith('/') ? key(target) : joinKey(parentOf(at), target);
|
|
156
|
+
path = joinKey(base, segs.slice(i).join('/'));
|
|
157
|
+
followed = true;
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
if (!followed)
|
|
161
|
+
return path;
|
|
162
|
+
}
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* The plan for one launch. Walks the namespace once, in pages.
|
|
167
|
+
*/
|
|
168
|
+
export async function planFacetData(source, input) {
|
|
169
|
+
const cwd = key(input.cwd);
|
|
170
|
+
const home = key(input.home);
|
|
171
|
+
const cwdPrefix = cwd ? cwd + '/' : '';
|
|
172
|
+
const homeDot = home ? home + '/.' : '.';
|
|
173
|
+
const closureRoots = new Set();
|
|
174
|
+
let typescriptRoot = null;
|
|
175
|
+
for (const path of input.closure) {
|
|
176
|
+
const root = packageRootOf(key(path));
|
|
177
|
+
if (root === null)
|
|
178
|
+
continue;
|
|
179
|
+
closureRoots.add(root);
|
|
180
|
+
if (typescriptRoot === null && root.endsWith('node_modules/typescript'))
|
|
181
|
+
typescriptRoot = root;
|
|
182
|
+
}
|
|
183
|
+
const conventionDirs = new Set([joinKey(cwd, 'node_modules')]);
|
|
184
|
+
for (let d = cwd;; d = parentOf(d)) {
|
|
185
|
+
conventionDirs.add(d);
|
|
186
|
+
if (d === '')
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
const closure = new Set();
|
|
190
|
+
for (const path of input.closure)
|
|
191
|
+
closure.add(key(path));
|
|
192
|
+
// Static references, as keys: each exact path, and whether any site reads
|
|
193
|
+
// it synchronously.
|
|
194
|
+
const exact = new Map();
|
|
195
|
+
const note = (k, sync) => exact.set(k, exact.get(k) === true || sync);
|
|
196
|
+
const listed = new Set();
|
|
197
|
+
const patterns = [];
|
|
198
|
+
const manifests = new Map();
|
|
199
|
+
for (const refs of input.refs) {
|
|
200
|
+
for (const r of refs.exact)
|
|
201
|
+
note(key(r.path), r.sync);
|
|
202
|
+
for (const r of refs.cwdRelative)
|
|
203
|
+
note(joinKey(cwd, r.path), r.sync);
|
|
204
|
+
for (const p of refs.listed)
|
|
205
|
+
listed.add(key(p));
|
|
206
|
+
for (const p of refs.patterns)
|
|
207
|
+
patterns.push({ dir: key(p.dir), prefix: p.prefix, suffix: p.suffix });
|
|
208
|
+
}
|
|
209
|
+
const learned = new Set();
|
|
210
|
+
for (const p of input.learned ?? [])
|
|
211
|
+
learned.add(key(p));
|
|
212
|
+
const rules = Object.fromEntries(['package-json', 'project', 'convention', 'package-data', 'home', 'typescript', 'static', 'learned']
|
|
213
|
+
.map((r) => [r, { files: 0, bytes: 0 }]));
|
|
214
|
+
const paths = [];
|
|
215
|
+
const planned = new Set();
|
|
216
|
+
let bytes = 0;
|
|
217
|
+
const take = (entry, rule) => {
|
|
218
|
+
if (planned.has(entry.path))
|
|
219
|
+
return;
|
|
220
|
+
planned.add(entry.path);
|
|
221
|
+
paths.push(entry.path);
|
|
222
|
+
bytes += entry.size;
|
|
223
|
+
rules[rule].files++;
|
|
224
|
+
rules[rule].bytes += entry.size;
|
|
225
|
+
};
|
|
226
|
+
// Directories a reference expands to: a listed directory.
|
|
227
|
+
const expanded = new Set();
|
|
228
|
+
const underExpanded = (k) => {
|
|
229
|
+
for (let d = parentOf(k); d !== ''; d = parentOf(d)) {
|
|
230
|
+
if (expanded.has(d))
|
|
231
|
+
return true;
|
|
232
|
+
if (baseOf(d) === 'node_modules')
|
|
233
|
+
return false;
|
|
234
|
+
}
|
|
235
|
+
return false;
|
|
236
|
+
};
|
|
237
|
+
const homeKept = (k) => {
|
|
238
|
+
const rel = k.slice(home ? home.length + 1 : 0) + '/';
|
|
239
|
+
return !HOME_EXCLUDED.some((prefix) => rel.startsWith(prefix));
|
|
240
|
+
};
|
|
241
|
+
/**
|
|
242
|
+
* Whether a file lies in a dependency, VCS or cache directory below `dir`,
|
|
243
|
+
* or in a cache of the home directory it is in ($HOME, or /home/<user>).
|
|
244
|
+
*/
|
|
245
|
+
const excludedBelow = (dir, k) => {
|
|
246
|
+
const rel = k.slice(dir === '' ? 0 : dir.length + 1).split('/');
|
|
247
|
+
if (rel.slice(0, -1).some((seg) => PROJECT_EXCLUDED.has(seg)))
|
|
248
|
+
return true;
|
|
249
|
+
const segs = k.split('/');
|
|
250
|
+
const userHome = home !== '' && k.startsWith(home + '/') ? home
|
|
251
|
+
: segs[0] === 'home' && segs.length > 2 ? 'home/' + segs[1] : null;
|
|
252
|
+
if (userHome === null)
|
|
253
|
+
return false;
|
|
254
|
+
const inHome = k.slice(userHome.length + 1) + '/';
|
|
255
|
+
return HOME_EXCLUDED.some((prefix) => inHome.startsWith(prefix));
|
|
256
|
+
};
|
|
257
|
+
/**
|
|
258
|
+
* Whether a file is one a pattern `dir/prefix*suffix` can name. A hole with
|
|
259
|
+
* a known prefix or suffix fills one name in `dir`: a file there, or the
|
|
260
|
+
* files directly in a directory there. A bare hole under a
|
|
261
|
+
* named directory (`join(dir, x)`) may be a relative path of any depth: the
|
|
262
|
+
* directory's files, minus dependency, VCS and cache directories. A bare
|
|
263
|
+
* hole at the root (`'/' + x`) names the whole filesystem, which nothing
|
|
264
|
+
* static bounds: it matches nothing and the read is a run-time one.
|
|
265
|
+
*/
|
|
266
|
+
const patternMatch = (k) => {
|
|
267
|
+
const dir = parentOf(k);
|
|
268
|
+
const name = baseOf(k);
|
|
269
|
+
for (const p of patterns) {
|
|
270
|
+
if (p.prefix === '' && p.suffix === '') {
|
|
271
|
+
if (p.dir !== '' && k.startsWith(p.dir + '/') && !excludedBelow(p.dir, k))
|
|
272
|
+
return true;
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
const named = (n) => n.startsWith(p.prefix) && n.endsWith(p.suffix) && n.length >= p.prefix.length + p.suffix.length;
|
|
276
|
+
if (p.dir === dir && named(name))
|
|
277
|
+
return true;
|
|
278
|
+
// A matched name may be a directory the code lists: its own files, one level.
|
|
279
|
+
if (dir !== '' && p.dir === parentOf(dir) && named(baseOf(dir)) && !excludedBelow(p.dir, k))
|
|
280
|
+
return true;
|
|
281
|
+
}
|
|
282
|
+
return false;
|
|
283
|
+
};
|
|
284
|
+
const declarations = [];
|
|
285
|
+
const packageRoots = new Set();
|
|
286
|
+
// Directories a home or project symlink points at, whose files the rule
|
|
287
|
+
// that took the link would have taken had they been in place.
|
|
288
|
+
const linkedDirs = [];
|
|
289
|
+
/**
|
|
290
|
+
* A statically named file is worth holding when the module map does not
|
|
291
|
+
* already hold it, and it is data-sized or the code reads it synchronously
|
|
292
|
+
* by that name: such a read cannot wait for bytes of any size. Its bytes
|
|
293
|
+
* count toward the plan's storage, which the launch admits or refuses.
|
|
294
|
+
*/
|
|
295
|
+
/** Sync-read paths the walk found as files under their own name. */
|
|
296
|
+
const seenFiles = new Set();
|
|
297
|
+
const staticWorthy = (entry) => !closure.has(entry.path)
|
|
298
|
+
&& (entry.size < PACKAGE_DATA_MAX_BYTES || exact.get(entry.path) === true);
|
|
299
|
+
let after = null;
|
|
300
|
+
for (;;) {
|
|
301
|
+
const page = await source.list(after);
|
|
302
|
+
if (input.spend)
|
|
303
|
+
await input.spend(page.entries.length * 64);
|
|
304
|
+
for (const raw of page.entries) {
|
|
305
|
+
const k = key(raw.path);
|
|
306
|
+
const entry = { path: k, kind: raw.kind, size: raw.size };
|
|
307
|
+
if (entry.kind === 'directory') {
|
|
308
|
+
if (listed.has(k))
|
|
309
|
+
expanded.add(k);
|
|
310
|
+
if (packageRootOf(k + '/x') === k)
|
|
311
|
+
packageRoots.add(k);
|
|
312
|
+
continue;
|
|
313
|
+
}
|
|
314
|
+
const segs = k.split('/');
|
|
315
|
+
if (entry.kind === 'symlink') {
|
|
316
|
+
if (raw.linkTarget === undefined)
|
|
317
|
+
continue;
|
|
318
|
+
const inProject = (cwdPrefix === '' || k.startsWith(cwdPrefix))
|
|
319
|
+
&& !(cwdPrefix === '' ? segs : k.slice(cwdPrefix.length).split('/')).slice(0, -1).some((x) => PROJECT_EXCLUDED.has(x));
|
|
320
|
+
const inHome = k.startsWith(homeDot) && homeKept(k) && !segs.includes('node_modules');
|
|
321
|
+
if (inProject || inHome) {
|
|
322
|
+
const target = raw.linkTarget.startsWith('/') ? key(raw.linkTarget) : joinKey(parentOf(k), raw.linkTarget);
|
|
323
|
+
linkedDirs.push({ target, rule: inProject ? 'project' : 'home' });
|
|
324
|
+
}
|
|
325
|
+
continue;
|
|
326
|
+
}
|
|
327
|
+
if (entry.kind !== 'file')
|
|
328
|
+
continue;
|
|
329
|
+
if (exact.get(k) === true)
|
|
330
|
+
seenFiles.add(k);
|
|
331
|
+
const name = baseOf(k);
|
|
332
|
+
if (name === 'package.json' && !segs.includes('.git')) {
|
|
333
|
+
take(entry, 'package-json');
|
|
334
|
+
continue;
|
|
335
|
+
}
|
|
336
|
+
if (cwdPrefix === '' || k.startsWith(cwdPrefix)) {
|
|
337
|
+
const rel = cwdPrefix === '' ? segs : k.slice(cwdPrefix.length).split('/');
|
|
338
|
+
if (!rel.slice(0, -1).some((s) => PROJECT_EXCLUDED.has(s))) {
|
|
339
|
+
take(entry, 'project');
|
|
340
|
+
continue;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
if (conventionDirs.has(parentOf(k)) && CONVENTION.some((re) => re.test(name))) {
|
|
344
|
+
take(entry, 'convention');
|
|
345
|
+
continue;
|
|
346
|
+
}
|
|
347
|
+
const root = packageRootOf(k);
|
|
348
|
+
if (root !== null && closureRoots.has(root) && !CODE_FILE.test(name) && entry.size < PACKAGE_DATA_MAX_BYTES
|
|
349
|
+
&& !k.slice(root.length + 1).includes('node_modules/')) {
|
|
350
|
+
take(entry, 'package-data');
|
|
351
|
+
continue;
|
|
352
|
+
}
|
|
353
|
+
if (k.startsWith(homeDot) && homeKept(k) && !segs.includes('node_modules') && !segs.includes('.git')) {
|
|
354
|
+
take(entry, 'home');
|
|
355
|
+
continue;
|
|
356
|
+
}
|
|
357
|
+
if (typescriptRoot !== null) {
|
|
358
|
+
if (root === typescriptRoot && parentOf(k) === typescriptRoot + '/lib' && /^lib\..*\.d\.ts$/.test(name)) {
|
|
359
|
+
take(entry, 'typescript');
|
|
360
|
+
continue;
|
|
361
|
+
}
|
|
362
|
+
if (k.includes('node_modules/@types/')) {
|
|
363
|
+
take(entry, 'typescript');
|
|
364
|
+
continue;
|
|
365
|
+
}
|
|
366
|
+
if (root !== null && DECLARATION_FILE.test(name))
|
|
367
|
+
declarations.push(entry);
|
|
368
|
+
}
|
|
369
|
+
if ((exact.has(k) || listed.has(parentOf(k)) || patternMatch(k) || underExpanded(k)) && staticWorthy(entry)) {
|
|
370
|
+
take(entry, 'static');
|
|
371
|
+
continue;
|
|
372
|
+
}
|
|
373
|
+
if (learned.has(k)) {
|
|
374
|
+
take(entry, 'learned');
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
if (page.next === null)
|
|
379
|
+
break;
|
|
380
|
+
after = page.next;
|
|
381
|
+
}
|
|
382
|
+
// What @types depends on (undici-types for @types/node): their declarations.
|
|
383
|
+
if (typescriptRoot !== null && declarations.length > 0) {
|
|
384
|
+
const typeDeps = new Set();
|
|
385
|
+
const typesRoots = new Set();
|
|
386
|
+
for (const p of paths) {
|
|
387
|
+
if (!p.endsWith('/package.json') || !p.includes('node_modules/@types/'))
|
|
388
|
+
continue;
|
|
389
|
+
const root = packageRootOf(p);
|
|
390
|
+
if (root !== null && root + '/package.json' === p)
|
|
391
|
+
typesRoots.add(root);
|
|
392
|
+
}
|
|
393
|
+
for (const root of typesRoots) {
|
|
394
|
+
const text = await source.readText(root + '/package.json');
|
|
395
|
+
try {
|
|
396
|
+
const deps = JSON.parse(text ?? '{}').dependencies ?? {};
|
|
397
|
+
for (const dep of Object.keys(deps))
|
|
398
|
+
typeDeps.add(dep);
|
|
399
|
+
}
|
|
400
|
+
catch { /* not a manifest */ }
|
|
401
|
+
}
|
|
402
|
+
for (const entry of declarations) {
|
|
403
|
+
const root = packageRootOf(entry.path);
|
|
404
|
+
const name = root.slice(root.lastIndexOf('node_modules/') + 'node_modules/'.length);
|
|
405
|
+
if (typeDeps.has(name))
|
|
406
|
+
take(entry, 'typescript');
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
// A synchronous read of a path through a symlink reads the file the link
|
|
410
|
+
// leads to, which the walk saw under its own name: hold that file. Only
|
|
411
|
+
// such a read's own path is resolved, one component at a time; the
|
|
412
|
+
// namespace's links are never collected.
|
|
413
|
+
for (const [k, sync] of exact) {
|
|
414
|
+
if (!sync || planned.has(k) || seenFiles.has(k))
|
|
415
|
+
continue;
|
|
416
|
+
const target = await throughLinks(source, k);
|
|
417
|
+
if (target === null || target === k || planned.has(target))
|
|
418
|
+
continue;
|
|
419
|
+
const found = await source.stat(target);
|
|
420
|
+
if (found === null || found.kind !== 'file')
|
|
421
|
+
continue;
|
|
422
|
+
const entry = { path: target, kind: 'file', size: found.size };
|
|
423
|
+
if (!closure.has(target))
|
|
424
|
+
take(entry, 'static');
|
|
425
|
+
}
|
|
426
|
+
// Specifiers resolve through package.json files, so only those whose
|
|
427
|
+
// package exists are looked up.
|
|
428
|
+
for (const refs of input.refs) {
|
|
429
|
+
for (const r of refs.resolves) {
|
|
430
|
+
const name = r.spec.split('/').slice(0, r.spec.startsWith('@') ? 2 : 1).join('/');
|
|
431
|
+
let exists = false;
|
|
432
|
+
for (let d = key(r.from); !exists; d = parentOf(d)) {
|
|
433
|
+
if (packageRoots.has(joinKey(d, 'node_modules/' + name)))
|
|
434
|
+
exists = true;
|
|
435
|
+
if (d === '')
|
|
436
|
+
break;
|
|
437
|
+
}
|
|
438
|
+
if (!exists)
|
|
439
|
+
continue;
|
|
440
|
+
const resolved = await resolveSpecifier(source, key(r.from), r.spec, manifests);
|
|
441
|
+
if (resolved === null || planned.has(resolved))
|
|
442
|
+
continue;
|
|
443
|
+
const found = await source.stat(resolved);
|
|
444
|
+
if (found === null || found.kind !== 'file')
|
|
445
|
+
continue;
|
|
446
|
+
const entry = { path: resolved, kind: 'file', size: found.size };
|
|
447
|
+
if (staticWorthy(entry))
|
|
448
|
+
take(entry, 'static');
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
// The files behind symlinked directories the project or home rule reached.
|
|
452
|
+
if (linkedDirs.length > 0) {
|
|
453
|
+
after = null;
|
|
454
|
+
for (;;) {
|
|
455
|
+
const page = await source.list(after);
|
|
456
|
+
if (input.spend)
|
|
457
|
+
await input.spend(page.entries.length * 64);
|
|
458
|
+
for (const raw of page.entries) {
|
|
459
|
+
if (raw.kind !== 'file')
|
|
460
|
+
continue;
|
|
461
|
+
const k = key(raw.path);
|
|
462
|
+
for (const { target, rule } of linkedDirs) {
|
|
463
|
+
if (k === target || k.startsWith(target + '/')) {
|
|
464
|
+
if (!k.slice(target.length).split('/').some((x) => x === 'node_modules' || x === '.git')) {
|
|
465
|
+
take({ path: k, kind: 'file', size: raw.size }, rule);
|
|
466
|
+
}
|
|
467
|
+
break;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
if (page.next === null)
|
|
472
|
+
break;
|
|
473
|
+
after = page.next;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
return { paths, bytes, rules };
|
|
477
|
+
}
|
|
@@ -1,14 +1,40 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import type {
|
|
1
|
+
import { EsbuildService, type EsbuildBuildHost, type EsbuildTransformHost } from '@nimbus-sh/core/runtime/esbuild-service.js';
|
|
2
|
+
import type { EsbuildCliArgs, EsbuildCliOutput } from '@nimbus-sh/core/runtime/esbuild-cli.js';
|
|
3
3
|
import type { WorkerCode } from '@nimbus-sh/fabric/vendor/types.js';
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
transform(code: string, options: EsbuildTransformOptions): Promise<TransformResult>;
|
|
7
|
-
};
|
|
4
|
+
import type { NamespaceFs } from '@nimbus-sh/core/runtime/process-files.js';
|
|
5
|
+
export declare const ESBUILD_FACET_WORKER_ID: string;
|
|
8
6
|
/**
|
|
9
|
-
* Slim Worker Loader module whose DO class owns the esbuild wasm
|
|
10
|
-
* `jsFnBody` is the staged adapter (fetchEsbuildJsFnBody),
|
|
11
|
-
*
|
|
7
|
+
* Slim Worker Loader module whose DO class owns the esbuild wasm.
|
|
8
|
+
* `jsFnBody` is the staged adapter (fetchEsbuildJsFnBody), compiled into a
|
|
9
|
+
* factory at startup, the one moment code may be generated from a string;
|
|
10
|
+
* each call of the factory is a separate esbuild. `cliRunner` is the staged
|
|
11
|
+
* runner of the `esbuild` command (fetchEsbuildCliRunner).
|
|
12
12
|
*/
|
|
13
|
-
export declare function
|
|
13
|
+
export declare function esbuildFacetWorkerCode(wasmBytes: ArrayBuffer, jsFnBody: string, cliRunner: string): WorkerCode;
|
|
14
|
+
/**
|
|
15
|
+
* The transform host a Durable Object's esbuild runs its transforms on: its
|
|
16
|
+
* esbuild facet, a slice per call. Transforms are pure, so a slice whose call
|
|
17
|
+
* failed (the facet reset, the connection dropped) is sent once more, to a
|
|
18
|
+
* freshly minted stub; an overloaded facet is not asked again. A slice that
|
|
19
|
+
* still fails answers each of its requests with a transient error, which is
|
|
20
|
+
* no verdict on the source, and the other slices keep their answers.
|
|
21
|
+
*/
|
|
22
|
+
export declare function esbuildTransformHost(ctx: DurableObjectState, env: unknown): EsbuildTransformHost;
|
|
23
|
+
/**
|
|
24
|
+
* The build host a Durable Object's esbuild runs its builds on: its esbuild
|
|
25
|
+
* facet. The plugin, and with it every file read, stays with the caller.
|
|
26
|
+
*/
|
|
27
|
+
export declare function esbuildBuildHost(ctx: DurableObjectState, env: unknown): EsbuildBuildHost;
|
|
28
|
+
/**
|
|
29
|
+
* Runs one `esbuild` command in the Durable Object's esbuild facet, as
|
|
30
|
+
* process `pid`: its files go through a supervisor capability minted for that
|
|
31
|
+
* pid, the one IsolatePool mints for a facet, and its stdout and stderr come
|
|
32
|
+
* back through `output` as esbuild writes them. Resolves to its exit status.
|
|
33
|
+
*/
|
|
34
|
+
export declare function runEsbuildCli(ctx: DurableObjectState, env: unknown, pid: number, args: EsbuildCliArgs, output: EsbuildCliOutput): Promise<number>;
|
|
35
|
+
/**
|
|
36
|
+
* The esbuild a Durable Object's supervisor shares: its transforms and its
|
|
37
|
+
* builds run in its esbuild facet, and build() reads `vfs` from here.
|
|
38
|
+
*/
|
|
39
|
+
export declare function supervisorEsbuildService(ctx: DurableObjectState, env: unknown, vfs: NamespaceFs): EsbuildService;
|
|
14
40
|
//# sourceMappingURL=esbuild-transform.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"esbuild-transform.d.ts","sourceRoot":"","sources":["../../src/facets/esbuild-transform.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"esbuild-transform.d.ts","sourceRoot":"","sources":["../../src/facets/esbuild-transform.ts"],"names":[],"mappings":"AACA,OAAO,EACL,cAAc,EAEd,KAAK,gBAAgB,EAIrB,KAAK,oBAAoB,EAG1B,MAAM,4CAA4C,CAAC;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAC;AAS/F,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AAIpE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0CAA0C,CAAC;AAwD5E,eAAO,MAAM,uBAAuB,QAAqG,CAAC;AAW1I;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,UAAU,CAoB9G;AAqED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,kBAAkB,EAAE,GAAG,EAAE,OAAO,GAAG,oBAAoB,CAmChG;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,kBAAkB,EAAE,GAAG,EAAE,OAAO,GAAG,gBAAgB,CAIxF;AAED;;;;;GAKG;AACH,wBAAsB,aAAa,CACjC,GAAG,EAAE,kBAAkB,EACvB,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,cAAc,EACpB,MAAM,EAAE,gBAAgB,GACvB,OAAO,CAAC,MAAM,CAAC,CAOjB;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,kBAAkB,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,WAAW,GAAG,cAAc,CAKhH"}
|