vike 0.4.159 → 0.4.160-commit-a1101c1

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.
Files changed (72) hide show
  1. package/dist/cjs/node/plugin/index.js +20 -1
  2. package/dist/cjs/node/plugin/plugins/devConfig/index.js +1 -1
  3. package/dist/cjs/node/plugin/plugins/importBuild/index.js +1 -1
  4. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getConfigFileExport.js +18 -0
  5. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileConfigEnv.js +129 -0
  6. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +139 -0
  7. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/{replaceImportStatements.js → getVikeConfig/transformImports.js} +44 -13
  8. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/{transpileAndExecuteFile.js → getVikeConfig/transpileAndExecuteFile.js} +110 -77
  9. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +58 -279
  10. package/dist/cjs/node/plugin/plugins/previewConfig.js +1 -1
  11. package/dist/cjs/node/plugin/shared/getHttpRequestAsyncStore.js +1 -1
  12. package/dist/cjs/node/plugin/shared/loggerNotProd/log.js +3 -3
  13. package/dist/cjs/node/plugin/shared/loggerNotProd.js +1 -1
  14. package/dist/cjs/node/runtime/globalContext.js +4 -3
  15. package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +1 -1
  16. package/dist/cjs/node/runtime/html/renderHtml.js +1 -1
  17. package/dist/cjs/node/runtime/html/stream.js +2 -2
  18. package/dist/cjs/node/runtime/renderPage/executeOnRenderHtmlHook.js +2 -2
  19. package/dist/cjs/node/runtime/renderPage/getHttpResponseBody.js +1 -1
  20. package/dist/cjs/node/runtime/renderPage/loadUserFilesServerSide.js +1 -1
  21. package/dist/cjs/shared/page-configs/assertPlusFileExport.js +44 -0
  22. package/dist/cjs/shared/page-configs/serialize/parseConfigValuesImported.js +2 -2
  23. package/dist/cjs/shared/route/abort.js +1 -1
  24. package/dist/cjs/utils/assert.js +5 -6
  25. package/dist/cjs/utils/assertIsNotProductionRuntime.js +35 -17
  26. package/dist/cjs/utils/nodeEnv.js +11 -1
  27. package/dist/cjs/utils/projectInfo.js +2 -4
  28. package/dist/esm/node/plugin/index.js +21 -2
  29. package/dist/esm/node/plugin/plugins/devConfig/index.js +2 -2
  30. package/dist/esm/node/plugin/plugins/importBuild/index.js +2 -2
  31. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getConfigFileExport.d.ts +2 -0
  32. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getConfigFileExport.js +12 -0
  33. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +6 -1
  34. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileConfigEnv.d.ts +21 -0
  35. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileConfigEnv.js +123 -0
  36. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.d.ts +12 -0
  37. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +133 -0
  38. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{replaceImportStatements.d.ts → getVikeConfig/transformImports.d.ts} +5 -5
  39. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{replaceImportStatements.js → getVikeConfig/transformImports.js} +43 -12
  40. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{transpileAndExecuteFile.d.ts → getVikeConfig/transpileAndExecuteFile.d.ts} +3 -3
  41. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{transpileAndExecuteFile.js → getVikeConfig/transpileAndExecuteFile.js} +110 -77
  42. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +14 -1
  43. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +55 -276
  44. package/dist/esm/node/plugin/plugins/previewConfig.js +2 -2
  45. package/dist/esm/node/plugin/shared/getHttpRequestAsyncStore.js +1 -1
  46. package/dist/esm/node/plugin/shared/loggerNotProd/log.js +3 -3
  47. package/dist/esm/node/plugin/shared/loggerNotProd.js +1 -1
  48. package/dist/esm/node/runtime/globalContext.js +5 -4
  49. package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +1 -1
  50. package/dist/esm/node/runtime/html/renderHtml.js +1 -1
  51. package/dist/esm/node/runtime/html/stream.js +2 -2
  52. package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.js +2 -2
  53. package/dist/esm/node/runtime/renderPage/getHttpResponseBody.js +1 -1
  54. package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.js +1 -1
  55. package/dist/esm/shared/page-configs/Config.d.ts +1 -1
  56. package/dist/esm/shared/page-configs/PageConfig.d.ts +4 -0
  57. package/dist/esm/shared/page-configs/assertPlusFileExport.d.ts +2 -0
  58. package/dist/esm/shared/page-configs/assertPlusFileExport.js +38 -0
  59. package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.js +2 -2
  60. package/dist/esm/shared/route/abort.js +2 -2
  61. package/dist/esm/utils/assert.js +5 -6
  62. package/dist/esm/utils/assertIsNotProductionRuntime.d.ts +8 -6
  63. package/dist/esm/utils/assertIsNotProductionRuntime.js +35 -17
  64. package/dist/esm/utils/debug.d.ts +1 -1
  65. package/dist/esm/utils/nodeEnv.d.ts +2 -0
  66. package/dist/esm/utils/nodeEnv.js +10 -0
  67. package/dist/esm/utils/projectInfo.d.ts +2 -8
  68. package/dist/esm/utils/projectInfo.js +2 -4
  69. package/package.json +1 -1
  70. package/dist/cjs/shared/page-configs/assertExports.js +0 -67
  71. package/dist/esm/shared/page-configs/assertExports.d.ts +0 -6
  72. package/dist/esm/shared/page-configs/assertExports.js +0 -61
