vike 0.4.228 → 0.4.229-commit-2a06dcc
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/index.js +3 -1
- 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 +9 -5
- 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 +6 -1
- 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/configDefinitionsBuiltIn.js +11 -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/crawlPlusFiles.js +1 -1
- 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 +15 -12
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +11 -11
- 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/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 +7 -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/isScriptFile.js +24 -21
- package/dist/cjs/utils/objectAssign.js +6 -10
- package/dist/cjs/utils/objectReplace.js +4 -4
- package/dist/cjs/utils/{isNpmPackage.js → parseNpmPackage.js} +24 -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/index.js +3 -1
- 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 +9 -5
- 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 +7 -2
- 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/configDefinitionsBuiltIn.js +11 -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/crawlPlusFiles.js +2 -2
- 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 +15 -12
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +11 -11
- 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/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 +7 -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/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 +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 +19 -0
- package/dist/esm/utils/{isNpmPackage.js → parseNpmPackage.js} +24 -24
- 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
|
@@ -50,7 +50,7 @@ __exportStar(require("../../utils/debug.js"), exports);
|
|
|
50
50
|
__exportStar(require("../../utils/urlToFile.js"), exports);
|
|
51
51
|
__exportStar(require("../../utils/getGlobalObject.js"), exports);
|
|
52
52
|
__exportStar(require("../../utils/freezePartial.js"), exports);
|
|
53
|
-
__exportStar(require("../../utils/
|
|
53
|
+
__exportStar(require("../../utils/parseNpmPackage.js"), exports);
|
|
54
54
|
__exportStar(require("../../utils/isNullish.js"), exports);
|
|
55
55
|
__exportStar(require("../../utils/isScriptFile.js"), exports);
|
|
56
56
|
__exportStar(require("../../utils/removeFileExtention.js"), exports);
|
|
@@ -74,4 +74,5 @@ __exportStar(require("../../utils/isVikeReactApp.js"), exports);
|
|
|
74
74
|
__exportStar(require("../../utils/getPropAccessNotation.js"), exports);
|
|
75
75
|
__exportStar(require("../../utils/PROJECT_VERSION.js"), exports);
|
|
76
76
|
__exportStar(require("../../utils/genPromise.js"), exports);
|
|
77
|
-
__exportStar(require("../../utils/
|
|
77
|
+
__exportStar(require("../../utils/getPublicProxy.js"), exports);
|
|
78
|
+
__exportStar(require("../../utils/augmentType.js"), exports);
|
|
@@ -12,7 +12,7 @@ function assertPageContextProvidedByUser(pageContextProvidedByUser, { hookName,
|
|
|
12
12
|
(0, utils_js_1.assert)(!hookName.endsWith(')'));
|
|
13
13
|
const errPrefix = `The ${picocolors_1.default.cyan('pageContext')} object provided by the ${hookName}() hook defined by ${hookFilePath}`;
|
|
14
14
|
(0, utils_js_1.assertUsage)((0, utils_js_1.isObject)(pageContextProvidedByUser), `${errPrefix} should be an object (but it's ${picocolors_1.default.cyan(`typeof pageContext === ${JSON.stringify(typeof pageContextProvidedByUser)}`)} instead)`);
|
|
15
|
-
(0, utils_js_1.assertUsage)(!('
|
|
15
|
+
(0, utils_js_1.assertUsage)(!('isPageContext' in pageContextProvidedByUser), `${errPrefix} shouldn't be the whole ${picocolors_1.default.cyan('pageContext')} object, see https://vike.dev/pageContext-manipulation#do-not-return-entire-pagecontext`);
|
|
16
16
|
// In principle, it's possible to use onBeforeRoute()` to override and define the whole routing.
|
|
17
17
|
// Is that a good idea to allow users to do this? Beyond deep integration with Vue Router or React Router, is there a use case for this?
|
|
18
18
|
(0, utils_js_1.assertWarning)(!('pageId' in pageContextProvidedByUser), `${errPrefix} sets ${picocolors_1.default.cyan('pageContext.pageId')} which means that Vike's routing is overriden. This is an experimental feature: make sure to contact a vike maintainer before using this.`, { onlyOnce: true });
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getGlobalContextSyncErrMsg = void 0;
|
|
4
|
+
exports.createGlobalContextShared = createGlobalContextShared;
|
|
5
|
+
const getGlobalContextSyncErrMsg = "The global context isn't set yet, call getGlobalContextSync() later or use getGlobalContext() instead.";
|
|
6
|
+
exports.getGlobalContextSyncErrMsg = getGlobalContextSyncErrMsg;
|
|
7
|
+
const getPageConfigsRuntime_js_1 = require("./getPageConfigsRuntime.js");
|
|
8
|
+
const executeHookGeneric_js_1 = require("./hooks/executeHookGeneric.js");
|
|
9
|
+
const utils_js_1 = require("./utils.js");
|
|
10
|
+
async function createGlobalContextShared(virtualFileExports, globalObject, addGlobalContext) {
|
|
11
|
+
const globalContext = createGlobalContextBase(virtualFileExports);
|
|
12
|
+
const globalContextAddendum = await addGlobalContext?.(globalContext);
|
|
13
|
+
(0, utils_js_1.objectAssign)(globalContext, globalContextAddendum);
|
|
14
|
+
if (!globalObject.globalContext) {
|
|
15
|
+
globalObject.globalContext = globalContext;
|
|
16
|
+
// - We deliberately call onCreateGlobalContext() only at the beginning and only once per process.
|
|
17
|
+
// - TO-DO/eventually: HMR
|
|
18
|
+
// - Once Photon supports it: `server.hot.send({ type: 'full-server-reload' })`
|
|
19
|
+
// - Either use:
|
|
20
|
+
// - import.meta.hot
|
|
21
|
+
// - https://vite.dev/guide/api-hmr.html
|
|
22
|
+
// - Use a Vite transformer to inject import.meta.hot code into each user-land `+onCreateGlobalContext.js` file
|
|
23
|
+
// - Seems more idiomatic
|
|
24
|
+
// - globalContext._viteDevServer.hot.send()
|
|
25
|
+
// - Send 'full-server-reload' signal whenever a onCreateGlobalContext() function is modified => we need a globalObject to track all hooks and see if one of them is new/modified.
|
|
26
|
+
// - Seems less idiomatic
|
|
27
|
+
await (0, executeHookGeneric_js_1.executeHookGenericGlobalCumulative)('onCreateGlobalContext', globalContext._pageConfigGlobal, null, globalContext);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
// Singleton: ensure all `globalContext` user-land references are preserved & updated.
|
|
31
|
+
// We don't use objectReplace() in order to keep user-land properties.
|
|
32
|
+
(0, utils_js_1.objectAssign)(globalObject.globalContext, globalContext);
|
|
33
|
+
}
|
|
34
|
+
return globalObject.globalContext;
|
|
35
|
+
}
|
|
36
|
+
function createGlobalContextBase(virtualFileExports) {
|
|
37
|
+
const { pageFilesAll, allPageIds, pageConfigs, pageConfigGlobal, globalConfig, pageConfigsUserFriendly } = (0, getPageConfigsRuntime_js_1.getPageConfigsRuntime)(virtualFileExports);
|
|
38
|
+
const globalContext = {
|
|
39
|
+
/**
|
|
40
|
+
* Useful for distinguishing `globalContext` from other objects and narrowing down TypeScript unions.
|
|
41
|
+
*
|
|
42
|
+
* https://vike.dev/globalContext#typescript
|
|
43
|
+
*/
|
|
44
|
+
isGlobalContext: true,
|
|
45
|
+
_virtualFileExports: virtualFileExports,
|
|
46
|
+
_pageFilesAll: pageFilesAll,
|
|
47
|
+
_pageConfigs: pageConfigs,
|
|
48
|
+
_pageConfigGlobal: pageConfigGlobal,
|
|
49
|
+
_allPageIds: allPageIds,
|
|
50
|
+
config: globalConfig.config,
|
|
51
|
+
pages: pageConfigsUserFriendly
|
|
52
|
+
};
|
|
53
|
+
return globalContext;
|
|
54
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createPageContextShared = createPageContextShared;
|
|
4
|
+
const executeHookGeneric_js_1 = require("./hooks/executeHookGeneric.js");
|
|
5
|
+
const getPageConfigUserFriendly_js_1 = require("./page-configs/getPageConfigUserFriendly.js");
|
|
6
|
+
const utils_js_1 = require("./utils.js");
|
|
7
|
+
async function createPageContextShared(pageContextCreated, pageConfigGlobal) {
|
|
8
|
+
const pageConfigGlobalUserFriendly = (0, getPageConfigUserFriendly_js_1.getPageConfigGlobalUserFriendly)({
|
|
9
|
+
pageConfigGlobalValues: pageConfigGlobal.configValues
|
|
10
|
+
});
|
|
11
|
+
(0, utils_js_1.objectAssign)(pageContextCreated, {
|
|
12
|
+
isPageContext: true,
|
|
13
|
+
...pageConfigGlobalUserFriendly
|
|
14
|
+
}, true);
|
|
15
|
+
await (0, executeHookGeneric_js_1.executeHookGenericGlobalCumulative)('onCreatePageContext', pageConfigGlobal, pageContextCreated, pageContextCreated);
|
|
16
|
+
return pageContextCreated;
|
|
17
|
+
}
|
|
@@ -25,7 +25,7 @@ function determineFileType(filePath) {
|
|
|
25
25
|
const isCSS = filePath.endsWith('.css');
|
|
26
26
|
if (isCSS) {
|
|
27
27
|
/* This assert() is skipped to reduce client-side bundle size
|
|
28
|
-
assert(
|
|
28
|
+
assert(isImportPathNpmPackage(filePath), filePath) // `.css` page files are only supported for npm packages
|
|
29
29
|
*/
|
|
30
30
|
return '.css';
|
|
31
31
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.executeHookGeneric = executeHookGeneric;
|
|
4
|
+
exports.executeHookGenericGlobalCumulative = executeHookGenericGlobalCumulative;
|
|
5
|
+
const executeHook_js_1 = require("./executeHook.js");
|
|
6
|
+
const getHook_js_1 = require("./getHook.js");
|
|
7
|
+
async function executeHookGeneric(hookName, pageContext) {
|
|
8
|
+
const hook = (0, getHook_js_1.getHookFromPageContext)(pageContext, hookName);
|
|
9
|
+
if (!hook)
|
|
10
|
+
return;
|
|
11
|
+
await (0, executeHook_js_1.executeHook)(() => hook.hookFn(pageContext), hook, pageContext);
|
|
12
|
+
}
|
|
13
|
+
async function executeHookGenericGlobalCumulative(hookName, pageConfigGlobal, pageContext, arg) {
|
|
14
|
+
const hooks = (0, getHook_js_1.getHookFromPageConfigGlobalCumulative)(pageConfigGlobal, hookName);
|
|
15
|
+
await Promise.all(hooks.map(async (hook) => {
|
|
16
|
+
await (0, executeHook_js_1.executeHook)(() => hook.hookFn(arg), hook, pageContext);
|
|
17
|
+
}));
|
|
18
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.scriptFileExtensionList = exports.
|
|
3
|
+
exports.scriptFileExtensionList = exports.scriptFileExtensionPattern = void 0;
|
|
4
4
|
exports.isScriptFile = isScriptFile;
|
|
5
|
-
exports.
|
|
5
|
+
exports.isPlainScriptFile = isPlainScriptFile;
|
|
6
6
|
exports.isTemplateFile = isTemplateFile;
|
|
7
|
-
const assert_js_1 = require("./assert.js");
|
|
8
7
|
// We can't use a RegExp:
|
|
9
8
|
// - Needs to work with Micromatch: https://github.com/micromatch/micromatch because:
|
|
10
9
|
// - Vite's `import.meta.glob()` uses Micromatch
|
|
@@ -16,26 +15,36 @@ const assert_js_1 = require("./assert.js");
|
|
|
16
15
|
// - A post `import.meta.glob()` blocklist filtering doesn't work because Vite would still process the files (e.g. including them in the bundle).
|
|
17
16
|
// prettier-ignore
|
|
18
17
|
// biome-ignore format:
|
|
19
|
-
const
|
|
18
|
+
const extJs = [
|
|
20
19
|
'js',
|
|
21
|
-
'ts',
|
|
22
20
|
'cjs',
|
|
23
|
-
'cts',
|
|
24
21
|
'mjs',
|
|
22
|
+
];
|
|
23
|
+
// prettier-ignore
|
|
24
|
+
// biome-ignore format:
|
|
25
|
+
const extTs = [
|
|
26
|
+
'ts',
|
|
27
|
+
'cts',
|
|
25
28
|
'mts',
|
|
26
29
|
];
|
|
30
|
+
const extJsOrTs = [...extJs, ...extTs];
|
|
27
31
|
// prettier-ignore
|
|
28
32
|
// biome-ignore format:
|
|
29
33
|
const extJsx = [
|
|
30
34
|
'jsx',
|
|
31
|
-
'tsx',
|
|
32
35
|
'cjsx',
|
|
33
|
-
'ctsx',
|
|
34
36
|
'mjsx',
|
|
35
|
-
'mtsx',
|
|
36
37
|
];
|
|
37
38
|
// prettier-ignore
|
|
38
39
|
// biome-ignore format:
|
|
40
|
+
const extTsx = [
|
|
41
|
+
'tsx',
|
|
42
|
+
'ctsx',
|
|
43
|
+
'mtsx'
|
|
44
|
+
];
|
|
45
|
+
const extJsxOrTsx = [...extJsx, ...extTsx];
|
|
46
|
+
// prettier-ignore
|
|
47
|
+
// biome-ignore format:
|
|
39
48
|
const extTemplates = [
|
|
40
49
|
'vue',
|
|
41
50
|
'svelte',
|
|
@@ -43,21 +52,15 @@ const extTemplates = [
|
|
|
43
52
|
'md',
|
|
44
53
|
'mdx'
|
|
45
54
|
];
|
|
46
|
-
const scriptFileExtensionList = [...
|
|
55
|
+
const scriptFileExtensionList = [...extJsOrTs, ...extJsxOrTsx, ...extTemplates];
|
|
47
56
|
exports.scriptFileExtensionList = scriptFileExtensionList;
|
|
48
|
-
const
|
|
49
|
-
exports.
|
|
57
|
+
const scriptFileExtensionPattern = '(' + scriptFileExtensionList.join('|') + ')';
|
|
58
|
+
exports.scriptFileExtensionPattern = scriptFileExtensionPattern;
|
|
50
59
|
function isScriptFile(filePath) {
|
|
51
|
-
|
|
52
|
-
if (isPlainJavaScriptFile(filePath))
|
|
53
|
-
(0, assert_js_1.assert)(yes);
|
|
54
|
-
return yes;
|
|
60
|
+
return scriptFileExtensionList.some((ext) => filePath.endsWith('.' + ext));
|
|
55
61
|
}
|
|
56
|
-
function
|
|
57
|
-
|
|
58
|
-
const yes2 = extJavaScript.some((ext) => filePath.endsWith('.' + ext));
|
|
59
|
-
(0, assert_js_1.assert)(yes1 === yes2);
|
|
60
|
-
return yes1;
|
|
62
|
+
function isPlainScriptFile(filePath) {
|
|
63
|
+
return extJsOrTs.some((ext) => filePath.endsWith('.' + ext));
|
|
61
64
|
}
|
|
62
65
|
function isTemplateFile(filePath) {
|
|
63
66
|
return extTemplates.some((ext) => filePath.endsWith('.' + ext));
|
|
@@ -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,47 @@
|
|
|
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.getNpmPackageName = getNpmPackageName;
|
|
8
|
+
exports.parseNpmPackage = parseNpmPackage;
|
|
8
9
|
exports.isDistinguishable = isDistinguishable;
|
|
9
10
|
const assert_js_1 = require("./assert.js");
|
|
10
11
|
const assertIsNotBrowser_js_1 = require("./assertIsNotBrowser.js");
|
|
11
12
|
(0, assertIsNotBrowser_js_1.assertIsNotBrowser)();
|
|
12
|
-
function
|
|
13
|
+
function isImportPathNpmPackage(str, { cannotBePathAlias }) {
|
|
13
14
|
(0, assert_js_1.assert)(cannotBePathAlias);
|
|
14
|
-
return
|
|
15
|
+
return isImportPathNpmPackageOrPathAlias(str);
|
|
15
16
|
}
|
|
16
17
|
// We cannot distinguish path aliases that look like npm package imports
|
|
17
|
-
function
|
|
18
|
-
const res =
|
|
18
|
+
function isImportPathNpmPackageOrPathAlias(str) {
|
|
19
|
+
const res = parseNpmPackage(str);
|
|
19
20
|
return res !== null;
|
|
20
21
|
}
|
|
21
|
-
function
|
|
22
|
-
(0, assert_js_1.assert)(
|
|
23
|
-
// If `str` is a path alias that looks like an npm package =>
|
|
22
|
+
function assertIsImportPathNpmPackage(str) {
|
|
23
|
+
(0, assert_js_1.assert)(isImportPathNpmPackage(str, {
|
|
24
|
+
// 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
25
|
cannotBePathAlias: true
|
|
25
26
|
}), str);
|
|
26
27
|
}
|
|
27
28
|
function isNpmPackageName(str) {
|
|
28
|
-
const res =
|
|
29
|
+
const res = parseNpmPackage(str);
|
|
29
30
|
return res !== null && res.importPath === null;
|
|
30
31
|
}
|
|
31
32
|
function getNpmPackageName(str) {
|
|
32
|
-
const res =
|
|
33
|
+
const res = parseNpmPackage(str);
|
|
33
34
|
if (!res)
|
|
34
35
|
return null;
|
|
35
36
|
return res.pkgName;
|
|
36
37
|
}
|
|
37
38
|
function getNpmPackageImportPath(str) {
|
|
38
|
-
const res =
|
|
39
|
+
const res = parseNpmPackage(str);
|
|
39
40
|
if (!res)
|
|
40
41
|
return null;
|
|
41
42
|
return res.importPath;
|
|
42
43
|
}
|
|
43
|
-
function
|
|
44
|
+
function isPathAliasRecommended(alias) {
|
|
44
45
|
// Cannot be distinguished from npm package names
|
|
45
46
|
if (!isDistinguishable(alias))
|
|
46
47
|
return false;
|
|
@@ -56,14 +57,14 @@ function isValidPathAlias(alias) {
|
|
|
56
57
|
return true;
|
|
57
58
|
}
|
|
58
59
|
function isDistinguishable(alias) {
|
|
59
|
-
return (
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
return (parseNpmPackage(alias) === null &&
|
|
61
|
+
parseNpmPackage(`${alias}fake-path`) === null &&
|
|
62
|
+
parseNpmPackage(`${alias}/fake-path`) === null &&
|
|
63
|
+
parseNpmPackage(`${alias}fake/deep/path`) === null &&
|
|
64
|
+
parseNpmPackage(`${alias}/fake/deep/path`) === null &&
|
|
64
65
|
// See note about '-' in ./isNpmPackageName.spec.ts
|
|
65
66
|
// ```ts
|
|
66
|
-
// expect(
|
|
67
|
+
// expect(parseNpmPackage('-')).toBe(null) // actually wrong: https://www.npmjs.com/package/-
|
|
67
68
|
// ```
|
|
68
69
|
!alias.startsWith('-'));
|
|
69
70
|
}
|
|
@@ -71,7 +72,7 @@ function isDistinguishable(alias) {
|
|
|
71
72
|
// - https://www.npmjs.com/package/-
|
|
72
73
|
// The correct logic is complex, see https://github.com/npm/validate-npm-package-name
|
|
73
74
|
// We don't need to be accurate: are there npm packages with weird names that are actually being used?
|
|
74
|
-
function
|
|
75
|
+
function parseNpmPackage(str) {
|
|
75
76
|
if (!str)
|
|
76
77
|
return null;
|
|
77
78
|
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
|
}
|