vike 0.4.215 → 0.4.216

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 (84) hide show
  1. package/dist/cjs/__internal/index.js +2 -2
  2. package/dist/cjs/node/api/build.js +7 -2
  3. package/dist/cjs/node/api/context.js +8 -6
  4. package/dist/cjs/node/api/dev.js +7 -2
  5. package/dist/cjs/node/api/{prepareApiCall.js → prepareViteApiCall.js} +2 -2
  6. package/dist/cjs/node/api/prerender.js +7 -2
  7. package/dist/cjs/node/api/preview.js +7 -2
  8. package/dist/cjs/node/api/utils.js +1 -0
  9. package/dist/cjs/node/plugin/index.js +2 -3
  10. package/dist/cjs/node/plugin/onLoad.js +2 -2
  11. package/dist/cjs/node/plugin/plugins/buildConfig.js +6 -5
  12. package/dist/cjs/node/plugin/plugins/commonConfig.js +21 -3
  13. package/dist/cjs/node/plugin/plugins/devConfig/index.js +0 -3
  14. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +8 -4
  15. package/dist/cjs/node/plugin/plugins/previewConfig.js +0 -1
  16. package/dist/cjs/node/plugin/plugins/setGlobalContext.js +32 -17
  17. package/dist/cjs/node/prerender/runPrerender.js +3 -3
  18. package/dist/cjs/node/prerender/utils.js +1 -1
  19. package/dist/cjs/node/runtime/globalContext.js +6 -6
  20. package/dist/cjs/node/runtime/index-common.js +3 -1
  21. package/dist/cjs/node/runtime/renderPage.js +4 -2
  22. package/dist/cjs/node/runtime/utils.js +1 -2
  23. package/dist/cjs/node/runtime-dev/createDevMiddleware.js +25 -0
  24. package/dist/cjs/node/runtime-dev/index.js +32 -0
  25. package/dist/cjs/shared/page-configs/getConfigValueBuildTime.js +2 -2
  26. package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +2 -2
  27. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  28. package/dist/cjs/utils/assertSetup.js +135 -0
  29. package/dist/cjs/utils/isDocker.js +2 -2
  30. package/dist/cjs/utils/requireResolve.js +2 -2
  31. package/dist/esm/__internal/index.js +2 -2
  32. package/dist/esm/node/api/build.d.ts +5 -0
  33. package/dist/esm/node/api/build.js +7 -2
  34. package/dist/esm/node/api/context.js +9 -7
  35. package/dist/esm/node/api/dev.d.ts +5 -0
  36. package/dist/esm/node/api/dev.js +7 -2
  37. package/dist/esm/node/api/{prepareApiCall.d.ts → prepareViteApiCall.d.ts} +2 -2
  38. package/dist/esm/node/api/{prepareApiCall.js → prepareViteApiCall.js} +2 -2
  39. package/dist/esm/node/api/prerender.d.ts +5 -0
  40. package/dist/esm/node/api/prerender.js +7 -2
  41. package/dist/esm/node/api/preview.d.ts +5 -0
  42. package/dist/esm/node/api/preview.js +7 -2
  43. package/dist/esm/node/api/utils.d.ts +1 -0
  44. package/dist/esm/node/api/utils.js +1 -0
  45. package/dist/esm/node/cli/parseCli.d.ts +1 -1
  46. package/dist/esm/node/plugin/index.js +3 -4
  47. package/dist/esm/node/plugin/onLoad.js +1 -1
  48. package/dist/esm/node/plugin/plugins/buildConfig.js +7 -6
  49. package/dist/esm/node/plugin/plugins/commonConfig.js +21 -3
  50. package/dist/esm/node/plugin/plugins/devConfig/index.js +1 -4
  51. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +8 -4
  52. package/dist/esm/node/plugin/plugins/previewConfig.js +1 -2
  53. package/dist/esm/node/plugin/plugins/setGlobalContext.d.ts +1 -1
  54. package/dist/esm/node/plugin/plugins/setGlobalContext.js +34 -19
  55. package/dist/esm/node/prerender/runPrerender.js +4 -4
  56. package/dist/esm/node/prerender/utils.d.ts +1 -1
  57. package/dist/esm/node/prerender/utils.js +1 -1
  58. package/dist/esm/node/runtime/globalContext.d.ts +2 -2
  59. package/dist/esm/node/runtime/globalContext.js +7 -7
  60. package/dist/esm/node/runtime/index-common.d.ts +1 -0
  61. package/dist/esm/node/runtime/index-common.js +1 -0
  62. package/dist/esm/node/runtime/renderPage.js +5 -3
  63. package/dist/esm/node/runtime/utils.d.ts +1 -2
  64. package/dist/esm/node/runtime/utils.js +1 -2
  65. package/dist/esm/node/runtime-dev/createDevMiddleware.d.ts +10 -0
  66. package/dist/esm/node/runtime-dev/createDevMiddleware.js +23 -0
  67. package/dist/esm/node/runtime-dev/index.d.ts +3 -0
  68. package/dist/esm/node/runtime-dev/index.js +6 -0
  69. package/dist/esm/shared/page-configs/getConfigValueBuildTime.js +1 -1
  70. package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +1 -1
  71. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  72. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  73. package/dist/esm/utils/assertSetup.d.ts +20 -0
  74. package/dist/esm/utils/assertSetup.js +130 -0
  75. package/dist/esm/utils/isDocker.js +1 -1
  76. package/dist/esm/utils/projectInfo.d.ts +1 -1
  77. package/dist/esm/utils/requireResolve.js +1 -1
  78. package/package.json +1 -1
  79. package/dist/cjs/utils/assertIsNotProductionRuntime.js +0 -62
  80. package/dist/cjs/utils/assertNodeEnv.js +0 -106
  81. package/dist/esm/utils/assertIsNotProductionRuntime.d.ts +0 -12
  82. package/dist/esm/utils/assertIsNotProductionRuntime.js +0 -59
  83. package/dist/esm/utils/assertNodeEnv.d.ts +0 -10
  84. package/dist/esm/utils/assertNodeEnv.js +0 -103
