vike 0.4.239-commit-050a4a3 → 0.4.239-commit-33e55d4
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/node/prerender/runPrerender.js +1 -0
- package/dist/cjs/node/runtime/globalContext.js +9 -0
- package/dist/cjs/node/vite/onLoad.js +1 -1
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginModuleBanner.js +13 -7
- package/dist/cjs/node/vite/plugins/pluginEnvVars.js +4 -5
- package/dist/cjs/node/vite/plugins/pluginExtractAssets.js +9 -5
- package/dist/cjs/node/vite/plugins/pluginExtractExportNames.js +11 -5
- package/dist/cjs/node/vite/plugins/pluginFileEnv.js +43 -30
- package/dist/cjs/node/vite/plugins/pluginNonRunnableDev.js +19 -7
- package/dist/cjs/node/vite/plugins/pluginReplaceConstants.js +23 -5
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles.js +12 -7
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/virtualFileId.js +15 -11
- 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-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 +4 -2
- package/dist/esm/node/prerender/runPrerender.js +2 -1
- package/dist/esm/node/runtime/globalContext.d.ts +13 -2
- package/dist/esm/node/runtime/globalContext.js +10 -1
- package/dist/esm/node/runtime/renderPage/createPageContextServerSide.d.ts +4 -2
- package/dist/esm/node/runtime/renderPage/loadPageConfigsLazyServerSide.d.ts +4 -2
- package/dist/esm/node/runtime/renderPage/renderPageAfterRoute.d.ts +8 -4
- package/dist/esm/node/runtime/renderPage.d.ts +4 -2
- package/dist/esm/node/vite/onLoad.js +1 -1
- package/dist/esm/node/vite/plugins/pluginBuild/pluginModuleBanner.js +14 -8
- package/dist/esm/node/vite/plugins/pluginEnvVars.js +4 -5
- package/dist/esm/node/vite/plugins/pluginExtractAssets.js +9 -3
- package/dist/esm/node/vite/plugins/pluginExtractExportNames.js +11 -5
- package/dist/esm/node/vite/plugins/pluginFileEnv.js +43 -30
- package/dist/esm/node/vite/plugins/pluginNonRunnableDev.js +20 -8
- package/dist/esm/node/vite/plugins/pluginReplaceConstants.d.ts +11 -0
- package/dist/esm/node/vite/plugins/pluginReplaceConstants.js +22 -5
- package/dist/esm/node/vite/plugins/pluginVirtualFiles.js +13 -8
- package/dist/esm/shared/createGlobalContextShared.d.ts +3 -3
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/virtualFileId.d.ts +4 -0
- package/dist/esm/utils/virtualFileId.js +14 -11
- package/package.json +4 -4
|
@@ -146,6 +146,7 @@ async function runPrerender(options = {}, trigger) {
|
|
|
146
146
|
await warnMissingPages(prerenderContext._prerenderedPageContexts, globalContext, doNotPrerenderList, partial);
|
|
147
147
|
const prerenderContextPublic = preparePrerenderContextForPublicUsage(prerenderContext);
|
|
148
148
|
(0, utils_js_1.objectAssign)(vikeConfig.prerenderContext, prerenderContextPublic, true);
|
|
149
|
+
(0, globalContext_js_1.setGlobalContext_prerenderContext)(prerenderContextPublic);
|
|
149
150
|
if (prerenderConfigGlobal.isPrerenderingEnabledForAllPages && !prerenderConfigGlobal.keepDistServer) {
|
|
150
151
|
node_fs_1.default.rmSync(outDirServer, { recursive: true });
|
|
151
152
|
}
|
|
@@ -16,6 +16,7 @@ exports.initGlobalContext_getPagesAndRoutes = initGlobalContext_getPagesAndRoute
|
|
|
16
16
|
exports.setGlobalContext_viteDevServer = setGlobalContext_viteDevServer;
|
|
17
17
|
exports.setGlobalContext_viteConfig = setGlobalContext_viteConfig;
|
|
18
18
|
exports.setGlobalContext_isPrerendering = setGlobalContext_isPrerendering;
|
|
19
|
+
exports.setGlobalContext_prerenderContext = setGlobalContext_prerenderContext;
|
|
19
20
|
exports.setGlobalContext_isProductionAccordingToVite = setGlobalContext_isProductionAccordingToVite;
|
|
20
21
|
exports.setGlobalContext_prodBuildEntry = setGlobalContext_prodBuildEntry;
|
|
21
22
|
exports.clearGlobalContext = clearGlobalContext;
|
|
@@ -154,6 +155,13 @@ function assertIsNotInitializedYet() {
|
|
|
154
155
|
function setGlobalContext_isPrerendering() {
|
|
155
156
|
globalObject.isPrerendering = true;
|
|
156
157
|
}
|
|
158
|
+
function setGlobalContext_prerenderContext(prerenderContextPublic) {
|
|
159
|
+
globalObject.prerenderContextPublic = prerenderContextPublic;
|
|
160
|
+
// Ugly redundancy, which we can remove after globalContext is a proxy
|
|
161
|
+
const { globalContext } = globalObjectTyped;
|
|
162
|
+
if (globalContext)
|
|
163
|
+
globalContext.prerenderContext = prerenderContextPublic;
|
|
164
|
+
}
|
|
157
165
|
function setGlobalContext_isProductionAccordingToVite(isProductionAccordingToVite) {
|
|
158
166
|
globalObject.isProductionAccordingToVite = isProductionAccordingToVite;
|
|
159
167
|
}
|
|
@@ -405,6 +413,7 @@ async function createGlobalContext(virtualFileExportsGlobalEntry) {
|
|
|
405
413
|
globalContext._pageConfigs.length > 0, globalContext._pageFilesAll);
|
|
406
414
|
assertGlobalContextIsDefined();
|
|
407
415
|
(0, utils_js_1.onSetupRuntime)();
|
|
416
|
+
(0, utils_js_1.objectAssign)(globalContext, { prerenderContext: globalObject.prerenderContextPublic });
|
|
408
417
|
// Never actually used, only used for TypeScript `ReturnType<typeof createGlobalContext>`
|
|
409
418
|
return globalContext;
|
|
410
419
|
}
|
|
@@ -15,7 +15,7 @@ function onLoad() {
|
|
|
15
15
|
// TO-DO/eventually: let's also use this.meta.viteVersion
|
|
16
16
|
// - https://github.com/vitejs/vite/pull/20088
|
|
17
17
|
// - https://github.com/vitejs/vite/blob/main/packages/vite/CHANGELOG.md#700-2025-06-24
|
|
18
|
-
(0, assertVersion_js_1.assertVersion)('Vite', vite_1.version, ['6.
|
|
18
|
+
(0, assertVersion_js_1.assertVersion)('Vite', vite_1.version, ['6.3.0']);
|
|
19
19
|
// Ensure we don't bloat the server runtime with heavy dependencies such Vite and esbuild
|
|
20
20
|
(0, assertSetup_js_1.assertIsNotProductionRuntime)();
|
|
21
21
|
}
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.pluginModuleBanner = pluginModuleBanner;
|
|
4
4
|
const utils_js_1 = require("../../utils.js");
|
|
5
5
|
const getMagicString_js_1 = require("../../shared/getMagicString.js");
|
|
6
|
-
const isViteServerSide_js_1 = require("../../shared/isViteServerSide.js");
|
|
7
6
|
// Rollup's banner feature doesn't work with Vite: https://github.com/vitejs/vite/issues/8412
|
|
8
7
|
// 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).
|
|
9
8
|
function pluginModuleBanner() {
|
|
@@ -12,6 +11,13 @@ function pluginModuleBanner() {
|
|
|
12
11
|
name: 'vike:build:pluginModuleBanner',
|
|
13
12
|
enforce: 'post',
|
|
14
13
|
apply: 'build',
|
|
14
|
+
applyToEnvironment(environment) {
|
|
15
|
+
const { config } = environment;
|
|
16
|
+
const { consumer } = config;
|
|
17
|
+
const { minify } = config.build;
|
|
18
|
+
(0, utils_js_1.assert)(minify === false || minify, { minify, consumer });
|
|
19
|
+
return !minify;
|
|
20
|
+
},
|
|
15
21
|
configResolved: {
|
|
16
22
|
handler(config_) {
|
|
17
23
|
config = config_;
|
|
@@ -19,12 +25,12 @@ function pluginModuleBanner() {
|
|
|
19
25
|
},
|
|
20
26
|
transform: {
|
|
21
27
|
order: 'post',
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
+
/* Using a Rolldown hook filter doesn't make sense here — we use applyToEnvironment() to conditionally apply this plugin.
|
|
29
|
+
filter: {},
|
|
30
|
+
*/
|
|
31
|
+
handler(code, id) {
|
|
32
|
+
const { minify } = this.environment.config.build;
|
|
33
|
+
(0, utils_js_1.assert)(minify === false, { minify });
|
|
28
34
|
if (id.startsWith('\0'))
|
|
29
35
|
id = id;
|
|
30
36
|
id = (0, utils_js_1.removeVirtualFileIdPrefix)(id);
|
|
@@ -7,6 +7,7 @@ const getFilePath_js_1 = require("../shared/getFilePath.js");
|
|
|
7
7
|
const normalizeId_js_1 = require("../shared/normalizeId.js");
|
|
8
8
|
const isViteServerSide_js_1 = require("../shared/isViteServerSide.js");
|
|
9
9
|
const getMagicString_js_1 = require("../shared/getMagicString.js");
|
|
10
|
+
const pluginReplaceConstants_js_1 = require("./pluginReplaceConstants.js");
|
|
10
11
|
// TO-DO/eventually:
|
|
11
12
|
// - Make ({}) work inside +config.js
|
|
12
13
|
// - 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
|
|
@@ -30,16 +31,14 @@ function pluginEnvVars() {
|
|
|
30
31
|
},
|
|
31
32
|
},
|
|
32
33
|
transform: {
|
|
34
|
+
filter: pluginReplaceConstants_js_1.filterRolldown,
|
|
33
35
|
handler(code, id, options) {
|
|
34
36
|
id = (0, normalizeId_js_1.normalizeId)(id);
|
|
35
37
|
(0, utils_js_1.assertPosixPath)(id);
|
|
36
|
-
if (id.includes('/node_modules/'))
|
|
37
|
-
return;
|
|
38
38
|
(0, utils_js_1.assertPosixPath)(config.root);
|
|
39
39
|
if (!id.startsWith(config.root))
|
|
40
|
-
return;
|
|
41
|
-
|
|
42
|
-
return;
|
|
40
|
+
return; // skip linked dependencies
|
|
41
|
+
(0, utils_js_1.assert)((0, pluginReplaceConstants_js_1.filterFunction)(id, code));
|
|
43
42
|
const isBuild = config.command === 'build';
|
|
44
43
|
const isClientSide = !(0, isViteServerSide_js_1.isViteServerSide_extraSafe)(config, this.environment, options);
|
|
45
44
|
const { magicString, getMagicStringResult } = (0, getMagicString_js_1.getMagicString)(code, id);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
//
|
|
3
|
-
// - Remove this file then revert this commit: https://github.com/vikejs/vike/commit/805a18974f13420a78fcc30fdd676696e405c3ca
|
|
2
|
+
// TO-DO/next-major-release: remove
|
|
4
3
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
5
|
};
|
|
@@ -24,6 +23,12 @@ const rawRE = /(\?|&)raw(?:&|$)/;
|
|
|
24
23
|
const urlRE = /(\?|&)url(?:&|$)/;
|
|
25
24
|
const EMPTY_MODULE_ID = 'virtual:vike:empty-module';
|
|
26
25
|
const debug = (0, utils_js_1.createDebugger)('vike:pluginExtractAssets');
|
|
26
|
+
const filterRolldown = {
|
|
27
|
+
id: {
|
|
28
|
+
include: extractAssetsRE,
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
const filterFunction = (id) => extractAssetsRE.test(id);
|
|
27
32
|
function pluginExtractAssets() {
|
|
28
33
|
let config;
|
|
29
34
|
let vikeConfig;
|
|
@@ -36,11 +41,10 @@ function pluginExtractAssets() {
|
|
|
36
41
|
apply: 'build',
|
|
37
42
|
enforce: 'post',
|
|
38
43
|
transform: {
|
|
44
|
+
filter: filterRolldown,
|
|
39
45
|
async handler(src, id, options) {
|
|
40
46
|
id = (0, normalizeId_js_1.normalizeId)(id);
|
|
41
|
-
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
47
|
+
(0, utils_js_1.assert)(filterFunction(id));
|
|
44
48
|
if (isFixEnabled) {
|
|
45
49
|
// I'm guessing isFixEnabled can only be true when mixing both designs: https://github.com/vikejs/vike/issues/1480
|
|
46
50
|
(0, assertV1Design_js_1.assertV1Design)(vikeConfig._pageConfigs, true);
|
|
@@ -11,6 +11,12 @@ const extractExportNamesRE = /(\?|&)extractExportNames(?:&|$)/;
|
|
|
11
11
|
exports.extractExportNamesRE = extractExportNamesRE;
|
|
12
12
|
const debug = (0, utils_js_1.createDebugger)('vike:pluginExtractExportNames');
|
|
13
13
|
const globalObject = (0, utils_js_1.getGlobalObject)('plugins/pluginExtractExportNames.ts', {});
|
|
14
|
+
const filterRolldown = {
|
|
15
|
+
id: {
|
|
16
|
+
include: extractExportNamesRE,
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
const filterFunction = (id) => extractExportNamesRE.test(id);
|
|
14
20
|
function pluginExtractExportNames() {
|
|
15
21
|
let isDev = false;
|
|
16
22
|
let config;
|
|
@@ -18,14 +24,14 @@ function pluginExtractExportNames() {
|
|
|
18
24
|
name: 'vike:pluginExtractExportNames',
|
|
19
25
|
enforce: 'post',
|
|
20
26
|
transform: {
|
|
27
|
+
filter: filterRolldown,
|
|
21
28
|
async handler(src, id, options) {
|
|
22
29
|
id = (0, normalizeId_js_1.normalizeId)(id);
|
|
23
30
|
const isClientSide = !(0, isViteServerSide_js_1.isViteServerSide_extraSafe)(config, this.environment, options);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
31
|
+
(0, utils_js_1.assert)(filterFunction(id));
|
|
32
|
+
const code = await getExtractExportNamesCode(src, isClientSide, !isDev, id);
|
|
33
|
+
debug('id ' + id, ['result:\n' + code.code.trim(), 'src:\n' + src.trim()]);
|
|
34
|
+
return code;
|
|
29
35
|
},
|
|
30
36
|
},
|
|
31
37
|
configureServer: {
|
|
@@ -13,19 +13,34 @@ const parseEsModule_js_1 = require("../shared/parseEsModule.js");
|
|
|
13
13
|
const normalizeId_js_1 = require("../shared/normalizeId.js");
|
|
14
14
|
const resolveVikeConfigInternal_js_1 = require("../shared/resolveVikeConfigInternal.js");
|
|
15
15
|
const isViteServerSide_js_1 = require("../shared/isViteServerSide.js");
|
|
16
|
+
const skipNodeModules = '/node_modules/'; // Only apply `.server.js` and `.client.js` to user files
|
|
17
|
+
const filterRolldown = {
|
|
18
|
+
id: {
|
|
19
|
+
include: ['client', 'server'].map((env) => `**/*${getSuffix(env)}*`),
|
|
20
|
+
exclude: [`**${skipNodeModules}**`],
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
const filterFunction = (id) => {
|
|
24
|
+
if (id.includes(skipNodeModules))
|
|
25
|
+
return false;
|
|
26
|
+
if (!id.includes(getSuffix('client')) && !id.includes(getSuffix('server')))
|
|
27
|
+
return false;
|
|
28
|
+
return true;
|
|
29
|
+
};
|
|
16
30
|
function pluginFileEnv() {
|
|
17
31
|
let config;
|
|
18
32
|
let viteDevServer;
|
|
19
33
|
return {
|
|
20
34
|
name: 'vike:pluginFileEnv',
|
|
21
35
|
load: {
|
|
36
|
+
filter: filterRolldown,
|
|
22
37
|
handler(id, options) {
|
|
23
38
|
// In build, we use generateBundle() instead of the load() hook. Using load() works for dynamic imports in dev thanks to Vite's lazy transpiling, but it doesn't work in build because Rollup transpiles any dynamically imported module even if it's never actually imported.
|
|
24
39
|
if (!viteDevServer)
|
|
25
40
|
return;
|
|
26
41
|
if (!(0, resolveVikeConfigInternal_js_1.isV1Design)())
|
|
27
42
|
return;
|
|
28
|
-
if (skip(id))
|
|
43
|
+
if (skip(id, config.root))
|
|
29
44
|
return;
|
|
30
45
|
// For `.vue` files: https://github.com/vikejs/vike/issues/1912#issuecomment-2394981475
|
|
31
46
|
if (id.endsWith('?direct'))
|
|
@@ -42,12 +57,13 @@ function pluginFileEnv() {
|
|
|
42
57
|
},
|
|
43
58
|
// In production, we have to use transform() to replace modules with a runtime error because generateBundle() doesn't work for dynamic imports. In production, dynamic imports can only be verified at runtime.
|
|
44
59
|
transform: {
|
|
60
|
+
filter: filterRolldown,
|
|
45
61
|
async handler(code, id, options) {
|
|
46
62
|
id = (0, normalizeId_js_1.normalizeId)(id);
|
|
47
63
|
// In dev, only using load() is enough as it also works for dynamic imports (see sibling comment).
|
|
48
64
|
if (viteDevServer)
|
|
49
65
|
return;
|
|
50
|
-
if (skip(id))
|
|
66
|
+
if (skip(id, config.root))
|
|
51
67
|
return;
|
|
52
68
|
const isServerSide = (0, isViteServerSide_js_1.isViteServerSide_extraSafe)(config, this.environment, options);
|
|
53
69
|
if (!isWrongEnv(id, isServerSide))
|
|
@@ -66,7 +82,8 @@ function pluginFileEnv() {
|
|
|
66
82
|
generateBundle: {
|
|
67
83
|
handler() {
|
|
68
84
|
Array.from(this.getModuleIds())
|
|
69
|
-
.filter(
|
|
85
|
+
.filter(filterFunction)
|
|
86
|
+
.filter((id) => !skip(id, config.root))
|
|
70
87
|
.forEach((moduleId) => {
|
|
71
88
|
const mod = this.getModuleInfo(moduleId);
|
|
72
89
|
const { importers } = mod;
|
|
@@ -129,31 +146,27 @@ function pluginFileEnv() {
|
|
|
129
146
|
}
|
|
130
147
|
return errMsg;
|
|
131
148
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
function getModulePath(moduleId) {
|
|
157
|
-
return moduleId.split('?')[0];
|
|
158
|
-
}
|
|
149
|
+
}
|
|
150
|
+
function isWrongEnv(moduleId, isServerSide) {
|
|
151
|
+
const modulePath = getModulePath(moduleId);
|
|
152
|
+
const suffixWrong = getSuffix(isServerSide ? 'client' : 'server');
|
|
153
|
+
return modulePath.includes(suffixWrong);
|
|
154
|
+
}
|
|
155
|
+
function skip(id, userRootDir) {
|
|
156
|
+
(0, utils_js_1.assert)(filterFunction(id));
|
|
157
|
+
// TO-DO/next-major-release: remove
|
|
158
|
+
if (pluginExtractAssets_js_1.extractAssetsRE.test(id) || pluginExtractExportNames_js_1.extractExportNamesRE.test(id))
|
|
159
|
+
return true;
|
|
160
|
+
if (getModulePath(id).endsWith('.css'))
|
|
161
|
+
return true;
|
|
162
|
+
// Skip linked dependencies
|
|
163
|
+
if (!id.startsWith(userRootDir))
|
|
164
|
+
return true;
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
function getSuffix(env) {
|
|
168
|
+
return `.${env}.`;
|
|
169
|
+
}
|
|
170
|
+
function getModulePath(moduleId) {
|
|
171
|
+
return moduleId.split('?')[0];
|
|
159
172
|
}
|
|
@@ -6,6 +6,17 @@ const retrievePageAssetsDev_js_1 = require("../../runtime/renderPage/getPageAsse
|
|
|
6
6
|
const getViteConfigRuntime_js_1 = require("../shared/getViteConfigRuntime.js");
|
|
7
7
|
const getMagicString_js_1 = require("../shared/getMagicString.js");
|
|
8
8
|
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
9
|
+
const distFileIsNonRunnableDev = (0, utils_js_1.requireResolveDistFile)('dist/esm/utils/isNonRunnableDev.js');
|
|
10
|
+
const distFileGlobalContext = (0, utils_js_1.requireResolveDistFile)('dist/esm/node/runtime/globalContext.js');
|
|
11
|
+
const filterRolldown = {
|
|
12
|
+
id: {
|
|
13
|
+
include: [distFileIsNonRunnableDev, distFileGlobalContext].map((filePath) => new RegExp(`^${(0, utils_js_1.escapeRegex)(filePath)}($|${(0, utils_js_1.escapeRegex)('?')}.*)`)),
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
const filterFunction = (id) => {
|
|
17
|
+
const idWithoutQuery = getIdWithoutQuery(id);
|
|
18
|
+
return idWithoutQuery === distFileIsNonRunnableDev || idWithoutQuery === distFileGlobalContext;
|
|
19
|
+
};
|
|
9
20
|
function getViteRpcFunctions(viteDevServer) {
|
|
10
21
|
return {
|
|
11
22
|
async transformIndexHtmlRPC(html) {
|
|
@@ -20,11 +31,10 @@ function getViteRpcFunctions(viteDevServer) {
|
|
|
20
31
|
};
|
|
21
32
|
}
|
|
22
33
|
function pluginNonRunnableDev() {
|
|
23
|
-
const distFileIsNonRunnableDev = (0, utils_js_1.requireResolveDistFile)('dist/esm/utils/isNonRunnableDev.js');
|
|
24
|
-
const distFileGlobalContext = (0, utils_js_1.requireResolveDistFile)('dist/esm/node/runtime/globalContext.js');
|
|
25
34
|
let config;
|
|
26
35
|
return {
|
|
27
36
|
name: 'vike:pluginNonRunnableDev',
|
|
37
|
+
apply: (_, configEnv) => (0, utils_js_1.isDevCheck)(configEnv),
|
|
28
38
|
configureServer: {
|
|
29
39
|
handler(viteDevServer) {
|
|
30
40
|
(0, utils_js_1.createViteRPC)(viteDevServer, getViteRpcFunctions);
|
|
@@ -36,12 +46,11 @@ function pluginNonRunnableDev() {
|
|
|
36
46
|
},
|
|
37
47
|
},
|
|
38
48
|
transform: {
|
|
49
|
+
filter: filterRolldown,
|
|
39
50
|
handler(code, id) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const idWithoutQuery = id
|
|
43
|
-
if (idWithoutQuery !== distFileIsNonRunnableDev && idWithoutQuery !== distFileGlobalContext)
|
|
44
|
-
return;
|
|
51
|
+
(0, utils_js_1.assert)(config._isDev);
|
|
52
|
+
(0, utils_js_1.assert)(filterFunction(id));
|
|
53
|
+
const idWithoutQuery = getIdWithoutQuery(id);
|
|
45
54
|
if ((0, utils_js_1.isRunnableDevEnvironment)(this.environment))
|
|
46
55
|
return;
|
|
47
56
|
const { magicString, getMagicStringResult } = (0, getMagicString_js_1.getMagicString)(code, id);
|
|
@@ -56,3 +65,6 @@ function pluginNonRunnableDev() {
|
|
|
56
65
|
},
|
|
57
66
|
};
|
|
58
67
|
}
|
|
68
|
+
function getIdWithoutQuery(id) {
|
|
69
|
+
return id.split('?')[0];
|
|
70
|
+
}
|
|
@@ -1,10 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.filterRolldown = exports.filterFunction = void 0;
|
|
3
4
|
exports.pluginReplaceConstants = pluginReplaceConstants;
|
|
4
5
|
const utils_js_1 = require("../utils.js");
|
|
5
6
|
const normalizeId_js_1 = require("../shared/normalizeId.js");
|
|
6
7
|
const isViteServerSide_js_1 = require("../shared/isViteServerSide.js");
|
|
7
8
|
const getMagicString_js_1 = require("../shared/getMagicString.js");
|
|
9
|
+
const skipNodeModules = '/node_modules/';
|
|
10
|
+
const skipIrrelevant = '({}).';
|
|
11
|
+
const filterRolldown = {
|
|
12
|
+
id: {
|
|
13
|
+
exclude: `**${skipNodeModules}**`,
|
|
14
|
+
},
|
|
15
|
+
code: {
|
|
16
|
+
include: skipIrrelevant,
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
exports.filterRolldown = filterRolldown;
|
|
20
|
+
const filterFunction = (id, code) => {
|
|
21
|
+
if (id.includes(skipNodeModules))
|
|
22
|
+
return false;
|
|
23
|
+
if (!code.includes(skipIrrelevant))
|
|
24
|
+
return false;
|
|
25
|
+
return true;
|
|
26
|
+
};
|
|
27
|
+
exports.filterFunction = filterFunction;
|
|
8
28
|
function pluginReplaceConstants() {
|
|
9
29
|
let config;
|
|
10
30
|
return {
|
|
@@ -17,16 +37,14 @@ function pluginReplaceConstants() {
|
|
|
17
37
|
},
|
|
18
38
|
},
|
|
19
39
|
transform: {
|
|
40
|
+
filter: filterRolldown,
|
|
20
41
|
handler(code, id, options) {
|
|
21
42
|
id = (0, normalizeId_js_1.normalizeId)(id);
|
|
22
43
|
(0, utils_js_1.assertPosixPath)(id);
|
|
23
|
-
if (id.includes('/node_modules/'))
|
|
24
|
-
return;
|
|
25
44
|
(0, utils_js_1.assertPosixPath)(config.root);
|
|
26
45
|
if (!id.startsWith(config.root))
|
|
27
|
-
return;
|
|
28
|
-
|
|
29
|
-
return;
|
|
46
|
+
return; // skip linked dependencies
|
|
47
|
+
(0, utils_js_1.assert)(filterFunction(id, code));
|
|
30
48
|
const isBuild = config.command === 'build';
|
|
31
49
|
(0, utils_js_1.assert)(isBuild);
|
|
32
50
|
// Used by vike.dev
|
|
@@ -17,6 +17,12 @@ const globalContext_js_1 = require("../../runtime/globalContext.js");
|
|
|
17
17
|
const crawlPlusFiles_js_1 = require("../shared/resolveVikeConfigInternal/crawlPlusFiles.js");
|
|
18
18
|
const transpileAndExecuteFile_js_1 = require("../shared/resolveVikeConfigInternal/transpileAndExecuteFile.js");
|
|
19
19
|
const getVikeConfigError_js_1 = require("../../shared/getVikeConfigError.js");
|
|
20
|
+
const filterRolldown = {
|
|
21
|
+
id: {
|
|
22
|
+
include: new RegExp(`^(${(0, utils_js_1.escapeRegex)(utils_js_1.virtualFileIdPrefix1)}|${(0, utils_js_1.escapeRegex)(utils_js_1.virtualFileIdPrefix2)})`),
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
const filterFunction = (id) => (0, utils_js_1.isVirtualFileId)(id);
|
|
20
26
|
function pluginVirtualFiles() {
|
|
21
27
|
let config;
|
|
22
28
|
return {
|
|
@@ -30,10 +36,10 @@ function pluginVirtualFiles() {
|
|
|
30
36
|
},
|
|
31
37
|
},
|
|
32
38
|
resolveId: {
|
|
39
|
+
filter: filterRolldown,
|
|
33
40
|
handler(id) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
41
|
+
(0, utils_js_1.assert)(filterFunction(id));
|
|
42
|
+
return (0, utils_js_1.addVirtualFileIdPrefix)(id);
|
|
37
43
|
},
|
|
38
44
|
},
|
|
39
45
|
handleHotUpdate: {
|
|
@@ -49,9 +55,9 @@ function pluginVirtualFiles() {
|
|
|
49
55
|
},
|
|
50
56
|
},
|
|
51
57
|
load: {
|
|
58
|
+
filter: filterRolldown,
|
|
52
59
|
async handler(id, options) {
|
|
53
|
-
|
|
54
|
-
return undefined;
|
|
60
|
+
(0, utils_js_1.assert)(filterFunction(id));
|
|
55
61
|
id = (0, utils_js_1.removeVirtualFileIdPrefix)(id);
|
|
56
62
|
const isDev = config._isDev;
|
|
57
63
|
(0, utils_js_1.assert)(typeof isDev === 'boolean');
|
|
@@ -141,8 +147,7 @@ async function handleHotUpdate(ctx, config) {
|
|
|
141
147
|
// Vite already invalidates it, but *after* handleHotUpdate() and thus after server.ssrLoadModule()
|
|
142
148
|
ctx.modules.forEach((mod) => server.moduleGraph.invalidateModule(mod));
|
|
143
149
|
if ((0, globalContext_js_1.isRunnable)(server)) {
|
|
144
|
-
|
|
145
|
-
(0, globalContext_js_1.updateUserFiles)();
|
|
150
|
+
await (0, globalContext_js_1.updateUserFiles)();
|
|
146
151
|
}
|
|
147
152
|
}
|
|
148
153
|
}
|
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.virtualFileIdPrefix2 = exports.virtualFileIdPrefix1 = void 0;
|
|
6
7
|
exports.isVirtualFileId = isVirtualFileId;
|
|
7
8
|
exports.addVirtualFileIdPrefix = addVirtualFileIdPrefix;
|
|
8
9
|
exports.removeVirtualFileIdPrefix = removeVirtualFileIdPrefix;
|
|
@@ -10,30 +11,33 @@ const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
|
10
11
|
const assert_js_1 = require("./assert.js");
|
|
11
12
|
const assertIsNotBrowser_js_1 = require("./assertIsNotBrowser.js");
|
|
12
13
|
(0, assertIsNotBrowser_js_1.assertIsNotBrowser)();
|
|
13
|
-
const
|
|
14
|
+
const virtualFileIdPrefix1 = 'virtual:vike:';
|
|
15
|
+
exports.virtualFileIdPrefix1 = virtualFileIdPrefix1;
|
|
14
16
|
// https://vitejs.dev/guide/api-plugin.html#virtual-modules-convention
|
|
15
|
-
const
|
|
17
|
+
const convention = '\0';
|
|
18
|
+
const virtualFileIdPrefix2 = `${convention}${virtualFileIdPrefix1}`;
|
|
19
|
+
exports.virtualFileIdPrefix2 = virtualFileIdPrefix2;
|
|
16
20
|
function isVirtualFileId(id) {
|
|
17
|
-
if (id.startsWith(
|
|
21
|
+
if (id.startsWith(virtualFileIdPrefix1))
|
|
18
22
|
return true;
|
|
19
|
-
if (id.startsWith(
|
|
23
|
+
if (id.startsWith(virtualFileIdPrefix2))
|
|
20
24
|
return true;
|
|
21
25
|
// https://github.com/vikejs/vike/issues/1985
|
|
22
|
-
(0, assert_js_1.assertUsage)(!id.includes(
|
|
26
|
+
(0, assert_js_1.assertUsage)(!id.includes(virtualFileIdPrefix1), `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
27
|
return false;
|
|
24
28
|
}
|
|
25
29
|
function addVirtualFileIdPrefix(id) {
|
|
26
30
|
(0, assert_js_1.assert)(isVirtualFileId(id));
|
|
27
|
-
if (!id.startsWith(
|
|
28
|
-
id =
|
|
31
|
+
if (!id.startsWith(convention)) {
|
|
32
|
+
id = convention + id;
|
|
29
33
|
}
|
|
30
|
-
(0, assert_js_1.assert)(id.startsWith(
|
|
34
|
+
(0, assert_js_1.assert)(id.startsWith(convention));
|
|
31
35
|
return id;
|
|
32
36
|
}
|
|
33
37
|
function removeVirtualFileIdPrefix(id) {
|
|
34
|
-
if (id.startsWith(
|
|
35
|
-
id = id.slice(
|
|
38
|
+
if (id.startsWith(convention)) {
|
|
39
|
+
id = id.slice(convention.length);
|
|
36
40
|
}
|
|
37
|
-
(0, assert_js_1.assert)(!id.startsWith(
|
|
41
|
+
(0, assert_js_1.assert)(!id.startsWith(convention));
|
|
38
42
|
return id;
|
|
39
43
|
}
|
|
@@ -58,7 +58,7 @@ declare function createPageContextClientSide(urlOriginal: string): Promise<{
|
|
|
58
58
|
} & {
|
|
59
59
|
_pageRoutes: import("../../__internal/index.js").PageRoutes;
|
|
60
60
|
_onBeforeRouteHook: import("../../shared/hooks/getHook.js").Hook | null;
|
|
61
|
-
}
|
|
61
|
+
};
|
|
62
62
|
_pageFilesAll: import("../../shared/getPageFiles.js").PageFile[];
|
|
63
63
|
_urlHandler: null;
|
|
64
64
|
_urlRewrite: null | string;
|
|
@@ -78,7 +78,7 @@ declare function getPageContextFromHooks_isHydration(pageContext: PageContextSer
|
|
|
78
78
|
} & {
|
|
79
79
|
_pageRoutes: import("../../__internal/index.js").PageRoutes;
|
|
80
80
|
_onBeforeRouteHook: import("../../shared/hooks/getHook.js").Hook | null;
|
|
81
|
-
}
|
|
81
|
+
};
|
|
82
82
|
_pageFilesAll: PageFile[];
|
|
83
83
|
_urlHandler: null;
|
|
84
84
|
_urlRewrite: null | string;
|
|
@@ -299,7 +299,7 @@ declare function getPageContextFromClientHooks(pageContext: {
|
|
|
299
299
|
} & {
|
|
300
300
|
_pageRoutes: import("../../__internal/index.js").PageRoutes;
|
|
301
301
|
_onBeforeRouteHook: import("../../shared/hooks/getHook.js").Hook | null;
|
|
302
|
-
}
|
|
302
|
+
};
|
|
303
303
|
_pageFilesAll: PageFile[];
|
|
304
304
|
_urlHandler: null;
|
|
305
305
|
_urlRewrite: null | string;
|
|
@@ -92,7 +92,7 @@ declare function getPageContextBegin(isForErrorPage: boolean, { urlOriginal, isB
|
|
|
92
92
|
} & {
|
|
93
93
|
_pageRoutes: import("../../shared/route/loadPageRoutes.js").PageRoutes;
|
|
94
94
|
_onBeforeRouteHook: import("../../shared/hooks/getHook.js").Hook | null;
|
|
95
|
-
}
|
|
95
|
+
};
|
|
96
96
|
_pageFilesAll: import("../../shared/getPageFiles.js").PageFile[];
|
|
97
97
|
_urlHandler: null;
|
|
98
98
|
_urlRewrite: null | string;
|
|
@@ -54,7 +54,7 @@ declare function createPageContextClientSide(): Promise<{
|
|
|
54
54
|
_allPageIds: string[];
|
|
55
55
|
} & {
|
|
56
56
|
isClientSide: true;
|
|
57
|
-
} & object
|
|
57
|
+
} & object;
|
|
58
58
|
_pageFilesAll: import("../../shared/getPageFiles.js").PageFile[];
|
|
59
59
|
isBackwardNavigation: null;
|
|
60
60
|
_hasPageContextFromServer: true;
|
|
@@ -58,7 +58,7 @@ declare function createGetGlobalContextClient<GlobalContextAddendum extends obje
|
|
|
58
58
|
* We recommend using `import.meta.env.SSR` instead, see https://vike.dev/globalContext
|
|
59
59
|
*/
|
|
60
60
|
isClientSide: true;
|
|
61
|
-
} & Awaited<GlobalContextAddendum
|
|
61
|
+
} & Awaited<GlobalContextAddendum>>;
|
|
62
62
|
type NeverExported = never;
|
|
63
63
|
declare function getGlobalContext(): Promise<NeverExported>;
|
|
64
64
|
declare function getGlobalContextSync(): NeverExported;
|
|
@@ -74,7 +74,7 @@ declare function createPageContextPrerendering(urlOriginal: string, prerenderCon
|
|
|
74
74
|
url?: string;
|
|
75
75
|
headers?: Record<string, string>;
|
|
76
76
|
} & {
|
|
77
|
-
_globalContext: {
|
|
77
|
+
_globalContext: ({
|
|
78
78
|
_globalConfigPublic: {
|
|
79
79
|
pages: {
|
|
80
80
|
[k: string]: {
|
|
@@ -162,7 +162,9 @@ declare function createPageContextPrerendering(urlOriginal: string, prerenderCon
|
|
|
162
162
|
inject: boolean | undefined;
|
|
163
163
|
};
|
|
164
164
|
};
|
|
165
|
-
})
|
|
165
|
+
})) & {
|
|
166
|
+
prerenderContext: PrerenderContextPublic | undefined;
|
|
167
|
+
};
|
|
166
168
|
_pageFilesAll: PageFile[];
|
|
167
169
|
_baseServer: string;
|
|
168
170
|
_baseAssets: string;
|
|
@@ -9,7 +9,7 @@ import { prerenderPage } from '../runtime/renderPage/renderPageAfterRoute.js';
|
|
|
9
9
|
import { createPageContextServerSide } from '../runtime/renderPage/createPageContextServerSide.js';
|
|
10
10
|
import pc from '@brillout/picocolors';
|
|
11
11
|
import { cpus } from 'node:os';
|
|
12
|
-
import { getGlobalContextServerInternal, initGlobalContext_runPrerender, setGlobalContext_isPrerendering, } from '../runtime/globalContext.js';
|
|
12
|
+
import { getGlobalContextServerInternal, initGlobalContext_runPrerender, setGlobalContext_isPrerendering, setGlobalContext_prerenderContext, } from '../runtime/globalContext.js';
|
|
13
13
|
import { resolveConfig as resolveViteConfig } from 'vite';
|
|
14
14
|
import { getPageFilesServerSide } from '../../shared/getPageFiles.js';
|
|
15
15
|
import { getPageContextRequestUrl } from '../../shared/getPageContextRequestUrl.js';
|
|
@@ -108,6 +108,7 @@ async function runPrerender(options = {}, trigger) {
|
|
|
108
108
|
await warnMissingPages(prerenderContext._prerenderedPageContexts, globalContext, doNotPrerenderList, partial);
|
|
109
109
|
const prerenderContextPublic = preparePrerenderContextForPublicUsage(prerenderContext);
|
|
110
110
|
objectAssign(vikeConfig.prerenderContext, prerenderContextPublic, true);
|
|
111
|
+
setGlobalContext_prerenderContext(prerenderContextPublic);
|
|
111
112
|
if (prerenderConfigGlobal.isPrerenderingEnabledForAllPages && !prerenderConfigGlobal.keepDistServer) {
|
|
112
113
|
fs.rmSync(outDirServer, { recursive: true });
|
|
113
114
|
}
|