vike 0.4.218 → 0.4.220-commit-a9f46b8
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/__internal/index.js +11 -11
- package/dist/cjs/node/api/build.js +22 -48
- package/dist/cjs/node/api/context.js +8 -6
- package/dist/cjs/node/api/index.js +17 -7
- package/dist/cjs/node/api/prepareViteApiCall.js +40 -13
- package/dist/cjs/node/cli/context.js +16 -0
- package/dist/cjs/node/cli/entry.js +21 -7
- package/dist/cjs/node/cli/utils.js +1 -0
- package/dist/cjs/node/plugin/index.js +5 -5
- package/dist/cjs/node/plugin/plugins/autoFullBuild.js +32 -20
- package/dist/cjs/node/plugin/plugins/baseUrls.js +3 -10
- package/dist/cjs/node/plugin/plugins/buildConfig.js +2 -2
- package/dist/cjs/node/plugin/plugins/{importBuild → buildEntry}/index.js +16 -17
- package/dist/cjs/node/plugin/plugins/commonConfig.js +41 -4
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +26 -23
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +171 -68
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +7 -5
- package/dist/cjs/node/plugin/plugins/setGlobalContext.js +1 -1
- package/dist/cjs/node/plugin/plugins/{vite6HmrRegressionWorkaround.js → workaroundVite6HmrRegression.js} +3 -3
- package/dist/cjs/node/plugin/shared/getHttpRequestAsyncStore.js +17 -7
- package/dist/cjs/node/prerender/context.js +24 -0
- package/dist/cjs/node/prerender/runPrerender.js +146 -96
- package/dist/cjs/node/prerender/utils.js +2 -0
- package/dist/cjs/node/runtime/globalContext.js +109 -55
- package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +2 -2
- package/dist/cjs/node/runtime/index-common.js +0 -15
- package/dist/cjs/node/runtime/onLoad.js +17 -3
- package/dist/cjs/node/runtime/page-files/setup.js +2 -4
- package/dist/cjs/node/runtime/renderPage/analyzePage.js +2 -2
- package/dist/cjs/node/runtime/renderPage/createHttpResponse/getCacheControl.js +2 -2
- package/dist/cjs/node/runtime/renderPage/loadUserFilesServerSide.js +1 -1
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +11 -33
- package/dist/cjs/node/runtime/renderPage/resolveRedirects.js +9 -1
- package/dist/cjs/node/runtime/renderPage.js +21 -22
- package/dist/cjs/node/runtime/utils.js +2 -0
- package/dist/cjs/node/runtime-dev/index.js +17 -7
- package/dist/cjs/node/shared/assertRuntimeManifest.js +0 -2
- package/dist/cjs/shared/getPageFiles/analyzeClientSide.js +3 -3
- package/dist/cjs/shared/getPageFiles/{setPageFiles.js → getPageFiles.js} +8 -6
- package/dist/cjs/shared/getPageFiles.js +3 -9
- package/dist/cjs/shared/hooks/getHook.js +3 -3
- package/dist/cjs/shared/{getPageFiles/getExports.js → page-configs/getPageConfigUserFriendly.js} +113 -81
- package/dist/cjs/shared/page-configs/loadConfigValues.js +5 -1
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +80 -55
- package/dist/cjs/shared/route/loadPageRoutes.js +3 -3
- package/dist/cjs/shared/utils.js +1 -0
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/assert.js +4 -3
- package/dist/cjs/utils/assertSetup.js +47 -16
- package/dist/cjs/utils/catchInfiniteLoop.js +34 -0
- package/dist/cjs/utils/debug.js +11 -6
- package/dist/cjs/utils/getGlobalObject.js +1 -2
- package/dist/cjs/utils/isDev.js +2 -0
- package/dist/cjs/utils/makePublicCopy.js +32 -0
- package/dist/cjs/utils/objectReplace.js +9 -0
- package/dist/esm/__internal/index.d.ts +3 -5
- package/dist/esm/__internal/index.js +6 -8
- package/dist/esm/client/client-routing-runtime/createPageContext.js +4 -1
- package/dist/esm/client/client-routing-runtime/entry.d.ts +1 -1
- package/dist/esm/client/client-routing-runtime/entry.js +0 -1
- package/dist/esm/client/client-routing-runtime/getPageContextCurrent.d.ts +2 -2
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.d.ts +4 -4
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.js +1 -1
- package/dist/esm/client/client-routing-runtime/history.d.ts +3 -1
- package/dist/esm/client/client-routing-runtime/history.js +23 -18
- package/dist/esm/client/client-routing-runtime/index.d.ts +0 -1
- package/dist/esm/client/client-routing-runtime/index.js +0 -1
- package/dist/esm/client/client-routing-runtime/initClientRouter.js +2 -2
- package/dist/esm/client/client-routing-runtime/initOnLinkClick.js +3 -4
- package/dist/esm/client/client-routing-runtime/initOnPopState.d.ts +0 -10
- package/dist/esm/client/client-routing-runtime/initOnPopState.js +50 -62
- package/dist/esm/client/client-routing-runtime/prefetch/getPrefetchSettings.d.ts +2 -2
- package/dist/esm/client/client-routing-runtime/prefetch.d.ts +2 -2
- package/dist/esm/client/client-routing-runtime/prefetch.js +2 -2
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +15 -15
- package/dist/esm/client/client-routing-runtime/scrollRestoration.d.ts +4 -6
- package/dist/esm/client/client-routing-runtime/scrollRestoration.js +17 -12
- package/dist/esm/client/client-routing-runtime/setScrollPosition.d.ts +1 -1
- package/dist/esm/client/client-routing-runtime/setScrollPosition.js +29 -5
- package/dist/esm/client/client-routing-runtime/utils.d.ts +1 -0
- package/dist/esm/client/client-routing-runtime/utils.js +1 -0
- package/dist/esm/client/server-routing-runtime/entry.d.ts +1 -1
- package/dist/esm/client/server-routing-runtime/entry.js +0 -1
- package/dist/esm/client/server-routing-runtime/getPageContext.d.ts +1 -1
- package/dist/esm/client/server-routing-runtime/getPageContext.js +5 -2
- package/dist/esm/client/shared/executeOnRenderClientHook.d.ts +2 -2
- package/dist/esm/client/shared/loadUserFilesClientSide.d.ts +2 -2
- package/dist/esm/client/shared/loadUserFilesClientSide.js +2 -2
- package/dist/esm/client/shared/normalizeClientSideUrl.js +2 -3
- package/dist/esm/client/shared/preparePageContextForUserConsumptionClientSide.d.ts +2 -2
- package/dist/esm/node/api/build.d.ts +1 -6
- package/dist/esm/node/api/build.js +20 -26
- package/dist/esm/node/api/context.d.ts +4 -2
- package/dist/esm/node/api/context.js +8 -7
- package/dist/esm/node/api/prepareViteApiCall.d.ts +0 -1
- package/dist/esm/node/api/prepareViteApiCall.js +26 -9
- package/dist/esm/node/cli/context.d.ts +5 -0
- package/dist/esm/node/cli/context.js +14 -0
- package/dist/esm/node/cli/entry.js +4 -0
- package/dist/esm/node/cli/parseCli.d.ts +3 -1
- package/dist/esm/node/cli/utils.d.ts +1 -0
- package/dist/esm/node/cli/utils.js +1 -0
- package/dist/esm/node/plugin/index.d.ts +1 -1
- package/dist/esm/node/plugin/index.js +5 -5
- package/dist/esm/node/plugin/plugins/autoFullBuild.js +32 -20
- package/dist/esm/node/plugin/plugins/baseUrls.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/baseUrls.js +4 -11
- package/dist/esm/node/plugin/plugins/buildConfig.js +2 -2
- package/dist/esm/node/plugin/plugins/{importBuild → buildEntry}/getVikeManifest.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/{importBuild → buildEntry}/index.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/{importBuild → buildEntry}/index.js +16 -17
- package/dist/esm/node/plugin/plugins/commonConfig.d.ts +10 -1
- package/dist/esm/node/plugin/plugins/commonConfig.js +42 -5
- package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +6 -9
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +25 -22
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +96 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +167 -64
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +7 -5
- package/dist/esm/node/plugin/plugins/setGlobalContext.js +1 -1
- package/dist/esm/node/plugin/plugins/workaroundVite6HmrRegression.d.ts +3 -0
- package/dist/esm/node/plugin/plugins/{vite6HmrRegressionWorkaround.js → workaroundVite6HmrRegression.js} +3 -3
- package/dist/esm/node/prerender/context.d.ts +9 -0
- package/dist/esm/node/prerender/context.js +22 -0
- package/dist/esm/node/prerender/runPrerender.d.ts +42 -2
- package/dist/esm/node/prerender/runPrerender.js +130 -90
- package/dist/esm/node/prerender/utils.d.ts +2 -0
- package/dist/esm/node/prerender/utils.js +2 -0
- package/dist/esm/node/runtime/globalContext.d.ts +23 -7
- package/dist/esm/node/runtime/globalContext.js +109 -55
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +1 -1
- package/dist/esm/node/runtime/index-common.d.ts +0 -1
- package/dist/esm/node/runtime/index-common.js +0 -15
- package/dist/esm/node/runtime/index-deprecated.d.ts +1 -0
- package/dist/esm/node/runtime/onLoad.js +16 -2
- package/dist/esm/node/runtime/page-files/setup.js +3 -3
- package/dist/esm/node/runtime/renderPage/analyzePage.js +1 -1
- package/dist/esm/node/runtime/renderPage/createHttpResponse/getCacheControl.js +1 -1
- package/dist/esm/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.js +2 -2
- package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +31 -46
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +11 -33
- package/dist/esm/node/runtime/renderPage/resolveRedirects.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/resolveRedirects.js +9 -1
- package/dist/esm/node/runtime/renderPage.js +22 -23
- package/dist/esm/node/runtime/utils.d.ts +2 -0
- package/dist/esm/node/runtime/utils.js +2 -0
- package/dist/esm/node/shared/assertPluginManifest.d.ts +0 -1
- package/dist/esm/node/shared/assertRuntimeManifest.d.ts +0 -1
- package/dist/esm/node/shared/assertRuntimeManifest.js +1 -3
- package/dist/esm/shared/getPageFiles/analyzeClientSide.js +1 -1
- package/dist/esm/shared/getPageFiles/{setPageFiles.d.ts → getPageFiles.d.ts} +3 -1
- package/dist/esm/shared/getPageFiles/{setPageFiles.js → getPageFiles.js} +8 -6
- package/dist/esm/shared/getPageFiles.d.ts +2 -5
- package/dist/esm/shared/getPageFiles.js +1 -4
- package/dist/esm/shared/hooks/getHook.d.ts +3 -3
- package/dist/esm/shared/hooks/getHook.js +1 -1
- package/dist/esm/shared/page-configs/Config/PageContextConfig.d.ts +9 -5
- package/dist/esm/shared/page-configs/Config.d.ts +20 -2
- package/dist/esm/shared/page-configs/PageConfig.d.ts +13 -6
- package/dist/esm/shared/{getPageFiles/getExports.d.ts → page-configs/getPageConfigUserFriendly.d.ts} +26 -12
- package/dist/esm/shared/{getPageFiles/getExports.js → page-configs/getPageConfigUserFriendly.js} +112 -80
- package/dist/esm/shared/page-configs/loadConfigValues.js +6 -2
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.d.ts +26 -6
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +80 -55
- package/dist/esm/shared/route/executeGuardHook.d.ts +2 -2
- package/dist/esm/shared/route/loadPageRoutes.js +1 -1
- package/dist/esm/shared/types.d.ts +1 -1
- package/dist/esm/shared/utils.d.ts +1 -0
- package/dist/esm/shared/utils.js +1 -0
- package/dist/esm/types/index.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/assert.js +4 -3
- package/dist/esm/utils/assertSetup.js +47 -16
- package/dist/esm/utils/catchInfiniteLoop.d.ts +2 -0
- package/dist/esm/utils/catchInfiniteLoop.js +32 -0
- package/dist/esm/utils/debug.d.ts +1 -1
- package/dist/esm/utils/debug.js +11 -6
- package/dist/esm/utils/getGlobalObject.js +1 -2
- package/dist/esm/utils/isDev.js +2 -0
- package/dist/esm/utils/makePublicCopy.d.ts +3 -0
- package/dist/esm/utils/makePublicCopy.js +30 -0
- package/dist/esm/utils/objectReplace.d.ts +1 -0
- package/dist/esm/utils/objectReplace.js +6 -0
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/package.json +4 -13
- package/__internal/loadImportBuild.js +0 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveVikeConfigGlobal.js +0 -128
- package/dist/cjs/node/runtime/globalContext/loadImportBuild.js +0 -25
- package/dist/cjs/node/runtime/page-files/getPageFilesExports.js +0 -22
- package/dist/esm/client/client-routing-runtime/pageFiles.d.ts +0 -1
- package/dist/esm/client/client-routing-runtime/pageFiles.js +0 -4
- package/dist/esm/client/server-routing-runtime/pageFiles.d.ts +0 -1
- package/dist/esm/client/server-routing-runtime/pageFiles.js +0 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveVikeConfigGlobal.d.ts +0 -104
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveVikeConfigGlobal.js +0 -123
- package/dist/esm/node/plugin/plugins/vite6HmrRegressionWorkaround.d.ts +0 -3
- package/dist/esm/node/runtime/globalContext/loadImportBuild.d.ts +0 -18
- package/dist/esm/node/runtime/globalContext/loadImportBuild.js +0 -23
- package/dist/esm/node/runtime/page-files/getPageFilesExports.d.ts +0 -2
- package/dist/esm/node/runtime/page-files/getPageFilesExports.js +0 -20
- /package/dist/cjs/node/plugin/plugins/{importBuild → buildEntry}/getVikeManifest.js +0 -0
- /package/dist/cjs/shared/page-configs/{getConfigValue.js → getConfigValueRuntime.js} +0 -0
- /package/dist/esm/node/plugin/plugins/{importBuild → buildEntry}/getVikeManifest.js +0 -0
- /package/dist/esm/shared/page-configs/{getConfigValue.d.ts → getConfigValueRuntime.d.ts} +0 -0
- /package/dist/esm/shared/page-configs/{getConfigValue.js → getConfigValueRuntime.js} +0 -0
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.serializeConfigValues = serializeConfigValues;
|
|
7
|
+
exports.getConfigValuesBase = getConfigValuesBase;
|
|
7
8
|
const assertSetup_js_1 = require("../../../utils/assertSetup.js");
|
|
8
9
|
const utils_js_1 = require("../../../node/plugin/utils.js");
|
|
9
10
|
const addImportStatement_js_1 = require("../../../node/plugin/plugins/importUserCode/addImportStatement.js");
|
|
@@ -17,77 +18,45 @@ const REPLACE_ME_AFTER = '__VIKE__REPLACE_ME_AFTER__';
|
|
|
17
18
|
// - vike/shared/page-configs/serialize/parsePageConfigs.ts
|
|
18
19
|
// - parsePageConfigs() is loaded on both the client- and server-side.
|
|
19
20
|
(0, assertSetup_js_1.assertIsNotProductionRuntime)();
|
|
20
|
-
function serializeConfigValues(pageConfig, importStatements, isEnvMatch,
|
|
21
|
+
function serializeConfigValues(pageConfig, importStatements, isEnvMatch, tabspace, isEager) {
|
|
21
22
|
const lines = [];
|
|
22
23
|
tabspace += ' ';
|
|
23
|
-
|
|
24
|
-
if (
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return;
|
|
29
|
-
const valueData = serializeWithJson(configValuesComputed.value, configName, null, importStatements);
|
|
30
|
-
const configValueBase = {
|
|
31
|
-
type: 'computed',
|
|
32
|
-
definedAtData: null
|
|
33
|
-
};
|
|
34
|
-
serializeConfigValue(configValueBase, valueData, configName, lines, tabspace);
|
|
35
|
-
});
|
|
36
|
-
Object.entries(pageConfig.configValueSources).forEach(([configName, sources]) => {
|
|
37
|
-
const configDef = pageConfig.configDefinitions[configName];
|
|
38
|
-
(0, utils_js_1.assert)(configDef);
|
|
39
|
-
if (isEager !== !!configDef.eager)
|
|
40
|
-
return;
|
|
41
|
-
if (!configDef.cumulative) {
|
|
42
|
-
const configValueSource = sources[0];
|
|
43
|
-
(0, utils_js_1.assert)(configValueSource);
|
|
44
|
-
(0, utils_js_1.assert)(sources.slice(1).every((s) => s.isOverriden === true));
|
|
45
|
-
if (!isEnvMatch(configValueSource.configEnv))
|
|
46
|
-
return;
|
|
47
|
-
const { valueData, definedAtFile } = serializeConfigValueSource(configValueSource, configName, importStatements);
|
|
48
|
-
const configValueBase = {
|
|
49
|
-
type: 'standard',
|
|
50
|
-
definedAtData: definedAtFile
|
|
51
|
-
};
|
|
24
|
+
getConfigValuesBase(pageConfig, isEnvMatch, isEager).forEach((entry) => {
|
|
25
|
+
if (entry.configValueBase.type === 'computed') {
|
|
26
|
+
(0, utils_js_1.assert)('value' in entry); // Help TS
|
|
27
|
+
const { configValueBase, value, configName } = entry;
|
|
28
|
+
const valueData = getValueSerializedWithJson(value, configName, configValueBase.definedAtData, importStatements);
|
|
52
29
|
serializeConfigValue(configValueBase, valueData, configName, lines, tabspace);
|
|
53
30
|
}
|
|
54
|
-
|
|
31
|
+
if (entry.configValueBase.type === 'standard') {
|
|
32
|
+
(0, utils_js_1.assert)('sourceRelevant' in entry); // Help TS
|
|
33
|
+
const { configValueBase, sourceRelevant, configName } = entry;
|
|
34
|
+
const valueData = getValueSerializedFromSource(sourceRelevant, configName, importStatements);
|
|
35
|
+
serializeConfigValue(configValueBase, valueData, configName, lines, tabspace);
|
|
36
|
+
}
|
|
37
|
+
if (entry.configValueBase.type === 'cumulative') {
|
|
38
|
+
(0, utils_js_1.assert)('sourcesRelevant' in entry); // Help TS
|
|
39
|
+
const { configValueBase, sourcesRelevant, configName } = entry;
|
|
55
40
|
const valueDataList = [];
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
.filter((s) => !s.isOverriden)
|
|
59
|
-
.forEach((configValueSource) => {
|
|
60
|
-
if (!isEnvMatch(configValueSource.configEnv))
|
|
61
|
-
return;
|
|
62
|
-
const { valueData, definedAtFile } = serializeConfigValueSource(configValueSource, configName, importStatements);
|
|
41
|
+
sourcesRelevant.forEach((source) => {
|
|
42
|
+
const valueData = getValueSerializedFromSource(source, configName, importStatements);
|
|
63
43
|
valueDataList.push(valueData);
|
|
64
|
-
definedAtData.push(definedAtFile);
|
|
65
44
|
});
|
|
66
|
-
if (valueDataList.length === 0)
|
|
67
|
-
return;
|
|
68
|
-
const configValueBase = {
|
|
69
|
-
type: 'cumulative',
|
|
70
|
-
definedAtData
|
|
71
|
-
};
|
|
72
45
|
serializeConfigValue(configValueBase, valueDataList, configName, lines, tabspace);
|
|
73
46
|
}
|
|
74
47
|
});
|
|
75
48
|
return lines;
|
|
76
49
|
}
|
|
77
|
-
function
|
|
50
|
+
function getValueSerializedFromSource(configValueSource, configName, importStatements) {
|
|
78
51
|
(0, utils_js_1.assert)(configValueSource.isOverriden === false);
|
|
79
52
|
let valueData;
|
|
80
53
|
if ('value' in configValueSource) {
|
|
81
|
-
valueData =
|
|
54
|
+
valueData = getValueSerializedWithJson(configValueSource.value, configName, configValueSource.definedAtFilePath, importStatements);
|
|
82
55
|
}
|
|
83
56
|
else {
|
|
84
|
-
valueData =
|
|
57
|
+
valueData = getValueSerializedWithImport(configValueSource, importStatements);
|
|
85
58
|
}
|
|
86
|
-
|
|
87
|
-
filePathToShowToUser: configValueSource.definedAtFilePath.filePathToShowToUser,
|
|
88
|
-
fileExportPathToShowToUser: configValueSource.definedAtFilePath.fileExportPathToShowToUser
|
|
89
|
-
};
|
|
90
|
-
return { valueData, definedAtFile };
|
|
59
|
+
return valueData;
|
|
91
60
|
}
|
|
92
61
|
function serializeConfigValue(configValueBase, valueData, configName, lines, tabspace) {
|
|
93
62
|
lineAdd(`[${JSON.stringify(configName)}]: {`);
|
|
@@ -131,7 +100,7 @@ function serializeConfigValue(configValueBase, valueData, configName, lines, tab
|
|
|
131
100
|
tabspace = tabspace.slice(2);
|
|
132
101
|
}
|
|
133
102
|
}
|
|
134
|
-
function
|
|
103
|
+
function getValueSerializedWithImport(configValueSource, importStatements) {
|
|
135
104
|
(0, utils_js_1.assert)(!configValueSource.valueIsFilePath);
|
|
136
105
|
const { valueIsImportedAtRuntime, valueIsDefinedByPlusFile, definedAtFilePath } = configValueSource;
|
|
137
106
|
(0, utils_js_1.assert)(valueIsImportedAtRuntime);
|
|
@@ -144,7 +113,7 @@ function serializeWithImport(configValueSource, importStatements) {
|
|
|
144
113
|
valueAsJsCode: importName
|
|
145
114
|
};
|
|
146
115
|
}
|
|
147
|
-
function
|
|
116
|
+
function getValueSerializedWithJson(value, configName, definedAtData, importStatements) {
|
|
148
117
|
const valueAsJsCode = valueToJson(value, configName, definedAtData, importStatements);
|
|
149
118
|
return {
|
|
150
119
|
type: 'js-serialized',
|
|
@@ -201,3 +170,59 @@ function logJsonSerializeError(err, configName, definedAtData) {
|
|
|
201
170
|
(0, utils_js_1.assert)(configValueFilePathToShowToUser);
|
|
202
171
|
(0, utils_js_1.assertUsage)(false, `${picocolors_1.default.cyan(configName)} defined by ${configValueFilePathToShowToUser} must be defined over a so-called "pointer import", see https://vike.dev/config#pointer-imports`);
|
|
203
172
|
}
|
|
173
|
+
function getConfigValuesBase(pageConfig, isEnvMatch, isEager) {
|
|
174
|
+
const fromComputed = Object.entries(pageConfig.configValuesComputed ?? {}).map(([configName, valueInfo]) => {
|
|
175
|
+
if (!isEnvMatch(valueInfo.configEnv))
|
|
176
|
+
return 'SKIP';
|
|
177
|
+
// Is there a use case for overriding computed values? If yes, then configValeSources has higher precedence
|
|
178
|
+
if (pageConfig.configValueSources[configName])
|
|
179
|
+
return 'SKIP';
|
|
180
|
+
const configValueBase = {
|
|
181
|
+
type: 'computed',
|
|
182
|
+
definedAtData: null
|
|
183
|
+
};
|
|
184
|
+
return { configValueBase, value: valueInfo.value, configName };
|
|
185
|
+
});
|
|
186
|
+
const fromSources = Object.entries(pageConfig.configValueSources).map(([configName, sources]) => {
|
|
187
|
+
const configDef = pageConfig.configDefinitions[configName];
|
|
188
|
+
(0, utils_js_1.assert)(configDef);
|
|
189
|
+
if (isEager !== null && isEager !== !!configDef.eager)
|
|
190
|
+
return 'SKIP';
|
|
191
|
+
if (!configDef.cumulative) {
|
|
192
|
+
const source = sources[0];
|
|
193
|
+
(0, utils_js_1.assert)(source);
|
|
194
|
+
(0, utils_js_1.assert)(sources.slice(1).every((s) => s.isOverriden === true));
|
|
195
|
+
if (!isEnvMatch(source.configEnv))
|
|
196
|
+
return 'SKIP';
|
|
197
|
+
const definedAtFile = getDefinedAtFileSource(source);
|
|
198
|
+
const configValueBase = {
|
|
199
|
+
type: 'standard',
|
|
200
|
+
definedAtData: definedAtFile
|
|
201
|
+
};
|
|
202
|
+
return { configValueBase, sourceRelevant: source, configName };
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
const sourcesRelevant = sources.filter((source) => !source.isOverriden && isEnvMatch(source.configEnv));
|
|
206
|
+
if (sourcesRelevant.length === 0)
|
|
207
|
+
return 'SKIP';
|
|
208
|
+
const definedAtData = [];
|
|
209
|
+
sourcesRelevant.forEach((source) => {
|
|
210
|
+
const definedAtFile = getDefinedAtFileSource(source);
|
|
211
|
+
definedAtData.push(definedAtFile);
|
|
212
|
+
});
|
|
213
|
+
const configValueBase = {
|
|
214
|
+
type: 'cumulative',
|
|
215
|
+
definedAtData
|
|
216
|
+
};
|
|
217
|
+
return { configValueBase, sourcesRelevant, configName };
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
return [...fromComputed, ...fromSources].filter((r) => r !== 'SKIP');
|
|
221
|
+
}
|
|
222
|
+
function getDefinedAtFileSource(source) {
|
|
223
|
+
const definedAtFile = {
|
|
224
|
+
filePathToShowToUser: source.definedAtFilePath.filePathToShowToUser,
|
|
225
|
+
fileExportPathToShowToUser: source.definedAtFilePath.fileExportPathToShowToUser
|
|
226
|
+
};
|
|
227
|
+
return definedAtFile;
|
|
228
|
+
}
|
|
@@ -5,7 +5,7 @@ const error_page_js_1 = require("../error-page.js");
|
|
|
5
5
|
const utils_js_1 = require("./utils.js");
|
|
6
6
|
const deduceRouteStringFromFilesystemPath_js_1 = require("./deduceRouteStringFromFilesystemPath.js");
|
|
7
7
|
const utils_js_2 = require("../utils.js");
|
|
8
|
-
const
|
|
8
|
+
const getConfigValueRuntime_js_1 = require("../page-configs/getConfigValueRuntime.js");
|
|
9
9
|
const getConfigDefinedAt_js_1 = require("../page-configs/getConfigDefinedAt.js");
|
|
10
10
|
const resolveRouteFunction_js_1 = require("./resolveRouteFunction.js");
|
|
11
11
|
const getHook_js_1 = require("../hooks/getHook.js");
|
|
@@ -30,7 +30,7 @@ function getPageRoutes(filesystemRoots, pageFilesAll, pageConfigs, allPageIds) {
|
|
|
30
30
|
let pageRoute = null;
|
|
31
31
|
{
|
|
32
32
|
const configName = 'route';
|
|
33
|
-
const configValue = (0,
|
|
33
|
+
const configValue = (0, getConfigValueRuntime_js_1.getConfigValueRuntime)(pageConfig, configName);
|
|
34
34
|
if (configValue) {
|
|
35
35
|
const route = configValue.value;
|
|
36
36
|
(0, utils_js_1.assert)(configValue.definedAtData);
|
|
@@ -46,7 +46,7 @@ function getPageRoutes(filesystemRoots, pageFilesAll, pageConfigs, allPageIds) {
|
|
|
46
46
|
}
|
|
47
47
|
else {
|
|
48
48
|
(0, utils_js_1.assert)((0, utils_js_2.isCallable)(route));
|
|
49
|
-
if ((0,
|
|
49
|
+
if ((0, getConfigValueRuntime_js_1.getConfigValueRuntime)(pageConfig, 'iKnowThePerformanceRisksOfAsyncRouteFunctions', 'boolean'))
|
|
50
50
|
(0, resolveRouteFunction_js_1.warnDeprecatedAllowKey)();
|
|
51
51
|
pageRoute = {
|
|
52
52
|
pageId,
|
package/dist/cjs/shared/utils.js
CHANGED
|
@@ -42,3 +42,4 @@ __exportStar(require("../utils/escapeRegex.js"), exports);
|
|
|
42
42
|
__exportStar(require("../utils/isArray.js"), exports);
|
|
43
43
|
__exportStar(require("../utils/changeEnumerable.js"), exports);
|
|
44
44
|
__exportStar(require("../utils/objectDefineProperty.js"), exports);
|
|
45
|
+
__exportStar(require("../utils/isScriptFile.js"), exports);
|
package/dist/cjs/utils/assert.js
CHANGED
|
@@ -35,6 +35,7 @@ const globalObject = (0, getGlobalObject_js_1.getGlobalObject)('utils/assert.ts'
|
|
|
35
35
|
(0, assertSingleInstance_js_1.assertSingleInstance_onAssertModuleLoad)();
|
|
36
36
|
const projectTag = `[vike]`;
|
|
37
37
|
const projectTagWithVersion = `[vike@${projectInfo_js_1.projectInfo.projectVersion}]`;
|
|
38
|
+
const bugTag = 'Bug';
|
|
38
39
|
const numberOfStackTraceLinesToRemove = 2;
|
|
39
40
|
function assert(condition, debugInfo) {
|
|
40
41
|
if (condition)
|
|
@@ -54,7 +55,7 @@ function assert(condition, debugInfo) {
|
|
|
54
55
|
.filter(Boolean)
|
|
55
56
|
.join(' ');
|
|
56
57
|
errMsg = addWhitespace(errMsg);
|
|
57
|
-
errMsg = addPrefixAssertType(errMsg,
|
|
58
|
+
errMsg = addPrefixAssertType(errMsg, bugTag);
|
|
58
59
|
errMsg = addPrefixProjctName(errMsg, true);
|
|
59
60
|
const internalError = (0, createErrorWithCleanStackTrace_js_1.createErrorWithCleanStackTrace)(errMsg, numberOfStackTraceLinesToRemove);
|
|
60
61
|
globalObject.onBeforeLog?.();
|
|
@@ -165,7 +166,7 @@ function getAssertErrMsg(thing) {
|
|
|
165
166
|
const showVikeVersion = tag === projectTagWithVersion;
|
|
166
167
|
const errStackPrefix = `Error: ${tag}`;
|
|
167
168
|
if (errStack?.startsWith(errStackPrefix)) {
|
|
168
|
-
if (globalObject.showStackTraceList.has(thing)) {
|
|
169
|
+
if (globalObject.showStackTraceList.has(thing) || isBug(thing)) {
|
|
169
170
|
const assertMsg = errStack.slice(errStackPrefix.length);
|
|
170
171
|
return { assertMsg, showVikeVersion };
|
|
171
172
|
}
|
|
@@ -184,7 +185,7 @@ function overwriteAssertProductionLogger(logger) {
|
|
|
184
185
|
globalObject.logger = logger;
|
|
185
186
|
}
|
|
186
187
|
function isBug(err) {
|
|
187
|
-
return
|
|
188
|
+
return String(err).includes(`[${bugTag}]`);
|
|
188
189
|
}
|
|
189
190
|
function setAlwaysShowStackTrace() {
|
|
190
191
|
globalObject.alwaysShowStackTrace = true;
|
|
@@ -33,16 +33,19 @@ function onSetupRuntime() {
|
|
|
33
33
|
debug('assertSetup()', new Error().stack);
|
|
34
34
|
if (isTest())
|
|
35
35
|
return;
|
|
36
|
+
assertNodeEnvIsNotUndefinedString();
|
|
36
37
|
if (!isViteLoaded()) {
|
|
37
38
|
// TODO: make it assertUsage() again once https://github.com/vikejs/vike/issues/1528 is implemented.
|
|
38
|
-
(0, assert_js_1.assertWarning)(!isNodeEnvDev(), `The ${getEnvDescription()}, which
|
|
39
|
+
(0, assert_js_1.assertWarning)(!isNodeEnvDev(), `The ${getEnvDescription()}, which is contradictory because the environment seems to be a production environment (Vite isn't loaded), see https://vike.dev/NODE_ENV`, { onlyOnce: true });
|
|
39
40
|
(0, assert_js_1.assertUsage)(!setup.vikeVitePlugin, "Loading Vike's Vite plugin (the vike/plugin module) is prohibited in production.");
|
|
40
41
|
// This assert() one of the main goal of this file: it ensures assertIsNotProductionRuntime()
|
|
41
42
|
(0, assert_js_1.assert)(!setup.shouldNotBeProduction);
|
|
42
43
|
}
|
|
43
44
|
else {
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
if (!setup.vitePreviewServer && !setup.isPrerendering) {
|
|
46
|
+
// TODO: make it assertUsage() again once https://github.com/vikejs/vike/issues/1528 is implemented.
|
|
47
|
+
(0, assert_js_1.assertWarning)(isNodeEnvDev(), `The ${getEnvDescription()}, but Vite is loaded which is prohibited in production, see https://vike.dev/NODE_ENV`, { onlyOnce: true });
|
|
48
|
+
}
|
|
46
49
|
// These two assert() calls aren't that interesting
|
|
47
50
|
(0, assert_js_1.assert)(setup.vikeVitePlugin);
|
|
48
51
|
(0, assert_js_1.assert)(setup.shouldNotBeProduction);
|
|
@@ -62,7 +65,7 @@ function onSetupBuild() {
|
|
|
62
65
|
}
|
|
63
66
|
function onSetupPrerender() {
|
|
64
67
|
markSetup_isPrerendering();
|
|
65
|
-
if (
|
|
68
|
+
if (getNodeEnv())
|
|
66
69
|
assertUsageNodeEnvIsNotDev('pre-rendering');
|
|
67
70
|
setNodeEnvProduction();
|
|
68
71
|
}
|
|
@@ -71,7 +74,7 @@ function isViteLoaded() {
|
|
|
71
74
|
return setup.viteDevServer || setup.vitePreviewServer || setup.isViteDev !== undefined;
|
|
72
75
|
}
|
|
73
76
|
function isTest() {
|
|
74
|
-
return (0, isVitest_js_1.isVitest)() ||
|
|
77
|
+
return (0, isVitest_js_1.isVitest)() || isNodeEnv('test');
|
|
75
78
|
}
|
|
76
79
|
// Called by Vite hook configureServer()
|
|
77
80
|
function markSetup_viteDevServer() {
|
|
@@ -110,26 +113,54 @@ function assertUsageNodeEnvIsNotDev(operation) {
|
|
|
110
113
|
(0, assert_js_1.assertWarning)(false, `The ${getEnvDescription()} which is forbidden upon ${operation}, see https://vike.dev/NODE_ENV`, { onlyOnce: true });
|
|
111
114
|
}
|
|
112
115
|
function getEnvDescription() {
|
|
113
|
-
const
|
|
114
|
-
const
|
|
115
|
-
const envType = `${(isDev ? 'development' : 'production')} environment`;
|
|
116
|
-
const nodeEnvDesc = `environment is set to be a ${picocolors_1.default.bold(envType)} by ${picocolors_1.default.cyan(`process.env.NODE_ENV===${JSON.stringify(nodeEnv)}`)}`;
|
|
116
|
+
const envType = `${(isNodeEnvDev() ? 'development' : 'production')} environment`;
|
|
117
|
+
const nodeEnvDesc = `environment is set to be a ${picocolors_1.default.bold(envType)} by ${picocolors_1.default.cyan(`process.env.NODE_ENV===${JSON.stringify(getNodeEnv())}`)}`;
|
|
117
118
|
return nodeEnvDesc;
|
|
118
119
|
}
|
|
120
|
+
// For example, Wrangler bug replaces `process.env.NODE_ENV` with `"undefined"`
|
|
121
|
+
// https://github.com/cloudflare/workers-sdk/issues/7886
|
|
122
|
+
function assertNodeEnvIsNotUndefinedString() {
|
|
123
|
+
const nodeEnv = getNodeEnv();
|
|
124
|
+
(0, assert_js_1.assertWarning)(nodeEnv !== 'undefined', `${picocolors_1.default.cyan('process.env.NODE_ENV==="undefined"')} which is unexpected: ${picocolors_1.default.cyan('process.env.NODE_ENV')} is allowed to be the *value* ${picocolors_1.default.cyan('undefined')} (i.e. ${picocolors_1.default.cyan('process.env.NODE_ENV===undefined')}) but it shouldn't be the *string* ${picocolors_1.default.cyan('"undefined"')} ${picocolors_1.default.underline('https://vike.dev/NODE_ENV')}`, { onlyOnce: true });
|
|
125
|
+
}
|
|
119
126
|
function isNodeEnvDev() {
|
|
120
|
-
const nodeEnv =
|
|
127
|
+
const nodeEnv = getNodeEnv();
|
|
121
128
|
// That's quite strict, let's see if some user complains
|
|
122
|
-
return
|
|
129
|
+
return nodeEnv === undefined || isNodeEnv(['development', 'dev', '']);
|
|
130
|
+
}
|
|
131
|
+
function isNodeEnv(value) {
|
|
132
|
+
const values = Array.isArray(value) ? value : [value];
|
|
133
|
+
const nodeEnv = getNodeEnv();
|
|
134
|
+
return nodeEnv !== undefined && values.includes(nodeEnv.toLowerCase());
|
|
123
135
|
}
|
|
124
|
-
function
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
136
|
+
function getNodeEnv() {
|
|
137
|
+
let val;
|
|
138
|
+
try {
|
|
139
|
+
val = process.env.NODE_ENV;
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
return undefined;
|
|
143
|
+
}
|
|
144
|
+
/*
|
|
145
|
+
// Should we show the following warning? So far I don't think so because of the following. Maybe we can show it once we enable users to disable warnings.
|
|
146
|
+
// - The warning isn't always actionable, e.g. if it's a tool that dynamically sets `process.env.NODE_ENV`.
|
|
147
|
+
// - We assume that tools use `process.env.NODE_ENV` and not someting like `const { env } = process; env.NODE_ENV`. Thus, in practice, `val` overrides `val2` so having `val!==val2` isn't an issue.
|
|
148
|
+
{
|
|
149
|
+
const val2 = process.env['NODE' + '_ENV']
|
|
150
|
+
if (val2)
|
|
151
|
+
assertWarning(
|
|
152
|
+
val === val2,
|
|
153
|
+
`Dynamically setting process.env.NODE_ENV to ${val2} hasn't any effect because process.env.NODE_ENV is being statically replaced to ${val}.`,
|
|
154
|
+
{ onlyOnce: true }
|
|
155
|
+
)
|
|
156
|
+
}
|
|
157
|
+
//*/
|
|
158
|
+
return val;
|
|
128
159
|
}
|
|
129
160
|
function setNodeEnvProduction() {
|
|
130
161
|
// The statement `process.env['NODE_ENV'] = 'production'` chokes webpack v4
|
|
131
162
|
const proc = process;
|
|
132
163
|
const { env } = proc;
|
|
133
164
|
env.NODE_ENV = 'production';
|
|
134
|
-
(0, assert_js_1.assert)(
|
|
165
|
+
(0, assert_js_1.assert)(isNodeEnv('production'));
|
|
135
166
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.catchInfiniteLoop = catchInfiniteLoop;
|
|
4
|
+
const assert_js_1 = require("./assert.js");
|
|
5
|
+
const trackers = {};
|
|
6
|
+
function catchInfiniteLoop(functionName, maxNumberOfCalls = 100, withinSeconds = 5) {
|
|
7
|
+
// Init
|
|
8
|
+
const now = new Date();
|
|
9
|
+
let tracker = (trackers[functionName] ?? (trackers[functionName] = createTracker(now)));
|
|
10
|
+
// Reset
|
|
11
|
+
const elapsedTime = now.getTime() - tracker.start.getTime();
|
|
12
|
+
if (elapsedTime > withinSeconds * 1000)
|
|
13
|
+
tracker = trackers[functionName] = createTracker(now);
|
|
14
|
+
// Count
|
|
15
|
+
tracker.count++;
|
|
16
|
+
// Error
|
|
17
|
+
const msg = `[Infinite Loop] ${functionName} called ${tracker.count} times within ${withinSeconds} seconds`;
|
|
18
|
+
if (tracker.count > maxNumberOfCalls) {
|
|
19
|
+
(0, assert_js_1.assert)(false, msg);
|
|
20
|
+
}
|
|
21
|
+
// Warning, at 50% threshold
|
|
22
|
+
if (!tracker.warned && tracker.count > maxNumberOfCalls * 0.5) {
|
|
23
|
+
// Warning is shown upon 10 calls a second, on average during 5 seconds, given the default parameters
|
|
24
|
+
(0, assert_js_1.assertWarning)(false, msg, { onlyOnce: false });
|
|
25
|
+
tracker.warned = true;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function createTracker(now) {
|
|
29
|
+
const tracker = {
|
|
30
|
+
count: 0,
|
|
31
|
+
start: now
|
|
32
|
+
};
|
|
33
|
+
return tracker;
|
|
34
|
+
}
|
package/dist/cjs/utils/debug.js
CHANGED
|
@@ -21,6 +21,7 @@ const flags = [
|
|
|
21
21
|
'vike:extractAssets',
|
|
22
22
|
'vike:extractExportNames',
|
|
23
23
|
'vike:glob',
|
|
24
|
+
'vike:globalContext',
|
|
24
25
|
'vike:log',
|
|
25
26
|
'vike:optimizeDeps',
|
|
26
27
|
'vike:outDir',
|
|
@@ -33,7 +34,7 @@ const flags = [
|
|
|
33
34
|
'vike:esbuild-resolve'
|
|
34
35
|
];
|
|
35
36
|
const flagRegex = /\bvike:[a-zA-Z-]+/g;
|
|
36
|
-
|
|
37
|
+
assertFlagsActivated();
|
|
37
38
|
function createDebugger(flag, optionsGlobal) {
|
|
38
39
|
(0, checkType_js_1.checkType)(flag);
|
|
39
40
|
(0, assert_js_1.assert)(flags.includes(flag));
|
|
@@ -76,8 +77,8 @@ function debug_(flag, options, ...msgs) {
|
|
|
76
77
|
function isDebugActivated(flag) {
|
|
77
78
|
(0, checkType_js_1.checkType)(flag);
|
|
78
79
|
(0, assert_js_1.assert)(flags.includes(flag));
|
|
79
|
-
const
|
|
80
|
-
const isActivated =
|
|
80
|
+
const flagsActivated = getFlagsActivated();
|
|
81
|
+
const isActivated = flagsActivated.includes(flag);
|
|
81
82
|
return isActivated;
|
|
82
83
|
}
|
|
83
84
|
function formatMsg(info, options, padding, position) {
|
|
@@ -140,13 +141,17 @@ function replaceFunctionSerializer(_key, value) {
|
|
|
140
141
|
}
|
|
141
142
|
return value;
|
|
142
143
|
}
|
|
143
|
-
function
|
|
144
|
-
const
|
|
145
|
-
const flagsActivated = DEBUG.match(flagRegex) ?? [];
|
|
144
|
+
function assertFlagsActivated() {
|
|
145
|
+
const flagsActivated = getFlagsActivated();
|
|
146
146
|
flagsActivated.forEach((flag) => {
|
|
147
147
|
(0, assert_js_1.assertUsage)(flags.includes(flag), `Unknown DEBUG flag ${picocolors_1.default.cyan(flag)}. Valid flags:\n${flags.map((f) => ` ${picocolors_1.default.cyan(f)}`).join('\n')}`);
|
|
148
148
|
});
|
|
149
149
|
}
|
|
150
|
+
function getFlagsActivated() {
|
|
151
|
+
const DEBUG = getDEBUG() ?? '';
|
|
152
|
+
const flagsActivated = DEBUG.match(flagRegex) ?? [];
|
|
153
|
+
return flagsActivated;
|
|
154
|
+
}
|
|
150
155
|
function getDEBUG() {
|
|
151
156
|
let DEBUG;
|
|
152
157
|
// - `process` can be undefined in edge workers
|
|
@@ -3,8 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getGlobalObject = getGlobalObject;
|
|
4
4
|
exports.assertIsSingleModuleInstance = assertIsSingleModuleInstance;
|
|
5
5
|
const assert_js_1 = require("./assert.js");
|
|
6
|
-
const projectInfo_js_1 = require("./projectInfo.js");
|
|
7
|
-
const projectKey = `_${projectInfo_js_1.projectInfo.projectName.toLowerCase()}`;
|
|
8
6
|
/** Share information across module instances. */
|
|
9
7
|
function getGlobalObject(
|
|
10
8
|
// We use the filename (or file path) as key. There should be only one getGlobalObject() usage per file. Thus the key should be unique, assuming the filename (or file path) is unique.
|
|
@@ -21,6 +19,7 @@ key) {
|
|
|
21
19
|
(0, assert_js_1.assert)(!(key in globalObjects));
|
|
22
20
|
}
|
|
23
21
|
function getGlobalObjects() {
|
|
22
|
+
const projectKey = '_vike';
|
|
24
23
|
// @ts-ignore
|
|
25
24
|
const globalObjects = (globalThis[projectKey] = globalThis[projectKey] || {});
|
|
26
25
|
return globalObjects;
|
package/dist/cjs/utils/isDev.js
CHANGED
|
@@ -7,6 +7,8 @@ const assert_js_1 = require("./assert.js");
|
|
|
7
7
|
function isDevCheck(configEnv) {
|
|
8
8
|
const { isPreview, command } = configEnv;
|
|
9
9
|
// Released at vite@5.1.0 which is guaranteed with `assertVersion('Vite', version, '5.1.0')`
|
|
10
|
+
// - Release: https://github.com/vitejs/vite/blob/6f7466e6211027686f40ad7e4ce6ec8477414546/packages/vite/CHANGELOG.md#510-beta4-2024-01-26:~:text=fix(preview)%3A-,set%20isPreview%20true,-(%2315695)%20(93fce55
|
|
11
|
+
// - Surprisingly, this assert() can fail: https://github.com/vikejs/vike/issues/2120
|
|
10
12
|
(0, assert_js_1.assert)(typeof isPreview === 'boolean');
|
|
11
13
|
return command === 'serve' && !isPreview;
|
|
12
14
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makePublicCopy = makePublicCopy;
|
|
4
|
+
const assert_js_1 = require("./assert.js");
|
|
5
|
+
const objectKeys_js_1 = require("./objectKeys.js");
|
|
6
|
+
/** Prefix internal properties with `_` + show warning */
|
|
7
|
+
function makePublicCopy(obj, objName, propsPublic, propsInternalNoWarning) {
|
|
8
|
+
const objPublic = {};
|
|
9
|
+
(0, objectKeys_js_1.objectKeys)(obj).forEach((key) => {
|
|
10
|
+
const val = obj[key];
|
|
11
|
+
if (propsPublic.includes(key)) {
|
|
12
|
+
objPublic[key] = val;
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
const keyPublic = key.startsWith('_') ? key : `_${key}`;
|
|
16
|
+
if (propsInternalNoWarning?.includes(key)) {
|
|
17
|
+
// @ts-expect-error
|
|
18
|
+
objPublic[keyPublic] = val;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
Object.defineProperty(objPublic, keyPublic, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get() {
|
|
24
|
+
(0, assert_js_1.assertWarning)(false, `Using internal ${objName}.${keyPublic} which may break in any minor version update. Reach out on GitHub and elaborate your use case so that the Vike team can add official support for your use case.`, { onlyOnce: true });
|
|
25
|
+
return val;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
return objPublic;
|
|
32
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.objectReplace = objectReplace;
|
|
4
|
+
function objectReplace(obj, objNew, except) {
|
|
5
|
+
Object.keys(obj)
|
|
6
|
+
.filter((key) => !except?.includes(key))
|
|
7
|
+
.forEach((key) => delete obj[key]);
|
|
8
|
+
Object.assign(obj, objNew);
|
|
9
|
+
}
|
|
@@ -1,14 +1,12 @@
|
|
|
1
|
+
export { setGlobalContext_buildEntry } from '../node/runtime/globalContext.js';
|
|
1
2
|
export { route, getPagesAndRoutes };
|
|
2
3
|
export type { PageRoutes, PageFile, PageConfigRuntime as PageConfig };
|
|
3
4
|
export { getMiddlewares };
|
|
4
5
|
import { route as routeInternal, type PageRoutes } from '../shared/route/index.js';
|
|
5
|
-
import {
|
|
6
|
+
import type { PageFile } from '../shared/getPageFiles/getPageFileObject.js';
|
|
6
7
|
import { PageConfigRuntime } from '../shared/page-configs/PageConfig.js';
|
|
7
8
|
/**
|
|
8
|
-
* Used by {@link https://github.com/magne4000/vite-plugin-vercel|vite-plugin-vercel}
|
|
9
|
-
* to compute some rewrite rules and extract { isr } configs.
|
|
10
|
-
* Needs `import 'vike/__internal/setup'`
|
|
11
|
-
* @param config
|
|
9
|
+
* Used by {@link https://github.com/magne4000/vite-plugin-vercel|vite-plugin-vercel} to compute some rewrite rules and extract { isr } configs.
|
|
12
10
|
*/
|
|
13
11
|
declare function getPagesAndRoutes(): Promise<{
|
|
14
12
|
pageRoutes: PageRoutes;
|
|
@@ -1,24 +1,22 @@
|
|
|
1
|
+
// Internals needed by Vike
|
|
2
|
+
export { setGlobalContext_buildEntry } from '../node/runtime/globalContext.js';
|
|
1
3
|
// Internals needed by vite-plugin-vercel
|
|
2
4
|
export { route, getPagesAndRoutes };
|
|
3
5
|
// Internals needed by experimental implementation of vike-telefunc
|
|
4
6
|
export { getMiddlewares };
|
|
5
7
|
import { route as routeInternal } from '../shared/route/index.js';
|
|
6
|
-
import { getPageFilesAll } from '../shared/getPageFiles.js';
|
|
8
|
+
import { getPageFilesAll } from '../shared/getPageFiles/getPageFiles.js';
|
|
7
9
|
import { getGlobalContext, initGlobalContext_getGlobalContextAsync } from '../node/runtime/globalContext.js';
|
|
8
10
|
import { setNodeEnvProduction } from '../utils/assertSetup.js';
|
|
9
|
-
import { getRenderContext } from '../node/runtime/renderPage/renderPageAlreadyRouted.js';
|
|
10
11
|
/**
|
|
11
|
-
* Used by {@link https://github.com/magne4000/vite-plugin-vercel|vite-plugin-vercel}
|
|
12
|
-
* to compute some rewrite rules and extract { isr } configs.
|
|
13
|
-
* Needs `import 'vike/__internal/setup'`
|
|
14
|
-
* @param config
|
|
12
|
+
* Used by {@link https://github.com/magne4000/vite-plugin-vercel|vite-plugin-vercel} to compute some rewrite rules and extract { isr } configs.
|
|
15
13
|
*/
|
|
16
14
|
async function getPagesAndRoutes() {
|
|
17
15
|
setNodeEnvProduction();
|
|
18
|
-
const
|
|
16
|
+
const globalContext = getGlobalContext();
|
|
19
17
|
const {
|
|
20
18
|
//
|
|
21
|
-
pageRoutes, pageFilesAll, pageConfigs, allPageIds } =
|
|
19
|
+
pageRoutes, pageFilesAll, pageConfigs, allPageIds } = globalContext;
|
|
22
20
|
return {
|
|
23
21
|
pageRoutes,
|
|
24
22
|
pageFilesAll,
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
export { createPageContext };
|
|
2
2
|
import { getPageContextUrlComputed } from '../../shared/getPageContextUrlComputed.js';
|
|
3
|
-
import { getPageFilesAll } from '../../shared/getPageFiles.js';
|
|
3
|
+
import { getPageFilesAll, setPageFiles } from '../../shared/getPageFiles/getPageFiles.js';
|
|
4
4
|
import { loadPageRoutes } from '../../shared/route/loadPageRoutes.js';
|
|
5
5
|
import { getBaseServer } from './getBaseServer.js';
|
|
6
6
|
import { assert, isBaseServer, getGlobalObject, objectAssign } from './utils.js';
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
import * as pageFilesExports from 'virtual:vike:importUserCode:client:client-routing';
|
|
7
9
|
const globalObject = getGlobalObject('createPageContext.ts', {});
|
|
10
|
+
setPageFiles(pageFilesExports);
|
|
8
11
|
async function createPageContext(urlOriginal) {
|
|
9
12
|
if (!globalObject.pageFilesData) {
|
|
10
13
|
globalObject.pageFilesData = await getPageFilesAll(true);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { assertClientRouting } from '../../utils/assertRoutingType.js';
|
|
2
2
|
assertClientRouting();
|
|
3
|
-
import './pageFiles';
|
|
4
3
|
import { initClientRouter } from './initClientRouter.js';
|
|
5
4
|
import { assertSingleInstance_onClientEntryClientRouting } from './utils.js';
|
|
6
5
|
import { removeFoucBuster } from '../shared/removeFoucBuster.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { setPageContextCurrent };
|
|
2
2
|
export { getPageContextCurrent };
|
|
3
|
-
import type {
|
|
4
|
-
type PageContextCurrent =
|
|
3
|
+
import type { PageConfigUserFriendly } from '../../shared/getPageFiles.js';
|
|
4
|
+
type PageContextCurrent = PageConfigUserFriendly & {
|
|
5
5
|
urlPathname: string;
|
|
6
6
|
};
|
|
7
7
|
declare function getPageContextCurrent(): null | PageContextCurrent;
|
|
@@ -5,7 +5,7 @@ export { getPageContextFromClientHooks };
|
|
|
5
5
|
export { setPageContextInitIsPassedToClient };
|
|
6
6
|
export type { PageContextFromServerHooks };
|
|
7
7
|
export type { PageContextFromClientHooks };
|
|
8
|
-
import type {
|
|
8
|
+
import type { PageConfigUserFriendly, PageFile } from '../../shared/getPageFiles.js';
|
|
9
9
|
import type { PageConfigRuntime } from '../../shared/page-configs/PageConfig.js';
|
|
10
10
|
type PageContext = {
|
|
11
11
|
urlOriginal: string;
|
|
@@ -21,9 +21,9 @@ declare function getPageContextFromHooks_serialized(): PageContextSerialized & {
|
|
|
21
21
|
routeParams: Record<string, string>;
|
|
22
22
|
_hasPageContextFromServer: true;
|
|
23
23
|
};
|
|
24
|
-
declare function getPageContextFromHooks_isHydration(pageContext: PageContextSerialized & PageContext &
|
|
24
|
+
declare function getPageContextFromHooks_isHydration(pageContext: PageContextSerialized & PageContext & PageConfigUserFriendly & {
|
|
25
25
|
_hasPageContextFromServer: true;
|
|
26
|
-
}): Promise<PageContextSerialized & PageContext &
|
|
26
|
+
}): Promise<PageContextSerialized & PageContext & PageConfigUserFriendly & {
|
|
27
27
|
_hasPageContextFromServer: true;
|
|
28
28
|
} & {
|
|
29
29
|
_hasPageContextFromClient: boolean;
|
|
@@ -45,5 +45,5 @@ type PageContextFromClientHooks = {
|
|
|
45
45
|
declare function getPageContextFromClientHooks(pageContext: {
|
|
46
46
|
pageId: string;
|
|
47
47
|
_hasPageContextFromServer: boolean;
|
|
48
|
-
} & PageContext &
|
|
48
|
+
} & PageContext & PageConfigUserFriendly, isErrorPage: boolean): Promise<PageContextFromClientHooks>;
|
|
49
49
|
declare function setPageContextInitIsPassedToClient(pageContext: Record<string, unknown>): void;
|