vike 0.4.158 → 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.
Files changed (45) 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.js +11 -12
  6. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.js +3 -3
  7. package/dist/cjs/node/plugin/plugins/previewConfig.js +1 -1
  8. package/dist/cjs/node/plugin/shared/loggerNotProd/log.js +3 -3
  9. package/dist/cjs/node/runtime/globalContext.js +4 -3
  10. package/dist/cjs/shared/page-configs/assertPlusFileExport.js +44 -0
  11. package/dist/cjs/shared/page-configs/serialize/parseConfigValuesImported.js +2 -2
  12. package/dist/cjs/shared/route/abort.js +1 -1
  13. package/dist/cjs/utils/assert.js +5 -6
  14. package/dist/cjs/utils/assertIsNotProductionRuntime.js +35 -17
  15. package/dist/cjs/utils/nodeEnv.js +11 -1
  16. package/dist/cjs/utils/projectInfo.js +2 -4
  17. package/dist/esm/node/plugin/index.js +21 -2
  18. package/dist/esm/node/plugin/plugins/devConfig/index.js +2 -2
  19. package/dist/esm/node/plugin/plugins/importBuild/index.js +2 -2
  20. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getConfigFileExport.d.ts +2 -0
  21. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getConfigFileExport.js +12 -0
  22. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +6 -1
  23. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +11 -12
  24. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.js +3 -3
  25. package/dist/esm/node/plugin/plugins/previewConfig.js +2 -2
  26. package/dist/esm/node/plugin/shared/loggerNotProd/log.js +3 -3
  27. package/dist/esm/node/runtime/globalContext.js +5 -4
  28. package/dist/esm/shared/page-configs/PageConfig.d.ts +4 -0
  29. package/dist/esm/shared/page-configs/assertPlusFileExport.d.ts +2 -0
  30. package/dist/esm/shared/page-configs/assertPlusFileExport.js +38 -0
  31. package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.js +2 -2
  32. package/dist/esm/shared/route/abort.js +2 -2
  33. package/dist/esm/shared/types.d.ts +55 -28
  34. package/dist/esm/utils/assert.js +5 -6
  35. package/dist/esm/utils/assertIsNotProductionRuntime.d.ts +8 -6
  36. package/dist/esm/utils/assertIsNotProductionRuntime.js +35 -17
  37. package/dist/esm/utils/debug.d.ts +1 -1
  38. package/dist/esm/utils/nodeEnv.d.ts +2 -0
  39. package/dist/esm/utils/nodeEnv.js +10 -0
  40. package/dist/esm/utils/projectInfo.d.ts +2 -8
  41. package/dist/esm/utils/projectInfo.js +2 -4
  42. package/package.json +1 -1
  43. package/dist/cjs/shared/page-configs/assertExports.js +0 -67
  44. package/dist/esm/shared/page-configs/assertExports.d.ts +0 -6
  45. package/dist/esm/shared/page-configs/assertExports.js +0 -61
@@ -1,5 +1,5 @@
1
1
  export { previewConfig };
2
- import { assertUsage, getOutDirs, resolveOutDir, markEnvAsPreview } from '../utils.js';
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
- markEnvAsPreview();
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 = `[${projectInfo.npmPackageName}@${projectInfo.projectVersion}]`;
23
+ projectTag = `[vike@${projectInfo.projectVersion}]`;
24
24
  }
