vike 0.4.150 → 0.4.151-commit-19bc995

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 (109) hide show
  1. package/dist/cjs/node/plugin/index.js +4 -4
  2. package/dist/cjs/node/plugin/plugins/assertFileEnv.js +107 -0
  3. package/dist/cjs/node/plugin/plugins/autoFullBuild.js +3 -2
  4. package/dist/cjs/node/plugin/plugins/baseUrls.js +2 -2
  5. package/dist/cjs/node/plugin/plugins/buildConfig.js +17 -36
  6. package/dist/cjs/node/plugin/plugins/commonConfig.js +1 -1
  7. package/dist/cjs/node/plugin/plugins/config/resolveExtensions.js +1 -1
  8. package/dist/cjs/node/plugin/plugins/config/stemUtils.js +1 -1
  9. package/dist/cjs/node/plugin/plugins/devConfig/determineFsAllowList.js +1 -1
  10. package/dist/cjs/node/plugin/plugins/importBuild/getVikeManifest.js +38 -0
  11. package/dist/cjs/node/plugin/plugins/importBuild/index.js +57 -19
  12. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +10 -0
  13. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +46 -28
  14. package/dist/cjs/node/plugin/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errSwc.js +5 -5
  15. package/dist/cjs/node/plugin/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errSwcBig.js +4 -4
  16. package/dist/cjs/node/plugin/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errVueCss.js +7 -7
  17. package/dist/cjs/node/plugin/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errVueHtml.js +2 -2
  18. package/dist/cjs/node/plugin/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errVueJavascript.js +3 -3
  19. package/dist/cjs/node/plugin/shared/loggerNotProd/errorWithCodeSnippet.js +1 -1
  20. package/dist/cjs/node/plugin/shared/loggerVite.js +1 -1
  21. package/dist/cjs/node/plugin/utils.js +1 -0
  22. package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +2 -0
  23. package/dist/cjs/node/runtime/html/serializePageContextClientSide.js +2 -1
  24. package/dist/cjs/node/runtime/index-deprecated.js +3 -2
  25. package/dist/cjs/node/runtime/index.js +3 -2
  26. package/dist/cjs/node/runtime/renderPage/createHttpResponseObject/getCacheControl.js +20 -0
  27. package/dist/cjs/node/runtime/renderPage/createHttpResponseObject.js +8 -1
  28. package/dist/cjs/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.js +33 -0
  29. package/dist/cjs/node/runtime/renderPage/getPageAssets.js +1 -1
  30. package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +5 -5
  31. package/dist/cjs/node/runtime/renderPage.js +21 -9
  32. package/dist/cjs/shared/getPageFiles/getExports.js +1 -1
  33. package/dist/cjs/shared/route/resolveRedirects.js +3 -11
  34. package/dist/cjs/shared/route/resolveUrlPathname.js +48 -0
  35. package/dist/cjs/utils/debug.js +35 -21
  36. package/dist/cjs/utils/getDependencyPackageJson.js +1 -1
  37. package/dist/cjs/utils/getFilePathAbsolute.js +1 -1
  38. package/dist/cjs/utils/getOutDirs.js +11 -1
  39. package/dist/cjs/utils/injectRollupInputs.js +29 -0
  40. package/dist/cjs/utils/isPlainObject.js +1 -1
  41. package/dist/cjs/utils/projectInfo.js +1 -1
  42. package/dist/cjs/utils/requireResolve.js +1 -1
  43. package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.js +105 -66
  44. package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +1 -1
  45. package/dist/esm/node/plugin/index.js +4 -4
  46. package/dist/esm/node/plugin/plugins/assertFileEnv.d.ts +3 -0
  47. package/dist/esm/node/plugin/plugins/assertFileEnv.js +101 -0
  48. package/dist/esm/node/plugin/plugins/autoFullBuild.js +3 -2
  49. package/dist/esm/node/plugin/plugins/baseUrls.js +2 -2
  50. package/dist/esm/node/plugin/plugins/buildConfig.js +17 -36
  51. package/dist/esm/node/plugin/plugins/commonConfig.js +1 -1
  52. package/dist/esm/node/plugin/plugins/config/resolveExtensions.js +1 -1
  53. package/dist/esm/node/plugin/plugins/config/stemUtils.js +1 -1
  54. package/dist/esm/node/plugin/plugins/devConfig/determineFsAllowList.js +1 -1
  55. package/dist/esm/node/plugin/plugins/importBuild/getVikeManifest.d.ts +5 -0
  56. package/dist/esm/node/plugin/plugins/importBuild/getVikeManifest.js +32 -0
  57. package/dist/esm/node/plugin/plugins/importBuild/index.js +59 -21
  58. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/debug.d.ts +1 -1
  59. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +10 -0
  60. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +47 -29
  61. package/dist/esm/node/plugin/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errSwc.js +5 -5
  62. package/dist/esm/node/plugin/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errSwcBig.js +4 -4
  63. package/dist/esm/node/plugin/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errVueCss.js +7 -7
  64. package/dist/esm/node/plugin/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errVueHtml.js +2 -2
  65. package/dist/esm/node/plugin/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errVueJavascript.js +3 -3
  66. package/dist/esm/node/plugin/shared/loggerNotProd/errorWithCodeSnippet.js +1 -1
  67. package/dist/esm/node/plugin/shared/loggerVite.js +1 -1
  68. package/dist/esm/node/plugin/utils.d.ts +1 -0
  69. package/dist/esm/node/plugin/utils.js +1 -0
  70. package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +2 -0
  71. package/dist/esm/node/runtime/html/serializePageContextClientSide.js +2 -1
  72. package/dist/esm/node/runtime/index-deprecated.js +3 -2
  73. package/dist/esm/node/runtime/index.js +3 -2
  74. package/dist/esm/node/runtime/renderPage/createHttpResponseObject/getCacheControl.d.ts +3 -0
  75. package/dist/esm/node/runtime/renderPage/createHttpResponseObject/getCacheControl.js +17 -0
  76. package/dist/esm/node/runtime/renderPage/createHttpResponseObject.js +8 -1
  77. package/dist/esm/node/runtime/renderPage/{executeOnBeforeRenderHook.d.ts → executeOnBeforeRenderAndDataHooks.d.ts} +2 -2
  78. package/dist/esm/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.js +30 -0
  79. package/dist/esm/node/runtime/renderPage/getPageAssets.js +1 -1
  80. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +5 -5
  81. package/dist/esm/node/runtime/renderPage.js +22 -10
  82. package/dist/esm/shared/VikeNamespace.d.ts +5 -1
  83. package/dist/esm/shared/getPageFiles/getExports.js +1 -1
  84. package/dist/esm/shared/page-configs/Config/PageContextConfig.d.ts +4 -4
  85. package/dist/esm/shared/page-configs/Config/helpers.d.ts +2 -2
  86. package/dist/esm/shared/page-configs/Config.d.ts +33 -7
  87. package/dist/esm/shared/route/resolveRedirects.js +3 -11
  88. package/dist/esm/shared/route/resolveUrlPathname.d.ts +12 -0
  89. package/dist/esm/shared/route/resolveUrlPathname.js +45 -0
  90. package/dist/esm/shared/types.d.ts +5 -0
  91. package/dist/esm/types/index.d.ts +1 -1
  92. package/dist/esm/utils/debug.d.ts +4 -4
  93. package/dist/esm/utils/debug.js +35 -21
  94. package/dist/esm/utils/debugGlob.d.ts +1 -1
  95. package/dist/esm/utils/getDependencyPackageJson.js +1 -1
  96. package/dist/esm/utils/getFilePathAbsolute.js +1 -1
  97. package/dist/esm/utils/getOutDirs.js +11 -1
  98. package/dist/esm/utils/injectRollupInputs.d.ts +7 -0
  99. package/dist/esm/utils/injectRollupInputs.js +26 -0
  100. package/dist/esm/utils/isPlainObject.js +1 -1
  101. package/dist/esm/utils/projectInfo.d.ts +2 -2
  102. package/dist/esm/utils/projectInfo.js +1 -1
  103. package/dist/esm/utils/requireResolve.js +1 -1
  104. package/package.json +38 -19
  105. package/dist/cjs/node/plugin/plugins/manifest.js +0 -59
  106. package/dist/cjs/node/runtime/renderPage/executeOnBeforeRenderHook.js +0 -23
  107. package/dist/esm/node/plugin/plugins/manifest.d.ts +0 -3
  108. package/dist/esm/node/plugin/plugins/manifest.js +0 -53
  109. package/dist/esm/node/runtime/renderPage/executeOnBeforeRenderHook.js +0 -20
