vike 0.4.228 → 0.4.229
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 +2 -2
- package/dist/cjs/client/client-routing-runtime/globalContext.js +49 -0
- package/dist/cjs/client/server-routing-runtime/globalContext.js +41 -0
- package/dist/cjs/client/server-routing-runtime/utils.js +1 -1
- package/dist/cjs/client/shared/createGetGlobalContextClient.js +58 -0
- package/dist/cjs/client/shared/getJsonSerializedInHtml.js +31 -0
- package/dist/cjs/client/shared/utils.js +22 -0
- package/dist/cjs/node/plugin/plugins/baseUrls.js +1 -1
- package/dist/cjs/node/plugin/plugins/build/handleAssetsManifest.js +10 -5
- package/dist/cjs/node/plugin/plugins/build/pluginBuildApp.js +1 -1
- package/dist/cjs/node/plugin/plugins/build/pluginBuildConfig.js +3 -10
- package/dist/cjs/node/plugin/plugins/build/pluginBuildEntry.js +9 -5
- package/dist/cjs/node/plugin/plugins/build/pluginModuleBanner.js +5 -1
- package/dist/cjs/node/plugin/plugins/commonConfig/assertResolveAlias.js +1 -1
- package/dist/cjs/node/plugin/plugins/commonConfig.js +14 -3
- package/dist/cjs/node/plugin/plugins/devConfig/determineFsAllowList.js +2 -7
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +10 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles/ignorePatternsBuiltIn.js +2 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformPointerImports.js → pointerImports.js} +13 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js +20 -19
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +13 -10
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +11 -11
- package/dist/cjs/node/plugin/shared/getFilePath.js +2 -2
- package/dist/cjs/node/plugin/shared/resolveClientEntriesDev.js +7 -19
- package/dist/cjs/node/plugin/utils.js +1 -0
- package/dist/cjs/node/prerender/runPrerender.js +44 -41
- package/dist/cjs/node/prerender/utils.js +1 -1
- package/dist/cjs/node/runtime/globalContext.js +102 -125
- package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +18 -5
- package/dist/cjs/node/runtime/html/injectAssets/getViteDevScript.js +2 -2
- package/dist/cjs/node/runtime/html/propKeys.js +47 -0
- package/dist/cjs/node/runtime/html/renderHtml.js +1 -1
- package/dist/cjs/node/runtime/html/{serializePageContextClientSide.js → serializeContext.js} +37 -67
- package/dist/cjs/node/runtime/index-deprecated.js +9 -38
- package/dist/cjs/node/runtime/index.js +56 -2
- package/dist/cjs/node/runtime/renderPage/analyzePage.js +1 -1
- package/dist/cjs/node/runtime/renderPage/createHttpResponse.js +8 -3
- package/dist/cjs/node/runtime/renderPage/createPageContextServerSide.js +73 -0
- package/dist/cjs/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.js +2 -2
- package/dist/cjs/node/runtime/renderPage/executeOnRenderHtmlHook.js +2 -2
- package/dist/cjs/node/runtime/renderPage/getPageAssets/getManifestEntry.js +1 -1
- package/dist/cjs/node/runtime/renderPage/getPageAssets/retrieveAssetsDev.js +1 -17
- package/dist/cjs/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.js +1 -1
- package/dist/cjs/node/runtime/renderPage/getPageAssets.js +2 -2
- package/dist/cjs/node/runtime/renderPage/handleErrorWithoutErrorPage.js +1 -1
- package/dist/cjs/node/runtime/renderPage/loadUserFilesServerSide.js +1 -1
- package/dist/cjs/node/runtime/renderPage/log404/index.js +1 -1
- package/dist/cjs/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.js +1 -1
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +3 -68
- package/dist/cjs/node/runtime/renderPage.js +102 -81
- package/dist/cjs/node/runtime/universal-middleware.js +7 -1
- package/dist/cjs/node/runtime/utils.js +3 -2
- package/dist/cjs/shared/assertPageContextProvidedByUser.js +1 -1
- package/dist/cjs/shared/createGlobalContextShared.js +54 -0
- package/dist/cjs/shared/createPageContextShared.js +17 -0
- package/dist/cjs/shared/getPageFiles/fileTypes.js +1 -1
- package/dist/cjs/shared/hooks/executeHookGeneric.js +18 -0
- package/dist/cjs/shared/hooks/getHook.js +45 -27
- package/dist/cjs/shared/htmlElementIds.js +5 -0
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +3 -7
- package/dist/cjs/shared/route/executeGuardHook.js +1 -1
- package/dist/cjs/shared/route/loadPageRoutes.js +2 -1
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/catchInfiniteLoop.js +3 -3
- package/dist/cjs/utils/getPublicProxy.js +27 -0
- package/dist/cjs/utils/isImportPath.js +21 -0
- package/dist/cjs/utils/objectAssign.js +6 -10
- package/dist/cjs/utils/objectReplace.js +4 -4
- package/dist/cjs/utils/{isNpmPackage.js → parseNpmPackage.js} +23 -23
- package/dist/cjs/utils/path.js +12 -2
- package/dist/cjs/utils/requireResolve.js +134 -53
- package/dist/esm/__internal/index.js +3 -3
- package/dist/esm/client/client-routing-runtime/createPageContext.d.ts +29 -10
- package/dist/esm/client/client-routing-runtime/createPageContext.js +23 -22
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.js +5 -4
- package/dist/esm/client/client-routing-runtime/globalContext.d.ts +20 -0
- package/dist/esm/client/client-routing-runtime/globalContext.js +13 -0
- package/dist/esm/client/client-routing-runtime/initOnLinkClick.js +2 -2
- package/dist/esm/client/client-routing-runtime/prefetch.js +2 -2
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +8 -7
- package/dist/esm/client/client-routing-runtime/utils.d.ts +0 -1
- package/dist/esm/client/client-routing-runtime/utils.js +0 -1
- package/dist/esm/client/index.d.ts +1 -0
- package/dist/esm/client/index.js +4 -0
- package/dist/esm/client/node.js +1 -3
- package/dist/esm/client/server-routing-runtime/createPageContextClientSide.d.ts +36 -0
- package/dist/esm/client/server-routing-runtime/createPageContextClientSide.js +47 -0
- package/dist/esm/client/server-routing-runtime/entry.js +2 -2
- package/dist/esm/client/server-routing-runtime/globalContext.d.ts +17 -0
- package/dist/esm/client/server-routing-runtime/globalContext.js +5 -0
- package/dist/esm/client/server-routing-runtime/utils.d.ts +1 -1
- package/dist/esm/client/server-routing-runtime/utils.js +1 -1
- package/dist/esm/client/shared/createGetGlobalContextClient.d.ts +23 -0
- package/dist/esm/client/shared/createGetGlobalContextClient.js +58 -0
- package/dist/esm/client/shared/executeOnRenderClientHook.js +5 -4
- package/dist/esm/client/shared/{getPageContextSerializedInHtml.d.ts → getJsonSerializedInHtml.d.ts} +2 -0
- package/dist/esm/client/shared/getJsonSerializedInHtml.js +29 -0
- package/dist/esm/client/shared/removeFoucBuster.js +1 -0
- package/dist/esm/client/shared/utils.d.ts +4 -0
- package/dist/esm/client/shared/utils.js +4 -0
- package/dist/esm/node/plugin/plugins/baseUrls.js +2 -2
- package/dist/esm/node/plugin/plugins/build/handleAssetsManifest.js +11 -6
- package/dist/esm/node/plugin/plugins/build/pluginBuildApp.js +2 -2
- package/dist/esm/node/plugin/plugins/build/pluginBuildConfig.js +4 -11
- package/dist/esm/node/plugin/plugins/build/pluginBuildEntry.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/build/pluginBuildEntry.js +10 -6
- package/dist/esm/node/plugin/plugins/build/pluginModuleBanner.js +5 -1
- package/dist/esm/node/plugin/plugins/commonConfig/assertResolveAlias.js +2 -2
- package/dist/esm/node/plugin/plugins/commonConfig.d.ts +2 -0
- package/dist/esm/node/plugin/plugins/commonConfig.js +15 -4
- package/dist/esm/node/plugin/plugins/devConfig/determineFsAllowList.js +3 -8
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +10 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles/ignorePatternsBuiltIn.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles/ignorePatternsBuiltIn.js +2 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformPointerImports.d.ts → pointerImports.d.ts} +2 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformPointerImports.js → pointerImports.js} +14 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js +20 -19
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +13 -10
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +11 -11
- package/dist/esm/node/plugin/shared/getFilePath.js +3 -3
- package/dist/esm/node/plugin/shared/resolveClientEntriesDev.js +8 -20
- package/dist/esm/node/plugin/utils.d.ts +1 -0
- package/dist/esm/node/plugin/utils.js +1 -0
- package/dist/esm/node/prerender/runPrerender.d.ts +314 -5
- package/dist/esm/node/prerender/runPrerender.js +48 -45
- 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 +425 -47
- package/dist/esm/node/runtime/globalContext.js +103 -126
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +18 -5
- package/dist/esm/node/runtime/html/injectAssets/getViteDevScript.d.ts +2 -2
- package/dist/esm/node/runtime/html/injectAssets/getViteDevScript.js +2 -2
- package/dist/esm/node/runtime/html/injectAssets.d.ts +3 -3
- package/dist/esm/node/runtime/html/propKeys.d.ts +8 -0
- package/dist/esm/node/runtime/html/propKeys.js +45 -0
- package/dist/esm/node/runtime/html/renderHtml.js +1 -1
- package/dist/esm/node/runtime/html/{serializePageContextClientSide.d.ts → serializeContext.d.ts} +7 -6
- package/dist/esm/node/runtime/html/{serializePageContextClientSide.js → serializeContext.js} +36 -67
- package/dist/esm/node/runtime/index-deprecated.d.ts +1 -16
- package/dist/esm/node/runtime/index-deprecated.js +9 -36
- package/dist/esm/node/runtime/index.d.ts +23 -1
- package/dist/esm/node/runtime/index.js +38 -3
- package/dist/esm/node/runtime/renderPage/analyzePage.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/analyzePage.js +1 -1
- package/dist/esm/node/runtime/renderPage/createHttpResponse.d.ts +5 -4
- package/dist/esm/node/runtime/renderPage/createHttpResponse.js +8 -3
- package/dist/esm/node/runtime/renderPage/createPageContextServerSide.d.ts +155 -0
- package/dist/esm/node/runtime/renderPage/createPageContextServerSide.js +71 -0
- package/dist/esm/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.js +3 -3
- package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.js +3 -3
- package/dist/esm/node/runtime/renderPage/getPageAssets/getManifestEntry.js +2 -2
- package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsDev.js +1 -17
- package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.js +2 -2
- package/dist/esm/node/runtime/renderPage/getPageAssets.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/getPageAssets.js +2 -2
- package/dist/esm/node/runtime/renderPage/handleErrorWithoutErrorPage.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/handleErrorWithoutErrorPage.js +1 -1
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.js +1 -1
- package/dist/esm/node/runtime/renderPage/log404/index.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/log404/index.js +1 -1
- package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.d.ts +3 -3
- package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.js +1 -1
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +225 -179
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +4 -69
- package/dist/esm/node/runtime/renderPage.d.ts +146 -7
- package/dist/esm/node/runtime/renderPage.js +105 -84
- package/dist/esm/node/runtime/universal-middleware.js +7 -1
- package/dist/esm/node/runtime/utils.d.ts +3 -2
- package/dist/esm/node/runtime/utils.js +3 -2
- package/dist/esm/shared/VikeNamespace.d.ts +35 -13
- package/dist/esm/shared/assertPageContextProvidedByUser.js +1 -1
- package/dist/esm/shared/createGlobalContextShared.d.ts +39 -0
- package/dist/esm/shared/createGlobalContextShared.js +51 -0
- package/dist/esm/shared/createPageContextShared.d.ts +9 -0
- package/dist/esm/shared/createPageContextShared.js +15 -0
- package/dist/esm/shared/getPageFiles/fileTypes.js +1 -1
- package/dist/esm/shared/hooks/executeHookGeneric.d.ts +8 -0
- package/dist/esm/shared/hooks/executeHookGeneric.js +16 -0
- package/dist/esm/shared/hooks/getHook.d.ts +5 -3
- package/dist/esm/shared/hooks/getHook.js +47 -29
- package/dist/esm/shared/htmlElementIds.d.ts +2 -0
- package/dist/esm/shared/htmlElementIds.js +2 -0
- package/dist/esm/shared/page-configs/Config.d.ts +12 -2
- package/dist/esm/shared/page-configs/getConfigDefinedAt.d.ts +1 -1
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +3 -7
- package/dist/esm/shared/route/executeGuardHook.js +2 -2
- package/dist/esm/shared/route/loadPageRoutes.js +2 -1
- package/dist/esm/shared/types.d.ts +64 -32
- package/dist/esm/types/index.d.ts +1 -5
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/catchInfiniteLoop.js +4 -4
- package/dist/esm/utils/getGlobalObject.d.ts +1 -1
- package/dist/esm/utils/getPublicProxy.d.ts +2 -0
- package/dist/esm/utils/getPublicProxy.js +25 -0
- package/dist/esm/utils/isImportPath.d.ts +4 -0
- package/dist/esm/utils/isImportPath.js +19 -0
- package/dist/esm/utils/objectAssign.d.ts +1 -1
- package/dist/esm/utils/objectAssign.js +6 -10
- package/dist/esm/utils/objectReplace.d.ts +1 -1
- package/dist/esm/utils/objectReplace.js +4 -4
- package/dist/esm/utils/parseNpmPackage.d.ts +17 -0
- package/dist/esm/utils/{isNpmPackage.js → parseNpmPackage.js} +23 -23
- package/dist/esm/utils/path.d.ts +1 -1
- package/dist/esm/utils/path.js +12 -2
- package/dist/esm/utils/requireResolve.d.ts +20 -7
- package/dist/esm/utils/requireResolve.js +134 -53
- package/package.json +14 -13
- package/dist/cjs/node/runtime/index-common.js +0 -27
- package/dist/cjs/utils/makePublicCopy.js +0 -32
- package/dist/esm/client/server-routing-runtime/getPageContext.d.ts +0 -19
- package/dist/esm/client/server-routing-runtime/getPageContext.js +0 -44
- package/dist/esm/client/shared/getPageContextSerializedInHtml.js +0 -20
- package/dist/esm/node/runtime/index-common.d.ts +0 -8
- package/dist/esm/node/runtime/index-common.js +0 -10
- package/dist/esm/utils/isNpmPackage.d.ts +0 -17
- package/dist/esm/utils/makePublicCopy.d.ts +0 -3
- package/dist/esm/utils/makePublicCopy.js +0 -30
|
@@ -3,9 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.getHookFromPageContext = getHookFromPageContext;
|
|
7
7
|
exports.getHookFromPageConfig = getHookFromPageConfig;
|
|
8
8
|
exports.getHookFromPageConfigGlobal = getHookFromPageConfigGlobal;
|
|
9
|
+
exports.getHookFromPageConfigGlobalCumulative = getHookFromPageConfigGlobalCumulative;
|
|
9
10
|
exports.assertHook = assertHook;
|
|
10
11
|
exports.getHook_setIsPrerenderering = getHook_setIsPrerenderering;
|
|
11
12
|
exports.getHookTimeoutDefault = getHookTimeoutDefault;
|
|
@@ -15,59 +16,76 @@ const getConfigValueRuntime_js_1 = require("../page-configs/getConfigValueRuntim
|
|
|
15
16
|
const utils_js_1 = require("../utils.js");
|
|
16
17
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
17
18
|
const globalObject = (0, getGlobalObject_js_1.getGlobalObject)('hooks/getHook.ts', {});
|
|
18
|
-
function
|
|
19
|
+
function getHookFromPageContext(pageContext, hookName) {
|
|
19
20
|
if (!(hookName in pageContext.exports)) {
|
|
20
21
|
return null;
|
|
21
22
|
}
|
|
22
23
|
const { hooksTimeout } = pageContext.config;
|
|
23
24
|
const hookTimeout = getHookTimeout(hooksTimeout, hookName);
|
|
24
25
|
const hookFn = pageContext.exports[hookName];
|
|
25
|
-
const file = pageContext.exportsAll[hookName][0];
|
|
26
|
-
(0, utils_js_1.assert)(file.exportValue === hookFn);
|
|
27
26
|
if (hookFn === null)
|
|
28
27
|
return null;
|
|
28
|
+
const file = pageContext.exportsAll[hookName][0];
|
|
29
|
+
(0, utils_js_1.assert)(file.exportValue === hookFn);
|
|
29
30
|
const hookFilePath = file.filePath;
|
|
30
31
|
(0, utils_js_1.assert)(hookFilePath);
|
|
31
|
-
(
|
|
32
|
-
assertHookFn(hookFn, { hookName, hookFilePath });
|
|
33
|
-
return { hookFn, hookName, hookFilePath, hookTimeout };
|
|
32
|
+
return getHook(hookFn, hookName, hookFilePath, hookTimeout);
|
|
34
33
|
}
|
|
35
34
|
function getHookFromPageConfig(pageConfig, hookName) {
|
|
36
35
|
const configValue = (0, getConfigValueRuntime_js_1.getConfigValueRuntime)(pageConfig, hookName);
|
|
37
|
-
|
|
38
|
-
if (!configValue)
|
|
36
|
+
if (!configValue?.value)
|
|
39
37
|
return null;
|
|
40
|
-
const hookFn = configValue
|
|
41
|
-
|
|
42
|
-
return null;
|
|
43
|
-
const hookFilePath = (0, helpers_js_1.getHookFilePathToShowToUser)(configValue.definedAtData);
|
|
44
|
-
// hook isn't a computed nor a cumulative config => hookFilePath should always be defined
|
|
45
|
-
(0, utils_js_1.assert)(hookFilePath);
|
|
46
|
-
assertHookFn(hookFn, { hookName, hookFilePath });
|
|
38
|
+
const { hookFn, hookFilePath } = getHookFromConfigValue(configValue);
|
|
39
|
+
const hooksTimeout = (0, getConfigValueRuntime_js_1.getConfigValueRuntime)(pageConfig, 'hooksTimeout')?.value;
|
|
47
40
|
const hookTimeout = getHookTimeout(hooksTimeout, hookName);
|
|
48
|
-
return
|
|
41
|
+
return getHook(hookFn, hookName, hookFilePath, hookTimeout);
|
|
49
42
|
}
|
|
50
43
|
function getHookFromPageConfigGlobal(pageConfigGlobal, hookName) {
|
|
51
44
|
const configValue = pageConfigGlobal.configValues[hookName];
|
|
52
|
-
if (!configValue)
|
|
53
|
-
return null;
|
|
54
|
-
const hookFn = configValue.value;
|
|
55
|
-
if (!hookFn)
|
|
45
|
+
if (!configValue?.value)
|
|
56
46
|
return null;
|
|
57
|
-
const hookFilePath = (
|
|
58
|
-
|
|
47
|
+
const { hookFn, hookFilePath } = getHookFromConfigValue(configValue);
|
|
48
|
+
const hookTimeout = getHookTimeoutGlobal(hookName);
|
|
49
|
+
return getHook(hookFn, hookName, hookFilePath, hookTimeout);
|
|
50
|
+
}
|
|
51
|
+
function getHookFromPageConfigGlobalCumulative(pageConfigGlobal, hookName) {
|
|
52
|
+
const configValue = pageConfigGlobal.configValues[hookName];
|
|
53
|
+
if (!configValue?.value)
|
|
54
|
+
return [];
|
|
55
|
+
const val = configValue.value;
|
|
56
|
+
(0, utils_js_1.assert)((0, utils_js_1.isArray)(val));
|
|
57
|
+
return val.map((v, i) => {
|
|
58
|
+
const hookFn = v;
|
|
59
|
+
const hookTimeout = getHookTimeoutGlobal(hookName);
|
|
60
|
+
(0, utils_js_1.assert)((0, utils_js_1.isArray)(configValue.definedAtData));
|
|
61
|
+
const hookFilePath = (0, helpers_js_1.getHookFilePathToShowToUser)(configValue.definedAtData[i]);
|
|
62
|
+
return getHook(hookFn, hookName, hookFilePath, hookTimeout);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
function getHookTimeoutGlobal(hookName) {
|
|
66
|
+
// TO-DO/perfection: we could use the global value of configooksTimeout but it requires some non-trivial refactoring
|
|
67
|
+
const hookTimeout = getHookTimeoutDefault(hookName);
|
|
68
|
+
return hookTimeout;
|
|
69
|
+
}
|
|
70
|
+
function getHook(hookFn, hookName, hookFilePath, hookTimeout) {
|
|
59
71
|
(0, utils_js_1.assert)(hookFilePath);
|
|
60
72
|
assertHookFn(hookFn, { hookName, hookFilePath });
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
73
|
+
const hook = { hookFn, hookName, hookFilePath, hookTimeout };
|
|
74
|
+
return hook;
|
|
75
|
+
}
|
|
76
|
+
function getHookFromConfigValue(configValue) {
|
|
77
|
+
const hookFn = configValue.value;
|
|
78
|
+
(0, utils_js_1.assert)(hookFn);
|
|
79
|
+
const hookFilePath = (0, helpers_js_1.getHookFilePathToShowToUser)(configValue.definedAtData);
|
|
80
|
+
return { hookFn, hookFilePath };
|
|
64
81
|
}
|
|
65
82
|
function assertHook(pageContext, hookName) {
|
|
66
|
-
|
|
83
|
+
getHookFromPageContext(pageContext, hookName);
|
|
67
84
|
}
|
|
68
85
|
function assertHookFn(hookFn, { hookName, hookFilePath }) {
|
|
69
86
|
(0, utils_js_1.assert)(hookName && hookFilePath);
|
|
70
87
|
(0, utils_js_1.assert)(!hookName.endsWith(')'));
|
|
88
|
+
(0, utils_js_1.assert)(!hookFilePath.endsWith(' '));
|
|
71
89
|
(0, utils_js_1.assertUsage)((0, utils_js_1.isCallable)(hookFn), `Hook ${hookName}() defined by ${hookFilePath} should be a function`);
|
|
72
90
|
(0, utils_js_1.checkType)(hookFn);
|
|
73
91
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.htmlElementId_globalContext = exports.htmlElementId_pageContext = void 0;
|
|
4
|
+
exports.htmlElementId_pageContext = 'vike_pageContext';
|
|
5
|
+
exports.htmlElementId_globalContext = 'vike_globalContext';
|
|
@@ -8,7 +8,7 @@ exports.getConfigValuesBase = getConfigValuesBase;
|
|
|
8
8
|
exports.isJsonValue = isJsonValue;
|
|
9
9
|
const assertSetup_js_1 = require("../../../utils/assertSetup.js");
|
|
10
10
|
const utils_js_1 = require("../../../node/plugin/utils.js");
|
|
11
|
-
const
|
|
11
|
+
const pointerImports_js_1 = require("../../../node/plugin/plugins/importUserCode/v1-design/getVikeConfig/pointerImports.js");
|
|
12
12
|
const helpers_js_1 = require("../helpers.js");
|
|
13
13
|
const stringify_1 = require("@brillout/json-serializer/stringify");
|
|
14
14
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
@@ -134,7 +134,7 @@ function valueToJson(value, configName, definedAtData, importStatements, filesEn
|
|
|
134
134
|
// - https://github.com/vikejs/vike-react/pull/113
|
|
135
135
|
replacer(_, value) {
|
|
136
136
|
if (typeof value === 'string') {
|
|
137
|
-
const importData = (0,
|
|
137
|
+
const importData = (0, pointerImports_js_1.parsePointerImportData)(value);
|
|
138
138
|
if (importData) {
|
|
139
139
|
const { importName } = addImportStatement(importStatements, importData.importPath, importData.exportName, filesEnv, configEnv, configName);
|
|
140
140
|
const replacement = [REPLACE_ME_BEFORE, importName, REPLACE_ME_AFTER].join('');
|
|
@@ -269,10 +269,10 @@ function addImportStatement(importStatements, importPath, exportName, filesEnv,
|
|
|
269
269
|
return { importName };
|
|
270
270
|
}
|
|
271
271
|
function assertFileEnv(importPath, configEnv, configName, filesEnv) {
|
|
272
|
+
(0, utils_js_1.assert)(!(0, utils_js_1.isImportPathRelative)(importPath));
|
|
272
273
|
const key = importPath;
|
|
273
274
|
(0, utils_js_1.assert)(key);
|
|
274
275
|
(0, utils_js_1.assertPosixPath)(key);
|
|
275
|
-
(0, utils_js_1.assert)(!isRelativeImportPath(key));
|
|
276
276
|
if (!filesEnv.has(key)) {
|
|
277
277
|
filesEnv.set(key, []);
|
|
278
278
|
}
|
|
@@ -288,7 +288,3 @@ function assertFileEnv(importPath, configEnv, configName, filesEnv) {
|
|
|
288
288
|
].join('\n'));
|
|
289
289
|
}
|
|
290
290
|
}
|
|
291
|
-
// TODO/now dedupe
|
|
292
|
-
function isRelativeImportPath(importPath) {
|
|
293
|
-
return importPath.startsWith('./') || importPath.startsWith('../');
|
|
294
|
-
}
|
|
@@ -14,7 +14,7 @@ async function executeGuardHook(pageContext, prepareForUserConsumption) {
|
|
|
14
14
|
}
|
|
15
15
|
else {
|
|
16
16
|
// V1 design
|
|
17
|
-
hook = (0, getHook_js_1.
|
|
17
|
+
hook = (0, getHook_js_1.getHookFromPageContext)(pageContext, 'guard');
|
|
18
18
|
}
|
|
19
19
|
if (!hook)
|
|
20
20
|
return;
|
|
@@ -10,7 +10,7 @@ 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");
|
|
12
12
|
async function loadPageRoutes(
|
|
13
|
-
// Remove all arguments and use
|
|
13
|
+
// Remove all arguments and use GlobalContextServerInternal instead?
|
|
14
14
|
pageFilesAll, pageConfigs, pageConfigGlobal, allPageIds) {
|
|
15
15
|
// TODO/next-major: remove & make this function sync
|
|
16
16
|
await Promise.all(pageFilesAll.filter((p) => p.fileType === '.page.route').map((p) => p.loadFile?.()));
|
|
@@ -47,6 +47,7 @@ function getPageRoutes(filesystemRoots, pageFilesAll, pageConfigs, allPageIds) {
|
|
|
47
47
|
}
|
|
48
48
|
else {
|
|
49
49
|
(0, utils_js_1.assert)((0, utils_js_2.isCallable)(route));
|
|
50
|
+
// TODO/next-major: remove
|
|
50
51
|
if ((0, getConfigValueRuntime_js_1.getConfigValueRuntime)(pageConfig, 'iKnowThePerformanceRisksOfAsyncRouteFunctions', 'boolean'))
|
|
51
52
|
(0, resolveRouteFunction_js_1.warnDeprecatedAllowKey)();
|
|
52
53
|
pageRoute = {
|
|
@@ -14,14 +14,14 @@ function catchInfiniteLoop(functionName, maxNumberOfCalls = 100, withinSeconds =
|
|
|
14
14
|
// Count
|
|
15
15
|
tracker.count++;
|
|
16
16
|
// Error
|
|
17
|
-
const msg = `[Infinite Loop]
|
|
17
|
+
const msg = `[Infinite Loop] Rendering ${tracker.count} times within ${withinSeconds} seconds [${functionName}]`;
|
|
18
18
|
if (tracker.count > maxNumberOfCalls) {
|
|
19
|
-
(0, assert_js_1.
|
|
19
|
+
(0, assert_js_1.assertUsage)(false, msg);
|
|
20
20
|
}
|
|
21
21
|
// Warning, at 50% threshold
|
|
22
22
|
if (!tracker.warned && tracker.count > maxNumberOfCalls * 0.5) {
|
|
23
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 });
|
|
24
|
+
(0, assert_js_1.assertWarning)(false, msg, { onlyOnce: false, showStackTrace: true });
|
|
25
25
|
tracker.warned = true;
|
|
26
26
|
}
|
|
27
27
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPublicProxy = getPublicProxy;
|
|
4
|
+
// We use a proxy instead of property getters.
|
|
5
|
+
// - The issue with property getters is that they can't be `writable: true` but we do want the user to be able to modify the value of internal properties.
|
|
6
|
+
// ```console
|
|
7
|
+
// TypeError: Invalid property descriptor. Cannot both specify accessors and a value or writable attribute, #<Object>
|
|
8
|
+
// ```
|
|
9
|
+
// - Previous implementation using property getters: https://github.com/vikejs/vike/blob/main/vike/utils/makePublicCopy.ts
|
|
10
|
+
const assert_js_1 = require("./assert.js");
|
|
11
|
+
// Show warning when user is accessing internal `_` properties.
|
|
12
|
+
function getPublicProxy(obj, objName, propsPublic, expectCustomUserLandProps) {
|
|
13
|
+
if (!expectCustomUserLandProps) {
|
|
14
|
+
Object.keys(obj).forEach((key) => (0, assert_js_1.assert)(key.startsWith('_') || propsPublic.includes(key)));
|
|
15
|
+
propsPublic.forEach((prop) => prop in obj);
|
|
16
|
+
}
|
|
17
|
+
return new Proxy(obj, {
|
|
18
|
+
get(_, prop) {
|
|
19
|
+
const propStr = String(prop);
|
|
20
|
+
if (propStr.startsWith('_')) {
|
|
21
|
+
(0, assert_js_1.assertWarning)(false, `Using internal ${objName}.${propStr} 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 });
|
|
22
|
+
}
|
|
23
|
+
// @ts-ignore Seems to be TypeScript bug
|
|
24
|
+
return Reflect.get(...arguments);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isImportPath = isImportPath;
|
|
4
|
+
exports.isImportPathRelative = isImportPathRelative;
|
|
5
|
+
const path_js_1 = require("./path.js");
|
|
6
|
+
const assert_js_1 = require("./assert.js");
|
|
7
|
+
const parseNpmPackage_js_1 = require("./parseNpmPackage.js");
|
|
8
|
+
function isImportPath(importPath) {
|
|
9
|
+
return isImportPathRelative(importPath) || (0, parseNpmPackage_js_1.isImportPathNpmPackageOrPathAlias)(importPath);
|
|
10
|
+
}
|
|
11
|
+
// See also `import { pathIsRelative } from './path'`
|
|
12
|
+
function isImportPathRelative(importPath) {
|
|
13
|
+
(0, path_js_1.assertPosixPath)(importPath);
|
|
14
|
+
if (importPath.startsWith('./') || importPath.startsWith('../')) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
(0, assert_js_1.assert)(!importPath.startsWith('.'));
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -4,15 +4,11 @@ exports.objectAssign = objectAssign;
|
|
|
4
4
|
const assert_js_1 = require("./assert.js");
|
|
5
5
|
// Same as Object.assign() but:
|
|
6
6
|
// - With type inference
|
|
7
|
-
// - Preserves property descriptors, which we need for preserving the getters
|
|
7
|
+
// - Preserves property descriptors, which we need for preserving the getters of getPageContextUrlComputed()
|
|
8
8
|
function objectAssign(obj, objAddendum, objAddendumCanBePageContextObject) {
|
|
9
|
-
if (objAddendum)
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
(0, assert_js_1.assert)(!('_isPageContextObject' in objAddendum));
|
|
15
|
-
}
|
|
16
|
-
Object.defineProperties(obj, Object.getOwnPropertyDescriptors(objAddendum));
|
|
17
|
-
}
|
|
9
|
+
if (!objAddendum)
|
|
10
|
+
return;
|
|
11
|
+
if (!objAddendumCanBePageContextObject)
|
|
12
|
+
(0, assert_js_1.assert)(!('isPageContext' in objAddendum));
|
|
13
|
+
Object.defineProperties(obj, Object.getOwnPropertyDescriptors(objAddendum));
|
|
18
14
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.objectReplace = objectReplace;
|
|
4
|
-
function objectReplace(
|
|
5
|
-
Object.keys(
|
|
4
|
+
function objectReplace(objOld, objNew, except) {
|
|
5
|
+
Object.keys(objOld)
|
|
6
6
|
.filter((key) => !except?.includes(key))
|
|
7
|
-
.forEach((key) => delete
|
|
8
|
-
Object.
|
|
7
|
+
.forEach((key) => delete objOld[key]);
|
|
8
|
+
Object.defineProperties(objOld, Object.getOwnPropertyDescriptors(objNew));
|
|
9
9
|
}
|
|
@@ -1,46 +1,46 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.
|
|
5
|
-
exports.
|
|
6
|
-
exports.
|
|
7
|
-
exports.
|
|
3
|
+
exports.isImportPathNpmPackage = isImportPathNpmPackage;
|
|
4
|
+
exports.isImportPathNpmPackageOrPathAlias = isImportPathNpmPackageOrPathAlias;
|
|
5
|
+
exports.assertIsImportPathNpmPackage = assertIsImportPathNpmPackage;
|
|
6
|
+
exports.isPathAliasRecommended = isPathAliasRecommended;
|
|
7
|
+
exports.parseNpmPackage = parseNpmPackage;
|
|
8
8
|
exports.isDistinguishable = isDistinguishable;
|
|
9
9
|
const assert_js_1 = require("./assert.js");
|
|
10
10
|
const assertIsNotBrowser_js_1 = require("./assertIsNotBrowser.js");
|
|
11
11
|
(0, assertIsNotBrowser_js_1.assertIsNotBrowser)();
|
|
12
|
-
function
|
|
12
|
+
function isImportPathNpmPackage(str, { cannotBePathAlias }) {
|
|
13
13
|
(0, assert_js_1.assert)(cannotBePathAlias);
|
|
14
|
-
return
|
|
14
|
+
return isImportPathNpmPackageOrPathAlias(str);
|
|
15
15
|
}
|
|
16
16
|
// We cannot distinguish path aliases that look like npm package imports
|
|
17
|
-
function
|
|
18
|
-
const res =
|
|
17
|
+
function isImportPathNpmPackageOrPathAlias(str) {
|
|
18
|
+
const res = parseNpmPackage(str);
|
|
19
19
|
return res !== null;
|
|
20
20
|
}
|
|
21
|
-
function
|
|
22
|
-
(0, assert_js_1.assert)(
|
|
23
|
-
// If `str` is a path alias that looks like an npm package =>
|
|
21
|
+
function assertIsImportPathNpmPackage(str) {
|
|
22
|
+
(0, assert_js_1.assert)(isImportPathNpmPackage(str, {
|
|
23
|
+
// If `str` is a path alias that looks like an npm package => assertIsImportPathNpmPackage() is erroneous but that's okay because the assertion will eventually fail for some other user using a disambiguated path alias.
|
|
24
24
|
cannotBePathAlias: true
|
|
25
25
|
}), str);
|
|
26
26
|
}
|
|
27
27
|
function isNpmPackageName(str) {
|
|
28
|
-
const res =
|
|
28
|
+
const res = parseNpmPackage(str);
|
|
29
29
|
return res !== null && res.importPath === null;
|
|
30
30
|
}
|
|
31
31
|
function getNpmPackageName(str) {
|
|
32
|
-
const res =
|
|
32
|
+
const res = parseNpmPackage(str);
|
|
33
33
|
if (!res)
|
|
34
34
|
return null;
|
|
35
35
|
return res.pkgName;
|
|
36
36
|
}
|
|
37
37
|
function getNpmPackageImportPath(str) {
|
|
38
|
-
const res =
|
|
38
|
+
const res = parseNpmPackage(str);
|
|
39
39
|
if (!res)
|
|
40
40
|
return null;
|
|
41
41
|
return res.importPath;
|
|
42
42
|
}
|
|
43
|
-
function
|
|
43
|
+
function isPathAliasRecommended(alias) {
|
|
44
44
|
// Cannot be distinguished from npm package names
|
|
45
45
|
if (!isDistinguishable(alias))
|
|
46
46
|
return false;
|
|
@@ -56,14 +56,14 @@ function isValidPathAlias(alias) {
|
|
|
56
56
|
return true;
|
|
57
57
|
}
|
|
58
58
|
function isDistinguishable(alias) {
|
|
59
|
-
return (
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
59
|
+
return (parseNpmPackage(alias) === null &&
|
|
60
|
+
parseNpmPackage(`${alias}fake-path`) === null &&
|
|
61
|
+
parseNpmPackage(`${alias}/fake-path`) === null &&
|
|
62
|
+
parseNpmPackage(`${alias}fake/deep/path`) === null &&
|
|
63
|
+
parseNpmPackage(`${alias}/fake/deep/path`) === null &&
|
|
64
64
|
// See note about '-' in ./isNpmPackageName.spec.ts
|
|
65
65
|
// ```ts
|
|
66
|
-
// expect(
|
|
66
|
+
// expect(parseNpmPackage('-')).toBe(null) // actually wrong: https://www.npmjs.com/package/-
|
|
67
67
|
// ```
|
|
68
68
|
!alias.startsWith('-'));
|
|
69
69
|
}
|
|
@@ -71,7 +71,7 @@ function isDistinguishable(alias) {
|
|
|
71
71
|
// - https://www.npmjs.com/package/-
|
|
72
72
|
// The correct logic is complex, see https://github.com/npm/validate-npm-package-name
|
|
73
73
|
// We don't need to be accurate: are there npm packages with weird names that are actually being used?
|
|
74
|
-
function
|
|
74
|
+
function parseNpmPackage(str) {
|
|
75
75
|
if (!str)
|
|
76
76
|
return null;
|
|
77
77
|
let scope = null;
|
package/dist/cjs/utils/path.js
CHANGED
|
@@ -44,6 +44,16 @@ function assertPosixPath(path) {
|
|
|
44
44
|
(0, assert_js_1.assert)(path);
|
|
45
45
|
(0, assert_js_1.assert)(!path.includes('\\'), errMsg(path));
|
|
46
46
|
}
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
// See also `import { isImportPathRelative } from './isImportPath.js'`
|
|
48
|
+
function pathIsRelative(path) {
|
|
49
|
+
assertPosixPath(path);
|
|
50
|
+
if (path.startsWith('./') || path.startsWith('../')) {
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
/* Not true if `path` starts with a hidden directory (i.e. a directory with a name that starts with `.`)
|
|
55
|
+
assert(!path.startsWith('.'))
|
|
56
|
+
*/
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
49
59
|
}
|