@alchemy.run/node-utils 2.0.0-beta.77 → 2.0.0-beta.78
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/lib/register-oxc.d.ts +54 -9
- package/lib/register-oxc.d.ts.map +1 -1
- package/lib/register-oxc.js +49 -86
- package/lib/register-oxc.js.map +1 -1
- package/lib/resolve-specifier.d.ts +0 -6
- package/lib/resolve-specifier.d.ts.map +1 -1
- package/lib/resolve-specifier.js +0 -16
- package/lib/resolve-specifier.js.map +1 -1
- package/lib/transform-cache.d.ts +63 -0
- package/lib/transform-cache.d.ts.map +1 -0
- package/lib/transform-cache.js +193 -0
- package/lib/transform-cache.js.map +1 -0
- package/lib/transform-source.d.ts +3 -3
- package/lib/transform-source.d.ts.map +1 -1
- package/lib/transform-source.js +123 -50
- package/lib/transform-source.js.map +1 -1
- package/lib/watch-import-bun.d.ts.map +1 -1
- package/lib/watch-import-bun.js +7 -2
- package/lib/watch-import-bun.js.map +1 -1
- package/lib/watch-import.d.ts +2 -2
- package/lib/watch-import.d.ts.map +1 -1
- package/lib/watch-import.js +4 -2
- package/lib/watch-import.js.map +1 -1
- package/package.json +1 -6
- package/src/register-oxc.ts +117 -122
- package/src/resolve-specifier.ts +0 -22
- package/src/transform-cache.ts +226 -0
- package/src/transform-source.ts +145 -61
- package/src/watch-import-bun.ts +7 -2
- package/src/watch-import.ts +7 -8
- package/lib/import-loader.d.ts +0 -54
- package/lib/import-loader.d.ts.map +0 -1
- package/lib/import-loader.js +0 -9
- package/lib/import-loader.js.map +0 -1
- package/src/import-loader.ts +0 -75
package/lib/register-oxc.d.ts
CHANGED
|
@@ -1,16 +1,61 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export interface OxcLoaderOptions {
|
|
2
|
+
/**
|
|
3
|
+
* Additional package export conditions used during module resolution.
|
|
4
|
+
* They are made available alongside Node's ambient conditions to both the
|
|
5
|
+
* TypeScript-aware resolver and Node's package exports resolver.
|
|
6
|
+
*/
|
|
7
|
+
readonly conditions?: ReadonlyArray<string> | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* Honour `tsconfig.json` discovered upward from each file: compiler
|
|
10
|
+
* options for the transform, `paths`/`baseUrl` aliases for resolution.
|
|
11
|
+
* @default true
|
|
12
|
+
*/
|
|
13
|
+
readonly tsconfig?: boolean | undefined;
|
|
14
|
+
/** Controls which file URLs belong to the fresh import graph. */
|
|
15
|
+
readonly shouldInvalidate?: ((url: string, parentURL: string | undefined) => boolean) | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Limits transformation to matching absolute file paths; everything else
|
|
18
|
+
* loads through Node untouched. Lets a published install transpile only
|
|
19
|
+
* the user's own TypeScript while alchemy and its dependencies run their
|
|
20
|
+
* built JavaScript.
|
|
21
|
+
*/
|
|
22
|
+
readonly filter?: ((path: string) => boolean) | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* On-disk cache of Oxc output shared by every process on the machine, so
|
|
25
|
+
* the CLI, its dev exec child and the local-provider sidecars transpile
|
|
26
|
+
* each source file once between them rather than once each. `false`
|
|
27
|
+
* disables it, a string names the directory.
|
|
28
|
+
* @default `$ALCHEMY_TRANSFORM_CACHE` (`0` disables), else a per-user
|
|
29
|
+
* directory under the OS temp directory
|
|
30
|
+
*/
|
|
31
|
+
readonly cache?: boolean | string | undefined;
|
|
32
|
+
}
|
|
33
|
+
export interface RegisterOxcOptions extends OxcLoaderOptions {
|
|
34
|
+
/**
|
|
35
|
+
* Isolates one import graph in the runtime's module cache: every file
|
|
36
|
+
* URL the graph resolves carries this namespace as a query parameter, so
|
|
37
|
+
* the same files import again as fresh modules under a new namespace.
|
|
38
|
+
* This is how `alchemy dev` reloads the user's stack (see
|
|
39
|
+
* `watch-import.ts`); an un-namespaced registration is the process-wide
|
|
40
|
+
* TypeScript loader.
|
|
41
|
+
*/
|
|
42
|
+
readonly namespace?: string | undefined;
|
|
43
|
+
/** Called once the runtime loads a file in this registration's graph. */
|
|
44
|
+
readonly onImport?: ((url: string) => void) | undefined;
|
|
45
|
+
}
|
|
46
|
+
export interface OxcLoader {
|
|
47
|
+
/**
|
|
48
|
+
* Imports a file under this registration's namespace. `specifier` is a
|
|
49
|
+
* file URL, an absolute path, or a path relative to `parentURL`.
|
|
50
|
+
*/
|
|
51
|
+
import<T = unknown>(specifier: string, parentURL: string): Promise<T>;
|
|
52
|
+
unregister(): void;
|
|
53
|
+
}
|
|
3
54
|
/**
|
|
4
55
|
* Registers synchronous Node module hooks that transpile TypeScript with
|
|
5
56
|
* Rolldown's Oxc transformer and resolve it the way TypeScript (and tsx)
|
|
6
57
|
* does. A namespaced registration also provides a scoped import whose
|
|
7
58
|
* namespace propagates through the complete ESM graph.
|
|
8
59
|
*/
|
|
9
|
-
export declare const registerOxc: (options?:
|
|
10
|
-
/**
|
|
11
|
-
* One-shot TypeScript import that leaves the rest of the runtime untouched:
|
|
12
|
-
* a private namespace is registered for the call, so nothing is shared with
|
|
13
|
-
* other imports of the same files. Mirrors tsx's `tsImport`.
|
|
14
|
-
*/
|
|
15
|
-
export declare const tsImport: <T = unknown>(specifier: string, parentURL: string, options?: Omit<ImportLoaderRegistrationOptions, "namespace">) => Promise<T>;
|
|
60
|
+
export declare const registerOxc: (options?: RegisterOxcOptions) => OxcLoader;
|
|
16
61
|
//# sourceMappingURL=register-oxc.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register-oxc.d.ts","sourceRoot":"","sources":["../src/register-oxc.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"register-oxc.d.ts","sourceRoot":"","sources":["../src/register-oxc.ts"],"names":[],"mappings":"AAkBA,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;IACxD;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACxC,iEAAiE;IACjE,QAAQ,CAAC,gBAAgB,CAAC,EACtB,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,SAAS,KAAK,OAAO,CAAC,GACzD,SAAS,CAAC;IACd;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,GAAG,SAAS,CAAC;IAC1D;;;;;;;OAOG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAAC;CAC/C;AAED,MAAM,WAAW,kBAAmB,SAAQ,gBAAgB;IAC1D;;;;;;;OAOG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACxC,yEAAyE;IACzE,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;CACzD;AAED,MAAM,WAAW,SAAS;IACxB;;;OAGG;IACH,MAAM,CAAC,CAAC,GAAG,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACtE,UAAU,IAAI,IAAI,CAAC;CACpB;AAkID;;;;;GAKG;AACH,eAAO,MAAM,WAAW,aAAa,kBAAkB,KAAQ,SA8H9D,CAAC"}
|
package/lib/register-oxc.js
CHANGED
|
@@ -6,12 +6,11 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
|
|
|
6
6
|
}
|
|
7
7
|
return path;
|
|
8
8
|
};
|
|
9
|
-
import
|
|
9
|
+
import * as NodeModule from "node:module";
|
|
10
10
|
import { registerHooks, } from "node:module";
|
|
11
11
|
import { pathToFileURL } from "node:url";
|
|
12
12
|
import { filePathOfUrl, isFileLikeSpecifier, isProjectPath, SpecifierResolver, splitSpecifierMetadata, } from "./resolve-specifier.js";
|
|
13
13
|
import { SourceTransformer } from "./transform-source.js";
|
|
14
|
-
const protocol = "alchemy-import:";
|
|
15
14
|
const namespaceParameter = "alchemy-import-namespace";
|
|
16
15
|
const globalRegistrationKey = Symbol.for("@alchemy.run/node-utils/register-oxc");
|
|
17
16
|
const namespaceOf = (url) => {
|
|
@@ -31,43 +30,33 @@ const withNamespace = (url, namespace) => {
|
|
|
31
30
|
parsed.searchParams.set(namespaceParameter, namespace);
|
|
32
31
|
return parsed.href;
|
|
33
32
|
};
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Node's module compile cache (`module.enableCompileCache`) keeps V8 code
|
|
35
|
+
* cache for compiled modules — transformed TypeScript included, since it is
|
|
36
|
+
* keyed by the compiled source — but Node only persists it once after the
|
|
37
|
+
* entry module evaluated and again on a clean exit. Alchemy processes load
|
|
38
|
+
* most of their graph lazily after that point (commands, the user's stack,
|
|
39
|
+
* provider layers) and usually stop on a signal, so without an explicit
|
|
40
|
+
* flush that code never reaches the cache. Flush once module loading has
|
|
41
|
+
* gone quiet; a no-op when the cache is off or this Node predates it.
|
|
42
|
+
*/
|
|
43
|
+
const scheduleCompileCacheFlush = (() => {
|
|
44
|
+
let timer;
|
|
45
|
+
return () => {
|
|
46
|
+
if (NodeModule.getCompileCacheDir?.() === undefined)
|
|
47
|
+
return;
|
|
48
|
+
if (timer !== undefined)
|
|
49
|
+
clearTimeout(timer);
|
|
50
|
+
timer = setTimeout(() => {
|
|
51
|
+
timer = undefined;
|
|
52
|
+
NodeModule.flushCompileCache?.();
|
|
53
|
+
}, 1000);
|
|
54
|
+
timer.unref();
|
|
55
|
+
};
|
|
56
|
+
})();
|
|
39
57
|
/** Specifiers Node owns outright: builtins, data URLs, remote schemes. */
|
|
40
58
|
const isForeignSpecifier = (specifier) => /^(?:node:|data:|[a-z][a-z\d+.-]*:\/\/)/i.test(specifier) &&
|
|
41
59
|
!specifier.startsWith("file:");
|
|
42
|
-
const notFoundCodes = new Set([
|
|
43
|
-
"ERR_MODULE_NOT_FOUND",
|
|
44
|
-
"MODULE_NOT_FOUND",
|
|
45
|
-
"ERR_UNSUPPORTED_DIR_IMPORT",
|
|
46
|
-
"ERR_PACKAGE_PATH_NOT_EXPORTED",
|
|
47
|
-
]);
|
|
48
|
-
const isNotFound = (error) => error instanceof Error &&
|
|
49
|
-
notFoundCodes.has(error.code ?? "");
|
|
50
|
-
/**
|
|
51
|
-
* The file Node could not find, from the error it raised. Node names the
|
|
52
|
-
* resolved target (`url` on ESM errors, the message on CommonJS ones) —
|
|
53
|
-
* for a package `exports` entry pointing at emitted JavaScript that was
|
|
54
|
-
* never built, that is the `.js` path whose `.ts` source we can substitute.
|
|
55
|
-
*/
|
|
56
|
-
const missingPathOf = (error) => {
|
|
57
|
-
if (error.url !== undefined)
|
|
58
|
-
return filePathOfUrl(error.url);
|
|
59
|
-
const match = error.message.match(/^Cannot find module '([^']+)'/);
|
|
60
|
-
if (match === null)
|
|
61
|
-
return undefined;
|
|
62
|
-
const [, target] = match;
|
|
63
|
-
if (target === undefined)
|
|
64
|
-
return undefined;
|
|
65
|
-
if (target.startsWith("file:"))
|
|
66
|
-
return filePathOfUrl(target);
|
|
67
|
-
return target.startsWith("/") || /^[a-zA-Z]:[\\/]/.test(target)
|
|
68
|
-
? target
|
|
69
|
-
: undefined;
|
|
70
|
-
};
|
|
71
60
|
/** A `require()` reaching the hooks: Node's CommonJS resolver wants paths, not URLs. */
|
|
72
61
|
const isRequireContext = (context) => context.conditions?.includes("require") === true &&
|
|
73
62
|
!context.conditions.includes("import");
|
|
@@ -104,25 +93,7 @@ const resolveSpecifier = (resolver, specifier, context, nextResolve) => {
|
|
|
104
93
|
return resolved;
|
|
105
94
|
}
|
|
106
95
|
}
|
|
107
|
-
|
|
108
|
-
return nextResolve(specifier, context);
|
|
109
|
-
}
|
|
110
|
-
catch (error) {
|
|
111
|
-
if (!isNotFound(error))
|
|
112
|
-
throw error;
|
|
113
|
-
// A package `exports`/`main` target naming emitted JavaScript that only
|
|
114
|
-
// exists as TypeScript source (workspace packages in a checkout).
|
|
115
|
-
const missing = missingPathOf(error);
|
|
116
|
-
if (missing !== undefined && isFileLikeSpecifier(missing)) {
|
|
117
|
-
const candidate = resolver.resolveMissing(missing, conditions);
|
|
118
|
-
if (candidate !== undefined && candidate !== missing) {
|
|
119
|
-
const resolved = resolveWithCandidate(candidate, metadata, context, nextResolve);
|
|
120
|
-
if (resolved !== undefined)
|
|
121
|
-
return resolved;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
throw error;
|
|
125
|
-
}
|
|
96
|
+
return nextResolve(specifier, context);
|
|
126
97
|
};
|
|
127
98
|
/**
|
|
128
99
|
* `import data from "./x.json"` without an import attribute is how
|
|
@@ -161,17 +132,18 @@ export const registerOxc = (options = {}) => {
|
|
|
161
132
|
tsconfig: options.tsconfig ?? true,
|
|
162
133
|
});
|
|
163
134
|
const shouldInvalidate = options.shouldInvalidate ?? (() => true);
|
|
164
|
-
// Transformed sources
|
|
165
|
-
// stack traces once source-map support
|
|
135
|
+
// Transformed sources reference their source maps (see transform-source);
|
|
136
|
+
// Node only reads and applies them to stack traces once source-map support
|
|
137
|
+
// is on.
|
|
166
138
|
const sourceMapsWereEnabled = process.sourceMapsEnabled;
|
|
167
139
|
process.setSourceMapsEnabled(true);
|
|
168
140
|
const hooks = registerHooks({
|
|
169
141
|
resolve(specifier, context, nextResolve) {
|
|
170
|
-
|
|
171
|
-
|
|
142
|
+
// A graph's entry carries the namespace itself (see `import` below);
|
|
143
|
+
// everything it imports inherits it from the importing module's URL.
|
|
172
144
|
const namespace = options.namespace === undefined
|
|
173
145
|
? undefined
|
|
174
|
-
: (
|
|
146
|
+
: (namespaceOf(specifier) ?? namespaceOf(context.parentURL));
|
|
175
147
|
if (options.namespace !== undefined && namespace !== options.namespace) {
|
|
176
148
|
return nextResolve(specifier, context);
|
|
177
149
|
}
|
|
@@ -183,9 +155,7 @@ export const registerOxc = (options = {}) => {
|
|
|
183
155
|
...new Set([...options.conditions, ...context.conditions]),
|
|
184
156
|
],
|
|
185
157
|
};
|
|
186
|
-
const resolved =
|
|
187
|
-
? resolveSpecifier(resolver, request.specifier, { ...resolutionContext, parentURL: request.parentURL }, nextResolve)
|
|
188
|
-
: resolveSpecifier(resolver, specifier, resolutionContext, nextResolve);
|
|
158
|
+
const resolved = resolveSpecifier(resolver, specifier, resolutionContext, nextResolve);
|
|
189
159
|
if (namespace !== undefined &&
|
|
190
160
|
resolved.url.startsWith("file:") &&
|
|
191
161
|
shouldInvalidate(withoutNamespace(resolved.url), context.parentURL === undefined
|
|
@@ -196,6 +166,7 @@ export const registerOxc = (options = {}) => {
|
|
|
196
166
|
return resolved;
|
|
197
167
|
},
|
|
198
168
|
load(url, context, nextLoad) {
|
|
169
|
+
scheduleCompileCacheFlush();
|
|
199
170
|
const namespace = namespaceOf(url);
|
|
200
171
|
if (options.namespace !== undefined && namespace !== options.namespace) {
|
|
201
172
|
return nextLoad(url, context);
|
|
@@ -208,7 +179,7 @@ export const registerOxc = (options = {}) => {
|
|
|
208
179
|
if (options.filter !== undefined && !options.filter(filePath)) {
|
|
209
180
|
return nextLoad(cleanUrl, withJsonAttribute(cleanUrl, context));
|
|
210
181
|
}
|
|
211
|
-
const transformed = transformer.transform(filePath,
|
|
182
|
+
const transformed = transformer.transform(filePath, context.format);
|
|
212
183
|
if (transformed === undefined) {
|
|
213
184
|
return nextLoad(cleanUrl, withJsonAttribute(cleanUrl, context));
|
|
214
185
|
}
|
|
@@ -217,14 +188,20 @@ export const registerOxc = (options = {}) => {
|
|
|
217
188
|
});
|
|
218
189
|
const loader = {
|
|
219
190
|
import(specifier, parentURL) {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
191
|
+
if (!isFileLikeSpecifier(specifier)) {
|
|
192
|
+
throw new Error(`Cannot import '${specifier}': expected a file URL or path.`);
|
|
193
|
+
}
|
|
194
|
+
const base = parentURL.startsWith("file:")
|
|
195
|
+
? parentURL
|
|
196
|
+
: pathToFileURL(parentURL).href;
|
|
197
|
+
const url = specifier.startsWith("file:")
|
|
198
|
+
? specifier
|
|
199
|
+
: new URL(specifier.startsWith(".")
|
|
200
|
+
? specifier
|
|
201
|
+
: pathToFileURL(specifier).href, base).href;
|
|
202
|
+
return import(__rewriteRelativeImportExtension(options.namespace === undefined
|
|
203
|
+
? url
|
|
204
|
+
: withNamespace(url, options.namespace)));
|
|
228
205
|
},
|
|
229
206
|
unregister() {
|
|
230
207
|
hooks.deregister();
|
|
@@ -240,18 +217,4 @@ export const registerOxc = (options = {}) => {
|
|
|
240
217
|
}
|
|
241
218
|
return loader;
|
|
242
219
|
};
|
|
243
|
-
/**
|
|
244
|
-
* One-shot TypeScript import that leaves the rest of the runtime untouched:
|
|
245
|
-
* a private namespace is registered for the call, so nothing is shared with
|
|
246
|
-
* other imports of the same files. Mirrors tsx's `tsImport`.
|
|
247
|
-
*/
|
|
248
|
-
export const tsImport = async (specifier, parentURL, options = {}) => {
|
|
249
|
-
const loader = registerOxc({ ...options, namespace: randomUUID() });
|
|
250
|
-
try {
|
|
251
|
-
return await loader.import(specifier, parentURL);
|
|
252
|
-
}
|
|
253
|
-
finally {
|
|
254
|
-
await loader.unregister();
|
|
255
|
-
}
|
|
256
|
-
};
|
|
257
220
|
//# sourceMappingURL=register-oxc.js.map
|
package/lib/register-oxc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register-oxc.js","sourceRoot":"","sources":["../src/register-oxc.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"register-oxc.js","sourceRoot":"","sources":["../src/register-oxc.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAO,KAAK,UAAU,MAAM,aAAa,CAAC;AAC1C,OAAO,EACL,aAAa,GAKd,MAAM,aAAa,C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CAAC,SAAS;oBACX,CAAC,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,IAAI,EACjC,IAAI,CACL,CAAC,IAAI,CAAC;YACX,OAAO,MAAM,kCACX,OAAO,CAAC,SAAS,KAAK,SAAS;gBAC7B,CAAC,CAAC,GAAG;gBACL,CAAC,CAAC,aAAa,CAAC,GAAG,EAAE,OAAO,CAAC,SAAS,CAAC,EAC5B,CAAC;QAClB,CAAC;QACD,UAAU;YACR,KAAK,CAAC,UAAU,EAAE,CAAC;YACnB,IAAI,kBAAkB,CAAC,qBAAqB,CAAC,KAAK,MAAM,EAAE,CAAC;gBACzD,OAAO,kBAAkB,CAAC,qBAAqB,CAAC,CAAC;YACnD,CAAC;YACD,IAAI,qBAAqB,KAAK,KAAK;gBAAE,OAAO,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC;QAC3E,CAAC;KACF,CAAC;IACF,IAAI,OAAO,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;QACpC,kBAAkB,CAAC,qBAAqB,CAAC,GAAG,MAAM,CAAC;IACrD,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC"}
|
|
@@ -42,11 +42,5 @@ export declare class SpecifierResolver {
|
|
|
42
42
|
* that map onto project files are ours.
|
|
43
43
|
*/
|
|
44
44
|
resolve(parentPath: string, specifier: string, conditions: ReadonlyArray<string>): string | undefined;
|
|
45
|
-
/**
|
|
46
|
-
* Given a file path Node failed to find (typically an `exports`/`main`
|
|
47
|
-
* target that names emitted JavaScript that was never built), finds the
|
|
48
|
-
* TypeScript source it was emitted from via extension substitution.
|
|
49
|
-
*/
|
|
50
|
-
resolveMissing(missingPath: string, conditions: ReadonlyArray<string>): string | undefined;
|
|
51
45
|
}
|
|
52
46
|
//# sourceMappingURL=resolve-specifier.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-specifier.d.ts","sourceRoot":"","sources":["../src/resolve-specifier.ts"],"names":[],"mappings":"AAIA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OpD,CAAC;AAEF,qBAAa,iBAAiB;;IAK5B,YAAY,OAAO,EAAE,wBAAwB,EA6B5C;IAuBD;;;;;;OAMG;IACH,OAAO,CACL,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,aAAa,CAAC,MAAM,CAAC,GAChC,MAAM,GAAG,SAAS,CAmBpB;CACF"}
|
package/lib/resolve-specifier.js
CHANGED
|
@@ -119,21 +119,5 @@ export class SpecifierResolver {
|
|
|
119
119
|
}
|
|
120
120
|
return result.path;
|
|
121
121
|
}
|
|
122
|
-
/**
|
|
123
|
-
* Given a file path Node failed to find (typically an `exports`/`main`
|
|
124
|
-
* target that names emitted JavaScript that was never built), finds the
|
|
125
|
-
* TypeScript source it was emitted from via extension substitution.
|
|
126
|
-
*/
|
|
127
|
-
resolveMissing(missingPath, conditions) {
|
|
128
|
-
const directory = path.dirname(missingPath);
|
|
129
|
-
const base = path.basename(missingPath);
|
|
130
|
-
try {
|
|
131
|
-
const result = this.#resolver(conditions, true).sync(directory, `./${base}`);
|
|
132
|
-
return result.path;
|
|
133
|
-
}
|
|
134
|
-
catch {
|
|
135
|
-
return undefined;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
122
|
}
|
|
139
123
|
//# sourceMappingURL=resolve-specifier.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-specifier.js","sourceRoot":"","sources":["../src/resolve-specifier.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,eAAe,EAAuB,MAAM,uBAAuB,CAAC;AAqB7E,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,IAAI,CAAC,GAAG,eAAe,IAAI,CAAC,GAAG,EAAE,CAAC;AAEvE,8EAA8E;AAC9E,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,QAAgB,EAAE,EAAE,CACh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,IAAI,CAAC,EAAE,CAAC;YACjE,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,OAAO,MAAM,CAAC,IAAI,CAAC;IACrB,CAAC;CACF"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export declare const TRANSFORM_CACHE_ENV = "ALCHEMY_TRANSFORM_CACHE";
|
|
2
|
+
/**
|
|
3
|
+
* The directory to use for the given option, or `undefined` when caching is
|
|
4
|
+
* off. `cache: false` and `ALCHEMY_TRANSFORM_CACHE=0` disable it; a string
|
|
5
|
+
* (option or env) names the directory; otherwise the per-user default.
|
|
6
|
+
*/
|
|
7
|
+
export declare const resolveCacheDirectory: (option: boolean | string | undefined) => string | undefined;
|
|
8
|
+
/** One transform's output as handed to {@link TransformCache.set}. */
|
|
9
|
+
export interface TransformCacheEntry {
|
|
10
|
+
readonly format: "module" | "commonjs";
|
|
11
|
+
readonly code: string;
|
|
12
|
+
/** Source map JSON, or `undefined` when the transform produced none. */
|
|
13
|
+
readonly map: string | undefined;
|
|
14
|
+
}
|
|
15
|
+
/** A cache hit: the code, and where its source map lives on disk. */
|
|
16
|
+
export interface CachedTransform {
|
|
17
|
+
readonly format: "module" | "commonjs";
|
|
18
|
+
readonly code: string;
|
|
19
|
+
/** Absolute path of the entry's `.map` file, present when it has one. */
|
|
20
|
+
readonly mapFile: string | undefined;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* On-disk cache of Oxc transform output shared by every process on the
|
|
24
|
+
* machine — the `alchemy` CLI, its dev exec child, the local-provider
|
|
25
|
+
* sidecars and dev-server runners all load the same source files, and
|
|
26
|
+
* without this each of them transpiles the whole graph again.
|
|
27
|
+
*
|
|
28
|
+
* Modelled on tsx's file cache: entries are keyed by a hash of the source
|
|
29
|
+
* file's path, size and mtime, the transform options and the resolved
|
|
30
|
+
* tsconfig, so a change to any input is simply a different key; nothing is
|
|
31
|
+
* ever invalidated in place. Size plus nanosecond mtime stands in for the
|
|
32
|
+
* contents so a hit never reads the source.
|
|
33
|
+
*
|
|
34
|
+
* An entry is two files: `<key>.json` with the code, and `<key>.map` with
|
|
35
|
+
* the source map. The map stays on disk and is referenced from the module
|
|
36
|
+
* by path rather than inlined — an inline `data:` map is part of the
|
|
37
|
+
* script's source text, which V8 keeps for the process lifetime; for a
|
|
38
|
+
* graph the size of alchemy's that is hundreds of megabytes per process.
|
|
39
|
+
* Node reads the referenced file synchronously as it compiles the module,
|
|
40
|
+
* so the map is written (atomically) before `set` returns; the code entry
|
|
41
|
+
* is a fire-and-forget write, because a missing one is only a slower
|
|
42
|
+
* cache. Reads are synchronous (the loader hook is). Stale entries are
|
|
43
|
+
* swept by age once per process.
|
|
44
|
+
*/
|
|
45
|
+
export declare class TransformCache {
|
|
46
|
+
#private;
|
|
47
|
+
constructor(directory: string);
|
|
48
|
+
/** The entry key for these transform inputs. */
|
|
49
|
+
key(parts: ReadonlyArray<string>): string;
|
|
50
|
+
/**
|
|
51
|
+
* The cached transform, or `undefined` on a miss. An entry whose map file
|
|
52
|
+
* has gone (swept, or never landed) is a miss too: the module would
|
|
53
|
+
* otherwise reference a map that is not there.
|
|
54
|
+
*/
|
|
55
|
+
get(key: string): CachedTransform | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Stores one transform. Returns the map file's path once it is on disk,
|
|
58
|
+
* or `undefined` when there is no map or it could not be written — the
|
|
59
|
+
* caller then falls back to inlining it.
|
|
60
|
+
*/
|
|
61
|
+
set(key: string, entry: TransformCacheEntry): string | undefined;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=transform-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform-cache.d.ts","sourceRoot":"","sources":["../src/transform-cache.ts"],"names":[],"mappings":"AAyBA,eAAO,MAAM,mBAAmB,4BAA4B,CAAC;AAW7D;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,WACxB,OAAO,GAAG,MAAM,GAAG,SAAS,KACnC,MAAM,GAAG,SAOX,CAAC;AAEF,sEAAsE;AACtE,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,MAAM,EAAE,QAAQ,GAAG,UAAU,CAAC;IACvC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,wEAAwE;IACxE,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;CAClC;AAED,qEAAqE;AACrE,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,MAAM,EAAE,QAAQ,GAAG,UAAU,CAAC;IACvC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,yEAAyE;IACzE,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;CACtC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,cAAc;;IAKzB,YAAY,SAAS,EAAE,MAAM,EAE5B;IAED,gDAAgD;IAChD,GAAG,CAAC,KAAK,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,MAAM,CASxC;IAED;;;;OAIG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS,CA4B5C;IAED;;;;OAIG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,mBAAmB,GAAG,MAAM,GAAG,SAAS,CAqB/D;CAoDF"}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { existsSync, mkdirSync, promises as fs, readFileSync, renameSync, unlinkSync, writeFileSync, } from "node:fs";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import rolldown from "rolldown/package.json" with { type: "json" };
|
|
6
|
+
import self from "../package.json" with { type: "json" };
|
|
7
|
+
/**
|
|
8
|
+
* Anything that changes Oxc's output for identical input invalidates every
|
|
9
|
+
* entry: the transformer itself (rolldown), this package's transform
|
|
10
|
+
* pipeline, and the on-disk entry layout.
|
|
11
|
+
*/
|
|
12
|
+
const CACHE_VERSION = ["1", self.version, rolldown.version].join("-");
|
|
13
|
+
/** Entries untouched for this long are swept on the first disk access. */
|
|
14
|
+
const MAX_AGE_MS = 7 * 24 * 60 * 60 * 1000;
|
|
15
|
+
export const TRANSFORM_CACHE_ENV = "ALCHEMY_TRANSFORM_CACHE";
|
|
16
|
+
/**
|
|
17
|
+
* Per-user directory, like tsx's `tsx-<uid>`: `tmpdir()` is shared on
|
|
18
|
+
* multi-user machines, and entries are written with the owner's umask.
|
|
19
|
+
*/
|
|
20
|
+
const defaultDirectory = () => {
|
|
21
|
+
const user = process.geteuid?.() ?? os.userInfo().username;
|
|
22
|
+
return path.join(os.tmpdir(), `alchemy-oxc-${user}`);
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* The directory to use for the given option, or `undefined` when caching is
|
|
26
|
+
* off. `cache: false` and `ALCHEMY_TRANSFORM_CACHE=0` disable it; a string
|
|
27
|
+
* (option or env) names the directory; otherwise the per-user default.
|
|
28
|
+
*/
|
|
29
|
+
export const resolveCacheDirectory = (option) => {
|
|
30
|
+
if (option === false)
|
|
31
|
+
return undefined;
|
|
32
|
+
if (typeof option === "string")
|
|
33
|
+
return option;
|
|
34
|
+
const env = process.env[TRANSFORM_CACHE_ENV];
|
|
35
|
+
if (env === "0" || env === "false")
|
|
36
|
+
return undefined;
|
|
37
|
+
if (env !== undefined && env !== "")
|
|
38
|
+
return env;
|
|
39
|
+
return defaultDirectory();
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* On-disk cache of Oxc transform output shared by every process on the
|
|
43
|
+
* machine — the `alchemy` CLI, its dev exec child, the local-provider
|
|
44
|
+
* sidecars and dev-server runners all load the same source files, and
|
|
45
|
+
* without this each of them transpiles the whole graph again.
|
|
46
|
+
*
|
|
47
|
+
* Modelled on tsx's file cache: entries are keyed by a hash of the source
|
|
48
|
+
* file's path, size and mtime, the transform options and the resolved
|
|
49
|
+
* tsconfig, so a change to any input is simply a different key; nothing is
|
|
50
|
+
* ever invalidated in place. Size plus nanosecond mtime stands in for the
|
|
51
|
+
* contents so a hit never reads the source.
|
|
52
|
+
*
|
|
53
|
+
* An entry is two files: `<key>.json` with the code, and `<key>.map` with
|
|
54
|
+
* the source map. The map stays on disk and is referenced from the module
|
|
55
|
+
* by path rather than inlined — an inline `data:` map is part of the
|
|
56
|
+
* script's source text, which V8 keeps for the process lifetime; for a
|
|
57
|
+
* graph the size of alchemy's that is hundreds of megabytes per process.
|
|
58
|
+
* Node reads the referenced file synchronously as it compiles the module,
|
|
59
|
+
* so the map is written (atomically) before `set` returns; the code entry
|
|
60
|
+
* is a fire-and-forget write, because a missing one is only a slower
|
|
61
|
+
* cache. Reads are synchronous (the loader hook is). Stale entries are
|
|
62
|
+
* swept by age once per process.
|
|
63
|
+
*/
|
|
64
|
+
export class TransformCache {
|
|
65
|
+
#directory;
|
|
66
|
+
#ready = false;
|
|
67
|
+
#sequence = 0;
|
|
68
|
+
constructor(directory) {
|
|
69
|
+
this.#directory = directory;
|
|
70
|
+
}
|
|
71
|
+
/** The entry key for these transform inputs. */
|
|
72
|
+
key(parts) {
|
|
73
|
+
const hash = createHash("sha1");
|
|
74
|
+
hash.update(CACHE_VERSION);
|
|
75
|
+
for (const part of parts) {
|
|
76
|
+
// Length-prefixed so adjacent parts cannot run into each other.
|
|
77
|
+
hash.update(`\0${part.length}\0`);
|
|
78
|
+
hash.update(part);
|
|
79
|
+
}
|
|
80
|
+
return hash.digest("hex");
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The cached transform, or `undefined` on a miss. An entry whose map file
|
|
84
|
+
* has gone (swept, or never landed) is a miss too: the module would
|
|
85
|
+
* otherwise reference a map that is not there.
|
|
86
|
+
*/
|
|
87
|
+
get(key) {
|
|
88
|
+
this.#prepare();
|
|
89
|
+
let raw;
|
|
90
|
+
try {
|
|
91
|
+
raw = readFileSync(this.#file(key, "json"), "utf8");
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
let entry;
|
|
97
|
+
try {
|
|
98
|
+
entry = JSON.parse(raw);
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
103
|
+
if ((entry.format !== "module" && entry.format !== "commonjs") ||
|
|
104
|
+
typeof entry.code !== "string" ||
|
|
105
|
+
typeof entry.map !== "boolean") {
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
const mapFile = this.#file(key, "map");
|
|
109
|
+
if (entry.map && !existsSync(mapFile))
|
|
110
|
+
return undefined;
|
|
111
|
+
return {
|
|
112
|
+
format: entry.format,
|
|
113
|
+
code: entry.code,
|
|
114
|
+
mapFile: entry.map ? mapFile : undefined,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Stores one transform. Returns the map file's path once it is on disk,
|
|
119
|
+
* or `undefined` when there is no map or it could not be written — the
|
|
120
|
+
* caller then falls back to inlining it.
|
|
121
|
+
*/
|
|
122
|
+
set(key, entry) {
|
|
123
|
+
this.#prepare();
|
|
124
|
+
let mapFile;
|
|
125
|
+
if (entry.map !== undefined) {
|
|
126
|
+
mapFile = this.#file(key, "map");
|
|
127
|
+
if (!this.#writeAtomically(mapFile, entry.map))
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
130
|
+
const file = this.#file(key, "json");
|
|
131
|
+
const temporary = this.#temporary(file);
|
|
132
|
+
// Best effort: a cache that cannot be written is only a slower cache.
|
|
133
|
+
fs.writeFile(temporary, JSON.stringify({
|
|
134
|
+
format: entry.format,
|
|
135
|
+
code: entry.code,
|
|
136
|
+
map: mapFile !== undefined,
|
|
137
|
+
}))
|
|
138
|
+
.then(() => fs.rename(temporary, file))
|
|
139
|
+
.catch(() => fs.unlink(temporary).catch(() => { }));
|
|
140
|
+
return mapFile;
|
|
141
|
+
}
|
|
142
|
+
#file(key, extension) {
|
|
143
|
+
return path.join(this.#directory, `${key}.${extension}`);
|
|
144
|
+
}
|
|
145
|
+
#temporary(file) {
|
|
146
|
+
return `${file}.${process.pid}.${this.#sequence++}.tmp`;
|
|
147
|
+
}
|
|
148
|
+
/** Temp file plus rename: concurrent readers never see a partial file. */
|
|
149
|
+
#writeAtomically(file, content) {
|
|
150
|
+
const temporary = this.#temporary(file);
|
|
151
|
+
try {
|
|
152
|
+
writeFileSync(temporary, content);
|
|
153
|
+
renameSync(temporary, file);
|
|
154
|
+
return true;
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
try {
|
|
158
|
+
unlinkSync(temporary);
|
|
159
|
+
}
|
|
160
|
+
catch { }
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
#prepare() {
|
|
165
|
+
if (this.#ready)
|
|
166
|
+
return;
|
|
167
|
+
this.#ready = true;
|
|
168
|
+
try {
|
|
169
|
+
mkdirSync(this.#directory, { recursive: true });
|
|
170
|
+
}
|
|
171
|
+
catch {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
// Off the hot path: the loader hook that got us here is synchronous.
|
|
175
|
+
setImmediate(() => {
|
|
176
|
+
this.#sweep().catch(() => { });
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
async #sweep() {
|
|
180
|
+
const cutoff = Date.now() - MAX_AGE_MS;
|
|
181
|
+
const names = await fs.readdir(this.#directory);
|
|
182
|
+
await Promise.all(names.map(async (name) => {
|
|
183
|
+
const file = path.join(this.#directory, name);
|
|
184
|
+
try {
|
|
185
|
+
const { mtimeMs } = await fs.stat(file);
|
|
186
|
+
if (mtimeMs < cutoff)
|
|
187
|
+
await fs.unlink(file);
|
|
188
|
+
}
|
|
189
|
+
catch { }
|
|
190
|
+
}));
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
//# sourceMappingURL=transform-cache.js.map
|