vike 0.4.236-commit-64431e7 → 0.4.236-commit-08fbc10
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 +1 -1
- package/dist/cjs/node/runtime/globalContext.js +17 -79
- package/dist/cjs/node/runtime/html/injectAssets/getViteDevScript.js +1 -8
- package/dist/cjs/node/runtime/renderPage/getPageAssets/retrieveAssetsDev.js +4 -0
- package/dist/cjs/node/runtime/renderPage/getPageAssets.js +1 -3
- package/dist/cjs/node/runtime/utils.js +1 -1
- 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 +0 -2
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildApp.js +28 -13
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildConfig.js +1 -2
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginDistFileNames.js +12 -9
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginModuleBanner.js +2 -2
- package/dist/cjs/node/vite/plugins/pluginCommon.js +0 -1
- package/dist/cjs/node/vite/plugins/pluginDev/determineOptimizeDeps.js +100 -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/pluginReplaceConstants.js +1 -1
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles/getVirtualFilePageConfigLazy.js +1 -0
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles.js +4 -5
- package/dist/cjs/node/vite/shared/applyRegExWithMagicString.js +0 -1
- package/dist/cjs/node/vite/utils.js +1 -0
- package/dist/cjs/shared/createGlobalContextShared.js +1 -5
- 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 +0 -3
- package/dist/cjs/utils/debug.js +0 -1
- package/dist/cjs/utils/isFilePathAbsoluteFilesystem.js +1 -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/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/node/prerender/runPrerender.d.ts +132 -40
- package/dist/esm/node/runtime/globalContext.d.ts +52 -32
- package/dist/esm/node/runtime/globalContext.js +18 -80
- package/dist/esm/node/runtime/html/injectAssets/getViteDevScript.js +1 -8
- package/dist/esm/node/runtime/renderPage/createPageContextServerSide.d.ts +33 -10
- package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsDev.js +4 -0
- package/dist/esm/node/runtime/renderPage/getPageAssets.js +2 -4
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +66 -20
- package/dist/esm/node/runtime/renderPage.d.ts +33 -10
- package/dist/esm/node/runtime/utils.d.ts +1 -1
- package/dist/esm/node/runtime/utils.js +1 -1
- 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 +0 -2
- package/dist/esm/node/vite/plugins/pluginBuild/handleAssetsManifest.d.ts +1 -1
- package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildApp.js +28 -13
- package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildConfig.d.ts +1 -1
- package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildConfig.js +1 -2
- package/dist/esm/node/vite/plugins/pluginBuild/pluginDistFileNames.js +12 -9
- package/dist/esm/node/vite/plugins/pluginBuild/pluginModuleBanner.js +2 -2
- package/dist/esm/node/vite/plugins/pluginCommon.d.ts +0 -3
- package/dist/esm/node/vite/plugins/pluginCommon.js +0 -1
- package/dist/esm/node/vite/plugins/pluginDev/determineOptimizeDeps.js +101 -59
- package/dist/esm/node/vite/plugins/pluginExtractAssets.js +3 -4
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/getVirtualFilePageConfigLazy.js +1 -0
- package/dist/esm/node/vite/plugins/pluginVirtualFiles.js +3 -4
- package/dist/esm/node/vite/shared/applyRegExWithMagicString.js +0 -1
- 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 +1 -5
- 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 +0 -3
- package/dist/esm/utils/debug.d.ts +1 -1
- package/dist/esm/utils/debug.js +0 -1
- package/dist/esm/utils/isFilePathAbsoluteFilesystem.d.ts +7 -0
- package/dist/esm/utils/isFilePathAbsoluteFilesystem.js +1 -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 +3 -12
- package/dist/cjs/node/shared/virtualFiles.js +0 -41
- package/dist/cjs/node/vite/plugins/pluginViteRPC.js +0 -42
- package/dist/cjs/utils/getViteRPC.js +0 -79
- package/dist/esm/node/shared/virtualFiles.d.ts +0 -8
- package/dist/esm/node/vite/plugins/pluginViteRPC.d.ts +0 -25
- package/dist/esm/node/vite/plugins/pluginViteRPC.js +0 -40
- package/dist/esm/utils/getViteRPC.d.ts +0 -6
- package/dist/esm/utils/getViteRPC.js +0 -77
|
@@ -11,38 +11,78 @@ 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
|
-
entries.
|
|
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
|
+
// TO-DO/eventually: use a check that is agnostic to @cloudflare/vite-plugin
|
|
18
|
+
const isNotRunnable = config.environments?.ssr?.resolve.conditions.includes('workerd');
|
|
19
|
+
if (isNotRunnable) {
|
|
20
|
+
config.ssr.optimizeDeps.include = add(config.ssr.optimizeDeps.include, includeServer);
|
|
21
|
+
// @ts-ignore — Vite doesn't seem to support ssr.optimizeDeps.entries (vite@7.0.6, July 2025)
|
|
22
|
+
config.ssr.optimizeDeps.entries = add(config.ssr.optimizeDeps.entries, entriesServer);
|
|
22
23
|
}
|
|
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
24
|
if (debug.isActivated)
|
|
29
|
-
debug('
|
|
25
|
+
debug('optimizeDeps', {
|
|
30
26
|
'config.optimizeDeps.entries': config.optimizeDeps.entries,
|
|
31
27
|
'config.optimizeDeps.include': config.optimizeDeps.include,
|
|
28
|
+
'config.optimizeDeps.exclude': config.optimizeDeps.exclude,
|
|
29
|
+
/* Vite doesn't seem to support ssr.optimizeDeps.entries (vite@7.0.6, July 2025)
|
|
30
|
+
'config.ssr.optimizeDeps.entries': config.ssr.optimizeDeps.entries,
|
|
31
|
+
//*/
|
|
32
|
+
'config.ssr.optimizeDeps.include': config.ssr.optimizeDeps.include,
|
|
33
|
+
'config.ssr.optimizeDeps.exclude': config.ssr.optimizeDeps.exclude,
|
|
32
34
|
});
|
|
33
35
|
}
|
|
34
36
|
async function getPageDeps(config, pageConfigs) {
|
|
35
|
-
let
|
|
36
|
-
let
|
|
37
|
-
|
|
37
|
+
let entriesClient = [];
|
|
38
|
+
let entriesServer = [];
|
|
39
|
+
let includeClient = [];
|
|
40
|
+
let includeServer = [];
|
|
41
|
+
const addEntry = (e, configEnv, definedAt) => {
|
|
38
42
|
(0, utils_js_1.assert)(e);
|
|
39
|
-
entries
|
|
43
|
+
// optimizeDeps.entries expects filesystem absolute paths
|
|
44
|
+
(0, utils_js_1.assert)((0, utils_js_1.isVirtualFileId)(e) || (0, utils_js_1.isFilePathAbsoluteFilesystem)(e));
|
|
45
|
+
if (isRelevant(e, false, configEnv, definedAt)) {
|
|
46
|
+
entriesClient.push(e);
|
|
47
|
+
}
|
|
48
|
+
if (isRelevant(e, true, configEnv, definedAt)) {
|
|
49
|
+
entriesServer.push(e);
|
|
50
|
+
}
|
|
40
51
|
};
|
|
41
|
-
const addInclude = (e) => {
|
|
52
|
+
const addInclude = (e, configEnv, definedAt) => {
|
|
42
53
|
(0, utils_js_1.assert)(e);
|
|
43
|
-
//
|
|
54
|
+
// optimizeDeps.include expects npm packages
|
|
55
|
+
(0, utils_js_1.assert)(!e.startsWith('/'));
|
|
56
|
+
// Shouldn't be a path alias, as path aliases would need to be added to optimizeDeps.entries instead of optimizeDeps.include
|
|
44
57
|
(0, utils_js_1.assertIsImportPathNpmPackage)(e);
|
|
45
|
-
|
|
58
|
+
if (isRelevant(e, false, configEnv, definedAt)) {
|
|
59
|
+
includeClient.push(e);
|
|
60
|
+
}
|
|
61
|
+
if (isRelevant(e, true, configEnv, definedAt)) {
|
|
62
|
+
includeServer.push(e);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const isRelevant = (e, server, configEnv, definedAt) => {
|
|
66
|
+
if (server) {
|
|
67
|
+
if (!configEnv || !configEnv.server)
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
if (configEnv && !configEnv.client)
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
return !isExcluded(e, server, definedAt);
|
|
75
|
+
};
|
|
76
|
+
const isExcluded = (e, server, definedAt) => {
|
|
77
|
+
const exclude = server ? config.ssr.optimizeDeps.exclude : config.optimizeDeps.exclude;
|
|
78
|
+
if (!exclude)
|
|
79
|
+
return false;
|
|
80
|
+
if (definedAt?.importPathAbsolute) {
|
|
81
|
+
const npmPackageName = (0, utils_js_1.getNpmPackageName)(definedAt.importPathAbsolute);
|
|
82
|
+
if (npmPackageName && exclude.includes(npmPackageName))
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
return exclude.includes(e);
|
|
46
86
|
};
|
|
47
87
|
// V1 design
|
|
48
88
|
{
|
|
@@ -54,22 +94,17 @@ async function getPageDeps(config, pageConfigs) {
|
|
|
54
94
|
if (!configValueSource.valueIsLoadedWithImport && !configValueSource.valueIsFilePath)
|
|
55
95
|
return;
|
|
56
96
|
const { definedAt, configEnv } = configValueSource;
|
|
57
|
-
if (!configEnv.client)
|
|
58
|
-
return;
|
|
59
97
|
if (definedAt.definedBy)
|
|
60
98
|
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
99
|
if (definedAt.filePathAbsoluteUserRootDir !== null) {
|
|
67
|
-
|
|
68
|
-
|
|
100
|
+
addEntry(
|
|
101
|
+
// optimizeDeps.entries expects filesystem absolute paths
|
|
102
|
+
definedAt.filePathAbsoluteFilesystem, configEnv, definedAt);
|
|
69
103
|
}
|
|
70
104
|
else {
|
|
71
|
-
|
|
72
|
-
|
|
105
|
+
addInclude(
|
|
106
|
+
// optimizeDeps.include expects npm packages
|
|
107
|
+
definedAt.importPathAbsolute, configEnv, definedAt);
|
|
73
108
|
}
|
|
74
109
|
});
|
|
75
110
|
});
|
|
@@ -85,32 +120,39 @@ async function getPageDeps(config, pageConfigs) {
|
|
|
85
120
|
addEntry(filePathAbsoluteFilesystem);
|
|
86
121
|
});
|
|
87
122
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
123
|
+
// Add virtual files.
|
|
124
|
+
// - This doesn't work: Vite's dep optimizer doesn't seem to be able to crawl virtual files.
|
|
125
|
+
// - Should we make it work? E.g. by creating a temporary file at node_modules/.vike/virtualFiles.js
|
|
126
|
+
// - Or should we remove it? And make sure getPageDeps() also works for aliased import paths
|
|
127
|
+
// - If we do, then we need to adjust include/entries (maybe by making include === entries -> will Vite complain?)
|
|
128
|
+
{
|
|
129
|
+
const { hasClientRouting, hasServerRouting, clientEntries } = (0, pluginBuildConfig_js_1.analyzeClientEntries)(pageConfigs, config);
|
|
130
|
+
Object.values(clientEntries).forEach((e) => addEntry(e));
|
|
131
|
+
if (hasClientRouting)
|
|
132
|
+
addEntry(virtualFileEntry_js_1.virtualFileIdEntryClientCR);
|
|
133
|
+
if (hasServerRouting)
|
|
134
|
+
addEntry(virtualFileEntry_js_1.virtualFileIdEntryClientSR);
|
|
135
|
+
}
|
|
136
|
+
entriesClient = entriesClient;
|
|
137
|
+
entriesServer = entriesServer;
|
|
138
|
+
includeClient = includeClient;
|
|
139
|
+
includeServer = includeServer;
|
|
140
|
+
return {
|
|
141
|
+
entriesClient,
|
|
142
|
+
entriesServer,
|
|
143
|
+
includeClient,
|
|
144
|
+
includeServer,
|
|
145
|
+
};
|
|
100
146
|
}
|
|
101
|
-
function
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
(0, utils_js_1.assert)(false);
|
|
147
|
+
function add(input, listAddendum) {
|
|
148
|
+
const list = !input ? [] : (0, utils_js_1.isArray)(input) ? unique(input) : [input];
|
|
149
|
+
listAddendum.forEach((e) => {
|
|
150
|
+
if (!list.includes(e))
|
|
151
|
+
list.push(e);
|
|
152
|
+
});
|
|
153
|
+
return list;
|
|
109
154
|
}
|
|
110
|
-
function
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
if (include === undefined)
|
|
114
|
-
return [];
|
|
115
|
-
(0, utils_js_1.assert)(false);
|
|
155
|
+
function unique(arr) {
|
|
156
|
+
const arrUnique = Array.from(new Set(arr));
|
|
157
|
+
return arr.length !== arrUnique.length ? arrUnique : arr;
|
|
116
158
|
}
|
|
@@ -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 import.meta.env 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('import.meta.env.'))
|
|
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 = `import.meta.env.${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 (import.meta.hot) import.meta.hot.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){import.meta.hot.accept(()=>{})};';
|
|
90
90
|
}
|
|
91
91
|
return code;
|
|
92
92
|
}
|
|
@@ -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('import.meta.env.'))
|
|
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");
|
|
@@ -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,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.applyRegExpWithMagicString = applyRegExpWithMagicString;
|
|
4
|
-
// TODO/now: replace with .replaceAll() ?
|
|
5
4
|
function applyRegExpWithMagicString(magicString, regExp, replacement) {
|
|
6
5
|
const envStatementRegEx = typeof regExp === 'string' ? new RegExp(regExp, 'g') : regExp;
|
|
7
6
|
let match;
|
|
@@ -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) {
|
|
16
16
|
const globalContext = createGlobalContextBase(virtualFileExports);
|
|
17
17
|
let isNewGlobalContext;
|
|
18
18
|
if (!globalObject.globalContext) {
|
|
@@ -34,10 +34,6 @@ addGlobalContextTmp, addGlobalContextAsync) {
|
|
|
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
|
-
}
|
|
41
37
|
const onCreateGlobalContextHooks = (0, getHook_js_1.getHookFromPageConfigGlobalCumulative)(globalContext._pageConfigGlobal, 'onCreateGlobalContext');
|
|
42
38
|
let hooksCalled = false;
|
|
43
39
|
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 import.meta.env.CLIENT (note `.env.`) doesn't seem possible: https://github.com/brillout/playground_node_import.meta.env
|
|
47
|
+
// - If Rolldown Vite + Rolldowns always transpiles node_modules/ then we can simply use import.meta.env.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
|
package/dist/cjs/utils/debug.js
CHANGED
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.assertFilePathAbsoluteFilesystem = assertFilePathAbsoluteFilesystem;
|
|
7
|
+
exports.isFilePathAbsoluteFilesystem = isFilePathAbsoluteFilesystem;
|
|
7
8
|
exports.isFilePathAbsolute = isFilePathAbsolute;
|
|
8
9
|
const node_path_1 = __importDefault(require("node:path"));
|
|
9
10
|
const assert_js_1 = require("./assert.js");
|
|
@@ -0,0 +1,39 @@
|
|
|
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.isVirtualFileId = isVirtualFileId;
|
|
7
|
+
exports.addVirtualFileIdPrefix = addVirtualFileIdPrefix;
|
|
8
|
+
exports.removeVirtualFileIdPrefix = removeVirtualFileIdPrefix;
|
|
9
|
+
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
10
|
+
const assert_js_1 = require("./assert.js");
|
|
11
|
+
const assertIsNotBrowser_js_1 = require("./assertIsNotBrowser.js");
|
|
12
|
+
(0, assertIsNotBrowser_js_1.assertIsNotBrowser)();
|
|
13
|
+
const idBase = 'virtual:vike:';
|
|
14
|
+
// https://vitejs.dev/guide/api-plugin.html#virtual-modules-convention
|
|
15
|
+
const prefix = '\0';
|
|
16
|
+
function isVirtualFileId(id) {
|
|
17
|
+
if (id.startsWith(idBase))
|
|
18
|
+
return true;
|
|
19
|
+
if (id.startsWith(prefix + idBase))
|
|
20
|
+
return true;
|
|
21
|
+
// https://github.com/vikejs/vike/issues/1985
|
|
22
|
+
(0, assert_js_1.assertUsage)(!id.includes(idBase), `Encountered a module ID ${picocolors_1.default.cyan(id)} that is unexpected. Are you using a tool that modifies the ID of modules? For example, the baseUrl setting in tsconfig.json cannot be used.`);
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
function addVirtualFileIdPrefix(id) {
|
|
26
|
+
(0, assert_js_1.assert)(isVirtualFileId(id));
|
|
27
|
+
if (!id.startsWith(prefix)) {
|
|
28
|
+
id = prefix + id;
|
|
29
|
+
}
|
|
30
|
+
(0, assert_js_1.assert)(id.startsWith(prefix));
|
|
31
|
+
return id;
|
|
32
|
+
}
|
|
33
|
+
function removeVirtualFileIdPrefix(id) {
|
|
34
|
+
if (id.startsWith(prefix)) {
|
|
35
|
+
id = id.slice(prefix.length);
|
|
36
|
+
}
|
|
37
|
+
(0, assert_js_1.assert)(!id.startsWith(prefix));
|
|
38
|
+
return id;
|
|
39
|
+
}
|
|
@@ -30,7 +30,7 @@ declare function createPageContextClientSide(urlOriginal: string): Promise<{
|
|
|
30
30
|
} & {
|
|
31
31
|
_pageRoutes: import("../../__internal/index.js").PageRoutes;
|
|
32
32
|
_onBeforeRouteHook: import("../../shared/hooks/getHook.js").Hook | null;
|
|
33
|
-
}
|
|
33
|
+
};
|
|
34
34
|
_pageFilesAll: import("../../shared/getPageFiles.js").PageFile[];
|
|
35
35
|
_urlHandler: null;
|
|
36
36
|
_urlRewrite: null | string;
|
|
@@ -50,7 +50,7 @@ declare function getPageContextFromHooks_isHydration(pageContext: PageContextSer
|
|
|
50
50
|
} & {
|
|
51
51
|
_pageRoutes: import("../../__internal/index.js").PageRoutes;
|
|
52
52
|
_onBeforeRouteHook: import("../../shared/hooks/getHook.js").Hook | null;
|
|
53
|
-
}
|
|
53
|
+
};
|
|
54
54
|
_pageFilesAll: PageFile[];
|
|
55
55
|
_urlHandler: null;
|
|
56
56
|
_urlRewrite: null | string;
|
|
@@ -264,7 +264,7 @@ declare function getPageContextFromClientHooks(pageContext: {
|
|
|
264
264
|
} & {
|
|
265
265
|
_pageRoutes: import("../../__internal/index.js").PageRoutes;
|
|
266
266
|
_onBeforeRouteHook: import("../../shared/hooks/getHook.js").Hook | null;
|
|
267
|
-
}
|
|
267
|
+
};
|
|
268
268
|
_pageFilesAll: PageFile[];
|
|
269
269
|
_urlHandler: null;
|
|
270
270
|
_urlRewrite: null | string;
|
|
@@ -63,7 +63,7 @@ declare function getPageContextBegin(isForErrorPage: boolean, { urlOriginal, isB
|
|
|
63
63
|
} & {
|
|
64
64
|
_pageRoutes: import("../../shared/route/loadPageRoutes.js").PageRoutes;
|
|
65
65
|
_onBeforeRouteHook: import("../../shared/hooks/getHook.js").Hook | null;
|
|
66
|
-
}
|
|
66
|
+
};
|
|
67
67
|
_pageFilesAll: import("../../shared/getPageFiles.js").PageFile[];
|
|
68
68
|
_urlHandler: null;
|
|
69
69
|
_urlRewrite: null | string;
|
|
@@ -84,7 +84,7 @@ async function renderPageClientSide(renderArgs) {
|
|
|
84
84
|
return;
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
|
-
//
|
|
87
|
+
// Get pageContext serialized in <script id="vike_pageContext" type="application/json">
|
|
88
88
|
if (isFirstRender) {
|
|
89
89
|
const pageContextSerialized = getPageContextFromHooks_serialized();
|
|
90
90
|
// TO-DO/eventually: create helper assertPageContextFromHook()
|
|
@@ -93,7 +93,9 @@ async function renderPageClientSide(renderArgs) {
|
|
|
93
93
|
// TO-DO/pageContext-prefetch: remove or change, because this only makes sense for a pre-rendered page
|
|
94
94
|
populatePageContextPrefetchCache(pageContext, { pageContextFromServerHooks: pageContextSerialized });
|
|
95
95
|
}
|
|
96
|
-
|
|
96
|
+
// Route
|
|
97
|
+
// - We must also run it upon hydration to call the onBeforeRoute() hook, which is needed for i18n URL locale extraction.
|
|
98
|
+
{
|
|
97
99
|
let pageContextFromRoute;
|
|
98
100
|
try {
|
|
99
101
|
pageContextFromRoute = await route(pageContext);
|
|
@@ -104,38 +106,49 @@ async function renderPageClientSide(renderArgs) {
|
|
|
104
106
|
}
|
|
105
107
|
if (isRenderOutdated())
|
|
106
108
|
return;
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
//
|
|
111
|
-
//
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
await renderErrorPage({ is404: true })
|
|
116
|
-
*/
|
|
117
|
-
redirectHard(urlOriginal);
|
|
118
|
-
return;
|
|
109
|
+
// TO-DO/eventually: create helper assertPageContextFromHook()
|
|
110
|
+
assert(!('urlOriginal' in pageContextFromRoute));
|
|
111
|
+
if (isFirstRender) {
|
|
112
|
+
// Set pageContext properties set by onBeforeRoute()
|
|
113
|
+
// - But we skip pageId and routeParams because routing may have been aborted by a server-side `throw render()`
|
|
114
|
+
const { pageId, routeParams, ...pageContextFromRouteRest } = pageContextFromRoute;
|
|
115
|
+
objectAssign(pageContext, pageContextFromRouteRest);
|
|
116
|
+
assert(hasProp(pageContext, 'routeParams', 'string{}')); // Help TS
|
|
119
117
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if (isRenderOutdated())
|
|
123
|
-
return;
|
|
124
|
-
if (!isClientRoutable) {
|
|
125
|
-
redirectHard(urlOriginal);
|
|
126
|
-
return;
|
|
118
|
+
else {
|
|
119
|
+
objectAssign(pageContext, pageContextFromRoute);
|
|
127
120
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
121
|
+
if (!isFirstRender) {
|
|
122
|
+
if (!pageContextFromRoute.pageId) {
|
|
123
|
+
/*
|
|
124
|
+
// We don't use the client router to render the 404 page:
|
|
125
|
+
// - So that the +redirects setting (https://vike.dev/redirects) can be applied.
|
|
126
|
+
// - This is the main argument.
|
|
127
|
+
// - See also failed CI: https://github.com/vikejs/vike/pull/1871
|
|
128
|
+
// - So that server-side error tracking can track 404 links?
|
|
129
|
+
// - We do use the client router for rendering the error page, so I don't think this is much of an argument.
|
|
130
|
+
await renderErrorPage({ is404: true })
|
|
131
|
+
*/
|
|
132
|
+
redirectHard(urlOriginal);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
const isClientRoutable = await isClientSideRoutable(pageContextFromRoute.pageId, pageContext);
|
|
136
|
+
if (isRenderOutdated())
|
|
137
|
+
return;
|
|
138
|
+
if (!isClientRoutable) {
|
|
139
|
+
redirectHard(urlOriginal);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
const isSamePage = pageContextFromRoute.pageId &&
|
|
143
|
+
previousPageContext?.pageId &&
|
|
144
|
+
pageContextFromRoute.pageId === previousPageContext.pageId;
|
|
145
|
+
if (doNotRenderIfSamePage && isSamePage) {
|
|
146
|
+
// Skip's Vike's rendering; let the user handle the navigation
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
134
149
|
}
|
|
135
|
-
// TO-DO/eventually: create helper assertPageContextFromHook()
|
|
136
|
-
assert(!('urlOriginal' in pageContextFromRoute));
|
|
137
|
-
objectAssign(pageContext, pageContextFromRoute);
|
|
138
150
|
}
|
|
151
|
+
assert(hasProp(pageContext, 'pageId', 'string')); // Help TS
|
|
139
152
|
const res = await loadPageConfigsLazyClientSideAndExecHook(pageContext, isFirstRender, isRenderOutdated);
|
|
140
153
|
/* Already called inside loadPageConfigsLazyClientSideAndExecHook()
|
|
141
154
|
if (isRenderOutdated()) return
|
|
@@ -26,7 +26,7 @@ declare function createPageContextClientSide(): Promise<{
|
|
|
26
26
|
};
|
|
27
27
|
} & {
|
|
28
28
|
isClientSide: true;
|
|
29
|
-
} & object
|
|
29
|
+
} & object;
|
|
30
30
|
_pageFilesAll: import("../../shared/getPageFiles.js").PageFile[];
|
|
31
31
|
isBackwardNavigation: null;
|
|
32
32
|
_hasPageContextFromServer: true;
|
|
@@ -30,7 +30,7 @@ declare function createGetGlobalContextClient<GlobalContextAddendum extends obje
|
|
|
30
30
|
* We recommend using `import.meta.env.SSR` instead, see https://vike.dev/globalContext
|
|
31
31
|
*/
|
|
32
32
|
isClientSide: true;
|
|
33
|
-
} & Awaited<GlobalContextAddendum
|
|
33
|
+
} & Awaited<GlobalContextAddendum>>;
|
|
34
34
|
type NeverExported = never;
|
|
35
35
|
declare function getGlobalContext(): Promise<NeverExported>;
|
|
36
36
|
declare function getGlobalContextSync(): NeverExported;
|