vite 8.1.5 → 8.2.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/LICENSE.md +35 -0
- package/dist/client/bundledDevClient.mjs +1463 -0
- package/dist/client/client.mjs +51 -82
- package/dist/node/chunks/build.js +19 -19
- package/dist/node/chunks/node.js +1182 -351
- package/dist/node/chunks/postcss-import.js +10 -10
- package/dist/node/index.d.ts +58 -14
- package/dist/node/module-runner.js +14 -9
- package/package.json +11 -11
- package/types/customEvent.d.ts +3 -1
- package/types/hmrPayload.d.ts +20 -6
package/dist/node/chunks/node.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Module, builtinModules, createRequire } from "node:module";
|
|
2
2
|
import { parseAst, parseAstAsync } from "rolldown/parseAst";
|
|
3
3
|
import { esmExternalRequirePlugin, esmExternalRequirePlugin as esmExternalRequirePlugin$1 } from "rolldown/plugins";
|
|
4
|
-
import { TsconfigCache, Visitor, minify, minifySync, parse, parseSync, transformSync } from "rolldown/utils";
|
|
4
|
+
import { TsconfigCache, Visitor, minify, minifySync, parse, parseSync, parseSync as parseSync$1, transformSync } from "rolldown/utils";
|
|
5
5
|
import * as fs$2 from "node:fs";
|
|
6
6
|
import fs, { existsSync, readFileSync } from "node:fs";
|
|
7
7
|
import path, { basename, dirname, extname, isAbsolute, join, normalize, posix, relative, resolve, sep } from "node:path";
|
|
@@ -13,6 +13,7 @@ import crypto from "node:crypto";
|
|
|
13
13
|
import pm from "picomatch";
|
|
14
14
|
import { MessageChannel, Worker } from "node:worker_threads";
|
|
15
15
|
import { VERSION as rolldownVersion, rolldown } from "rolldown";
|
|
16
|
+
import { escapePath, glob, globSync, isDynamicPattern } from "tinyglobby";
|
|
16
17
|
import os from "node:os";
|
|
17
18
|
import net from "node:net";
|
|
18
19
|
import childProcess, { exec, execFile, execSync } from "node:child_process";
|
|
@@ -23,7 +24,6 @@ import { exactRegex, makeIdFiltersToMatchWithQuery, prefixRegex, withFilter } fr
|
|
|
23
24
|
import { dev, oxcRuntimePlugin, resolveTsconfig, scan, viteAliasPlugin, viteBuildImportAnalysisPlugin, viteDynamicImportVarsPlugin, viteImportGlobPlugin, viteJsonPlugin, viteLoadFallbackPlugin, viteManifestPlugin, viteModulePreloadPolyfillPlugin, viteReporterPlugin, viteResolvePlugin, viteTransformPlugin, viteWebWorkerPostPlugin } from "rolldown/experimental";
|
|
24
25
|
import readline from "node:readline";
|
|
25
26
|
import isModuleSyncConditionEnabled from "#module-sync-enabled";
|
|
26
|
-
import { escapePath, glob, globSync, isDynamicPattern } from "tinyglobby";
|
|
27
27
|
import assert from "node:assert";
|
|
28
28
|
import process$1 from "node:process";
|
|
29
29
|
import v8 from "node:v8";
|
|
@@ -634,6 +634,7 @@ const CLIENT_PUBLIC_PATH = `/@vite/client`;
|
|
|
634
634
|
const ENV_PUBLIC_PATH = `/@vite/env`;
|
|
635
635
|
const VITE_PACKAGE_DIR = resolve(fileURLToPath(new URL("../../../src/node/constants.ts", import.meta.url)), "../../..");
|
|
636
636
|
const CLIENT_ENTRY = resolve(VITE_PACKAGE_DIR, "dist/client/client.mjs");
|
|
637
|
+
const BUNDLED_DEV_CLIENT_ENTRY = resolve(VITE_PACKAGE_DIR, "dist/client/bundledDevClient.mjs");
|
|
637
638
|
const ENV_ENTRY = resolve(VITE_PACKAGE_DIR, "dist/client/env.mjs");
|
|
638
639
|
const CLIENT_DIR = path.dirname(CLIENT_ENTRY);
|
|
639
640
|
const KNOWN_ASSET_TYPES = [
|
|
@@ -1603,11 +1604,11 @@ function getDate() {
|
|
|
1603
1604
|
function init$1(debug) {
|
|
1604
1605
|
debug.inspectOpts = Object.assign({}, inspectOpts);
|
|
1605
1606
|
}
|
|
1606
|
-
var require$1, colors$
|
|
1607
|
+
var require$1, colors$40, inspectOpts, humanize$1, createDebug, node_default;
|
|
1607
1608
|
var init_node = __esmMin((() => {
|
|
1608
1609
|
init_core();
|
|
1609
1610
|
require$1 = createRequire(import.meta.url);
|
|
1610
|
-
colors$
|
|
1611
|
+
colors$40 = process.stderr.getColorDepth && process.stderr.getColorDepth() > 2 ? [
|
|
1611
1612
|
20,
|
|
1612
1613
|
21,
|
|
1613
1614
|
26,
|
|
@@ -1709,7 +1710,7 @@ var init_node = __esmMin((() => {
|
|
|
1709
1710
|
} catch (_unused) {
|
|
1710
1711
|
humanize$1 = humanize;
|
|
1711
1712
|
}
|
|
1712
|
-
createDebug = setup(useColors(), colors$
|
|
1713
|
+
createDebug = setup(useColors(), colors$40, log, load, save, formatArgs, init$1);
|
|
1713
1714
|
createDebug.inspectOpts = inspectOpts;
|
|
1714
1715
|
createDebug.formatters.o = function(v) {
|
|
1715
1716
|
this.inspectOpts.colors = this.useColors;
|
|
@@ -2287,6 +2288,8 @@ function lookupFile(dir, fileNames) {
|
|
|
2287
2288
|
function isFilePathESM(filePath, packageCache) {
|
|
2288
2289
|
if (/\.m[jt]s$/.test(filePath)) return true;
|
|
2289
2290
|
else if (/\.c[jt]s$/.test(filePath)) return false;
|
|
2291
|
+
else if (filePath.startsWith("\0")) return true;
|
|
2292
|
+
else if (!path.isAbsolute(filePath)) return false;
|
|
2290
2293
|
else try {
|
|
2291
2294
|
return findNearestPackageData(path.dirname(filePath), packageCache)?.data.type === "module";
|
|
2292
2295
|
} catch {
|
|
@@ -2300,6 +2303,8 @@ function isFilePathESM(filePath, packageCache) {
|
|
|
2300
2303
|
*/
|
|
2301
2304
|
function isFilePathFormatExplicit(filePath, packageCache) {
|
|
2302
2305
|
if (/\.[mc][jt]s$/.test(filePath)) return true;
|
|
2306
|
+
if (filePath.startsWith("\0")) return true;
|
|
2307
|
+
if (!path.isAbsolute(filePath)) return false;
|
|
2303
2308
|
try {
|
|
2304
2309
|
const pkg = findNearestPackageData(path.dirname(filePath), packageCache);
|
|
2305
2310
|
return pkg?.data.type === "module" || pkg?.data.type === "commonjs";
|
|
@@ -2632,10 +2637,12 @@ function resolveServerUrls(server, options, hostname, httpsOptions, config) {
|
|
|
2632
2637
|
const isAddressInfo = (x) => x?.address;
|
|
2633
2638
|
if (!isAddressInfo(address)) return {
|
|
2634
2639
|
local: [],
|
|
2635
|
-
network: []
|
|
2640
|
+
network: [],
|
|
2641
|
+
networkInterfaceNames: []
|
|
2636
2642
|
};
|
|
2637
2643
|
const local = [];
|
|
2638
2644
|
const network = [];
|
|
2645
|
+
const networkInterfaceNames = [];
|
|
2639
2646
|
const protocol = options.https ? "https" : "http";
|
|
2640
2647
|
const port = address.port;
|
|
2641
2648
|
const base = config.rawBase === "./" || config.rawBase === "" ? "/" : config.rawBase;
|
|
@@ -2644,13 +2651,29 @@ function resolveServerUrls(server, options, hostname, httpsOptions, config) {
|
|
|
2644
2651
|
if (hostnameName.includes(":")) hostnameName = `[${hostnameName}]`;
|
|
2645
2652
|
const address = `${protocol}://${hostnameName}:${port}${base}`;
|
|
2646
2653
|
if (loopbackHosts.has(hostname.host)) local.push(address);
|
|
2647
|
-
else
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
+
else {
|
|
2655
|
+
network.push(address);
|
|
2656
|
+
let interfaceName;
|
|
2657
|
+
if (hostname.host) {
|
|
2658
|
+
const interfaces = os.networkInterfaces();
|
|
2659
|
+
outer: for (const [name, nInterface] of Object.entries(interfaces)) for (const detail of nInterface ?? []) if (detail.address === hostname.host) {
|
|
2660
|
+
interfaceName = name;
|
|
2661
|
+
break outer;
|
|
2662
|
+
}
|
|
2663
|
+
}
|
|
2664
|
+
networkInterfaceNames.push(interfaceName);
|
|
2665
|
+
}
|
|
2666
|
+
} else Object.entries(os.networkInterfaces()).forEach(([name, nInterface]) => {
|
|
2667
|
+
(nInterface ?? []).filter((detail) => detail.address && detail.family === "IPv4").forEach((detail) => {
|
|
2668
|
+
let host = detail.address.replace("127.0.0.1", hostname.name);
|
|
2669
|
+
if (host.includes(":")) host = `[${host}]`;
|
|
2670
|
+
const url = `${protocol}://${host}:${port}${base}`;
|
|
2671
|
+
if (detail.address.includes("127.0.0.1")) local.push(url);
|
|
2672
|
+
else {
|
|
2673
|
+
network.push(url);
|
|
2674
|
+
networkInterfaceNames.push(name);
|
|
2675
|
+
}
|
|
2676
|
+
});
|
|
2654
2677
|
});
|
|
2655
2678
|
const hostnamesFromCert = extractHostnamesFromCerts(httpsOptions?.cert);
|
|
2656
2679
|
if (hostnamesFromCert.length > 0) {
|
|
@@ -2659,7 +2682,8 @@ function resolveServerUrls(server, options, hostname, httpsOptions, config) {
|
|
|
2659
2682
|
}
|
|
2660
2683
|
return {
|
|
2661
2684
|
local,
|
|
2662
|
-
network
|
|
2685
|
+
network,
|
|
2686
|
+
networkInterfaceNames
|
|
2663
2687
|
};
|
|
2664
2688
|
}
|
|
2665
2689
|
function extractHostnamesFromSubjectAltName(subjectAltName) {
|
|
@@ -2851,7 +2875,10 @@ function mergeConfigRecursively(defaults, overrides, rootPath) {
|
|
|
2851
2875
|
else merged[key] = value;
|
|
2852
2876
|
continue;
|
|
2853
2877
|
}
|
|
2854
|
-
if (key === "
|
|
2878
|
+
if (key === "input" && rootPath === "") {
|
|
2879
|
+
merged[key] = mergeInput(existing, value);
|
|
2880
|
+
continue;
|
|
2881
|
+
} else if (key === "alias" && (rootPath === "resolve" || rootPath === "")) {
|
|
2855
2882
|
merged[key] = mergeAlias(existing, value);
|
|
2856
2883
|
continue;
|
|
2857
2884
|
} else if (key === "assetsInclude" && rootPath === "") {
|
|
@@ -2883,6 +2910,26 @@ function mergeConfig(defaults, overrides, isRoot = true) {
|
|
|
2883
2910
|
if (typeof defaults === "function" || typeof overrides === "function") throw new Error(`Cannot merge config in form of callback`);
|
|
2884
2911
|
return mergeConfigRecursively(defaults, overrides, isRoot ? "" : ".");
|
|
2885
2912
|
}
|
|
2913
|
+
function mergeInput(a, b) {
|
|
2914
|
+
if (!a) return b;
|
|
2915
|
+
if (!b) return a;
|
|
2916
|
+
if (typeof a === "string" && typeof b === "string") return [a, b];
|
|
2917
|
+
if (Array.isArray(a) && (typeof b === "string" || Array.isArray(b))) return [...a, ...Array.isArray(b) ? b : [b]];
|
|
2918
|
+
if (Array.isArray(b) && (typeof a === "string" || Array.isArray(a))) return [...Array.isArray(a) ? a : [a], ...b];
|
|
2919
|
+
if (typeof a !== "string" && !Array.isArray(a)) return {
|
|
2920
|
+
...a,
|
|
2921
|
+
...normalizeToInputObject(b)
|
|
2922
|
+
};
|
|
2923
|
+
return {
|
|
2924
|
+
...normalizeToInputObject(a),
|
|
2925
|
+
...b
|
|
2926
|
+
};
|
|
2927
|
+
}
|
|
2928
|
+
function normalizeToInputObject(input) {
|
|
2929
|
+
if (typeof input === "string") return { [path.basename(input, path.extname(input))]: input };
|
|
2930
|
+
if (Array.isArray(input)) return Object.fromEntries(input.map((i) => [path.basename(i, path.extname(i)), i]));
|
|
2931
|
+
return input;
|
|
2932
|
+
}
|
|
2886
2933
|
function mergeAlias(a, b) {
|
|
2887
2934
|
if (!a) return b;
|
|
2888
2935
|
if (!b) return a;
|
|
@@ -3237,10 +3284,20 @@ function createLogger(level = "info", options = {}) {
|
|
|
3237
3284
|
};
|
|
3238
3285
|
return logger;
|
|
3239
3286
|
}
|
|
3287
|
+
const maxNetworkInterfaceNameLength = 20;
|
|
3240
3288
|
function printServerUrls(urls, optionsHost, info) {
|
|
3241
3289
|
const colorUrl = (url) => import_picocolors.default.cyan(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
3242
3290
|
for (const url of urls.local) info(` ${import_picocolors.default.green("➜")} ${import_picocolors.default.bold("Local")}: ${colorUrl(url)}`);
|
|
3243
|
-
|
|
3291
|
+
const networkUrlMaxLength = Math.max(...urls.network.map((url) => url.length), 0);
|
|
3292
|
+
urls.network.forEach((url, index) => {
|
|
3293
|
+
const interfaceName = urls.networkInterfaceNames?.[index];
|
|
3294
|
+
let suffix = "";
|
|
3295
|
+
if (interfaceName) {
|
|
3296
|
+
const label = interfaceName.length > maxNetworkInterfaceNameLength ? `${interfaceName.slice(0, maxNetworkInterfaceNameLength - 1)}…` : interfaceName;
|
|
3297
|
+
suffix = " ".repeat(networkUrlMaxLength - url.length + 2) + import_picocolors.default.dim(label);
|
|
3298
|
+
}
|
|
3299
|
+
info(` ${import_picocolors.default.green("➜")} ${import_picocolors.default.bold("Network")}: ${colorUrl(url)}${suffix}`);
|
|
3300
|
+
});
|
|
3244
3301
|
if (urls.network.length === 0 && optionsHost === void 0) info(import_picocolors.default.dim(` ${import_picocolors.default.green("➜")} ${import_picocolors.default.bold("Network")}: use `) + import_picocolors.default.bold("--host") + import_picocolors.default.dim(" to expose"));
|
|
3245
3302
|
}
|
|
3246
3303
|
//#endregion
|
|
@@ -4148,7 +4205,7 @@ function warnDeprecatedShouldBeConvertedToPluginOptions(logger, name) {
|
|
|
4148
4205
|
logger.warn(import_picocolors.default.yellow(`\`esbuild.${name}\` option was specified. But this option is deprecated and will be removed in future versions. This option can be achieved by using a plugin with transform hook, please use that instead.`));
|
|
4149
4206
|
}
|
|
4150
4207
|
//#endregion
|
|
4151
|
-
//#region ../../node_modules/.pnpm/magic-string@
|
|
4208
|
+
//#region ../../node_modules/.pnpm/magic-string@1.1.0/node_modules/magic-string/dist/index.mjs
|
|
4152
4209
|
var BitSet = class BitSet {
|
|
4153
4210
|
constructor(arg) {
|
|
4154
4211
|
this.bits = arg instanceof BitSet ? arg.bits.slice() : [];
|
|
@@ -4192,14 +4249,16 @@ var Chunk = class Chunk {
|
|
|
4192
4249
|
return this.start < index && index < this.end;
|
|
4193
4250
|
}
|
|
4194
4251
|
eachNext(fn) {
|
|
4195
|
-
|
|
4252
|
+
fn(this);
|
|
4253
|
+
let chunk = this.next;
|
|
4196
4254
|
while (chunk) {
|
|
4197
4255
|
fn(chunk);
|
|
4198
4256
|
chunk = chunk.next;
|
|
4199
4257
|
}
|
|
4200
4258
|
}
|
|
4201
4259
|
eachPrevious(fn) {
|
|
4202
|
-
|
|
4260
|
+
fn(this);
|
|
4261
|
+
let chunk = this.previous;
|
|
4203
4262
|
while (chunk) {
|
|
4204
4263
|
fn(chunk);
|
|
4205
4264
|
chunk = chunk.previous;
|
|
@@ -4257,10 +4316,8 @@ var Chunk = class Chunk {
|
|
|
4257
4316
|
if (this.outro.length) return true;
|
|
4258
4317
|
const trimmed = this.content.replace(rx, "");
|
|
4259
4318
|
if (trimmed.length) {
|
|
4260
|
-
if (trimmed !== this.content)
|
|
4261
|
-
|
|
4262
|
-
if (this.edited) this.edit(trimmed, this.storeName, true);
|
|
4263
|
-
}
|
|
4319
|
+
if (trimmed !== this.content) if (this.edited) this.edit(trimmed, this.storeName, true);
|
|
4320
|
+
else this.split(this.start + trimmed.length).edit("", void 0, true);
|
|
4264
4321
|
return true;
|
|
4265
4322
|
} else {
|
|
4266
4323
|
this.edit("", void 0, true);
|
|
@@ -4273,9 +4330,9 @@ var Chunk = class Chunk {
|
|
|
4273
4330
|
if (this.intro.length) return true;
|
|
4274
4331
|
const trimmed = this.content.replace(rx, "");
|
|
4275
4332
|
if (trimmed.length) {
|
|
4276
|
-
if (trimmed !== this.content)
|
|
4277
|
-
|
|
4278
|
-
|
|
4333
|
+
if (trimmed !== this.content) if (this.edited) this.edit(trimmed, this.storeName, true);
|
|
4334
|
+
else {
|
|
4335
|
+
this.split(this.end - trimmed.length);
|
|
4279
4336
|
this.edit("", void 0, true);
|
|
4280
4337
|
}
|
|
4281
4338
|
return true;
|
|
@@ -4288,12 +4345,13 @@ var Chunk = class Chunk {
|
|
|
4288
4345
|
};
|
|
4289
4346
|
function getBtoa() {
|
|
4290
4347
|
if (typeof globalThis !== "undefined" && typeof globalThis.btoa === "function") return (str) => globalThis.btoa(unescape(encodeURIComponent(str)));
|
|
4291
|
-
|
|
4292
|
-
|
|
4348
|
+
const buffer = globalThis["Buffer"];
|
|
4349
|
+
if (buffer) return (str) => buffer.from(str, "utf-8").toString("base64");
|
|
4350
|
+
return () => {
|
|
4293
4351
|
throw new Error("Unsupported environment: `window.btoa` or `Buffer` should be supported.");
|
|
4294
4352
|
};
|
|
4295
4353
|
}
|
|
4296
|
-
const btoa$1 =
|
|
4354
|
+
const btoa$1 = /* #__PURE__ */ getBtoa();
|
|
4297
4355
|
var SourceMap = class {
|
|
4298
4356
|
constructor(properties) {
|
|
4299
4357
|
this.version = 3;
|
|
@@ -4305,43 +4363,20 @@ var SourceMap = class {
|
|
|
4305
4363
|
if (typeof properties.x_google_ignoreList !== "undefined") this.x_google_ignoreList = properties.x_google_ignoreList;
|
|
4306
4364
|
if (typeof properties.debugId !== "undefined") this.debugId = properties.debugId;
|
|
4307
4365
|
}
|
|
4366
|
+
/**
|
|
4367
|
+
* Returns the equivalent of `JSON.stringify(map)`
|
|
4368
|
+
*/
|
|
4308
4369
|
toString() {
|
|
4309
4370
|
return JSON.stringify(this);
|
|
4310
4371
|
}
|
|
4372
|
+
/**
|
|
4373
|
+
* Returns a DataURI containing the sourcemap. Useful for doing this sort of thing:
|
|
4374
|
+
* `generateMap(options?: SourceMapOptions): SourceMap;`
|
|
4375
|
+
*/
|
|
4311
4376
|
toUrl() {
|
|
4312
|
-
return
|
|
4377
|
+
return `data:application/json;charset=utf-8;base64,${btoa$1(this.toString())}`;
|
|
4313
4378
|
}
|
|
4314
4379
|
};
|
|
4315
|
-
function guessIndent(code) {
|
|
4316
|
-
const lines = code.split("\n");
|
|
4317
|
-
const tabbed = lines.filter((line) => /^\t+/.test(line));
|
|
4318
|
-
const spaced = lines.filter((line) => /^ {2,}/.test(line));
|
|
4319
|
-
if (tabbed.length === 0 && spaced.length === 0) return null;
|
|
4320
|
-
if (tabbed.length >= spaced.length) return " ";
|
|
4321
|
-
const min = spaced.reduce((previous, current) => {
|
|
4322
|
-
const numSpaces = /^ +/.exec(current)[0].length;
|
|
4323
|
-
return Math.min(numSpaces, previous);
|
|
4324
|
-
}, Infinity);
|
|
4325
|
-
return new Array(min + 1).join(" ");
|
|
4326
|
-
}
|
|
4327
|
-
function getRelativePath(from, to) {
|
|
4328
|
-
const fromParts = from.split(/[/\\]/);
|
|
4329
|
-
const toParts = to.split(/[/\\]/);
|
|
4330
|
-
fromParts.pop();
|
|
4331
|
-
while (fromParts[0] === toParts[0]) {
|
|
4332
|
-
fromParts.shift();
|
|
4333
|
-
toParts.shift();
|
|
4334
|
-
}
|
|
4335
|
-
if (fromParts.length) {
|
|
4336
|
-
let i = fromParts.length;
|
|
4337
|
-
while (i--) fromParts[i] = "..";
|
|
4338
|
-
}
|
|
4339
|
-
return fromParts.concat(toParts).join("/");
|
|
4340
|
-
}
|
|
4341
|
-
const toString = Object.prototype.toString;
|
|
4342
|
-
function isObject(thing) {
|
|
4343
|
-
return toString.call(thing) === "[object Object]";
|
|
4344
|
-
}
|
|
4345
4380
|
function getLocator(source) {
|
|
4346
4381
|
const originalLines = source.split("\n");
|
|
4347
4382
|
const lineOffsets = [];
|
|
@@ -4364,6 +4399,36 @@ function getLocator(source) {
|
|
|
4364
4399
|
};
|
|
4365
4400
|
};
|
|
4366
4401
|
}
|
|
4402
|
+
function getRelativePath(from, to) {
|
|
4403
|
+
const fromParts = from.split(/[/\\]/);
|
|
4404
|
+
const toParts = to.split(/[/\\]/);
|
|
4405
|
+
fromParts.pop();
|
|
4406
|
+
while (fromParts[0] === toParts[0]) {
|
|
4407
|
+
fromParts.shift();
|
|
4408
|
+
toParts.shift();
|
|
4409
|
+
}
|
|
4410
|
+
if (fromParts.length) {
|
|
4411
|
+
let i = fromParts.length;
|
|
4412
|
+
while (i--) fromParts[i] = "..";
|
|
4413
|
+
}
|
|
4414
|
+
return fromParts.concat(toParts).join("/");
|
|
4415
|
+
}
|
|
4416
|
+
function guessIndent(code) {
|
|
4417
|
+
const lines = code.split("\n");
|
|
4418
|
+
const tabbed = lines.filter((line) => /^\t+/.test(line));
|
|
4419
|
+
const spaced = lines.filter((line) => /^ {2,}/.test(line));
|
|
4420
|
+
if (tabbed.length === 0 && spaced.length === 0) return null;
|
|
4421
|
+
if (tabbed.length >= spaced.length) return " ";
|
|
4422
|
+
const min = spaced.reduce((previous, current) => {
|
|
4423
|
+
const numSpaces = /^ +/.exec(current)[0].length;
|
|
4424
|
+
return Math.min(numSpaces, previous);
|
|
4425
|
+
}, Infinity);
|
|
4426
|
+
return " ".repeat(min);
|
|
4427
|
+
}
|
|
4428
|
+
const toString = Object.prototype.toString;
|
|
4429
|
+
function isObject(thing) {
|
|
4430
|
+
return toString.call(thing) === "[object Object]";
|
|
4431
|
+
}
|
|
4367
4432
|
const wordRegex = /\w/;
|
|
4368
4433
|
var Mappings = class {
|
|
4369
4434
|
constructor(hires) {
|
|
@@ -4463,6 +4528,8 @@ var Mappings = class {
|
|
|
4463
4528
|
}
|
|
4464
4529
|
};
|
|
4465
4530
|
const n = "\n";
|
|
4531
|
+
const NEWLINE_CHAR = "\n".charCodeAt(0);
|
|
4532
|
+
const CR_CHAR = "\r".charCodeAt(0);
|
|
4466
4533
|
const warned = {
|
|
4467
4534
|
insertLeft: false,
|
|
4468
4535
|
insertRight: false,
|
|
@@ -4533,35 +4600,54 @@ var MagicString = class MagicString {
|
|
|
4533
4600
|
value: options.offset || 0
|
|
4534
4601
|
}
|
|
4535
4602
|
});
|
|
4536
|
-
this.byStart[0
|
|
4537
|
-
this.byEnd[string.length
|
|
4603
|
+
this.byStart = /* @__PURE__ */ new Map([[0, chunk]]);
|
|
4604
|
+
this.byEnd = /* @__PURE__ */ new Map([[string.length, chunk]]);
|
|
4538
4605
|
}
|
|
4606
|
+
/**
|
|
4607
|
+
* Adds the specified character index (with respect to the original string) to sourcemap mappings, if `hires` is false.
|
|
4608
|
+
*/
|
|
4539
4609
|
addSourcemapLocation(char) {
|
|
4540
4610
|
this.sourcemapLocations.add(char);
|
|
4541
4611
|
}
|
|
4612
|
+
/**
|
|
4613
|
+
* Appends the specified content to the end of the string.
|
|
4614
|
+
*/
|
|
4542
4615
|
append(content) {
|
|
4543
4616
|
if (typeof content !== "string") throw new TypeError("outro content must be a string");
|
|
4544
4617
|
this.outro += content;
|
|
4545
4618
|
return this;
|
|
4546
4619
|
}
|
|
4620
|
+
/**
|
|
4621
|
+
* Appends the specified content at the index in the original string.
|
|
4622
|
+
* If a range *ending* with index is subsequently moved, the insert will be moved with it.
|
|
4623
|
+
* See also `s.prependLeft(...)`.
|
|
4624
|
+
*/
|
|
4547
4625
|
appendLeft(index, content) {
|
|
4548
4626
|
index = index + this.offset;
|
|
4549
4627
|
if (typeof content !== "string") throw new TypeError("inserted content must be a string");
|
|
4550
4628
|
this._split(index);
|
|
4551
|
-
const chunk = this.byEnd
|
|
4629
|
+
const chunk = this.byEnd.get(index);
|
|
4552
4630
|
if (chunk) chunk.appendLeft(content);
|
|
4553
4631
|
else this.intro += content;
|
|
4554
4632
|
return this;
|
|
4555
4633
|
}
|
|
4634
|
+
/**
|
|
4635
|
+
* Appends the specified content at the index in the original string.
|
|
4636
|
+
* If a range *starting* with index is subsequently moved, the insert will be moved with it.
|
|
4637
|
+
* See also `s.prependRight(...)`.
|
|
4638
|
+
*/
|
|
4556
4639
|
appendRight(index, content) {
|
|
4557
4640
|
index = index + this.offset;
|
|
4558
4641
|
if (typeof content !== "string") throw new TypeError("inserted content must be a string");
|
|
4559
4642
|
this._split(index);
|
|
4560
|
-
const chunk = this.byStart
|
|
4643
|
+
const chunk = this.byStart.get(index);
|
|
4561
4644
|
if (chunk) chunk.appendRight(content);
|
|
4562
4645
|
else this.outro += content;
|
|
4563
4646
|
return this;
|
|
4564
4647
|
}
|
|
4648
|
+
/**
|
|
4649
|
+
* Does what you'd expect.
|
|
4650
|
+
*/
|
|
4565
4651
|
clone() {
|
|
4566
4652
|
const cloned = new MagicString(this.original, {
|
|
4567
4653
|
filename: this.filename,
|
|
@@ -4570,8 +4656,8 @@ var MagicString = class MagicString {
|
|
|
4570
4656
|
let originalChunk = this.firstChunk;
|
|
4571
4657
|
let clonedChunk = cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone();
|
|
4572
4658
|
while (originalChunk) {
|
|
4573
|
-
cloned.byStart
|
|
4574
|
-
cloned.byEnd
|
|
4659
|
+
cloned.byStart.set(clonedChunk.start, clonedChunk);
|
|
4660
|
+
cloned.byEnd.set(clonedChunk.end, clonedChunk);
|
|
4575
4661
|
const nextOriginalChunk = originalChunk.next;
|
|
4576
4662
|
const nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
|
|
4577
4663
|
if (nextClonedChunk) {
|
|
@@ -4588,6 +4674,10 @@ var MagicString = class MagicString {
|
|
|
4588
4674
|
cloned.outro = this.outro;
|
|
4589
4675
|
return cloned;
|
|
4590
4676
|
}
|
|
4677
|
+
/**
|
|
4678
|
+
* Generates a sourcemap object with raw mappings in array form, rather than encoded as a string.
|
|
4679
|
+
* Useful if you need to manipulate the sourcemap further, but most of the time you will use `generateMap` instead.
|
|
4680
|
+
*/
|
|
4591
4681
|
generateDecodedMap(options) {
|
|
4592
4682
|
options = options || {};
|
|
4593
4683
|
const sourceIndex = 0;
|
|
@@ -4612,12 +4702,17 @@ var MagicString = class MagicString {
|
|
|
4612
4702
|
x_google_ignoreList: this.ignoreList ? [sourceIndex] : void 0
|
|
4613
4703
|
};
|
|
4614
4704
|
}
|
|
4705
|
+
/**
|
|
4706
|
+
* Generates a version 3 sourcemap.
|
|
4707
|
+
*/
|
|
4615
4708
|
generateMap(options) {
|
|
4616
4709
|
return new SourceMap(this.generateDecodedMap(options));
|
|
4617
4710
|
}
|
|
4711
|
+
/** @internal */
|
|
4618
4712
|
_ensureindentStr() {
|
|
4619
4713
|
if (this.indentStr === void 0) this.indentStr = guessIndent(this.original);
|
|
4620
4714
|
}
|
|
4715
|
+
/** @internal */
|
|
4621
4716
|
_getRawIndentString() {
|
|
4622
4717
|
this._ensureindentStr();
|
|
4623
4718
|
return this.indentStr;
|
|
@@ -4637,6 +4732,7 @@ var MagicString = class MagicString {
|
|
|
4637
4732
|
indentStr = this.indentStr || " ";
|
|
4638
4733
|
}
|
|
4639
4734
|
if (indentStr === "") return this;
|
|
4735
|
+
const resolvedIndentStr = indentStr;
|
|
4640
4736
|
options = options || {};
|
|
4641
4737
|
const isExcluded = {};
|
|
4642
4738
|
if (options.exclude) (typeof options.exclude[0] === "number" ? [options.exclude] : options.exclude).forEach((exclusion) => {
|
|
@@ -4644,13 +4740,22 @@ var MagicString = class MagicString {
|
|
|
4644
4740
|
});
|
|
4645
4741
|
let shouldIndentNextCharacter = options.indentStart !== false;
|
|
4646
4742
|
const replacer = (match) => {
|
|
4647
|
-
if (shouldIndentNextCharacter) return `${
|
|
4743
|
+
if (shouldIndentNextCharacter) return `${resolvedIndentStr}${match}`;
|
|
4648
4744
|
shouldIndentNextCharacter = true;
|
|
4649
4745
|
return match;
|
|
4650
4746
|
};
|
|
4651
4747
|
this.intro = this.intro.replace(pattern, replacer);
|
|
4652
4748
|
let charIndex = 0;
|
|
4653
4749
|
let chunk = this.firstChunk;
|
|
4750
|
+
const indentAt = (index) => {
|
|
4751
|
+
shouldIndentNextCharacter = false;
|
|
4752
|
+
if (index === chunk.start) chunk.prependRight(resolvedIndentStr);
|
|
4753
|
+
else {
|
|
4754
|
+
this._splitChunk(chunk, index);
|
|
4755
|
+
chunk = chunk.next;
|
|
4756
|
+
chunk.prependRight(resolvedIndentStr);
|
|
4757
|
+
}
|
|
4758
|
+
};
|
|
4654
4759
|
while (chunk) {
|
|
4655
4760
|
const end = chunk.end;
|
|
4656
4761
|
if (chunk.edited) {
|
|
@@ -4658,22 +4763,32 @@ var MagicString = class MagicString {
|
|
|
4658
4763
|
chunk.content = chunk.content.replace(pattern, replacer);
|
|
4659
4764
|
if (chunk.content.length) shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === "\n";
|
|
4660
4765
|
}
|
|
4661
|
-
} else {
|
|
4766
|
+
} else if (options.exclude) {
|
|
4662
4767
|
charIndex = chunk.start;
|
|
4663
4768
|
while (charIndex < end) {
|
|
4664
4769
|
if (!isExcluded[charIndex]) {
|
|
4665
|
-
const char = this.original
|
|
4666
|
-
if (char ===
|
|
4667
|
-
else if (char !==
|
|
4668
|
-
|
|
4669
|
-
|
|
4670
|
-
|
|
4671
|
-
|
|
4672
|
-
|
|
4673
|
-
|
|
4674
|
-
|
|
4675
|
-
|
|
4770
|
+
const char = this.original.charCodeAt(charIndex);
|
|
4771
|
+
if (char === NEWLINE_CHAR) shouldIndentNextCharacter = true;
|
|
4772
|
+
else if (char !== CR_CHAR && shouldIndentNextCharacter) indentAt(charIndex);
|
|
4773
|
+
}
|
|
4774
|
+
charIndex += 1;
|
|
4775
|
+
}
|
|
4776
|
+
} else {
|
|
4777
|
+
charIndex = chunk.start;
|
|
4778
|
+
while (charIndex < end) {
|
|
4779
|
+
if (!shouldIndentNextCharacter) {
|
|
4780
|
+
const nextLine = this.original.indexOf(n, charIndex);
|
|
4781
|
+
if (nextLine === -1 || nextLine >= end) break;
|
|
4782
|
+
shouldIndentNextCharacter = true;
|
|
4783
|
+
charIndex = nextLine + 1;
|
|
4784
|
+
continue;
|
|
4785
|
+
}
|
|
4786
|
+
const char = this.original.charCodeAt(charIndex);
|
|
4787
|
+
if (char === NEWLINE_CHAR || char === CR_CHAR) {
|
|
4788
|
+
charIndex += 1;
|
|
4789
|
+
continue;
|
|
4676
4790
|
}
|
|
4791
|
+
indentAt(charIndex);
|
|
4677
4792
|
charIndex += 1;
|
|
4678
4793
|
}
|
|
4679
4794
|
}
|
|
@@ -4683,9 +4798,11 @@ var MagicString = class MagicString {
|
|
|
4683
4798
|
this.outro = this.outro.replace(pattern, replacer);
|
|
4684
4799
|
return this;
|
|
4685
4800
|
}
|
|
4801
|
+
/** @internal */
|
|
4686
4802
|
insert() {
|
|
4687
4803
|
throw new Error("magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)");
|
|
4688
4804
|
}
|
|
4805
|
+
/** @internal */
|
|
4689
4806
|
insertLeft(index, content) {
|
|
4690
4807
|
if (!warned.insertLeft) {
|
|
4691
4808
|
console.warn("magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead");
|
|
@@ -4693,6 +4810,7 @@ var MagicString = class MagicString {
|
|
|
4693
4810
|
}
|
|
4694
4811
|
return this.appendLeft(index, content);
|
|
4695
4812
|
}
|
|
4813
|
+
/** @internal */
|
|
4696
4814
|
insertRight(index, content) {
|
|
4697
4815
|
if (!warned.insertRight) {
|
|
4698
4816
|
console.warn("magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead");
|
|
@@ -4700,19 +4818,23 @@ var MagicString = class MagicString {
|
|
|
4700
4818
|
}
|
|
4701
4819
|
return this.prependRight(index, content);
|
|
4702
4820
|
}
|
|
4821
|
+
/**
|
|
4822
|
+
* Moves the characters from `start` and `end` to `index`.
|
|
4823
|
+
*/
|
|
4703
4824
|
move(start, end, index) {
|
|
4704
4825
|
start = start + this.offset;
|
|
4705
4826
|
end = end + this.offset;
|
|
4706
4827
|
index = index + this.offset;
|
|
4828
|
+
if (start === end) return this;
|
|
4707
4829
|
if (index >= start && index <= end) throw new Error("Cannot move a selection inside itself");
|
|
4708
4830
|
this._split(start);
|
|
4709
4831
|
this._split(end);
|
|
4710
4832
|
this._split(index);
|
|
4711
|
-
const first = this.byStart
|
|
4712
|
-
const last = this.byEnd
|
|
4833
|
+
const first = this.byStart.get(start);
|
|
4834
|
+
const last = this.byEnd.get(end);
|
|
4713
4835
|
const oldLeft = first.previous;
|
|
4714
4836
|
const oldRight = last.next;
|
|
4715
|
-
const newRight = this.byStart
|
|
4837
|
+
const newRight = this.byStart.get(index);
|
|
4716
4838
|
if (!newRight && last === this.lastChunk) return this;
|
|
4717
4839
|
const newLeft = newRight ? newRight.previous : this.lastChunk;
|
|
4718
4840
|
if (oldLeft) oldLeft.next = oldRight;
|
|
@@ -4730,13 +4852,30 @@ var MagicString = class MagicString {
|
|
|
4730
4852
|
if (!newRight) this.lastChunk = last;
|
|
4731
4853
|
return this;
|
|
4732
4854
|
}
|
|
4855
|
+
/**
|
|
4856
|
+
* Replaces the characters from `start` to `end` with `content`, along with the appended/prepended content in
|
|
4857
|
+
* that range. The same restrictions as `s.remove()` apply.
|
|
4858
|
+
*
|
|
4859
|
+
* The fourth argument is optional. It can have a storeName property - if true, the original name will be stored
|
|
4860
|
+
* for later inclusion in a sourcemap's names array - and a contentOnly property which determines whether only
|
|
4861
|
+
* the content is overwritten, or anything that was appended/prepended to the range as well.
|
|
4862
|
+
*
|
|
4863
|
+
* It may be preferred to use `s.update(...)` instead if you wish to avoid overwriting the appended/prepended content.
|
|
4864
|
+
*/
|
|
4733
4865
|
overwrite(start, end, content, options) {
|
|
4734
|
-
|
|
4866
|
+
const optionObject = typeof options === "object" && options ? options : {};
|
|
4735
4867
|
return this.update(start, end, content, {
|
|
4736
|
-
...
|
|
4737
|
-
overwrite: !
|
|
4868
|
+
...optionObject,
|
|
4869
|
+
overwrite: !optionObject.contentOnly
|
|
4738
4870
|
});
|
|
4739
4871
|
}
|
|
4872
|
+
/**
|
|
4873
|
+
* Replaces the characters from `start` to `end` with `content`. The same restrictions as `s.remove()` apply.
|
|
4874
|
+
*
|
|
4875
|
+
* The fourth argument is optional. It can have a storeName property - if true, the original name will be stored
|
|
4876
|
+
* for later inclusion in a sourcemap's names array - and an overwrite property which determines whether only
|
|
4877
|
+
* the content is overwritten, or anything that was appended/prepended to the range as well.
|
|
4878
|
+
*/
|
|
4740
4879
|
update(start, end, content, options) {
|
|
4741
4880
|
start = start + this.offset;
|
|
4742
4881
|
end = end + this.offset;
|
|
@@ -4756,8 +4895,9 @@ var MagicString = class MagicString {
|
|
|
4756
4895
|
}
|
|
4757
4896
|
options = { storeName: true };
|
|
4758
4897
|
}
|
|
4759
|
-
const
|
|
4760
|
-
const
|
|
4898
|
+
const optionObject = typeof options === "object" && options ? options : {};
|
|
4899
|
+
const storeName = optionObject.storeName || false;
|
|
4900
|
+
const overwrite = optionObject.overwrite || false;
|
|
4761
4901
|
if (storeName) {
|
|
4762
4902
|
const original = this.original.slice(start, end);
|
|
4763
4903
|
Object.defineProperty(this.storedNames, original, {
|
|
@@ -4766,12 +4906,12 @@ var MagicString = class MagicString {
|
|
|
4766
4906
|
enumerable: true
|
|
4767
4907
|
});
|
|
4768
4908
|
}
|
|
4769
|
-
const first = this.byStart
|
|
4770
|
-
const last = this.byEnd
|
|
4909
|
+
const first = this.byStart.get(start);
|
|
4910
|
+
const last = this.byEnd.get(end);
|
|
4771
4911
|
if (first) {
|
|
4772
4912
|
let chunk = first;
|
|
4773
4913
|
while (chunk !== last) {
|
|
4774
|
-
if (chunk.next !== this.byStart
|
|
4914
|
+
if (chunk.next !== this.byStart.get(chunk.end)) throw new Error("Cannot overwrite across a split point");
|
|
4775
4915
|
chunk = chunk.next;
|
|
4776
4916
|
chunk.edit("", false);
|
|
4777
4917
|
}
|
|
@@ -4783,29 +4923,42 @@ var MagicString = class MagicString {
|
|
|
4783
4923
|
}
|
|
4784
4924
|
return this;
|
|
4785
4925
|
}
|
|
4926
|
+
/**
|
|
4927
|
+
* Prepends the string with the specified content.
|
|
4928
|
+
*/
|
|
4786
4929
|
prepend(content) {
|
|
4787
4930
|
if (typeof content !== "string") throw new TypeError("outro content must be a string");
|
|
4788
4931
|
this.intro = content + this.intro;
|
|
4789
4932
|
return this;
|
|
4790
4933
|
}
|
|
4934
|
+
/**
|
|
4935
|
+
* Same as `s.appendLeft(...)`, except that the inserted content will go *before* any previous appends or prepends at index
|
|
4936
|
+
*/
|
|
4791
4937
|
prependLeft(index, content) {
|
|
4792
4938
|
index = index + this.offset;
|
|
4793
4939
|
if (typeof content !== "string") throw new TypeError("inserted content must be a string");
|
|
4794
4940
|
this._split(index);
|
|
4795
|
-
const chunk = this.byEnd
|
|
4941
|
+
const chunk = this.byEnd.get(index);
|
|
4796
4942
|
if (chunk) chunk.prependLeft(content);
|
|
4797
4943
|
else this.intro = content + this.intro;
|
|
4798
4944
|
return this;
|
|
4799
4945
|
}
|
|
4946
|
+
/**
|
|
4947
|
+
* Same as `s.appendRight(...)`, except that the inserted content will go *before* any previous appends or prepends at `index`
|
|
4948
|
+
*/
|
|
4800
4949
|
prependRight(index, content) {
|
|
4801
4950
|
index = index + this.offset;
|
|
4802
4951
|
if (typeof content !== "string") throw new TypeError("inserted content must be a string");
|
|
4803
4952
|
this._split(index);
|
|
4804
|
-
const chunk = this.byStart
|
|
4953
|
+
const chunk = this.byStart.get(index);
|
|
4805
4954
|
if (chunk) chunk.prependRight(content);
|
|
4806
4955
|
else this.outro = content + this.outro;
|
|
4807
4956
|
return this;
|
|
4808
4957
|
}
|
|
4958
|
+
/**
|
|
4959
|
+
* Removes the characters from `start` to `end` (of the original string, **not** the generated string).
|
|
4960
|
+
* Removing the same content twice, or making removals that partially overlap, will cause an error.
|
|
4961
|
+
*/
|
|
4809
4962
|
remove(start, end) {
|
|
4810
4963
|
start = start + this.offset;
|
|
4811
4964
|
end = end + this.offset;
|
|
@@ -4818,15 +4971,18 @@ var MagicString = class MagicString {
|
|
|
4818
4971
|
if (start > end) throw new Error("end must be greater than start");
|
|
4819
4972
|
this._split(start);
|
|
4820
4973
|
this._split(end);
|
|
4821
|
-
let chunk = this.byStart
|
|
4974
|
+
let chunk = this.byStart.get(start);
|
|
4822
4975
|
while (chunk) {
|
|
4823
4976
|
chunk.intro = "";
|
|
4824
4977
|
chunk.outro = "";
|
|
4825
4978
|
chunk.edit("");
|
|
4826
|
-
chunk = end > chunk.end ? this.byStart
|
|
4979
|
+
chunk = end > chunk.end ? this.byStart.get(chunk.end) : null;
|
|
4827
4980
|
}
|
|
4828
4981
|
return this;
|
|
4829
4982
|
}
|
|
4983
|
+
/**
|
|
4984
|
+
* Reset the modified characters from `start` to `end` (of the original string, **not** the generated string).
|
|
4985
|
+
*/
|
|
4830
4986
|
reset(start, end) {
|
|
4831
4987
|
start = start + this.offset;
|
|
4832
4988
|
end = end + this.offset;
|
|
@@ -4839,21 +4995,22 @@ var MagicString = class MagicString {
|
|
|
4839
4995
|
if (start > end) throw new Error("end must be greater than start");
|
|
4840
4996
|
this._split(start);
|
|
4841
4997
|
this._split(end);
|
|
4842
|
-
let chunk = this.byStart
|
|
4998
|
+
let chunk = this.byStart.get(start);
|
|
4843
4999
|
while (chunk) {
|
|
4844
5000
|
chunk.reset();
|
|
4845
|
-
chunk = end > chunk.end ? this.byStart
|
|
5001
|
+
chunk = end > chunk.end ? this.byStart.get(chunk.end) : null;
|
|
4846
5002
|
}
|
|
4847
5003
|
return this;
|
|
4848
5004
|
}
|
|
4849
5005
|
lastChar() {
|
|
4850
5006
|
if (this.outro.length) return this.outro[this.outro.length - 1];
|
|
4851
5007
|
let chunk = this.lastChunk;
|
|
4852
|
-
|
|
5008
|
+
while (chunk) {
|
|
4853
5009
|
if (chunk.outro.length) return chunk.outro[chunk.outro.length - 1];
|
|
4854
5010
|
if (chunk.content.length) return chunk.content[chunk.content.length - 1];
|
|
4855
5011
|
if (chunk.intro.length) return chunk.intro[chunk.intro.length - 1];
|
|
4856
|
-
|
|
5012
|
+
chunk = chunk.previous;
|
|
5013
|
+
}
|
|
4857
5014
|
if (this.intro.length) return this.intro[this.intro.length - 1];
|
|
4858
5015
|
return "";
|
|
4859
5016
|
}
|
|
@@ -4862,7 +5019,7 @@ var MagicString = class MagicString {
|
|
|
4862
5019
|
if (lineIndex !== -1) return this.outro.substr(lineIndex + 1);
|
|
4863
5020
|
let lineStr = this.outro;
|
|
4864
5021
|
let chunk = this.lastChunk;
|
|
4865
|
-
|
|
5022
|
+
while (chunk) {
|
|
4866
5023
|
if (chunk.outro.length > 0) {
|
|
4867
5024
|
lineIndex = chunk.outro.lastIndexOf(n);
|
|
4868
5025
|
if (lineIndex !== -1) return chunk.outro.substr(lineIndex + 1) + lineStr;
|
|
@@ -4878,11 +5035,16 @@ var MagicString = class MagicString {
|
|
|
4878
5035
|
if (lineIndex !== -1) return chunk.intro.substr(lineIndex + 1) + lineStr;
|
|
4879
5036
|
lineStr = chunk.intro + lineStr;
|
|
4880
5037
|
}
|
|
4881
|
-
|
|
5038
|
+
chunk = chunk.previous;
|
|
5039
|
+
}
|
|
4882
5040
|
lineIndex = this.intro.lastIndexOf(n);
|
|
4883
5041
|
if (lineIndex !== -1) return this.intro.substr(lineIndex + 1) + lineStr;
|
|
4884
5042
|
return this.intro + lineStr;
|
|
4885
5043
|
}
|
|
5044
|
+
/**
|
|
5045
|
+
* Returns the content of the generated string that corresponds to the slice between `start` and `end` of the original string.
|
|
5046
|
+
* Throws error if the indices are for characters that were already removed.
|
|
5047
|
+
*/
|
|
4886
5048
|
slice(start = 0, end = this.original.length - this.offset) {
|
|
4887
5049
|
start = start + this.offset;
|
|
4888
5050
|
end = end + this.offset;
|
|
@@ -4911,37 +5073,45 @@ var MagicString = class MagicString {
|
|
|
4911
5073
|
}
|
|
4912
5074
|
return result;
|
|
4913
5075
|
}
|
|
5076
|
+
/**
|
|
5077
|
+
* Returns a clone of `s`, with all content before the `start` and `end` characters of the original string removed.
|
|
5078
|
+
*/
|
|
4914
5079
|
snip(start, end) {
|
|
4915
5080
|
const clone = this.clone();
|
|
4916
5081
|
clone.remove(0, start);
|
|
4917
5082
|
clone.remove(end, clone.original.length);
|
|
4918
5083
|
return clone;
|
|
4919
5084
|
}
|
|
5085
|
+
/** @internal */
|
|
4920
5086
|
_split(index) {
|
|
4921
|
-
if (this.byStart
|
|
5087
|
+
if (this.byStart.get(index) || this.byEnd.get(index)) return;
|
|
4922
5088
|
let chunk = this.lastSearchedChunk;
|
|
4923
5089
|
let previousChunk = chunk;
|
|
4924
5090
|
const searchForward = index > chunk.end;
|
|
4925
5091
|
while (chunk) {
|
|
4926
5092
|
if (chunk.contains(index)) return this._splitChunk(chunk, index);
|
|
4927
|
-
chunk = searchForward ? this.byStart
|
|
5093
|
+
chunk = searchForward ? this.byStart.get(chunk.end) : this.byEnd.get(chunk.start);
|
|
4928
5094
|
if (chunk === previousChunk) return;
|
|
4929
5095
|
previousChunk = chunk;
|
|
4930
5096
|
}
|
|
4931
5097
|
}
|
|
5098
|
+
/** @internal */
|
|
4932
5099
|
_splitChunk(chunk, index) {
|
|
4933
5100
|
if (chunk.edited && chunk.content.length) {
|
|
4934
5101
|
const loc = getLocator(this.original)(index);
|
|
4935
5102
|
throw new Error(`Cannot split a chunk that has already been edited (${loc.line}:${loc.column} – "${chunk.original}")`);
|
|
4936
5103
|
}
|
|
4937
5104
|
const newChunk = chunk.split(index);
|
|
4938
|
-
this.byEnd
|
|
4939
|
-
this.byStart
|
|
4940
|
-
this.byEnd
|
|
5105
|
+
this.byEnd.set(index, chunk);
|
|
5106
|
+
this.byStart.set(index, newChunk);
|
|
5107
|
+
this.byEnd.set(newChunk.end, newChunk);
|
|
4941
5108
|
if (chunk === this.lastChunk) this.lastChunk = newChunk;
|
|
4942
5109
|
this.lastSearchedChunk = chunk;
|
|
4943
5110
|
return true;
|
|
4944
5111
|
}
|
|
5112
|
+
/**
|
|
5113
|
+
* Returns the generated string.
|
|
5114
|
+
*/
|
|
4945
5115
|
toString() {
|
|
4946
5116
|
let str = this.intro;
|
|
4947
5117
|
let chunk = this.firstChunk;
|
|
@@ -4951,29 +5121,41 @@ var MagicString = class MagicString {
|
|
|
4951
5121
|
}
|
|
4952
5122
|
return str + this.outro;
|
|
4953
5123
|
}
|
|
5124
|
+
/**
|
|
5125
|
+
* Returns true if the resulting source is empty (disregarding white space).
|
|
5126
|
+
*/
|
|
4954
5127
|
isEmpty() {
|
|
4955
5128
|
let chunk = this.firstChunk;
|
|
4956
|
-
|
|
5129
|
+
while (chunk) {
|
|
4957
5130
|
if (chunk.intro.length && chunk.intro.trim() || chunk.content.length && chunk.content.trim() || chunk.outro.length && chunk.outro.trim()) return false;
|
|
4958
|
-
|
|
5131
|
+
chunk = chunk.next;
|
|
5132
|
+
}
|
|
4959
5133
|
return true;
|
|
4960
5134
|
}
|
|
4961
5135
|
length() {
|
|
4962
5136
|
let chunk = this.firstChunk;
|
|
4963
5137
|
let length = 0;
|
|
4964
|
-
|
|
5138
|
+
while (chunk) {
|
|
4965
5139
|
length += chunk.intro.length + chunk.content.length + chunk.outro.length;
|
|
4966
|
-
|
|
5140
|
+
chunk = chunk.next;
|
|
5141
|
+
}
|
|
4967
5142
|
return length;
|
|
4968
5143
|
}
|
|
5144
|
+
/**
|
|
5145
|
+
* Removes empty lines from the start and end.
|
|
5146
|
+
*/
|
|
4969
5147
|
trimLines() {
|
|
4970
5148
|
return this.trim("[\\r\\n]");
|
|
4971
5149
|
}
|
|
5150
|
+
/**
|
|
5151
|
+
* Trims content matching `charType` (defaults to `\s`, i.e. whitespace) from the start and end.
|
|
5152
|
+
*/
|
|
4972
5153
|
trim(charType) {
|
|
4973
5154
|
return this.trimStart(charType).trimEnd(charType);
|
|
4974
5155
|
}
|
|
5156
|
+
/** @internal */
|
|
4975
5157
|
trimEndAborted(charType) {
|
|
4976
|
-
const rx = new RegExp(
|
|
5158
|
+
const rx = new RegExp(`${charType || "\\s"}+$`);
|
|
4977
5159
|
this.outro = this.outro.replace(rx, "");
|
|
4978
5160
|
if (this.outro.length) return true;
|
|
4979
5161
|
let chunk = this.lastChunk;
|
|
@@ -4982,21 +5164,25 @@ var MagicString = class MagicString {
|
|
|
4982
5164
|
const aborted = chunk.trimEnd(rx);
|
|
4983
5165
|
if (chunk.end !== end) {
|
|
4984
5166
|
if (this.lastChunk === chunk) this.lastChunk = chunk.next;
|
|
4985
|
-
this.byEnd
|
|
4986
|
-
this.byStart
|
|
4987
|
-
this.byEnd
|
|
5167
|
+
this.byEnd.set(chunk.end, chunk);
|
|
5168
|
+
this.byStart.set(chunk.next.start, chunk.next);
|
|
5169
|
+
this.byEnd.set(chunk.next.end, chunk.next);
|
|
4988
5170
|
}
|
|
4989
5171
|
if (aborted) return true;
|
|
4990
5172
|
chunk = chunk.previous;
|
|
4991
5173
|
} while (chunk);
|
|
4992
5174
|
return false;
|
|
4993
5175
|
}
|
|
5176
|
+
/**
|
|
5177
|
+
* Trims content matching `charType` (defaults to `\s`, i.e. whitespace) from the end.
|
|
5178
|
+
*/
|
|
4994
5179
|
trimEnd(charType) {
|
|
4995
5180
|
this.trimEndAborted(charType);
|
|
4996
5181
|
return this;
|
|
4997
5182
|
}
|
|
5183
|
+
/** @internal */
|
|
4998
5184
|
trimStartAborted(charType) {
|
|
4999
|
-
const rx = new RegExp(
|
|
5185
|
+
const rx = new RegExp(`^${charType || "\\s"}+`);
|
|
5000
5186
|
this.intro = this.intro.replace(rx, "");
|
|
5001
5187
|
if (this.intro.length) return true;
|
|
5002
5188
|
let chunk = this.firstChunk;
|
|
@@ -5005,22 +5191,29 @@ var MagicString = class MagicString {
|
|
|
5005
5191
|
const aborted = chunk.trimStart(rx);
|
|
5006
5192
|
if (chunk.end !== end) {
|
|
5007
5193
|
if (chunk === this.lastChunk) this.lastChunk = chunk.next;
|
|
5008
|
-
this.byEnd
|
|
5009
|
-
this.byStart
|
|
5010
|
-
this.byEnd
|
|
5194
|
+
this.byEnd.set(chunk.end, chunk);
|
|
5195
|
+
this.byStart.set(chunk.next.start, chunk.next);
|
|
5196
|
+
this.byEnd.set(chunk.next.end, chunk.next);
|
|
5011
5197
|
}
|
|
5012
5198
|
if (aborted) return true;
|
|
5013
5199
|
chunk = chunk.next;
|
|
5014
5200
|
} while (chunk);
|
|
5015
5201
|
return false;
|
|
5016
5202
|
}
|
|
5203
|
+
/**
|
|
5204
|
+
* Trims content matching `charType` (defaults to `\s`, i.e. whitespace) from the start.
|
|
5205
|
+
*/
|
|
5017
5206
|
trimStart(charType) {
|
|
5018
5207
|
this.trimStartAborted(charType);
|
|
5019
5208
|
return this;
|
|
5020
5209
|
}
|
|
5210
|
+
/**
|
|
5211
|
+
* Indicates if the string has been changed.
|
|
5212
|
+
*/
|
|
5021
5213
|
hasChanged() {
|
|
5022
5214
|
return this.original !== this.toString();
|
|
5023
5215
|
}
|
|
5216
|
+
/** @internal */
|
|
5024
5217
|
_replaceRegexp(searchValue, replacement) {
|
|
5025
5218
|
function getReplacement(match, str) {
|
|
5026
5219
|
if (typeof replacement === "string") return replacement.replace(/\$(\$|&|\d+)/g, (_, i) => {
|
|
@@ -5029,12 +5222,15 @@ var MagicString = class MagicString {
|
|
|
5029
5222
|
if (+i < match.length) return match[+i];
|
|
5030
5223
|
return `$${i}`;
|
|
5031
5224
|
});
|
|
5032
|
-
else return replacement(...match, match.index, str, match.groups);
|
|
5225
|
+
else return replacement(match[0], ...match.slice(1), match.index, str, match.groups);
|
|
5033
5226
|
}
|
|
5034
5227
|
function matchAll(re, str) {
|
|
5035
|
-
let match;
|
|
5036
5228
|
const matches = [];
|
|
5037
|
-
while (
|
|
5229
|
+
while (true) {
|
|
5230
|
+
const match = re.exec(str);
|
|
5231
|
+
if (!match) break;
|
|
5232
|
+
matches.push(match);
|
|
5233
|
+
}
|
|
5038
5234
|
return matches;
|
|
5039
5235
|
}
|
|
5040
5236
|
if (searchValue.global) matchAll(searchValue, this.original).forEach((match) => {
|
|
@@ -5052,6 +5248,7 @@ var MagicString = class MagicString {
|
|
|
5052
5248
|
}
|
|
5053
5249
|
return this;
|
|
5054
5250
|
}
|
|
5251
|
+
/** @internal */
|
|
5055
5252
|
_replaceString(string, replacement) {
|
|
5056
5253
|
const { original } = this;
|
|
5057
5254
|
const index = original.indexOf(string);
|
|
@@ -5061,21 +5258,27 @@ var MagicString = class MagicString {
|
|
|
5061
5258
|
}
|
|
5062
5259
|
return this;
|
|
5063
5260
|
}
|
|
5261
|
+
/**
|
|
5262
|
+
* String replacement with RegExp or string.
|
|
5263
|
+
*/
|
|
5064
5264
|
replace(searchValue, replacement) {
|
|
5065
5265
|
if (typeof searchValue === "string") return this._replaceString(searchValue, replacement);
|
|
5066
5266
|
return this._replaceRegexp(searchValue, replacement);
|
|
5067
5267
|
}
|
|
5268
|
+
/** @internal */
|
|
5068
5269
|
_replaceAllString(string, replacement) {
|
|
5069
5270
|
const { original } = this;
|
|
5070
5271
|
const stringLength = string.length;
|
|
5071
5272
|
for (let index = original.indexOf(string); index !== -1; index = original.indexOf(string, index + stringLength)) {
|
|
5072
5273
|
const previous = original.slice(index, index + stringLength);
|
|
5073
|
-
|
|
5074
|
-
if (typeof replacement === "function") _replacement = replacement(previous, index, original);
|
|
5274
|
+
const _replacement = typeof replacement === "function" ? replacement(previous, index, original) : replacement;
|
|
5075
5275
|
if (previous !== _replacement) this.overwrite(index, index + stringLength, _replacement);
|
|
5076
5276
|
}
|
|
5077
5277
|
return this;
|
|
5078
5278
|
}
|
|
5279
|
+
/**
|
|
5280
|
+
* Same as `s.replace`, but replace all matched strings instead of just one.
|
|
5281
|
+
*/
|
|
5079
5282
|
replaceAll(searchValue, replacement) {
|
|
5080
5283
|
if (typeof searchValue === "string") return this._replaceAllString(searchValue, replacement);
|
|
5081
5284
|
if (!searchValue.global) throw new TypeError("MagicString.prototype.replaceAll called with a non-global RegExp argument");
|
|
@@ -11628,7 +11831,276 @@ var SSRCompatModuleRunner = class extends ModuleRunner {
|
|
|
11628
11831
|
}
|
|
11629
11832
|
};
|
|
11630
11833
|
//#endregion
|
|
11834
|
+
//#region ../../node_modules/.pnpm/zimmerframe@1.1.4/node_modules/zimmerframe/src/walk.js
|
|
11835
|
+
/** @import { Context, Visitor, Visitors } from './types.js' */
|
|
11836
|
+
/**
|
|
11837
|
+
* @template {{ type: string }} T
|
|
11838
|
+
* @template {Record<string, any> | null} U
|
|
11839
|
+
* @param {T} node
|
|
11840
|
+
* @param {U} state
|
|
11841
|
+
* @param {Visitors<T, U>} visitors
|
|
11842
|
+
*/
|
|
11843
|
+
function walk$2(node, state, visitors) {
|
|
11844
|
+
const universal = visitors._;
|
|
11845
|
+
let stopped = false;
|
|
11846
|
+
/** @type {Visitor<T, U, T>} _ */
|
|
11847
|
+
function default_visitor(_, { next, state }) {
|
|
11848
|
+
next(state);
|
|
11849
|
+
}
|
|
11850
|
+
/**
|
|
11851
|
+
* @param {T} node
|
|
11852
|
+
* @param {T[]} path
|
|
11853
|
+
* @param {U} state
|
|
11854
|
+
* @returns {T | undefined}
|
|
11855
|
+
*/
|
|
11856
|
+
function visit(node, path, state) {
|
|
11857
|
+
if (stopped) return;
|
|
11858
|
+
if (!node.type) return;
|
|
11859
|
+
/** @type {T | void} */
|
|
11860
|
+
let result;
|
|
11861
|
+
/** @type {Record<string, any>} */
|
|
11862
|
+
const mutations = {};
|
|
11863
|
+
/** @type {Context<T, U>} */
|
|
11864
|
+
const context = {
|
|
11865
|
+
path,
|
|
11866
|
+
state,
|
|
11867
|
+
next: (next_state = state) => {
|
|
11868
|
+
path.push(node);
|
|
11869
|
+
for (const key in node) {
|
|
11870
|
+
if (key === "type") continue;
|
|
11871
|
+
const child_node = node[key];
|
|
11872
|
+
if (child_node && typeof child_node === "object") if (Array.isArray(child_node)) {
|
|
11873
|
+
/** @type {Record<number, T>} */
|
|
11874
|
+
const array_mutations = {};
|
|
11875
|
+
const len = child_node.length;
|
|
11876
|
+
let mutated = false;
|
|
11877
|
+
for (let i = 0; i < len; i++) {
|
|
11878
|
+
const node = child_node[i];
|
|
11879
|
+
if (node && typeof node === "object") {
|
|
11880
|
+
const result = visit(node, path, next_state);
|
|
11881
|
+
if (result) {
|
|
11882
|
+
array_mutations[i] = result;
|
|
11883
|
+
mutated = true;
|
|
11884
|
+
}
|
|
11885
|
+
}
|
|
11886
|
+
}
|
|
11887
|
+
if (mutated) mutations[key] = child_node.map((node, i) => array_mutations[i] ?? node);
|
|
11888
|
+
} else {
|
|
11889
|
+
const result = visit(child_node, path, next_state);
|
|
11890
|
+
if (result) mutations[key] = result;
|
|
11891
|
+
}
|
|
11892
|
+
}
|
|
11893
|
+
path.pop();
|
|
11894
|
+
if (Object.keys(mutations).length > 0) return apply_mutations(node, mutations);
|
|
11895
|
+
},
|
|
11896
|
+
stop: () => {
|
|
11897
|
+
stopped = true;
|
|
11898
|
+
},
|
|
11899
|
+
visit: (next_node, next_state = state) => {
|
|
11900
|
+
path.push(node);
|
|
11901
|
+
const result = visit(next_node, path, next_state) ?? next_node;
|
|
11902
|
+
path.pop();
|
|
11903
|
+
return result;
|
|
11904
|
+
}
|
|
11905
|
+
};
|
|
11906
|
+
let visitor = visitors[node.type] ?? default_visitor;
|
|
11907
|
+
if (universal) {
|
|
11908
|
+
/** @type {T | void} */
|
|
11909
|
+
let inner_result;
|
|
11910
|
+
result = universal(node, {
|
|
11911
|
+
...context,
|
|
11912
|
+
/** @param {U} next_state */
|
|
11913
|
+
next: (next_state = state) => {
|
|
11914
|
+
state = next_state;
|
|
11915
|
+
inner_result = visitor(node, {
|
|
11916
|
+
...context,
|
|
11917
|
+
state: next_state
|
|
11918
|
+
});
|
|
11919
|
+
return inner_result;
|
|
11920
|
+
}
|
|
11921
|
+
});
|
|
11922
|
+
if (!result && inner_result) result = inner_result;
|
|
11923
|
+
} else result = visitor(node, context);
|
|
11924
|
+
if (!result) {
|
|
11925
|
+
if (Object.keys(mutations).length > 0) result = apply_mutations(node, mutations);
|
|
11926
|
+
}
|
|
11927
|
+
if (result) return result;
|
|
11928
|
+
}
|
|
11929
|
+
return visit(node, [], state) ?? node;
|
|
11930
|
+
}
|
|
11931
|
+
/**
|
|
11932
|
+
* @template {Record<string, any>} T
|
|
11933
|
+
* @param {T} node
|
|
11934
|
+
* @param {Record<string, any>} mutations
|
|
11935
|
+
* @returns {T}
|
|
11936
|
+
*/
|
|
11937
|
+
function apply_mutations(node, mutations) {
|
|
11938
|
+
/** @type {Record<string, any>} */
|
|
11939
|
+
const obj = {};
|
|
11940
|
+
const descriptors = Object.getOwnPropertyDescriptors(node);
|
|
11941
|
+
for (const key in descriptors) Object.defineProperty(obj, key, descriptors[key]);
|
|
11942
|
+
for (const key in mutations) obj[key] = mutations[key];
|
|
11943
|
+
return obj;
|
|
11944
|
+
}
|
|
11945
|
+
//#endregion
|
|
11946
|
+
//#region ../../node_modules/.pnpm/is-reference@3.0.3/node_modules/is-reference/src/index.js
|
|
11947
|
+
/** @import { Node } from 'estree' */
|
|
11948
|
+
/**
|
|
11949
|
+
* @param {Node} node
|
|
11950
|
+
* @param {Node} parent
|
|
11951
|
+
* @returns {boolean}
|
|
11952
|
+
*/
|
|
11953
|
+
function is_reference(node, parent) {
|
|
11954
|
+
if (node.type === "MemberExpression") return !node.computed && is_reference(node.object, node);
|
|
11955
|
+
if (node.type !== "Identifier") return false;
|
|
11956
|
+
switch (parent?.type) {
|
|
11957
|
+
case "MemberExpression": return parent.computed || node === parent.object;
|
|
11958
|
+
case "MethodDefinition": return parent.computed;
|
|
11959
|
+
case "MetaProperty": return parent.meta === node;
|
|
11960
|
+
case "PropertyDefinition": return parent.computed || node === parent.value;
|
|
11961
|
+
case "Property": return parent.computed || node === parent.value;
|
|
11962
|
+
case "ExportSpecifier":
|
|
11963
|
+
case "ImportSpecifier": return node === parent.local;
|
|
11964
|
+
case "LabeledStatement":
|
|
11965
|
+
case "BreakStatement":
|
|
11966
|
+
case "ContinueStatement": return false;
|
|
11967
|
+
default: return true;
|
|
11968
|
+
}
|
|
11969
|
+
}
|
|
11970
|
+
//#endregion
|
|
11631
11971
|
//#region ../../node_modules/.pnpm/periscopic@4.0.3/node_modules/periscopic/src/index.js
|
|
11972
|
+
/** @param {import('estree').Node} expression */
|
|
11973
|
+
function analyze(expression) {
|
|
11974
|
+
/** @typedef {import('estree').Node} Node */
|
|
11975
|
+
/** @type {WeakMap<Node, Scope>} */
|
|
11976
|
+
const map = /* @__PURE__ */ new WeakMap();
|
|
11977
|
+
/** @type {Map<string, Node>} */
|
|
11978
|
+
const globals = /* @__PURE__ */ new Map();
|
|
11979
|
+
const scope = new Scope(null, false);
|
|
11980
|
+
/** @type {[Scope, import('estree').Identifier][]} */
|
|
11981
|
+
const references = [];
|
|
11982
|
+
/** @type {Scope} */
|
|
11983
|
+
let current_scope = scope;
|
|
11984
|
+
/**
|
|
11985
|
+
* @param {import('estree').Node} node
|
|
11986
|
+
* @param {boolean} block
|
|
11987
|
+
*/
|
|
11988
|
+
function push(node, block) {
|
|
11989
|
+
map.set(node, current_scope = new Scope(current_scope, block));
|
|
11990
|
+
}
|
|
11991
|
+
walk$2(expression, null, { _(node, context) {
|
|
11992
|
+
switch (node.type) {
|
|
11993
|
+
case "Identifier":
|
|
11994
|
+
const parent = context.path.at(-1);
|
|
11995
|
+
if (parent && is_reference(node, parent)) references.push([current_scope, node]);
|
|
11996
|
+
return;
|
|
11997
|
+
case "ImportDefaultSpecifier":
|
|
11998
|
+
case "ImportSpecifier":
|
|
11999
|
+
current_scope.declarations.set(node.local.name, node);
|
|
12000
|
+
return;
|
|
12001
|
+
case "ExportNamedDeclaration":
|
|
12002
|
+
if (node.source) {
|
|
12003
|
+
map.set(node, current_scope = new Scope(current_scope, true));
|
|
12004
|
+
for (const specifier of node.specifiers) current_scope.declarations.set(specifier.local.name, specifier);
|
|
12005
|
+
return;
|
|
12006
|
+
}
|
|
12007
|
+
break;
|
|
12008
|
+
case "FunctionExpression":
|
|
12009
|
+
case "FunctionDeclaration":
|
|
12010
|
+
case "ArrowFunctionExpression":
|
|
12011
|
+
if (node.type === "FunctionDeclaration") {
|
|
12012
|
+
if (node.id) current_scope.declarations.set(node.id.name, node);
|
|
12013
|
+
push(node, false);
|
|
12014
|
+
} else {
|
|
12015
|
+
push(node, false);
|
|
12016
|
+
if (node.type === "FunctionExpression" && node.id) current_scope.declarations.set(node.id.name, node);
|
|
12017
|
+
}
|
|
12018
|
+
for (const param of node.params) for (const name of extract_names(param)) current_scope.declarations.set(name, node);
|
|
12019
|
+
break;
|
|
12020
|
+
case "ForStatement":
|
|
12021
|
+
case "ForInStatement":
|
|
12022
|
+
case "ForOfStatement":
|
|
12023
|
+
case "BlockStatement":
|
|
12024
|
+
case "SwitchStatement":
|
|
12025
|
+
push(node, true);
|
|
12026
|
+
break;
|
|
12027
|
+
case "ClassDeclaration":
|
|
12028
|
+
case "VariableDeclaration":
|
|
12029
|
+
current_scope.add_declaration(node);
|
|
12030
|
+
break;
|
|
12031
|
+
case "CatchClause":
|
|
12032
|
+
push(node, true);
|
|
12033
|
+
if (node.param) {
|
|
12034
|
+
for (const name of extract_names(node.param)) if (node.param) current_scope.declarations.set(name, node.param);
|
|
12035
|
+
}
|
|
12036
|
+
break;
|
|
12037
|
+
}
|
|
12038
|
+
context.next();
|
|
12039
|
+
if (map.has(node) && current_scope !== null && current_scope.parent) current_scope = current_scope.parent;
|
|
12040
|
+
} });
|
|
12041
|
+
for (let i = references.length - 1; i >= 0; --i) {
|
|
12042
|
+
const [scope, reference] = references[i];
|
|
12043
|
+
if (!scope.references.has(reference.name)) add_reference(scope, reference.name);
|
|
12044
|
+
if (!scope.find_owner(reference.name)) globals.set(reference.name, reference);
|
|
12045
|
+
}
|
|
12046
|
+
return {
|
|
12047
|
+
map,
|
|
12048
|
+
scope,
|
|
12049
|
+
globals
|
|
12050
|
+
};
|
|
12051
|
+
}
|
|
12052
|
+
/**
|
|
12053
|
+
* @param {Scope} scope
|
|
12054
|
+
* @param {string} name
|
|
12055
|
+
*/
|
|
12056
|
+
function add_reference(scope, name) {
|
|
12057
|
+
scope.references.add(name);
|
|
12058
|
+
if (scope.parent) add_reference(scope.parent, name);
|
|
12059
|
+
}
|
|
12060
|
+
var Scope = class {
|
|
12061
|
+
/**
|
|
12062
|
+
* @param {Scope | null} parent
|
|
12063
|
+
* @param {boolean} block
|
|
12064
|
+
*/
|
|
12065
|
+
constructor(parent, block) {
|
|
12066
|
+
/** @type {Scope | null} */
|
|
12067
|
+
this.parent = parent;
|
|
12068
|
+
/** @type {boolean} */
|
|
12069
|
+
this.block = block;
|
|
12070
|
+
/** @type {Map<string, import('estree').Node>} */
|
|
12071
|
+
this.declarations = /* @__PURE__ */ new Map();
|
|
12072
|
+
/** @type {Set<string>} */
|
|
12073
|
+
this.initialised_declarations = /* @__PURE__ */ new Set();
|
|
12074
|
+
/** @type {Set<string>} */
|
|
12075
|
+
this.references = /* @__PURE__ */ new Set();
|
|
12076
|
+
}
|
|
12077
|
+
/**
|
|
12078
|
+
* @param {import('estree').VariableDeclaration | import('estree').ClassDeclaration} node
|
|
12079
|
+
*/
|
|
12080
|
+
add_declaration(node) {
|
|
12081
|
+
if (node.type === "VariableDeclaration") if (node.kind === "var" && this.block && this.parent) this.parent.add_declaration(node);
|
|
12082
|
+
else for (const declarator of node.declarations) for (const name of extract_names(declarator.id)) {
|
|
12083
|
+
this.declarations.set(name, node);
|
|
12084
|
+
if (declarator.init) this.initialised_declarations.add(name);
|
|
12085
|
+
}
|
|
12086
|
+
else if (node.id) this.declarations.set(node.id.name, node);
|
|
12087
|
+
}
|
|
12088
|
+
/**
|
|
12089
|
+
* @param {string} name
|
|
12090
|
+
* @returns {Scope | null}
|
|
12091
|
+
*/
|
|
12092
|
+
find_owner(name) {
|
|
12093
|
+
if (this.declarations.has(name)) return this;
|
|
12094
|
+
return this.parent && this.parent.find_owner(name);
|
|
12095
|
+
}
|
|
12096
|
+
/**
|
|
12097
|
+
* @param {string} name
|
|
12098
|
+
* @returns {boolean}
|
|
12099
|
+
*/
|
|
12100
|
+
has(name) {
|
|
12101
|
+
return this.declarations.has(name) || !!this.parent && this.parent.has(name);
|
|
12102
|
+
}
|
|
12103
|
+
};
|
|
11632
12104
|
/**
|
|
11633
12105
|
* @param {import('estree').Node} param
|
|
11634
12106
|
* @returns {string[]}
|
|
@@ -13305,7 +13777,7 @@ function checkPublicFile(url, config) {
|
|
|
13305
13777
|
return tryStatSync(publicFile)?.isFile() ? publicFile : void 0;
|
|
13306
13778
|
}
|
|
13307
13779
|
//#endregion
|
|
13308
|
-
//#region ../../node_modules/.pnpm/ws@8.21.
|
|
13780
|
+
//#region ../../node_modules/.pnpm/ws@8.21.1/node_modules/ws/lib/constants.js
|
|
13309
13781
|
var require_constants = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
13310
13782
|
const BINARY_TYPES = [
|
|
13311
13783
|
"nodebuffer",
|
|
@@ -13328,7 +13800,7 @@ var require_constants = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
13328
13800
|
};
|
|
13329
13801
|
}));
|
|
13330
13802
|
//#endregion
|
|
13331
|
-
//#region ../../node_modules/.pnpm/ws@8.21.
|
|
13803
|
+
//#region ../../node_modules/.pnpm/ws@8.21.1/node_modules/ws/lib/buffer-util.js
|
|
13332
13804
|
var require_buffer_util = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
13333
13805
|
const { EMPTY_BUFFER } = require_constants();
|
|
13334
13806
|
const FastBuffer = Buffer[Symbol.species];
|
|
@@ -13428,7 +13900,7 @@ var require_buffer_util = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
13428
13900
|
} catch (e) {}
|
|
13429
13901
|
}));
|
|
13430
13902
|
//#endregion
|
|
13431
|
-
//#region ../../node_modules/.pnpm/ws@8.21.
|
|
13903
|
+
//#region ../../node_modules/.pnpm/ws@8.21.1/node_modules/ws/lib/limiter.js
|
|
13432
13904
|
var require_limiter = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
13433
13905
|
const kDone = Symbol("kDone");
|
|
13434
13906
|
const kRun = Symbol("kRun");
|
|
@@ -13479,7 +13951,7 @@ var require_limiter = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
13479
13951
|
module.exports = Limiter;
|
|
13480
13952
|
}));
|
|
13481
13953
|
//#endregion
|
|
13482
|
-
//#region ../../node_modules/.pnpm/ws@8.21.
|
|
13954
|
+
//#region ../../node_modules/.pnpm/ws@8.21.1/node_modules/ws/lib/permessage-deflate.js
|
|
13483
13955
|
var require_permessage_deflate = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
13484
13956
|
const zlib$1 = __require("zlib");
|
|
13485
13957
|
const bufferUtil = require_buffer_util();
|
|
@@ -13815,7 +14287,7 @@ var require_permessage_deflate = /* @__PURE__ */ __commonJSMin(((exports, module
|
|
|
13815
14287
|
}
|
|
13816
14288
|
}));
|
|
13817
14289
|
//#endregion
|
|
13818
|
-
//#region ../../node_modules/.pnpm/ws@8.21.
|
|
14290
|
+
//#region ../../node_modules/.pnpm/ws@8.21.1/node_modules/ws/lib/validation.js
|
|
13819
14291
|
var require_validation = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
13820
14292
|
const { isUtf8 } = __require("buffer");
|
|
13821
14293
|
const { hasBlob } = require_constants();
|
|
@@ -14011,7 +14483,7 @@ var require_validation = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
14011
14483
|
} catch (e) {}
|
|
14012
14484
|
}));
|
|
14013
14485
|
//#endregion
|
|
14014
|
-
//#region ../../node_modules/.pnpm/ws@8.21.
|
|
14486
|
+
//#region ../../node_modules/.pnpm/ws@8.21.1/node_modules/ws/lib/receiver.js
|
|
14015
14487
|
var require_receiver = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
14016
14488
|
const { Writable: Writable$1 } = __require("stream");
|
|
14017
14489
|
const PerMessageDeflate = require_permessage_deflate();
|
|
@@ -14074,6 +14546,7 @@ var require_receiver = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
14074
14546
|
this._opcode = 0;
|
|
14075
14547
|
this._totalPayloadLength = 0;
|
|
14076
14548
|
this._messageLength = 0;
|
|
14549
|
+
this._numFragments = 0;
|
|
14077
14550
|
this._fragments = [];
|
|
14078
14551
|
this._errored = false;
|
|
14079
14552
|
this._loop = false;
|
|
@@ -14314,16 +14787,16 @@ var require_receiver = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
14314
14787
|
this.controlMessage(data, cb);
|
|
14315
14788
|
return;
|
|
14316
14789
|
}
|
|
14790
|
+
if (this._maxFragments > 0 && ++this._numFragments > this._maxFragments) {
|
|
14791
|
+
cb(this.createError(RangeError, "Too many message fragments", false, 1008, "WS_ERR_TOO_MANY_BUFFERED_PARTS"));
|
|
14792
|
+
return;
|
|
14793
|
+
}
|
|
14317
14794
|
if (this._compressed) {
|
|
14318
14795
|
this._state = INFLATING;
|
|
14319
14796
|
this.decompress(data, cb);
|
|
14320
14797
|
return;
|
|
14321
14798
|
}
|
|
14322
14799
|
if (data.length) {
|
|
14323
|
-
if (this._maxFragments > 0 && this._fragments.length >= this._maxFragments) {
|
|
14324
|
-
cb(this.createError(RangeError, "Too many message fragments", false, 1008, "WS_ERR_TOO_MANY_BUFFERED_PARTS"));
|
|
14325
|
-
return;
|
|
14326
|
-
}
|
|
14327
14800
|
this._messageLength = this._totalPayloadLength;
|
|
14328
14801
|
this._fragments.push(data);
|
|
14329
14802
|
}
|
|
@@ -14345,10 +14818,6 @@ var require_receiver = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
14345
14818
|
cb(this.createError(RangeError, "Max payload size exceeded", false, 1009, "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH"));
|
|
14346
14819
|
return;
|
|
14347
14820
|
}
|
|
14348
|
-
if (this._maxFragments > 0 && this._fragments.length >= this._maxFragments) {
|
|
14349
|
-
cb(this.createError(RangeError, "Too many message fragments", false, 1008, "WS_ERR_TOO_MANY_BUFFERED_PARTS"));
|
|
14350
|
-
return;
|
|
14351
|
-
}
|
|
14352
14821
|
this._fragments.push(buf);
|
|
14353
14822
|
}
|
|
14354
14823
|
this.dataMessage(cb);
|
|
@@ -14371,6 +14840,7 @@ var require_receiver = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
14371
14840
|
this._totalPayloadLength = 0;
|
|
14372
14841
|
this._messageLength = 0;
|
|
14373
14842
|
this._fragmented = 0;
|
|
14843
|
+
this._numFragments = 0;
|
|
14374
14844
|
this._fragments = [];
|
|
14375
14845
|
if (this._opcode === 2) {
|
|
14376
14846
|
let data;
|
|
@@ -14476,7 +14946,7 @@ var require_receiver = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
14476
14946
|
module.exports = Receiver;
|
|
14477
14947
|
}));
|
|
14478
14948
|
//#endregion
|
|
14479
|
-
//#region ../../node_modules/.pnpm/ws@8.21.
|
|
14949
|
+
//#region ../../node_modules/.pnpm/ws@8.21.1/node_modules/ws/lib/sender.js
|
|
14480
14950
|
var require_sender = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
14481
14951
|
const { Duplex: Duplex$3 } = __require("stream");
|
|
14482
14952
|
const { randomFillSync } = __require("crypto");
|
|
@@ -14970,7 +15440,7 @@ var require_sender = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
14970
15440
|
}
|
|
14971
15441
|
}));
|
|
14972
15442
|
//#endregion
|
|
14973
|
-
//#region ../../node_modules/.pnpm/ws@8.21.
|
|
15443
|
+
//#region ../../node_modules/.pnpm/ws@8.21.1/node_modules/ws/lib/event-target.js
|
|
14974
15444
|
var require_event_target = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
14975
15445
|
const { kForOnEventAttribute, kListener } = require_constants();
|
|
14976
15446
|
const kCode = Symbol("kCode");
|
|
@@ -15201,7 +15671,7 @@ var require_event_target = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
15201
15671
|
}
|
|
15202
15672
|
}));
|
|
15203
15673
|
//#endregion
|
|
15204
|
-
//#region ../../node_modules/.pnpm/ws@8.21.
|
|
15674
|
+
//#region ../../node_modules/.pnpm/ws@8.21.1/node_modules/ws/lib/extension.js
|
|
15205
15675
|
var require_extension = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
15206
15676
|
const { tokenChars } = require_validation();
|
|
15207
15677
|
/**
|
|
@@ -15344,7 +15814,7 @@ var require_extension = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
15344
15814
|
};
|
|
15345
15815
|
}));
|
|
15346
15816
|
//#endregion
|
|
15347
|
-
//#region ../../node_modules/.pnpm/ws@8.21.
|
|
15817
|
+
//#region ../../node_modules/.pnpm/ws@8.21.1/node_modules/ws/lib/websocket.js
|
|
15348
15818
|
var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
15349
15819
|
const EventEmitter$2 = __require("events");
|
|
15350
15820
|
const https$3 = __require("https");
|
|
@@ -15849,9 +16319,9 @@ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
15849
16319
|
* masking key
|
|
15850
16320
|
* @param {Number} [options.handshakeTimeout] Timeout in milliseconds for the
|
|
15851
16321
|
* handshake request
|
|
15852
|
-
* @param {Number} [options.maxBufferedChunks=
|
|
16322
|
+
* @param {Number} [options.maxBufferedChunks=262144] The maximum number of
|
|
15853
16323
|
* buffered data chunks
|
|
15854
|
-
* @param {Number} [options.maxFragments=
|
|
16324
|
+
* @param {Number} [options.maxFragments=16384] The maximum number of message
|
|
15855
16325
|
* fragments
|
|
15856
16326
|
* @param {Number} [options.maxPayload=104857600] The maximum allowed message
|
|
15857
16327
|
* size
|
|
@@ -15873,8 +16343,8 @@ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
15873
16343
|
autoPong: true,
|
|
15874
16344
|
closeTimeout: CLOSE_TIMEOUT,
|
|
15875
16345
|
protocolVersion: protocolVersions[1],
|
|
15876
|
-
maxBufferedChunks:
|
|
15877
|
-
maxFragments:
|
|
16346
|
+
maxBufferedChunks: 256 * 1024,
|
|
16347
|
+
maxFragments: 16 * 1024,
|
|
15878
16348
|
maxPayload: 100 * 1024 * 1024,
|
|
15879
16349
|
skipUTF8Validation: false,
|
|
15880
16350
|
perMessageDeflate: true,
|
|
@@ -16333,7 +16803,7 @@ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
16333
16803
|
}
|
|
16334
16804
|
}));
|
|
16335
16805
|
//#endregion
|
|
16336
|
-
//#region ../../node_modules/.pnpm/ws@8.21.
|
|
16806
|
+
//#region ../../node_modules/.pnpm/ws@8.21.1/node_modules/ws/lib/stream.js
|
|
16337
16807
|
var require_stream = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
16338
16808
|
require_websocket();
|
|
16339
16809
|
const { Duplex: Duplex$1 } = __require("stream");
|
|
@@ -16449,7 +16919,7 @@ var require_stream = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
16449
16919
|
module.exports = createWebSocketStream;
|
|
16450
16920
|
}));
|
|
16451
16921
|
//#endregion
|
|
16452
|
-
//#region ../../node_modules/.pnpm/ws@8.21.
|
|
16922
|
+
//#region ../../node_modules/.pnpm/ws@8.21.1/node_modules/ws/lib/subprotocol.js
|
|
16453
16923
|
var require_subprotocol = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
16454
16924
|
const { tokenChars } = require_validation();
|
|
16455
16925
|
/**
|
|
@@ -16488,7 +16958,7 @@ var require_subprotocol = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
16488
16958
|
module.exports = { parse };
|
|
16489
16959
|
}));
|
|
16490
16960
|
//#endregion
|
|
16491
|
-
//#region ../../node_modules/.pnpm/ws@8.21.
|
|
16961
|
+
//#region ../../node_modules/.pnpm/ws@8.21.1/node_modules/ws/lib/websocket-server.js
|
|
16492
16962
|
var require_websocket_server = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
16493
16963
|
const EventEmitter$1 = __require("events");
|
|
16494
16964
|
const http$4 = __require("http");
|
|
@@ -16527,9 +16997,9 @@ var require_websocket_server = /* @__PURE__ */ __commonJSMin(((exports, module)
|
|
|
16527
16997
|
* called
|
|
16528
16998
|
* @param {Function} [options.handleProtocols] A hook to handle protocols
|
|
16529
16999
|
* @param {String} [options.host] The hostname where to bind the server
|
|
16530
|
-
* @param {Number} [options.maxBufferedChunks=
|
|
17000
|
+
* @param {Number} [options.maxBufferedChunks=262144] The maximum number of
|
|
16531
17001
|
* buffered data chunks
|
|
16532
|
-
* @param {Number} [options.maxFragments=
|
|
17002
|
+
* @param {Number} [options.maxFragments=16384] The maximum number of message
|
|
16533
17003
|
* fragments
|
|
16534
17004
|
* @param {Number} [options.maxPayload=104857600] The maximum allowed message
|
|
16535
17005
|
* size
|
|
@@ -16552,8 +17022,8 @@ var require_websocket_server = /* @__PURE__ */ __commonJSMin(((exports, module)
|
|
|
16552
17022
|
options = {
|
|
16553
17023
|
allowSynchronousEvents: true,
|
|
16554
17024
|
autoPong: true,
|
|
16555
|
-
maxBufferedChunks:
|
|
16556
|
-
maxFragments:
|
|
17025
|
+
maxBufferedChunks: 256 * 1024,
|
|
17026
|
+
maxFragments: 16 * 1024,
|
|
16557
17027
|
maxPayload: 100 * 1024 * 1024,
|
|
16558
17028
|
skipUTF8Validation: false,
|
|
16559
17029
|
perMessageDeflate: false,
|
|
@@ -21388,7 +21858,7 @@ var require_src$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
21388
21858
|
};
|
|
21389
21859
|
}));
|
|
21390
21860
|
//#endregion
|
|
21391
|
-
//#region ../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.
|
|
21861
|
+
//#region ../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.23_tsx@4.23.1_yaml@2.9.0/node_modules/postcss-load-config/src/req.js
|
|
21392
21862
|
var require_req = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
21393
21863
|
const { createRequire: createRequire$1 } = __require("node:module");
|
|
21394
21864
|
const { fileURLToPath: fileURLToPath$1, pathToFileURL: pathToFileURL$1 } = __require("node:url");
|
|
@@ -21430,7 +21900,7 @@ var require_req = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
21430
21900
|
module.exports = req;
|
|
21431
21901
|
}));
|
|
21432
21902
|
//#endregion
|
|
21433
|
-
//#region ../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.
|
|
21903
|
+
//#region ../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.23_tsx@4.23.1_yaml@2.9.0/node_modules/postcss-load-config/src/options.js
|
|
21434
21904
|
var require_options = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
21435
21905
|
const req = require_req();
|
|
21436
21906
|
/**
|
|
@@ -21464,7 +21934,7 @@ var require_options = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
21464
21934
|
module.exports = options;
|
|
21465
21935
|
}));
|
|
21466
21936
|
//#endregion
|
|
21467
|
-
//#region ../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.
|
|
21937
|
+
//#region ../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.23_tsx@4.23.1_yaml@2.9.0/node_modules/postcss-load-config/src/plugins.js
|
|
21468
21938
|
var require_plugins = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
21469
21939
|
const req = require_req();
|
|
21470
21940
|
/**
|
|
@@ -21518,7 +21988,7 @@ var require_plugins = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
21518
21988
|
module.exports = plugins;
|
|
21519
21989
|
}));
|
|
21520
21990
|
//#endregion
|
|
21521
|
-
//#region ../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.
|
|
21991
|
+
//#region ../../node_modules/.pnpm/postcss-load-config@6.0.1_jiti@2.7.0_postcss@8.5.23_tsx@4.23.1_yaml@2.9.0/node_modules/postcss-load-config/src/index.js
|
|
21522
21992
|
var require_src = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
21523
21993
|
const { resolve: resolve$3 } = __require("node:path");
|
|
21524
21994
|
const config = require_src$1();
|
|
@@ -22071,6 +22541,7 @@ function cssPostPlugin(config) {
|
|
|
22071
22541
|
let codeSplitEmitQueue = createSerialPromiseQueue();
|
|
22072
22542
|
const urlEmitQueue = createSerialPromiseQueue();
|
|
22073
22543
|
let pureCssChunks;
|
|
22544
|
+
let chunkCssReferences;
|
|
22074
22545
|
let hasEmitted = false;
|
|
22075
22546
|
let chunkCSSMap;
|
|
22076
22547
|
const rolldownOptionsOutput = config.build.rolldownOptions.output;
|
|
@@ -22099,6 +22570,7 @@ function cssPostPlugin(config) {
|
|
|
22099
22570
|
name: "vite:css-post",
|
|
22100
22571
|
renderStart() {
|
|
22101
22572
|
pureCssChunks = /* @__PURE__ */ new Set();
|
|
22573
|
+
chunkCssReferences = /* @__PURE__ */ new Map();
|
|
22102
22574
|
hasEmitted = false;
|
|
22103
22575
|
chunkCSSMap = /* @__PURE__ */ new Map();
|
|
22104
22576
|
codeSplitEmitQueue = createSerialPromiseQueue();
|
|
@@ -22278,6 +22750,7 @@ function cssPostPlugin(config) {
|
|
|
22278
22750
|
originalFileName,
|
|
22279
22751
|
source: chunkCSS
|
|
22280
22752
|
});
|
|
22753
|
+
chunkCssReferences.set(chunk.fileName, referenceId);
|
|
22281
22754
|
if (isEntry) cssEntriesMap.get(this.environment).set(chunk.fileName, {
|
|
22282
22755
|
referenceId,
|
|
22283
22756
|
name: chunk.name
|
|
@@ -22338,6 +22811,20 @@ function cssPostPlugin(config) {
|
|
|
22338
22811
|
});
|
|
22339
22812
|
}
|
|
22340
22813
|
}
|
|
22814
|
+
if (config.build.chunkImportMap && chunkCssReferences.size) {
|
|
22815
|
+
const importMap = getImportMap(bundle, config);
|
|
22816
|
+
const importMapReverseMapping = Object.fromEntries(Object.entries(importMap.mapping).map(([k, v]) => [v, k]));
|
|
22817
|
+
const chunksByPreliminaryFileName = new Map(Object.values(bundle).filter((output) => output.type === "chunk").map((chunk) => [chunk.preliminaryFileName, chunk]));
|
|
22818
|
+
for (const [chunkFileName, referenceId] of chunkCssReferences) {
|
|
22819
|
+
const chunk = chunksByPreliminaryFileName.get(chunkFileName);
|
|
22820
|
+
if (!chunk) continue;
|
|
22821
|
+
const stableChunkFileName = importMapReverseMapping[chunk.fileName] ?? chunk.fileName;
|
|
22822
|
+
const extension = path.posix.extname(stableChunkFileName);
|
|
22823
|
+
const stableCssFileName = `${stableChunkFileName.slice(0, extension ? -extension.length : void 0)}.css`;
|
|
22824
|
+
importMap.content.imports[config.base + stableCssFileName] = config.base + this.getFileName(referenceId);
|
|
22825
|
+
}
|
|
22826
|
+
importMap.asset.source = JSON.stringify(importMap.content);
|
|
22827
|
+
}
|
|
22341
22828
|
if (pureCssChunks.size) {
|
|
22342
22829
|
const prelimaryNameToChunkMap = Object.fromEntries(Object.values(bundle).filter((chunk) => chunk.type === "chunk").map((chunk) => [chunk.preliminaryFileName, chunk.fileName]));
|
|
22343
22830
|
const pureCssChunkNames = [...pureCssChunks].map((pureCssChunk) => prelimaryNameToChunkMap[pureCssChunk.fileName]).filter(Boolean);
|
|
@@ -22786,7 +23273,7 @@ const UrlRewritePostcssPlugin = (opts) => {
|
|
|
22786
23273
|
if (!opts) throw new Error("base or replace is required");
|
|
22787
23274
|
return {
|
|
22788
23275
|
postcssPlugin: "vite-url-rewrite",
|
|
22789
|
-
|
|
23276
|
+
OnceExit(root) {
|
|
22790
23277
|
const promises = [];
|
|
22791
23278
|
root.walkDecls((declaration) => {
|
|
22792
23279
|
const importer = declaration.source?.input.file;
|
|
@@ -24490,6 +24977,7 @@ function getImportMap(bundle, config) {
|
|
|
24490
24977
|
const content = JSON.parse(typeof asset.source === "string" ? asset.source : new TextDecoder().decode(asset.source));
|
|
24491
24978
|
return {
|
|
24492
24979
|
asset,
|
|
24980
|
+
content,
|
|
24493
24981
|
mapping: Object.fromEntries(Object.entries(content.imports).map(([k, v]) => [k.slice(config.base.length), v.slice(config.base.length)]))
|
|
24494
24982
|
};
|
|
24495
24983
|
}
|
|
@@ -24818,6 +25306,7 @@ function handleDefineValue(value) {
|
|
|
24818
25306
|
//#endregion
|
|
24819
25307
|
//#region src/node/plugins/clientInjections.ts
|
|
24820
25308
|
const normalizedClientEntry$1 = normalizePath(CLIENT_ENTRY);
|
|
25309
|
+
const normalizedBundledDevClientEntry = normalizePath(BUNDLED_DEV_CLIENT_ENTRY);
|
|
24821
25310
|
const normalizedEnvEntry$1 = normalizePath(ENV_ENTRY);
|
|
24822
25311
|
/**
|
|
24823
25312
|
* some values used by the client needs to be dynamically injected by the server
|
|
@@ -24891,11 +25380,10 @@ async function createClientConfigValueReplacer(config) {
|
|
|
24891
25380
|
const hmrConfigNameReplacement = escapeReplacement(hmrConfigName);
|
|
24892
25381
|
const wsTokenReplacement = escapeReplacement(config.webSocketToken);
|
|
24893
25382
|
const serverForwardConsoleReplacement = escapeReplacement(config.server.forwardConsole);
|
|
24894
|
-
|
|
24895
|
-
return (code) => code.replace(`__MODE__`, modeReplacement).replace(/__BASE__/g, baseReplacement).replace(`__SERVER_HOST__`, serverHostReplacement).replace(`__HMR_PROTOCOL__`, hmrProtocolReplacement).replace(`__HMR_HOSTNAME__`, hmrHostnameReplacement).replace(`__HMR_PORT__`, hmrPortReplacement).replace(`__HMR_DIRECT_TARGET__`, hmrDirectTargetReplacement).replace(`__HMR_BASE__`, hmrBaseReplacement).replace(`__HMR_TIMEOUT__`, hmrTimeoutReplacement).replace(`__HMR_ENABLE_OVERLAY__`, hmrEnableOverlayReplacement).replace(`__HMR_CONFIG_NAME__`, hmrConfigNameReplacement).replace(`__WS_TOKEN__`, wsTokenReplacement).replace(`__SERVER_FORWARD_CONSOLE__`, serverForwardConsoleReplacement).replaceAll(`__BUNDLED_DEV__`, bundleDevReplacement);
|
|
25383
|
+
return (code) => code.replace(`__MODE__`, modeReplacement).replace(/__BASE__/g, baseReplacement).replace(`__SERVER_HOST__`, serverHostReplacement).replace(`__HMR_PROTOCOL__`, hmrProtocolReplacement).replace(`__HMR_HOSTNAME__`, hmrHostnameReplacement).replace(`__HMR_PORT__`, hmrPortReplacement).replace(`__HMR_DIRECT_TARGET__`, hmrDirectTargetReplacement).replace(`__HMR_BASE__`, hmrBaseReplacement).replace(`__HMR_TIMEOUT__`, hmrTimeoutReplacement).replace(`__HMR_ENABLE_OVERLAY__`, hmrEnableOverlayReplacement).replace(`__HMR_CONFIG_NAME__`, hmrConfigNameReplacement).replace(`__WS_TOKEN__`, wsTokenReplacement).replace(`__SERVER_FORWARD_CONSOLE__`, serverForwardConsoleReplacement);
|
|
24896
25384
|
}
|
|
24897
25385
|
async function getHmrImplementation(config) {
|
|
24898
|
-
const content = fs.readFileSync(
|
|
25386
|
+
const content = fs.readFileSync(normalizedBundledDevClientEntry, "utf-8");
|
|
24899
25387
|
return (await createClientConfigValueReplacer(config))(content).replace(/import\s*['"]@vite\/env['"]/, "");
|
|
24900
25388
|
}
|
|
24901
25389
|
//#endregion
|
|
@@ -24949,7 +25437,7 @@ const processNodeUrl = (url, useSrcSetReplacer, config, htmlPath, originalUrl, s
|
|
|
24949
25437
|
else if (url[0] === "." || isBareRelative(url)) preTransformUrl = path.posix.join(config.base, getHtmlDirnameForRelativeUrl(htmlPath), url);
|
|
24950
25438
|
}
|
|
24951
25439
|
if (server) {
|
|
24952
|
-
const mod = server.environments.client.moduleGraph.urlToModuleMap.get(preTransformUrl || url);
|
|
25440
|
+
const mod = server.environments.client.moduleGraph.urlToModuleMap.get(stripBase(preTransformUrl || url, config.decodedBase));
|
|
24953
25441
|
if (mod && mod.lastHMRTimestamp > 0) url = injectQuery(url, `t=${mod.lastHMRTimestamp}`);
|
|
24954
25442
|
}
|
|
24955
25443
|
if (server && preTransformUrl) {
|
|
@@ -25148,6 +25636,7 @@ async function generateFallbackHtml(server) {
|
|
|
25148
25636
|
<!DOCTYPE html>
|
|
25149
25637
|
<html lang="en">
|
|
25150
25638
|
<head>
|
|
25639
|
+
<script>globalThis.__vite_is_fallback_page__ = true<\/script>
|
|
25151
25640
|
<script type="module">
|
|
25152
25641
|
${(await getHmrImplementation(server.config)).replaceAll("<\/script>", "<\\/script>")}
|
|
25153
25642
|
<\/script>
|
|
@@ -25680,8 +26169,9 @@ function rejectInvalidRequestMiddleware() {
|
|
|
25680
26169
|
//#endregion
|
|
25681
26170
|
//#region src/node/server/middlewares/memoryFiles.ts
|
|
25682
26171
|
function memoryFilesMiddleware(server) {
|
|
25683
|
-
const
|
|
25684
|
-
|
|
26172
|
+
const bundledDev = server.environments.client.bundledDev;
|
|
26173
|
+
const memoryFiles = bundledDev?.memoryFiles;
|
|
26174
|
+
if (!bundledDev || !memoryFiles) throw new Error("memoryFilesMiddleware can only be used for fullBundleMode");
|
|
25685
26175
|
const headers = server.config.server.headers;
|
|
25686
26176
|
return function viteMemoryFilesMiddleware(req, res, next) {
|
|
25687
26177
|
const cleanedUrl = cleanUrl(req.url);
|
|
@@ -25706,6 +26196,7 @@ function memoryFilesMiddleware(server) {
|
|
|
25706
26196
|
const mime = lookup(filePath);
|
|
25707
26197
|
if (mime) res.setHeader("Content-Type", mime);
|
|
25708
26198
|
for (const name in headers) res.setHeader(name, headers[name]);
|
|
26199
|
+
res.on("finish", () => bundledDev.markPayloadDelivered(filePath));
|
|
25709
26200
|
return res.end(file.source);
|
|
25710
26201
|
}
|
|
25711
26202
|
next();
|
|
@@ -25726,10 +26217,11 @@ function triggerLazyBundlingMiddleware(server) {
|
|
|
25726
26217
|
}
|
|
25727
26218
|
const moduleId = params.get("id");
|
|
25728
26219
|
const clientId = params.get("clientId");
|
|
25729
|
-
const
|
|
25730
|
-
if (
|
|
26220
|
+
const result = await bundledDev.triggerLazyBundling(moduleId, clientId);
|
|
26221
|
+
if (result == null) return next();
|
|
25731
26222
|
res.setHeader("Content-Type", "application/javascript");
|
|
25732
|
-
|
|
26223
|
+
res.on("finish", () => bundledDev.markPayloadDelivered(result.filename));
|
|
26224
|
+
return res.end(result.code);
|
|
25733
26225
|
};
|
|
25734
26226
|
}
|
|
25735
26227
|
//#endregion
|
|
@@ -26388,7 +26880,9 @@ function getSortedHotUpdatePlugins(environment) {
|
|
|
26388
26880
|
async function handleHMRUpdate(type, file, server) {
|
|
26389
26881
|
const { config } = server;
|
|
26390
26882
|
const mixedModuleGraph = ignoreDeprecationWarnings(() => server.moduleGraph);
|
|
26391
|
-
const
|
|
26883
|
+
const environmentSnapshot = server.environments;
|
|
26884
|
+
const environments = Object.values(environmentSnapshot);
|
|
26885
|
+
const isStale = () => server.environments !== environmentSnapshot;
|
|
26392
26886
|
const shortFile = getShortName(file, config.root);
|
|
26393
26887
|
const isConfig = file === config.configFile;
|
|
26394
26888
|
const isConfigDependency = config.configFileDependencies.some((name) => file === name);
|
|
@@ -26449,8 +26943,9 @@ async function handleHMRUpdate(type, file, server) {
|
|
|
26449
26943
|
const clientHotUpdateOptions = hotMap.get(clientEnvironment).options;
|
|
26450
26944
|
const ssrHotUpdateOptions = hotMap.get(ssrEnvironment)?.options;
|
|
26451
26945
|
try {
|
|
26452
|
-
for (const plugin of getSortedHotUpdatePlugins(
|
|
26946
|
+
for (const plugin of getSortedHotUpdatePlugins(clientEnvironment)) if (plugin.hotUpdate) {
|
|
26453
26947
|
const filteredModules = await getHookHandler(plugin.hotUpdate).call(clientContext, clientHotUpdateOptions);
|
|
26948
|
+
if (isStale()) return;
|
|
26454
26949
|
if (filteredModules) {
|
|
26455
26950
|
clientHotUpdateOptions.modules = filteredModules;
|
|
26456
26951
|
mixedHmrContext.modules = mixedHmrContext.modules.filter((mixedMod) => filteredModules.some((mod) => mixedMod.id === mod.id) || ssrHotUpdateOptions?.modules.some((ssrMod) => ssrMod.id === mixedMod.id));
|
|
@@ -26459,6 +26954,7 @@ async function handleHMRUpdate(type, file, server) {
|
|
|
26459
26954
|
} else if (type === "update") {
|
|
26460
26955
|
warnFutureDeprecation(config, "removePluginHookHandleHotUpdate", `Used in plugin "${plugin.name}".`, false);
|
|
26461
26956
|
const filteredModules = await getHookHandler(plugin.handleHotUpdate).call(contextForHandleHotUpdate, mixedHmrContext);
|
|
26957
|
+
if (isStale()) return;
|
|
26462
26958
|
if (filteredModules) {
|
|
26463
26959
|
mixedHmrContext.modules = filteredModules;
|
|
26464
26960
|
clientHotUpdateOptions.modules = clientHotUpdateOptions.modules.filter((mod) => filteredModules.some((mixedMod) => mod.id === mixedMod.id));
|
|
@@ -26470,7 +26966,8 @@ async function handleHMRUpdate(type, file, server) {
|
|
|
26470
26966
|
}
|
|
26471
26967
|
}
|
|
26472
26968
|
} catch (error) {
|
|
26473
|
-
|
|
26969
|
+
if (isStale()) return;
|
|
26970
|
+
hotMap.get(clientEnvironment).error = error;
|
|
26474
26971
|
}
|
|
26475
26972
|
for (const environment of environments) {
|
|
26476
26973
|
if (environment.name === "client") continue;
|
|
@@ -26479,13 +26976,16 @@ async function handleHMRUpdate(type, file, server) {
|
|
|
26479
26976
|
try {
|
|
26480
26977
|
for (const plugin of getSortedHotUpdatePlugins(environment)) if (plugin.hotUpdate) {
|
|
26481
26978
|
const filteredModules = await getHookHandler(plugin.hotUpdate).call(context, hot.options);
|
|
26979
|
+
if (isStale()) return;
|
|
26482
26980
|
if (filteredModules) hot.options.modules = filteredModules;
|
|
26483
26981
|
}
|
|
26484
26982
|
} catch (error) {
|
|
26983
|
+
if (isStale()) return;
|
|
26485
26984
|
hot.error = error;
|
|
26486
26985
|
}
|
|
26487
26986
|
}
|
|
26488
26987
|
async function hmr(environment) {
|
|
26988
|
+
if (isStale()) return;
|
|
26489
26989
|
try {
|
|
26490
26990
|
const { options, error } = hotMap.get(environment);
|
|
26491
26991
|
if (error) throw error;
|
|
@@ -26510,6 +27010,7 @@ async function handleHMRUpdate(type, file, server) {
|
|
|
26510
27010
|
});
|
|
26511
27011
|
}
|
|
26512
27012
|
}
|
|
27013
|
+
if (isStale()) return;
|
|
26513
27014
|
await (server.config.server.hotUpdateEnvironments ?? ((server, hmr) => {
|
|
26514
27015
|
return Promise.all(Object.values(server.environments).map((environment) => hmr(environment)));
|
|
26515
27016
|
}))(server, hmr);
|
|
@@ -27003,6 +27504,22 @@ async function workerFileToUrl(config, id) {
|
|
|
27003
27504
|
}, config.logger);
|
|
27004
27505
|
return bundle;
|
|
27005
27506
|
}
|
|
27507
|
+
/**
|
|
27508
|
+
* Emit the bundled worker files during `load` / `transform`.
|
|
27509
|
+
*
|
|
27510
|
+
* They normally reach the output through `generateBundle`, which an HMR patch
|
|
27511
|
+
* skips, so without this a patched worker points at a file that was never
|
|
27512
|
+
* emitted.
|
|
27513
|
+
*/
|
|
27514
|
+
function emitWorkerAssetsForBundledDev(pluginContext, config) {
|
|
27515
|
+
if (config.isWorker) return;
|
|
27516
|
+
const workerOutput = workerOutputCaches.get(config.mainConfig || config);
|
|
27517
|
+
for (const asset of workerOutput.getAssets()) pluginContext.emitFile({
|
|
27518
|
+
type: "asset",
|
|
27519
|
+
fileName: asset.fileName,
|
|
27520
|
+
source: asset.source
|
|
27521
|
+
});
|
|
27522
|
+
}
|
|
27006
27523
|
function webWorkerPostPlugin(_config) {
|
|
27007
27524
|
return {
|
|
27008
27525
|
name: "vite:worker-post",
|
|
@@ -27113,8 +27630,10 @@ function webWorkerPlugin(config) {
|
|
|
27113
27630
|
} else {
|
|
27114
27631
|
const result = await workerFileToUrl(config, id);
|
|
27115
27632
|
let url;
|
|
27116
|
-
if (this.environment.config.command === "serve" && this.environment.config.isBundled)
|
|
27117
|
-
|
|
27633
|
+
if (this.environment.config.command === "serve" && this.environment.config.isBundled) {
|
|
27634
|
+
emitWorkerAssetsForBundledDev(this, config);
|
|
27635
|
+
url = toOutputFilePathInJSForBundledDev(this.environment, result.entryFilename);
|
|
27636
|
+
} else url = result.entryUrlPlaceholder;
|
|
27118
27637
|
urlCode = JSON.stringify(url);
|
|
27119
27638
|
for (const file of result.watchedFiles) this.addWatchFile(file);
|
|
27120
27639
|
}
|
|
@@ -27508,7 +28027,7 @@ function importAnalysisPlugin(config) {
|
|
|
27508
28027
|
config.safeModulePaths.add(fsPathFromUrl(stripBase(url, base)));
|
|
27509
28028
|
if (url !== specifier) {
|
|
27510
28029
|
let rewriteDone = false;
|
|
27511
|
-
if (!depsOptimizer?.isOptimizedDepFile(importer) && depsOptimizer?.isOptimizedDepFile(resolvedId) && !optimizedDepChunkRE.test(resolvedId)) {
|
|
28030
|
+
if (!(depsOptimizer?.isOptimizedDepFile(importer) && specifier[0] === ".") && depsOptimizer?.isOptimizedDepFile(resolvedId) && !optimizedDepChunkRE.test(resolvedId)) {
|
|
27512
28031
|
const file = cleanUrl(resolvedId);
|
|
27513
28032
|
const depInfo = optimizedDepInfoFromFile(depsOptimizer.metadata, file);
|
|
27514
28033
|
const needsInterop = await optimizedDepNeedsInterop(environment, depsOptimizer.metadata, file);
|
|
@@ -27718,7 +28237,14 @@ function __vite__injectQuery(url, queryToInject) {
|
|
|
27718
28237
|
const wasmHelperId = "\0vite/wasm-helper.js";
|
|
27719
28238
|
const wasmInitRE = /(?<![?#].*)\.wasm\?init/;
|
|
27720
28239
|
const wasmDirectRE = /(?<![?#].*)\.wasm$/;
|
|
28240
|
+
const wasmInstanceSuffix = "?vite-wasm-instance";
|
|
28241
|
+
const wasmInstanceRE = /[?&]vite-wasm-instance(?:&|$)/;
|
|
27721
28242
|
const wasmInitUrlRE = /__VITE_WASM_INIT__([\w$]+)__/g;
|
|
28243
|
+
const wasmCompileOptions = {
|
|
28244
|
+
builtins: ["js-string"],
|
|
28245
|
+
importedStringConstants: "wasm:js/string-constants"
|
|
28246
|
+
};
|
|
28247
|
+
const wasmReservedModules = /* @__PURE__ */ new Set([...wasmCompileOptions.builtins.map((name) => `wasm:${name}`), wasmCompileOptions.importedStringConstants]);
|
|
27722
28248
|
const wasmHelper = async (opts = {}, url) => {
|
|
27723
28249
|
let result;
|
|
27724
28250
|
if (url.startsWith("data:")) {
|
|
@@ -27730,7 +28256,7 @@ const wasmHelper = async (opts = {}, url) => {
|
|
|
27730
28256
|
bytes = new Uint8Array(binaryString.length);
|
|
27731
28257
|
for (let i = 0; i < binaryString.length; i++) bytes[i] = binaryString.charCodeAt(i);
|
|
27732
28258
|
} else throw new Error("Failed to decode base64-encoded data URL, Buffer and atob are not supported");
|
|
27733
|
-
result = await WebAssembly.instantiate(bytes, opts);
|
|
28259
|
+
result = await WebAssembly.instantiate(bytes, opts, wasmCompileOptions);
|
|
27734
28260
|
} else result = await instantiateFromUrl(url, opts);
|
|
27735
28261
|
return result.instance;
|
|
27736
28262
|
};
|
|
@@ -27738,10 +28264,10 @@ const wasmHelperCode = wasmHelper.toString();
|
|
|
27738
28264
|
const instantiateFromUrl = async (url, opts) => {
|
|
27739
28265
|
const response = await fetch(url);
|
|
27740
28266
|
const contentType = response.headers.get("Content-Type") || "";
|
|
27741
|
-
if ("instantiateStreaming" in WebAssembly && contentType.startsWith("application/wasm")) return WebAssembly.instantiateStreaming(response, opts);
|
|
28267
|
+
if ("instantiateStreaming" in WebAssembly && contentType.startsWith("application/wasm")) return WebAssembly.instantiateStreaming(response, opts, wasmCompileOptions);
|
|
27742
28268
|
else {
|
|
27743
28269
|
const buffer = await response.arrayBuffer();
|
|
27744
|
-
return WebAssembly.instantiate(buffer, opts);
|
|
28270
|
+
return WebAssembly.instantiate(buffer, opts, wasmCompileOptions);
|
|
27745
28271
|
}
|
|
27746
28272
|
};
|
|
27747
28273
|
const instantiateFromUrlCode = instantiateFromUrl.toString();
|
|
@@ -27752,7 +28278,7 @@ const instantiateFromFile = async (fileUrlString, opts) => {
|
|
|
27752
28278
|
/** #__KEEP__ */
|
|
27753
28279
|
import.meta.url
|
|
27754
28280
|
));
|
|
27755
|
-
return WebAssembly.instantiate(buffer, opts);
|
|
28281
|
+
return WebAssembly.instantiate(buffer, opts, wasmCompileOptions);
|
|
27756
28282
|
};
|
|
27757
28283
|
const instantiateFromFileCode = instantiateFromFile.toString();
|
|
27758
28284
|
const wasmHelperPlugin = () => {
|
|
@@ -27769,16 +28295,24 @@ const wasmHelperPlugin = () => {
|
|
|
27769
28295
|
filter: { id: [
|
|
27770
28296
|
exactRegex(wasmHelperId),
|
|
27771
28297
|
wasmInitRE,
|
|
27772
|
-
wasmDirectRE
|
|
28298
|
+
wasmDirectRE,
|
|
28299
|
+
wasmInstanceRE
|
|
27773
28300
|
] },
|
|
27774
28301
|
async handler(id) {
|
|
27775
28302
|
const ssr = this.environment.config.consumer === "server";
|
|
27776
28303
|
if (id === wasmHelperId) return `
|
|
28304
|
+
const wasmCompileOptions = ${JSON.stringify(wasmCompileOptions)}
|
|
27777
28305
|
const instantiateFromUrl = ${ssr ? instantiateFromFileCode : instantiateFromUrlCode}
|
|
27778
28306
|
export default ${wasmHelperCode}
|
|
27779
28307
|
`;
|
|
27780
28308
|
const isInit = wasmInitRE.test(id);
|
|
27781
|
-
const
|
|
28309
|
+
const isInstance = wasmInstanceRE.test(id);
|
|
28310
|
+
const cleanedId = isInstance ? cleanUrl(id) : id.split("?")[0];
|
|
28311
|
+
let wasmInfo;
|
|
28312
|
+
if (!isInit) {
|
|
28313
|
+
wasmInfo = await parseWasm(cleanedId);
|
|
28314
|
+
if (!isInstance && wasmInfo.hasGlobalExport) return generateWrapperGlue(wasmInfo, cleanedId + wasmInstanceSuffix);
|
|
28315
|
+
}
|
|
27782
28316
|
let url = await fileToUrl$1(this, cleanedId, ssr);
|
|
27783
28317
|
assetUrlRE.lastIndex = 0;
|
|
27784
28318
|
if (ssr && assetUrlRE.test(url)) url = url.replace("__VITE_ASSET__", "__VITE_WASM_INIT__");
|
|
@@ -27786,7 +28320,7 @@ export default ${wasmHelperCode}
|
|
|
27786
28320
|
import initWasm from "${wasmHelperId}"
|
|
27787
28321
|
export default opts => initWasm(opts, ${JSON.stringify(url)})
|
|
27788
28322
|
`;
|
|
27789
|
-
const glueCode =
|
|
28323
|
+
const glueCode = generateInstanceGlue(wasmInfo, {
|
|
27790
28324
|
initWasm: "__vite__initWasm",
|
|
27791
28325
|
wasmUrl: "__vite__wasmUrl"
|
|
27792
28326
|
});
|
|
@@ -27825,43 +28359,70 @@ ${glueCode}
|
|
|
27825
28359
|
async function parseWasm(wasmFilePath) {
|
|
27826
28360
|
try {
|
|
27827
28361
|
const wasmBinary = await fsp.readFile(wasmFilePath);
|
|
27828
|
-
const wasmModule = await WebAssembly.compile(wasmBinary);
|
|
27829
|
-
const importMap =
|
|
28362
|
+
const wasmModule = await WebAssembly.compile(wasmBinary, wasmCompileOptions);
|
|
28363
|
+
const importMap = /* @__PURE__ */ new Map();
|
|
27830
28364
|
for (const item of WebAssembly.Module.imports(wasmModule)) {
|
|
27831
|
-
|
|
27832
|
-
importMap
|
|
28365
|
+
if (wasmReservedModules.has(item.module)) continue;
|
|
28366
|
+
let names = importMap.get(item.module);
|
|
28367
|
+
if (!names) importMap.set(item.module, names = []);
|
|
28368
|
+
names.push({
|
|
28369
|
+
name: item.name,
|
|
28370
|
+
isGlobal: item.kind === "global"
|
|
28371
|
+
});
|
|
27833
28372
|
}
|
|
28373
|
+
const imports = [...importMap].map(([from, names]) => ({
|
|
28374
|
+
from,
|
|
28375
|
+
names
|
|
28376
|
+
}));
|
|
28377
|
+
let hasGlobalExport = false;
|
|
27834
28378
|
return {
|
|
27835
|
-
imports
|
|
27836
|
-
|
|
27837
|
-
|
|
27838
|
-
|
|
27839
|
-
|
|
28379
|
+
imports,
|
|
28380
|
+
exports: WebAssembly.Module.exports(wasmModule).map((item) => {
|
|
28381
|
+
const isGlobal = item.kind === "global";
|
|
28382
|
+
if (isGlobal) hasGlobalExport = true;
|
|
28383
|
+
return {
|
|
28384
|
+
name: item.name,
|
|
28385
|
+
isGlobal
|
|
28386
|
+
};
|
|
28387
|
+
}),
|
|
28388
|
+
hasGlobalExport
|
|
27840
28389
|
};
|
|
27841
28390
|
} catch (e) {
|
|
27842
28391
|
throw new Error(`Failed to parse WASM file "${wasmFilePath}": ${e.message}`, { cause: e });
|
|
27843
28392
|
}
|
|
27844
28393
|
}
|
|
27845
|
-
function
|
|
27846
|
-
const importStatements =
|
|
27847
|
-
return `import * as __vite__wasmImport_${i} from ${JSON.stringify(from)};`;
|
|
27848
|
-
});
|
|
28394
|
+
function generateInstanceGlue(wasmInfo, names) {
|
|
28395
|
+
const importStatements = [];
|
|
27849
28396
|
const importObject = wasmInfo.imports.map(({ from, names: importNames }, i) => {
|
|
28397
|
+
const value = [];
|
|
28398
|
+
const globals = importNames.filter((n) => n.isGlobal);
|
|
28399
|
+
const others = importNames.filter((n) => !n.isGlobal);
|
|
28400
|
+
if (others.length > 0) {
|
|
28401
|
+
const ns = `__vite__wasmImport_${i}`;
|
|
28402
|
+
importStatements.push(`import * as ${ns} from ${JSON.stringify(from)};`);
|
|
28403
|
+
for (const { name } of others) value.push({
|
|
28404
|
+
key: JSON.stringify(name),
|
|
28405
|
+
value: `${ns}[${JSON.stringify(name)}]`
|
|
28406
|
+
});
|
|
28407
|
+
}
|
|
28408
|
+
if (globals.length > 0) {
|
|
28409
|
+
const ns = `__vite__wasmImportInstance_${i}`;
|
|
28410
|
+
importStatements.push(`import * as ${ns} from ${JSON.stringify(from + wasmInstanceSuffix)};`);
|
|
28411
|
+
for (const { name } of globals) value.push({
|
|
28412
|
+
key: JSON.stringify(name),
|
|
28413
|
+
value: `${ns}[${JSON.stringify(name)}]`
|
|
28414
|
+
});
|
|
28415
|
+
}
|
|
27850
28416
|
return {
|
|
27851
28417
|
key: JSON.stringify(from),
|
|
27852
|
-
value
|
|
27853
|
-
return {
|
|
27854
|
-
key: JSON.stringify(name),
|
|
27855
|
-
value: `__vite__wasmImport_${i}[${JSON.stringify(name)}]`
|
|
27856
|
-
};
|
|
27857
|
-
})
|
|
28418
|
+
value
|
|
27858
28419
|
};
|
|
27859
28420
|
});
|
|
27860
28421
|
const initCode = `const __vite__wasmModule = (await ${names.initWasm}(${codegenSimpleObject(importObject)}, ${names.wasmUrl})).exports;`;
|
|
27861
28422
|
if (wasmInfo.exports.length === 0) return [...importStatements, initCode].join("\n");
|
|
27862
28423
|
const exportStatements = [];
|
|
27863
28424
|
const nameMap = /* @__PURE__ */ new Map();
|
|
27864
|
-
for (const [index, name] of wasmInfo.exports.entries()) if (isValidJsDeclareName(name)) exportStatements.push(` ${name},`);
|
|
28425
|
+
for (const [index, { name }] of wasmInfo.exports.entries()) if (isValidJsDeclareName(name)) exportStatements.push(` ${name},`);
|
|
27865
28426
|
else {
|
|
27866
28427
|
const placeholderName = `__vite__wasmExport_${index}`;
|
|
27867
28428
|
exportStatements.push(` ${JSON.stringify(name)}: ${placeholderName},`);
|
|
@@ -27871,7 +28432,7 @@ function generateGlueCode(wasmInfo, names) {
|
|
|
27871
28432
|
exportStatements.unshift(`const {`);
|
|
27872
28433
|
exportStatements.push(`} = __vite__wasmModule;`);
|
|
27873
28434
|
exportStatements.push(`export {`);
|
|
27874
|
-
for (const name of wasmInfo.exports) {
|
|
28435
|
+
for (const { name } of wasmInfo.exports) {
|
|
27875
28436
|
const localName = nameMap.get(name);
|
|
27876
28437
|
if (localName) exportStatements.push(` ${localName} as ${JSON.stringify(name)},`);
|
|
27877
28438
|
else exportStatements.push(` ${name},`);
|
|
@@ -27887,6 +28448,34 @@ function generateGlueCode(wasmInfo, names) {
|
|
|
27887
28448
|
...exportStatements
|
|
27888
28449
|
].join("\n");
|
|
27889
28450
|
}
|
|
28451
|
+
function generateWrapperGlue(wasmInfo, instanceId) {
|
|
28452
|
+
const instanceIdLiteral = JSON.stringify(instanceId);
|
|
28453
|
+
const lines = [`export * from ${instanceIdLiteral};`];
|
|
28454
|
+
if (wasmInfo.exports.some((e) => e.name === "default")) lines.push(`export { default } from ${instanceIdLiteral};`);
|
|
28455
|
+
const imports = [];
|
|
28456
|
+
const bindings = [];
|
|
28457
|
+
const unwraps = [];
|
|
28458
|
+
const reExports = [];
|
|
28459
|
+
for (const [index, { name, isGlobal }] of wasmInfo.exports.entries()) {
|
|
28460
|
+
if (!isGlobal || name === "default") continue;
|
|
28461
|
+
const alias = `__vite__wasmGlobal_${index}`;
|
|
28462
|
+
imports.push(`${codegenModuleExportName(name)} as ${alias}`);
|
|
28463
|
+
const binding = isValidJsDeclareName(name) ? name : `__vite__wasmGlobalValue_${index}`;
|
|
28464
|
+
bindings.push(binding);
|
|
28465
|
+
unwraps.push(`try { ${binding} = ${alias}.value; } catch {}`);
|
|
28466
|
+
reExports.push(binding === name ? name : `${binding} as ${JSON.stringify(name)}`);
|
|
28467
|
+
}
|
|
28468
|
+
if (bindings.length > 0) {
|
|
28469
|
+
lines.push(`import { ${imports.join(", ")} } from ${instanceIdLiteral};`);
|
|
28470
|
+
lines.push(`let ${bindings.join(", ")};`);
|
|
28471
|
+
lines.push(...unwraps);
|
|
28472
|
+
lines.push(`export { ${reExports.join(", ")} };`);
|
|
28473
|
+
}
|
|
28474
|
+
return lines.join("\n");
|
|
28475
|
+
}
|
|
28476
|
+
function codegenModuleExportName(name) {
|
|
28477
|
+
return isValidJsDeclareName(name) ? name : JSON.stringify(name);
|
|
28478
|
+
}
|
|
27890
28479
|
function codegenSimpleObject(obj) {
|
|
27891
28480
|
if (obj.length === 0) return "{}";
|
|
27892
28481
|
return `{ ${obj.map(({ key, value }) => {
|
|
@@ -28075,8 +28664,10 @@ function workerImportMetaUrlPlugin(config) {
|
|
|
28075
28664
|
let builtUrl;
|
|
28076
28665
|
if (isBundled) {
|
|
28077
28666
|
const result = await workerFileToUrl(config, file);
|
|
28078
|
-
if (this.environment.config.command === "serve")
|
|
28079
|
-
|
|
28667
|
+
if (this.environment.config.command === "serve") {
|
|
28668
|
+
emitWorkerAssetsForBundledDev(this, config);
|
|
28669
|
+
builtUrl = toOutputFilePathInJSForBundledDev(this.environment, result.entryFilename);
|
|
28670
|
+
} else builtUrl = result.entryUrlPlaceholder;
|
|
28080
28671
|
for (const file of result.watchedFiles) this.addWatchFile(file);
|
|
28081
28672
|
} else {
|
|
28082
28673
|
builtUrl = await fileToUrl$1(this, cleanUrl(file));
|
|
@@ -30066,7 +30657,11 @@ var EnvironmentPluginContainer = class {
|
|
|
30066
30657
|
}
|
|
30067
30658
|
this._started = true;
|
|
30068
30659
|
const config = this.environment.getTopLevelConfig();
|
|
30069
|
-
|
|
30660
|
+
const hookPromise = this.handleHookPromise(this.hookParallel("buildStart", (plugin) => this._getPluginContext(plugin), () => [this.options], (plugin) => this.environment.name === "client" || config.server.perEnvironmentStartEndDuringDev || plugin.perEnvironmentStartEndDuringDev));
|
|
30661
|
+
this._buildStartPromise = (async () => {
|
|
30662
|
+
await hookPromise;
|
|
30663
|
+
if (this.environment.mode === "dev") await this.environment._registerInputsAsSafeModules();
|
|
30664
|
+
})();
|
|
30070
30665
|
await this._buildStartPromise;
|
|
30071
30666
|
this._buildStartPromise = void 0;
|
|
30072
30667
|
}
|
|
@@ -30688,7 +31283,7 @@ function scanImports(environment) {
|
|
|
30688
31283
|
async function scan() {
|
|
30689
31284
|
const entries = await computeEntries(environment);
|
|
30690
31285
|
if (!entries.length) {
|
|
30691
|
-
if (!config.optimizeDeps.entries && !config.optimizeDeps.include) environment.logger.warn(import_picocolors.default.yellow("(!) Could not auto-determine entry point from rolldownOptions or html files and there are no explicit optimizeDeps.include patterns. Skipping dependency pre-bundling."));
|
|
31286
|
+
if (!config.optimizeDeps.entries && !config.optimizeDeps.include && !config.input) environment.logger.warn(import_picocolors.default.yellow("(!) Could not auto-determine entry point from rolldownOptions or html files and there are no explicit optimizeDeps.include patterns. Skipping dependency pre-bundling."));
|
|
30692
31287
|
return;
|
|
30693
31288
|
}
|
|
30694
31289
|
if (scanContext.cancelled) return;
|
|
@@ -30730,9 +31325,9 @@ function scanImports(environment) {
|
|
|
30730
31325
|
async function computeEntries(environment) {
|
|
30731
31326
|
let entries = [];
|
|
30732
31327
|
const explicitEntryPatterns = environment.config.optimizeDeps.entries;
|
|
30733
|
-
const
|
|
31328
|
+
const input = environment.config.input ?? environment.config.build.rolldownOptions.input;
|
|
30734
31329
|
if (explicitEntryPatterns) entries = await globEntries(explicitEntryPatterns, environment);
|
|
30735
|
-
else if (
|
|
31330
|
+
else if (input) {
|
|
30736
31331
|
const resolvePath = async (p) => {
|
|
30737
31332
|
const id = (await environment.pluginContainer.resolveId(p, void 0, {
|
|
30738
31333
|
isEntry: true,
|
|
@@ -30741,9 +31336,9 @@ async function computeEntries(environment) {
|
|
|
30741
31336
|
if (id === void 0) throw new Error(`failed to resolve rolldownOptions.input value: ${JSON.stringify(p)}.`);
|
|
30742
31337
|
return id;
|
|
30743
31338
|
};
|
|
30744
|
-
if (typeof
|
|
30745
|
-
else if (Array.isArray(
|
|
30746
|
-
else if (isObject$1(
|
|
31339
|
+
if (typeof input === "string") entries = [await resolvePath(input)];
|
|
31340
|
+
else if (Array.isArray(input)) entries = await Promise.all(input.map(resolvePath));
|
|
31341
|
+
else if (isObject$1(input)) entries = await Promise.all(Object.values(input).map(resolvePath));
|
|
30747
31342
|
else throw new Error("invalid rolldownOptions.input value.");
|
|
30748
31343
|
} else entries = await globEntries("**/*.html", environment);
|
|
30749
31344
|
entries = entries.filter((entry) => isScannable(entry, environment.config.optimizeDeps.extensions) && fs.existsSync(entry));
|
|
@@ -31881,6 +32476,11 @@ function isSingleDefaultExport(exports) {
|
|
|
31881
32476
|
return exports.length === 1 && exports[0] === "default";
|
|
31882
32477
|
}
|
|
31883
32478
|
const lockfileFormats = [
|
|
32479
|
+
{
|
|
32480
|
+
path: "node_modules/.pnpm/lock.yaml",
|
|
32481
|
+
checkPatchesDir: false,
|
|
32482
|
+
manager: "pnpm"
|
|
32483
|
+
},
|
|
31884
32484
|
{
|
|
31885
32485
|
path: "node_modules/.package-lock.json",
|
|
31886
32486
|
checkPatchesDir: "patches",
|
|
@@ -31891,6 +32491,26 @@ const lockfileFormats = [
|
|
|
31891
32491
|
checkPatchesDir: false,
|
|
31892
32492
|
manager: "yarn"
|
|
31893
32493
|
},
|
|
32494
|
+
{
|
|
32495
|
+
path: "bun.lock",
|
|
32496
|
+
checkPatchesDir: "patches",
|
|
32497
|
+
manager: "bun"
|
|
32498
|
+
},
|
|
32499
|
+
{
|
|
32500
|
+
path: ".rush/temp/shrinkwrap-deps.json",
|
|
32501
|
+
checkPatchesDir: false,
|
|
32502
|
+
manager: "pnpm"
|
|
32503
|
+
},
|
|
32504
|
+
{
|
|
32505
|
+
path: "aube-lock.yaml",
|
|
32506
|
+
checkPatchesDir: false,
|
|
32507
|
+
manager: "aube"
|
|
32508
|
+
},
|
|
32509
|
+
{
|
|
32510
|
+
path: "nub.lock",
|
|
32511
|
+
checkPatchesDir: "patches",
|
|
32512
|
+
manager: "nub"
|
|
32513
|
+
},
|
|
31894
32514
|
{
|
|
31895
32515
|
path: ".pnp.cjs",
|
|
31896
32516
|
checkPatchesDir: ".yarn/patches",
|
|
@@ -31906,21 +32526,6 @@ const lockfileFormats = [
|
|
|
31906
32526
|
checkPatchesDir: "patches",
|
|
31907
32527
|
manager: "yarn"
|
|
31908
32528
|
},
|
|
31909
|
-
{
|
|
31910
|
-
path: "node_modules/.pnpm/lock.yaml",
|
|
31911
|
-
checkPatchesDir: false,
|
|
31912
|
-
manager: "pnpm"
|
|
31913
|
-
},
|
|
31914
|
-
{
|
|
31915
|
-
path: ".rush/temp/shrinkwrap-deps.json",
|
|
31916
|
-
checkPatchesDir: false,
|
|
31917
|
-
manager: "pnpm"
|
|
31918
|
-
},
|
|
31919
|
-
{
|
|
31920
|
-
path: "bun.lock",
|
|
31921
|
-
checkPatchesDir: "patches",
|
|
31922
|
-
manager: "bun"
|
|
31923
|
-
},
|
|
31924
32529
|
{
|
|
31925
32530
|
path: "bun.lockb",
|
|
31926
32531
|
checkPatchesDir: "patches",
|
|
@@ -32853,7 +33458,7 @@ const _buildEnvironmentOptionsDefaults = Object.freeze({
|
|
|
32853
33458
|
watch: null
|
|
32854
33459
|
});
|
|
32855
33460
|
const buildEnvironmentOptionsDefaults = _buildEnvironmentOptionsDefaults;
|
|
32856
|
-
function resolveBuildEnvironmentOptions(raw, logger, consumer, isBundledDev, isSsrTargetWebworkerEnvironment) {
|
|
33461
|
+
function resolveBuildEnvironmentOptions(raw, logger, consumer, isBundledDev, input, isSsrTargetWebworkerEnvironment) {
|
|
32857
33462
|
const deprecatedPolyfillModulePreload = raw.polyfillModulePreload;
|
|
32858
33463
|
const { polyfillModulePreload, ...rest } = raw;
|
|
32859
33464
|
raw = rest;
|
|
@@ -32874,6 +33479,7 @@ function resolveBuildEnvironmentOptions(raw, logger, consumer, isBundledDev, isS
|
|
|
32874
33479
|
platform: consumer === "client" || isSsrTargetWebworkerEnvironment ? "browser" : "node",
|
|
32875
33480
|
...merged.rolldownOptions
|
|
32876
33481
|
};
|
|
33482
|
+
if (merged.lib && merged.lib.entry == null && input != null) merged.lib.entry = input;
|
|
32877
33483
|
if (merged.target === "baseline-widely-available") merged.target = ESBUILD_BASELINE_WIDELY_AVAILABLE_TARGET;
|
|
32878
33484
|
if (Array.isArray(merged.target)) merged.target = unique(merged.target);
|
|
32879
33485
|
if (merged.minify === "false") merged.minify = false;
|
|
@@ -32935,7 +33541,9 @@ function resolveRolldownOptions(environment, chunkMetadataMap) {
|
|
|
32935
33541
|
const { logger } = environment;
|
|
32936
33542
|
const ssr = environment.config.consumer === "server";
|
|
32937
33543
|
const resolve = (p) => path.resolve(root, p);
|
|
32938
|
-
const
|
|
33544
|
+
const topLevelInput = environment.config.input;
|
|
33545
|
+
if (libOptions && libOptions.entry == null) throw new Error(`Either "build.lib.entry" or the top-level "input" option is required when "build.lib" is set.`);
|
|
33546
|
+
const input = libOptions ? options.rolldownOptions.input || (typeof libOptions.entry === "string" ? resolve(libOptions.entry) : Array.isArray(libOptions.entry) ? libOptions.entry.map(resolve) : Object.fromEntries(Object.entries(libOptions.entry).map(([alias, file]) => [alias, resolve(file)]))) : typeof options.ssr === "string" ? resolve(options.ssr) : options.rolldownOptions.input || (topLevelInput ?? resolve("index.html"));
|
|
32939
33547
|
if (ssr && typeof input === "string" && input.endsWith(".html")) throw new Error("rolldownOptions.input should not be an html file when building for SSR. Please specify a dedicated SSR entry.");
|
|
32940
33548
|
if (options.cssCodeSplit === false) {
|
|
32941
33549
|
if ((typeof input === "string" ? [input] : Array.isArray(input) ? input : Object.values(input)).some((input) => input.endsWith(".css"))) throw new Error(`When "build.cssCodeSplit: false" is set, "rolldownOptions.input" should not include CSS files.`);
|
|
@@ -33117,7 +33725,7 @@ function resolveLibFilename(libOptions, format, entryName, root, extension, pack
|
|
|
33117
33725
|
}
|
|
33118
33726
|
function resolveBuildOutputs(outputs, libOptions, logger) {
|
|
33119
33727
|
if (libOptions) {
|
|
33120
|
-
const libHasMultipleEntries = typeof libOptions.entry !== "string" && Object.values(libOptions.entry).length > 1;
|
|
33728
|
+
const libHasMultipleEntries = typeof libOptions.entry !== "string" && libOptions.entry && Object.values(libOptions.entry).length > 1;
|
|
33121
33729
|
const libFormats = libOptions.formats || (libHasMultipleEntries ? ["es", "cjs"] : ["es", "umd"]);
|
|
33122
33730
|
if (!Array.isArray(outputs)) {
|
|
33123
33731
|
if (libFormats.includes("umd") || libFormats.includes("iife")) {
|
|
@@ -34353,7 +34961,6 @@ var BundledDev = class {
|
|
|
34353
34961
|
initialBuildCompleted = false;
|
|
34354
34962
|
_closed = false;
|
|
34355
34963
|
clients = new Clients();
|
|
34356
|
-
invalidateCalledModules = /* @__PURE__ */ new Map();
|
|
34357
34964
|
debouncedFullReload = debounce(20, () => {
|
|
34358
34965
|
this.environment.hot.send({
|
|
34359
34966
|
type: "full-reload",
|
|
@@ -34362,6 +34969,16 @@ var BundledDev = class {
|
|
|
34362
34969
|
this.environment.logger.info(import_picocolors.default.green(`page reload`), { timestamp: true });
|
|
34363
34970
|
});
|
|
34364
34971
|
fullReloadPending = false;
|
|
34972
|
+
reloadNeededClientIds = /* @__PURE__ */ new Set();
|
|
34973
|
+
debouncedReloadNeededFlush = debounce(20, () => {
|
|
34974
|
+
if (this.lastBuildError || this.reloadNeededClientIds.size === 0) return;
|
|
34975
|
+
for (const clientId of this.reloadNeededClientIds) this.clients.get(clientId)?.send({
|
|
34976
|
+
type: "full-reload",
|
|
34977
|
+
path: "*"
|
|
34978
|
+
});
|
|
34979
|
+
this.reloadNeededClientIds.clear();
|
|
34980
|
+
this.environment.logger.info(import_picocolors.default.green(`page reload`), { timestamp: true });
|
|
34981
|
+
});
|
|
34365
34982
|
lastBuildError = null;
|
|
34366
34983
|
memoryFiles = new MemoryFiles();
|
|
34367
34984
|
constructor(environment) {
|
|
@@ -34372,15 +34989,16 @@ var BundledDev = class {
|
|
|
34372
34989
|
if (!this._devEngine) throw new Error(`dev engine was not yet initialized`);
|
|
34373
34990
|
return this._devEngine;
|
|
34374
34991
|
}
|
|
34992
|
+
pendingPayloadFilenames = /* @__PURE__ */ new Set();
|
|
34375
34993
|
async listen() {
|
|
34376
34994
|
this._closed = false;
|
|
34377
34995
|
debug$1?.("INITIAL: setup bundle options");
|
|
34378
34996
|
const rolldownOptions = await this.getRolldownOptions();
|
|
34379
34997
|
if (Array.isArray(rolldownOptions.output) && rolldownOptions.output.length > 1) throw new Error("multiple output options are not supported in dev mode");
|
|
34380
34998
|
const outputOptions = Array.isArray(rolldownOptions.output) ? rolldownOptions.output[0] : rolldownOptions.output;
|
|
34381
|
-
this.environment.hot.on("vite:
|
|
34999
|
+
this.environment.hot.on("vite:client-connected", async (payload, client) => {
|
|
34382
35000
|
this.clients.setupIfNeeded(client, payload.clientId);
|
|
34383
|
-
this.devEngine.
|
|
35001
|
+
this.devEngine.registerClient(payload.clientId);
|
|
34384
35002
|
});
|
|
34385
35003
|
this.environment.hot.on("vite:client:connect", (_payload, client) => {
|
|
34386
35004
|
if (this.lastBuildError) {
|
|
@@ -34393,11 +35011,26 @@ var BundledDev = class {
|
|
|
34393
35011
|
});
|
|
34394
35012
|
this.environment.hot.on("vite:client:disconnect", (_payload, client) => {
|
|
34395
35013
|
const clientId = this.clients.delete(client);
|
|
34396
|
-
if (clientId)
|
|
35014
|
+
if (clientId) {
|
|
35015
|
+
this.devEngine.removeClient(clientId);
|
|
35016
|
+
this.reloadNeededClientIds.delete(clientId);
|
|
35017
|
+
}
|
|
35018
|
+
});
|
|
35019
|
+
this.environment.hot.on("vite:bundled-dev:reload-needed", (payload, client) => {
|
|
35020
|
+
const clientId = this.clients.getId(client);
|
|
35021
|
+
if (!clientId) return;
|
|
35022
|
+
debug$1?.(`TRIGGER: client ${clientId} requested a page reload (${payload.reason})`);
|
|
35023
|
+
this.environment.logger.info(import_picocolors.default.green(`bundling for page reload `) + import_picocolors.default.dim(payload.reason), {
|
|
35024
|
+
clear: true,
|
|
35025
|
+
timestamp: true
|
|
35026
|
+
});
|
|
35027
|
+
this.reloadNeededClientIds.add(clientId);
|
|
35028
|
+
this.ensureOutputAndFlushReloadNeeded();
|
|
34397
35029
|
});
|
|
34398
35030
|
this._devEngine = await dev(rolldownOptions, outputOptions, {
|
|
34399
35031
|
onHmrUpdates: (result) => {
|
|
34400
35032
|
if (result instanceof Error) {
|
|
35033
|
+
this.environment.logger.error(import_picocolors.default.red(`✘ Build error: ${result.message}`), { error: result });
|
|
34401
35034
|
for (const client of this.clients.getAll()) client.send({
|
|
34402
35035
|
type: "error",
|
|
34403
35036
|
err: prepareError(result)
|
|
@@ -34412,11 +35045,9 @@ var BundledDev = class {
|
|
|
34412
35045
|
}
|
|
34413
35046
|
for (const { clientId, update } of updates) {
|
|
34414
35047
|
const client = this.clients.get(clientId);
|
|
34415
|
-
if (client)
|
|
34416
|
-
this.invalidateCalledModules.get(client)?.clear();
|
|
34417
|
-
this.handleHmrOutput(client, changedFiles, update);
|
|
34418
|
-
}
|
|
35048
|
+
if (client) this.handleHmrOutput(client, changedFiles, update);
|
|
34419
35049
|
}
|
|
35050
|
+
if (this.reloadNeededClientIds.size) this.ensureOutputAndFlushReloadNeeded();
|
|
34420
35051
|
},
|
|
34421
35052
|
onOutput: (result) => {
|
|
34422
35053
|
if (result instanceof Error) {
|
|
@@ -34435,6 +35066,7 @@ var BundledDev = class {
|
|
|
34435
35066
|
this.fullReloadPending = false;
|
|
34436
35067
|
this.debouncedFullReload();
|
|
34437
35068
|
}
|
|
35069
|
+
if (this.reloadNeededClientIds.size) this.debouncedReloadNeededFlush();
|
|
34438
35070
|
},
|
|
34439
35071
|
onAdditionalAssets: (result) => {
|
|
34440
35072
|
this.storeOutputFiles(result.output);
|
|
@@ -34450,11 +35082,12 @@ var BundledDev = class {
|
|
|
34450
35082
|
this.waitForInitialBuildFinish().then(() => {
|
|
34451
35083
|
if (this._closed) return;
|
|
34452
35084
|
debug$1?.("INITIAL: build done");
|
|
34453
|
-
this.
|
|
35085
|
+
this.initialBuildCompleted = true;
|
|
35086
|
+
if (!this.lastBuildError) this.environment.hot.send({
|
|
34454
35087
|
type: "full-reload",
|
|
34455
|
-
path: "*"
|
|
35088
|
+
path: "*",
|
|
35089
|
+
ifFallback: true
|
|
34456
35090
|
});
|
|
34457
|
-
this.initialBuildCompleted = true;
|
|
34458
35091
|
});
|
|
34459
35092
|
}
|
|
34460
35093
|
async waitForInitialBuildFinish() {
|
|
@@ -34470,28 +35103,8 @@ var BundledDev = class {
|
|
|
34470
35103
|
state = await this.devEngine.getBundleState();
|
|
34471
35104
|
}
|
|
34472
35105
|
}
|
|
34473
|
-
|
|
34474
|
-
|
|
34475
|
-
if (invalidateCalledModules?.has(m.path)) {
|
|
34476
|
-
debug$1?.(`INVALIDATE: invalidate received from ${m.path}, but ignored because it was already invalidated`);
|
|
34477
|
-
return;
|
|
34478
|
-
}
|
|
34479
|
-
debug$1?.(`INVALIDATE: invalidate received from ${m.path}, re-triggering HMR`);
|
|
34480
|
-
if (!invalidateCalledModules) this.invalidateCalledModules.set(client, /* @__PURE__ */ new Set([]));
|
|
34481
|
-
this.invalidateCalledModules.get(client).add(m.path);
|
|
34482
|
-
let update;
|
|
34483
|
-
try {
|
|
34484
|
-
update = (await this.devEngine.invalidate(m.path, m.firstInvalidatedBy)).find((u) => this.clients.get(u.clientId) === client)?.update;
|
|
34485
|
-
} catch (e) {
|
|
34486
|
-
client.send({
|
|
34487
|
-
type: "error",
|
|
34488
|
-
err: prepareError(e)
|
|
34489
|
-
});
|
|
34490
|
-
return;
|
|
34491
|
-
}
|
|
34492
|
-
if (!update) return;
|
|
34493
|
-
if (update.type === "Patch") this.environment.logger.info(import_picocolors.default.yellow(`hmr invalidate `) + import_picocolors.default.dim(m.path) + (m.message ? ` ${m.message}` : ""), { timestamp: true });
|
|
34494
|
-
this.handleHmrOutput(client, [m.path], update, { firstInvalidatedBy: m.firstInvalidatedBy });
|
|
35106
|
+
ensureOutputAndFlushReloadNeeded() {
|
|
35107
|
+
this.devEngine.ensureLatestBuildOutput().then(() => this.debouncedReloadNeededFlush(), () => {});
|
|
34495
35108
|
}
|
|
34496
35109
|
async triggerBundleRegenerationIfStale() {
|
|
34497
35110
|
const bundleState = await this.devEngine.getBundleState();
|
|
@@ -34515,7 +35128,19 @@ var BundledDev = class {
|
|
|
34515
35128
|
async triggerLazyBundling(moduleId, clientId) {
|
|
34516
35129
|
if (!moduleId || !clientId) return;
|
|
34517
35130
|
debug$1?.(`TRIGGER-LAZY: trigger lazy bundling for module ${moduleId} for client ${clientId}`);
|
|
34518
|
-
|
|
35131
|
+
const result = await this.devEngine.compileEntry(moduleId, clientId);
|
|
35132
|
+
this.pendingPayloadFilenames.add(result.filename);
|
|
35133
|
+
return result;
|
|
35134
|
+
}
|
|
35135
|
+
/**
|
|
35136
|
+
* Called by the serving middlewares when the response for a payload completed.
|
|
35137
|
+
* Only delivered payloads are recorded on the server's per-client ship map, so
|
|
35138
|
+
* later chunks may omit a module only if the payload carrying it was delivered.
|
|
35139
|
+
*
|
|
35140
|
+
* Note: the payload filename is unique across all clients.
|
|
35141
|
+
*/
|
|
35142
|
+
markPayloadDelivered(filename) {
|
|
35143
|
+
if (this.pendingPayloadFilenames.delete(filename)) this.devEngine.notifyPayloadDelivered(filename);
|
|
34519
35144
|
}
|
|
34520
35145
|
async close() {
|
|
34521
35146
|
this._closed = true;
|
|
@@ -34573,46 +35198,35 @@ var BundledDev = class {
|
|
|
34573
35198
|
}
|
|
34574
35199
|
return rolldownOptions;
|
|
34575
35200
|
}
|
|
34576
|
-
handleHmrOutput(client, files, hmrOutput
|
|
35201
|
+
handleHmrOutput(client, files, hmrOutput) {
|
|
34577
35202
|
if (hmrOutput.type === "Noop") return;
|
|
34578
35203
|
const shortFile = files.map((file) => getShortName(file, this.environment.config.root)).join(", ");
|
|
34579
35204
|
if (hmrOutput.type === "FullReload") {
|
|
34580
35205
|
const reason = hmrOutput.reason ? import_picocolors.default.dim(` (${hmrOutput.reason})`) : "";
|
|
34581
35206
|
this.environment.logger.info(import_picocolors.default.green(`trigger page reload `) + import_picocolors.default.dim(shortFile) + reason, {
|
|
34582
|
-
clear:
|
|
35207
|
+
clear: true,
|
|
34583
35208
|
timestamp: true
|
|
34584
35209
|
});
|
|
34585
|
-
|
|
34586
|
-
this.debouncedFullReload();
|
|
34587
|
-
});
|
|
34588
|
-
else this.fullReloadPending = true;
|
|
35210
|
+
this.fullReloadPending = true;
|
|
34589
35211
|
return;
|
|
34590
35212
|
}
|
|
34591
35213
|
debug$1?.(`handle hmr output for ${shortFile}`, {
|
|
34592
35214
|
...hmrOutput,
|
|
34593
35215
|
code: typeof hmrOutput.code === "string" ? "[code]" : hmrOutput.code
|
|
34594
35216
|
});
|
|
35217
|
+
this.pendingPayloadFilenames.add(hmrOutput.filename);
|
|
34595
35218
|
this.memoryFiles.set(hmrOutput.filename, { source: hmrOutput.code + "\n; export {}" });
|
|
34596
35219
|
if (hmrOutput.sourcemapFilename && hmrOutput.sourcemap) this.memoryFiles.set(hmrOutput.sourcemapFilename, { source: hmrOutput.sourcemap });
|
|
34597
|
-
const updates = hmrOutput.hmrBoundaries.map((boundary) => {
|
|
34598
|
-
return {
|
|
34599
|
-
type: "js-update",
|
|
34600
|
-
url: hmrOutput.filename,
|
|
34601
|
-
path: boundary.boundary,
|
|
34602
|
-
acceptedPath: boundary.acceptedVia,
|
|
34603
|
-
firstInvalidatedBy: invalidateInformation?.firstInvalidatedBy,
|
|
34604
|
-
timestamp: Date.now()
|
|
34605
|
-
};
|
|
34606
|
-
});
|
|
34607
35220
|
client.send({
|
|
34608
|
-
type: "update",
|
|
34609
|
-
|
|
35221
|
+
type: "bundled-dev-update",
|
|
35222
|
+
changedIds: hmrOutput.changedIds,
|
|
35223
|
+
url: hmrOutput.filename,
|
|
35224
|
+
seq: hmrOutput.seq
|
|
34610
35225
|
});
|
|
34611
|
-
const
|
|
34612
|
-
|
|
34613
|
-
if (truncated) debugHmr?.(`hmr update ${filePaths.join(", ")}`);
|
|
35226
|
+
const { formatted, truncated } = formatAndTruncateFileList(hmrOutput.changedIds);
|
|
35227
|
+
if (truncated) debugHmr?.(`hmr update ${hmrOutput.changedIds.join(", ")}`);
|
|
34614
35228
|
this.environment.logger.info(import_picocolors.default.green(`hmr update `) + import_picocolors.default.dim(formatted), {
|
|
34615
|
-
clear:
|
|
35229
|
+
clear: true,
|
|
34616
35230
|
timestamp: true
|
|
34617
35231
|
});
|
|
34618
35232
|
}
|
|
@@ -34629,6 +35243,9 @@ var Clients = class {
|
|
|
34629
35243
|
get(id) {
|
|
34630
35244
|
return this.idToClient.get(id);
|
|
34631
35245
|
}
|
|
35246
|
+
getId(client) {
|
|
35247
|
+
return this.clientToId.get(client);
|
|
35248
|
+
}
|
|
34632
35249
|
getAll() {
|
|
34633
35250
|
return Array.from(this.idToClient.values());
|
|
34634
35251
|
}
|
|
@@ -34744,6 +35361,23 @@ var DevEnvironment = class extends BaseEnvironment {
|
|
|
34744
35361
|
this._initiated = true;
|
|
34745
35362
|
this._pluginContainer = await createEnvironmentPluginContainer(this, this.config.plugins, options?.watcher);
|
|
34746
35363
|
}
|
|
35364
|
+
/** @internal */
|
|
35365
|
+
async _registerInputsAsSafeModules() {
|
|
35366
|
+
const input = this.config.input;
|
|
35367
|
+
const entries = input == null ? ["index.html"] : typeof input === "string" ? [input] : Array.isArray(input) ? input : Object.values(input);
|
|
35368
|
+
const resolveEntries = async () => {
|
|
35369
|
+
const resolvedEntries = await Promise.all(entries.map((entry) => this.pluginContainer.resolveId(entry, void 0, {
|
|
35370
|
+
isEntry: true,
|
|
35371
|
+
scan: true
|
|
35372
|
+
})));
|
|
35373
|
+
for (const resolved of resolvedEntries) if (resolved && !resolved.external) {
|
|
35374
|
+
const resolvedId = cleanUrl(resolved.id);
|
|
35375
|
+
if (path.isAbsolute(resolvedId)) this.getTopLevelConfig().safeModulePaths.add(resolvedId);
|
|
35376
|
+
}
|
|
35377
|
+
};
|
|
35378
|
+
if (input == null) await resolveEntries().catch(() => {});
|
|
35379
|
+
else await resolveEntries();
|
|
35380
|
+
}
|
|
34747
35381
|
/**
|
|
34748
35382
|
* When the dev server is restarted, the methods are called in the following order:
|
|
34749
35383
|
* - new instance `init`
|
|
@@ -34786,10 +35420,7 @@ var DevEnvironment = class extends BaseEnvironment {
|
|
|
34786
35420
|
}
|
|
34787
35421
|
}
|
|
34788
35422
|
invalidateModule(m, _client) {
|
|
34789
|
-
if (this.bundledDev)
|
|
34790
|
-
this.bundledDev.invalidateModule(m, _client);
|
|
34791
|
-
return;
|
|
34792
|
-
}
|
|
35423
|
+
if (this.bundledDev) return;
|
|
34793
35424
|
const mod = this.moduleGraph.urlToModuleMap.get(m.path);
|
|
34794
35425
|
if (mod && mod.isSelfAccepting && mod.lastHMRTimestamp > 0 && !mod.lastHMRInvalidationReceived) {
|
|
34795
35426
|
mod.lastHMRInvalidationReceived = true;
|
|
@@ -35101,6 +35732,177 @@ async function preview(inlineConfig = {}) {
|
|
|
35101
35732
|
return server;
|
|
35102
35733
|
}
|
|
35103
35734
|
//#endregion
|
|
35735
|
+
//#region src/node/nativeConfigCompat.ts
|
|
35736
|
+
const jsTsExtRE = /\.[cm]?[jt]sx?$/;
|
|
35737
|
+
const indexFileRE = /^index\.[cm]?[jt]sx?$/;
|
|
35738
|
+
const lastSegmentOf = (specifier) => specifier.slice(specifier.lastIndexOf("/") + 1);
|
|
35739
|
+
/**
|
|
35740
|
+
* A specifier that already carries a JS/TS extension resolves as-is under the
|
|
35741
|
+
* native loader, so it can never be extension-less or a directory index and
|
|
35742
|
+
* needs no resolution to classify.
|
|
35743
|
+
*/
|
|
35744
|
+
const specifierHasJsExtension = (specifier) => jsTsExtRE.test(lastSegmentOf(specifier));
|
|
35745
|
+
function classifyImportRef(ref, resolvedId, file) {
|
|
35746
|
+
const { specifier, line, column } = ref;
|
|
35747
|
+
const base = {
|
|
35748
|
+
file,
|
|
35749
|
+
line,
|
|
35750
|
+
column,
|
|
35751
|
+
specifier
|
|
35752
|
+
};
|
|
35753
|
+
if (specifier.endsWith(".json")) {
|
|
35754
|
+
if (ref.hasTypeJsonAttribute) return void 0;
|
|
35755
|
+
return {
|
|
35756
|
+
type: "json-without-attributes",
|
|
35757
|
+
...base
|
|
35758
|
+
};
|
|
35759
|
+
}
|
|
35760
|
+
if (!resolvedId) return void 0;
|
|
35761
|
+
if (resolvedId.endsWith(".json") && !ref.hasTypeJsonAttribute) return {
|
|
35762
|
+
type: "json-without-attributes",
|
|
35763
|
+
...base
|
|
35764
|
+
};
|
|
35765
|
+
const lastSegment = lastSegmentOf(specifier);
|
|
35766
|
+
const specifierNamesIndex = lastSegment === "index" || indexFileRE.test(lastSegment);
|
|
35767
|
+
if (indexFileRE.test(path.basename(resolvedId)) && !specifierNamesIndex) return {
|
|
35768
|
+
type: "directory-index-import",
|
|
35769
|
+
...base
|
|
35770
|
+
};
|
|
35771
|
+
if (!jsTsExtRE.test(lastSegment)) return {
|
|
35772
|
+
type: "extensionless-import",
|
|
35773
|
+
...base
|
|
35774
|
+
};
|
|
35775
|
+
}
|
|
35776
|
+
const isPathSpecifier = (s) => s.startsWith(".") || path.isAbsolute(s);
|
|
35777
|
+
const hasTypeJson = (attributes) => !!attributes?.some((attr) => {
|
|
35778
|
+
return (attr.key.type === "Identifier" ? attr.key.name : attr.key.value) === "type" && attr.value?.value === "json";
|
|
35779
|
+
});
|
|
35780
|
+
const DIRNAME_FILENAME = {
|
|
35781
|
+
__dirname: "dirname",
|
|
35782
|
+
__filename: "filename"
|
|
35783
|
+
};
|
|
35784
|
+
function analyzeConfigModuleReferences(code, ast, file) {
|
|
35785
|
+
const imports = [];
|
|
35786
|
+
const addImportRef = (source, hasTypeJsonAttribute) => {
|
|
35787
|
+
if (!isPathSpecifier(source.value)) return;
|
|
35788
|
+
const { line, column } = numberToPos(code, source.start);
|
|
35789
|
+
imports.push({
|
|
35790
|
+
specifier: source.value,
|
|
35791
|
+
line,
|
|
35792
|
+
column,
|
|
35793
|
+
hasTypeJsonAttribute
|
|
35794
|
+
});
|
|
35795
|
+
};
|
|
35796
|
+
walk$1(ast, { enter(_node) {
|
|
35797
|
+
const node = _node;
|
|
35798
|
+
switch (node.type) {
|
|
35799
|
+
case "ImportDeclaration":
|
|
35800
|
+
addImportRef(node.source, hasTypeJson(node.attributes));
|
|
35801
|
+
break;
|
|
35802
|
+
case "ExportNamedDeclaration":
|
|
35803
|
+
case "ExportAllDeclaration":
|
|
35804
|
+
if (node.source) addImportRef(node.source, hasTypeJson(node.attributes));
|
|
35805
|
+
break;
|
|
35806
|
+
case "ImportExpression":
|
|
35807
|
+
if (node.source.type === "Literal" && typeof node.source.value === "string") addImportRef(node.source, node.options != null);
|
|
35808
|
+
break;
|
|
35809
|
+
}
|
|
35810
|
+
} });
|
|
35811
|
+
const globals = [];
|
|
35812
|
+
if (code.includes("__dirname") || code.includes("__filename")) {
|
|
35813
|
+
const { globals: freeReferences } = analyze(ast);
|
|
35814
|
+
for (const [name, type] of Object.entries(DIRNAME_FILENAME)) {
|
|
35815
|
+
const node = freeReferences.get(name);
|
|
35816
|
+
if (!node) continue;
|
|
35817
|
+
const { line, column } = numberToPos(code, node.start);
|
|
35818
|
+
globals.push({
|
|
35819
|
+
type,
|
|
35820
|
+
file,
|
|
35821
|
+
line,
|
|
35822
|
+
column
|
|
35823
|
+
});
|
|
35824
|
+
}
|
|
35825
|
+
}
|
|
35826
|
+
return {
|
|
35827
|
+
globals,
|
|
35828
|
+
imports
|
|
35829
|
+
};
|
|
35830
|
+
}
|
|
35831
|
+
const esmStatementTypes = /* @__PURE__ */ new Set([
|
|
35832
|
+
"ImportDeclaration",
|
|
35833
|
+
"ExportNamedDeclaration",
|
|
35834
|
+
"ExportDefaultDeclaration",
|
|
35835
|
+
"ExportAllDeclaration"
|
|
35836
|
+
]);
|
|
35837
|
+
function findEsmSyntaxInCjs(code, ast, file) {
|
|
35838
|
+
for (const node of ast.body) if (esmStatementTypes.has(node.type)) {
|
|
35839
|
+
const { line, column } = numberToPos(code, node.start);
|
|
35840
|
+
return {
|
|
35841
|
+
type: "esm-syntax-in-cjs",
|
|
35842
|
+
file,
|
|
35843
|
+
line,
|
|
35844
|
+
column
|
|
35845
|
+
};
|
|
35846
|
+
}
|
|
35847
|
+
}
|
|
35848
|
+
function describeIncompatibility(item, root) {
|
|
35849
|
+
const loc = `${normalizePath(path.relative(root, item.file))}:${item.line}:${item.column + 1}`;
|
|
35850
|
+
switch (item.type) {
|
|
35851
|
+
case "dirname": return `\`__dirname\` (${loc}). Use \`import.meta.dirname\` instead`;
|
|
35852
|
+
case "filename": return `\`__filename\` (${loc}). Use \`import.meta.filename\` instead`;
|
|
35853
|
+
case "extensionless-import": return `import "${item.specifier}" without a file extension (${loc}). Add the file extension`;
|
|
35854
|
+
case "directory-index-import": return `import "${item.specifier}" resolves to a directory index (${loc}). Import the index file directly`;
|
|
35855
|
+
case "json-without-attributes": return item.specifier?.endsWith(".json") ? `JSON import "${item.specifier}" without import attributes (${loc}). Add \`with { type: 'json' }\`` : `import "${item.specifier}" resolves to a JSON file (${loc}). Import it with a \`.json\` extension and \`with { type: 'json' }\``;
|
|
35856
|
+
case "esm-syntax-in-cjs": return `ESM syntax in a file loaded as CommonJS (${loc}). Use a \`.mjs\` extension or set \`"type": "module"\` in the closest package.json`;
|
|
35857
|
+
}
|
|
35858
|
+
}
|
|
35859
|
+
function formatNativeConfigIncompatWarning(items, root) {
|
|
35860
|
+
const header = "Your Vite config uses features that are unsupported by `configLoader: 'native'`, which is planned to become the default in a future major version of Vite:";
|
|
35861
|
+
const lines = items.map((it) => ` - ${describeIncompatibility(it, root)}`);
|
|
35862
|
+
const footer = `Set \`VITE_CONFIG_NATIVE_IGNORE_WARNING=true\` to suppress this warning.`;
|
|
35863
|
+
return import_picocolors.default.yellow([
|
|
35864
|
+
`(!) ${header}`,
|
|
35865
|
+
...lines,
|
|
35866
|
+
footer
|
|
35867
|
+
].join("\n"));
|
|
35868
|
+
}
|
|
35869
|
+
function createNativeConfigCompatPlugin(collector) {
|
|
35870
|
+
return {
|
|
35871
|
+
name: "vite:native-config-compat-check",
|
|
35872
|
+
transform: {
|
|
35873
|
+
filter: { id: {
|
|
35874
|
+
include: /\.[cm]?[jt]sx?$/,
|
|
35875
|
+
exclude: /^\0/
|
|
35876
|
+
} },
|
|
35877
|
+
async handler(code, id) {
|
|
35878
|
+
const isESM = typeof process.versions.deno === "string" || isFilePathESM(id);
|
|
35879
|
+
let program;
|
|
35880
|
+
try {
|
|
35881
|
+
const result = parseSync(id, code);
|
|
35882
|
+
if (result.errors.length > 0) return null;
|
|
35883
|
+
program = result.program;
|
|
35884
|
+
} catch {
|
|
35885
|
+
return null;
|
|
35886
|
+
}
|
|
35887
|
+
if (!isESM) {
|
|
35888
|
+
const finding = findEsmSyntaxInCjs(code, program, id);
|
|
35889
|
+
if (finding) collector.push(finding);
|
|
35890
|
+
return null;
|
|
35891
|
+
}
|
|
35892
|
+
const { globals, imports } = analyzeConfigModuleReferences(code, program, id);
|
|
35893
|
+
for (const g of globals) collector.push(g);
|
|
35894
|
+
for (const ref of imports) {
|
|
35895
|
+
let resolvedId = null;
|
|
35896
|
+
if (!ref.specifier.endsWith(".json") && !specifierHasJsExtension(ref.specifier)) resolvedId = (await this.resolve(ref.specifier, id))?.id ?? null;
|
|
35897
|
+
const finding = classifyImportRef(ref, resolvedId, id);
|
|
35898
|
+
if (finding) collector.push(finding);
|
|
35899
|
+
}
|
|
35900
|
+
return null;
|
|
35901
|
+
}
|
|
35902
|
+
}
|
|
35903
|
+
};
|
|
35904
|
+
}
|
|
35905
|
+
//#endregion
|
|
35104
35906
|
//#region src/node/ssr/index.ts
|
|
35105
35907
|
const _ssrConfigDefaults = Object.freeze({
|
|
35106
35908
|
target: "node",
|
|
@@ -35430,6 +36232,19 @@ const configDefaults = Object.freeze({
|
|
|
35430
36232
|
environments: {},
|
|
35431
36233
|
appType: "spa"
|
|
35432
36234
|
});
|
|
36235
|
+
function normalizeInput(input) {
|
|
36236
|
+
if (input === void 0) return;
|
|
36237
|
+
if (typeof input === "string") return unescapeGlobCharacters(input);
|
|
36238
|
+
if (Array.isArray(input)) return input.map(unescapeGlobCharacters);
|
|
36239
|
+
const resolved = {};
|
|
36240
|
+
for (const key in input) resolved[key] = unescapeGlobCharacters(input[key]);
|
|
36241
|
+
return resolved;
|
|
36242
|
+
}
|
|
36243
|
+
const escapedGlobCharactersRE = /\\([*?[\]{}()!+@|])/g;
|
|
36244
|
+
function unescapeGlobCharacters(value) {
|
|
36245
|
+
if (isDynamicPattern(value)) throw new Error(`\`input\` cannot contain glob characters. They are reserved, so the ${JSON.stringify(value)} is not allowed. Please escape them with a backslash (\\)`);
|
|
36246
|
+
return value.replace(escapedGlobCharactersRE, "$1");
|
|
36247
|
+
}
|
|
35433
36248
|
function resolveDevEnvironmentOptions(dev, environmentName, consumer, preTransformRequest) {
|
|
35434
36249
|
const resolved = mergeWithDefaults({
|
|
35435
36250
|
...configDefaults.dev,
|
|
@@ -35458,13 +36273,14 @@ function resolveEnvironmentOptions(options, alias, preserveSymlinks, forceOptimi
|
|
|
35458
36273
|
}
|
|
35459
36274
|
const resolve = resolveEnvironmentResolveOptions(options.resolve, alias, preserveSymlinks, logger, consumer, isSsrTargetWebworkerEnvironment);
|
|
35460
36275
|
return {
|
|
36276
|
+
input: normalizeInput(options.input),
|
|
35461
36277
|
define: options.define,
|
|
35462
36278
|
resolve,
|
|
35463
36279
|
keepProcessEnv: options.keepProcessEnv ?? (isSsrTargetWebworkerEnvironment ? false : consumer === "server"),
|
|
35464
36280
|
consumer,
|
|
35465
36281
|
optimizeDeps: resolveDepOptimizationOptions(options.optimizeDeps, resolve.preserveSymlinks, forceOptimizeDeps, consumer, logger),
|
|
35466
36282
|
dev: resolveDevEnvironmentOptions(options.dev, environmentName, consumer, preTransformRequests),
|
|
35467
|
-
build: resolveBuildEnvironmentOptions(options.build ?? {}, logger, consumer, isBundled && !isBuild, isSsrTargetWebworkerEnvironment),
|
|
36283
|
+
build: resolveBuildEnvironmentOptions(options.build ?? {}, logger, consumer, isBundled && !isBuild, options.input, isSsrTargetWebworkerEnvironment),
|
|
35468
36284
|
isBundled,
|
|
35469
36285
|
plugins: void 0,
|
|
35470
36286
|
optimizeDepsPluginNames: void 0
|
|
@@ -35656,7 +36472,11 @@ async function resolveConfig(inlineConfig, command, defaultMode = "development",
|
|
|
35656
36472
|
const tsconfigPathsPlugin = userPlugins.find((p) => p.name === "vite-tsconfig-paths" || p.name === "vite-plugin-tsconfig-paths");
|
|
35657
36473
|
if (tsconfigPathsPlugin) logger.warnOnce(import_picocolors.default.yellow(`The plugin ${JSON.stringify(tsconfigPathsPlugin.name)} is detected. Vite now supports tsconfig paths resolution natively via the ${import_picocolors.default.bold("resolve.tsconfigPaths")} option. You can remove the plugin and set ${import_picocolors.default.bold("resolve.tsconfigPaths: true")} in your Vite config instead.`));
|
|
35658
36474
|
if (process.versions.pnp) logger.warnOnce(import_picocolors.default.yellow(`Using Yarn PnP with Vite is discouraged and PnP-specific bugs will no longer be actively worked on. Please switch to a different ${import_picocolors.default.bold("nodeLinker")} mode or to a different package manager.`));
|
|
35659
|
-
|
|
36475
|
+
let nonNormalizedResolvedRoot = config.root ? path.resolve(config.root) : process.cwd();
|
|
36476
|
+
try {
|
|
36477
|
+
nonNormalizedResolvedRoot = safeRealpathSync(nonNormalizedResolvedRoot);
|
|
36478
|
+
} catch {}
|
|
36479
|
+
const resolvedRoot = normalizePath(nonNormalizedResolvedRoot);
|
|
35660
36480
|
checkBadCharactersInPath("The project root", "directory", resolvedRoot, logger);
|
|
35661
36481
|
const configEnvironmentsClient = config.environments.client;
|
|
35662
36482
|
configEnvironmentsClient.dev ??= {};
|
|
@@ -35688,6 +36508,7 @@ async function resolveConfig(inlineConfig, command, defaultMode = "development",
|
|
|
35688
36508
|
const defaultEnvironmentOptions = getDefaultEnvironmentOptions(config);
|
|
35689
36509
|
const defaultClientEnvironmentOptions = {
|
|
35690
36510
|
...defaultEnvironmentOptions,
|
|
36511
|
+
input: config.input,
|
|
35691
36512
|
resolve: config.resolve,
|
|
35692
36513
|
optimizeDeps: config.optimizeDeps
|
|
35693
36514
|
};
|
|
@@ -35714,7 +36535,7 @@ async function resolveConfig(inlineConfig, command, defaultMode = "development",
|
|
|
35714
36535
|
for (const environmentName of Object.keys(config.environments)) resolvedEnvironments[environmentName] = resolveEnvironmentOptions(config.environments[environmentName], resolvedDefaultResolve.alias, resolvedDefaultResolve.preserveSymlinks, inlineConfig.forceOptimizeDeps, logger, environmentName, isBuild, isBundledDev, config.ssr?.target === "webworker", config.server?.preTransformRequests);
|
|
35715
36536
|
const backwardCompatibleOptimizeDeps = resolvedEnvironments.client.optimizeDeps;
|
|
35716
36537
|
const resolvedDevEnvironmentOptions = resolveDevEnvironmentOptions(config.dev, void 0, void 0);
|
|
35717
|
-
const resolvedBuildOptions = resolveBuildEnvironmentOptions(config.build ?? {}, logger, void 0, isBundledDev);
|
|
36538
|
+
const resolvedBuildOptions = resolveBuildEnvironmentOptions(config.build ?? {}, logger, void 0, isBundledDev, config.input);
|
|
35718
36539
|
const ssr = resolveSSROptions({
|
|
35719
36540
|
...config.ssr,
|
|
35720
36541
|
external: resolvedEnvironments.ssr?.resolve.external,
|
|
@@ -35747,6 +36568,7 @@ async function resolveConfig(inlineConfig, command, defaultMode = "development",
|
|
|
35747
36568
|
const assetsFilter = config.assetsInclude && (!Array.isArray(config.assetsInclude) || config.assetsInclude.length) ? createFilter$1(config.assetsInclude) : () => false;
|
|
35748
36569
|
const { publicDir } = config;
|
|
35749
36570
|
const resolvedPublicDir = publicDir !== false && publicDir !== "" ? normalizePath(path.resolve(resolvedRoot, typeof publicDir === "string" ? publicDir : configDefaults.publicDir)) : "";
|
|
36571
|
+
const input = normalizeInput(config.input);
|
|
35750
36572
|
const server = await resolveServerOptions(resolvedRoot, config.server, logger);
|
|
35751
36573
|
const builder = resolveBuilderOptions(config.builder);
|
|
35752
36574
|
const BASE_URL = resolvedBase;
|
|
@@ -35871,6 +36693,7 @@ async function resolveConfig(inlineConfig, command, defaultMode = "development",
|
|
|
35871
36693
|
removeSsrLoadModule: "warn"
|
|
35872
36694
|
} : config.future,
|
|
35873
36695
|
ssr,
|
|
36696
|
+
input,
|
|
35874
36697
|
optimizeDeps: backwardCompatibleOptimizeDeps,
|
|
35875
36698
|
resolve: resolvedDefaultResolve,
|
|
35876
36699
|
dev: resolvedDevEnvironmentOptions,
|
|
@@ -35998,7 +36821,7 @@ async function loadConfigFromFile(configEnv, configFile, configRoot = process.cw
|
|
|
35998
36821
|
return null;
|
|
35999
36822
|
}
|
|
36000
36823
|
try {
|
|
36001
|
-
const { configExport, dependencies } = await (configLoader === "bundle" ? bundleAndLoadConfigFile : configLoader === "runner" ? runnerImportConfigFile : nativeImportConfigFile
|
|
36824
|
+
const { configExport, dependencies } = await (configLoader === "bundle" ? bundleAndLoadConfigFile(resolvedPath, configRoot, logLevel, customLogger) : configLoader === "runner" ? runnerImportConfigFile(resolvedPath) : nativeImportConfigFile(resolvedPath));
|
|
36002
36825
|
debug?.(`config file loaded in ${getTime()}`);
|
|
36003
36826
|
const config = await (typeof configExport === "function" ? configExport(configEnv) : configExport);
|
|
36004
36827
|
if (!isObject$1(config)) throw new Error(`config must export or return an object.`);
|
|
@@ -36035,11 +36858,13 @@ async function runnerImportConfigFile(resolvedPath) {
|
|
|
36035
36858
|
dependencies
|
|
36036
36859
|
};
|
|
36037
36860
|
}
|
|
36038
|
-
async function bundleAndLoadConfigFile(resolvedPath) {
|
|
36861
|
+
async function bundleAndLoadConfigFile(resolvedPath, configRoot, logLevel, customLogger) {
|
|
36039
36862
|
const isESM = typeof process.versions.deno === "string" || isFilePathESM(resolvedPath);
|
|
36040
36863
|
const bundled = await bundleConfigFile(resolvedPath, isESM);
|
|
36864
|
+
const userConfig = await loadConfigFromBundledFile(resolvedPath, bundled.code, isESM);
|
|
36865
|
+
if (bundled.nativeIncompatibilities.length > 0) createLogger(logLevel, { customLogger }).warn(formatNativeConfigIncompatWarning(bundled.nativeIncompatibilities, configRoot));
|
|
36041
36866
|
return {
|
|
36042
|
-
configExport:
|
|
36867
|
+
configExport: userConfig,
|
|
36043
36868
|
dependencies: bundled.dependencies
|
|
36044
36869
|
};
|
|
36045
36870
|
}
|
|
@@ -36051,6 +36876,7 @@ async function bundleConfigFile(fileName, isESM) {
|
|
|
36051
36876
|
const importMetaUrlVarName = "__vite_injected_original_import_meta_url";
|
|
36052
36877
|
const importMetaResolveVarName = "__vite_injected_original_import_meta_resolve";
|
|
36053
36878
|
const importMetaResolveRegex = /import\.meta\s*\.\s*resolve/;
|
|
36879
|
+
const nativeIncompatibilities = [];
|
|
36054
36880
|
const bundle = await rolldown({
|
|
36055
36881
|
input: fileName,
|
|
36056
36882
|
platform: "node",
|
|
@@ -36066,68 +36892,72 @@ async function bundleConfigFile(fileName, isESM) {
|
|
|
36066
36892
|
} },
|
|
36067
36893
|
treeshake: false,
|
|
36068
36894
|
tsconfig: false,
|
|
36069
|
-
plugins: [
|
|
36070
|
-
|
|
36071
|
-
|
|
36072
|
-
|
|
36073
|
-
|
|
36074
|
-
|
|
36075
|
-
|
|
36076
|
-
id
|
|
36077
|
-
|
|
36078
|
-
|
|
36079
|
-
|
|
36080
|
-
|
|
36081
|
-
|
|
36082
|
-
idFsPath
|
|
36083
|
-
|
|
36084
|
-
|
|
36085
|
-
|
|
36086
|
-
|
|
36087
|
-
|
|
36088
|
-
|
|
36089
|
-
|
|
36090
|
-
canResolveWithImport =
|
|
36091
|
-
|
|
36092
|
-
|
|
36895
|
+
plugins: [
|
|
36896
|
+
!process.env.VITE_CONFIG_NATIVE_IGNORE_WARNING && createNativeConfigCompatPlugin(nativeIncompatibilities),
|
|
36897
|
+
{
|
|
36898
|
+
name: "externalize-deps",
|
|
36899
|
+
resolveId: {
|
|
36900
|
+
filter: { id: /^[^.#].*/ },
|
|
36901
|
+
handler(id, importer, { kind }) {
|
|
36902
|
+
if (!importer || path.isAbsolute(id) || isNodeBuiltin(id)) return;
|
|
36903
|
+
if (isNodeLikeBuiltin(id) || id.startsWith("npm:")) return {
|
|
36904
|
+
id,
|
|
36905
|
+
external: true
|
|
36906
|
+
};
|
|
36907
|
+
const isImport = isESM || kind === "dynamic-import";
|
|
36908
|
+
let idFsPath;
|
|
36909
|
+
try {
|
|
36910
|
+
idFsPath = nodeResolveWithVite(id, importer, {
|
|
36911
|
+
root,
|
|
36912
|
+
isRequire: !isImport
|
|
36913
|
+
});
|
|
36914
|
+
} catch (e) {
|
|
36915
|
+
if (!isImport) {
|
|
36916
|
+
let canResolveWithImport = false;
|
|
36917
|
+
try {
|
|
36918
|
+
canResolveWithImport = !!nodeResolveWithVite(id, importer, { root });
|
|
36919
|
+
} catch {}
|
|
36920
|
+
if (canResolveWithImport) throw new Error(`Failed to resolve ${JSON.stringify(id)}. This package is ESM only but it was tried to load by \`require\`. See https://vite.dev/guide/troubleshooting.html#this-package-is-esm-only for more details.`);
|
|
36921
|
+
}
|
|
36922
|
+
throw e;
|
|
36093
36923
|
}
|
|
36094
|
-
|
|
36924
|
+
if (!idFsPath) return;
|
|
36925
|
+
if (idFsPath.endsWith(".json")) return idFsPath;
|
|
36926
|
+
if (idFsPath && isImport) idFsPath = pathToFileURL(idFsPath).href;
|
|
36927
|
+
return {
|
|
36928
|
+
id: idFsPath,
|
|
36929
|
+
external: true
|
|
36930
|
+
};
|
|
36095
36931
|
}
|
|
36096
|
-
if (!idFsPath) return;
|
|
36097
|
-
if (idFsPath.endsWith(".json")) return idFsPath;
|
|
36098
|
-
if (idFsPath && isImport) idFsPath = pathToFileURL(idFsPath).href;
|
|
36099
|
-
return {
|
|
36100
|
-
id: idFsPath,
|
|
36101
|
-
external: true
|
|
36102
|
-
};
|
|
36103
36932
|
}
|
|
36104
|
-
}
|
|
36105
|
-
|
|
36106
|
-
|
|
36107
|
-
|
|
36108
|
-
|
|
36109
|
-
|
|
36110
|
-
|
|
36111
|
-
|
|
36112
|
-
|
|
36113
|
-
|
|
36114
|
-
|
|
36115
|
-
|
|
36116
|
-
|
|
36117
|
-
|
|
36118
|
-
|
|
36119
|
-
|
|
36120
|
-
|
|
36121
|
-
|
|
36122
|
-
|
|
36123
|
-
|
|
36124
|
-
|
|
36125
|
-
|
|
36126
|
-
|
|
36127
|
-
|
|
36933
|
+
},
|
|
36934
|
+
{
|
|
36935
|
+
name: "inject-file-scope-variables",
|
|
36936
|
+
transform: {
|
|
36937
|
+
filter: { id: /\.[cm]?[jt]s$/ },
|
|
36938
|
+
handler(code, id) {
|
|
36939
|
+
let injectValues = `const ${dirnameVarName} = ${JSON.stringify(path.dirname(id))};const ${filenameVarName} = ${JSON.stringify(id)};const ${importMetaUrlVarName} = ${JSON.stringify(pathToFileURL(id).href)};`;
|
|
36940
|
+
if (importMetaResolveRegex.test(code)) if (isESM) {
|
|
36941
|
+
if (!importMetaResolverRegistered) {
|
|
36942
|
+
importMetaResolverRegistered = true;
|
|
36943
|
+
createImportMetaResolver();
|
|
36944
|
+
}
|
|
36945
|
+
injectValues += `const ${importMetaResolveVarName} = (specifier, importer = ${importMetaUrlVarName}) => (${importMetaResolveWithCustomHookString})(specifier, importer);`;
|
|
36946
|
+
} else injectValues += `const ${importMetaResolveVarName} = (specifier, importer = ${importMetaUrlVarName}) => { throw new Error('import.meta.resolve is not supported in CJS config files') };`;
|
|
36947
|
+
let injectedContents;
|
|
36948
|
+
if (code.startsWith("#!")) {
|
|
36949
|
+
let firstLineEndIndex = code.indexOf("\n");
|
|
36950
|
+
if (firstLineEndIndex < 0) firstLineEndIndex = code.length;
|
|
36951
|
+
injectedContents = code.slice(0, firstLineEndIndex + 1) + injectValues + code.slice(firstLineEndIndex + 1);
|
|
36952
|
+
} else injectedContents = injectValues + code;
|
|
36953
|
+
return {
|
|
36954
|
+
code: injectedContents,
|
|
36955
|
+
map: null
|
|
36956
|
+
};
|
|
36957
|
+
}
|
|
36128
36958
|
}
|
|
36129
36959
|
}
|
|
36130
|
-
|
|
36960
|
+
]
|
|
36131
36961
|
});
|
|
36132
36962
|
const result = await bundle.generate({
|
|
36133
36963
|
format: isESM ? "esm" : "cjs",
|
|
@@ -36144,7 +36974,8 @@ async function bundleConfigFile(fileName, isESM) {
|
|
|
36144
36974
|
collectAllModules(bundleChunks, entryChunk.fileName, allModules);
|
|
36145
36975
|
return {
|
|
36146
36976
|
code: entryChunk.code,
|
|
36147
|
-
dependencies: [...allModules].filter((m) => !m.startsWith("\0"))
|
|
36977
|
+
dependencies: [...allModules].filter((m) => !m.startsWith("\0")),
|
|
36978
|
+
nativeIncompatibilities
|
|
36148
36979
|
};
|
|
36149
36980
|
}
|
|
36150
36981
|
function collectAllModules(bundle, fileName, allModules, analyzedModules = /* @__PURE__ */ new Set()) {
|
|
@@ -36280,4 +37111,4 @@ const parseAst$1 = parseAst;
|
|
|
36280
37111
|
const parseAstAsync$1 = parseAstAsync;
|
|
36281
37112
|
const esbuildVersion = "0.25.0";
|
|
36282
37113
|
//#endregion
|
|
36283
|
-
export { mergeConfig as $, createServer$2 as A, ssrTransform as B, fetchModule as C, optimizeDeps as D, createBuilder as E, createIdResolver as F, resolveEnvPrefix as G, createServerModuleRunnerTransport as H, perEnvironmentState as I, createLogger as J, transformWithOxc as K, isFileLoadingAllowed as L, formatPostcssSourceMap as M, preprocessCSS as N, optimizer_exports as O, searchForWorkspaceRoot as P, mergeAlias as Q, isFileServingAllowed as R, DevEnvironment as S, build as T, buildErrorMessage as U, createServerModuleRunner as V, loadEnv as W, createFilter$1 as X, perEnvironmentPlugin as Y, isCSSRequest as Z, runnerImport as _, minifySync as a, DEFAULT_CLIENT_MAIN_FIELDS as at, createRunnableDevEnvironment as b, parseAstAsync$1 as c, DEFAULT_SERVER_MAIN_FIELDS as ct, isFetchableDevEnvironment as d, require_picocolors as dt, normalizePath as et, config_exports as f, __commonJSMin as ft, sortUserPlugins as g, resolveConfig as h, minify as i, DEFAULT_CLIENT_CONDITIONS as it, server_exports as j, createServerHotChannel as k, parseSync as l, VERSION as lt, loadConfigFromFile as m, __toESM as mt, esbuildVersion as n, rollupVersion as nt, parse as o, DEFAULT_EXTERNAL_CONDITIONS as ot, defineConfig as p, __require as pt, transformWithEsbuild as q, esmExternalRequirePlugin$1 as r, withFilter as rt, parseAst$1 as s, DEFAULT_SERVER_CONDITIONS as st, Visitor as t, rolldownVersion as tt, createFetchableDevEnvironment as u, defaultAllowedOrigins as ut, preview as v, BuildEnvironment as w, isRunnableDevEnvironment as x, preview_exports as y, send$1 as z };
|
|
37114
|
+
export { mergeConfig as $, createServer$2 as A, ssrTransform as B, fetchModule as C, optimizeDeps as D, createBuilder as E, createIdResolver as F, resolveEnvPrefix as G, createServerModuleRunnerTransport as H, perEnvironmentState as I, createLogger as J, transformWithOxc as K, isFileLoadingAllowed as L, formatPostcssSourceMap as M, preprocessCSS as N, optimizer_exports as O, searchForWorkspaceRoot as P, mergeAlias as Q, isFileServingAllowed as R, DevEnvironment as S, build as T, buildErrorMessage as U, createServerModuleRunner as V, loadEnv as W, createFilter$1 as X, perEnvironmentPlugin as Y, isCSSRequest as Z, runnerImport as _, minifySync as a, DEFAULT_CLIENT_MAIN_FIELDS as at, createRunnableDevEnvironment as b, parseAstAsync$1 as c, DEFAULT_SERVER_MAIN_FIELDS as ct, isFetchableDevEnvironment as d, require_picocolors as dt, normalizePath as et, config_exports as f, __commonJSMin as ft, sortUserPlugins as g, resolveConfig as h, minify as i, DEFAULT_CLIENT_CONDITIONS as it, server_exports as j, createServerHotChannel as k, parseSync$1 as l, VERSION as lt, loadConfigFromFile as m, __toESM as mt, esbuildVersion as n, rollupVersion as nt, parse as o, DEFAULT_EXTERNAL_CONDITIONS as ot, defineConfig as p, __require as pt, transformWithEsbuild as q, esmExternalRequirePlugin$1 as r, withFilter as rt, parseAst$1 as s, DEFAULT_SERVER_CONDITIONS as st, Visitor as t, rolldownVersion as tt, createFetchableDevEnvironment as u, defaultAllowedOrigins as ut, preview as v, BuildEnvironment as w, isRunnableDevEnvironment as x, preview_exports as y, send$1 as z };
|