vike 0.4.142 → 0.4.143-commit-f03b42d
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/node/plugin/index.js +2 -2
- package/dist/cjs/node/plugin/plugins/buildConfig.js +4 -5
- package/dist/cjs/node/plugin/plugins/commonConfig.js +2 -7
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +2 -2
- package/dist/cjs/node/plugin/plugins/envVars.js +3 -5
- package/dist/cjs/node/plugin/plugins/importUserCode/generateEagerImport.js +19 -8
- package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/index.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +110 -114
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +37 -27
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +50 -80
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/helpers.js +12 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/replaceImportStatements.js +25 -25
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.js +19 -16
- package/dist/cjs/node/plugin/plugins/suppressRollupWarning.js +16 -3
- package/dist/cjs/node/plugin/shared/{getConfigValueSource.js → getConfigValueSourcesRelevant.js} +1 -12
- package/dist/cjs/node/plugin/shared/loggerNotProd/errorWithCodeSnippet.js +1 -1
- package/dist/cjs/node/plugin/shared/loggerNotProd.js +3 -3
- package/dist/cjs/node/plugin/utils.js +1 -2
- package/dist/cjs/node/prerender/runPrerender.js +13 -16
- package/dist/cjs/node/runtime/html/stream.js +4 -1
- package/dist/cjs/node/runtime/renderPage/analyzePage.js +2 -2
- package/dist/cjs/node/runtime/renderPage/loadPageFilesServerSide.js +2 -2
- package/dist/cjs/node/shared/virtual-files/virtualFilePageConfigValuesAll.js +1 -1
- package/dist/cjs/shared/error-page.js +1 -1
- package/dist/cjs/shared/getPageFiles/assertPageConfigs.js +13 -13
- package/dist/cjs/shared/getPageFiles/getExports.js +3 -3
- package/dist/cjs/shared/getPageFiles/parseGlobResults.js +9 -43
- package/dist/cjs/shared/getPageFiles/parsePageConfigsSerialized.js +62 -0
- package/dist/cjs/shared/page-configs/assertExports.js +60 -0
- package/dist/cjs/shared/page-configs/loadConfigValues.js +18 -0
- package/dist/cjs/shared/page-configs/parseConfigValuesImported.js +50 -0
- package/dist/cjs/shared/page-configs/utils.js +1 -1
- package/dist/cjs/shared/route/loadPageRoutes.js +11 -13
- package/dist/cjs/shared/route/resolvePrecedence.js +32 -11
- package/dist/cjs/shared/route/resolveRedirects.js +1 -1
- package/dist/cjs/shared/route/resolveRouteFunction.js +1 -0
- package/dist/cjs/shared/route/resolveRouteString.js +99 -43
- package/dist/cjs/shared/utils.js +1 -1
- package/dist/cjs/types/defineConfig.js +7 -0
- package/dist/cjs/types/index.js +3 -0
- package/dist/cjs/utils/getFilePathAbsolute.js +16 -12
- package/dist/cjs/utils/objectAssign.js +3 -1
- package/dist/cjs/utils/parseUrl.js +6 -1
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/cjs/utils/requireResolve.js +60 -0
- package/dist/esm/__internal/index.d.ts +3 -3
- package/dist/esm/client/client-routing-runtime/createPageContext.d.ts +2 -2
- package/dist/esm/client/client-routing-runtime/getPageContext.d.ts +2 -2
- package/dist/esm/client/client-routing-runtime/getPageId.d.ts +2 -2
- package/dist/esm/client/client-routing-runtime/prefetch.js +3 -1
- package/dist/esm/client/client-routing-runtime/useClientRouter.js +2 -2
- package/dist/esm/client/server-routing-runtime/getPageContext.d.ts +1 -1
- package/dist/esm/client/shared/executeOnRenderClientHook.d.ts +2 -2
- package/dist/esm/client/shared/loadPageFilesClientSide.d.ts +2 -2
- package/dist/esm/client/shared/loadPageFilesClientSide.js +2 -2
- package/dist/esm/client/shared/preparePageContextForUserConsumptionClientSide.d.ts +2 -2
- package/dist/esm/node/plugin/index.js +3 -2
- package/dist/esm/node/plugin/plugins/buildConfig.js +4 -5
- package/dist/esm/node/plugin/plugins/commonConfig.js +2 -7
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +1 -1
- package/dist/esm/node/plugin/plugins/envVars.js +4 -6
- package/dist/esm/node/plugin/plugins/importUserCode/generateEagerImport.d.ts +13 -2
- package/dist/esm/node/plugin/plugins/importUserCode/generateEagerImport.js +19 -8
- package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/index.js +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.d.ts +8 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +111 -115
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.d.ts +5 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +35 -25
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.d.ts +3 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +49 -79
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/helpers.js +10 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/replaceImportStatements.d.ts +18 -6
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/replaceImportStatements.js +25 -25
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.js +19 -16
- package/dist/esm/node/plugin/plugins/suppressRollupWarning.js +16 -3
- package/dist/esm/node/plugin/shared/{getConfigValueSource.d.ts → getConfigValueSourcesRelevant.d.ts} +0 -2
- package/dist/esm/node/plugin/shared/{getConfigValueSource.js → getConfigValueSourcesRelevant.js} +0 -11
- package/dist/esm/node/plugin/shared/loggerNotProd/errorWithCodeSnippet.js +2 -2
- package/dist/esm/node/plugin/shared/loggerNotProd.js +4 -4
- package/dist/esm/node/plugin/utils.d.ts +1 -2
- package/dist/esm/node/plugin/utils.js +1 -2
- package/dist/esm/node/prerender/runPrerender.js +13 -16
- package/dist/esm/node/runtime/html/injectAssets.d.ts +2 -2
- package/dist/esm/node/runtime/html/serializePageContextClientSide.d.ts +2 -2
- package/dist/esm/node/runtime/html/stream.js +4 -1
- package/dist/esm/node/runtime/renderPage/analyzePage.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/analyzePage.js +2 -2
- package/dist/esm/node/runtime/renderPage/createHttpResponseObject.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/debugPageFiles.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/handleErrorWithoutErrorPage.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/loadPageFilesServerSide.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/loadPageFilesServerSide.js +2 -2
- package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +13 -13
- package/dist/esm/node/shared/getClientEntryFilePath.d.ts +2 -2
- package/dist/esm/node/shared/virtual-files/virtualFilePageConfigValuesAll.js +1 -1
- package/dist/esm/shared/addIs404ToPageProps.d.ts +2 -2
- package/dist/esm/shared/error-page.d.ts +3 -3
- package/dist/esm/shared/error-page.js +1 -1
- package/dist/esm/shared/getPageFiles/analyzeClientSide.d.ts +2 -2
- package/dist/esm/shared/getPageFiles/assertPageConfigs.d.ts +5 -5
- package/dist/esm/shared/getPageFiles/assertPageConfigs.js +12 -12
- package/dist/esm/shared/getPageFiles/getExports.d.ts +2 -2
- package/dist/esm/shared/getPageFiles/getExports.js +1 -1
- package/dist/esm/shared/getPageFiles/parseGlobResults.d.ts +3 -3
- package/dist/esm/shared/getPageFiles/parseGlobResults.js +9 -43
- package/dist/esm/shared/getPageFiles/parsePageConfigsSerialized.d.ts +6 -0
- package/dist/esm/shared/getPageFiles/parsePageConfigsSerialized.js +59 -0
- package/dist/esm/shared/getPageFiles/setPageFiles.d.ts +3 -3
- package/dist/esm/shared/page-configs/Config.d.ts +200 -11
- package/dist/esm/shared/page-configs/PageConfig.d.ts +59 -39
- package/dist/esm/shared/page-configs/assertExports.d.ts +6 -0
- package/dist/esm/shared/page-configs/assertExports.js +54 -0
- package/dist/esm/shared/page-configs/findPageConfig.d.ts +2 -2
- package/dist/esm/shared/page-configs/loadConfigValues.d.ts +3 -0
- package/dist/esm/shared/page-configs/loadConfigValues.js +15 -0
- package/dist/esm/shared/page-configs/parseConfigValuesImported.d.ts +3 -0
- package/dist/esm/shared/page-configs/parseConfigValuesImported.js +44 -0
- package/dist/esm/shared/page-configs/utils.d.ts +3 -2
- package/dist/esm/shared/page-configs/utils.js +1 -1
- package/dist/esm/shared/route/executeGuardHook.d.ts +2 -2
- package/dist/esm/shared/route/index.d.ts +3 -3
- package/dist/esm/shared/route/loadPageRoutes.d.ts +2 -2
- package/dist/esm/shared/route/loadPageRoutes.js +11 -13
- package/dist/esm/shared/route/resolvePrecedence.js +33 -12
- package/dist/esm/shared/route/resolveRedirects.js +1 -1
- package/dist/esm/shared/route/resolveRouteFunction.js +1 -0
- package/dist/esm/shared/route/resolveRouteString.d.ts +21 -4
- package/dist/esm/shared/route/resolveRouteString.js +98 -42
- package/dist/esm/shared/types.d.ts +7 -6
- package/dist/esm/shared/utils.d.ts +1 -1
- package/dist/esm/shared/utils.js +1 -1
- package/dist/esm/types/defineConfig.d.ts +3 -0
- package/dist/esm/types/defineConfig.js +4 -0
- package/dist/esm/types/index.d.ts +2 -1
- package/dist/esm/types/index.js +1 -1
- package/dist/esm/utils/getFilePathAbsolute.d.ts +2 -2
- package/dist/esm/utils/getFilePathAbsolute.js +15 -11
- package/dist/esm/utils/objectAssign.js +3 -1
- package/dist/esm/utils/parseUrl.js +6 -1
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/dist/esm/utils/projectInfo.js +1 -1
- package/dist/esm/utils/requireResolve.d.ts +2 -0
- package/dist/esm/utils/requireResolve.js +57 -0
- package/package.json +3 -3
- package/dist/cjs/shared/page-configs/loadPageCode.js +0 -63
- package/dist/cjs/utils/addFileExtensionsToRequireResolve.js +0 -23
- package/dist/cjs/utils/assertDefaultExport.js +0 -53
- package/dist/esm/shared/page-configs/loadPageCode.d.ts +0 -3
- package/dist/esm/shared/page-configs/loadPageCode.js +0 -57
- package/dist/esm/utils/addFileExtensionsToRequireResolve.d.ts +0 -2
- package/dist/esm/utils/addFileExtensionsToRequireResolve.js +0 -20
- package/dist/esm/utils/assertDefaultExport.d.ts +0 -8
- package/dist/esm/utils/assertDefaultExport.js +0 -47
- /package/dist/cjs/shared/getPageFiles/{assertExports.js → assert_exports_old_design.js} +0 -0
- /package/dist/esm/shared/getPageFiles/{assertExports.d.ts → assert_exports_old_design.d.ts} +0 -0
- /package/dist/esm/shared/getPageFiles/{assertExports.js → assert_exports_old_design.js} +0 -0
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
export { generateEagerImport };
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Naming:
|
|
4
|
+
* `import { someExport as someImport } from './some-file'`
|
|
5
|
+
* <=>
|
|
6
|
+
* `{`
|
|
7
|
+
* `importPath: './some-file',`
|
|
8
|
+
* `exportName: 'someExport',`
|
|
9
|
+
* `importName: 'someImport',`
|
|
10
|
+
* `}`
|
|
11
|
+
* We discard the information that the import variable is called `someImport` because we don't need it.
|
|
12
|
+
*/
|
|
13
|
+
declare function generateEagerImport(importPath: string, varCounter?: number, exportName?: string): {
|
|
14
|
+
importName: string;
|
|
4
15
|
importStatement: string;
|
|
5
16
|
};
|
|
@@ -1,18 +1,29 @@
|
|
|
1
1
|
export { generateEagerImport };
|
|
2
2
|
let varCounterGlobal = 0;
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Naming:
|
|
5
|
+
* `import { someExport as someImport } from './some-file'`
|
|
6
|
+
* <=>
|
|
7
|
+
* `{`
|
|
8
|
+
* `importPath: './some-file',`
|
|
9
|
+
* `exportName: 'someExport',`
|
|
10
|
+
* `importName: 'someImport',`
|
|
11
|
+
* `}`
|
|
12
|
+
* We discard the information that the import variable is called `someImport` because we don't need it.
|
|
13
|
+
*/
|
|
14
|
+
function generateEagerImport(importPath, varCounter, exportName) {
|
|
4
15
|
if (varCounter === undefined)
|
|
5
16
|
varCounter = varCounterGlobal++;
|
|
6
|
-
const
|
|
17
|
+
const importName = `import_${varCounter}`;
|
|
7
18
|
const importLiteral = (() => {
|
|
8
|
-
if (!
|
|
9
|
-
return `* as ${
|
|
19
|
+
if (!exportName || exportName === '*') {
|
|
20
|
+
return `* as ${importName}`;
|
|
10
21
|
}
|
|
11
|
-
if (
|
|
12
|
-
return
|
|
22
|
+
if (exportName === 'default') {
|
|
23
|
+
return importName;
|
|
13
24
|
}
|
|
14
|
-
return `{ ${
|
|
25
|
+
return `{ ${exportName} as ${importName} }`;
|
|
15
26
|
})();
|
|
16
27
|
const importStatement = `import ${importLiteral} from '${importPath}';`;
|
|
17
|
-
return {
|
|
28
|
+
return { importName, importStatement };
|
|
18
29
|
}
|
|
@@ -121,9 +121,9 @@ function addImport(importPath, fileType, exportNames, isBuild) {
|
|
|
121
121
|
return `() => import('${importPath}${query}')`;
|
|
122
122
|
}
|
|
123
123
|
else {
|
|
124
|
-
const {
|
|
124
|
+
const { importName, importStatement } = generateEagerImport(`${importPath}${query}`);
|
|
125
125
|
fileContent += importStatement + '\n';
|
|
126
|
-
return
|
|
126
|
+
return importName;
|
|
127
127
|
}
|
|
128
128
|
})();
|
|
129
129
|
fileContent += `${mapVar}['${importPath}'] = ${value};\n`;
|
|
@@ -3,7 +3,7 @@ import { normalizePath } from 'vite';
|
|
|
3
3
|
import { getConfigVike } from '../../../shared/getConfigVike.js';
|
|
4
4
|
import { getVirtualFilePageConfigValuesAll } from './v1-design/getVirtualFilePageConfigValuesAll.js';
|
|
5
5
|
import { getVirtualFileImportUserCode } from './getVirtualFileImportUserCode.js';
|
|
6
|
-
import { assert, assertPosixPath,
|
|
6
|
+
import { assert, assertPosixPath, getFilePathRelativeToUserRootDir, getVirtualFileId, isDev1, isDev1_onConfigureServer, isVirtualFileId, resolveVirtualFileId } from '../../utils.js';
|
|
7
7
|
import { isVirtualFileIdPageConfigValuesAll } from '../../../shared/virtual-files/virtualFilePageConfigValuesAll.js';
|
|
8
8
|
import { isVirtualFileIdImportUserCode } from '../../../shared/virtual-files/virtualFileImportUserCode.js';
|
|
9
9
|
import { vikeConfigDependencies, reloadVikeConfig, isVikeConfigFile } from './v1-design/getVikeConfig.js';
|
|
@@ -116,7 +116,7 @@ function isVikeConfigModule(filePathAbsolute) {
|
|
|
116
116
|
}
|
|
117
117
|
function reloadConfig(filePath, config, configVike, op) {
|
|
118
118
|
{
|
|
119
|
-
const filePathToShowToUser = pc.dim(
|
|
119
|
+
const filePathToShowToUser = pc.dim(getFilePathRelativeToUserRootDir(filePath, config.root, true));
|
|
120
120
|
const msg = `${op} ${filePathToShowToUser}`;
|
|
121
121
|
logConfigInfo(msg, 'info');
|
|
122
122
|
}
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
export { getFilePathToShowToUser };
|
|
2
2
|
export type { FilePath };
|
|
3
3
|
type FilePath = {
|
|
4
|
+
/** The file's path relative to the filesystem root.
|
|
5
|
+
*
|
|
6
|
+
* Example: `/home/rom/code/my-app/pages/some-page/Page.js`
|
|
7
|
+
*/
|
|
4
8
|
filePathAbsolute: string;
|
|
9
|
+
/** The file's path relative to the Vite's root (i.e. the user's project root directory).
|
|
10
|
+
*
|
|
11
|
+
* Example: `/pages/some-page/Page.js`
|
|
12
|
+
*/
|
|
5
13
|
filePathRelativeToUserRootDir: null | string;
|
|
6
14
|
};
|
|
7
15
|
declare function getFilePathToShowToUser(filePath: FilePath): string;
|
|
@@ -2,11 +2,11 @@ export { getVikeConfig };
|
|
|
2
2
|
export { reloadVikeConfig };
|
|
3
3
|
export { vikeConfigDependencies };
|
|
4
4
|
export { isVikeConfigFile };
|
|
5
|
-
import type {
|
|
5
|
+
import type { PageConfigGlobalBuildTime, PageConfigBuildTime } from '../../../../../shared/page-configs/PageConfig.js';
|
|
6
6
|
import type { ExtensionResolved } from '../../../../../shared/ConfigVike.js';
|
|
7
7
|
type VikeConfig = {
|
|
8
8
|
pageConfigs: PageConfigBuildTime[];
|
|
9
|
-
pageConfigGlobal:
|
|
9
|
+
pageConfigGlobal: PageConfigGlobalBuildTime;
|
|
10
10
|
globalVikeConfig: Record<string, unknown>;
|
|
11
11
|
};
|
|
12
12
|
declare const vikeConfigDependencies: Set<string>;
|
|
@@ -2,7 +2,7 @@ export { getVikeConfig };
|
|
|
2
2
|
export { reloadVikeConfig };
|
|
3
3
|
export { vikeConfigDependencies };
|
|
4
4
|
export { isVikeConfigFile };
|
|
5
|
-
import { assertPosixPath, assert, isObject, assertUsage, toPosixPath, assertWarning,
|
|
5
|
+
import { assertPosixPath, assert, isObject, assertUsage, toPosixPath, assertWarning, objectEntries, hasProp, arrayIncludes, assertIsNotProductionRuntime, getMostSimilar, isNpmPackageImport, joinEnglish, lowerFirst, scriptFileExtensions, mergeCumulativeValues, requireResolve } from '../../../utils.js';
|
|
6
6
|
import path from 'path';
|
|
7
7
|
import { configDefinitionsBuiltIn, configDefinitionsBuiltInGlobal } from './getVikeConfig/configDefinitionsBuiltIn.js';
|
|
8
8
|
import glob from 'fast-glob';
|
|
@@ -15,20 +15,18 @@ import { logConfigError, logConfigErrorRecover } from '../../../shared/loggerNot
|
|
|
15
15
|
import { removeSuperfluousViteLog_enable, removeSuperfluousViteLog_disable } from '../../../shared/loggerVite/removeSuperfluousViteLog.js';
|
|
16
16
|
import { getFilePathToShowToUser } from './getFilePathToShowToUser.js';
|
|
17
17
|
import pc from '@brillout/picocolors';
|
|
18
|
-
import { createRequire } from 'module';
|
|
19
18
|
import { getConfigDefinedAtString } from '../../../../../shared/page-configs/utils.js';
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const require_ = createRequire(importMetaUrl);
|
|
19
|
+
import { assertExportsOfConfigFile, assertExportsOfValueFile } from '../../../../../shared/page-configs/assertExports.js';
|
|
20
|
+
import { getConfigValueSerialized } from './getVirtualFilePageConfigs.js';
|
|
23
21
|
assertIsNotProductionRuntime();
|
|
24
22
|
let devServerIsCorrupt = false;
|
|
25
23
|
let wasConfigInvalid = null;
|
|
26
24
|
let vikeConfigPromise = null;
|
|
27
25
|
const vikeConfigDependencies = new Set();
|
|
28
|
-
const
|
|
26
|
+
const filesEnv = new Map();
|
|
29
27
|
function reloadVikeConfig(userRootDir, extensions) {
|
|
30
28
|
vikeConfigDependencies.clear();
|
|
31
|
-
|
|
29
|
+
filesEnv.clear();
|
|
32
30
|
vikeConfigPromise = loadVikeConfig_withErrorHandling(userRootDir, true, extensions, true);
|
|
33
31
|
handleReloadSideEffects();
|
|
34
32
|
}
|
|
@@ -100,27 +98,27 @@ async function loadInterfaceFiles(userRootDir, isDev, extensions) {
|
|
|
100
98
|
}));
|
|
101
99
|
// Value files
|
|
102
100
|
await Promise.all(valueFiles.map(async ({ filePathAbsolute, filePathRelativeToUserRootDir }) => {
|
|
103
|
-
const
|
|
104
|
-
assert(
|
|
101
|
+
const configName = getConfigName(filePathRelativeToUserRootDir);
|
|
102
|
+
assert(configName);
|
|
105
103
|
const interfaceFile = {
|
|
106
104
|
filePath: {
|
|
107
105
|
filePathRelativeToUserRootDir,
|
|
108
106
|
filePathAbsolute
|
|
109
107
|
},
|
|
110
108
|
configMap: {
|
|
111
|
-
[
|
|
109
|
+
[configName]: {}
|
|
112
110
|
},
|
|
113
111
|
isConfigFile: false,
|
|
114
112
|
isValueFile: true,
|
|
115
|
-
|
|
113
|
+
configName
|
|
116
114
|
};
|
|
117
115
|
{
|
|
118
116
|
// We don't have access to custom config definitions yet
|
|
119
|
-
// - We load +
|
|
117
|
+
// - We load +{configName}.js later
|
|
120
118
|
// - But we do need to eagerly load +meta.js (to get all the custom config definitions)
|
|
121
|
-
const configDef = getConfigDefinitionOptional(configDefinitionsBuiltIn,
|
|
119
|
+
const configDef = getConfigDefinitionOptional(configDefinitionsBuiltIn, configName);
|
|
122
120
|
if (configDef?.env === 'config-only') {
|
|
123
|
-
await loadValueFile(interfaceFile,
|
|
121
|
+
await loadValueFile(interfaceFile, configName, userRootDir);
|
|
124
122
|
}
|
|
125
123
|
}
|
|
126
124
|
{
|
|
@@ -140,14 +138,13 @@ function getConfigDefinition(configDefinitionsRelevant, configName, definedByFil
|
|
|
140
138
|
function getConfigDefinitionOptional(configDefinitions, configName) {
|
|
141
139
|
return configDefinitions[configName] ?? null;
|
|
142
140
|
}
|
|
143
|
-
async function loadValueFile(interfaceValueFile,
|
|
141
|
+
async function loadValueFile(interfaceValueFile, configName, userRootDir) {
|
|
144
142
|
const { fileExports } = await transpileAndExecuteFile(interfaceValueFile.filePath, true, userRootDir);
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
interfaceValueFile.configMap[configName] = { configValue };
|
|
143
|
+
const filePathToShowToUser = getFilePathToShowToUser(interfaceValueFile.filePath);
|
|
144
|
+
assertExportsOfValueFile(fileExports, filePathToShowToUser, configName);
|
|
145
|
+
Object.entries(fileExports).forEach(([exportName, configValue]) => {
|
|
146
|
+
const configName_ = exportName === 'default' ? configName : exportName;
|
|
147
|
+
interfaceValueFile.configMap[configName_] = { configValue };
|
|
151
148
|
});
|
|
152
149
|
}
|
|
153
150
|
function getInterfaceFileFromConfigFile(configFile, isConfigExtend) {
|
|
@@ -160,8 +157,8 @@ function getInterfaceFileFromConfigFile(configFile, isConfigExtend) {
|
|
|
160
157
|
isConfigExtend,
|
|
161
158
|
extendsFilePaths
|
|
162
159
|
};
|
|
163
|
-
const
|
|
164
|
-
|
|
160
|
+
const filePathToShowToUser = getFilePathToShowToUser(filePath);
|
|
161
|
+
assertExportsOfConfigFile(fileExports, filePathToShowToUser);
|
|
165
162
|
Object.entries(fileExports.default).forEach(([configName, configValue]) => {
|
|
166
163
|
interfaceFile.configMap[configName] = { configValue };
|
|
167
164
|
});
|
|
@@ -200,8 +197,7 @@ async function loadVikeConfig_withErrorHandling(userRootDir, isDev, extensions,
|
|
|
200
197
|
const dummyData = {
|
|
201
198
|
pageConfigs: [],
|
|
202
199
|
pageConfigGlobal: {
|
|
203
|
-
|
|
204
|
-
onBeforeRoute: null
|
|
200
|
+
configValueSources: {}
|
|
205
201
|
},
|
|
206
202
|
globalVikeConfig: {}
|
|
207
203
|
};
|
|
@@ -221,18 +217,18 @@ async function loadVikeConfig(userRootDir, isDev, extensions) {
|
|
|
221
217
|
await Promise.all(getInterfaceFileList(interfaceFilesRelevant).map(async (interfaceFile) => {
|
|
222
218
|
if (!interfaceFile.isValueFile)
|
|
223
219
|
return;
|
|
224
|
-
const {
|
|
225
|
-
if (isGlobalConfig(
|
|
220
|
+
const { configName } = interfaceFile;
|
|
221
|
+
if (isGlobalConfig(configName))
|
|
226
222
|
return;
|
|
227
|
-
const configDef = getConfigDefinition(configDefinitionsRelevant,
|
|
223
|
+
const configDef = getConfigDefinition(configDefinitionsRelevant, configName, getFilePathToShowToUser(interfaceFile.filePath));
|
|
228
224
|
if (configDef.env !== 'config-only')
|
|
229
225
|
return;
|
|
230
226
|
const isAlreadyLoaded = interfacefileIsAlreaydLoaded(interfaceFile);
|
|
231
227
|
if (isAlreadyLoaded)
|
|
232
228
|
return;
|
|
233
229
|
// Value files for built-in confg-only configs should have already been loaded at loadInterfaceFiles()
|
|
234
|
-
assert(!(
|
|
235
|
-
await loadValueFile(interfaceFile,
|
|
230
|
+
assert(!(configName in configDefinitionsBuiltIn));
|
|
231
|
+
await loadValueFile(interfaceFile, configName, userRootDir);
|
|
236
232
|
}));
|
|
237
233
|
const configValueSources = {};
|
|
238
234
|
objectEntries(configDefinitionsRelevant)
|
|
@@ -326,17 +322,16 @@ function getGlobalConfigs(interfaceFilesByLocationId, userRootDir) {
|
|
|
326
322
|
}
|
|
327
323
|
const globalVikeConfig = {};
|
|
328
324
|
const pageConfigGlobal = {
|
|
329
|
-
|
|
330
|
-
onPrerenderStart: null
|
|
325
|
+
configValueSources: {}
|
|
331
326
|
};
|
|
332
327
|
objectEntries(configDefinitionsBuiltInGlobal).forEach(([configName, configDef]) => {
|
|
333
328
|
const sources = resolveConfigValueSources(configName, configDef, interfaceFilesGlobal, userRootDir);
|
|
334
329
|
const configValueSource = sources?.[0];
|
|
335
330
|
if (!configValueSource)
|
|
336
331
|
return;
|
|
337
|
-
if (
|
|
332
|
+
if (configName === 'onBeforeRoute' || configName === 'onPrerenderStart') {
|
|
338
333
|
assert(!('value' in configValueSource));
|
|
339
|
-
pageConfigGlobal[configName] = configValueSource;
|
|
334
|
+
pageConfigGlobal.configValueSources[configName] = [configValueSource];
|
|
340
335
|
}
|
|
341
336
|
else {
|
|
342
337
|
assert('value' in configValueSource);
|
|
@@ -369,7 +364,7 @@ function resolveConfigValueSources(configName, configDef, interfaceFilesRelevant
|
|
|
369
364
|
const interfaceValueFiles = interfaceFilesDefiningConfig
|
|
370
365
|
.filter((interfaceFile) => interfaceFile.isValueFile &&
|
|
371
366
|
// We consider side-effect exports (e.g. `export { frontmatter }` of .mdx files) later (i.e. with less priority)
|
|
372
|
-
interfaceFile.
|
|
367
|
+
interfaceFile.configName === configName)
|
|
373
368
|
.sort(makeOrderDeterministic);
|
|
374
369
|
const interfaceConfigFiles = interfaceFilesDefiningConfig
|
|
375
370
|
.filter((interfaceFile) => interfaceFile.isConfigFile &&
|
|
@@ -379,9 +374,9 @@ function resolveConfigValueSources(configName, configDef, interfaceFilesRelevant
|
|
|
379
374
|
const interfaceValueFile = interfaceValueFiles[0];
|
|
380
375
|
const interfaceConfigFile = interfaceConfigFiles[0];
|
|
381
376
|
// Make this value:
|
|
382
|
-
// /pages/some-page/+
|
|
377
|
+
// /pages/some-page/+{configName}.js > `export default`
|
|
383
378
|
// override that value:
|
|
384
|
-
// /pages/some-page/+config > `export default { someConfig }`
|
|
379
|
+
// /pages/some-page/+config.h.js > `export default { someConfig }`
|
|
385
380
|
const interfaceFileWinner = interfaceValueFile ?? interfaceConfigFile;
|
|
386
381
|
if (interfaceFileWinner) {
|
|
387
382
|
const interfaceFilesOverriden = [...interfaceValueFiles, ...interfaceConfigFiles].filter((f) => f !== interfaceFileWinner);
|
|
@@ -396,7 +391,7 @@ function resolveConfigValueSources(configName, configDef, interfaceFilesRelevant
|
|
|
396
391
|
interfaceFilesDefiningConfig
|
|
397
392
|
.filter((interfaceFile) => interfaceFile.isValueFile &&
|
|
398
393
|
// Is side-effect export
|
|
399
|
-
interfaceFile.
|
|
394
|
+
interfaceFile.configName !== configName)
|
|
400
395
|
.forEach((interfaceValueFileSideEffect) => {
|
|
401
396
|
add(interfaceValueFileSideEffect);
|
|
402
397
|
});
|
|
@@ -434,22 +429,22 @@ function isInterfaceFileUserLand(interfaceFile) {
|
|
|
434
429
|
}
|
|
435
430
|
function getConfigValueSource(configName, interfaceFile, configDef, userRootDir) {
|
|
436
431
|
// TODO: rethink file paths of ConfigElement
|
|
437
|
-
const
|
|
432
|
+
const filePathToShowToUser = interfaceFile.filePath.filePathRelativeToUserRootDir ?? interfaceFile.filePath.filePathAbsolute;
|
|
438
433
|
const conf = interfaceFile.configMap[configName];
|
|
439
434
|
assert(conf);
|
|
440
435
|
const configEnv = configDef.env;
|
|
441
436
|
const definedAtInfoConfigFile = {
|
|
442
|
-
filePath:
|
|
437
|
+
filePath: filePathToShowToUser,
|
|
443
438
|
fileExportPath: ['default', configName]
|
|
444
439
|
};
|
|
445
440
|
if (configDef._valueIsFilePath) {
|
|
446
441
|
let filePath;
|
|
447
442
|
if (interfaceFile.isConfigFile) {
|
|
448
443
|
const { configValue } = conf;
|
|
449
|
-
const import_ =
|
|
444
|
+
const import_ = resolveImport(configValue, interfaceFile.filePath, userRootDir, configEnv, configName);
|
|
450
445
|
const configDefinedAt = getConfigDefinedAtString(configName, { definedAtInfo: definedAtInfoConfigFile }, true);
|
|
451
446
|
assertUsage(import_, `${configDefinedAt} should be an import`);
|
|
452
|
-
filePath = import_.
|
|
447
|
+
filePath = import_.filePathToShowToUser;
|
|
453
448
|
}
|
|
454
449
|
else {
|
|
455
450
|
assert(interfaceFile.isValueFile);
|
|
@@ -474,17 +469,16 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
|
|
|
474
469
|
if (interfaceFile.isConfigFile) {
|
|
475
470
|
assert('configValue' in conf);
|
|
476
471
|
const { configValue } = conf;
|
|
477
|
-
const import_ =
|
|
472
|
+
const import_ = resolveImport(configValue, interfaceFile.filePath, userRootDir, configEnv, configName);
|
|
478
473
|
if (import_) {
|
|
479
|
-
const {
|
|
480
|
-
assertCodeFileEnv(importFilePath, configEnv, configName);
|
|
474
|
+
const { filePathToShowToUser, fileExportName: exportName } = import_;
|
|
481
475
|
const configValueSource = {
|
|
482
476
|
configEnv,
|
|
483
477
|
valueIsImportedAtRuntime: true,
|
|
484
478
|
isComputed: false,
|
|
485
479
|
definedAtInfo: {
|
|
486
|
-
filePath:
|
|
487
|
-
fileExportPath: [
|
|
480
|
+
filePath: filePathToShowToUser,
|
|
481
|
+
fileExportPath: [exportName]
|
|
488
482
|
}
|
|
489
483
|
};
|
|
490
484
|
return configValueSource;
|
|
@@ -502,16 +496,16 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
|
|
|
502
496
|
}
|
|
503
497
|
else if (interfaceFile.isValueFile) {
|
|
504
498
|
// TODO: rethink file paths of ConfigElement
|
|
505
|
-
const
|
|
506
|
-
const
|
|
499
|
+
const importPath = interfaceFile.filePath.filePathRelativeToUserRootDir ?? interfaceFile.filePath.filePathAbsolute;
|
|
500
|
+
const exportName = configName === interfaceFile.configName ? 'default' : configName;
|
|
507
501
|
const valueAlreadyLoaded = 'configValue' in conf;
|
|
508
502
|
const configValueSource = {
|
|
509
503
|
configEnv,
|
|
510
504
|
valueIsImportedAtRuntime: !valueAlreadyLoaded,
|
|
511
505
|
isComputed: false,
|
|
512
506
|
definedAtInfo: {
|
|
513
|
-
filePath:
|
|
514
|
-
fileExportPath: [
|
|
507
|
+
filePath: importPath,
|
|
508
|
+
fileExportPath: [exportName]
|
|
515
509
|
}
|
|
516
510
|
};
|
|
517
511
|
if (valueAlreadyLoaded) {
|
|
@@ -524,16 +518,17 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
|
|
|
524
518
|
}
|
|
525
519
|
assert(false);
|
|
526
520
|
}
|
|
527
|
-
function
|
|
528
|
-
|
|
529
|
-
|
|
521
|
+
function assertFileEnv(filePathForEnvCheck, configEnv, configName) {
|
|
522
|
+
assertPosixPath(filePathForEnvCheck);
|
|
523
|
+
if (!filesEnv.has(filePathForEnvCheck)) {
|
|
524
|
+
filesEnv.set(filePathForEnvCheck, []);
|
|
530
525
|
}
|
|
531
|
-
const
|
|
532
|
-
|
|
533
|
-
const configDifferentEnv =
|
|
526
|
+
const fileEnv = filesEnv.get(filePathForEnvCheck);
|
|
527
|
+
fileEnv.push({ configEnv, configName });
|
|
528
|
+
const configDifferentEnv = fileEnv.filter((c) => c.configEnv !== configEnv)[0];
|
|
534
529
|
if (configDifferentEnv) {
|
|
535
530
|
assertUsage(false, [
|
|
536
|
-
`${
|
|
531
|
+
`${filePathForEnvCheck} defines the value of configs living in different environments:`,
|
|
537
532
|
...[configDifferentEnv, { configName, configEnv }].map((c) => ` - config ${pc.cyan(c.configName)} which value lives in environment ${pc.cyan(c.configEnv)}`),
|
|
538
533
|
'Defining config values in the same file is allowed only if they live in the same environment, see https://vike.dev/header-file/import-from-same-file'
|
|
539
534
|
].join('\n'));
|
|
@@ -551,53 +546,60 @@ function isDefiningPage(interfaceFiles) {
|
|
|
551
546
|
function isDefiningPageConfig(configName) {
|
|
552
547
|
return ['Page', 'route'].includes(configName);
|
|
553
548
|
}
|
|
554
|
-
function
|
|
549
|
+
function resolveImport(configValue, importerFilePath, userRootDir, configEnv, configName) {
|
|
555
550
|
if (typeof configValue !== 'string')
|
|
556
551
|
return null;
|
|
557
552
|
const importData = parseImportData(configValue);
|
|
558
553
|
if (!importData)
|
|
559
554
|
return null;
|
|
560
|
-
|
|
561
|
-
|
|
555
|
+
const { importPath, exportName } = importData;
|
|
556
|
+
const filePathAbsolute = resolveImportPath(importData, importerFilePath);
|
|
557
|
+
let filePathToShowToUser;
|
|
558
|
+
if (importPath.startsWith('.')) {
|
|
562
559
|
// We need to resolve relative paths into absolute paths. Because the import paths are included in virtual files:
|
|
563
560
|
// ```
|
|
564
561
|
// [vite] Internal server error: Failed to resolve import "./onPageTransitionHooks" from "virtual:vike:pageConfigValuesAll:client:/pages/index". Does the file exist?
|
|
565
562
|
// ```
|
|
566
|
-
|
|
563
|
+
assertImportPath(filePathAbsolute, importData, importerFilePath);
|
|
564
|
+
const filePathRelativeToUserRootDir = resolveImportPath_relativeToUserRootDir(filePathAbsolute, importData, importerFilePath, userRootDir);
|
|
565
|
+
filePathToShowToUser = filePathRelativeToUserRootDir;
|
|
567
566
|
}
|
|
568
567
|
else {
|
|
569
|
-
//
|
|
568
|
+
// importPath can be:
|
|
570
569
|
// - an npm package import
|
|
571
570
|
// - a path alias
|
|
571
|
+
filePathToShowToUser = importPath;
|
|
572
|
+
}
|
|
573
|
+
{
|
|
574
|
+
const filePathForEnvCheck = filePathAbsolute ?? importPath;
|
|
575
|
+
assertFileEnv(filePathForEnvCheck, configEnv, configName);
|
|
572
576
|
}
|
|
573
577
|
return {
|
|
574
|
-
|
|
575
|
-
|
|
578
|
+
filePathToShowToUser,
|
|
579
|
+
fileExportName: exportName
|
|
576
580
|
};
|
|
577
581
|
}
|
|
578
|
-
function
|
|
579
|
-
let importFilePath = resolveImport(importData, configFilePath);
|
|
580
|
-
// Make it a Vite path
|
|
582
|
+
function resolveImportPath_relativeToUserRootDir(filePathAbsolute, importData, configFilePath, userRootDir) {
|
|
581
583
|
assertPosixPath(userRootDir);
|
|
582
|
-
|
|
583
|
-
if (
|
|
584
|
-
|
|
584
|
+
let filePathRelativeToUserRootDir;
|
|
585
|
+
if (filePathAbsolute.startsWith(userRootDir)) {
|
|
586
|
+
filePathRelativeToUserRootDir = getVitePathFromAbsolutePath(filePathAbsolute, userRootDir);
|
|
585
587
|
}
|
|
586
588
|
else {
|
|
587
|
-
assertUsage(false, `${getFilePathToShowToUser(configFilePath)} imports from a relative path ${pc.cyan(importData.
|
|
589
|
+
assertUsage(false, `${getFilePathToShowToUser(configFilePath)} imports from a relative path ${pc.cyan(importData.importPath)} outside of ${userRootDir} which is forbidden: import from a relative path inside ${userRootDir}, or import from a dependency's package.json#exports entry instead`);
|
|
588
590
|
// None of the following works. Seems to be a Vite bug?
|
|
589
591
|
// /*
|
|
590
|
-
// assert(
|
|
591
|
-
//
|
|
592
|
+
// assert(filePathAbsolute.startsWith('/'))
|
|
593
|
+
// filePath = `/@fs${filePathAbsolute}`
|
|
592
594
|
// /*/
|
|
593
|
-
//
|
|
594
|
-
// assert(
|
|
595
|
-
//
|
|
595
|
+
// filePathRelativeToUserRootDir = path.posix.relative(userRootDir, filePathAbsolute)
|
|
596
|
+
// assert(filePathRelativeToUserRootDir.startsWith('../'))
|
|
597
|
+
// filePathRelativeToUserRootDir = '/' + filePathRelativeToUserRootDir
|
|
596
598
|
// //*/
|
|
597
599
|
}
|
|
598
|
-
assertPosixPath(
|
|
599
|
-
assert(
|
|
600
|
-
return
|
|
600
|
+
assertPosixPath(filePathRelativeToUserRootDir);
|
|
601
|
+
assert(filePathRelativeToUserRootDir.startsWith('/'));
|
|
602
|
+
return filePathRelativeToUserRootDir;
|
|
601
603
|
}
|
|
602
604
|
function getVitePathFromAbsolutePath(filePathAbsolute, root) {
|
|
603
605
|
assertPosixPath(filePathAbsolute);
|
|
@@ -709,10 +711,9 @@ function applyEffect(configModFromEffect, configValueEffectSource, configValueSo
|
|
|
709
711
|
function applyComputed(pageConfig, configDefinitionsRelevant) {
|
|
710
712
|
objectEntries(configDefinitionsRelevant).forEach(([configName, configDef]) => {
|
|
711
713
|
var _a;
|
|
712
|
-
|
|
713
|
-
if (!computed)
|
|
714
|
+
if (!configDef._computed)
|
|
714
715
|
return;
|
|
715
|
-
const value =
|
|
716
|
+
const value = configDef._computed(pageConfig);
|
|
716
717
|
if (value === undefined)
|
|
717
718
|
return;
|
|
718
719
|
const configValueSource = {
|
|
@@ -825,10 +826,11 @@ async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir
|
|
|
825
826
|
const extendsImportData = getExtendsImportData(configFileExports, configFilePath);
|
|
826
827
|
const extendsConfigFiles = [];
|
|
827
828
|
extendsImportData.map((importData) => {
|
|
828
|
-
const {
|
|
829
|
+
const { importPath: importPath } = importData;
|
|
829
830
|
// TODO
|
|
830
831
|
// - validate extends configs
|
|
831
|
-
const filePathAbsolute =
|
|
832
|
+
const filePathAbsolute = resolveImportPath(importData, configFilePath);
|
|
833
|
+
assertImportPath(filePathAbsolute, importData, configFilePath);
|
|
832
834
|
assertExtendsImportPath(importPath, filePathAbsolute, configFilePath);
|
|
833
835
|
extendsConfigFiles.push({
|
|
834
836
|
filePathAbsolute,
|
|
@@ -874,7 +876,7 @@ function assertExtendsImportPath(importPath, filePath, configFilePath) {
|
|
|
874
876
|
}
|
|
875
877
|
function getExtendsImportData(configFileExports, configFilePath) {
|
|
876
878
|
const filePathToShowToUser = getFilePathToShowToUser(configFilePath);
|
|
877
|
-
|
|
879
|
+
assertExportsOfConfigFile(configFileExports, filePathToShowToUser);
|
|
878
880
|
const defaultExports = configFileExports.default;
|
|
879
881
|
const wrongUsage = `${filePathToShowToUser} sets the config 'extends' to an invalid value, see https://vike.dev/extends`;
|
|
880
882
|
let extendList;
|
|
@@ -954,13 +956,16 @@ function handleUnknownConfig(configName, configNames, definedByFile) {
|
|
|
954
956
|
else {
|
|
955
957
|
configNameSimilar = getMostSimilar(configName, configNames);
|
|
956
958
|
}
|
|
957
|
-
if (configNameSimilar) {
|
|
959
|
+
if (configNameSimilar || configName === 'page') {
|
|
960
|
+
assert(configNameSimilar);
|
|
958
961
|
assert(configNameSimilar !== configName);
|
|
959
962
|
errMsg += `, did you mean to define ${pc.cyan(configNameSimilar)} instead?`;
|
|
963
|
+
if (configName === 'page') {
|
|
964
|
+
errMsg += ` (The name of the config ${pc.cyan('Page')} starts with a capital letter ${pc.cyan('P')} because it usually defines a UI component: a ubiquitous JavaScript convention is to start the name of UI components with a capital letter.)`;
|
|
965
|
+
}
|
|
960
966
|
}
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
errMsg += ` (The name of the config ${pc.cyan('Page')} starts with a capital letter ${pc.cyan('P')} because it usually defines a UI component: a ubiquitous JavaScript convention is to start the name of UI components with a capital letter.)`;
|
|
967
|
+
else {
|
|
968
|
+
errMsg += `, you need to define the config ${pc.cyan(configName)} by using ${pc.cyan('config.meta')} https://vike.dev/meta`;
|
|
964
969
|
}
|
|
965
970
|
assertUsage(false, errMsg);
|
|
966
971
|
}
|
|
@@ -969,7 +974,7 @@ function determineRouteFilesystem(locationId, configValueSources) {
|
|
|
969
974
|
const configFilesystemRoutingRoot = configValueSources[configName]?.[0];
|
|
970
975
|
let filesystemRouteString = getFilesystemRouteString(locationId);
|
|
971
976
|
if (determineIsErrorPage(filesystemRouteString)) {
|
|
972
|
-
return { isErrorPage: true, routeFilesystem:
|
|
977
|
+
return { isErrorPage: true, routeFilesystem: undefined };
|
|
973
978
|
}
|
|
974
979
|
let filesystemRouteDefinedBy = getFilesystemRouteDefinedBy(locationId); // for log404()
|
|
975
980
|
if (configFilesystemRoutingRoot) {
|
|
@@ -987,7 +992,7 @@ function determineRouteFilesystem(locationId, configValueSources) {
|
|
|
987
992
|
routeString: filesystemRouteString,
|
|
988
993
|
definedBy: filesystemRouteDefinedBy
|
|
989
994
|
};
|
|
990
|
-
return { routeFilesystem, isErrorPage:
|
|
995
|
+
return { routeFilesystem, isErrorPage: undefined };
|
|
991
996
|
}
|
|
992
997
|
function getFilesystemRoutingRootEffect(configFilesystemRoutingRoot, configName) {
|
|
993
998
|
assert(configFilesystemRoutingRoot.configEnv === 'config-only');
|
|
@@ -1007,33 +1012,22 @@ function determineIsErrorPage(routeFilesystem) {
|
|
|
1007
1012
|
assertPosixPath(routeFilesystem);
|
|
1008
1013
|
return routeFilesystem.split('/').includes('_error');
|
|
1009
1014
|
}
|
|
1010
|
-
function
|
|
1011
|
-
const
|
|
1012
|
-
assertPosixPath(
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
importedFile = require_.resolve(importData.importFilePath, { paths: [plusConfigFilDirPathAbsolute] });
|
|
1018
|
-
}
|
|
1019
|
-
catch {
|
|
1020
|
-
importedFile = null;
|
|
1021
|
-
}
|
|
1022
|
-
finally {
|
|
1023
|
-
clean();
|
|
1024
|
-
}
|
|
1025
|
-
assertImport(importedFile, importData, importerFilePath);
|
|
1026
|
-
importedFile = toPosixPath(importedFile);
|
|
1027
|
-
return importedFile;
|
|
1015
|
+
function resolveImportPath(importData, importerFilePath) {
|
|
1016
|
+
const importerFilePathAbsolute = importerFilePath.filePathAbsolute;
|
|
1017
|
+
assertPosixPath(importerFilePathAbsolute);
|
|
1018
|
+
const cwd = path.posix.dirname(importerFilePathAbsolute);
|
|
1019
|
+
// filePathAbsolute is expected to be null when importData.importPath is a Vite path alias
|
|
1020
|
+
const filePathAbsolute = requireResolve(importData.importPath, cwd);
|
|
1021
|
+
return filePathAbsolute;
|
|
1028
1022
|
}
|
|
1029
|
-
function
|
|
1030
|
-
const {
|
|
1023
|
+
function assertImportPath(filePathAbsolute, importData, importerFilePath) {
|
|
1024
|
+
const { importPath: importPath, importStringWasGenerated, importString } = importData;
|
|
1031
1025
|
const filePathToShowToUser = getFilePathToShowToUser(importerFilePath);
|
|
1032
|
-
if (!
|
|
1026
|
+
if (!filePathAbsolute) {
|
|
1033
1027
|
const importPathString = pc.cyan(`'${importPath}'`);
|
|
1034
|
-
const errIntro =
|
|
1028
|
+
const errIntro = importStringWasGenerated
|
|
1035
1029
|
? `The import path ${importPathString} in ${filePathToShowToUser}`
|
|
1036
|
-
: `The import ${pc.cyan(
|
|
1030
|
+
: `The import ${pc.cyan(importString)} defined in ${filePathToShowToUser}`;
|
|
1037
1031
|
const errIntro2 = `${errIntro} couldn't be resolved: does ${importPathString}`;
|
|
1038
1032
|
if (importPath.startsWith('.')) {
|
|
1039
1033
|
assertUsage(false, `${errIntro2} point to an existing file?`);
|
|
@@ -1084,6 +1078,8 @@ function mergeCumulative(configName, configValueSources) {
|
|
|
1084
1078
|
/* This is more confusing than adding value. For example, this explanation shouldn't be shown for the passToClient config.
|
|
1085
1079
|
const explanation = `(Because the values of ${configNameColored} are cumulative and therefore merged together.)` as const
|
|
1086
1080
|
*/
|
|
1081
|
+
// Make sure configValueSource.value is serializable
|
|
1082
|
+
getConfigValueSerialized(configValueSource.value, configName, configValueSource.definedAtInfo);
|
|
1087
1083
|
const assertNoMixing = (isSet) => {
|
|
1088
1084
|
const vals1 = isSet ? valuesSet : valuesArr;
|
|
1089
1085
|
const t1 = isSet ? 'a Set' : 'an array';
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
export { getVirtualFilePageConfigValuesAll };
|
|
2
|
+
export { serializeConfigValueImported };
|
|
3
|
+
import type { ConfigValueSource } from '../../../../../shared/page-configs/PageConfig.js';
|
|
2
4
|
import type { ConfigVikeResolved } from '../../../../../shared/ConfigVike.js';
|
|
3
5
|
declare function getVirtualFilePageConfigValuesAll(id: string, userRootDir: string, isDev: boolean, configVike: ConfigVikeResolved): Promise<string>;
|
|
6
|
+
declare function serializeConfigValueImported(configValueSource: ConfigValueSource, configName: string, whitespace: string, varCounterContainer: {
|
|
7
|
+
varCounter: number;
|
|
8
|
+
}, importStatements: string[]): string[];
|