vite 6.0.0-alpha.2 → 6.0.0-alpha.21

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.
@@ -14,17 +14,18 @@ var readline = require('node:readline');
14
14
  var require$$2 = require('os');
15
15
 
16
16
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
17
- const { version: version$2 } = JSON.parse(fs$1.readFileSync(new URL('../../package.json', (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('node-cjs/publicUtils.cjs', document.baseURI).href)))).toString());
17
+ const { version: version$2 } = JSON.parse(
18
+ fs$1.readFileSync(new URL("../../package.json", (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('node-cjs/publicUtils.cjs', document.baseURI).href)))).toString()
19
+ );
18
20
  const VERSION = version$2;
19
- /**
20
- * Prefix for resolved fs paths, since windows paths may not be valid as URLs.
21
- */
22
21
  const FS_PREFIX = `/@fs/`;
23
22
  const VITE_PACKAGE_DIR = path$3.resolve(
24
- // import.meta.url is `dist/node/constants.js` after bundle
25
- node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('node-cjs/publicUtils.cjs', document.baseURI).href))), '../../..');
26
- const CLIENT_ENTRY = path$3.resolve(VITE_PACKAGE_DIR, 'dist/client/client.mjs');
27
- path$3.resolve(VITE_PACKAGE_DIR, 'dist/client/env.mjs');
23
+ // import.meta.url is `dist/node/constants.js` after bundle
24
+ node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('node-cjs/publicUtils.cjs', document.baseURI).href))),
25
+ "../../.."
26
+ );
27
+ const CLIENT_ENTRY = path$3.resolve(VITE_PACKAGE_DIR, "dist/client/client.mjs");
28
+ path$3.resolve(VITE_PACKAGE_DIR, "dist/client/env.mjs");
28
29
  path$3.dirname(CLIENT_ENTRY);
29
30
 
30
31
  const comma = ','.charCodeAt(0);
@@ -37,6 +38,20 @@ for (let i = 0; i < chars.length; i++) {
37
38
  intToChar[i] = c;
38
39
  charToInt[c] = i;
39
40
  }
41
+ function encodeInteger(builder, num, relative) {
42
+ let delta = num - relative;
43
+ delta = delta < 0 ? (-delta << 1) | 1 : delta << 1;
44
+ do {
45
+ let clamped = delta & 0b011111;
46
+ delta >>>= 5;
47
+ if (delta > 0)
48
+ clamped |= 0b100000;
49
+ builder.write(intToChar[clamped]);
50
+ } while (delta > 0);
51
+ return num;
52
+ }
53
+
54
+ const bufLength = 1024 * 16;
40
55
  // Provide a fallback for older environments.
41
56
  const td = typeof TextDecoder !== 'undefined'
42
57
  ? /* #__PURE__ */ new TextDecoder()
@@ -56,80 +71,75 @@ const td = typeof TextDecoder !== 'undefined'
56
71
  return out;
57
72
  },
58
73
  };
74
+ class StringWriter {
75
+ constructor() {
76
+ this.pos = 0;
77
+ this.out = '';
78
+ this.buffer = new Uint8Array(bufLength);
79
+ }
80
+ write(v) {
81
+ const { buffer } = this;
82
+ buffer[this.pos++] = v;
83
+ if (this.pos === bufLength) {
84
+ this.out += td.decode(buffer);
85
+ this.pos = 0;
86
+ }
87
+ }
88
+ flush() {
89
+ const { buffer, out, pos } = this;
90
+ return pos > 0 ? out + td.decode(buffer.subarray(0, pos)) : out;
91
+ }
92
+ }
59
93
  function encode(decoded) {
60
- const state = new Int32Array(5);
61
- const bufLength = 1024 * 16;
62
- const subLength = bufLength - 36;
63
- const buf = new Uint8Array(bufLength);
64
- const sub = buf.subarray(0, subLength);
65
- let pos = 0;
66
- let out = '';
94
+ const writer = new StringWriter();
95
+ let sourcesIndex = 0;
96
+ let sourceLine = 0;
97
+ let sourceColumn = 0;
98
+ let namesIndex = 0;
67
99
  for (let i = 0; i < decoded.length; i++) {
68
100
  const line = decoded[i];
69
- if (i > 0) {
70
- if (pos === bufLength) {
71
- out += td.decode(buf);
72
- pos = 0;
73
- }
74
- buf[pos++] = semicolon;
75
- }
101
+ if (i > 0)
102
+ writer.write(semicolon);
76
103
  if (line.length === 0)
77
104
  continue;
78
- state[0] = 0;
105
+ let genColumn = 0;
79
106
  for (let j = 0; j < line.length; j++) {
80
107
  const segment = line[j];
81
- // We can push up to 5 ints, each int can take at most 7 chars, and we
82
- // may push a comma.
83
- if (pos > subLength) {
84
- out += td.decode(sub);
85
- buf.copyWithin(0, subLength, pos);
86
- pos -= subLength;
87
- }
88
108
  if (j > 0)
89
- buf[pos++] = comma;
90
- pos = encodeInteger(buf, pos, state, segment, 0); // genColumn
109
+ writer.write(comma);
110
+ genColumn = encodeInteger(writer, segment[0], genColumn);
91
111
  if (segment.length === 1)
92
112
  continue;
93
- pos = encodeInteger(buf, pos, state, segment, 1); // sourcesIndex
94
- pos = encodeInteger(buf, pos, state, segment, 2); // sourceLine
95
- pos = encodeInteger(buf, pos, state, segment, 3); // sourceColumn
113
+ sourcesIndex = encodeInteger(writer, segment[1], sourcesIndex);
114
+ sourceLine = encodeInteger(writer, segment[2], sourceLine);
115
+ sourceColumn = encodeInteger(writer, segment[3], sourceColumn);
96
116
  if (segment.length === 4)
97
117
  continue;
98
- pos = encodeInteger(buf, pos, state, segment, 4); // namesIndex
118
+ namesIndex = encodeInteger(writer, segment[4], namesIndex);
99
119
  }
100
120
  }
101
- return out + td.decode(buf.subarray(0, pos));
102
- }
103
- function encodeInteger(buf, pos, state, segment, j) {
104
- const next = segment[j];
105
- let num = next - state[j];
106
- state[j] = next;
107
- num = num < 0 ? (-num << 1) | 1 : num << 1;
108
- do {
109
- let clamped = num & 0b011111;
110
- num >>>= 5;
111
- if (num > 0)
112
- clamped |= 0b100000;
113
- buf[pos++] = intToChar[clamped];
114
- } while (num > 0);
115
- return pos;
121
+ return writer.flush();
116
122
  }
117
123
 
118
124
  function getDefaultExportFromCjs (x) {
119
125
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
120
126
  }
121
127
 
122
- var picocolors = {exports: {}};
128
+ function commonjsRequire(path) {
129
+ throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
130
+ }
123
131
 
124
- let tty = require$$0;
132
+ var picocolors = {exports: {}};
125
133
 
134
+ let argv = process.argv || [],
135
+ env = process.env;
126
136
  let isColorSupported =
127
- !("NO_COLOR" in process.env || process.argv.includes("--no-color")) &&
128
- ("FORCE_COLOR" in process.env ||
129
- process.argv.includes("--color") ||
137
+ !("NO_COLOR" in env || argv.includes("--no-color")) &&
138
+ ("FORCE_COLOR" in env ||
139
+ argv.includes("--color") ||
130
140
  process.platform === "win32" ||
131
- (tty.isatty(1) && process.env.TERM !== "dumb") ||
132
- "CI" in process.env);
141
+ (commonjsRequire != null && require$$0.isatty(1) && env.TERM !== "dumb") ||
142
+ "CI" in env);
133
143
 
134
144
  let formatter =
135
145
  (open, close, replace = open) =>
@@ -142,40 +152,47 @@ let formatter =
142
152
  };
143
153
 
144
154
  let replaceClose = (string, close, replace, index) => {
145
- let start = string.substring(0, index) + replace;
146
- let end = string.substring(index + close.length);
147
- let nextIndex = end.indexOf(close);
148
- return ~nextIndex ? start + replaceClose(end, close, replace, nextIndex) : start + end
155
+ let result = "";
156
+ let cursor = 0;
157
+ do {
158
+ result += string.substring(cursor, index) + replace;
159
+ cursor = index + close.length;
160
+ index = string.indexOf(close, cursor);
161
+ } while (~index)
162
+ return result + string.substring(cursor)
149
163
  };
150
164
 
