@alchemy.run/node-utils 2.0.0-beta.75 → 2.0.0-beta.77

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.
Files changed (37) hide show
  1. package/THIRD_PARTY_LICENSES.md +11 -11
  2. package/lib/dependency-watcher.d.ts +28 -0
  3. package/lib/dependency-watcher.d.ts.map +1 -0
  4. package/lib/dependency-watcher.js +114 -0
  5. package/lib/dependency-watcher.js.map +1 -0
  6. package/lib/import-loader.d.ts +54 -0
  7. package/lib/import-loader.d.ts.map +1 -0
  8. package/lib/import-loader.js +9 -0
  9. package/lib/import-loader.js.map +1 -0
  10. package/lib/register-oxc.d.ts +16 -0
  11. package/lib/register-oxc.d.ts.map +1 -0
  12. package/lib/register-oxc.js +257 -0
  13. package/lib/register-oxc.js.map +1 -0
  14. package/lib/resolve-specifier.d.ts +52 -0
  15. package/lib/resolve-specifier.d.ts.map +1 -0
  16. package/lib/resolve-specifier.js +139 -0
  17. package/lib/resolve-specifier.js.map +1 -0
  18. package/lib/transform-source.d.ts +19 -0
  19. package/lib/transform-source.d.ts.map +1 -0
  20. package/lib/transform-source.js +140 -0
  21. package/lib/transform-source.js.map +1 -0
  22. package/lib/watch-import-bun.d.ts +30 -0
  23. package/lib/watch-import-bun.d.ts.map +1 -0
  24. package/lib/watch-import-bun.js +68 -0
  25. package/lib/watch-import-bun.js.map +1 -0
  26. package/lib/watch-import.d.ts +27 -0
  27. package/lib/watch-import.d.ts.map +1 -0
  28. package/lib/watch-import.js +77 -0
  29. package/lib/watch-import.js.map +1 -0
  30. package/package.json +26 -2
  31. package/src/dependency-watcher.ts +130 -0
  32. package/src/import-loader.ts +75 -0
  33. package/src/register-oxc.ts +342 -0
  34. package/src/resolve-specifier.ts +179 -0
  35. package/src/transform-source.ts +170 -0
  36. package/src/watch-import-bun.ts +94 -0
  37. package/src/watch-import.ts +107 -0
@@ -6,7 +6,7 @@ respective license notices.
6
6
 
7
7
  ## Astro
8
8
 
9
- Portions of `packages/cloudflare-frameworks/src/astro` are derived from
9
+ Portions of `packages/frontend-frameworks/src/astro` are derived from
10
10
  `@astrojs/cloudflare`.
11
11
 
12
12
  Copyright (c) 2021 Fred K. Schott
@@ -33,7 +33,7 @@ SOFTWARE.
33
33
 
34
34
  ## SvelteKit
35
35
 
36
- Portions of `packages/cloudflare-frameworks/src/sveltekit` are derived from
36
+ Portions of `packages/frontend-frameworks/src/sveltekit` are derived from
37
37
  `@sveltejs/adapter-cloudflare`.
38
38
 
39
39
  Copyright (c) 2020 SvelteKit contributors
@@ -43,7 +43,7 @@ Astro section above.
43
43
 
44
44
  ## Waku
45
45
 
46
- Portions of `packages/cloudflare-frameworks/src/waku` are derived from Waku.
46
+ Portions of `packages/frontend-frameworks/src/waku` are derived from Waku.
47
47
 
48
48
  Copyright (c) 2023 Daishi Kato
49
49
 
@@ -65,7 +65,7 @@ License reproduced in the Astro section above.
65
65
 
66
66
  ## OpenNext for Cloudflare
67
67
 
68
- Portions of `packages/cloudflare-frameworks/src/nextjs`, including the build
68
+ Portions of `packages/frontend-frameworks/src/nextjs`, including the build
69
69
  runner and development-context integration, are derived from OpenNext for
70
70
  Cloudflare.
71
71
 
@@ -122,17 +122,17 @@ been dedicated to the public domain. See <https://www.sqlite.org/copyright.html>
122
122
 
123
123
  ## Upstream source references
124
124
 
