vike 0.4.257 → 0.4.258-commit-24a5c2b

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 (27) hide show
  1. package/dist/node/api/dev.js +4 -14
  2. package/dist/node/api/getStartupLogFirstLine.d.ts +7 -0
  3. package/dist/node/api/getStartupLogFirstLine.js +20 -0
  4. package/dist/node/api/preview.js +30 -9
  5. package/dist/node/vite/plugins/build/pluginDistFileNames.js +126 -58
  6. package/dist/node/vite/plugins/build/pluginModuleBanner.js +10 -1
  7. package/dist/node/vite/plugins/pluginUniversalDeploy/getServerConfig.d.ts +1 -1
  8. package/dist/node/vite/plugins/pluginUniversalDeploy/getServerConfig.js +2 -2
  9. package/dist/node/vite/shared/loggerVite.d.ts +1 -1
  10. package/dist/node/vite/shared/loggerVite.js +2 -2
  11. package/dist/node/vite/shared/resolveVikeConfigInternal/getPlusFilesByLocationId.js +2 -2
  12. package/dist/node/vite/shared/resolveVikeConfigInternal/loadFileAtConfigTime.d.ts +1 -1
  13. package/dist/node/vite/shared/resolveVikeConfigInternal/{configDefinitionsBuiltIn.d.ts → metaBuiltIn.d.ts} +2 -2
  14. package/dist/node/vite/shared/resolveVikeConfigInternal/{configDefinitionsBuiltIn.js → metaBuiltIn.js} +2 -3
  15. package/dist/node/vite/shared/resolveVikeConfigInternal/pointerImports.d.ts +5 -2
  16. package/dist/node/vite/shared/resolveVikeConfigInternal/resolvePointerImport.js +9 -1
  17. package/dist/node/vite/shared/resolveVikeConfigInternal.d.ts +1 -1
  18. package/dist/node/vite/shared/resolveVikeConfigInternal.js +4 -4
  19. package/dist/server/runtime/renderPageServer/createHttpResponse.js +8 -6
  20. package/dist/shared-server-client/page-configs/loadAndParseVirtualFilePageEntry.js +6 -3
  21. package/dist/types/Config.d.ts +1 -1
  22. package/dist/types/FilePath.d.ts +6 -6
  23. package/dist/types/PageConfig.d.ts +1 -1
  24. package/dist/types/index.d.ts +2 -2
  25. package/dist/utils/PROJECT_VERSION.d.ts +1 -1
  26. package/dist/utils/PROJECT_VERSION.js +1 -1
  27. package/package.json +5 -4
@@ -5,12 +5,9 @@ import { prepareViteApiCall } from './prepareViteApiCall.js';
5
5
  import { createServer } from 'vite';
6
6
  import { assert } from '../../utils/assert.js';
7
7
  import { assertIsNotProductionRuntime } from '../../utils/assertSetup.js';
8
- import { colorVike } from '../../utils/colorsClient.js';
9
- import { colorVite } from '../../utils/colorsServer.js';
10
- import { PROJECT_VERSION } from '../../utils/PROJECT_VERSION.js';
11
8
  import pc from '@brillout/picocolors';
12
- import { processStartupLog } from '../vite/shared/loggerVite.js';
13
9
  import './assertEnvApiDev.js';
10
+ import { getStartupLogFirstLine } from './getStartupLogFirstLine.js';
14
11
  assertIsNotProductionRuntime();
