vike 0.4.229 → 0.4.230-commit-dd11364
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/client/server-routing-runtime/utils.js +1 -0
- package/dist/cjs/client/shared/{preparePageContextForUserConsumptionClientSide.js → preparePageContextForPublicUsageClientShared.js} +14 -19
- package/dist/cjs/node/api/build.js +2 -5
- package/dist/cjs/node/plugin/index.js +3 -1
- package/dist/cjs/node/plugin/onLoad.js +2 -0
- package/dist/cjs/node/plugin/plugins/build/pluginDistFileNames.js +1 -0
- package/dist/cjs/node/plugin/plugins/build/pluginModuleBanner.js +4 -4
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +5 -0
- package/dist/cjs/node/plugin/plugins/envVars.js +17 -19
- package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +3 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/assertExtensions.js +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +5 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/getPlusFilesAll.js +6 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +12 -8
- package/dist/cjs/node/plugin/plugins/replaceConstants.js +76 -0
- package/dist/cjs/node/plugin/shared/applyRegExWithMagicString.js +10 -0
- package/dist/cjs/node/plugin/shared/findPageFiles.js +1 -1
- package/dist/cjs/node/plugin/shared/loggerNotProd.js +2 -2
- package/dist/cjs/node/plugin/shared/resolveClientEntriesDev.js +1 -1
- package/dist/cjs/node/prerender/runPrerender.js +42 -38
- package/dist/cjs/node/prerender/utils.js +1 -1
- package/dist/cjs/node/runtime/globalContext.js +13 -27
- package/dist/cjs/node/runtime/html/renderHtml.js +12 -2
- package/dist/cjs/node/runtime/html/serializeContext.js +4 -2
- package/dist/cjs/node/runtime/renderPage/createHttpResponse/getCacheControl.js +7 -5
- package/dist/cjs/node/runtime/renderPage/createHttpResponse.js +3 -4
- package/dist/cjs/node/runtime/renderPage/createPageContextServerSide.js +6 -9
- package/dist/cjs/node/runtime/renderPage/execHookServer.js +11 -0
- package/dist/cjs/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.js +14 -15
- package/dist/cjs/node/runtime/renderPage/executeOnRenderHtmlHook.js +8 -12
- package/dist/cjs/node/runtime/renderPage/getHttpResponseBody.js +1 -1
- package/dist/cjs/node/runtime/renderPage/getPageAssets.js +1 -1
- package/dist/cjs/node/runtime/renderPage/{loadUserFilesServerSide.js → loadPageConfigsLazyServerSide.js} +4 -4
- package/dist/cjs/node/runtime/renderPage/preparePageContextForPublicUsageServer.js +10 -0
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +5 -5
- package/dist/cjs/node/runtime/renderPage/resolveRedirects.js +0 -2
- package/dist/cjs/node/runtime/renderPage.js +21 -12
- package/dist/cjs/node/runtime/utils.js +1 -1
- package/dist/cjs/shared/NOT_SERIALIZABLE.js +0 -1
- package/dist/cjs/shared/addIs404ToPageProps.js +0 -7
- package/dist/cjs/shared/createGlobalContextShared.js +37 -8
- package/dist/cjs/shared/createPageContextShared.js +14 -11
- package/dist/cjs/shared/getPageContext.js +3 -3
- package/dist/cjs/shared/getPageContextUrlComputed.js +2 -36
- package/dist/cjs/shared/getProxyForPublicUsage.js +56 -0
- package/dist/cjs/shared/hooks/execHook.js +170 -0
- package/dist/cjs/shared/hooks/getHook.js +23 -4
- package/dist/cjs/shared/page-configs/{getPageConfigUserFriendly.js → getUserFriendlyConfigs.js} +54 -47
- package/dist/cjs/shared/prepareGlobalContextForPublicUsage.js +10 -0
- package/dist/cjs/shared/preparePageContextForPublicUsage.js +80 -0
- package/dist/cjs/shared/route/abort.js +2 -2
- package/dist/cjs/shared/route/debug.js +17 -7
- package/dist/cjs/shared/route/executeGuardHook.js +4 -9
- package/dist/cjs/shared/route/executeOnBeforeRouteHook.js +4 -3
- package/dist/cjs/shared/route/index.js +2 -4
- package/dist/cjs/shared/route/loadPageRoutes.js +6 -0
- package/dist/cjs/shared/route/resolveRouteFunction.js +14 -10
- package/dist/cjs/shared/utils.js +1 -0
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/debug.js +15 -6
- package/dist/cjs/utils/isDev.js +3 -1
- package/dist/cjs/utils/isScriptFile.js +24 -21
- package/dist/cjs/utils/objectAssign.js +3 -3
- package/dist/cjs/utils/objectDefineProperty.js +1 -1
- package/dist/cjs/utils/parseNpmPackage.js +1 -0
- package/dist/cjs/utils/parseUrl-extras.js +0 -1
- package/dist/cjs/utils/requireResolve.js +39 -19
- package/dist/esm/client/client-routing-runtime/{createPageContext.d.ts → createPageContextClientSide.d.ts} +21 -13
- package/dist/esm/client/client-routing-runtime/{createPageContext.js → createPageContextClientSide.js} +9 -11
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.d.ts +400 -15
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.js +56 -54
- package/dist/esm/client/client-routing-runtime/globalContext.d.ts +11 -1
- package/dist/esm/client/client-routing-runtime/prefetch.d.ts +3 -8
- package/dist/esm/client/client-routing-runtime/prefetch.js +3 -3
- package/dist/esm/client/client-routing-runtime/preparePageContextForPublicUsageClient.d.ts +11 -0
- package/dist/esm/client/client-routing-runtime/preparePageContextForPublicUsageClient.js +5 -0
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.d.ts +135 -0
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +72 -81
- 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/createPageContextClientSide.d.ts +19 -13
- package/dist/esm/client/server-routing-runtime/createPageContextClientSide.js +15 -26
- package/dist/esm/client/server-routing-runtime/entry.js +4 -4
- package/dist/esm/client/server-routing-runtime/globalContext.d.ts +11 -1
- package/dist/esm/client/server-routing-runtime/preparePageContextForPublicUsageClient.d.ts +9 -0
- package/dist/esm/client/server-routing-runtime/preparePageContextForPublicUsageClient.js +5 -0
- package/dist/esm/client/server-routing-runtime/utils.d.ts +1 -0
- package/dist/esm/client/server-routing-runtime/utils.js +1 -0
- package/dist/esm/client/shared/createGetGlobalContextClient.d.ts +11 -1
- package/dist/esm/client/shared/executeOnRenderClientHook.d.ts +3 -3
- package/dist/esm/client/shared/executeOnRenderClientHook.js +4 -13
- package/dist/esm/client/shared/{loadUserFilesClientSide.d.ts → loadPageConfigsLazyClientSide.d.ts} +2 -2
- package/dist/esm/client/shared/{loadUserFilesClientSide.js → loadPageConfigsLazyClientSide.js} +4 -4
- package/dist/esm/client/shared/preparePageContextForPublicUsageClientShared.d.ts +11 -0
- package/dist/esm/client/shared/preparePageContextForPublicUsageClientShared.js +39 -0
- package/dist/esm/node/api/build.js +2 -2
- package/dist/esm/node/plugin/index.js +3 -1
- package/dist/esm/node/plugin/onLoad.js +2 -0
- package/dist/esm/node/plugin/plugins/build/pluginDistFileNames.js +1 -0
- package/dist/esm/node/plugin/plugins/build/pluginModuleBanner.js +4 -4
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +6 -1
- package/dist/esm/node/plugin/plugins/envVars.js +18 -20
- package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +4 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/assertExtensions.d.ts +1 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/assertExtensions.js +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +5 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/getPlusFilesAll.js +7 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +12 -8
- package/dist/esm/node/plugin/plugins/replaceConstants.d.ts +3 -0
- package/dist/esm/node/plugin/plugins/replaceConstants.js +71 -0
- package/dist/esm/node/plugin/shared/applyRegExWithMagicString.d.ts +3 -0
- package/dist/esm/node/plugin/shared/applyRegExWithMagicString.js +8 -0
- package/dist/esm/node/plugin/shared/findPageFiles.js +2 -2
- package/dist/esm/node/plugin/shared/loggerNotProd.js +1 -1
- package/dist/esm/node/plugin/shared/resolveClientEntriesDev.d.ts +1 -1
- package/dist/esm/node/plugin/shared/resolveClientEntriesDev.js +1 -1
- package/dist/esm/node/prerender/runPrerender.d.ts +37 -73
- package/dist/esm/node/prerender/runPrerender.js +42 -38
- package/dist/esm/node/prerender/utils.d.ts +1 -1
- package/dist/esm/node/prerender/utils.js +1 -1
- package/dist/esm/node/runtime/globalContext.d.ts +46 -251
- package/dist/esm/node/runtime/globalContext.js +14 -28
- package/dist/esm/node/runtime/html/renderHtml.js +12 -2
- package/dist/esm/node/runtime/html/serializeContext.d.ts +1 -1
- package/dist/esm/node/runtime/html/serializeContext.js +4 -2
- package/dist/esm/node/runtime/renderPage/createHttpResponse/getCacheControl.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/createHttpResponse/getCacheControl.js +7 -5
- package/dist/esm/node/runtime/renderPage/createHttpResponse.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/createHttpResponse.js +3 -4
- package/dist/esm/node/runtime/renderPage/createPageContextServerSide.d.ts +26 -41
- package/dist/esm/node/runtime/renderPage/createPageContextServerSide.js +7 -10
- package/dist/esm/node/runtime/renderPage/execHookServer.d.ts +12 -0
- package/dist/esm/node/runtime/renderPage/execHookServer.js +9 -0
- package/dist/esm/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.d.ts +2 -3
- package/dist/esm/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.js +14 -15
- package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.d.ts +4 -2
- package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.js +8 -12
- package/dist/esm/node/runtime/renderPage/getHttpResponseBody.js +1 -1
- package/dist/esm/node/runtime/renderPage/getPageAssets.js +1 -1
- package/dist/esm/node/runtime/renderPage/{loadUserFilesServerSide.d.ts → loadPageConfigsLazyServerSide.d.ts} +6 -6
- package/dist/esm/node/runtime/renderPage/{loadUserFilesServerSide.js → loadPageConfigsLazyServerSide.js} +4 -4
- package/dist/esm/node/runtime/renderPage/preparePageContextForPublicUsageServer.d.ts +20 -0
- package/dist/esm/node/runtime/renderPage/preparePageContextForPublicUsageServer.js +8 -0
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +38 -74
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +5 -5
- package/dist/esm/node/runtime/renderPage/resolveRedirects.d.ts +0 -2
- package/dist/esm/node/runtime/renderPage/resolveRedirects.js +0 -1
- package/dist/esm/node/runtime/renderPage.d.ts +21 -39
- package/dist/esm/node/runtime/renderPage.js +22 -13
- package/dist/esm/node/runtime/utils.d.ts +1 -1
- package/dist/esm/node/runtime/utils.js +1 -1
- package/dist/esm/shared/NOT_SERIALIZABLE.js +0 -1
- package/dist/esm/shared/addIs404ToPageProps.d.ts +1 -6
- package/dist/esm/shared/addIs404ToPageProps.js +1 -8
- package/dist/esm/shared/createGlobalContextShared.d.ts +28 -6
- package/dist/esm/shared/createGlobalContextShared.js +37 -8
- package/dist/esm/shared/createPageContextShared.d.ts +7 -6
- package/dist/esm/shared/createPageContextShared.js +15 -12
- package/dist/esm/shared/getPageContext.d.ts +1 -1
- package/dist/esm/shared/getPageContext.js +1 -1
- package/dist/esm/shared/getPageContextUrlComputed.d.ts +2 -5
- package/dist/esm/shared/getPageContextUrlComputed.js +3 -37
- package/dist/esm/shared/getPageFiles.d.ts +1 -1
- package/dist/esm/shared/getProxyForPublicUsage.d.ts +4 -0
- package/dist/esm/shared/getProxyForPublicUsage.js +54 -0
- package/dist/esm/shared/hooks/execHook.d.ts +63 -0
- package/dist/esm/shared/hooks/execHook.js +168 -0
- package/dist/esm/shared/hooks/getHook.d.ts +10 -11
- package/dist/esm/shared/hooks/getHook.js +23 -4
- package/dist/esm/shared/page-configs/Config.d.ts +11 -4
- package/dist/esm/shared/page-configs/{getPageConfigUserFriendly.d.ts → getUserFriendlyConfigs.d.ts} +8 -6
- package/dist/esm/shared/page-configs/{getPageConfigUserFriendly.js → getUserFriendlyConfigs.js} +55 -48
- package/dist/esm/shared/prepareGlobalContextForPublicUsage.d.ts +7 -0
- package/dist/esm/shared/prepareGlobalContextForPublicUsage.js +8 -0
- package/dist/esm/shared/preparePageContextForPublicUsage.d.ts +11 -0
- package/dist/esm/shared/preparePageContextForPublicUsage.js +78 -0
- package/dist/esm/shared/route/abort.js +1 -1
- package/dist/esm/shared/route/debug.d.ts +4 -1
- package/dist/esm/shared/route/debug.js +17 -7
- package/dist/esm/shared/route/executeGuardHook.d.ts +4 -3
- package/dist/esm/shared/route/executeGuardHook.js +4 -9
- package/dist/esm/shared/route/executeOnBeforeRouteHook.js +4 -3
- package/dist/esm/shared/route/index.js +2 -4
- package/dist/esm/shared/route/loadPageRoutes.d.ts +2 -1
- package/dist/esm/shared/route/loadPageRoutes.js +7 -1
- package/dist/esm/shared/route/resolveRouteFunction.d.ts +2 -2
- package/dist/esm/shared/route/resolveRouteFunction.js +14 -10
- package/dist/esm/shared/types.d.ts +14 -4
- 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/debug.d.ts +1 -1
- package/dist/esm/utils/debug.js +15 -6
- package/dist/esm/utils/isDev.js +3 -1
- package/dist/esm/utils/isScriptFile.d.ts +5 -5
- package/dist/esm/utils/isScriptFile.js +23 -20
- package/dist/esm/utils/objectAssign.d.ts +1 -1
- package/dist/esm/utils/objectAssign.js +3 -3
- package/dist/esm/utils/objectDefineProperty.d.ts +0 -1
- package/dist/esm/utils/objectDefineProperty.js +1 -1
- package/dist/esm/utils/parseNpmPackage.d.ts +2 -0
- package/dist/esm/utils/parseNpmPackage.js +1 -1
- package/dist/esm/utils/parseUrl-extras.js +0 -1
- package/dist/esm/utils/requireResolve.js +39 -19
- package/package.json +2 -2
- package/dist/cjs/client/shared/getPageContextProxyForUser.js +0 -16
- package/dist/cjs/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.js +0 -16
- package/dist/cjs/shared/getPageConfigsRuntime.js +0 -23
- package/dist/cjs/shared/hooks/executeHook.js +0 -87
- package/dist/cjs/shared/hooks/executeHookGeneric.js +0 -18
- package/dist/cjs/shared/preparePageContextForUserConsumption.js +0 -34
- package/dist/cjs/utils/getPublicProxy.js +0 -27
- package/dist/esm/client/shared/getPageContextProxyForUser.d.ts +0 -2
- package/dist/esm/client/shared/getPageContextProxyForUser.js +0 -14
- package/dist/esm/client/shared/preparePageContextForUserConsumptionClientSide.d.ts +0 -12
- package/dist/esm/client/shared/preparePageContextForUserConsumptionClientSide.js +0 -44
- package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.d.ts +0 -24
- package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.js +0 -14
- package/dist/esm/shared/getPageConfigsRuntime.d.ts +0 -14
- package/dist/esm/shared/getPageConfigsRuntime.js +0 -21
- package/dist/esm/shared/hooks/executeHook.d.ts +0 -21
- package/dist/esm/shared/hooks/executeHook.js +0 -85
- package/dist/esm/shared/hooks/executeHookGeneric.d.ts +0 -8
- package/dist/esm/shared/hooks/executeHookGeneric.js +0 -16
- package/dist/esm/shared/preparePageContextForUserConsumption.d.ts +0 -5
- package/dist/esm/shared/preparePageContextForUserConsumption.js +0 -32
- package/dist/esm/utils/getPublicProxy.d.ts +0 -2
- package/dist/esm/utils/getPublicProxy.js +0 -25
|
@@ -31,3 +31,4 @@ __exportStar(require("../../utils/slice.js"), exports);
|
|
|
31
31
|
__exportStar(require("../../utils/unique.js"), exports); // Only used by Server Routing (not needed for Client Routing)
|
|
32
32
|
__exportStar(require("../../utils/getPropAccessNotation.js"), exports);
|
|
33
33
|
__exportStar(require("../../utils/augmentType.js"), exports);
|
|
34
|
+
__exportStar(require("../../utils/changeEnumerable.js"), exports);
|
|
@@ -1,31 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.preparePageContextForPublicUsageClientShared = preparePageContextForPublicUsageClientShared;
|
|
4
|
+
exports.preparePageContextForPublicUsageClientMinimal = preparePageContextForPublicUsageClientMinimal;
|
|
4
5
|
const utils_js_1 = require("../server-routing-runtime/utils.js");
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const pageContextTyped = pageContext;
|
|
10
|
-
(0, utils_js_1.assert)([true, false].includes(pageContextTyped.isHydration));
|
|
11
|
-
(0, utils_js_1.assert)([true, false, null].includes(pageContextTyped.isBackwardNavigation));
|
|
12
|
-
}
|
|
13
|
-
else {
|
|
14
|
-
const pageContextTyped = pageContext;
|
|
15
|
-
(0, utils_js_1.assert)(pageContextTyped.isHydration === true);
|
|
16
|
-
(0, utils_js_1.assert)(pageContextTyped.isBackwardNavigation === null);
|
|
17
|
-
}
|
|
18
|
-
const Page = pageContext.config.Page ||
|
|
6
|
+
const preparePageContextForPublicUsage_js_1 = require("../../shared/preparePageContextForPublicUsage.js");
|
|
7
|
+
function preparePageContextForPublicUsageClientShared(pageContext) {
|
|
8
|
+
// TODO/now use proxy
|
|
9
|
+
const Page = pageContext.config?.Page ||
|
|
19
10
|
// TODO/next-major-release: remove
|
|
20
|
-
pageContext.exports
|
|
11
|
+
pageContext.exports?.Page;
|
|
21
12
|
(0, utils_js_1.objectAssign)(pageContext, { Page });
|
|
13
|
+
// TODO/next-major-release: after we remove supportVueReactiviy() we can call this later inside the agnostic preparePageContextForPublicUsage()
|
|
14
|
+
(0, preparePageContextForPublicUsage_js_1.assertPropertyGetters)(pageContext);
|
|
22
15
|
// TODO/next-major-release: remove
|
|
23
16
|
// - Requires https://github.com/vikejs/vike-vue/issues/198
|
|
24
17
|
// - Last time I tried to remove it (https://github.com/vikejs/vike/commit/705fd23598d9d69bf46a52c8550216cd7117ce71) the tests were failing as expected: only the Vue integrations that used shallowReactive() failed.
|
|
25
18
|
supportVueReactiviy(pageContext);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
19
|
+
return preparePageContextForPublicUsageClientMinimal(pageContext);
|
|
20
|
+
}
|
|
21
|
+
function preparePageContextForPublicUsageClientMinimal(pageContext) {
|
|
22
|
+
const pageContextPublic = (0, preparePageContextForPublicUsage_js_1.preparePageContextForPublicUsage)(pageContext);
|
|
23
|
+
return pageContextPublic;
|
|
29
24
|
}
|
|
30
25
|
// With Vue + Cient Routing, the `pageContext` is made reactive:
|
|
31
26
|
// ```js
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.build = build;
|
|
7
4
|
const prepareViteApiCall_js_1 = require("./prepareViteApiCall.js");
|
|
8
5
|
const vite_1 = require("vite");
|
|
9
|
-
const assert_1 = __importDefault(require("assert"));
|
|
10
6
|
const context_js_1 = require("../cli/context.js");
|
|
11
7
|
const context_js_2 = require("../prerender/context.js");
|
|
12
8
|
const utils_js_1 = require("./utils.js");
|
|
@@ -21,6 +17,7 @@ async function build(options = {}) {
|
|
|
21
17
|
if (viteConfigFromUserEnhanced)
|
|
22
18
|
viteConfigFromUserEnhanced._viteConfigFromUserEnhanced = viteConfigFromUserEnhanced;
|
|
23
19
|
if (vikeConfig.global.config.vite6BuilderApp) {
|
|
20
|
+
// This assertion isn't reliable: the user may still use a Vite version older than 6.0.0 — see https://github.com/vitejs/vite/pull/19355
|
|
24
21
|
(0, utils_js_1.assertVersion)('Vite', vite_1.version, '6.0.0');
|
|
25
22
|
const builder = await (0, vite_1.createBuilder)(viteConfigFromUserEnhanced);
|
|
26
23
|
// See Vite plugin vike:build:pluginBuildApp
|
|
@@ -38,7 +35,7 @@ async function build(options = {}) {
|
|
|
38
35
|
await (0, vite_1.build)(viteConfigFromUserEnhanced);
|
|
39
36
|
// After pre-rendering, when using the Vike CLI, the process is forcefully exited at the end of the buildVite() call above.
|
|
40
37
|
if ((0, context_js_1.isVikeCli)() && (0, context_js_2.isPrerendering)())
|
|
41
|
-
(0,
|
|
38
|
+
(0, utils_js_1.assert)(false);
|
|
42
39
|
}
|
|
43
40
|
return {
|
|
44
41
|
/* We don't return `viteConfig` because `viteConfigFromUserEnhanced` is `InlineConfig` not `ResolvedConfig`
|
|
@@ -28,6 +28,7 @@ const getPageAssets_js_1 = require("../runtime/renderPage/getPageAssets.js");
|
|
|
28
28
|
const resolveClientEntriesDev_js_1 = require("./shared/resolveClientEntriesDev.js");
|
|
29
29
|
const workaroundCssModuleHmr_js_1 = require("./plugins/workaroundCssModuleHmr.js");
|
|
30
30
|
const workaroundVite6HmrRegression_js_1 = require("./plugins/workaroundVite6HmrRegression.js");
|
|
31
|
+
const replaceConstants_js_1 = require("./plugins/replaceConstants.js");
|
|
31
32
|
// We don't call this in ./onLoad.ts to avoid a cyclic dependency with utils.ts
|
|
32
33
|
(0, getPageAssets_js_1.setResolveClientEntriesDev)(resolveClientEntriesDev_js_1.resolveClientEntriesDev);
|
|
33
34
|
// Return `PluginInterop` instead of `Plugin` to avoid type mismatch upon different Vite versions
|
|
@@ -45,7 +46,8 @@ function plugin(vikeVitePluginOptions = {}) {
|
|
|
45
46
|
(0, envVars_js_1.envVarsPlugin)(),
|
|
46
47
|
(0, fileEnv_js_1.fileEnv)(),
|
|
47
48
|
(0, workaroundCssModuleHmr_js_1.workaroundCssModuleHmr)(),
|
|
48
|
-
(0, workaroundVite6HmrRegression_js_1.workaroundVite6HmrRegression)()
|
|
49
|
+
(0, workaroundVite6HmrRegression_js_1.workaroundVite6HmrRegression)(),
|
|
50
|
+
(0, replaceConstants_js_1.replaceConstants)()
|
|
49
51
|
];
|
|
50
52
|
Object.assign(plugins, { __vikeVitePluginOptions: vikeVitePluginOptions });
|
|
51
53
|
return plugins;
|
|
@@ -11,6 +11,8 @@ function onLoad() {
|
|
|
11
11
|
(0, assertIsNotBrowser_js_1.assertIsNotBrowser)();
|
|
12
12
|
(0, assertNodeVersion_js_1.assertNodeVersion)();
|
|
13
13
|
// package.json#peerDependencies isn't enough as users often ignore it
|
|
14
|
+
// This assertion isn't reliable: the user may still use a Vite version older than 5.1.0 — see https://github.com/vitejs/vite/pull/19355
|
|
15
|
+
// TO-DO/soon: let's also use this.meta.viteVersion https://github.com/vitejs/vite/pull/20088
|
|
14
16
|
(0, assertVersion_js_1.assertVersion)('Vite', vite_1.version, '5.1.0');
|
|
15
17
|
// Ensure we don't bloat the server runtime with heavy dependencies such Vite and esbuild
|
|
16
18
|
(0, assertSetup_js_1.assertIsNotProductionRuntime)();
|
|
@@ -52,6 +52,7 @@ function pluginDistFileNames() {
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
// Disable CSS bundling to workaround https://github.com/vikejs/vike/issues/1815
|
|
55
|
+
// TO-DO/eventually: let's bundle CSS again once Rolldown replaces Rollup
|
|
55
56
|
if (id.endsWith('.css')) {
|
|
56
57
|
const userRootDir = config.root;
|
|
57
58
|
if (id.startsWith(userRootDir)) {
|
|
@@ -32,14 +32,14 @@ function pluginModuleBanner() {
|
|
|
32
32
|
if (id.startsWith(config.root))
|
|
33
33
|
id = id.slice(config.root.length + 1);
|
|
34
34
|
id = id.replaceAll('*/', '*\\/'); // https://github.com/vikejs/vike/issues/2377
|
|
35
|
-
const
|
|
35
|
+
const magicString = new magic_string_1.default(code);
|
|
36
36
|
// Use legal comment so that esbuild doesn't remove it.
|
|
37
37
|
// - Terser still removes the comment, but I guess users use terser to minify JavaScript so I guess it's a good thing that comment is removed.
|
|
38
38
|
// - https://esbuild.github.io/api/#legal-comments
|
|
39
|
-
|
|
39
|
+
magicString.prepend(`/*! ${id} [vike:pluginModuleBanner] */\n`);
|
|
40
40
|
return {
|
|
41
|
-
code:
|
|
42
|
-
map:
|
|
41
|
+
code: magicString.toString(),
|
|
42
|
+
map: magicString.generateMap({ hires: true, source: id })
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
45
|
}
|
|
@@ -57,6 +57,11 @@ async function getPageDeps(config, pageConfigs) {
|
|
|
57
57
|
return;
|
|
58
58
|
if (definedAt.definedBy)
|
|
59
59
|
return;
|
|
60
|
+
if (definedAt.importPathAbsolute) {
|
|
61
|
+
const npmPackageName = (0, utils_js_1.getNpmPackageName)(definedAt.importPathAbsolute);
|
|
62
|
+
if (npmPackageName && config.optimizeDeps.exclude?.includes(npmPackageName))
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
60
65
|
if (definedAt.filePathAbsoluteUserRootDir !== null) {
|
|
61
66
|
// Vite expects entries to be filesystem absolute paths (surprisingly so).
|
|
62
67
|
addEntry(definedAt.filePathAbsoluteFilesystem);
|
|
@@ -10,7 +10,8 @@ const utils_js_1 = require("../utils.js");
|
|
|
10
10
|
const getFilePath_js_1 = require("../shared/getFilePath.js");
|
|
11
11
|
const normalizeId_js_1 = require("../shared/normalizeId.js");
|
|
12
12
|
const isViteServerBuild_js_1 = require("../shared/isViteServerBuild.js");
|
|
13
|
-
|
|
13
|
+
const applyRegExWithMagicString_js_1 = require("../shared/applyRegExWithMagicString.js");
|
|
14
|
+
// TODO/enventually:
|
|
14
15
|
// - Make import.meta.env work inside +config.js
|
|
15
16
|
// - For it to work, we'll probably need the user to define the settings (e.g. `envDir`) for loadEnv() inside vike.config.js instead of vite.config.js
|
|
16
17
|
// - Or stop using Vite's `mode` implemention and have Vike implement its own `mode` feature? (So that the only dependencies are `$ vike build --mode staging` and `$ MODE=staging vike build`.)
|
|
@@ -27,7 +28,6 @@ function envVarsPlugin() {
|
|
|
27
28
|
enforce: 'post',
|
|
28
29
|
configResolved(config_) {
|
|
29
30
|
config = config_;
|
|
30
|
-
config.command;
|
|
31
31
|
envsAll = (0, vite_1.loadEnv)(config.mode, config.envDir || config.root, '');
|
|
32
32
|
config.plugins.sort((0, utils_js_1.lowerFirst)((plugin) => (plugin.name === 'vite:define' ? 1 : 0)));
|
|
33
33
|
},
|
|
@@ -43,21 +43,22 @@ function envVarsPlugin() {
|
|
|
43
43
|
return;
|
|
44
44
|
const isBuild = config.command === 'build';
|
|
45
45
|
const isClientSide = !(0, isViteServerBuild_js_1.isViteServerBuild_safe)(config, options);
|
|
46
|
-
const
|
|
47
|
-
|
|
46
|
+
const magicString = new magic_string_1.default(code);
|
|
47
|
+
// Find & check
|
|
48
|
+
const replacements = Object.entries(envsAll)
|
|
48
49
|
.filter(([key]) => {
|
|
49
50
|
// Already handled by Vite
|
|
50
51
|
const envPrefix = !config.envPrefix ? [] : (0, utils_js_1.isArray)(config.envPrefix) ? config.envPrefix : [config.envPrefix];
|
|
51
52
|
return !envPrefix.some((prefix) => key.startsWith(prefix));
|
|
52
53
|
})
|
|
53
|
-
.
|
|
54
|
+
.map(([envName, envVal]) => {
|
|
54
55
|
const envStatement = `import.meta.env.${envName}`;
|
|
55
|
-
const
|
|
56
|
+
const envStatementRegExpStr = (0, utils_js_1.escapeRegex)(envStatement) + '\\b';
|
|
56
57
|
// Security check
|
|
57
58
|
{
|
|
58
59
|
const isPrivate = !envName.startsWith(PUBLIC_ENV_PREFIX) && !PUBLIC_ENV_ALLOWLIST.includes(envName);
|
|
59
60
|
if (isPrivate && isClientSide) {
|
|
60
|
-
if (!new RegExp(
|
|
61
|
+
if (!new RegExp(envStatementRegExpStr).test(code))
|
|
61
62
|
return;
|
|
62
63
|
const modulePath = (0, getFilePath_js_1.getModuleFilePathAbsolute)(id, config);
|
|
63
64
|
const errMsgAddendum = isBuild ? '' : ' (Vike will prevent your app from building for production)';
|
|
@@ -75,22 +76,19 @@ function envVarsPlugin() {
|
|
|
75
76
|
// Double check
|
|
76
77
|
(0, utils_js_1.assert)(!(isPrivate && isClientSide) || !isBuild);
|
|
77
78
|
}
|
|
78
|
-
|
|
79
|
-
|
|
79
|
+
return { regExpStr: envStatementRegExpStr, replacement: envVal };
|
|
80
|
+
})
|
|
81
|
+
.filter(utils_js_1.isNotNullish);
|
|
82
|
+
// Apply
|
|
83
|
+
replacements.forEach(({ regExpStr, replacement }) => {
|
|
84
|
+
(0, applyRegExWithMagicString_js_1.applyRegExpWithMagicString)(magicString, regExpStr, replacement);
|
|
80
85
|
});
|
|
81
|
-
if (!
|
|
86
|
+
if (!magicString.hasChanged())
|
|
82
87
|
return null;
|
|
83
88
|
return {
|
|
84
|
-
code:
|
|
85
|
-
map:
|
|
89
|
+
code: magicString.toString(),
|
|
90
|
+
map: magicString.generateMap({ hires: true, source: id })
|
|
86
91
|
};
|
|
87
92
|
}
|
|
88
93
|
};
|
|
89
94
|
}
|
|
90
|
-
function applyEnvVar(s, envStatementRegExStr, envVal) {
|
|
91
|
-
const envStatementRegEx = new RegExp(envStatementRegExStr, 'g');
|
|
92
|
-
let match;
|
|
93
|
-
while ((match = envStatementRegEx.exec(s.original))) {
|
|
94
|
-
s.overwrite(match.index, match.index + match[0].length, JSON.stringify(envVal));
|
|
95
|
-
}
|
|
96
|
-
}
|
|
@@ -179,7 +179,9 @@ function getGlobRoots(config) {
|
|
|
179
179
|
}
|
|
180
180
|
function getGlobPath(globRootDir, fileType) {
|
|
181
181
|
(0, utils_js_1.assertPosixPath)(globRootDir);
|
|
182
|
-
let globPath = [...globRootDir.split('/'), '**', `*${fileType}.${utils_js_1.
|
|
182
|
+
let globPath = [...globRootDir.split('/'), '**', `*${fileType}.${utils_js_1.scriptFileExtensionPattern}`]
|
|
183
|
+
.filter(Boolean)
|
|
184
|
+
.join('/');
|
|
183
185
|
if (!globPath.startsWith('/')) {
|
|
184
186
|
globPath = '/' + globPath;
|
|
185
187
|
}
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/assertExtensions.js
CHANGED
|
@@ -33,8 +33,8 @@ function assertExtensionName(plusFile) {
|
|
|
33
33
|
const name = getNameValue(plusFile);
|
|
34
34
|
(0, utils_js_1.assertUsage)(name, `Vike extension name missing: the config ${filePathToShowToUser} must define the setting ${picocolors_1.default.cyan('name')}`);
|
|
35
35
|
}
|
|
36
|
-
function assertExtensionsRequire(
|
|
37
|
-
const plusFilesRelevantList =
|
|
36
|
+
function assertExtensionsRequire(plusFiles) {
|
|
37
|
+
const plusFilesRelevantList = plusFiles;
|
|
38
38
|
// Collect extensions
|
|
39
39
|
const extensions = {};
|
|
40
40
|
plusFilesRelevantList.forEach((plusFile) => {
|
|
@@ -21,6 +21,7 @@ const configDefinitionsBuiltIn = {
|
|
|
21
21
|
},
|
|
22
22
|
onCreatePageContext: {
|
|
23
23
|
env: { server: true, client: true },
|
|
24
|
+
// Required because `onCreatePageContext()` is called before routing
|
|
24
25
|
global: true,
|
|
25
26
|
cumulative: true
|
|
26
27
|
},
|
|
@@ -57,6 +58,10 @@ const configDefinitionsBuiltIn = {
|
|
|
57
58
|
data: {
|
|
58
59
|
env: { server: true }
|
|
59
60
|
},
|
|
61
|
+
onData: {
|
|
62
|
+
env: { server: true, client: true },
|
|
63
|
+
cumulative: true
|
|
64
|
+
},
|
|
60
65
|
iKnowThePerformanceRisksOfAsyncRouteFunctions: {
|
|
61
66
|
env: { server: true, client: 'if-client-routing' },
|
|
62
67
|
eager: true
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js
CHANGED
|
@@ -120,7 +120,7 @@ async function gitLsFiles(userRootDir, ignorePatterns, ignoreMatchers) {
|
|
|
120
120
|
}
|
|
121
121
|
// Same as gitLsFiles() but using tinyglobby
|
|
122
122
|
async function tinyglobby(userRootDir, ignorePatterns) {
|
|
123
|
-
const pattern = `**/+*.${utils_js_1.
|
|
123
|
+
const pattern = `**/+*.${utils_js_1.scriptFileExtensionPattern}`;
|
|
124
124
|
const options = {
|
|
125
125
|
ignore: ignorePatterns,
|
|
126
126
|
cwd: userRootDir,
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/getPlusFilesAll.js
CHANGED
|
@@ -82,8 +82,14 @@ async function getPlusFilesAll(userRootDir, esbuildCache) {
|
|
|
82
82
|
Object.entries(plusFilesAll).forEach(([_locationId, plusFiles]) => {
|
|
83
83
|
plusFiles.sort(sortMakeDeterministic);
|
|
84
84
|
});
|
|
85
|
+
assertPlusFiles(plusFilesAll);
|
|
85
86
|
return plusFilesAll;
|
|
86
87
|
}
|
|
88
|
+
function assertPlusFiles(plusFilesAll) {
|
|
89
|
+
const plusFiles = Object.values(plusFilesAll).flat();
|
|
90
|
+
// The earlier we call it the better, so that +require can be used by Vike extensions to depend on new Vike features
|
|
91
|
+
(0, assertExtensions_js_1.assertExtensionsRequire)(plusFiles);
|
|
92
|
+
}
|
|
87
93
|
function getPlusFileFromConfigFile(configFile, isExtensionConfig, locationId, userRootDir) {
|
|
88
94
|
const { fileExports, filePath, extendsFilePaths } = configFile;
|
|
89
95
|
const fileExportsByConfigName = {};
|
|
@@ -31,7 +31,7 @@ async function transpileAndExecuteFile(filePath, userRootDir, isExtensionConfig,
|
|
|
31
31
|
}
|
|
32
32
|
const { promise, resolve } = (0, utils_js_1.genPromise)();
|
|
33
33
|
esbuildCache.transpileCache[filePathAbsoluteFilesystem] = promise;
|
|
34
|
-
(0, utils_js_1.assertUsage)((0, utils_js_1.
|
|
34
|
+
(0, utils_js_1.assertUsage)((0, utils_js_1.isPlainScriptFile)(filePathAbsoluteFilesystem), `${filePathToShowToUserResolved} has file extension .${fileExtension} but a config file can only be a JavaScript/TypeScript file`);
|
|
35
35
|
const isHeader = isHeaderFile(filePathAbsoluteFilesystem);
|
|
36
36
|
if (isHeader) {
|
|
37
37
|
(0, utils_js_1.assertWarning)(false, `${picocolors_1.default.cyan('.h.js')} files are deprecated: simply renaming ${filePathToShowToUserResolved} to ${removeHeaderFileExtension(filePathToShowToUserResolved)} is usually enough, although you may occasionally need to use ${picocolors_1.default.cyan("with { type: 'pointer' }")} as explained at https://vike.dev/config#pointer-imports`, { onlyOnce: true });
|
|
@@ -157,7 +157,7 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
|
|
|
157
157
|
const isVikeExtensionImport = (path.startsWith('vike-') && path.endsWith('/config')) || importPathResolved.endsWith('+config.js');
|
|
158
158
|
const isPointerImport = transformImports === 'all' ||
|
|
159
159
|
// .jsx, .vue, .svg, ... => obviously not config code => pointer import
|
|
160
|
-
!(0, utils_js_1.
|
|
160
|
+
!(0, utils_js_1.isPlainScriptFile)(importPathResolved) ||
|
|
161
161
|
// Import of a Vike extension config => make it a pointer import because we want to show nice error messages (that can display whether a config has been set by the user or by a Vike extension).
|
|
162
162
|
// - Should we stop doing this? (And instead let Node.js directly load Vike extensions.)
|
|
163
163
|
// - In principle, we can use the setting 'name' value of Vike extensions.
|
|
@@ -25,8 +25,7 @@ const loadFileAtConfigTime_js_1 = require("./getVikeConfig/loadFileAtConfigTime.
|
|
|
25
25
|
const resolvePointerImport_js_1 = require("./getVikeConfig/resolvePointerImport.js");
|
|
26
26
|
const getFilePath_js_1 = require("../../../shared/getFilePath.js");
|
|
27
27
|
const getConfigValueBuildTime_js_1 = require("../../../../../shared/page-configs/getConfigValueBuildTime.js");
|
|
28
|
-
const
|
|
29
|
-
const getPageConfigUserFriendly_js_1 = require("../../../../../shared/page-configs/getPageConfigUserFriendly.js");
|
|
28
|
+
const getUserFriendlyConfigs_js_1 = require("../../../../../shared/page-configs/getUserFriendlyConfigs.js");
|
|
30
29
|
const serializeConfigValues_js_1 = require("../../../../../shared/page-configs/serialize/serializeConfigValues.js");
|
|
31
30
|
const getPlusFilesAll_js_1 = require("./getVikeConfig/getPlusFilesAll.js");
|
|
32
31
|
const getEnvVarObject_js_1 = require("../../../shared/getEnvVarObject.js");
|
|
@@ -142,7 +141,7 @@ async function loadVikeConfig_withErrorHandling(userRootDir, isDev, vikeVitePlug
|
|
|
142
141
|
configDefinitions: {},
|
|
143
142
|
configValueSources: {}
|
|
144
143
|
},
|
|
145
|
-
global: (0,
|
|
144
|
+
global: (0, getUserFriendlyConfigs_js_1.getUserFriendlyConfigsGlobal)({ pageConfigGlobalValues: {} }),
|
|
146
145
|
pages: {},
|
|
147
146
|
vikeConfigDependencies: new Set()
|
|
148
147
|
};
|
|
@@ -163,13 +162,19 @@ async function loadVikeConfig(userRootDir, vikeVitePluginOptions) {
|
|
|
163
162
|
setCliAndApiOptions(pageConfigGlobal, configDefinitionsResolved);
|
|
164
163
|
// global
|
|
165
164
|
const pageConfigGlobalValues = getConfigValues(pageConfigGlobal);
|
|
166
|
-
const
|
|
165
|
+
const userFriendlyConfigsGlobal = (0, getUserFriendlyConfigs_js_1.getUserFriendlyConfigsGlobal)({ pageConfigGlobalValues });
|
|
167
166
|
// pages
|
|
168
|
-
const
|
|
167
|
+
const userFriendlyConfigsPageEager = (0, utils_js_1.objectFromEntries)(pageConfigs.map((pageConfig) => {
|
|
169
168
|
const pageConfigValues = getConfigValues(pageConfig, true);
|
|
170
|
-
return (0,
|
|
169
|
+
return (0, getUserFriendlyConfigs_js_1.getUserFriendlyConfigsPageEager)(pageConfigGlobalValues, pageConfig, pageConfigValues);
|
|
171
170
|
}));
|
|
172
|
-
return {
|
|
171
|
+
return {
|
|
172
|
+
pageConfigs,
|
|
173
|
+
pageConfigGlobal,
|
|
174
|
+
global: userFriendlyConfigsGlobal,
|
|
175
|
+
pages: userFriendlyConfigsPageEager,
|
|
176
|
+
vikeConfigDependencies: esbuildCache.vikeConfigDependencies
|
|
177
|
+
};
|
|
173
178
|
}
|
|
174
179
|
async function resolveConfigDefinitions(plusFilesAll, userRootDir, esbuildCache) {
|
|
175
180
|
const plusFilesAllOrdered = Object.values(plusFilesAll)
|
|
@@ -321,7 +326,6 @@ function assertGlobalConfigLocation(configName, sources, plusFilesAll, configDef
|
|
|
321
326
|
}
|
|
322
327
|
function assertPageConfigs(pageConfigs) {
|
|
323
328
|
pageConfigs.forEach((pageConfig) => {
|
|
324
|
-
(0, assertExtensions_js_1.assertExtensionsRequire)(pageConfig);
|
|
325
329
|
assertOnBeforeRenderEnv(pageConfig);
|
|
326
330
|
});
|
|
327
331
|
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.replaceConstants = replaceConstants;
|
|
7
|
+
const magic_string_1 = __importDefault(require("magic-string"));
|
|
8
|
+
const utils_js_1 = require("../utils.js");
|
|
9
|
+
const normalizeId_js_1 = require("../shared/normalizeId.js");
|
|
10
|
+
const isViteServerBuild_js_1 = require("../shared/isViteServerBuild.js");
|
|
11
|
+
const applyRegExWithMagicString_js_1 = require("../shared/applyRegExWithMagicString.js");
|
|
12
|
+
function replaceConstants() {
|
|
13
|
+
let config;
|
|
14
|
+
return {
|
|
15
|
+
name: 'vike:replaceConstants',
|
|
16
|
+
enforce: 'post',
|
|
17
|
+
apply: 'build',
|
|
18
|
+
configResolved(config_) {
|
|
19
|
+
config = config_;
|
|
20
|
+
},
|
|
21
|
+
transform(code, id, options) {
|
|
22
|
+
id = (0, normalizeId_js_1.normalizeId)(id);
|
|
23
|
+
(0, utils_js_1.assertPosixPath)(id);
|
|
24
|
+
if (id.includes('/node_modules/'))
|
|
25
|
+
return;
|
|
26
|
+
(0, utils_js_1.assertPosixPath)(config.root);
|
|
27
|
+
if (!id.startsWith(config.root))
|
|
28
|
+
return;
|
|
29
|
+
if (!code.includes('import.meta.env.'))
|
|
30
|
+
return;
|
|
31
|
+
const isBuild = config.command === 'build';
|
|
32
|
+
(0, utils_js_1.assert)(isBuild);
|
|
33
|
+
// Used by vike.dev
|
|
34
|
+
// https://github.com/vikejs/vike/blob/08a1ff55c80ddca64ca6d4417fefd45fefeb4ffb/docs/vite.config.ts#L12
|
|
35
|
+
// @ts-expect-error
|
|
36
|
+
if (config._skipVikeReplaceConstants?.(id))
|
|
37
|
+
return;
|
|
38
|
+
const magicString = new magic_string_1.default(code);
|
|
39
|
+
const constantsMap = [];
|
|
40
|
+
constantsMap.push({
|
|
41
|
+
constants: ['pageContext.isClientSide', 'globalContext.isClientSide', 'pageContext.globalContext.isClientSide'],
|
|
42
|
+
replacement: !(0, isViteServerBuild_js_1.isViteServerBuild_safe)(config, options)
|
|
43
|
+
});
|
|
44
|
+
constantsMap.forEach(({ constants, replacement }) => {
|
|
45
|
+
if (!constants.some((c) => code.includes(c)))
|
|
46
|
+
return;
|
|
47
|
+
const regExp = getConstantRegExp(constants);
|
|
48
|
+
(0, applyRegExWithMagicString_js_1.applyRegExpWithMagicString)(magicString, regExp, replacement);
|
|
49
|
+
});
|
|
50
|
+
if (!magicString.hasChanged())
|
|
51
|
+
return null;
|
|
52
|
+
return {
|
|
53
|
+
code: magicString.toString(),
|
|
54
|
+
map: magicString.generateMap({ hires: true, source: id })
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
// Copied & adapted from:
|
|
60
|
+
// https://github.com/rollup/plugins/blob/e1a5ef99f1578eb38a8c87563cb9651db228f3bd/packages/replace/src/index.js#L57-L67
|
|
61
|
+
function getConstantRegExp(constants) {
|
|
62
|
+
const keys = Object.values(constants).sort(longest).map(escape);
|
|
63
|
+
// const delimiters = ['\\b', '\\b(?!\\.)']
|
|
64
|
+
const delimiters = ['(?<!\\.)\\b', '\\b(?!\\.)']; // Improved version, to avoid replacing `globalContext.pageContext.isClientSide` with `globalContext.false`
|
|
65
|
+
const preventAssignment = false; // Let's try without it first, let's see if a user complains
|
|
66
|
+
const lookbehind = preventAssignment ? '(?<!\\b(?:const|let|var)\\s*)' : '';
|
|
67
|
+
const lookahead = preventAssignment ? '(?!\\s*=[^=])' : '';
|
|
68
|
+
const pattern = new RegExp(`${lookbehind}${delimiters[0]}(${keys.join('|')})${delimiters[1]}${lookahead}`, 'g');
|
|
69
|
+
return pattern;
|
|
70
|
+
}
|
|
71
|
+
function escape(str) {
|
|
72
|
+
return str.replace(/[-[\]/{}()*+?.\\^$|]/g, '\\$&');
|
|
73
|
+
}
|
|
74
|
+
function longest(a, b) {
|
|
75
|
+
return b.length - a.length;
|
|
76
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applyRegExpWithMagicString = applyRegExpWithMagicString;
|
|
4
|
+
function applyRegExpWithMagicString(magicString, regExp, replacement) {
|
|
5
|
+
const envStatementRegEx = typeof regExp === 'string' ? new RegExp(regExp, 'g') : regExp;
|
|
6
|
+
let match;
|
|
7
|
+
while ((match = envStatementRegEx.exec(magicString.original))) {
|
|
8
|
+
magicString.overwrite(match.index, match.index + match[0].length, JSON.stringify(replacement));
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -12,7 +12,7 @@ async function findPageFiles(config, fileTypes, isDev) {
|
|
|
12
12
|
const cwd = config.root;
|
|
13
13
|
const { outDirRoot } = (0, getOutDirs_js_1.getOutDirs)(config);
|
|
14
14
|
const timeBase = new Date().getTime();
|
|
15
|
-
let pageFiles = await (0, tinyglobby_1.glob)(fileTypes.map((fileType) => `**/*${fileType}.${utils_js_1.
|
|
15
|
+
let pageFiles = await (0, tinyglobby_1.glob)(fileTypes.map((fileType) => `**/*${fileType}.${utils_js_1.scriptFileExtensionPattern}`), { ignore: ['**/node_modules/**', `${outDirRoot}/**`], cwd, dot: false, expandDirectories: false });
|
|
16
16
|
pageFiles = pageFiles.map((p) => '/' + (0, utils_js_1.toPosixPath)(p));
|
|
17
17
|
const time = new Date().getTime() - timeBase;
|
|
18
18
|
if (isDev) {
|
|
@@ -27,7 +27,7 @@ const log_js_1 = require("./loggerNotProd/log.js");
|
|
|
27
27
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
28
28
|
const isNewError_js_1 = require("../../runtime/renderPage/isNewError.js");
|
|
29
29
|
const loggerProd_js_1 = require("../../runtime/renderPage/loggerProd.js");
|
|
30
|
-
const
|
|
30
|
+
const execHook_js_1 = require("../../../shared/hooks/execHook.js");
|
|
31
31
|
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
32
32
|
(0, loggerRuntime_js_1.overwriteRuntimeProductionLogger)(logRuntimeError, logRuntimeInfo);
|
|
33
33
|
(0, utils_js_1.overwriteAssertProductionLogger)(assertLogger);
|
|
@@ -97,7 +97,7 @@ function logErr(err, httpRequestId = null, errorComesFromVite) {
|
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
// Needs to be after assertion messages handling, because user hooks may throw an assertion error
|
|
100
|
-
const hook = (0,
|
|
100
|
+
const hook = (0, execHook_js_1.isUserHookError)(err);
|
|
101
101
|
if (hook) {
|
|
102
102
|
const { hookName, hookFilePath } = hook;
|
|
103
103
|
(0, log_js_1.logWithVikeTag)(picocolors_1.default.red(`Following error was thrown by the ${hookName}() hook defined at ${hookFilePath}`), 'error', category);
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.resolveClientEntriesDev = resolveClientEntriesDev;
|
|
4
4
|
const utils_js_1 = require("../utils.js");
|
|
5
5
|
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
6
|
-
|
|
6
|
+
function resolveClientEntriesDev(clientEntry, viteDevServer) {
|
|
7
7
|
let userRootDir = viteDevServer.config.root;
|
|
8
8
|
(0, utils_js_1.assert)(userRootDir);
|
|
9
9
|
userRootDir = (0, utils_js_1.toPosixPath)(userRootDir);
|