vike 0.4.227 → 0.4.228

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 (86) hide show
  1. package/dist/cjs/node/api/dev.js +2 -0
  2. package/dist/cjs/node/plugin/plugins/build/pluginBuildConfig.js +3 -5
  3. package/dist/cjs/node/plugin/plugins/build/pluginBuildEntry.js +5 -7
  4. package/dist/cjs/node/plugin/plugins/build/pluginModuleBanner.js +13 -21
  5. package/dist/cjs/node/plugin/plugins/devConfig/determineFsAllowList.js +8 -9
  6. package/dist/cjs/node/plugin/plugins/envVars.js +22 -13
  7. package/dist/cjs/node/plugin/plugins/extractAssetsPlugin.js +1 -2
  8. package/dist/cjs/node/plugin/plugins/extractExportNamesPlugin.js +1 -2
  9. package/dist/cjs/node/plugin/plugins/fileEnv.js +1 -2
  10. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js +1 -3
  11. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +25 -19
  12. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +1 -1
  13. package/dist/cjs/node/plugin/plugins/setGlobalContext.js +3 -4
  14. package/dist/cjs/node/plugin/shared/getViteConfigRuntime.js +21 -0
  15. package/dist/cjs/node/plugin/shared/resolveClientEntriesDev.js +11 -12
  16. package/dist/cjs/node/plugin/utils.js +1 -0
  17. package/dist/cjs/node/prerender/resolvePrerenderConfig.js +1 -1
  18. package/dist/cjs/node/prerender/runPrerender.js +157 -196
  19. package/dist/cjs/node/prerender/utils.js +1 -1
  20. package/dist/cjs/node/runtime/globalContext.js +52 -27
  21. package/dist/cjs/node/runtime/html/stream.js +2 -4
  22. package/dist/cjs/node/runtime/index-common.js +2 -1
  23. package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +0 -23
  24. package/dist/cjs/node/runtime-dev/createDevMiddleware.js +1 -1
  25. package/dist/cjs/shared/route/executeOnBeforeRouteHook.js +1 -1
  26. package/dist/cjs/shared/route/index.js +13 -11
  27. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  28. package/dist/cjs/utils/assert.js +2 -5
  29. package/dist/cjs/utils/findPackageJson.js +2 -2
  30. package/dist/cjs/utils/isFilePathAbsoluteFilesystem.js +1 -1
  31. package/dist/cjs/utils/isNpmPackage.js +1 -1
  32. package/dist/cjs/utils/isScriptFile.js +4 -4
  33. package/dist/cjs/utils/parseUrl.js +4 -4
  34. package/dist/cjs/utils/preservePropertyGetters.js +30 -0
  35. package/dist/cjs/utils/requireResolve.js +60 -16
  36. package/dist/cjs/{node/plugin/shared → utils}/rollupSourceMap.js +4 -4
  37. package/dist/esm/node/api/dev.js +2 -0
  38. package/dist/esm/node/plugin/plugins/build/pluginBuildConfig.js +2 -4
  39. package/dist/esm/node/plugin/plugins/build/pluginBuildEntry.js +4 -6
  40. package/dist/esm/node/plugin/plugins/build/pluginModuleBanner.js +11 -22
  41. package/dist/esm/node/plugin/plugins/devConfig/determineFsAllowList.js +7 -8
  42. package/dist/esm/node/plugin/plugins/envVars.js +19 -13
  43. package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +2 -3
  44. package/dist/esm/node/plugin/plugins/extractExportNamesPlugin.js +2 -3
  45. package/dist/esm/node/plugin/plugins/fileEnv.js +2 -3
  46. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js +2 -4
  47. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +26 -20
  48. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +1 -1
  49. package/dist/esm/node/plugin/plugins/setGlobalContext.js +4 -5
  50. package/dist/esm/node/plugin/shared/getViteConfigRuntime.d.ts +14 -0
  51. package/dist/esm/node/plugin/shared/getViteConfigRuntime.js +19 -0
  52. package/dist/esm/node/plugin/shared/resolveClientEntriesDev.js +10 -11
  53. package/dist/esm/node/plugin/utils.d.ts +1 -0
  54. package/dist/esm/node/plugin/utils.js +1 -0
  55. package/dist/esm/node/prerender/resolvePrerenderConfig.d.ts +1 -1
  56. package/dist/esm/node/prerender/resolvePrerenderConfig.js +1 -1
  57. package/dist/esm/node/prerender/runPrerender.d.ts +1 -0
  58. package/dist/esm/node/prerender/runPrerender.js +160 -199
  59. package/dist/esm/node/prerender/utils.d.ts +1 -1
  60. package/dist/esm/node/prerender/utils.js +1 -1
  61. package/dist/esm/node/runtime/globalContext.d.ts +26 -17
  62. package/dist/esm/node/runtime/globalContext.js +52 -27
  63. package/dist/esm/node/runtime/html/stream.js +2 -4
  64. package/dist/esm/node/runtime/index-common.d.ts +1 -1
  65. package/dist/esm/node/runtime/index-common.js +1 -1
  66. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +9 -197
  67. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +0 -23
  68. package/dist/esm/node/runtime-dev/createDevMiddleware.js +1 -1
  69. package/dist/esm/shared/route/executeOnBeforeRouteHook.js +1 -1
  70. package/dist/esm/shared/route/index.d.ts +1 -1
  71. package/dist/esm/shared/route/index.js +13 -11
  72. package/dist/esm/shared/types.d.ts +1 -3
  73. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  74. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  75. package/dist/esm/utils/assert.js +2 -5
  76. package/dist/esm/utils/isFilePathAbsoluteFilesystem.js +1 -1
  77. package/dist/esm/utils/isNpmPackage.js +1 -1
  78. package/dist/esm/utils/isScriptFile.js +4 -4
  79. package/dist/esm/utils/parseUrl.js +4 -4
  80. package/dist/esm/utils/preservePropertyGetters.d.ts +2 -0
  81. package/dist/esm/utils/preservePropertyGetters.js +28 -0
  82. package/dist/esm/utils/requireResolve.d.ts +7 -1
  83. package/dist/esm/utils/requireResolve.js +54 -13
  84. package/dist/esm/{node/plugin/shared → utils}/rollupSourceMap.d.ts +4 -4
  85. package/dist/esm/{node/plugin/shared → utils}/rollupSourceMap.js +4 -4
  86. package/package.json +3 -2