@@ -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/stream */
204
+ /** See https://vike.dev/streaming */
205
205
  enableEagerStreaming: boolean;
206
206
  }>;
207
207
  /** @deprecated Use a sync route() with an async guard() instead */
@@ -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,2 @@
1
+ export { assertPlusFileExport };
2
+ declare function assertPlusFileExport(fileExports: Record<string, unknown>, filePathToShowToUser: string, configName: string): void;
@@ -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 { assertExportsOfValueFile } from '../assertExports.js';
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
- assertExportsOfValueFile(exportValues, importPath, configName);
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, projectInfo, truncateString } from './utils.js';
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 ${projectInfo.githubRepository}/issues/1008 if you believe ${statusCode} should be added.)`, { onlyOnce: true });
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);
@@ -25,8 +25,8 @@ const globalObject = getGlobalObject('utils/assert.ts', {
25
25
  },
26
26
  showStackTraceList: new WeakSet()
27
27
  });
28
- const projectTag = `[${projectInfo.npmPackageName}]`;
29
- const projectTagWithVersion = `[${projectInfo.npmPackageName}@${projectInfo.projectVersion}]`;
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 ${projectInfo.projectName} maintainers; you can ignore this): ${debugInfoSerialized}`);
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 in ${projectInfo.projectName}'s source code.`,
44
- `Go to ${pc.blue(link)} and copy-paste this error. A maintainer will fix the bug (usually under 24 hours).`,
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 { markEnvAsDev };
3
- export { markEnvAsPreview };
4
- export { markEnvAsVite };
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 markEnvAsDev(): void | undefined;
8
- declare function markEnvAsPreview(): void | undefined;
9
- declare function markEnvAsVite(): void;
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 { markEnvAsDev };
4
- export { markEnvAsPreview };
5
- export { markEnvAsVite };
3
+ export { markEnvAsViteDev };
4
+ export { markEnvAsVitePreview };
5
+ export { markEnvAsVikePluginLoaded };
6
6
  export { assertEnv };
7
- import { assert } from './assert.js';
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 *.ts that want to ensure that they aren't loaded by the server runtime in production
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
- env.shouldBeVite = true;
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 markEnvAsDev() {
19
- env.isDev = true;
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 markEnvAsPreview() {
23
- env.isPreview = true;
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 markEnvAsVite() {
27
- env.isVite = true;
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
- if (env.isDev || env.isPreview) {
34
- assert(env.isVite);
35
- assert(env.shouldBeVite);
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(!env.isVite);
39
- assert(!env.shouldBeVite);
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,4 +1,6 @@
1
1
  export { getNodeEnv };
2
2
  export { setNodeEnvToProduction };
3
+ export { isNodeEnvDev };
3
4
  declare function getNodeEnv(): null | undefined | string;
4
5
  declare function setNodeEnvToProduction(): void | undefined;
6
+ declare function isNodeEnvDev(): boolean;
@@ -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.159";
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.160-commit-a1101c1";
8
4
  declare const projectInfo: {
9
5
  projectName: "Vike";
10
- projectVersion: "0.4.159";
11
- npmPackageName: "vike";
12
- githubRepository: "https://github.com/vikejs/vike";
6
+ projectVersion: "0.4.160-commit-a1101c1";
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.159';
4
+ const PROJECT_VERSION = '0.4.160-commit-a1101c1';
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,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.159",
3
+ "version": "0.4.160-commit-a1101c1",
4
4
  "scripts": {
5
5
  "dev": "tsc --watch",
6
6
  "build": "rimraf dist/ && pnpm run build:esm && pnpm run build:cjs",
@@ -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
- }