vite-plus 1.2.0 → 1.4.0

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 (94) hide show
  1. package/AGENTS.md +4 -0
  2. package/LICENSE +1 -849
  3. package/README.md +1 -1
  4. package/bin/vpx +9 -0
  5. package/binding/index.cjs +59 -54
  6. package/binding/index.d.cts +132 -2
  7. package/dist/{agent-KeDc6vmg.js → agent-D8oxxhVR.js} +7 -9
  8. package/dist/bin.js +27 -34
  9. package/dist/{cli-parse-DHE8NrBU.js → cli-parse-aeUeFDlC.js} +2 -3
  10. package/dist/command-TjS_6y9O.js +1 -0
  11. package/dist/{command-CguLh2KL.js → command-rY79K5NI.js} +40 -42
  12. package/dist/{comparison-CmVirWIW-DUGaiYqF.js → comparison-CmVirWIW-UlEf2maz.js} +1 -2
  13. package/dist/config/bin.js +8 -10
  14. package/dist/{constants-BW3g7VnD.js → constants-DRUnJ_Dz.js} +4 -6
  15. package/dist/create/bin.d.ts +4 -8
  16. package/dist/create/bin.js +64 -68
  17. package/dist/{define-config-CIlk9scU.js → define-config-ChwJcu5e.js} +6 -9
  18. package/dist/{define-config-Dq_23Eyr.cjs → define-config-Cv2P6NT2.cjs} +8 -13
  19. package/dist/{define-config-Bexdd6RZ.d.ts → define-config-rPhYIFSn.d.ts} +1 -11
  20. package/dist/define-config.cjs +1 -1
  21. package/dist/define-config.d.ts +1 -1
  22. package/dist/define-config.js +1 -1
  23. package/dist/{dist-Bi7ZEK3c.js → dist-Bs0SObNC.js} +77 -149
  24. package/dist/{dist-Cqz8OtiO.js → dist-CdkMvIiQ.js} +11 -5
  25. package/dist/dist-zDZV5eEc.js +3 -0
  26. package/dist/{documentation-DqcZSthV.js → documentation-cv_y0Auv.js} +1 -2
  27. package/dist/{editor-b1XUwt9v.js → editor-ClL78D8u.js} +1492 -4211
  28. package/dist/{help-BmKpeOP9.js → help-B03t_iQ4.js} +1 -2
  29. package/dist/hooks/bin.js +4 -5
  30. package/dist/{hooks-DhwsWb46.js → hooks-xRcJPc-O.js} +5 -4
  31. package/dist/index.cjs +2 -3
  32. package/dist/index.d.ts +1 -1
  33. package/dist/index.js +1 -1
  34. package/dist/{json-JP24qHUF.js → json-kl84kDyH.js} +9 -18
  35. package/dist/lint-plugins.cjs +1 -1
  36. package/dist/migration/bin.js +719 -184
  37. package/dist/migration/compat/worker.js +4 -6
  38. package/dist/{oxlint-plugin-config-Dx-ZY2MN.js → oxlint-plugin-config-BVpqYdcC.js} +3 -4
  39. package/dist/oxlint-plugin.d.ts +0 -2
  40. package/dist/oxlint-plugin.js +6 -7
  41. package/dist/{pack-BK38MLVZ.d.ts → pack-ARPFMefW.d.ts} +0 -2
  42. package/dist/pack-bin.d.ts +1 -3
  43. package/dist/pack-bin.js +3 -4
  44. package/dist/pack.d.ts +1 -1
  45. package/dist/{package-BP16iQby.js → package-DzsomcUD.js} +10 -95
  46. package/dist/{package-overrides-D1RcXSFl.js → package-overrides-Ci8GXouY.js} +5 -8
  47. package/dist/picomatch-DEUoj81q.js +1916 -0
  48. package/dist/{prompts-BGpQtC5z.js → prompts-GL1vj0wk.js} +113 -239
  49. package/dist/{protocol-D99W10Qi.js → protocol-CkNmY-Mr.js} +1 -2
  50. package/dist/{report-NhQk8VHb.js → report-DLHO30yZ.js} +2 -2
  51. package/dist/{resolve-vite-config-x47JetlI.js → resolve-vite-config-Dn5896A4.js} +9 -25
  52. package/dist/resolve-vite-config-QO6cC0SP.js +1 -0
  53. package/dist/{rolldown-runtime-CMFfr-1z.js → rolldown-runtime-DegdyBIC.js} +2 -3
  54. package/dist/script-esm-hooks.d.ts +8 -0
  55. package/dist/script-esm-hooks.js +24 -0
  56. package/dist/script-hooks-9Fof5UMY.js +176 -0
  57. package/dist/script-preload.cjs +468 -0
  58. package/dist/script-register.d.ts +1 -0
  59. package/dist/script-register.js +22 -0
  60. package/dist/script-watch.d.ts +1 -0
  61. package/dist/script-watch.js +1908 -0
  62. package/dist/staged/bin.js +81 -2011
  63. package/dist/sync-versions/bin.js +29 -50
  64. package/dist/sync-versions/bin.mjs +117 -224
  65. package/dist/{terminal-MKGAuy-p.js → terminal-BcuPUy-j.js} +1 -2
  66. package/dist/toolchain.js +36 -10
  67. package/dist/toolchain.json +36 -10
  68. package/dist/{tsconfig-C5PnJfW4.js → tsconfig-Do6MAG_f.js} +1 -1
  69. package/dist/{tsconfig-D2DzAQ_D.js → tsconfig-LE_mAwe_.js} +8 -10
  70. package/dist/version.d.ts +1 -3
  71. package/dist/version.js +5 -6
  72. package/dist/versions.js +5 -5
  73. package/dist/{vitest-ecosystem-BU0AqZq-.js → vitest-ecosystem-BeEYz-qF.js} +1 -2
  74. package/dist/{vitest-v5-entry-points-DthU1e_O.js → vitest-v5-entry-points-NyJsFeux.js} +1 -2
  75. package/dist/vpx-bin.d.ts +1 -0
  76. package/dist/vpx-bin.js +232 -0
  77. package/dist/vpx-script-EXgV5QOf.js +434 -0
  78. package/docs/config/run.md +4 -0
  79. package/docs/guide/check.md +1 -0
  80. package/docs/guide/ci.md +13 -3
  81. package/docs/guide/create.md +34 -0
  82. package/docs/guide/env.md +27 -13
  83. package/docs/guide/global-cli.md +52 -0
  84. package/docs/guide/local-cli.md +4 -4
  85. package/docs/guide/migrate-rules.md +48 -5
  86. package/docs/guide/migrate.md +6 -6
  87. package/docs/guide/package-management.md +19 -2
  88. package/docs/guide/test.md +1 -1
  89. package/docs/guide/vitest-v5.md +2 -2
  90. package/docs/guide/vpx.md +170 -9
  91. package/package.json +32 -29
  92. package/dist/command-DaRqSNpP.js +0 -1
  93. package/dist/dist-CBWGibx8.js +0 -3
  94. package/dist/resolve-vite-config-CGzlyhGr.js +0 -1