15
12
  /**
16
13
  * Programmatically trigger `$ vike dev`
@@ -42,22 +39,15 @@ async function dev(options = {}) {
42
39
  viteVersion,
43
40
  };
44
41
  }
45
- const startTime = performance.now();
46
42
  async function startupLog(resolvedUrls, viteServer) {
47
43
  const viteConfig = viteServer.config;
48
- const viteVersion = viteConfig._viteVersionResolved;
49
- assert(viteVersion);
50
- const startupDurationString = pc.dim(`ready in ${pc.reset(pc.bold(String(Math.ceil(performance.now() - startTime))))} ms`);
51
- const sep = pc.dim('·');
52
- const firstLine = `\n ${colorVike('Vike')} ${pc.yellow(`v${PROJECT_VERSION}`)} ${sep} ${colorVite('Vite')} ${pc.cyan(`v${viteVersion}`)} ${sep} ${startupDurationString}\n`;
53
- const ret = processStartupLog(firstLine, viteConfig);
54
- console.log(ret.firstLine);
55
- const { isCompact } = ret;
44
+ const { startupLogFirstLine, isStartupLogCompact } = getStartupLogFirstLine(viteConfig);
45
+ console.log(startupLogFirstLine);
56
46
  // We don't call viteServer.printUrls() because Vite throws an error if `resolvedUrls` is missing:
57
47
  // https://github.com/vitejs/vite/blob/df5a30d2690a2ebc4824a79becdcef30538dc602/packages/vite/src/node/server/index.ts#L745
58
48
  printServerUrls(resolvedUrls, viteConfig.server.host);
59
49
  viteServer.bindCLIShortcuts({ print: true });
60
- if (!isCompact)
50
+ if (!isStartupLogCompact)
61
51
  console.log();
62
52
  }
63
53
  // Copied & adapted from Vite
@@ -0,0 +1,7 @@
1
+ export { getStartupLogFirstLine };
2
+ import type { ResolvedConfig } from 'vite';
3
+ import './assertEnvApiDevAndProd.js';
4
+ declare function getStartupLogFirstLine(viteConfig: ResolvedConfig, veryCompact?: boolean): {
5
+ startupLogFirstLine: string;
6
+ isStartupLogCompact: boolean;
7
+ };
@@ -0,0 +1,20 @@
1
+ export { getStartupLogFirstLine };
2
+ import { colorVike } from '../../utils/colorsClient.js';
3
+ import { colorVite } from '../../utils/colorsServer.js';
4
+ import { PROJECT_VERSION } from '../../utils/PROJECT_VERSION.js';
5
+ import pc from '@brillout/picocolors';
6
+ import { assert } from '../../utils/assert.js';
7
+ import { processStartupLog } from '../vite/shared/loggerVite.js';
8
+ import './assertEnvApiDevAndProd.js';
9
+ const startTime = performance.now();
10
+ function getStartupLogFirstLine(viteConfig, veryCompact) {
11
+ const viteVersion = viteConfig._viteVersionResolved;
12
+ assert(viteVersion);
13
+ const startupDurationString = pc.dim(`ready in ${pc.reset(pc.bold(String(Math.ceil(performance.now() - startTime))))} ms`);
14
+ const sep = pc.dim('·');
15
+ const firstLine = `${veryCompact ? '' : '\n '}${colorVike('Vike')} ${pc.yellow(`v${PROJECT_VERSION}`)} ${sep} ${colorVite('Vite')} ${pc.cyan(`v${viteVersion}`)} ${sep} ${startupDurationString}${veryCompact ? '' : '\n'}`;
16
+ const ret = processStartupLog(firstLine, viteConfig, veryCompact);
17
+ const startupLogFirstLine = ret.firstLine;
18
+ const { isCompact } = ret;
19
+ return { startupLogFirstLine, isStartupLogCompact: isCompact };
20
+ }
@@ -3,7 +3,7 @@ import { prepareViteApiCall } from './prepareViteApiCall.js';
3
3
  import { preview as previewVite } from 'vite';
4
4
  import { importServerProductionIndex } from '@brillout/vite-plugin-server-entry/runtime';
5
5
  import { getOutDirs } from '../vite/shared/getOutDirs.js';
6
- import { assertUsage, assertWarning } from '../../utils/assert.js';
6
+ import { assert, assertInfo, assertUsage } from '../../utils/assert.js';
7
7
  import { onSetupPreview } from '../../utils/assertSetup.js';
8
8
  import { isCallable } from '../../utils/isCallable.js';
9
9
  import pc from '@brillout/picocolors';
@@ -11,6 +11,7 @@ import path from 'node:path';
11
11
  import { getVikeConfigInternal } from '../vite/shared/resolveVikeConfigInternal.js';
12
12
  import { isUniversalDeployVitePreview } from '../vite/plugins/pluginUniversalDeploy/getServerConfig.js';
13
13
  import './assertEnvApiDev.js';
14
+ import { getStartupLogFirstLine } from './getStartupLogFirstLine.js';
14
15
  /**
15
16
  * Programmatically trigger `$ vike preview`
16
17
  *
@@ -23,19 +24,29 @@ async function preview(options = {}) {
23
24
  const cliPreviewConfig = await resolveCliPreviewConfig(vikeConfig);
24
25
  assertUsage(cliPreviewConfig !== false, `${pc.cyan('$ vike preview')} isn't supported`);
25
26
  const isUDVitePreview = isUniversalDeployVitePreview(vikeConfig, viteConfigResolved);
26
- const useVitePreviewServer = cliPreviewConfig === 'vite' ||
27
- (cliPreviewConfig === undefined &&
28
- // dist/server/index.mjs exists when using @brillout/vite-plugin-server-entry inject mode; otherwise it's missing -> we must use Vite's preview server
29
- (!viteConfigResolved.vitePluginServerEntry?.inject ||
30
- // dist/server/index.mjs doesn't exist with some deployment plugins such as vite-plugin-vercel -> we must use Vite's preview server
31
- isUDVitePreview));
27
+ const useVitePreviewServer = (() => {
28
+ // === +cli.preview => manual overriding
29
+ if (cliPreviewConfig === 'vite')
30
+ return true;
31
+ if (cliPreviewConfig === true)
32
+ return false;
33
+ assert(cliPreviewConfig === undefined);
34
+ // === Universal Deploy
35
+ // dist/server/index.mjs doesn't exist with some deployment plugins such as vite-plugin-vercel -> we must use Vite's preview server
36
+ if (isUDVitePreview !== null)
37
+ return isUDVitePreview;
38
+ // === @brillout/vite-plugin-server-entry
39
+ // dist/server/index.mjs exists when using @brillout/vite-plugin-server-entry inject mode; otherwise it's missing -> we must use Vite's preview server
40
+ return !viteConfigResolved.vitePluginServerEntry?.inject;
41
+ })();
42
+ const { startupLogFirstLine, isStartupLogCompact } = getStartupLogFirstLine(viteConfigResolved, !useVitePreviewServer);
43
+ console.log(startupLogFirstLine);
32
44
  if (!useVitePreviewServer) {
33
45
  // Dynamically import() server production entry dist/server/index.js
34
46
  const outDir = getOutDirs(viteConfigResolved, undefined).outDirRoot;
35
47
  const { outServerIndex } = await importServerProductionIndex({ outDir });
36
48
  const outServerIndexRelative = path.relative(viteConfigResolved.root, outServerIndex);
37
- // TODO/after-PR-merge: always show a warning
38
- assertWarning(false, `Never run ${pc.cyan('$ vike preview')} in production, run ${pc.cyan(`$ node ${outServerIndexRelative}`)} instead (or Bun/Deno).`, { onlyOnce: true });
49
+ logHint(`, run ${pc.cyan(`$ node ${outServerIndexRelative}`)} instead (or Bun/Deno).`, isStartupLogCompact);
39
50
  return {
40
51
  viteConfig: viteConfigResolved,
41
52
  };
@@ -43,12 +54,22 @@ async function preview(options = {}) {
43
54
  else {
44
55
  // Use Vite's preview server
45
56
  const server = await previewVite(viteConfigFromUserResolved);
57
+ logHint(vikeConfig.prerenderContext.isPrerenderingEnabledForAllPages
58
+ ? ' — your app is fully pre-rendered and can be statically deployed.'
59
+ : '', isStartupLogCompact);
46
60
  return {
47
61
  viteServer: server,
48
62
  viteConfig: server.config,
49
63
  };
50
64
  }
51
65
  }
66
+ function logHint(hint = '', isStartupLogCompact) {
67
+ setTimeout(() => {
68
+ if (!isStartupLogCompact)
69
+ console.log();
70
+ assertInfo(false, `Don't use ${pc.cyan('$ vike preview')} for production${hint}`, { onlyOnce: true });
71
+ }, 0);
72
+ }
52
73
  async function resolveCliPreviewConfig(vikeConfig) {
53
74
  const val = vikeConfig.config.cli?.preview;
54
75
  if (!isCallable(val)) {
@@ -11,6 +11,7 @@ import crypto from 'node:crypto';
11
11
  import { getAssetsDir } from '../../shared/getAssetsDir.js';
12
12
  import { assertModuleId, getFilePathToShowToUserModule } from '../../shared/getFilePath.js';
13
13
  import '../../assertEnvVite.js';
14
+ import { isVersionMatch } from '../../../../utils/assertVersion.js';
14
15
  function pluginDistFileNames() {
15
16
  return [
16
17
  {
@@ -41,65 +42,8 @@ function pluginDistFileNames() {
41
42
  // - If rollupOutput.assetFileNames is a function then use a wrapper function to apply the assertUsage()
42
43
  assertUsage(rollupOutput.assetFileNames.isTheOneSetByVike, "Setting Vite's configuration build.rollupOptions.output.assetFileNames is currently forbidden. Reach out if you need to use it.");
43
44
  }
44
- {
45
- const manualChunksOriginal = rollupOutput.manualChunks;
46
- rollupOutput.manualChunks = function (id, ...args) {
47
- if (manualChunksOriginal) {
48
- if (isCallable(manualChunksOriginal)) {
49
- const result = manualChunksOriginal.call(this, id, ...args);
50
- if (result !== undefined)
51
- return result;
52
- }
53
- else {
54
- assertUsage(false, "The Vite's configuration build.rollupOptions.output.manualChunks must be a function. Reach out if you need to set it to another value.");
55
- }
56
- }
57
- // Disable CSS bundling to workaround https://github.com/vikejs/vike/issues/1815
58
- // TO-DO/eventually: let's bundle CSS again once Rolldown replaces Rollup
59
- if (id.endsWith('.css')) {
60
- const userRootDir = config.root;
61
- if (id.startsWith(userRootDir)) {
62
- assertPosixPath(id);
63
- assertModuleId(id);
64
- let name;
65
- const isNodeModules = id.match(/node_modules\/([^\/]+)\/(?!.*node_modules)/);
66
- if (isNodeModules) {
67
- name = isNodeModules[1];
68
- }
69
- else {
70
- const filePath = getFilePathToShowToUserModule(id, config);
71
- name = filePath;
72
- name = name.split('.').slice(0, -1).join('.'); // remove file extension
73
- name = name.split('/').filter(Boolean).join('_');
74
- }
75
- // Make fileHash the same between local development and CI
76
- const idStable = path.posix.relative(userRootDir, id);
77
- // Don't remove `?` queries because each `id` should belong to a unique bundle.
78
- const hash = getIdHash(idStable);
79
- return `${name}-${hash}`;
80
- }
81
- else {
82
- let name;
83
- const isVirtualModule = id.match(/virtual:([^:]+):/);
84
- if (isVirtualModule) {
85
- name = isVirtualModule[1];
86
- assert(name);
87
- }
88
- else if (
89
- // https://github.com/vikejs/vike/issues/1818#issuecomment-2298478321
90
- id.startsWith('/__uno')) {
91
- name = 'uno';
92
- }
93
- else {
94
- name = 'style';
95
- }
96
- const hash = getIdHash(id);
97
- return `${name}-${hash}`;
98
- }
99
- }
100
- };
101
- }
102
45
  });
46
+ disableCSSBundling(config);
103
47
  },
104
48
  },
105
49
  },
@@ -243,6 +187,115 @@ function workaroundGlob(name) {
243
187
  name = name.replace(/\.page$/, '-page');
244
188
  return name;
245
189
  }
190
+ // Workaround for Vite CSS duplication bug: https://github.com/vikejs/vike/issues/1815
191
+ function disableCSSBundling(config) {
192
+ if (isVite8OrAbove(config)) {
193
+ for (const output of getRolldownOutputs(config)) {
194
+ assert(output);
195
+ const { codeSplitting } = output;
196
+ // `codeSplitting: false` => single-bundle mode; respect the user's choice.
197
+ if (codeSplitting === false)
198
+ continue;
199
+ // `codeSplitting` set as an object => Rolldown ignores `manualChunks`, so inject a group into `codeSplitting.groups` instead.
200
+ if (codeSplitting && typeof codeSplitting === 'object') {
201
+ if (codeSplittingHasWorkaround.has(codeSplitting))
202
+ continue;
203
+ codeSplittingHasWorkaround.add(codeSplitting);
204
+ codeSplitting.groups ?? (codeSplitting.groups = []);
205
+ codeSplitting.groups.push({
206
+ test: /\.css$/,
207
+ name: (moduleId) => getCssChunkName(moduleId, config) ?? null,
208
+ /*
209
+ // Default priority — user-defined groups with the same priority appear earlier in the array and win the match.
210
+ // https://rolldown.rs/options/output-advanced-chunks
211
+ priority: 0
212
+ */
213
+ });
214
+ continue;
215
+ }
216
+ // `codeSplitting` unset / `true` => wrap `manualChunks` (Rolldown auto-converts it to a group).
217
+ // - Rolldown supports `manualChunks` whenever `codeSplitting` isn't an object (despite what the migration guide implies).
218
+ wrapManualChunks(output, config, 'rolldownOptions');
219
+ }
220
+ }
221
+ else {
222
+ for (const output of getRollupOutputs(config)) {
223
+ assert(output);
224
+ wrapManualChunks(output, config, 'rollupOptions');
225
+ }
226
+ }
227
+ }
228
+ const codeSplittingHasWorkaround = new WeakSet();
229
+ function wrapManualChunks(output, config, optsName) {
230
+ const manualChunksOriginal = output.manualChunks;
231
+ // Sometimes applied twice => skip if we already wrapped — same rationale as `isTheOneSetByVike` for assetFileNames above.
232
+ if (manualChunksOriginal?.isTheOneSetByVike)
233
+ return;
234
+ output.manualChunks = function (id, ...args) {
235
+ if (manualChunksOriginal) {
236
+ if (isCallable(manualChunksOriginal)) {
237
+ const result = manualChunksOriginal.call(this, id,
238
+ // @ts-ignore
239
+ ...args);
240
+ if (result !== undefined)
241
+ return result;
242
+ }
243
+ else {
244
+ assertUsage(false, `The Vite's configuration build.${optsName}.output.manualChunks must be a function. Reach out if you need to set it to another value.`);
245
+ }
246
+ }
247
+ return getCssChunkName(id, config);
248
+ };
249
+ output.manualChunks.isTheOneSetByVike = true;
250
+ }
251
+ function getCssChunkName(id, config) {
252
+ if (!id.endsWith('.css'))
253
+ return undefined;
254
+ const userRootDir = config.root;
255
+ if (id.startsWith(userRootDir)) {
256
+ assertPosixPath(id);
257
+ assertModuleId(id);
258
+ let name;
259
+ const isNodeModules = id.match(/node_modules\/([^\/]+)\/(?!.*node_modules)/);
260
+ if (isNodeModules) {
261
+ name = isNodeModules[1];
262
+ }
263
+ else {
264
+ const filePath = getFilePathToShowToUserModule(id, config);
265
+ name = filePath;
266
+ name = name.split('.').slice(0, -1).join('.'); // remove file extension
267
+ name = name.split('/').filter(Boolean).join('_');
268
+ }
269
+ // Make fileHash the same between local development and CI
270
+ const idStable = path.posix.relative(userRootDir, id);
271
+ // Don't remove `?` queries because each `id` should belong to a unique bundle.
272
+ const hash = getIdHash(idStable);
273
+ return `${name}-${hash}`;
274
+ }
275
+ else {
276
+ let name;
277
+ const isVirtualModule = id.match(/virtual:([^:]+):/);
278
+ if (isVirtualModule) {
279
+ name = isVirtualModule[1];
280
+ assert(name);
281
+ }
282
+ else if (
283
+ // https://github.com/vikejs/vike/issues/1818#issuecomment-2298478321
284
+ id.startsWith('/__uno')) {
285
+ name = 'uno';
286
+ }
287
+ else {
288
+ name = 'style';
289
+ }
290
+ const hash = getIdHash(id);
291
+ return `${name}-${hash}`;
292
+ }
293
+ }
294
+ function isVite8OrAbove(config) {
295
+ const viteVersion = config._viteVersionResolved;
296
+ assert(viteVersion);
297
+ return isVersionMatch(viteVersion, ['8.0.0']);
298
+ }
246
299
  function getRollupOutputs(config) {
247
300
  var _a, _b;
248
301
  // @ts-expect-error is read-only
@@ -255,3 +308,18 @@ function getRollupOutputs(config) {
255
308
  }
256
309
  return output;
257
310
  }
