@scriptc/compiler 0.0.0 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/ambient/package.json +3 -0
- package/ambient/scriptc-node-fallback.d.ts +3001 -0
- package/ambient/scriptc-overrides.d.ts +95 -0
- package/ambient/scriptc.d.ts +74 -0
- package/dist/backend/cc.d.ts +169 -0
- package/dist/backend/cc.js +897 -0
- package/dist/backend/cc.js.map +1 -0
- package/dist/backend/emission/emit-async.d.ts +145 -0
- package/dist/backend/emission/emit-async.js +996 -0
- package/dist/backend/emission/emit-async.js.map +1 -0
- package/dist/backend/emission/emit-exprs.d.ts +3 -0
- package/dist/backend/emission/emit-exprs.js +5949 -0
- package/dist/backend/emission/emit-exprs.js.map +1 -0
- package/dist/backend/emission/emit-island.d.ts +45 -0
- package/dist/backend/emission/emit-island.js +271 -0
- package/dist/backend/emission/emit-island.js.map +1 -0
- package/dist/backend/emission/emit-shapes.d.ts +142 -0
- package/dist/backend/emission/emit-shapes.js +575 -0
- package/dist/backend/emission/emit-shapes.js.map +1 -0
- package/dist/backend/emission/emit-stmts.d.ts +78 -0
- package/dist/backend/emission/emit-stmts.js +960 -0
- package/dist/backend/emission/emit-stmts.js.map +1 -0
- package/dist/backend/emission/emit-types.d.ts +65 -0
- package/dist/backend/emission/emit-types.js +652 -0
- package/dist/backend/emission/emit-types.js.map +1 -0
- package/dist/backend/emission/emit-walkers.d.ts +154 -0
- package/dist/backend/emission/emit-walkers.js +1587 -0
- package/dist/backend/emission/emit-walkers.js.map +1 -0
- package/dist/backend/emission/emitter.d.ts +452 -0
- package/dist/backend/emission/emitter.js +1249 -0
- package/dist/backend/emission/emitter.js.map +1 -0
- package/dist/backend/emission/may-throw.d.ts +15 -0
- package/dist/backend/emission/may-throw.js +250 -0
- package/dist/backend/emission/may-throw.js.map +1 -0
- package/dist/backend/llvm/blocks.d.ts +21 -0
- package/dist/backend/llvm/blocks.js +68 -0
- package/dist/backend/llvm/blocks.js.map +1 -0
- package/dist/backend/llvm/classes.d.ts +84 -0
- package/dist/backend/llvm/classes.js +438 -0
- package/dist/backend/llvm/classes.js.map +1 -0
- package/dist/backend/llvm/dyn.d.ts +123 -0
- package/dist/backend/llvm/dyn.js +2624 -0
- package/dist/backend/llvm/dyn.js.map +1 -0
- package/dist/backend/llvm/emitter.d.ts +3 -0
- package/dist/backend/llvm/emitter.js +10102 -0
- package/dist/backend/llvm/emitter.js.map +1 -0
- package/dist/backend/llvm/shapes.d.ts +78 -0
- package/dist/backend/llvm/shapes.js +754 -0
- package/dist/backend/llvm/shapes.js.map +1 -0
- package/dist/backend/llvm/unsupported.d.ts +6 -0
- package/dist/backend/llvm/unsupported.js +12 -0
- package/dist/backend/llvm/unsupported.js.map +1 -0
- package/dist/backend/llvm/walkers.d.ts +58 -0
- package/dist/backend/llvm/walkers.js +793 -0
- package/dist/backend/llvm/walkers.js.map +1 -0
- package/dist/backend/mangle.d.ts +124 -0
- package/dist/backend/mangle.js +232 -0
- package/dist/backend/mangle.js.map +1 -0
- package/dist/coverage/report.d.ts +65 -0
- package/dist/coverage/report.js +238 -0
- package/dist/coverage/report.js.map +1 -0
- package/dist/diagnostics/diagnostic.d.ts +140 -0
- package/dist/diagnostics/diagnostic.js +458 -0
- package/dist/diagnostics/diagnostic.js.map +1 -0
- package/dist/diagnostics/render.d.ts +11 -0
- package/dist/diagnostics/render.js +58 -0
- package/dist/diagnostics/render.js.map +1 -0
- package/dist/frontend/cjs-lexer.d.ts +20 -0
- package/dist/frontend/cjs-lexer.js +813 -0
- package/dist/frontend/cjs-lexer.js.map +1 -0
- package/dist/frontend/lowering/http2-constants.d.ts +1 -0
- package/dist/frontend/lowering/http2-constants.js +251 -0
- package/dist/frontend/lowering/http2-constants.js.map +1 -0
- package/dist/frontend/lowering/lib-boundary.d.ts +6 -0
- package/dist/frontend/lowering/lib-boundary.js +143 -0
- package/dist/frontend/lowering/lib-boundary.js.map +1 -0
- package/dist/frontend/lowering/lower-assert.d.ts +18 -0
- package/dist/frontend/lowering/lower-assert.js +1269 -0
- package/dist/frontend/lowering/lower-assert.js.map +1 -0
- package/dist/frontend/lowering/lower-builtins.d.ts +511 -0
- package/dist/frontend/lowering/lower-builtins.js +5249 -0
- package/dist/frontend/lowering/lower-builtins.js.map +1 -0
- package/dist/frontend/lowering/lower-calls.d.ts +581 -0
- package/dist/frontend/lowering/lower-calls.js +6286 -0
- package/dist/frontend/lowering/lower-calls.js.map +1 -0
- package/dist/frontend/lowering/lower-classes.d.ts +727 -0
- package/dist/frontend/lowering/lower-classes.js +4701 -0
- package/dist/frontend/lowering/lower-classes.js.map +1 -0
- package/dist/frontend/lowering/lower-comptime.d.ts +53 -0
- package/dist/frontend/lowering/lower-comptime.js +244 -0
- package/dist/frontend/lowering/lower-comptime.js.map +1 -0
- package/dist/frontend/lowering/lower-containers.d.ts +486 -0
- package/dist/frontend/lowering/lower-containers.js +6345 -0
- package/dist/frontend/lowering/lower-containers.js.map +1 -0
- package/dist/frontend/lowering/lower-dgram.d.ts +20 -0
- package/dist/frontend/lowering/lower-dgram.js +319 -0
- package/dist/frontend/lowering/lower-dgram.js.map +1 -0
- package/dist/frontend/lowering/lower-emitter.d.ts +10 -0
- package/dist/frontend/lowering/lower-emitter.js +688 -0
- package/dist/frontend/lowering/lower-emitter.js.map +1 -0
- package/dist/frontend/lowering/lower-enums.d.ts +22 -0
- package/dist/frontend/lowering/lower-enums.js +235 -0
- package/dist/frontend/lowering/lower-enums.js.map +1 -0
- package/dist/frontend/lowering/lower-expando.d.ts +35 -0
- package/dist/frontend/lowering/lower-expando.js +276 -0
- package/dist/frontend/lowering/lower-expando.js.map +1 -0
- package/dist/frontend/lowering/lower-exprs.d.ts +524 -0
- package/dist/frontend/lowering/lower-exprs.js +8111 -0
- package/dist/frontend/lowering/lower-exprs.js.map +1 -0
- package/dist/frontend/lowering/lower-generators.d.ts +50 -0
- package/dist/frontend/lowering/lower-generators.js +421 -0
- package/dist/frontend/lowering/lower-generators.js.map +1 -0
- package/dist/frontend/lowering/lower-inspect.d.ts +20 -0
- package/dist/frontend/lowering/lower-inspect.js +1074 -0
- package/dist/frontend/lowering/lower-inspect.js.map +1 -0
- package/dist/frontend/lowering/lower-island.d.ts +108 -0
- package/dist/frontend/lowering/lower-island.js +650 -0
- package/dist/frontend/lowering/lower-island.js.map +1 -0
- package/dist/frontend/lowering/lower-mixins.d.ts +96 -0
- package/dist/frontend/lowering/lower-mixins.js +534 -0
- package/dist/frontend/lowering/lower-mixins.js.map +1 -0
- package/dist/frontend/lowering/lower-modules.d.ts +135 -0
- package/dist/frontend/lowering/lower-modules.js +1613 -0
- package/dist/frontend/lowering/lower-modules.js.map +1 -0
- package/dist/frontend/lowering/lower-namespaces.d.ts +168 -0
- package/dist/frontend/lowering/lower-namespaces.js +706 -0
- package/dist/frontend/lowering/lower-namespaces.js.map +1 -0
- package/dist/frontend/lowering/lower-server.d.ts +90 -0
- package/dist/frontend/lowering/lower-server.js +3471 -0
- package/dist/frontend/lowering/lower-server.js.map +1 -0
- package/dist/frontend/lowering/lower-stmts.d.ts +361 -0
- package/dist/frontend/lowering/lower-stmts.js +5341 -0
- package/dist/frontend/lowering/lower-stmts.js.map +1 -0
- package/dist/frontend/lowering/lower-stream.d.ts +88 -0
- package/dist/frontend/lowering/lower-stream.js +1533 -0
- package/dist/frontend/lowering/lower-stream.js.map +1 -0
- package/dist/frontend/lowering/lower-test.d.ts +27 -0
- package/dist/frontend/lowering/lower-test.js +353 -0
- package/dist/frontend/lowering/lower-test.js.map +1 -0
- package/dist/frontend/lowering/lowerer.d.ts +1748 -0
- package/dist/frontend/lowering/lowerer.js +6257 -0
- package/dist/frontend/lowering/lowerer.js.map +1 -0
- package/dist/frontend/lowering/surfaces.d.ts +272 -0
- package/dist/frontend/lowering/surfaces.js +1096 -0
- package/dist/frontend/lowering/surfaces.js.map +1 -0
- package/dist/frontend/npm-static.d.ts +55 -0
- package/dist/frontend/npm-static.js +300 -0
- package/dist/frontend/npm-static.js.map +1 -0
- package/dist/frontend/npm.d.ts +330 -0
- package/dist/frontend/npm.js +1259 -0
- package/dist/frontend/npm.js.map +1 -0
- package/dist/frontend/program.d.ts +186 -0
- package/dist/frontend/program.js +2255 -0
- package/dist/frontend/program.js.map +1 -0
- package/dist/frontend/provenance-registry.d.ts +48 -0
- package/dist/frontend/provenance-registry.js +87 -0
- package/dist/frontend/provenance-registry.js.map +1 -0
- package/dist/frontend/provenance.d.ts +6 -0
- package/dist/frontend/provenance.js +459 -0
- package/dist/frontend/provenance.js.map +1 -0
- package/dist/frontend/resolve.d.ts +56 -0
- package/dist/frontend/resolve.js +682 -0
- package/dist/frontend/resolve.js.map +1 -0
- package/dist/frontend/shared.d.ts +67 -0
- package/dist/frontend/shared.js +241 -0
- package/dist/frontend/shared.js.map +1 -0
- package/dist/frontend/ts7/adapter.d.ts +7 -0
- package/dist/frontend/ts7/adapter.js +54 -0
- package/dist/frontend/ts7/adapter.js.map +1 -0
- package/dist/frontend/ts7/ast.d.ts +50 -0
- package/dist/frontend/ts7/ast.js +211 -0
- package/dist/frontend/ts7/ast.js.map +1 -0
- package/dist/frontend/ts7/census-check.d.ts +1 -0
- package/dist/frontend/ts7/census-check.js +12 -0
- package/dist/frontend/ts7/census-check.js.map +1 -0
- package/dist/frontend/ts7/checker.d.ts +140 -0
- package/dist/frontend/ts7/checker.js +544 -0
- package/dist/frontend/ts7/checker.js.map +1 -0
- package/dist/frontend/ts7/enums.d.ts +18 -0
- package/dist/frontend/ts7/enums.js +43 -0
- package/dist/frontend/ts7/enums.js.map +1 -0
- package/dist/frontend/ts7/program.d.ts +99 -0
- package/dist/frontend/ts7/program.js +278 -0
- package/dist/frontend/ts7/program.js.map +1 -0
- package/dist/frontend/ts7/world-check.d.ts +3 -0
- package/dist/frontend/ts7/world-check.js +34 -0
- package/dist/frontend/ts7/world-check.js.map +1 -0
- package/dist/frontend/types.d.ts +205 -0
- package/dist/frontend/types.js +2485 -0
- package/dist/frontend/types.js.map +1 -0
- package/dist/index.d.ts +85 -0
- package/dist/index.js +429 -0
- package/dist/index.js.map +1 -0
- package/dist/ir/nodes.d.ts +4334 -0
- package/dist/ir/nodes.js +1906 -0
- package/dist/ir/nodes.js.map +1 -0
- package/dist/ir/serialize.d.ts +4 -0
- package/dist/ir/serialize.js +34 -0
- package/dist/ir/serialize.js.map +1 -0
- package/dist/ir/validate.d.ts +36 -0
- package/dist/ir/validate.js +4885 -0
- package/dist/ir/validate.js.map +1 -0
- package/package.json +30 -6
- package/README.md +0 -3
- package/index.js +0 -2
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
export type EmbeddedFormat = "esm" | "cjs" | "json";
|
|
2
|
+
export interface EmbeddedModule {
|
|
3
|
+
/** The resolved REAL path (symlinks followed) — the loader's cache key. */
|
|
4
|
+
key: string;
|
|
5
|
+
source: string;
|
|
6
|
+
format: EmbeddedFormat;
|
|
7
|
+
/** CommonJS only: the synthesized ESM facade the island's module loader
|
|
8
|
+
* evaluates when an ES module imports this file — default plus the LEXED
|
|
9
|
+
* named exports (cjsEsmFacadeSource). ESM sources compile natively and
|
|
10
|
+
* JSON keeps the loader's default-only wrapper, so both leave this
|
|
11
|
+
* unset. */
|
|
12
|
+
esm?: string;
|
|
13
|
+
}
|
|
14
|
+
/** The ESM facade for an embedded CommonJS module, matching Node's interop
|
|
15
|
+
* exactly (verified against Node 24): `default` IS module.exports;
|
|
16
|
+
* "module.exports" is a named alias for it (Node ships that export name);
|
|
17
|
+
* every lexed name binds the exports object's OWN property when one exists
|
|
18
|
+
* at facade evaluation (getters read once — a snapshot, like Node's
|
|
19
|
+
* loop over the lexed set) and stays undefined otherwise (a lexed-but-
|
|
20
|
+
* never-assigned name is a live binding of undefined, not an error;
|
|
21
|
+
* inherited properties do NOT leak through, hence the hasOwnProperty
|
|
22
|
+
* guard). Export names that aren't identifiers ("dash-name") use string
|
|
23
|
+
* ModuleExportNames — every name does, uniformly; the locals are e0, e1, …
|
|
24
|
+
* temps. */
|
|
25
|
+
export declare function cjsEsmFacadeSource(key: string, names: readonly string[]): string;
|
|
26
|
+
export interface EmbeddedEdge {
|
|
27
|
+
/** Importer's key. */
|
|
28
|
+
from: string;
|
|
29
|
+
/** The specifier as written in the importer's source. */
|
|
30
|
+
specifier: string;
|
|
31
|
+
/** Resolved target: an embedded module's key, or a "node:*" builtin. */
|
|
32
|
+
to: string;
|
|
33
|
+
/** Which call forms this resolution serves — Node picks the "exports"
|
|
34
|
+
* condition set from the EDGE KIND, not the importer's format, so one
|
|
35
|
+
* (from, specifier) can name TWO targets: a dual package's "import"
|
|
36
|
+
* condition for import/import() sites and its "require" condition for
|
|
37
|
+
* require() sites. "any" (relative files, builtins, edges whose kinds
|
|
38
|
+
* agree) answers both lookups. */
|
|
39
|
+
kind: "any" | "import" | "require";
|
|
40
|
+
}
|
|
41
|
+
/** What a dynamic import() specifier resolves to at build time. */
|
|
42
|
+
export type DynamicImportResolution =
|
|
43
|
+
/** An embedded module's key or a shimmed builtin's "node:x" key —
|
|
44
|
+
* island.importDyn loads it through the engine's module system. */
|
|
45
|
+
{
|
|
46
|
+
kind: "module";
|
|
47
|
+
key: string;
|
|
48
|
+
}
|
|
49
|
+
/** A Node builtin the island ships no shim for — a build diagnostic,
|
|
50
|
+
* exactly like a static import of it. */
|
|
51
|
+
| {
|
|
52
|
+
kind: "unsupported-builtin";
|
|
53
|
+
builtin: string;
|
|
54
|
+
}
|
|
55
|
+
/** The specifier resolves into the compiled program's own TypeScript —
|
|
56
|
+
* fenced at the site (static imports are the way in). */
|
|
57
|
+
| {
|
|
58
|
+
kind: "program-module";
|
|
59
|
+
}
|
|
60
|
+
/** No resolution — a build diagnostic, like static imports. */
|
|
61
|
+
| {
|
|
62
|
+
kind: "unresolved";
|
|
63
|
+
message: string;
|
|
64
|
+
};
|
|
65
|
+
export interface NpmGraphError {
|
|
66
|
+
/** Human-readable failure ("package 'x' requires 'node:stream', which
|
|
67
|
+
* the island does not provide"). The caller attaches the import site. */
|
|
68
|
+
message: string;
|
|
69
|
+
}
|
|
70
|
+
/** One Node builtin the embedded graph imports — the coverage report's
|
|
71
|
+
* honesty about what the island must (or cannot) provide. */
|
|
72
|
+
export interface NpmBuiltinUse {
|
|
73
|
+
/** Canonical "node:x" key. */
|
|
74
|
+
builtin: string;
|
|
75
|
+
/** Whether the island ships a shim for it. */
|
|
76
|
+
shimmed: boolean;
|
|
77
|
+
/** Unshimmed AND only require()/import() edges reach it: the build
|
|
78
|
+
* embeds the island's lazy throw at the call instead of failing —
|
|
79
|
+
* Node's laziness for those edge kinds (Node itself would LOAD the
|
|
80
|
+
* builtin; the trap is the island's honest refusal at the only point
|
|
81
|
+
* Node would have loaded it). Always false when shimmed or when any
|
|
82
|
+
* static import reaches it (static keeps the eager build error). */
|
|
83
|
+
lazy: boolean;
|
|
84
|
+
/** The packages whose embedded code imports it (sorted). */
|
|
85
|
+
packages: string[];
|
|
86
|
+
}
|
|
87
|
+
/** One unresolvable specifier reached ONLY by require()/dynamic import()
|
|
88
|
+
* edges: the build embeds a runtime trap with Node's call-time error shape
|
|
89
|
+
* (MODULE_NOT_FOUND for require, ERR_MODULE_NOT_FOUND for import()) instead
|
|
90
|
+
* of failing — the coverage report lists these beside the builtins so the
|
|
91
|
+
* build output stays honest about what the binary cannot reach. */
|
|
92
|
+
export interface NpmLazyTrap {
|
|
93
|
+
/** The specifier as written at the call site. */
|
|
94
|
+
specifier: string;
|
|
95
|
+
/** The call forms that reach it (sorted, require first). "import" is a
|
|
96
|
+
* STATIC import inside a lazily-reached module — Node links that whole
|
|
97
|
+
* subgraph at the require()/import() boundary that reaches it, so the
|
|
98
|
+
* failure surfaces there, at the call. */
|
|
99
|
+
via: ("require" | "import()" | "import")[];
|
|
100
|
+
/** The packages whose embedded code holds the call sites (sorted). */
|
|
101
|
+
packages: string[];
|
|
102
|
+
/** The specifier RESOLVED — to a native .node addon the island cannot
|
|
103
|
+
* dlopen. The build embeds a throwing stub (Node's ERR_DLOPEN_FAILED
|
|
104
|
+
* code) instead of the addon's raw bytes; the require/import() throws
|
|
105
|
+
* at the call. Unset for the unresolvable rows above. */
|
|
106
|
+
native?: boolean;
|
|
107
|
+
}
|
|
108
|
+
export interface NpmRuntimeGraph {
|
|
109
|
+
modules: EmbeddedModule[];
|
|
110
|
+
edges: EmbeddedEdge[];
|
|
111
|
+
/** (importing file dir + specifier) → the package's runtime entry key. */
|
|
112
|
+
entryOf: (fromFile: string, specifier: string) => string | null;
|
|
113
|
+
/** Every Node builtin the embedded graph imports, shimmed or not. */
|
|
114
|
+
builtins: NpmBuiltinUse[];
|
|
115
|
+
/** Unresolvable lazily-reached specifiers embedded as runtime traps. */
|
|
116
|
+
lazyTraps: NpmLazyTrap[];
|
|
117
|
+
errors: NpmGraphError[];
|
|
118
|
+
}
|
|
119
|
+
interface Host {
|
|
120
|
+
readFile: (path: string) => string | null;
|
|
121
|
+
isFile: (path: string) => boolean;
|
|
122
|
+
isDirectory: (path: string) => boolean;
|
|
123
|
+
/** fs.realpathSync semantics; returns the input when resolution fails. */
|
|
124
|
+
realpath: (path: string) => string;
|
|
125
|
+
}
|
|
126
|
+
/** Package name from a PATH into node_modules ("…/node_modules/@s/p/d/x.js"
|
|
127
|
+
* → "@s/p"), for diagnostics/chains when the entry is a file, not a bare
|
|
128
|
+
* specifier. Null when the path holds no node_modules segment. */
|
|
129
|
+
export declare function packageNameOfPath(path: string): string | null;
|
|
130
|
+
/** package.json "exports" resolution, per Node: subpath map with exact
|
|
131
|
+
* keys first, then '*' patterns (longest literal prefix wins, the matched
|
|
132
|
+
* text substitutes into the target), condition objects matched in OBJECT
|
|
133
|
+
* KEY order against the enabled set ("import" or "require", plus "node"
|
|
134
|
+
* and "default"), string targets, arrays taking the first resolvable
|
|
135
|
+
* entry. Returns a path relative to the package dir, or null. */
|
|
136
|
+
export declare function resolveExports(exports: unknown, subpath: string, mode: "import" | "require"): string | null;
|
|
137
|
+
/** A bare-specifier import edge Node's ESM resolution REFUSES, with Node's
|
|
138
|
+
* exact error message and code — or null (resolvable, or a shape this
|
|
139
|
+
* probe stays conservative about). The three refusal shapes it answers,
|
|
140
|
+
* per Node's PACKAGE_RESOLVE with the ["import","node","default"]
|
|
141
|
+
* condition set:
|
|
142
|
+
* - nothing installed: no node_modules/<name> from the importer up to
|
|
143
|
+
* the filesystem root (and no matching self-scope) — ERR_MODULE_NOT_FOUND
|
|
144
|
+
* ("Cannot find package ...");
|
|
145
|
+
* - an "exports" map that refuses the subpath (unmatched, or matched to
|
|
146
|
+
* a null target) — ERR_PACKAGE_PATH_NOT_EXPORTED. Node's self-reference
|
|
147
|
+
* rule participates: a nearest package scope whose "name" matches makes
|
|
148
|
+
* that scope's "exports" the FINAL answer (no node_modules fallback);
|
|
149
|
+
* - a matched exports target whose exact file does not exist —
|
|
150
|
+
* ERR_MODULE_NOT_FOUND ("Cannot find module '<abs>' ..."). Exports
|
|
151
|
+
* targets resolve to exact files in Node's ESM — no extension guessing.
|
|
152
|
+
* Everything else (no "exports": legacy main/index resolution with its
|
|
153
|
+
* leniencies; directory-shaped targets; unreadable package.json) answers
|
|
154
|
+
* null — the caller keeps its existing story. Callers exclude builtins and
|
|
155
|
+
* project-internal (#alias/self-name) resolutions BEFORE probing. */
|
|
156
|
+
export interface NodeImportRefusal {
|
|
157
|
+
message: string;
|
|
158
|
+
code: "ERR_MODULE_NOT_FOUND" | "ERR_PACKAGE_PATH_NOT_EXPORTED";
|
|
159
|
+
/** file:// url of the missing resolved target, when the refusal has one
|
|
160
|
+
* (Node's ERR_MODULE_NOT_FOUND carries it for resolved-but-missing). */
|
|
161
|
+
url?: string;
|
|
162
|
+
}
|
|
163
|
+
export declare function probeNodeImportRefusal(fromFile: string, specifier: string, host?: Host): NodeImportRefusal | null;
|
|
164
|
+
/** A bare-specifier `require()` edge Node's CJS resolution REFUSES because
|
|
165
|
+
* NOTHING INSTALLED resolves it: no node_modules/<name> from the requiring
|
|
166
|
+
* file up to the filesystem root, and no self-scope whose "name" matches.
|
|
167
|
+
* Answers Node's exact require-site Error message (MODULE_NOT_FOUND's
|
|
168
|
+
* "Cannot find module '<spec>'" with the one-entry require stack — the
|
|
169
|
+
* message property really carries both lines). Everything else — installed
|
|
170
|
+
* packages (whatever their exports say), builtins, relative and "#"
|
|
171
|
+
* specifiers — answers null: the callers' existing stories stand. Unlike
|
|
172
|
+
* the ESM startup-crash channel (SEMANTICS.md 287), this refusal is a
|
|
173
|
+
* RUNTIME throw at the require site, catchable — the optional-dependency
|
|
174
|
+
* try/require pattern depends on exactly that. */
|
|
175
|
+
export declare function probeNodeRequireRefusal(fromFile: string, specifier: string, host?: Host): {
|
|
176
|
+
message: string;
|
|
177
|
+
} | null;
|
|
178
|
+
export declare class NpmGraphBuilder {
|
|
179
|
+
private readonly host;
|
|
180
|
+
private readonly modules;
|
|
181
|
+
private readonly edges;
|
|
182
|
+
private readonly edgeSeen;
|
|
183
|
+
private readonly entries;
|
|
184
|
+
readonly errors: NpmGraphError[];
|
|
185
|
+
private readonly pkgJsonCache;
|
|
186
|
+
/** Modules whose format the RESOLUTION decided (the "module" field names
|
|
187
|
+
* ESM sources regardless of the package's "type"). */
|
|
188
|
+
private readonly formatOverrides;
|
|
189
|
+
/** Canonical "node:x" → packages whose code imports it. */
|
|
190
|
+
private readonly builtinsSeen;
|
|
191
|
+
/** Canonical "node:x" keys some STATIC import reaches — those keep the
|
|
192
|
+
* eager build error, so their builtins never mark lazy. */
|
|
193
|
+
private readonly builtinsEager;
|
|
194
|
+
/** Unresolvable (or native-addon) lazily-reached specifiers → merged
|
|
195
|
+
* call forms/packages. */
|
|
196
|
+
private readonly lazyTrapsSeen;
|
|
197
|
+
/** Synthetic keys for embedded import()-not-found stubs. */
|
|
198
|
+
private importTrapCount;
|
|
199
|
+
/** moduleSpecifiersOf per module key — sweepEdges parses each module
|
|
200
|
+
* once; the `__require` attribution chain re-reads helper chunks
|
|
201
|
+
* through this cache. */
|
|
202
|
+
private readonly specifiersCache;
|
|
203
|
+
constructor(host?: Host);
|
|
204
|
+
/** Registers one user-level npm import and walks everything it reaches.
|
|
205
|
+
* Idempotent per (importing dir, specifier). */
|
|
206
|
+
addImport(fromFile: string, specifier: string): void;
|
|
207
|
+
/** Registers one user-level RELATIVE import whose target lives inside
|
|
208
|
+
* node_modules — the e2e driver shape (`import "../node_modules/vercel/
|
|
209
|
+
* dist/index.js"`): tsc resolves the FILE into the program, but shipped
|
|
210
|
+
* package code has exactly one execution home, the embedded engine.
|
|
211
|
+
* Resolves with Node's file rules, embeds the reached graph EAGERLY (a
|
|
212
|
+
* static import links at the root), and answers the runtime entry key.
|
|
213
|
+
* Idempotent per (importing dir, specifier). */
|
|
214
|
+
addFileImport(fromFile: string, specifier: string): string | null;
|
|
215
|
+
/** Registers one user-level dynamic `import(specifier)` and embeds what
|
|
216
|
+
* it reaches, returning the build-time classification the lowering acts
|
|
217
|
+
* on. Bare package specifiers take the same path as static imports;
|
|
218
|
+
* builtins map to their island shim keys ("fs" → "node:fs") or report
|
|
219
|
+
* the missing shim; RELATIVE specifiers — the shape static imports never
|
|
220
|
+
* see, because tsc compiles those — resolve against the importing FILE
|
|
221
|
+
* with Node's file/extension/directory rules and embed the reached JS
|
|
222
|
+
* graph. A relative target that is TypeScript is the program's own
|
|
223
|
+
* module (fenced at the site: static imports are the way in), and one
|
|
224
|
+
* with an extension no loader executes (.wasm, .node, ...) embeds a stub
|
|
225
|
+
* whose EVALUATION throws Node's exact ERR_UNKNOWN_FILE_EXTENSION
|
|
226
|
+
* TypeError — the build succeeds and the import() rejects at runtime,
|
|
227
|
+
* which is precisely what Node does. */
|
|
228
|
+
addDynamicImport(fromFile: string, specifier: string): DynamicImportResolution;
|
|
229
|
+
/** Embeds (once per distinct refusal) the ESM stub whose EVALUATION
|
|
230
|
+
* throws a probed Node refusal — the import() rejects at runtime with
|
|
231
|
+
* Node's exact message and code, the build succeeds. */
|
|
232
|
+
private refusalTrap;
|
|
233
|
+
/** The runtime entry key a previously-added import resolved to. */
|
|
234
|
+
entryOf(fromFile: string, specifier: string): string | null;
|
|
235
|
+
private entryKeyFor;
|
|
236
|
+
private resolveEntry;
|
|
237
|
+
/** The cjs-lexer.ts pass over every embedded CommonJS module: lex the
|
|
238
|
+
* export names exactly as Node's vendored lexer would, follow the
|
|
239
|
+
* re-export forms (`module.exports = require(…)`, table spreads/values,
|
|
240
|
+
* the tsc/babel star patterns) through the ALREADY-RESOLVED edges
|
|
241
|
+
* (builtin and unresolved targets are skipped; a require cycle
|
|
242
|
+
* contributes what is known when re-entered, like Node's seen-set), then
|
|
243
|
+
* synthesize each module's ESM facade. */
|
|
244
|
+
private synthesizeCjsFacades;
|
|
245
|
+
finish(): NpmRuntimeGraph;
|
|
246
|
+
/** Records one unresolvable lazily-reached specifier for the build-time
|
|
247
|
+
* inventory (the coverage report's lazy-trap rows). `via` carries only
|
|
248
|
+
* the call forms whose OWN resolution failed — with per-kind condition
|
|
249
|
+
* resolution, one form of a specifier can fail while another succeeds. */
|
|
250
|
+
private noteLazyTrap;
|
|
251
|
+
/** Embeds the throwing ESM stub for an unresolvable dynamic import()
|
|
252
|
+
* edge — Node's exact ERR_MODULE_NOT_FOUND shape at evaluation: bare
|
|
253
|
+
* specifiers say `Cannot find package 'x' imported from <file>`,
|
|
254
|
+
* relative ones resolve against the importer first and say `Cannot find
|
|
255
|
+
* module '<abs>' imported from <file>` carrying the file:// url, which
|
|
256
|
+
* is what Node's ESM resolver rejects with. Returns the stub's key (the
|
|
257
|
+
* edge target). require() never reaches these: unresolvable require
|
|
258
|
+
* edges embed NO edge and the island's require shim throws Node's
|
|
259
|
+
* MODULE_NOT_FOUND at the call, with the LIVE require stack. */
|
|
260
|
+
private importNotFoundTrap;
|
|
261
|
+
/** The throwing stub embedded for a resolved .node native addon: Node's
|
|
262
|
+
* ERR_DLOPEN_FAILED code (what a broken dlopen throws) with the island's
|
|
263
|
+
* honest message. Evaluation throws — at the require() call, at a
|
|
264
|
+
* facade-mediated import, at import() — and the CJS cache keeps no entry
|
|
265
|
+
* for a throwing module, so every retry throws again, like Node. */
|
|
266
|
+
static nativeAddonStub(key: string): string;
|
|
267
|
+
private pkgJsonOf;
|
|
268
|
+
/** The nearest package.json "type" above `file` — the .js format rule.
|
|
269
|
+
* Resolution-time overrides (the "module" field) win. */
|
|
270
|
+
private formatOf;
|
|
271
|
+
/** Node-style file resolution: exact file, extension candidates
|
|
272
|
+
* (commander requires './suggestSimilar'; ".node" is in Node's require
|
|
273
|
+
* probe list — the resolved addon embeds as a throwing dlopen stub),
|
|
274
|
+
* then directory resolution (the directory's package.json "main", else
|
|
275
|
+
* its index files). */
|
|
276
|
+
private resolveFile;
|
|
277
|
+
/** "a → b → c" — the package chain from the user's import to the point
|
|
278
|
+
* of failure, for diagnostics. */
|
|
279
|
+
private static chainOf;
|
|
280
|
+
/** Locates node_modules/<name> by walking up from `fromDir` to the
|
|
281
|
+
* filesystem ROOT (dependencies hoist arbitrarily far in workspace
|
|
282
|
+
* layouts), following symlinks with realpath (pnpm/bun virtual stores),
|
|
283
|
+
* then resolves the runtime entry: package.json "exports" with the
|
|
284
|
+
* given condition (strict — an exports map that doesn't match is an
|
|
285
|
+
* error, like Node's ERR_PACKAGE_PATH_NOT_EXPORTED), else the "module"/
|
|
286
|
+
* "main" fallbacks. Returns the realpath'd entry key. */
|
|
287
|
+
private resolvePackage;
|
|
288
|
+
/** Modules reached ONLY through lazy edges so far. Node has not linked
|
|
289
|
+
* these at the root: the whole subgraph behind a require()/import()
|
|
290
|
+
* boundary links AT THE CALL, so every blocked edge inside it — static
|
|
291
|
+
* imports included — fails there at runtime, never at build time. A
|
|
292
|
+
* later STATIC path promotes the module to eager: its edges re-sweep so
|
|
293
|
+
* blocked static ones become build errors, exactly the graph Node would
|
|
294
|
+
* refuse at link. */
|
|
295
|
+
private readonly lazilyReached;
|
|
296
|
+
/** Embeds `key` and everything it reaches. `chain` is the package path
|
|
297
|
+
* from the user's import to this module's package — diagnostics name it
|
|
298
|
+
* so a failure five dependencies deep is attributable. `lazy` is the
|
|
299
|
+
* REACHABILITY mode: true when every path from the user's import to this
|
|
300
|
+
* module crosses a require()/dynamic-import() edge. */
|
|
301
|
+
private walk;
|
|
302
|
+
/** moduleSpecifiersOf through the per-module cache (each module parses
|
|
303
|
+
* once even across promotion re-sweeps, and the `__require` attribution
|
|
304
|
+
* chain re-reads helper chunks it never sweeps itself). */
|
|
305
|
+
private specifiersOf;
|
|
306
|
+
/** The module whose scope DEFINES the `__require` helper that `key`'s
|
|
307
|
+
* call sites invoke, or null when it is key's own (or unresolvable).
|
|
308
|
+
* esbuild splits the helper into a shared chunk that every other chunk
|
|
309
|
+
* imports; the helper closed over THAT chunk's banner require
|
|
310
|
+
* (createRequire(import.meta.url)), so Node resolves its calls from the
|
|
311
|
+
* DEFINING chunk — and the island's require shim looks the edge up
|
|
312
|
+
* under that key at the call. Follows import → re-export hops through
|
|
313
|
+
* intermediate chunks, bounded. */
|
|
314
|
+
private requireHelperOriginOf;
|
|
315
|
+
/** One module's edge sweep. Per-edge semantics match Node's: an edge is
|
|
316
|
+
* EAGER only when the module itself is eagerly reached AND the site is a
|
|
317
|
+
* static import/export declaration — Node's link-time surface, where a
|
|
318
|
+
* blocked edge fails the BUILD. Everything else is LAZY — Node fails
|
|
319
|
+
* require at the CALL and import() at evaluation, and a subgraph behind
|
|
320
|
+
* either boundary (its static edges included) links at that call — so a
|
|
321
|
+
* blocked lazy edge embeds a runtime trap and the build succeeds: a
|
|
322
|
+
* program that never executes the call runs fine under Node too. */
|
|
323
|
+
private sweepEdges;
|
|
324
|
+
}
|
|
325
|
+
/** One-call convenience over NpmGraphBuilder. */
|
|
326
|
+
export declare function buildNpmRuntimeGraph(imports: readonly {
|
|
327
|
+
fromFile: string;
|
|
328
|
+
specifier: string;
|
|
329
|
+
}[]): NpmRuntimeGraph;
|
|
330
|
+
export {};
|