vike 0.4.159 → 0.4.160-commit-30d535e
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/autoFullBuild.js +2 -2
- package/dist/cjs/node/plugin/plugins/buildConfig.js +9 -0
- package/dist/cjs/node/plugin/plugins/commonConfig.js +1 -1
- package/dist/cjs/node/plugin/plugins/config/stemUtils.js +1 -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/crawlPlusFiles.js +1 -5
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +28 -46
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +129 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.js +33 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +139 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/{replaceImportStatements.js → getVikeConfig/transformFileImports.js} +44 -13
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/{transpileAndExecuteFile.js → getVikeConfig/transpileAndExecuteFile.js} +105 -78
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +201 -382
- package/dist/cjs/node/plugin/plugins/previewConfig.js +1 -1
- package/dist/cjs/node/plugin/shared/getHttpRequestAsyncStore.js +1 -1
- package/dist/cjs/node/plugin/shared/loggerNotProd/log.js +3 -3
- package/dist/cjs/node/plugin/shared/loggerNotProd.js +1 -1
- package/dist/cjs/node/plugin/utils.js +1 -2
- package/dist/cjs/node/prerender/runPrerender.js +12 -5
- package/dist/cjs/node/runtime/globalContext.js +7 -3
- package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +2 -2
- package/dist/cjs/node/runtime/html/renderHtml.js +1 -1
- package/dist/cjs/node/runtime/html/stream.js +2 -2
- package/dist/cjs/node/runtime/renderPage/executeOnRenderHtmlHook.js +2 -2
- package/dist/cjs/node/runtime/renderPage/getHttpResponseBody.js +1 -1
- package/dist/cjs/node/runtime/renderPage/loadUserFilesServerSide.js +1 -1
- package/dist/cjs/node/runtime/renderPage/{logHintForCjsEsmError.js → logErrorHint.js} +81 -43
- package/dist/cjs/node/runtime/renderPage/loggerProd.js +3 -3
- package/dist/cjs/node/runtime/utils.js +1 -1
- package/dist/cjs/shared/page-configs/assertPlusFileExport.js +44 -0
- package/dist/cjs/shared/page-configs/serialize/parseConfigValuesImported.js +54 -27
- package/dist/cjs/shared/route/abort.js +1 -1
- package/dist/cjs/shared/route/executeGuardHook.js +3 -2
- package/dist/cjs/shared/utils.js +0 -1
- package/dist/cjs/utils/assert.js +5 -6
- package/dist/cjs/utils/assertIsNotProductionRuntime.js +35 -17
- package/dist/cjs/utils/{findUserPackageJsonPath.js → findFile.js} +11 -8
- package/dist/cjs/utils/nodeEnv.js +33 -1
- package/dist/cjs/utils/objectKeys.js +19 -3
- package/dist/cjs/utils/projectInfo.js +2 -4
- package/dist/cjs/utils/sorter.js +62 -1
- package/dist/esm/node/plugin/index.js +21 -2
- package/dist/esm/node/plugin/plugins/autoFullBuild.js +2 -2
- package/dist/esm/node/plugin/plugins/buildConfig.js +10 -1
- package/dist/esm/node/plugin/plugins/commonConfig.js +2 -2
- package/dist/esm/node/plugin/plugins/config/stemUtils.js +2 -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 +8 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.d.ts +0 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +1 -5
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.d.ts +39 -12
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +29 -47
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.d.ts +21 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +123 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.d.ts +5 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.js +27 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.d.ts +12 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +133 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{replaceImportStatements.d.ts → getVikeConfig/transformFileImports.d.ts} +5 -5
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{replaceImportStatements.js → getVikeConfig/transformFileImports.js} +43 -12
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{transpileAndExecuteFile.d.ts → getVikeConfig/transpileAndExecuteFile.d.ts} +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{transpileAndExecuteFile.js → getVikeConfig/transpileAndExecuteFile.js} +105 -78
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +16 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +199 -380
- package/dist/esm/node/plugin/plugins/previewConfig.js +2 -2
- package/dist/esm/node/plugin/shared/getHttpRequestAsyncStore.js +1 -1
- package/dist/esm/node/plugin/shared/loggerNotProd/log.js +3 -3
- package/dist/esm/node/plugin/shared/loggerNotProd.js +1 -1
- 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 -6
- package/dist/esm/node/runtime/globalContext.js +8 -4
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +2 -2
- package/dist/esm/node/runtime/html/renderHtml.js +1 -1
- package/dist/esm/node/runtime/html/stream.js +2 -2
- package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.js +2 -2
- package/dist/esm/node/runtime/renderPage/getHttpResponseBody.js +1 -1
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.js +1 -1
- package/dist/esm/node/runtime/renderPage/logErrorHint.d.ts +8 -0
- package/dist/esm/node/runtime/renderPage/{logHintForCjsEsmError.js → logErrorHint.js} +80 -42
- package/dist/esm/node/runtime/renderPage/loggerProd.js +3 -3
- package/dist/esm/node/runtime/utils.d.ts +1 -1
- package/dist/esm/node/runtime/utils.js +1 -1
- package/dist/esm/shared/page-configs/Config.d.ts +1 -1
- package/dist/esm/shared/page-configs/PageConfig.d.ts +6 -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 +54 -27
- package/dist/esm/shared/route/abort.js +2 -2
- package/dist/esm/shared/route/executeGuardHook.js +3 -2
- package/dist/esm/shared/utils.d.ts +0 -1
- package/dist/esm/shared/utils.js +0 -1
- 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/findFile.d.ts +3 -0
- package/dist/esm/utils/findFile.js +21 -0
- package/dist/esm/utils/nodeEnv.d.ts +6 -0
- package/dist/esm/utils/nodeEnv.js +29 -0
- package/dist/esm/utils/objectKeys.d.ts +10 -1
- package/dist/esm/utils/objectKeys.js +20 -3
- package/dist/esm/utils/projectInfo.d.ts +2 -8
- package/dist/esm/utils/projectInfo.js +2 -4
- package/dist/esm/utils/sorter.d.ts +59 -0
- package/dist/esm/utils/sorter.js +61 -0
- package/package.json +1 -1
- package/dist/cjs/shared/page-configs/assertExports.js +0 -67
- package/dist/cjs/utils/objectEntries.js +0 -8
- package/dist/esm/node/runtime/renderPage/logHintForCjsEsmError.d.ts +0 -13
- package/dist/esm/shared/page-configs/assertExports.d.ts +0 -6
- package/dist/esm/shared/page-configs/assertExports.js +0 -61
- package/dist/esm/utils/findUserPackageJsonPath.d.ts +0 -2
- package/dist/esm/utils/findUserPackageJsonPath.js +0 -18
- package/dist/esm/utils/objectEntries.d.ts +0 -4
- package/dist/esm/utils/objectEntries.js +0 -5
- /package/dist/cjs/node/runtime/renderPage/{logHintForCjsEsmError → logErrorHint}/errors.js +0 -0
- /package/dist/esm/node/runtime/renderPage/{logHintForCjsEsmError → logErrorHint}/errors.d.ts +0 -0
- /package/dist/esm/node/runtime/renderPage/{logHintForCjsEsmError → logErrorHint}/errors.js +0 -0
|
@@ -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'`.
|
|
@@ -12,7 +12,7 @@ export { getHttpRequestAsyncStore };
|
|
|
12
12
|
export { installHttpRequestAsyncStore };
|
|
13
13
|
import { renderPage_addWrapper } from '../../runtime/renderPage.js';
|
|
14
14
|
import { assert, assertIsNotProductionRuntime, isObject } from '../utils.js';
|
|
15
|
-
import { getConfigBuildErrorFormatted } from '../plugins/importUserCode/v1-design/transpileAndExecuteFile.js';
|
|
15
|
+
import { getConfigBuildErrorFormatted } from '../plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js';
|
|
16
16
|
import { logErrorDebugNote } from './loggerNotProd.js';
|
|
17
17
|
import { isEquivalentErrorWithCodeSnippet } from './loggerNotProd/errorWithCodeSnippet.js';
|
|
18
18
|
assertIsNotProductionRuntime();
|
|
@@ -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
|
};
|
|
@@ -18,7 +18,7 @@ import { assert, assertIsNotProductionRuntime, formatHintLog, getAssertErrMsg, i
|
|
|
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 { getConfigExecutionErrorIntroMsg, getConfigBuildErrorFormatted } from '../plugins/importUserCode/v1-design/transpileAndExecuteFile.js';
|
|
21
|
+
import { getConfigExecutionErrorIntroMsg, getConfigBuildErrorFormatted } from '../plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js';
|
|
22
22
|
import { logWithVikeTag, logWithViteTag, logDirectly, isFirstLog, screenHasErrors, clearScreen, applyViteSourceMapToStackTrace } from './loggerNotProd/log.js';
|
|
23
23
|
import pc from '@brillout/picocolors';
|
|
24
24
|
import { setAlreadyLogged } from '../../runtime/renderPage/isNewError.js';
|
|
@@ -5,7 +5,6 @@ export * from '../../utils/getDependencyPackageJson.js';
|
|
|
5
5
|
export * from '../../utils/requireResolve.js';
|
|
6
6
|
export * from '../../utils/arrayIncludes.js';
|
|
7
7
|
export * from '../../utils/isDev.js';
|
|
8
|
-
export * from '../../utils/objectKeys.js';
|
|
9
8
|
export * from '../../utils/getMostSimilar.js';
|
|
10
9
|
export * from '../../utils/getRandomId.js';
|
|
11
10
|
export * from '../../utils/joinEnglish.js';
|
|
@@ -13,7 +12,7 @@ export * from '../../utils/escapeRegex.js';
|
|
|
13
12
|
export * from '../../utils/stripAnsi.js';
|
|
14
13
|
export * from '../../utils/trimWithAnsi.js';
|
|
15
14
|
export * from '../../utils/removeEmptyLines.js';
|
|
16
|
-
export * from '../../utils/
|
|
15
|
+
export * from '../../utils/findFile.js';
|
|
17
16
|
export * from '../../utils/getPropAccessNotation.js';
|
|
18
17
|
export * from '../../utils/mergeCumulativeValues.js';
|
|
19
18
|
export * from '../../utils/deepEqual.js';
|
|
@@ -11,7 +11,6 @@ export * from '../../utils/getDependencyPackageJson.js';
|
|
|
11
11
|
export * from '../../utils/requireResolve.js';
|
|
12
12
|
export * from '../../utils/arrayIncludes.js';
|
|
13
13
|
export * from '../../utils/isDev.js';
|
|
14
|
-
export * from '../../utils/objectKeys.js';
|
|
15
14
|
export * from '../../utils/getMostSimilar.js';
|
|
16
15
|
export * from '../../utils/getRandomId.js';
|
|
17
16
|
export * from '../../utils/joinEnglish.js';
|
|
@@ -19,7 +18,7 @@ export * from '../../utils/escapeRegex.js';
|
|
|
19
18
|
export * from '../../utils/stripAnsi.js';
|
|
20
19
|
export * from '../../utils/trimWithAnsi.js';
|
|
21
20
|
export * from '../../utils/removeEmptyLines.js';
|
|
22
|
-
export * from '../../utils/
|
|
21
|
+
export * from '../../utils/findFile.js';
|
|
23
22
|
export * from '../../utils/getPropAccessNotation.js';
|
|
24
23
|
export * from '../../utils/mergeCumulativeValues.js';
|
|
25
24
|
export * from '../../utils/deepEqual.js';
|
|
@@ -5,7 +5,7 @@ export { runPrerender_forceExit };
|
|
|
5
5
|
import '../runtime/page-files/setup.js';
|
|
6
6
|
import path from 'path';
|
|
7
7
|
import { route } from '../../shared/route/index.js';
|
|
8
|
-
import { assert, assertUsage, assertWarning, hasProp, projectInfo, objectAssign, isObjectWithKeys, isCallable, getOutDirs, isPropertyGetter, assertPosixPath, urlToFile, executeHook, isPlainObject, setNodeEnvToProduction, isUserHookError } from './utils.js';
|
|
8
|
+
import { assert, assertUsage, assertWarning, hasProp, projectInfo, objectAssign, isObjectWithKeys, isCallable, getOutDirs, isPropertyGetter, assertPosixPath, urlToFile, executeHook, isPlainObject, setNodeEnvToProduction, isUserHookError, assertNodeEnvIsNotDev, getNodeEnv } from './utils.js';
|
|
9
9
|
import { pLimit } from '../../utils/pLimit.js';
|
|
10
10
|
import { prerenderPage, prerender404Page, getRenderContext, getPageContextInitEnhanced } from '../runtime/renderPage/renderPageAlreadyRouted.js';
|
|
11
11
|
import pc from '@brillout/picocolors';
|
|
@@ -26,11 +26,11 @@ import { loadUserFilesServerSide } from '../runtime/renderPage/loadUserFilesServ
|
|
|
26
26
|
import { getHookFromPageConfig, getHookFromPageConfigGlobal, getHookTimeoutDefault, setIsPrerenderering } from '../../shared/hooks/getHook.js';
|
|
27
27
|
import { noRouteMatch } from '../../shared/route/noRouteMatch.js';
|
|
28
28
|
import { getVikeConfig } from '../plugin/plugins/importUserCode/v1-design/getVikeConfig.js';
|
|
29
|
-
import {
|
|
29
|
+
import { logErrorHint } from '../runtime/renderPage/logErrorHint.js';
|
|
30
30
|
async function runPrerenderFromAPI(options = {}) {
|
|
31
31
|
await runPrerender(options, 'prerender()');
|
|
32
32
|
// - We purposely propagate the error to the user land, so that the error interrupts the user land. It's also, I guess, a nice-to-have that the user has control over the error.
|
|
33
|
-
// - We don't use
|
|
33
|
+
// - We don't use logErrorHint() because we don't have control over what happens with the error. For example, if the user land purposely swallows the error then the hint shouldn't be logged. Also, it's best if the hint is shown to the user *after* the error, but we cannot do/guarentee that.
|
|
34
34
|
}
|
|
35
35
|
async function runPrerenderFromCLI(options) {
|
|
36
36
|
try {
|
|
@@ -38,7 +38,7 @@ async function runPrerenderFromCLI(options) {
|
|
|
38
38
|
}
|
|
39
39
|
catch (err) {
|
|
40
40
|
console.error(err);
|
|
41
|
-
|
|
41
|
+
logErrorHint(err);
|
|
42
42
|
process.exit(1);
|
|
43
43
|
}
|
|
44
44
|
}
|
|
@@ -48,7 +48,7 @@ async function runPrerenderFromAutoFullBuild(options) {
|
|
|
48
48
|
}
|
|
49
49
|
catch (err) {
|
|
50
50
|
console.error(err);
|
|
51
|
-
|
|
51
|
+
logErrorHint(err);
|
|
52
52
|
process.exit(1);
|
|
53
53
|
}
|
|
54
54
|
}
|
|
@@ -59,7 +59,7 @@ async function runPrerender(options, manuallyTriggered) {
|
|
|
59
59
|
if (logLevel === 'info') {
|
|
60
60
|
console.log(`${pc.cyan(`vike v${projectInfo.projectVersion}`)} ${pc.green('pre-rendering HTML...')}`);
|
|
61
61
|
}
|
|
62
|
-
|
|
62
|
+
handleNodeEnv();
|
|
63
63
|
await disableReactStreaming();
|
|
64
64
|
const viteConfig = await resolveConfig(options.viteConfig || {}, 'vike pre-rendering', 'production');
|
|
65
65
|
assertLoadedConfig(viteConfig, options);
|
|
@@ -713,3 +713,10 @@ function assertIsNotAbort(err, urlOr404) {
|
|
|
713
713
|
assert(abortCall);
|
|
714
714
|
assertUsage(false, `${pc.cyan(abortCall)} thrown${thrownBy} while pre-rendering ${urlOr404} but ${pc.cyan(abortCaller)} isn't supported for pre-rendered pages`);
|
|
715
715
|
}
|
|
716
|
+
function handleNodeEnv() {
|
|
717
|
+
const assertNodeEnv = () => assertNodeEnvIsNotDev('pre-rendering');
|
|
718
|
+
if (getNodeEnv())
|
|
719
|
+
assertNodeEnv();
|
|
720
|
+
setNodeEnvToProduction();
|
|
721
|
+
assertNodeEnv();
|
|
722
|
+
}
|
|
@@ -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, getNodeEnvDesc, 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,11 @@ function assertNodeEnv(hasViteDevServer) {
|
|
|
151
151
|
const nodeEnv = getNodeEnv();
|
|
152
152
|
if (nodeEnv === null || nodeEnv === 'test')
|
|
153
153
|
return;
|
|
154
|
-
const
|
|
155
|
-
//
|
|
156
|
-
|
|
154
|
+
const isDev = 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
|
+
if (hasViteDevServer === isDev)
|
|
157
|
+
return;
|
|
158
|
+
const nodeEnvDesc = getNodeEnvDesc();
|
|
159
|
+
// 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)
|
|
160
|
+
assertUsage(false, `Vite's development server was${hasViteDevServer ? '' : "n't"} instantiated while the ${nodeEnvDesc} which is contradictory, see https://vike.dev/NODE_ENV`);
|
|
157
161
|
}
|
|
@@ -85,8 +85,8 @@ async function getHtmlTags(pageContext, injectToStream, injectFilter) {
|
|
|
85
85
|
// See https://github.com/vikejs/vike/pull/1271
|
|
86
86
|
const positionJavaScriptEntry = (() => {
|
|
87
87
|
if (pageContext._pageContextPromise) {
|
|
88
|
-
assertWarning(!injectToStream, "[getHtmlTags()] We recommend against using streaming and a pageContext promise at the same time
|
|
89
|
-
// If there is a pageContext._pageContextPromise (which is resolved after the stream has ended) then the pageContext JSON data needs to await for it: https://vike.dev/
|
|
88
|
+
assertWarning(!injectToStream, "[getHtmlTags()] We recommend against using streaming and a pageContext promise at the same time, because progressive hydration won't work.", { onlyOnce: true });
|
|
89
|
+
// If there is a pageContext._pageContextPromise (which is resolved after the stream has ended) then the pageContext JSON data needs to await for it: https://vike.dev/streaming#initial-data-after-stream-end
|
|
90
90
|
return 'HTML_END';
|
|
91
91
|
}
|
|
92
92
|
if (injectToStream) {
|
|
@@ -181,7 +181,7 @@ async function renderTemplate(templateContent, pageContext) {
|
|
|
181
181
|
const varType = typeof templateVar;
|
|
182
182
|
const streamNote = ['boolean', 'number', 'bigint', 'symbol'].includes(varType)
|
|
183
183
|
? null
|
|
184
|
-
: '(See https://vike.dev/
|
|
184
|
+
: '(See https://vike.dev/streaming for HTML streaming.)';
|
|
185
185
|
assertUsage(varType === 'string', getErrMsg(pc.cyan(`typeof htmlVar === "${varType}"`), streamNote));
|
|
186
186
|
}
|
|
187
187
|
{
|
|
@@ -634,7 +634,7 @@ function isStream(something) {
|
|
|
634
634
|
const __streamPipeWeb = '__streamPipeWeb';
|
|
635
635
|
/** @deprecated */
|
|
636
636
|
function pipeWebStream(pipe) {
|
|
637
|
-
assertWarning(false, 'pipeWebStream() is outdated, use stampPipe() instead. See https://vike.dev/
|
|
637
|
+
assertWarning(false, 'pipeWebStream() is outdated, use stampPipe() instead. See https://vike.dev/streaming', {
|
|
638
638
|
onlyOnce: true,
|
|
639
639
|
showStackTrace: true
|
|
640
640
|
});
|
|
@@ -669,7 +669,7 @@ function isStreamPipeWeb(thing) {
|
|
|
669
669
|
const __streamPipeNode = '__streamPipeNode';
|
|
670
670
|
/** @deprecated */
|
|
671
671
|
function pipeNodeStream(pipe) {
|
|
672
|
-
assertWarning(false, 'pipeNodeStream() is outdated, use stampPipe() instead. See https://vike.dev/
|
|
672
|
+
assertWarning(false, 'pipeNodeStream() is outdated, use stampPipe() instead. See https://vike.dev/streaming', {
|
|
673
673
|
onlyOnce: true,
|
|
674
674
|
showStackTrace: true
|
|
675
675
|
});
|
|
@@ -119,11 +119,11 @@ function processHookReturnValue(hookReturnValue, renderHook) {
|
|
|
119
119
|
const val = hookReturnValue.pageContext;
|
|
120
120
|
const errBegin = `${errPrefix} returned ${pc.cyan('{ pageContext }')}, but ${pc.cyan('pageContext')}`;
|
|
121
121
|
if (isPromise(val) || isCallable(val)) {
|
|
122
|
-
assertWarning(!isPromise(val), `${errBegin} is a promise which is deprecated in favor of async functions, see https://vike.dev/
|
|
122
|
+
assertWarning(!isPromise(val), `${errBegin} is a promise which is deprecated in favor of async functions, see https://vike.dev/streaming#initial-data-after-stream-end`, { onlyOnce: true });
|
|
123
123
|
pageContextPromise = val;
|
|
124
124
|
}
|
|
125
125
|
else {
|
|
126
|
-
assertUsage(isObject(val), `${errBegin} should be an object or an async function, see https://vike.dev/
|
|
126
|
+
assertUsage(isObject(val), `${errBegin} should be an object or an async function, see https://vike.dev/streaming#initial-data-after-stream-end`);
|
|
127
127
|
assertPageContextProvidedByUser(val, renderHook);
|
|
128
128
|
pageContextProvidedByRenderHook = val;
|
|
129
129
|
}
|
|
@@ -4,7 +4,7 @@ import { isStream, getStreamName, inferStreamName, isStreamWritableWeb, isStream
|
|
|
4
4
|
import { assert, assertUsage, assertWarning } from '../utils.js';
|
|
5
5
|
import { getHtmlString } from '../html/renderHtml.js';
|
|
6
6
|
import pc from '@brillout/picocolors';
|
|
7
|
-
const streamDocs = 'See https://vike.dev/
|
|
7
|
+
const streamDocs = 'See https://vike.dev/streaming for more information.';
|
|
8
8
|
function getHttpResponseBody(htmlRender, renderHook) {
|
|
9
9
|
if (typeof htmlRender !== 'string') {
|
|
10
10
|
assertUsage(false, getErrMsg(htmlRender, renderHook, 'body', `Use ${pc.cyan('pageContext.httpResponse.pipe()')} instead`));
|
|
@@ -42,7 +42,7 @@ async function loadUserFilesServerSide(pageContext) {
|
|
|
42
42
|
// TODO/v1-release: remove
|
|
43
43
|
Object.assign(pageContextAddendum, {
|
|
44
44
|
_getPageAssets: async () => {
|
|
45
|
-
assertWarning(false, 'pageContext._getPageAssets() deprecated, see https://vike.dev/
|
|
45
|
+
assertWarning(false, 'pageContext._getPageAssets() deprecated, see https://vike.dev/preloading', {
|
|
46
46
|
onlyOnce: true,
|
|
47
47
|
showStackTrace: true
|
|
48
48
|
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { logErrorHint };
|
|
2
|
+
export { isCjsEsmError };
|
|
3
|
+
export { isKnownError };
|
|
4
|
+
export { getHint };
|
|
5
|
+
declare function logErrorHint(error: unknown): void;
|
|
6
|
+
declare function getHint(error: unknown): null | string;
|
|
7
|
+
declare function isKnownError(error: unknown): false | string;
|
|
8
|
+
declare function isCjsEsmError(error: unknown): boolean | string[];
|
|
@@ -1,12 +1,22 @@
|
|
|
1
|
-
export {
|
|
2
|
-
// For ./
|
|
1
|
+
export { logErrorHint };
|
|
2
|
+
// For ./logErrorHint/*.spec.ts
|
|
3
3
|
export { isCjsEsmError };
|
|
4
|
-
export {
|
|
4
|
+
export { isKnownError };
|
|
5
5
|
export { getHint };
|
|
6
6
|
import pc from '@brillout/picocolors';
|
|
7
7
|
import { assert, formatHintLog, isNotNullish, isObject, unique, joinEnglish } from '../utils.js';
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
const knownErrors = [
|
|
9
|
+
{
|
|
10
|
+
errMsg: 'jsxDEV is not a function',
|
|
11
|
+
link: 'https://github.com/vikejs/vike/issues/1469#issuecomment-1919518096'
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
errMsg: 'Element type is invalid: expected a string (for built-in components) or a class/function (for composite components)',
|
|
15
|
+
link: 'https://vike.dev/broken-npm-package#react-invalid-component'
|
|
16
|
+
}
|
|
17
|
+
];
|
|
18
|
+
function logErrorHint(error) {
|
|
19
|
+
/* Collect errors for ./logErrorHint.spec.ts
|
|
10
20
|
collectError(error)
|
|
11
21
|
//*/
|
|
12
22
|
const hint = getHint(error);
|
|
@@ -14,9 +24,10 @@ function logHintForCjsEsmError(error) {
|
|
|
14
24
|
logHint(hint);
|
|
15
25
|
}
|
|
16
26
|
function getHint(error) {
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
|
|
27
|
+
{
|
|
28
|
+
const link = isKnownError(error);
|
|
29
|
+
if (link)
|
|
30
|
+
return `To fix this error, see ${link}`;
|
|
20
31
|
}
|
|
21
32
|
const res = isCjsEsmError(error);
|
|
22
33
|
if (res) {
|
|
@@ -37,43 +48,71 @@ function logHint(hint) {
|
|
|
37
48
|
hint = formatHintLog(hint);
|
|
38
49
|
console.error(hint);
|
|
39
50
|
}
|
|
40
|
-
function
|
|
51
|
+
function isKnownError(error) {
|
|
41
52
|
const anywhere = getAnywhere(error);
|
|
42
|
-
|
|
53
|
+
const knownErr = knownErrors.find((knownErorr) => {
|
|
54
|
+
return includes(anywhere, knownErorr.errMsg);
|
|
55
|
+
});
|
|
56
|
+
if (!knownErr)
|
|
57
|
+
return false;
|
|
58
|
+
return knownErr.link;
|
|
43
59
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
* `'some-npm-package'` -> add some-npm-package to `ssr.noExternal`
|
|
48
|
-
*/
|
|
60
|
+
// `false` -> noop
|
|
61
|
+
// `true` -> generic message
|
|
62
|
+
// `'some-npm-package'` -> add some-npm-package to `ssr.noExternal`
|
|
49
63
|
function isCjsEsmError(error) {
|
|
64
|
+
const res = check(error);
|
|
65
|
+
if (res === true || res === false)
|
|
66
|
+
return res;
|
|
67
|
+
const packageNames = normalizeRes(res);
|
|
68
|
+
if (packageNames === false)
|
|
69
|
+
return packageNames;
|
|
70
|
+
packageNames.forEach((packageName) => {
|
|
71
|
+
assert(!['vite', 'vike'].includes(packageName));
|
|
72
|
+
});
|
|
73
|
+
return packageNames;
|
|
74
|
+
}
|
|
75
|
+
function normalizeRes(res) {
|
|
76
|
+
let packageNames = Array.isArray(res) ? res : [res];
|
|
77
|
+
packageNames = unique(packageNames.filter(isNotNullish).filter((packageName) => packageName !== '@brillout/import'));
|
|
78
|
+
if (packageNames.length === 0)
|
|
79
|
+
return false;
|
|
80
|
+
return packageNames;
|
|
81
|
+
}
|
|
82
|
+
function check(error) {
|
|
50
83
|
const message = getErrMessage(error);
|
|
51
84
|
const anywhere = getAnywhere(error);
|
|
52
85
|
const packageName_stack1 = getPackageName_stack1(error);
|
|
53
86
|
const packageName_stack2 = getPackageName_stack2(error);
|
|
54
87
|
const isRelatedToNodeModules = !!packageName_stack1 || !!packageName_stack2 || includesNodeModules(message);
|
|
55
|
-
|
|
88
|
+
/*
|
|
89
|
+
const relatedNpmPackages = normalizeArray([
|
|
90
|
+
packageName_stack1 || null,
|
|
91
|
+
packageName_stack2 || null,
|
|
92
|
+
(message && extractFromNodeModulesPath(message)) || null
|
|
93
|
+
])
|
|
94
|
+
*/
|
|
56
95
|
// ERR_UNSUPPORTED_DIR_IMPORT
|
|
57
96
|
{
|
|
58
|
-
const
|
|
59
|
-
if (
|
|
60
|
-
return
|
|
97
|
+
const packageName = parseNodeModulesPathMessage('ERR_UNSUPPORTED_DIR_IMPORT', anywhere);
|
|
98
|
+
if (packageName)
|
|
99
|
+
return packageName;
|
|
61
100
|
}
|
|
62
101
|
// ERR_UNKNOWN_FILE_EXTENSION
|
|
63
102
|
{
|
|
64
|
-
const
|
|
65
|
-
if (
|
|
66
|
-
return
|
|
103
|
+
const packageName = parseUnkownFileExtensionMessage(anywhere);
|
|
104
|
+
if (packageName)
|
|
105
|
+
return packageName;
|
|
67
106
|
}
|
|
68
107
|
{
|
|
69
|
-
const
|
|
70
|
-
if (
|
|
71
|
-
return
|
|
108
|
+
const packageName = parseNodeModulesPathMessage('ERR_UNKNOWN_FILE_EXTENSION', anywhere);
|
|
109
|
+
if (packageName)
|
|
110
|
+
return packageName;
|
|
72
111
|
}
|
|
73
112
|
{
|
|
74
|
-
const
|
|
75
|
-
if (
|
|
76
|
-
return
|
|
113
|
+
const packageName = parseNodeModulesPathMessage('is not exported', anywhere);
|
|
114
|
+
if (packageName)
|
|
115
|
+
return packageName;
|
|
77
116
|
}
|
|
78
117
|
// Using CJS inside ESM modules.
|
|
79
118
|
if (includes(anywhere, 'require is not a function') ||
|
|
@@ -94,7 +133,7 @@ function isCjsEsmError(error) {
|
|
|
94
133
|
if (includes(anywhere, 'ERR_REQUIRE_ESM')) {
|
|
95
134
|
/* The issue is the importer, not the importee.
|
|
96
135
|
if (relatedNpmPackages) return relatedNpmPackages
|
|
97
|
-
|
|
136
|
+
*/
|
|
98
137
|
{
|
|
99
138
|
if (packageName_stack1)
|
|
100
139
|
return packageName_stack1;
|
|
@@ -114,9 +153,9 @@ function isCjsEsmError(error) {
|
|
|
114
153
|
*/
|
|
115
154
|
// `SyntaxError: Named export '${exportName}' not found. The requested module '${packageName}' is a CommonJS module, which may not support all module.exports as named exports.`
|
|
116
155
|
{
|
|
117
|
-
const
|
|
118
|
-
if (
|
|
119
|
-
return
|
|
156
|
+
const packageName = parseImportFrom(anywhere);
|
|
157
|
+
if (packageName)
|
|
158
|
+
return packageName;
|
|
120
159
|
}
|
|
121
160
|
if (includes(anywhere, 'Cannot read properties of undefined')) {
|
|
122
161
|
if (isRelatedToNodeModules) {
|
|
@@ -152,7 +191,7 @@ function parseCannotFindMessage(str) {
|
|
|
152
191
|
return false;
|
|
153
192
|
// const packageNameCannotFind = extractFromPath(match[1]!)
|
|
154
193
|
const packageNameFrom = extractFromPath(match[2]);
|
|
155
|
-
return
|
|
194
|
+
return normalizeArray([
|
|
156
195
|
// packageNameCannotFind,
|
|
157
196
|
packageNameFrom
|
|
158
197
|
]);
|
|
@@ -163,7 +202,7 @@ function parseUnkownFileExtensionMessage(str) {
|
|
|
163
202
|
return false;
|
|
164
203
|
const filePath = match[1];
|
|
165
204
|
const packageName = extractFromPath(filePath);
|
|
166
|
-
return
|
|
205
|
+
return packageName;
|
|
167
206
|
}
|
|
168
207
|
function parseImportFrom(str) {
|
|
169
208
|
const match = /\bimport\b.*?\bfrom\b\s*?"(.+?)"/.exec(str);
|
|
@@ -171,7 +210,7 @@ function parseImportFrom(str) {
|
|
|
171
210
|
return false;
|
|
172
211
|
const importPath = match[1];
|
|
173
212
|
const packageName = extractFromPath(importPath);
|
|
174
|
-
return
|
|
213
|
+
return packageName;
|
|
175
214
|
}
|
|
176
215
|
function parseNodeModulesPathMessage(begin, str) {
|
|
177
216
|
str = str.replaceAll('\\', '/');
|
|
@@ -225,7 +264,6 @@ function extractFromPath(filePath) {
|
|
|
225
264
|
packageName = packageName.split('/')[0];
|
|
226
265
|
}
|
|
227
266
|
packageName = clean(packageName);
|
|
228
|
-
assert(!['vite', 'vike'].includes(packageName));
|
|
229
267
|
return packageName;
|
|
230
268
|
}
|
|
231
269
|
function clean(packageName) {
|
|
@@ -243,7 +281,7 @@ function extractFromNodeModulesPath(str) {
|
|
|
243
281
|
return false;
|
|
244
282
|
const packageName = extractFromPath(str);
|
|
245
283
|
assert(packageName);
|
|
246
|
-
return
|
|
284
|
+
return packageName;
|
|
247
285
|
}
|
|
248
286
|
function includes(str1, str2) {
|
|
249
287
|
return !!str1 && str1.toLowerCase().includes(str2.toLowerCase());
|
|
@@ -258,11 +296,11 @@ function includesNodeModules(str) {
|
|
|
258
296
|
return false;
|
|
259
297
|
return true;
|
|
260
298
|
}
|
|
261
|
-
function
|
|
262
|
-
const
|
|
263
|
-
if (
|
|
264
|
-
return
|
|
265
|
-
return
|
|
299
|
+
function normalizeArray(arr) {
|
|
300
|
+
const arrNormalized = arr.filter(isNotNullish);
|
|
301
|
+
if (arrNormalized.length === 0)
|
|
302
|
+
return null;
|
|
303
|
+
return arrNormalized;
|
|
266
304
|
}
|
|
267
305
|
function getErrMessage(err) {
|
|
268
306
|
if (!isObject(err))
|
|
@@ -6,7 +6,7 @@ import { isAbortError } from '../../../shared/route/abort.js';
|
|
|
6
6
|
import { setAlreadyLogged } from './isNewError.js';
|
|
7
7
|
import { isObject, warnIfErrorIsNotObject } from '../utils.js';
|
|
8
8
|
import pc from '@brillout/picocolors';
|
|
9
|
-
import {
|
|
9
|
+
import { logErrorHint } from './logErrorHint.js';
|
|
10
10
|
function logErrorProd(err, _httpRquestId) {
|
|
11
11
|
warnIfErrorIsNotObject(err);
|
|
12
12
|
setAlreadyLogged(err);
|
|
@@ -20,6 +20,6 @@ function logErrorProd(err, _httpRquestId) {
|
|
|
20
20
|
}
|
|
21
21
|
// Every server-side runtime error is expected to go through onRuntimeError(). (In principle, any runtime error is (or at least should) be catched by Vike, otherwise Vike couldn't render the error page.)
|
|
22
22
|
function onRuntimeError(err) {
|
|
23
|
-
// The more runtime errors we pass to
|
|
24
|
-
|
|
23
|
+
// The more runtime errors we pass to logErrorHint() the better.
|
|
24
|
+
logErrorHint(err);
|
|
25
25
|
}
|
|
@@ -36,7 +36,7 @@ export * from '../../utils/isNpmPackage.js';
|
|
|
36
36
|
export * from '../../utils/isNotNullish.js';
|
|
37
37
|
export * from '../../utils/isScriptFile.js';
|
|
38
38
|
export * from '../../utils/removeFileExtention.js';
|
|
39
|
-
export * from '../../utils/
|
|
39
|
+
export * from '../../utils/objectKeys.js';
|
|
40
40
|
export * from '../../utils/isStringRecord.js';
|
|
41
41
|
export * from '../../utils/getFileExtension.js';
|
|
42
42
|
export * from '../../utils/assertIsNotProductionRuntime.js';
|
|
@@ -39,7 +39,7 @@ export * from '../../utils/isNpmPackage.js';
|
|
|
39
39
|
export * from '../../utils/isNotNullish.js';
|
|
40
40
|
export * from '../../utils/isScriptFile.js';
|
|
41
41
|
export * from '../../utils/removeFileExtention.js';
|
|
42
|
-
export * from '../../utils/
|
|
42
|
+
export * from '../../utils/objectKeys.js';
|
|
43
43
|
export * from '../../utils/isStringRecord.js';
|
|
44
44
|
export * from '../../utils/getFileExtension.js';
|
|
45
45
|
export * from '../../utils/assertIsNotProductionRuntime.js';
|
|
@@ -201,7 +201,7 @@ type OnRenderHtmlSync = (pageContext: PageContextServer) => DocumentHtml | {
|
|
|
201
201
|
pageContext: OnRenderHtmlPageContextReturn | (() => Promise<OnRenderHtmlPageContextReturn> | OnRenderHtmlPageContextReturn);
|
|
202
202
|
};
|
|
203
203
|
type OnRenderHtmlPageContextReturn = Partial<Vike.PageContext & {
|
|
204
|
-
/** See https://vike.dev/
|
|
204
|
+
/** See https://vike.dev/streaming */
|
|
205
205
|
enableEagerStreaming: boolean;
|
|
206
206
|
}>;
|
|
207
207
|
/** @deprecated Use a sync route() with an async guard() instead */
|
|
@@ -17,6 +17,7 @@ export type { DefinedAtFileFullInfo };
|
|
|
17
17
|
export type { FilePathResolved };
|
|
18
18
|
export type { FilePath };
|
|
19
19
|
import type { ConfigValueImported, ConfigValueSerialized } from './serialize/PageConfigSerialized.js';
|
|
20
|
+
import type { LocationId } from '../../node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js';
|
|
20
21
|
type PageConfigBase = {
|
|
21
22
|
pageId: string;
|
|
22
23
|
isErrorPage?: true;
|
|
@@ -53,6 +54,10 @@ type PageConfigGlobalRuntime = {
|
|
|
53
54
|
type PageConfigGlobalBuildTime = {
|
|
54
55
|
configValueSources: ConfigValueSources;
|
|
55
56
|
};
|
|
57
|
+
/** In what environment(s) the config value is loaded.
|
|
58
|
+
*
|
|
59
|
+
* https://vike.dev/meta
|
|
60
|
+
*/
|
|
56
61
|
type ConfigEnv = {
|
|
57
62
|
client?: boolean;
|
|
58
63
|
server?: boolean;
|
|
@@ -67,6 +72,7 @@ type ConfigValueSource = {
|
|
|
67
72
|
value?: unknown;
|
|
68
73
|
configEnv: ConfigEnvInternal;
|
|
69
74
|
definedAt: DefinedAtFileFullInfo;
|
|
75
|
+
locationId: LocationId;
|
|
70
76
|
/** Wether the config value is loaded at runtime, for example config.Page or config.onBeforeRender */
|
|
71
77
|
valueIsImportedAtRuntime: boolean;
|
|
72
78
|
/** Whether the config value is a file path, for example config.client */
|
|
@@ -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
|
+
}
|