vite 3.0.0-alpha.5 → 3.0.0-alpha.8
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/dist/node/chunks/{dep-21067347.js → dep-6b269949.js} +1 -1
- package/dist/node/chunks/{dep-0232e200.js → dep-8250f392.js} +422 -200
- package/dist/node/chunks/{dep-cd161504.js → dep-8259d5f4.js} +1 -1
- package/dist/node/chunks/{dep-13a14c32.js → dep-cfa39351.js} +1 -1
- package/dist/node/cli.js +5 -5
- package/dist/node/constants.js +1 -1
- package/dist/node/index.d.ts +40 -4
- package/dist/node/index.js +1 -1
- package/dist/node-cjs/publicUtils.cjs +1 -1
- package/dist/node-cjs/terser.cjs +1023 -2876
- package/package.json +11 -10
- package/dist/node/build.d.ts +0 -178
- package/dist/node/certificate.d.ts +0 -2
- package/dist/node/cli.d.ts +0 -1
- package/dist/node/config.d.ts +0 -246
- package/dist/node/constants.d.ts +0 -35
- package/dist/node/env.d.ts +0 -3
- package/dist/node/http.d.ts +0 -88
- package/dist/node/logger.d.ts +0 -31
- package/dist/node/optimizer/esbuildDepPlugin.d.ts +0 -4
- package/dist/node/optimizer/index.d.ts +0 -181
- package/dist/node/optimizer/optimizer.d.ts +0 -4
- package/dist/node/optimizer/scan.d.ts +0 -8
- package/dist/node/packages.d.ts +0 -27
- package/dist/node/plugin.d.ts +0 -130
- package/dist/node/plugins/asset.d.ts +0 -68
- package/dist/node/plugins/assetImportMetaUrl.d.ts +0 -13
- package/dist/node/plugins/clientInjections.d.ts +0 -7
- package/dist/node/plugins/css.d.ts +0 -86
- package/dist/node/plugins/dataUri.d.ts +0 -5
- package/dist/node/plugins/define.d.ts +0 -3
- package/dist/node/plugins/dynamicImportVars.d.ts +0 -9
- package/dist/node/plugins/ensureWatch.d.ts +0 -5
- package/dist/node/plugins/esbuild.d.ts +0 -15
- package/dist/node/plugins/html.d.ts +0 -120
- package/dist/node/plugins/importAnalysis.d.ts +0 -47
- package/dist/node/plugins/importAnalysisBuild.d.ts +0 -16
- package/dist/node/plugins/importMetaGlob.d.ts +0 -34
- package/dist/node/plugins/index.d.ts +0 -3
- package/dist/node/plugins/json.d.ts +0 -23
- package/dist/node/plugins/loadFallback.d.ts +0 -5
- package/dist/node/plugins/manifest.d.ts +0 -14
- package/dist/node/plugins/metadata.d.ts +0 -9
- package/dist/node/plugins/modulePreloadPolyfill.d.ts +0 -4
- package/dist/node/plugins/optimizedDeps.d.ts +0 -7
- package/dist/node/plugins/preAlias.d.ts +0 -6
- package/dist/node/plugins/reporter.d.ts +0 -3
- package/dist/node/plugins/resolve.d.ts +0 -41
- package/dist/node/plugins/splitVendorChunk.d.ts +0 -12
- package/dist/node/plugins/ssrRequireHook.d.ts +0 -12
- package/dist/node/plugins/terser.d.ts +0 -3
- package/dist/node/plugins/wasm.d.ts +0 -4
- package/dist/node/plugins/worker.d.ts +0 -9
- package/dist/node/plugins/workerImportMetaUrl.d.ts +0 -3
- package/dist/node/preview.d.ts +0 -33
- package/dist/node/publicUtils.d.ts +0 -11
- package/dist/node/server/hmr.d.ts +0 -39
- package/dist/node/server/index.d.ts +0 -189
- package/dist/node/server/middlewares/base.d.ts +0 -3
- package/dist/node/server/middlewares/compression.d.ts +0 -1
- package/dist/node/server/middlewares/error.d.ts +0 -8
- package/dist/node/server/middlewares/indexHtml.d.ts +0 -4
- package/dist/node/server/middlewares/proxy.d.ts +0 -20
- package/dist/node/server/middlewares/spaFallback.d.ts +0 -2
- package/dist/node/server/middlewares/static.d.ts +0 -6
- package/dist/node/server/middlewares/time.d.ts +0 -2
- package/dist/node/server/middlewares/transform.d.ts +0 -3
- package/dist/node/server/moduleGraph.d.ts +0 -55
- package/dist/node/server/openBrowser.d.ts +0 -15
- package/dist/node/server/pluginContainer.d.ts +0 -41
- package/dist/node/server/searchRoot.d.ts +0 -8
- package/dist/node/server/send.d.ts +0 -10
- package/dist/node/server/sourcemap.d.ts +0 -11
- package/dist/node/server/transformRequest.d.ts +0 -14
- package/dist/node/server/ws.d.ts +0 -55
- package/dist/node/ssr/ssrExternal.d.ts +0 -11
- package/dist/node/ssr/ssrManifestPlugin.d.ts +0 -3
- package/dist/node/ssr/ssrModuleLoader.d.ts +0 -7
- package/dist/node/ssr/ssrStacktrace.d.ts +0 -3
- package/dist/node/ssr/ssrTransform.d.ts +0 -14
- package/dist/node/utils.d.ts +0 -144
|
@@ -11567,7 +11567,7 @@ function writeFile(filename, content) {
|
|
|
11567
11567
|
fs__default.writeFileSync(filename, content);
|
|
11568
11568
|
}
|
|
11569
11569
|
/**
|
|
11570
|
-
* Use instead of fs.existsSync(filename)
|
|
11570
|
+
* Use fs.statSync(filename) instead of fs.existsSync(filename)
|
|
11571
11571
|
* #2051 if we don't have read permission on a directory, existsSync() still
|
|
11572
11572
|
* works and will result in massively slow subsequent checks (which are
|
|
11573
11573
|
* unnecessary in the first place)
|
|
@@ -11939,6 +11939,14 @@ function normalizeSingleAlias({ find, replacement, customResolver }) {
|
|
|
11939
11939
|
}
|
|
11940
11940
|
return alias;
|
|
11941
11941
|
}
|
|
11942
|
+
function transformResult(s, id, config) {
|
|
11943
|
+
const isBuild = config.command === 'build';
|
|
11944
|
+
const needSourceMap = !isBuild || config.build.sourcemap;
|
|
11945
|
+
return {
|
|
11946
|
+
code: s.toString(),
|
|
11947
|
+
map: needSourceMap ? s.generateMap({ hires: true, source: id }) : null
|
|
11948
|
+
};
|
|
11949
|
+
}
|
|
11942
11950
|
|
|
11943
11951
|
/* eslint no-console: 0 */
|
|
11944
11952
|
const LogLevels = {
|
|
@@ -14682,7 +14690,7 @@ const debug$c = createDebugger('vite:resolve-details', {
|
|
|
14682
14690
|
onlyWhenFocused: true
|
|
14683
14691
|
});
|
|
14684
14692
|
function resolvePlugin(baseOptions) {
|
|
14685
|
-
const { root, isProduction, asSrc, ssrConfig, preferRelative = false } = baseOptions;
|
|
14693
|
+
const { root, isBuild, isProduction, asSrc, ssrConfig, preferRelative = false } = baseOptions;
|
|
14686
14694
|
const { target: ssrTarget, noExternal: ssrNoExternal } = ssrConfig ?? {};
|
|
14687
14695
|
return {
|
|
14688
14696
|
name: 'vite:resolve',
|
|
@@ -14809,18 +14817,20 @@ function resolvePlugin(baseOptions) {
|
|
|
14809
14817
|
}
|
|
14810
14818
|
// bare package imports, perform node resolve
|
|
14811
14819
|
if (bareImportRE.test(id)) {
|
|
14812
|
-
|
|
14820
|
+
const external = options.shouldExternalize?.(id);
|
|
14821
|
+
if (!external &&
|
|
14822
|
+
asSrc &&
|
|
14813
14823
|
depsOptimizer &&
|
|
14814
|
-
!ssr &&
|
|
14824
|
+
(isBuild || !ssr) &&
|
|
14815
14825
|
!options.scan &&
|
|
14816
14826
|
(res = await tryOptimizedResolve(depsOptimizer, id, importer))) {
|
|
14817
14827
|
return res;
|
|
14818
14828
|
}
|
|
14819
14829
|
if (targetWeb &&
|
|
14820
|
-
(res = tryResolveBrowserMapping(id, importer, options, false))) {
|
|
14830
|
+
(res = tryResolveBrowserMapping(id, importer, options, false, external))) {
|
|
14821
14831
|
return res;
|
|
14822
14832
|
}
|
|
14823
|
-
if ((res = tryNodeResolve(id, importer, options, targetWeb, depsOptimizer, ssr))) {
|
|
14833
|
+
if ((res = tryNodeResolve(id, importer, options, targetWeb, depsOptimizer, ssr, external))) {
|
|
14824
14834
|
return res;
|
|
14825
14835
|
}
|
|
14826
14836
|
// node built-ins.
|
|
@@ -14951,7 +14961,7 @@ function tryResolveFile(file, postfix, options, tryIndex, targetWeb, tryPrefix,
|
|
|
14951
14961
|
}
|
|
14952
14962
|
}
|
|
14953
14963
|
const idToPkgMap = new Map();
|
|
14954
|
-
function tryNodeResolve(id, importer, options, targetWeb, depsOptimizer, ssr) {
|
|
14964
|
+
function tryNodeResolve(id, importer, options, targetWeb, depsOptimizer, ssr, externalize) {
|
|
14955
14965
|
const { root, dedupe, isBuild, preserveSymlinks, packageCache } = options;
|
|
14956
14966
|
// split id by last '>' for nested selected packages, for example:
|
|
14957
14967
|
// 'foo > bar > baz' => 'foo > bar' & 'baz'
|
|
@@ -15005,7 +15015,8 @@ function tryNodeResolve(id, importer, options, targetWeb, depsOptimizer, ssr) {
|
|
|
15005
15015
|
}
|
|
15006
15016
|
let resolveId = resolvePackageEntry;
|
|
15007
15017
|
let unresolvedId = pkgId;
|
|
15008
|
-
|
|
15018
|
+
const isDeepImport = unresolvedId !== nestedPath;
|
|
15019
|
+
if (isDeepImport) {
|
|
15009
15020
|
resolveId = resolveDeepImport;
|
|
15010
15021
|
unresolvedId = '.' + nestedPath.slice(pkgId.length);
|
|
15011
15022
|
}
|
|
@@ -15029,15 +15040,23 @@ function tryNodeResolve(id, importer, options, targetWeb, depsOptimizer, ssr) {
|
|
|
15029
15040
|
if (!resolved) {
|
|
15030
15041
|
return;
|
|
15031
15042
|
}
|
|
15043
|
+
const processResult = (resolved) => {
|
|
15044
|
+
if (!externalize) {
|
|
15045
|
+
return resolved;
|
|
15046
|
+
}
|
|
15047
|
+
const resolvedExt = path$p.extname(resolved.id);
|
|
15048
|
+
const resolvedId = isDeepImport && path$p.extname(id) !== resolvedExt ? id + resolvedExt : id;
|
|
15049
|
+
return { ...resolved, id: resolvedId, external: true };
|
|
15050
|
+
};
|
|
15032
15051
|
// link id to pkg for browser field mapping check
|
|
15033
15052
|
idToPkgMap.set(resolved, pkg);
|
|
15034
|
-
if (isBuild && !depsOptimizer) {
|
|
15053
|
+
if ((isBuild && !depsOptimizer) || externalize) {
|
|
15035
15054
|
// Resolve package side effects for build so that rollup can better
|
|
15036
15055
|
// perform tree-shaking
|
|
15037
|
-
return {
|
|
15056
|
+
return processResult({
|
|
15038
15057
|
id: resolved,
|
|
15039
15058
|
moduleSideEffects: pkg.hasSideEffects(resolved)
|
|
15040
|
-
};
|
|
15059
|
+
});
|
|
15041
15060
|
}
|
|
15042
15061
|
if (!resolved.includes('node_modules') || // linked
|
|
15043
15062
|
!depsOptimizer || // resolving before listening to the server
|
|
@@ -15053,7 +15072,7 @@ function tryNodeResolve(id, importer, options, targetWeb, depsOptimizer, ssr) {
|
|
|
15053
15072
|
exclude?.includes(pkgId) ||
|
|
15054
15073
|
exclude?.includes(nestedPath) ||
|
|
15055
15074
|
SPECIAL_QUERY_RE.test(resolved) ||
|
|
15056
|
-
ssr) {
|
|
15075
|
+
(!isBuild && ssr)) {
|
|
15057
15076
|
// excluded from optimization
|
|
15058
15077
|
// Inject a version query to npm deps so that the browser
|
|
15059
15078
|
// can cache it without re-validation, but only do so for known js types.
|
|
@@ -15067,7 +15086,6 @@ function tryNodeResolve(id, importer, options, targetWeb, depsOptimizer, ssr) {
|
|
|
15067
15086
|
}
|
|
15068
15087
|
}
|
|
15069
15088
|
else {
|
|
15070
|
-
// TODO: depsBuild
|
|
15071
15089
|
// this is a missing import, queue optimize-deps re-run and
|
|
15072
15090
|
// get a resolved its optimized info
|
|
15073
15091
|
const optimizedInfo = depsOptimizer.registerMissingImport(id, resolved);
|
|
@@ -15282,7 +15300,7 @@ function resolveDeepImport(id, { webResolvedImports, setResolvedCache, getResolv
|
|
|
15282
15300
|
}
|
|
15283
15301
|
}
|
|
15284
15302
|
}
|
|
15285
|
-
function tryResolveBrowserMapping(id, importer, options, isFilePath) {
|
|
15303
|
+
function tryResolveBrowserMapping(id, importer, options, isFilePath, externalize) {
|
|
15286
15304
|
let res;
|
|
15287
15305
|
const pkg = importer && idToPkgMap.get(importer);
|
|
15288
15306
|
if (pkg && isObject$2(pkg.data.browser)) {
|
|
@@ -15294,10 +15312,11 @@ function tryResolveBrowserMapping(id, importer, options, isFilePath) {
|
|
|
15294
15312
|
isDebug$4 &&
|
|
15295
15313
|
debug$c(`[browser mapped] ${colors$1.cyan(id)} -> ${colors$1.dim(res)}`);
|
|
15296
15314
|
idToPkgMap.set(res, pkg);
|
|
15297
|
-
|
|
15315
|
+
const result = {
|
|
15298
15316
|
id: res,
|
|
15299
15317
|
moduleSideEffects: pkg.hasSideEffects(res)
|
|
15300
15318
|
};
|
|
15319
|
+
return externalize ? { ...result, external: true } : result;
|
|
15301
15320
|
}
|
|
15302
15321
|
}
|
|
15303
15322
|
else if (browserMappedPath === false) {
|
|
@@ -15464,9 +15483,8 @@ function esbuildDepPlugin(qualified, exportsData, config) {
|
|
|
15464
15483
|
relativePath = `./${relativePath}`;
|
|
15465
15484
|
}
|
|
15466
15485
|
let contents = '';
|
|
15467
|
-
const
|
|
15468
|
-
|
|
15469
|
-
if (!imports.length && !exports.length) {
|
|
15486
|
+
const { hasImports, exports, hasReExports } = exportsData[id];
|
|
15487
|
+
if (!hasImports && !exports.length) {
|
|
15470
15488
|
// cjs
|
|
15471
15489
|
contents += `export default require("${relativePath}");`;
|
|
15472
15490
|
}
|
|
@@ -15474,9 +15492,7 @@ function esbuildDepPlugin(qualified, exportsData, config) {
|
|
|
15474
15492
|
if (exports.includes('default')) {
|
|
15475
15493
|
contents += `import d from "${relativePath}";export default d;`;
|
|
15476
15494
|
}
|
|
15477
|
-
if (
|
|
15478
|
-
exports.length > 1 ||
|
|
15479
|
-
exports[0] !== 'default') {
|
|
15495
|
+
if (hasReExports || exports.length > 1 || exports[0] !== 'default') {
|
|
15480
15496
|
contents += `\nexport * from "${relativePath}"`;
|
|
15481
15497
|
}
|
|
15482
15498
|
}
|
|
@@ -26231,10 +26247,7 @@ function importGlobPlugin(config) {
|
|
|
26231
26247
|
server.watcher.add(dirname(file));
|
|
26232
26248
|
});
|
|
26233
26249
|
}
|
|
26234
|
-
return
|
|
26235
|
-
code: result.s.toString(),
|
|
26236
|
-
map: config.build.sourcemap ? result.s.generateMap() : null
|
|
26237
|
-
};
|
|
26250
|
+
return transformResult(result.s, id, config);
|
|
26238
26251
|
}
|
|
26239
26252
|
}
|
|
26240
26253
|
};
|
|
@@ -26773,9 +26786,18 @@ function esbuildScanPlugin(config, container, depImports, missing, entries) {
|
|
|
26773
26786
|
(loader.startsWith('ts') ? extractImportPaths(content) : '');
|
|
26774
26787
|
const key = `${path}?id=${scriptId++}`;
|
|
26775
26788
|
if (contents.includes('import.meta.glob')) {
|
|
26789
|
+
let transpiledContents;
|
|
26790
|
+
// transpile because `transformGlobImport` only expects js
|
|
26791
|
+
if (loader !== 'js') {
|
|
26792
|
+
transpiledContents = (await transform$2(contents, { loader }))
|
|
26793
|
+
.code;
|
|
26794
|
+
}
|
|
26795
|
+
else {
|
|
26796
|
+
transpiledContents = contents;
|
|
26797
|
+
}
|
|
26776
26798
|
scripts[key] = {
|
|
26777
26799
|
loader: 'js',
|
|
26778
|
-
contents: (await transformGlobImport(
|
|
26800
|
+
contents: (await transformGlobImport(transpiledContents, path, config.root, resolve))?.s.toString() || transpiledContents
|
|
26779
26801
|
};
|
|
26780
26802
|
}
|
|
26781
26803
|
else {
|
|
@@ -26962,6 +26984,7 @@ function getDepsOptimizer(config) {
|
|
|
26962
26984
|
async function initDepsOptimizer(config, server) {
|
|
26963
26985
|
const { logger } = config;
|
|
26964
26986
|
const isBuild = config.command === 'build';
|
|
26987
|
+
const scan = config.command !== 'build' && config.optimizeDeps.devScan;
|
|
26965
26988
|
const sessionTimestamp = Date.now().toString();
|
|
26966
26989
|
const cachedMetadata = loadCachedDepOptimizationMetadata(config);
|
|
26967
26990
|
let handle;
|
|
@@ -27000,7 +27023,7 @@ async function initDepsOptimizer(config, server) {
|
|
|
27000
27023
|
// If there wasn't a cache or it is outdated, we need to prepare a first run
|
|
27001
27024
|
let firstRunCalled = !!cachedMetadata;
|
|
27002
27025
|
if (!cachedMetadata) {
|
|
27003
|
-
if (
|
|
27026
|
+
if (!scan) {
|
|
27004
27027
|
// Initialize discovered deps with manually added optimizeDeps.include info
|
|
27005
27028
|
const discovered = await initialProjectDependencies(config, sessionTimestamp);
|
|
27006
27029
|
const { metadata } = depsOptimizer;
|
|
@@ -27267,9 +27290,13 @@ async function initDepsOptimizer(config, server) {
|
|
|
27267
27290
|
processing: depOptimizationProcessing.promise,
|
|
27268
27291
|
exportsData: extractExportsData(resolved, config)
|
|
27269
27292
|
});
|
|
27270
|
-
//
|
|
27271
|
-
// the
|
|
27272
|
-
|
|
27293
|
+
// Until the first optimize run is called, avoid triggering processing
|
|
27294
|
+
// We'll wait until the user codebase is eagerly processed by Vite so
|
|
27295
|
+
// we can get a list of every missing dependency before giving to the
|
|
27296
|
+
// browser a dependency that may be outdated, thus avoiding full page reloads
|
|
27297
|
+
if (scan || firstRunCalled) {
|
|
27298
|
+
// Debounced rerun, let other missing dependencies be discovered before
|
|
27299
|
+
// the running next optimizeDeps
|
|
27273
27300
|
debouncedProcessing();
|
|
27274
27301
|
}
|
|
27275
27302
|
// Return the path for the optimized bundle, this path is known before
|
|
@@ -27506,7 +27533,7 @@ async function runOptimizeDeps(resolvedConfig, depsInfo) {
|
|
|
27506
27533
|
splitting: true,
|
|
27507
27534
|
sourcemap: true,
|
|
27508
27535
|
outdir: processingCacheDir,
|
|
27509
|
-
ignoreAnnotations:
|
|
27536
|
+
ignoreAnnotations: resolvedConfig.command !== 'build',
|
|
27510
27537
|
metafile: true,
|
|
27511
27538
|
define,
|
|
27512
27539
|
plugins: [
|
|
@@ -27592,12 +27619,22 @@ function depsFromOptimizedDepInfo(depsInfo) {
|
|
|
27592
27619
|
function getOptimizedDepPath(id, config) {
|
|
27593
27620
|
return normalizePath$3(path$p.resolve(getDepsCacheDir(config), flattenId(id) + '.js'));
|
|
27594
27621
|
}
|
|
27622
|
+
function getDepsCacheSuffix(config) {
|
|
27623
|
+
let suffix = '';
|
|
27624
|
+
if (config.command === 'build') {
|
|
27625
|
+
suffix += '_build';
|
|
27626
|
+
if (config.build.ssr) {
|
|
27627
|
+
suffix += '_ssr';
|
|
27628
|
+
}
|
|
27629
|
+
}
|
|
27630
|
+
return suffix;
|
|
27631
|
+
}
|
|
27595
27632
|
function getDepsCacheDir(config) {
|
|
27596
|
-
const dirName =
|
|
27633
|
+
const dirName = 'deps' + getDepsCacheSuffix(config);
|
|
27597
27634
|
return normalizePath$3(path$p.resolve(config.cacheDir, dirName));
|
|
27598
27635
|
}
|
|
27599
27636
|
function getProcessingDepsCacheDir(config) {
|
|
27600
|
-
const dirName =
|
|
27637
|
+
const dirName = 'deps' + getDepsCacheSuffix(config) + '_temp';
|
|
27601
27638
|
return normalizePath$3(path$p.resolve(config.cacheDir, dirName));
|
|
27602
27639
|
}
|
|
27603
27640
|
function isOptimizedDepFile(id, config) {
|
|
@@ -27694,7 +27731,6 @@ function esbuildOutputFromId(outputs, id, cacheDirOutputPath) {
|
|
|
27694
27731
|
}
|
|
27695
27732
|
async function extractExportsData(filePath, config) {
|
|
27696
27733
|
await init;
|
|
27697
|
-
let exportsData;
|
|
27698
27734
|
const esbuildOptions = config.optimizeDeps?.esbuildOptions ?? {};
|
|
27699
27735
|
if (config.optimizeDeps.extensions?.some((ext) => filePath.endsWith(ext))) {
|
|
27700
27736
|
// For custom supported extensions, build the entry file to transform it into JS,
|
|
@@ -27706,35 +27742,45 @@ async function extractExportsData(filePath, config) {
|
|
|
27706
27742
|
write: false,
|
|
27707
27743
|
format: 'esm'
|
|
27708
27744
|
});
|
|
27709
|
-
|
|
27745
|
+
const [imports, exports, facade] = parse$h(result.outputFiles[0].text);
|
|
27746
|
+
return {
|
|
27747
|
+
hasImports: imports.length > 0,
|
|
27748
|
+
exports,
|
|
27749
|
+
facade
|
|
27750
|
+
};
|
|
27751
|
+
}
|
|
27752
|
+
let parseResult;
|
|
27753
|
+
let usedJsxLoader = false;
|
|
27754
|
+
const entryContent = fs__default.readFileSync(filePath, 'utf-8');
|
|
27755
|
+
try {
|
|
27756
|
+
parseResult = parse$h(entryContent);
|
|
27757
|
+
}
|
|
27758
|
+
catch {
|
|
27759
|
+
const loader = esbuildOptions.loader?.[path$p.extname(filePath)] || 'jsx';
|
|
27760
|
+
debug$a(`Unable to parse: ${filePath}.\n Trying again with a ${loader} transform.`);
|
|
27761
|
+
const transformed = await transformWithEsbuild(entryContent, filePath, {
|
|
27762
|
+
loader
|
|
27763
|
+
});
|
|
27764
|
+
// Ensure that optimization won't fail by defaulting '.js' to the JSX parser.
|
|
27765
|
+
// This is useful for packages such as Gatsby.
|
|
27766
|
+
esbuildOptions.loader = {
|
|
27767
|
+
'.js': 'jsx',
|
|
27768
|
+
...esbuildOptions.loader
|
|
27769
|
+
};
|
|
27770
|
+
parseResult = parse$h(transformed.code);
|
|
27771
|
+
usedJsxLoader = true;
|
|
27710
27772
|
}
|
|
27711
|
-
|
|
27712
|
-
|
|
27713
|
-
|
|
27714
|
-
|
|
27715
|
-
|
|
27716
|
-
|
|
27717
|
-
const loader = esbuildOptions.loader?.[path$p.extname(filePath)] || 'jsx';
|
|
27718
|
-
debug$a(`Unable to parse: ${filePath}.\n Trying again with a ${loader} transform.`);
|
|
27719
|
-
const transformed = await transformWithEsbuild(entryContent, filePath, {
|
|
27720
|
-
loader
|
|
27721
|
-
});
|
|
27722
|
-
// Ensure that optimization won't fail by defaulting '.js' to the JSX parser.
|
|
27723
|
-
// This is useful for packages such as Gatsby.
|
|
27724
|
-
esbuildOptions.loader = {
|
|
27725
|
-
'.js': 'jsx',
|
|
27726
|
-
...esbuildOptions.loader
|
|
27727
|
-
};
|
|
27728
|
-
exportsData = parse$h(transformed.code);
|
|
27729
|
-
exportsData.jsxLoader = true;
|
|
27730
|
-
}
|
|
27731
|
-
for (const { ss, se } of exportsData[0]) {
|
|
27773
|
+
const [imports, exports, facade] = parseResult;
|
|
27774
|
+
const exportsData = {
|
|
27775
|
+
hasImports: imports.length > 0,
|
|
27776
|
+
exports,
|
|
27777
|
+
facade,
|
|
27778
|
+
hasReExports: imports.some(({ ss, se }) => {
|
|
27732
27779
|
const exp = entryContent.slice(ss, se);
|
|
27733
|
-
|
|
27734
|
-
|
|
27735
|
-
|
|
27736
|
-
|
|
27737
|
-
}
|
|
27780
|
+
return /export\s+\*\s+from/.test(exp);
|
|
27781
|
+
}),
|
|
27782
|
+
jsxLoader: usedJsxLoader
|
|
27783
|
+
};
|
|
27738
27784
|
return exportsData;
|
|
27739
27785
|
}
|
|
27740
27786
|
// https://github.com/vitejs/vite/issues/1724#issuecomment-767619642
|
|
@@ -27746,9 +27792,9 @@ function needsInterop(config, id, exportsData, output) {
|
|
|
27746
27792
|
KNOWN_INTEROP_IDS.has(id)) {
|
|
27747
27793
|
return true;
|
|
27748
27794
|
}
|
|
27749
|
-
const
|
|
27795
|
+
const { hasImports, exports } = exportsData;
|
|
27750
27796
|
// entry has no ESM syntax - likely CJS or UMD
|
|
27751
|
-
if (!exports.length && !
|
|
27797
|
+
if (!exports.length && !hasImports) {
|
|
27752
27798
|
return true;
|
|
27753
27799
|
}
|
|
27754
27800
|
if (output) {
|
|
@@ -35858,7 +35904,7 @@ const assetAttrsConfig = {
|
|
|
35858
35904
|
const isAsyncScriptMap = new WeakMap();
|
|
35859
35905
|
async function traverseHtml(html, filePath, visitor) {
|
|
35860
35906
|
// lazy load compiler
|
|
35861
|
-
const { parse, transform } = await import('./dep-
|
|
35907
|
+
const { parse, transform } = await import('./dep-cfa39351.js').then(function (n) { return n.c; });
|
|
35862
35908
|
// @vue/compiler-core doesn't like lowercase doctypes
|
|
35863
35909
|
html = html.replace(/<!doctype\s/i, '<!DOCTYPE ');
|
|
35864
35910
|
try {
|
|
@@ -36963,7 +37009,7 @@ async function compileCSS(id, code, config, urlReplacer, atImportResolvers, serv
|
|
|
36963
37009
|
logger: config.logger
|
|
36964
37010
|
}));
|
|
36965
37011
|
if (isModule) {
|
|
36966
|
-
postcssPlugins.unshift((await import('./dep-
|
|
37012
|
+
postcssPlugins.unshift((await import('./dep-6b269949.js').then(function (n) { return n.i; })).default({
|
|
36967
37013
|
...modulesOptions,
|
|
36968
37014
|
getJSON(cssFileName, _modules, outputFileName) {
|
|
36969
37015
|
modules = _modules;
|
|
@@ -37935,7 +37981,7 @@ function lexAcceptedHmrDeps(code, start, urls) {
|
|
|
37935
37981
|
return false;
|
|
37936
37982
|
}
|
|
37937
37983
|
function error$1(pos) {
|
|
37938
|
-
const err = new Error(`import.meta.accept() can only accept string literals or an ` +
|
|
37984
|
+
const err = new Error(`import.meta.hot.accept() can only accept string literals or an ` +
|
|
37939
37985
|
`Array of string literals.`);
|
|
37940
37986
|
err.pos = pos;
|
|
37941
37987
|
throw err;
|
|
@@ -37982,7 +38028,7 @@ function stripNesting(packages) {
|
|
|
37982
38028
|
* Heuristics for determining whether a dependency should be externalized for
|
|
37983
38029
|
* server-side rendering.
|
|
37984
38030
|
*/
|
|
37985
|
-
function
|
|
38031
|
+
function cjsSsrResolveExternals(config, knownImports) {
|
|
37986
38032
|
// strip nesting since knownImports may be passed in from optimizeDeps which
|
|
37987
38033
|
// supports a "parent > child" syntax
|
|
37988
38034
|
knownImports = stripNesting(knownImports);
|
|
@@ -37996,7 +38042,7 @@ function resolveSSRExternal(config, knownImports) {
|
|
|
37996
38042
|
ssrExternals.add(id);
|
|
37997
38043
|
seen.add(id);
|
|
37998
38044
|
});
|
|
37999
|
-
|
|
38045
|
+
cjsSsrCollectExternals(config.root, config.resolve.preserveSymlinks, ssrExternals, seen, config.logger);
|
|
38000
38046
|
const importedDeps = knownImports.map(getNpmPackageName).filter(isDefined);
|
|
38001
38047
|
for (const dep of importedDeps) {
|
|
38002
38048
|
// Assume external if not yet seen
|
|
@@ -38018,8 +38064,71 @@ function resolveSSRExternal(config, knownImports) {
|
|
|
38018
38064
|
const CJS_CONTENT_RE = /\bmodule\.exports\b|\bexports[.\[]|\brequire\s*\(|\bObject\.(defineProperty|defineProperties|assign)\s*\(\s*exports\b/;
|
|
38019
38065
|
// TODO: use import()
|
|
38020
38066
|
const _require$2 = createRequire$1(import.meta.url);
|
|
38021
|
-
|
|
38022
|
-
function
|
|
38067
|
+
const isSsrExternalCache = new WeakMap();
|
|
38068
|
+
function shouldExternalizeForSSR(id, config) {
|
|
38069
|
+
let isSsrExternal = isSsrExternalCache.get(config);
|
|
38070
|
+
if (!isSsrExternal) {
|
|
38071
|
+
isSsrExternal = createIsSsrExternal(config);
|
|
38072
|
+
isSsrExternalCache.set(config, isSsrExternal);
|
|
38073
|
+
}
|
|
38074
|
+
return isSsrExternal(id);
|
|
38075
|
+
}
|
|
38076
|
+
function createIsSsrExternal(config) {
|
|
38077
|
+
const processedIds = new Map();
|
|
38078
|
+
const { ssr, root } = config;
|
|
38079
|
+
const noExternal = ssr?.noExternal;
|
|
38080
|
+
const noExternalFilter = noExternal !== 'undefined' &&
|
|
38081
|
+
typeof noExternal !== 'boolean' &&
|
|
38082
|
+
createFilter$1(undefined, noExternal, { resolve: false });
|
|
38083
|
+
const isConfiguredAsExternal = (id) => {
|
|
38084
|
+
const { ssr } = config;
|
|
38085
|
+
if (!ssr || ssr.external?.includes(id)) {
|
|
38086
|
+
return true;
|
|
38087
|
+
}
|
|
38088
|
+
if (typeof noExternal === 'boolean') {
|
|
38089
|
+
return !noExternal;
|
|
38090
|
+
}
|
|
38091
|
+
if (noExternalFilter) {
|
|
38092
|
+
return noExternalFilter(id);
|
|
38093
|
+
}
|
|
38094
|
+
return true;
|
|
38095
|
+
};
|
|
38096
|
+
const resolveOptions = {
|
|
38097
|
+
root,
|
|
38098
|
+
preserveSymlinks: config.resolve.preserveSymlinks,
|
|
38099
|
+
isProduction: false,
|
|
38100
|
+
isBuild: true
|
|
38101
|
+
};
|
|
38102
|
+
const isPackageEntry = (id) => {
|
|
38103
|
+
if (!bareImportRE.test(id) || id.includes('\0')) {
|
|
38104
|
+
return false;
|
|
38105
|
+
}
|
|
38106
|
+
if (tryNodeResolve(id, undefined, resolveOptions, ssr?.target === 'webworker', undefined, true)) {
|
|
38107
|
+
return true;
|
|
38108
|
+
}
|
|
38109
|
+
try {
|
|
38110
|
+
// no main entry, but deep imports may be allowed
|
|
38111
|
+
if (resolveFrom(`${id}/package.json`, root)) {
|
|
38112
|
+
return true;
|
|
38113
|
+
}
|
|
38114
|
+
}
|
|
38115
|
+
catch { }
|
|
38116
|
+
return false;
|
|
38117
|
+
};
|
|
38118
|
+
return (id) => {
|
|
38119
|
+
if (processedIds.has(id)) {
|
|
38120
|
+
return processedIds.get(id);
|
|
38121
|
+
}
|
|
38122
|
+
const external = !id.startsWith('.') &&
|
|
38123
|
+
!path$p.isAbsolute(id) &&
|
|
38124
|
+
(isBuiltin(id) || (isConfiguredAsExternal(id) && isPackageEntry(id)));
|
|
38125
|
+
processedIds.set(id, external);
|
|
38126
|
+
return external;
|
|
38127
|
+
};
|
|
38128
|
+
}
|
|
38129
|
+
// When ssr.format is 'cjs', this function is used reverting to the Vite 2.9
|
|
38130
|
+
// SSR externalization heuristics
|
|
38131
|
+
function cjsSsrCollectExternals(root, preserveSymlinks, ssrExternals, seen, logger) {
|
|
38023
38132
|
const rootPkgContent = lookupFile(root, ['package.json']);
|
|
38024
38133
|
if (!rootPkgContent) {
|
|
38025
38134
|
return;
|
|
@@ -38103,10 +38212,13 @@ function collectExternals(root, preserveSymlinks, ssrExternals, seen, logger) {
|
|
|
38103
38212
|
}
|
|
38104
38213
|
}
|
|
38105
38214
|
for (const depRoot of depsToTrace) {
|
|
38106
|
-
|
|
38215
|
+
cjsSsrCollectExternals(depRoot, preserveSymlinks, ssrExternals, seen, logger);
|
|
38107
38216
|
}
|
|
38108
38217
|
}
|
|
38109
|
-
function
|
|
38218
|
+
function cjsShouldExternalizeForSSR(id, externals) {
|
|
38219
|
+
if (!externals) {
|
|
38220
|
+
return false;
|
|
38221
|
+
}
|
|
38110
38222
|
const should = externals.some((e) => {
|
|
38111
38223
|
if (id === e) {
|
|
38112
38224
|
return true;
|
|
@@ -39643,6 +39755,19 @@ function runOptimizerWhenIdle(config) {
|
|
|
39643
39755
|
function optimizedDepsPlugin(config) {
|
|
39644
39756
|
return {
|
|
39645
39757
|
name: 'vite:optimized-deps',
|
|
39758
|
+
buildStart() {
|
|
39759
|
+
if (!config.isWorker) {
|
|
39760
|
+
initRunProcessingInfo(config);
|
|
39761
|
+
}
|
|
39762
|
+
},
|
|
39763
|
+
async resolveId(id) {
|
|
39764
|
+
if (getDepsOptimizer(config)?.isOptimizedDepFile(id)) {
|
|
39765
|
+
return id;
|
|
39766
|
+
}
|
|
39767
|
+
},
|
|
39768
|
+
// this.load({ id }) isn't implemented in PluginContainer
|
|
39769
|
+
// The logic to register an id to wait until it is processed
|
|
39770
|
+
// is in importAnalysis, see call to delayDepsOptimizerUntil
|
|
39646
39771
|
async load(id) {
|
|
39647
39772
|
const depsOptimizer = getDepsOptimizer(config);
|
|
39648
39773
|
if (depsOptimizer?.isOptimizedDepFile(id)) {
|
|
@@ -40005,8 +40130,12 @@ function importAnalysisPlugin(config) {
|
|
|
40005
40130
|
}
|
|
40006
40131
|
// skip ssr external
|
|
40007
40132
|
if (ssr) {
|
|
40008
|
-
if (
|
|
40009
|
-
|
|
40133
|
+
if (config.ssr?.format === 'cjs') {
|
|
40134
|
+
if (cjsShouldExternalizeForSSR(specifier, server._ssrExternals)) {
|
|
40135
|
+
continue;
|
|
40136
|
+
}
|
|
40137
|
+
}
|
|
40138
|
+
else if (shouldExternalizeForSSR(specifier, config)) {
|
|
40010
40139
|
continue;
|
|
40011
40140
|
}
|
|
40012
40141
|
if (isBuiltin(specifier)) {
|
|
@@ -40082,7 +40211,7 @@ function importAnalysisPlugin(config) {
|
|
|
40082
40211
|
importedUrls.add(urlWithoutBase);
|
|
40083
40212
|
if (!isDynamicImport) {
|
|
40084
40213
|
// for pre-transforming
|
|
40085
|
-
staticImportedUrls.add(urlWithoutBase);
|
|
40214
|
+
staticImportedUrls.add({ url: urlWithoutBase, id: resolvedId });
|
|
40086
40215
|
}
|
|
40087
40216
|
}
|
|
40088
40217
|
else if (!importer.startsWith(clientDir) && !ssr) {
|
|
@@ -40171,10 +40300,11 @@ function importAnalysisPlugin(config) {
|
|
|
40171
40300
|
isDebug$1 &&
|
|
40172
40301
|
debug$7(`${timeFrom(start)} ${colors$1.dim(`[${importedUrls.size} imports rewritten] ${prettyImporter}`)}`);
|
|
40173
40302
|
// pre-transform known direct imports
|
|
40303
|
+
// TODO: we should also crawl dynamic imports
|
|
40174
40304
|
if (config.server.preTransformRequests && staticImportedUrls.size) {
|
|
40175
|
-
staticImportedUrls.forEach((url) => {
|
|
40305
|
+
staticImportedUrls.forEach(({ url, id }) => {
|
|
40176
40306
|
url = unwrapId(removeImportQuery(url)).replace(NULL_BYTE_PLACEHOLDER, '\0');
|
|
40177
|
-
transformRequest(url, server, { ssr }).catch((e) => {
|
|
40307
|
+
const request = transformRequest(url, server, { ssr }).catch((e) => {
|
|
40178
40308
|
if (e?.code === ERR_OUTDATED_OPTIMIZED_DEP) {
|
|
40179
40309
|
// This are expected errors
|
|
40180
40310
|
return;
|
|
@@ -40182,13 +40312,13 @@ function importAnalysisPlugin(config) {
|
|
|
40182
40312
|
// Unexpected error, log the issue but avoid an unhandled exception
|
|
40183
40313
|
config.logger.error(e.message);
|
|
40184
40314
|
});
|
|
40315
|
+
if (!config.optimizeDeps.devScan) {
|
|
40316
|
+
delayDepsOptimizerUntil(config, id, () => request);
|
|
40317
|
+
}
|
|
40185
40318
|
});
|
|
40186
40319
|
}
|
|
40187
40320
|
if (s) {
|
|
40188
|
-
return
|
|
40189
|
-
code: s.toString(),
|
|
40190
|
-
map: config.build.sourcemap ? s.generateMap({ hires: true }) : null
|
|
40191
|
-
};
|
|
40321
|
+
return transformResult(s, importer, config);
|
|
40192
40322
|
}
|
|
40193
40323
|
else {
|
|
40194
40324
|
return source;
|
|
@@ -40702,7 +40832,7 @@ function ssrManifestPlugin(config) {
|
|
|
40702
40832
|
const chunk = bundle[filename];
|
|
40703
40833
|
if (chunk) {
|
|
40704
40834
|
chunk.viteMetadata.importedCss.forEach((file) => {
|
|
40705
|
-
deps.push(
|
|
40835
|
+
deps.push(join$1(config.base, file));
|
|
40706
40836
|
});
|
|
40707
40837
|
chunk.imports.forEach(addDeps);
|
|
40708
40838
|
}
|
|
@@ -40781,10 +40911,7 @@ function assetImportMetaUrlPlugin(config) {
|
|
|
40781
40911
|
s.overwrite(index, index + exp.length, `new URL(${JSON.stringify(builtUrl)}, self.location)`, { contentOnly: true });
|
|
40782
40912
|
}
|
|
40783
40913
|
if (s) {
|
|
40784
|
-
return
|
|
40785
|
-
code: s.toString(),
|
|
40786
|
-
map: config.build.sourcemap ? s.generateMap({ hires: true }) : null
|
|
40787
|
-
};
|
|
40914
|
+
return transformResult(s, id, config);
|
|
40788
40915
|
}
|
|
40789
40916
|
}
|
|
40790
40917
|
return null;
|
|
@@ -40911,7 +41038,7 @@ function resolveBuildPlugins(config) {
|
|
|
40911
41038
|
pre: [
|
|
40912
41039
|
...(options.watch ? [ensureWatchPlugin()] : []),
|
|
40913
41040
|
watchPackageDataPlugin(config),
|
|
40914
|
-
...(!isDepsOptimizerEnabled(config)
|
|
41041
|
+
...(!isDepsOptimizerEnabled(config)
|
|
40915
41042
|
? [commonjs(options.commonjsOptions)]
|
|
40916
41043
|
: []),
|
|
40917
41044
|
dataURIPlugin(),
|
|
@@ -40975,25 +41102,15 @@ async function doBuild(inlineConfig = {}) {
|
|
|
40975
41102
|
const outDir = resolve(options.outDir);
|
|
40976
41103
|
// inject ssr arg to plugin load/transform hooks
|
|
40977
41104
|
const plugins = (ssr ? config.plugins.map((p) => injectSsrFlagToHooks(p)) : config.plugins);
|
|
40978
|
-
// inject ssrExternal if present
|
|
40979
41105
|
const userExternal = options.rollupOptions?.external;
|
|
40980
41106
|
let external = userExternal;
|
|
40981
|
-
|
|
40982
|
-
|
|
40983
|
-
|
|
40984
|
-
|
|
40985
|
-
|
|
40986
|
-
const data = JSON.parse(fs__default.readFileSync(dataPath, 'utf-8'));
|
|
40987
|
-
knownImports = Object.keys(data.optimized);
|
|
40988
|
-
}
|
|
40989
|
-
catch (e) { }
|
|
40990
|
-
if (!knownImports) {
|
|
40991
|
-
// no dev deps optimization data, do a fresh scan
|
|
40992
|
-
knownImports = await findKnownImports(config);
|
|
40993
|
-
}
|
|
40994
|
-
external = resolveExternal(resolveSSRExternal(config, knownImports), userExternal);
|
|
41107
|
+
// In CJS, we can pass the externals to rollup as is. In ESM, we need to
|
|
41108
|
+
// do it in the resolve plugin so we can add the resolved extension for
|
|
41109
|
+
// deep node_modules imports
|
|
41110
|
+
if (ssr && config.ssr?.format === 'cjs') {
|
|
41111
|
+
external = await cjsSsrResolveExternal(config, userExternal);
|
|
40995
41112
|
}
|
|
40996
|
-
if (isDepsOptimizerEnabled(config)
|
|
41113
|
+
if (isDepsOptimizerEnabled(config)) {
|
|
40997
41114
|
await initDepsOptimizer(config);
|
|
40998
41115
|
}
|
|
40999
41116
|
const rollupOptions = {
|
|
@@ -41023,20 +41140,26 @@ async function doBuild(inlineConfig = {}) {
|
|
|
41023
41140
|
};
|
|
41024
41141
|
try {
|
|
41025
41142
|
const buildOutputOptions = (output = {}) => {
|
|
41143
|
+
const cjsSsrBuild = ssr && config.ssr?.format === 'cjs';
|
|
41144
|
+
const format = output.format || (cjsSsrBuild ? 'cjs' : 'es');
|
|
41145
|
+
const jsExt = (ssr && config.ssr?.target !== 'webworker') || libOptions
|
|
41146
|
+
? resolveOutputJsExtension(format, getPkgJson(config.root)?.type)
|
|
41147
|
+
: 'js';
|
|
41026
41148
|
return {
|
|
41027
41149
|
dir: outDir,
|
|
41028
|
-
format
|
|
41029
|
-
|
|
41150
|
+
// Default format is 'es' for regular and for SSR builds
|
|
41151
|
+
format,
|
|
41152
|
+
exports: cjsSsrBuild ? 'named' : 'auto',
|
|
41030
41153
|
sourcemap: options.sourcemap,
|
|
41031
41154
|
name: libOptions ? libOptions.name : undefined,
|
|
41032
41155
|
generatedCode: 'es2015',
|
|
41033
41156
|
entryFileNames: ssr
|
|
41034
|
-
? `[name]
|
|
41157
|
+
? `[name].${jsExt}`
|
|
41035
41158
|
: libOptions
|
|
41036
|
-
? resolveLibFilename(libOptions,
|
|
41159
|
+
? resolveLibFilename(libOptions, format, config.root, jsExt)
|
|
41037
41160
|
: path$p.posix.join(options.assetsDir, `[name].[hash].js`),
|
|
41038
41161
|
chunkFileNames: libOptions
|
|
41039
|
-
? `[name].[hash]
|
|
41162
|
+
? `[name].[hash].${jsExt}`
|
|
41040
41163
|
: path$p.posix.join(options.assetsDir, `[name].[hash].js`),
|
|
41041
41164
|
assetFileNames: libOptions
|
|
41042
41165
|
? `[name].[ext]`
|
|
@@ -41148,7 +41271,15 @@ function getPkgJson(root) {
|
|
|
41148
41271
|
function getPkgName(name) {
|
|
41149
41272
|
return name?.startsWith('@') ? name.split('/')[1] : name;
|
|
41150
41273
|
}
|
|
41151
|
-
function
|
|
41274
|
+
function resolveOutputJsExtension(format, type = 'commonjs') {
|
|
41275
|
+
if (type === 'module') {
|
|
41276
|
+
return format === 'cjs' || format === 'umd' ? 'cjs' : 'js';
|
|
41277
|
+
}
|
|
41278
|
+
else {
|
|
41279
|
+
return format === 'es' ? 'mjs' : 'js';
|
|
41280
|
+
}
|
|
41281
|
+
}
|
|
41282
|
+
function resolveLibFilename(libOptions, format, root, extension) {
|
|
41152
41283
|
if (typeof libOptions.fileName === 'function') {
|
|
41153
41284
|
return libOptions.fileName(format);
|
|
41154
41285
|
}
|
|
@@ -41156,13 +41287,7 @@ function resolveLibFilename(libOptions, format, root) {
|
|
|
41156
41287
|
const name = libOptions.fileName || getPkgName(packageJson.name);
|
|
41157
41288
|
if (!name)
|
|
41158
41289
|
throw new Error('Name in package.json is required if option "build.lib.fileName" is not provided.');
|
|
41159
|
-
|
|
41160
|
-
if (packageJson?.type === 'module') {
|
|
41161
|
-
extension = format === 'cjs' || format === 'umd' ? 'cjs' : 'js';
|
|
41162
|
-
}
|
|
41163
|
-
else {
|
|
41164
|
-
extension = format === 'es' ? 'mjs' : 'js';
|
|
41165
|
-
}
|
|
41290
|
+
extension ?? (extension = resolveOutputJsExtension(format, packageJson.type));
|
|
41166
41291
|
if (format === 'cjs' || format === 'es') {
|
|
41167
41292
|
return `${name}.${extension}`;
|
|
41168
41293
|
}
|
|
@@ -41224,24 +41349,41 @@ function onRollupWarning(warning, warn, config) {
|
|
|
41224
41349
|
}
|
|
41225
41350
|
}
|
|
41226
41351
|
}
|
|
41227
|
-
function
|
|
41352
|
+
async function cjsSsrResolveExternal(config, user) {
|
|
41353
|
+
// see if we have cached deps data available
|
|
41354
|
+
let knownImports;
|
|
41355
|
+
const dataPath = path$p.join(getDepsCacheDir(config), '_metadata.json');
|
|
41356
|
+
try {
|
|
41357
|
+
const data = JSON.parse(fs__default.readFileSync(dataPath, 'utf-8'));
|
|
41358
|
+
knownImports = Object.keys(data.optimized);
|
|
41359
|
+
}
|
|
41360
|
+
catch (e) { }
|
|
41361
|
+
if (!knownImports) {
|
|
41362
|
+
// no dev deps optimization data, do a fresh scan
|
|
41363
|
+
knownImports = await findKnownImports(config);
|
|
41364
|
+
}
|
|
41365
|
+
const ssrExternals = cjsSsrResolveExternals(config, knownImports);
|
|
41228
41366
|
return (id, parentId, isResolved) => {
|
|
41229
|
-
|
|
41367
|
+
const isExternal = cjsShouldExternalizeForSSR(id, ssrExternals);
|
|
41368
|
+
if (isExternal) {
|
|
41230
41369
|
return true;
|
|
41231
41370
|
}
|
|
41232
41371
|
if (user) {
|
|
41233
|
-
|
|
41234
|
-
return user(id, parentId, isResolved);
|
|
41235
|
-
}
|
|
41236
|
-
else if (Array.isArray(user)) {
|
|
41237
|
-
return user.some((test) => isExternal(id, test));
|
|
41238
|
-
}
|
|
41239
|
-
else {
|
|
41240
|
-
return isExternal(id, user);
|
|
41241
|
-
}
|
|
41372
|
+
return resolveUserExternal(user, id, parentId, isResolved);
|
|
41242
41373
|
}
|
|
41243
41374
|
};
|
|
41244
41375
|
}
|
|
41376
|
+
function resolveUserExternal(user, id, parentId, isResolved) {
|
|
41377
|
+
if (typeof user === 'function') {
|
|
41378
|
+
return user(id, parentId, isResolved);
|
|
41379
|
+
}
|
|
41380
|
+
else if (Array.isArray(user)) {
|
|
41381
|
+
return user.some((test) => isExternal(id, test));
|
|
41382
|
+
}
|
|
41383
|
+
else {
|
|
41384
|
+
return isExternal(id, user);
|
|
41385
|
+
}
|
|
41386
|
+
}
|
|
41245
41387
|
function isExternal(id, test) {
|
|
41246
41388
|
if (typeof test === 'string') {
|
|
41247
41389
|
return id === test;
|
|
@@ -47250,12 +47392,21 @@ var guess = function guessEditor (specifiedEditor) {
|
|
|
47250
47392
|
if (specifiedEditor) {
|
|
47251
47393
|
return shellQuote.parse(specifiedEditor)
|
|
47252
47394
|
}
|
|
47395
|
+
|
|
47396
|
+
if (process.versions.webcontainer) {
|
|
47397
|
+
return [process.env.EDITOR || 'code']
|
|
47398
|
+
}
|
|
47399
|
+
|
|
47253
47400
|
// We can find out which editor is currently running by:
|
|
47254
47401
|
// `ps x` on macOS and Linux
|
|
47255
47402
|
// `Get-Process` on Windows
|
|
47256
47403
|
try {
|
|
47257
47404
|
if (process.platform === 'darwin') {
|
|
47258
|
-
const output = childProcess$2
|
|
47405
|
+
const output = childProcess$2
|
|
47406
|
+
.execSync('ps x', {
|
|
47407
|
+
stdio: ['pipe', 'pipe', 'ignore']
|
|
47408
|
+
})
|
|
47409
|
+
.toString();
|
|
47259
47410
|
const processNames = Object.keys(COMMON_EDITORS_OSX);
|
|
47260
47411
|
for (let i = 0; i < processNames.length; i++) {
|
|
47261
47412
|
const processName = processNames[i];
|
|
@@ -47288,7 +47439,9 @@ var guess = function guessEditor (specifiedEditor) {
|
|
|
47288
47439
|
// x List all processes owned by you
|
|
47289
47440
|
// -o comm Need only names column
|
|
47290
47441
|
const output = childProcess$2
|
|
47291
|
-
.execSync('ps x --no-heading -o comm --sort=comm'
|
|
47442
|
+
.execSync('ps x --no-heading -o comm --sort=comm', {
|
|
47443
|
+
stdio: ['pipe', 'pipe', 'ignore']
|
|
47444
|
+
})
|
|
47292
47445
|
.toString();
|
|
47293
47446
|
const processNames = Object.keys(COMMON_EDITORS_LINUX);
|
|
47294
47447
|
for (let i = 0; i < processNames.length; i++) {
|
|
@@ -47603,7 +47756,7 @@ async function getCertificate(cacheDir) {
|
|
|
47603
47756
|
return content;
|
|
47604
47757
|
}
|
|
47605
47758
|
catch {
|
|
47606
|
-
const content = (await import('./dep-
|
|
47759
|
+
const content = (await import('./dep-8259d5f4.js')).createCertificate();
|
|
47607
47760
|
promises
|
|
47608
47761
|
.mkdir(cacheDir, { recursive: true })
|
|
47609
47762
|
.then(() => promises.writeFile(cachePath, content))
|
|
@@ -47645,8 +47798,10 @@ async function httpServerStart(httpServer, serverOptions) {
|
|
|
47645
47798
|
*/
|
|
47646
47799
|
function ssrRequireHookPlugin(config) {
|
|
47647
47800
|
if (config.command !== 'build' ||
|
|
47801
|
+
!config.build.ssr ||
|
|
47648
47802
|
!config.resolve.dedupe?.length ||
|
|
47649
47803
|
config.ssr?.noExternal === true ||
|
|
47804
|
+
config.ssr?.format !== 'cjs' ||
|
|
47650
47805
|
isBuildOutputEsm(config)) {
|
|
47651
47806
|
return null;
|
|
47652
47807
|
}
|
|
@@ -51128,6 +51283,7 @@ function initAsClient(websocket, address, protocols, options) {
|
|
|
51128
51283
|
|
|
51129
51284
|
if (opts.followRedirects) {
|
|
51130
51285
|
if (websocket._redirects === 0) {
|
|
51286
|
+
websocket._originalSecure = isSecure;
|
|
51131
51287
|
websocket._originalHost = parsedUrl.host;
|
|
51132
51288
|
|
|
51133
51289
|
const headers = options && options.headers;
|
|
@@ -51143,18 +51299,21 @@ function initAsClient(websocket, address, protocols, options) {
|
|
|
51143
51299
|
options.headers[key.toLowerCase()] = value;
|
|
51144
51300
|
}
|
|
51145
51301
|
}
|
|
51146
|
-
} else if (
|
|
51147
|
-
|
|
51148
|
-
|
|
51149
|
-
|
|
51150
|
-
|
|
51151
|
-
|
|
51152
|
-
|
|
51153
|
-
|
|
51154
|
-
|
|
51155
|
-
|
|
51156
|
-
|
|
51157
|
-
|
|
51302
|
+
} else if (websocket.listenerCount('redirect') === 0) {
|
|
51303
|
+
const isSameHost = parsedUrl.host === websocket._originalHost;
|
|
51304
|
+
|
|
51305
|
+
if (!isSameHost || (websocket._originalSecure && !isSecure)) {
|
|
51306
|
+
//
|
|
51307
|
+
// Match curl 7.77.0 behavior and drop the following headers. These
|
|
51308
|
+
// headers are also dropped when following a redirect to a subdomain.
|
|
51309
|
+
//
|
|
51310
|
+
delete opts.headers.authorization;
|
|
51311
|
+
delete opts.headers.cookie;
|
|
51312
|
+
|
|
51313
|
+
if (!isSameHost) delete opts.headers.host;
|
|
51314
|
+
|
|
51315
|
+
opts.auth = undefined;
|
|
51316
|
+
}
|
|
51158
51317
|
}
|
|
51159
51318
|
|
|
51160
51319
|
//
|
|
@@ -51246,6 +51405,11 @@ function initAsClient(websocket, address, protocols, options) {
|
|
|
51246
51405
|
|
|
51247
51406
|
req = websocket._req = null;
|
|
51248
51407
|
|
|
51408
|
+
if (res.headers.upgrade.toLowerCase() !== 'websocket') {
|
|
51409
|
+
abortHandshake$1(websocket, socket, 'Invalid Upgrade header');
|
|
51410
|
+
return;
|
|
51411
|
+
}
|
|
51412
|
+
|
|
51249
51413
|
const digest = createHash$1('sha1')
|
|
51250
51414
|
.update(key + GUID$1)
|
|
51251
51415
|
.digest('base64');
|
|
@@ -51931,21 +52095,36 @@ class WebSocketServer extends EventEmitter {
|
|
|
51931
52095
|
handleUpgrade(req, socket, head, cb) {
|
|
51932
52096
|
socket.on('error', socketOnError);
|
|
51933
52097
|
|
|
51934
|
-
const key =
|
|
51935
|
-
req.headers['sec-websocket-key'] !== undefined
|
|
51936
|
-
? req.headers['sec-websocket-key']
|
|
51937
|
-
: false;
|
|
52098
|
+
const key = req.headers['sec-websocket-key'];
|
|
51938
52099
|
const version = +req.headers['sec-websocket-version'];
|
|
51939
52100
|
|
|
51940
|
-
if (
|
|
51941
|
-
|
|
51942
|
-
|
|
51943
|
-
|
|
51944
|
-
|
|
51945
|
-
|
|
51946
|
-
|
|
51947
|
-
|
|
51948
|
-
|
|
52101
|
+
if (req.method !== 'GET') {
|
|
52102
|
+
const message = 'Invalid HTTP method';
|
|
52103
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 405, message);
|
|
52104
|
+
return;
|
|
52105
|
+
}
|
|
52106
|
+
|
|
52107
|
+
if (req.headers.upgrade.toLowerCase() !== 'websocket') {
|
|
52108
|
+
const message = 'Invalid Upgrade header';
|
|
52109
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
|
52110
|
+
return;
|
|
52111
|
+
}
|
|
52112
|
+
|
|
52113
|
+
if (!key || !keyRegex.test(key)) {
|
|
52114
|
+
const message = 'Missing or invalid Sec-WebSocket-Key header';
|
|
52115
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
|
52116
|
+
return;
|
|
52117
|
+
}
|
|
52118
|
+
|
|
52119
|
+
if (version !== 8 && version !== 13) {
|
|
52120
|
+
const message = 'Missing or invalid Sec-WebSocket-Version header';
|
|
52121
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
|
52122
|
+
return;
|
|
52123
|
+
}
|
|
52124
|
+
|
|
52125
|
+
if (!this.shouldHandle(req)) {
|
|
52126
|
+
abortHandshake(socket, 400);
|
|
52127
|
+
return;
|
|
51949
52128
|
}
|
|
51950
52129
|
|
|
51951
52130
|
const secWebSocketProtocol = req.headers['sec-websocket-protocol'];
|
|
@@ -51955,7 +52134,9 @@ class WebSocketServer extends EventEmitter {
|
|
|
51955
52134
|
try {
|
|
51956
52135
|
protocols = subprotocol.parse(secWebSocketProtocol);
|
|
51957
52136
|
} catch (err) {
|
|
51958
|
-
|
|
52137
|
+
const message = 'Invalid Sec-WebSocket-Protocol header';
|
|
52138
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
|
52139
|
+
return;
|
|
51959
52140
|
}
|
|
51960
52141
|
}
|
|
51961
52142
|
|
|
@@ -51980,7 +52161,10 @@ class WebSocketServer extends EventEmitter {
|
|
|
51980
52161
|
extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
|
|
51981
52162
|
}
|
|
51982
52163
|
} catch (err) {
|
|
51983
|
-
|
|
52164
|
+
const message =
|
|
52165
|
+
'Invalid or unacceptable Sec-WebSocket-Extensions header';
|
|
52166
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
|
52167
|
+
return;
|
|
51984
52168
|
}
|
|
51985
52169
|
}
|
|
51986
52170
|
|
|
@@ -52147,7 +52331,7 @@ function emitClose(server) {
|
|
|
52147
52331
|
}
|
|
52148
52332
|
|
|
52149
52333
|
/**
|
|
52150
|
-
* Handle
|
|
52334
|
+
* Handle socket errors.
|
|
52151
52335
|
*
|
|
52152
52336
|
* @private
|
|
52153
52337
|
*/
|
|
@@ -52165,27 +52349,54 @@ function socketOnError() {
|
|
|
52165
52349
|
* @private
|
|
52166
52350
|
*/
|
|
52167
52351
|
function abortHandshake(socket, code, message, headers) {
|
|
52168
|
-
|
|
52169
|
-
|
|
52170
|
-
|
|
52171
|
-
|
|
52172
|
-
|
|
52173
|
-
|
|
52174
|
-
|
|
52175
|
-
|
|
52352
|
+
//
|
|
52353
|
+
// The socket is writable unless the user destroyed or ended it before calling
|
|
52354
|
+
// `server.handleUpgrade()` or in the `verifyClient` function, which is a user
|
|
52355
|
+
// error. Handling this does not make much sense as the worst that can happen
|
|
52356
|
+
// is that some of the data written by the user might be discarded due to the
|
|
52357
|
+
// call to `socket.end()` below, which triggers an `'error'` event that in
|
|
52358
|
+
// turn causes the socket to be destroyed.
|
|
52359
|
+
//
|
|
52360
|
+
message = message || http$2.STATUS_CODES[code];
|
|
52361
|
+
headers = {
|
|
52362
|
+
Connection: 'close',
|
|
52363
|
+
'Content-Type': 'text/html',
|
|
52364
|
+
'Content-Length': Buffer.byteLength(message),
|
|
52365
|
+
...headers
|
|
52366
|
+
};
|
|
52176
52367
|
|
|
52177
|
-
|
|
52178
|
-
`HTTP/1.1 ${code} ${http$2.STATUS_CODES[code]}\r\n` +
|
|
52179
|
-
Object.keys(headers)
|
|
52180
|
-
.map((h) => `${h}: ${headers[h]}`)
|
|
52181
|
-
.join('\r\n') +
|
|
52182
|
-
'\r\n\r\n' +
|
|
52183
|
-
message
|
|
52184
|
-
);
|
|
52185
|
-
}
|
|
52368
|
+
socket.once('finish', socket.destroy);
|
|
52186
52369
|
|
|
52187
|
-
socket.
|
|
52188
|
-
|
|
52370
|
+
socket.end(
|
|
52371
|
+
`HTTP/1.1 ${code} ${http$2.STATUS_CODES[code]}\r\n` +
|
|
52372
|
+
Object.keys(headers)
|
|
52373
|
+
.map((h) => `${h}: ${headers[h]}`)
|
|
52374
|
+
.join('\r\n') +
|
|
52375
|
+
'\r\n\r\n' +
|
|
52376
|
+
message
|
|
52377
|
+
);
|
|
52378
|
+
}
|
|
52379
|
+
|
|
52380
|
+
/**
|
|
52381
|
+
* Emit a `'wsClientError'` event on a `WebSocketServer` if there is at least
|
|
52382
|
+
* one listener for it, otherwise call `abortHandshake()`.
|
|
52383
|
+
*
|
|
52384
|
+
* @param {WebSocketServer} server The WebSocket server
|
|
52385
|
+
* @param {http.IncomingMessage} req The request object
|
|
52386
|
+
* @param {(net.Socket|tls.Socket)} socket The socket of the upgrade request
|
|
52387
|
+
* @param {Number} code The HTTP response status code
|
|
52388
|
+
* @param {String} message The HTTP response body
|
|
52389
|
+
* @private
|
|
52390
|
+
*/
|
|
52391
|
+
function abortHandshakeOrEmitwsClientError(server, req, socket, code, message) {
|
|
52392
|
+
if (server.listenerCount('wsClientError')) {
|
|
52393
|
+
const err = new Error(message);
|
|
52394
|
+
Error.captureStackTrace(err, abortHandshakeOrEmitwsClientError);
|
|
52395
|
+
|
|
52396
|
+
server.emit('wsClientError', err, socket, req);
|
|
52397
|
+
} else {
|
|
52398
|
+
abortHandshake(socket, code, message);
|
|
52399
|
+
}
|
|
52189
52400
|
}
|
|
52190
52401
|
|
|
52191
52402
|
const HMR_HEADER = 'vite-hmr';
|
|
@@ -54780,8 +54991,19 @@ function transformMiddleware(server) {
|
|
|
54780
54991
|
const publicPath = `${publicDir.slice(rootDir.length)}/`;
|
|
54781
54992
|
// warn explicit public paths
|
|
54782
54993
|
if (url.startsWith(publicPath)) {
|
|
54783
|
-
|
|
54784
|
-
|
|
54994
|
+
let warning;
|
|
54995
|
+
if (isImportRequest(url)) {
|
|
54996
|
+
const rawUrl = removeImportQuery(url);
|
|
54997
|
+
warning =
|
|
54998
|
+
'Assets in public cannot be imported from JavaScript.\n' +
|
|
54999
|
+
`Instead of ${colors$1.cyan(rawUrl)}, put the file in the src directory, and use ${colors$1.cyan(rawUrl.replace(publicPath, '/src/'))} instead.`;
|
|
55000
|
+
}
|
|
55001
|
+
else {
|
|
55002
|
+
warning =
|
|
55003
|
+
`files in the public directory are served at the root path.\n` +
|
|
55004
|
+
`Instead of ${colors$1.cyan(url)}, use ${colors$1.cyan(url.replace(publicPath, '/'))}.`;
|
|
55005
|
+
}
|
|
55006
|
+
logger.warn(colors$1.yellow(warning));
|
|
54785
55007
|
}
|
|
54786
55008
|
}
|
|
54787
55009
|
if (isJSRequest(url) ||
|
|
@@ -56422,18 +56644,7 @@ async function createServer(inlineConfig = {}) {
|
|
|
56422
56644
|
},
|
|
56423
56645
|
transformIndexHtml: null,
|
|
56424
56646
|
async ssrLoadModule(url, opts) {
|
|
56425
|
-
|
|
56426
|
-
let knownImports = [];
|
|
56427
|
-
const depsOptimizer = getDepsOptimizer(config);
|
|
56428
|
-
if (depsOptimizer) {
|
|
56429
|
-
await depsOptimizer.scanProcessing;
|
|
56430
|
-
knownImports = [
|
|
56431
|
-
...Object.keys(depsOptimizer.metadata.optimized),
|
|
56432
|
-
...Object.keys(depsOptimizer.metadata.discovered)
|
|
56433
|
-
];
|
|
56434
|
-
}
|
|
56435
|
-
server._ssrExternals = resolveSSRExternal(config, knownImports);
|
|
56436
|
-
}
|
|
56647
|
+
await updateCjsSsrExternals(server);
|
|
56437
56648
|
return ssrLoadModule(url, server, undefined, undefined, opts?.fixStacktrace);
|
|
56438
56649
|
},
|
|
56439
56650
|
ssrFixStacktrace(e) {
|
|
@@ -56779,6 +56990,20 @@ async function restartServer(server) {
|
|
|
56779
56990
|
// new server (the current server) can restart now
|
|
56780
56991
|
newServer._restartPromise = null;
|
|
56781
56992
|
}
|
|
56993
|
+
async function updateCjsSsrExternals(server) {
|
|
56994
|
+
if (!server._ssrExternals) {
|
|
56995
|
+
let knownImports = [];
|
|
56996
|
+
const depsOptimizer = getDepsOptimizer(server.config);
|
|
56997
|
+
if (depsOptimizer) {
|
|
56998
|
+
await depsOptimizer.scanProcessing;
|
|
56999
|
+
knownImports = [
|
|
57000
|
+
...Object.keys(depsOptimizer.metadata.optimized),
|
|
57001
|
+
...Object.keys(depsOptimizer.metadata.discovered)
|
|
57002
|
+
];
|
|
57003
|
+
}
|
|
57004
|
+
server._ssrExternals = cjsSsrResolveExternals(server.config, knownImports);
|
|
57005
|
+
}
|
|
57006
|
+
}
|
|
56782
57007
|
|
|
56783
57008
|
var index = {
|
|
56784
57009
|
__proto__: null,
|
|
@@ -59001,10 +59226,7 @@ function workerImportMetaUrlPlugin(config) {
|
|
|
59001
59226
|
});
|
|
59002
59227
|
}
|
|
59003
59228
|
if (s) {
|
|
59004
|
-
return
|
|
59005
|
-
code: s.toString(),
|
|
59006
|
-
map: config.build.sourcemap ? s.generateMap({ hires: true }) : null
|
|
59007
|
-
};
|
|
59229
|
+
return transformResult(s, id, config);
|
|
59008
59230
|
}
|
|
59009
59231
|
return null;
|
|
59010
59232
|
}
|
|
@@ -59258,10 +59480,7 @@ function dynamicImportVarsPlugin(config) {
|
|
|
59258
59480
|
if (needDynamicImportHelper) {
|
|
59259
59481
|
s.prepend(`import __variableDynamicImportRuntimeHelper from "${dynamicImportHelperId}";`);
|
|
59260
59482
|
}
|
|
59261
|
-
return
|
|
59262
|
-
code: s.toString(),
|
|
59263
|
-
map: config.build.sourcemap ? s.generateMap({ hires: true }) : null
|
|
59264
|
-
};
|
|
59483
|
+
return transformResult(s, importer, config);
|
|
59265
59484
|
}
|
|
59266
59485
|
}
|
|
59267
59486
|
};
|
|
@@ -59297,7 +59516,10 @@ async function resolvePlugins(config, prePlugins, normalPlugins, postPlugins) {
|
|
|
59297
59516
|
packageCache: config.packageCache,
|
|
59298
59517
|
ssrConfig: config.ssr,
|
|
59299
59518
|
asSrc: true,
|
|
59300
|
-
getDepsOptimizer: () => getDepsOptimizer(config)
|
|
59519
|
+
getDepsOptimizer: () => getDepsOptimizer(config),
|
|
59520
|
+
shouldExternalize: isBuild && config.build.ssr && config.ssr?.format !== 'cjs'
|
|
59521
|
+
? (id) => shouldExternalizeForSSR(id, config)
|
|
59522
|
+
: undefined
|
|
59301
59523
|
}),
|
|
59302
59524
|
htmlInlineProxyPlugin(config),
|
|
59303
59525
|
cssPlugin(config),
|