311
+ function getRolldownOutputs(config) {
312
+ var _a, _b;
313
+ // @ts-expect-error is read-only
314
+ config.build ?? (config.build = {});
315
+ // @ts-ignore
316
+ (_a = config.build).rolldownOptions ?? (_a.rolldownOptions = {});
317
+ // @ts-ignore
318
+ (_b = config.build.rolldownOptions).output ?? (_b.output = {});
319
+ // @ts-ignore
320
+ const { output } = config.build.rolldownOptions;
321
+ if (!isArray(output)) {
322
+ return [output];
323
+ }
324
+ return output;
325
+ }
@@ -1,5 +1,6 @@
1
1
  export { pluginModuleBanner };
2
2
  import { assert } from '../../../../utils/assert.js';
3
+ import { isVersionMatch } from '../../../../utils/assertVersion.js';
3
4
  import { removeVirtualFileIdPrefix } from '../../../../utils/virtualFileId.js';
4
5
  import { getMagicString } from '../../shared/getMagicString.js';
5
6
  import '../../assertEnvVite.js';
@@ -56,10 +57,18 @@ function pluginModuleBanner() {
56
57
  function checkIsEnabled(config) {
57
58
  const { minify } = config.build;
58
59
  assert(minify === false || minify, { minify });
59
- const isEnabled = !minify;
60
+ const isEnabled = !minify && !hasNativeModuleRegions(config);
60
61
  // Avoid the legal comments inserted in the transform() hook to be removed.
61
62
  // https://github.com/vitejs/vite/issues/21085#issuecomment-3502781005
62
63
  if (isEnabled && config.esbuild)
63
64
  config.esbuild.legalComments = 'inline';
64
65
  return isEnabled;
65
66
  }
67
+ // Vite 8 / Rolldown already emits native `//#region /path/...` markers for non-minified builds.
68
+ // - https://github.com/vitejs/vite/issues/21228#issuecomment-3627899741
69
+ // - TO-DO/eventually: remove this file once Vike requires Vite 8 or above
70
+ function hasNativeModuleRegions(config) {
71
+ const viteVersion = config._viteVersionResolved;
72
+ assert(viteVersion);
73
+ return isVersionMatch(viteVersion, ['8.0.0']);
74
+ }
@@ -8,4 +8,4 @@ declare function getServerConfig(vikeConfig: VikeConfigInternal): {
8
8
  serverEntryVike: string;
9
9
  serverFilePath: string | null;
10
10
  } | undefined;
11
- declare function isUniversalDeployVitePreview(vikeConfig: VikeConfigInternal, viteConfigResolved: ResolvedConfig): boolean;
11
+ declare function isUniversalDeployVitePreview(vikeConfig: VikeConfigInternal, viteConfigResolved: ResolvedConfig): boolean | null;
@@ -41,9 +41,9 @@ function getServerConfig(vikeConfig) {
41
41
  function isUniversalDeployVitePreview(vikeConfig, viteConfigResolved) {
42
42
  const isServerConfig = getServerConfig(vikeConfig);
43
43
  if (!isServerConfig)
44
- return false;
44
+ return null; // not UD
45
45
  // @universal-deploy/node -> real preview
46
46
  // else -> vite preview
47
- const udNodePlugin = viteConfigResolved.plugins.find((p) => p.name.startsWith('ud:node:emit'));
47
+ const udNodePlugin = viteConfigResolved.plugins.find((p) => p.name.match(/^ud:node:(?!.*:disabled$)/));
48
48
  return !udNodePlugin;
49
49
  }
@@ -7,7 +7,7 @@ export { swallowViteLogConnected_clean };
7
7
  import type { ResolvedConfig } from 'vite';
8
8
  import '../assertEnvVite.js';
9
9
  declare function interceptViteLogs(config: ResolvedConfig): void;
10
- declare function processStartupLog(firstLine: string, config: ResolvedConfig): {
10
+ declare function processStartupLog(firstLine: string, config: ResolvedConfig, veryCompact?: boolean): {
11
11
  firstLine: string;
12
12
  isCompact: boolean;
13
13
  };
@@ -65,7 +65,7 @@ function intercept(loggerType, config) {
65
65
  }
66
66
  // - Clears screen if zero previous log
67
67
  // - Manages new lines
68
- function processStartupLog(firstLine, config) {
68
+ function processStartupLog(firstLine, config, veryCompact) {
69
69
  const shouldClear = processStartupLog_shouldClear(config);
70
70
  if (shouldClear) {
71
71
  config.logger.clearScreen('info');
@@ -74,7 +74,7 @@ function processStartupLog(firstLine, config) {
74
74
  // Remove leading new line (for both Vite and Vike's startup log)
75
75
  firstLine = removeEmptyLines(firstLine);
76
76
  }
77
- return { firstLine, isCompact: !shouldClear };
77
+ return { firstLine, isCompact: veryCompact || !shouldClear };
78
78
  }
79
79
  function processStartupLog_shouldClear(config) {
80
80
  const hasLoggedBefore = process.stdout.bytesWritten !== 0 || process.stderr.bytesWritten !== 0;
@@ -1,6 +1,6 @@
1
1
  export { getPlusFilesByLocationId };
2
2
  import { assert } from '../../../../utils/assert.js';
3
- import { configDefinitionsBuiltIn } from './configDefinitionsBuiltIn.js';
3
+ import { metaBuiltIn } from './metaBuiltIn.js';
4
4
  import { getLocationId } from './filesystemRouting.js';
5
5
  import { crawlPlusFilePaths, getPlusFileValueConfigName } from './crawlPlusFilePaths.js';
6
6
  import { getConfigFileExport } from './getConfigFileExport.js';
@@ -64,7 +64,7 @@ async function getPlusFilesByLocationId(userRootDir, esbuildCache) {
64
64
  // We don't have access to the custom config definitions defined by the user yet.
65
65
  // - If `configDef` is `undefined` => we load the file +{configName}.js later.
66
66
  // - We already need to load +meta.js here (to get the custom config definitions defined by the user)
67
- await loadValueFile(plusFile, configDefinitionsBuiltIn, userRootDir, esbuildCache);
67
+ await loadValueFile(plusFile, metaBuiltIn, userRootDir, esbuildCache);
68
68
  }
69
69
  }));
70
70
  // Make lists element order deterministic
@@ -7,7 +7,7 @@ import type { FilePathResolved } from '../../../../types/FilePath.js';
7
7
  import { type EsbuildCache } from './transpileAndExecuteFile.js';
8
8
  import type { PlusFileValue } from './getPlusFilesByLocationId.js';
9
9
  import { PointerImport } from './resolvePointerImport.js';
10
- import type { ConfigDefinitionsInternal } from './configDefinitionsBuiltIn.js';
10
+ import type { ConfigDefinitionsInternal } from './metaBuiltIn.js';
11
11
  import '../../assertEnvVite.js';
12
12
  type ConfigFile = {
13
13
  fileExports: Record<string, unknown>;
@@ -1,4 +1,4 @@
1
- export { configDefinitionsBuiltIn };
1
+ export { metaBuiltIn };
2
2
  export type { ConfigDefinition };
3
3
  export type { ConfigDefinitions };
4
4
  export type { ConfigDefinitionsInternal };
@@ -93,4 +93,4 @@ ConfigDefinition>;
93
93
  type ConfigDefinitionsInternal = Record<string, // configName
94
94
  ConfigDefinitionInternal>;
95
95
  type ConfigDefinitionsBuiltIn = Record<ConfigNameBuiltIn | ConfigNameGlobal, ConfigDefinitionInternal>;
96
- declare const configDefinitionsBuiltIn: ConfigDefinitionsBuiltIn;
96
+ declare const metaBuiltIn: ConfigDefinitionsBuiltIn;
@@ -1,11 +1,10 @@
1
- export { configDefinitionsBuiltIn };
1
+ export { metaBuiltIn };
2
2
  import { assert, assertUsage } from '../../../../utils/assert.js';
3
3
  import { getConfigDefinedAt, } from '../../../../shared-server-client/page-configs/getConfigDefinedAt.js';
4
4
  import { getConfigValueSourceRelevantAnyEnv, getConfigValueSourcesRelevant, isConfigSourceValueNull, } from '../../plugins/pluginVirtualFiles/getConfigValueSourcesRelevant.js';
5
5
  import { getFileSuffixes } from '../../../../shared-server-node/getFileSuffixes.js';
6
6
  import '../../assertEnvVite.js';
7
- // TODO/after-PR-merge: rename_full configDefinitionsBuiltIn metaBuiltIn
8
- const configDefinitionsBuiltIn = {
7
+ const metaBuiltIn = {
9
8
  onRenderHtml: {
10
9
  env: { server: true },
11
10
  },
@@ -17,10 +17,13 @@ declare function transformPointerImports(code: string, filePathToShowToUser2: st
17
17
  * We discard the import name `someImport` because we don't need it.
18
18
  */
19
19
  type PointerImportData = {
20
+ importStringWasGenerated: boolean;
21
+ /** For example: `import:./some-file:someExport` */
22
+ importString: string;
23
+ /** For example: `./some-file` */
20
24
  importPath: string;
25
+ /** For example: `someExport` */
21
26
  exportName: string;
22
- importString: string;
23
- importStringWasGenerated: boolean;
24
27
  };
25
28
  declare function parsePointerImportData(importString: string): null | PointerImportData;
26
29
  declare function assertPointerImportPath(importPath: string): boolean;
@@ -78,7 +78,15 @@ function resolveImportPathWithNode(pointerImportData, importerFilePath, userRoot
78
78
  userRootDir,
79
79
  });
80
80
  if (!filePathAbsoluteFilesystem) {
81
- assert(!isImportPathRelative(pointerImportData.importPath));
81
+ if (isImportPathRelative(pointerImportData.importPath)) {
82
+ const { importPath, importStringWasGenerated, importString } = pointerImportData;
83
+ const { filePathToShowToUserResolved } = importerFilePath;
84
+ assert(filePathToShowToUserResolved);
85
+ const errIntro = importStringWasGenerated
86
+ ? `The import path ${pc.cyan(importPath)} in ${filePathToShowToUserResolved}`
87
+ : `The import ${pc.cyan(importString)} defined by ${filePathToShowToUserResolved}`;
88
+ assertUsage(false, `${errIntro} couldn't be resolved: does ${pc.cyan(importPath)} point to an existing file?`);
89
+ }
82
90
  /* This assertion fails if the npm package has a wrongly defined package.json#exports
83
91
  // Libraries don't use path aliases => filePathAbsoluteFilesystem should be defined
84
92
  assert(!importerFilePathAbsolute.includes('node_modules'))
@@ -12,7 +12,7 @@ export { getVikeConfigFromCliOrEnv };
12
12
  export type { VikeConfigInternal };
13
13
  export type { PageConfigBuildTimeBeforeComputed };
14
14
  import type { PageConfigGlobalBuildTime, PageConfigBuildTime } from '../../../types/PageConfig.js';
15
- import { type ConfigDefinitionsInternal, type ConfigDefinitionInternal } from './resolveVikeConfigInternal/configDefinitionsBuiltIn.js';
15
+ import { type ConfigDefinitionsInternal, type ConfigDefinitionInternal } from './resolveVikeConfigInternal/metaBuiltIn.js';
16
16
  import { type GlobalConfigPublic } from '../../../shared-server-client/page-configs/resolveVikeConfigPublic.js';
17
17
  import { type PlusFile } from './resolveVikeConfigInternal/getPlusFilesByLocationId.js';
18
18
  import type { PrerenderContextPublic } from '../../prerender/runPrerender.js';
@@ -31,7 +31,7 @@ import { objectAssign } from '../../../utils/objectAssign.js';
31
31
  import { makeFirst, lowerFirst } from '../../../utils/sorter.js';
32
32
  import { unique } from '../../../utils/unique.js';
33
33
  import { assertPosixPath } from '../../../utils/path.js';
34
- import { configDefinitionsBuiltIn, } from './resolveVikeConfigInternal/configDefinitionsBuiltIn.js';
34
+ import { metaBuiltIn, } from './resolveVikeConfigInternal/metaBuiltIn.js';
35
35
  import { getFileSuffixes } from '../../../shared-server-node/getFileSuffixes.js';
36
36
  import { getLocationId, getFilesystemRouteString, getFilesystemRouteDefinedBy, isInherited, sortAfterInheritanceOrder, applyFilesystemRoutingRootEffect, } from './resolveVikeConfigInternal/filesystemRouting.js';
37
37
  import { getViteDevServer, vikeConfigErrorRecoverMsg } from '../../../server/runtime/globalContext.js';
@@ -504,8 +504,8 @@ function getVikeConfigFromCliOrEnv() {
504
504
  };
505
505
  }
506
506
  function getSourceNonConfigFile(configName, value, definedAt) {
507
- assert(includes(objectKeys(configDefinitionsBuiltIn), configName));
508
- const configDef = configDefinitionsBuiltIn[configName];
507
+ assert(includes(objectKeys(metaBuiltIn), configName));
508
+ const configDef = metaBuiltIn[configName];
509
509
  const source = {
510
510
  valueIsLoaded: true,
511
511
  value,
@@ -773,7 +773,7 @@ function getConfigNamesSetByPlusFile(plusFile) {
773
773
  }
774
774
  }
775
775
  function getConfigDefinitions(plusFilesRelevant, filter) {
776
- let configDefinitions = { ...configDefinitionsBuiltIn };
776
+ let configDefinitions = { ...metaBuiltIn };
777
777
  // Add user-land meta configs
778
778
  plusFilesRelevant
779
779
  .slice()
@@ -18,6 +18,7 @@ import { stringify } from '@brillout/json-serializer/stringify';
18
18
  import '../../assertEnvServer.js';
19
19
  const contentTypeJson = 'application/json';
20
20
  const contentTypeHtml = 'text/html;charset=utf-8';
21
+ const htmlFallbackLog = 'This HTML was generated by Vike.';
21
22
  async function createHttpResponsePage(htmlRender, renderHook, pageContext) {
22
23
  let statusCode = pageContext.abortStatusCode;
23
24
  if (!statusCode) {
@@ -39,7 +40,7 @@ async function createHttpResponsePage(htmlRender, renderHook, pageContext) {
39
40
  return createHttpResponse(statusCode, contentTypeHtml, headers, htmlRender, earlyHints, renderHook);
40
41
  }
41
42
  function createHttpResponse404(errMsg404) {
42
- const httpResponse = createHttpResponse(404, contentTypeHtml, [], `<p>${errMsg404}.</p><script>console.log('This HTML was generated by Vike.')</script>`);
43
+ const httpResponse = createHttpResponse(404, contentTypeHtml, [], getHtmlFallback(`<p>${errMsg404}.</p>`));
43
44
  return httpResponse;
44
45
  }
45
46
  function createHttpResponseBaseIsMissing(urlOriginal, baseServer) {
@@ -81,7 +82,7 @@ function createHttpResponseErrorFallback_noGlobalContext() {
81
82
  return createHttpResponseError_('no error page (https://vike.dev/error-page) could be rendered');
82
83
  }
83
84
  function createHttpResponseError_(reason) {
84
- const httpResponse = createHttpResponse(500, contentTypeHtml, [], `<p>An error occurred.</p><script>console.log(${JSON.stringify(`This HTML was generated by Vike. Vike returned this HTML because ${reason}.`)})</script>`);
85
+ const httpResponse = createHttpResponse(500, contentTypeHtml, [], getHtmlFallback('<p>An error occurred.</p>', `${htmlFallbackLog} Vike returned this HTML because ${reason}.`));
85
86
  return httpResponse;
86
87
  }
87
88
  function createHttpResponseErrorFallbackJson() {
@@ -101,15 +102,16 @@ function createHttpResponseRedirect({ url, statusCode }, pageContextInit) {
101
102
  return createHttpResponse(statusCode, contentTypeHtml, headers,
102
103
  // For bots / programmatic crawlig: show what's going on.
103
104
  // For users: showing a blank page is probably better than a flickering text.
104
- `<p style="display: none">Redirecting to ${escapeHtml(url)}</p><script>console.log('This HTML was generated by Vike.')</script>`);
105
+ getHtmlFallback(`<p style="display: none">Redirecting to ${escapeHtml(url)}</p>`));
105
106
  }
106
107
  function createHttpResponseFromUniversalMiddleware(response, earlyHints) {
107
- // @brillout TODO/after-PR-merge: dedupe such HTML responses generated by Vike
108
- const body = response.body ??
109
- `<p style="display: none">No HTTP response body.</p><script>console.log('This HTML was generated by Vike.')</script>`;
108
+ const body = response.body ?? getHtmlFallback('<p style="display: none">No HTTP response body.</p>');
110
109
  const httpResponse = createHttpResponseCommon(response.status, Array.from(response.headers.entries()), body, earlyHints);
111
110
  return httpResponse;
112
111
  }
112
+ function getHtmlFallback(bodyHtml, logText = htmlFallbackLog) {
113
+ return `${bodyHtml}<script>console.log(${JSON.stringify(logText)})</script>`;
114
+ }
113
115
  function createHttpResponse(statusCode, contentType, headers, htmlRender, earlyHints, renderHook) {
114
116
  headers.push(['Content-Type', contentType]);
115
117
  assert(renderHook || typeof htmlRender === 'string');
@@ -21,10 +21,13 @@ async function loadAndParseVirtualFilePageEntry(pageConfig, isDev) {
21
21
  configValues = parseVirtualFileExportsPageEntry(virtualFileExportsPageEntry);
22
22
  }
23
23
  catch (e) {
24
- if (!(e instanceof ReferenceError))
24
+ // Safari WebKit bug: dynamic import() may resolve before the module body executes.
25
+ if (
26
+ // Throwing ReferenceError (TDZ): https://github.com/vikejs/vike/issues/3121
27
+ !(e instanceof ReferenceError) &&
28
+ // Or TypeError (undefined exports) on some WebKit builds: https://github.com/vikejs/vike/issues/3199
29
+ !(e instanceof TypeError))
25
30
  throw e;
26
- // Safari WebKit bug: dynamic import() may resolve before the module body executes,
27
- // https://github.com/vikejs/vike/issues/3121
28
31
  await new Promise((resolve) => setTimeout(resolve));
29
32
  configValues = parseVirtualFileExportsPageEntry(virtualFileExportsPageEntry);
30
33
  }
@@ -36,7 +36,7 @@ export type { OnRenderHtmlSync };
36
36
  export type { RouteAsync };
37
37
  export type { RouteSync };
38
38
  import type { PrefetchSetting, PrefetchStaticAssets } from '../client/runtime-client-routing/prefetch/PrefetchSetting.js';
39
- import type { ConfigDefinition } from '../node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js';
39
+ import type { ConfigDefinition } from '../node/vite/shared/resolveVikeConfigInternal/metaBuiltIn.js';
40
40
  import type { DocumentHtml } from '../server/runtime/renderPageServer/html/renderHtml.js';
41
41
  import type { InjectFilterEntry } from './index.js';
42
42
  import type { VikeVitePluginOptions } from '../node/vite/index.js';
@@ -15,11 +15,11 @@ type FilePathResolved = FilePathCommon & {
15
15
  */
16
16
  filePathAbsoluteFilesystem: string;
17
17
  /**
18
- * The file's path, shown to the user in logs.
18
+ * The file path shown to the user in logs.
19
19
  *
20
- * Resolved: it always shows a file path. (It never shows an import path such as `vike-react/config`.)
20
+ * Its value is: `filePath.filePathAbsoluteUserRootDir ?? filePath.filePathAbsoluteFilesystem`.
21
21
  *
22
- * Its value is equivalent to `filePath.filePathAbsoluteUserRootDir ?? filePath.filePathAbsoluteFilesystem`.
22
+ * Note that it always shows a file path. (It never shows an import path such as `vike-react/config`.)
23
23
  */
24
24
  filePathToShowToUserResolved: string;
25
25
  /**
@@ -52,11 +52,11 @@ type FilePathAbsoluteUserRootDir = {
52
52
  };
53
53
  type FilePathCommon = {
54
54
  /**
55
- * The file's path, shown to the user in logs.
55
+ * The file or import path shown to the user in logs.
56
56
  *
57
- * Unresolved: it may show an import path instead of a file path such as `vike-react/config`.
57
+ * Its value is: `filePath.filePathAbsoluteUserRootDir ?? filePath.importPathAbsolute`.
58
58
  *
59
- * Its value is equivalent to `filePath.filePathAbsoluteUserRootDir ?? filePath.importPathAbsolute`.
59
+ * Note that if `filePath.filePathAbsoluteUserRootDir` isn't defined then it shows the import path (e.g. `vike-react/config`) instead of a file path.
60
60
  */
61
61
  filePathToShowToUser: string;
62
62
  /**
@@ -24,7 +24,7 @@ export type { VirtualFileExportsPageEntry };
24
24
  import type { ConfigValueSerialized } from '../shared-server-client/page-configs/serialize/PageConfigSerialized.js';
25
25
  import type { LocationId } from '../node/vite/shared/resolveVikeConfigInternal/filesystemRouting.js';
26
26
  import type { FilePath } from './FilePath.js';
27
- import type { ConfigDefinitionsInternal } from '../node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js';
27
+ import type { ConfigDefinitionsInternal } from '../node/vite/shared/resolveVikeConfigInternal/metaBuiltIn.js';
28
28
  import type { PlusFile } from '../node/vite/shared/resolveVikeConfigInternal/getPlusFilesByLocationId.js';
29
29
  import type { ApiOperation } from '../node/api/types.js';
30
30
  type PageConfigCommon = {
@@ -9,7 +9,7 @@ export type { ImportString } from '../node/vite/shared/importString.js';
9
9
  export type { 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 './Config.js';
10
10
  export type { ConfigResolved } from './Config/ConfigResolved.js';
11
11
  export type { ConfigEnv } from './PageConfig.js';
12
- export type { ConfigDefinition, ConfigEffect, } from '../node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js';
12
+ export type { ConfigDefinition, ConfigEffect, } from '../node/vite/shared/resolveVikeConfigInternal/metaBuiltIn.js';
13
13
  export type { ConfigEntries } from '../shared-server-client/page-configs/resolveVikeConfigPublic.js';
14
14
  export type { VikeConfig } from '../node/vite/shared/resolveVikeConfigInternal.js';
15
15
  export type { UrlPublic as Url } from '../utils/parseUrl.js';
@@ -24,7 +24,7 @@ import type { ConfigEnv } from './PageConfig.js';
24
24
  */
25
25
  type Env = ConfigEnv;
26
26
  export type { Env };
27
- import type { ConfigEffect } from '../node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js';
27
+ import type { ConfigEffect } from '../node/vite/shared/resolveVikeConfigInternal/metaBuiltIn.js';
28
28
  /** @deprecated Replace:
29
29
  * `import type { Effect } from 'vike/types'`
30
30
  * With:
@@ -1 +1 @@
1
- export declare const PROJECT_VERSION: "0.4.257";
1
+ export declare const PROJECT_VERSION: "0.4.258-commit-24a5c2b";
@@ -1,2 +1,2 @@
1
1
  // Automatically updated by @brillout/release-me
2
- export const PROJECT_VERSION = '0.4.257';
2
+ export const PROJECT_VERSION = '0.4.258-commit-24a5c2b';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.257",
3
+ "version": "0.4.258-commit-24a5c2b",
4
4
  "repository": "https://github.com/vikejs/vike",
5
5
  "exports": {
6
6
  "./server": {
@@ -129,11 +129,11 @@
129
129
  "@babel/core": "^7.28.5",
130
130
  "@babel/types": "^7.28.5",
131
131
  "@brillout/import": "^0.2.6",
132
- "@brillout/json-serializer": "^0.5.22",
132
+ "@brillout/json-serializer": "^0.5.23",
133
133
  "@brillout/picocolors": "^1.0.30",
134
134
  "@brillout/vite-plugin-server-entry": "0.7.18",
135
135
  "@universal-deploy/store": "^0.2.1",
136
- "@universal-deploy/vite": "^0.1.6",
136
+ "@universal-deploy/vite": "^0.1.7",
137
137
  "@universal-middleware/core": "^0.4.17",
138
138
  "@universal-middleware/node": "^0.1.0",
139
139
  "cac": "^6.0.0",
@@ -262,7 +262,7 @@
262
262
  "./fetch.js"
263
263
  ],
264
264
  "devDependencies": {
265
- "@brillout/release-me": "^0.4.13",
265
+ "@brillout/release-me": "^0.4.15",
266
266
  "@types/babel__core": "^7.20.5",
267
267
  "@types/estree": "^1.0.5",
268
268
  "@types/node": "^20.10.5",
@@ -271,6 +271,7 @@
271
271
  "@types/source-map-support": "^0.5.10",
272
272
  "react-streaming": "^0.4.17",
273
273
  "rimraf": "^6.1.3",
274
+ "rolldown": "1.0.0-rc.17",
274
275
  "typescript": "^5.9.3",
275
276
  "vite": "^7.2.6"
276
277
  },