151
- let createColors = (enabled = isColorSupported) => ({
152
- isColorSupported: enabled,
153
- reset: enabled ? s => `\x1b[0m${s}\x1b[0m` : String,
154
- bold: enabled ? formatter("\x1b[1m", "\x1b[22m", "\x1b[22m\x1b[1m") : String,
155
- dim: enabled ? formatter("\x1b[2m", "\x1b[22m", "\x1b[22m\x1b[2m") : String,
156
- italic: enabled ? formatter("\x1b[3m", "\x1b[23m") : String,
157
- underline: enabled ? formatter("\x1b[4m", "\x1b[24m") : String,
158
- inverse: enabled ? formatter("\x1b[7m", "\x1b[27m") : String,
159
- hidden: enabled ? formatter("\x1b[8m", "\x1b[28m") : String,
160
- strikethrough: enabled ? formatter("\x1b[9m", "\x1b[29m") : String,
161
- black: enabled ? formatter("\x1b[30m", "\x1b[39m") : String,
162
- red: enabled ? formatter("\x1b[31m", "\x1b[39m") : String,
163
- green: enabled ? formatter("\x1b[32m", "\x1b[39m") : String,
164
- yellow: enabled ? formatter("\x1b[33m", "\x1b[39m") : String,
165
- blue: enabled ? formatter("\x1b[34m", "\x1b[39m") : String,
166
- magenta: enabled ? formatter("\x1b[35m", "\x1b[39m") : String,
167
- cyan: enabled ? formatter("\x1b[36m", "\x1b[39m") : String,
168
- white: enabled ? formatter("\x1b[37m", "\x1b[39m") : String,
169
- gray: enabled ? formatter("\x1b[90m", "\x1b[39m") : String,
170
- bgBlack: enabled ? formatter("\x1b[40m", "\x1b[49m") : String,
171
- bgRed: enabled ? formatter("\x1b[41m", "\x1b[49m") : String,
172
- bgGreen: enabled ? formatter("\x1b[42m", "\x1b[49m") : String,
173
- bgYellow: enabled ? formatter("\x1b[43m", "\x1b[49m") : String,
174
- bgBlue: enabled ? formatter("\x1b[44m", "\x1b[49m") : String,
175
- bgMagenta: enabled ? formatter("\x1b[45m", "\x1b[49m") : String,
176
- bgCyan: enabled ? formatter("\x1b[46m", "\x1b[49m") : String,
177
- bgWhite: enabled ? formatter("\x1b[47m", "\x1b[49m") : String,
178
- });
165
+ let createColors = (enabled = isColorSupported) => {
166
+ let init = enabled ? formatter : () => String;
167
+ return {
168
+ isColorSupported: enabled,
169
+ reset: init("\x1b[0m", "\x1b[0m"),
170
+ bold: init("\x1b[1m", "\x1b[22m", "\x1b[22m\x1b[1m"),
171
+ dim: init("\x1b[2m", "\x1b[22m", "\x1b[22m\x1b[2m"),
172
+ italic: init("\x1b[3m", "\x1b[23m"),
173
+ underline: init("\x1b[4m", "\x1b[24m"),
174
+ inverse: init("\x1b[7m", "\x1b[27m"),
175
+ hidden: init("\x1b[8m", "\x1b[28m"),
176
+ strikethrough: init("\x1b[9m", "\x1b[29m"),
177
+ black: init("\x1b[30m", "\x1b[39m"),
178
+ red: init("\x1b[31m", "\x1b[39m"),
179
+ green: init("\x1b[32m", "\x1b[39m"),
180
+ yellow: init("\x1b[33m", "\x1b[39m"),
181
+ blue: init("\x1b[34m", "\x1b[39m"),
182
+ magenta: init("\x1b[35m", "\x1b[39m"),
183
+ cyan: init("\x1b[36m", "\x1b[39m"),
184
+ white: init("\x1b[37m", "\x1b[39m"),
185
+ gray: init("\x1b[90m", "\x1b[39m"),
186
+ bgBlack: init("\x1b[40m", "\x1b[49m"),
187
+ bgRed: init("\x1b[41m", "\x1b[49m"),
188
+ bgGreen: init("\x1b[42m", "\x1b[49m"),
189
+ bgYellow: init("\x1b[43m", "\x1b[49m"),
190
+ bgBlue: init("\x1b[44m", "\x1b[49m"),
191
+ bgMagenta: init("\x1b[45m", "\x1b[49m"),
192
+ bgCyan: init("\x1b[46m", "\x1b[49m"),
193
+ bgWhite: init("\x1b[47m", "\x1b[49m"),
194
+ }
195
+ };
179
196
 
180
197
  picocolors.exports = createColors();
181
198
  picocolors.exports.createColors = createColors;
@@ -773,6 +790,8 @@ function requireBrowser () {
773
790
  return false;
774
791
  }
775
792
 
793
+ let m;
794
+
776
795
  // Is webkit? http://stackoverflow.com/a/16459606/376773
777
796
  // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
778
797
  return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
