vike 0.4.165 → 0.4.166

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 (90) hide show
  1. package/dist/cjs/node/plugin/index.js +1 -1
  2. package/dist/cjs/node/plugin/plugins/baseUrls.js +1 -1
  3. package/dist/cjs/node/plugin/plugins/buildConfig/fixServerAssets.js +6 -2
  4. package/dist/cjs/node/plugin/plugins/buildConfig.js +68 -58
  5. package/dist/cjs/node/plugin/plugins/commonConfig/assertResolveAlias.js +12 -0
  6. package/dist/cjs/node/plugin/plugins/config/index.js +1 -1
  7. package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +2 -2
  8. package/dist/cjs/node/plugin/plugins/envVars.js +1 -1
  9. package/dist/cjs/node/plugin/plugins/fileEnv.js +2 -2
  10. package/dist/cjs/node/plugin/plugins/importUserCode/index.js +1 -1
  11. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +0 -1
  12. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +53 -24
  13. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +6 -6
  14. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +5 -24
  15. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +15 -22
  16. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +11 -20
  17. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +21 -20
  18. package/dist/cjs/node/plugin/shared/getFilePath.js +88 -0
  19. package/dist/cjs/node/plugin/shared/loggerNotProd/errorWithCodeSnippet.js +1 -1
  20. package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +1 -0
  21. package/dist/cjs/node/runtime/html/injectAssets/injectHtmlTags.js +1 -1
  22. package/dist/cjs/node/runtime/renderPage/getPageAssets/getManifestEntry.js +26 -24
  23. package/dist/cjs/node/runtime/renderPage/logErrorHint.js +5 -0
  24. package/dist/cjs/node/runtime/renderPage.js +34 -21
  25. package/dist/cjs/shared/page-configs/FilePath.js +2 -0
  26. package/dist/cjs/utils/assert.js +2 -0
  27. package/dist/cjs/utils/assertSingleInstance.js +6 -5
  28. package/dist/cjs/utils/assertVersion.js +4 -1
  29. package/dist/cjs/utils/getFilePathAbsolute.js +11 -11
  30. package/dist/cjs/utils/getGlobalObject.js +21 -6
  31. package/dist/cjs/utils/isNpmPackage.js +1 -4
  32. package/dist/cjs/utils/parseUrl.js +8 -1
  33. package/dist/cjs/utils/projectInfo.js +1 -4
  34. package/dist/esm/client/client-routing-runtime/history.d.ts +1 -1
  35. package/dist/esm/client/client-routing-runtime/history.js +5 -5
  36. package/dist/esm/client/client-routing-runtime/onBrowserHistoryNavigation.js +1 -1
  37. package/dist/esm/node/plugin/index.js +1 -1
  38. package/dist/esm/node/plugin/plugins/baseUrls.js +1 -1
  39. package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.js +6 -2
  40. package/dist/esm/node/plugin/plugins/buildConfig.d.ts +1 -1
  41. package/dist/esm/node/plugin/plugins/buildConfig.js +69 -59
  42. package/dist/esm/node/plugin/plugins/commonConfig/assertResolveAlias.js +12 -0
  43. package/dist/esm/node/plugin/plugins/config/index.js +1 -1
  44. package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +3 -3
  45. package/dist/esm/node/plugin/plugins/envVars.js +2 -2
  46. package/dist/esm/node/plugin/plugins/fileEnv.js +3 -3
  47. package/dist/esm/node/plugin/plugins/importUserCode/index.js +2 -2
  48. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +1 -1
  49. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +0 -1
  50. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.d.ts +1 -1
  51. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +54 -25
  52. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.d.ts +1 -1
  53. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +6 -6
  54. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.d.ts +1 -1
  55. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +6 -25
  56. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.d.ts +2 -1
  57. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +15 -22
  58. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.d.ts +1 -1
  59. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +11 -20
  60. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +3 -2
  61. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +21 -20
  62. package/dist/esm/node/plugin/shared/getFilePath.d.ts +20 -0
  63. package/dist/esm/node/plugin/shared/getFilePath.js +82 -0
  64. package/dist/esm/node/plugin/shared/loggerNotProd/errorWithCodeSnippet.js +2 -2
  65. package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +1 -0
  66. package/dist/esm/node/runtime/html/injectAssets/injectHtmlTags.js +1 -1
  67. package/dist/esm/node/runtime/renderPage/getPageAssets/getManifestEntry.js +26 -24
  68. package/dist/esm/node/runtime/renderPage/logErrorHint.js +2 -0
  69. package/dist/esm/node/runtime/renderPage.js +34 -21
  70. package/dist/esm/shared/page-configs/Config/PageContextConfig.d.ts +1 -1
  71. package/dist/esm/shared/page-configs/FilePath.d.ts +52 -0
  72. package/dist/esm/shared/page-configs/FilePath.js +1 -0
  73. package/dist/esm/shared/page-configs/PageConfig.d.ts +1 -42
  74. package/dist/esm/utils/assert.js +2 -0
  75. package/dist/esm/utils/assertSingleInstance.d.ts +2 -2
  76. package/dist/esm/utils/assertSingleInstance.js +5 -4
  77. package/dist/esm/utils/assertVersion.js +4 -1
  78. package/dist/esm/utils/getFilePathAbsolute.d.ts +4 -4
  79. package/dist/esm/utils/getFilePathAbsolute.js +10 -10
  80. package/dist/esm/utils/getGlobalObject.d.ts +6 -1
  81. package/dist/esm/utils/getGlobalObject.js +22 -6
  82. package/dist/esm/utils/isNpmPackage.d.ts +0 -6
  83. package/dist/esm/utils/isNpmPackage.js +5 -3
  84. package/dist/esm/utils/parseUrl.js +8 -1
  85. package/dist/esm/utils/projectInfo.d.ts +2 -2
  86. package/dist/esm/utils/projectInfo.js +1 -4
  87. package/package.json +26 -14
  88. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.js +0 -33
  89. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.d.ts +0 -5
  90. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.js +0 -27
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isDistinguishable = exports.parse = exports.isValidPathAlias = exports.getNpmPackageImportPath = exports.getNpmPackageName = exports.isNpmPackageName = exports.isNpmPackageImport = void 0;
3
+ exports.isDistinguishable = exports.parse = exports.isValidPathAlias = exports.isNpmPackageImport = void 0;
4
4
  const assert_js_1 = require("./assert.js");
