vike 0.4.224 → 0.4.225-commit-2b7971f

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 (163) hide show
  1. package/dist/cjs/client/shared/getPageContextProxyForUser.js +3 -66
  2. package/dist/cjs/node/api/build.js +1 -1
  3. package/dist/cjs/node/api/context.js +4 -4
  4. package/dist/cjs/node/api/dev.js +1 -1
  5. package/dist/cjs/node/api/prepareViteApiCall.js +25 -14
  6. package/dist/cjs/node/api/prerender.js +1 -1
  7. package/dist/cjs/node/api/preview.js +1 -1
  8. package/dist/cjs/node/cli/context.js +5 -4
  9. package/dist/cjs/node/cli/entry.js +3 -3
  10. package/dist/cjs/node/cli/parseCli.js +43 -15
  11. package/dist/cjs/node/cli/utils.js +1 -1
  12. package/dist/cjs/node/plugin/plugins/build/pluginBuildEntry.js +1 -1
  13. package/dist/cjs/node/plugin/plugins/commonConfig.js +16 -11
  14. package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +6 -4
  15. package/dist/cjs/node/plugin/plugins/devConfig/index.js +1 -1
  16. package/dist/cjs/node/plugin/plugins/importUserCode/index.js +14 -10
  17. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +10 -2
  18. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +11 -12
  19. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +139 -84
  20. package/dist/cjs/node/plugin/plugins/previewConfig.js +12 -7
  21. package/dist/cjs/node/plugin/plugins/setGlobalContext.js +10 -1
  22. package/dist/cjs/node/plugin/shared/addSsrMiddleware.js +5 -1
  23. package/dist/cjs/node/plugin/shared/getEnvVarObject.js +9 -8
  24. package/dist/cjs/node/plugin/shared/loggerNotProd/log.js +1 -1
  25. package/dist/cjs/node/prerender/context.js +1 -1
  26. package/dist/cjs/node/prerender/resolvePrerenderConfig.js +33 -18
  27. package/dist/cjs/node/prerender/runPrerender.js +12 -18
  28. package/dist/cjs/node/prerender/utils.js +1 -1
  29. package/dist/cjs/node/runtime/globalContext.js +9 -5
  30. package/dist/cjs/node/runtime/html/injectAssets/getViteDevScript.js +6 -3
  31. package/dist/cjs/node/runtime/html/serializePageContextClientSide.js +67 -14
  32. package/dist/cjs/node/runtime/html/stream.js +7 -0
  33. package/dist/cjs/node/runtime/renderPage/createHttpResponse/assertNoInfiniteHttpRedirect.js +14 -5
  34. package/dist/cjs/node/runtime/renderPage/createHttpResponse.js +2 -4
  35. package/dist/cjs/node/runtime/renderPage/logErrorHint.js +6 -1
  36. package/dist/cjs/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.js +3 -0
  37. package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +18 -12
  38. package/dist/cjs/node/runtime/renderPage.js +19 -38
  39. package/dist/cjs/node/runtime/utils.js +0 -1
  40. package/dist/cjs/node/runtime-dev/createDevMiddleware.js +10 -8
  41. package/dist/cjs/node/shared/assertV1Design.js +2 -1
  42. package/dist/cjs/node/shared/utils.js +0 -1
  43. package/dist/cjs/shared/NOT_SERIALIZABLE.js +5 -0
  44. package/dist/cjs/shared/page-configs/getConfigDefinedAt.js +19 -2
  45. package/dist/cjs/shared/page-configs/getConfigValueBuildTime.js +8 -5
  46. package/dist/cjs/shared/page-configs/helpers.js +1 -1
  47. package/dist/cjs/shared/page-configs/serialize/parsePageConfigs.js +2 -5
  48. package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +9 -5
  49. package/dist/cjs/shared/route/loadPageRoutes.js +2 -2
  50. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  51. package/dist/cjs/utils/assert.js +12 -5
  52. package/dist/cjs/utils/assertSingleInstance.js +11 -17
  53. package/dist/cjs/utils/debug.js +2 -1
  54. package/dist/cjs/utils/getRandomId.js +1 -1
  55. package/dist/cjs/utils/normalizeHeaders.js +1 -1
  56. package/dist/cjs/utils/objectAssign.js +7 -2
  57. package/dist/cjs/utils/parseUrl-extras.js +1 -0
  58. package/dist/esm/client/client-routing-runtime/createPageContext.d.ts +3 -1
  59. package/dist/esm/client/client-routing-runtime/createPageContext.js +4 -3
  60. package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +1 -1
  61. package/dist/esm/client/server-routing-runtime/getPageContext.d.ts +6 -3
  62. package/dist/esm/client/server-routing-runtime/getPageContext.js +6 -3
  63. package/dist/esm/client/shared/getPageContextProxyForUser.d.ts +1 -11
  64. package/dist/esm/client/shared/getPageContextProxyForUser.js +4 -67
  65. package/dist/esm/client/shared/preparePageContextForUserConsumptionClientSide.d.ts +2 -2
  66. package/dist/esm/node/api/build.js +1 -1
  67. package/dist/esm/node/api/context.d.ts +8 -2
  68. package/dist/esm/node/api/context.js +4 -4
  69. package/dist/esm/node/api/dev.js +1 -1
  70. package/dist/esm/node/api/prepareViteApiCall.d.ts +2 -2
  71. package/dist/esm/node/api/prepareViteApiCall.js +25 -14
  72. package/dist/esm/node/api/prerender.js +1 -1
  73. package/dist/esm/node/api/preview.js +1 -1
  74. package/dist/esm/node/api/types.d.ts +7 -0
  75. package/dist/esm/node/cli/context.d.ts +4 -2
  76. package/dist/esm/node/cli/context.js +5 -4
  77. package/dist/esm/node/cli/entry.js +4 -4
  78. package/dist/esm/node/cli/parseCli.d.ts +3 -0
  79. package/dist/esm/node/cli/parseCli.js +44 -16
  80. package/dist/esm/node/cli/utils.d.ts +1 -1
  81. package/dist/esm/node/cli/utils.js +1 -1
  82. package/dist/esm/node/plugin/plugins/build/pluginBuildEntry.js +2 -2
  83. package/dist/esm/node/plugin/plugins/commonConfig.d.ts +1 -0
  84. package/dist/esm/node/plugin/plugins/commonConfig.js +16 -11
  85. package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +6 -4
  86. package/dist/esm/node/plugin/plugins/devConfig/index.js +1 -1
  87. package/dist/esm/node/plugin/plugins/importUserCode/index.js +15 -11
  88. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +3 -1
  89. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +10 -2
  90. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.d.ts +5 -2
  91. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +11 -12
  92. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +3 -2
  93. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +141 -85
  94. package/dist/esm/node/plugin/plugins/previewConfig.js +12 -7
  95. package/dist/esm/node/plugin/plugins/setGlobalContext.js +11 -2
  96. package/dist/esm/node/plugin/shared/addSsrMiddleware.d.ts +1 -1
  97. package/dist/esm/node/plugin/shared/addSsrMiddleware.js +5 -1
  98. package/dist/esm/node/plugin/shared/getEnvVarObject.d.ts +3 -1
  99. package/dist/esm/node/plugin/shared/getEnvVarObject.js +9 -8
  100. package/dist/esm/node/plugin/shared/loggerNotProd/log.js +2 -2
  101. package/dist/esm/node/prerender/context.js +1 -1
  102. package/dist/esm/node/prerender/resolvePrerenderConfig.d.ts +2 -1
  103. package/dist/esm/node/prerender/resolvePrerenderConfig.js +34 -19
  104. package/dist/esm/node/prerender/runPrerender.js +13 -19
  105. package/dist/esm/node/prerender/utils.d.ts +1 -1
  106. package/dist/esm/node/prerender/utils.js +1 -1
  107. package/dist/esm/node/runtime/globalContext.d.ts +1 -1
  108. package/dist/esm/node/runtime/globalContext.js +10 -6
  109. package/dist/esm/node/runtime/html/injectAssets/getViteDevScript.js +6 -3
  110. package/dist/esm/node/runtime/html/serializePageContextClientSide.d.ts +2 -0
  111. package/dist/esm/node/runtime/html/serializePageContextClientSide.js +69 -15
  112. package/dist/esm/node/runtime/html/stream.js +7 -0
  113. package/dist/esm/node/runtime/index-deprecated.d.ts +1 -3
  114. package/dist/esm/node/runtime/renderPage/createHttpResponse/assertNoInfiniteHttpRedirect.d.ts +3 -1
  115. package/dist/esm/node/runtime/renderPage/createHttpResponse/assertNoInfiniteHttpRedirect.js +15 -6
  116. package/dist/esm/node/runtime/renderPage/createHttpResponse.d.ts +3 -1
  117. package/dist/esm/node/runtime/renderPage/createHttpResponse.js +2 -4
  118. package/dist/esm/node/runtime/renderPage/logErrorHint.js +6 -1
  119. package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.js +3 -0
  120. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +32 -6
  121. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +18 -12
  122. package/dist/esm/node/runtime/renderPage.js +21 -40
  123. package/dist/esm/node/runtime/utils.d.ts +0 -1
  124. package/dist/esm/node/runtime/utils.js +0 -1
  125. package/dist/esm/node/runtime-dev/createDevMiddleware.js +10 -8
  126. package/dist/esm/node/shared/assertV1Design.js +2 -1
  127. package/dist/esm/node/shared/utils.d.ts +0 -1
  128. package/dist/esm/node/shared/utils.js +0 -1
  129. package/dist/esm/shared/NOT_SERIALIZABLE.d.ts +1 -0
  130. package/dist/esm/shared/NOT_SERIALIZABLE.js +2 -0
  131. package/dist/esm/shared/page-configs/Config.d.ts +23 -3
  132. package/dist/esm/shared/page-configs/PageConfig.d.ts +17 -6
  133. package/dist/esm/shared/page-configs/getConfigDefinedAt.d.ts +5 -3
  134. package/dist/esm/shared/page-configs/getConfigDefinedAt.js +20 -3
  135. package/dist/esm/shared/page-configs/getConfigValueBuildTime.js +8 -5
  136. package/dist/esm/shared/page-configs/helpers.js +1 -1
  137. package/dist/esm/shared/page-configs/serialize/parsePageConfigs.d.ts +1 -1
  138. package/dist/esm/shared/page-configs/serialize/parsePageConfigs.js +2 -5
  139. package/dist/esm/shared/page-configs/serialize/serializeConfigValues.d.ts +3 -3
  140. package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +9 -5
  141. package/dist/esm/shared/route/abort.d.ts +2 -2
  142. package/dist/esm/shared/route/loadPageRoutes.js +2 -2
  143. package/dist/esm/shared/types.d.ts +39 -3
  144. package/dist/esm/types/index.d.ts +2 -0
  145. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  146. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  147. package/dist/esm/utils/assert.d.ts +2 -1
  148. package/dist/esm/utils/assert.js +12 -5
  149. package/dist/esm/utils/assertSingleInstance.js +11 -17
  150. package/dist/esm/utils/debug.js +2 -1
  151. package/dist/esm/utils/getRandomId.d.ts +1 -1
  152. package/dist/esm/utils/getRandomId.js +1 -1
  153. package/dist/esm/utils/normalizeHeaders.js +1 -1
  154. package/dist/esm/utils/objectAssign.d.ts +1 -1
  155. package/dist/esm/utils/objectAssign.js +7 -2
  156. package/dist/esm/utils/parseUrl-extras.js +1 -0
  157. package/package.json +6 -3
  158. package/dist/cjs/shared/notSerializable.js +0 -5
  159. package/dist/cjs/utils/projectInfo.js +0 -8
  160. package/dist/esm/shared/notSerializable.d.ts +0 -1
  161. package/dist/esm/shared/notSerializable.js +0 -2
  162. package/dist/esm/utils/projectInfo.d.ts +0 -4
  163. package/dist/esm/utils/projectInfo.js +0 -5