@@ -0,0 +1,468 @@
1
+ // \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod, mod.exports), cb = null), mod.exports);
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
+ get: ((k) => from[k]).bind(null, key),
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
20
+ value: mod,
21
+ enumerable: true
22
+ }) : target, mod));
23
+ let node_module = require("node:module");
24
+ node_module = __toESM(node_module, 1);
25
+ let node_path = require("node:path");
26
+ node_path = __toESM(node_path, 1);
27
+ let node_worker_threads = require("node:worker_threads");
28
+ let node_net = require("node:net");
29
+ // ../../oxc-node/packages/core/signal-ack.mjs
30
+ var import_lib = (/* @__PURE__ */ __commonJSMin(((exports, module) => {
31
+ const BuiltinModule = require("module");
32
+ const path = require("path");
33
+ const nodeModulesRegex = /^(?:.*[\\/])?node_modules(?:[\\/].*)?$/;
34
+ const Module = module.constructor.length > 1 ? module.constructor : BuiltinModule;
35
+ const HOOK_RETURNED_NOTHING_ERROR_MESSAGE = "[Pirates] A hook returned a non-string, or nothing at all! This is a violation of intergalactic law!\n--------------------\nIf you have no idea what this means or what Pirates is, let me explain: Pirates is a module that makes it easy to implement require hooks. One of the require hooks you're using uses it. One of these require hooks didn't return anything from it's handler, so we don't know what to do. You might want to debug this.";
36
+ /**
37
+ * @param {string} filename The filename to check.
38
+ * @param {string[]} exts The extensions to hook. Should start with '.' (ex. ['.js']).
39
+ * @param {Matcher|null} matcher A matcher function, will be called with path to a file. Should return truthy if the file should be hooked, falsy otherwise.
40
+ * @param {boolean} ignoreNodeModules Auto-ignore node_modules. Independent of any matcher.
41
+ */
42
+ function shouldCompile(filename, exts, matcher, ignoreNodeModules) {
43
+ if (typeof filename !== "string") return false;
44
+ if (exts.indexOf(path.extname(filename)) === -1) return false;
45
+ const resolvedFilename = path.resolve(filename);
46
+ if (ignoreNodeModules && nodeModulesRegex.test(resolvedFilename)) return false;
47
+ if (matcher && typeof matcher === "function") return !!matcher(resolvedFilename);
48
+ return true;
49
+ }
50
+ /**
51
+ * @callback Hook The hook. Accepts the code of the module and the filename.
52
+ * @param {string} code
53
+ * @param {string} filename
54
+ * @returns {string}
55
+ */
56
+ /**
57
+ * @callback Matcher A matcher function, will be called with path to a file.
58
+ *
59
+ * Should return truthy if the file should be hooked, falsy otherwise.
60
+ * @param {string} path
61
+ * @returns {boolean}
62
+ */
63
+ /**
64
+ * @callback RevertFunction Reverts the hook when called.
65
+ * @returns {void}
66
+ */
67
+ /**
68
+ * @typedef {object} Options
69
+ * @property {Matcher|null} [matcher=null] A matcher function, will be called with path to a file.
70
+ *
71
+ * Should return truthy if the file should be hooked, falsy otherwise.
72
+ *
73
+ * @property {string[]} [extensions=['.js']] The extensions to hook. Should start with '.' (ex. ['.js']).
74
+ * @property {string[]} [exts=['.js']] The extensions to hook. Should start with '.' (ex. ['.js']).
75
+ *
76
+ * @property {string[]} [extension=['.js']] The extensions to hook. Should start with '.' (ex. ['.js']).
77
+ * @property {string[]} [ext=['.js']] The extensions to hook. Should start with '.' (ex. ['.js']).
78
+ *
79
+ * @property {boolean} [ignoreNodeModules=true] Auto-ignore node_modules. Independent of any matcher.
80
+ */
81
+ /**
82
+ * Add a require hook.
83
+ *
84
+ * @param {Hook} hook The hook. Accepts the code of the module and the filename. Required.
85
+ * @param {Options} [opts] Options
86
+ * @returns {RevertFunction} The `revert` function. Reverts the hook when called.
87
+ */
88
+ function addHook(hook, opts = {}) {
89
+ let reverted = false;
90
+ const loaders = [];
91
+ const oldLoaders = [];
92
+ let exts;
93
+ const originalJSLoader = Module._extensions[".js"];
94
+ const matcher = opts.matcher || null;
95
+ const ignoreNodeModules = opts.ignoreNodeModules !== false;
96
+ exts = opts.extensions || opts.exts || opts.extension || opts.ext || [".js"];
97
+ if (!Array.isArray(exts)) exts = [exts];
98
+ exts.forEach((ext) => {
99
+ if (typeof ext !== "string") throw new TypeError(`Invalid Extension: ${ext}`);
100
+ const oldLoader = Module._extensions[ext] || originalJSLoader;
101
+ oldLoaders[ext] = Module._extensions[ext];
102
+ loaders[ext] = Module._extensions[ext] = function newLoader(mod, filename) {
103
+ let compile;
104
+ if (!reverted) {
105
+ if (shouldCompile(filename, exts, matcher, ignoreNodeModules)) {
106
+ compile = mod._compile;
107
+ mod._compile = function _compile(code) {
108
+ mod._compile = compile;
109
+ const newCode = hook(code, filename);
110
+ if (typeof newCode !== "string") throw new Error(HOOK_RETURNED_NOTHING_ERROR_MESSAGE);
111
+ return mod._compile(newCode, filename);
112
+ };
113
+ }
114
+ }
115
+ oldLoader(mod, filename);
116
+ };
117
+ });
118
+ return function revert() {
119
+ if (reverted) return;
120
+ reverted = true;
121
+ exts.forEach((ext) => {
122
+ if (Module._extensions[ext] === loaders[ext]) {
123
+ if (!oldLoaders[ext]) delete Module._extensions[ext];
124
+ else Module._extensions[ext] = oldLoaders[ext];
125
+ }
126
+ });
127
+ };
128
+ }
129
+ exports.addHook = addHook;
130
+ })))();
131
+ /**
132
+ * Ack every SIGINT this process gets, for as long as the app listens for SIGINT
133
+ * itself. An app that does not keeps Node.js' default and dies on the signal,
134
+ * so there is nothing to ack, and the extra listener must not keep it alive.
135
+ *
136
+ * A no-op unless OXNODE_SIGNAL_ACK is set. Call it on the main thread only.
137
+ */
138
+ function installSignalAck() {
139
+ const path = process.env.OXNODE_SIGNAL_ACK;
140
+ delete process.env.OXNODE_SIGNAL_ACK;
141
+ if (!path) return;
142
+ let socket = null;
143
+ let installed = false;
144
+ const ack = () => {
145
+ socket?.write("I");
146
+ };
147
+ const getMaxListeners = process.getMaxListeners.bind(process);
148
+ const setMaxListeners = process.setMaxListeners.bind(process);
149
+ let raised = null;
150
+ const raise = () => {
151
+ const max = getMaxListeners();
152
+ raised = max > 0 && Number.isFinite(max) ? max + 1 : null;
153
+ if (raised !== null) setMaxListeners(raised);
154
+ };
155
+ const lower = () => {
156
+ if (raised !== null && getMaxListeners() === raised) setMaxListeners(raised - 1);
157
+ raised = null;
158
+ };
159
+ const install = () => {
160
+ installed = true;
161
+ raise();
162
+ if (!socket) {
163
+ socket = (0, node_net.connect)(path);
164
+ socket.on("error", () => {
165
+ socket = null;
166
+ });
167
+ socket.unref();
168
+ }
169
+ process.prependListener("SIGINT", ack);
170
+ };
171
+ const listeners = process.listeners.bind(process);
172
+ const rawListeners = process.rawListeners.bind(process);
173
+ const listenerCount = process.listenerCount.bind(process);
174
+ if (listenerCount("SIGINT") > 0) install();
175
+ process.on("newListener", (event, listener) => {
176
+ if (event === "SIGINT" && listener !== ack && !installed) install();
177
+ });
178
+ process.on("removeListener", (event, listener) => {
179
+ if (event !== "SIGINT") return;
180
+ if (listener === ack) {
181
+ installed = false;
182
+ lower();
183
+ return;
184
+ }
185
+ const left = rawListeners("SIGINT");
186
+ if (installed && left.length === 1 && left[0] === ack) process.removeListener("SIGINT", ack);
187
+ });
188
+ const visible = (list) => list.filter((listener) => listener !== ack);
189
+ process.listeners = (event) => {
190
+ const list = listeners(event);
191
+ return event === "SIGINT" ? visible(list) : list;
192
+ };
193
+ process.rawListeners = (event) => {
194
+ const list = rawListeners(event);
195
+ return event === "SIGINT" ? visible(list) : list;
196
+ };
197
+ process.listenerCount = (event, ...rest) => {
198
+ const count = listenerCount(event, ...rest);
199
+ if (event !== "SIGINT" || !installed || rest.length > 0) return count;
200
+ return count - 1;
201
+ };
202
+ process.getMaxListeners = () => {
203
+ const max = getMaxListeners();
204
+ return raised !== null && max === raised ? max - 1 : max;
205
+ };
206
+ process.setMaxListeners = (n) => {
207
+ setMaxListeners(n);
208
+ if (installed) raise();
209
+ return process;
210
+ };
211
+ }
212
+ // ../../oxc-node/packages/core/watch-report.mjs
213
+ const WATCH_CHANNEL = "@oxc-node/core:watch-deps";
214
+ /**
215
+ * Where this thread sends its reports, or `null` when nobody is watching. With
216
+ * `null` nothing is wrapped, opened or listened to.
217
+ *
218
+ * @returns {((message: { "watch:import": string[] }) => void) | null}
219
+ */
220
+ function watchSink() {
221
+ if (!process.env.WATCH_REPORT_DEPENDENCIES) return null;
222
+ if (node_worker_threads.isMainThread) {
223
+ if (typeof process.send !== "function") return null;
224
+ const seen = /* @__PURE__ */ new Set();
225
+ const send = (message) => {
226
+ const url = message?.["watch:import"]?.[0];
227
+ if (typeof url !== "string" || seen.has(url) || !process.connected) return;
228
+ seen.add(url);
229
+ try {
230
+ process.send(message, () => {});
231
+ } catch {}
232
+ };
233
+ const channel = new BroadcastChannel(WATCH_CHANNEL);
234
+ channel.onmessage = (event) => send(event.data);
235
+ channel.unref();
236
+ return send;
237
+ }
238
+ const channel = new BroadcastChannel(WATCH_CHANNEL);
239
+ channel.unref();
240
+ return (message) => channel.postMessage(message);
241
+ }
242
+ /**
243
+ * Send what the binding recorded, one URL per message: the watch parent reads a
244
+ * whole array in one `try`, so one bad entry would drop the rest. `oxnode watch`
245
+ * reads the `oxc-node` key to tell these from what Node.js reports (a tsconfig
246
+ * in `node_modules` counts, an imported file there does not); Node.js ignores it.
247
+ *
248
+ * @param {(message: { "watch:import": string[], "oxc-node": true }) => void} sink
249
+ * @param {() => string[]} take the binding's `takeWatchDependencies`
250
+ */
251
+ function flush(sink, take) {
252
+ for (const url of take()) sink({
253
+ "watch:import": [url],
254
+ "oxc-node": true
255
+ });
256
+ }
257
+ /**
258
+ * `fn`, flushing after each call whether it returns, throws or returns a promise.
259
+ * A failed resolve records its candidates and then throws, which is exactly the
260
+ * case that has to be reported. `sink` and `take` are as for `flush`.
261
+ */
262
+ function withFlush(fn, sink, take) {
263
+ return function(...args) {
264
+ let result;
265
+ try {
266
+ result = fn.apply(this, args);
267
+ } catch (error) {
268
+ flush(sink, take);
269
+ throw error;
270
+ }
271
+ if (result && typeof result.then === "function") return result.then((value) => {
272
+ flush(sink, take);
273
+ return value;
274
+ }, (error) => {
275
+ flush(sink, take);
276
+ throw error;
277
+ });
278
+ flush(sink, take);
279
+ return result;
280
+ };
281
+ }
282
+ // src/script-hooks.ts
283
+ /**
284
+ * Shared pieces of the `vpx <script>` loader (see `script-preload.ts`).
285
+ */
286
+ /**
287
+ * The oxc-node hooks compiled into the Vite+ binding. Required, not imported: importing
288
+ * `index.js` makes a `module.register()` hooks thread translate the whole CommonJS
289
+ * binding for ESM, and `module.register()` waits for that (5-13 ms).
290
+ */
291
+ function loadOxcNode() {
292
+ return (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href)("../binding/index.cjs").oxcNode;
293
+ }
294
+ const WATCH_SINK = Symbol.for("vite-plus:script-watch-sink");
295
+ /**
296
+ * Where this thread reports the files watch mode restarts on, or `null` when nobody is
297
+ * watching (see oxc-node's `watchSink()`). It opens a channel, so it runs once per thread:
298
+ * the preload and the `--import` entry are separate bundles and share it here.
299
+ */
300
+ function threadWatchSink() {
301
+ const holder = globalThis;
302
+ if (holder[WATCH_SINK] === void 0) holder[WATCH_SINK] = watchSink();
303
+ return holder[WATCH_SINK];
304
+ }
305
+ /** Must match `engines.node` in package.json; `__tests__/vpx-script.spec.ts` checks it. */
306
+ const SUPPORTED_NODE_RANGE = "^22.18.0 || ^24.11.0 || >=26.0.0";
307
+ function isSupportedNodeVersion(version) {
308
+ const [major = 0, minor = 0] = version.split(".").map(Number);
309
+ if (major === 22) return minor >= 18;
310
+ if (major === 24) return minor >= 11;
311
+ return major >= 26;
312
+ }
313
+ /**
314
+ * Whether to use the in-thread `module.registerHooks()` instead of the off-thread
315
+ * `module.register()`, which needs a hooks thread (about twice the startup time) and
316
+ * which Node.js deprecates from 25.9 (DEP0205).
317
+ *
318
+ * The in-thread hooks need two fixes: a sync resolve hook had its `conditions`
319
+ * overridden (nodejs/node#59011, in 22.19 and 24.5), and a sync load hook could not
320
+ * return a null source for CommonJS (nodejs/node#59929, in 22.22.3 and 24.11.1). tsx
321
+ * switches at the same releases. Upstream oxc-node waits for 26.2 for a third fix,
322
+ * nodejs/node#62920 (also in 24.18.0), which only matters when a load hook returns
323
+ * CommonJS source. These hooks return it only for source another hook supplied, so
324
+ * without that fix `require()` inside such a module can fail.
325
+ */
326
+ function canRegisterSyncHooks(version) {
327
+ const [major = 0, minor = 0, patch = 0] = version.split(".").map(Number);
328
+ if (major === 22) return minor > 22 || minor === 22 && patch >= 3;
329
+ if (major === 24) return minor > 11 || minor === 11 && patch >= 1;
330
+ return major >= 26;
331
+ }
332
+ /**
333
+ * The module name oxc-node gives the runtime helpers it injects, passed to its transformer
334
+ * and load hook. Only these hooks emit it, so they redirect only their own helper imports,
335
+ * not `@oxc-node/core/helpers/*` imports that another oxc-node copy produced.
336
+ */
337
+ const HELPER_MODULE_NAME = "vite-plus:oxc-node";
338
+ const OXC_NODE_HELPERS = `${HELPER_MODULE_NAME}/helpers/`;
339
+ const RUNTIME_HELPERS = "@oxc-project/runtime/helpers/";
340
+ /**
341
+ * oxc-node lowers class fields, static blocks, `using`, and legacy decorators to
342
+ * helper imports. The same helpers ship in `@oxc-project/runtime`, a dependency of
343
+ * `vite-plus`; the hooks resolve them from here, because the user's project usually
344
+ * does not have it.
345
+ */
346
+ function runtimeHelperSpecifier(specifier) {
347
+ return specifier.startsWith(OXC_NODE_HELPERS) ? RUNTIME_HELPERS + specifier.slice(OXC_NODE_HELPERS.length) : void 0;
348
+ }
349
+ /** URL that runtime helper imports resolve from: this package. */
350
+ const HELPERS_PARENT_URL = require("url").pathToFileURL(__filename).href;
351
+ /**
352
+ * CommonJS output (a file without `import`/`export`) loads helpers with `require()`,
353
+ * which never reaches the `module.register()` hooks, while `registerHooks()` hands it
354
+ * to Node.js' CommonJS resolution. Both go through `Module._resolveFilename`, so this
355
+ * wraps it to resolve the helpers from this package, as upstream's `register.mjs` does.
356
+ * The mapped specifier is not a helper specifier, so resolving it falls through.
357
+ */
358
+ function routeHelperRequires(Module) {
359
+ const resolveFilename = Module._resolveFilename;
360
+ const requireFromHere = (0, node_module.createRequire)(HELPERS_PARENT_URL);
361
+ Module._resolveFilename = function(request, parent, isMain, options) {
362
+ const helper = runtimeHelperSpecifier(request);
363
+ return helper ? requireFromHere.resolve(helper) : resolveFilename.call(this, request, parent, isMain, options);
364
+ };
365
+ }
366
+ /**
367
+ * The first line of oxc-node's error for `require()` of an ES module with top-level
368
+ * await, worded as Node.js words it.
369
+ */
370
+ const REQUIRE_ASYNC_MODULE_MESSAGE = "require() cannot be used on an ESM graph with top-level await. Use import() instead.";
371
+ /**
372
+ * Give oxc-node's `require()`-with-top-level-await error the code Node.js uses, which
373
+ * code catches to fall back to `import()`; the binding can only report `GenericFailure`.
374
+ * Mirrors upstream's `register.mjs` (oxc-project/oxc-node#842).
375
+ */
376
+ function withRequireAsyncModuleCode(error) {
377
+ if (error instanceof Error && error.message.startsWith(REQUIRE_ASYNC_MODULE_MESSAGE)) error.code = "ERR_REQUIRE_ASYNC_MODULE";
378
+ return error;
379
+ }
380
+ /**
381
+ * Whether this request comes from `require()`. Only `module.registerHooks()` shows
382
+ * `require()` to the hooks; those requests stay on Node.js' CommonJS resolution and
383
+ * the `pirates` hook. A CommonJS context never carries `importAttributes`.
384
+ */
385
+ function isCommonJsRequire(context) {
386
+ return context?.importAttributes === void 0;
387
+ }
388
+ /**
389
+ * The resolve hook for both hook paths: `require()` stays on Node.js' resolution, where
390
+ * `routeHelperRequires` maps runtime helpers (it resolves from the requiring file and
391
+ * ignores a `parentURL`), runtime helper imports resolve from this package, and
392
+ * everything else goes through oxc-node.
393
+ */
394
+ function resolveWithOxcNode(oxcNode, specifier, context, nextResolve) {
395
+ if (isCommonJsRequire(context)) return nextResolve(specifier, context);
396
+ const helper = runtimeHelperSpecifier(specifier);
397
+ if (helper) return nextResolve(helper, {
398
+ ...context,
399
+ parentURL: HELPERS_PARENT_URL
400
+ });
401
+ return oxcNode.createResolve(specifier, context, nextResolve);
402
+ }
403
+ // src/script-preload.ts
404
+ if (!isSupportedNodeVersion(process.versions.node)) {
405
+ process.stderr.write(`error: Running scripts with vpx requires Node.js ${SUPPORTED_NODE_RANGE} (current: ${process.version})\n`);
406
+ process.exit(1);
407
+ }
408
+ if (node_worker_threads.isMainThread) installSignalAck();
409
+ const oxcNode = loadOxcNode();
410
+ const watch = threadWatchSink();
411
+ if (watch) oxcNode.enableWatchReport();
412
+ oxcNode.setTsconfigPath(process.env.VP_SCRIPT_TSCONFIG);
413
+ oxcNode.setTransformDeps("typescript");
414
+ (0, node_module.setSourceMapsSupport)(true, {
415
+ nodeModules: true,
416
+ generatedCode: true
417
+ });
418
+ routeHelperRequires(node_module.default);
419
+ const EXTENSIONS = [
420
+ ".js",
421
+ ".jsx",
422
+ ".ts",
423
+ ".tsx",
424
+ ".mjs",
425
+ ".mts",
426
+ ".cjs",
427
+ ".cts",
428
+ ".es6",
429
+ ".es"
430
+ ];
431
+ const NODE_MODULES = `${node_path.default.sep}node_modules${node_path.default.sep}`;
432
+ const SOURCEMAP_PREFIX = "\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,";
433
+ const transformer = new oxcNode.OxcTransformer(process.cwd(), HELPER_MODULE_NAME);
434
+ (0, import_lib.addHook)((code, filename) => {
435
+ let output;
436
+ try {
437
+ output = transformer.transform(filename, code);
438
+ } catch (error) {
439
+ throw withRequireAsyncModuleCode(error);
440
+ } finally {
441
+ if (watch) flush(watch, oxcNode.takeWatchDependencies);
442
+ }
443
+ const source = output.source;
444
+ const sourceMap = output.sourceMap;
445
+ return sourceMap ? source + SOURCEMAP_PREFIX + Buffer.from(sourceMap, "utf8").toString("base64") : source;
446
+ }, {
447
+ exts: EXTENSIONS,
448
+ ignoreNodeModules: false,
449
+ matcher: (filename) => !filename.includes(NODE_MODULES) || oxcNode.transformsDep(filename)
450
+ });
451
+ const resolve = (specifier, context, nextResolve) => resolveWithOxcNode(oxcNode, specifier, context, nextResolve);
452
+ const load = (url, context, nextLoad) => {
453
+ if (isCommonJsRequire(context)) return nextLoad(url, context);
454
+ const result = oxcNode.load(url, context, nextLoad, HELPER_MODULE_NAME);
455
+ if (result.format === "commonjs" && result.source == null) return {
456
+ format: "commonjs",
457
+ source: null,
458
+ responseURL: result.responseURL ?? url
459
+ };
460
+ return result;
461
+ };
462
+ if (canRegisterSyncHooks(process.versions.node)) (0, node_module.registerHooks)(watch ? {
463
+ resolve: withFlush(resolve, watch, oxcNode.takeWatchDependencies),
464
+ load: withFlush(load, watch, oxcNode.takeWatchDependencies)
465
+ } : {
466
+ resolve,
467
+ load
468
+ });
@@ -0,0 +1 @@
1
+ export {}
@@ -0,0 +1,22 @@
1
+ import { a as threadWatchSink, n as canRegisterSyncHooks, o as createRelay, r as loadOxcNode } from "./script-hooks-9Fof5UMY.js";
2
+ import * as NodeModule from "node:module";
3
+ // src/script-register.ts
4
+ /**
5
+ * `--import` entry for `vpx <script>`; `script-preload.ts` (the `--require` entry) runs
6
+ * first and does the rest.
7
+ *
8
+ * Where `canRegisterSyncHooks` rules out the in-thread hooks, it registers the off-thread
9
+ * ESM hooks through `module.register()`, which Node.js 22 cannot run from a `--require`.
10
+ * On every version, an `--import` makes Node.js run the entry point through the ESM
11
+ * loader, where the hooks decide each file's module format.
12
+ */
13
+ const { register } = NodeModule;
14
+ if (!canRegisterSyncHooks(process.versions.node)) {
15
+ const watch = threadWatchSink();
16
+ const watchPort = watch ? createRelay(watch, loadOxcNode().takeWatchDependencies) : void 0;
17
+ register(new URL("./script-esm-hooks.js", import.meta.url), {
18
+ data: { watchPort },
19
+ transferList: watchPort ? [watchPort] : []
20
+ });
21
+ }
22
+ export {};
@@ -0,0 +1 @@
1
+ export {}