@@ -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, isPlainObject, handleNodeEnv_prerender, pLimit, isArray, changeEnumerable } from './utils.js';
8
+ import { assert, assertUsage, assertWarning, hasProp, projectInfo, objectAssign, isObjectWithKeys, isCallable, getOutDirs, isPropertyGetter, assertPosixPath, urlToFile, isPlainObject, pLimit, isArray, changeEnumerable, onSetupPrerender } from './utils.js';
9
9
  import { prerenderPage, prerender404Page, getRenderContext, getPageContextInitEnhanced } from '../runtime/renderPage/renderPageAlreadyRouted.js';
10
10
  import pc from '@brillout/picocolors';
11
11
  import { cpus } from 'os';
@@ -28,7 +28,7 @@ import { getVikeConfig } from '../plugin/plugins/importUserCode/v1-design/getVik
28
28
  import { logErrorHint } from '../runtime/renderPage/logErrorHint.js';
29
29
  import { executeHook, isUserHookError } from '../../shared/hooks/executeHook.js';
30
30
  import { getConfigValueBuildTime } from '../../shared/page-configs/getConfigValueBuildTime.js';
31
- import { prepareApiCall } from '../api/prepareApiCall.js';
31
+ import { prepareViteApiCall } from '../api/prepareViteApiCall.js';
32
32
  async function runPrerenderFromAPI(options = {}) {
33
33
  return await runPrerender(options, 'prerender()');
34
34
  // - 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.
@@ -36,7 +36,7 @@ async function runPrerenderFromAPI(options = {}) {
36
36
  }
37
37
  async function runPrerenderFromCLIPrerenderCommand() {
38
38
  try {
39
- const { viteConfigEnhanced } = await prepareApiCall(undefined, 'prerender');
39
+ const { viteConfigEnhanced } = await prepareViteApiCall(undefined, 'prerender');
40
40
  await runPrerender({ viteConfig: viteConfigEnhanced }, '$ vike prerender');
41
41
  }
42
42
  catch (err) {
@@ -61,13 +61,13 @@ async function runPrerenderFromAutoRun(viteConfig, forceExit) {
61
61
  }
62
62
  async function runPrerender(options = {}, standaloneTrigger) {
63
63
  checkOutdatedOptions(options);
64
+ onSetupPrerender();
64
65
  setGlobalContext_isPrerendering();
65
66
  getHook_setIsPrerenderering();
66
67
  const logLevel = !!options.onPagePrerender ? 'warn' : 'info';
67
68
  if (logLevel === 'info') {
68
69
  console.log(`${pc.cyan(`vike v${projectInfo.projectVersion}`)} ${pc.green('pre-rendering HTML...')}`);
69
70
  }
70
- handleNodeEnv_prerender();
71
71
  await disableReactStreaming();
72
72
  const viteConfig = await resolveConfig(options.viteConfig || {}, 'vike pre-rendering', 'production');
73
73
  assertLoadedConfig(viteConfig, options);
@@ -9,7 +9,7 @@ export * from '../../utils/isPropertyGetter.js';
9
9
  export * from '../../utils/filesystemPathHandling.js';
10
10
  export * from '../../utils/urlToFile.js';
11
11
  export * from '../../utils/isPlainObject.js';
12
- export * from '../../utils/assertNodeEnv.js';
12
+ export * from '../../utils/assertSetup.js';
13
13
  export * from '../../utils/pLimit.js';
14
14
  export * from '../../utils/isFilePathAbsoluteFilesystem.js';
15
15
  export * from '../../utils/isArray.js';
@@ -11,7 +11,7 @@ export * from '../../utils/isPropertyGetter.js';
11
11
  export * from '../../utils/filesystemPathHandling.js';
12
12
  export * from '../../utils/urlToFile.js';
13
13
  export * from '../../utils/isPlainObject.js';
14
- export * from '../../utils/assertNodeEnv.js';
14
+ export * from '../../utils/assertSetup.js';
15
15
  export * from '../../utils/pLimit.js';
16
16
  export * from '../../utils/isFilePathAbsoluteFilesystem.js';
17
17
  export * from '../../utils/isArray.js';
@@ -9,7 +9,7 @@ export { initGlobalContext_runPrerender };
9
9
  export { initGlobalContext_getGlobalContextAsync };
10
10
  export { setGlobalContext_viteDevServer };
11
11
  export { setGlobalContext_viteConfig };
12
- export { setGlobalContext_isDev };
12
+ export { setGlobalContext_isViteDev };
13
13
  export { setGlobalContext_isPrerendering };
14
14
  import type { ViteManifest } from '../shared/ViteManifest.js';
15
15
  import type { ResolvedConfig, ViteDevServer } from 'vite';
@@ -52,7 +52,7 @@ declare function getGlobalContextSync(): GlobalContextPublic;
52
52
  declare function getGlobalContextAsync(isProduction: boolean): Promise<GlobalContextPublic>;
53
53
  declare function setGlobalContext_viteDevServer(viteDevServer: ViteDevServer): void;
54
54
  declare function setGlobalContext_viteConfig(viteConfig: ResolvedConfig, outDirRoot: string): void;
55
- declare function setGlobalContext_isDev(isDev: boolean): void;
55
+ declare function setGlobalContext_isViteDev(isViteDev: boolean): void;
56
56
  declare function setGlobalContext_isPrerendering(): void;
57
57
  declare function getViteDevServer(): ViteDevServer | null;
58
58
  declare function getViteConfig(): ResolvedConfig | null;
@@ -11,9 +11,9 @@ export { initGlobalContext_runPrerender };
11
11
  export { initGlobalContext_getGlobalContextAsync };
12
12
  export { setGlobalContext_viteDevServer };
13
13
  export { setGlobalContext_viteConfig };
14
- export { setGlobalContext_isDev };
14
+ export { setGlobalContext_isViteDev };
15
15
  export { setGlobalContext_isPrerendering };
16
- import { assert, assertNodeEnv_runtime, assertUsage, assertWarning, getGlobalObject, isPlainObject, objectAssign, objectKeys, genPromise } from './utils.js';
16
+ import { assert, onSetupRuntime, assertUsage, assertWarning, getGlobalObject, isPlainObject, objectAssign, objectKeys, genPromise } from './utils.js';
17
17
  import { loadImportBuild } from './globalContext/loadImportBuild.js';
18
18
  import { setPageFiles } from '../../shared/getPageFiles.js';
19
19
  import { assertPluginManifest } from '../shared/assertPluginManifest.js';
@@ -89,8 +89,8 @@ function assertIsNotInitilizedYet() {
89
89
  // In develpoment, globalObject.viteDevServer always needs to be awaited for before initializing globalObject.globalContext
90
90
  assert(!globalObject.globalContext);
91
91
  }
92
- function setGlobalContext_isDev(isDev) {
93
- globalObject.isDev = isDev;
92
+ function setGlobalContext_isViteDev(isViteDev) {
93
+ globalObject.isViteDev = isViteDev;
94
94
  }
95
95
  function setGlobalContext_isPrerendering() {
96
96
  globalObject.isPrerendering = true;
@@ -102,7 +102,7 @@ function getViteConfig() {
102
102
  return globalObject.viteConfig ?? null;
103
103
  }
104
104
  async function initGlobalContext_renderPage() {
105
- await initGlobalContext(!globalObject.isDev);
105
+ await initGlobalContext(!globalObject.isViteDev);
106
106
  }
107
107
  async function initGlobalContext_runPrerender() {
108
108
  if (globalObject.initGlobalContext_runPrerender_alreadyCalled)
@@ -138,8 +138,8 @@ async function initGlobalContext(isProduction) {
138
138
  assert(globalObject.globalContext.isPrerendering === (globalObject.isPrerendering ?? false));
139
139
  return;
140
140
  }
141
- const { viteDevServer, viteConfig, isDev, isPrerendering } = globalObject;
142
- assertNodeEnv_runtime(isDev ?? false);
141
+ const { viteDevServer, viteConfig, isPrerendering } = globalObject;
142
+ onSetupRuntime();
143
143
  if (!isProduction) {
144
144
  assert(viteConfig);
145
145
  assert(viteDevServer);
@@ -3,6 +3,7 @@ export { escapeInject, dangerouslySkipEscape } from './html/renderHtml.js';
3
3
  export { pipeWebStream, pipeNodeStream, pipeStream, stampPipe } from './html/stream.js';
4
4
  export { PROJECT_VERSION as version } from './utils.js';
5
5
  export { getGlobalContextSync, getGlobalContextAsync } from './globalContext.js';
6
+ export { createDevMiddleware } from '../runtime-dev/index.js';
6
7
  export { injectAssets__public as _injectAssets } from './html/injectAssets/injectAssets__public.js';
7
8
  export { createPageRenderer } from '../createPageRenderer.js';
8
9
  import './page-files/setup.js';
@@ -3,6 +3,7 @@ export { escapeInject, dangerouslySkipEscape } from './html/renderHtml.js';
3
3
  export { pipeWebStream, pipeNodeStream, pipeStream, stampPipe } from './html/stream.js';
4
4
  export { PROJECT_VERSION as version } from './utils.js';
5
5
  export { getGlobalContextSync, getGlobalContextAsync } from './globalContext.js';
6
+ export { createDevMiddleware } from '../runtime-dev/index.js';
6
7
  // TODO/v1-release: remove
7
8
  export { injectAssets__public as _injectAssets } from './html/injectAssets/injectAssets__public.js';
8
9
  // TODO/v1-release: remove
@@ -2,7 +2,7 @@ export { renderPage };
2
2
  export { renderPage_addWrapper };
3
3
  import { getRenderContext, getPageContextInitEnhanced, renderPageAlreadyRouted } from './renderPage/renderPageAlreadyRouted.js';
4
4
  import { route } from '../../shared/route/index.js';
5
- import { assert, hasProp, objectAssign, isUrl, parseUrl, assertEnv, assertWarning, getGlobalObject, checkType, assertUsage, normalizeUrlPathname, removeBaseServer, modifyUrlPathname, prependBase, removeUrlOrigin, setUrlOrigin, createUrlFromComponents, isUri, getUrlPretty } from './utils.js';
5
+ import { assert, hasProp, objectAssign, isUrl, parseUrl, onSetupRuntime, assertWarning, getGlobalObject, checkType, assertUsage, normalizeUrlPathname, removeBaseServer, modifyUrlPathname, prependBase, removeUrlOrigin, setUrlOrigin, createUrlFromComponents, isUri, getUrlPretty } from './utils.js';
6
6
  import { assertNoInfiniteAbortLoop, getPageContextFromAllRewrites, isAbortError, logAbortErrorHandled } from '../../shared/route/abort.js';
7
7
  import { getGlobalContext, initGlobalContext_renderPage } from './globalContext.js';
8
8
  import { handlePageContextRequestUrl } from './renderPage/handlePageContextRequestUrl.js';
@@ -31,7 +31,7 @@ const renderPage_addWrapper = (wrapper) => {
31
31
  async function renderPage(pageContextInit) {
32
32
  assertArguments(...arguments);
33
33
  assert(hasProp(pageContextInit, 'urlOriginal', 'string')); // assertUsage() already implemented at assertArguments()
34
- assertEnv();
34
+ onSetupRuntime();
35
35
  assertIsUrl(pageContextInit.urlOriginal);
36
36
  const urlPathnameWithBase = parseUrl(pageContextInit.urlOriginal, '/').pathname;
37
37
  assertIsNotViteRequest(urlPathnameWithBase, pageContextInit.urlOriginal);
@@ -332,7 +332,9 @@ function assertIsUrl(urlOriginal) {
332
332
  }
333
333
  function assertIsNotViteRequest(urlPathname, urlOriginal) {
334
334
  const isViteRequest = urlPathname.startsWith('/@vite/client') || urlPathname.startsWith('/@fs/') || urlPathname.startsWith('/__vite_ping');
335
- assertUsage(!isViteRequest, `${pc.code('renderPage(pageContextInit)')} (https://vike.dev/renderPage) called with ${pc.code(`pageContextInit.urlOriginal===${JSON.stringify(urlOriginal)}`)} which is unexpected because this URL should have already been handled by Vite's development middleware. Make sure to 1. install Vite's development middleware and 2. add Vite's middleware *before* Vike's middleware, see https://vike.dev/renderPage`);
335
+ if (!isViteRequest)
336
+ return;
337
+ assertUsage(false, `${pc.code('renderPage(pageContextInit)')} called with ${pc.code(`pageContextInit.urlOriginal===${JSON.stringify(urlOriginal)}`)} which is unexpected because the URL ${pc.bold(urlOriginal)} should have already been handled by the development middleware: make sure the ${pc.cyan('createDevMiddleware()')} middleware is executed *before* the ${pc.cyan('renderPage()')} middleware, see ${pc.underline('https://vike.dev/renderPage')}`);
336
338
  }
337
339
  function normalizeUrl(pageContextInit, httpRequestId) {
338
340
  const { trailingSlash, disableUrlNormalization, baseServer } = getGlobalContext();
@@ -39,9 +39,8 @@ export * from '../../utils/objectKeys.js';
39
39
  export * from '../../utils/objectEntries.js';
40
40
  export * from '../../utils/objectFromEntries.js';
41
41
  export * from '../../utils/getFileExtension.js';
42
- export * from '../../utils/assertIsNotProductionRuntime.js';
42
+ export * from '../../utils/assertSetup.js';
43
43
  export * from '../../utils/path-shim.js';
44
- export * from '../../utils/assertNodeEnv.js';
45
44
  export * from '../../utils/isHtml.js';
46
45
  export * from '../../utils/warnIfErrorIsNotObject.js';
47
46
  export * from '../../utils/stripAnsi.js';
@@ -43,9 +43,8 @@ export * from '../../utils/objectKeys.js';
43
43
  export * from '../../utils/objectEntries.js';
44
44
  export * from '../../utils/objectFromEntries.js';
45
45
  export * from '../../utils/getFileExtension.js';
46
- export * from '../../utils/assertIsNotProductionRuntime.js';
46
+ export * from '../../utils/assertSetup.js';
47
47
  export * from '../../utils/path-shim.js';
48
- export * from '../../utils/assertNodeEnv.js';
49
48
  export * from '../../utils/isHtml.js';
50
49
  export * from '../../utils/warnIfErrorIsNotObject.js';
51
50
  export * from '../../utils/stripAnsi.js';
@@ -0,0 +1,10 @@
1
+ export { createDevMiddleware };
2
+ import type { ResolvedConfig, Connect, ViteDevServer } from 'vite';
3
+ import type { APIOptions } from '../api/types.js';
4
+ declare function createDevMiddleware(options?: {
5
+ root?: string;
6
+ } & APIOptions): Promise<{
7
+ devMiddleware: Connect.Server;
8
+ viteServer: ViteDevServer;
9
+ viteConfig: ResolvedConfig;
10
+ }>;
@@ -0,0 +1,23 @@
1
+ export { createDevMiddleware };
2
+ import { createServer } from 'vite';
3
+ import { prepareViteApiCall } from '../api/prepareViteApiCall.js';
4
+ /*
5
+ * Create server middleware for development with HMR and lazy-transpiling.
6
+ *
7
+ * https://vike.dev/createDevMiddleware
8
+ */
9
+ async function createDevMiddleware(options = {}) {
10
+ const viteConfig = {
11
+ ...options.viteConfig,
12
+ server: {
13
+ ...options.viteConfig?.server,
14
+ middlewareMode: options.viteConfig?.server?.middlewareMode ?? true
15
+ }
16
+ };
17
+ if (options.root)
18
+ viteConfig.root = options.root;
19
+ const { viteConfigEnhanced } = await prepareViteApiCall(viteConfig, 'dev');
20
+ const server = await createServer(viteConfigEnhanced);
21
+ const devMiddleware = server.middlewares;
22
+ return { devMiddleware, viteServer: server, viteConfig: server.config };
23
+ }
@@ -0,0 +1,3 @@
1
+ export { createDevMiddleware_ as createDevMiddleware };
2
+ import type { createDevMiddleware as createDevMiddlewareType } from '../runtime-dev/createDevMiddleware.js';
3
+ declare const createDevMiddleware_: typeof createDevMiddlewareType;
@@ -0,0 +1,6 @@
1
+ export { createDevMiddleware_ as createDevMiddleware };
2
+ const createDevMiddleware_ = async (...args) => {
3
+ const p = './createDevMiddleware.js';
4
+ const { createDevMiddleware } = await import(/*webpackIgnore: true*/ /* @vite-ignore */ p);
5
+ return createDevMiddleware(...args);
6
+ };
@@ -1,6 +1,6 @@
1
1
  export { getConfigValueBuildTime };
2
2
  import { assert } from '../utils.js';
3
- import { assertIsNotProductionRuntime } from '../../utils/assertIsNotProductionRuntime.js';
3
+ import { assertIsNotProductionRuntime } from '../../utils/assertSetup.js';
4
4
  import { getConfigValueTyped } from './getConfigValueTyped.js';
5
5
  assertIsNotProductionRuntime();
6
6
  function getConfigValueBuildTime(pageConfig, configName, type) {
@@ -1,5 +1,5 @@
1
1
  export { serializeConfigValues };
2
- import { assertIsNotProductionRuntime } from '../../../utils/assertIsNotProductionRuntime.js';
2
+ import { assertIsNotProductionRuntime } from '../../../utils/assertSetup.js';
3
3
  import { assert, assertUsage, getPropAccessNotation } from '../../../node/plugin/utils.js';
4
4
  import { addImportStatement } from '../../../node/plugin/plugins/importUserCode/addImportStatement.js';
5
5
  import { parsePointerImportData } from '../../../node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transformPointerImports.js';
@@ -1 +1 @@
1
- export declare const PROJECT_VERSION: "0.4.215";
1
+ export declare const PROJECT_VERSION: "0.4.216";
@@ -1,2 +1,2 @@
1
1
  // Automatically updated by @brillout/release-me
2
- export const PROJECT_VERSION = '0.4.215';
2
+ export const PROJECT_VERSION = '0.4.216';
@@ -0,0 +1,20 @@
1
+ export { assertIsNotProductionRuntime };
2
+ export { onSetupRuntime };
3
+ export { onSetupBuild };
4
+ export { onSetupPrerender };
5
+ export { setNodeEnvProduction };
6
+ export { markSetup_viteDevServer };
7
+ export { markSetup_vitePreviewServer };
8
+ export { markSetup_vikeVitePlugin };
9
+ export { markSetup_isViteDev };
10
+ export { markSetup_isPrerendering };
11
+ declare function assertIsNotProductionRuntime(): void | undefined;
12
+ declare function onSetupRuntime(): void | undefined;
13
+ declare function onSetupBuild(): void;
14
+ declare function onSetupPrerender(): void;
15
+ declare function markSetup_viteDevServer(): void | undefined;
16
+ declare function markSetup_vitePreviewServer(): void | undefined;
17
+ declare function markSetup_vikeVitePlugin(): void;
18
+ declare function markSetup_isViteDev(isViteDev: boolean): void;
19
+ declare function markSetup_isPrerendering(): void;
20
+ declare function setNodeEnvProduction(): void | undefined;
@@ -0,0 +1,130 @@
1
+ export { assertIsNotProductionRuntime };
2
+ export { onSetupRuntime };
3
+ export { onSetupBuild };
4
+ export { onSetupPrerender };
5
+ export { setNodeEnvProduction };
6
+ export { markSetup_viteDevServer };
7
+ export { markSetup_vitePreviewServer };
8
+ export { markSetup_vikeVitePlugin };
9
+ export { markSetup_isViteDev };
10
+ export { markSetup_isPrerendering };
11
+ import { assert, assertUsage, assertWarning } from './assert.js';
12
+ import { assertIsNotBrowser } from './assertIsNotBrowser.js';
13
+ import { createDebugger } from './debug.js';
14
+ import { getGlobalObject } from './getGlobalObject.js';
15
+ import { isVitest } from './isVitest.js';
16
+ import pc from '@brillout/picocolors';
17
+ assertIsNotBrowser();
18
+ const debug = createDebugger('vike:setup');
19
+ const setup = getGlobalObject('utils/assertIsNotProductionRuntime.ts', {});
20
+ // Called by Vike modules that want to ensure that they aren't loaded by the server runtime in production
21
+ function assertIsNotProductionRuntime() {
22
+ if (debug.isActivated)
23
+ debug('assertIsNotProductionRuntime()', new Error().stack);
24
+ setup.shouldNotBeProduction = true;
25
+ }
26
+ function onSetupRuntime() {
27
+ if (debug.isActivated)
28
+ debug('assertSetup()', new Error().stack);
29
+ if (isTest())
30
+ return;
31
+ if (!isViteLoaded()) {
32
+ // TODO: make it assertUsage() again once https://github.com/vikejs/vike/issues/1528 is implemented.
33
+ assertWarning(!isNodeEnvDev(), `The ${getEnvDescription()}, which seems contradictory because the environment seems to be a production environment (Vite isn't loaded), see https://vike.dev/NODE_ENV`, { onlyOnce: true });
34
+ assertUsage(!setup.vikeVitePlugin, "Loading Vike's Vite plugin (the vike/plugin module) is prohibited in production.");
35
+ // This assert() one of the main goal of this file: it ensures assertIsNotProductionRuntime()
36
+ assert(!setup.shouldNotBeProduction);
37
+ }
38
+ else {
39
+ // TODO: make it assertUsage() again once https://github.com/vikejs/vike/issues/1528 is implemented.
40
+ assertWarning(isNodeEnvDev() || setup.vitePreviewServer || setup.isPrerendering, `The ${getEnvDescription()}, but Vite is loaded which is prohibited in production, see https://vike.dev/NODE_ENV`, { onlyOnce: true });
41
+ // These two assert() calls aren't that interesting
42
+ assert(setup.vikeVitePlugin);
43
+ assert(setup.shouldNotBeProduction);
44
+ }
45
+ }
46
+ // Ensure NODE_ENV is 'production' when building.
47
+ // - Used by both Vue and React for bundling minified version:
48
+ // - Vue: https://github.com/vuejs/core/blob/f66a75ea75c8aece065b61e2126b4c5b2338aa6e/packages/vue/index.js
49
+ // - React: https://github.com/facebook/react/blob/01ab35a9a731dec69995fbd28f3ac7eaad11e183/packages/react/npm/index.js
50
+ // - Required for React: setting NODE_ENV to a value other than 'production' triggers an error: https://github.com/vikejs/vike/issues/1469#issuecomment-1969301797
51
+ // - Not required for Vue: when building the app, NODE_ENV can be set to a value other than 'production', e.g. 'development'.
52
+ function onSetupBuild() {
53
+ assertUsageNodeEnvIsNotDev('building');
54
+ /* Not needed: Vite already sets `process.env.NODE_ENV = 'production'`
55
+ setNodeEnvProduction()
56
+ */
57
+ }
58
+ function onSetupPrerender() {
59
+ markSetup_isPrerendering();
60
+ if (getNodeEnvValue())
61
+ assertUsageNodeEnvIsNotDev('pre-rendering');
62
+ setNodeEnvProduction();
63
+ }
64
+ function isViteLoaded() {
65
+ // Do we need setup.viteDevServer or setup.vitePreviewServer ?
66
+ return setup.viteDevServer || setup.vitePreviewServer || setup.isViteDev !== undefined;
67
+ }
68
+ function isTest() {
69
+ return isVitest() || getNodeEnvValue() === 'test';
70
+ }
71
+ // Called by Vite hook configureServer()
72
+ function markSetup_viteDevServer() {
73
+ if (debug.isActivated)
74
+ debug('markSetup_viteDevServer()', new Error().stack);
75
+ setup.viteDevServer = true;
76
+ }
77
+ // Called by Vite hook configurePreviewServer()
78
+ function markSetup_vitePreviewServer() {
79
+ if (debug.isActivated)
80
+ debug('markSetup_vitePreviewServer()', new Error().stack);
81
+ setup.vitePreviewServer = true;
82
+ }
83
+ // Called by ../node/plugin/index.ts
84
+ function markSetup_vikeVitePlugin() {
85
+ if (debug.isActivated)
86
+ debug('markSetup_vikeVitePlugin()', new Error().stack);
87
+ setup.vikeVitePlugin = true;
88
+ }
89
+ // Whether Vite is loaded and whether it's in dev mode (the value returned by `isDevCheck()`)
90
+ function markSetup_isViteDev(isViteDev) {
91
+ if (debug.isActivated)
92
+ debug('markSetup_isViteDev()', new Error().stack);
93
+ setup.isViteDev = isViteDev;
94
+ }
95
+ // Called by ../node/prerender/runPrerender.ts
96
+ function markSetup_isPrerendering() {
97
+ if (debug.isActivated)
98
+ debug('markSetup_isPrerendering()', new Error().stack);
99
+ setup.isPrerendering = true;
100
+ }
101
+ function assertUsageNodeEnvIsNotDev(operation) {
102
+ if (!isNodeEnvDev())
103
+ return;
104
+ // TODO: make it assertUsage() again once https://github.com/vikejs/vike/issues/1528 is implemented.
105
+ assertWarning(false, `The ${getEnvDescription()} which is forbidden upon ${operation}, see https://vike.dev/NODE_ENV`, { onlyOnce: true });
106
+ }
107
+ function getEnvDescription() {
108
+ const nodeEnv = getNodeEnvValue();
109
+ const isDev = isNodeEnvDev();
110
+ const envType = `${(isDev ? 'development' : 'production')} environment`;
111
+ const nodeEnvDesc = `environment is set to be a ${pc.bold(envType)} by ${pc.cyan(`process.env.NODE_ENV===${JSON.stringify(nodeEnv)}`)}`;
112
+ return nodeEnvDesc;
113
+ }
114
+ function isNodeEnvDev() {
115
+ const nodeEnv = getNodeEnvValue();
116
+ // That's quite strict, let's see if some user complains
117
+ return !nodeEnv || ['development', 'dev'].includes(nodeEnv);
118
+ }
119
+ function getNodeEnvValue() {
120
+ if (typeof process === 'undefined')
121
+ return null;
122
+ return process.env.NODE_ENV?.toLowerCase();
123
+ }
124
+ function setNodeEnvProduction() {
125
+ // The statement `process.env['NODE_ENV'] = 'production'` chokes webpack v4
126
+ const proc = process;
127
+ const { env } = proc;
128
+ env.NODE_ENV = 'production';
129
+ assert(getNodeEnvValue() === 'production');
130
+ }
@@ -1,6 +1,6 @@
1
1
  export { isDocker };
2
2
  import fs from 'node:fs';
3
- import { assertIsNotProductionRuntime } from './assertIsNotProductionRuntime.js';
3
+ import { assertIsNotProductionRuntime } from './assertSetup.js';
4
4
  assertIsNotProductionRuntime();
5
5
  function isDocker() {
6
6
  return hasContainerEnv() || isDockerContainer();
@@ -1,4 +1,4 @@
1
1
  export declare const projectInfo: {
2
2
  projectName: "Vike";
3
- projectVersion: "0.4.215";
3
+ projectVersion: "0.4.216";
4
4
  };
@@ -1,7 +1,7 @@
1
1
  export { requireResolve };
2
2
  import { assert } from './assert.js';
3
3
  import { assertIsNotBrowser } from './assertIsNotBrowser.js';
4
- import { assertIsNotProductionRuntime } from './assertIsNotProductionRuntime.js';
4
+ import { assertIsNotProductionRuntime } from './assertSetup.js';
5
5
  import { assertPosixPath, toPosixPath } from './filesystemPathHandling.js';
6
6
  import { scriptFileExtensionList } from './isScriptFile.js';
7
7
  import { createRequire } from 'module';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.215",
3
+ "version": "0.4.216",
4
4
  "repository": "https://github.com/vikejs/vike",
5
5
  "exports": {
6
6
  "./server": {
@@ -1,62 +0,0 @@
1
- "use strict";
2
- // Mechanism to ensure code isn't loaded by production runtime
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.vikeVitePluginLoadedInProductionError = void 0;
5
- exports.assertIsNotProductionRuntime = assertIsNotProductionRuntime;
6
- exports.markEnvAsViteDev = markEnvAsViteDev;
7
- exports.markEnvAsVitePreview = markEnvAsVitePreview;
8
- exports.markEnvAsVikePluginLoaded = markEnvAsVikePluginLoaded;
9
- exports.assertEnv = assertEnv;
10
- const assert_js_1 = require("./assert.js");
11
- const assertIsNotBrowser_js_1 = require("./assertIsNotBrowser.js");
12
- const debug_js_1 = require("./debug.js");
13
- const getGlobalObject_js_1 = require("./getGlobalObject.js");
14
- const isVitest_js_1 = require("./isVitest.js");
15
- (0, assertIsNotBrowser_js_1.assertIsNotBrowser)();
16
- const debug = (0, debug_js_1.createDebugger)('vike:setup');
17
- const vikeVitePluginLoadedInProductionError = `Loading Vike's Vite plugin (the vike/plugin module) is prohibited in production.`;
18
- exports.vikeVitePluginLoadedInProductionError = vikeVitePluginLoadedInProductionError;
19
- const env = (0, getGlobalObject_js_1.getGlobalObject)('utils/assertIsNotProductionRuntime.ts', {});
20
- // Called by Vike modules that want to ensure that they aren't loaded by the server runtime in production
21
- function assertIsNotProductionRuntime() {
22
- if (debug.isActivated)
23
- debug('assertIsNotProductionRuntime()', new Error().stack);
24
- env.shouldNotBeProduction = true;
25
- }
26
- // Called by Vite hook configureServer()
27
- function markEnvAsViteDev() {
28
- if (debug.isActivated)
29
- debug('markEnvAsViteDev()', new Error().stack);
30
- env.isViteDev = true;
31
- }
32
- // Called by Vite hook configurePreviewServer()
33
- function markEnvAsVitePreview() {
34
- if (debug.isActivated)
35
- debug('markEnvAsVitePreview()', new Error().stack);
36
- env.isVitePreview = true;
37
- }
38
- // Called by ../node/plugin/index.ts
39
- function markEnvAsVikePluginLoaded() {
40
- if (debug.isActivated)
41
- debug('markEnvAsVikePluginLoaded()', new Error().stack);
42
- env.isVikePluginLoaded = true;
43
- }
44
- // Called by ../node/runtime/index.ts
45
- function assertEnv() {
46
- if (debug.isActivated)
47
- debug('assertEnv()', new Error().stack);
48
- if ((0, isVitest_js_1.isVitest)())
49
- return;
50
- const isProduction = !env.isViteDev && !env.isVitePreview;
51
- if (isProduction) {
52
- // 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.)
53
- (0, assert_js_1.assertUsage)(!env.isVikePluginLoaded, vikeVitePluginLoadedInProductionError);
54
- // This assert() is the main goal of this file: it ensures assertIsNotProductionRuntime()
55
- (0, assert_js_1.assert)(!env.shouldNotBeProduction);
56
- }
57
- else {
58
- // This assert() is obious and boring
59
- (0, assert_js_1.assert)(env.shouldNotBeProduction);
60
- (0, assert_js_1.assert)(env.isVikePluginLoaded);
61
- }
62
- }
@@ -1,106 +0,0 @@
1
- "use strict";
2
- // This file serves the following three purposes:
3
- // 1. Upon building the app, we ensure the right NODE_ENV value is set.
4
- // - Both Vue and React use NODE_ENV for enabling production-specific features:
5
- // - Vue: https://github.com/vuejs/core/blob/f66a75ea75c8aece065b61e2126b4c5b2338aa6e/packages/vue/index.js
6
- // - React: https://github.com/facebook/react/blob/01ab35a9a731dec69995fbd28f3ac7eaad11e183/packages/react/npm/index.js
7
- // - Setting NODE_ENV to 'production' doesn't seem to make any sense in development.
8
- // - With React upon building the app, setting NODE_ENV to a value other than 'production' triggers an error: https://github.com/vikejs/vike/issues/1469#issuecomment-1969301797
9
- // - With Vue upon building the app, NODE_ENV can be set to a value other than 'production', e.g. 'development'.
10
- // 2. Ensure Vite isn't loaded in production.
11
- // - We currently only check whether Vite's development middleware is instantiated (i.e. whether Vite's `createServer()` was called). Is there a way to detect whether Vite's code is loaded?
12
- // 3. Ensure NODE_ENV isn't mistakenly set to a wrong value.
13
- var __importDefault = (this && this.__importDefault) || function (mod) {
14
- return (mod && mod.__esModule) ? mod : { "default": mod };
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.assertNodeEnv_build = assertNodeEnv_build;
18
- exports.assertNodeEnv_runtime = assertNodeEnv_runtime;
19
- exports.assertNodeEnv_onVikePluginLoad = assertNodeEnv_onVikePluginLoad;
20
- exports.handleNodeEnv_prerender = handleNodeEnv_prerender;
21
- exports.handleNodeEnv_vitePluginVercel = handleNodeEnv_vitePluginVercel;
22
- const picocolors_1 = __importDefault(require("@brillout/picocolors"));
23
- const assertIsNotBrowser_js_1 = require("./assertIsNotBrowser.js");
24
- const assert_js_1 = require("./assert.js");
25
- const assertIsNotProductionRuntime_js_1 = require("./assertIsNotProductionRuntime.js");
26
- (0, assertIsNotBrowser_js_1.assertIsNotBrowser)();
27
- function assertNodeEnv_build() {
28
- assertNodeEnvIsNotDev('building');
29
- }
30
- function assertNodeEnv_runtime(isViteDev) {
31
- const nodeEnv = getNodeEnv();
32
- if (nodeEnv === null || nodeEnv === 'test')
33
- return;
34
- const isNodeDev = isNodeEnvDev();
35
- // 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
36
- if (isViteDev === isNodeDev)
37
- return;
38
- const nodeEnvDesc = getNodeEnvDesc();
39
- // TODO: make it assertUsage() again once #1528 is implemented.
40
- const errMsg = `Running ${isViteDev ? picocolors_1.default.cyan('$ vike dev') : 'app in production'} while the ${nodeEnvDesc} which is contradictory, see https://vike.dev/NODE_ENV`;
41
- (0, assert_js_1.assertWarning)(false, errMsg, { onlyOnce: true });
42
- }
43
- function assertNodeEnv_onVikePluginLoad() {
44
- const nodeEnv = getNodeEnv();
45
- if (nodeEnv === 'test')
46
- return;
47
- // TODO: make it assertUsage() again once #1528 is implemented.
48
- (0, assert_js_1.assertWarning)(
49
- /* We can enable this assertion after Vike's CLI is implemented and using Vite's CLI is deprecated (we can then check whether the context is a `$ vike build`).
50
- isNodeEnvDev() || isVikeCliBuild(),
51
- /*/
52
- isNodeEnvDev() || true,
53
- ///*/
54
- [
55
- picocolors_1.default.cyan(`process.env.NODE_ENV === ${JSON.stringify(nodeEnv)}`),
56
- '(which Vike interprets as a non-development environment https://vike.dev/NODE_ENV)',
57
- 'while the vike/plugin module is loaded.',
58
- assertIsNotProductionRuntime_js_1.vikeVitePluginLoadedInProductionError
59
- ].join(' '), { onlyOnce: true });
60
- }
61
- function handleNodeEnv_prerender() {
62
- const assertNodeEnv = () => assertNodeEnvIsNotDev('pre-rendering');
63
- if (getNodeEnv())
64
- assertNodeEnv();
65
- setNodeEnvToProduction();
66
- assertNodeEnv();
67
- }
68
- function handleNodeEnv_vitePluginVercel() {
69
- setNodeEnvToProduction();
70
- }
71
- function getNodeEnv() {
72
- if (typeof process === 'undefined')
73
- return null;
74
- return process.env.NODE_ENV;
75
- }
76
- function setNodeEnvToProduction() {
77
- // The statement `process.env['NODE_ENV'] = 'production'` chokes webpack v4
78
- const proc = process;
79
- const { env } = proc;
80
- env.NODE_ENV = 'production';
81
- }
82
- function isNodeEnvDev() {
83
- const nodeEnv = getNodeEnv();
84
- if (!nodeEnv)
85
- return true;
86
- if (['development', 'dev'].includes(nodeEnv))
87
- return true;
88
- // That's quite aggressive, let's see if some user complains
89
- return false;
90
- }
91
- function getNodeEnvDesc() {
92
- const nodeEnv = getNodeEnv();
93
- const isDev = isNodeEnvDev();
94
- const nodeEnvDesc = `environment is set to be a ${(isDev ? 'development' : 'production')} environment by ${picocolors_1.default.cyan(`process.env.NODE_ENV === ${JSON.stringify(nodeEnv)}`)}`;
95
- return nodeEnvDesc;
96
- }
97
- function assertNodeEnvIsNotDev(operation) {
98
- const isDev = isNodeEnvDev();
99
- if (!isDev)
100
- return;
101
- const nodeEnvDesc = getNodeEnvDesc();
102
- // TODO: make it assertUsage() again once #1528 is implemented.
103
- (0, assert_js_1.assertWarning)(false, `The ${nodeEnvDesc} which is forbidden upon ${operation}, see https://vike.dev/NODE_ENV`, {
104
- onlyOnce: true
105
- });
106
- }