@@ -780,7 +799,7 @@ function requireBrowser () {
780
799
  (typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
781
800
  // Is firefox >= v31?
782
801
  // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
783
- (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) ||
802
+ (typeof navigator !== 'undefined' && navigator.userAgent && (m = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(m[1], 10) >= 31) ||
784
803
  // Double check webkit in userAgent just in case we are in a worker
785
804
  (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
786
805
  }
@@ -1116,11 +1135,11 @@ function requireNode () {
1116
1135
  }
1117
1136
 
1118
1137
  /**
1119
- * Invokes `util.format()` with the specified arguments and writes to stderr.
1138
+ * Invokes `util.formatWithOptions()` with the specified arguments and writes to stderr.
1120
1139
  */
1121
1140
 
1122
1141
  function log(...args) {
1123
- return process.stderr.write(util.format(...args) + '\n');
1142
+ return process.stderr.write(util.formatWithOptions(exports.inspectOpts, ...args) + '\n');
1124
1143
  }
1125
1144
 
1126
1145
  /**
@@ -3342,363 +3361,320 @@ const builtins = 'arguments Infinity NaN undefined null true false eval uneval i
3342
3361
  const forbiddenIdentifiers = new Set(`${reservedWords} ${builtins}`.split(' '));
3343
3362
  forbiddenIdentifiers.add('');
3344
3363
 
3345
- const isWindows = typeof process !== 'undefined' && process.platform === 'win32';
3364
+ const isWindows = typeof process !== "undefined" && process.platform === "win32";
3346
3365
  const windowsSlashRE = /\\/g;
3347
3366
  function slash(p) {
3348
- return p.replace(windowsSlashRE, '/');
3367
+ return p.replace(windowsSlashRE, "/");
3349
3368
  }
3350
3369
  const postfixRE = /[?#].*$/;
3351
3370
  function cleanUrl(url) {
3352
- return url.replace(postfixRE, '');
3371
+ return url.replace(postfixRE, "");
3353
3372
  }
3354
3373
  function withTrailingSlash(path) {
3355
- if (path[path.length - 1] !== '/') {
3356
- return `${path}/`;
3357
- }
3358
- return path;
3374
+ if (path[path.length - 1] !== "/") {
3375
+ return `${path}/`;
3376
+ }
3377
+ return path;
3359
3378
  }
3360
3379
 
3361
3380
  if (process.versions.pnp) {
3362
- try {
3363
- node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('node-cjs/publicUtils.cjs', document.baseURI).href)))('pnpapi');
3364
- }
3365
- catch { }
3381
+ try {
3382
+ node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('node-cjs/publicUtils.cjs', document.baseURI).href)))("pnpapi");
3383
+ } catch {
3384
+ }
3366
3385
  }
3367
3386
 
3368
3387
  const createFilter = createFilter$1;
3369
- // Some runtimes like Bun injects namespaced modules here, which is not a node builtin
3370
- node_module.builtinModules.filter((id) => !id.includes(':'));
3388
+ node_module.builtinModules.filter((id) => !id.includes(":"));
3371
3389
  function isInNodeModules(id) {
3372
- return id.includes('node_modules');
3390
+ return id.includes("node_modules");
3373
3391
  }
3374
- // TODO: use import()
3375
3392
  const _require = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('node-cjs/publicUtils.cjs', document.baseURI).href)));
3376
- function resolveDependencyVersion(dep, pkgRelativePath = '../../package.json') {
3377
- const pkgPath = path$3.resolve(_require.resolve(dep), pkgRelativePath);
3378
- return JSON.parse(fs$1.readFileSync(pkgPath, 'utf-8')).version;
3393
+ function resolveDependencyVersion(dep, pkgRelativePath = "../../package.json") {
3394
+ const pkgPath = path$3.resolve(_require.resolve(dep), pkgRelativePath);
3395
+ return JSON.parse(fs$1.readFileSync(pkgPath, "utf-8")).version;
3379
3396
  }
3380
- const rollupVersion = resolveDependencyVersion('rollup');
3381
- // set in bin/vite.js
3397
+ const rollupVersion = resolveDependencyVersion("rollup");
3382
3398
  const filter = process.env.VITE_DEBUG_FILTER;
3383
3399
  const DEBUG = process.env.DEBUG;
3384
3400
  function createDebugger(namespace, options = {}) {
3385
- const log = debug$2(namespace);
3386
- const { onlyWhenFocused } = options;
3387
- let enabled = log.enabled;
3388
- if (enabled && onlyWhenFocused) {
3389
- const ns = typeof onlyWhenFocused === 'string' ? onlyWhenFocused : namespace;
3390
- enabled = !!DEBUG?.includes(ns);
3391
- }
3392
- if (enabled) {
3393
- return (...args) => {
3394
- if (!filter || args.some((a) => a?.includes?.(filter))) {
3395
- log(...args);
3396
- }
3397
- };
3398
- }
3401
+ const log = debug$2(namespace);
3402
+ const { onlyWhenFocused } = options;
3403
+ let enabled = log.enabled;
3404
+ if (enabled && onlyWhenFocused) {
3405
+ const ns = typeof onlyWhenFocused === "string" ? onlyWhenFocused : namespace;
3406
+ enabled = !!DEBUG?.includes(ns);
3407
+ }
3408
+ if (enabled) {
3409
+ return (...args) => {
3410
+ if (!filter || args.some((a) => a?.includes?.(filter))) {
3411
+ log(...args);
3412
+ }
3413
+ };
3414
+ }
3399
3415
  }
3400
3416
  function testCaseInsensitiveFS() {
3401
- if (!CLIENT_ENTRY.endsWith('client.mjs')) {
3402
- throw new Error(`cannot test case insensitive FS, CLIENT_ENTRY const doesn't contain client.mjs`);
3403
- }
3404
- if (!fs$1.existsSync(CLIENT_ENTRY)) {
3405
- throw new Error('cannot test case insensitive FS, CLIENT_ENTRY does not point to an existing file: ' +
3406
- CLIENT_ENTRY);
3407
- }
3408
- return fs$1.existsSync(CLIENT_ENTRY.replace('client.mjs', 'cLiEnT.mjs'));
3417
+ if (!CLIENT_ENTRY.endsWith("client.mjs")) {
3418
+ throw new Error(
3419
+ `cannot test case insensitive FS, CLIENT_ENTRY const doesn't contain client.mjs`
3420
+ );
3421
+ }
3422
+ if (!fs$1.existsSync(CLIENT_ENTRY)) {
3423
+ throw new Error(
3424
+ "cannot test case insensitive FS, CLIENT_ENTRY does not point to an existing file: " + CLIENT_ENTRY
3425
+ );
3426
+ }
3427
+ return fs$1.existsSync(CLIENT_ENTRY.replace("client.mjs", "cLiEnT.mjs"));
3409
3428
  }
3410
3429
  const isCaseInsensitiveFS = testCaseInsensitiveFS();
3411
3430
  const VOLUME_RE = /^[A-Z]:/i;
3412
3431
  function normalizePath(id) {
3413
- return path$3.posix.normalize(isWindows ? slash(id) : id);
3432
+ return path$3.posix.normalize(isWindows ? slash(id) : id);
3414
3433
  }
3415
3434
  function fsPathFromId(id) {
3416
- const fsPath = normalizePath(id.startsWith(FS_PREFIX) ? id.slice(FS_PREFIX.length) : id);
3417
- return fsPath[0] === '/' || VOLUME_RE.test(fsPath) ? fsPath : `/${fsPath}`;
3435
+ const fsPath = normalizePath(
3436
+ id.startsWith(FS_PREFIX) ? id.slice(FS_PREFIX.length) : id
3437
+ );
3438
+ return fsPath[0] === "/" || VOLUME_RE.test(fsPath) ? fsPath : `/${fsPath}`;
3418
3439
  }
3419
3440
  function fsPathFromUrl(url) {
3420
- return fsPathFromId(cleanUrl(url));
3441
+ return fsPathFromId(cleanUrl(url));
3421
3442
  }
3422
- /**
3423
- * Check if dir is a parent of file
3424
- *
3425
- * Warning: parameters are not validated, only works with normalized absolute paths
3426
- *
3427
- * @param dir - normalized absolute path
3428
- * @param file - normalized absolute path
3429
- * @returns true if dir is a parent of file
3430
- */
3431
3443
  function isParentDirectory(dir, file) {
3432
- dir = withTrailingSlash(dir);
3433
- return (file.startsWith(dir) ||
3434
- (isCaseInsensitiveFS && file.toLowerCase().startsWith(dir.toLowerCase())));
3444
+ dir = withTrailingSlash(dir);
3445
+ return file.startsWith(dir) || isCaseInsensitiveFS && file.toLowerCase().startsWith(dir.toLowerCase());
3435
3446
  }
3436
- /**
3437
- * Check if 2 file name are identical
3438
- *
3439
- * Warning: parameters are not validated, only works with normalized absolute paths
3440
- *
3441
- * @param file1 - normalized absolute path
3442
- * @param file2 - normalized absolute path
3443
- * @returns true if both files url are identical
3444
- */
3445
3447
  function isSameFileUri(file1, file2) {
3446
- return (file1 === file2 ||
3447
- (isCaseInsensitiveFS && file1.toLowerCase() === file2.toLowerCase()));
3448
+ return file1 === file2 || isCaseInsensitiveFS && file1.toLowerCase() === file2.toLowerCase();
3448
3449
  }
3449
3450
  const trailingSeparatorRE = /[?&]$/;
3450
3451
  const timestampRE = /\bt=\d{13}&?\b/;
3451
3452
  function removeTimestampQuery(url) {
3452
- return url.replace(timestampRE, '').replace(trailingSeparatorRE, '');
3453
+ return url.replace(timestampRE, "").replace(trailingSeparatorRE, "");
3453
3454
  }
3454
3455
  function isObject$1(value) {
3455
- return Object.prototype.toString.call(value) === '[object Object]';
3456
+ return Object.prototype.toString.call(value) === "[object Object]";
3456
3457
  }
3457
3458
  function tryStatSync(file) {
3458
- try {
3459
- // The "throwIfNoEntry" is a performance optimization for cases where the file does not exist
3460
- return fs$1.statSync(file, { throwIfNoEntry: false });
3461
- }
3462
- catch {
3463
- // Ignore errors
3464
- }
3459
+ try {
3460
+ return fs$1.statSync(file, { throwIfNoEntry: false });
3461
+ } catch {
3462
+ }
3465
3463
  }
3466
3464
  function isFileReadable(filename) {
3467
- if (!tryStatSync(filename)) {
3468
- return false;
3469
- }
3470
- try {
3471
- // Check if current process has read permission to the file
3472
- fs$1.accessSync(filename, fs$1.constants.R_OK);
3473
- return true;
3474
- }
3475
- catch {
3476
- return false;
3477
- }
3465
+ if (!tryStatSync(filename)) {
3466
+ return false;
3467
+ }
3468
+ try {
3469
+ fs$1.accessSync(filename, fs$1.constants.R_OK);
3470
+ return true;
3471
+ } catch {
3472
+ return false;
3473
+ }
3478
3474
  }
3479
3475
  function arraify(target) {
3480
- return Array.isArray(target) ? target : [target];
3476
+ return Array.isArray(target) ? target : [target];
3481
3477
  }
3482
3478
  path$3.dirname(node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('node-cjs/publicUtils.cjs', document.baseURI).href))));
3483
3479
  function backwardCompatibleWorkerPlugins(plugins) {
3484
- if (Array.isArray(plugins)) {
3485
- return plugins;
3486
- }
3487
- if (typeof plugins === 'function') {
3488
- return plugins();
3489
- }
3490
- return [];
3480
+ if (Array.isArray(plugins)) {
3481
+ return plugins;
3482
+ }
3483
+ if (typeof plugins === "function") {
3484
+ return plugins();
3485
+ }
3486
+ return [];
3491
3487
  }
