vike 0.4.228 → 0.4.229-commit-a19745d
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 +8 -20
- 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 +13 -3
- 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 +3 -3
- 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/debug.js +1 -0
- 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 +148 -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.d.ts +1 -1
- package/dist/esm/node/plugin/shared/resolveClientEntriesDev.js +9 -21
- 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 +13 -3
- 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 +3 -3
- 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/debug.d.ts +1 -1
- package/dist/esm/utils/debug.js +1 -0
- 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 +148 -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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { determineFsAllowList };
|
|
2
2
|
import { searchForWorkspaceRoot } from 'vite';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
-
import { assert, assertPosixPath,
|
|
4
|
+
import { assert, assertPosixPath, getVikeNodeModulesRoot } from '../../utils.js';
|
|
5
5
|
import { fileURLToPath } from 'url';
|
|
6
6
|
// @ts-ignore import.meta.url is shimmed at dist/cjs by dist-cjs-fixup.js.
|
|
7
7
|
const importMetaUrl = import.meta.url;
|
|
@@ -18,11 +18,6 @@ async function determineFsAllowList(config) {
|
|
|
18
18
|
// We add it again just to be sure.
|
|
19
19
|
fsAllow.push(searchForWorkspaceRoot(process.cwd()));
|
|
20
20
|
// Add node_modules/vike/
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const vikeRoot = path.posix.join(__dirname_, '../../../../../../');
|
|
24
|
-
// Assert that `vikeRoot` is indeed pointing to `node_modules/vike/`
|
|
25
|
-
requireResolveNonUserFile(`${vikeRoot}/dist/esm/node/plugin/plugins/devConfig/index.js`, importMetaUrl);
|
|
26
|
-
fsAllow.push(vikeRoot);
|
|
27
|
-
}
|
|
21
|
+
const vikeNodeModulesRoot = getVikeNodeModulesRoot();
|
|
22
|
+
fsAllow.push(vikeNodeModulesRoot);
|
|
28
23
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { determineOptimizeDeps };
|
|
2
2
|
import { findPageFiles } from '../../shared/findPageFiles.js';
|
|
3
|
-
import { assert,
|
|
3
|
+
import { assert, assertIsImportPathNpmPackage, createDebugger, getNpmPackageName, isArray, unique } from '../../utils.js';
|
|
4
4
|
import { getVikeConfig, isOverriden } from '../importUserCode/v1-design/getVikeConfig.js';
|
|
5
5
|
import { analyzeClientEntries } from '../build/pluginBuildConfig.js';
|
|
6
6
|
import { virtualFileIdImportUserCodeClientCR, virtualFileIdImportUserCodeClientSR } from '../../../shared/virtual-files/virtualFileImportUserCode.js';
|
|
@@ -38,7 +38,7 @@ async function getPageDeps(config, pageConfigs) {
|
|
|
38
38
|
const addInclude = (e) => {
|
|
39
39
|
assert(e);
|
|
40
40
|
// Shouldn't be a path alias, as path aliases would need to be added to config.optimizeDeps.entries instead of config.optimizeDeps.include
|
|
41
|
-
|
|
41
|
+
assertIsImportPathNpmPackage(e);
|
|
42
42
|
include.push(e);
|
|
43
43
|
};
|
|
44
44
|
// V1 design
|
|
@@ -55,6 +55,11 @@ async function getPageDeps(config, pageConfigs) {
|
|
|
55
55
|
return;
|
|
56
56
|
if (definedAt.definedBy)
|
|
57
57
|
return;
|
|
58
|
+
if (definedAt.importPathAbsolute) {
|
|
59
|
+
const npmPackageName = getNpmPackageName(definedAt.importPathAbsolute);
|
|
60
|
+
if (npmPackageName && config.optimizeDeps.exclude?.includes(npmPackageName))
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
58
63
|
if (definedAt.filePathAbsoluteUserRootDir !== null) {
|
|
59
64
|
// Vite expects entries to be filesystem absolute paths (surprisingly so).
|
|
60
65
|
addEntry(definedAt.filePathAbsoluteFilesystem);
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
export { envVarsPlugin };
|
|
2
2
|
import MagicString from 'magic-string';
|
|
3
3
|
import { loadEnv } from 'vite';
|
|
4
|
-
import { assert, assertPosixPath, assertUsage, assertWarning, escapeRegex, isArray, lowerFirst } from '../utils.js';
|
|
4
|
+
import { assert, assertPosixPath, assertUsage, assertWarning, escapeRegex, isArray, isNotNullish, lowerFirst } from '../utils.js';
|
|
5
5
|
import { getModuleFilePathAbsolute } from '../shared/getFilePath.js';
|
|
6
6
|
import { normalizeId } from '../shared/normalizeId.js';
|
|
7
7
|
import { isViteServerBuild_safe } from '../shared/isViteServerBuild.js';
|
|
8
|
-
|
|
8
|
+
import { applyRegExpWithMagicString } from '../shared/applyRegExWithMagicString.js';
|
|
9
|
+
// TODO/enventually:
|
|
9
10
|
// - Make import.meta.env work inside +config.js
|
|
10
11
|
// - For it to work, we'll probably need the user to define the settings (e.g. `envDir`) for loadEnv() inside vike.config.js instead of vite.config.js
|
|
11
12
|
// - Or stop using Vite's `mode` implemention and have Vike implement its own `mode` feature? (So that the only dependencies are `$ vike build --mode staging` and `$ MODE=staging vike build`.)
|
|
@@ -22,7 +23,6 @@ function envVarsPlugin() {
|
|
|
22
23
|
enforce: 'post',
|
|
23
24
|
configResolved(config_) {
|
|
24
25
|
config = config_;
|
|
25
|
-
config.command;
|
|
26
26
|
envsAll = loadEnv(config.mode, config.envDir || config.root, '');
|
|
27
27
|
config.plugins.sort(lowerFirst((plugin) => (plugin.name === 'vite:define' ? 1 : 0)));
|
|
28
28
|
},
|
|
@@ -38,21 +38,22 @@ function envVarsPlugin() {
|
|
|
38
38
|
return;
|
|
39
39
|
const isBuild = config.command === 'build';
|
|
40
40
|
const isClientSide = !isViteServerBuild_safe(config, options);
|
|
41
|
-
const
|
|
42
|
-
|
|
41
|
+
const magicString = new MagicString(code);
|
|
42
|
+
// Find & check
|
|
43
|
+
const replacements = Object.entries(envsAll)
|
|
43
44
|
.filter(([key]) => {
|
|
44
45
|
// Already handled by Vite
|
|
45
46
|
const envPrefix = !config.envPrefix ? [] : isArray(config.envPrefix) ? config.envPrefix : [config.envPrefix];
|
|
46
47
|
return !envPrefix.some((prefix) => key.startsWith(prefix));
|
|
47
48
|
})
|
|
48
|
-
.
|
|
49
|
+
.map(([envName, envVal]) => {
|
|
49
50
|
const envStatement = `import.meta.env.${envName}`;
|
|
50
|
-
const
|
|
51
|
+
const envStatementRegExpStr = escapeRegex(envStatement) + '\\b';
|
|
51
52
|
// Security check
|
|
52
53
|
{
|
|
53
54
|
const isPrivate = !envName.startsWith(PUBLIC_ENV_PREFIX) && !PUBLIC_ENV_ALLOWLIST.includes(envName);
|
|
54
55
|
if (isPrivate && isClientSide) {
|
|
55
|
-
if (!new RegExp(
|
|
56
|
+
if (!new RegExp(envStatementRegExpStr).test(code))
|
|
56
57
|
return;
|
|
57
58
|
const modulePath = getModuleFilePathAbsolute(id, config);
|
|
58
59
|
const errMsgAddendum = isBuild ? '' : ' (Vike will prevent your app from building for production)';
|
|
@@ -70,22 +71,19 @@ function envVarsPlugin() {
|
|
|
70
71
|
// Double check
|
|
71
72
|
assert(!(isPrivate && isClientSide) || !isBuild);
|
|
72
73
|
}
|
|
73
|
-
|
|
74
|
-
|
|
74
|
+
return { regExpStr: envStatementRegExpStr, replacement: envVal };
|
|
75
|
+
})
|
|
76
|
+
.filter(isNotNullish);
|
|
77
|
+
// Apply
|
|
78
|
+
replacements.forEach(({ regExpStr, replacement }) => {
|
|
79
|
+
applyRegExpWithMagicString(magicString, regExpStr, replacement);
|
|
75
80
|
});
|
|
76
|
-
if (!
|
|
81
|
+
if (!magicString.hasChanged())
|
|
77
82
|
return null;
|
|
78
83
|
return {
|
|
79
|
-
code:
|
|
80
|
-
map:
|
|
84
|
+
code: magicString.toString(),
|
|
85
|
+
map: magicString.generateMap({ hires: true, source: id })
|
|
81
86
|
};
|
|
82
87
|
}
|
|
83
88
|
};
|
|
84
89
|
}
|
|
85
|
-
function applyEnvVar(s, envStatementRegExStr, envVal) {
|
|
86
|
-
const envStatementRegEx = new RegExp(envStatementRegExStr, 'g');
|
|
87
|
-
let match;
|
|
88
|
-
while ((match = envStatementRegEx.exec(s.original))) {
|
|
89
|
-
s.overwrite(match.index, match.index + match[0].length, JSON.stringify(envVal));
|
|
90
|
-
}
|
|
91
|
-
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { getVirtualFileImportUserCode };
|
|
2
|
-
import { assert, assertPosixPath,
|
|
2
|
+
import { assert, assertPosixPath, scriptFileExtensionPattern, debugGlob, isVersionOrAbove, assertWarning } from '../../utils.js';
|
|
3
3
|
import { isVirtualFileIdImportUserCode } from '../../../shared/virtual-files/virtualFileImportUserCode.js';
|
|
4
4
|
import { version as viteVersion } from 'vite';
|
|
5
5
|
import { fileTypes } from '../../../../shared/getPageFiles/fileTypes.js';
|
|
@@ -174,7 +174,9 @@ function getGlobRoots(config) {
|
|
|
174
174
|
}
|
|
175
175
|
function getGlobPath(globRootDir, fileType) {
|
|
176
176
|
assertPosixPath(globRootDir);
|
|
177
|
-
let globPath = [...globRootDir.split('/'), '**', `*${fileType}.${
|
|
177
|
+
let globPath = [...globRootDir.split('/'), '**', `*${fileType}.${scriptFileExtensionPattern}`]
|
|
178
|
+
.filter(Boolean)
|
|
179
|
+
.join('/');
|
|
178
180
|
if (!globPath.startsWith('/')) {
|
|
179
181
|
globPath = '/' + globPath;
|
|
180
182
|
}
|
|
@@ -17,6 +17,17 @@ const configDefinitionsBuiltIn = {
|
|
|
17
17
|
onPageTransitionEnd: {
|
|
18
18
|
env: { client: true }
|
|
19
19
|
},
|
|
20
|
+
onCreatePageContext: {
|
|
21
|
+
env: { server: true, client: true },
|
|
22
|
+
// Required because `onCreatePageContext()` is called before routing
|
|
23
|
+
global: true,
|
|
24
|
+
cumulative: true
|
|
25
|
+
},
|
|
26
|
+
onCreateGlobalContext: {
|
|
27
|
+
env: { server: true, client: true },
|
|
28
|
+
global: true,
|
|
29
|
+
cumulative: true
|
|
30
|
+
},
|
|
20
31
|
onBeforeRender: {
|
|
21
32
|
env: { server: true }
|
|
22
33
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const ignorePatternsBuiltIn: readonly ["**/node_modules/**", "**/ejected/**", "**/*.telefunc.*", "**/*.generated.*"];
|
|
1
|
+
export declare const ignorePatternsBuiltIn: readonly ["**/node_modules/**", "**/ejected/**", "**/*.telefunc.*", "**/.history/**", "**/*.generated.*"];
|
|
@@ -8,6 +8,8 @@ export const ignorePatternsBuiltIn = [
|
|
|
8
8
|
// +Page.telefunc.js
|
|
9
9
|
// ```
|
|
10
10
|
'**/*.telefunc.*',
|
|
11
|
+
// https://github.com/vikejs/vike/issues/1589#issuecomment-2031925598
|
|
12
|
+
'**/.history/**',
|
|
11
13
|
// https://github.com/vikejs/vike/discussions/2222
|
|
12
14
|
'**/*.generated.*'
|
|
13
15
|
];
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { crawlPlusFiles };
|
|
2
2
|
export { isPlusFile };
|
|
3
3
|
export { getPlusFileValueConfigName };
|
|
4
|
-
import { assertPosixPath, assert,
|
|
4
|
+
import { assertPosixPath, assert, scriptFileExtensionPattern, assertIsSingleModuleInstance, assertIsNotProductionRuntime, isVersionOrAbove, isScriptFile, scriptFileExtensionList, createDebugger, deepEqual, assertUsage, assertFilePathAbsoluteFilesystem, assertWarning, hasProp, isNotNullish } from '../../../../utils.js';
|
|
5
5
|
import path from 'path';
|
|
6
6
|
import { glob } from 'tinyglobby';
|
|
7
7
|
import { exec } from 'child_process';
|
|
@@ -115,7 +115,7 @@ async function gitLsFiles(userRootDir, ignorePatterns, ignoreMatchers) {
|
|
|
115
115
|
}
|
|
116
116
|
// Same as gitLsFiles() but using tinyglobby
|
|
117
117
|
async function tinyglobby(userRootDir, ignorePatterns) {
|
|
118
|
-
const pattern = `**/+*.${
|
|
118
|
+
const pattern = `**/+*.${scriptFileExtensionPattern}`;
|
|
119
119
|
const options = {
|
|
120
120
|
ignore: ignorePatterns,
|
|
121
121
|
cwd: userRootDir,
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js
CHANGED
|
@@ -7,7 +7,7 @@ import { transpileAndExecuteFile } from './transpileAndExecuteFile.js';
|
|
|
7
7
|
import { getConfigDefinitionOptional } from '../getVikeConfig.js';
|
|
8
8
|
import { assertPlusFileExport } from '../../../../../../shared/page-configs/assertPlusFileExport.js';
|
|
9
9
|
import pc from '@brillout/picocolors';
|
|
10
|
-
import { parsePointerImportData } from './
|
|
10
|
+
import { parsePointerImportData } from './pointerImports.js';
|
|
11
11
|
import { getConfigFileExport } from './getConfigFileExport.js';
|
|
12
12
|
import { resolvePointerImportData } from './resolvePointerImport.js';
|
|
13
13
|
import { getConfigDefinedAt } from '../../../../../../shared/page-configs/getConfigDefinedAt.js';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { transformPointerImports };
|
|
2
2
|
export { parsePointerImportData };
|
|
3
3
|
export { isPointerImportData };
|
|
4
|
+
export { assertPointerImportPath };
|
|
4
5
|
export type { PointerImportData };
|
|
5
6
|
declare function transformPointerImports(code: string, filePathToShowToUser2: string, pointerImports: Record<string, boolean> | 'all', skipWarnings?: true): string | null;
|
|
6
7
|
/**
|
|
@@ -23,6 +24,7 @@ type PointerImportData = {
|
|
|
23
24
|
};
|
|
24
25
|
declare function isPointerImportData(str: string): boolean;
|
|
25
26
|
declare function parsePointerImportData(importString: string): null | PointerImportData;
|
|
27
|
+
declare function assertPointerImportPath(importPath: string): boolean;
|
|
26
28
|
declare module 'estree' {
|
|
27
29
|
interface BaseNodeWithoutComments {
|
|
28
30
|
start: number;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { transformPointerImports };
|
|
2
2
|
export { parsePointerImportData };
|
|
3
3
|
export { isPointerImportData };
|
|
4
|
+
export { assertPointerImportPath };
|
|
4
5
|
// Playground: https://github.com/brillout/acorn-playground
|
|
5
6
|
// Notes about `with { type: 'pointer' }`
|
|
6
7
|
// - 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
|
|
@@ -17,7 +18,7 @@ export { isPointerImportData };
|
|
|
17
18
|
// - Esbuild removes comments: https://github.com/evanw/esbuild/issues/1439#issuecomment-877656182
|
|
18
19
|
// - Using source maps to track these magic comments is brittle (source maps can easily break)
|
|
19
20
|
import { parse } from 'acorn';
|
|
20
|
-
import { assert, assertUsage, assertWarning, styleFileRE } from '../../../../utils.js';
|
|
21
|
+
import { assert, assertUsage, assertWarning, isFilePathAbsolute, isImportPath, styleFileRE } from '../../../../utils.js';
|
|
21
22
|
import pc from '@brillout/picocolors';
|
|
22
23
|
function transformPointerImports(code, filePathToShowToUser2, pointerImports,
|
|
23
24
|
// For ./transformPointerImports.spec.ts
|
|
@@ -144,8 +145,20 @@ function parsePointerImportData(importString) {
|
|
|
144
145
|
assert(parts.length >= 2);
|
|
145
146
|
const exportName = parts[parts.length - 1];
|
|
146
147
|
const importPath = parts.slice(0, -1).join(SEP);
|
|
148
|
+
if (importPath.startsWith('.') && !(importPath.startsWith('./') || importPath.startsWith('../'))) {
|
|
149
|
+
assert(!importStringWasGenerated);
|
|
150
|
+
assertUsage(false, `Invalid relative import path ${pc.code(importPath)} defined by ${pc.code(JSON.stringify(importString))} because it should start with ${pc.code('./')} or ${pc.code('../')}, or use an npm package import instead.`);
|
|
151
|
+
}
|
|
152
|
+
assertPointerImportPath(importPath);
|
|
147
153
|
return { importPath, exportName, importStringWasGenerated, importString };
|
|
148
154
|
}
|
|
155
|
+
// `importPath` is one of the following:
|
|
156
|
+
// - A relative import path
|
|
157
|
+
// - An npm package import
|
|
158
|
+
// - A filesystem absolute path, see transpileWithEsbuild()
|
|
159
|
+
function assertPointerImportPath(importPath) {
|
|
160
|
+
return isImportPath(importPath) || isFilePathAbsolute(importPath);
|
|
161
|
+
}
|
|
149
162
|
function spliceMany(str, operations) {
|
|
150
163
|
let strMod = '';
|
|
151
164
|
let endPrev;
|
|
@@ -2,7 +2,7 @@ export { resolvePointerImport };
|
|
|
2
2
|
export { resolvePointerImportData };
|
|
3
3
|
export type { PointerImport };
|
|
4
4
|
import type { DefinedAtFilePath } from '../../../../../../shared/page-configs/PageConfig.js';
|
|
5
|
-
import { type PointerImportData } from './
|
|
5
|
+
import { type PointerImportData } from './pointerImports.js';
|
|
6
6
|
import type { FilePath, FilePathResolved } from '../../../../../../shared/page-configs/FilePath.js';
|
|
7
7
|
type PointerImport = {
|
|
8
8
|
fileExportPath: FileExportPath;
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
export { resolvePointerImport };
|
|
2
2
|
export { resolvePointerImportData };
|
|
3
3
|
import pc from '@brillout/picocolors';
|
|
4
|
-
import { assert, assertPosixPath, assertUsage, isFilePathAbsolute,
|
|
5
|
-
import { parsePointerImportData } from './
|
|
6
|
-
import path from 'path';
|
|
4
|
+
import { assert, assertPosixPath, assertUsage, isFilePathAbsolute, isImportPathRelative, isImportPathNpmPackageOrPathAlias, requireResolveOptional } from '../../../../utils.js';
|
|
5
|
+
import { assertPointerImportPath, parsePointerImportData } from './pointerImports.js';
|
|
7
6
|
import { getFilePathAbsoluteUserRootDir, getFilePathResolved, getFilePathUnresolved } from '../../../../shared/getFilePath.js';
|
|
8
7
|
function resolvePointerImport(configValue, importerFilePath, userRootDir, configName) {
|
|
9
8
|
if (typeof configValue !== 'string')
|
|
@@ -22,24 +21,18 @@ function resolvePointerImport(configValue, importerFilePath, userRootDir, config
|
|
|
22
21
|
return { fileExportPath };
|
|
23
22
|
}
|
|
24
23
|
function resolvePointerImportData(pointerImportData, importerFilePath, userRootDir) {
|
|
25
|
-
// `importPath` should be one of the following:
|
|
26
|
-
// - A relative import path
|
|
27
|
-
// - A filesystem absolute path
|
|
28
|
-
// - An npm package import
|
|
29
24
|
const { importPath } = pointerImportData;
|
|
30
|
-
|
|
25
|
+
assertPointerImportPath(importPath);
|
|
26
|
+
const filePathAbsoluteFilesystem = resolveImportPathWithNode(pointerImportData, importerFilePath, userRootDir);
|
|
31
27
|
let filePath;
|
|
32
28
|
assertPosixPath(importPath);
|
|
33
|
-
if (importPath
|
|
34
|
-
if (importPath.startsWith('.')) {
|
|
35
|
-
assertUsage(pathIsRelative(importPath), `Invalid relative import path ${pc.code(importPath)} defined by ${importerFilePath.filePathToShowToUser} because it should start with ${pc.code('./')} or ${pc.code('../')}, or use an npm package import instead.`);
|
|
36
|
-
}
|
|
29
|
+
if (isImportPathRelative(importPath) || isFilePathAbsolute(importPath)) {
|
|
37
30
|
// Pointer imports are included in virtual files, thus relative imports need to be resolved. (Virtual modules cannot contain relative imports.)
|
|
38
31
|
assertUsageResolutionSuccess(filePathAbsoluteFilesystem, pointerImportData, importerFilePath);
|
|
39
32
|
// 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
|
|
40
33
|
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.`;
|
|
41
34
|
const filePathAbsoluteUserRootDir = getFilePathAbsoluteUserRootDir({ filePathAbsoluteFilesystem, userRootDir });
|
|
42
|
-
if (importPath
|
|
35
|
+
if (isImportPathRelative(importPath)) {
|
|
43
36
|
assertUsage(filePathAbsoluteUserRootDir, `The relative import ${pc.cyan(importPath)} defined by ${importerFilePath.filePathToShowToUser} resolves to ${filePathAbsoluteFilesystem} ${errSuffix}`);
|
|
44
37
|
}
|
|
45
38
|
else {
|
|
@@ -51,6 +44,7 @@ function resolvePointerImportData(pointerImportData, importerFilePath, userRootD
|
|
|
51
44
|
filePath = getFilePathResolved({ filePathAbsoluteUserRootDir, userRootDir });
|
|
52
45
|
}
|
|
53
46
|
else {
|
|
47
|
+
assert(isImportPathNpmPackageOrPathAlias(importPath));
|
|
54
48
|
const importPathAbsolute = importPath;
|
|
55
49
|
if (filePathAbsoluteFilesystem) {
|
|
56
50
|
filePath = getFilePathResolved({
|
|
@@ -68,12 +62,20 @@ function resolvePointerImportData(pointerImportData, importerFilePath, userRootD
|
|
|
68
62
|
}
|
|
69
63
|
return filePath;
|
|
70
64
|
}
|
|
71
|
-
function resolveImportPathWithNode(pointerImportData, importerFilePath) {
|
|
65
|
+
function resolveImportPathWithNode(pointerImportData, importerFilePath, userRootDir) {
|
|
72
66
|
const importerFilePathAbsolute = importerFilePath.filePathAbsoluteFilesystem;
|
|
73
67
|
assertPosixPath(importerFilePathAbsolute);
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
68
|
+
// filePathAbsoluteFilesystem is null when pointerImportData.importPath is a path alias that Node.js doesn't know about
|
|
69
|
+
const filePathAbsoluteFilesystem = requireResolveOptional({
|
|
70
|
+
importPath: pointerImportData.importPath,
|
|
71
|
+
importerFilePath: importerFilePathAbsolute,
|
|
72
|
+
userRootDir
|
|
73
|
+
});
|
|
74
|
+
if (!filePathAbsoluteFilesystem) {
|
|
75
|
+
assert(!isImportPathRelative(pointerImportData.importPath));
|
|
76
|
+
// Libraries don't use path aliases => filePathAbsoluteFilesystem should be defined
|
|
77
|
+
assert(!importerFilePathAbsolute.includes('node_modules'));
|
|
78
|
+
}
|
|
77
79
|
return filePathAbsoluteFilesystem;
|
|
78
80
|
}
|
|
79
81
|
function assertUsageResolutionSuccess(filePathAbsoluteFilesystem, pointerImportData, importerFilePath) {
|
|
@@ -85,8 +87,7 @@ function assertUsageResolutionSuccess(filePathAbsoluteFilesystem, pointerImportD
|
|
|
85
87
|
? `The import path ${importPathString} in ${filePathToShowToUser}`
|
|
86
88
|
: `The import ${pc.code(importString)} defined by ${filePathToShowToUser}`;
|
|
87
89
|
const errIntro2 = `${errIntro} couldn't be resolved: does ${importPathString}`;
|
|
88
|
-
if (importPath
|
|
89
|
-
assert(pathIsRelative(importPath));
|
|
90
|
+
if (isImportPathRelative(importPath)) {
|
|
90
91
|
assertUsage(false, `${errIntro2} point to an existing file?`);
|
|
91
92
|
}
|
|
92
93
|
else {
|
|
@@ -7,8 +7,8 @@ import fs from 'fs';
|
|
|
7
7
|
import path from 'path';
|
|
8
8
|
import pc from '@brillout/picocolors';
|
|
9
9
|
import { import_ } from '@brillout/import';
|
|
10
|
-
import { assertPosixPath, getRandomId, assertIsNotProductionRuntime, assert, assertWarning, isObject, toPosixPath, assertUsage,
|
|
11
|
-
import { transformPointerImports } from './
|
|
10
|
+
import { assertPosixPath, getRandomId, assertIsNotProductionRuntime, assert, assertWarning, isObject, toPosixPath, assertUsage, isPlainScriptFile, createDebugger, assertFilePathAbsoluteFilesystem, assertIsImportPathNpmPackage, genPromise, isVitest, isImportPathNpmPackageOrPathAlias, isImportPathRelative, requireResolveOptionalDir } from '../../../../utils.js';
|
|
11
|
+
import { transformPointerImports } from './pointerImports.js';
|
|
12
12
|
import sourceMapSupport from 'source-map-support';
|
|
13
13
|
import { getFilePathAbsoluteUserRootDir } from '../../../../shared/getFilePath.js';
|
|
14
14
|
assertIsNotProductionRuntime();
|
|
@@ -26,7 +26,7 @@ async function transpileAndExecuteFile(filePath, userRootDir, isExtensionConfig,
|
|
|
26
26
|
}
|
|
27
27
|
const { promise, resolve } = genPromise();
|
|
28
28
|
esbuildCache.transpileCache[filePathAbsoluteFilesystem] = promise;
|
|
29
|
-
assertUsage(
|
|
29
|
+
assertUsage(isPlainScriptFile(filePathAbsoluteFilesystem), `${filePathToShowToUserResolved} has file extension .${fileExtension} but a config file can only be a JavaScript/TypeScript file`);
|
|
30
30
|
const isHeader = isHeaderFile(filePathAbsoluteFilesystem);
|
|
31
31
|
if (isHeader) {
|
|
32
32
|
assertWarning(false, `${pc.cyan('.h.js')} files are deprecated: simply renaming ${filePathToShowToUserResolved} to ${removeHeaderFileExtension(filePathToShowToUserResolved)} is usually enough, although you may occasionally need to use ${pc.cyan("with { type: 'pointer' }")} as explained at https://vike.dev/config#pointer-imports`, { onlyOnce: true });
|
|
@@ -121,7 +121,11 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
|
|
|
121
121
|
// - Sitll required for esbuild@0.24.0 (November 2024).
|
|
122
122
|
// - Let's try to remove this workaround again later.
|
|
123
123
|
if (resolved.errors.length > 0) {
|
|
124
|
-
const resolvedWithNode =
|
|
124
|
+
const resolvedWithNode = requireResolveOptionalDir({
|
|
125
|
+
importPath: path,
|
|
126
|
+
importerDir: toPosixPath(args.resolveDir),
|
|
127
|
+
userRootDir
|
|
128
|
+
});
|
|
125
129
|
if (debugEsbuildResolve.isActivated)
|
|
126
130
|
debugEsbuildResolve('resolvedWithNode', resolvedWithNode);
|
|
127
131
|
if (resolvedWithNode)
|
|
@@ -141,14 +145,14 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
|
|
|
141
145
|
const importPathOriginal = args.path;
|
|
142
146
|
// Esbuild resolves path aliases.
|
|
143
147
|
// - Enabling us to use:
|
|
144
|
-
// -
|
|
145
|
-
// -
|
|
148
|
+
// - assertIsImportPathNpmPackage()
|
|
149
|
+
// - isImportPathNpmPackage(str, { cannotBePathAlias: true })
|
|
146
150
|
assertFilePathAbsoluteFilesystem(importPathResolved);
|
|
147
151
|
// Should be remove this? See comment below.
|
|
148
152
|
const isVikeExtensionImport = (path.startsWith('vike-') && path.endsWith('/config')) || importPathResolved.endsWith('+config.js');
|
|
149
153
|
const isPointerImport = transformImports === 'all' ||
|
|
150
154
|
// .jsx, .vue, .svg, ... => obviously not config code => pointer import
|
|
151
|
-
!
|
|
155
|
+
!isPlainScriptFile(importPathResolved) ||
|
|
152
156
|
// 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).
|
|
153
157
|
// - Should we stop doing this? (And instead let Node.js directly load Vike extensions.)
|
|
154
158
|
// - In principle, we can use the setting 'name' value of Vike extensions.
|
|
@@ -160,7 +164,7 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
|
|
|
160
164
|
const isNpmPkgImport = (() => {
|
|
161
165
|
if (importPathResolved.includes('/node_modules/')) {
|
|
162
166
|
// 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.
|
|
163
|
-
assert(
|
|
167
|
+
assert(isImportPathNpmPackageOrPathAlias(importPathOriginal));
|
|
164
168
|
return true;
|
|
165
169
|
}
|
|
166
170
|
// Linked npm packages
|
|
@@ -169,7 +173,7 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
|
|
|
169
173
|
// - This isn't always the case: https://github.com/vikejs/vike/issues/2326
|
|
170
174
|
!importPathResolved.startsWith(userRootDir) &&
|
|
171
175
|
// 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.
|
|
172
|
-
|
|
176
|
+
isImportPathNpmPackageOrPathAlias(importPathOriginal)) {
|
|
173
177
|
return true;
|
|
174
178
|
}
|
|
175
179
|
return false;
|
|
@@ -186,7 +190,7 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
|
|
|
186
190
|
}
|
|
187
191
|
let importPathTranspiled;
|
|
188
192
|
assertPosixPath(importPathOriginal);
|
|
189
|
-
if (
|
|
193
|
+
if (isImportPathRelative(importPathOriginal)) {
|
|
190
194
|
importPathTranspiled = importPathResolved;
|
|
191
195
|
}
|
|
192
196
|
else {
|
|
@@ -203,12 +207,11 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
|
|
|
203
207
|
// - Vike doesn't resolve path aliases at all.
|
|
204
208
|
// - Node.js doesn't support `tsconfig.js#compilerOptions.paths`.
|
|
205
209
|
// - Esbuild path alias resolution seems reliable, e.g. it supports `tsconfig.js#compilerOptions.paths`.
|
|
206
|
-
assert(!isNpmPackageImport_unreliable(importPathOriginal));
|
|
207
210
|
importPathTranspiled = importPathResolved;
|
|
208
211
|
}
|
|
209
212
|
else {
|
|
210
213
|
// `importPathOriginal` is most likely an npm package import.
|
|
211
|
-
|
|
214
|
+
assertIsImportPathNpmPackage(importPathOriginal);
|
|
212
215
|
// For improved error messages, let the resolution be handled by Vike or Node.js.
|
|
213
216
|
importPathTranspiled = importPathOriginal;
|
|
214
217
|
}
|
|
@@ -70,7 +70,7 @@ async function handleReloadSideEffects() {
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
|
-
// TODO/soon: predominantly use
|
|
73
|
+
// TODO/soon: predominantly use getVikeConfigInternal() instead of getVikeConfig() then maybe refector?
|
|
74
74
|
async function getVikeConfig(config, { doNotRestartViteOnError } = {}) {
|
|
75
75
|
const userRootDir = config.root;
|
|
76
76
|
const vikeVitePluginOptions = config._vikeVitePluginOptions;
|
|
@@ -405,7 +405,7 @@ function setCliAndApiOptions(pageConfigGlobal, configDefinitionsResolved) {
|
|
|
405
405
|
Object.entries(configValues).forEach(([configName, value]) => {
|
|
406
406
|
var _a;
|
|
407
407
|
const sourceName = `The ${getDefinedByString(definedBy, configName)}`;
|
|
408
|
-
assertKnownConfig(configName, configDefinitionsResolved.configNamesKnownGlobal, configDefinitionsResolved, '/', sourceName, exitOnError);
|
|
408
|
+
assertKnownConfig(configName, configDefinitionsResolved.configNamesKnownGlobal, configDefinitionsResolved, '/', false, sourceName, exitOnError);
|
|
409
409
|
const sources = ((_a = pageConfigGlobal.configValueSources)[configName] ?? (_a[configName] = []));
|
|
410
410
|
sources.unshift(getSourceNonConfigFile(configName, value, definedBy));
|
|
411
411
|
});
|
|
@@ -677,15 +677,12 @@ function resolveIsGlobalValue(configDefGlobal, source, plusFilesAll) {
|
|
|
677
677
|
return isGlobal;
|
|
678
678
|
}
|
|
679
679
|
function getConfigNamesSetByPlusFile(plusFile) {
|
|
680
|
-
let configNames = [];
|
|
681
680
|
if (!plusFile.isConfigFile) {
|
|
682
|
-
|
|
681
|
+
return [plusFile.configName];
|
|
683
682
|
}
|
|
684
|
-
|
|
685
|
-
|
|
683
|
+
else {
|
|
684
|
+
return Object.keys(plusFile.fileExportsByConfigName);
|
|
686
685
|
}
|
|
687
|
-
configNames = unique(configNames);
|
|
688
|
-
return configNames;
|
|
689
686
|
}
|
|
690
687
|
function getConfigDefinitions(plusFilesRelevant, filter) {
|
|
691
688
|
let configDefinitions = { ...configDefinitionsBuiltIn };
|
|
@@ -880,12 +877,12 @@ function assertKnownConfigs(configDefinitionsResolved) {
|
|
|
880
877
|
configNames.forEach((configName) => {
|
|
881
878
|
const { locationId } = plusFile;
|
|
882
879
|
const sourceName = plusFile.filePath.filePathToShowToUser;
|
|
883
|
-
assertKnownConfig(configName, configNamesKnownLocal, configDefinitionsResolved, locationId, sourceName, false);
|
|
880
|
+
assertKnownConfig(configName, configNamesKnownLocal, configDefinitionsResolved, locationId, true, sourceName, false);
|
|
884
881
|
});
|
|
885
882
|
});
|
|
886
883
|
});
|
|
887
884
|
}
|
|
888
|
-
function assertKnownConfig(configName, configNamesKnownRelevant, configDefinitionsResolved, locationId, sourceName, exitOnError) {
|
|
885
|
+
function assertKnownConfig(configName, configNamesKnownRelevant, configDefinitionsResolved, locationId, isPlusFile, sourceName, exitOnError) {
|
|
889
886
|
const { configNamesKnownAll } = configDefinitionsResolved;
|
|
890
887
|
if (configNamesKnownRelevant.includes(configName)) {
|
|
891
888
|
assert(configNamesKnownAll.includes(configName));
|
|
@@ -896,7 +893,10 @@ function assertKnownConfig(configName, configNamesKnownRelevant, configDefinitio
|
|
|
896
893
|
if (configNamesKnownAll.includes(configName)) {
|
|
897
894
|
assertUsage(false, `${sourceName} sets the value of the config ${configNameColored} which is a custom config that is defined with ${pc.underline('https://vike.dev/meta')} at a path that doesn't apply to ${locationId} — see ${pc.underline('https://vike.dev/config#inheritance')}`, { exitOnError });
|
|
898
895
|
}
|
|
899
|
-
const errMsg =
|
|
896
|
+
const errMsg = isPlusFile
|
|
897
|
+
? `${sourceName} sets an unknown config ${configNameColored}`
|
|
898
|
+
: `${sourceName} sets an unknown Vike config, see ${pc.underline('https://vike.dev/cli')} for the list of CLI options`;
|
|
899
|
+
assert(errMsg.includes(configName));
|
|
900
900
|
// Missing vike-{react,vue,solid} installation
|
|
901
901
|
{
|
|
902
902
|
const ui = ['vike-react', 'vike-vue', 'vike-solid'];
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
export { replaceConstants };
|
|
2
|
+
import MagicString from 'magic-string';
|
|
3
|
+
import { assert, assertPosixPath } from '../utils.js';
|
|
4
|
+
import { normalizeId } from '../shared/normalizeId.js';
|
|
5
|
+
import { isViteServerBuild_safe } from '../shared/isViteServerBuild.js';
|
|
6
|
+
import { applyRegExpWithMagicString } from '../shared/applyRegExWithMagicString.js';
|
|
7
|
+
function replaceConstants() {
|
|
8
|
+
let config;
|
|
9
|
+
return {
|
|
10
|
+
name: 'vike:replaceConstants',
|
|
11
|
+
enforce: 'post',
|
|
12
|
+
apply: 'build',
|
|
13
|
+
configResolved(config_) {
|
|
14
|
+
config = config_;
|
|
15
|
+
},
|
|
16
|
+
transform(code, id, options) {
|
|
17
|
+
id = normalizeId(id);
|
|
18
|
+
assertPosixPath(id);
|
|
19
|
+
if (id.includes('/node_modules/'))
|
|
20
|
+
return;
|
|
21
|
+
assertPosixPath(config.root);
|
|
22
|
+
if (!id.startsWith(config.root))
|
|
23
|
+
return;
|
|
24
|
+
if (!code.includes('import.meta.env.'))
|
|
25
|
+
return;
|
|
26
|
+
const isBuild = config.command === 'build';
|
|
27
|
+
assert(isBuild);
|
|
28
|
+
// Used by vike.dev
|
|
29
|
+
// https://github.com/vikejs/vike/blob/08a1ff55c80ddca64ca6d4417fefd45fefeb4ffb/docs/vite.config.ts#L12
|
|
30
|
+
// @ts-expect-error
|
|
31
|
+
if (config._skipVikeReplaceConstants?.(id))
|
|
32
|
+
return;
|
|
33
|
+
const magicString = new MagicString(code);
|
|
34
|
+
const constantsMap = [];
|
|
35
|
+
constantsMap.push({
|
|
36
|
+
constants: ['pageContext.isClientSide', 'globalContext.isClientSide', 'pageContext.globalContext.isClientSide'],
|
|
37
|
+
replacement: !isViteServerBuild_safe(config, options)
|
|
38
|
+
});
|
|
39
|
+
constantsMap.forEach(({ constants, replacement }) => {
|
|
40
|
+
if (!constants.some((c) => code.includes(c)))
|
|
41
|
+
return;
|
|
42
|
+
const regExp = getConstantRegExp(constants);
|
|
43
|
+
applyRegExpWithMagicString(magicString, regExp, replacement);
|
|
44
|
+
});
|
|
45
|
+
if (!magicString.hasChanged())
|
|
46
|
+
return null;
|
|
47
|
+
return {
|
|
48
|
+
code: magicString.toString(),
|
|
49
|
+
map: magicString.generateMap({ hires: true, source: id })
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
// Copied & adapted from:
|
|
55
|
+
// https://github.com/rollup/plugins/blob/e1a5ef99f1578eb38a8c87563cb9651db228f3bd/packages/replace/src/index.js#L57-L67
|
|
56
|
+
function getConstantRegExp(constants) {
|
|
57
|
+
const keys = Object.values(constants).sort(longest).map(escape);
|
|
58
|
+
// const delimiters = ['\\b', '\\b(?!\\.)']
|
|
59
|
+
const delimiters = ['(?<!\\.)\\b', '\\b(?!\\.)']; // Improved version, to avoid replacing `globalContext.pageContext.isClientSide` with `globalContext.false`
|
|
60
|
+
const preventAssignment = false; // Let's try without it first, let's see if a user complains
|
|
61
|
+
const lookbehind = preventAssignment ? '(?<!\\b(?:const|let|var)\\s*)' : '';
|
|
62
|
+
const lookahead = preventAssignment ? '(?!\\s*=[^=])' : '';
|
|
63
|
+
const pattern = new RegExp(`${lookbehind}${delimiters[0]}(${keys.join('|')})${delimiters[1]}${lookahead}`, 'g');
|
|
64
|
+
return pattern;
|
|
65
|
+
}
|
|
66
|
+
function escape(str) {
|
|
67
|
+
return str.replace(/[-[\]/{}()*+?.\\^$|]/g, '\\$&');
|
|
68
|
+
}
|
|
69
|
+
function longest(a, b) {
|
|
70
|
+
return b.length - a.length;
|
|
71
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { applyRegExpWithMagicString };
|
|
2
|
+
function applyRegExpWithMagicString(magicString, regExp, replacement) {
|
|
3
|
+
const envStatementRegEx = typeof regExp === 'string' ? new RegExp(regExp, 'g') : regExp;
|
|
4
|
+
let match;
|
|
5
|
+
while ((match = envStatementRegEx.exec(magicString.original))) {
|
|
6
|
+
magicString.overwrite(match.index, match.index + match[0].length, JSON.stringify(replacement));
|
|
7
|
+
}
|
|
8
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
export { findPageFiles };
|
|
2
2
|
import { glob } from 'tinyglobby';
|
|
3
|
-
import { assertWarning, toPosixPath,
|
|
3
|
+
import { assertWarning, toPosixPath, scriptFileExtensionPattern } from '../utils.js';
|
|
4
4
|
import pc from '@brillout/picocolors';
|
|
5
5
|
import { getOutDirs } from './getOutDirs.js';
|
|
6
6
|
async function findPageFiles(config, fileTypes, isDev) {
|
|
7
7
|
const cwd = config.root;
|
|
8
8
|
const { outDirRoot } = getOutDirs(config);
|
|
9
9
|
const timeBase = new Date().getTime();
|
|
10
|
-
let pageFiles = await glob(fileTypes.map((fileType) => `**/*${fileType}.${
|
|
10
|
+
let pageFiles = await glob(fileTypes.map((fileType) => `**/*${fileType}.${scriptFileExtensionPattern}`), { ignore: ['**/node_modules/**', `${outDirRoot}/**`], cwd, dot: false, expandDirectories: false });
|
|
11
11
|
pageFiles = pageFiles.map((p) => '/' + toPosixPath(p));
|
|
12
12
|
const time = new Date().getTime() - timeBase;
|
|
13
13
|
if (isDev) {
|