vike 0.4.238-commit-d48a597 → 0.4.239-commit-050a4a3

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 (60) hide show
  1. package/dist/cjs/node/runtime/globalContext.js +1 -0
  2. package/dist/cjs/node/vite/onLoad.js +1 -1
  3. package/dist/cjs/node/vite/plugins/pluginBaseUrls.js +32 -28
  4. package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildApp.js +24 -20
  5. package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildConfig.js +4 -2
  6. package/dist/cjs/node/vite/plugins/pluginBuild/pluginDistFileNames.js +76 -74
  7. package/dist/cjs/node/vite/plugins/pluginBuild/pluginDistPackageJsonFile.js +18 -14
  8. package/dist/cjs/node/vite/plugins/pluginBuild/pluginModuleBanner.js +4 -2
  9. package/dist/cjs/node/vite/plugins/pluginBuild/pluginProdBuildEntry.js +4 -2
  10. package/dist/cjs/node/vite/plugins/pluginBuild/pluginSuppressRollupWarning.js +20 -18
  11. package/dist/cjs/node/vite/plugins/pluginCommon.js +7 -21
  12. package/dist/cjs/node/vite/plugins/pluginDev.js +51 -47
  13. package/dist/cjs/node/vite/plugins/pluginEnvVars.js +63 -57
  14. package/dist/cjs/node/vite/plugins/pluginExtractAssets.js +101 -91
  15. package/dist/cjs/node/vite/plugins/pluginExtractExportNames.js +24 -16
  16. package/dist/cjs/node/vite/plugins/pluginFileEnv.js +67 -57
  17. package/dist/cjs/node/vite/plugins/pluginNonRunnableDev.js +26 -20
  18. package/dist/cjs/node/vite/plugins/pluginPreview.js +30 -24
  19. package/dist/cjs/node/vite/plugins/pluginReplaceConstants.js +41 -33
  20. package/dist/cjs/node/vite/plugins/pluginSetGlobalContext.js +4 -2
  21. package/dist/cjs/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntryWithOldDesign.js +1 -1
  22. package/dist/cjs/node/vite/plugins/pluginVirtualFiles.js +50 -37
  23. package/dist/cjs/node/vite/plugins/pluginWorkaroundCssModuleHmr.js +8 -6
  24. package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/crawlPlusFiles.js +1 -1
  25. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  26. package/dist/cjs/utils/assertNodeVersion.js +3 -1
  27. package/dist/cjs/utils/assertVersion.js +26 -5
  28. package/dist/cjs/utils/joinEnglish.js +2 -1
  29. package/dist/esm/node/runtime/globalContext.d.ts +2 -0
  30. package/dist/esm/node/runtime/globalContext.js +1 -0
  31. package/dist/esm/node/vite/onLoad.js +1 -1
  32. package/dist/esm/node/vite/plugins/pluginBaseUrls.js +32 -28
  33. package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildApp.js +24 -20
  34. package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildConfig.js +4 -2
  35. package/dist/esm/node/vite/plugins/pluginBuild/pluginDistFileNames.js +76 -74
  36. package/dist/esm/node/vite/plugins/pluginBuild/pluginDistPackageJsonFile.js +18 -14
  37. package/dist/esm/node/vite/plugins/pluginBuild/pluginModuleBanner.js +4 -2
  38. package/dist/esm/node/vite/plugins/pluginBuild/pluginProdBuildEntry.js +4 -2
  39. package/dist/esm/node/vite/plugins/pluginBuild/pluginSuppressRollupWarning.js +20 -18
  40. package/dist/esm/node/vite/plugins/pluginCommon.js +8 -22
  41. package/dist/esm/node/vite/plugins/pluginDev.js +51 -47
  42. package/dist/esm/node/vite/plugins/pluginEnvVars.js +63 -57
  43. package/dist/esm/node/vite/plugins/pluginExtractAssets.js +101 -91
  44. package/dist/esm/node/vite/plugins/pluginExtractExportNames.js +24 -16
  45. package/dist/esm/node/vite/plugins/pluginFileEnv.js +67 -57
  46. package/dist/esm/node/vite/plugins/pluginNonRunnableDev.js +26 -20
  47. package/dist/esm/node/vite/plugins/pluginPreview.js +30 -24
  48. package/dist/esm/node/vite/plugins/pluginReplaceConstants.js +41 -33
  49. package/dist/esm/node/vite/plugins/pluginSetGlobalContext.js +4 -2
  50. package/dist/esm/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntryWithOldDesign.js +2 -2
  51. package/dist/esm/node/vite/plugins/pluginVirtualFiles.js +51 -38
  52. package/dist/esm/node/vite/plugins/pluginWorkaroundCssModuleHmr.js +8 -6
  53. package/dist/esm/node/vite/shared/resolveVikeConfigInternal/crawlPlusFiles.js +2 -2
  54. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  55. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  56. package/dist/esm/utils/assertNodeVersion.js +3 -1
  57. package/dist/esm/utils/assertVersion.d.ts +4 -3
  58. package/dist/esm/utils/assertVersion.js +23 -5
  59. package/dist/esm/utils/joinEnglish.js +2 -1
  60. package/package.json +2 -2
