@nodetool-ai/sandbox-compiler 0.8.1
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/README.md +80 -0
- package/dist/.nodetool-build-stamp +1 -0
- package/dist/bundle.d.ts +70 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +252 -0
- package/dist/bundle.js.map +1 -0
- package/dist/cache.d.ts +115 -0
- package/dist/cache.d.ts.map +1 -0
- package/dist/cache.js +290 -0
- package/dist/cache.js.map +1 -0
- package/dist/catalog.d.ts +41 -0
- package/dist/catalog.d.ts.map +1 -0
- package/dist/catalog.js +0 -0
- package/dist/catalog.js.map +1 -0
- package/dist/compile.d.ts +29 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +128 -0
- package/dist/compile.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/options.d.ts +62 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/options.js +62 -0
- package/dist/options.js.map +1 -0
- package/dist/probe.d.ts +23 -0
- package/dist/probe.d.ts.map +1 -0
- package/dist/probe.js +118 -0
- package/dist/probe.js.map +1 -0
- package/dist/scan.d.ts +34 -0
- package/dist/scan.d.ts.map +1 -0
- package/dist/scan.js +378 -0
- package/dist/scan.js.map +1 -0
- package/package.json +84 -0
package/README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# @nodetool-ai/sandbox-compiler
|
|
2
|
+
|
|
3
|
+
Turns a sandbox pack's npm dependency into a guest module.
|
|
4
|
+
|
|
5
|
+
A pack does not have to author code for the QuickJS guest. It can point at an
|
|
6
|
+
npm dependency instead:
|
|
7
|
+
|
|
8
|
+
```jsonc
|
|
9
|
+
{
|
|
10
|
+
"name": "@acme/sandbox-yaml",
|
|
11
|
+
"dependencies": { "js-yaml": "^4.1.0" },
|
|
12
|
+
"nodetool": {
|
|
13
|
+
"apiVersion": 1,
|
|
14
|
+
"sandboxModules": [{ "name": ".", "kind": "js", "npm": "js-yaml" }]
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
This package produces the module. Three stages, in order:
|
|
20
|
+
|
|
21
|
+
1. **Bundle** — esbuild, `bundle`, `format: "esm"`, `platform: "neutral"`,
|
|
22
|
+
pinned `conditions` (`import`, `module`, `default`) and `mainFields`
|
|
23
|
+
(`module`, `main`), no externals, no minification. An import of a Node
|
|
24
|
+
builtin fails the bundle by name; that is the filter, not a bug.
|
|
25
|
+
2. **Scan** — a scope-aware walk of the bundle's AST. A *free* reference to a
|
|
26
|
+
global the guest does not have (`process`, `Buffer`, `require`, `eval`,
|
|
27
|
+
`Function`, timers, `WebAssembly`, DOM names) is an error; a shadowed one is
|
|
28
|
+
not a reference at all. A reference the module feature-detects — the
|
|
29
|
+
argument of a `typeof`, or one in a branch such a check guards — is a
|
|
30
|
+
warning. The warning is a heads-up, not a compatibility promise.
|
|
31
|
+
3. **Probe** — the bundle is imported in the real engine, because bundling
|
|
32
|
+
proves resolution and nothing else. The probe context is capability-free:
|
|
33
|
+
no `fetch`, no filesystem, no bridges, no env, a short deadline and capped
|
|
34
|
+
output. It proves the module initializes; runtime loading stays
|
|
35
|
+
authoritative after that.
|
|
36
|
+
|
|
37
|
+
Nothing here throws at a pack author. Every way admission can end short is a
|
|
38
|
+
named skip: `npm-module-builtin-import`, `npm-module-unresolved`,
|
|
39
|
+
`npm-module-too-large`, `npm-module-forbidden-global`,
|
|
40
|
+
`npm-module-scan-rejected`, `npm-module-probe-failed`.
|
|
41
|
+
|
|
42
|
+
## Cache
|
|
43
|
+
|
|
44
|
+
Keys are digests, never `name@version` — a linked pack, a transitive update, a
|
|
45
|
+
lockfile change and an esbuild upgrade all change the bundle while the version
|
|
46
|
+
stays put. The key covers every input file's content hash from esbuild's
|
|
47
|
+
metafile, the esbuild version, this compiler's contract version, and the
|
|
48
|
+
normalized options. The stored value carries the scan report and the probe
|
|
49
|
+
verdict, so a warm cache skips the probe too.
|
|
50
|
+
|
|
51
|
+
Writes are temp-file-plus-rename; a key is validated against
|
|
52
|
+
`^[a-f0-9]{64}$` before it reaches a path. The root is
|
|
53
|
+
`getNodetoolCacheDir()/sandbox-modules` (`NODETOOL_CACHE_DIR` overrides).
|
|
54
|
+
|
|
55
|
+
## Hosts
|
|
56
|
+
|
|
57
|
+
Discovery in `@nodetool-ai/node-sdk` stays synchronous and engine-free — it
|
|
58
|
+
never runs esbuild and never starts QuickJS. Hosts compile here and inject:
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
import { compileSandboxCatalog } from "@nodetool-ai/sandbox-compiler";
|
|
62
|
+
|
|
63
|
+
const host = await compileSandboxCatalog(); // compile, then discover with the results
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
The server does this in its catalog refresh, Electron after a pack installs,
|
|
67
|
+
and `nodetool packs compile` on demand. A synchronous host reads the cache
|
|
68
|
+
only:
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
import { createCachedNpmLookup } from "@nodetool-ai/sandbox-compiler/cache";
|
|
72
|
+
|
|
73
|
+
discoverSandboxCatalog(undefined, { compiled: createCachedNpmLookup() });
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
A miss there is `pending-compile`, naming `nodetool packs compile`.
|
|
77
|
+
|
|
78
|
+
Design: [docs/sandbox-package-design.md](../../docs/sandbox-package-design.md)
|
|
79
|
+
§ Config-only modules from npm packages. Measured candidates and the size cap:
|
|
80
|
+
[docs/m3-implementation-plan.md](../../docs/m3-implementation-plan.md).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
2026-09-28T09:19:15.482Z
|
package/dist/bundle.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* esbuild half of the compile pipeline: resolve an npm dependency from a pack's
|
|
3
|
+
* own directory and produce one ESM bundle with no externals.
|
|
4
|
+
*
|
|
5
|
+
* Two things this deliberately does *not* do. It does not minify — a digest and
|
|
6
|
+
* a human review both beat the bytes saved. And it does not allow a single
|
|
7
|
+
* external: an import that leaves the bundle is an import the guest cannot
|
|
8
|
+
* resolve, so the resolution failure has to happen here, at admission, where it
|
|
9
|
+
* becomes a named skip.
|
|
10
|
+
*/
|
|
11
|
+
/** One input file esbuild read, with its content hash. */
|
|
12
|
+
export interface InputDigest {
|
|
13
|
+
/** Pack-relative path, so the record is the same on every machine. */
|
|
14
|
+
readonly path: string;
|
|
15
|
+
readonly sha256: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* One file that decided *which* inputs esbuild read, with its content hash.
|
|
19
|
+
*
|
|
20
|
+
* Input hashes answer "did the files we bundled change". They cannot answer
|
|
21
|
+
* "would we still resolve to those files", because a `package.json` is
|
|
22
|
+
* consulted during resolution and never appears among the inputs: flip
|
|
23
|
+
* `exports` from `v1.js` to `v2.js` and, as long as `v1.js` is still on disk
|
|
24
|
+
* unchanged, every recorded input still matches while the bundle is wrong.
|
|
25
|
+
* These records close that gap — the manifests governing each input, plus the
|
|
26
|
+
* places a closer copy of the dependency could appear and shadow the one that
|
|
27
|
+
* won.
|
|
28
|
+
*/
|
|
29
|
+
export interface ResolutionDigest {
|
|
30
|
+
/**
|
|
31
|
+
* Pack-relative path. Unlike an input this may reach above the pack, because
|
|
32
|
+
* a hoisted install puts the manifest that resolved it there.
|
|
33
|
+
*/
|
|
34
|
+
readonly path: string;
|
|
35
|
+
/** Content hash, or {@link ABSENT} for a file that did not exist. */
|
|
36
|
+
readonly sha256: string;
|
|
37
|
+
}
|
|
38
|
+
/** Recorded in place of a hash for a file that was not there. */
|
|
39
|
+
export declare const ABSENT = "absent";
|
|
40
|
+
/** A successful bundle plus what the cache key is computed from. */
|
|
41
|
+
export interface BundleResult {
|
|
42
|
+
readonly source: string;
|
|
43
|
+
readonly bytes: number;
|
|
44
|
+
/** Every input esbuild read, sorted by path. */
|
|
45
|
+
readonly inputDigests: readonly InputDigest[];
|
|
46
|
+
/** Every file that decided which inputs those were, sorted by path. */
|
|
47
|
+
readonly resolutionDigests: readonly ResolutionDigest[];
|
|
48
|
+
readonly inputsDigest: string;
|
|
49
|
+
readonly optionsDigest: string;
|
|
50
|
+
readonly esbuildVersion: string;
|
|
51
|
+
/** Whether the shim re-exported a default binding. */
|
|
52
|
+
readonly defaultExport: boolean;
|
|
53
|
+
}
|
|
54
|
+
/** A bundle that cannot be produced, with the reason already named. */
|
|
55
|
+
export interface BundleFailure {
|
|
56
|
+
readonly code: "npm-module-builtin-import" | "npm-module-unresolved" | "npm-module-bundle-failed";
|
|
57
|
+
readonly message: string;
|
|
58
|
+
}
|
|
59
|
+
export type BundleOutcome = {
|
|
60
|
+
readonly status: "bundled";
|
|
61
|
+
readonly result: BundleResult;
|
|
62
|
+
} | {
|
|
63
|
+
readonly status: "failed";
|
|
64
|
+
readonly failure: BundleFailure;
|
|
65
|
+
};
|
|
66
|
+
/** Bundle `npmName` as resolved from `packDir`. */
|
|
67
|
+
export declare function bundleNpmModule(packDir: string, npmName: string): Promise<BundleOutcome>;
|
|
68
|
+
/** Digest of the pinned options plus the esbuild that will apply them. */
|
|
69
|
+
export declare function optionsDigest(esbuildVersion: string): string;
|
|
70
|
+
//# sourceMappingURL=bundle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../src/bundle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAgBH,0DAA0D;AAC1D,MAAM,WAAW,WAAW;IAC1B,sEAAsE;IACtE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,qEAAqE;IACrE,QAAQ,CAAC,MAAM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ve an npm dependency from a pack's
|
|
3
|
+
* own directory and produce one ESM bundle with no externals.
|
|
4
|
+
*
|
|
5
|
+
* Two things this deliberately does *not* do. It does not minify — a digest and
|
|
6
|
+
* a human review both beat the bytes saved. And it does not allow a single
|
|
7
|
+
* external: an import that leaves the bundle is an import the guest cannot
|
|
8
|
+
* resolve, so the resolution failure has to happen here, at admission, where it
|
|
9
|
+
* becomes a named skip.
|
|
10
|
+
*/
|
|
11
|
+
import { createHash } from "node:crypto";
|
|
12
|
+
import { readFileSync } from "node:fs";
|
|
13
|
+
import { isBuiltin } from "node:module";
|
|
14
|
+
import { basename, dirname, join, relative, resolve } from "node:path";
|
|
15
|
+
import esbuild from "esbuild";
|
|
16
|
+
import { NPM_BUNDLE_CONDITIONS, NPM_BUNDLE_MAIN_FIELDS, NPM_BUNDLE_TARGET, normalizedCompileOptions } from "./options.js";
|
|
17
|
+
/** Recorded in place of a hash for a file that was not there. */
|
|
18
|
+
export const ABSENT = "absent";
|
|
19
|
+
const NAMESPACE = "nodetool-sandbox-entry";
|
|
20
|
+
/** Bundle `npmName` as resolved from `packDir`. */
|
|
21
|
+
export async function bundleNpmModule(packDir, npmName) {
|
|
22
|
+
const withDefault = await runBuild(packDir, npmName, true);
|
|
23
|
+
if (withDefault.status === "bundled")
|
|
24
|
+
return withDefault;
|
|
25
|
+
if (withDefault.failure.code !== "npm-module-bundle-failed")
|
|
26
|
+
return withDefault;
|
|
27
|
+
// A real ESM package without a default export rejects `export { default }`.
|
|
28
|
+
// Re-export only the named bindings rather than call the package unusable.
|
|
29
|
+
const namedOnly = await runBuild(packDir, npmName, false);
|
|
30
|
+
return namedOnly.status === "bundled" ? namedOnly : withDefault;
|
|
31
|
+
}
|
|
32
|
+
async function runBuild(packDir, npmName, withDefault) {
|
|
33
|
+
const builtins = [];
|
|
34
|
+
const contents = withDefault
|
|
35
|
+
? `export * from ${JSON.stringify(npmName)};\nexport { default } from ${JSON.stringify(npmName)};\n`
|
|
36
|
+
: `export * from ${JSON.stringify(npmName)};\n`;
|
|
37
|
+
try {
|
|
38
|
+
const built = await esbuild.build({
|
|
39
|
+
stdin: { contents, resolveDir: packDir, sourcefile: `${NAMESPACE}.js`, loader: "js" },
|
|
40
|
+
// Metafile input paths are relative to the working directory. Pinning it
|
|
41
|
+
// to the pack makes them pack-relative, so the recorded input list is the
|
|
42
|
+
// same on every machine and a synchronous reader can re-hash them.
|
|
43
|
+
absWorkingDir: packDir,
|
|
44
|
+
bundle: true,
|
|
45
|
+
format: "esm",
|
|
46
|
+
platform: "neutral",
|
|
47
|
+
conditions: [...NPM_BUNDLE_CONDITIONS],
|
|
48
|
+
mainFields: [...NPM_BUNDLE_MAIN_FIELDS],
|
|
49
|
+
target: NPM_BUNDLE_TARGET,
|
|
50
|
+
minify: false,
|
|
51
|
+
treeShaking: true,
|
|
52
|
+
sourcemap: false,
|
|
53
|
+
charset: "utf8",
|
|
54
|
+
legalComments: "none",
|
|
55
|
+
write: false,
|
|
56
|
+
metafile: true,
|
|
57
|
+
logLevel: "silent",
|
|
58
|
+
plugins: [rejectBuiltins(builtins)]
|
|
59
|
+
});
|
|
60
|
+
const output = built.outputFiles?.[0];
|
|
61
|
+
if (output === undefined) {
|
|
62
|
+
return failed("npm-module-bundle-failed", `${npmName}: esbuild produced no output`);
|
|
63
|
+
}
|
|
64
|
+
const source = output.text;
|
|
65
|
+
const inputDigests = hashInputs(packDir, built.metafile);
|
|
66
|
+
const resolutionDigests = hashResolution(packDir, npmName, built.metafile);
|
|
67
|
+
return {
|
|
68
|
+
status: "bundled",
|
|
69
|
+
result: {
|
|
70
|
+
source,
|
|
71
|
+
bytes: Buffer.byteLength(source, "utf8"),
|
|
72
|
+
inputDigests,
|
|
73
|
+
resolutionDigests,
|
|
74
|
+
inputsDigest: digestOf(inputDigests, resolutionDigests),
|
|
75
|
+
optionsDigest: optionsDigest(esbuild.version),
|
|
76
|
+
esbuildVersion: esbuild.version,
|
|
77
|
+
defaultExport: withDefault
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
if (builtins.length > 0) {
|
|
83
|
+
const names = [...new Set(builtins)].sort().join(", ");
|
|
84
|
+
return failed("npm-module-builtin-import", `${npmName} imports ${names} — a Node builtin needs the host bridge path, which the guest does not have`);
|
|
85
|
+
}
|
|
86
|
+
const text = buildFailureText(error);
|
|
87
|
+
if (/could not resolve/i.test(text)) {
|
|
88
|
+
return failed("npm-module-unresolved", `${npmName}: ${text}`);
|
|
89
|
+
}
|
|
90
|
+
return failed("npm-module-bundle-failed", `${npmName}: ${text}`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function failed(code, message) {
|
|
94
|
+
return { status: "failed", failure: { code, message } };
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Fail the bundle on any Node builtin, by name.
|
|
98
|
+
*
|
|
99
|
+
* `platform: "neutral"` would already refuse to resolve `node:fs`, but the
|
|
100
|
+
* message it produces reads like a missing package. Naming the builtin is what
|
|
101
|
+
* turns the failure into a skip a pack author can act on.
|
|
102
|
+
*/
|
|
103
|
+
function rejectBuiltins(collected) {
|
|
104
|
+
return {
|
|
105
|
+
name: "nodetool-reject-node-builtins",
|
|
106
|
+
setup(build) {
|
|
107
|
+
build.onResolve({ filter: /.*/ }, (args) => {
|
|
108
|
+
if (args.kind === "entry-point")
|
|
109
|
+
return null;
|
|
110
|
+
const target = args.path;
|
|
111
|
+
if (!isBuiltin(target))
|
|
112
|
+
return null;
|
|
113
|
+
collected.push(target.startsWith("node:") ? target : `node:${target}`);
|
|
114
|
+
return {
|
|
115
|
+
errors: [{ text: `${target} is a Node builtin and is not available in the sandbox` }]
|
|
116
|
+
};
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function hashInputs(packDir, metafile) {
|
|
122
|
+
if (metafile === undefined)
|
|
123
|
+
return [];
|
|
124
|
+
const digests = [];
|
|
125
|
+
for (const relativePath of Object.keys(metafile.inputs)) {
|
|
126
|
+
if (isSyntheticEntry(packDir, relativePath))
|
|
127
|
+
continue;
|
|
128
|
+
const absolute = resolve(packDir, relativePath);
|
|
129
|
+
let bytes;
|
|
130
|
+
try {
|
|
131
|
+
bytes = readFileSync(absolute);
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
// An input esbuild read but we cannot re-read is recorded as missing so
|
|
135
|
+
// the key changes rather than silently matching a stale entry.
|
|
136
|
+
digests.push({ path: relativePath, sha256: "unreadable" });
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
digests.push({ path: relativePath, sha256: createHash("sha256").update(bytes).digest("hex") });
|
|
140
|
+
}
|
|
141
|
+
return digests.sort(byPath);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Hash every file that decided which inputs esbuild read.
|
|
145
|
+
*
|
|
146
|
+
* Two sets, both of them `package.json` files. The *governing* manifests are
|
|
147
|
+
* the ones a resolver consults on the way to an input — the package's own
|
|
148
|
+
* manifest, whose `exports`/`main` chose the file, any nested manifest between
|
|
149
|
+
* it and the file, and the pack's own. The *shadow* candidates are the places
|
|
150
|
+
* a nearer copy of the dependency could be installed later; those are usually
|
|
151
|
+
* absent, and an absence that becomes a file is exactly the change that
|
|
152
|
+
* silently re-resolves the import.
|
|
153
|
+
*
|
|
154
|
+
* Lockfiles are deliberately not hashed. A lockfile records what *should* be
|
|
155
|
+
* installed, so hashing one invalidates every pack's cache on any unrelated
|
|
156
|
+
* dependency edit while still saying nothing about the tree on disk. Once the
|
|
157
|
+
* install actually happens it moves either an input or one of these manifests,
|
|
158
|
+
* which is what the digest is watching.
|
|
159
|
+
*/
|
|
160
|
+
function hashResolution(packDir, npmName, metafile) {
|
|
161
|
+
const paths = new Set(shadowCandidates(packDir, npmName));
|
|
162
|
+
paths.add(join(packDir, "package.json"));
|
|
163
|
+
for (const relativePath of Object.keys(metafile?.inputs ?? {})) {
|
|
164
|
+
if (isSyntheticEntry(packDir, relativePath))
|
|
165
|
+
continue;
|
|
166
|
+
for (const manifest of manifestsGoverning(packDir, resolve(packDir, relativePath))) {
|
|
167
|
+
paths.add(manifest);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
const digests = [];
|
|
171
|
+
for (const absolute of paths) {
|
|
172
|
+
let bytes;
|
|
173
|
+
try {
|
|
174
|
+
bytes = readFileSync(absolute);
|
|
175
|
+
}
|
|
176
|
+
catch {
|
|
177
|
+
digests.push({ path: relative(packDir, absolute), sha256: ABSENT });
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
digests.push({
|
|
181
|
+
path: relative(packDir, absolute),
|
|
182
|
+
sha256: createHash("sha256").update(bytes).digest("hex")
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
return digests.sort(byPath);
|
|
186
|
+
}
|
|
187
|
+
function isSyntheticEntry(packDir, inputPath) {
|
|
188
|
+
return resolve(packDir, inputPath) === join(packDir, `${NAMESPACE}.js`);
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Every `package.json` between `file` and the root of the package holding it.
|
|
192
|
+
*
|
|
193
|
+
* The walk stops at the enclosing `node_modules` — above that directory is a
|
|
194
|
+
* different package, whose manifest had no say in resolving this file — or at
|
|
195
|
+
* the pack itself for a file the pack ships.
|
|
196
|
+
*/
|
|
197
|
+
function manifestsGoverning(packDir, file) {
|
|
198
|
+
const manifests = [];
|
|
199
|
+
let dir = dirname(file);
|
|
200
|
+
while (basename(dir) !== "node_modules") {
|
|
201
|
+
manifests.push(join(dir, "package.json"));
|
|
202
|
+
const parent = dirname(dir);
|
|
203
|
+
if (parent === dir || dir === packDir)
|
|
204
|
+
break;
|
|
205
|
+
dir = parent;
|
|
206
|
+
}
|
|
207
|
+
return manifests;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Every `node_modules/<npmName>/package.json` from the pack upward.
|
|
211
|
+
*
|
|
212
|
+
* Node resolution takes the nearest one, so a copy installed closer to the
|
|
213
|
+
* pack than the one that won replaces the dependency without touching a single
|
|
214
|
+
* recorded input.
|
|
215
|
+
*/
|
|
216
|
+
function shadowCandidates(packDir, npmName) {
|
|
217
|
+
const segments = npmName.split("/");
|
|
218
|
+
const candidates = [];
|
|
219
|
+
let dir = packDir;
|
|
220
|
+
for (;;) {
|
|
221
|
+
if (basename(dir) !== "node_modules") {
|
|
222
|
+
candidates.push(join(dir, "node_modules", ...segments, "package.json"));
|
|
223
|
+
}
|
|
224
|
+
const parent = dirname(dir);
|
|
225
|
+
if (parent === dir)
|
|
226
|
+
break;
|
|
227
|
+
dir = parent;
|
|
228
|
+
}
|
|
229
|
+
return candidates;
|
|
230
|
+
}
|
|
231
|
+
function byPath(left, right) {
|
|
232
|
+
return left.path < right.path ? -1 : left.path > right.path ? 1 : 0;
|
|
233
|
+
}
|
|
234
|
+
function digestOf(inputDigests, resolutionDigests) {
|
|
235
|
+
return createHash("sha256")
|
|
236
|
+
.update(JSON.stringify({ inputs: inputDigests, resolution: resolutionDigests }))
|
|
237
|
+
.digest("hex");
|
|
238
|
+
}
|
|
239
|
+
/** Digest of the pinned options plus the esbuild that will apply them. */
|
|
240
|
+
export function optionsDigest(esbuildVersion) {
|
|
241
|
+
return createHash("sha256")
|
|
242
|
+
.update(JSON.stringify({ esbuildVersion, options: normalizedCompileOptions() }))
|
|
243
|
+
.digest("hex");
|
|
244
|
+
}
|
|
245
|
+
function buildFailureText(error) {
|
|
246
|
+
const failure = error;
|
|
247
|
+
if (Array.isArray(failure.errors) && failure.errors.length > 0) {
|
|
248
|
+
return failure.errors.map((message) => message.text).join("; ");
|
|
249
|
+
}
|
|
250
|
+
return error instanceof Error ? error.message : String(error);
|
|
251
|
+
}
|
|
252
|
+
//# sourceMappingURL=bundle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundle.js","sourceRoot":"","sources":["../src/bundle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE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AO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAClE,CAAC;IACD,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAChE,CAAC"}
|
package/dist/cache.d.ts
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content-addressed cache for compiled npm modules.
|
|
3
|
+
*
|
|
4
|
+
* The key is never `pack/name@version`. A linked pack, a transitive update, a
|
|
5
|
+
* re-install, and an esbuild upgrade all change the bundle while the version
|
|
6
|
+
* stays exactly where it was, so the key is a digest over what actually
|
|
7
|
+
* determines the output: every input file's content hash from esbuild's
|
|
8
|
+
* metafile, the resolution inputs that decided which files those were, the
|
|
9
|
+
* esbuild version, this compiler's contract version, and the normalized build
|
|
10
|
+
* options.
|
|
11
|
+
*
|
|
12
|
+
* The value carries the scan report and the probe verdict alongside the source,
|
|
13
|
+
* so a warm cache skips the probe too — the expensive half of admission.
|
|
14
|
+
*/
|
|
15
|
+
import { type InputDigest, type ResolutionDigest } from "./bundle.js";
|
|
16
|
+
/** One free reference the scan flagged. Mirrored here so the cache stays engine-free. */
|
|
17
|
+
export interface CachedScanFinding {
|
|
18
|
+
readonly name: string;
|
|
19
|
+
readonly line: number;
|
|
20
|
+
readonly column: number;
|
|
21
|
+
readonly kind: "hard" | "feature-detected";
|
|
22
|
+
}
|
|
23
|
+
/** What one cache entry stores. */
|
|
24
|
+
export interface CachedCompilation {
|
|
25
|
+
readonly key: string;
|
|
26
|
+
readonly npmName: string;
|
|
27
|
+
readonly compilerVersion: string;
|
|
28
|
+
readonly esbuildVersion: string;
|
|
29
|
+
readonly optionsDigest: string;
|
|
30
|
+
readonly inputsDigest: string;
|
|
31
|
+
readonly source: string;
|
|
32
|
+
readonly bytes: number;
|
|
33
|
+
/** Every input's content hash, kept so a synchronous reader can re-verify. */
|
|
34
|
+
readonly inputDigests: readonly InputDigest[];
|
|
35
|
+
/** Every resolution input's hash, re-verified alongside the inputs. */
|
|
36
|
+
readonly resolutionDigests: readonly ResolutionDigest[];
|
|
37
|
+
readonly scanWarnings: readonly CachedScanFinding[];
|
|
38
|
+
readonly probeOk: boolean;
|
|
39
|
+
readonly probeExports: readonly string[];
|
|
40
|
+
}
|
|
41
|
+
/** The parts of a compile that determine its identity. */
|
|
42
|
+
export interface CacheKeyInput {
|
|
43
|
+
readonly npmName: string;
|
|
44
|
+
readonly esbuildVersion: string;
|
|
45
|
+
/** Every input's content hash, from esbuild's metafile. */
|
|
46
|
+
readonly inputDigests: readonly InputDigest[];
|
|
47
|
+
/** Every file that decided which inputs those were. */
|
|
48
|
+
readonly resolutionDigests: readonly ResolutionDigest[];
|
|
49
|
+
}
|
|
50
|
+
/** Compute the digest a compilation is stored under. */
|
|
51
|
+
export declare function computeCacheKey(input: CacheKeyInput): string;
|
|
52
|
+
/** Default cache root: `<user cache>/sandbox-modules`. */
|
|
53
|
+
export declare function defaultCacheRoot(): string;
|
|
54
|
+
/** A cache over one directory. Every failure degrades to a miss, never a throw. */
|
|
55
|
+
export declare class CompiledModuleCache {
|
|
56
|
+
private readonly root;
|
|
57
|
+
constructor(root?: string);
|
|
58
|
+
/** Read an entry, or `undefined` on a miss, a bad key, or corrupt content. */
|
|
59
|
+
read(key: string): CachedCompilation | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* Read a compiled module without running esbuild.
|
|
62
|
+
*
|
|
63
|
+
* The key is a digest over esbuild's input list, which only a bundle run
|
|
64
|
+
* produces — so a synchronous host cannot compute it. A pointer written
|
|
65
|
+
* alongside each entry maps `(pack directory, dependency)` to that key, and
|
|
66
|
+
* this reader then re-hashes every input the entry recorded before trusting
|
|
67
|
+
* it. Content still decides: an entry whose inputs moved is a miss, and a
|
|
68
|
+
* miss is `pending-compile`, never a stale hit.
|
|
69
|
+
*
|
|
70
|
+
* The inputs alone are not enough to decide that. Resolution metadata never
|
|
71
|
+
* appears among them, so a `package.json` that starts pointing `exports` at
|
|
72
|
+
* a different file, or a nearer copy of the dependency that shadows the one
|
|
73
|
+
* that won, leaves every input untouched while making the bundle wrong.
|
|
74
|
+
* Those files are re-hashed here too — an absent one that has appeared
|
|
75
|
+
* counts as changed.
|
|
76
|
+
*/
|
|
77
|
+
readForPack(packDir: string, npmName: string): CachedCompilation | undefined;
|
|
78
|
+
/** Record where a pack's dependency compiled to, for {@link readForPack}. */
|
|
79
|
+
writePointer(packDir: string, npmName: string, key: string): void;
|
|
80
|
+
private pointerPathFor;
|
|
81
|
+
/**
|
|
82
|
+
* Write an entry atomically.
|
|
83
|
+
*
|
|
84
|
+
* A temp file in the same directory plus a rename, so a reader never observes
|
|
85
|
+
* half an entry and two compilers racing on one key both leave a whole one.
|
|
86
|
+
*/
|
|
87
|
+
write(entry: CachedCompilation): void;
|
|
88
|
+
/** Remove an entry. Used when one fails to parse. */
|
|
89
|
+
evict(key: string): void;
|
|
90
|
+
/** Reject anything that is not a bare digest before it reaches the path. */
|
|
91
|
+
private pathFor;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* A {@link SandboxCompiledNpmLookup} that only reads the cache.
|
|
95
|
+
*
|
|
96
|
+
* This is the synchronous host's path: the CLI's `buildFullRegistry` never
|
|
97
|
+
* compiles, so a module it has no cached artifact for surfaces as
|
|
98
|
+
* `pending-compile` naming `nodetool packs compile`.
|
|
99
|
+
*/
|
|
100
|
+
export declare function createCachedNpmLookup(cache?: CompiledModuleCache): (request: {
|
|
101
|
+
readonly packName: string;
|
|
102
|
+
readonly packDir: string;
|
|
103
|
+
readonly specifier: string;
|
|
104
|
+
readonly npmName: string;
|
|
105
|
+
}) => {
|
|
106
|
+
readonly status: "compiled";
|
|
107
|
+
readonly artifact: {
|
|
108
|
+
readonly source: string;
|
|
109
|
+
readonly compilerVersion: string;
|
|
110
|
+
readonly optionsDigest: string;
|
|
111
|
+
readonly inputsDigest: string;
|
|
112
|
+
};
|
|
113
|
+
readonly warnings?: readonly string[];
|
|
114
|
+
} | undefined;
|
|
115
|
+
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAgBH,OAAO,EAAU,KAAK,WAAW,EAAE,KAAK,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAS9E,yFAAyF;AACzF,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,CAAC;CAC5C;AAID,mCAAmC;AACnC,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,8EAA8E;IAC9E,QAAQ,CAAC,YAAY,EAAE,SAAS,WAAW,EAAE,CAAC;IAC9C,uEAAuE;IACvE,QAAQ,CAAC,iBAAiB,EAAE,SAAS,gBAAgB,EAAE,CAAC;IACxD,QAAQ,CAAC,YAAY,EAAE,SAAS,iBAAiB,EAAE,CAAC;IACpD,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,YAAY,EAAE,SAAS,MAAM,EA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