@@ -14,10 +14,10 @@ import { assert } from './assert.js';
14
14
  import { assertIsNotBrowser } from './assertIsNotBrowser.js';
15
15
  assertIsNotBrowser();
16
16
  function isNpmPackageImport(str, { cannotBePathAlias }) {
17
- // We cannot distinguish path alises that look like npm package imports
18
17
  assert(cannotBePathAlias);
19
18
  return isNpmPackageImport_unreliable(str);
20
19
  }
20
+ // We cannot distinguish path aliases that look like npm package imports
21
21
  function isNpmPackageImport_unreliable(str) {
22
22
  const res = parse(str);
23
23
  return res !== null;
@@ -7,12 +7,12 @@ import { assert } from './assert.js';
7
7
  // We can't use a RegExp:
8
8
  // - Needs to work with Micromatch: https://github.com/micromatch/micromatch because:
9
9
  // - Vite's `import.meta.glob()` uses Micromatch
10
- // - We need this to be a whitelist because:
10
+ // - We need this to be a allowlist because:
11
11
  // - A pattern `*([a-zA-Z0-9]` doesn't work.
12
12
  // - Because of ReScript: `.res` are ReScript source files which need to be ignored. (The ReScript compiler generates `.js` files alongside `.res` files.)
13
- // - Black listing doesn't work.
14
- // - We cannot implement a blacklist with a glob pattern.
15
- // - A post `import.meta.glob()` blacklist filtering doesn't work because Vite would still process the files (e.g. including them in the bundle).
13
+ // - Block listing doesn't work.
14
+ // - We cannot implement a blocklist with a glob pattern.
15
+ // - A post `import.meta.glob()` blocklist filtering doesn't work because Vite would still process the files (e.g. including them in the bundle).
16
16
  // prettier-ignore
17
17
  // biome-ignore format:
18
18
  const extJavaScript = [
@@ -182,14 +182,14 @@ function parseProtocol(uri) {
182
182
  return { protocol, uriWithoutProtocol };
183
183
  }
184
184
  function isUrlProtocol(protocol) {
185
- // Is there an altenrative to having a blacklist?
186
- // - If the blacklist becomes too big, maybe use a whitelist instead ['tauri://', 'file://', 'capacitor://', 'http://', 'https://']
187
- const blacklist = [
185
+ // Is there an alternative to having a blocklist?
186
+ // - If the blocklist becomes too big, maybe use a allowlist instead ['tauri://', 'file://', 'capacitor://', 'http://', 'https://']
187
+ const blocklist = [
188
188
  // https://docs.ipfs.tech/how-to/address-ipfs-on-web
189
189
  'ipfs://',
190
190
  'ipns://'
191
191
  ];
192
- if (blacklist.includes(protocol))
192
+ if (blocklist.includes(protocol))
193
193
  return false;
194
194
  return protocol.endsWith('://');
195
195
  }
@@ -0,0 +1,2 @@
1
+ export { preservePropertyGetters };
2
+ declare function preservePropertyGetters<T extends object>(objOriginal: T): void;
@@ -0,0 +1,28 @@
1
+ export { preservePropertyGetters };
2
+ import { assert } from './assert.js';
3
+ function preservePropertyGetters(objOriginal) {
4
+ // Store original getter descriptors
5
+ const getters = Object.fromEntries(Object.entries(Object.getOwnPropertyDescriptors(objOriginal)).filter(([_, desc]) => 'get' in desc));
6
+ // Make getters non-enumerable
7
+ for (const [key, desc] of Object.entries(getters)) {
8
+ Object.defineProperty(objOriginal, key, { ...desc, enumerable: false });
9
+ }
10
+ const restorePropertyGetters = function () {
11
+ const objCopy = this;
12
+ delete objOriginal._restorePropertyGetters;
13
+ delete objCopy._restorePropertyGetters;
14
+ for (const [key, desc] of Object.entries(getters)) {
15
+ if (objCopy !== objOriginal) {
16
+ assert(!(key in objCopy));
17
+ Object.defineProperty(objCopy, key, desc); // Add property getters to copy
18
+ }
19
+ assert(key in objOriginal);
20
+ Object.defineProperty(objOriginal, key, desc); // Restore original `enumerable` value
21
+ }
22
+ };
23
+ Object.defineProperty(objOriginal, '_restorePropertyGetters', {
24
+ value: restorePropertyGetters,
25
+ enumerable: true,
26
+ configurable: true
27
+ });
28
+ }
@@ -1,2 +1,8 @@
1
1
  export { requireResolve };
2
- declare function requireResolve(importPath: string, cwd: string): string | null;
2
+ export { requireResolveOptional };
3
+ export { requireResolveNonUserFile };
4
+ export { requireResolveOptionalNonUserFile };
5
+ declare function requireResolveOptional(importPath: string, cwd: string): string | null;
6
+ declare function requireResolveOptionalNonUserFile(importPath: string, cwd: string): string | null;
7
+ declare function requireResolveNonUserFile(importPath: string, cwd: string): string;
8
+ declare function requireResolve(importPath: string, cwd: string): string;
@@ -1,35 +1,76 @@
1
1
  export { requireResolve };
2
+ export { requireResolveOptional };
3
+ export { requireResolveNonUserFile };
4
+ export { requireResolveOptionalNonUserFile };
2
5
  import { assert } from './assert.js';
3
6
  import { assertIsNotBrowser } from './assertIsNotBrowser.js';
4
7
  import { assertIsNotProductionRuntime } from './assertSetup.js';
5
8
  import { assertPosixPath, toPosixPath } from './path.js';
6
9
  import { scriptFileExtensionList } from './isScriptFile.js';
7
- import { createRequire } from 'module';
10
+ import { createRequire } from 'node:module';
11
+ import path from 'node:path';
8
12
  // @ts-ignore import.meta.url is shimmed at dist/cjs by dist-cjs-fixup.js.
9
13
  const importMetaUrl = import.meta.url;
10
14
  const require_ = createRequire(importMetaUrl);
11
15
  assertIsNotBrowser();
12
16
  assertIsNotProductionRuntime();
13
- // We still can't use import.meta.resolve() as of 23.1.0 (November 2024) because `parent` argument requires an experimental flag.
14
- // - https://stackoverflow.com/questions/54977743/do-require-resolve-for-es-modules#comment139581675_62272600
15
- function requireResolve(importPath, cwd) {
17
+ function requireResolve_(importPath, cwd, options) {
16
18
  assertPosixPath(cwd);
17
- const clean = addFileExtensionsToRequireResolve();
18
- importPath = removeFileExtention(importPath);
19
+ assertPosixPath(importPath);
20
+ cwd = resolveCwd(cwd);
21
+ let clean = () => { };
22
+ if (!options?.doNotHandleFileExtension) {
23
+ clean = addFileExtensionsToRequireResolve();
24
+ importPath = removeFileExtention(importPath);
25
+ }
19
26
  let importedFile;
20
27
  try {
28
+ // We still can't use import.meta.resolve() as of 23.1.0 (November 2024) because `parent` argument requires an experimental flag.
29
+ // - https://stackoverflow.com/questions/54977743/do-require-resolve-for-es-modules#comment139581675_62272600
21
30
  importedFile = require_.resolve(importPath, { paths: [cwd] });
22
31
  }
23
- catch {
24
- importedFile = null;
25
- }
26
- finally {
32
+ catch (err) {
27
33
  clean();
34
+ return { importedFile: undefined, err, hasFailed: true };
28
35
  }
29
- if (importedFile) {
30
- importedFile = toPosixPath(importedFile);
36
+ clean();
37
+ importedFile = toPosixPath(importedFile);
38
+ return { importedFile, err: undefined, hasFailed: false };
39
+ }
40
+ function requireResolveOptional(importPath, cwd) {
41
+ const res = requireResolve_(importPath, cwd);
42
+ if (res.hasFailed)
43
+ return null;
44
+ return res.importedFile;
45
+ }
46
+ function requireResolveOptionalNonUserFile(importPath, cwd) {
47
+ const res = requireResolve_(importPath, cwd, { doNotHandleFileExtension: true });
48
+ if (res.hasFailed)
49
+ return null;
50
+ return res.importedFile;
51
+ }
52
+ function requireResolveNonUserFile(importPath, cwd) {
53
+ const res = requireResolve_(importPath, cwd, { doNotHandleFileExtension: true });
54
+ if (res.hasFailed)
55
+ throw res.err;
56
+ return res.importedFile;
57
+ }
58
+ function requireResolve(importPath, cwd) {
59
+ const res = requireResolve_(importPath, cwd);
60
+ if (res.hasFailed)
61
+ throw res.err;
62
+ return res.importedFile;
63
+ }
64
+ function resolveCwd(cwd) {
65
+ let prefix = 'file://';
66
+ if (process.platform === 'win32')
67
+ prefix += '/';
68
+ if (cwd.startsWith(prefix)) {
69
+ cwd = cwd.slice(prefix.length);
70
+ cwd = path.posix.dirname(cwd);
31
71
  }
32
- return importedFile;
72
+ assert(!cwd.startsWith('file:'));
73
+ return cwd;
33
74
  }
34
75
  function removeFileExtention(importPath) {
35
76
  // Skip for Bun: https://github.com/vikejs/vike/issues/2204
@@ -1,14 +1,14 @@
1
- export { sourceMapRemove };
2
- export { sourceMapPassthrough };
1
+ export { rollupSourceMapRemove };
2
+ export { rollupSourceMapPassthrough };
3
3
  /** Remove entire source mapping, to save KBs. */
4
- declare function sourceMapRemove(code: string): {
4
+ declare function rollupSourceMapRemove(code: string): {
5
5
  code: string;
6
6
  map: {
7
7
  mappings: '';
8
8
  };
9
9
  };
10
10
  /** Don't provide any source map, pass through current source map instead. */
11
- declare function sourceMapPassthrough(code: string): {
11
+ declare function rollupSourceMapPassthrough(code: string): {
12
12
  code: string;
13
13
  map: null;
14
14
  };
@@ -1,15 +1,15 @@
1
- export { sourceMapRemove };
2
- export { sourceMapPassthrough };
1
+ export { rollupSourceMapRemove };
2
+ export { rollupSourceMapPassthrough };
3
3
  // https://rollupjs.org/guide/en/#source-code-transformations
4
4
  /** Remove entire source mapping, to save KBs. */
5
- function sourceMapRemove(code) {
5
+ function rollupSourceMapRemove(code) {
6
6
  return {
7
7
  code,
8
8
  map: { mappings: '' }
9
9
  };
10
10
  }
11
11
  /** Don't provide any source map, pass through current source map instead. */
12
- function sourceMapPassthrough(code) {
12
+ function rollupSourceMapPassthrough(code) {
13
13
  return {
14
14
  code,
15
15
  map: null
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.227",
3
+ "version": "0.4.228",
4
4
  "repository": "https://github.com/vikejs/vike",
5
5
  "exports": {
6
6
  "./server": {
@@ -123,12 +123,13 @@
123
123
  "@brillout/json-serializer": "^0.5.15",
124
124
  "@brillout/picocolors": "^1.0.26",
125
125
  "@brillout/require-shim": "^0.1.2",
126
- "@brillout/vite-plugin-server-entry": "^0.7.1",
126
+ "@brillout/vite-plugin-server-entry": "^0.7.5",
127
127
  "acorn": "^8.0.0",
128
128
  "cac": "^6.0.0",
129
129
  "es-module-lexer": "^1.0.0",
130
130
  "esbuild": "^0.19.0 || ^0.20.0 || ^0.21.0 || ^0.22.0 || ^0.23.0 || ^0.24.0",
131
131
  "json5": "^2.0.0",
132
+ "magic-string": "^0.30.17",
132
133
  "picomatch": "^4.0.2",
133
134
  "semver": "^7.0.0",
134
135
  "sirv": "^3.0.1",