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
|
@@ -19,6 +19,17 @@ const configDefinitionsBuiltIn = {
|
|
|
19
19
|
onPageTransitionEnd: {
|
|
20
20
|
env: { client: true }
|
|
21
21
|
},
|
|
22
|
+
onCreatePageContext: {
|
|
23
|
+
env: { server: true, client: true },
|
|
24
|
+
// Required because `onCreatePageContext()` is called before routing
|
|
25
|
+
global: true,
|
|
26
|
+
cumulative: true
|
|
27
|
+
},
|
|
28
|
+
onCreateGlobalContext: {
|
|
29
|
+
env: { server: true, client: true },
|
|
30
|
+
global: true,
|
|
31
|
+
cumulative: true
|
|
32
|
+
},
|
|
22
33
|
onBeforeRender: {
|
|
23
34
|
env: { server: true }
|
|
24
35
|
},
|
|
@@ -11,6 +11,8 @@ exports.ignorePatternsBuiltIn = [
|
|
|
11
11
|
// +Page.telefunc.js
|
|
12
12
|
// ```
|
|
13
13
|
'**/*.telefunc.*',
|
|
14
|
+
// https://github.com/vikejs/vike/issues/1589#issuecomment-2031925598
|
|
15
|
+
'**/.history/**',
|
|
14
16
|
// https://github.com/vikejs/vike/discussions/2222
|
|
15
17
|
'**/*.generated.*'
|
|
16
18
|
];
|
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/loadFileAtConfigTime.js
CHANGED
|
@@ -12,7 +12,7 @@ const transpileAndExecuteFile_js_1 = require("./transpileAndExecuteFile.js");
|
|
|
12
12
|
const getVikeConfig_js_1 = require("../getVikeConfig.js");
|
|
13
13
|
const assertPlusFileExport_js_1 = require("../../../../../../shared/page-configs/assertPlusFileExport.js");
|
|
14
14
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
15
|
-
const
|
|
15
|
+
const pointerImports_js_1 = require("./pointerImports.js");
|
|
16
16
|
const getConfigFileExport_js_1 = require("./getConfigFileExport.js");
|
|
17
17
|
const resolvePointerImport_js_1 = require("./resolvePointerImport.js");
|
|
18
18
|
const getConfigDefinedAt_js_1 = require("../../../../../../shared/page-configs/getConfigDefinedAt.js");
|
|
@@ -117,7 +117,7 @@ function getExtendsPointerImportData(configFileExports, configFilePath) {
|
|
|
117
117
|
(0, utils_js_1.assertUsage)(false, wrongUsage);
|
|
118
118
|
}
|
|
119
119
|
extendsPointerImportData.push(...extendList.map((importString) => {
|
|
120
|
-
const pointerImportData = (0,
|
|
120
|
+
const pointerImportData = (0, pointerImports_js_1.parsePointerImportData)(importString);
|
|
121
121
|
(0, utils_js_1.assertUsage)(pointerImportData, wrongUsage);
|
|
122
122
|
return pointerImportData;
|
|
123
123
|
}));
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.transformPointerImports = transformPointerImports;
|
|
7
7
|
exports.parsePointerImportData = parsePointerImportData;
|
|
8
8
|
exports.isPointerImportData = isPointerImportData;
|
|
9
|
+
exports.assertPointerImportPath = assertPointerImportPath;
|
|
9
10
|
// Playground: https://github.com/brillout/acorn-playground
|
|
10
11
|
// Notes about `with { type: 'pointer' }`
|
|
11
12
|
// - It works well with TypeScript: it doesn't complain upon `with { type: 'unknown-to-typescript' }` and go-to-definition & types are preserved: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-3.html#import-attributes
|
|
@@ -149,8 +150,20 @@ function parsePointerImportData(importString) {
|
|
|
149
150
|
(0, utils_js_1.assert)(parts.length >= 2);
|
|
150
151
|
const exportName = parts[parts.length - 1];
|
|
151
152
|
const importPath = parts.slice(0, -1).join(SEP);
|
|
153
|
+
if (importPath.startsWith('.') && !(importPath.startsWith('./') || importPath.startsWith('../'))) {
|
|
154
|
+
(0, utils_js_1.assert)(!importStringWasGenerated);
|
|
155
|
+
(0, utils_js_1.assertUsage)(false, `Invalid relative import path ${picocolors_1.default.code(importPath)} defined by ${picocolors_1.default.code(JSON.stringify(importString))} because it should start with ${picocolors_1.default.code('./')} or ${picocolors_1.default.code('../')}, or use an npm package import instead.`);
|
|
156
|
+
}
|
|
157
|
+
assertPointerImportPath(importPath);
|
|
152
158
|
return { importPath, exportName, importStringWasGenerated, importString };
|
|
153
159
|
}
|
|
160
|
+
// `importPath` is one of the following:
|
|
161
|
+
// - A relative import path
|
|
162
|
+
// - An npm package import
|
|
163
|
+
// - A filesystem absolute path, see transpileWithEsbuild()
|
|
164
|
+
function assertPointerImportPath(importPath) {
|
|
165
|
+
return (0, utils_js_1.isImportPath)(importPath) || (0, utils_js_1.isFilePathAbsolute)(importPath);
|
|
166
|
+
}
|
|
154
167
|
function spliceMany(str, operations) {
|
|
155
168
|
let strMod = '';
|
|
156
169
|
let endPrev;
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js
CHANGED
|
@@ -7,13 +7,12 @@ exports.resolvePointerImport = resolvePointerImport;
|
|
|
7
7
|
exports.resolvePointerImportData = resolvePointerImportData;
|
|
8
8
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
9
9
|
const utils_js_1 = require("../../../../utils.js");
|
|
10
|
-
const
|
|
11
|
-
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const pointerImports_js_1 = require("./pointerImports.js");
|
|
12
11
|
const getFilePath_js_1 = require("../../../../shared/getFilePath.js");
|
|
13
12
|
function resolvePointerImport(configValue, importerFilePath, userRootDir, configName) {
|
|
14
13
|
if (typeof configValue !== 'string')
|
|
15
14
|
return null;
|
|
16
|
-
const pointerImportData = (0,
|
|
15
|
+
const pointerImportData = (0, pointerImports_js_1.parsePointerImportData)(configValue);
|
|
17
16
|
if (!pointerImportData)
|
|
18
17
|
return null;
|
|
19
18
|
const { exportName } = pointerImportData;
|
|
@@ -27,24 +26,18 @@ function resolvePointerImport(configValue, importerFilePath, userRootDir, config
|
|
|
27
26
|
return { fileExportPath };
|
|
28
27
|
}
|
|
29
28
|
function resolvePointerImportData(pointerImportData, importerFilePath, userRootDir) {
|
|
30
|
-
// `importPath` should be one of the following:
|
|
31
|
-
// - A relative import path
|
|
32
|
-
// - A filesystem absolute path
|
|
33
|
-
// - An npm package import
|
|
34
29
|
const { importPath } = pointerImportData;
|
|
35
|
-
|
|
30
|
+
(0, pointerImports_js_1.assertPointerImportPath)(importPath);
|
|
31
|
+
const filePathAbsoluteFilesystem = resolveImportPathWithNode(pointerImportData, importerFilePath, userRootDir);
|
|
36
32
|
let filePath;
|
|
37
33
|
(0, utils_js_1.assertPosixPath)(importPath);
|
|
38
|
-
if (
|
|
39
|
-
if (importPath.startsWith('.')) {
|
|
40
|
-
(0, utils_js_1.assertUsage)((0, utils_js_1.pathIsRelative)(importPath), `Invalid relative import path ${picocolors_1.default.code(importPath)} defined by ${importerFilePath.filePathToShowToUser} because it should start with ${picocolors_1.default.code('./')} or ${picocolors_1.default.code('../')}, or use an npm package import instead.`);
|
|
41
|
-
}
|
|
34
|
+
if ((0, utils_js_1.isImportPathRelative)(importPath) || (0, utils_js_1.isFilePathAbsolute)(importPath)) {
|
|
42
35
|
// Pointer imports are included in virtual files, thus relative imports need to be resolved. (Virtual modules cannot contain relative imports.)
|
|
43
36
|
assertUsageResolutionSuccess(filePathAbsoluteFilesystem, pointerImportData, importerFilePath);
|
|
44
37
|
// Pointer imports are included in virtual files, and we need filePathAbsoluteUserRootDir because we didn't find a way to have filesystem absolute import paths in virtual files: https://gist.github.com/brillout/2315231c9a8164f950c64b4b4a7bbd39
|
|
45
38
|
const errSuffix = `outside of the ${userRootDir} directory which is forbidden: make sure your import paths resolve inside the ${userRootDir} directory, or import from an npm package.`;
|
|
46
39
|
const filePathAbsoluteUserRootDir = (0, getFilePath_js_1.getFilePathAbsoluteUserRootDir)({ filePathAbsoluteFilesystem, userRootDir });
|
|
47
|
-
if (
|
|
40
|
+
if ((0, utils_js_1.isImportPathRelative)(importPath)) {
|
|
48
41
|
(0, utils_js_1.assertUsage)(filePathAbsoluteUserRootDir, `The relative import ${picocolors_1.default.cyan(importPath)} defined by ${importerFilePath.filePathToShowToUser} resolves to ${filePathAbsoluteFilesystem} ${errSuffix}`);
|
|
49
42
|
}
|
|
50
43
|
else {
|
|
@@ -56,6 +49,7 @@ function resolvePointerImportData(pointerImportData, importerFilePath, userRootD
|
|
|
56
49
|
filePath = (0, getFilePath_js_1.getFilePathResolved)({ filePathAbsoluteUserRootDir, userRootDir });
|
|
57
50
|
}
|
|
58
51
|
else {
|
|
52
|
+
(0, utils_js_1.assert)((0, utils_js_1.isImportPathNpmPackageOrPathAlias)(importPath));
|
|
59
53
|
const importPathAbsolute = importPath;
|
|
60
54
|
if (filePathAbsoluteFilesystem) {
|
|
61
55
|
filePath = (0, getFilePath_js_1.getFilePathResolved)({
|
|
@@ -73,12 +67,20 @@ function resolvePointerImportData(pointerImportData, importerFilePath, userRootD
|
|
|
73
67
|
}
|
|
74
68
|
return filePath;
|
|
75
69
|
}
|
|
76
|
-
function resolveImportPathWithNode(pointerImportData, importerFilePath) {
|
|
70
|
+
function resolveImportPathWithNode(pointerImportData, importerFilePath, userRootDir) {
|
|
77
71
|
const importerFilePathAbsolute = importerFilePath.filePathAbsoluteFilesystem;
|
|
78
72
|
(0, utils_js_1.assertPosixPath)(importerFilePathAbsolute);
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
73
|
+
// filePathAbsoluteFilesystem is null when pointerImportData.importPath is a path alias that Node.js doesn't know about
|
|
74
|
+
const filePathAbsoluteFilesystem = (0, utils_js_1.requireResolveOptional)({
|
|
75
|
+
importPath: pointerImportData.importPath,
|
|
76
|
+
importerFilePath: importerFilePathAbsolute,
|
|
77
|
+
userRootDir
|
|
78
|
+
});
|
|
79
|
+
if (!filePathAbsoluteFilesystem) {
|
|
80
|
+
(0, utils_js_1.assert)(!(0, utils_js_1.isImportPathRelative)(pointerImportData.importPath));
|
|
81
|
+
// Libraries don't use path aliases => filePathAbsoluteFilesystem should be defined
|
|
82
|
+
(0, utils_js_1.assert)(!importerFilePathAbsolute.includes('node_modules'));
|
|
83
|
+
}
|
|
82
84
|
return filePathAbsoluteFilesystem;
|
|
83
85
|
}
|
|
84
86
|
function assertUsageResolutionSuccess(filePathAbsoluteFilesystem, pointerImportData, importerFilePath) {
|
|
@@ -90,8 +92,7 @@ function assertUsageResolutionSuccess(filePathAbsoluteFilesystem, pointerImportD
|
|
|
90
92
|
? `The import path ${importPathString} in ${filePathToShowToUser}`
|
|
91
93
|
: `The import ${picocolors_1.default.code(importString)} defined by ${filePathToShowToUser}`;
|
|
92
94
|
const errIntro2 = `${errIntro} couldn't be resolved: does ${importPathString}`;
|
|
93
|
-
if (
|
|
94
|
-
(0, utils_js_1.assert)((0, utils_js_1.pathIsRelative)(importPath));
|
|
95
|
+
if ((0, utils_js_1.isImportPathRelative)(importPath)) {
|
|
95
96
|
(0, utils_js_1.assertUsage)(false, `${errIntro2} point to an existing file?`);
|
|
96
97
|
}
|
|
97
98
|
else {
|
|
@@ -13,7 +13,7 @@ const path_1 = __importDefault(require("path"));
|
|
|
13
13
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
14
14
|
const import_1 = require("@brillout/import");
|
|
15
15
|
const utils_js_1 = require("../../../../utils.js");
|
|
16
|
-
const
|
|
16
|
+
const pointerImports_js_1 = require("./pointerImports.js");
|
|
17
17
|
const source_map_support_1 = __importDefault(require("source-map-support"));
|
|
18
18
|
const getFilePath_js_1 = require("../../../../shared/getFilePath.js");
|
|
19
19
|
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
@@ -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 });
|
|
@@ -61,7 +61,7 @@ async function transpileFile(filePath, transformImports, userRootDir, esbuildCac
|
|
|
61
61
|
debug(`code, post esbuild (${filePathToShowToUserResolved})`, code);
|
|
62
62
|
let isImportTransformed = false;
|
|
63
63
|
if (transformImports) {
|
|
64
|
-
const codeMod = (0,
|
|
64
|
+
const codeMod = (0, pointerImports_js_1.transformPointerImports)(code, filePathToShowToUserResolved, pointerImports);
|
|
65
65
|
if (codeMod) {
|
|
66
66
|
code = codeMod;
|
|
67
67
|
isImportTransformed = true;
|
|
@@ -126,7 +126,11 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
|
|
|
126
126
|
// - Sitll required for esbuild@0.24.0 (November 2024).
|
|
127
127
|
// - Let's try to remove this workaround again later.
|
|
128
128
|
if (resolved.errors.length > 0) {
|
|
129
|
-
const resolvedWithNode = (0, utils_js_1.
|
|
129
|
+
const resolvedWithNode = (0, utils_js_1.requireResolveOptionalDir)({
|
|
130
|
+
importPath: path,
|
|
131
|
+
importerDir: (0, utils_js_1.toPosixPath)(args.resolveDir),
|
|
132
|
+
userRootDir
|
|
133
|
+
});
|
|
130
134
|
if (debugEsbuildResolve.isActivated)
|
|
131
135
|
debugEsbuildResolve('resolvedWithNode', resolvedWithNode);
|
|
132
136
|
if (resolvedWithNode)
|
|
@@ -146,14 +150,14 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
|
|
|
146
150
|
const importPathOriginal = args.path;
|
|
147
151
|
// Esbuild resolves path aliases.
|
|
148
152
|
// - Enabling us to use:
|
|
149
|
-
// -
|
|
150
|
-
// -
|
|
153
|
+
// - assertIsImportPathNpmPackage()
|
|
154
|
+
// - isImportPathNpmPackage(str, { cannotBePathAlias: true })
|
|
151
155
|
(0, utils_js_1.assertFilePathAbsoluteFilesystem)(importPathResolved);
|
|
152
156
|
// Should be remove this? See comment below.
|
|
153
157
|
const isVikeExtensionImport = (path.startsWith('vike-') && path.endsWith('/config')) || importPathResolved.endsWith('+config.js');
|
|
154
158
|
const isPointerImport = transformImports === 'all' ||
|
|
155
159
|
// .jsx, .vue, .svg, ... => obviously not config code => pointer import
|
|
156
|
-
!(0, utils_js_1.
|
|
160
|
+
!(0, utils_js_1.isPlainScriptFile)(importPathResolved) ||
|
|
157
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).
|
|
158
162
|
// - Should we stop doing this? (And instead let Node.js directly load Vike extensions.)
|
|
159
163
|
// - In principle, we can use the setting 'name' value of Vike extensions.
|
|
@@ -165,7 +169,7 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
|
|
|
165
169
|
const isNpmPkgImport = (() => {
|
|
166
170
|
if (importPathResolved.includes('/node_modules/')) {
|
|
167
171
|
// So far I can't think of a use case where this assertion would fail, but let's eventually remove it to avoid artificially restricting the user.
|
|
168
|
-
(0, utils_js_1.assert)((0, utils_js_1.
|
|
172
|
+
(0, utils_js_1.assert)((0, utils_js_1.isImportPathNpmPackageOrPathAlias)(importPathOriginal));
|
|
169
173
|
return true;
|
|
170
174
|
}
|
|
171
175
|
// Linked npm packages
|
|
@@ -174,7 +178,7 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
|
|
|
174
178
|
// - This isn't always the case: https://github.com/vikejs/vike/issues/2326
|
|
175
179
|
!importPathResolved.startsWith(userRootDir) &&
|
|
176
180
|
// False positive if `importPathOriginal` is a path alias that a) looks like an npm package import and b) resolves outside of `userRootDir` => we then we wrongfully assume that `importPathOriginal` is an npm package import.
|
|
177
|
-
(0, utils_js_1.
|
|
181
|
+
(0, utils_js_1.isImportPathNpmPackageOrPathAlias)(importPathOriginal)) {
|
|
178
182
|
return true;
|
|
179
183
|
}
|
|
180
184
|
return false;
|
|
@@ -191,7 +195,7 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
|
|
|
191
195
|
}
|
|
192
196
|
let importPathTranspiled;
|
|
193
197
|
(0, utils_js_1.assertPosixPath)(importPathOriginal);
|
|
194
|
-
if (
|
|
198
|
+
if ((0, utils_js_1.isImportPathRelative)(importPathOriginal)) {
|
|
195
199
|
importPathTranspiled = importPathResolved;
|
|
196
200
|
}
|
|
197
201
|
else {
|
|
@@ -208,12 +212,11 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
|
|
|
208
212
|
// - Vike doesn't resolve path aliases at all.
|
|
209
213
|
// - Node.js doesn't support `tsconfig.js#compilerOptions.paths`.
|
|
210
214
|
// - Esbuild path alias resolution seems reliable, e.g. it supports `tsconfig.js#compilerOptions.paths`.
|
|
211
|
-
(0, utils_js_1.assert)(!(0, utils_js_1.isNpmPackageImport_unreliable)(importPathOriginal));
|
|
212
215
|
importPathTranspiled = importPathResolved;
|
|
213
216
|
}
|
|
214
217
|
else {
|
|
215
218
|
// `importPathOriginal` is most likely an npm package import.
|
|
216
|
-
(0, utils_js_1.
|
|
219
|
+
(0, utils_js_1.assertIsImportPathNpmPackage)(importPathOriginal);
|
|
217
220
|
// For improved error messages, let the resolution be handled by Vike or Node.js.
|
|
218
221
|
importPathTranspiled = importPathOriginal;
|
|
219
222
|
}
|
|
@@ -75,7 +75,7 @@ async function handleReloadSideEffects() {
|
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
|
-
// TODO/soon: predominantly use
|
|
78
|
+
// TODO/soon: predominantly use getVikeConfigInternal() instead of getVikeConfig() then maybe refector?
|
|
79
79
|
async function getVikeConfig(config, { doNotRestartViteOnError } = {}) {
|
|
80
80
|
const userRootDir = config.root;
|
|
81
81
|
const vikeVitePluginOptions = config._vikeVitePluginOptions;
|
|
@@ -410,7 +410,7 @@ function setCliAndApiOptions(pageConfigGlobal, configDefinitionsResolved) {
|
|
|
410
410
|
Object.entries(configValues).forEach(([configName, value]) => {
|
|
411
411
|
var _a;
|
|
412
412
|
const sourceName = `The ${(0, getConfigDefinedAt_js_1.getDefinedByString)(definedBy, configName)}`;
|
|
413
|
-
assertKnownConfig(configName, configDefinitionsResolved.configNamesKnownGlobal, configDefinitionsResolved, '/', sourceName, exitOnError);
|
|
413
|
+
assertKnownConfig(configName, configDefinitionsResolved.configNamesKnownGlobal, configDefinitionsResolved, '/', false, sourceName, exitOnError);
|
|
414
414
|
const sources = ((_a = pageConfigGlobal.configValueSources)[configName] ?? (_a[configName] = []));
|
|
415
415
|
sources.unshift(getSourceNonConfigFile(configName, value, definedBy));
|
|
416
416
|
});
|
|
@@ -682,15 +682,12 @@ function resolveIsGlobalValue(configDefGlobal, source, plusFilesAll) {
|
|
|
682
682
|
return isGlobal;
|
|
683
683
|
}
|
|
684
684
|
function getConfigNamesSetByPlusFile(plusFile) {
|
|
685
|
-
let configNames = [];
|
|
686
685
|
if (!plusFile.isConfigFile) {
|
|
687
|
-
|
|
686
|
+
return [plusFile.configName];
|
|
688
687
|
}
|
|
689
|
-
|
|
690
|
-
|
|
688
|
+
else {
|
|
689
|
+
return Object.keys(plusFile.fileExportsByConfigName);
|
|
691
690
|
}
|
|
692
|
-
configNames = (0, utils_js_1.unique)(configNames);
|
|
693
|
-
return configNames;
|
|
694
691
|
}
|
|
695
692
|
function getConfigDefinitions(plusFilesRelevant, filter) {
|
|
696
693
|
let configDefinitions = { ...configDefinitionsBuiltIn_js_1.configDefinitionsBuiltIn };
|
|
@@ -885,12 +882,12 @@ function assertKnownConfigs(configDefinitionsResolved) {
|
|
|
885
882
|
configNames.forEach((configName) => {
|
|
886
883
|
const { locationId } = plusFile;
|
|
887
884
|
const sourceName = plusFile.filePath.filePathToShowToUser;
|
|
888
|
-
assertKnownConfig(configName, configNamesKnownLocal, configDefinitionsResolved, locationId, sourceName, false);
|
|
885
|
+
assertKnownConfig(configName, configNamesKnownLocal, configDefinitionsResolved, locationId, true, sourceName, false);
|
|
889
886
|
});
|
|
890
887
|
});
|
|
891
888
|
});
|
|
892
889
|
}
|
|
893
|
-
function assertKnownConfig(configName, configNamesKnownRelevant, configDefinitionsResolved, locationId, sourceName, exitOnError) {
|
|
890
|
+
function assertKnownConfig(configName, configNamesKnownRelevant, configDefinitionsResolved, locationId, isPlusFile, sourceName, exitOnError) {
|
|
894
891
|
const { configNamesKnownAll } = configDefinitionsResolved;
|
|
895
892
|
if (configNamesKnownRelevant.includes(configName)) {
|
|
896
893
|
(0, utils_js_1.assert)(configNamesKnownAll.includes(configName));
|
|
@@ -901,7 +898,10 @@ function assertKnownConfig(configName, configNamesKnownRelevant, configDefinitio
|
|
|
901
898
|
if (configNamesKnownAll.includes(configName)) {
|
|
902
899
|
(0, utils_js_1.assertUsage)(false, `${sourceName} sets the value of the config ${configNameColored} which is a custom config that is defined with ${picocolors_1.default.underline('https://vike.dev/meta')} at a path that doesn't apply to ${locationId} — see ${picocolors_1.default.underline('https://vike.dev/config#inheritance')}`, { exitOnError });
|
|
903
900
|
}
|
|
904
|
-
const errMsg =
|
|
901
|
+
const errMsg = isPlusFile
|
|
902
|
+
? `${sourceName} sets an unknown config ${configNameColored}`
|
|
903
|
+
: `${sourceName} sets an unknown Vike config, see ${picocolors_1.default.underline('https://vike.dev/cli')} for the list of CLI options`;
|
|
904
|
+
(0, utils_js_1.assert)(errMsg.includes(configName));
|
|
905
905
|
// Missing vike-{react,vue,solid} installation
|
|
906
906
|
{
|
|
907
907
|
const ui = ['vike-react', 'vike-vue', 'vike-solid'];
|
|
@@ -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) {
|
|
@@ -44,7 +44,7 @@ function getComputedProps(args) {
|
|
|
44
44
|
const importPathAbsolute = args.importPathAbsolute ?? null;
|
|
45
45
|
const { filePathAbsoluteUserRootDir } = args;
|
|
46
46
|
if (importPathAbsolute)
|
|
47
|
-
(0, utils_js_1.
|
|
47
|
+
(0, utils_js_1.assertIsImportPathNpmPackage)(importPathAbsolute);
|
|
48
48
|
return {
|
|
49
49
|
importPathAbsolute,
|
|
50
50
|
filePathAbsoluteUserRootDir,
|
|
@@ -58,7 +58,7 @@ function getComputedProps(args) {
|
|
|
58
58
|
}
|
|
59
59
|
function getComputedPropsImportPathAbsolute(args) {
|
|
60
60
|
const { importPathAbsolute } = args;
|
|
61
|
-
(0, utils_js_1.
|
|
61
|
+
(0, utils_js_1.assertIsImportPathNpmPackage)(importPathAbsolute);
|
|
62
62
|
return {
|
|
63
63
|
filePathAbsoluteUserRootDir: null,
|
|
64
64
|
importPathAbsolute,
|
|
@@ -2,13 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.resolveClientEntriesDev = resolveClientEntriesDev;
|
|
4
4
|
const utils_js_1 = require("../utils.js");
|
|
5
|
-
// @ts-ignore `file:///${__filename.split('\\').join('/')}` is shimmed at dist/cjs by dist-cjs-fixup.js.
|
|
6
|
-
const importMetaUrl = `file:///${__filename.split('\\').join('/')}`;
|
|
7
5
|
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
8
6
|
async function resolveClientEntriesDev(clientEntry, viteDevServer) {
|
|
9
|
-
let
|
|
10
|
-
(0, utils_js_1.assert)(
|
|
11
|
-
|
|
7
|
+
let userRootDir = viteDevServer.config.root;
|
|
8
|
+
(0, utils_js_1.assert)(userRootDir);
|
|
9
|
+
userRootDir = (0, utils_js_1.toPosixPath)(userRootDir);
|
|
12
10
|
// The `?import` suffix is needed for MDX to be transpiled:
|
|
13
11
|
// - Not transpiled: `/pages/markdown.page.mdx`
|
|
14
12
|
// - Transpiled: `/pages/markdown.page.mdx?import`
|
|
@@ -22,26 +20,16 @@ async function resolveClientEntriesDev(clientEntry, viteDevServer) {
|
|
|
22
20
|
(0, utils_js_1.assertPosixPath)(clientEntry);
|
|
23
21
|
let filePath;
|
|
24
22
|
if (clientEntry.startsWith('/')) {
|
|
25
|
-
filePath = (0, utils_js_1.pathJoin)(
|
|
23
|
+
filePath = (0, utils_js_1.pathJoin)(userRootDir, clientEntry);
|
|
26
24
|
}
|
|
27
25
|
else {
|
|
28
26
|
if (clientEntry.startsWith('@@vike/')) {
|
|
29
27
|
(0, utils_js_1.assert)(clientEntry.endsWith('.js'));
|
|
30
|
-
|
|
31
|
-
// For Vitest (which doesn't resolve vike to its dist but to its source files)
|
|
32
|
-
// [RELATIVE_PATH_FROM_DIST] Current file: node_modules/vike/node/plugin/shared/resolveClientEntriesDev.js
|
|
33
|
-
filePath_ = (0, utils_js_1.requireResolveOptionalNonUserFile)(clientEntry.replace('@@vike/dist/esm/client/', '../../../client/').replace('.js', '.ts'), importMetaUrl);
|
|
34
|
-
if (!filePath_) {
|
|
35
|
-
// For users
|
|
36
|
-
// [RELATIVE_PATH_FROM_DIST] Current file: node_modules/vike/dist/esm/node/plugin/shared/resolveClientEntriesDev.js
|
|
37
|
-
filePath_ = (0, utils_js_1.requireResolveOptionalNonUserFile)(clientEntry.replace('@@vike/dist/esm/client/', '../../../../../dist/esm/client/'), importMetaUrl);
|
|
38
|
-
}
|
|
39
|
-
(0, utils_js_1.assert)(filePath_);
|
|
40
|
-
filePath = filePath_;
|
|
28
|
+
filePath = (0, utils_js_1.requireResolveVikeDistFile)(`dist/esm/${clientEntry.replace('@@vike/dist/esm/', '')}`);
|
|
41
29
|
}
|
|
42
30
|
else {
|
|
43
|
-
(0, utils_js_1.
|
|
44
|
-
filePath = (0, utils_js_1.
|
|
31
|
+
(0, utils_js_1.assertIsImportPathNpmPackage)(clientEntry);
|
|
32
|
+
filePath = (0, utils_js_1.requireResolveNpmPackage)({ importPathNpmPackage: clientEntry, userRootDir });
|
|
45
33
|
}
|
|
46
34
|
}
|
|
47
35
|
if (!filePath.startsWith('/')) {
|
|
@@ -46,3 +46,4 @@ __exportStar(require("../../utils/isEqualStringList.js"), exports);
|
|
|
46
46
|
__exportStar(require("../../utils/isDocker.js"), exports);
|
|
47
47
|
__exportStar(require("../../utils/isVitest.js"), exports);
|
|
48
48
|
__exportStar(require("../../utils/rollupSourceMap.js"), exports);
|
|
49
|
+
__exportStar(require("../../utils/isImportPath.js"), exports);
|