vike 0.4.144 → 0.4.145-commit-2520555
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 +6 -2
- package/dist/cjs/node/plugin/plugins/buildConfig.js +3 -3
- package/dist/cjs/node/plugin/plugins/commonConfig.js +0 -3
- package/dist/cjs/node/plugin/plugins/config/index.js +3 -3
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +8 -8
- package/dist/cjs/node/plugin/plugins/devConfig/index.js +1 -0
- package/dist/cjs/node/plugin/plugins/envVars.js +34 -20
- package/dist/cjs/node/plugin/plugins/importBuild/index.js +3 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/index.js +3 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +5 -4
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +12 -12
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +249 -228
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +8 -6
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +36 -14
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/helpers.js +1 -14
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +18 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.js +15 -17
- package/dist/cjs/node/plugin/plugins/previewConfig.js +11 -2
- package/dist/cjs/node/prerender/runPrerender.js +34 -26
- package/dist/cjs/node/prerender/utils.js +1 -1
- package/dist/cjs/node/runtime/html/serializePageContextClientSide.js +20 -6
- package/dist/cjs/node/runtime/renderPage/debugPageFiles.js +5 -5
- package/dist/cjs/node/runtime/renderPage/log404/index.js +28 -17
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +3 -3
- package/dist/cjs/node/runtime/renderPage.js +3 -3
- package/dist/cjs/node/runtime/utils.js +1 -1
- package/dist/cjs/node/shared/getClientEntryFilePath.js +2 -2
- package/dist/cjs/node/shared/getConfigVike.js +4 -1
- package/dist/cjs/shared/addUrlComputedProps.js +24 -12
- package/dist/cjs/shared/getPageFiles/analyzeClientSide.js +4 -6
- package/dist/cjs/shared/getPageFiles/getExports.js +3 -3
- package/dist/cjs/shared/hooks/getHook.js +1 -1
- package/dist/cjs/shared/page-configs/getExportPath.js +3 -3
- package/dist/cjs/shared/page-configs/helpers/getConfigDefinedAtString.js +43 -0
- package/dist/cjs/shared/page-configs/helpers/getConfigValue.js +44 -0
- package/dist/cjs/shared/page-configs/helpers.js +33 -0
- package/dist/cjs/shared/page-configs/loadConfigValues.js +2 -2
- package/dist/cjs/shared/page-configs/serialize/parseConfigValuesImported.js +14 -13
- package/dist/cjs/shared/page-configs/serialize/parsePageConfigs.js +2 -2
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValue.js +9 -10
- package/dist/cjs/shared/route/abort.js +1 -1
- package/dist/cjs/shared/route/executeOnBeforeRouteHook.js +41 -15
- package/dist/cjs/shared/route/index.js +22 -32
- package/dist/cjs/shared/route/loadPageRoutes.js +11 -10
- package/dist/cjs/shared/route/noRouteMatch.js +4 -0
- package/dist/cjs/shared/route/resolveRouteFunction.js +1 -1
- package/dist/cjs/shared/utils.js +1 -1
- package/dist/cjs/utils/getFilePathAbsolute.js +11 -11
- package/dist/cjs/utils/isExternalLink.js +7 -0
- package/dist/cjs/utils/{hasPropertyGetter.js → isPropertyGetter.js} +3 -3
- package/dist/cjs/utils/onPageVisibilityChange.js +19 -0
- package/dist/cjs/utils/parseUrl.js +1 -1
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/cjs/utils/truncateString.js +12 -7
- package/dist/esm/__internal/index.d.ts +6 -3
- package/dist/esm/__internal/index.js +8 -3
- package/dist/esm/client/client-routing-runtime/createPageContext.d.ts +2 -3
- package/dist/esm/client/client-routing-runtime/createPageContext.js +3 -4
- package/dist/esm/client/client-routing-runtime/entry.js +2 -2
- package/dist/esm/client/client-routing-runtime/getBaseServer.d.ts +2 -1
- package/dist/esm/client/client-routing-runtime/getBaseServer.js +2 -1
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.d.ts +39 -0
- package/dist/esm/client/client-routing-runtime/{getPageContext.js → getPageContextFromHooks.js} +50 -79
- package/dist/esm/client/client-routing-runtime/history.d.ts +3 -1
- package/dist/esm/client/client-routing-runtime/history.js +31 -9
- package/dist/esm/client/client-routing-runtime/installClientRouter.d.ts +2 -0
- package/dist/esm/client/client-routing-runtime/installClientRouter.js +22 -0
- package/dist/esm/client/client-routing-runtime/isClientSideRoutable.d.ts +8 -0
- package/dist/esm/client/client-routing-runtime/isClientSideRoutable.js +12 -0
- package/dist/esm/client/client-routing-runtime/navigate.d.ts +0 -2
- package/dist/esm/client/client-routing-runtime/navigate.js +9 -8
- package/dist/esm/client/client-routing-runtime/onBrowserHistoryNavigation.d.ts +4 -0
- package/dist/esm/client/client-routing-runtime/onBrowserHistoryNavigation.js +63 -0
- package/dist/esm/client/client-routing-runtime/onLinkClick.d.ts +2 -0
- package/dist/esm/client/client-routing-runtime/onLinkClick.js +40 -0
- package/dist/esm/client/client-routing-runtime/prefetch.js +54 -29
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.d.ts +19 -0
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +347 -0
- package/dist/esm/client/client-routing-runtime/scrollRestoration.d.ts +6 -0
- package/dist/esm/client/client-routing-runtime/scrollRestoration.js +25 -0
- package/dist/esm/client/client-routing-runtime/setScrollPosition.d.ts +7 -0
- package/dist/esm/client/client-routing-runtime/setScrollPosition.js +77 -0
- package/dist/esm/client/client-routing-runtime/skipLink.d.ts +0 -1
- package/dist/esm/client/client-routing-runtime/skipLink.js +9 -5
- package/dist/esm/client/client-routing-runtime/utils.d.ts +2 -0
- package/dist/esm/client/client-routing-runtime/utils.js +2 -0
- package/dist/esm/client/server-routing-runtime/getPageContext.js +1 -1
- package/dist/esm/client/shared/executeOnRenderClientHook.js +6 -5
- package/dist/esm/client/shared/getPageContextProxyForUser.js +13 -7
- package/dist/esm/client/shared/loadPageFilesClientSide.d.ts +8 -3
- package/dist/esm/client/shared/loadPageFilesClientSide.js +5 -5
- package/dist/esm/node/plugin/plugins/buildConfig.js +3 -3
- package/dist/esm/node/plugin/plugins/commonConfig.js +0 -3
- package/dist/esm/node/plugin/plugins/config/index.js +4 -4
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +9 -9
- package/dist/esm/node/plugin/plugins/devConfig/index.js +1 -0
- package/dist/esm/node/plugin/plugins/envVars.d.ts +2 -0
- package/dist/esm/node/plugin/plugins/envVars.js +35 -20
- package/dist/esm/node/plugin/plugins/importBuild/index.js +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/index.js +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +2 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +5 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +12 -12
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +2 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +250 -229
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +7 -5
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +37 -15
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/helpers.js +1 -14
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.d.ts +7 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +15 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.js +16 -18
- package/dist/esm/node/plugin/plugins/previewConfig.js +11 -2
- package/dist/esm/node/prerender/runPrerender.js +29 -21
- package/dist/esm/node/prerender/utils.d.ts +1 -1
- package/dist/esm/node/prerender/utils.js +1 -1
- package/dist/esm/node/runtime/html/serializePageContextClientSide.js +21 -7
- package/dist/esm/node/runtime/renderPage/debugPageFiles.d.ts +5 -5
- package/dist/esm/node/runtime/renderPage/debugPageFiles.js +5 -5
- package/dist/esm/node/runtime/renderPage/loadPageFilesServerSide.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/log404/index.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/log404/index.js +28 -16
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +2 -2
- package/dist/esm/node/runtime/renderPage.js +3 -3
- package/dist/esm/node/runtime/utils.d.ts +1 -1
- package/dist/esm/node/runtime/utils.js +1 -1
- package/dist/esm/node/shared/getClientEntryFilePath.js +1 -1
- package/dist/esm/node/shared/getConfigVike.d.ts +2 -1
- package/dist/esm/node/shared/getConfigVike.js +4 -1
- package/dist/esm/shared/addUrlComputedProps.d.ts +1 -0
- package/dist/esm/shared/addUrlComputedProps.js +25 -13
- package/dist/esm/shared/getPageFiles/analyzeClientSide.js +2 -4
- package/dist/esm/shared/getPageFiles/getExports.js +2 -2
- package/dist/esm/shared/hooks/getHook.js +1 -1
- package/dist/esm/shared/page-configs/PageConfig.d.ts +55 -31
- package/dist/esm/shared/page-configs/getExportPath.d.ts +1 -1
- package/dist/esm/shared/page-configs/getExportPath.js +3 -3
- package/dist/esm/shared/page-configs/helpers/getConfigDefinedAtString.d.ts +7 -0
- package/dist/esm/shared/page-configs/helpers/getConfigDefinedAtString.js +37 -0
- package/dist/esm/shared/page-configs/helpers/getConfigValue.d.ts +14 -0
- package/dist/esm/shared/page-configs/helpers/getConfigValue.js +38 -0
- package/dist/esm/shared/page-configs/helpers.d.ts +13 -0
- package/dist/esm/shared/page-configs/helpers.js +27 -0
- package/dist/esm/shared/page-configs/loadConfigValues.js +2 -2
- package/dist/esm/shared/page-configs/serialize/PageConfigSerialized.d.ts +4 -4
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.js +15 -11
- package/dist/esm/shared/page-configs/serialize/parsePageConfigs.js +2 -2
- package/dist/esm/shared/page-configs/serialize/serializeConfigValue.js +9 -10
- package/dist/esm/shared/route/abort.js +1 -1
- package/dist/esm/shared/route/executeOnBeforeRouteHook.d.ts +5 -8
- package/dist/esm/shared/route/executeOnBeforeRouteHook.js +41 -15
- package/dist/esm/shared/route/index.d.ts +12 -10
- package/dist/esm/shared/route/index.js +23 -33
- package/dist/esm/shared/route/loadPageRoutes.js +8 -7
- package/dist/esm/shared/route/noRouteMatch.d.ts +1 -0
- package/dist/esm/shared/route/noRouteMatch.js +1 -0
- package/dist/esm/shared/route/resolveRouteFunction.js +1 -1
- package/dist/esm/shared/utils.d.ts +1 -1
- package/dist/esm/shared/utils.js +1 -1
- package/dist/esm/utils/getFilePathAbsolute.d.ts +1 -1
- package/dist/esm/utils/getFilePathAbsolute.js +11 -11
- package/dist/esm/utils/isPropertyGetter.d.ts +1 -0
- package/dist/esm/utils/{hasPropertyGetter.js → isPropertyGetter.js} +1 -1
- package/dist/esm/utils/onPageVisibilityChange.d.ts +4 -0
- package/dist/esm/utils/onPageVisibilityChange.js +16 -0
- package/dist/esm/utils/parseUrl.js +1 -1
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/dist/esm/utils/projectInfo.js +1 -1
- package/dist/esm/utils/truncateString.d.ts +2 -1
- package/dist/esm/utils/truncateString.js +10 -7
- package/node/cli/bin-entry.js +1 -1
- package/package.json +2 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.js +0 -16
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/isConfigEnvMatch.js +0 -13
- package/dist/cjs/shared/page-configs/utils.js +0 -103
- package/dist/esm/client/client-routing-runtime/getPageContext.d.ts +0 -29
- package/dist/esm/client/client-routing-runtime/getPageId.d.ts +0 -10
- package/dist/esm/client/client-routing-runtime/getPageId.js +0 -17
- package/dist/esm/client/client-routing-runtime/navigationState.d.ts +0 -5
- package/dist/esm/client/client-routing-runtime/navigationState.js +0 -14
- package/dist/esm/client/client-routing-runtime/skipLink/isClientSideRoutable.d.ts +0 -2
- package/dist/esm/client/client-routing-runtime/skipLink/isClientSideRoutable.js +0 -15
- package/dist/esm/client/client-routing-runtime/useClientRouter.d.ts +0 -6
- package/dist/esm/client/client-routing-runtime/useClientRouter.js +0 -493
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.d.ts +0 -24
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.js +0 -13
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isConfigEnvMatch.d.ts +0 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isConfigEnvMatch.js +0 -10
- package/dist/esm/shared/page-configs/utils.d.ts +0 -35
- package/dist/esm/shared/page-configs/utils.js +0 -97
- package/dist/esm/utils/hasPropertyGetter.d.ts +0 -1
- /package/dist/esm/{client/client-routing-runtime → utils}/isExternalLink.d.ts +0 -0
- /package/dist/esm/{client/client-routing-runtime → utils}/isExternalLink.js +0 -0
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// Internal functions of vike needed by other plugins are exported via this file
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
3
|
exports.getPagesAndRoutes = exports.route = void 0;
|
|
5
4
|
const index_js_1 = require("../shared/route/index.js");
|
|
6
|
-
Object.defineProperty(exports, "route", { enumerable: true, get: function () { return index_js_1.route; } });
|
|
7
5
|
const globalContext_js_1 = require("../node/runtime/globalContext.js");
|
|
8
6
|
const nodeEnv_js_1 = require("../utils/nodeEnv.js");
|
|
9
7
|
const assert_js_1 = require("../utils/assert.js");
|
|
@@ -29,3 +27,9 @@ async function getPagesAndRoutes() {
|
|
|
29
27
|
};
|
|
30
28
|
}
|
|
31
29
|
exports.getPagesAndRoutes = getPagesAndRoutes;
|
|
30
|
+
async function route(pageContext) {
|
|
31
|
+
const pageContextFromRoute = await (0, index_js_1.route)(pageContext);
|
|
32
|
+
// Old interface
|
|
33
|
+
return { pageContextAddendum: pageContextFromRoute };
|
|
34
|
+
}
|
|
35
|
+
exports.route = route;
|
|
@@ -7,7 +7,7 @@ exports.analyzeClientEntries = exports.assertRollupInput = exports.buildConfig =
|
|
|
7
7
|
const utils_js_1 = require("../utils.js");
|
|
8
8
|
const virtualFileImportUserCode_js_1 = require("../../shared/virtual-files/virtualFileImportUserCode.js");
|
|
9
9
|
const getVikeConfig_js_1 = require("./importUserCode/v1-design/getVikeConfig.js");
|
|
10
|
-
const
|
|
10
|
+
const helpers_js_1 = require("../../../shared/page-configs/helpers.js");
|
|
11
11
|
const findPageFiles_js_1 = require("../shared/findPageFiles.js");
|
|
12
12
|
const getConfigVike_js_1 = require("../../shared/getConfigVike.js");
|
|
13
13
|
const virtualFilePageConfigValuesAll_js_1 = require("../../shared/virtual-files/virtualFilePageConfigValuesAll.js");
|
|
@@ -73,7 +73,7 @@ exports.buildConfig = buildConfig;
|
|
|
73
73
|
async function getEntries(config) {
|
|
74
74
|
const configVike = await (0, getConfigVike_js_1.getConfigVike)(config);
|
|
75
75
|
const pageFileEntries = await getPageFileEntries(config, configVike.includeAssetsImportedByServer); // TODO/v1-release: remove
|
|
76
|
-
const { pageConfigs } = await (0, getVikeConfig_js_1.getVikeConfig)(config
|
|
76
|
+
const { pageConfigs } = await (0, getVikeConfig_js_1.getVikeConfig)(config, false);
|
|
77
77
|
(0, utils_js_1.assertUsage)(Object.keys(pageFileEntries).length !== 0 || pageConfigs.length !== 0, 'At least one page should be defined, see https://vike.dev/add');
|
|
78
78
|
if ((0, utils_js_1.viteIsSSR)(config)) {
|
|
79
79
|
const serverEntries = analyzeServerEntries(pageConfigs);
|
|
@@ -112,7 +112,7 @@ function analyzeClientEntries(pageConfigs, config) {
|
|
|
112
112
|
let clientEntries = {};
|
|
113
113
|
let clientFilePaths = [];
|
|
114
114
|
pageConfigs.forEach((pageConfig) => {
|
|
115
|
-
const configValue = (0,
|
|
115
|
+
const configValue = (0, helpers_js_1.getConfigValue)(pageConfig, 'clientRouting', 'boolean');
|
|
116
116
|
if (configValue?.value) {
|
|
117
117
|
hasClientRouting = true;
|
|
118
118
|
}
|
|
@@ -17,20 +17,20 @@ function resolveVikeConfig(vikeConfig) {
|
|
|
17
17
|
name: 'vike:resolveVikeConfig',
|
|
18
18
|
enforce: 'pre',
|
|
19
19
|
async configResolved(config) {
|
|
20
|
-
const promise =
|
|
20
|
+
const promise = getConfigVikPromise(vikeConfig, config);
|
|
21
21
|
config.configVikePromise = promise;
|
|
22
22
|
await promise;
|
|
23
23
|
}
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
26
|
exports.resolveVikeConfig = resolveVikeConfig;
|
|
27
|
-
async function
|
|
27
|
+
async function getConfigVikPromise(vikeConfig, config) {
|
|
28
28
|
const fromPluginOptions = (vikeConfig ?? {});
|
|
29
29
|
const fromViteConfig = (config.vike ?? {});
|
|
30
30
|
const fromStemPackages = await (0, findConfigVikeFromStemPackages_js_1.findConfigVikeFromStemPackages)(config.root);
|
|
31
31
|
const configs = [fromPluginOptions, ...fromStemPackages, fromViteConfig];
|
|
32
32
|
const extensions = (0, resolveExtensions_js_1.resolveExtensions)(configs, config);
|
|
33
|
-
const { globalVikeConfig: fromPlusConfigFile } = await (0, getVikeConfig_js_1.getVikeConfig)(config
|
|
33
|
+
const { globalVikeConfig: fromPlusConfigFile } = await (0, getVikeConfig_js_1.getVikeConfig)(config, (0, utils_js_1.isDev2)(config), false, extensions);
|
|
34
34
|
configs.push(fromPlusConfigFile);
|
|
35
35
|
(0, assertVikeConfig_js_1.assertVikeConfig)(fromPlusConfigFile, ({ prop, errMsg }) => {
|
|
36
36
|
// TODO: add config file path ?
|
|
@@ -8,7 +8,7 @@ const getConfigValueSourcesRelevant_js_1 = require("../../shared/getConfigValueS
|
|
|
8
8
|
const buildConfig_js_1 = require("../buildConfig.js");
|
|
9
9
|
const virtualFileImportUserCode_js_1 = require("../../../shared/virtual-files/virtualFileImportUserCode.js");
|
|
10
10
|
async function determineOptimizeDeps(config, configVike, isDev) {
|
|
11
|
-
const { pageConfigs } = await (0, getVikeConfig_js_1.getVikeConfig)(config
|
|
11
|
+
const { pageConfigs } = await (0, getVikeConfig_js_1.getVikeConfig)(config, isDev);
|
|
12
12
|
const { entries, include } = await getPageDeps(config, pageConfigs, isDev);
|
|
13
13
|
{
|
|
14
14
|
// This actually doesn't work: Vite's dep optimizer doesn't seem to be able to crawl virtual files.
|
|
@@ -37,18 +37,18 @@ async function getPageDeps(config, pageConfigs, isDev) {
|
|
|
37
37
|
configValueSourcesRelevant.forEach((configValueSource) => {
|
|
38
38
|
if (!configValueSource.valueIsImportedAtRuntime)
|
|
39
39
|
return;
|
|
40
|
-
const {
|
|
40
|
+
const { definedAt, configEnv } = configValueSource;
|
|
41
41
|
if (configEnv !== 'client-only' && configEnv !== 'server-and-client')
|
|
42
42
|
return;
|
|
43
|
-
if (
|
|
44
|
-
const {
|
|
45
|
-
(0, utils_js_1.assert)(
|
|
43
|
+
if (definedAt.filePathRelativeToUserRootDir !== null) {
|
|
44
|
+
const { filePathAbsoluteFilesystem } = definedAt;
|
|
45
|
+
(0, utils_js_1.assert)(filePathAbsoluteFilesystem);
|
|
46
46
|
// Surprisingly Vite expects entries to be absolute paths
|
|
47
|
-
entries.push(
|
|
47
|
+
entries.push(filePathAbsoluteFilesystem);
|
|
48
48
|
}
|
|
49
49
|
else {
|
|
50
|
-
// Adding
|
|
51
|
-
const { importPathAbsolute } =
|
|
50
|
+
// Adding definedAt.filePathAbsoluteFilesystem doesn't work for npm packages, I guess because of Vite's config.server.fs.allow
|
|
51
|
+
const { importPathAbsolute } = definedAt;
|
|
52
52
|
(0, utils_js_1.assert)(importPathAbsolute);
|
|
53
53
|
// We need to differentiate between npm package imports and path aliases.
|
|
54
54
|
// There are path aliases that cannot be distinguished from npm package names.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.envVarsPlugin = void 0;
|
|
3
|
+
exports.applyEnvVar = exports.envVarsPlugin = void 0;
|
|
4
4
|
const vite_1 = require("vite");
|
|
5
5
|
const utils_js_1 = require("../utils.js");
|
|
6
6
|
function envVarsPlugin() {
|
|
@@ -35,27 +35,32 @@ function envVarsPlugin() {
|
|
|
35
35
|
: [config.envPrefix];
|
|
36
36
|
return !envPrefix.some((prefix) => key.startsWith(prefix));
|
|
37
37
|
})
|
|
38
|
-
.forEach(([
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
38
|
+
.forEach(([envName, envVal]) => {
|
|
39
|
+
// Security check
|
|
40
|
+
{
|
|
41
|
+
const envStatement = getEnvStatement(envName);
|
|
42
|
+
const publicPrefix = 'PUBLIC_ENV__';
|
|
43
|
+
const isPrivate = !envName.startsWith(publicPrefix);
|
|
44
|
+
if (isPrivate && isClientSide) {
|
|
45
|
+
if (!code.includes(envStatement))
|
|
46
|
+
return;
|
|
47
|
+
const filePathToShowToUser = (0, utils_js_1.getFilePathRelativeToUserRootDir)(id, config.root);
|
|
48
|
+
const errMsgAddendum = isBuild ? '' : ' (Vike will prevent your app from building for production)';
|
|
49
|
+
const keyPublic = `${publicPrefix}${envName}`;
|
|
50
|
+
const errMsg = `${envStatement} is used in client-side file ${filePathToShowToUser} which means that the environment variable ${envName} will be included in client-side bundles and, therefore, ${envName} will be publicly exposed which can be a security leak${errMsgAddendum}. Use ${envStatement} only in server-side files, or rename ${envName} to ${keyPublic}, see https://vike.dev/env`;
|
|
51
|
+
if (isBuild) {
|
|
52
|
+
(0, utils_js_1.assertUsage)(false, errMsg);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
// Only a warning for faster development DX (e.g. when user toggles `ssr: boolean` or `onBeforeRenderIsomorph: boolean`)
|
|
56
|
+
(0, utils_js_1.assertWarning)(false, errMsg, { onlyOnce: true });
|
|
57
|
+
}
|
|
55
58
|
}
|
|
59
|
+
// Double check
|
|
60
|
+
(0, utils_js_1.assert)(!(isPrivate && isClientSide) || !isBuild);
|
|
56
61
|
}
|
|
57
|
-
|
|
58
|
-
code =
|
|
62
|
+
// Apply
|
|
63
|
+
code = applyEnvVar(envName, envVal, code);
|
|
59
64
|
});
|
|
60
65
|
// No need for low-resolution source map since line numbers didn't change. (Does Vite do high-resolution column numbers source mapping?)
|
|
61
66
|
return code;
|
|
@@ -63,6 +68,15 @@ function envVarsPlugin() {
|
|
|
63
68
|
};
|
|
64
69
|
}
|
|
65
70
|
exports.envVarsPlugin = envVarsPlugin;
|
|
71
|
+
function applyEnvVar(envName, envVal, code) {
|
|
72
|
+
const envStatement = getEnvStatement(envName);
|
|
73
|
+
const regex = new RegExp((0, utils_js_1.escapeRegex)(envStatement) + '\\b', 'g');
|
|
74
|
+
return code.replace(regex, JSON.stringify(envVal));
|
|
75
|
+
}
|
|
76
|
+
exports.applyEnvVar = applyEnvVar;
|
|
77
|
+
function getEnvStatement(envName) {
|
|
78
|
+
return `import.meta.env.${envName}`;
|
|
79
|
+
}
|
|
66
80
|
function getIsClientSide(config, options) {
|
|
67
81
|
const isBuild = config.command === 'build';
|
|
68
82
|
if (isBuild) {
|
|
@@ -32,15 +32,15 @@ function importBuild() {
|
|
|
32
32
|
}
|
|
33
33
|
exports.importBuild = importBuild;
|
|
34
34
|
function getImporterCode(config, pageFilesEntry) {
|
|
35
|
-
const
|
|
35
|
+
const filePathAbsolute = (0, utils_js_1.toPosixPath)(
|
|
36
36
|
// [RELATIVE_PATH_FROM_DIST] Current file: node_modules/vike/dist/esm/node/plugin/plugins/importBuild/index.js
|
|
37
37
|
require_.resolve(`../../../../../../dist/esm/node/runtime/globalContext/loadImportBuild.js`));
|
|
38
38
|
const { outDirServer } = (0, utils_js_1.getOutDirs)(config);
|
|
39
|
-
const
|
|
39
|
+
const filePathRelative = path_1.default.posix.relative(outDirServer, filePathAbsolute);
|
|
40
40
|
// The only reason we went for using CJS require() instead of ESM import() is because import() doesn't support .json files
|
|
41
41
|
const importerCode = [
|
|
42
42
|
'(async () => {',
|
|
43
|
-
` const { setImportBuildGetters } = await import('${
|
|
43
|
+
` const { setImportBuildGetters } = await import('${filePathRelative}');`,
|
|
44
44
|
' setImportBuildGetters({',
|
|
45
45
|
` pageFiles: () => import('./${pageFilesEntry}'),`,
|
|
46
46
|
" clientManifest: () => require('../assets.json'),",
|
|
@@ -146,7 +146,7 @@ export const pageFilesList = [];
|
|
|
146
146
|
export const neverLoaded = {};
|
|
147
147
|
export const isGeneratedFile = true;
|
|
148
148
|
|
|
149
|
-
${await (0, getVirtualFilePageConfigs_js_1.getVirtualFilePageConfigs)(
|
|
149
|
+
${await (0, getVirtualFilePageConfigs_js_1.getVirtualFilePageConfigs)(isForClientSide, isDev, id, isClientRouting, config)}
|
|
150
150
|
|
|
151
151
|
`;
|
|
152
152
|
fileTypes_js_1.fileTypes
|
|
@@ -52,7 +52,7 @@ function importUserCode() {
|
|
|
52
52
|
return undefined;
|
|
53
53
|
id = (0, utils_js_1.getVirtualFileId)(id);
|
|
54
54
|
if ((0, virtualFilePageConfigValuesAll_js_1.isVirtualFileIdPageConfigValuesAll)(id)) {
|
|
55
|
-
const code = await (0, getVirtualFilePageConfigValuesAll_js_1.getVirtualFilePageConfigValuesAll)(id,
|
|
55
|
+
const code = await (0, getVirtualFilePageConfigValuesAll_js_1.getVirtualFilePageConfigValuesAll)(id, isDev, config);
|
|
56
56
|
return code;
|
|
57
57
|
}
|
|
58
58
|
if ((0, virtualFileImportUserCode_js_1.isVirtualFileIdImportUserCode)(id)) {
|
|
@@ -117,8 +117,8 @@ function handleHotUpdate(ctx, config, configVike) {
|
|
|
117
117
|
return virtualModules;
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
|
-
function isVikeConfigModule(
|
|
121
|
-
return getVikeConfig_js_1.vikeConfigDependencies.has(
|
|
120
|
+
function isVikeConfigModule(filePathAbsoluteFilesystem) {
|
|
121
|
+
return getVikeConfig_js_1.vikeConfigDependencies.has(filePathAbsoluteFilesystem);
|
|
122
122
|
}
|
|
123
123
|
function reloadConfig(filePath, config, configVike, op) {
|
|
124
124
|
{
|
|
@@ -49,16 +49,17 @@ const configDefinitionsBuiltIn = {
|
|
|
49
49
|
_valueIsFilePath: true
|
|
50
50
|
},
|
|
51
51
|
clientRouting: {
|
|
52
|
-
|
|
52
|
+
// We could make it 'server-only' (we don't yet because of some legacy V0.4 design code)
|
|
53
|
+
env: 'server-and-client'
|
|
53
54
|
},
|
|
54
55
|
prerender: {
|
|
55
|
-
env: '
|
|
56
|
+
env: 'config-only'
|
|
56
57
|
},
|
|
57
58
|
hydrationCanBeAborted: {
|
|
58
|
-
env: 'client-only'
|
|
59
|
+
env: 'client-only'
|
|
59
60
|
},
|
|
60
61
|
prefetchStaticAssets: {
|
|
61
|
-
env: 'client-only'
|
|
62
|
+
env: 'client-only'
|
|
62
63
|
},
|
|
63
64
|
extends: {
|
|
64
65
|
env: 'config-only'
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js
CHANGED
|
@@ -7,8 +7,8 @@ const utils_js_1 = require("../../../../utils.js");
|
|
|
7
7
|
* getLocationId('/pages/some-page') => '/pages/some-page'
|
|
8
8
|
* getLocationId('/renderer/+config.js') => '/renderer'
|
|
9
9
|
*/
|
|
10
|
-
function getLocationId(
|
|
11
|
-
const locationId = removeFilename(
|
|
10
|
+
function getLocationId(filePathAbsoluteVite) {
|
|
11
|
+
const locationId = removeFilename(filePathAbsoluteVite, true);
|
|
12
12
|
assertLocationId(locationId);
|
|
13
13
|
return locationId;
|
|
14
14
|
}
|
|
@@ -110,21 +110,21 @@ function removeDirectories(somePath, removeDirs) {
|
|
|
110
110
|
somePath = '/';
|
|
111
111
|
return somePath;
|
|
112
112
|
}
|
|
113
|
-
function removeFilename(
|
|
114
|
-
(0, utils_js_1.assertPosixPath)(
|
|
115
|
-
(0, utils_js_1.assert)(
|
|
113
|
+
function removeFilename(filePathAbsoluteVite, optional) {
|
|
114
|
+
(0, utils_js_1.assertPosixPath)(filePathAbsoluteVite);
|
|
115
|
+
(0, utils_js_1.assert)(filePathAbsoluteVite.startsWith('/') || (0, utils_js_1.isNpmPackageImport)(filePathAbsoluteVite));
|
|
116
116
|
{
|
|
117
|
-
const filename =
|
|
117
|
+
const filename = filePathAbsoluteVite.split('/').slice(-1)[0];
|
|
118
118
|
if (!filename.includes('.')) {
|
|
119
119
|
(0, utils_js_1.assert)(optional);
|
|
120
|
-
return
|
|
120
|
+
return filePathAbsoluteVite;
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
|
-
|
|
124
|
-
if (
|
|
125
|
-
|
|
126
|
-
assertLocationId(
|
|
127
|
-
return
|
|
123
|
+
let locationId = filePathAbsoluteVite.split('/').slice(0, -1).join('/');
|
|
124
|
+
if (locationId === '')
|
|
125
|
+
locationId = '/';
|
|
126
|
+
assertLocationId(locationId);
|
|
127
|
+
return locationId;
|
|
128
128
|
}
|
|
129
129
|
function getFilesystemRouteDefinedBy(locationId) {
|
|
130
130
|
if (locationId === '/')
|