vike 0.4.158-commit-7e44992 → 0.4.159-commit-6bcb2fd
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 +20 -1
- package/dist/cjs/node/plugin/plugins/devConfig/index.js +1 -1
- package/dist/cjs/node/plugin/plugins/importBuild/index.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getConfigFileExport.js +18 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +11 -12
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.js +3 -3
- package/dist/cjs/node/plugin/plugins/previewConfig.js +1 -1
- package/dist/cjs/node/plugin/shared/loggerNotProd/log.js +3 -3
- package/dist/cjs/node/runtime/globalContext.js +4 -3
- package/dist/cjs/shared/page-configs/assertPlusFileExport.js +44 -0
- package/dist/cjs/shared/page-configs/serialize/parseConfigValuesImported.js +2 -2
- package/dist/cjs/shared/route/abort.js +1 -1
- package/dist/cjs/utils/assert.js +5 -6
- package/dist/cjs/utils/assertIsNotProductionRuntime.js +35 -17
- package/dist/cjs/utils/nodeEnv.js +11 -1
- package/dist/cjs/utils/projectInfo.js +2 -4
- package/dist/esm/node/plugin/index.js +21 -2
- package/dist/esm/node/plugin/plugins/devConfig/index.js +2 -2
- package/dist/esm/node/plugin/plugins/importBuild/index.js +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getConfigFileExport.d.ts +2 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getConfigFileExport.js +12 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +6 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +11 -12
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.js +3 -3
- package/dist/esm/node/plugin/plugins/previewConfig.js +2 -2
- package/dist/esm/node/plugin/shared/loggerNotProd/log.js +3 -3
- package/dist/esm/node/runtime/globalContext.js +5 -4
- package/dist/esm/shared/page-configs/PageConfig.d.ts +4 -0
- package/dist/esm/shared/page-configs/assertPlusFileExport.d.ts +2 -0
- package/dist/esm/shared/page-configs/assertPlusFileExport.js +38 -0
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.js +2 -2
- package/dist/esm/shared/route/abort.js +2 -2
- package/dist/esm/utils/assert.js +5 -6
- package/dist/esm/utils/assertIsNotProductionRuntime.d.ts +8 -6
- package/dist/esm/utils/assertIsNotProductionRuntime.js +35 -17
- package/dist/esm/utils/debug.d.ts +1 -1
- package/dist/esm/utils/nodeEnv.d.ts +2 -0
- package/dist/esm/utils/nodeEnv.js +10 -0
- package/dist/esm/utils/projectInfo.d.ts +2 -8
- package/dist/esm/utils/projectInfo.js +2 -4
- package/package.json +1 -1
- package/dist/cjs/shared/page-configs/assertExports.js +0 -67
- package/dist/esm/shared/page-configs/assertExports.d.ts +0 -6
- package/dist/esm/shared/page-configs/assertExports.js +0 -61
|
@@ -28,7 +28,8 @@ const baseUrls_js_1 = require("./plugins/baseUrls.js");
|
|
|
28
28
|
const envVars_js_1 = require("./plugins/envVars.js");
|
|
29
29
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
30
30
|
const fileEnv_js_1 = require("./plugins/fileEnv.js");
|
|
31
|
-
(
|
|
31
|
+
assertNodeEnv();
|
|
32
|
+
(0, utils_js_2.markEnvAsVikePluginLoaded)();
|
|
32
33
|
// Return as `any` to avoid Plugin type mismatches when there are multiple Vite versions installed
|
|
33
34
|
function plugin(vikeConfig) {
|
|
34
35
|
const plugins = [
|
|
@@ -70,3 +71,21 @@ Object.defineProperty(plugin, 'apply', {
|
|
|
70
71
|
(0, utils_js_2.assertUsage)(false, `Add ${picocolors_1.default.cyan('vike()')} instead of ${picocolors_1.default.cyan('vike')} to vite.config.js#plugins (i.e. call the function and add the return value instead of adding the function itself)`, { showStackTrace: true });
|
|
71
72
|
}
|
|
72
73
|
});
|
|
74
|
+
function assertNodeEnv() {
|
|
75
|
+
const nodeEnv = (0, utils_js_2.getNodeEnv)();
|
|
76
|
+
if (nodeEnv === 'test')
|
|
77
|
+
return;
|
|
78
|
+
// We should change this to be a warning if it blocks users (e.g. if a bad-citizen tool sets a wrong process.env.NODE_ENV value).
|
|
79
|
+
(0, utils_js_2.assertUsage)(
|
|
80
|
+
/* We can enable this assertion after Vike's CLI is implemented and using Vite's CLI is deprecated (we can then check whether the context is a `$ vike build`).
|
|
81
|
+
isNodeEnvDev() || isVikeCliBuild(),
|
|
82
|
+
/*/
|
|
83
|
+
(0, utils_js_2.isNodeEnvDev)() || true,
|
|
84
|
+
///*/
|
|
85
|
+
[
|
|
86
|
+
picocolors_1.default.cyan(`process.env.NODE_ENV === ${JSON.stringify(nodeEnv)}`),
|
|
87
|
+
'(which Vike interprets as a non-development environment https://vike.dev/NODE_ENV)',
|
|
88
|
+
'while the vike/plugin module is loaded.',
|
|
89
|
+
utils_js_2.vikeVitePluginLoadedInProductionError
|
|
90
|
+
].join(' '));
|
|
91
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getConfigFileExport = void 0;
|
|
7
|
+
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
8
|
+
const assertPlusFileExport_js_1 = require("../../../../../shared/page-configs/assertPlusFileExport.js");
|
|
9
|
+
const utils_js_1 = require("../../../utils.js");
|
|
10
|
+
function getConfigFileExport(fileExports, filePathToShowToUser) {
|
|
11
|
+
(0, assertPlusFileExport_js_1.assertPlusFileExport)(fileExports, filePathToShowToUser, 'config');
|
|
12
|
+
const fileExport = fileExports.default || fileExports.config;
|
|
13
|
+
(0, utils_js_1.assert)('default' in fileExports !== 'config' in fileExports);
|
|
14
|
+
const exportName = picocolors_1.default.cyan('default' in fileExports ? 'export default' : 'export { config }');
|
|
15
|
+
(0, utils_js_1.assertUsage)((0, utils_js_1.isObject)(fileExport), `The ${exportName} of ${filePathToShowToUser} should be an object (but it's ${picocolors_1.default.cyan(`typeof exportedValue === ${JSON.stringify(typeof fileExport)}`)} instead)`);
|
|
16
|
+
return fileExport;
|
|
17
|
+
}
|
|
18
|
+
exports.getConfigFileExport = getConfigFileExport;
|
|
@@ -16,10 +16,11 @@ const loggerNotProd_js_1 = require("../../../shared/loggerNotProd.js");
|
|
|
16
16
|
const removeSuperfluousViteLog_js_1 = require("../../../shared/loggerVite/removeSuperfluousViteLog.js");
|
|
17
17
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
18
18
|
const helpers_js_1 = require("../../../../../shared/page-configs/helpers.js");
|
|
19
|
-
const
|
|
19
|
+
const assertPlusFileExport_js_1 = require("../../../../../shared/page-configs/assertPlusFileExport.js");
|
|
20
20
|
const getConfigVike_js_1 = require("../../../../shared/getConfigVike.js");
|
|
21
21
|
const getConfigValuesSerialized_js_1 = require("./getConfigValuesSerialized.js");
|
|
22
22
|
const crawlPlusFiles_js_1 = require("./getVikeConfig/crawlPlusFiles.js");
|
|
23
|
+
const getConfigFileExport_js_1 = require("./getConfigFileExport.js");
|
|
23
24
|
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
24
25
|
let devServerIsCorrupt = false;
|
|
25
26
|
let wasConfigInvalid = null;
|
|
@@ -142,7 +143,7 @@ function getConfigDefinitionOptional(configDefinitions, configName) {
|
|
|
142
143
|
async function loadValueFile(interfaceValueFile, configName, userRootDir) {
|
|
143
144
|
const { fileExports } = await (0, transpileAndExecuteFile_js_1.transpileAndExecuteFile)(interfaceValueFile.filePath, true, userRootDir);
|
|
144
145
|
const { filePathToShowToUser } = interfaceValueFile.filePath;
|
|
145
|
-
(0,
|
|
146
|
+
(0, assertPlusFileExport_js_1.assertPlusFileExport)(fileExports, filePathToShowToUser, configName);
|
|
146
147
|
Object.entries(fileExports).forEach(([exportName, configValue]) => {
|
|
147
148
|
const configName_ = exportName === 'default' ? configName : exportName;
|
|
148
149
|
interfaceValueFile.configMap[configName_] = { configValue };
|
|
@@ -174,9 +175,8 @@ function getInterfaceFileFromConfigFile(configFile, isConfigExtend) {
|
|
|
174
175
|
isConfigExtend,
|
|
175
176
|
extendsFilePaths
|
|
176
177
|
};
|
|
177
|
-
const
|
|
178
|
-
(
|
|
179
|
-
Object.entries(fileExports.default).forEach(([configName, configValue]) => {
|
|
178
|
+
const fileExport = (0, getConfigFileExport_js_1.getConfigFileExport)(fileExports, filePath.filePathToShowToUser);
|
|
179
|
+
Object.entries(fileExport).forEach(([configName, configValue]) => {
|
|
180
180
|
interfaceFile.configMap[configName] = { configValue };
|
|
181
181
|
});
|
|
182
182
|
return interfaceFile;
|
|
@@ -925,18 +925,17 @@ function assertExtendsImportPath(importPath, filePath, configFilePath) {
|
|
|
925
925
|
}
|
|
926
926
|
function getExtendsImportData(configFileExports, configFilePath) {
|
|
927
927
|
const { filePathToShowToUser } = configFilePath;
|
|
928
|
-
(0,
|
|
929
|
-
const defaultExports = configFileExports.default;
|
|
928
|
+
const configFileExport = (0, getConfigFileExport_js_1.getConfigFileExport)(configFileExports, filePathToShowToUser);
|
|
930
929
|
const wrongUsage = `${filePathToShowToUser} sets the config ${picocolors_1.default.cyan('extends')} to an invalid value, see https://vike.dev/extends`;
|
|
931
930
|
let extendList;
|
|
932
|
-
if (!('extends' in
|
|
931
|
+
if (!('extends' in configFileExport)) {
|
|
933
932
|
return [];
|
|
934
933
|
}
|
|
935
|
-
else if ((0, utils_js_1.hasProp)(
|
|
936
|
-
extendList = [
|
|
934
|
+
else if ((0, utils_js_1.hasProp)(configFileExport, 'extends', 'string')) {
|
|
935
|
+
extendList = [configFileExport.extends];
|
|
937
936
|
}
|
|
938
|
-
else if ((0, utils_js_1.hasProp)(
|
|
939
|
-
extendList =
|
|
937
|
+
else if ((0, utils_js_1.hasProp)(configFileExport, 'extends', 'string[]')) {
|
|
938
|
+
extendList = configFileExport.extends;
|
|
940
939
|
}
|
|
941
940
|
else {
|
|
942
941
|
(0, utils_js_1.assertUsage)(false, wrongUsage);
|
|
@@ -13,7 +13,7 @@ const utils_js_1 = require("../../../utils.js");
|
|
|
13
13
|
const replaceImportStatements_js_1 = require("./replaceImportStatements.js");
|
|
14
14
|
const getVikeConfig_js_1 = require("./getVikeConfig.js");
|
|
15
15
|
require("source-map-support/register.js");
|
|
16
|
-
const
|
|
16
|
+
const getConfigFileExport_js_1 = require("./getConfigFileExport.js");
|
|
17
17
|
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
18
18
|
async function transpileAndExecuteFile(filePath, isValueFile, userRootDir) {
|
|
19
19
|
const { code, fileImports } = await transpileFile(filePath, isValueFile, userRootDir);
|
|
@@ -212,8 +212,8 @@ function isTmpFile(filePath) {
|
|
|
212
212
|
}
|
|
213
213
|
exports.isTmpFile = isTmpFile;
|
|
214
214
|
function assertImportsAreReExported(fileImports, fileExports, filePathToShowToUser) {
|
|
215
|
-
(0,
|
|
216
|
-
const exportedStrings = getExportedStrings(
|
|
215
|
+
const fileExport = (0, getConfigFileExport_js_1.getConfigFileExport)(fileExports, filePathToShowToUser);
|
|
216
|
+
const exportedStrings = getExportedStrings(fileExport);
|
|
217
217
|
Object.values(exportedStrings).forEach((exportVal) => {
|
|
218
218
|
if (typeof exportVal !== 'string')
|
|
219
219
|
return;
|
|
@@ -33,7 +33,7 @@ function previewConfig() {
|
|
|
33
33
|
- This ugly hack to set appType for preview won't be need once https://github.com/vitejs/vite/pull/14855 is merged.
|
|
34
34
|
config.appType = 'mpa'
|
|
35
35
|
*/
|
|
36
|
-
(0, utils_js_1.
|
|
36
|
+
(0, utils_js_1.markEnvAsVitePreview)();
|
|
37
37
|
return () => {
|
|
38
38
|
assertDist();
|
|
39
39
|
/* We don't use this condition (we wrongfully always use the SSR middleware) because of the regression introduced by https://github.com/vitejs/vite/pull/14756 which stops servering .html files when `appType: 'custom'`.
|
|
@@ -22,10 +22,10 @@ exports.logWithVikeTag = logWithVikeTag;
|
|
|
22
22
|
function getProjectTag(showVikeVersion) {
|
|
23
23
|
let projectTag;
|
|
24
24
|
if (showVikeVersion) {
|
|
25
|
-
projectTag = `[
|
|
25
|
+
projectTag = `[vike@${utils_js_1.projectInfo.projectVersion}]`;
|
|
26
26
|
}
|
|
27
27
|
else {
|
|
28
|
-
projectTag = `[
|
|
28
|
+
projectTag = `[vike]`;
|
|
29
29
|
}
|
|
30
30
|
return projectTag;
|
|
31
31
|
}
|
|
@@ -89,7 +89,7 @@ function prependTags(msg, projectTag, category, logType) {
|
|
|
89
89
|
return picocolors_1.default.yellow(s);
|
|
90
90
|
if (projectTag === '[vite]')
|
|
91
91
|
return picocolors_1.default.bold(picocolors_1.default.cyan(s));
|
|
92
|
-
if (projectTag.startsWith(`[
|
|
92
|
+
if (projectTag.startsWith(`[vike`))
|
|
93
93
|
return picocolors_1.default.bold(picocolors_1.default.cyan(s));
|
|
94
94
|
(0, utils_js_1.assert)(false);
|
|
95
95
|
};
|
|
@@ -157,7 +157,8 @@ function assertNodeEnv(hasViteDevServer) {
|
|
|
157
157
|
const nodeEnv = (0, utils_js_1.getNodeEnv)();
|
|
158
158
|
if (nodeEnv === null || nodeEnv === 'test')
|
|
159
159
|
return;
|
|
160
|
-
const isDevNodeEnv =
|
|
161
|
-
//
|
|
162
|
-
|
|
160
|
+
const isDevNodeEnv = (0, utils_js_1.isNodeEnvDev)();
|
|
161
|
+
// - Calling Vite's createServer() is enough for hasViteDevServer to be true, even without actually adding Vite's development middleware to the server: https://github.com/vikejs/vike/issues/792#issuecomment-1516830759
|
|
162
|
+
// - We should change this to be a warning if it blocks users (e.g. if a bad-citizen tool sets a wrong process.env.NODE_ENV value).
|
|
163
|
+
(0, utils_js_1.assertUsage)(hasViteDevServer === isDevNodeEnv, `Vite's development server was${hasViteDevServer ? '' : "n't"} instantiated while the environment is set to be a ${isDevNodeEnv ? 'development' : 'production'} environment by ${picocolors_1.default.cyan(`process.env.NODE_ENV === ${JSON.stringify(nodeEnv)}`)} which is contradictory, see https://vike.dev/NODE_ENV`);
|
|
163
164
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.assertPlusFileExport = void 0;
|
|
7
|
+
const utils_js_1 = require("../utils.js");
|
|
8
|
+
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
9
|
+
const EXPORTS_IGNORE = [
|
|
10
|
+
// vite-plugin-solid adds `export { $$registrations }`
|
|
11
|
+
'$$registrations',
|
|
12
|
+
// @vitejs/plugin-vue adds `export { _rerender_only }`
|
|
13
|
+
'_rerender_only'
|
|
14
|
+
];
|
|
15
|
+
// Tolerate `export { frontmatter }` in .mdx files
|
|
16
|
+
const TOLERATE_SIDE_EXPORTS = ['.md', '.mdx'];
|
|
17
|
+
function assertPlusFileExport(fileExports, filePathToShowToUser, configName) {
|
|
18
|
+
const exportsAll = Object.keys(fileExports).filter((exportName) => !EXPORTS_IGNORE.includes(exportName));
|
|
19
|
+
const exportsInvalid = exportsAll.filter((e) => e !== 'default' && e !== configName);
|
|
20
|
+
if (exportsInvalid.length === 0) {
|
|
21
|
+
if (exportsAll.length === 1) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const exportDefault = picocolors_1.default.cyan('export default');
|
|
25
|
+
const exportNamed = picocolors_1.default.cyan(`export { ${configName} }`);
|
|
26
|
+
if (exportsAll.length === 0) {
|
|
27
|
+
(0, utils_js_1.assertUsage)(false, `${filePathToShowToUser} doesn't export any value, but it should have a ${exportNamed} or ${exportDefault}`);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
(0, utils_js_1.assert)(exportsAll.length === 2); // because `exportsInvalid.length === 0`
|
|
31
|
+
(0, utils_js_1.assertWarning)(false, `${filePathToShowToUser} remove ${exportNamed} or ${exportDefault}`, {
|
|
32
|
+
onlyOnce: true
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
if (TOLERATE_SIDE_EXPORTS.some((ext) => filePathToShowToUser.endsWith(ext)))
|
|
38
|
+
return;
|
|
39
|
+
exportsInvalid.forEach((exportInvalid) => {
|
|
40
|
+
(0, utils_js_1.assertWarning)(false, `${filePathToShowToUser} should have only one export: move ${picocolors_1.default.cyan(`export { ${exportInvalid} }`)} to its own +${exportsInvalid}.js file`, { onlyOnce: true });
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.assertPlusFileExport = assertPlusFileExport;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseConfigValuesImported = void 0;
|
|
4
4
|
const utils_js_1 = require("../../utils.js");
|
|
5
|
-
const
|
|
5
|
+
const assertPlusFileExport_js_1 = require("../assertPlusFileExport.js");
|
|
6
6
|
function parseConfigValuesImported(configValuesImported) {
|
|
7
7
|
const configValues = {};
|
|
8
8
|
const addConfigValue = (configName, value, importPath, exportName) => {
|
|
@@ -23,7 +23,7 @@ function parseConfigValuesImported(configValuesImported) {
|
|
|
23
23
|
if (configValueLoaded.isValueFile) {
|
|
24
24
|
const { exportValues, importPath, configName } = configValueLoaded;
|
|
25
25
|
if (configName !== 'client') {
|
|
26
|
-
(0,
|
|
26
|
+
(0, assertPlusFileExport_js_1.assertPlusFileExport)(exportValues, importPath, configName);
|
|
27
27
|
}
|
|
28
28
|
Object.entries(exportValues).forEach(([exportName, exportValue]) => {
|
|
29
29
|
const isSideExport = exportName !== 'default'; // .md files may have "side-exports" such as `export { frontmatter }`
|
|
@@ -136,7 +136,7 @@ function logAbortErrorHandled(err, isProduction, pageContext) {
|
|
|
136
136
|
exports.logAbortErrorHandled = logAbortErrorHandled;
|
|
137
137
|
function assertStatusCode(statusCode, expected, caller) {
|
|
138
138
|
const expectedEnglish = (0, utils_js_1.joinEnglish)(expected.map((s) => s.toString()), 'or');
|
|
139
|
-
(0, utils_js_1.assertWarning)(expected.includes(statusCode), `Unepexected status code ${statusCode} passed to ${caller}(), we recommend ${expectedEnglish} instead. (Or reach out at
|
|
139
|
+
(0, utils_js_1.assertWarning)(expected.includes(statusCode), `Unepexected status code ${statusCode} passed to ${caller}(), we recommend ${expectedEnglish} instead. (Or reach out at https://github.com/vikejs/vike/issues/1008 if you believe ${statusCode} should be added.)`, { onlyOnce: true });
|
|
140
140
|
}
|
|
141
141
|
function getPageContextFromAllRewrites(pageContextsFromRewrite) {
|
|
142
142
|
assertNoInfiniteLoop(pageContextsFromRewrite);
|
package/dist/cjs/utils/assert.js
CHANGED
|
@@ -22,8 +22,8 @@ const globalObject = (0, getGlobalObject_js_1.getGlobalObject)('utils/assert.ts'
|
|
|
22
22
|
},
|
|
23
23
|
showStackTraceList: new WeakSet()
|
|
24
24
|
});
|
|
25
|
-
const projectTag = `[
|
|
26
|
-
const projectTagWithVersion = `[
|
|
25
|
+
const projectTag = `[vike]`;
|
|
26
|
+
const projectTagWithVersion = `[vike@${projectInfo_js_1.projectInfo.projectVersion}]`;
|
|
27
27
|
const numberOfStackTraceLinesToRemove = 2;
|
|
28
28
|
function assert(condition, debugInfo) {
|
|
29
29
|
if (condition)
|
|
@@ -33,12 +33,11 @@ function assert(condition, debugInfo) {
|
|
|
33
33
|
return null;
|
|
34
34
|
}
|
|
35
35
|
const debugInfoSerialized = typeof debugInfo === 'string' ? debugInfo : JSON.stringify(debugInfo);
|
|
36
|
-
return picocolors_1.default.dim(`Debug info (for
|
|
36
|
+
return picocolors_1.default.dim(`Debug info (for Vike maintainers; you can ignore this): ${debugInfoSerialized}`);
|
|
37
37
|
})();
|
|
38
|
-
const link = `${projectInfo_js_1.projectInfo.githubRepository}/issues/new`;
|
|
39
38
|
let errMsg = [
|
|
40
|
-
`You stumbled upon a bug
|
|
41
|
-
`Go to ${picocolors_1.default.blue(
|
|
39
|
+
`You stumbled upon a Vike bug.`,
|
|
40
|
+
`Go to ${picocolors_1.default.blue('https://github.com/vikejs/vike/issues/new')} and copy-paste this error. A maintainer will fix the bug (usually under 24 hours).`,
|
|
42
41
|
debugStr
|
|
43
42
|
]
|
|
44
43
|
.filter(Boolean)
|
|
@@ -1,44 +1,62 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Mechanism to ensure code isn't loaded by production runtime
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.assertEnv = exports.
|
|
4
|
+
exports.vikeVitePluginLoadedInProductionError = exports.assertEnv = exports.markEnvAsVikePluginLoaded = exports.markEnvAsVitePreview = exports.markEnvAsViteDev = exports.assertIsNotProductionRuntime = void 0;
|
|
5
5
|
const assert_js_1 = require("./assert.js");
|
|
6
6
|
const assertIsNotBrowser_js_1 = require("./assertIsNotBrowser.js");
|
|
7
|
+
const debug_js_1 = require("./debug.js");
|
|
7
8
|
const getGlobalObject_js_1 = require("./getGlobalObject.js");
|
|
8
9
|
const isVitest_js_1 = require("./isVitest.js");
|
|
9
10
|
(0, assertIsNotBrowser_js_1.assertIsNotBrowser)();
|
|
11
|
+
const debug = (0, debug_js_1.createDebugger)('vike:setup');
|
|
12
|
+
const vikeVitePluginLoadedInProductionError = `Loading Vike's Vite plugin (the vike/plugin module) is prohibited in production.`;
|
|
13
|
+
exports.vikeVitePluginLoadedInProductionError = vikeVitePluginLoadedInProductionError;
|
|
10
14
|
const env = (0, getGlobalObject_js_1.getGlobalObject)('utils/assertIsNotProductionRuntime.ts', {});
|
|
11
|
-
// Called by
|
|
15
|
+
// Called by Vike modules that want to ensure that they aren't loaded by the server runtime in production
|
|
12
16
|
function assertIsNotProductionRuntime() {
|
|
13
|
-
|
|
17
|
+
if (debug.isEnabled)
|
|
18
|
+
debug('assertIsNotProductionRuntime()', new Error().stack);
|
|
19
|
+
env.shouldNotBeProduction = true;
|
|
14
20
|
}
|
|
15
21
|
exports.assertIsNotProductionRuntime = assertIsNotProductionRuntime;
|
|
16
22
|
// Called by Vite hook configureServer()
|
|
17
|
-
function
|
|
18
|
-
|
|
23
|
+
function markEnvAsViteDev() {
|
|
24
|
+
if (debug.isEnabled)
|
|
25
|
+
debug('markEnvAsViteDev()', new Error().stack);
|
|
26
|
+
env.isViteDev = true;
|
|
19
27
|
}
|
|
20
|
-
exports.
|
|
28
|
+
exports.markEnvAsViteDev = markEnvAsViteDev;
|
|
21
29
|
// Called by Vite hook configurePreviewServer()
|
|
22
|
-
function
|
|
23
|
-
|
|
30
|
+
function markEnvAsVitePreview() {
|
|
31
|
+
if (debug.isEnabled)
|
|
32
|
+
debug('markEnvAsVitePreview()', new Error().stack);
|
|
33
|
+
env.isVitePreview = true;
|
|
24
34
|
}
|
|
25
|
-
exports.
|
|
35
|
+
exports.markEnvAsVitePreview = markEnvAsVitePreview;
|
|
26
36
|
// Called by ../node/plugin/index.ts
|
|
27
|
-
function
|
|
28
|
-
|
|
37
|
+
function markEnvAsVikePluginLoaded() {
|
|
38
|
+
if (debug.isEnabled)
|
|
39
|
+
debug('markEnvAsVikePluginLoaded()', new Error().stack);
|
|
40
|
+
env.isVikePluginLoaded = true;
|
|
29
41
|
}
|
|
30
|
-
exports.
|
|
42
|
+
exports.markEnvAsVikePluginLoaded = markEnvAsVikePluginLoaded;
|
|
31
43
|
// Called by ../node/runtime/index.ts
|
|
32
44
|
function assertEnv() {
|
|
45
|
+
if (debug.isEnabled)
|
|
46
|
+
debug('assertEnv()', new Error().stack);
|
|
33
47
|
if ((0, isVitest_js_1.isVitest)())
|
|
34
48
|
return;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
(
|
|
49
|
+
const isProduction = !env.isViteDev && !env.isVitePreview;
|
|
50
|
+
if (isProduction) {
|
|
51
|
+
// Seems to be the only reliable way to assert that the user doesn't load Vike's Vite plugin in production. (The other assert() that uses process.env.NODE_ENV doesn't work if the user sets the process.env.NODE_ENV value later.)
|
|
52
|
+
(0, assert_js_1.assertUsage)(!env.isVikePluginLoaded, vikeVitePluginLoadedInProductionError);
|
|
53
|
+
// This assert() is the main goal of this file: it ensures assertIsNotProductionRuntime()
|
|
54
|
+
(0, assert_js_1.assert)(!env.shouldNotBeProduction);
|
|
38
55
|
}
|
|
39
56
|
else {
|
|
40
|
-
|
|
41
|
-
(0, assert_js_1.assert)(
|
|
57
|
+
// This assert() is obious and boring
|
|
58
|
+
(0, assert_js_1.assert)(env.shouldNotBeProduction);
|
|
59
|
+
(0, assert_js_1.assert)(env.isVikePluginLoaded);
|
|
42
60
|
}
|
|
43
61
|
}
|
|
44
62
|
exports.assertEnv = assertEnv;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.setNodeEnvToProduction = exports.getNodeEnv = void 0;
|
|
3
|
+
exports.isNodeEnvDev = exports.setNodeEnvToProduction = exports.getNodeEnv = void 0;
|
|
4
4
|
function getNodeEnv() {
|
|
5
5
|
if (typeof process === 'undefined')
|
|
6
6
|
return null;
|
|
@@ -14,3 +14,13 @@ function setNodeEnvToProduction() {
|
|
|
14
14
|
env.NODE_ENV = 'production';
|
|
15
15
|
}
|
|
16
16
|
exports.setNodeEnvToProduction = setNodeEnvToProduction;
|
|
17
|
+
function isNodeEnvDev() {
|
|
18
|
+
const nodeEnv = getNodeEnv();
|
|
19
|
+
if (!nodeEnv)
|
|
20
|
+
return true;
|
|
21
|
+
if (['development', 'dev'].includes(nodeEnv))
|
|
22
|
+
return true;
|
|
23
|
+
// That's quite aggressive, let's see if some user complains
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
exports.isNodeEnvDev = isNodeEnvDev;
|
|
@@ -2,13 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PROJECT_VERSION = exports.projectInfo = void 0;
|
|
4
4
|
const assertSingleInstance_js_1 = require("./assertSingleInstance.js");
|
|
5
|
-
const PROJECT_VERSION = '0.4.
|
|
5
|
+
const PROJECT_VERSION = '0.4.159-commit-6bcb2fd';
|
|
6
6
|
exports.PROJECT_VERSION = PROJECT_VERSION;
|
|
7
7
|
const projectInfo = {
|
|
8
8
|
projectName: 'Vike',
|
|
9
|
-
projectVersion: PROJECT_VERSION
|
|
10
|
-
npmPackageName: 'vike',
|
|
11
|
-
githubRepository: 'https://github.com/vikejs/vike'
|
|
9
|
+
projectVersion: PROJECT_VERSION
|
|
12
10
|
};
|
|
13
11
|
exports.projectInfo = projectInfo;
|
|
14
12
|
// Trick: since `utils/asserts.ts` depends on this file (`utils/projectInfo.ts`), we can have confidence that this file is always instantiated. So that we don't have to initialize this code snippet at every possible entry. (There are a *lot* of entries: `client/router/`, `client/`, `node/`, `node/plugin/`, `node/cli`, etc.)
|
|
@@ -3,7 +3,7 @@ export { plugin };
|
|
|
3
3
|
// TODO/v1-release: remove
|
|
4
4
|
export { plugin as ssr };
|
|
5
5
|
export { PROJECT_VERSION as version } from './utils.js';
|
|
6
|
-
import { assertUsage,
|
|
6
|
+
import { assertUsage, getNodeEnv, isNodeEnvDev, markEnvAsVikePluginLoaded, vikeVitePluginLoadedInProductionError } from './utils.js';
|
|
7
7
|
import { buildConfig } from './plugins/buildConfig.js';
|
|
8
8
|
import { previewConfig } from './plugins/previewConfig.js';
|
|
9
9
|
import { autoFullBuild } from './plugins/autoFullBuild.js';
|
|
@@ -24,7 +24,8 @@ import { baseUrls } from './plugins/baseUrls.js';
|
|
|
24
24
|
import { envVarsPlugin } from './plugins/envVars.js';
|
|
25
25
|
import pc from '@brillout/picocolors';
|
|
26
26
|
import { fileEnv } from './plugins/fileEnv.js';
|
|
27
|
-
|
|
27
|
+
assertNodeEnv();
|
|
28
|
+
markEnvAsVikePluginLoaded();
|
|
28
29
|
// Return as `any` to avoid Plugin type mismatches when there are multiple Vite versions installed
|
|
29
30
|
function plugin(vikeConfig) {
|
|
30
31
|
const plugins = [
|
|
@@ -64,3 +65,21 @@ Object.defineProperty(plugin, 'apply', {
|
|
|
64
65
|
assertUsage(false, `Add ${pc.cyan('vike()')} instead of ${pc.cyan('vike')} to vite.config.js#plugins (i.e. call the function and add the return value instead of adding the function itself)`, { showStackTrace: true });
|
|
65
66
|
}
|
|
66
67
|
});
|
|
68
|
+
function assertNodeEnv() {
|
|
69
|
+
const nodeEnv = getNodeEnv();
|
|
70
|
+
if (nodeEnv === 'test')
|
|
71
|
+
return;
|
|
72
|
+
// We should change this to be a warning if it blocks users (e.g. if a bad-citizen tool sets a wrong process.env.NODE_ENV value).
|
|
73
|
+
assertUsage(
|
|
74
|
+
/* We can enable this assertion after Vike's CLI is implemented and using Vite's CLI is deprecated (we can then check whether the context is a `$ vike build`).
|
|
75
|
+
isNodeEnvDev() || isVikeCliBuild(),
|
|
76
|
+
/*/
|
|
77
|
+
isNodeEnvDev() || true,
|
|
78
|
+
///*/
|
|
79
|
+
[
|
|
80
|
+
pc.cyan(`process.env.NODE_ENV === ${JSON.stringify(nodeEnv)}`),
|
|
81
|
+
'(which Vike interprets as a non-development environment https://vike.dev/NODE_ENV)',
|
|
82
|
+
'while the vike/plugin module is loaded.',
|
|
83
|
+
vikeVitePluginLoadedInProductionError
|
|
84
|
+
].join(' '));
|
|
85
|
+
}
|
|
@@ -3,7 +3,7 @@ import { determineOptimizeDeps } from './determineOptimizeDeps.js';
|
|
|
3
3
|
import { determineFsAllowList } from './determineFsAllowList.js';
|
|
4
4
|
import { getConfigVike } from '../../../shared/getConfigVike.js';
|
|
5
5
|
import { addSsrMiddleware } from '../../shared/addSsrMiddleware.js';
|
|
6
|
-
import {
|
|
6
|
+
import { markEnvAsViteDev } from '../../utils.js';
|
|
7
7
|
import { improveViteLogs } from '../../shared/loggerVite.js';
|
|
8
8
|
import { isErrorDebug } from '../../shared/isErrorDebug.js';
|
|
9
9
|
import { installHttpRequestAsyncStore } from '../../shared/getHttpRequestAsyncStore.js';
|
|
@@ -64,7 +64,7 @@ function devConfig() {
|
|
|
64
64
|
}
|
|
65
65
|
},
|
|
66
66
|
configureServer() {
|
|
67
|
-
|
|
67
|
+
markEnvAsViteDev();
|
|
68
68
|
}
|
|
69
69
|
},
|
|
70
70
|
{
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { importBuild };
|
|
2
2
|
import { serverEntryPlugin, findServerEntry } from '@brillout/vite-plugin-server-entry/plugin.js';
|
|
3
|
-
import { assert, getOutDirs,
|
|
3
|
+
import { assert, getOutDirs, toPosixPath, viteIsSSR } from '../../utils.js';
|
|
4
4
|
import path from 'path';
|
|
5
5
|
import { createRequire } from 'module';
|
|
6
6
|
import { getConfigVike } from '../../../shared/getConfigVike.js';
|
|
@@ -32,7 +32,7 @@ function importBuild() {
|
|
|
32
32
|
getImporterCode: () => {
|
|
33
33
|
return getEntryCode(config, configVike);
|
|
34
34
|
},
|
|
35
|
-
libraryName:
|
|
35
|
+
libraryName: 'Vike'
|
|
36
36
|
})
|
|
37
37
|
];
|
|
38
38
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { getConfigFileExport };
|
|
2
|
+
import pc from '@brillout/picocolors';
|
|
3
|
+
import { assertPlusFileExport } from '../../../../../shared/page-configs/assertPlusFileExport.js';
|
|
4
|
+
import { assert, assertUsage, isObject } from '../../../utils.js';
|
|
5
|
+
function getConfigFileExport(fileExports, filePathToShowToUser) {
|
|
6
|
+
assertPlusFileExport(fileExports, filePathToShowToUser, 'config');
|
|
7
|
+
const fileExport = fileExports.default || fileExports.config;
|
|
8
|
+
assert('default' in fileExports !== 'config' in fileExports);
|
|
9
|
+
const exportName = pc.cyan('default' in fileExports ? 'export default' : 'export { config }');
|
|
10
|
+
assertUsage(isObject(fileExport), `The ${exportName} of ${filePathToShowToUser} should be an object (but it's ${pc.cyan(`typeof exportedValue === ${JSON.stringify(typeof fileExport)}`)} instead)`);
|
|
11
|
+
return fileExport;
|
|
12
|
+
}
|
|
@@ -24,12 +24,17 @@ type ConfigDefinition = {
|
|
|
24
24
|
*/
|
|
25
25
|
cumulative?: boolean;
|
|
26
26
|
/**
|
|
27
|
-
*
|
|
27
|
+
* Function called when the config value is defined.
|
|
28
28
|
*
|
|
29
29
|
* https://vike.dev/meta
|
|
30
30
|
*/
|
|
31
31
|
effect?: ConfigEffect;
|
|
32
32
|
};
|
|
33
|
+
/**
|
|
34
|
+
* Function called when the config value is defined.
|
|
35
|
+
*
|
|
36
|
+
* https://vike.dev/meta
|
|
37
|
+
*/
|
|
33
38
|
type ConfigEffect = (config: {
|
|
34
39
|
/** The config value.
|
|
35
40
|
*
|
|
@@ -14,10 +14,11 @@ import { logConfigError, logConfigErrorRecover } from '../../../shared/loggerNot
|
|
|
14
14
|
import { removeSuperfluousViteLog_enable, removeSuperfluousViteLog_disable } from '../../../shared/loggerVite/removeSuperfluousViteLog.js';
|
|
15
15
|
import pc from '@brillout/picocolors';
|
|
16
16
|
import { getConfigDefinedAtString } from '../../../../../shared/page-configs/helpers.js';
|
|
17
|
-
import {
|
|
17
|
+
import { assertPlusFileExport } from '../../../../../shared/page-configs/assertPlusFileExport.js';
|
|
18
18
|
import { getConfigVike } from '../../../../shared/getConfigVike.js';
|
|
19
19
|
import { assertConfigValueIsSerializable } from './getConfigValuesSerialized.js';
|
|
20
20
|
import { crawlPlusFiles } from './getVikeConfig/crawlPlusFiles.js';
|
|
21
|
+
import { getConfigFileExport } from './getConfigFileExport.js';
|
|
21
22
|
assertIsNotProductionRuntime();
|
|
22
23
|
let devServerIsCorrupt = false;
|
|
23
24
|
let wasConfigInvalid = null;
|
|
@@ -137,7 +138,7 @@ function getConfigDefinitionOptional(configDefinitions, configName) {
|
|
|
137
138
|
async function loadValueFile(interfaceValueFile, configName, userRootDir) {
|
|
138
139
|
const { fileExports } = await transpileAndExecuteFile(interfaceValueFile.filePath, true, userRootDir);
|
|
139
140
|
const { filePathToShowToUser } = interfaceValueFile.filePath;
|
|
140
|
-
|
|
141
|
+
assertPlusFileExport(fileExports, filePathToShowToUser, configName);
|
|
141
142
|
Object.entries(fileExports).forEach(([exportName, configValue]) => {
|
|
142
143
|
const configName_ = exportName === 'default' ? configName : exportName;
|
|
143
144
|
interfaceValueFile.configMap[configName_] = { configValue };
|
|
@@ -169,9 +170,8 @@ function getInterfaceFileFromConfigFile(configFile, isConfigExtend) {
|
|
|
169
170
|
isConfigExtend,
|
|
170
171
|
extendsFilePaths
|
|
171
172
|
};
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
Object.entries(fileExports.default).forEach(([configName, configValue]) => {
|
|
173
|
+
const fileExport = getConfigFileExport(fileExports, filePath.filePathToShowToUser);
|
|
174
|
+
Object.entries(fileExport).forEach(([configName, configValue]) => {
|
|
175
175
|
interfaceFile.configMap[configName] = { configValue };
|
|
176
176
|
});
|
|
177
177
|
return interfaceFile;
|
|
@@ -920,18 +920,17 @@ function assertExtendsImportPath(importPath, filePath, configFilePath) {
|
|
|
920
920
|
}
|
|
921
921
|
function getExtendsImportData(configFileExports, configFilePath) {
|
|
922
922
|
const { filePathToShowToUser } = configFilePath;
|
|
923
|
-
|
|
924
|
-
const defaultExports = configFileExports.default;
|
|
923
|
+
const configFileExport = getConfigFileExport(configFileExports, filePathToShowToUser);
|
|
925
924
|
const wrongUsage = `${filePathToShowToUser} sets the config ${pc.cyan('extends')} to an invalid value, see https://vike.dev/extends`;
|
|
926
925
|
let extendList;
|
|
927
|
-
if (!('extends' in
|
|
926
|
+
if (!('extends' in configFileExport)) {
|
|
928
927
|
return [];
|
|
929
928
|
}
|
|
930
|
-
else if (hasProp(
|
|
931
|
-
extendList = [
|
|
929
|
+
else if (hasProp(configFileExport, 'extends', 'string')) {
|
|
930
|
+
extendList = [configFileExport.extends];
|
|
932
931
|
}
|
|
933
|
-
else if (hasProp(
|
|
934
|
-
extendList =
|
|
932
|
+
else if (hasProp(configFileExport, 'extends', 'string[]')) {
|
|
933
|
+
extendList = configFileExport.extends;
|
|
935
934
|
}
|
|
936
935
|
else {
|
|
937
936
|
assertUsage(false, wrongUsage);
|
|
@@ -11,7 +11,7 @@ import { assertPosixPath, getRandomId, assertIsNotProductionRuntime, assert, uni
|
|
|
11
11
|
import { isImportData, replaceImportStatements } from './replaceImportStatements.js';
|
|
12
12
|
import { vikeConfigDependencies } from './getVikeConfig.js';
|
|
13
13
|
import 'source-map-support/register.js';
|
|
14
|
-
import {
|
|
14
|
+
import { getConfigFileExport } from './getConfigFileExport.js';
|
|
15
15
|
assertIsNotProductionRuntime();
|
|
16
16
|
async function transpileAndExecuteFile(filePath, isValueFile, userRootDir) {
|
|
17
17
|
const { code, fileImports } = await transpileFile(filePath, isValueFile, userRootDir);
|
|
@@ -206,8 +206,8 @@ function isTmpFile(filePath) {
|
|
|
206
206
|
return fileName.startsWith(tmpPrefix);
|
|
207
207
|
}
|
|
208
208
|
function assertImportsAreReExported(fileImports, fileExports, filePathToShowToUser) {
|
|
209
|
-
|
|
210
|
-
const exportedStrings = getExportedStrings(
|
|
209
|
+
const fileExport = getConfigFileExport(fileExports, filePathToShowToUser);
|
|
210
|
+
const exportedStrings = getExportedStrings(fileExport);
|
|
211
211
|
Object.values(exportedStrings).forEach((exportVal) => {
|
|
212
212
|
if (typeof exportVal !== 'string')
|
|
213
213
|
return;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { previewConfig };
|
|
2
|
-
import { assertUsage, getOutDirs, resolveOutDir,
|
|
2
|
+
import { assertUsage, getOutDirs, resolveOutDir, markEnvAsVitePreview } from '../utils.js';
|
|
3
3
|
import { getConfigVike } from '../../shared/getConfigVike.js';
|
|
4
4
|
import fs from 'fs';
|
|
5
5
|
import path from 'path';
|
|
@@ -28,7 +28,7 @@ function previewConfig() {
|
|
|
28
28
|
- This ugly hack to set appType for preview won't be need once https://github.com/vitejs/vite/pull/14855 is merged.
|
|
29
29
|
config.appType = 'mpa'
|
|
30
30
|
*/
|
|
31
|
-
|
|
31
|
+
markEnvAsVitePreview();
|
|
32
32
|
return () => {
|
|
33
33
|
assertDist();
|
|
34
34
|
/* We don't use this condition (we wrongfully always use the SSR middleware) because of the regression introduced by https://github.com/vitejs/vite/pull/14756 which stops servering .html files when `appType: 'custom'`.
|
|
@@ -20,10 +20,10 @@ function logWithVikeTag(msg, logType, category, showVikeVersion = false) {
|
|
|
20
20
|
function getProjectTag(showVikeVersion) {
|
|
21
21
|
let projectTag;
|
|
22
22
|
if (showVikeVersion) {
|
|
23
|
-
projectTag = `[
|
|
23
|
+
projectTag = `[vike@${projectInfo.projectVersion}]`;
|
|
24
24
|
}
|
|
25
25
|
else {
|
|
26
|
-
projectTag = `[
|
|
26
|
+
projectTag = `[vike]`;
|
|
27
27
|
}
|
|
28
28
|
return projectTag;
|
|
29
29
|
}
|
|
@@ -83,7 +83,7 @@ function prependTags(msg, projectTag, category, logType) {
|
|
|
83
83
|
return pc.yellow(s);
|
|
84
84
|
if (projectTag === '[vite]')
|
|
85
85
|
return pc.bold(pc.cyan(s));
|
|
86
|
-
if (projectTag.startsWith(`[
|
|
86
|
+
if (projectTag.startsWith(`[vike`))
|
|
87
87
|
return pc.bold(pc.cyan(s));
|
|
88
88
|
assert(false);
|
|
89
89
|
};
|
|
@@ -6,7 +6,7 @@ export { setGlobalContext_viteDevServer };
|
|
|
6
6
|
export { setGlobalContext_vitePreviewServer };
|
|
7
7
|
export { setGlobalContext_viteConfig };
|
|
8
8
|
export { getRuntimeManifest };
|
|
9
|
-
import { assert, assertUsage,
|
|
9
|
+
import { assert, assertUsage, getGlobalObject, getNodeEnv, isNodeEnvDev, isPlainObject, objectAssign } from './utils.js';
|
|
10
10
|
import { loadImportBuild } from './globalContext/loadImportBuild.js';
|
|
11
11
|
import { setPageFiles } from '../../shared/getPageFiles.js';
|
|
12
12
|
import { assertPluginManifest } from '../shared/assertPluginManifest.js';
|
|
@@ -151,7 +151,8 @@ function assertNodeEnv(hasViteDevServer) {
|
|
|
151
151
|
const nodeEnv = getNodeEnv();
|
|
152
152
|
if (nodeEnv === null || nodeEnv === 'test')
|
|
153
153
|
return;
|
|
154
|
-
const isDevNodeEnv =
|
|
155
|
-
//
|
|
156
|
-
|
|
154
|
+
const isDevNodeEnv = isNodeEnvDev();
|
|
155
|
+
// - Calling Vite's createServer() is enough for hasViteDevServer to be true, even without actually adding Vite's development middleware to the server: https://github.com/vikejs/vike/issues/792#issuecomment-1516830759
|
|
156
|
+
// - We should change this to be a warning if it blocks users (e.g. if a bad-citizen tool sets a wrong process.env.NODE_ENV value).
|
|
157
|
+
assertUsage(hasViteDevServer === isDevNodeEnv, `Vite's development server was${hasViteDevServer ? '' : "n't"} instantiated while the environment is set to be a ${isDevNodeEnv ? 'development' : 'production'} environment by ${pc.cyan(`process.env.NODE_ENV === ${JSON.stringify(nodeEnv)}`)} which is contradictory, see https://vike.dev/NODE_ENV`);
|
|
157
158
|
}
|
|
@@ -53,6 +53,10 @@ type PageConfigGlobalRuntime = {
|
|
|
53
53
|
type PageConfigGlobalBuildTime = {
|
|
54
54
|
configValueSources: ConfigValueSources;
|
|
55
55
|
};
|
|
56
|
+
/** In what environment(s) the config value is loaded.
|
|
57
|
+
*
|
|
58
|
+
* https://vike.dev/meta
|
|
59
|
+
*/
|
|
56
60
|
type ConfigEnv = {
|
|
57
61
|
client?: boolean;
|
|
58
62
|
server?: boolean;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export { assertPlusFileExport };
|
|
2
|
+
import { assert, assertUsage, assertWarning } from '../utils.js';
|
|
3
|
+
import pc from '@brillout/picocolors';
|
|
4
|
+
const EXPORTS_IGNORE = [
|
|
5
|
+
// vite-plugin-solid adds `export { $$registrations }`
|
|
6
|
+
'$$registrations',
|
|
7
|
+
// @vitejs/plugin-vue adds `export { _rerender_only }`
|
|
8
|
+
'_rerender_only'
|
|
9
|
+
];
|
|
10
|
+
// Tolerate `export { frontmatter }` in .mdx files
|
|
11
|
+
const TOLERATE_SIDE_EXPORTS = ['.md', '.mdx'];
|
|
12
|
+
function assertPlusFileExport(fileExports, filePathToShowToUser, configName) {
|
|
13
|
+
const exportsAll = Object.keys(fileExports).filter((exportName) => !EXPORTS_IGNORE.includes(exportName));
|
|
14
|
+
const exportsInvalid = exportsAll.filter((e) => e !== 'default' && e !== configName);
|
|
15
|
+
if (exportsInvalid.length === 0) {
|
|
16
|
+
if (exportsAll.length === 1) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const exportDefault = pc.cyan('export default');
|
|
20
|
+
const exportNamed = pc.cyan(`export { ${configName} }`);
|
|
21
|
+
if (exportsAll.length === 0) {
|
|
22
|
+
assertUsage(false, `${filePathToShowToUser} doesn't export any value, but it should have a ${exportNamed} or ${exportDefault}`);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
assert(exportsAll.length === 2); // because `exportsInvalid.length === 0`
|
|
26
|
+
assertWarning(false, `${filePathToShowToUser} remove ${exportNamed} or ${exportDefault}`, {
|
|
27
|
+
onlyOnce: true
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
if (TOLERATE_SIDE_EXPORTS.some((ext) => filePathToShowToUser.endsWith(ext)))
|
|
33
|
+
return;
|
|
34
|
+
exportsInvalid.forEach((exportInvalid) => {
|
|
35
|
+
assertWarning(false, `${filePathToShowToUser} should have only one export: move ${pc.cyan(`export { ${exportInvalid} }`)} to its own +${exportsInvalid}.js file`, { onlyOnce: true });
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { parseConfigValuesImported };
|
|
2
2
|
import { assert } from '../../utils.js';
|
|
3
|
-
import {
|
|
3
|
+
import { assertPlusFileExport } from '../assertPlusFileExport.js';
|
|
4
4
|
function parseConfigValuesImported(configValuesImported) {
|
|
5
5
|
const configValues = {};
|
|
6
6
|
const addConfigValue = (configName, value, importPath, exportName) => {
|
|
@@ -21,7 +21,7 @@ function parseConfigValuesImported(configValuesImported) {
|
|
|
21
21
|
if (configValueLoaded.isValueFile) {
|
|
22
22
|
const { exportValues, importPath, configName } = configValueLoaded;
|
|
23
23
|
if (configName !== 'client') {
|
|
24
|
-
|
|
24
|
+
assertPlusFileExport(exportValues, importPath, configName);
|
|
25
25
|
}
|
|
26
26
|
Object.entries(exportValues).forEach(([exportName, exportValue]) => {
|
|
27
27
|
const isSideExport = exportName !== 'default'; // .md files may have "side-exports" such as `export { frontmatter }`
|
|
@@ -7,7 +7,7 @@ export { logAbortErrorHandled };
|
|
|
7
7
|
export { getPageContextFromAllRewrites };
|
|
8
8
|
export { AbortRender };
|
|
9
9
|
export { assertNoInfiniteAbortLoop };
|
|
10
|
-
import { assert, assertInfo, assertUsage, assertWarning, checkType, hasProp, isUriWithProtocol, isUserHookError, joinEnglish, objectAssign,
|
|
10
|
+
import { assert, assertInfo, assertUsage, assertWarning, checkType, hasProp, isUriWithProtocol, isUserHookError, joinEnglish, objectAssign, truncateString } from './utils.js';
|
|
11
11
|
import pc from '@brillout/picocolors';
|
|
12
12
|
/**
|
|
13
13
|
* Abort the rendering of the current page, and redirect the user to another URL instead.
|
|
@@ -132,7 +132,7 @@ function logAbortErrorHandled(err, isProduction, pageContext) {
|
|
|
132
132
|
}
|
|
133
133
|
function assertStatusCode(statusCode, expected, caller) {
|
|
134
134
|
const expectedEnglish = joinEnglish(expected.map((s) => s.toString()), 'or');
|
|
135
|
-
assertWarning(expected.includes(statusCode), `Unepexected status code ${statusCode} passed to ${caller}(), we recommend ${expectedEnglish} instead. (Or reach out at
|
|
135
|
+
assertWarning(expected.includes(statusCode), `Unepexected status code ${statusCode} passed to ${caller}(), we recommend ${expectedEnglish} instead. (Or reach out at https://github.com/vikejs/vike/issues/1008 if you believe ${statusCode} should be added.)`, { onlyOnce: true });
|
|
136
136
|
}
|
|
137
137
|
function getPageContextFromAllRewrites(pageContextsFromRewrite) {
|
|
138
138
|
assertNoInfiniteLoop(pageContextsFromRewrite);
|
package/dist/esm/utils/assert.js
CHANGED
|
@@ -25,8 +25,8 @@ const globalObject = getGlobalObject('utils/assert.ts', {
|
|
|
25
25
|
},
|
|
26
26
|
showStackTraceList: new WeakSet()
|
|
27
27
|
});
|
|
28
|
-
const projectTag = `[
|
|
29
|
-
const projectTagWithVersion = `[
|
|
28
|
+
const projectTag = `[vike]`;
|
|
29
|
+
const projectTagWithVersion = `[vike@${projectInfo.projectVersion}]`;
|
|
30
30
|
const numberOfStackTraceLinesToRemove = 2;
|
|
31
31
|
function assert(condition, debugInfo) {
|
|
32
32
|
if (condition)
|
|
@@ -36,12 +36,11 @@ function assert(condition, debugInfo) {
|
|
|
36
36
|
return null;
|
|
37
37
|
}
|
|
38
38
|
const debugInfoSerialized = typeof debugInfo === 'string' ? debugInfo : JSON.stringify(debugInfo);
|
|
39
|
-
return pc.dim(`Debug info (for
|
|
39
|
+
return pc.dim(`Debug info (for Vike maintainers; you can ignore this): ${debugInfoSerialized}`);
|
|
40
40
|
})();
|
|
41
|
-
const link = `${projectInfo.githubRepository}/issues/new`;
|
|
42
41
|
let errMsg = [
|
|
43
|
-
`You stumbled upon a bug
|
|
44
|
-
`Go to ${pc.blue(
|
|
42
|
+
`You stumbled upon a Vike bug.`,
|
|
43
|
+
`Go to ${pc.blue('https://github.com/vikejs/vike/issues/new')} and copy-paste this error. A maintainer will fix the bug (usually under 24 hours).`,
|
|
45
44
|
debugStr
|
|
46
45
|
]
|
|
47
46
|
.filter(Boolean)
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
export { assertIsNotProductionRuntime };
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
2
|
+
export { markEnvAsViteDev };
|
|
3
|
+
export { markEnvAsVitePreview };
|
|
4
|
+
export { markEnvAsVikePluginLoaded };
|
|
5
5
|
export { assertEnv };
|
|
6
|
+
export { vikeVitePluginLoadedInProductionError };
|
|
7
|
+
declare const vikeVitePluginLoadedInProductionError = "Loading Vike's Vite plugin (the vike/plugin module) is prohibited in production.";
|
|
6
8
|
declare function assertIsNotProductionRuntime(): void | undefined;
|
|
7
|
-
declare function
|
|
8
|
-
declare function
|
|
9
|
-
declare function
|
|
9
|
+
declare function markEnvAsViteDev(): void | undefined;
|
|
10
|
+
declare function markEnvAsVitePreview(): void | undefined;
|
|
11
|
+
declare function markEnvAsVikePluginLoaded(): void;
|
|
10
12
|
declare function assertEnv(): void | undefined;
|
|
@@ -1,41 +1,59 @@
|
|
|
1
1
|
// Mechanism to ensure code isn't loaded by production runtime
|
|
2
2
|
export { assertIsNotProductionRuntime };
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
3
|
+
export { markEnvAsViteDev };
|
|
4
|
+
export { markEnvAsVitePreview };
|
|
5
|
+
export { markEnvAsVikePluginLoaded };
|
|
6
6
|
export { assertEnv };
|
|
7
|
-
|
|
7
|
+
export { vikeVitePluginLoadedInProductionError };
|
|
8
|
+
import { assert, assertUsage } from './assert.js';
|
|
8
9
|
import { assertIsNotBrowser } from './assertIsNotBrowser.js';
|
|
10
|
+
import { createDebugger } from './debug.js';
|
|
9
11
|
import { getGlobalObject } from './getGlobalObject.js';
|
|
10
12
|
import { isVitest } from './isVitest.js';
|
|
11
13
|
assertIsNotBrowser();
|
|
14
|
+
const debug = createDebugger('vike:setup');
|
|
15
|
+
const vikeVitePluginLoadedInProductionError = `Loading Vike's Vite plugin (the vike/plugin module) is prohibited in production.`;
|
|
12
16
|
const env = getGlobalObject('utils/assertIsNotProductionRuntime.ts', {});
|
|
13
|
-
// Called by
|
|
17
|
+
// Called by Vike modules that want to ensure that they aren't loaded by the server runtime in production
|
|
14
18
|
function assertIsNotProductionRuntime() {
|
|
15
|
-
|
|
19
|
+
if (debug.isEnabled)
|
|
20
|
+
debug('assertIsNotProductionRuntime()', new Error().stack);
|
|
21
|
+
env.shouldNotBeProduction = true;
|
|
16
22
|
}
|
|
17
23
|
// Called by Vite hook configureServer()
|
|
18
|
-
function
|
|
19
|
-
|
|
24
|
+
function markEnvAsViteDev() {
|
|
25
|
+
if (debug.isEnabled)
|
|
26
|
+
debug('markEnvAsViteDev()', new Error().stack);
|
|
27
|
+
env.isViteDev = true;
|
|
20
28
|
}
|
|
21
29
|
// Called by Vite hook configurePreviewServer()
|
|
22
|
-
function
|
|
23
|
-
|
|
30
|
+
function markEnvAsVitePreview() {
|
|
31
|
+
if (debug.isEnabled)
|
|
32
|
+
debug('markEnvAsVitePreview()', new Error().stack);
|
|
33
|
+
env.isVitePreview = true;
|
|
24
34
|
}
|
|
25
35
|
// Called by ../node/plugin/index.ts
|
|
26
|
-
function
|
|
27
|
-
|
|
36
|
+
function markEnvAsVikePluginLoaded() {
|
|
37
|
+
if (debug.isEnabled)
|
|
38
|
+
debug('markEnvAsVikePluginLoaded()', new Error().stack);
|
|
39
|
+
env.isVikePluginLoaded = true;
|
|
28
40
|
}
|
|
29
41
|
// Called by ../node/runtime/index.ts
|
|
30
42
|
function assertEnv() {
|
|
43
|
+
if (debug.isEnabled)
|
|
44
|
+
debug('assertEnv()', new Error().stack);
|
|
31
45
|
if (isVitest())
|
|
32
46
|
return;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
assert(env.
|
|
47
|
+
const isProduction = !env.isViteDev && !env.isVitePreview;
|
|
48
|
+
if (isProduction) {
|
|
49
|
+
// Seems to be the only reliable way to assert that the user doesn't load Vike's Vite plugin in production. (The other assert() that uses process.env.NODE_ENV doesn't work if the user sets the process.env.NODE_ENV value later.)
|
|
50
|
+
assertUsage(!env.isVikePluginLoaded, vikeVitePluginLoadedInProductionError);
|
|
51
|
+
// This assert() is the main goal of this file: it ensures assertIsNotProductionRuntime()
|
|
52
|
+
assert(!env.shouldNotBeProduction);
|
|
36
53
|
}
|
|
37
54
|
else {
|
|
38
|
-
assert(
|
|
39
|
-
assert(
|
|
55
|
+
// This assert() is obious and boring
|
|
56
|
+
assert(env.shouldNotBeProduction);
|
|
57
|
+
assert(env.isVikePluginLoaded);
|
|
40
58
|
}
|
|
41
59
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { createDebugger };
|
|
2
2
|
export { isDebugEnabled };
|
|
3
3
|
export type { Debug };
|
|
4
|
-
type Flag = 'vike:routing' | 'vike:error' | 'vike:stream' | 'vike:log' | 'vike:virtual-files' | 'vike:outDir' | 'vike:extractExportNames' | 'vike:extractAssets' | 'vike:glob' | 'vike:pageFiles' | 'vike:stem';
|
|
4
|
+
type Flag = 'vike:routing' | 'vike:error' | 'vike:stream' | 'vike:log' | 'vike:virtual-files' | 'vike:outDir' | 'vike:extractExportNames' | 'vike:extractAssets' | 'vike:glob' | 'vike:pageFiles' | 'vike:stem' | 'vike:setup';
|
|
5
5
|
type Debug = ReturnType<typeof createDebugger>;
|
|
6
6
|
type Options = {
|
|
7
7
|
serialization?: {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { getNodeEnv };
|
|
2
2
|
export { setNodeEnvToProduction };
|
|
3
|
+
export { isNodeEnvDev };
|
|
3
4
|
function getNodeEnv() {
|
|
4
5
|
if (typeof process === 'undefined')
|
|
5
6
|
return null;
|
|
@@ -11,3 +12,12 @@ function setNodeEnvToProduction() {
|
|
|
11
12
|
const { env } = proc;
|
|
12
13
|
env.NODE_ENV = 'production';
|
|
13
14
|
}
|
|
15
|
+
function isNodeEnvDev() {
|
|
16
|
+
const nodeEnv = getNodeEnv();
|
|
17
|
+
if (!nodeEnv)
|
|
18
|
+
return true;
|
|
19
|
+
if (['development', 'dev'].includes(nodeEnv))
|
|
20
|
+
return true;
|
|
21
|
+
// That's quite aggressive, let's see if some user complains
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
export { projectInfo };
|
|
2
|
-
export type { ProjectTag };
|
|
3
2
|
export { PROJECT_VERSION };
|
|
4
|
-
declare const PROJECT_VERSION: "0.4.
|
|
5
|
-
type PackageName = typeof projectInfo.npmPackageName;
|
|
6
|
-
type ProjectVersion = typeof projectInfo.projectVersion;
|
|
7
|
-
type ProjectTag = `[${PackageName}]` | `[${PackageName}@${ProjectVersion}]`;
|
|
3
|
+
declare const PROJECT_VERSION: "0.4.159-commit-6bcb2fd";
|
|
8
4
|
declare const projectInfo: {
|
|
9
5
|
projectName: "Vike";
|
|
10
|
-
projectVersion: "0.4.
|
|
11
|
-
npmPackageName: "vike";
|
|
12
|
-
githubRepository: "https://github.com/vikejs/vike";
|
|
6
|
+
projectVersion: "0.4.159-commit-6bcb2fd";
|
|
13
7
|
};
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
export { projectInfo };
|
|
2
2
|
export { PROJECT_VERSION };
|
|
3
3
|
import { onProjectInfo } from './assertSingleInstance.js';
|
|
4
|
-
const PROJECT_VERSION = '0.4.
|
|
4
|
+
const PROJECT_VERSION = '0.4.159-commit-6bcb2fd';
|
|
5
5
|
const projectInfo = {
|
|
6
6
|
projectName: 'Vike',
|
|
7
|
-
projectVersion: PROJECT_VERSION
|
|
8
|
-
npmPackageName: 'vike',
|
|
9
|
-
githubRepository: 'https://github.com/vikejs/vike'
|
|
7
|
+
projectVersion: PROJECT_VERSION
|
|
10
8
|
};
|
|
11
9
|
// Trick: since `utils/asserts.ts` depends on this file (`utils/projectInfo.ts`), we can have confidence that this file is always instantiated. So that we don't have to initialize this code snippet at every possible entry. (There are a *lot* of entries: `client/router/`, `client/`, `node/`, `node/plugin/`, `node/cli`, etc.)
|
|
12
10
|
onProjectInfo(projectInfo.projectVersion);
|
package/package.json
CHANGED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.assertExportsOfConfigFile = exports.assertExportsOfValueFile = void 0;
|
|
7
|
-
const utils_js_1 = require("../utils.js");
|
|
8
|
-
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
9
|
-
const EXPORTS_IGNORE = [
|
|
10
|
-
// vite-plugin-solid adds `export { $$registrations }`
|
|
11
|
-
'$$registrations',
|
|
12
|
-
// @vitejs/plugin-vue adds `export { _rerender_only }`
|
|
13
|
-
'_rerender_only'
|
|
14
|
-
];
|
|
15
|
-
// Tolerate `export { frontmatter }` in .mdx files
|
|
16
|
-
const TOLERATE_SIDE_EXPORTS = ['.md', '.mdx'];
|
|
17
|
-
function assertExportsOfValueFile(fileExports, filePathToShowToUser, configName) {
|
|
18
|
-
assertExports(fileExports, filePathToShowToUser, configName);
|
|
19
|
-
}
|
|
20
|
-
exports.assertExportsOfValueFile = assertExportsOfValueFile;
|
|
21
|
-
function assertExportsOfConfigFile(fileExports, filePathToShowToUser) {
|
|
22
|
-
assertExports(fileExports, filePathToShowToUser);
|
|
23
|
-
const exportDefault = fileExports.default;
|
|
24
|
-
(0, utils_js_1.assertUsage)((0, utils_js_1.isObject)(exportDefault), `The ${picocolors_1.default.cyan('export default')} of ${filePathToShowToUser} should be an object (but it's ${picocolors_1.default.cyan(`typeof exportDefault === ${JSON.stringify(typeof exportDefault)}`)} instead)`);
|
|
25
|
-
}
|
|
26
|
-
exports.assertExportsOfConfigFile = assertExportsOfConfigFile;
|
|
27
|
-
function assertExports(fileExports, filePathToShowToUser, configName) {
|
|
28
|
-
const exportsAll = Object.keys(fileExports);
|
|
29
|
-
const exportsRelevant = exportsAll.filter((exportName) => !EXPORTS_IGNORE.includes(exportName));
|
|
30
|
-
const exportsInvalid = exportsRelevant.filter((e) => e !== 'default' &&
|
|
31
|
-
// !!configName => isValueFile
|
|
32
|
-
e !== configName);
|
|
33
|
-
if (exportsInvalid.length === 0) {
|
|
34
|
-
if (exportsRelevant.length === 1) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
const exportDefault = picocolors_1.default.cyan('export default');
|
|
38
|
-
const exportConfigName = picocolors_1.default.cyan(`export { ${configName} }`);
|
|
39
|
-
if (exportsRelevant.length === 0) {
|
|
40
|
-
let errMsg = `${filePathToShowToUser} doesn't export any value, but it should have a ${exportDefault}`;
|
|
41
|
-
if (configName)
|
|
42
|
-
errMsg += ` or ${exportConfigName}`;
|
|
43
|
-
(0, utils_js_1.assertUsage)(false, errMsg);
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
(0, utils_js_1.assert)(exportsRelevant.length === 2);
|
|
47
|
-
(0, utils_js_1.assertWarning)(false, `${filePathToShowToUser} remove ${exportConfigName} or ${exportDefault}`, {
|
|
48
|
-
onlyOnce: true
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
// !configName => isConfigFile
|
|
54
|
-
if (!configName) {
|
|
55
|
-
const exportsInvalidStr = exportsInvalid.join(', ');
|
|
56
|
-
(0, utils_js_1.assertUsage)(false, `${filePathToShowToUser} replace ${picocolors_1.default.cyan(`export { ${exportsInvalidStr} }`)} with ${picocolors_1.default.cyan(`export default { ${exportsInvalidStr} }`)}`);
|
|
57
|
-
}
|
|
58
|
-
// !!configName => isValueFile
|
|
59
|
-
else {
|
|
60
|
-
if (TOLERATE_SIDE_EXPORTS.some((ext) => filePathToShowToUser.endsWith(ext)))
|
|
61
|
-
return;
|
|
62
|
-
exportsInvalid.forEach((exportInvalid) => {
|
|
63
|
-
(0, utils_js_1.assertWarning)(false, `${filePathToShowToUser} should have only a single export: move ${picocolors_1.default.cyan(`export { ${exportInvalid} }`)} to +config.h.js or its own +${exportsInvalid}.js`, { onlyOnce: true });
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export { assertExportsOfValueFile };
|
|
2
|
-
export { assertExportsOfConfigFile };
|
|
3
|
-
declare function assertExportsOfValueFile(fileExports: Record<string, unknown>, filePathToShowToUser: string, configName: string): void;
|
|
4
|
-
declare function assertExportsOfConfigFile(fileExports: Record<string, unknown>, filePathToShowToUser: string): asserts fileExports is {
|
|
5
|
-
default: Record<string, unknown>;
|
|
6
|
-
};
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
export { assertExportsOfValueFile };
|
|
2
|
-
export { assertExportsOfConfigFile };
|
|
3
|
-
import { assert, assertUsage, assertWarning, isObject } from '../utils.js';
|
|
4
|
-
import pc from '@brillout/picocolors';
|
|
5
|
-
const EXPORTS_IGNORE = [
|
|
6
|
-
// vite-plugin-solid adds `export { $$registrations }`
|
|
7
|
-
'$$registrations',
|
|
8
|
-
// @vitejs/plugin-vue adds `export { _rerender_only }`
|
|
9
|
-
'_rerender_only'
|
|
10
|
-
];
|
|
11
|
-
// Tolerate `export { frontmatter }` in .mdx files
|
|
12
|
-
const TOLERATE_SIDE_EXPORTS = ['.md', '.mdx'];
|
|
13
|
-
function assertExportsOfValueFile(fileExports, filePathToShowToUser, configName) {
|
|
14
|
-
assertExports(fileExports, filePathToShowToUser, configName);
|
|
15
|
-
}
|
|
16
|
-
function assertExportsOfConfigFile(fileExports, filePathToShowToUser) {
|
|
17
|
-
assertExports(fileExports, filePathToShowToUser);
|
|
18
|
-
const exportDefault = fileExports.default;
|
|
19
|
-
assertUsage(isObject(exportDefault), `The ${pc.cyan('export default')} of ${filePathToShowToUser} should be an object (but it's ${pc.cyan(`typeof exportDefault === ${JSON.stringify(typeof exportDefault)}`)} instead)`);
|
|
20
|
-
}
|
|
21
|
-
function assertExports(fileExports, filePathToShowToUser, configName) {
|
|
22
|
-
const exportsAll = Object.keys(fileExports);
|
|
23
|
-
const exportsRelevant = exportsAll.filter((exportName) => !EXPORTS_IGNORE.includes(exportName));
|
|
24
|
-
const exportsInvalid = exportsRelevant.filter((e) => e !== 'default' &&
|
|
25
|
-
// !!configName => isValueFile
|
|
26
|
-
e !== configName);
|
|
27
|
-
if (exportsInvalid.length === 0) {
|
|
28
|
-
if (exportsRelevant.length === 1) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
const exportDefault = pc.cyan('export default');
|
|
32
|
-
const exportConfigName = pc.cyan(`export { ${configName} }`);
|
|
33
|
-
if (exportsRelevant.length === 0) {
|
|
34
|
-
let errMsg = `${filePathToShowToUser} doesn't export any value, but it should have a ${exportDefault}`;
|
|
35
|
-
if (configName)
|
|
36
|
-
errMsg += ` or ${exportConfigName}`;
|
|
37
|
-
assertUsage(false, errMsg);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
assert(exportsRelevant.length === 2);
|
|
41
|
-
assertWarning(false, `${filePathToShowToUser} remove ${exportConfigName} or ${exportDefault}`, {
|
|
42
|
-
onlyOnce: true
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
// !configName => isConfigFile
|
|
48
|
-
if (!configName) {
|
|
49
|
-
const exportsInvalidStr = exportsInvalid.join(', ');
|
|
50
|
-
assertUsage(false, `${filePathToShowToUser} replace ${pc.cyan(`export { ${exportsInvalidStr} }`)} with ${pc.cyan(`export default { ${exportsInvalidStr} }`)}`);
|
|
51
|
-
}
|
|
52
|
-
// !!configName => isValueFile
|
|
53
|
-
else {
|
|
54
|
-
if (TOLERATE_SIDE_EXPORTS.some((ext) => filePathToShowToUser.endsWith(ext)))
|
|
55
|
-
return;
|
|
56
|
-
exportsInvalid.forEach((exportInvalid) => {
|
|
57
|
-
assertWarning(false, `${filePathToShowToUser} should have only a single export: move ${pc.cyan(`export { ${exportInvalid} }`)} to +config.h.js or its own +${exportsInvalid}.js`, { onlyOnce: true });
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|