vike 0.4.142 → 0.4.143-commit-dc6fea0
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/getFilePathToShowToUser.js +6 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +122 -124
- 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/injectAssets/getHtmlTags.js +1 -1
- 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/runtime/renderPage/log404/index.js +10 -5
- 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 +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 +3 -2
- 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 +123 -125
- 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/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/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/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/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/addUrlComputedProps.d.ts +4 -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 +201 -14
- package/dist/esm/shared/page-configs/PageConfig.d.ts +60 -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 +8 -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 +3 -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,6 +1,6 @@
|
|
|
1
1
|
export { getVirtualFilePageConfigs };
|
|
2
|
+
export { getConfigValueSerialized };
|
|
2
3
|
import { assert, assertUsage, getPropAccessNotation, hasProp, objectEntries } from '../../../utils.js';
|
|
3
|
-
import { generateEagerImport } from '../generateEagerImport.js';
|
|
4
4
|
import { getVirtualFileIdPageConfigValuesAll } from '../../../../shared/virtual-files/virtualFilePageConfigValuesAll.js';
|
|
5
5
|
import { debug } from './debug.js';
|
|
6
6
|
import { stringify } from '@brillout/json-serializer/stringify';
|
|
@@ -8,6 +8,7 @@ import { getConfigEnv } from './helpers.js';
|
|
|
8
8
|
import pc from '@brillout/picocolors';
|
|
9
9
|
import { getVikeConfig } from './getVikeConfig.js';
|
|
10
10
|
import { isConfigEnvMatch } from './isConfigEnvMatch.js';
|
|
11
|
+
import { serializeConfigValueImported } from './getVirtualFilePageConfigValuesAll.js';
|
|
11
12
|
async function getVirtualFilePageConfigs(userRootDir, isForClientSide, isDev, id, configVike, isClientRouting) {
|
|
12
13
|
const { pageConfigs, pageConfigGlobal } = await getVikeConfig(userRootDir, isDev, configVike.extensions, true);
|
|
13
14
|
return getContent(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, isClientRouting);
|
|
@@ -15,7 +16,8 @@ async function getVirtualFilePageConfigs(userRootDir, isForClientSide, isDev, id
|
|
|
15
16
|
function getContent(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, isClientRouting) {
|
|
16
17
|
const lines = [];
|
|
17
18
|
const importStatements = [];
|
|
18
|
-
|
|
19
|
+
const varCounterContainer = { varCounter: 0 };
|
|
20
|
+
lines.push('export const pageConfigsSerialized = [');
|
|
19
21
|
pageConfigs.forEach((pageConfig) => {
|
|
20
22
|
const { pageId, routeFilesystem, isErrorPage } = pageConfig;
|
|
21
23
|
const virtualFileIdPageConfigValuesAll = getVirtualFileIdPageConfigValuesAll(pageId, isForClientSide);
|
|
@@ -24,7 +26,7 @@ function getContent(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, i
|
|
|
24
26
|
lines.push(` isErrorPage: ${JSON.stringify(isErrorPage)},`);
|
|
25
27
|
lines.push(` routeFilesystem: ${JSON.stringify(routeFilesystem)},`);
|
|
26
28
|
lines.push(` loadConfigValuesAll: async () => (await import(${JSON.stringify(virtualFileIdPageConfigValuesAll)})).default,`);
|
|
27
|
-
lines.push(`
|
|
29
|
+
lines.push(` configValuesSerialized: {`);
|
|
28
30
|
Object.entries(pageConfig.configValueSources).forEach(([configName, sources]) => {
|
|
29
31
|
const configValue = pageConfig.configValues[configName];
|
|
30
32
|
if (configValue) {
|
|
@@ -33,101 +35,71 @@ function getContent(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, i
|
|
|
33
35
|
if (!isConfigEnvMatch(configEnv, isForClientSide, isClientRouting))
|
|
34
36
|
return;
|
|
35
37
|
const { value, definedAtInfo } = configValue;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const valueSerialized = JSON.stringify(value);
|
|
39
|
-
serializeConfigValue(lines, configName, { definedAtInfo }, valueSerialized);
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
const configValueSource = sources[0];
|
|
43
|
-
assert(configValueSource);
|
|
44
|
-
if (configValueSource.configEnv === '_routing-eager') {
|
|
45
|
-
const { definedAtInfo } = configValueSource;
|
|
46
|
-
const configValue = { configName, definedAtInfo };
|
|
47
|
-
assert(!configValueSource.isComputed);
|
|
48
|
-
const { filePath, fileExportPath } = configValueSource.definedAtInfo;
|
|
49
|
-
const [exportName] = fileExportPath;
|
|
50
|
-
assert(exportName);
|
|
51
|
-
const configValueEagerImport = getConfigValueEagerImport(filePath, exportName, importStatements);
|
|
52
|
-
serializeConfigValue(lines, configName, configValue, configValueEagerImport);
|
|
53
|
-
}
|
|
38
|
+
const valueSerialized = getConfigValueSerialized(value, configName, definedAtInfo);
|
|
39
|
+
serializeConfigValue(lines, configName, { definedAtInfo, valueSerialized });
|
|
54
40
|
}
|
|
55
41
|
});
|
|
56
42
|
lines.push(` },`);
|
|
43
|
+
let whitespace = ' ';
|
|
44
|
+
lines.push(`${whitespace}configValuesImported: [`);
|
|
45
|
+
Object.entries(pageConfig.configValueSources).forEach(([configName, sources]) => {
|
|
46
|
+
const configValue = pageConfig.configValues[configName];
|
|
47
|
+
if (configValue)
|
|
48
|
+
return;
|
|
49
|
+
const configValueSource = sources[0];
|
|
50
|
+
assert(configValueSource);
|
|
51
|
+
if (configValueSource.configEnv !== '_routing-eager')
|
|
52
|
+
return;
|
|
53
|
+
assert(!configValueSource.isComputed);
|
|
54
|
+
lines.push(...serializeConfigValueImported(configValueSource, configName, whitespace, varCounterContainer, importStatements));
|
|
55
|
+
});
|
|
56
|
+
lines.push(`${whitespace}],`);
|
|
57
|
+
// pageConfig end
|
|
57
58
|
lines.push(` },`);
|
|
58
59
|
});
|
|
59
60
|
lines.push('];');
|
|
60
|
-
lines.push('export const
|
|
61
|
-
|
|
61
|
+
lines.push('export const pageConfigGlobalSerialized = {');
|
|
62
|
+
/* Nothing (yet)
|
|
63
|
+
lines.push(` configValuesSerialized: {`)
|
|
64
|
+
lines.push(` },`)
|
|
65
|
+
*/
|
|
66
|
+
lines.push(` configValuesImported: [`);
|
|
67
|
+
objectEntries(pageConfigGlobal.configValueSources).forEach(([configName, sources]) => {
|
|
62
68
|
if (configName === 'onBeforeRoute') {
|
|
63
69
|
// if( isForClientSide && !isClientRouting ) return
|
|
64
70
|
}
|
|
65
71
|
else if (configName === 'onPrerenderStart') {
|
|
66
72
|
if (isDev || isForClientSide) {
|
|
67
73
|
// Only load onPrerenderStart() in server production runtime
|
|
68
|
-
|
|
74
|
+
return;
|
|
69
75
|
}
|
|
70
76
|
}
|
|
71
77
|
else {
|
|
72
78
|
assert(false);
|
|
73
79
|
}
|
|
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);
|
|
80
|
+
const configValueSource = sources[0];
|
|
81
|
+
assert(configValueSource);
|
|
82
|
+
const whitespace = ' ';
|
|
83
|
+
lines.push(...serializeConfigValueImported(configValueSource, configName, whitespace, varCounterContainer, importStatements));
|
|
85
84
|
});
|
|
85
|
+
lines.push(` ],`);
|
|
86
86
|
lines.push('};');
|
|
87
87
|
const code = [...importStatements, ...lines].join('\n');
|
|
88
88
|
debug(id, isForClientSide ? 'CLIENT-SIDE' : 'SERVER-SIDE', code);
|
|
89
89
|
return code;
|
|
90
90
|
}
|
|
91
|
-
function serializeConfigValue(lines, configName,
|
|
91
|
+
function serializeConfigValue(lines, configName, configValueSerialized) {
|
|
92
92
|
let whitespace = ' ';
|
|
93
93
|
lines.push(`${whitespace}['${configName}']: {`);
|
|
94
94
|
whitespace += ' ';
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
return;
|
|
99
|
-
// if (val === undefined) return
|
|
100
|
-
lines.push(`${whitespace} ${key}: ${JSON.stringify(val)},`);
|
|
95
|
+
Object.entries(configValueSerialized).forEach(([key, val]) => {
|
|
96
|
+
const valSerialized = key === 'definedAtInfo' ? JSON.stringify(val) : val;
|
|
97
|
+
lines.push(`${whitespace} ${key}: ${valSerialized},`);
|
|
101
98
|
});
|
|
102
99
|
whitespace = whitespace.slice(2);
|
|
103
100
|
lines.push(`${whitespace}},`);
|
|
104
101
|
}
|
|
105
|
-
function
|
|
106
|
-
assert(!configValueSource.isComputed);
|
|
107
|
-
const { definedAtInfo, configEnv } = configValueSource;
|
|
108
|
-
const lines = [];
|
|
109
|
-
lines.push(`{`);
|
|
110
|
-
lines.push(`${whitespace} definedAtInfo: ${JSON.stringify(definedAtInfo)},`);
|
|
111
|
-
lines.push(`${whitespace} configEnv: ${JSON.stringify(configEnv)},`);
|
|
112
|
-
const eager = configValueSource.configEnv === '_routing-eager' || isGlobalConfig;
|
|
113
|
-
if (isConfigEnvMatch(configEnv, isForClientSide, isClientRouting) || eager) {
|
|
114
|
-
if ('value' in configValueSource) {
|
|
115
|
-
const { value } = configValueSource;
|
|
116
|
-
const valueSerialized = getConfigValueSerialized(value, configName, definedAtInfo.filePath);
|
|
117
|
-
lines.push(`${whitespace} valueSerialized: ${valueSerialized}`);
|
|
118
|
-
}
|
|
119
|
-
else if (eager) {
|
|
120
|
-
const { filePath, fileExportPath } = configValueSource.definedAtInfo;
|
|
121
|
-
const [exportName] = fileExportPath;
|
|
122
|
-
assert(exportName);
|
|
123
|
-
const configValueEagerImport = getConfigValueEagerImport(filePath, exportName, importStatements);
|
|
124
|
-
lines.push(`${whitespace} value: ${configValueEagerImport},`);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
lines.push(`${whitespace}},`);
|
|
128
|
-
return lines.join('\n');
|
|
129
|
-
}
|
|
130
|
-
function getConfigValueSerialized(value, configName, configDefinedByFile) {
|
|
102
|
+
function getConfigValueSerialized(value, configName, definedAtInfo) {
|
|
131
103
|
let configValueSerialized;
|
|
132
104
|
const valueName = `config${getPropAccessNotation(configName)}`;
|
|
133
105
|
try {
|
|
@@ -135,20 +107,18 @@ function getConfigValueSerialized(value, configName, configDefinedByFile) {
|
|
|
135
107
|
}
|
|
136
108
|
catch (err) {
|
|
137
109
|
assert(hasProp(err, 'messageCore', 'string'));
|
|
110
|
+
// definedAtInfo is null when config value is:
|
|
111
|
+
// - computed => all computed values defined by Vike can are serializable
|
|
112
|
+
// - cumulative => the values are already ensured to be serializable
|
|
113
|
+
assert(definedAtInfo);
|
|
114
|
+
const configDefinedByFile = definedAtInfo.filePath;
|
|
115
|
+
assert(configDefinedByFile);
|
|
138
116
|
assertUsage(false, [
|
|
139
|
-
`The value of the config ${pc.cyan(configName)} cannot be defined inside the file ${configDefinedByFile}
|
|
140
|
-
`
|
|
141
|
-
`Only serializable config values can be defined inside
|
|
117
|
+
`The value of the config ${pc.cyan(configName)} cannot be defined inside the file ${configDefinedByFile}:`,
|
|
118
|
+
`its value must be defined in an another file and then imported by ${configDefinedByFile}. (Because the value isn't serializable: ${err.messageCore}.)`,
|
|
119
|
+
`Only serializable config values can be defined inside +config.h.js files, see https://vike.dev/header-file.`
|
|
142
120
|
].join(' '));
|
|
143
121
|
}
|
|
144
122
|
configValueSerialized = JSON.stringify(configValueSerialized);
|
|
145
123
|
return configValueSerialized;
|
|
146
124
|
}
|
|
147
|
-
function getConfigValueEagerImport(importFilePath, exportName, importStatements) {
|
|
148
|
-
let configValueEagerImport;
|
|
149
|
-
const { importVar, importStatement } = generateEagerImport(importFilePath);
|
|
150
|
-
importStatements.push(importStatement);
|
|
151
|
-
// TODO: expose all exports so that assertDefaultExport can be applied
|
|
152
|
-
configValueEagerImport = `${importVar}[${JSON.stringify(exportName)}]`;
|
|
153
|
-
return configValueEagerImport;
|
|
154
|
-
}
|
|
@@ -1,6 +1,5 @@
|
|
|
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
5
|
function getConfigEnv(pageConfig, configName) {
|
|
@@ -29,3 +28,13 @@ function isConfigSet(pageConfig, configName) {
|
|
|
29
28
|
return false;
|
|
30
29
|
return !!configValueSource;
|
|
31
30
|
}
|
|
31
|
+
function getConfigValueSource(pageConfig, configName) {
|
|
32
|
+
// Doesn't exist on the client-side, but we are on the server-side as attested by assertIsNotBrowser()
|
|
33
|
+
assert(pageConfig.configValueSources);
|
|
34
|
+
const sources = pageConfig.configValueSources[configName];
|
|
35
|
+
if (!sources)
|
|
36
|
+
return null;
|
|
37
|
+
const configValueSource = sources[0];
|
|
38
|
+
assert(configValueSource);
|
|
39
|
+
return configValueSource;
|
|
40
|
+
}
|
|
@@ -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) {
|
|
@@ -52,7 +53,9 @@ function transpileImports(codeOriginal, filePath, isValueFile) {
|
|
|
52
53
|
const { code, fileImports } = res;
|
|
53
54
|
if (!isHeader) {
|
|
54
55
|
const filePathCorrect = appendHeaderFileExtension(filePathToShowToUser);
|
|
55
|
-
assertWarning(false, `Rename ${filePathToShowToUser} to ${filePathCorrect}, see https://vike.dev/header-file`, {
|
|
56
|
+
assertWarning(false, `Rename ${filePathToShowToUser} to ${filePathCorrect}, see https://vike.dev/header-file`, {
|
|
57
|
+
onlyOnce: true
|
|
58
|
+
});
|
|
56
59
|
}
|
|
57
60
|
return { code, fileImports };
|
|
58
61
|
}
|
|
@@ -130,7 +133,7 @@ async function transpileWithEsbuild(filePath, bundle, userRootDir) {
|
|
|
130
133
|
assert(typeof code === 'string');
|
|
131
134
|
return code;
|
|
132
135
|
}
|
|
133
|
-
async function executeFile(filePath, code, fileImports) {
|
|
136
|
+
async function executeFile(filePath, code, fileImports, isValueFile) {
|
|
134
137
|
const { filePathAbsolute, filePathRelativeToUserRootDir } = filePath;
|
|
135
138
|
// Alternative to using a temporary file: https://github.com/vitejs/vite/pull/13269
|
|
136
139
|
// - But seems to break source maps, so I don't think it's worth it
|
|
@@ -155,10 +158,10 @@ async function executeFile(filePath, code, fileImports) {
|
|
|
155
158
|
// - import() returns `[Module: null prototype] { default: { onRenderClient: '...' }}`
|
|
156
159
|
// - We don't need this special object
|
|
157
160
|
fileExports = { ...fileExports };
|
|
158
|
-
if (fileImports) {
|
|
161
|
+
if (fileImports && !isValueFile) {
|
|
159
162
|
assert(filePathRelativeToUserRootDir !== undefined);
|
|
160
|
-
const
|
|
161
|
-
|
|
163
|
+
const filePathToShowToUser = filePathRelativeToUserRootDir ?? filePathAbsolute;
|
|
164
|
+
assertImportsAreReExported(fileImports, fileExports, filePathToShowToUser);
|
|
162
165
|
}
|
|
163
166
|
return { fileExports };
|
|
164
167
|
}
|
|
@@ -183,7 +186,7 @@ async function formatBuildErr(err, filePath) {
|
|
|
183
186
|
err[formatted] = `${msgIntro}\n${msgEsbuild}`;
|
|
184
187
|
}
|
|
185
188
|
const execErrIntroMsg = new WeakMap();
|
|
186
|
-
function
|
|
189
|
+
function getConfigExecutionErrorIntroMsg(err) {
|
|
187
190
|
if (!isObject(err))
|
|
188
191
|
return null;
|
|
189
192
|
const errIntroMsg = execErrIntroMsg.get(err);
|
|
@@ -204,17 +207,17 @@ function isTmpFile(filePath) {
|
|
|
204
207
|
const fileName = path.posix.basename(filePath);
|
|
205
208
|
return fileName.startsWith(tmpPrefix);
|
|
206
209
|
}
|
|
207
|
-
function
|
|
208
|
-
|
|
210
|
+
function assertImportsAreReExported(fileImports, fileExports, filePathToShowToUser) {
|
|
211
|
+
assertExportsOfConfigFile(fileExports, filePathToShowToUser);
|
|
209
212
|
const exportedStrings = getExportedStrings(fileExports.default);
|
|
210
213
|
Object.values(exportedStrings).forEach((exportVal) => {
|
|
211
214
|
if (typeof exportVal !== 'string')
|
|
212
215
|
return;
|
|
213
216
|
if (!isImportData(exportVal))
|
|
214
217
|
return;
|
|
215
|
-
const
|
|
218
|
+
const importString = exportVal;
|
|
216
219
|
fileImports.forEach((fileImport) => {
|
|
217
|
-
if (fileImport.
|
|
220
|
+
if (fileImport.importString === importString) {
|
|
218
221
|
fileImport.isReExported = true;
|
|
219
222
|
}
|
|
220
223
|
});
|
|
@@ -225,11 +228,11 @@ function assertFileImports(fileImports, fileExports, filePath) {
|
|
|
225
228
|
const importStatements = unique(fileImportsUnused.map((fi) => fi.importStatementCode));
|
|
226
229
|
const importNamesUnused = fileImportsUnused.map((fi) => pc.cyan(fi.importLocalName)).join(', ');
|
|
227
230
|
const singular = fileImportsUnused.length === 1;
|
|
228
|
-
|
|
229
|
-
`${
|
|
231
|
+
assertUsage(fileImportsUnused.length === 0, [
|
|
232
|
+
`${filePathToShowToUser} imports the following:`,
|
|
230
233
|
...importStatements.map((s) => pc.cyan(` ${s}`)),
|
|
231
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`
|
|
232
|
-
].join('\n')
|
|
235
|
+
].join('\n'));
|
|
233
236
|
}
|
|
234
237
|
function getExportedStrings(obj) {
|
|
235
238
|
const exportedStrings = [];
|
|
@@ -39,10 +39,23 @@ function suppressUnusedImport(warning) {
|
|
|
39
39
|
if (warning.code !== 'UNUSED_EXTERNAL_IMPORT')
|
|
40
40
|
return false;
|
|
41
41
|
// I guess it's expected that JSX contains unsused `import React from 'react'`
|
|
42
|
-
if (warning.exporter === 'react' && warning.names?.includes('default'))
|
|
43
|
-
|
|
42
|
+
if (warning.exporter === 'react' && warning.names?.includes('default')) {
|
|
43
|
+
warning.names = warning.names.filter((n) => n !== 'default');
|
|
44
|
+
if (warning.names.length === 0)
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
// Suppress:
|
|
48
|
+
// ```
|
|
49
|
+
// "untrack" is imported from external module "solid-js" but never used in "pages/star-wars/index/+Page.tsx", "pages/index/Counter.tsx", "components/Link.tsx", "pages/todo/TodoList.tsx" and "pages/todo/+Page.tsx".
|
|
50
|
+
// ```
|
|
51
|
+
// I'm guessing Solid's transformer injects `import { untrack } from 'solid-js'`
|
|
52
|
+
if (warning.exporter === 'solid-js' && warning.names?.includes('untrack')) {
|
|
53
|
+
warning.names = warning.names.filter((n) => n !== 'untrack');
|
|
54
|
+
if (warning.names.length === 0)
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
44
57
|
// If some library does something unexpected, we suppress since it isn't actionable
|
|
45
|
-
if (warning.ids?.
|
|
58
|
+
if (warning.ids?.every((id) => id.includes('/node_modules/')))
|
|
46
59
|
return true;
|
|
47
60
|
return false;
|
|
48
61
|
}
|
package/dist/esm/node/plugin/shared/{getConfigValueSource.d.ts → getConfigValueSourcesRelevant.d.ts}
RENAMED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
export { getConfigValueSource };
|
|
2
1
|
export { getConfigValueSourcesRelevant };
|
|
3
2
|
import type { ConfigValueSource, PageConfigBuildTime } from '../../../shared/page-configs/PageConfig.js';
|
|
4
|
-
declare function getConfigValueSource(pageConfig: PageConfigBuildTime, configName: string): null | ConfigValueSource;
|
|
5
3
|
declare function getConfigValueSourcesRelevant(pageConfig: PageConfigBuildTime): (ConfigValueSource & {
|
|
6
4
|
configName: string;
|
|
7
5
|
})[];
|
package/dist/esm/node/plugin/shared/{getConfigValueSource.js → getConfigValueSourcesRelevant.js}
RENAMED
|
@@ -1,17 +1,6 @@
|
|
|
1
|
-
export { getConfigValueSource };
|
|
2
1
|
export { getConfigValueSourcesRelevant };
|
|
3
2
|
import { assert, assertIsNotBrowser } from '../../shared/utils.js';
|
|
4
3
|
assertIsNotBrowser();
|
|
5
|
-
function getConfigValueSource(pageConfig, configName) {
|
|
6
|
-
// Doesn't exist on the client-side, but we are on the server-side as attested by assertIsNotBrowser()
|
|
7
|
-
assert(pageConfig.configValueSources);
|
|
8
|
-
const sources = pageConfig.configValueSources[configName];
|
|
9
|
-
if (!sources)
|
|
10
|
-
return null;
|
|
11
|
-
const configValueSource = sources[0];
|
|
12
|
-
assert(configValueSource);
|
|
13
|
-
return configValueSource;
|
|
14
|
-
}
|
|
15
4
|
function getConfigValueSourcesRelevant(pageConfig) {
|
|
16
5
|
const configValueSourcesRelevant = Object.entries(pageConfig.configValueSources).map(([configName, sources]) => {
|
|
17
6
|
const configValueSource = sources[0];
|
|
@@ -7,7 +7,7 @@ export { isEquivalentErrorWithCodeSnippet };
|
|
|
7
7
|
export { getPrettyErrMessage };
|
|
8
8
|
// Copied & adapted from https://github.com/vitejs/vite/blob/9c114c5c72a6af87e3330d5573362554b4511265/packages/vite/src/node/server/middlewares/error.ts
|
|
9
9
|
import pc from '@brillout/picocolors';
|
|
10
|
-
import { assert, escapeRegex,
|
|
10
|
+
import { assert, escapeRegex, getFilePathRelativeToUserRootDir, isObject, removeEmptyLines, stripAnsi, toPosixPath } from '../../utils.js';
|
|
11
11
|
function isErrorWithCodeSnippet(err) {
|
|
12
12
|
if (!isObject(err)) {
|
|
13
13
|
return false;
|
|
@@ -46,7 +46,7 @@ function getPrettyErrorWithCodeSnippet(err, userRootDir) {
|
|
|
46
46
|
let { id, frame } = err;
|
|
47
47
|
const msgFirstLine = [
|
|
48
48
|
pc.red('Failed to transpile'),
|
|
49
|
-
pc.bold(pc.red(
|
|
49
|
+
pc.bold(pc.red(getFilePathRelativeToUserRootDir(normalizeId(id), userRootDir))),
|
|
50
50
|
pc.red('because:')
|
|
51
51
|
].join(' ');
|
|
52
52
|
const errMsg = getPrettyErrMessage(err);
|
|
@@ -18,7 +18,7 @@ import { assert, assertIsNotProductionRuntime, getAssertErrMsg, isUserHookError,
|
|
|
18
18
|
import { getHttpRequestAsyncStore } from './getHttpRequestAsyncStore.js';
|
|
19
19
|
import { isErrorDebug } from './isErrorDebug.js';
|
|
20
20
|
import { isErrorWithCodeSnippet, getPrettyErrorWithCodeSnippet } from './loggerNotProd/errorWithCodeSnippet.js';
|
|
21
|
-
import {
|
|
21
|
+
import { getConfigExecutionErrorIntroMsg, getConfigBuildErrorFormatted } from '../plugins/importUserCode/v1-design/transpileAndExecuteFile.js';
|
|
22
22
|
import { logWithVikeTag, logWithViteTag, logDirectly, isFirstLog, screenHasErrors, clearScreen } from './loggerNotProd/log.js';
|
|
23
23
|
import pc from '@brillout/picocolors';
|
|
24
24
|
import { setAlreadyLogged } from '../../runtime/renderPage/isNewError.js';
|
|
@@ -108,7 +108,7 @@ function logConfigError(err) {
|
|
|
108
108
|
warnIfErrorIsNotObject(err);
|
|
109
109
|
const category = getConfigCategory();
|
|
110
110
|
{
|
|
111
|
-
const errIntroMsg =
|
|
111
|
+
const errIntroMsg = getConfigExecutionErrorIntroMsg(err);
|
|
112
112
|
if (errIntroMsg) {
|
|
113
113
|
assert(stripAnsi(errIntroMsg).startsWith('Failed to execute'));
|
|
114
114
|
logWithVikeTag(errIntroMsg, 'error', category);
|
|
@@ -194,9 +194,9 @@ function logErrorDebugNote() {
|
|
|
194
194
|
store.errorDebugNoteAlreadyShown = true;
|
|
195
195
|
}
|
|
196
196
|
const msg = pc.dim([
|
|
197
|
-
'
|
|
197
|
+
'┌──────────────────────────────────────────────────────────┐',
|
|
198
198
|
"│ Error isn't helpful? See https://vike.dev/errors#verbose │",
|
|
199
|
-
'
|
|
199
|
+
'└──────────────────────────────────────────────────────────┘'
|
|
200
200
|
].join('\n'));
|
|
201
201
|
logDirectly(msg, 'error');
|
|
202
202
|
}
|
|
@@ -2,8 +2,7 @@ export * from '../runtime/utils.js';
|
|
|
2
2
|
export * from '../../utils/viteIsSSR.js';
|
|
3
3
|
export * from '../../utils/getFilePathAbsolute.js';
|
|
4
4
|
export * from '../../utils/getDependencyPackageJson.js';
|
|
5
|
-
export * from '../../utils/
|
|
6
|
-
export * from '../../utils/assertDefaultExport.js';
|
|
5
|
+
export * from '../../utils/requireResolve.js';
|
|
7
6
|
export * from '../../utils/arrayIncludes.js';
|
|
8
7
|
export * from '../../utils/isDev.js';
|
|
9
8
|
export * from '../../utils/objectKeys.js';
|
|
@@ -8,8 +8,7 @@ export * from '../runtime/utils.js';
|
|
|
8
8
|
export * from '../../utils/viteIsSSR.js';
|
|
9
9
|
export * from '../../utils/getFilePathAbsolute.js';
|
|
10
10
|
export * from '../../utils/getDependencyPackageJson.js';
|
|
11
|
-
export * from '../../utils/
|
|
12
|
-
export * from '../../utils/assertDefaultExport.js';
|
|
11
|
+
export * from '../../utils/requireResolve.js';
|
|
13
12
|
export * from '../../utils/arrayIncludes.js';
|
|
14
13
|
export * from '../../utils/isDev.js';
|
|
15
14
|
export * from '../../utils/objectKeys.js';
|