@@ -2,78 +2,15 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getPageContextProxyForUser = getPageContextProxyForUser;
4
4
  const utils_js_1 = require("../server-routing-runtime/utils.js");
5
- const notSerializable_js_1 = require("../../shared/notSerializable.js");
6
- const globalObject = (0, utils_js_1.getGlobalObject)('shared/getPageContextProxyForUser.ts', {});
7
- /**
8
- * Throw error when pageContext value isn't:
9
- * - serializable, or
10
- * - defined.
11
- */
5
+ const NOT_SERIALIZABLE_js_1 = require("../../shared/NOT_SERIALIZABLE.js");
6
+ // Throw error when pageContext value isn't serializable
12
7
  function getPageContextProxyForUser(pageContext) {
13
- (0, utils_js_1.assert)([true, false].includes(pageContext._hasPageContextFromServer));
14
- (0, utils_js_1.assert)([true, false].includes(pageContext._hasPageContextFromClient));
15
8
  return new Proxy(pageContext, {
16
9
  get(_, prop) {
17
10
  const val = pageContext[prop];
18
11
  const propName = (0, utils_js_1.getPropAccessNotation)(prop);
19
- (0, utils_js_1.assertUsage)(val !== notSerializable_js_1.notSerializable, `Can't access pageContext${propName} on the client side. Because it can't be serialized, see server logs.`);
20
- passToClientHint(pageContext, prop, propName);
12
+ (0, utils_js_1.assertUsage)(val !== NOT_SERIALIZABLE_js_1.NOT_SERIALIZABLE, `Can't access pageContext${propName} on the client side. Because it can't be serialized, see server logs.`);
21
13
  return val;
22
14
  }
23
15
  });
24
16
  }