3492
3488
  function mergeConfigRecursively(defaults, overrides, rootPath) {
3493
- const merged = { ...defaults };
3494
- for (const key in overrides) {
3495
- const value = overrides[key];
3496
- if (value == null) {
3497
- continue;
3498
- }
3499
- const existing = merged[key];
3500
- if (existing == null) {
3501
- merged[key] = value;
3502
- continue;
3503
- }
3504
- // fields that require special handling
3505
- if (key === 'alias' && (rootPath === 'resolve' || rootPath === '')) {
3506
- merged[key] = mergeAlias(existing, value);
3507
- continue;
3508
- }
3509
- else if (key === 'assetsInclude' && rootPath === '') {
3510
- merged[key] = [].concat(existing, value);
3511
- continue;
3512
- }
3513
- else if (key === 'noExternal' && // TODO: environments
3514
- rootPath === 'ssr' &&
3515
- (existing === true || value === true)) {
3516
- merged[key] = true;
3517
- continue;
3518
- }
3519
- else if (key === 'plugins' && rootPath === 'worker') {
3520
- merged[key] = () => [
3521
- ...backwardCompatibleWorkerPlugins(existing),
3522
- ...backwardCompatibleWorkerPlugins(value),
3523
- ];
3524
- continue;
3525
- }
3526
- if (Array.isArray(existing) || Array.isArray(value)) {
3527
- merged[key] = [...arraify(existing), ...arraify(value)];
3528
- continue;
3529
- }
3530
- if (isObject$1(existing) && isObject$1(value)) {
3531
- merged[key] = mergeConfigRecursively(existing, value, rootPath ? `${rootPath}.${key}` : key);
3532
- continue;
3533
- }
3534
- merged[key] = value;
3489
+ const merged = { ...defaults };
3490
+ for (const key in overrides) {
3491
+ const value = overrides[key];
3492
+ if (value == null) {
3493
+ continue;
3494
+ }
3495
+ const existing = merged[key];
3496
+ if (existing == null) {
3497
+ merged[key] = value;
3498
+ continue;
3535
3499
  }
3536
- return merged;
3500
+ if (key === "alias" && (rootPath === "resolve" || rootPath === "")) {
3501
+ merged[key] = mergeAlias(existing, value);
3502
+ continue;
3503
+ } else if (key === "assetsInclude" && rootPath === "") {
3504
+ merged[key] = [].concat(existing, value);
3505
+ continue;
3506
+ } else if (key === "noExternal" && (rootPath === "ssr" || rootPath === "resolve") && (existing === true || value === true)) {
3507
+ merged[key] = true;
3508
+ continue;
3509
+ } else if (key === "plugins" && rootPath === "worker") {
3510
+ merged[key] = () => [
3511
+ ...backwardCompatibleWorkerPlugins(existing),
3512
+ ...backwardCompatibleWorkerPlugins(value)
3513
+ ];
3514
+ continue;
3515
+ } else if (key === "server" && rootPath === "server.hmr") {
3516
+ merged[key] = value;
3517
+ continue;
3518
+ }
3519
+ if (Array.isArray(existing) || Array.isArray(value)) {
3520
+ merged[key] = [...arraify(existing), ...arraify(value)];
3521
+ continue;
3522
+ }
3523
+ if (isObject$1(existing) && isObject$1(value)) {
3524
+ merged[key] = mergeConfigRecursively(
3525
+ existing,
3526
+ value,
3527
+ rootPath ? `${rootPath}.${key}` : key
3528
+ );
3529
+ continue;
3530
+ }
3531
+ merged[key] = value;
3532
+ }
3533
+ return merged;
3537
3534
  }
3538
3535
  function mergeConfig(defaults, overrides, isRoot = true) {
3539
- if (typeof defaults === 'function' || typeof overrides === 'function') {
3540
- throw new Error(`Cannot merge config in form of callback`);
3541
- }
3542
- return mergeConfigRecursively(defaults, overrides, isRoot ? '' : '.');
3536
+ if (typeof defaults === "function" || typeof overrides === "function") {
3537
+ throw new Error(`Cannot merge config in form of callback`);
3538
+ }
3539
+ return mergeConfigRecursively(defaults, overrides, isRoot ? "" : ".");
3543
3540
  }
3544
3541
  function mergeAlias(a, b) {
3545
- if (!a)
3546
- return b;
3547
- if (!b)
3548
- return a;
3549
- if (isObject$1(a) && isObject$1(b)) {
3550
- return { ...a, ...b };
3551
- }
3552
- // the order is flipped because the alias is resolved from top-down,
3553
- // where the later should have higher priority
3554
- return [...normalizeAlias(b), ...normalizeAlias(a)];
3542
+ if (!a) return b;
3543
+ if (!b) return a;
3544
+ if (isObject$1(a) && isObject$1(b)) {
3545
+ return { ...a, ...b };
3546
+ }
3547
+ return [...normalizeAlias(b), ...normalizeAlias(a)];
3555
3548
  }
3556
3549
  function normalizeAlias(o = []) {
3557
- return Array.isArray(o)
3558
- ? o.map(normalizeSingleAlias)
3559
- : Object.keys(o).map((find) => normalizeSingleAlias({
3560
- find,
3561
- replacement: o[find],
3562
- }));
3550
+ return Array.isArray(o) ? o.map(normalizeSingleAlias) : Object.keys(o).map(
3551
+ (find) => normalizeSingleAlias({
3552
+ find,
3553
+ replacement: o[find]
3554
+ })
3555
+ );
3563
3556
  }
3564
- // https://github.com/vitejs/vite/issues/1363
3565
- // work around https://github.com/rollup/plugins/issues/759
3566
- function normalizeSingleAlias({ find, replacement, customResolver, }) {
3567
- if (typeof find === 'string' &&
3568
- find[find.length - 1] === '/' &&
3569
- replacement[replacement.length - 1] === '/') {
3570
- find = find.slice(0, find.length - 1);
3571
- replacement = replacement.slice(0, replacement.length - 1);
3572
- }
3573
- const alias = {
3574
- find,
3575
- replacement,
3576
- };
3577
- if (customResolver) {
3578
- alias.customResolver = customResolver;
3579
- }
3580
- return alias;
3557
+ function normalizeSingleAlias({
3558
+ find,
3559
+ replacement,
3560
+ customResolver
3561
+ }) {
3562
+ if (typeof find === "string" && find[find.length - 1] === "/" && replacement[replacement.length - 1] === "/") {
3563
+ find = find.slice(0, find.length - 1);
3564
+ replacement = replacement.slice(0, replacement.length - 1);
3565
+ }
3566
+ const alias = {
3567
+ find,
3568
+ replacement
3569
+ };
3570
+ if (customResolver) {
3571
+ alias.customResolver = customResolver;
3572
+ }
3573
+ return alias;
3581
3574
  }
3582
3575
 
3583
- // This file will be built for both ESM and CJS. Avoid relying on other modules as possible.
3584
- // copy from constants.ts
3585
- const CSS_LANGS_RE =
3586
- // eslint-disable-next-line regexp/no-unused-capturing-group
3587
- /\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\?)/;
3576
+ const CSS_LANGS_RE = (
3577
+ // eslint-disable-next-line regexp/no-unused-capturing-group
3578
+ /\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\?)/
3579
+ );
3588
3580
  const isCSSRequest = (request) => CSS_LANGS_RE.test(request);
3589
- // Use splitVendorChunkPlugin() to get the same manualChunks strategy as Vite 2.7
3590
- // We don't recommend using this strategy as a general solution moving forward
3591
- // splitVendorChunk is a simple index/vendor strategy that was used in Vite
3592
- // until v2.8. It is exposed to let people continue to use it in case it was
3593
- // working well for their setups.
3594
- // The cache needs to be reset on buildStart for watch mode to work correctly
3595
- // Don't use this manualChunks strategy for ssr, lib mode, and 'umd' or 'iife'
3596
- /**
3597
- * @deprecated use build.rollupOutput.manualChunks or framework specific configuration
3598
- */
3599
3581
  class SplitVendorChunkCache {
3600
- cache;
3601
- constructor() {
3602
- this.cache = new Map();
3603
- }
3604
- reset() {
3605
- this.cache = new Map();
3606
- }
3582
+ cache;
3583
+ constructor() {
3584
+ this.cache = /* @__PURE__ */ new Map();
3585
+ }
3586
+ reset() {
3587
+ this.cache = /* @__PURE__ */ new Map();
3588
+ }
3607
3589
  }
3608
- /**
3609
- * @deprecated use build.rollupOutput.manualChunks or framework specific configuration
3610
- */
3611
3590
  function splitVendorChunk(options = {}) {
3612
- const cache = options.cache ?? new SplitVendorChunkCache();
3613
- return (id, { getModuleInfo }) => {
3614
- if (isInNodeModules(id) &&
3615
- !isCSSRequest(id) &&
3616
- staticImportedByEntry(id, getModuleInfo, cache.cache)) {
3617
- return 'vendor';
3618
- }
3619
- };
3591
+ const cache = options.cache ?? new SplitVendorChunkCache();
3592
+ return (id, { getModuleInfo }) => {
3593
+ if (isInNodeModules(id) && !isCSSRequest(id) && staticImportedByEntry(id, getModuleInfo, cache.cache)) {
3594
+ return "vendor";
3595
+ }
3596
+ };
3620
3597
  }
