@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/dist/cache.js
ADDED
|
@@ -0,0 +1,290 @@
|
|
|
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 { createHash, randomBytes } from "node:crypto";
|
|
16
|
+
import { mkdirSync, readFileSync, realpathSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
17
|
+
import { join, resolve } from "node:path";
|
|
18
|
+
import { getNodetoolCacheDir } from "@nodetool-ai/config";
|
|
19
|
+
import { ABSENT } from "./bundle.js";
|
|
20
|
+
import { normalizedCompileOptions, SANDBOX_COMPILER_VERSION } from "./options.js";
|
|
21
|
+
const KEY_PATTERN = /^[a-f0-9]{64}$/;
|
|
22
|
+
/** Compute the digest a compilation is stored under. */
|
|
23
|
+
export function computeCacheKey(input) {
|
|
24
|
+
return createHash("sha256")
|
|
25
|
+
.update(JSON.stringify({
|
|
26
|
+
compilerVersion: SANDBOX_COMPILER_VERSION,
|
|
27
|
+
esbuildVersion: input.esbuildVersion,
|
|
28
|
+
options: normalizedCompileOptions(),
|
|
29
|
+
npmName: input.npmName,
|
|
30
|
+
inputs: [...input.inputDigests].sort(byPath),
|
|
31
|
+
resolution: [...input.resolutionDigests].sort(byPath)
|
|
32
|
+
}))
|
|
33
|
+
.digest("hex");
|
|
34
|
+
}
|
|
35
|
+
function byPath(left, right) {
|
|
36
|
+
return left.path < right.path ? -1 : left.path > right.path ? 1 : 0;
|
|
37
|
+
}
|
|
38
|
+
/** Default cache root: `<user cache>/sandbox-modules`. */
|
|
39
|
+
export function defaultCacheRoot() {
|
|
40
|
+
return join(getNodetoolCacheDir(), "sandbox-modules");
|
|
41
|
+
}
|
|
42
|
+
/** A cache over one directory. Every failure degrades to a miss, never a throw. */
|
|
43
|
+
export class CompiledModuleCache {
|
|
44
|
+
root;
|
|
45
|
+
constructor(root = defaultCacheRoot()) {
|
|
46
|
+
this.root = root;
|
|
47
|
+
}
|
|
48
|
+
/** Read an entry, or `undefined` on a miss, a bad key, or corrupt content. */
|
|
49
|
+
read(key) {
|
|
50
|
+
const path = this.pathFor(key);
|
|
51
|
+
if (path === undefined)
|
|
52
|
+
return undefined;
|
|
53
|
+
let raw;
|
|
54
|
+
try {
|
|
55
|
+
raw = readFileSync(path, "utf8");
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
// A miss and an unreadable entry are the same answer: compile again.
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
let parsed;
|
|
62
|
+
try {
|
|
63
|
+
parsed = JSON.parse(raw);
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
// A truncated or hand-edited entry is discarded rather than trusted.
|
|
67
|
+
this.evict(key);
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
const entry = parsed;
|
|
71
|
+
if (entry.key !== key ||
|
|
72
|
+
entry.compilerVersion !== SANDBOX_COMPILER_VERSION ||
|
|
73
|
+
typeof entry.source !== "string" ||
|
|
74
|
+
typeof entry.npmName !== "string" ||
|
|
75
|
+
typeof entry.probeOk !== "boolean") {
|
|
76
|
+
this.evict(key);
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
key,
|
|
81
|
+
npmName: entry.npmName,
|
|
82
|
+
compilerVersion: SANDBOX_COMPILER_VERSION,
|
|
83
|
+
esbuildVersion: entry.esbuildVersion ?? "",
|
|
84
|
+
optionsDigest: entry.optionsDigest ?? "",
|
|
85
|
+
inputsDigest: entry.inputsDigest ?? "",
|
|
86
|
+
source: entry.source,
|
|
87
|
+
bytes: entry.bytes ?? Buffer.byteLength(entry.source, "utf8"),
|
|
88
|
+
inputDigests: entry.inputDigests ?? [],
|
|
89
|
+
resolutionDigests: entry.resolutionDigests ?? [],
|
|
90
|
+
scanWarnings: entry.scanWarnings ?? [],
|
|
91
|
+
probeOk: entry.probeOk,
|
|
92
|
+
probeExports: entry.probeExports ?? []
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Read a compiled module without running esbuild.
|
|
97
|
+
*
|
|
98
|
+
* The key is a digest over esbuild's input list, which only a bundle run
|
|
99
|
+
* produces — so a synchronous host cannot compute it. A pointer written
|
|
100
|
+
* alongside each entry maps `(pack directory, dependency)` to that key, and
|
|
101
|
+
* this reader then re-hashes every input the entry recorded before trusting
|
|
102
|
+
* it. Content still decides: an entry whose inputs moved is a miss, and a
|
|
103
|
+
* miss is `pending-compile`, never a stale hit.
|
|
104
|
+
*
|
|
105
|
+
* The inputs alone are not enough to decide that. Resolution metadata never
|
|
106
|
+
* appears among them, so a `package.json` that starts pointing `exports` at
|
|
107
|
+
* a different file, or a nearer copy of the dependency that shadows the one
|
|
108
|
+
* that won, leaves every input untouched while making the bundle wrong.
|
|
109
|
+
* Those files are re-hashed here too — an absent one that has appeared
|
|
110
|
+
* counts as changed.
|
|
111
|
+
*/
|
|
112
|
+
readForPack(packDir, npmName) {
|
|
113
|
+
const pointerPath = this.pointerPathFor(packDir, npmName);
|
|
114
|
+
if (pointerPath === undefined)
|
|
115
|
+
return undefined;
|
|
116
|
+
let key;
|
|
117
|
+
try {
|
|
118
|
+
key = JSON.parse(readFileSync(pointerPath, "utf8"))
|
|
119
|
+
.key;
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
// No pointer, or an unreadable one: compile again.
|
|
123
|
+
return undefined;
|
|
124
|
+
}
|
|
125
|
+
if (typeof key !== "string")
|
|
126
|
+
return undefined;
|
|
127
|
+
const entry = this.read(key);
|
|
128
|
+
if (entry === undefined)
|
|
129
|
+
return undefined;
|
|
130
|
+
if (!inputsUnchanged(packDir, entry.inputDigests))
|
|
131
|
+
return undefined;
|
|
132
|
+
return resolutionUnchanged(packDir, entry.resolutionDigests)
|
|
133
|
+
? entry
|
|
134
|
+
: undefined;
|
|
135
|
+
}
|
|
136
|
+
/** Record where a pack's dependency compiled to, for {@link readForPack}. */
|
|
137
|
+
writePointer(packDir, npmName, key) {
|
|
138
|
+
const pointerPath = this.pointerPathFor(packDir, npmName);
|
|
139
|
+
if (pointerPath === undefined || !KEY_PATTERN.test(key))
|
|
140
|
+
return;
|
|
141
|
+
const temporary = `${pointerPath}.${randomBytes(8).toString("hex")}.tmp`;
|
|
142
|
+
try {
|
|
143
|
+
mkdirSync(join(this.root, "index"), { recursive: true });
|
|
144
|
+
writeFileSync(temporary, JSON.stringify({ key }), "utf8");
|
|
145
|
+
renameSync(temporary, pointerPath);
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
try {
|
|
149
|
+
rmSync(temporary, { force: true });
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
// Nothing further to do about an undeletable temp file.
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
pointerPathFor(packDir, npmName) {
|
|
157
|
+
let realDir;
|
|
158
|
+
try {
|
|
159
|
+
realDir = realpathSync(packDir);
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
// A pack directory that no longer exists has nothing to point at.
|
|
163
|
+
return undefined;
|
|
164
|
+
}
|
|
165
|
+
const digest = createHash("sha256")
|
|
166
|
+
.update(JSON.stringify({
|
|
167
|
+
compilerVersion: SANDBOX_COMPILER_VERSION,
|
|
168
|
+
realDir,
|
|
169
|
+
npmName
|
|
170
|
+
}))
|
|
171
|
+
.digest("hex");
|
|
172
|
+
return join(this.root, "index", `${digest}.json`);
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Write an entry atomically.
|
|
176
|
+
*
|
|
177
|
+
* A temp file in the same directory plus a rename, so a reader never observes
|
|
178
|
+
* half an entry and two compilers racing on one key both leave a whole one.
|
|
179
|
+
*/
|
|
180
|
+
write(entry) {
|
|
181
|
+
const path = this.pathFor(entry.key);
|
|
182
|
+
if (path === undefined)
|
|
183
|
+
return;
|
|
184
|
+
const temporary = `${path}.${randomBytes(8).toString("hex")}.tmp`;
|
|
185
|
+
try {
|
|
186
|
+
mkdirSync(this.root, { recursive: true });
|
|
187
|
+
writeFileSync(temporary, JSON.stringify(entry), "utf8");
|
|
188
|
+
renameSync(temporary, path);
|
|
189
|
+
}
|
|
190
|
+
catch {
|
|
191
|
+
// A cache that cannot be written still compiles; drop the temp file.
|
|
192
|
+
try {
|
|
193
|
+
rmSync(temporary, { force: true });
|
|
194
|
+
}
|
|
195
|
+
catch {
|
|
196
|
+
// Nothing further to do about an undeletable temp file.
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/** Remove an entry. Used when one fails to parse. */
|
|
201
|
+
evict(key) {
|
|
202
|
+
const path = this.pathFor(key);
|
|
203
|
+
if (path === undefined)
|
|
204
|
+
return;
|
|
205
|
+
try {
|
|
206
|
+
rmSync(path, { force: true });
|
|
207
|
+
}
|
|
208
|
+
catch {
|
|
209
|
+
// An entry that cannot be removed is simply re-read and re-rejected.
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
/** Reject anything that is not a bare digest before it reaches the path. */
|
|
213
|
+
pathFor(key) {
|
|
214
|
+
if (!KEY_PATTERN.test(key))
|
|
215
|
+
return undefined;
|
|
216
|
+
return join(this.root, `${key}.json`);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
/** Re-hash every recorded input and report whether all of them still match. */
|
|
220
|
+
function inputsUnchanged(packDir, inputDigests) {
|
|
221
|
+
if (inputDigests.length === 0)
|
|
222
|
+
return false;
|
|
223
|
+
for (const record of inputDigests) {
|
|
224
|
+
let bytes;
|
|
225
|
+
try {
|
|
226
|
+
bytes = readFileSync(resolve(packDir, record.path));
|
|
227
|
+
}
|
|
228
|
+
catch {
|
|
229
|
+
// An input that disappeared changes the bundle; treat it as a miss.
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
if (createHash("sha256").update(bytes).digest("hex") !== record.sha256)
|
|
233
|
+
return false;
|
|
234
|
+
}
|
|
235
|
+
return true;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Re-hash every recorded resolution input and report whether all still match.
|
|
239
|
+
*
|
|
240
|
+
* A record whose file is gone must hash to {@link ABSENT}, and one recorded as
|
|
241
|
+
* absent must still be absent — an appearing `package.json` is a dependency
|
|
242
|
+
* that now resolves somewhere else.
|
|
243
|
+
*/
|
|
244
|
+
function resolutionUnchanged(packDir, resolutionDigests) {
|
|
245
|
+
if (resolutionDigests.length === 0)
|
|
246
|
+
return false;
|
|
247
|
+
for (const record of resolutionDigests) {
|
|
248
|
+
let current;
|
|
249
|
+
try {
|
|
250
|
+
current = createHash("sha256")
|
|
251
|
+
.update(readFileSync(resolve(packDir, record.path)))
|
|
252
|
+
.digest("hex");
|
|
253
|
+
}
|
|
254
|
+
catch {
|
|
255
|
+
current = ABSENT;
|
|
256
|
+
}
|
|
257
|
+
if (current !== record.sha256)
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
return true;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* A {@link SandboxCompiledNpmLookup} that only reads the cache.
|
|
264
|
+
*
|
|
265
|
+
* This is the synchronous host's path: the CLI's `buildFullRegistry` never
|
|
266
|
+
* compiles, so a module it has no cached artifact for surfaces as
|
|
267
|
+
* `pending-compile` naming `nodetool packs compile`.
|
|
268
|
+
*/
|
|
269
|
+
export function createCachedNpmLookup(cache = new CompiledModuleCache()) {
|
|
270
|
+
return (request) => {
|
|
271
|
+
const entry = cache.readForPack(request.packDir, request.npmName);
|
|
272
|
+
if (entry === undefined || !entry.probeOk)
|
|
273
|
+
return undefined;
|
|
274
|
+
const warnings = entry.scanWarnings.map((finding) => `${request.npmName} feature-detects ${finding.name} at ${finding.line}:${finding.column}; the guest has no such global, so that branch never runs`);
|
|
275
|
+
const outcome = {
|
|
276
|
+
status: "compiled",
|
|
277
|
+
artifact: {
|
|
278
|
+
source: entry.source,
|
|
279
|
+
compilerVersion: entry.compilerVersion,
|
|
280
|
+
optionsDigest: entry.optionsDigest,
|
|
281
|
+
inputsDigest: entry.inputsDigest
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
if (warnings.length > 0) {
|
|
285
|
+
outcome.warnings = warnings;
|
|
286
|
+
}
|
|
287
|
+
return outcome;
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
//# sourceMappingURL=cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EACL,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,MAAM,EACN,aAAa,EACd,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAG1D,OAAO,EAAE,MAAM,EAA2C,MAAM,aAAa,CAAC;AAC9E,OAAO,EACL,wBAAwB,EACxB,wBAAwB,EACzB,MAAM,cAAc,CAAC;AAatB,MAAM,WAAW,GAAG,gBAAgB,CAAC;AA+BrC,wDAAwD;AACxD,MAAM,UAAU,eAAe,CAAC,KAAoB;IAClD,OAAO,UAAU,CAAC,QAAQ,CAAC;SACxB,MAAM,CACL,IAAI,CAAC,SAAS,CAAC;QACb,eAAe,EAAE,wBAAwB;QACzC,cAAc,EAAE,KAAK,CAAC,cAAc;QACpC,OAAO,EAAE,wBAAwB,EAAE;QACnC,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,MAAM,EAAE,CAAC,GAAG,KAAK,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC;QAC5C,UAAU,EAAE,CAAC,GAAG,KAAK,CAAC,iBAAiB,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC;KACtD,CAAC,CACH;SACA,MAAM,CAAC,KAAK,CAAC,CAAC;AACnB,CAAC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,QAAQ,GAAG,QAAQ,CAAC;QAC9B,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The async host seam: compile a pack's npm modules, then discover with the
|
|
3
|
+
* results injected.
|
|
4
|
+
*
|
|
5
|
+
* Discovery runs twice. The first pass is the cheap, engine-free one node-sdk
|
|
6
|
+
* already does — it tells us which npm dependencies a pack declares, after its
|
|
7
|
+
* manifest has been validated. The second pass runs with the compiled artifacts
|
|
8
|
+
* in hand, so an npm module joins the source graph exactly like an authored
|
|
9
|
+
* file. Nothing here changes what discovery *validates*; it only supplies what
|
|
10
|
+
* discovery cannot produce for itself.
|
|
11
|
+
*/
|
|
12
|
+
import { type SandboxCatalogHost, type SandboxCompiledNpmLookup, type SandboxNpmCompileOutcome, type SandboxPackDiscovery } from "@nodetool-ai/node-sdk";
|
|
13
|
+
import { CompiledModuleCache } from "./cache.js";
|
|
14
|
+
/** One npm module the compiler looked at. */
|
|
15
|
+
export interface CompiledModuleReport {
|
|
16
|
+
readonly packName: string;
|
|
17
|
+
readonly packDir: string;
|
|
18
|
+
readonly specifier: string;
|
|
19
|
+
readonly npmName: string;
|
|
20
|
+
readonly outcome: SandboxNpmCompileOutcome;
|
|
21
|
+
readonly cached: boolean;
|
|
22
|
+
}
|
|
23
|
+
export interface CompileCatalogOptions {
|
|
24
|
+
readonly searchPaths?: readonly string[];
|
|
25
|
+
readonly cache?: CompiledModuleCache;
|
|
26
|
+
/** Recompile and re-probe even when the cache has an answer. */
|
|
27
|
+
readonly noCache?: boolean;
|
|
28
|
+
}
|
|
29
|
+
export interface CompiledCatalogHost extends SandboxCatalogHost {
|
|
30
|
+
readonly compiled: readonly CompiledModuleReport[];
|
|
31
|
+
}
|
|
32
|
+
/** Compile every npm module declared by every installed sandbox pack. */
|
|
33
|
+
export declare function compileSandboxCatalog(options?: CompileCatalogOptions): Promise<CompiledCatalogHost>;
|
|
34
|
+
/** Compile the npm modules of already-discovered packs. */
|
|
35
|
+
export declare function compileDiscoveries(discoveries: readonly SandboxPackDiscovery[], options?: {
|
|
36
|
+
cache?: CompiledModuleCache;
|
|
37
|
+
noCache?: boolean;
|
|
38
|
+
}): Promise<CompiledModuleReport[]>;
|
|
39
|
+
/** Turn compile reports into the lookup discovery consumes. */
|
|
40
|
+
export declare function createCompiledNpmLookup(reports: readonly CompiledModuleReport[]): SandboxCompiledNpmLookup;
|
|
41
|
+
//# sourceMappingURL=catalog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../src/catalog.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAEL,KAAK,kBAAkB,EACvB,KAAK,wBAAwB,EAC7B,KAAK,wBAAwB,EAC7B,KAAK,oBAAoB,EAC1B,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAGjD,6CAA6C;AAC7C,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,wBAAwB,CAAC;IAC3C,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,WAAW,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACzC,QAAQ,CAAC,KAAK,CAAC,EAAE,mBAAmB,CAAC;IACrC,gEAAgE;IAChE,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,MAAM,WAAW,mBAAoB,SAAQ,kBAAkB;IAC7D,QAAQ,CAAC,QAAQ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,CAAC;AAED,+DAA+D;AAC/D,MAAM,UAAU,uBAAuB,CACrC,OAAwC;IAExC,MAAM,KAAK,GAAG,IAAI,GAAG,CACnB,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC;QACtB,GAAG,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,OAAO,EAAE;QACtC,MAAM,CAAC,OAAO;KACf,CAAC,CACH,CAAC;IACF,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;AAC1E,CAAC;AAED,SAAS,QAAQ,CACf,WAA0C,EAC1C,QAAmC;IAEnC,MAAM,OAAO,GAAG,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC;IAC3D,OAAO,WAAW,KAAK,SAAS;QAC9B,CAAC,CAAC,sBAAsB,CAAC,SAAS,EAAE,OAAO,CAAC;QAC5C,CAAC,CAAC,sBAAsB,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;AACnD,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The compile pipeline, in execution order: bundle, scan, probe — wrapped by
|
|
3
|
+
* the content-addressed cache.
|
|
4
|
+
*
|
|
5
|
+
* Every way this can end short of an admitted module is a *named skip*, not an
|
|
6
|
+
* error. A pack that imports `node:fs`, one that reaches for `process`, one
|
|
7
|
+
* whose bundle is over the cap, and one that throws while initializing are four
|
|
8
|
+
* different problems, and the pack author gets told which.
|
|
9
|
+
*/
|
|
10
|
+
import { CompiledModuleCache } from "./cache.js";
|
|
11
|
+
import type { SandboxNpmCompileOutcome } from "@nodetool-ai/node-sdk/sandbox-pack-discovery";
|
|
12
|
+
export interface CompileNpmModuleRequest {
|
|
13
|
+
readonly packDir: string;
|
|
14
|
+
readonly npmName: string;
|
|
15
|
+
/** Provide a cache to reuse one across a whole discovery pass. */
|
|
16
|
+
readonly cache?: CompiledModuleCache;
|
|
17
|
+
/** Skip the cache entirely. Tests and `--force` use this. */
|
|
18
|
+
readonly noCache?: boolean;
|
|
19
|
+
}
|
|
20
|
+
/** The compile pipeline's own result, before it becomes a discovery outcome. */
|
|
21
|
+
export interface CompileNpmModuleResult {
|
|
22
|
+
readonly outcome: SandboxNpmCompileOutcome;
|
|
23
|
+
/** Whether the answer came from the cache without re-probing. */
|
|
24
|
+
readonly cached: boolean;
|
|
25
|
+
readonly key?: string;
|
|
26
|
+
}
|
|
27
|
+
/** Bundle, scan, and probe one npm dependency of one pack. */
|
|
28
|
+
export declare function compileNpmModule(request: CompileNpmModuleRequest): Promise<CompileNpmModuleResult>;
|
|
29
|
+
//# sourceMappingURL=compile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../src/compile.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EACL,mBAAmB,EAGpB,MAAM,YAAY,CAAC;AAIpB,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,8CAA8C,CAAC;AAK7F,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,kEAAkE;IAClE,QAAQ,CAAC,KAAK,CAAC,EAAE,mBAAmB,CAAC;IACrC,6DAA6D;IAC7D,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,gFAAgF;AAChF,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,OAAO,EAAE,wBAAwB,CAAC;IAC3C,iEAAiE;IACjE,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,8DAA8D;AAC9D,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,sBAAsB,CAAC,CA+FjC"}
|
package/dist/compile.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The compile pipeline, in execution order: bundle, scan, probe — wrapped by
|
|
3
|
+
* the content-addressed cache.
|
|
4
|
+
*
|
|
5
|
+
* Every way this can end short of an admitted module is a *named skip*, not an
|
|
6
|
+
* error. A pack that imports `node:fs`, one that reaches for `process`, one
|
|
7
|
+
* whose bundle is over the cap, and one that throws while initializing are four
|
|
8
|
+
* different problems, and the pack author gets told which.
|
|
9
|
+
*/
|
|
10
|
+
import { bundleNpmModule } from "./bundle.js";
|
|
11
|
+
import { CompiledModuleCache, computeCacheKey } from "./cache.js";
|
|
12
|
+
import { NPM_BUNDLE_MAX_BYTES, SANDBOX_COMPILER_VERSION } from "./options.js";
|
|
13
|
+
import { probeBundle } from "./probe.js";
|
|
14
|
+
import { scanBundle } from "./scan.js";
|
|
15
|
+
/** Bundle, scan, and probe one npm dependency of one pack. */
|
|
16
|
+
export async function compileNpmModule(request) {
|
|
17
|
+
const { packDir, npmName } = request;
|
|
18
|
+
const bundled = await bundleNpmModule(packDir, npmName);
|
|
19
|
+
if (bundled.status === "failed") {
|
|
20
|
+
return {
|
|
21
|
+
outcome: { status: "skipped", ...bundled.failure },
|
|
22
|
+
cached: false
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
const bundle = bundled.result;
|
|
26
|
+
if (bundle.bytes > NPM_BUNDLE_MAX_BYTES) {
|
|
27
|
+
return {
|
|
28
|
+
outcome: {
|
|
29
|
+
status: "skipped",
|
|
30
|
+
code: "npm-module-too-large",
|
|
31
|
+
message: `${npmName} bundles to ${bundle.bytes} bytes, over the ${NPM_BUNDLE_MAX_BYTES} byte sandbox module cap`
|
|
32
|
+
},
|
|
33
|
+
cached: false
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
const key = computeCacheKey({
|
|
37
|
+
npmName,
|
|
38
|
+
esbuildVersion: bundle.esbuildVersion,
|
|
39
|
+
inputDigests: bundle.inputDigests,
|
|
40
|
+
resolutionDigests: bundle.resolutionDigests
|
|
41
|
+
});
|
|
42
|
+
const cache = request.noCache === true
|
|
43
|
+
? undefined
|
|
44
|
+
: (request.cache ?? new CompiledModuleCache());
|
|
45
|
+
const hit = cache?.read(key);
|
|
46
|
+
if (hit !== undefined) {
|
|
47
|
+
// Re-point even on a hit: a pack whose dependency was updated back to a
|
|
48
|
+
// previously-compiled state must still resolve synchronously.
|
|
49
|
+
cache?.writePointer(packDir, npmName, key);
|
|
50
|
+
return { outcome: outcomeFor(npmName, hit), cached: true, key };
|
|
51
|
+
}
|
|
52
|
+
const scan = scanBundle(bundle.source);
|
|
53
|
+
if (scan.rejection !== undefined) {
|
|
54
|
+
return {
|
|
55
|
+
outcome: {
|
|
56
|
+
status: "skipped",
|
|
57
|
+
code: "npm-module-scan-rejected",
|
|
58
|
+
message: `${npmName}: ${scan.rejection}`
|
|
59
|
+
},
|
|
60
|
+
cached: false,
|
|
61
|
+
key
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
if (scan.errors.length > 0) {
|
|
65
|
+
return {
|
|
66
|
+
outcome: {
|
|
67
|
+
status: "skipped",
|
|
68
|
+
code: "npm-module-forbidden-global",
|
|
69
|
+
message: `${npmName} references ${describeFindings(scan.errors)}, which the guest does not provide`
|
|
70
|
+
},
|
|
71
|
+
cached: false,
|
|
72
|
+
key
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
const probe = await probeBundle(bundle.source);
|
|
76
|
+
if (!probe.ok) {
|
|
77
|
+
return {
|
|
78
|
+
outcome: {
|
|
79
|
+
status: "skipped",
|
|
80
|
+
code: "npm-module-probe-failed",
|
|
81
|
+
message: `${npmName} failed the sandbox admission probe: ${probe.error ?? "the module did not initialize"}`
|
|
82
|
+
},
|
|
83
|
+
cached: false,
|
|
84
|
+
key
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
const entry = {
|
|
88
|
+
key,
|
|
89
|
+
npmName,
|
|
90
|
+
compilerVersion: SANDBOX_COMPILER_VERSION,
|
|
91
|
+
esbuildVersion: bundle.esbuildVersion,
|
|
92
|
+
optionsDigest: bundle.optionsDigest,
|
|
93
|
+
inputsDigest: bundle.inputsDigest,
|
|
94
|
+
source: bundle.source,
|
|
95
|
+
bytes: bundle.bytes,
|
|
96
|
+
inputDigests: bundle.inputDigests,
|
|
97
|
+
resolutionDigests: bundle.resolutionDigests,
|
|
98
|
+
scanWarnings: scan.warnings,
|
|
99
|
+
probeOk: true,
|
|
100
|
+
probeExports: probe.exports
|
|
101
|
+
};
|
|
102
|
+
cache?.write(entry);
|
|
103
|
+
cache?.writePointer(packDir, npmName, key);
|
|
104
|
+
return { outcome: outcomeFor(npmName, entry), cached: false, key };
|
|
105
|
+
}
|
|
106
|
+
function outcomeFor(npmName, entry) {
|
|
107
|
+
const warnings = entry.scanWarnings.map((finding) => `${npmName} feature-detects ${finding.name} at ${finding.line}:${finding.column}; the guest has no such global, so that branch never runs`);
|
|
108
|
+
const outcome = {
|
|
109
|
+
status: "compiled",
|
|
110
|
+
artifact: {
|
|
111
|
+
source: entry.source,
|
|
112
|
+
compilerVersion: entry.compilerVersion,
|
|
113
|
+
optionsDigest: entry.optionsDigest,
|
|
114
|
+
inputsDigest: entry.inputsDigest
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
if (warnings.length > 0) {
|
|
118
|
+
outcome.warnings = warnings;
|
|
119
|
+
}
|
|
120
|
+
return outcome;
|
|
121
|
+
}
|
|
122
|
+
function describeFindings(findings) {
|
|
123
|
+
const names = [...new Set(findings.map((finding) => finding.name))].sort();
|
|
124
|
+
const first = findings[0];
|
|
125
|
+
const where = first === undefined ? "" : ` (first at ${first.line}:${first.column})`;
|
|
126
|
+
return `${names.join(", ")}${where}`;
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=compile.js.map
|
|
@@ -0,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,EAAE,UAAU;QAClB,QAAQ,EAAE;YACR,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,eAAe,EAAE,KAAK,CAAC,eAAe;YACtC,aAAa,EAAE,KAAK,CAAC,aAAa;YAClC,YAAY,EAAE,KAAK,CAAC,YAAY;SACjC;KACF,CAAC;IACF,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,OAAO,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC9B,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAS,gBAAgB,CAAC,QAAgC;IACxD,MAAM,KAAK,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAC3E,MAAM,KAAK,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;IAC1B,MAAM,KAAK,GACT,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,cAAc,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;IACzE,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,KAAK,EAAE,CAAC;AACvC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The dedicated npm-module compiler for the sandbox package system.
|
|
3
|
+
*
|
|
4
|
+
* A pack can declare `{"name": ".", "kind": "js", "npm": "js-yaml"}` instead of
|
|
5
|
+
* authoring guest code, and this package produces the module: esbuild bundles
|
|
6
|
+
* the dependency with pinned resolver conditions, a scope-aware scan rejects
|
|
7
|
+
* free references to globals the guest lacks, and a capability-free QuickJS
|
|
8
|
+
* probe imports the result to prove it initializes. Everything is cached by
|
|
9
|
+
* content digest, never by version.
|
|
10
|
+
*
|
|
11
|
+
* It lives outside node-sdk on purpose. node-sdk's discovery is synchronous and
|
|
12
|
+
* must not depend on esbuild or a JavaScript engine, so hosts compile here and
|
|
13
|
+
* inject the artifacts into discovery.
|
|
14
|
+
*/
|
|
15
|
+
export { NPM_BUNDLE_CONDITIONS, NPM_BUNDLE_MAIN_FIELDS, NPM_BUNDLE_MAX_BYTES, NPM_BUNDLE_TARGET, NPM_PROBE_TIMEOUT_MS, SANDBOX_COMPILER_VERSION, normalizedCompileOptions, type NormalizedCompileOptions } from "./options.js";
|
|
16
|
+
export { ABSENT, bundleNpmModule, optionsDigest, type BundleFailure, type BundleOutcome, type BundleResult, type InputDigest, type ResolutionDigest } from "./bundle.js";
|
|
17
|
+
export { FORBIDDEN_GLOBALS, scanBundle, type ScanFinding, type ScanReport } from "./scan.js";
|
|
18
|
+
export { probeBundle, type ProbeVerdict } from "./probe.js";
|
|
19
|
+
export { CompiledModuleCache, computeCacheKey, defaultCacheRoot, type CachedCompilation, type CacheKeyInput } from "./cache.js";
|
|
20
|
+
export { compileNpmModule, type CompileNpmModuleRequest, type CompileNpmModuleResult } from "./compile.js";
|
|
21
|
+
export { compileDiscoveries, compileSandboxCatalog, createCompiledNpmLookup, type CompileCatalogOptions, type CompiledCatalogHost, type CompiledModuleReport } from "./catalog.js";
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,oBAAoB,EACpB,iBAAiB,EACjB,oBAAoB,EACpB,wBAAwB,EACxB,wBAAwB,EACxB,KAAK,wBAAwB,EAC9B,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,MAAM,EACN,eAAe,EACf,aAAa,EACb,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACtB,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,iBAAiB,EACjB,UAAU,EACV,KAAK,WAAW,EAChB,KAAK,UAAU,EAChB,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAE5D,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EAChB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EACnB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,gBAAgB,EAChB,KAAK,uBAAuB,EAC5B,KAAK,sBAAsB,EAC5B,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,uBAAuB,EACvB,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EAC1B,MAAM,cAAc,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The dedicated npm-module compiler for the sandbox package system.
|
|
3
|
+
*
|
|
4
|
+
* A pack can declare `{"name": ".", "kind": "js", "npm": "js-yaml"}` instead of
|
|
5
|
+
* authoring guest code, and this package produces the module: esbuild bundles
|
|
6
|
+
* the dependency with pinned resolver conditions, a scope-aware scan rejects
|
|
7
|
+
* free references to globals the guest lacks, and a capability-free QuickJS
|
|
8
|
+
* probe imports the result to prove it initializes. Everything is cached by
|
|
9
|
+
* content digest, never by version.
|
|
10
|
+
*
|
|
11
|
+
* It lives outside node-sdk on purpose. node-sdk's discovery is synchronous and
|
|
12
|
+
* must not depend on esbuild or a JavaScript engine, so hosts compile here and
|
|
13
|
+
* inject the artifacts into discovery.
|
|
14
|
+
*/
|
|
15
|
+
export { NPM_BUNDLE_CONDITIONS, NPM_BUNDLE_MAIN_FIELDS, NPM_BUNDLE_MAX_BYTES, NPM_BUNDLE_TARGET, NPM_PROBE_TIMEOUT_MS, SANDBOX_COMPILER_VERSION, normalizedCompileOptions } from "./options.js";
|
|
16
|
+
export { ABSENT, bundleNpmModule, optionsDigest } from "./bundle.js";
|
|
17
|
+
export { FORBIDDEN_GLOBALS, scanBundle } from "./scan.js";
|
|
18
|
+
export { probeBundle } from "./probe.js";
|
|
19
|
+
export { CompiledModuleCache, computeCacheKey, defaultCacheRoot } from "./cache.js";
|
|
20
|
+
export { compileNpmModule } from "./compile.js";
|
|
21
|
+
export { compileDiscoveries, compileSandboxCatalog, createCompiledNpmLookup } from "./catalog.js";
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,oBAAoB,EACpB,iBAAiB,EACjB,oBAAoB,EACpB,wBAAwB,EACxB,wBAAwB,EAEzB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,MAAM,EACN,eAAe,EACf,aAAa,EAMd,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,iBAAiB,EACjB,UAAU,EAGX,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,WAAW,EAAqB,MAAM,YAAY,CAAC;AAE5D,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EAGjB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,gBAAgB,EAGjB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,uBAAuB,EAIxB,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The compiler's pinned build options.
|
|
3
|
+
*
|
|
4
|
+
* Every constant here is part of the cache key and of an npm module's content
|
|
5
|
+
* digest, so changing one invalidates every cached artifact — which is the
|
|
6
|
+
* point: a different resolver condition can select a different file of the same
|
|
7
|
+
* package version, and the old bundle must not survive the change.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Export conditions, in priority order.
|
|
11
|
+
*
|
|
12
|
+
* `platform: "neutral"` alone leaves the condition set empty, so a package with
|
|
13
|
+
* `exports` maps resolves through `default` only — or fails. These are pinned
|
|
14
|
+
* instead: the guest is neither Node nor a browser, so `node` and `browser` are
|
|
15
|
+
* deliberately absent and a package's most portable build wins.
|
|
16
|
+
*/
|
|
17
|
+
export declare const NPM_BUNDLE_CONDITIONS: readonly string[];
|
|
18
|
+
/** `package.json` fields consulted for packages that predate `exports`. */
|
|
19
|
+
export declare const NPM_BUNDLE_MAIN_FIELDS: readonly string[];
|
|
20
|
+
/** Syntax level the bundle is lowered to. QuickJS-ng covers ES2022. */
|
|
21
|
+
export declare const NPM_BUNDLE_TARGET = "es2022";
|
|
22
|
+
/**
|
|
23
|
+
* Maximum bundled source, in bytes.
|
|
24
|
+
*
|
|
25
|
+
* Measured against the real bridge candidates in
|
|
26
|
+
* `docs/m3-implementation-plan.md`; the number is evidence, not a guess. It
|
|
27
|
+
* matches `SANDBOX_PACKAGE_LIMITS.npmBundledJsBytes` in node-sdk, which
|
|
28
|
+
* re-checks the artifact discovery actually loads.
|
|
29
|
+
*/
|
|
30
|
+
export declare const NPM_BUNDLE_MAX_BYTES: number;
|
|
31
|
+
/** Wall clock the admission probe gets to import the bundle. */
|
|
32
|
+
export declare const NPM_PROBE_TIMEOUT_MS = 5000;
|
|
33
|
+
/** Guest heap the admission probe gets. */
|
|
34
|
+
export declare const NPM_PROBE_MEMORY_BYTES: number;
|
|
35
|
+
/** Guest stack the admission probe gets. */
|
|
36
|
+
export declare const NPM_PROBE_STACK_BYTES: number;
|
|
37
|
+
/** Console lines the probe keeps; a chatty module cannot flood the host. */
|
|
38
|
+
export declare const NPM_PROBE_MAX_LOG_LINES = 20;
|
|
39
|
+
/** Characters kept per captured probe log line. */
|
|
40
|
+
export declare const NPM_PROBE_MAX_LOG_CHARS = 500;
|
|
41
|
+
/**
|
|
42
|
+
* The compiler's own contract version.
|
|
43
|
+
*
|
|
44
|
+
* Bump it whenever the bundle shim, the scan rules, or the probe change what
|
|
45
|
+
* "admitted" means. It is part of the cache key, so a bump re-compiles and
|
|
46
|
+
* re-probes everything rather than trusting a verdict an older compiler made.
|
|
47
|
+
*/
|
|
48
|
+
export declare const SANDBOX_COMPILER_VERSION = "2";
|
|
49
|
+
/** The build options exactly as the cache key records them. */
|
|
50
|
+
export interface NormalizedCompileOptions {
|
|
51
|
+
readonly conditions: readonly string[];
|
|
52
|
+
readonly mainFields: readonly string[];
|
|
53
|
+
readonly target: string;
|
|
54
|
+
readonly format: "esm";
|
|
55
|
+
readonly platform: "neutral";
|
|
56
|
+
readonly bundle: true;
|
|
57
|
+
readonly minify: false;
|
|
58
|
+
readonly maxBytes: number;
|
|
59
|
+
}
|
|
60
|
+
/** The one option set the compiler builds with. */
|
|
61
|
+
export declare function normalizedCompileOptions(): NormalizedCompileOptions;
|
|
62
|
+
//# sourceMappingURL=options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,EAAE,SAAS,MAAM,EAAoC,CAAC;AAExF,2EAA2E;AAC3E,eAAO,MAAM,sBAAsB,EAAE,SAAS,MAAM,EAAuB,CAAC;AAE5E,uEAAuE;AACvE,eAAO,MAAM,iBAAiB,WAAW,CAAC;AAE1C;;;;;;;GAOG;AACH,eAAO,MAAM,oBAAoB,QAAc,CAAC;AAEhD,gEAAgE;AAChE,eAAO,MAAM,oBAAoB,OAAQ,CAAC;AAE1C,2CAA2C;AAC3C,eAAO,MAAM,sBAAsB,QAAmB,CAAC;AAEvD,4CAA4C;AAC5C,eAAO,MAAM,qBAAqB,QAAc,CAAC;AAEjD,4EAA4E;AAC5E,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAE1C,mDA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