25
- function passToClientHint(pageContext, prop, propName) {
26
- if (handleVueReactivity(prop))
27
- return;
28
- // `prop in pageContext` is the trick we use to know the passToClient value on the client-side, as we set a value to all passToClient props, even `undefined` ones:
29
- // ```html
30
- // <script id="vike_pageContext" type="application/json">{"pageProps":"!undefined"}</script>
31
- // ```
32
- if (prop in pageContext)
33
- return;
34
- if (isWhitelisted(prop))
35
- return;
36
- // The trick described above (`prop in pageContext`) doesn't work if Vike doesn't fetch any pageContext from the server.
37
- // - There would still be some value to show a warning, but it isn't worth it because of the confusion that the first recommendation (adding `prop` to `passToClient`) wouldn't actually remove the warning, and only the second recommendation (using `prop in pageContext` instead of `pageContext[prop]`) would work.
38
- if (!pageContext._hasPageContextFromServer)
39
- return;
40
- const errMsg = `pageContext${propName} isn't defined on the client-side, see https://vike.dev/passToClient#error`;
41
- if (
42
- // TODO/next-major-release always make it an error.
43
- // - Remove pageContext._hasPageContextFromClient logic (IIRC this is its only use case).
44
- pageContext._hasPageContextFromClient) {
45
- (0, utils_js_1.assertWarning)(false, errMsg, { onlyOnce: false, showStackTrace: true });
46
- }
47
- else {
48
- (0, utils_js_1.assertUsage)(false, errMsg);
49
- }
50
- }
51
- const WHITELIST = [
52
- 'then',
53
- // Vue calls toJSON()
54
- 'toJSON'
55
- ];
56
- function isWhitelisted(prop) {
57
- if (WHITELIST.includes(prop))
58
- return true;
59
- if (typeof prop === 'symbol')
60
- return true; // Vue tries to access some symbols
61
- if (typeof prop !== 'string')
62
- return true;
63
- if (prop.startsWith('__v_'))
64
- return true; // Vue internals upon `reactive(pageContext)`
65
- return false;
66
- }
67
- // Handle Vue's reactivity.
68
- // When changing a reactive object:
69
- // - Vue tries to read its old value first. This triggers a `assertIsDefined()` failure if e.g. `pageContextReactive.routeParams = pageContextNew.routeParams` and `pageContextReactive` has no `routeParams`.
70
- // - Vue seems to read __v_raw before reading the property.
71
- function handleVueReactivity(prop) {
72
- if (globalObject.prev === prop || globalObject.prev === '__v_raw')
73
- return true;
74
- globalObject.prev = prop;
75
- window.setTimeout(() => {
76
- globalObject.prev = undefined;
77
- }, 0);
78
- return false;
79
- }
@@ -16,7 +16,7 @@ const utils_js_1 = require("./utils.js");
16
16
  * https://vike.dev/api#build
17
17
  */