3621
3598
  function staticImportedByEntry(id, getModuleInfo, cache, importStack = []) {
3622
- if (cache.has(id)) {
3623
- return cache.get(id);
3624
- }
3625
- if (importStack.includes(id)) {
3626
- // circular deps!
3627
- cache.set(id, false);
3628
- return false;
3629
- }
3630
- const mod = getModuleInfo(id);
3631
- if (!mod) {
3632
- cache.set(id, false);
3633
- return false;
3634
- }
3635
- if (mod.isEntry) {
3636
- cache.set(id, true);
3637
- return true;
3638
- }
3639
- const someImporterIs = mod.importers.some((importer) => staticImportedByEntry(importer, getModuleInfo, cache, importStack.concat(id)));
3640
- cache.set(id, someImporterIs);
3641
- return someImporterIs;
3599
+ if (cache.has(id)) {
3600
+ return cache.get(id);
3601
+ }
3602
+ if (importStack.includes(id)) {
3603
+ cache.set(id, false);
3604
+ return false;
3605
+ }
3606
+ const mod = getModuleInfo(id);
3607
+ if (!mod) {
3608
+ cache.set(id, false);
3609
+ return false;
3610
+ }
3611
+ if (mod.isEntry) {
3612
+ cache.set(id, true);
3613
+ return true;
3614
+ }
3615
+ const someImporterIs = mod.importers.some(
3616
+ (importer) => staticImportedByEntry(
3617
+ importer,
3618
+ getModuleInfo,
3619
+ cache,
3620
+ importStack.concat(id)
3621
+ )
3622
+ );
3623
+ cache.set(id, someImporterIs);
3624
+ return someImporterIs;
3642
3625
  }