@@ -4,6 +4,7 @@ export { resolveRouteStringRedirect };
4
4
  import { assertIsNotBrowser } from '../../utils/assertIsNotBrowser.js';
5
5
  import { isUriWithProtocol } from '../../utils/parseUrl-extras.js';
6
6
  import { assert, assertUsage } from '../utils.js';
7
+ import { resolveUrlPathname } from './resolveUrlPathname.js';
7
8
  import { assertRouteString, resolveRouteString } from './resolveRouteString.js';
8
9
  import pc from '@brillout/picocolors';
9
10
  assertIsNotBrowser(); // Don't bloat the client
@@ -22,21 +23,12 @@ function resolveRouteStringRedirect(urlSource, urlTarget, urlPathname) {
22
23
  assertUsage(urlTarget.startsWith('/') ||
23
24
  // Is allowing any protocol a safety issue? https://github.com/vikejs/vike/pull/1292#issuecomment-1828043917
24
25
  isUriWithProtocol(urlTarget) ||
25
- urlTarget === '*', `${configSrc} Invalid redirection target URL ${pc.cyan(urlTarget)}: the target URL should start with ${pc.cyan('/')}, a valid protocol (${pc.cyan('https:')}, ${pc.cyan('http:')}, ${pc.cyan('ipfs:')}, ${pc.cyan('magnet:')}, ...), or be ${pc.cyan('*')}`);
26
+ urlTarget === '*', `${configSrc} Invalid redirection target URL ${pc.cyan(urlTarget)}: the target URL should start with ${pc.cyan('/')}, a valid protocol (${pc.cyan('https:')}, ${pc.cyan('http:')}, ${pc.cyan('mailto:')}, ${pc.cyan('ipfs:')}, ${pc.cyan('magnet:')}, ...), or be ${pc.cyan('*')}`);
26
27
  assertParams(urlSource, urlTarget);