5
5
  const assertIsNotBrowser_js_1 = require("./assertIsNotBrowser.js");
6
6
  (0, assertIsNotBrowser_js_1.assertIsNotBrowser)();
@@ -13,21 +13,18 @@ function isNpmPackageName(str) {
13
13
  const res = parse(str);
14
14
  return res !== null && res.importPath === null;
15
15
  }
16
- exports.isNpmPackageName = isNpmPackageName;
17
16
  function getNpmPackageName(str) {
18
17
  const res = parse(str);
19
18
  if (!res)
20
19
  return null;
21
20
  return res.pkgName;
22
21
  }
23
- exports.getNpmPackageName = getNpmPackageName;
24
22
  function getNpmPackageImportPath(str) {
25
23
  const res = parse(str);
26
24
  if (!res)
27
25
  return null;
28
26
  return res.importPath;
29
27
  }
30
- exports.getNpmPackageImportPath = getNpmPackageImportPath;
31
28
  function isValidPathAlias(alias) {
32
29
  // Cannot be distinguished from npm package names
33
30
  if (!isDistinguishable(alias))
@@ -10,7 +10,14 @@ exports.isUriWithProtocol = exports.createUrlFromComponents = exports.assertUrlC
10
10
  const slice_js_1 = require("./slice.js");
11
11
  const assert_js_1 = require("./assert.js");
12
12
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
13
- const PROTOCOLS = ['http://', 'https://', 'tauri://'];
13
+ const PROTOCOLS = [
14
+ 'http://',
15
+ 'https://',
16
+ // For [Tauri](https://tauri.app/)
17
+ 'tauri://',
18
+ // For Electron: https://github.com/vikejs/vike/issues/1557
19
+ 'file://'
20
+ ];
14
21
  function isParsable(url) {
15
22
  // `parseUrl()` works with these URLs
16
23
  return (PROTOCOLS.some((p) => url.startsWith(p)) ||
@@ -1,13 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PROJECT_VERSION = exports.projectInfo = void 0;
4
- const assertSingleInstance_js_1 = require("./assertSingleInstance.js");
5
- const PROJECT_VERSION = '0.4.165';
4
+ const PROJECT_VERSION = '0.4.166';
6
5
  exports.PROJECT_VERSION = PROJECT_VERSION;
7
6
  const projectInfo = {
8
7
  projectName: 'Vike',
9
8
  projectVersion: PROJECT_VERSION
10
9
  };
11
10
  exports.projectInfo = projectInfo;
12
- // Trick: since `utils/asserts.ts` depends on this file (`utils/projectInfo.ts`), we can have confidence that this file is always instantiated. So that we don't have to initialize this code snippet at every possible entry. (There are a *lot* of entries: `client/router/`, `client/`, `node/`, `node/plugin/`, `node/cli`, etc.)
13
- (0, assertSingleInstance_js_1.onProjectInfo)(projectInfo.projectVersion);
@@ -2,7 +2,7 @@ export { initHistoryState, getHistoryState, pushHistory, ScrollPosition, saveScr
2
2
  type HistoryState = {
3
3
  timestamp?: number;
4
4
  scrollPosition?: null | ScrollPosition;
5
- triggedBy?: 'user' | 'vike' | 'browser';
5
+ triggeredBy?: 'user' | 'vike' | 'browser';
6
6
  };
7
7
  type ScrollPosition = {
8
8
  x: number;
@@ -21,8 +21,8 @@ function initHistoryState() {
21
21
  hasModifications = true;
22
22
  state.scrollPosition = getScrollPosition();
23
23
  }
24
- if (!('triggedBy' in state)) {
25
- state.triggedBy = 'browser';
24
+ if (!('triggeredBy' in state)) {
25
+ state.triggeredBy = 'browser';
26
26
  }
27
27
  assertState(state);
28
28
  if (hasModifications) {
@@ -49,7 +49,7 @@ function saveScrollPosition() {
49
49
  function pushHistory(url, overwriteLastHistoryEntry) {
50
50
  if (!overwriteLastHistoryEntry) {
51
51
  const timestamp = getTimestamp();
52
- pushHistoryState({ timestamp, scrollPosition: null, triggedBy: 'vike' }, url);
52
+ pushHistoryState({ timestamp, scrollPosition: null, triggeredBy: 'vike' }, url);
53
53
  }
54
54
  else {
55
55
  replaceHistoryState(getHistoryState(), url);
@@ -82,8 +82,8 @@ function monkeyPatchHistoryPushState() {
82
82
  scrollPosition: getScrollPosition(),
83
83
  timestamp: getTimestamp(),
84
84
  ...stateFromUser,
85
- // Don't allow user to overwrite triggedBy as it would break Vike's handling of the 'popstate' event
86
- triggedBy: 'user'
85
+ // Don't allow user to overwrite triggeredBy as it would break Vike's handling of the 'popstate' event
86
+ triggeredBy: 'user'
87
87
  };
88
88
  return pushStateOriginal(state, ...rest);
89
89
  };
@@ -18,7 +18,7 @@ function onBrowserHistoryNavigation() {
18
18
  window.addEventListener('popstate', async () => {
19
19
  const currentState = getState();
20
20
  const scrollTarget = currentState.historyState.scrollPosition || 'scroll-to-top-or-hash';
21
- const isUserLandPushStateNavigation = currentState.historyState.triggedBy === 'user';
21
+ const isUserLandPushStateNavigation = currentState.historyState.triggeredBy === 'user';
22
22
  const isHashNavigation = currentState.urlWithoutHash === globalObject.previousState.urlWithoutHash;
23
23
  const isBackwardNavigation = !currentState.historyState.timestamp || !globalObject.previousState.historyState.timestamp
24
24
  ? null
@@ -34,7 +34,7 @@ function plugin(vikeConfig) {
34
34
  ...commonConfig(),
35
35
  importUserCode(),
36
36
  ...devConfig(),
37
- buildConfig(),
37
+ ...buildConfig(),
38
38
  previewConfig(),
39
39
  ...autoFullBuild(),
40
40
  packageJsonFile(),
@@ -8,7 +8,7 @@ function baseUrls(configVike) {
8
8
  return {
9
9
  name: 'vike:baseUrls',
10
10
  enforce: 'post',
11
- config: (config) => {
11
+ async config(config) {
12
12
  const bases = resolveBaseFromUserConfig(config, configVike);
13
13
  baseServer = bases.baseServer;
14
14
  baseAssets = bases.baseAssets;
@@ -43,10 +43,14 @@ async function copyAssets(filesToCopy, config) {
43
43
  return;
44
44
  assert(existsSync(assetsDirServer));
45
45
  const concurrencyLimit = pLimit(10);
46
- await Promise.all(filesToCopy.map((file) => concurrencyLimit(() => fs.cp(path.posix.join(outDirServer, file), path.posix.join(outDirClient, file), {
46
+ await Promise.all(filesToCopy.map((file) => concurrencyLimit(() =>
47
+ // TODO: move instead of copying
48
+ fs.cp(path.posix.join(outDirServer, file), path.posix.join(outDirClient, file), {
47
49
  recursive: true
48
50
  }))));
49
- await fs.rm(assetsDirServer, { recursive: true });
51
+ /* We cannot do that because, with some edge case Rollup settings (outputing JavaScript chunks and static assets to the same directoy), this removes JavaScript chunks, see https://github.com/vikejs/vike/issues/1154#issuecomment-1975762404
52
+ await fs.rm(assetsDirServer, { recursive: true })
53
+ */
50
54
  }
51
55
  // Add serverManifest resources to clientManifest
52
56
  function addServerAssets(clientManifest, serverManifest) {
@@ -5,7 +5,7 @@ export { manifestTempFile };
5
5
  import type { ResolvedConfig, Plugin } from 'vite';
6
6
  import type { PageConfigBuildTime } from '../../../shared/page-configs/PageConfig.js';
7
7
  declare const manifestTempFile = "_temp_manifest.json";
8
- declare function buildConfig(): Plugin;
8
+ declare function buildConfig(): Plugin[];
9
9
  declare function analyzeClientEntries(pageConfigs: PageConfigBuildTime[], config: ResolvedConfig): {
10
10
  hasClientRouting: boolean;
11
11
  hasServerRouting: boolean;
@@ -2,7 +2,7 @@ export { buildConfig };
2
2
  export { assertRollupInput };
3
3
  export { analyzeClientEntries };
4
4
  export { manifestTempFile };
5
- import { assert, resolveOutDir, viteIsSSR, getFilePathAbsolute, addOnBeforeLogHook, removeFileExtention, unique, assertPosixPath, assertUsage, injectRollupInputs, normalizeRollupInput, getOutDirs, isNpmPackageImport, assertNodeEnv_build } from '../utils.js';
5
+ import { assert, resolveOutDir, viteIsSSR, getFilePathAbsoluteFilesystem, addOnBeforeLogHook, removeFileExtention, unique, assertPosixPath, assertUsage, injectRollupInputs, normalizeRollupInput, getOutDirs, isNpmPackageImport, assertNodeEnv_build } from '../utils.js';
6
6
  import { getVikeConfig, isV1Design } from './importUserCode/v1-design/getVikeConfig.js';
7
7
  import { getConfigValue } from '../../../shared/page-configs/helpers.js';
8
8
  import { findPageFiles } from '../shared/findPageFiles.js';
@@ -25,71 +25,81 @@ function buildConfig() {
25
25
  let isSsrBuild;
26
26
  let outDirs;
27
27
  let config;
28
- return {
29
- name: 'vike:buildConfig',
30
- apply: 'build',
31
- enforce: 'post',
32
- configResolved: {
33
- order: 'post',
34
- async handler(config_) {
35
- config = config_;
36
- assertNodeEnv_build();
37
- assertRollupInput(config);
38
- const entries = await getEntries(config);
39
- assert(Object.keys(entries).length > 0);
40
- config.build.rollupOptions.input = injectRollupInputs(entries, config);
41
- addLogHook();
42
- outDirs = getOutDirs(config);
43
- {
44
- isServerAssetsFixEnabled = fixServerAssets_isEnabled() && (await isV1Design(config, false));
45
- if (isServerAssetsFixEnabled) {
46
- // https://github.com/vikejs/vike/issues/1339
47
- config.build.ssrEmitAssets = true;
48
- // Required if `ssrEmitAssets: true`, see https://github.com/vitejs/vite/pull/11430#issuecomment-1454800934
49
- config.build.cssMinify = 'esbuild';
28
+ return [
29
+ {
30
+ name: 'vike:buildConfig:configResolved',
31
+ apply: 'build',
32
+ enforce: 'post',
33
+ configResolved: {
34
+ order: 'post',
35
+ async handler(config_) {
36
+ config = config_;
37
+ assertNodeEnv_build();
38
+ assertRollupInput(config);
39
+ const entries = await getEntries(config);
40
+ assert(Object.keys(entries).length > 0);
41
+ config.build.rollupOptions.input = injectRollupInputs(entries, config);
42
+ addLogHook();
43
+ outDirs = getOutDirs(config);
44
+ {
45
+ isServerAssetsFixEnabled = fixServerAssets_isEnabled() && (await isV1Design(config, false));
46
+ if (isServerAssetsFixEnabled) {
47
+ // https://github.com/vikejs/vike/issues/1339
48
+ config.build.ssrEmitAssets = true;
49
+ // Required if `ssrEmitAssets: true`, see https://github.com/vitejs/vite/pull/11430#issuecomment-1454800934
50
+ config.build.cssMinify = 'esbuild';
51
+ }
50
52
  }
51
53
  }
54
+ },
55
+ config(config) {
56
+ assertNodeEnv_build();
57
+ isSsrBuild = viteIsSSR(config);
58
+ return {
59
+ build: {
60
+ outDir: resolveOutDir(config),
61
+ manifest: manifestTempFile,
62
+ copyPublicDir: !isSsrBuild
63
+ }
64
+ };
65
+ },
66
+ buildStart() {
67
+ assertNodeEnv_build();
52
68
  }
53
69
  },
54
- config(config) {
55
- assertNodeEnv_build();
56
- isSsrBuild = viteIsSSR(config);
57
- return {
58
- build: {
59
- outDir: resolveOutDir(config),
60
- manifest: manifestTempFile,
61
- copyPublicDir: !isSsrBuild
62
- }
63
- };
64
- },
65
- buildStart() {
66
- assertNodeEnv_build();
67
- },
68
- writeBundle: {
69
- order: 'post',
70
- sequential: true,
71
- async handler(options, bundle) {
72
- if (isSsrBuild) {
73
- // Ideally we'd move dist/_temp_manifest.json to dist/server/client-assets.json instead of dist/assets.json
74
- // - But we can't because there is no guarentee whether dist/server/ is generated before or after dist/client/ (generating dist/server/ after dist/client/ erases dist/server/client-assets.json)
75
- // - We'll able to do so once we replace `$ vite build` with `$ vike build`
76
- const assetsJsonFilePath = path.posix.join(outDirs.outDirRoot, 'assets.json');
77
- const clientManifestFilePath = path.posix.join(outDirs.outDirClient, manifestTempFile);
78
- const serverManifestFilePath = path.posix.join(outDirs.outDirServer, manifestTempFile);
79
- if (!isServerAssetsFixEnabled) {
80
- await fs.copyFile(clientManifestFilePath, assetsJsonFilePath);
81
- }
82
- else {
83
- const clientManifestMod = await fixServerAssets(config);
84
- await fs.writeFile(assetsJsonFilePath, JSON.stringify(clientManifestMod, null, 2), 'utf-8');
70
+ {
71
+ name: 'vike:buildConfig:writeBundle',
72
+ apply: 'build',
73
+ // Make sure other writeBundle() hooks are called after this writeBundle() hook.
74
+ // - set_constant_ASSETS_MAP() needs to be called before dist/server/ code is executed.
75
+ // - For example, the writeBundle() hook of vite-plugin-vercel needs to be called after this writeBundle() hook, otherwise: https://github.com/vikejs/vike/issues/1527
76
+ enforce: 'pre',
77
+ writeBundle: {
78
+ order: 'pre',
79
+ sequential: true,
80
+ async handler(options, bundle) {
81
+ if (isSsrBuild) {
82
+ // Ideally we'd move dist/_temp_manifest.json to dist/server/client-assets.json instead of dist/assets.json
83
+ // - But we can't because there is no guarentee whether dist/server/ is generated before or after dist/client/ (generating dist/server/ after dist/client/ erases dist/server/client-assets.json)
84
+ // - We'll able to do so once we replace `$ vite build` with `$ vike build`
85
+ const assetsJsonFilePath = path.posix.join(outDirs.outDirRoot, 'assets.json');
86
+ const clientManifestFilePath = path.posix.join(outDirs.outDirClient, manifestTempFile);
87
+ const serverManifestFilePath = path.posix.join(outDirs.outDirServer, manifestTempFile);
88
+ if (!isServerAssetsFixEnabled) {
89
+ await fs.copyFile(clientManifestFilePath, assetsJsonFilePath);
90
+ }
91
+ else {
92
+ const clientManifestMod = await fixServerAssets(config);
93
+ await fs.writeFile(assetsJsonFilePath, JSON.stringify(clientManifestMod, null, 2), 'utf-8');
94
+ }
95
+ await fs.rm(clientManifestFilePath);
96
+ await fs.rm(serverManifestFilePath);
97
+ await set_constant_ASSETS_MAP(options, bundle);
85
98
  }
86
- await fs.rm(clientManifestFilePath);
87
- await fs.rm(serverManifestFilePath);
88
- await set_constant_ASSETS_MAP(options, bundle);
89
99
  }
90
100
  }
91
101
  }
92
- };
102
+ ];
93
103
  }
94
104
  async function getEntries(config) {
95
105
  const configVike = await getConfigVike(config);
@@ -198,7 +208,7 @@ function getEntryFromClientEntry(clientEntry, config, addExtractAssetsQuery) {
198
208
  const filePath = clientEntry;
199
209
  assertPosixPath(filePath);
200
210
  assert(filePath.startsWith('/'));
201
- let entryTarget = getFilePathAbsolute(filePath, config);
211
+ let entryTarget = getFilePathAbsoluteFilesystem(filePath, config);
202
212
  if (addExtractAssetsQuery)
203
213
  entryTarget = extractAssetsAddQuery(entryTarget);
204
214
  let entryName = filePath;
@@ -1,6 +1,18 @@
1
1
  export { assertResolveAlias };
2
2
  import { assert, assertUsage, assertWarning, isValidPathAlias } from '../../utils.js';
3
3
  import pc from '@brillout/picocolors';
4
+ // Recommend users to avoid un-distinguishable path aliases.
5
+ // There are a lot of libraries that don't or cannot follow that recommendation, for example:
6
+ // - Nx
7
+ // - Not sure why, but Nx seems to add a path alias for each monorepo package
8
+ // - https://github.com/vikejs/vike/discussions/1134
9
+ // - MUI
10
+ // - https://mui.com/material-ui/guides/minimizing-bundle-size/#how-to-use-custom-bundles
11
+ // - https://github.com/vikejs/vike/discussions/1549#discussioncomment-8789002
12
+ // - @preact/preset-vite
13
+ // - Aliases react imports
14
+ // - @vitejs/plugin-vue2
15
+ // - https://github.com/vikejs/vike/issues/1329
4
16
  // TODO/v1-release: replace assertWarning() with assertUsage()
5
17
  function assertResolveAlias(config) {
6
18
  const aliases = getAliases(config);
@@ -20,7 +20,7 @@ async function getConfigVikPromise(vikeConfig, config) {
20
20
  const fromPluginOptions = (vikeConfig ?? {});
21
21
  const fromViteConfig = (config.vike ?? {});
22
22
  const configs = [fromPluginOptions, fromViteConfig];
23
- const { globalVikeConfig: fromPlusConfigFile } = await getVikeConfig(config, isDev2(config), false);
23
+ const { globalVikeConfig: fromPlusConfigFile } = await getVikeConfig(config, isDev2(config));
24
24
  configs.push(fromPlusConfigFile);
25
25
  assertVikeConfig(fromPlusConfigFile, ({ prop, errMsg }) => {
26
26
  // TODO: add config file path ?
@@ -1,6 +1,6 @@
1
1
  export { determineOptimizeDeps };
2
2
  import { findPageFiles } from '../../shared/findPageFiles.js';
3
- import { assert, getFilePathAbsolute, isNpmPackageImport, unique } from '../../utils.js';
3
+ import { assert, getFilePathAbsoluteFilesystem, isNpmPackageImport, unique } from '../../utils.js';
4
4
  import { getVikeConfig } from '../importUserCode/v1-design/getVikeConfig.js';
5
5
  import { getConfigValueSourcesNotOverriden } from '../../shared/getConfigValueSourcesNotOverriden.js';
6
6
  import { analyzeClientEntries } from '../buildConfig.js';
@@ -35,7 +35,7 @@ async function getPageDeps(config, pageConfigs, isDev) {
35
35
  const { definedAt, configEnv } = configValueSource;
36
36
  if (!configEnv.client)
37
37
  return;
38
- if (definedAt.filePathRelativeToUserRootDir !== null) {
38
+ if (definedAt.filePathAbsoluteUserRootDir !== null) {
39
39
  const { filePathAbsoluteFilesystem } = definedAt;
40
40
  assert(filePathAbsoluteFilesystem);
41
41
  // Surprisingly Vite expects entries to be absolute paths
@@ -70,7 +70,7 @@ async function getPageDeps(config, pageConfigs, isDev) {
70
70
  {
71
71
  const pageFiles = await findPageFiles(config, ['.page', '.page.client'], isDev);
72
72
  pageFiles.forEach((filePath) => {
73
- const entry = getFilePathAbsolute(filePath, config);
73
+ const entry = getFilePathAbsoluteFilesystem(filePath, config);
74
74
  entries.push(entry);
75
75
  });
76
76
  }
@@ -2,7 +2,7 @@ export { envVarsPlugin };
2
2
  // For ./envVars.spec.ts
3
3
  export { applyEnvVar };
4
4
  import { loadEnv } from 'vite';
5
- import { assert, assertPosixPath, assertUsage, assertWarning, escapeRegex, getFilePathRelativeToUserRootDir, lowerFirst } from '../utils.js';
5
+ import { assert, assertPosixPath, assertUsage, assertWarning, escapeRegex, getFilePathAbsoluteUserRootDir, lowerFirst } from '../utils.js';
6
6
  import { sourceMapPassthrough } from '../shared/rollupSourceMap.js';
7
7
  function envVarsPlugin() {
8
8
  let envsAll;
@@ -45,7 +45,7 @@ function envVarsPlugin() {
45
45
  if (isPrivate && isClientSide) {
46
46
  if (!code.includes(envStatement))
47
47
  return;
48
- const filePathToShowToUser = getFilePathRelativeToUserRootDir(id, config.root);
48
+ const filePathToShowToUser = getFilePathAbsoluteUserRootDir(id, config.root);
49
49
  const errMsgAddendum = isBuild ? '' : ' (Vike will prevent your app from building for production)';
50
50
  const keyPublic = `${publicPrefix}${envName}`;
51
51
  const errMsg = `${envStatement} is used in client-side file ${filePathToShowToUser} which means that the environment variable ${envName} will be included in client-side bundles and, therefore, ${envName} will be publicly exposed which can be a security leak${errMsgAddendum}. Use ${envStatement} only in server-side files, or rename ${envName} to ${keyPublic}, see https://vike.dev/env`;
@@ -1,5 +1,5 @@
1
1
  export { fileEnv };
2
- import { assert, assertUsage, assertWarning, capitalizeFirstLetter, getFilePathRelativeToUserRootDir } from '../utils.js';
2
+ import { assert, assertUsage, assertWarning, capitalizeFirstLetter, getFilePathAbsoluteUserRootDir } from '../utils.js';
3
3
  import { extractAssetsRE } from './extractAssetsPlugin.js';
4
4
  import { extractExportNamesRE } from './extractExportNamesPlugin.js';
5
5
  import pc from '@brillout/picocolors';
@@ -55,7 +55,7 @@ function fileEnv() {
55
55
  return;
56
56
  // Show error message
57
57
  let errMsg;
58
- let modulePathPretty = getFilePathRelativeToUserRootDir(modulePath, config.root);
58
+ let modulePathPretty = getFilePathAbsoluteUserRootDir(modulePath, config.root);
59
59
  modulePathPretty = modulePathPretty.replaceAll(suffix, pc.bold(suffix));
60
60
  errMsg = `${capitalizeFirstLetter(envExpect)}-only module ${modulePathPretty} (https://vike.dev/file-env) imported on the ${envActual}-side`;
61
61
  if (importer &&
@@ -63,7 +63,7 @@ function fileEnv() {
63
63
  !importer.includes('virtual:vike:') &&
64
64
  // I don't know why and who sets importer to '<stdin>' (I guess Vite?)
65
65
  importer !== '<stdin>') {
66
- const importerPath = getFilePathRelativeToUserRootDir(importer.split('?')[0], config.root);
66
+ const importerPath = getFilePathAbsoluteUserRootDir(importer.split('?')[0], config.root);
67
67
  errMsg += ` by ${importerPath}`;
68
68
  }
69
69
  if (isDev) {
@@ -3,7 +3,7 @@ import { normalizePath } from 'vite';
3
3
  import { getConfigVike } from '../../../shared/getConfigVike.js';
4
4
  import { getVirtualFilePageConfigValuesAll } from './v1-design/getVirtualFilePageConfigValuesAll.js';
5
5
  import { getVirtualFileImportUserCode } from './getVirtualFileImportUserCode.js';
6
- import { assert, assertPosixPath, getFilePathRelativeToUserRootDir, getOutDirs, getVirtualFileId, isDev1, isDev1_onConfigureServer, isVirtualFileId, resolveVirtualFileId } from '../../utils.js';
6
+ import { assert, assertPosixPath, getFilePathAbsoluteUserRootDir, getOutDirs, getVirtualFileId, isDev1, isDev1_onConfigureServer, isVirtualFileId, resolveVirtualFileId } from '../../utils.js';
7
7
  import { isVirtualFileIdPageConfigValuesAll } from '../../../shared/virtual-files/virtualFilePageConfigValuesAll.js';
8
8
  import { isVirtualFileIdImportUserCode } from '../../../shared/virtual-files/virtualFileImportUserCode.js';
9
9
  import { vikeConfigDependencies, reloadVikeConfig, isVikeConfigFile } from './v1-design/getVikeConfig.js';
@@ -118,7 +118,7 @@ function isVikeConfigModule(filePathAbsoluteFilesystem) {
118
118
  }
119
119
  function reloadConfig(filePath, config, op) {
120
120
  {
121
- const filePathToShowToUser = pc.dim(getFilePathRelativeToUserRootDir(filePath, config.root, true));
121
+ const filePathToShowToUser = pc.dim(getFilePathAbsoluteUserRootDir(filePath, config.root, true));
122
122
  const msg = `${op} ${filePathToShowToUser}`;
123
123
  logConfigInfo(msg, 'info');
124
124
  }
@@ -58,5 +58,5 @@ type ConfigDefinitionInternal = Omit<ConfigDefinition, 'env'> & {
58
58
  type ConfigDefinitions = Record<string, ConfigDefinitionInternal>;
59
59
  type ConfigDefinitionsBuiltIn = Record<ConfigNameBuiltIn, ConfigDefinitionInternal>;
60
60
  declare const configDefinitionsBuiltIn: ConfigDefinitionsBuiltIn;
61
- type ConfigNameGlobal = 'onPrerenderStart' | 'onBeforeRoute' | 'prerender' | 'extensions' | 'disableAutoFullBuild' | 'includeAssetsImportedByServer' | 'baseAssets' | 'baseServer' | 'redirects' | 'trailingSlash' | 'disableUrlNormalization';
61
+ type ConfigNameGlobal = 'onPrerenderStart' | 'onBeforeRoute' | 'prerender' | 'disableAutoFullBuild' | 'includeAssetsImportedByServer' | 'baseAssets' | 'baseServer' | 'redirects' | 'trailingSlash' | 'disableUrlNormalization';
62
62
  declare const configDefinitionsBuiltInGlobal: Record<ConfigNameGlobal, ConfigDefinitionInternal>;
@@ -103,7 +103,6 @@ const configDefinitionsBuiltInGlobal = {
103
103
  prerender: {
104
104
  env: { config: true }
105
105
  },
106
- extensions: { env: { config: true } },
107
106
  disableAutoFullBuild: { env: { config: true } },
108
107
  includeAssetsImportedByServer: { env: { config: true } },
109
108
  baseAssets: { env: { config: true } },
@@ -1,4 +1,4 @@
1
1
  export { crawlPlusFiles };
2
2
  declare function crawlPlusFiles(userRootDir: string, outDirAbsoluteFilesystem: string, isDev: boolean): Promise<{
3
- filePathRelativeToUserRootDir: string;
3
+ filePathAbsoluteUserRootDir: string;
4
4
  }[]>;
@@ -1,14 +1,14 @@
1
1
  export { crawlPlusFiles };
2
- import { assertPosixPath, assert, toPosixPath, assertWarning, scriptFileExtensionList, scriptFileExtensions, getGlobalObject, humanizeTime } from '../../../../utils.js';
2
+ import { assertPosixPath, assert, toPosixPath, assertWarning, scriptFileExtensionList, scriptFileExtensions, humanizeTime, assertIsSingleModuleInstance, assertIsNotProductionRuntime, isVersionOrAbove } from '../../../../utils.js';
3
3
  import path from 'path';
4
4
  import glob from 'fast-glob';
5
5
  import { exec } from 'child_process';
6
6
  import { promisify } from 'util';
7
7
  import pc from '@brillout/picocolors';
8
8
  const execA = promisify(exec);
9
- const globalObject = getGlobalObject('crawlPlusFiles.ts', {
10
- gitIsMissing: false
11
- });
9
+ assertIsNotProductionRuntime();
10
+ assertIsSingleModuleInstance('crawlPlusFiles.ts');
11
+ let gitIsNotUsable = false;
12
12
  async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev) {
13
13
  assertPosixPath(userRootDir);
14
14
  assertPosixPath(outDirAbsoluteFilesystem);
@@ -43,14 +43,14 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev) {
43
43
  const plusFiles = files.map((p) => {
44
44
  p = toPosixPath(p);
45
45
  assert(!p.startsWith(userRootDir));
46
- const filePathRelativeToUserRootDir = path.posix.join('/', p);
47
- return { filePathRelativeToUserRootDir };
46
+ const filePathAbsoluteUserRootDir = path.posix.join('/', p);
47
+ return { filePathAbsoluteUserRootDir };
48
48
  });
49
49
  return plusFiles;
50
50
  }
51
51
  // Same as fastGlob() but using `$ git ls-files`
52
52
  async function gitLsFiles(userRootDir, outDirRelativeFromUserRootDir) {
53
- if (globalObject.gitIsMissing)
53
+ if (gitIsNotUsable)
54
54
  return null;
55
55
  const ignoreAsPatterns = getIgnoreAsPatterns(outDirRelativeFromUserRootDir);
56
56
  const ignoreAsFilterFn = getIgnoreAsFilterFn(outDirRelativeFromUserRootDir);
@@ -68,14 +68,14 @@ async function gitLsFiles(userRootDir, outDirRelativeFromUserRootDir) {
68
68
  ;
69
69
  [files, filesDeleted] = await Promise.all([
70
70
  // Main command
71
- runCmd(cmd, userRootDir),
71
+ runCmd1(cmd, userRootDir),
72
72
  // Get tracked by deleted files
73
- runCmd('git ls-files --deleted', userRootDir)
73
+ runCmd1('git ls-files --deleted', userRootDir)
74
74
  ]);
75
75
  }
76
76
  catch (err) {
77
- if (await isGitMissing(userRootDir)) {
78
- globalObject.gitIsMissing = true;
77
+ if (await isGitNotUsable(userRootDir)) {
78
+ gitIsNotUsable = true;
79
79
  return null;
80
80
  }
81
81
  throw err;
@@ -119,24 +119,53 @@ function getIgnoreAsFilterFn(outDirRelativeFromUserRootDir) {
119
119
  !file.includes('.telefunc.') &&
120
120
  (outDirRelativeFromUserRootDir === null || !file.startsWith(`${outDirRelativeFromUserRootDir}/`));
121
121
  }
122
- // Whether Git is installed and whether userRootDir is inside a Git repository
123
- async function isGitMissing(userRootDir) {
124
- let res;
125
- try {
126
- res = await execA('git rev-parse --is-inside-work-tree', { cwd: userRootDir });
122
+ // Whether Git is installed and whether we can use it
123
+ async function isGitNotUsable(userRootDir) {
124
+ // Check Git version
125
+ {
126
+ const res = await runCmd2('git --version', userRootDir);
127
+ if ('err' in res)
128
+ return true;
129
+ let { stdout, stderr } = res;
130
+ assert(stderr === '');
131
+ const prefix = 'git version ';
132
+ assert(stdout.startsWith(prefix));
133
+ const gitVersion = stdout.slice(prefix.length);
134
+ // - Works with Git 2.43.1 but also (most certainly) with earlier versions.
135
+ // - We didn't bother test which is the earliest verision that works.
136
+ // - Git 2.32.0 doesn't seem to work: https://github.com/vikejs/vike/discussions/1549
137
+ // - Maybe it's because of StackBlitz: looking at the release notes, Git 2.32.0 should be working.
138
+ if (!isVersionOrAbove(gitVersion, '2.43.1'))
139
+ return true;
127
140
  }
128
- catch {
129
- return true;
141
+ // Is userRootDir inside a Git repository?
142
+ {
143
+ const res = await runCmd2('git rev-parse --is-inside-work-tree', userRootDir);
144
+ if ('err' in res)
145
+ return true;
146
+ let { stdout, stderr } = res;
147
+ assert(stderr === '');
148
+ assert(stdout === 'true');
149
+ return false;
130
150
  }
131
- const { stdout, stderr } = res;
132
- assert(stderr.toString().trim() === '');
133
- assert(stdout.toString().trim() === 'true');
134
- return false;
135
151
  }
136
- async function runCmd(cmd, cwd) {
137
- const res = await execA(cmd, { cwd });
152
+ async function runCmd1(cmd, cwd) {
153
+ const { stdout } = await execA(cmd, { cwd });
138
154
  /* Not always true: https://github.com/vikejs/vike/issues/1440#issuecomment-1892831303
139
155
  assert(res.stderr === '')
140
156
  */
141
- return res.stdout.toString().split('\n').filter(Boolean);
157
+ return stdout.toString().split('\n').filter(Boolean);
158
+ }
159
+ async function runCmd2(cmd, cwd) {
160
+ let res;
161
+ try {
162
+ res = await execA(cmd, { cwd });
163
+ }
164
+ catch (err) {
165
+ return { err };
166
+ }
167
+ let { stdout, stderr } = res;
168
+ stdout = stdout.toString().trim();
169
+ stderr = stderr.toString().trim();
170
+ return { stdout, stderr };
142
171
  }
@@ -39,7 +39,7 @@ type LocationId = string & {
39
39
  *
40
40
  * The value `locationId` is always a user-land path, because Filesystem Routing/Inheritance only applies to the user-land (Vike never uses Filesystem Routing/Inheritance for `node_modules/**`).
41
41
  */
42
- declare function getLocationId(filePathRelativeToUserRootDir: string): LocationId;
42
+ declare function getLocationId(filePathAbsoluteUserRootDir: string): LocationId;
43
43
  /** Filesystem Routing: get the URL */
44
44
  declare function getFilesystemRouteString(locationId: LocationId): string;
45
45
  /**
@@ -16,10 +16,10 @@ import { assert, assertPosixPath, higherFirst } from '../../../../utils.js';
16
16
  */
17
17
  function getLocationId(
18
18
  // We always determine `locationId` from a real user-land file: the `locationId` for Vike extensions is the `locationId` of the the user's `+config.js` that extends the Vike extension.
19
- filePathRelativeToUserRootDir) {
20
- assertPosixPath(filePathRelativeToUserRootDir);
21
- assert(filePathRelativeToUserRootDir.startsWith('/'));
22
- const locationId = removeFilename(filePathRelativeToUserRootDir);
19
+ filePathAbsoluteUserRootDir) {
20
+ assertPosixPath(filePathAbsoluteUserRootDir);
21
+ assert(filePathAbsoluteUserRootDir.startsWith('/'));
22
+ const locationId = removeFilename(filePathAbsoluteUserRootDir);
23
23
  assertLocationId(locationId);
24
24
  return locationId;
25
25
  }
@@ -96,8 +96,8 @@ function removeDirectories(somePath, removeDirs) {
96
96
  somePath = '/';
97
97
  return somePath;
98
98
  }
99
- function removeFilename(filePathRelativeToUserRootDir) {
100
- const filePathParts = filePathRelativeToUserRootDir.split('/');
99
+ function removeFilename(filePathAbsoluteUserRootDir) {
100
+ const filePathParts = filePathAbsoluteUserRootDir.split('/');
101
101
  {
102
102
  const filename = filePathParts.slice(-1)[0];
103
103
  assert(filename.includes('.'));