vike 0.4.225-commit-b8fc36e → 0.4.225-commit-706a37b

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 (62) hide show
  1. package/dist/cjs/node/api/prepareViteApiCall.js +4 -2
  2. package/dist/cjs/node/api/prerender.js +0 -1
  3. package/dist/cjs/node/api/preview.js +27 -6
  4. package/dist/cjs/node/cli/entry.js +4 -2
  5. package/dist/cjs/node/plugin/plugins/build/pluginModuleBanner.js +51 -0
  6. package/dist/cjs/node/plugin/plugins/build.js +3 -1
  7. package/dist/cjs/node/plugin/plugins/commonConfig.js +4 -0
  8. package/dist/cjs/node/prerender/utils.js +1 -1
  9. package/dist/cjs/node/runtime/globalContext.js +8 -4
  10. package/dist/cjs/node/runtime/utils.js +1 -1
  11. package/dist/cjs/node/shared/utils.js +1 -1
  12. package/dist/cjs/node/shared/virtual-files.js +14 -10
  13. package/dist/cjs/shared/modifyUrl.js +3 -5
  14. package/dist/cjs/shared/modifyUrlSameOrigin.js +42 -0
  15. package/dist/cjs/shared/utils.js +2 -1
  16. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  17. package/dist/cjs/utils/assertSetup.js +17 -8
  18. package/dist/cjs/utils/isNullish.js +16 -0
  19. package/dist/cjs/utils/objectFilter.js +10 -0
  20. package/dist/esm/client/client-routing-runtime/navigate.d.ts +6 -5
  21. package/dist/esm/client/client-routing-runtime/navigate.js +6 -2
  22. package/dist/esm/client/client-routing-runtime/normalizeUrlArgument.js +1 -1
  23. package/dist/esm/node/api/prepareViteApiCall.d.ts +1 -0
  24. package/dist/esm/node/api/prepareViteApiCall.js +4 -2
  25. package/dist/esm/node/api/prerender.js +0 -1
  26. package/dist/esm/node/api/preview.d.ts +1 -1
  27. package/dist/esm/node/api/preview.js +24 -6
  28. package/dist/esm/node/cli/entry.js +4 -2
  29. package/dist/esm/node/plugin/plugins/build/pluginModuleBanner.d.ts +3 -0
  30. package/dist/esm/node/plugin/plugins/build/pluginModuleBanner.js +49 -0
  31. package/dist/esm/node/plugin/plugins/build.js +3 -1
  32. package/dist/esm/node/plugin/plugins/commonConfig.d.ts +2 -0
  33. package/dist/esm/node/plugin/plugins/commonConfig.js +4 -0
  34. package/dist/esm/node/prerender/utils.d.ts +1 -1
  35. package/dist/esm/node/prerender/utils.js +1 -1
  36. package/dist/esm/node/runtime/globalContext.d.ts +2 -3
  37. package/dist/esm/node/runtime/globalContext.js +8 -4
  38. package/dist/esm/node/runtime/utils.d.ts +1 -1
  39. package/dist/esm/node/runtime/utils.js +1 -1
  40. package/dist/esm/node/shared/utils.d.ts +1 -1
  41. package/dist/esm/node/shared/utils.js +1 -1
  42. package/dist/esm/node/shared/virtual-files.d.ts +2 -0
  43. package/dist/esm/node/shared/virtual-files.js +14 -10
  44. package/dist/esm/shared/modifyUrl.d.ts +2 -2
  45. package/dist/esm/shared/modifyUrl.js +3 -5
  46. package/dist/esm/shared/modifyUrlSameOrigin.d.ts +9 -0
  47. package/dist/esm/shared/modifyUrlSameOrigin.js +40 -0
  48. package/dist/esm/shared/utils.d.ts +2 -1
  49. package/dist/esm/shared/utils.js +2 -1
  50. package/dist/esm/types/index.d.ts +0 -1
  51. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  52. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  53. package/dist/esm/utils/assertSetup.d.ts +2 -2
  54. package/dist/esm/utils/assertSetup.js +17 -8
  55. package/dist/esm/utils/isNullish.d.ts +3 -0
  56. package/dist/esm/utils/isNullish.js +11 -0
  57. package/dist/esm/utils/objectFilter.d.ts +1 -0
  58. package/dist/esm/utils/objectFilter.js +7 -0
  59. package/package.json +2 -2
  60. package/dist/cjs/utils/isNotNullish.js +0 -5
  61. package/dist/esm/utils/isNotNullish.d.ts +0 -1
  62. package/dist/esm/utils/isNotNullish.js +0 -1