27
28
  const match = resolveRouteString(urlSource, urlPathname);
28
29
  if (!match)
29
30
  return null;
30
- let urlResolved = urlTarget;
31
- Object.entries(match.routeParams).forEach(([key, val]) => {
32
- if (key !== '*') {
33
- key = `@${key}`;
34
- }
35
- urlResolved = urlResolved.replaceAll(key, val);
36
- });
37
- if (!urlResolved.startsWith('mailto:')) {
38
- assertUsage(!urlResolved.includes('@'), 'URL should not contain "@" unless it is a mailto link.');
39
- }
31
+ const urlResolved = resolveUrlPathname(urlTarget, match.routeParams);
40
32
  if (urlResolved === urlPathname)
41
33
  return null;
42
34
  assert(urlResolved.startsWith('/') || isUriWithProtocol(urlResolved));
@@ -0,0 +1,12 @@
1
+ export { resolveUrlPathname };
2
+ /** Given a `routeString` and `routeParams`, resolve `urlPathname`.
3
+ *
4
+ * Basically, the correct implementation of following:
5
+ * ```js
6
+ * let urlPathname = routeString
7
+ * Object.entries(routeParams).forEach(([key, val]) => {
8
+ * urlPathname = urlPathname.replaceAll(key, val)
9
+ * })
10
+ * ```
11
+ */
12
+ declare function resolveUrlPathname(routeString: string, routeParams: Record<string, string>): string;
@@ -0,0 +1,45 @@
1
+ export { resolveUrlPathname };
2
+ import { assertIsNotBrowser } from '../../utils/assertIsNotBrowser.js';
3
+ import { assert, assertUsage } from '../utils.js';
4
+ assertIsNotBrowser(); // Don't bloat the client
5
+ /** Given a `routeString` and `routeParams`, resolve `urlPathname`.
6
+ *
7
+ * Basically, the correct implementation of following:
8
+ * ```js
9
+ * let urlPathname = routeString
10
+ * Object.entries(routeParams).forEach(([key, val]) => {
11
+ * urlPathname = urlPathname.replaceAll(key, val)
12
+ * })
13
+ * ```
14
+ */
15
+ function resolveUrlPathname(routeString, routeParams) {
16
+ let parts = [{ val: routeString, type: 'ROUTE_STRING' }];
17
+ Object.entries(routeParams).forEach(([key, val]) => {
18
+ if (key.startsWith('*')) {
19
+ assert(key === '*' || /\d+/.test(key.slice(1)));
20
+ assertUsage(key === '*', "Resolving URL with multiple globs isn't implemented yet");
21
+ }
22
+ else {
23
+ key = `@${key}`;
24
+ }
25
+ parts = parts
26
+ .map((part) => {
27
+ if (part.type === 'URL') {
28
+ return part;
29
+ }
30
+ else {
31
+ return part.val
32
+ .split(key)
33
+ .map((rest, i) => {
34
+ const partURL = { val, type: 'URL' };
35
+ const partRouteString = { val: rest, type: 'ROUTE_STRING' };
36
+ return i === 0 ? [partRouteString] : [partURL, partRouteString];
37
+ })
38
+ .flat();
39
+ }
40
+ })
41
+ .flat();
42
+ });
43
+ const urlPathname = parts.map((p) => p.val).join('');
44
+ return urlPathname;
45
+ }
@@ -35,6 +35,11 @@ type PageContextBuiltInCommon<Page = [never]> = {
35
35
  * https://vike.dev/route-string
36
36
  */
37
37
  routeParams: Record<string, string>;
38
+ /** The page's data which was fetched using the data() hook.
39
+ *
40
+ * https://vike.dev/data
41
+ */
42
+ data?: unknown;
38
43
  /** The page's configuration values.
39
44
  *
40
45
  * https://vike.dev/config
@@ -6,7 +6,7 @@ export type { PageContextClientWithServerRouting } from '../shared/types.js';
6
6
  export type { PageContextBuiltInServer } from '../shared/types.js';
7
7
  export type { PageContextBuiltInClientWithClientRouting } from '../shared/types.js';
8
8
  export type { PageContextBuiltInClientWithServerRouting } from '../shared/types.js';
9
- export type { Config, ConfigMeta as Meta, GuardAsync, GuardSync, OnBeforePrerenderStartAsync, OnBeforePrerenderStartSync, OnBeforeRenderAsync, OnBeforeRenderSync, OnBeforeRouteAsync, OnBeforeRouteSync, OnHydrationEndAsync, OnHydrationEndSync, OnPageTransitionEndAsync, OnPageTransitionEndSync, OnPageTransitionStartAsync, OnPageTransitionStartSync, OnPrerenderStartAsync, OnPrerenderStartSync, OnRenderClientAsync, OnRenderClientSync, OnRenderHtmlAsync, OnRenderHtmlSync, RouteAsync, RouteSync } from '../shared/page-configs/Config.js';
9
+ export type { Config, ConfigMeta as Meta, DataAsync, DataSync, GuardAsync, GuardSync, OnBeforePrerenderStartAsync, OnBeforePrerenderStartSync, OnBeforeRenderAsync, OnBeforeRenderSync, OnBeforeRouteAsync, OnBeforeRouteSync, OnHydrationEndAsync, OnHydrationEndSync, OnPageTransitionEndAsync, OnPageTransitionEndSync, OnPageTransitionStartAsync, OnPageTransitionStartSync, OnPrerenderStartAsync, OnPrerenderStartSync, OnRenderClientAsync, OnRenderClientSync, OnRenderHtmlAsync, OnRenderHtmlSync, RouteAsync, RouteSync } from '../shared/page-configs/Config.js';
10
10
  export type { ConfigEnv } from '../shared/page-configs/PageConfig.js';
11
11
  export type { ConfigDefinition, ConfigEffect } from '../node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js';
12
12
  export type { ConfigEntries } from '../shared/getPageFiles/getExports.js';
@@ -1,15 +1,15 @@
1
1
  export { createDebugger };
2
2
  export { isDebugEnabled };
3
3
  export type { Debug };
4
- type Namespace = 'vike:error' | 'vike:extractAssets' | 'vike:extractExportNames' | 'vike:glob' | 'vike:pageFiles' | 'vike:log' | 'vike:routing' | 'vike:virtual-files' | 'vike:stem' | 'vike:stream';
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';
5
5
  type Debug = ReturnType<typeof createDebugger>;
6
6
  type Options = {
7
7
  serialization?: {
8
8
  emptyArray?: string;
9
9
  };
10
10
  };
11
- declare function createDebugger(namespace: Namespace, optionsGlobal?: Options): ((...msgs: unknown[]) => void) & {
12
- options: (options: Options) => (...msgs: unknown[]) => void;
11
+ declare function createDebugger(flag: Flag, optionsGlobal?: Options): ((...msgs: unknown[]) => void) & {
12
+ options: (optionsLocal: Options) => (...msgs: unknown[]) => void;
13
13
  isEnabled: boolean;
14
14
  };
15
- declare function isDebugEnabled(namespace: Namespace): boolean;
15
+ declare function isDebugEnabled(flag: Flag): boolean;
@@ -9,32 +9,46 @@ import { getTerminalWidth } from './getTerminWidth.js';
9
9
  // Avoid this to be loaded in the browser. For isomorphic code: instead of `import { createDebugger } from './utils.js'`, use `globalThis.createDebugger()`.
10
10
  assert(!isBrowser());
11
11
  globalThis.__brillout_debug_createDebugger = createDebugger;
12
- function createDebugger(namespace, optionsGlobal) {
13
- checkType(namespace);
14
- const debugWithOptions = (options) => {
12
+ function createDebugger(flag, optionsGlobal) {
13
+ checkType(flag);
14
+ const debugWithOptions = (optionsLocal) => {
15
15
  return (...msgs) => {
16
- if (!isDebugEnabled(namespace))
17
- return;
18
- let [msgFirst, ...msgsRest] = msgs;
19
- const padding = ' '.repeat(namespace.length + 1);
20
- const optionsResolved = { ...optionsGlobal, ...options };
21
- msgFirst = formatMsg(msgFirst, optionsResolved, padding, 'FIRST');
22
- msgsRest = msgsRest.map((msg, i) => {
23
- const position = i === msgsRest.length - 1 ? 'LAST' : 'MIDDLE';
24
- return formatMsg(msg, optionsResolved, padding, position);
25
- });
26
- console.log('\x1b[1m%s\x1b[0m', namespace, msgFirst);
27
- msgsRest.forEach((msg) => {
28
- console.log(msg);
29
- });
16
+ const options = { ...optionsGlobal, ...optionsLocal };
17
+ debug_(flag, options, ...msgs);
30
18
  };
31
19
  };
32
20
  const debug = (...msgs) => debugWithOptions({})(...msgs);
33
- objectAssign(debug, { options: debugWithOptions, isEnabled: isDebugEnabled(namespace) });
21
+ objectAssign(debug, { options: debugWithOptions, isEnabled: isDebugEnabled(flag) });
34
22
  return debug;
35
23
  }
36
- function isDebugEnabled(namespace) {
37
- checkType(namespace);
24
+ function debug_(flag, options, ...msgs) {
25
+ if (!isDebugEnabled(flag))
26
+ return;
27
+ let [msgFirst, ...msgsRest] = msgs;
28
+ const padding = ' '.repeat(flag.length + 1);
29
+ msgFirst = formatMsg(msgFirst, options, padding, 'FIRST');
30
+ msgsRest = msgsRest.map((msg, i) => {
31
+ const position = i === msgsRest.length - 1 ? 'LAST' : 'MIDDLE';
32
+ return formatMsg(msg, options, padding, position);
33
+ });
34
+ let logFirst;
35
+ let logsRest;
36
+ const noNewLine = msgsRest.length <= 1 && [msgFirst, ...msgsRest].every((m) => typeof m === 'string' && !m.includes('\n'));
37
+ if (noNewLine) {
38
+ logFirst = [msgFirst, ...msgsRest].map((m) => String(m).trim());
39
+ logsRest = [];
40
+ }
41
+ else {
42
+ logFirst = [msgFirst];
43
+ logsRest = msgsRest;
44
+ }
45
+ console.log('\x1b[1m%s\x1b[0m', flag, ...logFirst);
46
+ logsRest.forEach((msg) => {
47
+ console.log(msg);
48
+ });
49
+ }
50
+ function isDebugEnabled(flag) {
51
+ checkType(flag);
38
52
  let DEBUG;
39
53
  // - `process` can be undefined in edge workers
40
54
  // - We want bundlers to be able to statically replace `process.env.*`
@@ -42,7 +56,7 @@ function isDebugEnabled(namespace) {
42
56
  DEBUG = process.env.DEBUG;
43
57
  }
44
58
  catch { }
45
- return DEBUG?.includes(namespace) ?? false;
59
+ return DEBUG?.includes(flag) ?? false;
46
60
  }
47
61
  function formatMsg(info, options, padding, position) {
48
62
  if (info === undefined) {
@@ -1,5 +1,5 @@
1
1
  export declare const debugGlob: ((...msgs: unknown[]) => void) & {
2
- options: (options: {
2
+ options: (optionsLocal: {
3
3
  serialization?: {
4
4
  emptyArray?: string | undefined;
5
5
  } | undefined;
@@ -14,7 +14,7 @@ import path from 'path';
14
14
  import fs from 'fs';
15
15
  import { assertIsNotProductionRuntime } from './assertIsNotProductionRuntime.js';
16
16
  import { createRequire } from 'module';
17
- // @ts-ignore Shimed by dist-cjs-fixup.js for CJS build.
17
+ // @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
18
18
  const importMetaUrl = import.meta.url;
19
19
  const require_ = createRequire(importMetaUrl);
20
20
  assertIsNotProductionRuntime();
@@ -7,7 +7,7 @@ import { assertIsNotProductionRuntime } from './assertIsNotProductionRuntime.js'
7
7
  import { isNpmPackageImport } from './isNpmPackage.js';
8
8
  import { assertPathIsFilesystemAbsolute } from './assertPathIsFilesystemAbsolute.js';
9
9
  import { createRequire } from 'module';
10
- // @ts-ignore Shimed by dist-cjs-fixup.js for CJS build.
10
+ // @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
11
11
  const importMetaUrl = import.meta.url;
12
12
  const require_ = createRequire(importMetaUrl);
13
13
  assertIsNotProductionRuntime();
@@ -5,7 +5,10 @@ import { assert, assertUsage } from './assert.js';
5
5
  import { pathJoin } from './path-shim.js';
6
6
  import { assertPosixPath, toPosixPath } from './filesystemPathHandling.js';
7
7
  import pc from '@brillout/picocolors';
8
+ import { createDebugger } from './debug.js';
9
+ const debug = createDebugger('vike:outDir');
8
10
  function getOutDirs(config) {
11
+ debug('getOutDirs()', new Error().stack);
9
12
  let outDirRoot;
10
13
  {
11
14
  const outDir = getOutDirFromViteResolvedConfig(config);
@@ -19,11 +22,16 @@ function getOutDirs(config) {
19
22
  outDirRoot = outDir.slice(0, -1 * '/client'.length);
20
23
  }
21
24
  }
22
- return getOutDirsAll(outDirRoot, config.root);
25
+ const outDirs = getOutDirsAll(outDirRoot, config.root);
26
+ debug('outDirRoot', outDirRoot);
27
+ debug('outDirs', outDirs);
28
+ return outDirs;
23
29
  }
24
30
  /** Appends `client/` or `server/` to `config.build.outDir` */
25
31
  function resolveOutDir(config) {
32
+ debug('resolveOutDir()', new Error().stack);
26
33
  const outDir = getOutDirFromViteUserConfig(config) || 'dist';
34
+ debug('outDir', 'outDir');
27
35
  // outDir may already be resolved when using Telefunc + vike (because both Telefunc and vike use this logic)
28
36
  if (!isOutDirRoot(outDir)) {
29
37
  assertOutDirResolved(outDir, config);
@@ -32,9 +40,11 @@ function resolveOutDir(config) {
32
40
  else {
33
41
  const { outDirClient, outDirServer } = determineOutDirs(outDir);
34
42
  if (viteIsSSR(config)) {
43
+ debug('outDirServer', 'outDirServer');
35
44
  return outDirServer;
36
45
  }
37
46
  else {
47
+ debug('outDirClient', 'outDirClient');
38
48
  return outDirClient;
39
49
  }
40
50
  }
@@ -0,0 +1,7 @@
1
+ export { injectRollupInputs };
2
+ export { normalizeRollupInput };
3
+ import type { ResolvedConfig, Rollup } from 'vite';
4
+ type InputOption = Rollup.InputOption;
5
+ type InputsMap = Record<string, string>;
6
+ declare function injectRollupInputs(inputsNew: InputsMap, config: ResolvedConfig): InputsMap;
7
+ declare function normalizeRollupInput(input?: InputOption): InputsMap;
@@ -0,0 +1,26 @@
1
+ export { injectRollupInputs };
2
+ export { normalizeRollupInput };
3
+ import { assert } from './assert.js';
4
+ import { isObject } from './isObject.js';
5
+ function injectRollupInputs(inputsNew, config) {
6
+ const inputsCurrent = normalizeRollupInput(config.build.rollupOptions.input);
7
+ const input = {
8
+ ...inputsNew,
9
+ ...inputsCurrent
10
+ };
11
+ return input;
12
+ }
13
+ function normalizeRollupInput(input) {
14
+ if (!input) {
15
+ return {};
16
+ }
17
+ // Usually `input` is an oject, but the user can set it as a `string` or `string[]`
18
+ if (typeof input === 'string') {
19
+ input = [input];
20
+ }
21
+ if (Array.isArray(input)) {
22
+ return Object.fromEntries(input.map((input) => [input, input]));
23
+ }
24
+ assert(isObject(input));
25
+ return input;
26
+ }
@@ -8,7 +8,7 @@ function isPlainObject(value) {
8
8
  return true;
9
9
  }
10
10
  return (
11
- /* Doesn't work in Cloudlfare Pages workers
11
+ /* Doesn't work in Cloudflare Pages workers
12
12
  value.constructor === Object
13
13
  */
14
14
  value.constructor.name === 'Object');
@@ -1,13 +1,13 @@
1
1
  export { projectInfo };
2
2
  export type { ProjectTag };
3
3
  export { PROJECT_VERSION };
4
- declare const PROJECT_VERSION: "0.4.150";
4
+ declare const PROJECT_VERSION: "0.4.151-commit-19bc995";
5
5
  type PackageName = typeof projectInfo.npmPackageName;
6
6
  type ProjectVersion = typeof projectInfo.projectVersion;
7
7
  type ProjectTag = `[${PackageName}]` | `[${PackageName}@${ProjectVersion}]`;
8
8
  declare const projectInfo: {
9
9
  projectName: "Vike";
10
- projectVersion: "0.4.150";
10
+ projectVersion: "0.4.151-commit-19bc995";
11
11
  npmPackageName: "vike";
12
12
  githubRepository: "https://github.com/vikejs/vike";
13
13
  };
@@ -1,7 +1,7 @@
1
1
  export { projectInfo };
2
2
  export { PROJECT_VERSION };
3
3
  import { onProjectInfo } from './assertSingleInstance.js';
4
- const PROJECT_VERSION = '0.4.150';
4
+ const PROJECT_VERSION = '0.4.151-commit-19bc995';
5
5
  const projectInfo = {
6
6
  projectName: 'Vike',
7
7
  projectVersion: PROJECT_VERSION,
@@ -5,7 +5,7 @@ import { assertIsNotProductionRuntime } from './assertIsNotProductionRuntime.js'
5
5
  import { assertPosixPath, toPosixPath } from './filesystemPathHandling.js';
6
6
  import { scriptFileExtensionList } from './isScriptFile.js';
7
7
  import { createRequire } from 'module';
8
- // @ts-ignore Shimed by dist-cjs-fixup.js for CJS build.
8
+ // @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
9
9
  const importMetaUrl = import.meta.url;
10
10
  const require_ = createRequire(importMetaUrl);
11
11
  assertIsNotBrowser();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.150",
3
+ "version": "0.4.151-commit-19bc995",
4
4
  "scripts": {
5
5
  "dev": "tsc --watch",
6
6
  "build": "rimraf dist/ && pnpm run build:esm && pnpm run build:cjs",
@@ -12,18 +12,18 @@
12
12
  "release:commit": "release-me commit"
13
13
  },
14
14
  "dependencies": {
15
- "@brillout/import": "0.2.3",
15
+ "@brillout/import": "^0.2.3",
16
16
  "@brillout/json-serializer": "^0.5.8",
17
17
  "@brillout/picocolors": "^1.0.10",
18
18
  "@brillout/require-shim": "^0.1.2",
19
- "@brillout/vite-plugin-import-build": "^0.2.20",
20
- "acorn": "^8.8.2",
21
- "cac": "^6.7.14",
22
- "es-module-lexer": "^1.3.0",
23
- "esbuild": "^0.17.18",
24
- "fast-glob": "^3.2.12",
25
- "sirv": "^2.0.2",
26
- "source-map-support": "^0.5.21"
19
+ "@brillout/vite-plugin-import-build": "^0.3.1",
20
+ "acorn": "^8.0.0",
21
+ "cac": "^6.0.0",
22
+ "es-module-lexer": "^1.0.0",
23
+ "esbuild": "^0.19.0",
24
+ "fast-glob": "^3.0.0",
25
+ "sirv": "^2.0.0",
26
+ "source-map-support": "^0.5.0"
27
27
  },
28
28
  "type": "module",
29
29
  "exports": {
@@ -105,6 +105,13 @@
105
105
  "require": "./dist/cjs/node/runtime/page-files/setup.js",
106
106
  "node": "./dist/esm/node/runtime/page-files/setup.js",
107
107
  "types": "./dist/esm/node/runtime/page-files/setup.d.ts"
108
+ },
109
+ "./__internal/loadImportBuild": {
110
+ "worker": "./dist/esm/node/runtime/globalContext/loadImportBuild.js",
111
+ "edge-light": "./dist/esm/node/runtime/globalContext/loadImportBuild.js",
112
+ "require": "./dist/cjs/node/runtime/globalContext/loadImportBuild.js",
113
+ "node": "./dist/esm/node/runtime/globalContext/loadImportBuild.js",
114
+ "types": "./dist/esm/node/runtime/globalContext/loadImportBuild.d.ts"
108
115
  }
109
116
  },
110
117
  "peerDependencies": {
@@ -162,15 +169,27 @@
162
169
  "vike": "./node/cli/bin-entry.js"
163
170
  },
164
171
  "devDependencies": {
165
- "@brillout/release-me": "^0.1.11",
166
- "@types/estree": "^1.0.0",
167
- "@types/jest": "^27.4.1",
168
- "@types/node": "^20.1.0",
169
- "@types/resolve": "^1.20.2",
170
- "@types/source-map-support": "^0.5.6",
171
- "rimraf": "^3.0.2",
172
- "typescript": "^5.2.2",
173
- "vite": "^4.2.1"
172
+ "@brillout/import": "^0.2.3",
173
+ "@brillout/json-serializer": "^0.5.8",
174
+ "@brillout/picocolors": "^1.0.10",
175
+ "@brillout/require-shim": "^0.1.2",
176
+ "@brillout/vite-plugin-import-build": "^0.3.1",
177
+ "acorn": "^8.11.2",
178
+ "cac": "^6.7.14",
179
+ "es-module-lexer": "^1.4.1",
180
+ "esbuild": "^0.19.10",
181
+ "fast-glob": "^3.3.2",
182
+ "sirv": "^2.0.4",
183
+ "source-map-support": "^0.5.21",
184
+ "@brillout/release-me": "^0.1.13",
185
+ "@types/estree": "^1.0.5",
186
+ "@types/jest": "^29.5.11",
187
+ "@types/node": "^20.10.5",
188
+ "@types/resolve": "^1.20.6",
189
+ "@types/source-map-support": "^0.5.10",
190
+ "rimraf": "^5.0.5",
191
+ "typescript": "^5.3.3",
192
+ "vite": "^5.0.10"
174
193
  },
175
194
  "engines": {
176
195
  "node": ">=16.0.0"
@@ -1,59 +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.manifest = void 0;
7
- const utils_js_1 = require("../utils.js");
8
- const assertPluginManifest_js_1 = require("../../shared/assertPluginManifest.js");
9
- const extractExportNamesPlugin_js_1 = require("./extractExportNamesPlugin.js");
10
- const getConfigVike_js_1 = require("../../shared/getConfigVike.js");
11
- const path_1 = __importDefault(require("path"));
12
- const globalContext_js_1 = require("../../runtime/globalContext.js");
13
- function manifest() {
14
- let configVike;
15
- let config;
16
- return [
17
- {
18
- name: 'vike:pluginManifest',
19
- apply: 'build',
20
- async configResolved(config_) {
21
- config = config_;
22
- configVike = await (0, getConfigVike_js_1.getConfigVike)(config);
23
- },
24
- generateBundle() {
25
- if ((0, utils_js_1.viteIsSSR)(config))
26
- return;
27
- const runtimeManifest = (0, globalContext_js_1.getRuntimeManifest)(configVike);
28
- const manifest = {
29
- version: utils_js_1.projectInfo.projectVersion,
30
- usesClientRouter: (0, extractExportNamesPlugin_js_1.isUsingClientRouter)(),
31
- manifestKeyMap: getManifestKeyMap(configVike, config),
32
- ...runtimeManifest
33
- };
34
- (0, assertPluginManifest_js_1.assertPluginManifest)(manifest);
35
- this.emitFile({
36
- fileName: `vike.json`,
37
- type: 'asset',
38
- source: JSON.stringify(manifest, null, 2)
39
- });
40
- }
41
- }
42
- ];
43
- }
44
- exports.manifest = manifest;
45
- function getManifestKeyMap(configVike, config) {
46
- const manifestKeyMap = {};
47
- configVike.extensions
48
- .map(({ pageConfigsDistFiles }) => pageConfigsDistFiles)
49
- .flat()
50
- .filter(utils_js_1.isNotNullish)
51
- .forEach(({ importPath, filePath }) => {
52
- // Recreating https://github.com/vitejs/vite/blob/8158ece72b66307e7b607b98496891610ca70ea2/packages/vite/src/node/plugins/manifest.ts#L38
53
- const filePathRelative = path_1.default.posix.relative(config.root, (0, utils_js_1.toPosixPath)(filePath));
54
- (0, utils_js_1.assertPosixPath)(filePathRelative);
55
- (0, utils_js_1.assertPosixPath)(importPath);
56
- manifestKeyMap[importPath] = filePathRelative;
57
- });
58
- return manifestKeyMap;
59
- }
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.executeOnBeforeRenderHooks = void 0;
4
- const getHook_js_1 = require("../../../shared/hooks/getHook.js");
5
- const preparePageContextForUserConsumptionServerSide_js_1 = require("./preparePageContextForUserConsumptionServerSide.js");
6
- const utils_js_1 = require("../utils.js");
7
- const assertOnBeforeRenderHookReturn_js_1 = require("../../../shared/assertOnBeforeRenderHookReturn.js");
8
- async function executeOnBeforeRenderHooks(pageContext) {
9
- if (pageContext._pageContextAlreadyProvidedByOnPrerenderHook) {
10
- return;
11
- }
12
- const hook = (0, getHook_js_1.getHook)(pageContext, 'onBeforeRender');
13
- if (!hook) {
14
- return;
15
- }
16
- const onBeforeRender = hook.hookFn;
17
- (0, preparePageContextForUserConsumptionServerSide_js_1.preparePageContextForUserConsumptionServerSide)(pageContext);
18
- const hookResult = await (0, utils_js_1.executeHook)(() => onBeforeRender(pageContext), hook);
19
- (0, assertOnBeforeRenderHookReturn_js_1.assertOnBeforeRenderHookReturn)(hookResult, hook.hookFilePath);
20
- const pageContextFromHook = hookResult?.pageContext;
21
- Object.assign(pageContext, pageContextFromHook);
22
- }
23
- exports.executeOnBeforeRenderHooks = executeOnBeforeRenderHooks;
@@ -1,3 +0,0 @@
1
- export { manifest };
2
- import { Plugin } from 'vite';
3
- declare function manifest(): Plugin[];
@@ -1,53 +0,0 @@
1
- export { manifest };
2
- import { projectInfo, viteIsSSR, toPosixPath, assertPosixPath, isNotNullish } from '../utils.js';
3
- import { assertPluginManifest } from '../../shared/assertPluginManifest.js';
4
- import { isUsingClientRouter } from './extractExportNamesPlugin.js';
5
- import { getConfigVike } from '../../shared/getConfigVike.js';
6
- import path from 'path';
7
- import { getRuntimeManifest } from '../../runtime/globalContext.js';
8
- function manifest() {
9
- let configVike;
10
- let config;
11
- return [
12
- {
13
- name: 'vike:pluginManifest',
14
- apply: 'build',
15
- async configResolved(config_) {
16
- config = config_;
17
- configVike = await getConfigVike(config);
18
- },
19
- generateBundle() {
20
- if (viteIsSSR(config))
21
- return;
22
- const runtimeManifest = getRuntimeManifest(configVike);
23
- const manifest = {
24
- version: projectInfo.projectVersion,
25
- usesClientRouter: isUsingClientRouter(),
26
- manifestKeyMap: getManifestKeyMap(configVike, config),
27
- ...runtimeManifest
28
- };
29
- assertPluginManifest(manifest);
30
- this.emitFile({
31
- fileName: `vike.json`,
32
- type: 'asset',
33
- source: JSON.stringify(manifest, null, 2)
34
- });
35
- }
36
- }
37
- ];
38
- }
39
- function getManifestKeyMap(configVike, config) {
40
- const manifestKeyMap = {};
41
- configVike.extensions
42
- .map(({ pageConfigsDistFiles }) => pageConfigsDistFiles)
43
- .flat()
44
- .filter(isNotNullish)
45
- .forEach(({ importPath, filePath }) => {
46
- // Recreating https://github.com/vitejs/vite/blob/8158ece72b66307e7b607b98496891610ca70ea2/packages/vite/src/node/plugins/manifest.ts#L38
47
- const filePathRelative = path.posix.relative(config.root, toPosixPath(filePath));
48
- assertPosixPath(filePathRelative);
49
- assertPosixPath(importPath);
50
- manifestKeyMap[importPath] = filePathRelative;
51
- });
52
- return manifestKeyMap;
53
- }
@@ -1,20 +0,0 @@
1
- export { executeOnBeforeRenderHooks };
2
- import { getHook } from '../../../shared/hooks/getHook.js';
3
- import { preparePageContextForUserConsumptionServerSide } from './preparePageContextForUserConsumptionServerSide.js';
4
- import { executeHook } from '../utils.js';
5
- import { assertOnBeforeRenderHookReturn } from '../../../shared/assertOnBeforeRenderHookReturn.js';
6
- async function executeOnBeforeRenderHooks(pageContext) {
7
- if (pageContext._pageContextAlreadyProvidedByOnPrerenderHook) {
8
- return;
9
- }
10
- const hook = getHook(pageContext, 'onBeforeRender');
11
- if (!hook) {
12
- return;
13
- }
14
- const onBeforeRender = hook.hookFn;
15
- preparePageContextForUserConsumptionServerSide(pageContext);
16
- const hookResult = await executeHook(() => onBeforeRender(pageContext), hook);
17
- assertOnBeforeRenderHookReturn(hookResult, hook.hookFilePath);
18
- const pageContextFromHook = hookResult?.pageContext;
19
- Object.assign(pageContext, pageContextFromHook);
20
- }