25
25
  else {
26
- projectTag = `[${projectInfo.npmPackageName}]`;
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(`[${projectInfo.npmPackageName}`))
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, assertWarning, getGlobalObject, getNodeEnv, isPlainObject, objectAssign } from './utils.js';
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 = [undefined, '', 'dev', 'development'].includes(nodeEnv);
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
- assertWarning(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`, { onlyOnce: true });
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,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);
@@ -3,33 +3,26 @@ export { PageContextServer };
3
3
  export { PageContextClient };
4
4
  export { PageContextWithServerRouting };
5
5
  export { PageContextClientWithServerRouting };
6
- export { PageContextBuiltInServer };
7
6
  export { PageContextBuiltInServerInternal };
8
- export { PageContextBuiltInClientWithClientRouting };
9
- export { PageContextBuiltInClientWithServerRouting };
7
+ export { PageContextBuiltInServer_deprecated as PageContextBuiltInServer };
8
+ export { PageContextBuiltInClientWithClientRouting_deprecated as PageContextBuiltInClientWithClientRouting };
9
+ export { PageContextBuiltInClientWithServerRouting_deprecated as PageContextBuiltInClientWithServerRouting };
10
10
  import type { PageContextUrlComputedPropsInternal, PageContextUrlComputedPropsClient, PageContextUrlComputedPropsServer } from './addUrlComputedProps.js';
11
11
  import type { ConfigEntries, ExportsAll } from './getPageFiles/getExports.js';
12
12
  import type { Config } from './page-configs/Config.js';
13
13
  import type { PageContextConfig } from './page-configs/Config/PageContextConfig.js';
14
14
  import type { AbortStatusCode } from './route/abort.js';
15
- type PageContextServer = PageContextBuiltInServer & Vike.PageContext;
16
- type PageContext = PageContextClient | PageContextServer;
17
- type PageContextClient = PageContextBuiltInClientWithClientRouting & Vike.PageContext;
18
- type PageContextWithServerRouting = PageContextClientWithServerRouting | PageContextServer;
19
- type PageContextClientWithServerRouting = PageContextBuiltInClientWithServerRouting & Vike.PageContext;
20
- /** Built-in `pageContext` properties set by vike.
21
- *
22
- * https://vike.dev/pageContext
23
- */
24
- type PageContextBuiltInServer<Page = [never]> = PageContextBuiltInCommon<Page> & PageContextUrlComputedPropsServer;
25
- /** For Vike internal use */
26
- type PageContextBuiltInServerInternal<Page = [never]> = PageContextBuiltInCommon<Page> & PageContextUrlComputedPropsInternal;
27
- type PageContextBuiltInCommon<Page = [never]> = {
15
+ type PageContextServer<Data = unknown> = PageContextBuiltInServer<Data> & Vike.PageContext;
16
+ type PageContext<Data = unknown> = PageContextClient<Data> | PageContextServer<Data>;
17
+ type PageContextClient<Data = unknown> = PageContextBuiltInClientWithClientRouting<Data> & Vike.PageContext;
18
+ type PageContextWithServerRouting<Data = unknown> = PageContextClientWithServerRouting<Data> | PageContextServer<Data>;
19
+ type PageContextClientWithServerRouting<Data = unknown> = PageContextBuiltInClientWithServerRouting<Data> & Vike.PageContext;
20
+ type PageContextBuiltInCommon<Data> = {
28
21
  /** The `export { Page }` of your `.page.js` file.
29
22
  *
30
23
  * https://vike.dev/Page
31
24
  */
32
- Page: Page extends [never] ? Config['Page'] : Page;
25
+ Page: Config['Page'];
33
26
  /** Route Parameters, e.g. `pageContext.routeParams.productId` for a Route String `/product/@productId`.
34
27
  *
35
28
  * https://vike.dev/route-string
@@ -39,7 +32,7 @@ type PageContextBuiltInCommon<Page = [never]> = {
39
32
  *
40
33
  * https://vike.dev/data
41
34
  */
42
- data?: unknown;
35
+ data: Data;
43
36
  /** The page's configuration values.
44
37
  *
45
38
  * https://vike.dev/config
@@ -100,11 +93,8 @@ type PageContextBuiltInCommon<Page = [never]> = {
100
93
  /** @deprecated */
101
94
  pageExports: Record<string, unknown>;
102
95
  };
103
- /** Client-side built-in `pageContext` properties set by vike (Client Routing).
104
- *
105
- * https://vike.dev/pageContext
106
- */
107
- type PageContextBuiltInClientWithClientRouting<Page = unknown> = Partial<PageContextBuiltInCommon<Page>> & Pick<PageContextBuiltInCommon<Page>, 'Page' | 'pageExports' | 'config' | 'configEntries' | 'exports' | 'exportsAll' | 'abortReason'> & {
96
+ type PageContextBuiltInServer<Data> = PageContextBuiltInCommon<Data> & PageContextUrlComputedPropsServer;
97
+ type PageContextBuiltInClientWithClientRouting<Data> = Partial<PageContextBuiltInCommon<Data>> & Pick<PageContextBuiltInCommon<Data>, 'Page' | 'pageExports' | 'config' | 'configEntries' | 'exports' | 'exportsAll' | 'abortReason' | 'data'> & {
108
98
  /** Whether the current page is already rendered to HTML */
109
99
  isHydration: boolean;
110
100
  /**
@@ -114,11 +104,7 @@ type PageContextBuiltInClientWithClientRouting<Page = unknown> = Partial<PageCon
114
104
  */
115
105
  isBackwardNavigation: boolean | null;
116
106
  } & PageContextUrlComputedPropsClient;
117
- /** Client-side built-in `pageContext` properties set by vike (Server Routing).
118
- *
119
- * https://vike.dev/pageContext
120
- */
121
- type PageContextBuiltInClientWithServerRouting<Page = unknown> = Partial<PageContextBuiltInCommon<Page>> & Pick<PageContextBuiltInCommon<Page>, 'Page' | 'pageExports' | 'exports' | 'abortReason'> & {
107
+ type PageContextBuiltInClientWithServerRouting<Data> = Partial<PageContextBuiltInCommon<Data>> & Pick<PageContextBuiltInCommon<Data>, 'Page' | 'pageExports' | 'exports' | 'abortReason' | 'data'> & {
122
108
  /**
123
109
  * Whether the current page is already rendered to HTML.
124
110
  *
@@ -132,3 +118,44 @@ type PageContextBuiltInClientWithServerRouting<Page = unknown> = Partial<PageCon
132
118
  */
133
119
  isBackwardNavigation: null;
134
120
  };
121
+ /** For Vike internal use */
122
+ type PageContextBuiltInServerInternal = Omit<PageContextBuiltInCommon<unknown> & PageContextUrlComputedPropsInternal, 'data'>;
123
+ /** @deprecated
124
+ * Replace:
125
+ * ```
126
+ * import type { PageContextBuiltInServer } from 'vike/types'
127
+ * ```
128
+ * With:
129
+ * ```
130
+ * import { PageContextServer } from 'vike/types'
131
+ * ```
132
+ *
133
+ * See https://vike.dev/pageContext#typescript
134
+ */
135
+ type PageContextBuiltInServer_deprecated<Page = never> = PageContextBuiltInServer<unknown>;
136
+ /** @deprecated
137
+ * Replace:
138
+ * ```
139
+ * import type { PageContextBuiltInClientWithClientRouting } from 'vike/types'
140
+ * ```
141
+ * With:
142
+ * ```
143
+ * import { PageContextClient } from 'vike/types'
144
+ * ```
145
+ *
146
+ * See https://vike.dev/pageContext#typescript
147
+ */
148
+ type PageContextBuiltInClientWithClientRouting_deprecated<Page = never> = PageContextBuiltInClientWithClientRouting<unknown>;
149
+ /** @deprecated
150
+ * Replace:
151
+ * ```
152
+ * import type { PageContextBuiltInClientWithServerRouting } from 'vike/types'
153
+ * ```
154
+ * With:
155
+ * ```
156
+ * import { PageContextClientWithServerRouting as PageContextClient } from 'vike/types'
157
+ * ```
158
+ *
159
+ * See https://vike.dev/pageContext#typescript
160
+ */
161
+ type PageContextBuiltInClientWithServerRouting_deprecated<Page = never> = PageContextBuiltInClientWithServerRouting<unknown>;
@@ -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.158";
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.158";
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.158';
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,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.158",
3
+ "version": "0.4.159-commit-6bcb2fd",
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
- }