@@ -18,68 +18,78 @@ function pluginFileEnv() {
18
18
  let viteDevServer;
19
19
  return {
20
20
  name: 'vike:pluginFileEnv',
21
- load(id, options) {
22
- // In build, we use generateBundle() instead of the load() hook. Using load() works for dynamic imports in dev thanks to Vite's lazy transpiling, but it doesn't work in build because Rollup transpiles any dynamically imported module even if it's never actually imported.
23
- if (!viteDevServer)
24
- return;
25
- if (!(0, resolveVikeConfigInternal_js_1.isV1Design)())
26
- return;
27
- if (skip(id))
28
- return;
29
- // For `.vue` files: https://github.com/vikejs/vike/issues/1912#issuecomment-2394981475
30
- if (id.endsWith('?direct'))
31
- id = id.slice(0, -1 * '?direct'.length);
32
- const moduleInfo = viteDevServer.moduleGraph.getModuleById(id);
33
- (0, utils_js_1.assert)(moduleInfo);
34
- const importers = Array.from(moduleInfo.importers)
35
- .map((m) => m.id)
36
- .filter((id) => id !== null);
37
- assertFileEnv(id, (0, isViteServerSide_js_1.isViteServerSide_extraSafe)(config, this.environment, options), importers,
38
- // In dev, we only show a warning because we don't want to disrupt when the user plays with settings such as [ssr](https://vike.dev/ssr).
39
- true);
21
+ load: {
22
+ handler(id, options) {
23
+ // In build, we use generateBundle() instead of the load() hook. Using load() works for dynamic imports in dev thanks to Vite's lazy transpiling, but it doesn't work in build because Rollup transpiles any dynamically imported module even if it's never actually imported.
24
+ if (!viteDevServer)
25
+ return;
26
+ if (!(0, resolveVikeConfigInternal_js_1.isV1Design)())
27
+ return;
28
+ if (skip(id))
29
+ return;
30
+ // For `.vue` files: https://github.com/vikejs/vike/issues/1912#issuecomment-2394981475
31
+ if (id.endsWith('?direct'))
32
+ id = id.slice(0, -1 * '?direct'.length);
33
+ const moduleInfo = viteDevServer.moduleGraph.getModuleById(id);
34
+ (0, utils_js_1.assert)(moduleInfo);
35
+ const importers = Array.from(moduleInfo.importers)
36
+ .map((m) => m.id)
37
+ .filter((id) => id !== null);
38
+ assertFileEnv(id, (0, isViteServerSide_js_1.isViteServerSide_extraSafe)(config, this.environment, options), importers,
39
+ // In dev, we only show a warning because we don't want to disrupt when the user plays with settings such as [ssr](https://vike.dev/ssr).
40
+ true);
41
+ },
40
42
  },
41
43
  // In production, we have to use transform() to replace modules with a runtime error because generateBundle() doesn't work for dynamic imports. In production, dynamic imports can only be verified at runtime.
42
- async transform(code, id, options) {
43
- id = (0, normalizeId_js_1.normalizeId)(id);
44
- // In dev, only using load() is enough as it also works for dynamic imports (see sibling comment).
45
- if (viteDevServer)
46
- return;
47
- if (skip(id))
48
- return;
49
- const isServerSide = (0, isViteServerSide_js_1.isViteServerSide_extraSafe)(config, this.environment, options);
50
- if (!isWrongEnv(id, isServerSide))
51
- return;
52
- const { importers } = this.getModuleInfo(id);
53
- // Throwing a verbose error doesn't waste client-side KBs as dynamic imports are code split.
54
- const errMsg = getErrorMessage(id, isServerSide, importers, false, true);
55
- // We have to inject empty exports to avoid Rollup complaining about missing exports, see https://gist.github.com/brillout/5ea45776e65bd65100a52ecd7bfda3ff
56
- const { exportNames } = await (0, parseEsModule_js_1.getExportNames)(code);
57
- return (0, utils_js_1.rollupSourceMapRemove)([
58
- `throw new Error(${JSON.stringify(errMsg)});`,
59
- ...exportNames.map((name) => name === 'default' ? 'export default undefined;' : `export const ${name} = undefined;`),
60
- ].join('\n'));
61
- },
62
- generateBundle() {
63
- Array.from(this.getModuleIds())
64
- .filter((id) => !skip(id))
65
- .forEach((moduleId) => {
66
- const mod = this.getModuleInfo(moduleId);
67
- const { importers } = mod;
68
- if (importers.length === 0) {
69
- // Dynamic imports can only be verified at runtime
70
- /* This assertion can fail: https://github.com/vikejs/vike/issues/2227
71
- assert(dynamicImporters.length > 0)
72
- */
44
+ transform: {
45
+ async handler(code, id, options) {
46
+ id = (0, normalizeId_js_1.normalizeId)(id);
47
+ // In dev, only using load() is enough as it also works for dynamic imports (see sibling comment).
48
+ if (viteDevServer)
73
49
  return;
74
- }
75
- assertFileEnv(moduleId, (0, isViteServerSide_js_1.isViteServerSide)(config, this.environment), importers, false);
76
- });
50
+ if (skip(id))
51
+ return;
52
+ const isServerSide = (0, isViteServerSide_js_1.isViteServerSide_extraSafe)(config, this.environment, options);
53
+ if (!isWrongEnv(id, isServerSide))
54
+ return;
55
+ const { importers } = this.getModuleInfo(id);
56
+ // Throwing a verbose error doesn't waste client-side KBs as dynamic imports are code split.
57
+ const errMsg = getErrorMessage(id, isServerSide, importers, false, true);
58
+ // We have to inject empty exports to avoid Rollup complaining about missing exports, see https://gist.github.com/brillout/5ea45776e65bd65100a52ecd7bfda3ff
59
+ const { exportNames } = await (0, parseEsModule_js_1.getExportNames)(code);
60
+ return (0, utils_js_1.rollupSourceMapRemove)([
61
+ `throw new Error(${JSON.stringify(errMsg)});`,
62
+ ...exportNames.map((name) => name === 'default' ? 'export default undefined;' : `export const ${name} = undefined;`),
63
+ ].join('\n'));
64
+ },
65
+ },
66
+ generateBundle: {
67
+ handler() {
68
+ Array.from(this.getModuleIds())
69
+ .filter((id) => !skip(id))
70
+ .forEach((moduleId) => {
71
+ const mod = this.getModuleInfo(moduleId);
72
+ const { importers } = mod;
73
+ if (importers.length === 0) {
74
+ // Dynamic imports can only be verified at runtime
75
+ /* This assertion can fail: https://github.com/vikejs/vike/issues/2227
76
+ assert(dynamicImporters.length > 0)
77
+ */
78
+ return;
79
+ }
80
+ assertFileEnv(moduleId, (0, isViteServerSide_js_1.isViteServerSide)(config, this.environment), importers, false);
81
+ });
82
+ },
77
83
  },
78
- configResolved(config_) {
79
- config = config_;
84
+ configResolved: {
85
+ handler(config_) {
86
+ config = config_;
87
+ },
80
88
  },
81
- configureServer(viteDevServer_) {
82
- viteDevServer = viteDevServer_;
89
+ configureServer: {
90
+ handler(viteDevServer_) {
91
+ viteDevServer = viteDevServer_;
92
+ },
83
93
  },
84
94
  };
85
95
  function assertFileEnv(moduleId, isServerSide, importers, onlyWarn) {
@@ -25,28 +25,34 @@ function pluginNonRunnableDev() {
25
25
  let config;
26
26
  return {
27
27
  name: 'vike:pluginNonRunnableDev',
28
- configureServer(viteDevServer) {
29
- (0, utils_js_1.createViteRPC)(viteDevServer, getViteRpcFunctions);
28
+ configureServer: {
29
+ handler(viteDevServer) {
30
+ (0, utils_js_1.createViteRPC)(viteDevServer, getViteRpcFunctions);
31
+ },
30
32
  },
31
- configResolved(config_) {
32
- config = config_;
33
+ configResolved: {
34
+ handler(config_) {
35
+ config = config_;
36
+ },
33
37
  },
34
- transform(code, id) {
35
- if (!config._isDev)
36
- return;
37
- const idWithoutQuery = id.split('?')[0];
38
- if (idWithoutQuery !== distFileIsNonRunnableDev && idWithoutQuery !== distFileGlobalContext)
39
- return;
40
- if ((0, utils_js_1.isRunnableDevEnvironment)(this.environment))
41
- return;
42
- const { magicString, getMagicStringResult } = (0, getMagicString_js_1.getMagicString)(code, id);
43
- if (idWithoutQuery === distFileIsNonRunnableDev) {
44
- magicString.replaceAll('__VIKE__IS_NON_RUNNABLE_DEV', JSON.stringify(true));
45
- }
46
- if (idWithoutQuery === distFileGlobalContext) {
47
- magicString.replaceAll('__VIKE__DYNAMIC_IMPORT', 'import');
48
- }
49
- return getMagicStringResult();
38
+ transform: {
39
+ handler(code, id) {
40
+ if (!config._isDev)
41
+ return;
42
+ const idWithoutQuery = id.split('?')[0];
43
+ if (idWithoutQuery !== distFileIsNonRunnableDev && idWithoutQuery !== distFileGlobalContext)
44
+ return;
45
+ if ((0, utils_js_1.isRunnableDevEnvironment)(this.environment))
46
+ return;
47
+ const { magicString, getMagicStringResult } = (0, getMagicString_js_1.getMagicString)(code, id);
48
+ if (idWithoutQuery === distFileIsNonRunnableDev) {
49
+ magicString.replaceAll('__VIKE__IS_NON_RUNNABLE_DEV', JSON.stringify(true));
50
+ }
51
+ if (idWithoutQuery === distFileGlobalContext) {
52
+ magicString.replaceAll('__VIKE__DYNAMIC_IMPORT', 'import');
53
+ }
54
+ return getMagicStringResult();
55
+ },
50
56
  },
51
57
  };
52
58
  }
@@ -19,32 +19,38 @@ function pluginPreview() {
19
19
  return {
20
20
  name: 'vike:pluginPreview',
21
21
  apply: utils_js_1.applyPreview,
22
- config() {
23
- return {
24
- appType: 'custom',
25
- };
22
+ config: {
23
+ handler() {
24
+ return {
25
+ appType: 'custom',
26
+ };
27
+ },
26
28
  },
27
- async configResolved(config_) {
28
- config = config_;
29
- vikeConfig = await (0, resolveVikeConfigInternal_js_1.getVikeConfigInternal)();
30
- (0, pluginDev_js_1.logDockerHint)(config.preview.host);
31
- // vikeConfig = await getVikeConfig(config)
29
+ configResolved: {
30
+ async handler(config_) {
31
+ config = config_;
32
+ vikeConfig = await (0, resolveVikeConfigInternal_js_1.getVikeConfigInternal)();
33
+ (0, pluginDev_js_1.logDockerHint)(config.preview.host);
34
+ // vikeConfig = await getVikeConfig(config)
35
+ },
32
36
  },
33
- configurePreviewServer(server) {
34
- /* - Couldn't make `appType: 'mpa'` work as of npm:@brillout/vite@5.0.0-beta.14.0426910c
35
- - This ugly hack to set appType for preview won't be need once https://github.com/vitejs/vite/pull/14855 is merged.
36
- config.appType = 'mpa'
37
- */
38
- return () => {
39
- const { isPrerenderingEnabledForAllPages, isPrerenderingEnabled } = vikeConfig.prerenderContext;
40
- assertDist(isPrerenderingEnabledForAllPages);
41
- // We cannot re-use Vite's static middleware: https://github.com/vitejs/vite/pull/14836#issuecomment-1788540300
42
- addStaticAssetsMiddleware(server.middlewares);
43
- if (!isPrerenderingEnabledForAllPages) {
44
- (0, addSsrMiddleware_js_1.addSsrMiddleware)(server.middlewares, config, true, isPrerenderingEnabled);
45
- }
46
- addStatic404Middleware(server.middlewares);
47
- };
37
+ configurePreviewServer: {
38
+ handler(server) {
39
+ /* - Couldn't make `appType: 'mpa'` work as of npm:@brillout/vite@5.0.0-beta.14.0426910c
40
+ - This ugly hack to set appType for preview won't be need once https://github.com/vitejs/vite/pull/14855 is merged.
41
+ config.appType = 'mpa'
42
+ */
43
+ return () => {
44
+ const { isPrerenderingEnabledForAllPages, isPrerenderingEnabled } = vikeConfig.prerenderContext;
45
+ assertDist(isPrerenderingEnabledForAllPages);
46
+ // We cannot re-use Vite's static middleware: https://github.com/vitejs/vite/pull/14836#issuecomment-1788540300
47
+ addStaticAssetsMiddleware(server.middlewares);
48
+ if (!isPrerenderingEnabledForAllPages) {
49
+ (0, addSsrMiddleware_js_1.addSsrMiddleware)(server.middlewares, config, true, isPrerenderingEnabled);
50
+ }
51
+ addStatic404Middleware(server.middlewares);
52
+ };
53
+ },
48
54
  },
49
55
  };
50
56
  function assertDist(isPrerenderingEnabledForAllPages) {
@@ -11,41 +11,49 @@ function pluginReplaceConstants() {
11
11
  name: 'vike:pluginReplaceConstants',
12
12
  enforce: 'post',
13
13
  apply: 'build',
14
- configResolved(config_) {
15
- config = config_;
14
+ configResolved: {
15
+ handler(config_) {
16
+ config = config_;
17
+ },
16
18
  },
17
- transform(code, id, options) {
18
- id = (0, normalizeId_js_1.normalizeId)(id);
19
- (0, utils_js_1.assertPosixPath)(id);
20
- if (id.includes('/node_modules/'))
21
- return;
22
- (0, utils_js_1.assertPosixPath)(config.root);
23
- if (!id.startsWith(config.root))
24
- return;
25
- if (!code.includes('({}).'))
26
- return;
27
- const isBuild = config.command === 'build';
28
- (0, utils_js_1.assert)(isBuild);
29
- // Used by vike.dev
30
- // https://github.com/vikejs/vike/blob/08a1ff55c80ddca64ca6d4417fefd45fefeb4ffb/docs/vite.config.ts#L12
31
- // @ts-expect-error
32
- if (config._skipVikeReplaceConstants?.(id))
33
- return;
34
- const { magicString, getMagicStringResult } = (0, getMagicString_js_1.getMagicString)(code, id);
35
- const constantsMap = [];
36
- constantsMap.push({
37
- constants: ['pageContext.isClientSide', 'globalContext.isClientSide', 'pageContext.globalContext.isClientSide'],
38
- replacement: !(0, isViteServerSide_js_1.isViteServerSide_extraSafe)(config, this.environment, options),
39
- });
40
- constantsMap.forEach(({ constants, replacement }) => {
41
- if (!constants.some((c) => code.includes(c)))
19
+ transform: {
20
+ handler(code, id, options) {
21
+ id = (0, normalizeId_js_1.normalizeId)(id);
22
+ (0, utils_js_1.assertPosixPath)(id);
23
+ if (id.includes('/node_modules/'))
42
24
  return;
43
- const regExp = getConstantRegExp(constants);
44
- magicString.replaceAll(regExp, JSON.stringify(replacement));
45
- });
46
- if (!magicString.hasChanged())
47
- return null;
48
- return getMagicStringResult();
25
+ (0, utils_js_1.assertPosixPath)(config.root);
26
+ if (!id.startsWith(config.root))
27
+ return;
28
+ if (!code.includes('({}).'))
29
+ return;
30
+ const isBuild = config.command === 'build';
31
+ (0, utils_js_1.assert)(isBuild);
32
+ // Used by vike.dev
33
+ // https://github.com/vikejs/vike/blob/08a1ff55c80ddca64ca6d4417fefd45fefeb4ffb/docs/vite.config.ts#L12
34
+ // @ts-expect-error
35
+ if (config._skipVikeReplaceConstants?.(id))
36
+ return;
37
+ const { magicString, getMagicStringResult } = (0, getMagicString_js_1.getMagicString)(code, id);
38
+ const constantsMap = [];
39
+ constantsMap.push({
40
+ constants: [
41
+ 'pageContext.isClientSide',
42
+ 'globalContext.isClientSide',
43
+ 'pageContext.globalContext.isClientSide',
44
+ ],
45
+ replacement: !(0, isViteServerSide_js_1.isViteServerSide_extraSafe)(config, this.environment, options),
46
+ });
47
+ constantsMap.forEach(({ constants, replacement }) => {
48
+ if (!constants.some((c) => code.includes(c)))
49
+ return;
50
+ const regExp = getConstantRegExp(constants);
51
+ magicString.replaceAll(regExp, JSON.stringify(replacement));
52
+ });
53
+ if (!magicString.hasChanged())
54
+ return null;
55
+ return getMagicStringResult();
56
+ },
49
57
  },
50
58
  };
51
59
  }
@@ -22,8 +22,10 @@ function pluginSetGlobalContext() {
22
22
  (0, utils_js_1.markSetup_viteDevServer)();
23
23
  },
24
24
  },
25
- configurePreviewServer() {
26
- (0, utils_js_1.markSetup_vitePreviewServer)();
25
+ configurePreviewServer: {
26
+ handler() {
27
+ (0, utils_js_1.markSetup_vitePreviewServer)();
28
+ },
27
29
  },
28
30
  config: {
29
31
  order: 'pre',
@@ -144,7 +144,7 @@ function getGlobs(globRoots, isBuild, fileType, query, isV1Design) {
144
144
  const globExcludePath = globRoot.excludeDir ? `'!${getGlobPath(globRoot.excludeDir, fileType)}'` : null;
145
145
  const globOptions = { eager: isEager };
146
146
  if (query) {
147
- const isNewViteInterface = (0, utils_js_1.isVersionOrAbove)(vite_1.version, '5.1.0');
147
+ const isNewViteInterface = (0, utils_js_1.isVersionMatch)(vite_1.version, ['5.1.0']);
148
148
  if (isNewViteInterface &&
149
149
  // When used for the old design, the new syntax breaks Vike's CI (surprinsigly so). I couldn't reproduce locally (I didn't dig much).
150
150
  isV1Design) {
@@ -21,47 +21,57 @@ function pluginVirtualFiles() {
21
21
  let config;
22
22
  return {
23
23
  name: 'vike:pluginVirtualFiles',
24
- async configResolved(config_) {
25
- config = config_;
26
- // TO-DO/next-major-release: remove
27
- if (!(0, resolveVikeConfigInternal_js_1.isV1Design)())
28
- config.experimental.importGlobRestoreExtension = true;
24
+ configResolved: {
25
+ async handler(config_) {
26
+ config = config_;
27
+ // TO-DO/next-major-release: remove
28
+ if (!(0, resolveVikeConfigInternal_js_1.isV1Design)())
29
+ config.experimental.importGlobRestoreExtension = true;
30
+ },
29
31
  },
30
- resolveId(id) {
31
- if ((0, utils_js_1.isVirtualFileId)(id)) {
32
- return (0, utils_js_1.addVirtualFileIdPrefix)(id);
33
- }
34
- },
35
- async handleHotUpdate(ctx) {
36
- try {
37
- return await handleHotUpdate(ctx, config);
38
- }
39
- catch (err) {
40
- // Vite swallows errors thrown by handleHotUpdate()
41
- console.error(err);
42
- throw err;
43
- }
32
+ resolveId: {
33
+ handler(id) {
34
+ if ((0, utils_js_1.isVirtualFileId)(id)) {
35
+ return (0, utils_js_1.addVirtualFileIdPrefix)(id);
36
+ }
37
+ },
44
38
  },
45
- async load(id, options) {
46
- if (!(0, utils_js_1.isVirtualFileId)(id))
47
- return undefined;
48
- id = (0, utils_js_1.removeVirtualFileIdPrefix)(id);
49
- const isDev = config._isDev;
50
- (0, utils_js_1.assert)(typeof isDev === 'boolean');
51
- const idParsed = (0, virtualFileId_js_1.parseVirtualFileId)(id);
52
- if (idParsed) {
53
- if (idParsed.type === 'page-entry') {
54
- const code = await (0, generateVirtualFilePageEntry_js_1.generateVirtualFilePageEntry)(id, isDev);
55
- return code;
39
+ handleHotUpdate: {
40
+ async handler(ctx) {
41
+ try {
42
+ return await handleHotUpdate(ctx, config);
56
43
  }
57
- if (idParsed.type === 'global-entry') {
58
- const code = await (0, generateVirtualFileGlobalEntryWithOldDesign_js_1.generateVirtualFileGlobalEntryWithOldDesign)(id, options, config, this.environment, isDev);
59
- return code;
44
+ catch (err) {
45
+ // Vite swallows errors thrown by handleHotUpdate()
46
+ console.error(err);
47
+ throw err;
60
48
  }
61
- }
49
+ },
50
+ },
51
+ load: {
52
+ async handler(id, options) {
53
+ if (!(0, utils_js_1.isVirtualFileId)(id))
54
+ return undefined;
55
+ id = (0, utils_js_1.removeVirtualFileIdPrefix)(id);
56
+ const isDev = config._isDev;
57
+ (0, utils_js_1.assert)(typeof isDev === 'boolean');
58
+ const idParsed = (0, virtualFileId_js_1.parseVirtualFileId)(id);
59
+ if (idParsed) {
60
+ if (idParsed.type === 'page-entry') {
61
+ const code = await (0, generateVirtualFilePageEntry_js_1.generateVirtualFilePageEntry)(id, isDev);
62
+ return code;
63
+ }
64
+ if (idParsed.type === 'global-entry') {
65
+ const code = await (0, generateVirtualFileGlobalEntryWithOldDesign_js_1.generateVirtualFileGlobalEntryWithOldDesign)(id, options, config, this.environment, isDev);
66
+ return code;
67
+ }
68
+ }
69
+ },
62
70
  },
63
- configureServer(server) {
64
- handleFileAddRemove(server, config);
71
+ configureServer: {
72
+ handler(server) {
73
+ handleFileAddRemove(server, config);
74
+ },
65
75
  },
66
76
  };
67
77
  }
@@ -130,7 +140,10 @@ async function handleHotUpdate(ctx, config) {
130
140
  // Ensure we invalidate `file` *before* server.ssrLoadModule() in updateUserFiles()
131
141
  // Vite already invalidates it, but *after* handleHotUpdate() and thus after server.ssrLoadModule()
132
142
  ctx.modules.forEach((mod) => server.moduleGraph.invalidateModule(mod));
133
- (0, globalContext_js_1.updateUserFiles)();
143
+ if ((0, globalContext_js_1.isRunnable)(server)) {
144
+ // TODO/now: await
145
+ (0, globalContext_js_1.updateUserFiles)();
146
+ }
134
147
  }
135
148
  }
136
149
  }
@@ -4,12 +4,14 @@ exports.pluginWorkaroundCssModuleHmr = pluginWorkaroundCssModuleHmr;
4
4
  function pluginWorkaroundCssModuleHmr() {
5
5
  return {
6
6
  name: 'vike:pluginWorkaroundCssModuleHmr',
7
- handleHotUpdate(ctx) {
8
- // prevent full reload due to non self-accepting css module.
9
- // here only "?direct" module should be filtered out as it doesn't have a parent module.
10
- if (ctx.file.includes('module.css')) {
11
- return ctx.modules.filter((m) => !m.id?.includes('?direct'));
12
- }
7
+ handleHotUpdate: {
8
+ handler(ctx) {
9
+ // prevent full reload due to non self-accepting css module.
10
+ // here only "?direct" module should be filtered out as it doesn't have a parent module.
11
+ if (ctx.file.includes('module.css')) {
12
+ return ctx.modules.filter((m) => !m.id?.includes('?direct'));
13
+ }
14
+ },
13
15
  },
14
16
  };
15
17
  }
@@ -152,7 +152,7 @@ async function isGitNotUsable(userRootDir) {
152
152
  // - We didn't bother test which is the earliest version that works.
153
153
  // - Git 2.32.0 doesn't seem to work: https://github.com/vikejs/vike/discussions/1549
154
154
  // - Maybe it's because of StackBlitz: looking at the release notes, Git 2.32.0 should be working.
155
- if (!(0, utils_js_1.isVersionOrAbove)(gitVersion, '2.43.1'))
155
+ if (!(0, utils_js_1.isVersionMatch)(gitVersion, ['2.43.1']))
156
156
  return true;
157
157
  }
158
158
  // Is userRootDir inside a Git repository?
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PROJECT_VERSION = void 0;
4
4
  // Automatically updated by @brillout/release-me
5
- exports.PROJECT_VERSION = '0.4.238-commit-d48a597';
5
+ exports.PROJECT_VERSION = '0.4.239-commit-050a4a3';
@@ -8,5 +8,7 @@ function assertNodeVersion() {
8
8
  if (!(0, isNodeJS_js_1.isNodeJS)())
9
9
  return;
10
10
  const version = process.versions.node;
11
- (0, assertVersion_js_1.assertVersion)('Node.js', version, '18.0.0');
11
+ (0, assertVersion_js_1.assertVersion)('Node.js', version,
12
+ // https://gist.github.com/brillout/8e0133716e169b981b6c4e8a938b0134
13
+ ['20.19.0', '22.12.0', '23.0.0']);
12
14
  }
@@ -1,16 +1,37 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.assertVersion = assertVersion;
4
- exports.isVersionOrAbove = isVersionOrAbove;
7
+ exports.isVersionMatch = isVersionMatch;
8
+ const picocolors_1 = __importDefault(require("@brillout/picocolors"));
5
9
  const assert_js_1 = require("./assert.js");
6
10
  const assertIsNotBrowser_js_1 = require("./assertIsNotBrowser.js");
11
+ const joinEnglish_js_1 = require("./joinEnglish.js");
7
12
  (0, assertIsNotBrowser_js_1.assertIsNotBrowser)();
8
- function assertVersion(dependencyName, versionActual, versionExpected) {
13
+ function assertVersion(dependencyName, versionActual, versionExpectedList) {
14
+ (0, assert_js_1.assertUsage)(isVersionMatch(versionActual, versionExpectedList), `${picocolors_1.default.bold(dependencyName)} ${picocolors_1.default.red(picocolors_1.default.bold(versionActual))} isn't supported, use ${picocolors_1.default.bold(dependencyName)} ${(0, joinEnglish_js_1.joinEnglish)([...versionExpectedList, 'above'].map((v) => picocolors_1.default.green(picocolors_1.default.bold(v))), 'or')}.`);
15
+ }
16
+ function isVersionMatch(versionActual, versionExpectedList) {
9
17
  (0, assert_js_1.assert)(versionActual);
10
- (0, assert_js_1.assert)(versionExpected);
11
- (0, assert_js_1.assertUsage)(isVersionOrAbove(versionActual, versionExpected), `${dependencyName} ${versionActual} isn't supported, use ${dependencyName} >= ${versionExpected} instead.`);
18
+ (0, assert_js_1.assert)(versionExpectedList);
19
+ (0, assert_js_1.assert)(versionExpectedList.length > 0);
20
+ const versionActualMajor = parseVersion(versionActual)[0];
21
+ const versionExpectedListSameMajor = versionExpectedList.filter((versionExpected) => {
22
+ const versionExpectedMajor = parseVersion(versionExpected)[0];
23
+ return versionExpectedMajor === versionActualMajor;
24
+ });
25
+ (0, assert_js_1.assert)(versionExpectedListSameMajor.length <= 1);
26
+ const versionExpectedSameMajor = versionExpectedListSameMajor[0];
27
+ if (versionExpectedSameMajor) {
28
+ return isSameOrAbove(versionActual, versionExpectedSameMajor);
29
+ }
30
+ else {
31
+ return versionExpectedList.every((versionExpected) => isSameOrAbove(versionActual, versionExpected));
32
+ }
12
33
  }
13
- function isVersionOrAbove(versionActual, versionExpected) {
34
+ function isSameOrAbove(versionActual, versionExpected) {
14
35
  const p1 = parseVersion(versionActual);
15
36
  const p2 = parseVersion(versionExpected);
16
37
  // major
@@ -9,5 +9,6 @@ function joinEnglish(arr, conjunction, colorizer = (s) => s) {
9
9
  return colorizer(arr[0]);
10
10
  const firsts = arr.slice(0, arr.length - 1);
11
11
  const last = arr[arr.length - 1];
12
- return firsts.map(colorizer).join(', ') + `, ${conjunction} ` + colorizer(last);
12
+ const lastComma = arr.length > 2 ? ',' : '';
13
+ return firsts.map(colorizer).join(', ') + `${lastComma} ${conjunction} ` + colorizer(last);
13
14
  }
@@ -15,6 +15,7 @@ export { setGlobalContext_prodBuildEntry };
15
15
  export { clearGlobalContext };
16
16
  export { assertBuildInfo };
17
17
  export { updateUserFiles };
18
+ export { isRunnable };
18
19
  export { vikeConfigErrorRecoverMsg };
19
20
  export type { BuildInfo };
20
21
  export type { GlobalContextServerInternal as GlobalContextServerInternal };
@@ -364,3 +365,4 @@ declare function createGlobalContext(virtualFileExportsGlobalEntry: unknown): Pr
364
365
  };
365
366
  })>;
366
367
  declare function clearGlobalContext(): void;
368
+ declare function isRunnable(viteDevServer: ViteDevServer): boolean;
@@ -17,6 +17,7 @@ export { setGlobalContext_prodBuildEntry }; // production entry
17
17
  export { clearGlobalContext };
18
18
  export { assertBuildInfo };
19
19
  export { updateUserFiles };
20
+ export { isRunnable };
20
21
  export { vikeConfigErrorRecoverMsg };
21
22
  // The core logic revolves around:
22
23
  // - virtualFileExportsGlobalEntry is the main requirement
@@ -13,7 +13,7 @@ function onLoad() {
13
13
  // TO-DO/eventually: let's also use this.meta.viteVersion
14
14
  // - https://github.com/vitejs/vite/pull/20088
15
15
  // - https://github.com/vitejs/vite/blob/main/packages/vite/CHANGELOG.md#700-2025-06-24
16
- assertVersion('Vite', version, '6.0.0');
16
+ assertVersion('Vite', version, ['6.0.0']);
17
17
  // Ensure we don't bloat the server runtime with heavy dependencies such Vite and esbuild
18
18
  assertIsNotProductionRuntime();
19
19
  }