@@ -57,8 +57,10 @@ async function cmdBuild() {
57
57
  async function cmdPreview() {
58
58
  try {
59
59
  const { viteServer } = await preview();
60
- viteServer.printUrls();
61
- viteServer.bindCLIShortcuts({ print: true });
60
+ if (viteServer) {
61
+ viteServer.printUrls();
62
+ viteServer.bindCLIShortcuts({ print: true });
63
+ }
62
64
  }
63
65
  catch (err) {
64
66
  console.error(pc.red(`Error while starting preview server:`));
@@ -0,0 +1,3 @@
1
+ export { pluginModuleBanner };
2
+ import type { Plugin } from 'vite';
3
+ declare function pluginModuleBanner(): Plugin;
@@ -0,0 +1,49 @@
1
+ export { pluginModuleBanner };
2
+ import { assert } from '../../utils.js';
3
+ import { removeVirtualIdTag } from '../../../shared/virtual-files.js';
4
+ import { isViteServerBuild, isViteServerBuild_safe } from '../../shared/isViteServerBuild.js';
5
+ // Rollup's banner feature doesn't work with Vite: https://github.com/vitejs/vite/issues/8412
6
+ // But, anyways, we want to prepend the banner at the beginning of each module, not at the beginning of each file (I believe that's what Rollup's banner feature does).
7
+ const vikeModuleBannerPlaceholder = 'vikeModuleBannerPlaceholder';
8
+ function pluginModuleBanner() {
9
+ let config;
10
+ return {
11
+ name: 'vike:pluginModuleBanner',
12
+ enforce: 'post',
13
+ apply: 'build',
14
+ configResolved(config_) {
15
+ config = config_;
16
+ },
17
+ generateBundle: {
18
+ order: 'post',
19
+ handler(_options, bundle) {
20
+ for (const module of Object.values(bundle)) {
21
+ if (module.type === 'chunk') {
22
+ if (isViteServerBuild(config)) {
23
+ const codeOld = module.code;
24
+ const codeNew = codeOld.replace(/vikeModuleBannerPlaceholder\("([^"]*)"\);/g, '/* $1 [vike:pluginModuleBanner] */');
25
+ assert(!codeNew.includes(vikeModuleBannerPlaceholder));
26
+ module.code = codeNew;
27
+ }
28
+ else {
29
+ assert(!module.code.includes(vikeModuleBannerPlaceholder));
30
+ }
31
+ }
32
+ }
33
+ }
34
+ },
35
+ transform: {
36
+ order: 'post',
37
+ handler(code, id, options) {
38
+ if (!isViteServerBuild_safe(config, options))
39
+ return;
40
+ if (id.startsWith('\0'))
41
+ id = id;
42
+ id = removeVirtualIdTag(id);
43
+ if (id.startsWith(config.root))
44
+ id = id.slice(config.root.length + 1);
45
+ return `${vikeModuleBannerPlaceholder}(${JSON.stringify(id)}); ${code}`;
46
+ }
47
+ }
48
+ };
49
+ }
@@ -6,6 +6,7 @@ import { pluginDistFileNames } from './build/pluginDistFileNames.js';
6
6
  import { pluginAutoFullBuild } from './build/pluginAutoFullBuild.js';
7
7
  import { pluginBuildEntry } from './build/pluginBuildEntry.js';
8
8
  import { pluginBuildConfig } from './build/pluginBuildConfig.js';
9
+ import { pluginModuleBanner } from './build/pluginModuleBanner.js';
9
10
  function build() {
10
11
  return [
11
12
  ...pluginBuildConfig(),
@@ -14,6 +15,7 @@ function build() {
14
15
  ...pluginBuildEntry(),
15
16
  pluginDistPackageJsonFile(),
16
17
  pluginSuppressRollupWarning(),
17
- pluginDistFileNames()
18
+ pluginDistFileNames(),
19
+ pluginModuleBanner()
18
20
  ];
19
21
  }
@@ -4,10 +4,12 @@ export type { VikeConfigPublic };
4
4
  import { type InlineConfig, type Plugin, type ResolvedConfig, type UserConfig } from 'vite';
5
5
  import { type VikeConfigObject } from './importUserCode/v1-design/getVikeConfig.js';
6
6
  import type { PrerenderContextPublic } from '../../prerender/runPrerender.js';
7
+ import type { VitePluginServerEntryOptions } from '@brillout/vite-plugin-server-entry/plugin';
7
8
  declare module 'vite' {
8
9
  interface UserConfig {
9
10
  _isDev?: boolean;
10
11
  _vikeVitePluginOptions?: unknown;
12
+ vitePluginServerEntry?: VitePluginServerEntryOptions;
11
13
  _root?: string;
12
14
  _baseViteOriginal?: string;
13
15
  _viteConfigFromUserEnhanced?: InlineConfig;
@@ -66,6 +66,10 @@ function commonConfig(vikeVitePluginOptions) {
66
66
  assertEsm(config.root);
67
67
  assertVikeCliOrApi(config);
68
68
  temp_supportOldInterface(config);
69
+ // Only emit dist/server/entry.mjs if necessary
70
+ if (config.vitePluginServerEntry?.inject &&
71
+ !resolvePrerenderConfigGlobal(config._vikeConfigObject).isPrerenderingEnabled)
72
+ config.vitePluginServerEntry.disableServerEntryEmit = true;
69
73
  }
70
74
  },
71
75
  config: {
@@ -15,4 +15,4 @@ export * from '../../utils/isArray.js';
15
15
  export * from '../../utils/isObject.js';
16
16
  export * from '../../utils/changeEnumerable.js';
17
17
  export * from '../../utils/makePublicCopy.js';
18
- export * from '../../utils/isNotNullish.js';
18
+ export * from '../../utils/isNullish.js';
@@ -17,4 +17,4 @@ export * from '../../utils/isArray.js';
17
17
  export * from '../../utils/isObject.js';
18
18
  export * from '../../utils/changeEnumerable.js';
19
19
  export * from '../../utils/makePublicCopy.js';
20
- export * from '../../utils/isNotNullish.js';
20
+ export * from '../../utils/isNullish.js';
@@ -21,7 +21,6 @@ export type { GlobalContextPublic };
21
21
  import type { ViteManifest } from '../shared/ViteManifest.js';
22
22
  import type { ResolvedConfig, ViteDevServer } from 'vite';
23
23
  import type { PageConfigUserFriendly, PageConfigsUserFriendly } from '../../shared/page-configs/getPageConfigUserFriendly.js';
24
- import type { ConfigVitePluginServerEntry } from '@brillout/vite-plugin-server-entry/plugin';
25
24
  import { type BaseUrlsResolved } from '../shared/resolveBase.js';
26
25
  type PageRuntimeInfo = Awaited<ReturnType<typeof getUserFiles>>;
27
26
  type GlobalContextInternal = GlobalContext & {
@@ -84,11 +83,11 @@ type BuildInfo = {
84
83
  viteConfigRuntime: {
85
84
  _baseViteOriginal: string;
86
85
  vitePluginServerEntry: {
87
- inject?: NonNullable<ConfigVitePluginServerEntry['vitePluginServerEntry']>['inject'];
86
+ inject?: boolean;
88
87
  };
89
88
  };
90
89
  };
91
90
  declare function assertBuildInfo(buildInfo: unknown): asserts buildInfo is BuildInfo;
92
- declare function getViteConfigRuntime(viteConfig: ResolvedConfig & ConfigVitePluginServerEntry): BuildInfo['viteConfigRuntime'];
91
+ declare function getViteConfigRuntime(viteConfig: ResolvedConfig): BuildInfo['viteConfigRuntime'];
93
92
  declare function updateUserFiles(): Promise<void>;
94
93
  declare function clearGlobalContext(): void;
@@ -308,10 +308,14 @@ async function loadBuildEntry(outDir) {
308
308
  globalObject.buildEntry = globalObject.buildEntryPrevious;
309
309
  }
310
310
  assert(globalObject.buildEntry);
311
- assertWarning(!globalObject.buildInfo?.viteConfigRuntime.vitePluginServerEntry.inject,
312
- // TODO/soon: show precise path
313
- // TODO/soon: make this warning work on test/vike-node/
314
- `Run the server production build (e.g. ${pc.cyan('$ node dist/server/index.mjs')}) instead of running the original server entry (e.g. ${pc.cyan('$ ts-node server/index.ts')})`, { onlyOnce: true });
311
+ assertWarning(
312
+ // vike-server => `vitePluginServerEntry.inject === true`
313
+ // vike-node => `vitePluginServerEntry.inject === [ 'index' ]`
314
+ globalObject.buildInfo?.viteConfigRuntime.vitePluginServerEntry.inject !== true,
315
+ /* TO-DO/eventually:
316
+ !!globalObject.buildInfo?.viteConfigRuntime.vitePluginServerEntry.inject,
317
+ */
318
+ `Run the built server entry (e.g. ${pc.cyan('$ node dist/server/index.mjs')}) instead of the original server entry (e.g. ${pc.cyan('$ ts-node server/index.ts')})`, { onlyOnce: true });
315
319
  }
316
320
  const { buildEntry } = globalObject;
317
321
  assertBuildEntry(buildEntry);
@@ -31,7 +31,7 @@ export * from '../../utils/urlToFile.js';
31
31
  export * from '../../utils/getGlobalObject.js';
32
32
  export * from '../../utils/freezePartial.js';
33
33
  export * from '../../utils/isNpmPackage.js';
34
- export * from '../../utils/isNotNullish.js';
34
+ export * from '../../utils/isNullish.js';
35
35
  export * from '../../utils/isScriptFile.js';
36
36
  export * from '../../utils/removeFileExtention.js';
37
37
  export * from '../../utils/objectKeys.js';
@@ -35,7 +35,7 @@ export * from '../../utils/urlToFile.js';
35
35
  export * from '../../utils/getGlobalObject.js';
36
36
  export * from '../../utils/freezePartial.js';
37
37
  export * from '../../utils/isNpmPackage.js';
38
- export * from '../../utils/isNotNullish.js';
38
+ export * from '../../utils/isNullish.js';
39
39
  export * from '../../utils/isScriptFile.js';
40
40
  export * from '../../utils/removeFileExtention.js';
41
41
  export * from '../../utils/objectKeys.js';
@@ -10,6 +10,6 @@ export * from '../../utils/parseUrl.js';
10
10
  export * from '../../utils/parseUrl-extras.js';
11
11
  export * from '../../utils/isObject.js';
12
12
  export * from '../../utils/assertIsNotBrowser.js';
13
- export * from '../../utils/isNotNullish.js';
13
+ export * from '../../utils/isNullish.js';
14
14
  export * from '../../utils/unique.js';
15
15
  export * from '../../utils/debug.js';
@@ -12,6 +12,6 @@ export * from '../../utils/parseUrl.js';
12
12
  export * from '../../utils/parseUrl-extras.js';
13
13
  export * from '../../utils/isObject.js';
14
14
  export * from '../../utils/assertIsNotBrowser.js';
15
- export * from '../../utils/isNotNullish.js';
15
+ export * from '../../utils/isNullish.js';
16
16
  export * from '../../utils/unique.js';
17
17
  export * from '../../utils/debug.js';
@@ -1,6 +1,8 @@
1
1
  export { isVirtualFileId };
2
2
  export { getVirtualFileId };
3
3
  export { resolveVirtualFileId };
4
+ export { removeVirtualIdTag };
4
5
  declare function isVirtualFileId(id: string): boolean;
5
6
  declare function getVirtualFileId(id: string): string;
6
7
  declare function resolveVirtualFileId(id: string): string;
8
+ declare function removeVirtualIdTag(id: string): string;
@@ -1,32 +1,36 @@
1
1
  export { isVirtualFileId };
2
2
  export { getVirtualFileId };
3
3
  export { resolveVirtualFileId };
4
+ export { removeVirtualIdTag };
4
5
  import pc from '@brillout/picocolors';
5
6
  import { assert, assertUsage } from './utils.js';
6
7
  const idBase = 'virtual:vike:';
7
8
  // https://vitejs.dev/guide/api-plugin.html#virtual-modules-convention
8
- const tag = '\0';
9
+ const virtualIdTag = '\0';
9
10
  function isVirtualFileId(id) {
10
11
  if (id.startsWith(idBase))
11
12
  return true;
12
- if (id.startsWith(tag + idBase))
13
+ if (id.startsWith(virtualIdTag + idBase))
13
14
  return true;
14
15
  // https://github.com/vikejs/vike/issues/1985
15
16
  assertUsage(!id.includes(idBase), `Encountered a module ID ${pc.cyan(id)} that is unexpected. Are you using a tool that modifies the ID of modules? For example, the baseUrl setting in tsconfig.json cannot be used.`);
16
17
  return false;
17
18
  }
18
19
  function getVirtualFileId(id) {
19
- if (id.startsWith(tag)) {
20
- id = id.slice(tag.length);
21
- }
22
- assert(!id.startsWith(tag));
23
- return id;
20
+ return removeVirtualIdTag(id);
24
21
  }
25
22
  function resolveVirtualFileId(id) {
26
23
  assert(isVirtualFileId(id));
27
- if (!id.startsWith(tag)) {
28
- id = tag + id;
24
+ if (!id.startsWith(virtualIdTag)) {
25
+ id = virtualIdTag + id;
26
+ }
27
+ assert(id.startsWith(virtualIdTag));
28
+ return id;
29
+ }
30
+ function removeVirtualIdTag(id) {
31
+ if (id.startsWith(virtualIdTag)) {
32
+ id = id.slice(virtualIdTag.length);
29
33
  }
30
- assert(id.startsWith(tag));
34
+ assert(!id.startsWith(virtualIdTag));
31
35
  return id;
32
36
  }
@@ -1,4 +1,5 @@
1
1
  export { modifyUrl };
2
+ import { type ModifyUrlSameOriginOptions } from './modifyUrlSameOrigin.js';
2
3
  /**
3
4
  * Modify a URL.
4
5
  *
@@ -6,8 +7,7 @@ export { modifyUrl };
6
7
  *
7
8
  * https://vike.dev/modifyUrl
8
9
  */
9
- declare function modifyUrl(url: string, modify: {
10
- pathname?: string;
10
+ declare function modifyUrl(url: string, modify: ModifyUrlSameOriginOptions & {
11
11
  hostname?: string;
12
12
  port?: number;
13
13
  protocol?: string;
@@ -1,4 +1,5 @@
1
1
  export { modifyUrl };
2
+ import { modifyUrlSameOrigin } from './modifyUrlSameOrigin.js';
2
3
  import { createUrlFromComponents, parseUrl } from './utils.js';
3
4
  /**
4
5
  * Modify a URL.
@@ -8,9 +9,8 @@ import { createUrlFromComponents, parseUrl } from './utils.js';
8
9
  * https://vike.dev/modifyUrl
9
10
  */
10
11
  function modifyUrl(url, modify) {
12
+ url = modifyUrlSameOrigin(url, modify);
11
13
  const urlParsed = parseUrl(url, '/');
12
- // Pathname
13
- const pathname = modify.pathname ?? urlParsed.pathname;
14
14
  // Origin
15
15
  const originParts = [
16
16
  modify.protocol ?? urlParsed.protocol ?? '',
@@ -21,8 +21,6 @@ function modifyUrl(url, modify) {
21
21
  originParts.push(`:${port}`);
22
22
  }
23
23
  const origin = originParts.join('');
24
- const urlModified = createUrlFromComponents(origin, pathname,
25
- // Should we also support modifying search and hash?
26
- urlParsed.searchOriginal, urlParsed.hashOriginal);
24
+ const urlModified = createUrlFromComponents(origin, urlParsed.pathname, urlParsed.searchOriginal, urlParsed.hashOriginal);
27
25
  return urlModified;
28
26
  }
@@ -0,0 +1,9 @@
1
+ export { modifyUrlSameOrigin };
2
+ export { ModifyUrlSameOriginOptions };
3
+ type ModifyUrlSameOriginOptions = {
4
+ hash?: string | null;
5
+ search?: Search | null;
6
+ pathname?: string;
7
+ };
8
+ type Search = Record<string, string | null> | URLSearchParams;
9
+ declare function modifyUrlSameOrigin(url: string, modify: ModifyUrlSameOriginOptions): string;
@@ -0,0 +1,40 @@
1
+ export { modifyUrlSameOrigin };
2
+ import { createUrlFromComponents, isNotNullish_keyVal, parseUrl, objectFilter, assertUsageUrlPathnameAbsolute } from './utils.js';
3
+ function modifyUrlSameOrigin(url, modify) {
4
+ const urlParsed = parseUrl(url, '/');
5
+ // Pathname
6
+ const pathname = modify.pathname ?? urlParsed.pathnameOriginal;
7
+ assertUsageUrlPathnameAbsolute(pathname, 'modify.pathname');
8
+ // Search
9
+ let search = modify.search === null ? '' : !modify.search ? urlParsed.searchOriginal : resolveSearch(urlParsed, modify.search);
10
+ if (search === '?')
11
+ search = '';
12
+ // Hash
13
+ let hash;
14
+ if (modify.hash === null) {
15
+ hash = '';
16
+ }
17
+ else if (modify.hash === undefined) {
18
+ hash = urlParsed.hashOriginal ?? '';
19
+ }
20
+ else {
21
+ hash = modify.hash;
22
+ if (!hash.startsWith('#'))
23
+ hash = '#' + hash;
24
+ }
25
+ const urlModified = createUrlFromComponents(urlParsed.origin, pathname, search, hash);
26
+ return urlModified;
27
+ }
28
+ function resolveSearch(urlParsed, search) {
29
+ let searchParams;
30
+ if (search instanceof URLSearchParams) {
31
+ // Overwrite
32
+ searchParams = search;
33
+ }
34
+ else {
35
+ // Merge
36
+ const searchMap = objectFilter({ ...urlParsed.search, ...search }, (isNotNullish_keyVal));
37
+ searchParams = new URLSearchParams(searchMap);
38
+ }
39
+ return '?' + searchParams.toString();
40
+ }
@@ -10,7 +10,7 @@ export * from '../utils/isBrowser.js';
10
10
  export * from '../utils/hasProp.js';
11
11
  export * from '../utils/isPlainObject.js';
12
12
  export * from '../utils/compareString.js';
13
- export * from '../utils/isNotNullish.js';
13
+ export * from '../utils/isNullish.js';
14
14
  export * from '../utils/stringifyStringArray.js';
15
15
  export * from '../utils/cast.js';
16
16
  export * from '../utils/isPropertyGetter.js';
@@ -22,3 +22,4 @@ export * from '../utils/isArray.js';
22
22
  export * from '../utils/changeEnumerable.js';
23
23
  export * from '../utils/objectDefineProperty.js';
24
24
  export * from '../utils/isScriptFile.js';
25
+ export * from '../utils/objectFilter.js';
@@ -14,7 +14,7 @@ export * from '../utils/isBrowser.js';
14
14
  export * from '../utils/hasProp.js';
15
15
  export * from '../utils/isPlainObject.js';
16
16
  export * from '../utils/compareString.js';
17
- export * from '../utils/isNotNullish.js';
17
+ export * from '../utils/isNullish.js';
18
18
  export * from '../utils/stringifyStringArray.js';
19
19
  export * from '../utils/cast.js';
20
20
  export * from '../utils/isPropertyGetter.js';
@@ -26,3 +26,4 @@ export * from '../utils/isArray.js';
26
26
  export * from '../utils/changeEnumerable.js';
27
27
  export * from '../utils/objectDefineProperty.js';
28
28
  export * from '../utils/isScriptFile.js';
29
+ export * from '../utils/objectFilter.js';
@@ -3,7 +3,6 @@ export type { PageContextServer } from '../shared/types.js';
3
3
  export type { PageContextClient } from '../shared/types.js';
4
4
  export type { PageContextWithServerRouting } from '../shared/types.js';
5
5
  export type { PageContextClientWithServerRouting } from '../shared/types.js';
6
- export type { ConfigVitePluginServerEntry } from '@brillout/vite-plugin-server-entry/plugin';
7
6
  export type { PageContextBuiltInServer } from '../shared/types.js';
8
7
  export type { PageContextBuiltInClientWithClientRouting } from '../shared/types.js';
9
8
  export type { PageContextBuiltInClientWithServerRouting } from '../shared/types.js';
@@ -1 +1 @@
1
- export declare const PROJECT_VERSION: "0.4.225-commit-b8fc36e";
1
+ export declare const PROJECT_VERSION: "0.4.225-commit-706a37b";
@@ -1,2 +1,2 @@
1
1
  // Automatically updated by @brillout/release-me
2
- export const PROJECT_VERSION = '0.4.225-commit-b8fc36e';
2
+ export const PROJECT_VERSION = '0.4.225-commit-706a37b';
@@ -2,19 +2,19 @@ export { assertIsNotProductionRuntime };
2
2
  export { onSetupRuntime };
3
3
  export { onSetupBuild };
4
4
  export { onSetupPrerender };
5
+ export { onSetupPreview };
5
6
  export { setNodeEnvProduction };
6
7
  export { markSetup_viteDevServer };
7
8
  export { markSetup_vitePreviewServer };
8
9
  export { markSetup_vikeVitePlugin };
9
10
  export { markSetup_isViteDev };
10
- export { markSetup_isPrerendering };
11
11
  declare function assertIsNotProductionRuntime(): void | undefined;
12
12
  declare function onSetupRuntime(): void | undefined;
13
13
  declare function onSetupBuild(): void;
14
14
  declare function onSetupPrerender(): void;
15
+ declare function onSetupPreview(): void;
15
16
  declare function markSetup_viteDevServer(): void | undefined;
16
17
  declare function markSetup_vitePreviewServer(): void | undefined;
17
18
  declare function markSetup_vikeVitePlugin(): void;
18
19
  declare function markSetup_isViteDev(isViteDev: boolean): void;
19
- declare function markSetup_isPrerendering(): void;
20
20
  declare function setNodeEnvProduction(): void | undefined;
@@ -2,12 +2,12 @@ export { assertIsNotProductionRuntime };
2
2
  export { onSetupRuntime };
3
3
  export { onSetupBuild };
4
4
  export { onSetupPrerender };
5
+ export { onSetupPreview };
5
6
  export { setNodeEnvProduction };
6
7
  export { markSetup_viteDevServer };
7
8
  export { markSetup_vitePreviewServer };
8
9
  export { markSetup_vikeVitePlugin };
9
10
  export { markSetup_isViteDev };
10
- export { markSetup_isPrerendering };
11
11
  import { assert, assertUsage, assertWarning } from './assert.js';
12
12
  import { assertIsNotBrowser } from './assertIsNotBrowser.js';
13
13
  import { createDebugger } from './debug.js';
@@ -29,7 +29,7 @@ function onSetupRuntime() {
29
29
  if (isTest())
30
30
  return;
31
31
  assertNodeEnvIsNotUndefinedString();
32
- if (!isViteLoaded()) {
32
+ if (!setup.isViteDev) {
33
33
  // TODO: make it assertUsage() again once https://github.com/vikejs/vike/issues/1528 is implemented.
34
34
  assertWarning(!isNodeEnvDev(), `The ${getEnvDescription()}, which is contradictory because the environment seems to be a production environment (Vite isn't loaded), see https://vike.dev/NODE_ENV`, { onlyOnce: true });
35
35
  assertUsage(!setup.vikeVitePlugin, `Loading Vike's Vite plugin (the ${pc.cyan('vike/plugin')} module) is prohibited in production.`);
@@ -37,11 +37,12 @@ function onSetupRuntime() {
37
37
  assert(!setup.shouldNotBeProduction);
38
38
  }
39
39
  else {
40
- if (!setup.vitePreviewServer && !setup.isPrerendering) {
40
+ if (!setup.isPreview && !setup.vitePreviewServer && !setup.isPrerendering) {
41
41
  // TODO: make it assertUsage() again once https://github.com/vikejs/vike/issues/1528 is implemented.
42
42
  assertWarning(isNodeEnvDev(), `The ${getEnvDescription()}, but Vite is loaded which is prohibited in production, see https://vike.dev/NODE_ENV`, { onlyOnce: true });
43
43
  }
44
- // These two assert() calls aren't that interesting
44
+ // These assert() calls aren't that interesting
45
+ assert(setup.viteDevServer);
45
46
  assert(setup.vikeVitePlugin);
46
47
  assert(setup.shouldNotBeProduction);
47
48
  }
@@ -58,15 +59,19 @@ function onSetupBuild() {
58
59
  setNodeEnvProduction()
59
60
  */
60
61
  }
62
+ // Called by ../node/prerender/runPrerender.ts
61
63
  function onSetupPrerender() {
62
64
  markSetup_isPrerendering();
63
65
  if (getNodeEnv())
64
66
  assertUsageNodeEnvIsNotDev('pre-rendering');
65
67
  setNodeEnvProduction();
66
68
  }
67
- function isViteLoaded() {
68
- // Do we need setup.viteDevServer or setup.vitePreviewServer ?
69
- return setup.viteDevServer || setup.vitePreviewServer || setup.isViteDev !== undefined;
69
+ // Called by ../node/api/preview.ts
70
+ function onSetupPreview() {
71
+ markSetup_isPreview();
72
+ if (getNodeEnv())
73
+ assertUsageNodeEnvIsNotDev('pre-rendering');
74
+ setNodeEnvProduction();
70
75
  }
71
76
  function isTest() {
72
77
  return isVitest() || isNodeEnv('test');
@@ -95,12 +100,16 @@ function markSetup_isViteDev(isViteDev) {
95
100
  debug('markSetup_isViteDev()', new Error().stack);
96
101
  setup.isViteDev = isViteDev;
97
102
  }
98
- // Called by ../node/prerender/runPrerender.ts
99
103
  function markSetup_isPrerendering() {
100
104
  if (debug.isActivated)
101
105
  debug('markSetup_isPrerendering()', new Error().stack);
102
106
  setup.isPrerendering = true;
103
107
  }
108
+ function markSetup_isPreview() {
109
+ if (debug.isActivated)
110
+ debug('markSetup_isPreview()', new Error().stack);
111
+ setup.isPreview = true;
112
+ }
104
113
  function assertUsageNodeEnvIsNotDev(operation) {
105
114
  if (!isNodeEnvDev())
106
115
  return;
@@ -0,0 +1,3 @@
1
+ export declare function isNullish(val: unknown): val is null | undefined;
2
+ export declare function isNotNullish<T>(p: T | null | undefined): p is T;
3
+ export declare function isNotNullish_keyVal<T>(arg: [string, T | null | undefined]): arg is [string, T];
@@ -0,0 +1,11 @@
1
+ export function isNullish(val) {
2
+ return val === null || val === undefined;
3
+ }
4
+ // someArray.filter(isNotNullish)
5
+ export function isNotNullish(p) {
6
+ return !isNullish(p);
7
+ }
8
+ // objectFilter(obj).filter(isNotNullish_keyVal)
9
+ export function isNotNullish_keyVal(arg) {
10
+ return !isNullish(arg[1]);
11
+ }
@@ -0,0 +1 @@
1
+ export declare function objectFilter<Val, Val2 extends Val, Obj extends Record<string, Val>>(obj: Obj, filter: (arg: [string, Val]) => arg is [string, Val2]): Record<string, Val2>;
@@ -0,0 +1,7 @@
1
+ // Type inference for:
2
+ // ```js
3
+ // Object.fromEntries(Object.entries(obj).filter(someFilter))
4
+ // ```
5
+ export function objectFilter(obj, filter) {
6
+ return Object.fromEntries(Object.entries(obj).filter(filter));
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.225-commit-b8fc36e",
3
+ "version": "0.4.225-commit-706a37b",
4
4
  "repository": "https://github.com/vikejs/vike",
5
5
  "exports": {
6
6
  "./server": {
@@ -123,7 +123,7 @@
123
123
  "@brillout/json-serializer": "^0.5.15",
124
124
  "@brillout/picocolors": "^1.0.26",
125
125
  "@brillout/require-shim": "^0.1.2",
126
- "@brillout/vite-plugin-server-entry": "^0.6.3",
126
+ "@brillout/vite-plugin-server-entry": "0.6.3-commit-0c67c6a",
127
127
  "acorn": "^8.0.0",
128
128
  "cac": "^6.0.0",
129
129
  "es-module-lexer": "^1.0.0",
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isNotNullish = void 0;
4
- const isNotNullish = (p) => p !== null && p !== undefined;
5
- exports.isNotNullish = isNotNullish;
@@ -1 +0,0 @@
1
- export declare const isNotNullish: <T>(p: T | null | undefined) => p is T;
@@ -1 +0,0 @@
1
- export const isNotNullish = (p) => p !== null && p !== undefined;