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
@@ -1,4 +1,4 @@
1
- //#region src/migration/report.ts
1
+ // src/migration/report.ts
2
2
  function createMigrationReport() {
3
3
  return {
4
4
  createdViteConfigCount: 0,
@@ -14,6 +14,7 @@ function createMigrationReport() {
14
14
  rewrittenImportErrors: [],
15
15
  eslintMigrated: false,
16
16
  tsupMigrated: false,
17
+ tsxMigrated: false,
17
18
  prettierMigrated: false,
18
19
  nodeVersionFileMigrated: false,
19
20
  setupVpVersionUpdatedFileCount: 0,
@@ -33,5 +34,4 @@ function addManualStep(report, step) {
33
34
  if (!report || report.manualSteps.includes(step)) return;
34
35
  report.manualSteps.push(step);
35
36
  }
36
- //#endregion
37
37
  export { addMigrationWarning as n, createMigrationReport as r, addManualStep as t };
@@ -1,8 +1,9 @@
1
- import { l as VITE_CONFIG_FILES } from "./constants-BW3g7VnD.js";
2
- import { u as withConfigMetadataResolution } from "./define-config-CIlk9scU.js";
1
+ import { l as VITE_CONFIG_FILES } from "./constants-DRUnJ_Dz.js";
2
+ import { u as withConfigMetadataResolution } from "./define-config-ChwJcu5e.js";
3
3
  import path from "node:path";
4
+ import { findMonorepoRoot } from "../binding/index.js";
4
5
  import fs from "node:fs";
5
- //#region src/resolve-vite-config.ts
6
+ // src/resolve-vite-config.ts
6
7
  /**
7
8
  * Find a vite config file by walking up from `startDir` to `stopDir`.
8
9
  * Returns the absolute path of the first config file found, or undefined.
@@ -10,13 +11,15 @@ import fs from "node:fs";
10
11
  function findViteConfigUp(startDir, stopDir) {
11
12
  let dir = path.resolve(startDir);
12
13
  const stop = path.resolve(stopDir);
14
+ const relative = path.relative(stop, dir);
15
+ if (relative === ".." || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) return;
13
16
  while (true) {
14
17
  for (const filename of VITE_CONFIG_FILES) {
15
18
  const filePath = path.join(dir, filename);
16
19
  if (fs.existsSync(filePath)) return filePath;
17
20
  }
18
21
  const parent = path.dirname(dir);
19
- if (parent === dir || !parent.startsWith(stop)) break;
22
+ if (dir === stop || parent === dir) break;
20
23
  dir = parent;
21
24
  }
22
25
  }
@@ -33,31 +36,13 @@ function hasViteConfig(dir) {
33
36
  return findViteConfig(dir) !== void 0;
34
37
  }
35
38
  /**
36
- * Find the workspace root by walking up from `startDir` looking for
37
- * monorepo indicators (pnpm-workspace.yaml, workspaces in package.json, lerna.json).
38
- */
39
- function findWorkspaceRoot(startDir) {
40
- let dir = path.resolve(startDir);
41
- while (true) {
42
- if (fs.existsSync(path.join(dir, "pnpm-workspace.yaml"))) return dir;
43
- const pkgPath = path.join(dir, "package.json");
44
- if (fs.existsSync(pkgPath)) try {
45
- if (JSON.parse(fs.readFileSync(pkgPath, "utf-8")).workspaces) return dir;
46
- } catch {}
47
- if (fs.existsSync(path.join(dir, "lerna.json"))) return dir;
48
- const parent = path.dirname(dir);
49
- if (parent === dir) break;
50
- dir = parent;
51
- }
52
- }
53
- /**
54
39
  * Resolve vite.config.ts and return the config object.
55
40
  */
56
41
  async function resolveViteConfig(cwd, options) {
57
42
  const { resolveConfig } = await import("./index.js");
58
43
  return withConfigMetadataResolution(async () => {
59
44
  if (options?.traverseUp && !hasViteConfig(cwd)) {
60
- const workspaceRoot = findWorkspaceRoot(cwd);
45
+ const workspaceRoot = findMonorepoRoot(cwd);
61
46
  if (workspaceRoot) {
62
47
  const configFile = findViteConfigUp(path.dirname(cwd), workspaceRoot);
63
48
  if (configFile) return resolveConfig({
@@ -86,5 +71,4 @@ async function resolveUniversalViteConfig(err, viteConfigCwd) {
86
71
  throw resolveErr;
87
72
  }
88
73
  }
89
- //#endregion
90
- export { resolveUniversalViteConfig as a, hasViteConfig as i, findViteConfigUp as n, resolveViteConfig as o, findWorkspaceRoot as r, findViteConfig as t };
74
+ export { resolveViteConfig as a, resolveUniversalViteConfig as i, findViteConfigUp as n, hasViteConfig as r, findViteConfig as t };
@@ -0,0 +1 @@
1
+ export { i as resolveUniversalViteConfig } from "./resolve-vite-config-Dn5896A4.js";
@@ -1,12 +1,12 @@
1
1
  import { createRequire } from "node:module";
2
- //#region \0rolldown/runtime.js
2
+ // \0rolldown/runtime.js
3
3
  var __create = Object.create;
4
4
  var __defProp = Object.defineProperty;
5
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
7
  var __getProtoOf = Object.getPrototypeOf;
8
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
9
+ var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod, mod.exports), cb = null), mod.exports);
10
10
  var __copyProps = (to, from, except, desc) => {
11
11
  if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
12
12
  key = keys[i];
@@ -22,5 +22,4 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
22
22
  enumerable: true
23
23
  }) : target, mod));
24
24
  var __require = /* #__PURE__ */ (() => createRequire(import.meta.url))();
25
- //#endregion
26
25
  export { __require as n, __toESM as r, __commonJSMin as t };
@@ -0,0 +1,8 @@
1
+ import { InitializeHook, LoadHook, ResolveHook } from "node:module";
2
+ import { MessagePort } from "node:worker_threads";
3
+ /** Receives the port `script-register.ts` relays watch reports through. */
4
+ export declare const initialize: InitializeHook<{
5
+ watchPort?: MessagePort;
6
+ } | undefined>;
7
+ export declare const resolve: ResolveHook;
8
+ export declare const load: LoadHook;
@@ -0,0 +1,24 @@
1
+ import { i as resolveWithOxcNode, r as loadOxcNode, s as withFlush, t as HELPER_MODULE_NAME } from "./script-hooks-9Fof5UMY.js";
2
+ import { MessageChannel, isMainThread } from "node:worker_threads";
3
+ // src/script-esm-hooks.ts
4
+ const oxcNode = loadOxcNode();
5
+ if (!isMainThread) new MessageChannel().port1.ref();
6
+ const resolveHook = (specifier, context, nextResolve) => resolveWithOxcNode(oxcNode, specifier, context, nextResolve);
7
+ const loadHook = (url, context, nextLoad) => oxcNode.load(url, context, nextLoad, HELPER_MODULE_NAME);
8
+ /** Under watch mode, the hooks wrapped to report what each call read or looked for. */
9
+ let watchHooks;
10
+ /** Receives the port `script-register.ts` relays watch reports through. */
11
+ const initialize = (data) => {
12
+ const port = data?.watchPort;
13
+ if (port) {
14
+ port.unref();
15
+ const sink = (message) => port.postMessage(message);
16
+ watchHooks = {
17
+ resolve: withFlush(resolveHook, sink, oxcNode.takeWatchDependencies),
18
+ load: withFlush(loadHook, sink, oxcNode.takeWatchDependencies)
19
+ };
20
+ }
21
+ };
22
+ const resolve = (specifier, context, nextResolve) => (watchHooks?.resolve ?? resolveHook)(specifier, context, nextResolve);
23
+ const load = (url, context, nextLoad) => (watchHooks?.load ?? loadHook)(url, context, nextLoad);
24
+ export { initialize, load, resolve };
@@ -0,0 +1,176 @@
1
+ import { createRequire } from "node:module";
2
+ import { MessageChannel, isMainThread, receiveMessageOnPort } from "node:worker_threads";
3
+ // ../../oxc-node/packages/core/watch-report.mjs
4
+ const WATCH_CHANNEL = "@oxc-node/core:watch-deps";
5
+ /**
6
+ * Where this thread sends its reports, or `null` when nobody is watching. With
7
+ * `null` nothing is wrapped, opened or listened to.
8
+ *
9
+ * @returns {((message: { "watch:import": string[] }) => void) | null}
10
+ */
11
+ function watchSink() {
12
+ if (!process.env.WATCH_REPORT_DEPENDENCIES) return null;
13
+ if (isMainThread) {
14
+ if (typeof process.send !== "function") return null;
15
+ const seen = /* @__PURE__ */ new Set();
16
+ const send = (message) => {
17
+ const url = message?.["watch:import"]?.[0];
18
+ if (typeof url !== "string" || seen.has(url) || !process.connected) return;
19
+ seen.add(url);
20
+ try {
21
+ process.send(message, () => {});
22
+ } catch {}
23
+ };
24
+ const channel = new BroadcastChannel(WATCH_CHANNEL);
25
+ channel.onmessage = (event) => send(event.data);
26
+ channel.unref();
27
+ return send;
28
+ }
29
+ const channel = new BroadcastChannel(WATCH_CHANNEL);
30
+ channel.unref();
31
+ return (message) => channel.postMessage(message);
32
+ }
33
+ /**
34
+ * Send what the binding recorded, one URL per message: the watch parent reads a
35
+ * whole array in one `try`, so one bad entry would drop the rest. `oxnode watch`
36
+ * reads the `oxc-node` key to tell these from what Node.js reports (a tsconfig
37
+ * in `node_modules` counts, an imported file there does not); Node.js ignores it.
38
+ *
39
+ * @param {(message: { "watch:import": string[], "oxc-node": true }) => void} sink
40
+ * @param {() => string[]} take the binding's `takeWatchDependencies`
41
+ */
42
+ function flush(sink, take) {
43
+ for (const url of take()) sink({
44
+ "watch:import": [url],
45
+ "oxc-node": true
46
+ });
47
+ }
48
+ /**
49
+ * `fn`, flushing after each call whether it returns, throws or returns a promise.
50
+ * A failed resolve records its candidates and then throws, which is exactly the
51
+ * case that has to be reported. `sink` and `take` are as for `flush`.
52
+ */
53
+ function withFlush(fn, sink, take) {
54
+ return function(...args) {
55
+ let result;
56
+ try {
57
+ result = fn.apply(this, args);
58
+ } catch (error) {
59
+ flush(sink, take);
60
+ throw error;
61
+ }
62
+ if (result && typeof result.then === "function") return result.then((value) => {
63
+ flush(sink, take);
64
+ return value;
65
+ }, (error) => {
66
+ flush(sink, take);
67
+ throw error;
68
+ });
69
+ flush(sink, take);
70
+ return result;
71
+ };
72
+ }
73
+ /**
74
+ * For `module.register()`: the hooks run on a thread of their own with no
75
+ * `process.send`, so they post into the returned port and the thread that
76
+ * registered them forwards to `sink`. `take` is as for `flush`: what this thread's
77
+ * binding recorded is drained here too, before the process ends.
78
+ */
79
+ function createRelay(sink, take) {
80
+ const { port1, port2 } = new MessageChannel();
81
+ port1.on("message", sink);
82
+ port1.unref();
83
+ const drain = () => {
84
+ let received;
85
+ while (received = receiveMessageOnPort(port1)) sink(received.message);
86
+ flush(sink, take);
87
+ };
88
+ process.on("uncaughtExceptionMonitor", drain);
89
+ process.on("exit", drain);
90
+ return port2;
91
+ }
92
+ // src/script-hooks.ts
93
+ /**
94
+ * Shared pieces of the `vpx <script>` loader (see `script-preload.ts`).
95
+ */
96
+ /**
97
+ * The oxc-node hooks compiled into the Vite+ binding. Required, not imported: importing
98
+ * `index.js` makes a `module.register()` hooks thread translate the whole CommonJS
99
+ * binding for ESM, and `module.register()` waits for that (5-13 ms).
100
+ */
101
+ function loadOxcNode() {
102
+ return createRequire(import.meta.url)("../binding/index.cjs").oxcNode;
103
+ }
104
+ const WATCH_SINK = Symbol.for("vite-plus:script-watch-sink");
105
+ /**
106
+ * Where this thread reports the files watch mode restarts on, or `null` when nobody is
107
+ * watching (see oxc-node's `watchSink()`). It opens a channel, so it runs once per thread:
108
+ * the preload and the `--import` entry are separate bundles and share it here.
109
+ */
110
+ function threadWatchSink() {
111
+ const holder = globalThis;
112
+ if (holder[WATCH_SINK] === void 0) holder[WATCH_SINK] = watchSink();
113
+ return holder[WATCH_SINK];
114
+ }
115
+ /**
116
+ * Whether to use the in-thread `module.registerHooks()` instead of the off-thread
117
+ * `module.register()`, which needs a hooks thread (about twice the startup time) and
118
+ * which Node.js deprecates from 25.9 (DEP0205).
119
+ *
120
+ * The in-thread hooks need two fixes: a sync resolve hook had its `conditions`
121
+ * overridden (nodejs/node#59011, in 22.19 and 24.5), and a sync load hook could not
122
+ * return a null source for CommonJS (nodejs/node#59929, in 22.22.3 and 24.11.1). tsx
123
+ * switches at the same releases. Upstream oxc-node waits for 26.2 for a third fix,
124
+ * nodejs/node#62920 (also in 24.18.0), which only matters when a load hook returns
125
+ * CommonJS source. These hooks return it only for source another hook supplied, so
126
+ * without that fix `require()` inside such a module can fail.
127
+ */
128
+ function canRegisterSyncHooks(version) {
129
+ const [major = 0, minor = 0, patch = 0] = version.split(".").map(Number);
130
+ if (major === 22) return minor > 22 || minor === 22 && patch >= 3;
131
+ if (major === 24) return minor > 11 || minor === 11 && patch >= 1;
132
+ return major >= 26;
133
+ }
134
+ /**
135
+ * The module name oxc-node gives the runtime helpers it injects, passed to its transformer
136
+ * and load hook. Only these hooks emit it, so they redirect only their own helper imports,
137
+ * not `@oxc-node/core/helpers/*` imports that another oxc-node copy produced.
138
+ */
139
+ const HELPER_MODULE_NAME = "vite-plus:oxc-node";
140
+ const OXC_NODE_HELPERS = `${HELPER_MODULE_NAME}/helpers/`;
141
+ const RUNTIME_HELPERS = "@oxc-project/runtime/helpers/";
142
+ /**
143
+ * oxc-node lowers class fields, static blocks, `using`, and legacy decorators to
144
+ * helper imports. The same helpers ship in `@oxc-project/runtime`, a dependency of
145
+ * `vite-plus`; the hooks resolve them from here, because the user's project usually
146
+ * does not have it.
147
+ */
148
+ function runtimeHelperSpecifier(specifier) {
149
+ return specifier.startsWith(OXC_NODE_HELPERS) ? RUNTIME_HELPERS + specifier.slice(OXC_NODE_HELPERS.length) : void 0;
150
+ }
151
+ /** URL that runtime helper imports resolve from: this package. */
152
+ const HELPERS_PARENT_URL = import.meta.url;
153
+ /**
154
+ * Whether this request comes from `require()`. Only `module.registerHooks()` shows
155
+ * `require()` to the hooks; those requests stay on Node.js' CommonJS resolution and
156
+ * the `pirates` hook. A CommonJS context never carries `importAttributes`.
157
+ */
158
+ function isCommonJsRequire(context) {
159
+ return context?.importAttributes === void 0;
160
+ }
161
+ /**
162
+ * The resolve hook for both hook paths: `require()` stays on Node.js' resolution, where
163
+ * `routeHelperRequires` maps runtime helpers (it resolves from the requiring file and
164
+ * ignores a `parentURL`), runtime helper imports resolve from this package, and
165
+ * everything else goes through oxc-node.
166
+ */
167
+ function resolveWithOxcNode(oxcNode, specifier, context, nextResolve) {
168
+ if (isCommonJsRequire(context)) return nextResolve(specifier, context);
169
+ const helper = runtimeHelperSpecifier(specifier);
170
+ if (helper) return nextResolve(helper, {
171
+ ...context,
172
+ parentURL: HELPERS_PARENT_URL
173
+ });
174
+ return oxcNode.createResolve(specifier, context, nextResolve);
175
+ }
176
+ export { threadWatchSink as a, resolveWithOxcNode as i, canRegisterSyncHooks as n, createRelay as o, loadOxcNode as r, withFlush as s, HELPER_MODULE_NAME as t };