3643
- /**
3644
- * @deprecated use build.rollupOutput.manualChunks or framework specific configuration
3645
- */
3646
3626
  function splitVendorChunkPlugin() {
3647
- const caches = [];
3648
- function createSplitVendorChunk(output, config) {
3649
- const cache = new SplitVendorChunkCache();
3650
- caches.push(cache);
3651
- const build = config.build ?? {};
3652
- const format = output?.format;
3653
- if (!build.ssr && !build.lib && format !== 'umd' && format !== 'iife') {
3654
- return splitVendorChunk({ cache });
3655
- }
3627
+ const caches = [];
3628
+ function createSplitVendorChunk(output, config) {
3629
+ const cache = new SplitVendorChunkCache();
3630
+ caches.push(cache);
3631
+ const build = config.build ?? {};
3632
+ const format = output?.format;
3633
+ if (!build.ssr && !build.lib && format !== "umd" && format !== "iife") {
3634
+ return splitVendorChunk({ cache });
3656
3635
  }
3657
- return {
3658
- name: 'vite:split-vendor-chunk',
3659
- config(config) {
3660
- let outputs = config?.build?.rollupOptions?.output;
3661
- if (outputs) {
3662
- outputs = arraify(outputs);
3663
- for (const output of outputs) {
3664
- const viteManualChunks = createSplitVendorChunk(output, config);
3665
- if (viteManualChunks) {
3666
- if (output.manualChunks) {
3667
- if (typeof output.manualChunks === 'function') {
3668
- const userManualChunks = output.manualChunks;
3669
- output.manualChunks = (id, api) => {
3670
- return userManualChunks(id, api) ?? viteManualChunks(id, api);
3671
- };
3672
- }
3673
- else {
3674
- // else, leave the object form of manualChunks untouched, as
3675
- // we can't safely replicate rollup handling.
3676
- // eslint-disable-next-line no-console
3677
- console.warn("(!) the `splitVendorChunk` plugin doesn't have any effect when using the object form of `build.rollupOptions.output.manualChunks`. Consider using the function form instead.");
3678
- }
3679
- }
3680
- else {
3681
- output.manualChunks = viteManualChunks;
3682
- }
3683
- }
3684
- }
3685
- }
3686
- else {
3687
- return {
3688
- build: {
3689
- rollupOptions: {
3690
- output: {
3691
- manualChunks: createSplitVendorChunk({}, config),
3692
- },
3693
- },
3694
- },
3636
+ }
3637
+ return {
3638
+ name: "vite:split-vendor-chunk",
3639
+ config(config) {
3640
+ let outputs = config?.build?.rollupOptions?.output;
3641
+ if (outputs) {
3642
+ outputs = arraify(outputs);
3643
+ for (const output of outputs) {
3644
+ const viteManualChunks = createSplitVendorChunk(output, config);
3645
+ if (viteManualChunks) {
3646
+ if (output.manualChunks) {
3647
+ if (typeof output.manualChunks === "function") {
3648
+ const userManualChunks = output.manualChunks;
3649
+ output.manualChunks = (id, api) => {
3650
+ return userManualChunks(id, api) ?? viteManualChunks(id, api);
3695
3651
  };
3652
+ } else {
3653
+ console.warn(
3654
+ "(!) the `splitVendorChunk` plugin doesn't have any effect when using the object form of `build.rollupOptions.output.manualChunks`. Consider using the function form instead."
3655
+ );
3656
+ }
3657
+ } else {
3658
+ output.manualChunks = viteManualChunks;
3696
3659
  }
3697
- },
3698
- buildStart() {
3699
- caches.forEach((cache) => cache.reset());
3700
- },
3701
- };
3660
+ }
3661
+ }
3662
+ } else {
3663
+ return {
3664
+ build: {
3665
+ rollupOptions: {
3666
+ output: {
3667
+ manualChunks: createSplitVendorChunk({}, config)
3668
+ }
3669
+ }
3670
+ }
3671
+ };
3672
+ }
3673
+ },
3674
+ buildStart() {
3675
+ caches.forEach((cache) => cache.reset());
3676
+ }
3677
+ };
3702
3678
  }
3703
3679
 
3704
3680
  var convertSourceMap$1 = {};
@@ -4827,8 +4803,10 @@ class MagicString {
4827
4803
  update(start, end, content, options) {
4828
4804
  if (typeof content !== 'string') throw new TypeError('replacement content must be a string');
4829
4805
 
4830
- while (start < 0) start += this.original.length;
4831
- while (end < 0) end += this.original.length;
4806
+ if (this.original.length !== 0) {
4807
+ while (start < 0) start += this.original.length;
4808
+ while (end < 0) end += this.original.length;
4809
+ }
4832
4810
 
4833
4811
  if (end > this.original.length) throw new Error('end is out of bounds');
4834
4812
  if (start === end)
@@ -4924,8 +4902,10 @@ class MagicString {
4924
4902
  }
4925
4903
 
4926
4904
  remove(start, end) {
4927
- while (start < 0) start += this.original.length;
4928
- while (end < 0) end += this.original.length;
4905
+ if (this.original.length !== 0) {
4906
+ while (start < 0) start += this.original.length;
4907
+ while (end < 0) end += this.original.length;
4908
+ }
4929
4909
 
4930
4910
  if (start === end) return this;
4931
4911
 
@@ -4948,8 +4928,10 @@ class MagicString {
4948
4928
  }
4949
4929
 
4950
4930
  reset(start, end) {
4951
- while (start < 0) start += this.original.length;
4952
- while (end < 0) end += this.original.length;
4931
+ if (this.original.length !== 0) {
4932
+ while (start < 0) start += this.original.length;
4933
+ while (end < 0) end += this.original.length;
4934
+ }
4953
4935
 
4954
4936
  if (start === end) return this;
4955
4937
 
@@ -5011,8 +4993,10 @@ class MagicString {
5011
4993
  }
5012
4994
 
5013
4995
  slice(start = 0, end = this.original.length) {
5014
- while (start < 0) start += this.original.length;
5015
- while (end < 0) end += this.original.length;
4996
+ if (this.original.length !== 0) {
4997
+ while (start < 0) start += this.original.length;
4998
+ while (end < 0) end += this.original.length;
4999
+ }
5016
5000
 
5017
5001
  let result = '';
5018
5002
 
@@ -5318,270 +5302,262 @@ class MagicString {
5318
5302
  }
5319
5303
  }
5320
5304
 
5321
- const debug$1 = createDebugger('vite:sourcemap', {
5322
- onlyWhenFocused: true,
5305
+ const debug$1 = createDebugger("vite:sourcemap", {
5306
+ onlyWhenFocused: true
5323
5307
  });
5324
5308
  function genSourceMapUrl(map) {
5325
- if (typeof map !== 'string') {
5326
- map = JSON.stringify(map);
5327
- }
5328
- return `data:application/json;base64,${Buffer.from(map).toString('base64')}`;
5309
+ if (typeof map !== "string") {
5310
+ map = JSON.stringify(map);
5311
+ }
5312
+ return `data:application/json;base64,${Buffer.from(map).toString("base64")}`;
5329
5313
  }
5330
5314
  function getCodeWithSourcemap(type, code, map) {
5331
- if (debug$1) {
5332
- code += `\n/*${JSON.stringify(map, null, 2).replace(/\*\//g, '*\\/')}*/\n`;
5333
- }
5334
- if (type === 'js') {
5335
- code += `\n//# sourceMappingURL=${genSourceMapUrl(map)}`;
5336
- }
5337
- else if (type === 'css') {
5338
- code += `\n/*# sourceMappingURL=${genSourceMapUrl(map)} */`;
5339
- }
5340
- return code;
5315
+ if (debug$1) {
5316
+ code += `
5317
+ /*${JSON.stringify(map, null, 2).replace(/\*\//g, "*\\/")}*/
5318
+ `;
5319
+ }
5320
+ if (type === "js") {
5321
+ code += `
5322
+ //# sourceMappingURL=${genSourceMapUrl(map)}`;
5323
+ } else if (type === "css") {
5324
+ code += `
5325
+ /*# sourceMappingURL=${genSourceMapUrl(map)} */`;
5326
+ }
5327
+ return code;
5341
5328
  }
5342
5329
 
5343
- const debug = createDebugger('vite:send', {
5344
- onlyWhenFocused: true,
5330
+ const debug = createDebugger("vite:send", {
5331
+ onlyWhenFocused: true
5345
5332
  });
5346
5333
  const alias = {
5347
- js: 'text/javascript',
5348
- css: 'text/css',
5349
- html: 'text/html',
5350
- json: 'application/json',
5334
+ js: "text/javascript",
5335
+ css: "text/css",
5336
+ html: "text/html",
5337
+ json: "application/json"
5351
5338
  };
5352
5339
  function send(req, res, content, type, options) {
5353
- const { etag = getEtag(content, { weak: true }), cacheControl = 'no-cache', headers, map, } = options;
5354
- if (res.writableEnded) {
5355
- return;
5356
- }
5357
- if (req.headers['if-none-match'] === etag) {
5358
- res.statusCode = 304;
5359
- res.end();
5360
- return;
5361
- }
5362
- res.setHeader('Content-Type', alias[type] || type);
5363
- res.setHeader('Cache-Control', cacheControl);
5364
- res.setHeader('Etag', etag);
5365
- if (headers) {
5366
- for (const name in headers) {
5367
- res.setHeader(name, headers[name]);
5368
- }
5340
+ const {
5341
+ etag = getEtag(content, { weak: true }),
5342
+ cacheControl = "no-cache",
5343
+ headers,
5344
+ map
5345
+ } = options;
5346
+ if (res.writableEnded) {
5347
+ return;
5348
+ }
5349
+ if (req.headers["if-none-match"] === etag) {
5350
+ res.statusCode = 304;
5351
+ res.end();
5352
+ return;
5353
+ }
5354
+ res.setHeader("Content-Type", alias[type] || type);
5355
+ res.setHeader("Cache-Control", cacheControl);
5356
+ res.setHeader("Etag", etag);
5357
+ if (headers) {
5358
+ for (const name in headers) {
5359
+ res.setHeader(name, headers[name]);
5369
5360
  }
5370
- // inject source map reference
5371
- if (map && 'version' in map && map.mappings) {
5372
- if (type === 'js' || type === 'css') {
5373
- content = getCodeWithSourcemap(type, content.toString(), map);
5374
- }
5361
+ }
5362
+ if (map && "version" in map && map.mappings) {
5363
+ if (type === "js" || type === "css") {
5364
+ content = getCodeWithSourcemap(type, content.toString(), map);
5375
5365
  }
5376
- // inject fallback sourcemap for js for improved debugging
5377
- // https://github.com/vitejs/vite/pull/13514#issuecomment-1592431496
5378
- else if (type === 'js' && (!map || map.mappings !== '')) {
5379
- const code = content.toString();
5380
- // if the code has existing inline sourcemap, assume it's correct and skip
5381
- if (convertSourceMap.mapFileCommentRegex.test(code)) {
5382
- debug?.(`Skipped injecting fallback sourcemap for ${req.url}`);
5383
- }
5384
- else {
5385
- const urlWithoutTimestamp = removeTimestampQuery(req.url);
5386
- const ms = new MagicString(code);
5387
- content = getCodeWithSourcemap(type, code, ms.generateMap({
5388
- source: path$3.basename(urlWithoutTimestamp),
5389
- hires: 'boundary',
5390
- includeContent: true,
5391
- }));
5392
- }
5366
+ } else if (type === "js" && (!map || map.mappings !== "")) {
5367
+ const code = content.toString();
5368
+ if (convertSourceMap.mapFileCommentRegex.test(code)) {
5369
+ debug?.(`Skipped injecting fallback sourcemap for ${req.url}`);
5370
+ } else {
5371
+ const urlWithoutTimestamp = removeTimestampQuery(req.url);
5372
+ const ms = new MagicString(code);
5373
+ content = getCodeWithSourcemap(
5374
+ type,
5375
+ code,
5376
+ ms.generateMap({
5377
+ source: path$3.basename(urlWithoutTimestamp),
5378
+ hires: "boundary",
5379
+ includeContent: true
5380
+ })
5381
+ );
5393
5382
  }
5394
- res.statusCode = 200;
5395
- res.end(content);
5396
- return;
5383
+ }
5384
+ res.statusCode = 200;
5385
+ res.end(content);
5386
+ return;
5397
5387
  }
5398
5388
 
5399
- /* eslint no-console: 0 */
5400
5389
  const LogLevels = {
5401
- silent: 0,
5402
- error: 1,
5403
- warn: 2,
5404
- info: 3,
5390
+ silent: 0,
5391
+ error: 1,
5392
+ warn: 2,
5393
+ info: 3
5405
5394
  };
5406
5395
  let lastType;
5407
5396
  let lastMsg;
5408
5397
  let sameCount = 0;
5409
5398
  function clearScreen() {
5410
- const repeatCount = process.stdout.rows - 2;
5411
- const blank = repeatCount > 0 ? '\n'.repeat(repeatCount) : '';
5412
- console.log(blank);
5413
- readline.cursorTo(process.stdout, 0, 0);
5414
- readline.clearScreenDown(process.stdout);
5399
+ const repeatCount = process.stdout.rows - 2;
5400
+ const blank = repeatCount > 0 ? "\n".repeat(repeatCount) : "";
5401
+ console.log(blank);
5402
+ readline.cursorTo(process.stdout, 0, 0);
5403
+ readline.clearScreenDown(process.stdout);
5415
5404
  }
5416
- // Only initialize the timeFormatter when the timestamp option is used, and
5417
- // reuse it across all loggers
5418
5405
  let timeFormatter;
5419
5406
  function getTimeFormatter() {
5420
- timeFormatter ??= new Intl.DateTimeFormat(undefined, {
5421
- hour: 'numeric',
5422
- minute: 'numeric',
5423
- second: 'numeric',
5424
- });
5425
- return timeFormatter;
5407
+ timeFormatter ??= new Intl.DateTimeFormat(void 0, {
5408
+ hour: "numeric",
5409
+ minute: "numeric",
5410
+ second: "numeric"
5411
+ });
5412
+ return timeFormatter;
5426
5413
  }
5427
- function createLogger(level = 'info', options = {}) {
5428
- if (options.customLogger) {
5429
- return options.customLogger;
5414
+ function createLogger(level = "info", options = {}) {
5415
+ if (options.customLogger) {
5416
+ return options.customLogger;
5417
+ }
5418
+ const loggedErrors = /* @__PURE__ */ new WeakSet();
5419
+ const { prefix = "[vite]", allowClearScreen = true } = options;
5420
+ const thresh = LogLevels[level];
5421
+ const canClearScreen = allowClearScreen && process.stdout.isTTY && !process.env.CI;
5422
+ const clear = canClearScreen ? clearScreen : () => {
5423
+ };
5424
+ function format(type, msg, options2 = {}) {
5425
+ if (options2.timestamp) {
5426
+ let tag = "";
5427
+ if (type === "info") {
5428
+ tag = colors.cyan(colors.bold(prefix));
5429
+ } else if (type === "warn") {
5430
+ tag = colors.yellow(colors.bold(prefix));
5431
+ } else {
5432
+ tag = colors.red(colors.bold(prefix));
5433
+ }
5434
+ const environment = options2.environment ? options2.environment + " " : "";
5435
+ return `${colors.dim(getTimeFormatter().format(/* @__PURE__ */ new Date()))} ${tag} ${environment}${msg}`;
5436
+ } else {
5437
+ return msg;
5430
5438
  }
5431
- const loggedErrors = new WeakSet();
5432
- const { prefix = '[vite]', allowClearScreen = true } = options;
5433
- const thresh = LogLevels[level];
5434
- const canClearScreen = allowClearScreen && process.stdout.isTTY && !process.env.CI;
5435
- const clear = canClearScreen ? clearScreen : () => { };
5436
- function format(type, msg, options = {}) {
5437
- if (options.timestamp) {
5438
- const tag = type === 'info'
5439
- ? colors.cyan(colors.bold(prefix))
5440
- : type === 'warn'
5441
- ? colors.yellow(colors.bold(prefix))
5442
- : colors.red(colors.bold(prefix));
5443
- return `${colors.dim(getTimeFormatter().format(new Date()))} ${tag} ${msg}`;
5444
- }
5445
- else {
5446
- return msg;
5439
+ }
5440
+ function output(type, msg, options2 = {}) {
5441
+ if (thresh >= LogLevels[type]) {
5442
+ const method = type === "info" ? "log" : type;
5443
+ if (options2.error) {
5444
+ loggedErrors.add(options2.error);
5445
+ }
5446
+ if (canClearScreen) {
5447
+ if (type === lastType && msg === lastMsg) {
5448
+ sameCount++;
5449
+ clear();
5450
+ console[method](
5451
+ format(type, msg, options2),
5452
+ colors.yellow(`(x${sameCount + 1})`)
5453
+ );
5454
+ } else {
5455
+ sameCount = 0;
5456
+ lastMsg = msg;
5457
+ lastType = type;
5458
+ if (options2.clear) {
5459
+ clear();
5460
+ }
5461
+ console[method](format(type, msg, options2));
5447
5462
  }
5463
+ } else {
5464
+ console[method](format(type, msg, options2));
5465
+ }
5448
5466
  }
5449
- function output(type, msg, options = {}) {
5450
- if (thresh >= LogLevels[type]) {
5451
- const method = type === 'info' ? 'log' : type;
5452
- if (options.error) {
5453
- loggedErrors.add(options.error);
5454
- }
5455
- if (canClearScreen) {
5456
- if (type === lastType && msg === lastMsg) {
5457
- sameCount++;
5458
- clear();
5459
- console[method](format(type, msg, options), colors.yellow(`(x${sameCount + 1})`));
5460
- }
5461
- else {
5462
- sameCount = 0;
5463
- lastMsg = msg;
5464
- lastType = type;
5465
- if (options.clear) {
5466
- clear();
5467
- }
5468
- console[method](format(type, msg, options));
5469
- }
5470
- }
5471
- else {
5472
- console[method](format(type, msg, options));
5473
- }
5474
- }
5467
+ }
5468
+ const warnedMessages = /* @__PURE__ */ new Set();
5469
+ const logger = {
5470
+ hasWarned: false,
5471
+ info(msg, opts) {
5472
+ output("info", msg, opts);
5473
+ },
5474
+ warn(msg, opts) {
5475
+ logger.hasWarned = true;
5476
+ output("warn", msg, opts);
5477
+ },
5478
+ warnOnce(msg, opts) {
5479
+ if (warnedMessages.has(msg)) return;
5480
+ logger.hasWarned = true;
5481
+ output("warn", msg, opts);
5482
+ warnedMessages.add(msg);
5483
+ },
5484
+ error(msg, opts) {
5485
+ logger.hasWarned = true;
5486
+ output("error", msg, opts);
5487
+ },
5488
+ clearScreen(type) {
5489
+ if (thresh >= LogLevels[type]) {
5490
+ clear();
5491
+ }
5492
+ },
5493
+ hasErrorLogged(error) {
5494
+ return loggedErrors.has(error);
5475
5495
  }
5476
- const warnedMessages = new Set();
5477
- const logger = {
5478
- hasWarned: false,
5479
- info(msg, opts) {
5480
- output('info', msg, opts);
5481
- },
5482
- warn(msg, opts) {
5483
- logger.hasWarned = true;
5484
- output('warn', msg, opts);
5485
- },
5486
- warnOnce(msg, opts) {
5487
- if (warnedMessages.has(msg))
5488
- return;
5489
- logger.hasWarned = true;
5490
- output('warn', msg, opts);
5491
- warnedMessages.add(msg);
5492
- },
5493
- error(msg, opts) {
5494
- logger.hasWarned = true;
5495
- output('error', msg, opts);
5496
- },
5497
- clearScreen(type) {
5498
- if (thresh >= LogLevels[type]) {
5499
- clear();
5500
- }
5501
- },
5502
- hasErrorLogged(error) {
5503
- return loggedErrors.has(error);
5504
- },
5505
- };
5506
- return logger;
5496
+ };
5497
+ return logger;
5507
5498
  }
5508
5499
 
5509
- // https://github.com/vitejs/vite/issues/2820#issuecomment-812495079
5510
5500
  const ROOT_FILES = [
5511
- // '.git',
5512
- // https://pnpm.io/workspaces/
5513
- 'pnpm-workspace.yaml',
5514
- // https://rushjs.io/pages/advanced/config_files/
5515
- // 'rush.json',
5516
- // https://nx.dev/latest/react/getting-started/nx-setup
5517
- // 'workspace.json',
5518
- // 'nx.json',
5519
- // https://github.com/lerna/lerna#lernajson
5520
- 'lerna.json',
5501
+ // '.git',
5502
+ // https://pnpm.io/workspaces/
5503
+ "pnpm-workspace.yaml",
5504
+ // https://rushjs.io/pages/advanced/config_files/
5505
+ // 'rush.json',
5506
+ // https://nx.dev/latest/react/getting-started/nx-setup
5507
+ // 'workspace.json',
5508
+ // 'nx.json',
5509
+ // https://github.com/lerna/lerna#lernajson
5510
+ "lerna.json"
5521
5511
  ];
5522
- // npm: https://docs.npmjs.com/cli/v7/using-npm/workspaces#installing-workspaces
5523
- // yarn: https://classic.yarnpkg.com/en/docs/workspaces/#toc-how-to-use-it
5524
5512
  function hasWorkspacePackageJSON(root) {
5525
- const path = path$3.join(root, 'package.json');
5526
- if (!isFileReadable(path)) {
5527
- return false;
5528
- }
5529
- try {
5530
- const content = JSON.parse(fs$1.readFileSync(path, 'utf-8')) || {};
5531
- return !!content.workspaces;
5532
- }
5533
- catch {
5534
- return false;
5535
- }
5513
+ const path = path$3.join(root, "package.json");
5514
+ if (!isFileReadable(path)) {
5515
+ return false;
5516
+ }
5517
+ try {
5518
+ const content = JSON.parse(fs$1.readFileSync(path, "utf-8")) || {};
5519
+ return !!content.workspaces;
5520
+ } catch {
5521
+ return false;
5522
+ }
5536
5523
  }
5537
5524
  function hasRootFile(root) {
5538
- return ROOT_FILES.some((file) => fs$1.existsSync(path$3.join(root, file)));
5525
+ return ROOT_FILES.some((file) => fs$1.existsSync(path$3.join(root, file)));
5539
5526
  }
5540
5527
  function hasPackageJSON(root) {
5541
- const path = path$3.join(root, 'package.json');
5542
- return fs$1.existsSync(path);
5528
+ const path = path$3.join(root, "package.json");
5529
+ return fs$1.existsSync(path);
5543
5530
  }
5544
- /**
5545
- * Search up for the nearest `package.json`
5546
- */
5547
5531
  function searchForPackageRoot(current, root = current) {
5548
- if (hasPackageJSON(current))
5549
- return current;
5550
- const dir = path$3.dirname(current);
5551
- // reach the fs root
5552
- if (!dir || dir === current)
5553
- return root;
5554
- return searchForPackageRoot(dir, root);
5532
+ if (hasPackageJSON(current)) return current;
5533
+ const dir = path$3.dirname(current);
5534
+ if (!dir || dir === current) return root;
5535
+ return searchForPackageRoot(dir, root);
5555
5536
  }
5556
- /**
5557
- * Search up for the nearest workspace root
5558
- */
5559
5537
  function searchForWorkspaceRoot(current, root = searchForPackageRoot(current)) {
5560
- if (hasRootFile(current))
5561
- return current;
5562
- if (hasWorkspacePackageJSON(current))
5563
- return current;
5564
- const dir = path$3.dirname(current);
5565
- // reach the fs root
5566
- if (!dir || dir === current)
5567
- return root;
5568
- return searchForWorkspaceRoot(dir, root);
5538
+ if (hasRootFile(current)) return current;
5539
+ if (hasWorkspacePackageJSON(current)) return current;
5540
+ const dir = path$3.dirname(current);
5541
+ if (!dir || dir === current) return root;
5542
+ return searchForWorkspaceRoot(dir, root);
5569
5543
  }
5570
5544
 
5571
- /**
5572
- * Check if the url is allowed to be served, via the `server.fs` config.
5573
- */
5574
5545
  function isFileServingAllowed(url, server) {
5575
- if (!server.config.server.fs.strict)
5576
- return true;
5577
- const file = fsPathFromUrl(url);
5578
- if (server._fsDenyGlob(file))
5579
- return false;
5580
- if (server._safeModulesPath.has(file))
5581
- return true;
5582
- if (server.config.server.fs.allow.some((uri) => isSameFileUri(uri, file) || isParentDirectory(uri, file)))
5583
- return true;
5584
- return false;
5546
+ const { config } = server;
5547
+ if (!config.server.fs.strict) return true;
5548
+ const filePath = fsPathFromUrl(url);
5549
+ return isFileLoadingAllowed(config, filePath);
5550
+ }
5551
+ function isUriInFilePath(uri, filePath) {
5552
+ return isSameFileUri(uri, filePath) || isParentDirectory(uri, filePath);
5553
+ }
5554
+ function isFileLoadingAllowed(config, filePath) {
5555
+ const { fs } = config.server;
5556
+ if (!fs.strict) return true;
5557
+ if (config.fsDenyGlob(filePath)) return false;
5558
+ if (config.safeModulePaths.has(filePath)) return true;
5559
+ if (fs.allow.some((uri) => isUriInFilePath(uri, filePath))) return true;
5560
+ return false;
5585
5561
  }
5586
5562
 
5587
5563
  var main$1 = {exports: {}};
@@ -6117,68 +6093,72 @@ function expand (options) {
6117
6093
  var expand_1 = expand;
6118
6094
 
6119
6095
  function getEnvFilesForMode(mode, envDir) {
6120
- return [
6121
- /** default file */ `.env`,
6122
- /** local file */ `.env.local`,
6123
- /** mode file */ `.env.${mode}`,
6124
- /** mode local file */ `.env.${mode}.local`,
6125
- ].map((file) => normalizePath(path$3.join(envDir, file)));
6096
+ return [
6097
+ /** default file */
6098
+ `.env`,
6099
+ /** local file */
6100
+ `.env.local`,
6101
+ /** mode file */
6102
+ `.env.${mode}`,
6103
+ /** mode local file */
6104
+ `.env.${mode}.local`
6105
+ ].map((file) => normalizePath(path$3.join(envDir, file)));
6126
6106
  }
6127
- function loadEnv(mode, envDir, prefixes = 'VITE_') {
6128
- if (mode === 'local') {
6129
- throw new Error(`"local" cannot be used as a mode name because it conflicts with ` +
6130
- `the .local postfix for .env files.`);
6131
- }
6132
- prefixes = arraify(prefixes);
6133
- const env = {};
6134
- const envFiles = getEnvFilesForMode(mode, envDir);
6135
- const parsed = Object.fromEntries(envFiles.flatMap((filePath) => {
6136
- if (!tryStatSync(filePath)?.isFile())
6137
- return [];
6138
- return Object.entries(parse_1(fs$1.readFileSync(filePath)));
6139
- }));
6140
- // test NODE_ENV override before expand as otherwise process.env.NODE_ENV would override this
6141
- if (parsed.NODE_ENV && process.env.VITE_USER_NODE_ENV === undefined) {
6142
- process.env.VITE_USER_NODE_ENV = parsed.NODE_ENV;
6143
- }
6144
- // support BROWSER and BROWSER_ARGS env variables
6145
- if (parsed.BROWSER && process.env.BROWSER === undefined) {
6146
- process.env.BROWSER = parsed.BROWSER;
6147
- }
6148
- if (parsed.BROWSER_ARGS && process.env.BROWSER_ARGS === undefined) {
6149
- process.env.BROWSER_ARGS = parsed.BROWSER_ARGS;
6150
- }
6151
- // let environment variables use each other. make a copy of `process.env` so that `dotenv-expand`
6152
- // doesn't re-assign the expanded values to the global `process.env`.
6153
- const processEnv = { ...process.env };
6154
- expand_1({ parsed, processEnv });
6155
- // only keys that start with prefix are exposed to client
6156
- for (const [key, value] of Object.entries(parsed)) {
6157
- if (prefixes.some((prefix) => key.startsWith(prefix))) {
6158
- env[key] = value;
6159
- }
6107
+ function loadEnv(mode, envDir, prefixes = "VITE_") {
6108
+ if (mode === "local") {
6109
+ throw new Error(
6110
+ `"local" cannot be used as a mode name because it conflicts with the .local postfix for .env files.`
6111
+ );
6112
+ }
6113
+ prefixes = arraify(prefixes);
6114
+ const env = {};
6115
+ const envFiles = getEnvFilesForMode(mode, envDir);
6116
+ const parsed = Object.fromEntries(
6117
+ envFiles.flatMap((filePath) => {
6118
+ if (!tryStatSync(filePath)?.isFile()) return [];
6119
+ return Object.entries(parse_1(fs$1.readFileSync(filePath)));
6120
+ })
6121
+ );
6122
+ if (parsed.NODE_ENV && process.env.VITE_USER_NODE_ENV === void 0) {
6123
+ process.env.VITE_USER_NODE_ENV = parsed.NODE_ENV;
6124
+ }
6125
+ if (parsed.BROWSER && process.env.BROWSER === void 0) {
6126
+ process.env.BROWSER = parsed.BROWSER;
6127
+ }
6128
+ if (parsed.BROWSER_ARGS && process.env.BROWSER_ARGS === void 0) {
6129
+ process.env.BROWSER_ARGS = parsed.BROWSER_ARGS;
6130
+ }
6131
+ const processEnv = { ...process.env };
6132
+ expand_1({ parsed, processEnv });
6133
+ for (const [key, value] of Object.entries(parsed)) {
6134
+ if (prefixes.some((prefix) => key.startsWith(prefix))) {
6135
+ env[key] = value;
6160
6136
  }
6161
- // check if there are actual env variables starting with VITE_*
6162
- // these are typically provided inline and should be prioritized
6163
- for (const key in process.env) {
6164
- if (prefixes.some((prefix) => key.startsWith(prefix))) {
6165
- env[key] = process.env[key];
6166
- }
6137
+ }
6138
+ for (const key in process.env) {
6139
+ if (prefixes.some((prefix) => key.startsWith(prefix))) {
6140
+ env[key] = process.env[key];
6167
6141
  }
6168
- return env;
6142
+ }
6143
+ return env;
6169
6144
  }
6170
- function resolveEnvPrefix({ envPrefix = 'VITE_', }) {
6171
- envPrefix = arraify(envPrefix);
6172
- if (envPrefix.includes('')) {
6173
- throw new Error(`envPrefix option contains value '', which could lead unexpected exposure of sensitive information.`);
6174
- }
6175
- return envPrefix;
6145
+ function resolveEnvPrefix({
6146
+ envPrefix = "VITE_"
6147
+ }) {
6148
+ envPrefix = arraify(envPrefix);
6149
+ if (envPrefix.includes("")) {
6150
+ throw new Error(
6151
+ `envPrefix option contains value '', which could lead unexpected exposure of sensitive information.`
6152
+ );
6153
+ }
6154
+ return envPrefix;
6176
6155
  }
6177
6156
 
6178
6157
  exports.esbuildVersion = esbuild.version;
6179
6158
  exports.createFilter = createFilter;
6180
6159
  exports.createLogger = createLogger;
6181
6160
  exports.isCSSRequest = isCSSRequest;
6161
+ exports.isFileLoadingAllowed = isFileLoadingAllowed;
6182
6162
  exports.isFileServingAllowed = isFileServingAllowed;
6183
6163
  exports.loadEnv = loadEnv;
6184
6164
  exports.mergeAlias = mergeAlias;