vike 0.4.143 → 0.4.144-commit-e40e9b1
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 +1 -1
- package/dist/cjs/node/plugin/plugins/config/index.js +1 -1
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +31 -30
- package/dist/cjs/node/plugin/plugins/importUserCode/generateEagerImport.js +19 -8
- package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +19 -10
- package/dist/cjs/node/plugin/plugins/importUserCode/index.js +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.js +6 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +4 -4
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +228 -186
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +11 -35
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +60 -95
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/helpers.js +12 -5
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +18 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/replaceImportStatements.js +25 -25
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.js +14 -13
- package/dist/cjs/node/plugin/shared/findPageFiles.js +2 -1
- package/dist/cjs/node/plugin/shared/{getConfigValueSource.js → getConfigValueSourcesRelevant.js} +1 -12
- package/dist/cjs/node/plugin/shared/loggerNotProd.js +1 -1
- package/dist/cjs/node/plugin/utils.js +2 -3
- package/dist/cjs/node/prerender/runPrerender.js +18 -20
- package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +1 -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/runtime/renderPage/log404/index.js +10 -5
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +3 -2
- package/dist/cjs/node/runtime/renderPage.js +1 -1
- package/dist/cjs/node/shared/getClientEntryFilePath.js +1 -7
- package/dist/cjs/shared/assertPageContextProvidedByUser.js +1 -1
- package/dist/cjs/shared/error-page.js +1 -1
- package/dist/cjs/shared/getPageFiles/getExports.js +8 -11
- package/dist/cjs/shared/getPageFiles/parseGlobResults.js +10 -44
- package/dist/cjs/shared/hooks/getHook.js +3 -1
- package/dist/cjs/shared/page-configs/assertExports.js +60 -0
- package/dist/cjs/shared/page-configs/getExportPath.js +9 -10
- package/dist/cjs/shared/page-configs/loadConfigValues.js +18 -0
- package/dist/cjs/shared/page-configs/serialize/PageConfigSerialized.js +2 -0
- package/dist/cjs/shared/page-configs/serialize/assertPageConfigs.js +19 -0
- package/dist/cjs/shared/page-configs/serialize/parseConfigValuesImported.js +56 -0
- package/dist/cjs/shared/page-configs/serialize/parsePageConfigs.js +65 -0
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValue.js +58 -0
- package/dist/cjs/shared/page-configs/utils.js +65 -42
- package/dist/cjs/shared/route/loadPageRoutes.js +12 -15
- package/dist/cjs/shared/route/resolveRedirects.js +1 -1
- package/dist/cjs/shared/route/resolveRouteFunction.js +1 -0
- package/dist/cjs/shared/utils.js +0 -1
- package/dist/cjs/utils/getOutDirs.js +25 -18
- package/dist/cjs/utils/getValuePrintable.js +1 -1
- package/dist/cjs/utils/objectAssign.js +3 -1
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/cjs/utils/{resolve.js → requireResolve.js} +3 -3
- package/dist/cjs/utils/warnIfErrorIsNotObject.js +1 -1
- 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/useClientRouter.js +3 -3
- 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 +2 -2
- package/dist/esm/node/plugin/plugins/config/index.js +2 -2
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +31 -30
- 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 +20 -11
- package/dist/esm/node/plugin/plugins/importUserCode/index.js +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.d.ts +19 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.js +6 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +5 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +4 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +4 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +229 -187
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +11 -32
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.d.ts +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +60 -95
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/helpers.d.ts +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/helpers.js +12 -5
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.d.ts +7 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +15 -0
- 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 +14 -13
- package/dist/esm/node/plugin/shared/findPageFiles.js +3 -2
- 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.js +2 -2
- package/dist/esm/node/plugin/utils.d.ts +1 -2
- package/dist/esm/node/plugin/utils.js +2 -3
- package/dist/esm/node/prerender/runPrerender.js +20 -22
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +1 -1
- 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/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/log404/index.js +10 -5
- 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/runtime/renderPage/renderPageAlreadyRouted.js +3 -2
- package/dist/esm/node/runtime/renderPage.js +1 -1
- package/dist/esm/node/shared/getClientEntryFilePath.d.ts +2 -2
- package/dist/esm/node/shared/getClientEntryFilePath.js +2 -8
- package/dist/esm/shared/addIs404ToPageProps.d.ts +2 -2
- package/dist/esm/shared/addUrlComputedProps.d.ts +4 -2
- package/dist/esm/shared/assertPageContextProvidedByUser.js +1 -1
- 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/getExports.d.ts +3 -4
- package/dist/esm/shared/getPageFiles/getExports.js +7 -10
- package/dist/esm/shared/getPageFiles/parseGlobResults.d.ts +3 -3
- package/dist/esm/shared/getPageFiles/parseGlobResults.js +9 -43
- package/dist/esm/shared/getPageFiles/setPageFiles.d.ts +3 -3
- package/dist/esm/shared/hooks/getHook.js +3 -1
- package/dist/esm/shared/page-configs/Config.d.ts +201 -14
- package/dist/esm/shared/page-configs/PageConfig.d.ts +80 -73
- 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/getExportPath.d.ts +1 -1
- package/dist/esm/shared/page-configs/getExportPath.js +9 -10
- 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/serialize/PageConfigSerialized.d.ts +32 -0
- package/dist/esm/shared/page-configs/serialize/PageConfigSerialized.js +1 -0
- package/dist/esm/shared/page-configs/serialize/assertPageConfigs.d.ts +5 -0
- package/dist/esm/shared/page-configs/serialize/assertPageConfigs.js +16 -0
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.d.ts +4 -0
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.js +50 -0
- package/dist/esm/shared/page-configs/serialize/parsePageConfigs.d.ts +7 -0
- package/dist/esm/shared/page-configs/serialize/parsePageConfigs.js +62 -0
- package/dist/esm/shared/page-configs/serialize/serializeConfigValue.d.ts +8 -0
- package/dist/esm/shared/page-configs/serialize/serializeConfigValue.js +52 -0
- package/dist/esm/shared/page-configs/utils.d.ts +21 -14
- package/dist/esm/shared/page-configs/utils.js +64 -41
- 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 +13 -16
- package/dist/esm/shared/route/resolveRedirects.js +1 -1
- package/dist/esm/shared/route/resolveRouteFunction.js +1 -0
- package/dist/esm/shared/types.d.ts +8 -6
- package/dist/esm/shared/utils.d.ts +0 -1
- package/dist/esm/shared/utils.js +0 -1
- package/dist/esm/types/index.d.ts +2 -1
- package/dist/esm/utils/getOutDirs.d.ts +0 -2
- package/dist/esm/utils/getOutDirs.js +24 -17
- package/dist/esm/utils/getValuePrintable.js +1 -1
- package/dist/esm/utils/objectAssign.js +3 -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/{resolve.js → requireResolve.js} +2 -2
- package/dist/esm/utils/warnIfErrorIsNotObject.js +1 -1
- package/package.json +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/isConfigEnvMatch.js +0 -13
- package/dist/cjs/shared/getPageFiles/assertPageConfigs.js +0 -19
- package/dist/cjs/shared/page-configs/loadPageCode.js +0 -63
- package/dist/cjs/utils/assertDefaultExport.js +0 -53
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isConfigEnvMatch.d.ts +0 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isConfigEnvMatch.js +0 -10
- package/dist/esm/shared/getPageFiles/assertPageConfigs.d.ts +0 -5
- package/dist/esm/shared/getPageFiles/assertPageConfigs.js +0 -16
- 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/assertDefaultExport.d.ts +0 -8
- package/dist/esm/utils/assertDefaultExport.js +0 -47
- package/dist/esm/utils/resolve.d.ts +0 -2
- /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
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { getVirtualFilePageConfigValuesAll };
|
|
2
2
|
import type { ConfigVikeResolved } from '../../../../../shared/ConfigVike.js';
|
|
3
|
-
declare function getVirtualFilePageConfigValuesAll(id: string, userRootDir: string, isDev: boolean, configVike: ConfigVikeResolved): Promise<string>;
|
|
3
|
+
declare function getVirtualFilePageConfigValuesAll(id: string, userRootDir: string, outDirRoot: string, isDev: boolean, configVike: ConfigVikeResolved): Promise<string>;
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
export { getVirtualFilePageConfigValuesAll };
|
|
2
|
-
import { assert
|
|
3
|
-
import { generateEagerImport } from '../generateEagerImport.js';
|
|
2
|
+
import { assert } from '../../../utils.js';
|
|
4
3
|
import { getVirtualFileIdPageConfigValuesAll, isVirtualFileIdPageConfigValuesAll } from '../../../../shared/virtual-files/virtualFilePageConfigValuesAll.js';
|
|
5
4
|
import { getVikeConfig } from './getVikeConfig.js';
|
|
6
5
|
import { extractAssetsAddQuery } from '../../../../shared/extractAssetsQuery.js';
|
|
7
6
|
import { debug } from './debug.js';
|
|
8
|
-
import path from 'path';
|
|
9
7
|
import { getConfigValue } from '../../../../../shared/page-configs/utils.js';
|
|
10
|
-
import { getConfigValueSourcesRelevant } from '../../../shared/
|
|
11
|
-
import {
|
|
12
|
-
|
|
8
|
+
import { getConfigValueSourcesRelevant } from '../../../shared/getConfigValueSourcesRelevant.js';
|
|
9
|
+
import { isRuntimeEnvMatch } from './isRuntimeEnvMatch.js';
|
|
10
|
+
import { serializeConfigValueImported } from '../../../../../shared/page-configs/serialize/serializeConfigValue.js';
|
|
11
|
+
async function getVirtualFilePageConfigValuesAll(id, userRootDir, outDirRoot, isDev, configVike) {
|
|
13
12
|
const result = isVirtualFileIdPageConfigValuesAll(id);
|
|
14
13
|
assert(result);
|
|
15
14
|
/* This assertion fails when using includeAssetsImportedByServer
|
|
@@ -19,7 +18,7 @@ async function getVirtualFilePageConfigValuesAll(id, userRootDir, isDev, configV
|
|
|
19
18
|
}
|
|
20
19
|
*/
|
|
21
20
|
const { pageId, isForClientSide } = result;
|
|
22
|
-
const { pageConfigs } = await getVikeConfig(userRootDir, isDev, configVike.extensions, true);
|
|
21
|
+
const { pageConfigs } = await getVikeConfig(userRootDir, outDirRoot, isDev, configVike.extensions, true);
|
|
23
22
|
const pageConfig = pageConfigs.find((pageConfig) => pageConfig.pageId === pageId);
|
|
24
23
|
assert(pageConfig);
|
|
25
24
|
const code = getLoadConfigValuesAll(pageConfig, isForClientSide, pageId, configVike.includeAssetsImportedByServer, isDev);
|
|
@@ -32,37 +31,17 @@ function getLoadConfigValuesAll(pageConfig, isForClientSide, pageId, includeAsse
|
|
|
32
31
|
const lines = [];
|
|
33
32
|
const importStatements = [];
|
|
34
33
|
lines.push('export default [');
|
|
35
|
-
|
|
34
|
+
const varCounterContainer = { varCounter: 0 };
|
|
36
35
|
getConfigValueSourcesRelevant(pageConfig).forEach((configValueSource) => {
|
|
37
|
-
const { valueIsImportedAtRuntime,
|
|
36
|
+
const { valueIsImportedAtRuntime, configEnv, configName } = configValueSource;
|
|
38
37
|
if (!valueIsImportedAtRuntime)
|
|
39
38
|
return;
|
|
40
39
|
if (configValueSource.valueIsFilePath)
|
|
41
40
|
return;
|
|
42
|
-
if (!
|
|
41
|
+
if (!isRuntimeEnvMatch(configEnv, { isForClientSide, isClientRouting, isEager: false }))
|
|
43
42
|
return;
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
const fileName = path.posix.basename(filePath);
|
|
47
|
-
const isPlusFile = fileName.startsWith('+');
|
|
48
|
-
const fileExportName = fileExportPath[0];
|
|
49
|
-
assert(!configValueSource.valueIsFilePath);
|
|
50
|
-
assert(fileExportName);
|
|
51
|
-
const { importVar, importStatement } = generateEagerImport(filePath, varCounter++, isPlusFile ? undefined : fileExportName);
|
|
52
|
-
importStatements.push(importStatement);
|
|
53
|
-
lines.push(` {`);
|
|
54
|
-
lines.push(` configName: '${configName}',`);
|
|
55
|
-
lines.push(` importFilePath: '${filePath}',`);
|
|
56
|
-
lines.push(` isPlusFile: ${JSON.stringify(isPlusFile)},`);
|
|
57
|
-
if (isPlusFile) {
|
|
58
|
-
lines.push(` importFileExports: ${importVar},`);
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
lines.push(` importFileExportValue: ${importVar},`);
|
|
62
|
-
assert(fileExportName);
|
|
63
|
-
lines.push(` importFileExportName: ${JSON.stringify(fileExportName)},`);
|
|
64
|
-
}
|
|
65
|
-
lines.push(` },`);
|
|
43
|
+
const whitespace = ' ';
|
|
44
|
+
lines.push(...serializeConfigValueImported(configValueSource, configName, whitespace, varCounterContainer, importStatements));
|
|
66
45
|
});
|
|
67
46
|
lines.push('];');
|
|
68
47
|
if (includeAssetsImportedByServer && isForClientSide && !isDev) {
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { getVirtualFilePageConfigs };
|
|
2
2
|
export { getConfigValueSerialized };
|
|
3
|
-
import type {
|
|
3
|
+
import type { DefinedAt } from '../../../../../shared/page-configs/PageConfig.js';
|
|
4
4
|
import type { ConfigVikeResolved } from '../../../../../shared/ConfigVike.js';
|
|
5
|
-
declare function getVirtualFilePageConfigs(userRootDir: string, isForClientSide: boolean, isDev: boolean, id: string, configVike: ConfigVikeResolved, isClientRouting: boolean): Promise<string>;
|
|
6
|
-
declare function getConfigValueSerialized(value: unknown, configName: string,
|
|
5
|
+
declare function getVirtualFilePageConfigs(userRootDir: string, outDirRoot: string, isForClientSide: boolean, isDev: boolean, id: string, configVike: ConfigVikeResolved, isClientRouting: boolean): Promise<string>;
|
|
6
|
+
declare function getConfigValueSerialized(value: unknown, configName: string, definedAt: DefinedAt): string;
|
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
export { getVirtualFilePageConfigs };
|
|
2
2
|
export { getConfigValueSerialized };
|
|
3
3
|
import { assert, assertUsage, getPropAccessNotation, hasProp, objectEntries } from '../../../utils.js';
|
|
4
|
-
import { generateEagerImport } from '../generateEagerImport.js';
|
|
5
4
|
import { getVirtualFileIdPageConfigValuesAll } from '../../../../shared/virtual-files/virtualFilePageConfigValuesAll.js';
|
|
6
5
|
import { debug } from './debug.js';
|
|
7
6
|
import { stringify } from '@brillout/json-serializer/stringify';
|
|
8
7
|
import { getConfigEnv } from './helpers.js';
|
|
9
8
|
import pc from '@brillout/picocolors';
|
|
10
9
|
import { getVikeConfig } from './getVikeConfig.js';
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
import { isRuntimeEnvMatch } from './isRuntimeEnvMatch.js';
|
|
11
|
+
import { getConfigValueFilePathToShowToUser } from '../../../../../shared/page-configs/utils.js';
|
|
12
|
+
import { serializeConfigValue, serializeConfigValueImported } from '../../../../../shared/page-configs/serialize/serializeConfigValue.js';
|
|
13
|
+
async function getVirtualFilePageConfigs(userRootDir, outDirRoot, isForClientSide, isDev, id, configVike, isClientRouting) {
|
|
14
|
+
const { pageConfigs, pageConfigGlobal } = await getVikeConfig(userRootDir, outDirRoot, isDev, configVike.extensions, true);
|
|
14
15
|
return getContent(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, isClientRouting);
|
|
15
16
|
}
|
|
16
17
|
function getContent(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, isClientRouting) {
|
|
17
18
|
const lines = [];
|
|
18
19
|
const importStatements = [];
|
|
19
|
-
|
|
20
|
+
const varCounterContainer = { varCounter: 0 };
|
|
21
|
+
lines.push('export const pageConfigsSerialized = [');
|
|
20
22
|
pageConfigs.forEach((pageConfig) => {
|
|
21
23
|
const { pageId, routeFilesystem, isErrorPage } = pageConfig;
|
|
22
24
|
const virtualFileIdPageConfigValuesAll = getVirtualFileIdPageConfigValuesAll(pageId, isForClientSide);
|
|
@@ -25,133 +27,96 @@ function getContent(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, i
|
|
|
25
27
|
lines.push(` isErrorPage: ${JSON.stringify(isErrorPage)},`);
|
|
26
28
|
lines.push(` routeFilesystem: ${JSON.stringify(routeFilesystem)},`);
|
|
27
29
|
lines.push(` loadConfigValuesAll: async () => (await import(${JSON.stringify(virtualFileIdPageConfigValuesAll)})).default,`);
|
|
28
|
-
lines.push(`
|
|
29
|
-
Object.entries(pageConfig.
|
|
30
|
+
lines.push(` configValuesSerialized: {`);
|
|
31
|
+
Object.entries(pageConfig.configValuesComputed).forEach(([configName, configValuesComputed]) => {
|
|
32
|
+
const { value, configEnv } = configValuesComputed;
|
|
33
|
+
if (!isRuntimeEnvMatch(configEnv, { isForClientSide, isClientRouting, isEager: true }))
|
|
34
|
+
return;
|
|
35
|
+
if (pageConfig.configValueSources[configName])
|
|
36
|
+
return;
|
|
37
|
+
const configValue = pageConfig.configValues[configName];
|
|
38
|
+
assert(configValue);
|
|
39
|
+
const { definedAt } = configValue;
|
|
40
|
+
const valueSerialized = getConfigValueSerialized(value, configName, definedAt);
|
|
41
|
+
serializeConfigValue(lines, configName, { definedAt, valueSerialized });
|
|
42
|
+
});
|
|
43
|
+
Object.entries(pageConfig.configValueSources).forEach(([configName]) => {
|
|
30
44
|
const configValue = pageConfig.configValues[configName];
|
|
31
45
|
if (configValue) {
|
|
32
|
-
const configEnv = getConfigEnv(pageConfig, configName);
|
|
46
|
+
const configEnv = getConfigEnv(pageConfig.configValueSources, configName);
|
|
33
47
|
assert(configEnv, configName);
|
|
34
|
-
|
|
48
|
+
const isEnvMatch = isRuntimeEnvMatch(configEnv, { isForClientSide, isClientRouting, isEager: true });
|
|
49
|
+
if (!isEnvMatch)
|
|
35
50
|
return;
|
|
36
|
-
const { value,
|
|
37
|
-
const valueSerialized = getConfigValueSerialized(value, configName,
|
|
38
|
-
|
|
39
|
-
serializeConfigValue(lines, configName, configValue2);
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
const configValueSource = sources[0];
|
|
43
|
-
assert(configValueSource);
|
|
44
|
-
if (configValueSource.configEnv === '_routing-eager') {
|
|
45
|
-
const { definedAtInfo } = configValueSource;
|
|
46
|
-
assert(!configValueSource.isComputed);
|
|
47
|
-
const { filePath, fileExportPath } = configValueSource.definedAtInfo;
|
|
48
|
-
const [exportName] = fileExportPath;
|
|
49
|
-
assert(exportName);
|
|
50
|
-
const configValueEagerImport = getConfigValueEagerImport(filePath, exportName, importStatements);
|
|
51
|
-
const configValue = { definedAtInfo, value: configValueEagerImport };
|
|
52
|
-
serializeConfigValue(lines, configName, configValue);
|
|
53
|
-
}
|
|
51
|
+
const { value, definedAt } = configValue;
|
|
52
|
+
const valueSerialized = getConfigValueSerialized(value, configName, definedAt);
|
|
53
|
+
serializeConfigValue(lines, configName, { definedAt, valueSerialized });
|
|
54
54
|
}
|
|
55
55
|
});
|
|
56
56
|
lines.push(` },`);
|
|
57
|
+
let whitespace = ' ';
|
|
58
|
+
lines.push(`${whitespace}configValuesImported: [`);
|
|
59
|
+
Object.entries(pageConfig.configValueSources).forEach(([configName, sources]) => {
|
|
60
|
+
const configValue = pageConfig.configValues[configName];
|
|
61
|
+
if (configValue)
|
|
62
|
+
return;
|
|
63
|
+
const configValueSource = sources[0];
|
|
64
|
+
assert(configValueSource);
|
|
65
|
+
if (configValueSource.configEnv !== '_routing-eager')
|
|
66
|
+
return;
|
|
67
|
+
lines.push(...serializeConfigValueImported(configValueSource, configName, whitespace, varCounterContainer, importStatements));
|
|
68
|
+
});
|
|
69
|
+
lines.push(`${whitespace}],`);
|
|
70
|
+
// pageConfig end
|
|
57
71
|
lines.push(` },`);
|
|
58
72
|
});
|
|
59
73
|
lines.push('];');
|
|
60
|
-
lines.push('export const
|
|
61
|
-
|
|
74
|
+
lines.push('export const pageConfigGlobalSerialized = {');
|
|
75
|
+
/* Nothing (yet)
|
|
76
|
+
lines.push(` configValuesSerialized: {`)
|
|
77
|
+
lines.push(` },`)
|
|
78
|
+
*/
|
|
79
|
+
lines.push(` configValuesImported: [`);
|
|
80
|
+
objectEntries(pageConfigGlobal.configValueSources).forEach(([configName, sources]) => {
|
|
62
81
|
if (configName === 'onBeforeRoute') {
|
|
63
82
|
// if( isForClientSide && !isClientRouting ) return
|
|
64
83
|
}
|
|
65
84
|
else if (configName === 'onPrerenderStart') {
|
|
66
85
|
if (isDev || isForClientSide) {
|
|
67
86
|
// Only load onPrerenderStart() in server production runtime
|
|
68
|
-
|
|
87
|
+
return;
|
|
69
88
|
}
|
|
70
89
|
}
|
|
71
90
|
else {
|
|
72
91
|
assert(false);
|
|
73
92
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
content = serializeConfigValueSource(configValueSource, configName, whitespace, isForClientSide, isClientRouting, importStatements, true);
|
|
81
|
-
assert(content.startsWith('{') && content.endsWith('},') && content.includes('\n'));
|
|
82
|
-
}
|
|
83
|
-
content = `${whitespace}[${JSON.stringify(configName)}]: ${content}`;
|
|
84
|
-
lines.push(content);
|
|
93
|
+
const configValueSource = sources[0];
|
|
94
|
+
assert(configValueSource);
|
|
95
|
+
const whitespace = ' ';
|
|
96
|
+
lines.push(...serializeConfigValueImported(configValueSource, configName, whitespace, varCounterContainer, importStatements));
|
|
85
97
|
});
|
|
98
|
+
lines.push(` ],`);
|
|
86
99
|
lines.push('};');
|
|
87
100
|
const code = [...importStatements, ...lines].join('\n');
|
|
88
101
|
debug(id, isForClientSide ? 'CLIENT-SIDE' : 'SERVER-SIDE', code);
|
|
89
102
|
return code;
|
|
90
103
|
}
|
|
91
|
-
function
|
|
92
|
-
let whitespace = ' ';
|
|
93
|
-
lines.push(`${whitespace}['${configName}']: {`);
|
|
94
|
-
whitespace += ' ';
|
|
95
|
-
Object.entries(configValue).forEach(([key, val]) => {
|
|
96
|
-
const valSerialized = key === 'value' || key === 'valueSerialized' ? val : JSON.stringify(val);
|
|
97
|
-
lines.push(`${whitespace} ${key}: ${valSerialized},`);
|
|
98
|
-
});
|
|
99
|
-
whitespace = whitespace.slice(2);
|
|
100
|
-
lines.push(`${whitespace}},`);
|
|
101
|
-
}
|
|
102
|
-
function serializeConfigValueSource(configValueSource, configName, whitespace, isForClientSide, isClientRouting, importStatements, isGlobalConfig) {
|
|
103
|
-
assert(!configValueSource.isComputed);
|
|
104
|
-
const { definedAtInfo, configEnv } = configValueSource;
|
|
105
|
-
const lines = [];
|
|
106
|
-
lines.push(`{`);
|
|
107
|
-
lines.push(`${whitespace} definedAtInfo: ${JSON.stringify(definedAtInfo)},`);
|
|
108
|
-
lines.push(`${whitespace} configEnv: ${JSON.stringify(configEnv)},`);
|
|
109
|
-
const eager = configValueSource.configEnv === '_routing-eager' || isGlobalConfig;
|
|
110
|
-
if (isConfigEnvMatch(configEnv, isForClientSide, isClientRouting) || eager) {
|
|
111
|
-
if ('value' in configValueSource) {
|
|
112
|
-
const { value } = configValueSource;
|
|
113
|
-
const valueSerialized = getConfigValueSerialized(value, configName, definedAtInfo);
|
|
114
|
-
lines.push(`${whitespace} valueSerialized: ${valueSerialized}`);
|
|
115
|
-
}
|
|
116
|
-
else if (eager) {
|
|
117
|
-
const { filePath, fileExportPath } = configValueSource.definedAtInfo;
|
|
118
|
-
const [exportName] = fileExportPath;
|
|
119
|
-
assert(exportName);
|
|
120
|
-
const configValueEagerImport = getConfigValueEagerImport(filePath, exportName, importStatements);
|
|
121
|
-
lines.push(`${whitespace} value: ${configValueEagerImport},`);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
lines.push(`${whitespace}},`);
|
|
125
|
-
return lines.join('\n');
|
|
126
|
-
}
|
|
127
|
-
function getConfigValueSerialized(value, configName, definedAtInfo) {
|
|
128
|
-
let configValueSerialized;
|
|
104
|
+
function getConfigValueSerialized(value, configName, definedAt) {
|
|
129
105
|
const valueName = `config${getPropAccessNotation(configName)}`;
|
|
106
|
+
let configValueSerialized;
|
|
130
107
|
try {
|
|
131
108
|
configValueSerialized = stringify(value, { valueName });
|
|
132
109
|
}
|
|
133
110
|
catch (err) {
|
|
134
111
|
assert(hasProp(err, 'messageCore', 'string'));
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
// - cumulative => the values are already ensured to be serializable
|
|
138
|
-
assert(definedAtInfo);
|
|
139
|
-
const configDefinedByFile = definedAtInfo.filePath;
|
|
140
|
-
assert(configDefinedByFile);
|
|
112
|
+
const configValueFilePathToShowToUser = getConfigValueFilePathToShowToUser({ definedAt });
|
|
113
|
+
assert(configValueFilePathToShowToUser);
|
|
141
114
|
assertUsage(false, [
|
|
142
|
-
`The value of the config ${pc.cyan(configName)} cannot be defined inside the file ${
|
|
143
|
-
`its value must be defined in an another file and then imported by ${
|
|
115
|
+
`The value of the config ${pc.cyan(configName)} cannot be defined inside the file ${configValueFilePathToShowToUser}:`,
|
|
116
|
+
`its value must be defined in an another file and then imported by ${configValueFilePathToShowToUser}. (Because the value isn't serializable: ${err.messageCore}.)`,
|
|
144
117
|
`Only serializable config values can be defined inside +config.h.js files, see https://vike.dev/header-file.`
|
|
145
118
|
].join(' '));
|
|
146
119
|
}
|
|
147
120
|
configValueSerialized = JSON.stringify(configValueSerialized);
|
|
148
121
|
return configValueSerialized;
|
|
149
122
|
}
|
|
150
|
-
function getConfigValueEagerImport(importFilePath, exportName, importStatements) {
|
|
151
|
-
let configValueEagerImport;
|
|
152
|
-
const { importVar, importStatement } = generateEagerImport(importFilePath);
|
|
153
|
-
importStatements.push(importStatement);
|
|
154
|
-
// TODO: expose all exports so that assertDefaultExport can be applied
|
|
155
|
-
configValueEagerImport = `${importVar}[${JSON.stringify(exportName)}]`;
|
|
156
|
-
return configValueEagerImport;
|
|
157
|
-
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { getConfigEnv };
|
|
2
2
|
export { isConfigSet };
|
|
3
|
-
import type { ConfigEnvInternal,
|
|
4
|
-
declare function getConfigEnv(
|
|
5
|
-
declare function isConfigSet(
|
|
3
|
+
import type { ConfigEnvInternal, ConfigValueSources } from '../../../../../shared/page-configs/PageConfig.js';
|
|
4
|
+
declare function getConfigEnv(configValueSources: ConfigValueSources, configName: string): null | ConfigEnvInternal;
|
|
5
|
+
declare function isConfigSet(configValueSources: ConfigValueSources, configName: string): boolean;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
export { getConfigEnv };
|
|
2
2
|
export { isConfigSet };
|
|
3
|
-
import { getConfigValueSource } from '../../../shared/getConfigValueSource.js';
|
|
4
3
|
import { assert, assertIsNotProductionRuntime } from '../../../utils.js';
|
|
5
4
|
assertIsNotProductionRuntime();
|
|
6
|
-
function getConfigEnv(
|
|
7
|
-
const configValueSource = getConfigValueSource(
|
|
5
|
+
function getConfigEnv(configValueSources, configName) {
|
|
6
|
+
const configValueSource = getConfigValueSource(configValueSources, configName);
|
|
8
7
|
if (!configValueSource)
|
|
9
8
|
return null;
|
|
10
9
|
if (configValueSource) {
|
|
@@ -22,10 +21,18 @@ function getConfigEnv(pageConfig, configName) {
|
|
|
22
21
|
*/
|
|
23
22
|
}
|
|
24
23
|
}
|
|
25
|
-
function isConfigSet(
|
|
26
|
-
const configValueSource = getConfigValueSource(
|
|
24
|
+
function isConfigSet(configValueSources, configName) {
|
|
25
|
+
const configValueSource = getConfigValueSource(configValueSources, configName);
|
|
27
26
|
// Enable users to suppress global config values by overriding the config's value to null
|
|
28
27
|
if (configValueSource?.value === null)
|
|
29
28
|
return false;
|
|
30
29
|
return !!configValueSource;
|
|
31
30
|
}
|
|
31
|
+
function getConfigValueSource(configValueSources, configName) {
|
|
32
|
+
const sources = configValueSources[configName];
|
|
33
|
+
if (!sources)
|
|
34
|
+
return null;
|
|
35
|
+
const configValueSource = sources[0];
|
|
36
|
+
assert(configValueSource);
|
|
37
|
+
return configValueSource;
|
|
38
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { isRuntimeEnvMatch };
|
|
2
|
+
import type { ConfigEnvInternal } from '../../../../../shared/page-configs/PageConfig.js';
|
|
3
|
+
declare function isRuntimeEnvMatch(configEnv: ConfigEnvInternal, runtime: {
|
|
4
|
+
isForClientSide: boolean;
|
|
5
|
+
isClientRouting: boolean;
|
|
6
|
+
isEager: boolean;
|
|
7
|
+
}): boolean;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { isRuntimeEnvMatch };
|
|
2
|
+
function isRuntimeEnvMatch(configEnv, runtime) {
|
|
3
|
+
const { isForClientSide, isClientRouting, isEager } = runtime;
|
|
4
|
+
if (configEnv === 'config-only')
|
|
5
|
+
return false;
|
|
6
|
+
if (configEnv === (isForClientSide ? 'server-only' : 'client-only'))
|
|
7
|
+
return false;
|
|
8
|
+
if (configEnv === '_routing-eager' || configEnv === '_routing-lazy') {
|
|
9
|
+
if (isForClientSide && !isClientRouting)
|
|
10
|
+
return false;
|
|
11
|
+
if (isEager !== (configEnv === '_routing-eager'))
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
@@ -5,7 +5,7 @@ export type { FileImport };
|
|
|
5
5
|
export type { ImportData };
|
|
6
6
|
type FileImport = {
|
|
7
7
|
importStatementCode: string;
|
|
8
|
-
|
|
8
|
+
importString: string;
|
|
9
9
|
importLocalName: string;
|
|
10
10
|
};
|
|
11
11
|
declare function replaceImportStatements(code: string, filePathToShowToUser: string): {
|
|
@@ -15,14 +15,26 @@ declare function replaceImportStatements(code: string, filePathToShowToUser: str
|
|
|
15
15
|
code: string;
|
|
16
16
|
fileImports: FileImport[];
|
|
17
17
|
};
|
|
18
|
+
/**
|
|
19
|
+
* Data Structure holding info about import statement:
|
|
20
|
+
* `import { someExport as someImport } from './some-file'`
|
|
21
|
+
* <=>
|
|
22
|
+
* `importData === {`
|
|
23
|
+
* `importPath: './some-file',`
|
|
24
|
+
* `exportName: 'someExport',`
|
|
25
|
+
* `importString: 'import:./some-file:someExport',`
|
|
26
|
+
* `importStringWasGenerated: true,`
|
|
27
|
+
* `}`
|
|
28
|
+
* We discard the import name `someImport` because we don't need it.
|
|
29
|
+
*/
|
|
18
30
|
type ImportData = {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
31
|
+
importPath: string;
|
|
32
|
+
exportName: string;
|
|
33
|
+
importString: string;
|
|
34
|
+
importStringWasGenerated: boolean;
|
|
23
35
|
};
|
|
24
36
|
declare function isImportData(str: string): boolean;
|
|
25
|
-
declare function parseImportData(
|
|
37
|
+
declare function parseImportData(importString: string): null | ImportData;
|
|
26
38
|
declare module 'estree' {
|
|
27
39
|
interface BaseNodeWithoutComments {
|
|
28
40
|
start: number;
|
|
@@ -14,13 +14,13 @@ function replaceImportStatements(code, filePathToShowToUser) {
|
|
|
14
14
|
imports.forEach((node) => {
|
|
15
15
|
if (node.type !== 'ImportDeclaration')
|
|
16
16
|
return;
|
|
17
|
-
const
|
|
18
|
-
assert(typeof
|
|
17
|
+
const importPath = node.source.value;
|
|
18
|
+
assert(typeof importPath === 'string');
|
|
19
19
|
const { start, end } = node;
|
|
20
20
|
const importStatementCode = code.slice(start, end);
|
|
21
21
|
// No variable imported
|
|
22
22
|
if (node.specifiers.length === 0) {
|
|
23
|
-
const isWarning = !styleFileRE.test(
|
|
23
|
+
const isWarning = !styleFileRE.test(importPath);
|
|
24
24
|
let quote = indent(importStatementCode);
|
|
25
25
|
if (isWarning) {
|
|
26
26
|
quote = pc.cyan(quote);
|
|
@@ -43,7 +43,7 @@ function replaceImportStatements(code, filePathToShowToUser) {
|
|
|
43
43
|
specifier.type === 'ImportDefaultSpecifier' ||
|
|
44
44
|
specifier.type === 'ImportNamespaceSpecifier');
|
|
45
45
|
const importLocalName = specifier.local.name;
|
|
46
|
-
const
|
|
46
|
+
const exportName = (() => {
|
|
47
47
|
if (specifier.type === 'ImportDefaultSpecifier')
|
|
48
48
|
return 'default';
|
|
49
49
|
if (specifier.type === 'ImportNamespaceSpecifier')
|
|
@@ -55,11 +55,11 @@ function replaceImportStatements(code, filePathToShowToUser) {
|
|
|
55
55
|
}
|
|
56
56
|
return importLocalName;
|
|
57
57
|
})();
|
|
58
|
-
const
|
|
59
|
-
replacement += `const ${importLocalName} = '${
|
|
58
|
+
const importString = serializeImportData({ importPath, exportName, importStringWasGenerated: true });
|
|
59
|
+
replacement += `const ${importLocalName} = '${importString}';`;
|
|
60
60
|
fileImports.push({
|
|
61
61
|
importStatementCode,
|
|
62
|
-
|
|
62
|
+
importString,
|
|
63
63
|
importLocalName
|
|
64
64
|
});
|
|
65
65
|
});
|
|
@@ -88,34 +88,34 @@ function getImports(code) {
|
|
|
88
88
|
const import_ = 'import';
|
|
89
89
|
const SEP = ':';
|
|
90
90
|
const zeroWidthSpace = '\u200b';
|
|
91
|
-
function serializeImportData({
|
|
92
|
-
const tag =
|
|
93
|
-
// `import:${
|
|
94
|
-
return `${tag}${import_}${SEP}${
|
|
91
|
+
function serializeImportData({ importPath, exportName, importStringWasGenerated }) {
|
|
92
|
+
const tag = importStringWasGenerated ? zeroWidthSpace : '';
|
|
93
|
+
// `import:${importPath}:${importPath}`
|
|
94
|
+
return `${tag}${import_}${SEP}${importPath}${SEP}${exportName}`;
|
|
95
95
|
}
|
|
96
96
|
function isImportData(str) {
|
|
97
97
|
return str.startsWith(import_ + SEP) || str.startsWith(zeroWidthSpace + import_ + SEP);
|
|
98
98
|
}
|
|
99
|
-
function parseImportData(
|
|
100
|
-
if (!isImportData(
|
|
99
|
+
function parseImportData(importString) {
|
|
100
|
+
if (!isImportData(importString)) {
|
|
101
101
|
return null;
|
|
102
102
|
}
|
|
103
|
-
let
|
|
104
|
-
if (
|
|
105
|
-
|
|
103
|
+
let importStringWasGenerated = false;
|
|
104
|
+
if (importString.startsWith(zeroWidthSpace)) {
|
|
105
|
+
importStringWasGenerated = true;
|
|
106
106
|
assert(zeroWidthSpace.length === 1);
|
|
107
|
-
|
|
107
|
+
importString = importString.slice(1);
|
|
108
108
|
}
|
|
109
|
-
const parts =
|
|
110
|
-
if (!
|
|
111
|
-
const
|
|
112
|
-
const
|
|
113
|
-
return {
|
|
109
|
+
const parts = importString.split(SEP).slice(1);
|
|
110
|
+
if (!importStringWasGenerated && parts.length === 1) {
|
|
111
|
+
const exportName = 'default';
|
|
112
|
+
const importPath = parts[0];
|
|
113
|
+
return { importPath, exportName, importStringWasGenerated, importString };
|
|
114
114
|
}
|
|
115
115
|
assert(parts.length >= 2);
|
|
116
|
-
const
|
|
117
|
-
const
|
|
118
|
-
return {
|
|
116
|
+
const exportName = parts[parts.length - 1];
|
|
117
|
+
const importPath = parts.slice(0, -1).join(SEP);
|
|
118
|
+
return { importPath, exportName, importStringWasGenerated, importString };
|
|
119
119
|
}
|
|
120
120
|
function spliceMany(str, operations) {
|
|
121
121
|
let strMod = '';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { transpileAndExecuteFile };
|
|
2
2
|
export { getConfigBuildErrorFormatted };
|
|
3
|
-
export {
|
|
3
|
+
export { getConfigExecutionErrorIntroMsg as getConfigExecutionErrorIntroMsg };
|
|
4
4
|
export { isTmpFile };
|
|
5
5
|
import 'source-map-support/register.js';
|
|
6
6
|
import { type FilePath } from './getFilePathToShowToUser.js';
|
|
@@ -8,5 +8,5 @@ declare function transpileAndExecuteFile(filePath: FilePath, isValueFile: boolea
|
|
|
8
8
|
fileExports: Record<string, unknown>;
|
|
9
9
|
}>;
|
|
10
10
|
declare function getConfigBuildErrorFormatted(err: unknown): null | string;
|
|
11
|
-
declare function
|
|
11
|
+
declare function getConfigExecutionErrorIntroMsg(err: unknown): string | null;
|
|
12
12
|
declare function isTmpFile(filePath: string): boolean;
|
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
export { transpileAndExecuteFile };
|
|
2
2
|
export { getConfigBuildErrorFormatted };
|
|
3
|
-
export {
|
|
3
|
+
export { getConfigExecutionErrorIntroMsg as getConfigExecutionErrorIntroMsg };
|
|
4
4
|
export { isTmpFile };
|
|
5
5
|
import { build, formatMessages } from 'esbuild';
|
|
6
6
|
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,
|
|
10
|
+
import { assertPosixPath, getRandomId, assertIsNotProductionRuntime, assert, unique, assertWarning, isObject, toPosixPath, assertUsage } from '../../../utils.js';
|
|
11
11
|
import { isImportData, replaceImportStatements } from './replaceImportStatements.js';
|
|
12
12
|
import { vikeConfigDependencies } from './getVikeConfig.js';
|
|
13
13
|
import 'source-map-support/register.js';
|
|
14
14
|
import { getFilePathToShowToUser } from './getFilePathToShowToUser.js';
|
|
15
|
+
import { assertExportsOfConfigFile } from '../../../../../shared/page-configs/assertExports.js';
|
|
15
16
|
assertIsNotProductionRuntime();
|
|
16
17
|
async function transpileAndExecuteFile(filePath, isValueFile, userRootDir) {
|
|
17
18
|
const { code, fileImports } = await transpileFile(filePath, isValueFile, userRootDir);
|
|
18
|
-
const { fileExports } = await executeFile(filePath, code, fileImports);
|
|
19
|
+
const { fileExports } = await executeFile(filePath, code, fileImports, isValueFile);
|
|
19
20
|
return { fileExports };
|
|
20
21
|
}
|
|
21
22
|
async function transpileFile(filePath, isValueFile, userRootDir) {
|
|
@@ -132,7 +133,7 @@ async function transpileWithEsbuild(filePath, bundle, userRootDir) {
|
|
|
132
133
|
assert(typeof code === 'string');
|
|
133
134
|
return code;
|
|
134
135
|
}
|
|
135
|
-
async function executeFile(filePath, code, fileImports) {
|
|
136
|
+
async function executeFile(filePath, code, fileImports, isValueFile) {
|
|
136
137
|
const { filePathAbsolute, filePathRelativeToUserRootDir } = filePath;
|
|
137
138
|
// Alternative to using a temporary file: https://github.com/vitejs/vite/pull/13269
|
|
138
139
|
// - But seems to break source maps, so I don't think it's worth it
|
|
@@ -157,10 +158,10 @@ async function executeFile(filePath, code, fileImports) {
|
|
|
157
158
|
// - import() returns `[Module: null prototype] { default: { onRenderClient: '...' }}`
|
|
158
159
|
// - We don't need this special object
|
|
159
160
|
fileExports = { ...fileExports };
|
|
160
|
-
if (fileImports) {
|
|
161
|
+
if (fileImports && !isValueFile) {
|
|
161
162
|
assert(filePathRelativeToUserRootDir !== undefined);
|
|
162
|
-
const
|
|
163
|
-
|
|
163
|
+
const filePathToShowToUser = filePathRelativeToUserRootDir ?? filePathAbsolute;
|
|
164
|
+
assertImportsAreReExported(fileImports, fileExports, filePathToShowToUser);
|
|
164
165
|
}
|
|
165
166
|
return { fileExports };
|
|
166
167
|
}
|
|
@@ -185,7 +186,7 @@ async function formatBuildErr(err, filePath) {
|
|
|
185
186
|
err[formatted] = `${msgIntro}\n${msgEsbuild}`;
|
|
186
187
|
}
|
|
187
188
|
const execErrIntroMsg = new WeakMap();
|
|
188
|
-
function
|
|
189
|
+
function getConfigExecutionErrorIntroMsg(err) {
|
|
189
190
|
if (!isObject(err))
|
|
190
191
|
return null;
|
|
191
192
|
const errIntroMsg = execErrIntroMsg.get(err);
|
|
@@ -206,17 +207,17 @@ function isTmpFile(filePath) {
|
|
|
206
207
|
const fileName = path.posix.basename(filePath);
|
|
207
208
|
return fileName.startsWith(tmpPrefix);
|
|
208
209
|
}
|
|
209
|
-
function
|
|
210
|
-
|
|
210
|
+
function assertImportsAreReExported(fileImports, fileExports, filePathToShowToUser) {
|
|
211
|
+
assertExportsOfConfigFile(fileExports, filePathToShowToUser);
|
|
211
212
|
const exportedStrings = getExportedStrings(fileExports.default);
|
|
212
213
|
Object.values(exportedStrings).forEach((exportVal) => {
|
|
213
214
|
if (typeof exportVal !== 'string')
|
|
214
215
|
return;
|
|
215
216
|
if (!isImportData(exportVal))
|
|
216
217
|
return;
|
|
217
|
-
const
|
|
218
|
+
const importString = exportVal;
|
|
218
219
|
fileImports.forEach((fileImport) => {
|
|
219
|
-
if (fileImport.
|
|
220
|
+
if (fileImport.importString === importString) {
|
|
220
221
|
fileImport.isReExported = true;
|
|
221
222
|
}
|
|
222
223
|
});
|
|
@@ -228,7 +229,7 @@ function assertFileImports(fileImports, fileExports, filePath) {
|
|
|
228
229
|
const importNamesUnused = fileImportsUnused.map((fi) => pc.cyan(fi.importLocalName)).join(', ');
|
|
229
230
|
const singular = fileImportsUnused.length === 1;
|
|
230
231
|
assertUsage(fileImportsUnused.length === 0, [
|
|
231
|
-
`${
|
|
232
|
+
`${filePathToShowToUser} imports the following:`,
|
|
232
233
|
...importStatements.map((s) => pc.cyan(` ${s}`)),
|
|
233
234
|
`But the import${singular ? '' : 's'} ${importNamesUnused} ${singular ? "isn't" : "aren't"} re-exported at ${pc.cyan('export default { ... }')} and therefore ${singular ? 'has' : 'have'} no effect, see explanation at https://vike.dev/header-file`
|
|
234
235
|
].join('\n'));
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
export { findPageFiles };
|
|
2
2
|
import glob from 'fast-glob';
|
|
3
|
-
import { assertWarning, toPosixPath, scriptFileExtensions } from '../utils.js';
|
|
3
|
+
import { assertWarning, toPosixPath, scriptFileExtensions, getOutDirs } from '../utils.js';
|
|
4
4
|
import pc from '@brillout/picocolors';
|
|
5
5
|
async function findPageFiles(config, fileTypes, isDev) {
|
|
6
6
|
const cwd = config.root;
|
|
7
|
+
const { outDirRoot } = getOutDirs(config);
|
|
7
8
|
const timeBase = new Date().getTime();
|
|
8
|
-
let pageFiles = await glob(fileTypes.map((fileType) => `**/*${fileType}.${scriptFileExtensions}`), { ignore: ['**/node_modules/**'], cwd, dot: false });
|
|
9
|
+
let pageFiles = await glob(fileTypes.map((fileType) => `**/*${fileType}.${scriptFileExtensions}`), { ignore: ['**/node_modules/**', `${outDirRoot}/**`], cwd, dot: false });
|
|
9
10
|
pageFiles = pageFiles.map((p) => '/' + toPosixPath(p));
|
|
10
11
|
const time = new Date().getTime() - timeBase;
|
|
11
12
|
if (isDev) {
|