vike 0.4.236-commit-e752d12 → 0.4.236-commit-79f1ef0
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/cjs/client/shared/createGetGlobalContextClient.js +20 -10
- package/dist/cjs/client/shared/utils.js +1 -0
- package/dist/cjs/node/runtime/globalContext.js +104 -20
- package/dist/cjs/node/runtime/html/injectAssets/getViteDevScript.js +3 -1
- package/dist/cjs/node/runtime/renderPage/getPageAssets/retrieveAssetsDev.js +4 -0
- package/dist/cjs/node/runtime/renderPage/getPageAssets.js +3 -1
- package/dist/cjs/node/runtime/utils.js +4 -0
- package/dist/cjs/node/shared/utils.js +1 -0
- package/dist/cjs/node/shared/virtualFiles/virtualFileEntry.js +16 -14
- package/dist/cjs/node/shared/virtualFiles/virtualFilePageConfigLazy.js +10 -4
- package/dist/cjs/node/vite/index.js +2 -0
- package/dist/cjs/node/vite/plugins/pluginBuild/handleAssetsManifest.js +19 -11
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginAutoFullBuild.js +2 -2
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildApp.js +28 -13
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildConfig.js +0 -3
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginDistFileNames.js +12 -7
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginModuleBanner.js +2 -2
- package/dist/cjs/node/vite/plugins/pluginCommon.js +1 -0
- package/dist/cjs/node/vite/plugins/pluginDev/determineOptimizeDeps.js +102 -58
- package/dist/cjs/node/vite/plugins/pluginEnvVars.js +3 -3
- package/dist/cjs/node/vite/plugins/pluginExtractAssets.js +3 -4
- package/dist/cjs/node/vite/plugins/pluginExtractExportNames.js +2 -2
- package/dist/cjs/node/vite/plugins/pluginNonRunnableDev.js +51 -0
- package/dist/cjs/node/vite/plugins/pluginReplaceConstants.js +1 -1
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles/getVirtualFilePageConfigLazy.js +1 -0
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles/getVirtualFilePageConfigsEager.js +4 -0
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles.js +4 -5
- package/dist/cjs/node/vite/shared/applyRegExWithMagicString.js +1 -0
- package/dist/cjs/node/vite/shared/getMagicString.js +18 -0
- package/dist/cjs/node/vite/shared/getManifestFilePathRelative.js +10 -0
- package/dist/cjs/node/vite/utils.js +1 -0
- package/dist/cjs/shared/createGlobalContextShared.js +5 -1
- package/dist/cjs/shared/getPageFiles/parseVirtualFileExports.js +6 -0
- package/dist/cjs/shared/getProxyForPublicUsage.js +2 -2
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/assertSetup.js +2 -0
- package/dist/cjs/utils/debug.js +1 -0
- package/dist/cjs/utils/getViteRPC.js +79 -0
- package/dist/cjs/utils/isFilePathAbsoluteFilesystem.js +1 -0
- package/dist/cjs/utils/isRunnableDevEnvironment.js +9 -0
- package/dist/cjs/utils/virtualFileId.js +39 -0
- package/dist/esm/client/runtime-client-routing/createPageContextClientSide.d.ts +1 -1
- package/dist/esm/client/runtime-client-routing/getPageContextFromHooks.d.ts +2 -2
- package/dist/esm/client/runtime-client-routing/globalContext.d.ts +1 -1
- package/dist/esm/client/runtime-client-routing/history.d.ts +4 -2
- package/dist/esm/client/runtime-client-routing/history.js +13 -35
- package/dist/esm/client/runtime-client-routing/initClientRouter.js +3 -2
- package/dist/esm/client/runtime-client-routing/renderPageClientSide.d.ts +1 -1
- package/dist/esm/client/runtime-client-routing/renderPageClientSide.js +43 -30
- package/dist/esm/client/runtime-server-routing/createPageContextClientSide.d.ts +1 -1
- package/dist/esm/client/runtime-server-routing/globalContext.d.ts +1 -1
- package/dist/esm/client/shared/createGetGlobalContextClient.d.ts +1 -1
- package/dist/esm/client/shared/createGetGlobalContextClient.js +20 -10
- package/dist/esm/client/shared/utils.d.ts +1 -0
- package/dist/esm/client/shared/utils.js +1 -0
- package/dist/esm/node/prerender/runPrerender.d.ts +40 -132
- package/dist/esm/node/runtime/globalContext.d.ts +32 -52
- package/dist/esm/node/runtime/globalContext.js +105 -21
- package/dist/esm/node/runtime/html/injectAssets/getViteDevScript.js +4 -2
- package/dist/esm/node/runtime/renderPage/createPageContextServerSide.d.ts +10 -33
- package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsDev.js +4 -0
- package/dist/esm/node/runtime/renderPage/getPageAssets.js +4 -2
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +20 -66
- package/dist/esm/node/runtime/renderPage.d.ts +10 -33
- package/dist/esm/node/runtime/utils.d.ts +4 -0
- package/dist/esm/node/runtime/utils.js +4 -0
- package/dist/esm/node/shared/utils.d.ts +1 -0
- package/dist/esm/node/shared/utils.js +1 -0
- package/dist/esm/node/shared/virtualFiles/virtualFileEntry.js +16 -14
- package/dist/esm/node/shared/virtualFiles/virtualFilePageConfigLazy.js +11 -5
- package/dist/esm/node/vite/index.js +2 -0
- package/dist/esm/node/vite/plugins/pluginBuild/handleAssetsManifest.d.ts +1 -1
- package/dist/esm/node/vite/plugins/pluginBuild/handleAssetsManifest.js +19 -11
- package/dist/esm/node/vite/plugins/pluginBuild/pluginAutoFullBuild.js +2 -2
- package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildApp.js +28 -13
- package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildConfig.d.ts +0 -2
- package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildConfig.js +0 -2
- package/dist/esm/node/vite/plugins/pluginBuild/pluginDistFileNames.js +12 -7
- package/dist/esm/node/vite/plugins/pluginBuild/pluginModuleBanner.js +2 -2
- package/dist/esm/node/vite/plugins/pluginCommon.d.ts +3 -0
- package/dist/esm/node/vite/plugins/pluginCommon.js +1 -0
- package/dist/esm/node/vite/plugins/pluginDev/determineOptimizeDeps.js +103 -59
- package/dist/esm/node/vite/plugins/pluginExtractAssets.js +3 -4
- package/dist/esm/node/vite/plugins/pluginNonRunnableDev.d.ts +26 -0
- package/dist/esm/node/vite/plugins/pluginNonRunnableDev.js +49 -0
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/getVirtualFilePageConfigLazy.js +1 -0
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/getVirtualFilePageConfigsEager.js +4 -0
- package/dist/esm/node/vite/plugins/pluginVirtualFiles.js +3 -4
- package/dist/esm/node/vite/shared/applyRegExWithMagicString.js +1 -0
- package/dist/esm/node/vite/shared/getMagicString.d.ts +9 -0
- package/dist/esm/node/vite/shared/getMagicString.js +13 -0
- package/dist/esm/node/vite/shared/getManifestFilePathRelative.d.ts +2 -0
- package/dist/esm/node/vite/shared/getManifestFilePathRelative.js +8 -0
- package/dist/esm/node/vite/utils.d.ts +1 -0
- package/dist/esm/node/vite/utils.js +1 -0
- package/dist/esm/shared/createGlobalContextShared.d.ts +3 -3
- package/dist/esm/shared/createGlobalContextShared.js +5 -1
- package/dist/esm/shared/getPageFiles/parseVirtualFileExports.js +6 -0
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/assertSetup.js +2 -0
- package/dist/esm/utils/debug.d.ts +1 -1
- package/dist/esm/utils/debug.js +1 -0
- package/dist/esm/utils/getViteRPC.d.ts +6 -0
- package/dist/esm/utils/getViteRPC.js +77 -0
- package/dist/esm/utils/isFilePathAbsoluteFilesystem.d.ts +7 -0
- package/dist/esm/utils/isFilePathAbsoluteFilesystem.js +1 -0
- package/dist/esm/utils/isRunnableDevEnvironment.d.ts +3 -0
- package/dist/esm/utils/isRunnableDevEnvironment.js +7 -0
- package/dist/esm/utils/virtualFileId.d.ts +6 -0
- package/dist/esm/{node/shared/virtualFiles.js → utils/virtualFileId.js} +15 -17
- package/package.json +12 -3
- package/dist/cjs/node/shared/virtualFiles.js +0 -41
- package/dist/esm/node/shared/virtualFiles.d.ts +0 -8
|
@@ -156,13 +156,8 @@ function getEntryFileName(chunkInfo, config, isEntry) {
|
|
|
156
156
|
return `${name}.${isEntry ? 'mjs' : 'js'}`;
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
|
-
function removePathSeparators(name
|
|
159
|
+
function removePathSeparators(name) {
|
|
160
160
|
(0, utils_js_1.assertPosixPath)(name);
|
|
161
|
-
if (name.startsWith(userRootDir)) {
|
|
162
|
-
name = name.slice(userRootDir.length);
|
|
163
|
-
if (name.startsWith('/'))
|
|
164
|
-
name = name.slice(1);
|
|
165
|
-
}
|
|
166
161
|
(0, utils_js_1.assert)(!name.startsWith('/'), { name });
|
|
167
162
|
const entryDir = 'entries/';
|
|
168
163
|
const hasEntryDir = name.startsWith(entryDir);
|
|
@@ -176,14 +171,24 @@ function removePathSeparators(name, userRootDir) {
|
|
|
176
171
|
}
|
|
177
172
|
return name;
|
|
178
173
|
}
|
|
174
|
+
function removeUserRootDir(name, userRootDir) {
|
|
175
|
+
if (name.startsWith(userRootDir)) {
|
|
176
|
+
name = name.slice(userRootDir.length);
|
|
177
|
+
if (name.startsWith('/'))
|
|
178
|
+
name = name.slice(1);
|
|
179
|
+
}
|
|
180
|
+
(0, utils_js_1.assert)(!name.startsWith('/'), { name });
|
|
181
|
+
return name;
|
|
182
|
+
}
|
|
179
183
|
function clean(name, userRootDir, removePathSep, fixGlob) {
|
|
184
|
+
name = removeUserRootDir(name, userRootDir);
|
|
180
185
|
name = fixExtractAssetsQuery(name);
|
|
181
186
|
if (fixGlob) {
|
|
182
187
|
name = workaroundGlob(name);
|
|
183
188
|
}
|
|
184
189
|
name = replaceNonLatinCharacters(name);
|
|
185
190
|
if (removePathSep) {
|
|
186
|
-
name = removePathSeparators(name
|
|
191
|
+
name = removePathSeparators(name);
|
|
187
192
|
}
|
|
188
193
|
name = removeLeadingUnderscoreInFilename(name);
|
|
189
194
|
name = removeUnderscoreDoublets(name);
|
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.pluginModuleBanner = pluginModuleBanner;
|
|
7
7
|
const magic_string_1 = __importDefault(require("magic-string"));
|
|
8
|
-
const
|
|
8
|
+
const utils_js_1 = require("../../utils.js");
|
|
9
9
|
const isViteServerBuild_js_1 = require("../../shared/isViteServerBuild.js");
|
|
10
10
|
// Rollup's banner feature doesn't work with Vite: https://github.com/vitejs/vite/issues/8412
|
|
11
11
|
// But, anyways, we want to prepend the banner at the beginning of each module, not at the beginning of each file (I believe that's what Rollup's banner feature does).
|
|
@@ -28,7 +28,7 @@ function pluginModuleBanner() {
|
|
|
28
28
|
}
|
|
29
29
|
if (id.startsWith('\0'))
|
|
30
30
|
id = id;
|
|
31
|
-
id = (0,
|
|
31
|
+
id = (0, utils_js_1.removeVirtualFileIdPrefix)(id);
|
|
32
32
|
if (id.startsWith(config.root))
|
|
33
33
|
id = id.slice(config.root.length + 1);
|
|
34
34
|
id = id.replaceAll('*/', '*\\/'); // https://github.com/vikejs/vike/issues/2377
|
|
@@ -16,6 +16,7 @@ const resolveVikeConfigInternal_js_1 = require("../shared/resolveVikeConfigInter
|
|
|
16
16
|
const prepareViteApiCall_js_1 = require("../../api/prepareViteApiCall.js");
|
|
17
17
|
const context_js_2 = require("../../prerender/context.js");
|
|
18
18
|
const pluginName = 'vike:pluginCommon';
|
|
19
|
+
globalThis.__VIKE__IS_PROCESS_SHARED_WITH_VITE = true;
|
|
19
20
|
function pluginCommon(vikeVitePluginOptions) {
|
|
20
21
|
return [
|
|
21
22
|
{
|
|
@@ -11,38 +11,80 @@ const debug = (0, utils_js_1.createDebugger)('vike:optimizeDeps');
|
|
|
11
11
|
async function determineOptimizeDeps(config) {
|
|
12
12
|
const vikeConfig = await (0, resolveVikeConfigInternal_js_1.getVikeConfigInternal)();
|
|
13
13
|
const { _pageConfigs: pageConfigs } = vikeConfig;
|
|
14
|
-
const {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
const { entriesClient, entriesServer, includeClient, includeServer } = await getPageDeps(config, pageConfigs);
|
|
15
|
+
config.optimizeDeps.include = add(config.optimizeDeps.include, includeClient);
|
|
16
|
+
config.optimizeDeps.entries = add(config.optimizeDeps.entries, entriesClient);
|
|
17
|
+
// Workaround until https://github.com/vitejs/vite-plugin-react/issues/650
|
|
18
|
+
// - TODO/soon: remove workaround once https://github.com/vitejs/vite/pull/20495 is released
|
|
19
|
+
includeServer.push('react/jsx-dev-runtime');
|
|
20
|
+
for (const envName in config.environments) {
|
|
21
|
+
const env = config.environments[envName];
|
|
22
|
+
if (env.consumer === 'server' && env.optimizeDeps.noDiscovery === false) {
|
|
23
|
+
env.optimizeDeps.include = add(env.optimizeDeps.include, includeServer);
|
|
24
|
+
env.optimizeDeps.entries = add(env.optimizeDeps.entries, entriesServer);
|
|
25
|
+
}
|
|
22
26
|
}
|
|
23
|
-
/* Other Vite plugins may populate optimizeDeps, e.g. Cypress: https://github.com/vikejs/vike/issues/386
|
|
24
|
-
assert(config.optimizeDeps.entries === undefined)
|
|
25
|
-
*/
|
|
26
|
-
config.optimizeDeps.include = [...include, ...normalizeInclude(config.optimizeDeps.include)];
|
|
27
|
-
config.optimizeDeps.entries = [...entries, ...normalizeEntries(config.optimizeDeps.entries)];
|
|
28
27
|
if (debug.isActivated)
|
|
29
|
-
debug('
|
|
28
|
+
debug('optimizeDeps', {
|
|
30
29
|
'config.optimizeDeps.entries': config.optimizeDeps.entries,
|
|
31
30
|
'config.optimizeDeps.include': config.optimizeDeps.include,
|
|
31
|
+
'config.optimizeDeps.exclude': config.optimizeDeps.exclude,
|
|
32
|
+
// @ts-ignore Vite doesn't seem to support ssr.optimizeDeps.entries (vite@7.0.6, July 2025)
|
|
33
|
+
'config.ssr.optimizeDeps.entries': config.ssr.optimizeDeps.entries,
|
|
34
|
+
'config.ssr.optimizeDeps.include': config.ssr.optimizeDeps.include,
|
|
35
|
+
'config.ssr.optimizeDeps.exclude': config.ssr.optimizeDeps.exclude,
|
|
32
36
|
});
|
|
33
37
|
}
|
|
34
38
|
async function getPageDeps(config, pageConfigs) {
|
|
35
|
-
let
|
|
36
|
-
let
|
|
37
|
-
|
|
39
|
+
let entriesClient = [];
|
|
40
|
+
let entriesServer = [];
|
|
41
|
+
let includeClient = [];
|
|
42
|
+
let includeServer = [];
|
|
43
|
+
const addEntry = (e, configEnv, definedAt) => {
|
|
38
44
|
(0, utils_js_1.assert)(e);
|
|
39
|
-
entries
|
|
45
|
+
// optimizeDeps.entries expects filesystem absolute paths
|
|
46
|
+
(0, utils_js_1.assert)((0, utils_js_1.isVirtualFileId)(e) || (0, utils_js_1.isFilePathAbsoluteFilesystem)(e));
|
|
47
|
+
if (isRelevant(e, false, configEnv, definedAt)) {
|
|
48
|
+
entriesClient.push(e);
|
|
49
|
+
}
|
|
50
|
+
if (isRelevant(e, true, configEnv, definedAt)) {
|
|
51
|
+
entriesServer.push(e);
|
|
52
|
+
}
|
|
40
53
|
};
|
|
41
|
-
const addInclude = (e) => {
|
|
54
|
+
const addInclude = (e, configEnv, definedAt) => {
|
|
42
55
|
(0, utils_js_1.assert)(e);
|
|
43
|
-
//
|
|
56
|
+
// optimizeDeps.include expects npm packages
|
|
57
|
+
(0, utils_js_1.assert)(!e.startsWith('/'));
|
|
58
|
+
// Shouldn't be a path alias, as path aliases would need to be added to optimizeDeps.entries instead of optimizeDeps.include
|
|
44
59
|
(0, utils_js_1.assertIsImportPathNpmPackage)(e);
|
|
45
|
-
|
|
60
|
+
if (isRelevant(e, false, configEnv, definedAt)) {
|
|
61
|
+
includeClient.push(e);
|
|
62
|
+
}
|
|
63
|
+
if (isRelevant(e, true, configEnv, definedAt)) {
|
|
64
|
+
includeServer.push(e);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
const isRelevant = (e, server, configEnv, definedAt) => {
|
|
68
|
+
if (server) {
|
|
69
|
+
if (!configEnv || !configEnv.server)
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
if (configEnv && !configEnv.client)
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
return !isExcluded(e, server, definedAt);
|
|
77
|
+
};
|
|
78
|
+
const isExcluded = (e, server, definedAt) => {
|
|
79
|
+
const exclude = server ? config.ssr.optimizeDeps.exclude : config.optimizeDeps.exclude;
|
|
80
|
+
if (!exclude)
|
|
81
|
+
return false;
|
|
82
|
+
if (definedAt?.importPathAbsolute) {
|
|
83
|
+
const npmPackageName = (0, utils_js_1.getNpmPackageName)(definedAt.importPathAbsolute);
|
|
84
|
+
if (npmPackageName && exclude.includes(npmPackageName))
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
return exclude.includes(e);
|
|
46
88
|
};
|
|
47
89
|
// V1 design
|
|
48
90
|
{
|
|
@@ -54,22 +96,17 @@ async function getPageDeps(config, pageConfigs) {
|
|
|
54
96
|
if (!configValueSource.valueIsLoadedWithImport && !configValueSource.valueIsFilePath)
|
|
55
97
|
return;
|
|
56
98
|
const { definedAt, configEnv } = configValueSource;
|
|
57
|
-
if (!configEnv.client)
|
|
58
|
-
return;
|
|
59
99
|
if (definedAt.definedBy)
|
|
60
100
|
return;
|
|
61
|
-
if (definedAt.importPathAbsolute) {
|
|
62
|
-
const npmPackageName = (0, utils_js_1.getNpmPackageName)(definedAt.importPathAbsolute);
|
|
63
|
-
if (npmPackageName && config.optimizeDeps.exclude?.includes(npmPackageName))
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
101
|
if (definedAt.filePathAbsoluteUserRootDir !== null) {
|
|
67
|
-
|
|
68
|
-
|
|
102
|
+
addEntry(
|
|
103
|
+
// optimizeDeps.entries expects filesystem absolute paths
|
|
104
|
+
definedAt.filePathAbsoluteFilesystem, configEnv, definedAt);
|
|
69
105
|
}
|
|
70
106
|
else {
|
|
71
|
-
|
|
72
|
-
|
|
107
|
+
addInclude(
|
|
108
|
+
// optimizeDeps.include expects npm packages
|
|
109
|
+
definedAt.importPathAbsolute, configEnv, definedAt);
|
|
73
110
|
}
|
|
74
111
|
});
|
|
75
112
|
});
|
|
@@ -85,32 +122,39 @@ async function getPageDeps(config, pageConfigs) {
|
|
|
85
122
|
addEntry(filePathAbsoluteFilesystem);
|
|
86
123
|
});
|
|
87
124
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
125
|
+
// Add virtual files.
|
|
126
|
+
// - This doesn't work: Vite's dep optimizer doesn't seem to be able to crawl virtual files.
|
|
127
|
+
// - Should we make it work? E.g. by creating a temporary file at node_modules/.vike/virtualFiles.js
|
|
128
|
+
// - Or should we remove it? And make sure getPageDeps() also works for aliased import paths
|
|
129
|
+
// - If we do, then we need to adjust include/entries (maybe by making include === entries -> will Vite complain?)
|
|
130
|
+
{
|
|
131
|
+
const { hasClientRouting, hasServerRouting, clientEntries } = (0, pluginBuildConfig_js_1.analyzeClientEntries)(pageConfigs, config);
|
|
132
|
+
Object.values(clientEntries).forEach((e) => addEntry(e));
|
|
133
|
+
if (hasClientRouting)
|
|
134
|
+
addEntry(virtualFileEntry_js_1.virtualFileIdEntryClientCR);
|
|
135
|
+
if (hasServerRouting)
|
|
136
|
+
addEntry(virtualFileEntry_js_1.virtualFileIdEntryClientSR);
|
|
137
|
+
}
|
|
138
|
+
entriesClient = entriesClient;
|
|
139
|
+
entriesServer = entriesServer;
|
|
140
|
+
includeClient = includeClient;
|
|
141
|
+
includeServer = includeServer;
|
|
142
|
+
return {
|
|
143
|
+
entriesClient,
|
|
144
|
+
entriesServer,
|
|
145
|
+
includeClient,
|
|
146
|
+
includeServer,
|
|
147
|
+
};
|
|
100
148
|
}
|
|
101
|
-
function
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
(0, utils_js_1.assert)(false);
|
|
149
|
+
function add(input, listAddendum) {
|
|
150
|
+
const list = !input ? [] : (0, utils_js_1.isArray)(input) ? unique(input) : [input];
|
|
151
|
+
listAddendum.forEach((e) => {
|
|
152
|
+
if (!list.includes(e))
|
|
153
|
+
list.push(e);
|
|
154
|
+
});
|
|
155
|
+
return list;
|
|
109
156
|
}
|
|
110
|
-
function
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
if (include === undefined)
|
|
114
|
-
return [];
|
|
115
|
-
(0, utils_js_1.assert)(false);
|
|
157
|
+
function unique(arr) {
|
|
158
|
+
const arrUnique = Array.from(new Set(arr));
|
|
159
|
+
return arr.length !== arrUnique.length ? arrUnique : arr;
|
|
116
160
|
}
|
|
@@ -12,7 +12,7 @@ const normalizeId_js_1 = require("../shared/normalizeId.js");
|
|
|
12
12
|
const isViteServerBuild_js_1 = require("../shared/isViteServerBuild.js");
|
|
13
13
|
const applyRegExWithMagicString_js_1 = require("../shared/applyRegExWithMagicString.js");
|
|
14
14
|
// TO-DO/eventually:
|
|
15
|
-
// - Make
|
|
15
|
+
// - Make ({}) work inside +config.js
|
|
16
16
|
// - For it to work, we'll probably need the user to define the settings (e.g. `envDir`) for loadEnv() inside vike.config.js instead of vite.config.js
|
|
17
17
|
// - Or stop using Vite's `mode` implementation and have Vike implement its own `mode` feature? (So that the only dependencies are `$ vike build --mode staging` and `$ MODE=staging vike build`.)
|
|
18
18
|
const PUBLIC_ENV_PREFIX = 'PUBLIC_ENV__';
|
|
@@ -39,7 +39,7 @@ function pluginEnvVars() {
|
|
|
39
39
|
(0, utils_js_1.assertPosixPath)(config.root);
|
|
40
40
|
if (!id.startsWith(config.root))
|
|
41
41
|
return;
|
|
42
|
-
if (!code.includes('
|
|
42
|
+
if (!code.includes('({}).'))
|
|
43
43
|
return;
|
|
44
44
|
const isBuild = config.command === 'build';
|
|
45
45
|
const isClientSide = !(0, isViteServerBuild_js_1.isViteServerBuild_safe)(config, options);
|
|
@@ -52,7 +52,7 @@ function pluginEnvVars() {
|
|
|
52
52
|
return !envPrefix.some((prefix) => key.startsWith(prefix));
|
|
53
53
|
})
|
|
54
54
|
.map(([envName, envVal]) => {
|
|
55
|
-
const envStatement = `
|
|
55
|
+
const envStatement = `({}).${envName}`;
|
|
56
56
|
const envStatementRegExpStr = (0, utils_js_1.escapeRegex)(envStatement) + '\\b';
|
|
57
57
|
// Security check
|
|
58
58
|
{
|
|
@@ -8,7 +8,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
8
8
|
exports.extractAssetsRE = void 0;
|
|
9
9
|
exports.pluginExtractAssets = pluginExtractAssets;
|
|
10
10
|
const utils_js_1 = require("../utils.js");
|
|
11
|
-
const virtualFiles_js_1 = require("../../shared/virtualFiles.js");
|
|
12
11
|
const extractAssetsQuery_js_1 = require("../../shared/extractAssetsQuery.js");
|
|
13
12
|
const isAsset_js_1 = require("../shared/isAsset.js");
|
|
14
13
|
const parseEsModule_js_1 = require("../shared/parseEsModule.js");
|
|
@@ -124,9 +123,9 @@ function pluginExtractAssets() {
|
|
|
124
123
|
name: 'vike:pluginExtractAssets-3',
|
|
125
124
|
apply: 'build',
|
|
126
125
|
load(id) {
|
|
127
|
-
if (!(0,
|
|
126
|
+
if (!(0, utils_js_1.isVirtualFileId)(id))
|
|
128
127
|
return undefined;
|
|
129
|
-
id = (0,
|
|
128
|
+
id = (0, utils_js_1.removeVirtualFileIdPrefix)(id);
|
|
130
129
|
if (id === EMPTY_MODULE_ID) {
|
|
131
130
|
return '// Erased by vike:pluginExtractAssets';
|
|
132
131
|
}
|
|
@@ -153,7 +152,7 @@ function pluginExtractAssets() {
|
|
|
153
152
|
}
|
|
154
153
|
function emptyModule(file, importer) {
|
|
155
154
|
debugOperation('NUKED', file, importer);
|
|
156
|
-
return (0,
|
|
155
|
+
return (0, utils_js_1.addVirtualFileIdPrefix)(EMPTY_MODULE_ID);
|
|
157
156
|
}
|
|
158
157
|
function appendExtractAssetsQuery(file, importer) {
|
|
159
158
|
debugOperation('TRANSFORMED', file, importer);
|
|
@@ -81,12 +81,12 @@ function injectHmr(code, isClientSide, isProduction) {
|
|
|
81
81
|
}
|
|
82
82
|
if (isClientSide) {
|
|
83
83
|
code += '\n';
|
|
84
|
-
code += `if (
|
|
84
|
+
code += `if ((undefined)) (undefined).accept((mod) => { exportNames.length=0; exportNames.push(...mod.exportNames); });`;
|
|
85
85
|
}
|
|
86
86
|
else {
|
|
87
87
|
// Ensure Vite considers the module as `isSelfAccepting`. (Needed because Vite's module graph erroneously conflates the Vite server-side modules with their client-side counterparts.)
|
|
88
88
|
code += '\n';
|
|
89
|
-
code += 'if(false){
|
|
89
|
+
code += 'if(false){(undefined).accept(()=>{})};';
|
|
90
90
|
}
|
|
91
91
|
return code;
|
|
92
92
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pluginNonRunnableDev = pluginNonRunnableDev;
|
|
4
|
+
const utils_js_1 = require("../utils.js");
|
|
5
|
+
const resolveClientEntriesDev_js_1 = require("../shared/resolveClientEntriesDev.js");
|
|
6
|
+
const retrieveAssetsDev_js_1 = require("../../runtime/renderPage/getPageAssets/retrieveAssetsDev.js");
|
|
7
|
+
const getViteConfigRuntime_js_1 = require("../shared/getViteConfigRuntime.js");
|
|
8
|
+
const getMagicString_js_1 = require("../shared/getMagicString.js");
|
|
9
|
+
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
10
|
+
function getViteRpcFunctions(viteDevServer) {
|
|
11
|
+
return {
|
|
12
|
+
async transformIndexHtmlRPC(html) {
|
|
13
|
+
return await viteDevServer.transformIndexHtml('/', html);
|
|
14
|
+
},
|
|
15
|
+
// TODO/now: dedupe retrievePageAssetsDevRPC and retrievePageAssetsDev()
|
|
16
|
+
async retrievePageAssetsDevRPC(clientDependencies, clientEntries) {
|
|
17
|
+
const clientEntriesSrc = clientEntries.map((clientEntry) => (0, resolveClientEntriesDev_js_1.resolveClientEntriesDev)(clientEntry, viteDevServer));
|
|
18
|
+
const assetUrls = await (0, retrieveAssetsDev_js_1.retrieveAssetsDev)(clientDependencies, viteDevServer);
|
|
19
|
+
return { clientEntriesSrc, assetUrls };
|
|
20
|
+
},
|
|
21
|
+
async getViteConfigRuntimeRPC() {
|
|
22
|
+
return (0, getViteConfigRuntime_js_1.getViteConfigRuntime)(viteDevServer.config);
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function pluginNonRunnableDev() {
|
|
27
|
+
const runtimeGlobalContextFilePath = (0, utils_js_1.requireResolveVikeDistFile)('dist/esm/node/runtime/globalContext.js');
|
|
28
|
+
let config;
|
|
29
|
+
return {
|
|
30
|
+
name: 'vike:pluginNonRunnableDev',
|
|
31
|
+
configureServer(viteDevServer) {
|
|
32
|
+
(0, utils_js_1.createViteRPC)(viteDevServer, getViteRpcFunctions);
|
|
33
|
+
},
|
|
34
|
+
configResolved(config_) {
|
|
35
|
+
config = config_;
|
|
36
|
+
},
|
|
37
|
+
transform(code, id) {
|
|
38
|
+
if (!config._isDev)
|
|
39
|
+
return;
|
|
40
|
+
if (id !== runtimeGlobalContextFilePath)
|
|
41
|
+
return;
|
|
42
|
+
const isNonRunnableDev = !(0, utils_js_1.isRunnableDevEnvironment)(this.environment);
|
|
43
|
+
const { magicString, getMagicStringResult } = (0, getMagicString_js_1.getMagicString)(code, id);
|
|
44
|
+
if (isNonRunnableDev) {
|
|
45
|
+
magicString.replaceAll('__VIKE__DYNAMIC_IMPORT', 'import');
|
|
46
|
+
}
|
|
47
|
+
magicString.replaceAll('__VIKE__IS_NON_RUNNABLE_DEV', JSON.stringify(isNonRunnableDev));
|
|
48
|
+
return getMagicStringResult();
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
@@ -26,7 +26,7 @@ function pluginReplaceConstants() {
|
|
|
26
26
|
(0, utils_js_1.assertPosixPath)(config.root);
|
|
27
27
|
if (!id.startsWith(config.root))
|
|
28
28
|
return;
|
|
29
|
-
if (!code.includes('
|
|
29
|
+
if (!code.includes('({}).'))
|
|
30
30
|
return;
|
|
31
31
|
const isBuild = config.command === 'build';
|
|
32
32
|
(0, utils_js_1.assert)(isBuild);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getVirtualFilePageConfigLazy = getVirtualFilePageConfigLazy;
|
|
4
|
+
// TODO/now: rename file to generateVirtualFileEntryPage.ts
|
|
4
5
|
const utils_js_1 = require("../../utils.js");
|
|
5
6
|
const virtualFilePageConfigLazy_js_1 = require("../../../shared/virtualFiles/virtualFilePageConfigLazy.js");
|
|
6
7
|
const resolveVikeConfigInternal_js_1 = require("../../shared/resolveVikeConfigInternal.js");
|
|
@@ -21,6 +21,10 @@ function getCode(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, isCl
|
|
|
21
21
|
lines.push('export const pageConfigGlobalSerialized = {');
|
|
22
22
|
lines.push(getCodePageConfigGlobalSerialized(pageConfigGlobal, isForClientSide, isClientRouting, isDev, importStatements, filesEnv));
|
|
23
23
|
lines.push('};');
|
|
24
|
+
if (!isForClientSide && isDev) {
|
|
25
|
+
// https://vite.dev/guide/api-environment-frameworks.html
|
|
26
|
+
lines.push('if ((undefined)) (undefined).accept();');
|
|
27
|
+
}
|
|
24
28
|
const code = [...importStatements, ...lines].join('\n');
|
|
25
29
|
(0, debug_js_1.debug)(id, isForClientSide ? 'CLIENT-SIDE' : 'SERVER-SIDE', code);
|
|
26
30
|
return code;
|
|
@@ -8,7 +8,6 @@ const vite_1 = require("vite");
|
|
|
8
8
|
const getVirtualFilePageConfigLazy_js_1 = require("./pluginVirtualFiles/getVirtualFilePageConfigLazy.js");
|
|
9
9
|
const getVirtualFileEntry_js_1 = require("./pluginVirtualFiles/getVirtualFileEntry.js");
|
|
10
10
|
const utils_js_1 = require("../utils.js");
|
|
11
|
-
const virtualFiles_js_1 = require("../../shared/virtualFiles.js");
|
|
12
11
|
const virtualFilePageConfigLazy_js_1 = require("../../shared/virtualFiles/virtualFilePageConfigLazy.js");
|
|
13
12
|
const virtualFileEntry_js_1 = require("../../shared/virtualFiles/virtualFileEntry.js");
|
|
14
13
|
const resolveVikeConfigInternal_js_1 = require("../shared/resolveVikeConfigInternal.js");
|
|
@@ -30,8 +29,8 @@ function pluginVirtualFiles() {
|
|
|
30
29
|
config.experimental.importGlobRestoreExtension = true;
|
|
31
30
|
},
|
|
32
31
|
resolveId(id) {
|
|
33
|
-
if ((0,
|
|
34
|
-
return (0,
|
|
32
|
+
if ((0, utils_js_1.isVirtualFileId)(id)) {
|
|
33
|
+
return (0, utils_js_1.addVirtualFileIdPrefix)(id);
|
|
35
34
|
}
|
|
36
35
|
},
|
|
37
36
|
async handleHotUpdate(ctx) {
|
|
@@ -45,9 +44,9 @@ function pluginVirtualFiles() {
|
|
|
45
44
|
}
|
|
46
45
|
},
|
|
47
46
|
async load(id, options) {
|
|
48
|
-
if (!(0,
|
|
47
|
+
if (!(0, utils_js_1.isVirtualFileId)(id))
|
|
49
48
|
return undefined;
|
|
50
|
-
id = (0,
|
|
49
|
+
id = (0, utils_js_1.removeVirtualFileIdPrefix)(id);
|
|
51
50
|
const isDev = config._isDev;
|
|
52
51
|
(0, utils_js_1.assert)(typeof isDev === 'boolean');
|
|
53
52
|
if ((0, virtualFilePageConfigLazy_js_1.isVirtualFileIdPageConfigLazy)(id)) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.applyRegExpWithMagicString = applyRegExpWithMagicString;
|
|
4
|
+
// TODO/now: replace with .replaceAll() ?
|
|
4
5
|
function applyRegExpWithMagicString(magicString, regExp, replacement) {
|
|
5
6
|
const envStatementRegEx = typeof regExp === 'string' ? new RegExp(regExp, 'g') : regExp;
|
|
6
7
|
let match;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getMagicString = getMagicString;
|
|
7
|
+
const magic_string_1 = __importDefault(require("magic-string"));
|
|
8
|
+
// TODO/now use everywhere
|
|
9
|
+
function getMagicString(code, id) {
|
|
10
|
+
const magicString = new magic_string_1.default(code);
|
|
11
|
+
const getMagicStringResult = () => {
|
|
12
|
+
return {
|
|
13
|
+
code: magicString.toString(),
|
|
14
|
+
map: magicString.generateMap({ hires: true, source: id }),
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
return { magicString, getMagicStringResult };
|
|
18
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getManifestFilePathRelative = getManifestFilePathRelative;
|
|
4
|
+
const utils_js_1 = require("../utils.js");
|
|
5
|
+
function getManifestFilePathRelative(manifestConfig) {
|
|
6
|
+
(0, utils_js_1.assert)(['string', 'boolean'].includes(typeof manifestConfig));
|
|
7
|
+
(0, utils_js_1.assert)(manifestConfig !== false);
|
|
8
|
+
const manifestFileRelative = typeof manifestConfig === 'string' ? manifestConfig : '.vite/manifest.json';
|
|
9
|
+
return manifestFileRelative;
|
|
10
|
+
}
|
|
@@ -42,3 +42,4 @@ __exportStar(require("../../utils/isDocker.js"), exports);
|
|
|
42
42
|
__exportStar(require("../../utils/isVitest.js"), exports);
|
|
43
43
|
__exportStar(require("../../utils/rollupSourceMap.js"), exports);
|
|
44
44
|
__exportStar(require("../../utils/isImportPath.js"), exports);
|
|
45
|
+
__exportStar(require("../../utils/virtualFileId.js"), exports);
|
|
@@ -12,7 +12,7 @@ const getGlobalContextSyncErrMsg = "The global context isn't set yet, call getGl
|
|
|
12
12
|
exports.getGlobalContextSyncErrMsg = getGlobalContextSyncErrMsg;
|
|
13
13
|
async function createGlobalContextShared(virtualFileExports, globalObject, addGlobalContext,
|
|
14
14
|
// TO-DO/next-major-release: we'll be able to remove addGlobalContextTmp after loadPageRoutes() is sync (it will be sync after we remove the old design)
|
|
15
|
-
addGlobalContextTmp) {
|
|
15
|
+
addGlobalContextTmp, addGlobalContextAsync) {
|
|
16
16
|
const globalContext = createGlobalContextBase(virtualFileExports);
|
|
17
17
|
let isNewGlobalContext;
|
|
18
18
|
if (!globalObject.globalContext) {
|
|
@@ -34,6 +34,10 @@ addGlobalContextTmp) {
|
|
|
34
34
|
const globalContextAdded = await addGlobalContextTmp?.(globalContext);
|
|
35
35
|
(0, utils_js_1.objectAssign)(globalContext, globalContextAdded);
|
|
36
36
|
}
|
|
37
|
+
{
|
|
38
|
+
const globalContextAddedAsync = await addGlobalContextAsync?.(globalContext);
|
|
39
|
+
(0, utils_js_1.objectAssign)(globalContext, globalContextAddedAsync);
|
|
40
|
+
}
|
|
37
41
|
const onCreateGlobalContextHooks = (0, getHook_js_1.getHookFromPageConfigGlobalCumulative)(globalContext._pageConfigGlobal, 'onCreateGlobalContext');
|
|
38
42
|
let hooksCalled = false;
|
|
39
43
|
if (!hooksAreEqual(globalObject.onCreateGlobalContextHooks ?? [], onCreateGlobalContextHooks)) {
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseVirtualFileExports = parseVirtualFileExports;
|
|
4
|
+
// TODO/now: rename parseVirtualFileExportsEntryGlobal
|
|
5
|
+
// TODO/now: merge or collocate following both files?
|
|
6
|
+
// ```filesystem
|
|
7
|
+
// vike/packages/vike/shared/getPageFiles/parseVirtualFileExports.ts
|
|
8
|
+
// vike/shared/page-configs/serialize/parsePageConfigs.ts
|
|
9
|
+
// ```
|
|
4
10
|
// TO-DO/next-major-release: remove old design code, and remove all assertions.
|
|
5
11
|
const utils_js_1 = require("../utils.js");
|
|
6
12
|
const assert_exports_old_design_js_1 = require("./assert_exports_old_design.js");
|
|
@@ -43,8 +43,8 @@ function onInternalProp(propStr, objName) {
|
|
|
43
43
|
// - We must skip it in the client-side because of the reactivity mechanism of UI frameworks like Solid.
|
|
44
44
|
// - TO-DO/eventually: use import.meta.CLIENT instead of isBrowser()
|
|
45
45
|
// - Where import.meta.CLIENT is defined by Vike
|
|
46
|
-
// - Using
|
|
47
|
-
// - If Rolldown Vite + Rolldowns always transpiles node_modules/ then we can simply use
|
|
46
|
+
// - Using ({}).CLIENT (note `.env.`) doesn't seem possible: https://github.com/brillout/playground_node_({})
|
|
47
|
+
// - If Rolldown Vite + Rolldowns always transpiles node_modules/ then we can simply use ({}).SSR
|
|
48
48
|
if ((0, utils_js_1.isBrowser)())
|
|
49
49
|
return;
|
|
50
50
|
// TO-DO/soon/proxy: remove this and only warn on built-in access instead
|