vite 8.2.2 → 8.3.0-beta.1

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/bin/vite.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { performance } from 'node:perf_hooks'
3
2
  import module from 'node:module'
3
+ import { performance } from 'node:perf_hooks'
4
4
 
5
5
  if (!import.meta.url.includes('node_modules')) {
6
6
  if (!process.env.DEBUG_DISABLE_SOURCE_MAP) {
@@ -20,7 +20,9 @@ const debugIndex = process.argv.findIndex((arg) => /^(?:-d|--debug)$/.test(arg))
20
20
  const filterIndex = process.argv.findIndex((arg) =>
21
21
  /^(?:-f|--filter)$/.test(arg),
22
22
  )
23
- const profileIndex = process.argv.indexOf('--profile')
23
+ const profileIndex = process.argv.findIndex(
24
+ (arg) => arg === '--profile' || arg.startsWith('--profile='),
25
+ )
24
26
 
25
27
  if (debugIndex > 0) {
26
28
  let value = process.argv[debugIndex + 1]
@@ -63,10 +65,19 @@ function start() {
63
65
  }
64
66
 
65
67
  if (profileIndex > 0) {
66
- process.argv.splice(profileIndex, 1)
67
- const next = process.argv[profileIndex]
68
- if (next && next[0] !== '-') {
69
- process.argv.splice(profileIndex, 1)
68
+ const [profileArg] = process.argv.splice(profileIndex, 1)
69
+ // `--profile [name]` writes the profile to `<name>.cpuprofile`. The value is
70
+ // optional and consumed like cac does for other `[optional]` value flags.
71
+ let profileName = profileArg.slice('--profile='.length)
72
+ if (!profileName) {
73
+ const next = process.argv[profileIndex]
74
+ if (next && next[0] !== '-') {
75
+ process.argv.splice(profileIndex, 1)
76
+ profileName = next
77
+ }
78
+ }
79
+ if (profileName) {
80
+ global.__vite_profile_name = profileName
70
81
  }
71
82
  const inspector = await import('node:inspector').then((r) => r.default)
72
83
  const session = (global.__vite_profile_session = new inspector.Session())
@@ -8,7 +8,7 @@ let nanoid = (size = 21) => {
8
8
  return id;
9
9
  };
10
10
  //#endregion
11
- //#region ../../node_modules/.pnpm/rolldown@1.2.4/node_modules/rolldown/dist/experimental-runtime-base.mjs
11
+ //#region ../../node_modules/.pnpm/rolldown@1.2.6/node_modules/rolldown/dist/experimental-runtime-base.mjs
12
12
  var __create = Object.create;
13
13
  var __defProp = Object.defineProperty;
14
14
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -41,7 +41,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
41
41
  }) : target, mod));
42
42
  var __toCommonJS = (mod) => __hasOwnProp.call(mod, "module.exports") ? mod["module.exports"] : __copyProps(__defProp({}, "__esModule", { value: true }), mod);
43
43
  //#endregion
44
- //#region \0@oxc-project+runtime@0.144.0/helpers/esm/typeof.js
44
+ //#region \0@oxc-project+runtime@0.147.0/helpers/esm/typeof.js
45
45
  function _typeof(o) {
46
46
  "@babel/helpers - typeof";
47
47
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -51,7 +51,7 @@ function _typeof(o) {
51
51
  }, _typeof(o);
52
52
  }
53
53
  //#endregion
54
- //#region \0@oxc-project+runtime@0.144.0/helpers/esm/toPrimitive.js
54
+ //#region \0@oxc-project+runtime@0.147.0/helpers/esm/toPrimitive.js
55
55
  function toPrimitive(t, r) {
56
56
  if ("object" != _typeof(t) || !t) return t;
57
57
  var e = t[Symbol.toPrimitive];
@@ -63,13 +63,13 @@ function toPrimitive(t, r) {
63
63
  return ("string" === r ? String : Number)(t);
64
64
  }
65
65
  //#endregion
66
- //#region \0@oxc-project+runtime@0.144.0/helpers/esm/toPropertyKey.js
66
+ //#region \0@oxc-project+runtime@0.147.0/helpers/esm/toPropertyKey.js
67
67
  function toPropertyKey(t) {
68
68
  var i = toPrimitive(t, "string");
69
69
  return "symbol" == _typeof(i) ? i : i + "";
70
70
  }
71
71
  //#endregion
72
- //#region \0@oxc-project+runtime@0.144.0/helpers/esm/defineProperty.js
72
+ //#region \0@oxc-project+runtime@0.147.0/helpers/esm/defineProperty.js
73
73
  function _defineProperty(e, r, t) {
74
74
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
75
75
  value: t,
@@ -79,7 +79,7 @@ function _defineProperty(e, r, t) {
79
79
  }) : e[r] = t, e;
80
80
  }
81
81
  //#endregion
82
- //#region ../../node_modules/.pnpm/rolldown@1.2.4/node_modules/rolldown/dist/experimental-runtime.mjs
82
+ //#region ../../node_modules/.pnpm/rolldown@1.2.6/node_modules/rolldown/dist/experimental-runtime.mjs
83
83
  var Module = class {
84
84
  /**
85
85
  * @param {string} id
@@ -287,9 +287,9 @@ var DevRuntime = class {
287
287
  }
288
288
  /**
289
289
  * @param {string} id
290
- * @param {{ exports: any }} exportsHolder
290
+ * @param {{ exports: any }} [exportsHolder]
291
291
  */
292
- registerModule(id, exportsHolder) {
292
+ registerModule(id, exportsHolder = { exports: {} }) {
293
293
  const module = new Module(id);
294
294
  module.exportsHolder = exportsHolder;
295
295
  this.moduleCache.set(id, module);
@@ -632,14 +632,14 @@ var BundledDevHMRClient = class extends HMRClient {
632
632
  if (importerIndex > -1) {
633
633
  const importChain = [
634
634
  importer,
635
- ...[...currentChain].reverse(),
635
+ ...currentChain.toReversed(),
636
636
  ...nodeChain.slice(importerIndex, -1).reverse()
637
637
  ];
638
638
  this.logger.debug(`circular imports detected: ${importChain.join(" -> ")}`);
639
639
  return true;
640
640
  }
641
641
  if (!currentChain.includes(importer)) {
642
- const result = this.isNodeWithinCircularImports(importer, nodeChain, currentChain.concat(importer), traversedModules);
642
+ const result = this.isNodeWithinCircularImports(importer, nodeChain, [...currentChain, importer], traversedModules);
643
643
  if (result) return result;
644
644
  }
645
645
  }
@@ -782,9 +782,33 @@ var BundledDevHMRContext = class extends HMRContext {
782
782
  };
783
783
  //#endregion
784
784
  //#region src/shared/constants.ts
785
+ /**
786
+ * Prefix for resolved Ids that are not valid browser import specifiers
787
+ */
788
+ const VALID_ID_PREFIX = `/@id/`;
789
+ /**
790
+ * Plugins that use 'virtual modules' (e.g. for helper functions), prefix the
791
+ * module ID with `\0`, a convention from the rollup ecosystem.
792
+ * This prevents other plugins from trying to process the id (like node resolution),
793
+ * and core features like sourcemaps can use this info to differentiate between
794
+ * virtual modules and regular files.
795
+ * `\0` is not a permitted char in import URLs so we have to replace them during
796
+ * import analysis. The id will be decoded back before entering the plugins pipeline.
797
+ * These encoded virtual ids are also prefixed by the VALID_ID_PREFIX, so virtual
798
+ * modules in the browser end up encoded as `/@id/__x00__{id}`
799
+ */
800
+ const NULL_BYTE_PLACEHOLDER = `__x00__`;
785
801
  let SOURCEMAPPING_URL = "sourceMa";
786
802
  SOURCEMAPPING_URL += "ppingURL";
787
803
  typeof process !== "undefined" && process.platform;
804
+ /**
805
+ * Prepend `/@id/` and replace null byte so the id is URL-safe.
806
+ * This is prepended to resolved ids that are not valid browser
807
+ * import specifiers by the importAnalysis plugin.
808
+ */
809
+ function wrapId(id) {
810
+ return id.startsWith(VALID_ID_PREFIX) ? id : VALID_ID_PREFIX + id.replace("\0", NULL_BYTE_PLACEHOLDER);
811
+ }
788
812
  (async function() {}).constructor;
789
813
  function promiseWithResolvers() {
790
814
  let resolve;
@@ -1002,39 +1026,6 @@ const createWebSocketModuleRunnerTransport = (options) => {
1002
1026
  };
1003
1027
  };
1004
1028
  //#endregion
1005
- //#region src/shared/hmrHandler.ts
1006
- function createHMRHandler(handler) {
1007
- const queue = new Queue();
1008
- return (payload) => queue.enqueue(() => handler(payload));
1009
- }
1010
- var Queue = class {
1011
- constructor() {
1012
- _defineProperty(this, "queue", []);
1013
- _defineProperty(this, "pending", false);
1014
- }
1015
- enqueue(promise) {
1016
- return new Promise((resolve, reject) => {
1017
- this.queue.push({
1018
- promise,
1019
- resolve,
1020
- reject
1021
- });
1022
- this.dequeue();
1023
- });
1024
- }
1025
- dequeue() {
1026
- if (this.pending) return false;
1027
- const item = this.queue.shift();
1028
- if (!item) return false;
1029
- this.pending = true;
1030
- item.promise().then(item.resolve).catch(item.reject).finally(() => {
1031
- this.pending = false;
1032
- this.dequeue();
1033
- });
1034
- return true;
1035
- }
1036
- };
1037
- //#endregion
1038
1029
  //#region src/shared/forwardConsole.ts
1039
1030
  function setupForwardConsoleHandler(transport, options, console = globalThis.console) {
1040
1031
  if (!options.enabled) return;
@@ -1163,6 +1154,39 @@ function stringifyConsoleArg(value) {
1163
1154
  }
1164
1155
  }
1165
1156
  //#endregion
1157
+ //#region src/shared/hmrHandler.ts
1158
+ function createHMRHandler(handler) {
1159
+ const queue = new Queue();
1160
+ return (payload) => queue.enqueue(() => handler(payload));
1161
+ }
1162
+ var Queue = class {
1163
+ constructor() {
1164
+ _defineProperty(this, "queue", []);
1165
+ _defineProperty(this, "pending", false);
1166
+ }
1167
+ enqueue(promise) {
1168
+ return new Promise((resolve, reject) => {
1169
+ this.queue.push({
1170
+ promise,
1171
+ resolve,
1172
+ reject
1173
+ });
1174
+ this.dequeue();
1175
+ });
1176
+ }
1177
+ dequeue() {
1178
+ if (this.pending) return false;
1179
+ const item = this.queue.shift();
1180
+ if (!item) return false;
1181
+ this.pending = true;
1182
+ item.promise().then(item.resolve).catch(item.reject).finally(() => {
1183
+ this.pending = false;
1184
+ this.dequeue();
1185
+ });
1186
+ return true;
1187
+ }
1188
+ };
1189
+ //#endregion
1166
1190
  //#region src/client/overlay.ts
1167
1191
  const hmrConfigName = __HMR_CONFIG_NAME__;
1168
1192
  const base$1 = __BASE__ || "/";
@@ -1480,14 +1504,18 @@ const debounceReload = (time) => {
1480
1504
  };
1481
1505
  };
1482
1506
  const pageReload = debounceReload(20);
1507
+ function wrapIdIfNeeded(id) {
1508
+ return id[0] === "." || id[0] === "/" ? id : wrapId(id);
1509
+ }
1483
1510
  const hmrClient = new HMRClient({
1484
1511
  error: (err) => console.error("[vite]", err),
1485
1512
  debug: (...msg) => console.debug("[vite]", ...msg)
1486
1513
  }, transport, async function importUpdatedModule({ acceptedPath, timestamp, explicitImportRequired, isWithinCircularImport }) {
1487
1514
  const [acceptedPathWithoutQuery, query] = acceptedPath.split(`?`);
1515
+ const browserPath = wrapIdIfNeeded(acceptedPathWithoutQuery);
1488
1516
  const importPromise = import(
1489
1517
  /* @vite-ignore */
1490
- base + acceptedPathWithoutQuery.slice(1) + `?${explicitImportRequired ? "import&" : ""}t=${timestamp}${query ? `&${query}` : ""}`
1518
+ base + browserPath.slice(1) + `?${explicitImportRequired ? "import&" : ""}t=${timestamp}${query ? `&${query}` : ""}`
1491
1519
  );
1492
1520
  if (isWithinCircularImport) importPromise.catch(() => {
1493
1521
  console.info(`[hmr] ${acceptedPath} failed to apply HMR as it's within a circular import. Reloading page to reset the execution order. To debug and break the circular import, you can run \`vite --debug hmr\` to log the circular dependency path if a file change triggered it.`);
@@ -1796,6 +1824,13 @@ function injectQuery(url, queryToInject) {
1796
1824
  if (typeof DevRuntime !== "undefined") {
1797
1825
  var _ref;
1798
1826
  class ViteDevRuntime extends DevRuntime {
1827
+ payloadDelivered(filename) {
1828
+ transport.send({
1829
+ type: "custom",
1830
+ event: "vite:bundled-dev:payload-delivered",
1831
+ data: { filename }
1832
+ });
1833
+ }
1799
1834
  createModuleHotContext(moduleId) {
1800
1835
  const ctx = new BundledDevHMRContext(bundledDevHmrClient, moduleId);
1801
1836
  ctx._internal = {