18
18
  async function build(options = {}) {
19
- const { viteConfigEnhanced, vikeConfig } = await (0, prepareViteApiCall_js_1.prepareViteApiCall)(options.viteConfig, 'build');
19
+ const { viteConfigEnhanced, vikeConfig } = await (0, prepareViteApiCall_js_1.prepareViteApiCall)(options, 'build');
20
20
  // Pass it to pluginAutoFullBuild()
21
21
  if (viteConfigEnhanced)
22
22
  viteConfigEnhanced._viteConfigEnhanced = viteConfigEnhanced;
@@ -3,19 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isVikeCliOrApi = isVikeCliOrApi;
4
4
  exports.setContextApiOperation = setContextApiOperation;
5
5
  exports.clearContextApiOperation = clearContextApiOperation;
6
+ exports.getApiOperation = getApiOperation;
6
7
  const utils_js_1 = require("./utils.js");
7
8
  const globalObject = (0, utils_js_1.getGlobalObject)('api/context.ts', {});
8
9
  function getApiOperation() {
9
- (0, utils_js_1.assert)(globalObject.apiOperation);
10
- return globalObject.apiOperation;
10
+ return globalObject.apiOperation ?? null;
11
11
  }
12
12
  function isVikeCliOrApi() {
13
13
  // The CLI uses the API
14
14
  return !!globalObject.apiOperation;
15
15
  }
16
- function setContextApiOperation(operation) {
16
+ function setContextApiOperation(operation, options) {
17
17
  (0, utils_js_1.assert)(!globalObject.apiOperation);
18
- globalObject.apiOperation = operation;
18
+ globalObject.apiOperation = { operation, options };
19
19
  }
20
20
  function clearContextApiOperation() {
21
21
  globalObject.apiOperation = undefined;
@@ -9,7 +9,7 @@ const vite_1 = require("vite");
9
9
  * https://vike.dev/api#dev
10
10
  */
11
11
  async function dev(options = {}) {
12
- const { viteConfigEnhanced } = await (0, prepareViteApiCall_js_1.prepareViteApiCall)(options.viteConfig, 'dev');
12
+ const { viteConfigEnhanced } = await (0, prepareViteApiCall_js_1.prepareViteApiCall)(options, 'dev');
13
13
  const server = await (0, vite_1.createServer)(viteConfigEnhanced);
14
14
  return {
15
15
  viteServer: server,
@@ -47,10 +47,12 @@ const path_1 = __importDefault(require("path"));
47
47
  const utils_js_1 = require("./utils.js");
48
48
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
49
49
  const globalContext_js_1 = require("../runtime/globalContext.js");
50
+ const getEnvVarObject_js_1 = require("../plugin/shared/getEnvVarObject.js");
50
51
  const globalObject = (0, utils_js_1.getGlobalObject)('api/prepareViteApiCall.ts', {});
51
- async function prepareViteApiCall(viteConfigFromOptions, operation) {
52
+ async function prepareViteApiCall(options, operation) {
52
53
  clear();
53
- (0, context_js_1.setContextApiOperation)(operation);
54
+ (0, context_js_1.setContextApiOperation)(operation, options);
55
+ const viteConfigFromOptions = options.viteConfig;
54
56
  return enhanceViteConfig(viteConfigFromOptions, operation);
55
57
  }
56
58
  // For subsequent API calls, e.g. calling prerender() after build()
@@ -59,7 +61,7 @@ function clear() {
59
61
  (0, globalContext_js_1.clearGlobalContext)();
60
62
  }
61
63
  async function enhanceViteConfig(viteConfigFromOptions, operation) {
62
- const viteInfo = await getInfoFromVite(viteConfigFromOptions, operation);
64
+ const viteInfo = await getViteInfo(viteConfigFromOptions, operation);
63
65
  await assertViteRoot2(viteInfo.root, viteInfo.viteConfigEnhanced, operation);
64
66
  const vikeConfig = await (0, getVikeConfig_js_1.getVikeConfig2)(viteInfo.root, operation === 'dev', viteInfo.vikeVitePluginOptions);
65
67
  const viteConfigEnhanced = addViteSettingsSetByVikeConfig(viteInfo.viteConfigEnhanced, vikeConfig);
@@ -81,21 +83,30 @@ function addViteSettingsSetByVikeConfig(viteConfigEnhanced, vikeConfig) {
81
83
  }
82
84
  async function getViteRoot(operation) {
83
85
  if (!globalObject.root)
84
- await getInfoFromVite(undefined, operation);
86
+ await getViteInfo(undefined, operation);
85
87
  (0, utils_js_1.assert)(globalObject.root);
86
88
  return globalObject.root;
87
89
  }
88
- async function getInfoFromVite(viteConfigFromOptions, operation) {
89
- const viteConfigFromUserViteFile = await loadViteConfigFile(viteConfigFromOptions, operation);
90
- const root = normalizeViteRoot(
91
- // `viteConfigFromOptions.root` before `viteConfigFromUserViteFile.root` replicates Vite's precedence:
90
+ async function getViteInfo(viteConfigFromOptions, operation) {
91
+ let viteConfigEnhanced = viteConfigFromOptions;
92
+ // Precedence:
93
+ // - viteConfigFromUserEnvVar (highest precendence)
94
+ // - viteConfigFromOptions
95
+ // - viteConfigFromUserViteFile (lowest precendence)
96
+ const viteConfigFromUserEnvVar = (0, getEnvVarObject_js_1.getEnvVarObject)('VITE_CONFIG');
97
+ if (viteConfigFromUserEnvVar)
98
+ viteConfigEnhanced = (0, vite_1.mergeConfig)(viteConfigEnhanced ?? {}, viteConfigFromUserEnvVar);
99
+ const viteConfigFromUserViteFile = await loadViteConfigFile(viteConfigEnhanced, operation);
100
+ // Correct precedence, replicates Vite:
92
101
  // https://github.com/vitejs/vite/blob/4f5845a3182fc950eb9cd76d7161698383113b18/packages/vite/src/node/config.ts#L1001
93
- viteConfigFromOptions?.root ?? viteConfigFromUserViteFile?.root ?? process.cwd());
102
+ const viteConfigResolved = (0, vite_1.mergeConfig)(viteConfigFromUserViteFile ?? {}, viteConfigEnhanced ?? {});
103
+ const root = normalizeViteRoot(viteConfigResolved.root ?? process.cwd());
94
104
  globalObject.root = root;
105
+ // - Find options `vike(options)` set in vite.config.js
106
+ // - TODO/next-major: remove
107
+ // - Add Vike's Vite plugin if missing
95
108
  let vikeVitePluginOptions;
96
- let viteConfigEnhanced = viteConfigFromOptions;
97
- // If Vike's Vite plugin is found in both viteConfigFromOptions and viteConfigFromUserViteFile then Vike will later throw an error
98
- const found = findVikeVitePlugin(viteConfigFromOptions) || findVikeVitePlugin(viteConfigFromUserViteFile);
109
+ const found = findVikeVitePlugin(viteConfigResolved);
99
110
  if (found) {
100
111
  vikeVitePluginOptions = found.vikeVitePluginOptions;
101
112
  }
@@ -104,8 +115,8 @@ async function getInfoFromVite(viteConfigFromOptions, operation) {
104
115
  // Using a dynamic import because the script calling the Vike API may not live in the same place as vite.config.js, thus vike/plugin may resolved to two different node_modules/vike directories.
105
116
  const { plugin: vikePlugin } = await Promise.resolve().then(() => __importStar(require('../plugin/index.js')));
106
117
  viteConfigEnhanced = {
107
- ...viteConfigFromOptions,
108
- plugins: [...(viteConfigFromOptions?.plugins ?? []), vikePlugin()]
118
+ ...viteConfigEnhanced,
119
+ plugins: [...(viteConfigEnhanced?.plugins ?? []), vikePlugin()]
109
120
  };
110
121
  const res = findVikeVitePlugin(viteConfigEnhanced);
111
122
  (0, utils_js_1.assert)(res);
@@ -10,7 +10,7 @@ const prepareViteApiCall_js_1 = require("./prepareViteApiCall.js");
10
10
  * https://vike.dev/api#prerender
11
11
  */
12
12
  async function prerender(options = {}) {
13
- const { viteConfigEnhanced } = await (0, prepareViteApiCall_js_1.prepareViteApiCall)(options.viteConfig, 'prerender');
13
+ const { viteConfigEnhanced } = await (0, prepareViteApiCall_js_1.prepareViteApiCall)(options, 'prerender');
14
14
  options.viteConfig = viteConfigEnhanced;
15
15
  const { viteConfig } = await (0, runPrerender_js_1.runPrerenderFromAPI)(options);
16
16
  return {
@@ -9,7 +9,7 @@ const vite_1 = require("vite");
9
9
  * https://vike.dev/api#preview
10
10
  */
11
11
  async function preview(options = {}) {
12
- const { viteConfigEnhanced } = await (0, prepareViteApiCall_js_1.prepareViteApiCall)(options.viteConfig, 'preview');
12
+ const { viteConfigEnhanced } = await (0, prepareViteApiCall_js_1.prepareViteApiCall)(options, 'preview');
13
13
  const server = await (0, vite_1.preview)(viteConfigEnhanced);
14
14
  return {
15
15
  viteServer: server,
@@ -2,15 +2,16 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isVikeCli = isVikeCli;
4
4
  exports.setContextCliCommand = setContextCliCommand;
5
+ exports.getCliOptions = getCliOptions;
5
6
  const utils_js_1 = require("./utils.js");
6
7
  const globalObject = (0, utils_js_1.getGlobalObject)('cli/context.ts', {});
7
- function getCliCommand() {
8
- return globalObject.cliCommand;
8
+ function getCliOptions() {
9
+ return globalObject.cliCommand?.cliOptions ?? null;
9
10
  }
10
11
  function isVikeCli() {
11
12
  return !!globalObject.cliCommand;
12
13
  }
13
- function setContextCliCommand(command) {
14
+ function setContextCliCommand(command, cliOptions) {
14
15
  (0, utils_js_1.assert)(!globalObject.cliCommand);
15
- globalObject.cliCommand = command;
16
+ globalObject.cliCommand = { command, cliOptions };
16
17
  }
@@ -43,8 +43,8 @@ const parseCli_js_1 = require("./parseCli.js");
43
43
  const context_js_1 = require("./context.js");
44
44
  cli();
45
45
  async function cli() {
46
- const { command } = (0, parseCli_js_1.parseCli)();
47
- (0, context_js_1.setContextCliCommand)(command);
46
+ const { command, cliOptions } = (0, parseCli_js_1.parseCli)();
47
+ (0, context_js_1.setContextCliCommand)(command, cliOptions);
48
48
  if (command === 'dev') {
49
49
  await cmdDev();
50
50
  }
@@ -66,7 +66,7 @@ async function cmdDev() {
66
66
  const info = viteServer.config.logger.info;
67
67
  const startupDurationString = picocolors_1.default.dim(`ready in ${picocolors_1.default.reset(picocolors_1.default.bold(String(Math.ceil(performance.now() - startTime))))} ms`);
68
68
  const hasExistingLogs = process.stdout.bytesWritten > 0 || process.stderr.bytesWritten > 0;
69
- info(` ${picocolors_1.default.yellow(`${picocolors_1.default.bold(utils_js_1.projectInfo.projectName)} v${utils_js_1.projectInfo.projectVersion}`)} ${startupDurationString}\n`, {
69
+ info(` ${picocolors_1.default.yellow(`${picocolors_1.default.bold('Vike')} v${utils_js_1.PROJECT_VERSION}`)} ${startupDurationString}\n`, {
70
70
  clear: !hasExistingLogs
71
71
  });
72
72
  viteServer.printUrls();
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.parseCli = parseCli;
7
7
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
8
8
  const utils_js_1 = require("./utils.js");
9
+ const getEnvVarObject_js_1 = require("../plugin/shared/getEnvVarObject.js");
9
10
  const commands = [
10
11
  { name: 'dev', desc: 'Start development server' },
11
12
  { name: 'build', desc: 'Build for production' },
@@ -13,32 +14,59 @@ const commands = [
13
14
  { name: 'prerender', desc: 'Pre-render pages (only needed when partial.disableAutoRun is true)' }
14
15
  ];
15
16
  function parseCli() {
16
- const command = (() => {
17
- const firstArg = process.argv[2];
18
- if (!firstArg) {
19
- showHelp();
20
- }
21
- showHelpOrVersion(firstArg);
22
- if ((0, utils_js_1.includes)(commands.map((c) => c.name), firstArg))
23
- return firstArg;
24
- wrongUsage(`Unknown command ${picocolors_1.default.bold(firstArg)}`);
25
- })();
17
+ const command = getCommand();
18
+ const cliOptions = getCliOptions();
19
+ return { command, cliOptions };
20
+ }
21
+ function getCommand() {
22
+ const firstArg = process.argv[2];
23
+ if ((0, utils_js_1.includes)(commands.map((c) => c.name), firstArg)) {
24
+ return firstArg;
25
+ }
26
+ if (!firstArg)
27
+ showHelp();
28
+ showHelpOrVersion(firstArg);
29
+ wrongUsage(`Unknown command ${picocolors_1.default.bold(firstArg)}`);
30
+ }
31
+ function getCliOptions() {
32
+ let cliOptions = {};
33
+ let configNameCurrent;
34
+ const commitIfDefinedWithoutValue = () => {
35
+ if (configNameCurrent)
36
+ commit(true);
37
+ };
38
+ const commit = (val) => {
39
+ (0, utils_js_1.assert)(configNameCurrent);
40
+ cliOptions[configNameCurrent] = val;
41
+ configNameCurrent = undefined;
42
+ };
26
43
  for (const arg of process.argv.slice(3)) {
27
44
  showHelpOrVersion(arg);
28
- wrongUsage(`Unknown option ${picocolors_1.default.bold(arg)}`);
45
+ if (arg.startsWith('--')) {
46
+ commitIfDefinedWithoutValue();
47
+ configNameCurrent = arg.slice('--'.length);
48
+ }
49
+ else {
50
+ if (!configNameCurrent)
51
+ wrongUsage(`Unknown option ${picocolors_1.default.bold(arg)}`);
52
+ commit((0, getEnvVarObject_js_1.parseJson5)(arg, `CLI option --${configNameCurrent}`));
53
+ }
29
54
  }
30
- return { command };
55
+ commitIfDefinedWithoutValue();
56
+ return cliOptions;
31
57
  }
32
58
  function showHelp() {
33
59
  const TAB = ' '.repeat(3);
34
60
  const nameMaxLength = Math.max(...commands.map((c) => c.name.length));
35
61
  console.log([
36
- `vike@${utils_js_1.projectInfo.projectVersion}`,
62
+ `vike@${utils_js_1.PROJECT_VERSION}`,
37
63
  '',
38
64
  'Usage:',
39
65
  ...[...commands, { name: '-v', desc: "Print Vike's installed version" }].map((c) => ` ${picocolors_1.default.dim('$')} ${picocolors_1.default.bold(`vike ${c.name}`)}${' '.repeat(nameMaxLength - c.name.length)}${TAB}${picocolors_1.default.dim(`# ${c.desc}`)}`),
40
66
  '',
41
- `More infos at ${picocolors_1.default.underline('https://vike.dev/cli')}`
67
+ `Vike settings can be passed over the ${picocolors_1.default.cyan('VIKE_CONFIG')} environment variable or as ${picocolors_1.default.cyan('CLI options')} such as --host.`,
68
+ `Vite settings can be passed over the ${picocolors_1.default.cyan('VITE_CONFIG')} environment variable.`,
69
+ `See ${picocolors_1.default.underline('https://vike.dev/cli')} for more information.`
42
70
  ].join('\n'));
43
71
  process.exit(1);
44
72
  }
@@ -51,7 +79,7 @@ function showHelpOrVersion(arg) {
51
79
  }
52
80
  }
53
81
  function showVersion() {
54
- console.log(utils_js_1.projectInfo.projectVersion);
82
+ console.log(utils_js_1.PROJECT_VERSION);
55
83
  process.exit(1);
56
84
  }
57
85
  function wrongUsage(msg) {
@@ -19,6 +19,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
19
19
  const onLoad_js_1 = require("./onLoad.js");
20
20
  (0, onLoad_js_1.onLoad)();
21
21
  __exportStar(require("../../utils/assert.js"), exports);
22
- __exportStar(require("../../utils/projectInfo.js"), exports);
22
+ __exportStar(require("../../utils/PROJECT_VERSION.js"), exports);
23
23
  __exportStar(require("../../utils/includes.js"), exports);
24
24
  __exportStar(require("../../utils/getGlobalObject.js"), exports);
@@ -40,7 +40,7 @@ function pluginBuildEntry() {
40
40
  function getServerProductionEntryCode(config) {
41
41
  const importPath = getImportPath(config);
42
42
  const buildInfo = {
43
- versionAtBuildTime: utils_js_1.projectInfo.projectVersion,
43
+ versionAtBuildTime: utils_js_1.PROJECT_VERSION,
44
44
  usesClientRouter: (0, extractExportNamesPlugin_js_1.isUsingClientRouter)(), // TODO/v1-release: remove
45
45
  viteConfigRuntime: (0, globalContext_js_1.getViteConfigRuntime)(config)
46
46
  };
@@ -5,14 +5,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.commonConfig = commonConfig;
7
7
  exports.getVikeConfigPublic = getVikeConfigPublic;
8
- const vite_1 = require("vite");
9
8
  const utils_js_1 = require("../utils.js");
10
9
  const pluginBuildConfig_js_1 = require("./build/pluginBuildConfig.js");
11
10
  const require_shim_1 = require("@brillout/require-shim");
12
11
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
13
12
  const path_1 = __importDefault(require("path"));
14
13
  const assertResolveAlias_js_1 = require("./commonConfig/assertResolveAlias.js");
15
- const getEnvVarObject_js_1 = require("../shared/getEnvVarObject.js");
16
14
  const isViteCliCall_js_1 = require("../shared/isViteCliCall.js");
17
15
  const context_js_1 = require("../../api/context.js");
18
16
  const getVikeConfig_js_1 = require("./importUserCode/v1-design/getVikeConfig.js");
@@ -44,7 +42,7 @@ function commonConfig(vikeVitePluginOptions) {
44
42
  },
45
43
  // TODO/v1-release: remove https://github.com/vikejs/vike/issues/2122
46
44
  configVikePromise: Promise.resolve({
47
- prerender: (0, resolvePrerenderConfig_js_1.resolvePrerenderConfigGlobal)(vikeConfig).isEnabled
45
+ prerender: (0, resolvePrerenderConfig_js_1.resolvePrerenderConfigGlobal)(vikeConfig).isPrerenderingEnabled
48
46
  })
49
47
  };
50
48
  }
@@ -78,17 +76,24 @@ function commonConfig(vikeVitePluginOptions) {
78
76
  config: {
79
77
  order: 'post',
80
78
  handler(configFromUser) {
81
- // Change default port
82
79
  let configFromVike = { server: {}, preview: {} };
83
- setDefault('port', 3000, configFromUser, configFromVike);
84
- // Set `--host` for Docker/Podman
85
- if ((0, utils_js_1.isDocker)()) {
80
+ const vike = getVikeConfigPublic(configFromUser);
81
+ if (vike.config.port !== undefined) {
82
+ // https://vike.dev/port
83
+ setDefault('port', vike.config.port, configFromUser, configFromVike);
84
+ }
85
+ else {
86
+ // Change Vite's default port
87
+ setDefault('port', 3000, configFromUser, configFromVike);
88
+ }
89
+ if (vike.config.host) {
90
+ // https://vike.dev/host
91
+ setDefault('host', vike.config.host, configFromUser, configFromVike);
92
+ }
93
+ else if ((0, utils_js_1.isDocker)()) {
94
+ // Set `--host` for Docker/Podman
86
95
  setDefault('host', true, configFromUser, configFromVike);
87
96
  }
88
- // VITE_CONFIG
89
- const configFromEnvVar = (0, getEnvVarObject_js_1.getEnvVarObject)('VITE_CONFIG');
90
- if (configFromEnvVar)
91
- configFromVike = (0, vite_1.mergeConfig)(configFromVike, configFromEnvVar);
92
97
  return configFromVike;
93
98
  }
94
99
  }
@@ -52,16 +52,18 @@ async function getPageDeps(config, pageConfigs) {
52
52
  .forEach((configValueSource) => {
53
53
  if (!configValueSource.valueIsLoadedWithImport && !configValueSource.valueIsFilePath)
54
54
  return;
55
- const { definedAtFilePath, configEnv } = configValueSource;
55
+ const { definedAt, configEnv } = configValueSource;
56
56
  if (!configEnv.client)
57
57
  return;
58
- if (definedAtFilePath.filePathAbsoluteUserRootDir !== null) {
58
+ if (definedAt.definedBy)
59
+ return;
60
+ if (definedAt.filePathAbsoluteUserRootDir !== null) {
59
61
  // Vite expects entries to be filesystem absolute paths (surprisingly so).
60
- addEntry(definedAtFilePath.filePathAbsoluteFilesystem);
62
+ addEntry(definedAt.filePathAbsoluteFilesystem);
61
63
  }
62
64
  else {
63
65
  // Adding definedAtFilePath.filePathAbsoluteFilesystem doesn't work for npm packages, I guess because of Vite's config.server.fs.allow
64
- addInclude(definedAtFilePath.importPathAbsolute);
66
+ addInclude(definedAt.importPathAbsolute);
65
67
  }
66
68
  });
67
69
  });
@@ -84,7 +84,7 @@ function devConfig() {
84
84
  if (config.server.middlewareMode || hasHonoViteDevServer)
85
85
  return;
86
86
  return () => {
87
- (0, addSsrMiddleware_js_1.addSsrMiddleware)(server.middlewares, config, false);
87
+ (0, addSsrMiddleware_js_1.addSsrMiddleware)(server.middlewares, config, false, null);
88
88
  };
89
89
  }
90
90
  },
@@ -34,9 +34,9 @@ function importUserCode() {
34
34
  return (0, virtual_files_js_1.resolveVirtualFileId)(id);
35
35
  }
36
36
  },
37
- handleHotUpdate(ctx) {
37
+ async handleHotUpdate(ctx) {
38
38
  try {
39
- return handleHotUpdate(ctx, config);
39
+ return await handleHotUpdate(ctx, config);
40
40
  }
41
41
  catch (err) {
42
42
  // Vite swallows errors thrown by handleHotUpdate()
@@ -68,9 +68,9 @@ function handleFileAddRemove(server, config) {
68
68
  server.watcher.prependListener('add', (f) => listener(f, false));
69
69
  server.watcher.prependListener('unlink', (f) => listener(f, true));
70
70
  return;
71
- function listener(file, isRemove) {
71
+ async function listener(file, isRemove) {
72
72
  file = (0, vite_1.normalizePath)(file);
73
- if ((0, crawlPlusFiles_js_1.isPlusFile)(file) || isVikeConfigDependency(file, server.moduleGraph)?.modifiesVikeVirtualFiles) {
73
+ if ((0, crawlPlusFiles_js_1.isPlusFile)(file) || (await isVikeConfigDependency(file, server.moduleGraph))?.modifiesVikeVirtualFiles) {
74
74
  invalidateVikeVirtualFiles(server);
75
75
  reloadConfig(file, config, isRemove ? 'removed' : 'created');
76
76
  }
@@ -82,9 +82,9 @@ function invalidateVikeVirtualFiles(server) {
82
82
  server.moduleGraph.invalidateModule(mod);
83
83
  });
84
84
  }
85
- function handleHotUpdate(ctx, config) {
85
+ async function handleHotUpdate(ctx, config) {
86
86
  const { file, server } = ctx;
87
- const isVikeConfig = isVikeConfigDependency(ctx.file, ctx.server.moduleGraph);
87
+ const isVikeConfig = await isVikeConfigDependency(ctx.file, ctx.server.moduleGraph);
88
88
  if (isVikeConfig) {
89
89
  if (isVikeConfig.modifiesVikeVirtualFiles) {
90
90
  /* Tailwind breaks this assertion, see https://github.com/vikejs/vike/discussions/1330#discussioncomment-7787238
@@ -106,12 +106,16 @@ function handleHotUpdate(ctx, config) {
106
106
  }
107
107
  }
108
108
  }
109
- function isVikeConfigDependency(filePathAbsoluteFilesystem, moduleGraph) {
109
+ async function isVikeConfigDependency(filePathAbsoluteFilesystem, moduleGraph) {
110
110
  // Check config-only files, for example all pages/+config.js dependencies. (There aren't part of Vite's module graph.)
111
111
  (0, utils_js_1.assertPosixPath)(filePathAbsoluteFilesystem);
112
- getVikeConfig_js_1.vikeConfigDependencies.forEach((f) => (0, utils_js_1.assertPosixPath)(f));
113
- if (getVikeConfig_js_1.vikeConfigDependencies.has(filePathAbsoluteFilesystem))
114
- return { modifiesVikeVirtualFiles: true };
112
+ const vikeConfigObject = await (0, getVikeConfig_js_1.getVikeConfigOptional)();
113
+ if (vikeConfigObject) {
114
+ const { vikeConfigDependencies } = vikeConfigObject;
115
+ vikeConfigDependencies.forEach((f) => (0, utils_js_1.assertPosixPath)(f));
116
+ if (vikeConfigDependencies.has(filePathAbsoluteFilesystem))
117
+ return { modifiesVikeVirtualFiles: true };
118
+ }
115
119
  // Check using Vite's module graph, for example all +htmlAttributes dependencies.
116
120
  // Alternatively, simply call updateUserFiles() on every handleHotUpdate() call.
117
121
  const importers = getImporters(filePathAbsoluteFilesystem, moduleGraph);
@@ -98,7 +98,7 @@ const configDefinitionsBuiltIn = {
98
98
  (0, utils_js_1.assert)(source.valueIsLoaded);
99
99
  if (source.value !== null) {
100
100
  const { value } = source;
101
- const definedAt = (0, getConfigDefinedAt_js_1.getConfigDefinedAt)('Config', 'clientHooks', source.definedAtFilePath);
101
+ const definedAt = (0, getConfigDefinedAt_js_1.getConfigDefinedAt)('Config', 'clientHooks', source.definedAt);
102
102
  (0, utils_js_1.assertUsage)(typeof value === 'boolean', `${definedAt} should be a boolean`);
103
103
  return value;
104
104
  }
@@ -125,6 +125,14 @@ const configDefinitionsBuiltIn = {
125
125
  cacheControl: {
126
126
  env: { server: true }
127
127
  },
128
+ host: {
129
+ env: { config: true },
130
+ global: true
131
+ },
132
+ port: {
133
+ env: { config: true },
134
+ global: true
135
+ },
128
136
  injectScriptsAt: {
129
137
  env: { server: true }
130
138
  },
@@ -150,7 +158,7 @@ const configDefinitionsBuiltIn = {
150
158
  },
151
159
  prerender: {
152
160
  env: { config: true },
153
- global: (value) => typeof value === 'object',
161
+ global: (value, { isGlobalLocation }) => typeof value === 'object' || isGlobalLocation,
154
162
  type: ['boolean', 'object'],
155
163
  cumulative: true
156
164
  },
@@ -14,7 +14,6 @@ const picocolors_1 = __importDefault(require("@brillout/picocolors"));
14
14
  const import_1 = require("@brillout/import");
15
15
  const utils_js_1 = require("../../../../utils.js");
16
16
  const transformPointerImports_js_1 = require("./transformPointerImports.js");
17
- const getVikeConfig_js_1 = require("../getVikeConfig.js");
18
17
  const source_map_support_1 = __importDefault(require("source-map-support"));
19
18
  const getFilePath_js_1 = require("../../../../shared/getFilePath.js");
20
19
  const module_1 = require("module");
@@ -31,11 +30,11 @@ async function transpileAndExecuteFile(filePath, userRootDir, isExtensionConfig,
31
30
  const { filePathAbsoluteFilesystem, filePathToShowToUserResolved } = filePath;
32
31
  (0, utils_js_1.assert)(filePathAbsoluteFilesystem);
33
32
  const fileExtension = getFileExtension(filePathAbsoluteFilesystem);
34
- if (esbuildCache[filePathAbsoluteFilesystem]) {
35
- return await esbuildCache[filePathAbsoluteFilesystem];
33
+ if (esbuildCache.transpileCache[filePathAbsoluteFilesystem]) {
34
+ return await esbuildCache.transpileCache[filePathAbsoluteFilesystem];
36
35
  }
37
36
  const { promise, resolve } = (0, utils_js_1.genPromise)();
38
- esbuildCache[filePathAbsoluteFilesystem] = promise;
37
+ esbuildCache.transpileCache[filePathAbsoluteFilesystem] = promise;
39
38
  (0, utils_js_1.assertUsage)((0, utils_js_1.isPlainJavaScriptFile)(filePathAbsoluteFilesystem), `${filePathToShowToUserResolved} has file extension .${fileExtension} but a config file can only be a JavaScript/TypeScript file`);
40
39
  const isHeader = isHeaderFile(filePathAbsoluteFilesystem);
41
40
  if (isHeader) {
@@ -48,20 +47,20 @@ async function transpileAndExecuteFile(filePath, userRootDir, isExtensionConfig,
48
47
  }
49
48
  else {
50
49
  const transformImports = isHeader ? 'all' : true;
51
- const code = await transpileFile(filePath, transformImports, userRootDir);
50
+ const code = await transpileFile(filePath, transformImports, userRootDir, esbuildCache);
52
51
  fileExports = await executeTranspiledFile(filePath, code);
53
52
  }
54
53
  resolve({ fileExports });
55
54
  return { fileExports };
56
55
  }
57
- async function transpileFile(filePath, transformImports, userRootDir) {
56
+ async function transpileFile(filePath, transformImports, userRootDir, esbuildCache) {
58
57
  const { filePathAbsoluteFilesystem, filePathToShowToUserResolved } = filePath;
59
58
  (0, utils_js_1.assert)(filePathAbsoluteFilesystem);
60
59
  (0, utils_js_1.assertPosixPath)(filePathAbsoluteFilesystem);
61
- getVikeConfig_js_1.vikeConfigDependencies.add(filePathAbsoluteFilesystem);
60
+ esbuildCache.vikeConfigDependencies.add(filePathAbsoluteFilesystem);
62
61
  if (debug.isActivated)
63
62
  debug('transpile', filePathToShowToUserResolved);
64
- let { code, pointerImports } = await transpileWithEsbuild(filePath, userRootDir, transformImports);
63
+ let { code, pointerImports } = await transpileWithEsbuild(filePath, userRootDir, transformImports, esbuildCache);
65
64
  if (debug.isActivated)
66
65
  debug(`code, post esbuild (${filePathToShowToUserResolved})`, code);
67
66
  let isImportTransformed = false;
@@ -80,7 +79,7 @@ async function transpileFile(filePath, transformImports, userRootDir) {
80
79
  }
81
80
  return code;
82
81
  }
83
- async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
82
+ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esbuildCache) {
84
83
  const entryFilePath = filePath.filePathAbsoluteFilesystem;
85
84
  const entryFileDir = path_1.default.posix.dirname(entryFilePath);
86
85
  const options = {
@@ -234,7 +233,7 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
234
233
  // We collect the dependency `args.path` in case the bulid fails (upon build error => error is thrown => no metafile)
235
234
  let { path } = args;
236
235
  path = (0, utils_js_1.toPosixPath)(path);
237
- getVikeConfig_js_1.vikeConfigDependencies.add(path);
236
+ esbuildCache.vikeConfigDependencies.add(path);
238
237
  return undefined;
239
238
  });
240
239
  /* To exhaustively collect all dependencies upon build failure, we would also need to use onResolve().
@@ -263,7 +262,7 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
263
262
  filePathRelative = (0, utils_js_1.toPosixPath)(filePathRelative);
264
263
  (0, utils_js_1.assertPosixPath)(userRootDir);
265
264
  const filePathAbsoluteFilesystem = path_1.default.posix.join(userRootDir, filePathRelative);
266
- getVikeConfig_js_1.vikeConfigDependencies.add(filePathAbsoluteFilesystem);
265
+ esbuildCache.vikeConfigDependencies.add(filePathAbsoluteFilesystem);
267
266
  });
268
267
  const code = result.outputFiles[0].text;
269
268
  (0, utils_js_1.assert)(typeof code === 'string');
@@ -335,7 +334,7 @@ function getTemporaryBuildFilePath(filePathAbsoluteFilesystem) {
335
334
  const dirname = path_1.default.posix.dirname(filePathAbsoluteFilesystem);
336
335
  const filename = path_1.default.posix.basename(filePathAbsoluteFilesystem);
337
336
  // Syntax with semicolon `build:${/*...*/}` doesn't work on Windows: https://github.com/vikejs/vike/issues/800#issuecomment-1517329455
338
- const filePathTmp = path_1.default.posix.join(dirname, `${filename}.build-${(0, utils_js_1.getRandomId)(12)}.mjs`);
337
+ const filePathTmp = path_1.default.posix.join(dirname, `${filename}.build-${(0, utils_js_1.getRandomId)()}.mjs`);
339
338
  (0, utils_js_1.assert)(isTemporaryBuildFile(filePathTmp));
340
339
  return filePathTmp;
341
340
  }