vite-plus 1.3.0 → 1.5.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.
- package/AGENTS.md +4 -0
- package/LICENSE +1 -878
- package/README.md +1 -1
- package/bin/vpx +9 -0
- package/binding/index.cjs +59 -54
- package/binding/index.d.cts +159 -2
- package/dist/{agent-97KmGCyL.js → agent-DkQD3xqe.js} +5 -7
- package/dist/bin.js +35 -34
- package/dist/{cli-parse-DHE8NrBU.js → cli-parse-aeUeFDlC.js} +2 -3
- package/dist/command-TjS_6y9O.js +1 -0
- package/dist/{command-CdMBoZFD.js → command-rY79K5NI.js} +28 -30
- package/dist/{comparison-CmVirWIW-DUGaiYqF.js → comparison-CmVirWIW-UlEf2maz.js} +1 -2
- package/dist/config/bin.js +8 -10
- package/dist/{constants-DR55DpRm.js → constants-D2P2aVKb.js} +8 -6
- package/dist/create/bin.d.ts +4 -8
- package/dist/create/bin.js +151 -120
- package/dist/{define-config-Bexdd6RZ.d.ts → define-config-BrvHRi-G.d.ts} +31 -13
- package/dist/{define-config-BxDc_9BK.cjs → define-config-CwtQqYC1.cjs} +41 -14
- package/dist/{define-config-CvE5pHqB.js → define-config-wR57OZG_.js} +34 -12
- package/dist/define-config.cjs +2 -1
- package/dist/define-config.d.ts +2 -2
- package/dist/define-config.js +1 -1
- package/dist/{dist-DIpm7mot.js → dist-Bs0SObNC.js} +73 -145
- package/dist/{dist-Cqz8OtiO.js → dist-CdkMvIiQ.js} +11 -5
- package/dist/dist-zDZV5eEc.js +3 -0
- package/dist/{documentation-DqcZSthV.js → documentation-cv_y0Auv.js} +1 -2
- package/dist/{editor-CtJGQP7C.js → editor-aOy1T15H.js} +2735 -5072
- package/dist/{help-BmKpeOP9.js → help-B03t_iQ4.js} +1 -2
- package/dist/hooks/bin.js +4 -5
- package/dist/{hooks-DhwsWb46.js → hooks-w_e2whkQ.js} +45 -25
- package/dist/index.cjs +5 -5
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/{json-JP24qHUF.js → json-kl84kDyH.js} +9 -18
- package/dist/lint-plugins.cjs +1 -1
- package/dist/migration/bin.js +1782 -256
- package/dist/migration/compat/worker.js +4 -6
- package/dist/{oxlint-plugin-config-BIzrO2y2.js → oxlint-plugin-config-CHsI_zKo.js} +3 -4
- package/dist/oxlint-plugin.d.ts +0 -2
- package/dist/oxlint-plugin.js +33 -9
- package/dist/{pack-BK38MLVZ.d.ts → pack-ARPFMefW.d.ts} +0 -2
- package/dist/pack-bin.d.ts +1 -3
- package/dist/pack-bin.js +4 -5
- package/dist/pack.d.ts +1 -1
- package/dist/{package-CQDXTm6j.js → package-DfFo6-E-.js} +10 -95
- package/dist/{package-overrides-D1RcXSFl.js → package-overrides-Ci8GXouY.js} +5 -8
- package/dist/picomatch-DEUoj81q.js +1916 -0
- package/dist/{prompts-1xNz_ne0.js → prompts-C7DI63WP.js} +30 -50
- package/dist/{protocol-D99W10Qi.js → protocol-CkNmY-Mr.js} +1 -2
- package/dist/register.d.ts +1 -0
- package/dist/register.js +12 -0
- package/dist/{report-NhQk8VHb.js → report-BEdpIQvC.js} +4 -2
- package/dist/resolve-vite-config-33bzSaeT.js +1 -0
- package/dist/{resolve-vite-config-BVr1SUNg.js → resolve-vite-config-Cx3cnVVI.js} +9 -25
- package/dist/{rolldown-runtime-kJ_i4yPo.js → rolldown-runtime-DegdyBIC.js} +1 -2
- package/dist/script-esm-hooks.d.ts +11 -0
- package/dist/script-esm-hooks.js +27 -0
- package/dist/script-hooks-9Fof5UMY.js +176 -0
- package/dist/script-preload.cjs +491 -0
- package/dist/script-register.d.ts +1 -0
- package/dist/script-register.js +27 -0
- package/dist/script-watch.d.ts +1 -0
- package/dist/script-watch.js +2002 -0
- package/dist/staged/bin.js +53 -2011
- package/dist/sync-versions/bin.js +26 -48
- package/dist/sync-versions/bin.mjs +109 -217
- package/dist/{terminal-MKGAuy-p.js → terminal-BcuPUy-j.js} +1 -2
- package/dist/toolchain.js +38 -12
- package/dist/toolchain.json +38 -12
- package/dist/{tsconfig-zWgHiQ3X.js → tsconfig-BE3Wj9OX.js} +1 -1
- package/dist/{tsconfig-BZu7kl-x.js → tsconfig-shNmmCE_.js} +8 -10
- package/dist/version.d.ts +1 -3
- package/dist/version.js +5 -6
- package/dist/versions.js +7 -7
- package/dist/{vitest-ecosystem-BU0AqZq-.js → vitest-ecosystem-BeEYz-qF.js} +1 -2
- package/dist/{vitest-v5-entry-points-DthU1e_O.js → vitest-v5-entry-points-NyJsFeux.js} +1 -2
- package/dist/vpx-bin.d.ts +1 -0
- package/dist/vpx-bin.js +232 -0
- package/dist/vpx-script-EXgV5QOf.js +434 -0
- package/docs/config/check.md +2 -0
- package/docs/config/fmt.md +1 -1
- package/docs/config/lint.md +1 -1
- package/docs/config/run.md +10 -2
- package/docs/config/staged.md +1 -1
- package/docs/guide/check.md +6 -1
- package/docs/guide/ci.md +13 -3
- package/docs/guide/create.md +1 -1
- package/docs/guide/env.md +11 -4
- package/docs/guide/global-cli.md +59 -3
- package/docs/guide/homebrew.md +127 -0
- package/docs/guide/ide-integration.md +1 -3
- package/docs/guide/implode.md +5 -3
- package/docs/guide/local-cli.md +21 -0
- package/docs/guide/migrate-rules.md +120 -18
- package/docs/guide/migrate.md +9 -9
- package/docs/guide/package-management.md +1 -1
- package/docs/guide/run.md +23 -1
- package/docs/guide/test.md +1 -1
- package/docs/guide/troubleshooting.md +1 -1
- package/docs/guide/upgrade.md +12 -6
- package/docs/guide/vitest-v5.md +2 -2
- package/docs/guide/vpx.md +210 -9
- package/package.json +43 -34
- package/dist/command-DVTILtS-.js +0 -1
- package/dist/dist-Dhu07wmN.js +0 -3
- package/dist/resolve-vite-config-7WDtXO4G.js +0 -1
|
@@ -0,0 +1,491 @@
|
|
|
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
|
+
const SCRIPT_CONFIG = Symbol.for("vite-plus:script-config");
|
|
296
|
+
/**
|
|
297
|
+
* Capture this JavaScript thread's configuration before its first resolve. Worker
|
|
298
|
+
* environments can differ from the native process environment, including clearing
|
|
299
|
+
* the parent's variables. Both emitted preload entries share this selection.
|
|
300
|
+
*/
|
|
301
|
+
function threadScriptConfig() {
|
|
302
|
+
const holder = globalThis;
|
|
303
|
+
if (holder[SCRIPT_CONFIG] === void 0) {
|
|
304
|
+
const source = [
|
|
305
|
+
"VP_SCRIPT_TSCONFIG",
|
|
306
|
+
"TSX_TSCONFIG_PATH",
|
|
307
|
+
"TS_NODE_PROJECT",
|
|
308
|
+
"OXC_TSCONFIG_PATH"
|
|
309
|
+
].find((name) => process.env[name]);
|
|
310
|
+
holder[SCRIPT_CONFIG] = {
|
|
311
|
+
path: source ? process.env[source] : void 0,
|
|
312
|
+
source: source === "TS_NODE_PROJECT" || source === "OXC_TSCONFIG_PATH" ? source : void 0
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
return holder[SCRIPT_CONFIG];
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Where this thread reports the files watch mode restarts on, or `null` when nobody is
|
|
319
|
+
* watching (see oxc-node's `watchSink()`). It opens a channel, so it runs once per thread:
|
|
320
|
+
* the preload and the `--import` entry are separate bundles and share it here.
|
|
321
|
+
*/
|
|
322
|
+
function threadWatchSink() {
|
|
323
|
+
const holder = globalThis;
|
|
324
|
+
if (holder[WATCH_SINK] === void 0) holder[WATCH_SINK] = watchSink();
|
|
325
|
+
return holder[WATCH_SINK];
|
|
326
|
+
}
|
|
327
|
+
/** Must match `engines.node` in package.json; `__tests__/vpx-script.spec.ts` checks it. */
|
|
328
|
+
const SUPPORTED_NODE_RANGE = "^22.18.0 || ^24.11.0 || >=26.0.0";
|
|
329
|
+
function isSupportedNodeVersion(version) {
|
|
330
|
+
const [major = 0, minor = 0] = version.split(".").map(Number);
|
|
331
|
+
if (major === 22) return minor >= 18;
|
|
332
|
+
if (major === 24) return minor >= 11;
|
|
333
|
+
return major >= 26;
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Whether to use the in-thread `module.registerHooks()` instead of the off-thread
|
|
337
|
+
* `module.register()`, which needs a hooks thread (about twice the startup time) and
|
|
338
|
+
* which Node.js deprecates from 25.9 (DEP0205).
|
|
339
|
+
*
|
|
340
|
+
* The in-thread hooks need two fixes: a sync resolve hook had its `conditions`
|
|
341
|
+
* overridden (nodejs/node#59011, in 22.19 and 24.5), and a sync load hook could not
|
|
342
|
+
* return a null source for CommonJS (nodejs/node#59929, in 22.22.3 and 24.11.1). tsx
|
|
343
|
+
* switches at the same releases. Upstream oxc-node waits for 26.2 for a third fix,
|
|
344
|
+
* nodejs/node#62920 (also in 24.18.0), which only matters when a load hook returns
|
|
345
|
+
* CommonJS source. These hooks return it only for source another hook supplied, so
|
|
346
|
+
* without that fix `require()` inside such a module can fail.
|
|
347
|
+
*/
|
|
348
|
+
function canRegisterSyncHooks(version) {
|
|
349
|
+
const [major = 0, minor = 0, patch = 0] = version.split(".").map(Number);
|
|
350
|
+
if (major === 22) return minor > 22 || minor === 22 && patch >= 3;
|
|
351
|
+
if (major === 24) return minor > 11 || minor === 11 && patch >= 1;
|
|
352
|
+
return major >= 26;
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* The module name oxc-node gives the runtime helpers it injects, passed to its transformer
|
|
356
|
+
* and load hook. Only these hooks emit it, so they redirect only their own helper imports,
|
|
357
|
+
* not `@oxc-node/core/helpers/*` imports that another oxc-node copy produced.
|
|
358
|
+
*/
|
|
359
|
+
const HELPER_MODULE_NAME = "vite-plus:oxc-node";
|
|
360
|
+
const OXC_NODE_HELPERS = `${HELPER_MODULE_NAME}/helpers/`;
|
|
361
|
+
const RUNTIME_HELPERS = "@oxc-project/runtime/helpers/";
|
|
362
|
+
/**
|
|
363
|
+
* oxc-node lowers class fields, static blocks, `using`, and legacy decorators to
|
|
364
|
+
* helper imports. The same helpers ship in `@oxc-project/runtime`, a dependency of
|
|
365
|
+
* `vite-plus`; the hooks resolve them from here, because the user's project usually
|
|
366
|
+
* does not have it.
|
|
367
|
+
*/
|
|
368
|
+
function runtimeHelperSpecifier(specifier) {
|
|
369
|
+
return specifier.startsWith(OXC_NODE_HELPERS) ? RUNTIME_HELPERS + specifier.slice(OXC_NODE_HELPERS.length) : void 0;
|
|
370
|
+
}
|
|
371
|
+
/** URL that runtime helper imports resolve from: this package. */
|
|
372
|
+
const HELPERS_PARENT_URL = require("url").pathToFileURL(__filename).href;
|
|
373
|
+
/**
|
|
374
|
+
* CommonJS output (a file without `import`/`export`) loads helpers with `require()`,
|
|
375
|
+
* which never reaches the `module.register()` hooks, while `registerHooks()` hands it
|
|
376
|
+
* to Node.js' CommonJS resolution. Both go through `Module._resolveFilename`, so this
|
|
377
|
+
* wraps it to resolve the helpers from this package, as upstream's `register.mjs` does.
|
|
378
|
+
* The mapped specifier is not a helper specifier, so resolving it falls through.
|
|
379
|
+
*/
|
|
380
|
+
function routeHelperRequires(Module) {
|
|
381
|
+
const resolveFilename = Module._resolveFilename;
|
|
382
|
+
const requireFromHere = (0, node_module.createRequire)(HELPERS_PARENT_URL);
|
|
383
|
+
Module._resolveFilename = function(request, parent, isMain, options) {
|
|
384
|
+
const helper = runtimeHelperSpecifier(request);
|
|
385
|
+
return helper ? requireFromHere.resolve(helper) : resolveFilename.call(this, request, parent, isMain, options);
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* The first line of oxc-node's error for `require()` of an ES module with top-level
|
|
390
|
+
* await, worded as Node.js words it.
|
|
391
|
+
*/
|
|
392
|
+
const REQUIRE_ASYNC_MODULE_MESSAGE = "require() cannot be used on an ESM graph with top-level await. Use import() instead.";
|
|
393
|
+
/**
|
|
394
|
+
* Give oxc-node's `require()`-with-top-level-await error the code Node.js uses, which
|
|
395
|
+
* code catches to fall back to `import()`; the binding can only report `GenericFailure`.
|
|
396
|
+
* Mirrors upstream's `register.mjs` (oxc-project/oxc-node#842).
|
|
397
|
+
*/
|
|
398
|
+
function withRequireAsyncModuleCode(error) {
|
|
399
|
+
if (error instanceof Error && error.message.startsWith(REQUIRE_ASYNC_MODULE_MESSAGE)) error.code = "ERR_REQUIRE_ASYNC_MODULE";
|
|
400
|
+
return error;
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Whether this request comes from `require()`. Only `module.registerHooks()` shows
|
|
404
|
+
* `require()` to the hooks; those requests stay on Node.js' CommonJS resolution and
|
|
405
|
+
* the `pirates` hook. A CommonJS context never carries `importAttributes`.
|
|
406
|
+
*/
|
|
407
|
+
function isCommonJsRequire(context) {
|
|
408
|
+
return context?.importAttributes === void 0;
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* The resolve hook for both hook paths: `require()` stays on Node.js' resolution, where
|
|
412
|
+
* `routeHelperRequires` maps runtime helpers (it resolves from the requiring file and
|
|
413
|
+
* ignores a `parentURL`), runtime helper imports resolve from this package, and
|
|
414
|
+
* everything else goes through oxc-node.
|
|
415
|
+
*/
|
|
416
|
+
function resolveWithOxcNode(oxcNode, specifier, context, nextResolve) {
|
|
417
|
+
if (isCommonJsRequire(context)) return nextResolve(specifier, context);
|
|
418
|
+
const helper = runtimeHelperSpecifier(specifier);
|
|
419
|
+
if (helper) return nextResolve(helper, {
|
|
420
|
+
...context,
|
|
421
|
+
parentURL: HELPERS_PARENT_URL
|
|
422
|
+
});
|
|
423
|
+
return oxcNode.createResolve(specifier, context, nextResolve);
|
|
424
|
+
}
|
|
425
|
+
// src/script-preload.ts
|
|
426
|
+
if (!isSupportedNodeVersion(process.versions.node)) {
|
|
427
|
+
process.stderr.write(`error: Running scripts with vpx requires Node.js ${SUPPORTED_NODE_RANGE} (current: ${process.version})\n`);
|
|
428
|
+
process.exit(1);
|
|
429
|
+
}
|
|
430
|
+
if (node_worker_threads.isMainThread) installSignalAck();
|
|
431
|
+
const oxcNode = loadOxcNode();
|
|
432
|
+
const watch = threadWatchSink();
|
|
433
|
+
if (watch) oxcNode.enableWatchReport();
|
|
434
|
+
const tsconfig = threadScriptConfig();
|
|
435
|
+
oxcNode.initializeLoader(tsconfig.path, tsconfig.source);
|
|
436
|
+
oxcNode.setTransformDeps("typescript");
|
|
437
|
+
(0, node_module.setSourceMapsSupport)(true, {
|
|
438
|
+
nodeModules: true,
|
|
439
|
+
generatedCode: true
|
|
440
|
+
});
|
|
441
|
+
routeHelperRequires(node_module.default);
|
|
442
|
+
const EXTENSIONS = [
|
|
443
|
+
".js",
|
|
444
|
+
".jsx",
|
|
445
|
+
".ts",
|
|
446
|
+
".tsx",
|
|
447
|
+
".mjs",
|
|
448
|
+
".mts",
|
|
449
|
+
".cjs",
|
|
450
|
+
".cts",
|
|
451
|
+
".es6",
|
|
452
|
+
".es"
|
|
453
|
+
];
|
|
454
|
+
const NODE_MODULES = `${node_path.default.sep}node_modules${node_path.default.sep}`;
|
|
455
|
+
const SOURCEMAP_PREFIX = "\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,";
|
|
456
|
+
const transformer = new oxcNode.OxcTransformer(process.cwd(), HELPER_MODULE_NAME);
|
|
457
|
+
(0, import_lib.addHook)((code, filename) => {
|
|
458
|
+
let output;
|
|
459
|
+
try {
|
|
460
|
+
output = transformer.transform(filename, code);
|
|
461
|
+
} catch (error) {
|
|
462
|
+
throw withRequireAsyncModuleCode(error);
|
|
463
|
+
} finally {
|
|
464
|
+
if (watch) flush(watch, oxcNode.takeWatchDependencies);
|
|
465
|
+
}
|
|
466
|
+
const source = output.source;
|
|
467
|
+
const sourceMap = output.sourceMap;
|
|
468
|
+
return sourceMap ? source + SOURCEMAP_PREFIX + Buffer.from(sourceMap, "utf8").toString("base64") : source;
|
|
469
|
+
}, {
|
|
470
|
+
exts: EXTENSIONS,
|
|
471
|
+
ignoreNodeModules: false,
|
|
472
|
+
matcher: (filename) => !filename.includes(NODE_MODULES) || oxcNode.transformsDep(filename)
|
|
473
|
+
});
|
|
474
|
+
const resolve = (specifier, context, nextResolve) => resolveWithOxcNode(oxcNode, specifier, context, nextResolve);
|
|
475
|
+
const load = (url, context, nextLoad) => {
|
|
476
|
+
if (isCommonJsRequire(context)) return nextLoad(url, context);
|
|
477
|
+
const result = oxcNode.load(url, context, nextLoad, HELPER_MODULE_NAME);
|
|
478
|
+
if (result.format === "commonjs" && result.source == null) return {
|
|
479
|
+
format: "commonjs",
|
|
480
|
+
source: null,
|
|
481
|
+
responseURL: result.responseURL ?? url
|
|
482
|
+
};
|
|
483
|
+
return result;
|
|
484
|
+
};
|
|
485
|
+
if (canRegisterSyncHooks(process.versions.node)) (0, node_module.registerHooks)(watch ? {
|
|
486
|
+
resolve: withFlush(resolve, watch, oxcNode.takeWatchDependencies),
|
|
487
|
+
load: withFlush(load, watch, oxcNode.takeWatchDependencies)
|
|
488
|
+
} : {
|
|
489
|
+
resolve,
|
|
490
|
+
load
|
|
491
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
|
@@ -0,0 +1,27 @@
|
|
|
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 oxcNode = loadOxcNode();
|
|
16
|
+
const watch = threadWatchSink();
|
|
17
|
+
const watchPort = watch ? createRelay(watch, oxcNode.takeWatchDependencies) : void 0;
|
|
18
|
+
register(new URL("./script-esm-hooks.js", import.meta.url), {
|
|
19
|
+
data: {
|
|
20
|
+
tsconfig: oxcNode.freezeTsconfig(process.cwd()),
|
|
21
|
+
transformDeps: oxcNode.freezeTransformDeps(),
|
|
22
|
+
watchPort
|
|
23
|
+
},
|
|
24
|
+
transferList: watchPort ? [watchPort] : []
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|