125
- - Astro: <https://github.com/withastro/astro>
126
- - SvelteKit: <https://github.com/sveltejs/kit>
127
- - Waku: <https://github.com/wakujs/waku>
128
- - Cloudflare Workers SDK: <https://github.com/cloudflare/workers-sdk>
129
- - OpenNext for Cloudflare: <https://github.com/opennextjs/opennextjs-cloudflare>
125
+ - Astro: [`a2240c43830e29c1d85667f4c610655d6b10253f`](https://github.com/withastro/astro/tree/a2240c43830e29c1d85667f4c610655d6b10253f)
126
+ - SvelteKit: [`f36b3a4cd307bd8c89e03fa191becc175e7b3077`](https://github.com/sveltejs/kit/tree/f36b3a4cd307bd8c89e03fa191becc175e7b3077)
127
+ - Waku: [`39e868f2638c27de9635c68ebf965e14a4112e9b`](https://github.com/wakujs/waku/tree/39e868f2638c27de9635c68ebf965e14a4112e9b)
128
+ - Cloudflare Workers SDK: [`b7b4ff84477982e7c770bb93928287893fcf2e03`](https://github.com/cloudflare/workers-sdk/tree/b7b4ff84477982e7c770bb93928287893fcf2e03)
129
+ - OpenNext for Cloudflare: [`da4b7fc8c89441a6f96205635fa70e329d1f0df7`](https://github.com/opennextjs/opennextjs-cloudflare/tree/da4b7fc8c89441a6f96205635fa70e329d1f0df7)
130
130
  - SST: <https://github.com/sst/sst>
131
131
  - node-sanitize-filename: <https://github.com/parshap/node-sanitize-filename>
132
132
  - node-ignore: <https://github.com/kaelzhang/node-ignore>
133
133
  - SQLite: <https://github.com/sqlite/sqlite>
134
134
 
135
- The external `.vendor` Git submodules are separate works governed by the
136
- license files in their respective repositories. This notice covers code copied
135
+ The first-class `submodules/` checkouts (distilled, floci) are separate works
136
+ governed by the license files in their respective repositories. This notice covers code copied
137
137
  or adapted into the Alchemy repository; it does not replace the license
138
138
  documentation within those submodules.
@@ -0,0 +1,28 @@
1
+ import { type ChokidarOptions } from "chokidar";
2
+ export interface DependencyChange {
3
+ readonly paths: ReadonlySet<string>;
4
+ }
5
+ export type DependencyChangeListener = (change: DependencyChange) => void;
6
+ export interface DependencyWatcherOptions {
7
+ /** Chokidar options passed to the file watcher. */
8
+ readonly watch?: ChokidarOptions | undefined;
9
+ readonly debounceMs?: number | undefined;
10
+ }
11
+ /**
12
+ * Watches an explicit set of absolute file paths and delivers debounced
13
+ * batches only when their contents change. Chokidar follows editor atomic-save
14
+ * replacements without polling by default. The set is replaced wholesale
15
+ * with {@link set}, so the watcher always mirrors exactly the files the caller
16
+ * currently depends on.
17
+ */
18
+ export declare class DependencyWatcher {
19
+ #private;
20
+ constructor(options?: DependencyWatcherOptions);
21
+ get dependencies(): ReadonlySet<string>;
22
+ subscribe(listener: DependencyChangeListener): () => void;
23
+ /** Replace the watched set with `dependencies` (absolute paths). */
24
+ set(dependencies: ReadonlySet<string>): void;
25
+ close(): Promise<void>;
26
+ [Symbol.asyncDispose](): Promise<void>;
27
+ }
28
+ //# sourceMappingURL=dependency-watcher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dependency-watcher.d.ts","sourceRoot":"","sources":["../src/dependency-watcher.ts"],"names":[],"mappings":"AAGA,OAAO,EAAS,KAAK,eAAe,EAAkB,MAAM,UAAU,CAAC;AAEvE,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CACrC;AAED,MAAM,MAAM,wBAAwB,GAAG,CAAC,MAAM,EAAE,gBAAgB,KAAK,IAAI,CAAC;AAE1E,MAAM,WAAW,wBAAwB;IACvC,mDAAmD;IACnD,QAAQ,CAAC,KAAK,CAAC,EAAE,eAAe,GAAG,SAAS,CAAC;IAC7C,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1C;AAED;;;;;;GAMG;AACH,qBAAa,iBAAiB;;IAU5B,YAAY,OAAO,GAAE,wBAA6B,EAUjD;IAED,IAAI,YAAY,IAAI,WAAW,CAAC,MAAM,CAAC,CAEtC;IAED,SAAS,CAAC,QAAQ,EAAE,wBAAwB,GAAG,MAAM,IAAI,CAGxD;IAED,oEAAoE;IACpE,GAAG,CAAC,YAAY,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,IAAI,CAuB3C;IAEK,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAM3B;IAEK,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAE3C;CAsCF"}
@@ -0,0 +1,114 @@
1
+ import { createHash } from "node:crypto";
2
+ import { readFileSync } from "node:fs";
3
+ import path from "node:path";
4
+ import { watch } from "chokidar";
5
+ /**
6
+ * Watches an explicit set of absolute file paths and delivers debounced
7
+ * batches only when their contents change. Chokidar follows editor atomic-save
8
+ * replacements without polling by default. The set is replaced wholesale
9
+ * with {@link set}, so the watcher always mirrors exactly the files the caller
10
+ * currently depends on.
11
+ */
12
+ export class DependencyWatcher {
13
+ #options;
14
+ #listeners = new Set();
15
+ #watcher;
16
+ #dependencies = new Set();
17
+ #fingerprints = new Map();
18
+ #pending = new Set();
19
+ #timer;
20
+ #closed = false;
21
+ constructor(options = {}) {
22
+ this.#options = options;
23
+ this.#watcher = watch([], {
24
+ ...options.watch,
25
+ ignoreInitial: true,
26
+ });
27
+ this.#watcher.on("all", (_event, changed) => {
28
+ const absolute = path.resolve(this.#cwd(), changed);
29
+ if (this.#dependencies.has(absolute))
30
+ this.#queue(absolute);
31
+ });
32
+ }
33
+ get dependencies() {
34
+ return this.#dependencies;
35
+ }
36
+ subscribe(listener) {
37
+ this.#listeners.add(listener);
38
+ return () => this.#listeners.delete(listener);
39
+ }
40
+ /** Replace the watched set with `dependencies` (absolute paths). */
41
+ set(dependencies) {
42
+ if (this.#closed)
43
+ return;
44
+ const previous = this.#dependencies;
45
+ this.#dependencies = dependencies;
46
+ const removed = [...previous].filter((dependency) => !dependencies.has(dependency));
47
+ const added = [...dependencies].filter((dependency) => !previous.has(dependency));
48
+ if (removed.length > 0) {
49
+ for (const dependency of removed) {
50
+ this.#fingerprints.delete(dependency);
51
+ this.#pending.delete(dependency);
52
+ }
53
+ void this.#watcher.unwatch(removed);
54
+ }
55
+ if (added.length > 0) {
56
+ for (const dependency of added) {
57
+ this.#fingerprints.set(dependency, this.#fingerprint(dependency));
58
+ }
59
+ this.#watcher.add(added);
60
+ }
61
+ }
62
+ async close() {
63
+ if (this.#closed)
64
+ return;
65
+ this.#closed = true;
66
+ if (this.#timer !== undefined)
67
+ clearTimeout(this.#timer);
68
+ await this.#watcher.close();
69
+ this.#listeners.clear();
70
+ }
71
+ async [Symbol.asyncDispose]() {
72
+ await this.close();
73
+ }
74
+ #cwd() {
75
+ return this.#options.watch?.cwd ?? process.cwd();
76
+ }
77
+ #queue(changed) {
78
+ this.#pending.add(changed);
79
+ if (this.#timer !== undefined)
80
+ clearTimeout(this.#timer);
81
+ this.#timer = setTimeout(() => {
82
+ this.#timer = undefined;
83
+ const pending = this.#pending;
84
+ this.#pending = new Set();
85
+ const paths = new Set();
86
+ for (const dependency of pending) {
87
+ const previous = this.#fingerprints.get(dependency);
88
+ const current = this.#fingerprint(dependency);
89
+ if (current === previous)
90
+ continue;
91
+ this.#fingerprints.set(dependency, current);
92
+ paths.add(dependency);
93
+ }
94
+ if (paths.size === 0)
95
+ return;
96
+ for (const listener of this.#listeners)
97
+ listener({ paths });
98
+ }, this.#options.debounceMs ?? 50);
99
+ }
100
+ #fingerprint(file) {
101
+ try {
102
+ return createHash("sha256")
103
+ .update(readFileSync(file))
104
+ .digest("base64url");
105
+ }
106
+ catch {
107
+ // Missing and unreadable are both materially different from the last
108
+ // successfully read contents, while repeated missing-file events fold
109
+ // onto the same value.
110
+ return undefined;
111
+ }
112
+ }
113
+ }
114
+ //# sourceMappingURL=dependency-watcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dependency-watcher.js","sourceRoot":"","sources":["../src/dependency-watcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,KAAK,EAAwC,MAAM,UAAU,CAAC;AAcvE;;;;;;GAMG;AACH,MAAM,OAAO,iBAAiB;IACnB,QAAQ,CAA2B;IACnC,UAAU,GAAG,IAAI,GAAG,EAA4B,CAAC;IACjD,QAAQ,CAAY;IAC7B,aAAa,GAAwB,IAAI,GAAG,EAAE,CAAC;IAC/C,aAAa,GAAG,IAAI,GAAG,EAA8B,CAAC;IACtD,QAAQ,GAAG,IAAI,GAAG,EAAU,CAAC;IAC7B,MAAM,CAA6B;IACnC,OAAO,GAAG,KAAK,CAAC;IAEhB,YAAY,OAAO,GAA6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C;QACnB,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,54 @@
1
+ import type { TransformOptions } from "rolldown/utils";
2
+ export interface TransformContext {
3
+ readonly url: string;
4
+ readonly path: string;
5
+ readonly format: "module" | "commonjs";
6
+ }
7
+ export interface SourceTransformResult {
8
+ readonly code: string;
9
+ readonly map?: string | object | undefined;
10
+ }
11
+ export type SourceTransform = (code: string, context: TransformContext) => string | SourceTransformResult | undefined;
12
+ export interface ImportLoaderOptions {
13
+ /**
14
+ * Additional package export conditions used during module resolution.
15
+ * They are made available alongside Node's ambient conditions to both the
16
+ * TypeScript-aware resolver and Node's package exports resolver.
17
+ */
18
+ readonly conditions?: ReadonlyArray<string> | undefined;
19
+ /**
20
+ * Oxc transform configuration, layered over the nearest `tsconfig.json`
21
+ * of each transformed file (`jsx`, decorators, …).
22
+ */
23
+ readonly transform?: TransformOptions | undefined;
24
+ /** Additional synchronous source transforms, applied after Oxc. */
25
+ readonly transforms?: ReadonlyArray<SourceTransform> | undefined;
26
+ /**
27
+ * Honour `tsconfig.json` discovered upward from each file: compiler
28
+ * options for the transform, `paths`/`baseUrl` aliases for resolution.
29
+ * @default true
30
+ */
31
+ readonly tsconfig?: boolean | undefined;
32
+ /** Controls which file URLs belong to the fresh import graph. */
33
+ readonly shouldInvalidate?: ((url: string, parentURL: string | undefined) => boolean) | undefined;
34
+ /**
35
+ * Limits transformation to matching absolute file paths; everything else
36
+ * loads through Node untouched. Lets a published install transpile only
37
+ * the user's own TypeScript while alchemy and its dependencies run their
38
+ * built JavaScript.
39
+ */
40
+ readonly filter?: ((path: string) => boolean) | undefined;
41
+ }
42
+ export interface ImportLoaderRegistrationOptions extends ImportLoaderOptions {
43
+ /** Isolates one import graph in the runtime's module cache. */
44
+ readonly namespace?: string | undefined;
45
+ /** Called once the runtime loads a file in this registration's graph. */
46
+ readonly onImport?: ((url: string) => void) | undefined;
47
+ }
48
+ export interface ImportLoader {
49
+ import<T = unknown>(specifier: string, parentURL: string): Promise<T>;
50
+ unregister(): void | Promise<void>;
51
+ }
52
+ /** Creates a Node import loader using synchronous module hooks backed by Oxc. */
53
+ export declare const createImportLoader: (options?: ImportLoaderRegistrationOptions) => Promise<ImportLoader>;
54
+ //# sourceMappingURL=import-loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"import-loader.d.ts","sourceRoot":"","sources":["../src/import-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,QAAQ,GAAG,UAAU,CAAC;CACxC;AAED,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;CAC5C;AAED,MAAM,MAAM,eAAe,GAAG,CAC5B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,gBAAgB,KACtB,MAAM,GAAG,qBAAqB,GAAG,SAAS,CAAC;AAEhD,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;IACxD;;;OAGG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,gBAAgB,GAAG,SAAS,CAAC;IAClD,mEAAmE;IACnE,QAAQ,CAAC,UAAU,CAAC,EAAE,aAAa,CAAC,eAAe,CAAC,GAAG,SAAS,CAAC;IACjE;;;;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;CAC3D;AAED,MAAM,WAAW,+BAAgC,SAAQ,mBAAmB;IAC1E,+DAA+D;IAC/D,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,YAAY;IAC3B,MAAM,CAAC,CAAC,GAAG,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACtE,UAAU,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACpC;AAED,iFAAiF;AACjF,eAAO,MAAM,kBAAkB,aACpB,+BAA+B,KACvC,OAAO,CAAC,YAAY,CAQtB,CAAC"}
@@ -0,0 +1,9 @@
1
+ /** Creates a Node import loader using synchronous module hooks backed by Oxc. */
2
+ export const createImportLoader = async (options = {}) => {
3
+ if (process.versions.bun !== undefined) {
4
+ throw new Error("The import-aware loader is only available in Node; use Bun's process-level watcher instead.");
5
+ }
6
+ const { registerOxc } = await import("./register-oxc.js");
7
+ return registerOxc(options);
8
+ };
9
+ //# sourceMappingURL=import-loader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"import-loader.js","sourceRoot":"","sources":["../src/import-loader.ts"],"names":[],"mappings":"AA+DA,iFAAiF;AACjF,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,EACrC,OAAO,GAAoC,EAAE,EACtB,EAAE;IACzB,IAAI,OAAO,CAAC,QAAQ,CAAC,GAAG,KAAK,SAAS,EAAE,CAAC;QACvC,MAAM,IAAI,KAAK,CACb,6FAA6F,CAC9F,CAAC;IACJ,CAAC;IACD,MAAM,EAAE,WAAW,EAAE,GAAG,MAAM,MAAM,CAAC,mBAAmB,CAAC,CAAC;IAC1D,OAAO,WAAW,CAAC,OAAO,CAAC,CAAC;AAC9B,CAAC,CAAC"}
@@ -0,0 +1,16 @@
1
+ import type { ImportLoader, ImportLoaderRegistrationOptions } from "./import-loader.ts";
2
+ export type { ImportLoader as RegisteredOxcImporter, ImportLoaderRegistrationOptions as RegisterOxcOptions, SourceTransform, SourceTransformResult, TransformContext, } from "./import-loader.ts";
3
+ /**
4
+ * Registers synchronous Node module hooks that transpile TypeScript with
5
+ * Rolldown's Oxc transformer and resolve it the way TypeScript (and tsx)
6
+ * does. A namespaced registration also provides a scoped import whose
7
+ * namespace propagates through the complete ESM graph.
8
+ */
9
+ export declare const registerOxc: (options?: ImportLoaderRegistrationOptions) => ImportLoader;
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>;
16
+ //# sourceMappingURL=register-oxc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register-oxc.d.ts","sourceRoot":"","sources":["../src/register-oxc.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACV,YAAY,EACZ,+BAA+B,EAChC,MAAM,oBAAoB,CAAC;AAU5B,YAAY,EACV,YAAY,IAAI,qBAAqB,EACrC,+BAA+B,IAAI,kBAAkB,EACrD,eAAe,EACf,qBAAqB,EACrB,gBAAgB,GACjB,MAAM,oBAAoB,CAAC;AAwK5B;;;;;GAKG;AACH,eAAO,MAAM,WAAW,aACb,+BAA+B,KACvC,YAuHF,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,QAAQ,GAAU,CAAC,GAAG,OAAO,aAC7B,MAAM,aACN,MAAM,YACR,IAAI,CAAC,+BAA+B,EAAE,WAAW,CAAC,KAC1D,OAAO,CAAC,CAAC,CAOX,CAAC"}
@@ -0,0 +1,257 @@
1
+ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
2
+ if (typeof path === "string" && /^\.\.?\//.test(path)) {
3
+ return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
4
+ return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
5
+ });
6
+ }
7
+ return path;
8
+ };
9
+ import { randomUUID } from "node:crypto";
10
+ import { registerHooks, } from "node:module";
11
+ import { pathToFileURL } from "node:url";
12
+ import { filePathOfUrl, isFileLikeSpecifier, isProjectPath, SpecifierResolver, splitSpecifierMetadata, } from "./resolve-specifier.js";
13
+ import { SourceTransformer } from "./transform-source.js";
14
+ const protocol = "alchemy-import:";
15
+ const namespaceParameter = "alchemy-import-namespace";
16
+ const globalRegistrationKey = Symbol.for("@alchemy.run/node-utils/register-oxc");
17
+ const namespaceOf = (url) => {
18
+ if (url === undefined || !url.startsWith("file:"))
19
+ return undefined;
20
+ return new URL(url).searchParams.get(namespaceParameter) ?? undefined;
21
+ };
22
+ const withoutNamespace = (url) => {
23
+ if (!url.startsWith("file:"))
24
+ return url;
25
+ const parsed = new URL(url);
26
+ parsed.searchParams.delete(namespaceParameter);
27
+ return parsed.href;
28
+ };
29
+ const withNamespace = (url, namespace) => {
30
+ const parsed = new URL(url);
31
+ parsed.searchParams.set(namespaceParameter, namespace);
32
+ return parsed.href;
33
+ };
34
+ const parseRequest = (specifier) => {
35
+ if (!specifier.startsWith(protocol))
36
+ return undefined;
37
+ return JSON.parse(decodeURIComponent(specifier.slice(protocol.length)));
38
+ };
39
+ /** Specifiers Node owns outright: builtins, data URLs, remote schemes. */
40
+ const isForeignSpecifier = (specifier) => /^(?:node:|data:|[a-z][a-z\d+.-]*:\/\/)/i.test(specifier) &&
41
+ !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
+ /** A `require()` reaching the hooks: Node's CommonJS resolver wants paths, not URLs. */
72
+ const isRequireContext = (context) => context.conditions?.includes("require") === true &&
73
+ !context.conditions.includes("import");
74
+ const resolveWithCandidate = (candidate, metadata, context, nextResolve) => {
75
+ const specifier = isRequireContext(context)
76
+ ? candidate + metadata
77
+ : pathToFileURL(candidate).href + metadata;
78
+ try {
79
+ return nextResolve(specifier, context);
80
+ }
81
+ catch {
82
+ return undefined;
83
+ }
84
+ };
85
+ /**
86
+ * tsx-compatible resolution. Node's resolver decides in the end; Oxc's
87
+ * resolver supplies the TypeScript-aware candidate (tsconfig `paths`,
88
+ * `.js` → `.ts` substitution, extensionless and directory imports) that
89
+ * Node would not find on its own.
90
+ */
91
+ const resolveSpecifier = (resolver, specifier, context, nextResolve) => {
92
+ if (isForeignSpecifier(specifier))
93
+ return nextResolve(specifier, context);
94
+ const parentPath = filePathOfUrl(context.parentURL);
95
+ const { specifier: clean, metadata } = splitSpecifierMetadata(specifier);
96
+ const conditions = context.conditions ?? [];
97
+ // TypeScript's rules apply to project code. Dependencies keep Node's plain
98
+ // resolution so published packages behave exactly as they would without us.
99
+ if (parentPath !== undefined && isProjectPath(parentPath)) {
100
+ const candidate = resolver.resolve(parentPath, clean, conditions);
101
+ if (candidate !== undefined) {
102
+ const resolved = resolveWithCandidate(candidate, metadata, context, nextResolve);
103
+ if (resolved !== undefined)
104
+ return resolved;
105
+ }
106
+ }
107
+ try {
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
+ }
126
+ };
127
+ /**
128
+ * `import data from "./x.json"` without an import attribute is how
129
+ * TypeScript projects import JSON (`resolveJsonModule`); Node insists on
130
+ * `with { type: "json" }` for ESM. Supply it, as tsx does.
131
+ */
132
+ const withJsonAttribute = (url, context) => {
133
+ if (!/\.json(?:[?#]|$)/.test(url) || context.importAttributes?.type) {
134
+ return context;
135
+ }
136
+ return {
137
+ ...context,
138
+ importAttributes: { ...context.importAttributes, type: "json" },
139
+ };
140
+ };
141
+ /**
142
+ * Registers synchronous Node module hooks that transpile TypeScript with
143
+ * Rolldown's Oxc transformer and resolve it the way TypeScript (and tsx)
144
+ * does. A namespaced registration also provides a scoped import whose
145
+ * namespace propagates through the complete ESM graph.
146
+ */
147
+ export const registerOxc = (options = {}) => {
148
+ // One global (un-namespaced) registration per process. Alchemy starts every
149
+ // Node process with `--import` of a file that calls this, and in-process
150
+ // callers (the dev exec child, tests) may call it again; a second copy of
151
+ // the hooks would only re-run the resolve chain. The marker lives on
152
+ // globalThis because a checkout can load this module twice (src/ and lib/).
153
+ const globalRegistration = globalThis;
154
+ if (options.namespace === undefined) {
155
+ const existing = globalRegistration[globalRegistrationKey];
156
+ if (existing !== undefined)
157
+ return existing;
158
+ }
159
+ const transformer = new SourceTransformer(options);
160
+ const resolver = new SpecifierResolver({
161
+ tsconfig: options.tsconfig ?? true,
162
+ });
163
+ const shouldInvalidate = options.shouldInvalidate ?? (() => true);
164
+ // Transformed sources carry inline source maps; Node only applies them to
165
+ // stack traces once source-map support is on.
166
+ const sourceMapsWereEnabled = process.sourceMapsEnabled;
167
+ process.setSourceMapsEnabled(true);
168
+ const hooks = registerHooks({
169
+ resolve(specifier, context, nextResolve) {
170
+ const request = parseRequest(specifier);
171
+ const inheritedNamespace = namespaceOf(context.parentURL);
172
+ const namespace = options.namespace === undefined
173
+ ? undefined
174
+ : (request?.namespace ?? inheritedNamespace);
175
+ if (options.namespace !== undefined && namespace !== options.namespace) {
176
+ return nextResolve(specifier, context);
177
+ }
178
+ const resolutionContext = options.conditions === undefined || options.conditions.length === 0
179
+ ? context
180
+ : {
181
+ ...context,
182
+ conditions: [
183
+ ...new Set([...options.conditions, ...context.conditions]),
184
+ ],
185
+ };
186
+ const resolved = request
187
+ ? resolveSpecifier(resolver, request.specifier, { ...resolutionContext, parentURL: request.parentURL }, nextResolve)
188
+ : resolveSpecifier(resolver, specifier, resolutionContext, nextResolve);
189
+ if (namespace !== undefined &&
190
+ resolved.url.startsWith("file:") &&
191
+ shouldInvalidate(withoutNamespace(resolved.url), context.parentURL === undefined
192
+ ? undefined
193
+ : withoutNamespace(context.parentURL))) {
194
+ return { ...resolved, url: withNamespace(resolved.url, namespace) };
195
+ }
196
+ return resolved;
197
+ },
198
+ load(url, context, nextLoad) {
199
+ const namespace = namespaceOf(url);
200
+ if (options.namespace !== undefined && namespace !== options.namespace) {
201
+ return nextLoad(url, context);
202
+ }
203
+ const cleanUrl = withoutNamespace(url);
204
+ const filePath = filePathOfUrl(cleanUrl);
205
+ if (filePath === undefined)
206
+ return nextLoad(cleanUrl, context);
207
+ options.onImport?.(cleanUrl);
208
+ if (options.filter !== undefined && !options.filter(filePath)) {
209
+ return nextLoad(cleanUrl, withJsonAttribute(cleanUrl, context));
210
+ }
211
+ const transformed = transformer.transform(filePath, cleanUrl, context.format);
212
+ if (transformed === undefined) {
213
+ return nextLoad(cleanUrl, withJsonAttribute(cleanUrl, context));
214
+ }
215
+ return { ...transformed, shortCircuit: true };
216
+ },
217
+ });
218
+ const loader = {
219
+ import(specifier, parentURL) {
220
+ const request = {
221
+ namespace: options.namespace,
222
+ parentURL: parentURL.startsWith("file:")
223
+ ? parentURL
224
+ : pathToFileURL(parentURL).href,
225
+ specifier,
226
+ };
227
+ return import(__rewriteRelativeImportExtension(`${protocol}${encodeURIComponent(JSON.stringify(request))}`));
228
+ },
229
+ unregister() {
230
+ hooks.deregister();
231
+ if (globalRegistration[globalRegistrationKey] === loader) {
232
+ delete globalRegistration[globalRegistrationKey];
233
+ }
234
+ if (sourceMapsWereEnabled === false)
235
+ process.setSourceMapsEnabled(false);
236
+ },
237
+ };
238
+ if (options.namespace === undefined) {
239
+ globalRegistration[globalRegistrationKey] = loader;
240
+ }
241
+ return loader;
242
+ };
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
+ //# sourceMapp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,CAAC;YAAS,CAAC;QACT,MAAM,MAAM,CAAC,UAAU,EAAE,CAAC;IAC5B,CAAC;AACH,CAAC,CAAC"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * TypeScript-aware specifier resolution on top of Oxc's resolver, mirroring
3
+ * what tsx layers over Node's resolver:
4
+ *
5
+ * - `tsconfig.json` `paths` / `baseUrl` aliases, discovered per importing file
6
+ * - emitted-extension substitution (`./x.js` → `x.ts`/`x.tsx`, `.mjs` → `.mts`,
7
+ * `.cjs` → `.cts`, `.jsx` → `.tsx`), TypeScript source winning over an
8
+ * emitted sibling
9
+ * - extensionless specifiers and directory indexes, TypeScript first
10
+ *
11
+ * Node's own resolver stays the authority: every candidate this class
12
+ * produces is handed back to Node (`nextResolve`) so it decides the format,
13
+ * validates package exports, and reports the canonical error.
14
+ */
15
+ export interface SpecifierResolverOptions {
16
+ /** Discover `tsconfig.json` upward from each importing file. */
17
+ readonly tsconfig: boolean;
18
+ }
19
+ export declare const nodeModulesSegment: string;
20
+ /** Local project code: a file path outside every `node_modules` directory. */
21
+ export declare const isProjectPath: (filePath: string) => boolean;
22
+ /** Whether TypeScript's extension substitution applies to this importer. */
23
+ export declare const isTypeScriptPath: (filePath: string) => boolean;
24
+ export declare const isFileLikeSpecifier: (specifier: string) => boolean;
25
+ /**
26
+ * Splits `?query#fragment` metadata off a specifier. Bare specifiers never
27
+ * carry fragments in Node, so only `?` is honoured there.
28
+ */
29
+ export declare const splitSpecifierMetadata: (specifier: string) => {
30
+ specifier: string;
31
+ metadata: string;
32
+ };
33
+ export declare const filePathOfUrl: (url: string | undefined) => string | undefined;
34
+ export declare class SpecifierResolver {
35
+ #private;
36
+ constructor(options: SpecifierResolverOptions);
37
+ /**
38
+ * Resolves `specifier` as imported from `parentPath` to an absolute file
39
+ * path, or `undefined` when Oxc cannot resolve it (Node then reports the
40
+ * error), when it is a builtin, or when a bare specifier lands inside
41
+ * `node_modules` — packages are Node's business, only `paths` aliases
42
+ * that map onto project files are ours.
43
+ */
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
+ }
52
+ //# sourceMappingURL=resolve-specifier.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-specifier.d.ts","sourceRoot":"","sources":["../src/resolve-specifier.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,wBAAwB;IACvC,gEAAgE;IAChE,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;CAC5B;AAED,eAAO,MAAM,kBAAkB,QAAuC,CAAC;AAEvE,8EAA8E;AAC9E,eAAO,MAAM,aAAa,aAAc,MAAM,YACN,CAAC;AAIzC,4EAA4E;AAC5E,eAAO,MAAM,gBAAgB,aAAc,MAAM,YACZ,CAAC;AAEtC,eAAO,MAAM,mBAAmB,cAAe,MAAM,YAMzB,CAAC;AAE7B;;;GAGG;AACH,eAAO,MAAM,sBAAsB,cAAe,MAAM;;;CAUvD,CAAC;AAEF,eAAO,MAAM,aAAa,QAAS,MAAM,GAAG,SAAS,uBAOpD,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;IAED;;;;OAIG;IACH,cAAc,CACZ,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,aAAa,CAAC,MAAM,CAAC,GAChC,MAAM,GAAG,SAAS,CAYpB;CACF"}