vike 0.4.165 → 0.4.166-commit-a5e2596

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 (130) 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 +78 -63
  5. package/dist/cjs/node/plugin/plugins/commonConfig/assertResolveAlias.js +14 -1
  6. package/dist/cjs/node/plugin/plugins/config/index.js +1 -1
  7. package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +18 -23
  8. package/dist/cjs/node/plugin/plugins/envVars.js +3 -2
  9. package/dist/cjs/node/plugin/plugins/extractAssetsPlugin.js +9 -9
  10. package/dist/cjs/node/plugin/plugins/fileEnv.js +6 -3
  11. package/dist/cjs/node/plugin/plugins/importUserCode/index.js +6 -2
  12. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +0 -1
  13. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +53 -24
  14. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +6 -6
  15. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +10 -25
  16. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +32 -35
  17. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +18 -26
  18. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +26 -21
  19. package/dist/cjs/node/plugin/shared/getFilePath.js +142 -0
  20. package/dist/cjs/node/plugin/shared/loggerNotProd/errorWithCodeSnippet.js +3 -8
  21. package/dist/cjs/node/plugin/shared/loggerNotProd.js +2 -1
  22. package/dist/cjs/node/plugin/utils.js +1 -1
  23. package/dist/cjs/node/prerender/runPrerender.js +6 -7
  24. package/dist/cjs/node/prerender/utils.js +2 -1
  25. package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +1 -0
  26. package/dist/cjs/node/runtime/html/injectAssets/injectHtmlTags.js +1 -1
  27. package/dist/cjs/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.js +3 -3
  28. package/dist/cjs/node/runtime/renderPage/executeOnRenderHtmlHook.js +2 -1
  29. package/dist/cjs/node/runtime/renderPage/getPageAssets/getManifestEntry.js +31 -33
  30. package/dist/cjs/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.js +9 -8
  31. package/dist/cjs/node/runtime/renderPage/getPageAssets.js +6 -12
  32. package/dist/cjs/node/runtime/renderPage/logErrorHint.js +5 -0
  33. package/dist/cjs/node/runtime/renderPage.js +34 -21
  34. package/dist/cjs/node/runtime/utils.js +0 -1
  35. package/dist/cjs/shared/page-configs/FilePath.js +2 -0
  36. package/dist/cjs/shared/route/abort.js +2 -1
  37. package/dist/cjs/shared/route/executeGuardHook.js +2 -1
  38. package/dist/cjs/shared/route/executeOnBeforeRouteHook.js +2 -1
  39. package/dist/cjs/shared/route/index.js +2 -3
  40. package/dist/cjs/shared/route/utils.js +0 -1
  41. package/dist/cjs/utils/assert.js +2 -0
  42. package/dist/cjs/utils/assertPathIsFilesystemAbsolute.js +1 -0
  43. package/dist/cjs/utils/assertSingleInstance.js +6 -5
  44. package/dist/cjs/utils/assertVersion.js +4 -1
  45. package/dist/cjs/utils/getGlobalObject.js +21 -6
  46. package/dist/cjs/utils/isNpmPackage.js +11 -5
  47. package/dist/cjs/utils/parseUrl.js +8 -1
  48. package/dist/cjs/utils/projectInfo.js +1 -4
  49. package/dist/esm/client/client-routing-runtime/history.d.ts +1 -1
  50. package/dist/esm/client/client-routing-runtime/history.js +5 -5
  51. package/dist/esm/client/client-routing-runtime/onBrowserHistoryNavigation.js +1 -1
  52. package/dist/esm/node/plugin/index.js +1 -1
  53. package/dist/esm/node/plugin/plugins/baseUrls.js +1 -1
  54. package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.js +6 -2
  55. package/dist/esm/node/plugin/plugins/buildConfig.d.ts +1 -1
  56. package/dist/esm/node/plugin/plugins/buildConfig.js +79 -64
  57. package/dist/esm/node/plugin/plugins/commonConfig/assertResolveAlias.js +14 -1
  58. package/dist/esm/node/plugin/plugins/config/index.js +1 -1
  59. package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +19 -24
  60. package/dist/esm/node/plugin/plugins/envVars.js +4 -3
  61. package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +9 -9
  62. package/dist/esm/node/plugin/plugins/fileEnv.js +7 -4
  63. package/dist/esm/node/plugin/plugins/importUserCode/index.js +7 -3
  64. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +1 -1
  65. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +0 -1
  66. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.d.ts +1 -1
  67. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +54 -25
  68. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.d.ts +1 -1
  69. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +6 -6
  70. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.d.ts +1 -1
  71. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +11 -26
  72. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.d.ts +2 -1
  73. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +32 -35
  74. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.d.ts +1 -1
  75. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +18 -26
  76. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +3 -2
  77. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +26 -21
  78. package/dist/esm/node/plugin/shared/getFilePath.d.ts +21 -0
  79. package/dist/esm/node/plugin/shared/getFilePath.js +136 -0
  80. package/dist/esm/node/plugin/shared/loggerNotProd/errorWithCodeSnippet.js +4 -9
  81. package/dist/esm/node/plugin/shared/loggerNotProd.js +2 -1
  82. package/dist/esm/node/plugin/utils.d.ts +1 -1
  83. package/dist/esm/node/plugin/utils.js +1 -1
  84. package/dist/esm/node/prerender/runPrerender.js +2 -3
  85. package/dist/esm/node/prerender/utils.d.ts +2 -1
  86. package/dist/esm/node/prerender/utils.js +2 -1
  87. package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +1 -0
  88. package/dist/esm/node/runtime/html/injectAssets/injectHtmlTags.js +1 -1
  89. package/dist/esm/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.js +1 -1
  90. package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.js +2 -1
  91. package/dist/esm/node/runtime/renderPage/getPageAssets/getManifestEntry.js +32 -34
  92. package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.js +9 -8
  93. package/dist/esm/node/runtime/renderPage/getPageAssets.js +7 -13
  94. package/dist/esm/node/runtime/renderPage/logErrorHint.js +2 -0
  95. package/dist/esm/node/runtime/renderPage.js +34 -21
  96. package/dist/esm/node/runtime/utils.d.ts +0 -1
  97. package/dist/esm/node/runtime/utils.js +0 -1
  98. package/dist/esm/shared/page-configs/Config/PageContextConfig.d.ts +1 -1
  99. package/dist/esm/shared/page-configs/FilePath.d.ts +64 -0
  100. package/dist/esm/shared/page-configs/FilePath.js +1 -0
  101. package/dist/esm/shared/page-configs/PageConfig.d.ts +1 -42
  102. package/dist/esm/shared/route/abort.js +2 -1
  103. package/dist/esm/shared/route/executeGuardHook.js +2 -1
  104. package/dist/esm/shared/route/executeOnBeforeRouteHook.js +2 -1
  105. package/dist/esm/shared/route/index.js +2 -3
  106. package/dist/esm/shared/route/utils.d.ts +0 -1
  107. package/dist/esm/shared/route/utils.js +0 -1
  108. package/dist/esm/utils/assert.js +2 -0
  109. package/dist/esm/utils/assertPathIsFilesystemAbsolute.js +1 -0
  110. package/dist/esm/utils/assertSingleInstance.d.ts +2 -2
  111. package/dist/esm/utils/assertSingleInstance.js +5 -4
  112. package/dist/esm/utils/assertVersion.js +4 -1
  113. package/dist/esm/utils/debug.d.ts +1 -1
  114. package/dist/esm/utils/getGlobalObject.d.ts +6 -1
  115. package/dist/esm/utils/getGlobalObject.js +22 -6
  116. package/dist/esm/utils/isNpmPackage.d.ts +5 -7
  117. package/dist/esm/utils/isNpmPackage.js +15 -4
  118. package/dist/esm/utils/parseUrl.js +8 -1
  119. package/dist/esm/utils/projectInfo.d.ts +2 -2
  120. package/dist/esm/utils/projectInfo.js +1 -4
  121. package/package.json +26 -14
  122. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.js +0 -33
  123. package/dist/cjs/node/runtime/renderPage/getPageAssets/assertClientEntryId.js +0 -19
  124. package/dist/cjs/utils/getFilePathAbsolute.js +0 -70
  125. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.d.ts +0 -5
  126. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.js +0 -27
  127. package/dist/esm/node/runtime/renderPage/getPageAssets/assertClientEntryId.d.ts +0 -2
  128. package/dist/esm/node/runtime/renderPage/getPageAssets/assertClientEntryId.js +0 -16
  129. package/dist/esm/utils/getFilePathAbsolute.d.ts +0 -5
  130. package/dist/esm/utils/getFilePathAbsolute.js +0 -64
@@ -1,33 +1,39 @@
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.assertIsNpmPackageImport = 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)();
7
- function isNpmPackageImport(str) {
7
+ function isNpmPackageImport(str, { cannotBePathAlias }) {
8
+ // We cannot distinguish path alises that look like npm package imports
9
+ (0, assert_js_1.assert)(cannotBePathAlias);
8
10
  const res = parse(str);
9
11
  return res !== null;
10
12
  }
11
13
  exports.isNpmPackageImport = isNpmPackageImport;
14
+ function assertIsNpmPackageImport(str) {
15
+ (0, assert_js_1.assert)(isNpmPackageImport(str, {
16
+ // If `str` is a path alias that looks like an npm package => assertIsNpmPackageImport() is erroneous but that's okay because the assertion will eventually fail for some other user using a disambiguated path alias.
17
+ cannotBePathAlias: true
18
+ }));
19
+ }
20
+ exports.assertIsNpmPackageImport = assertIsNpmPackageImport;
12
21
  function isNpmPackageName(str) {
13
22
  const res = parse(str);
14
23
  return res !== null && res.importPath === null;
15
24
  }
16
- exports.isNpmPackageName = isNpmPackageName;
17
25
  function getNpmPackageName(str) {
18
26
  const res = parse(str);
19
27
  if (!res)
20
28
  return null;
21
29
  return res.pkgName;
22
30
  }
23
- exports.getNpmPackageName = getNpmPackageName;
24
31
  function getNpmPackageImportPath(str) {
25
32
  const res = parse(str);
26
33
  if (!res)
27
34
  return null;
28
35
  return res.importPath;
29
36
  }
30
- exports.getNpmPackageImportPath = getNpmPackageImportPath;
31
37
  function isValidPathAlias(alias) {
32
38
  // Cannot be distinguished from npm package names
33
39
  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-commit-a5e2596';
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, addOnBeforeLogHook, removeFileExtention, unique, assertUsage, injectRollupInputs, normalizeRollupInput, getOutDirs, assertNodeEnv_build, assertIsNpmPackageImport } 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';
@@ -16,6 +16,7 @@ import path from 'path';
16
16
  import { fixServerAssets, fixServerAssets_isEnabled } from './buildConfig/fixServerAssets.js';
17
17
  import { set_constant_ASSETS_MAP } from './importBuild/index.js';
18
18
  import { prependEntriesDir } from '../../shared/prependEntriesDir.js';
19
+ import { getFilePathResolved } from '../shared/getFilePath.js';
19
20
  // @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
20
21
  const importMetaUrl = import.meta.url;
21
22
  const require_ = createRequire(importMetaUrl);
@@ -25,71 +26,81 @@ function buildConfig() {
25
26
  let isSsrBuild;
26
27
  let outDirs;
27
28
  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';
29
+ return [
30
+ {
31
+ name: 'vike:buildConfig:configResolved',
32
+ apply: 'build',
33
+ enforce: 'post',
34
+ configResolved: {
35
+ order: 'post',
36
+ async handler(config_) {
37
+ config = config_;
38
+ assertNodeEnv_build();
39
+ assertRollupInput(config);
40
+ const entries = await getEntries(config);
41
+ assert(Object.keys(entries).length > 0);
42
+ config.build.rollupOptions.input = injectRollupInputs(entries, config);
43
+ addLogHook();
44
+ outDirs = getOutDirs(config);
45
+ {
46
+ isServerAssetsFixEnabled = fixServerAssets_isEnabled() && (await isV1Design(config, false));
47
+ if (isServerAssetsFixEnabled) {
48
+ // https://github.com/vikejs/vike/issues/1339
49
+ config.build.ssrEmitAssets = true;
50
+ // Required if `ssrEmitAssets: true`, see https://github.com/vitejs/vite/pull/11430#issuecomment-1454800934
51
+ config.build.cssMinify = 'esbuild';
52
+ }
50
53
  }
51
54
  }
55
+ },
56
+ config(config) {
57
+ assertNodeEnv_build();
58
+ isSsrBuild = viteIsSSR(config);
59
+ return {
60
+ build: {
61
+ outDir: resolveOutDir(config),
62
+ manifest: manifestTempFile,
63
+ copyPublicDir: !isSsrBuild
64
+ }
65
+ };
66
+ },
67
+ buildStart() {
68
+ assertNodeEnv_build();
52
69
  }
53
70
  },
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');
71
+ {
72
+ name: 'vike:buildConfig:writeBundle',
73
+ apply: 'build',
74
+ // Make sure other writeBundle() hooks are called after this writeBundle() hook.
75
+ // - set_constant_ASSETS_MAP() needs to be called before dist/server/ code is executed.
76
+ // - 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
77
+ enforce: 'pre',
78
+ writeBundle: {
79
+ order: 'pre',
80
+ sequential: true,
81
+ async handler(options, bundle) {
82
+ if (isSsrBuild) {
83
+ // Ideally we'd move dist/_temp_manifest.json to dist/server/client-assets.json instead of dist/assets.json
84
+ // - 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)
85
+ // - We'll able to do so once we replace `$ vite build` with `$ vike build`
86
+ const assetsJsonFilePath = path.posix.join(outDirs.outDirRoot, 'assets.json');
87
+ const clientManifestFilePath = path.posix.join(outDirs.outDirClient, manifestTempFile);
88
+ const serverManifestFilePath = path.posix.join(outDirs.outDirServer, manifestTempFile);
89
+ if (!isServerAssetsFixEnabled) {
90
+ await fs.copyFile(clientManifestFilePath, assetsJsonFilePath);
91
+ }
92
+ else {
93
+ const clientManifestMod = await fixServerAssets(config);
94
+ await fs.writeFile(assetsJsonFilePath, JSON.stringify(clientManifestMod, null, 2), 'utf-8');
95
+ }
96
+ await fs.rm(clientManifestFilePath);
97
+ await fs.rm(serverManifestFilePath);
98
+ await set_constant_ASSETS_MAP(options, bundle);
85
99
  }
86
- await fs.rm(clientManifestFilePath);
87
- await fs.rm(serverManifestFilePath);
88
- await set_constant_ASSETS_MAP(options, bundle);
89
100
  }
90
101
  }
91
102
  }
92
- };
103
+ ];
93
104
  }
94
105
  async function getEntries(config) {
95
106
  const configVike = await getConfigVike(config);
@@ -190,18 +201,22 @@ async function getPageFileEntries(config, includeAssetsImportedByServer) {
190
201
  return pageFileEntries;
191
202
  }
192
203
  function getEntryFromClientEntry(clientEntry, config, addExtractAssetsQuery) {
193
- if (isNpmPackageImport(clientEntry)) {
204
+ if (!clientEntry.startsWith('/')) {
205
+ assertIsNpmPackageImport(clientEntry);
194
206
  const entryTarget = clientEntry;
195
207
  const entryName = prependEntriesDir(clientEntry);
196
208
  return { entryName, entryTarget };
197
209
  }
198
- const filePath = clientEntry;
199
- assertPosixPath(filePath);
200
- assert(filePath.startsWith('/'));
201
- let entryTarget = getFilePathAbsolute(filePath, config);
210
+ const filePathAbsoluteUserRootDir = clientEntry;
211
+ assert(filePathAbsoluteUserRootDir.startsWith('/'));
212
+ const filePath = getFilePathResolved({
213
+ filePathAbsoluteUserRootDir,
214
+ userRootDir: config.root
215
+ });
216
+ let entryTarget = filePath.filePathAbsoluteFilesystem;
202
217
  if (addExtractAssetsQuery)
203
218
  entryTarget = extractAssetsAddQuery(entryTarget);
204
- let entryName = filePath;
219
+ let entryName = filePathAbsoluteUserRootDir;
205
220
  if (addExtractAssetsQuery)
206
221
  entryName = extractAssetsAddQuery(entryName);
207
222
  entryName = removeFileExtention(entryName);
@@ -1,8 +1,21 @@
1
1
  export { assertResolveAlias };
2
2
  import { assert, assertUsage, assertWarning, isValidPathAlias } from '../../utils.js';
3
3
  import pc from '@brillout/picocolors';
4
- // TODO/v1-release: replace assertWarning() with assertUsage()
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
5
16
  function assertResolveAlias(config) {
17
+ // TODO: re-implement warning https://github.com/vikejs/vike/issues/1567
18
+ return;
6
19
  const aliases = getAliases(config);
7
20
  const errPrefix = config.configFile || 'Your Vite configuration';
8
21
  const errSuffix1 = 'see https://vike.dev/path-aliases#vite';
@@ -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,10 +1,12 @@
1
1
  export { determineOptimizeDeps };
2
2
  import { findPageFiles } from '../../shared/findPageFiles.js';
3
- import { assert, getFilePathAbsolute, isNpmPackageImport, unique } from '../../utils.js';
3
+ import { assert, assertIsNpmPackageImport, createDebugger, 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';
7
7
  import { virtualFileIdImportUserCodeClientCR, virtualFileIdImportUserCodeClientSR } from '../../../shared/virtual-files/virtualFileImportUserCode.js';
8
+ import { getFilePathResolved } from '../../shared/getFilePath.js';
9
+ const debug = createDebugger('vike:optimizeDeps');
8
10
  async function determineOptimizeDeps(config, isDev) {
9
11
  const { pageConfigs } = await getVikeConfig(config, isDev);
10
12
  const { entries, include } = await getPageDeps(config, pageConfigs, isDev);
@@ -21,7 +23,11 @@ async function determineOptimizeDeps(config, isDev) {
21
23
  */
22
24
  config.optimizeDeps.include = [...include, ...normalizeInclude(config.optimizeDeps.include)];
23
25
  config.optimizeDeps.entries = [...entries, ...normalizeEntries(config.optimizeDeps.entries)];
24
- // console.log('config.optimizeDeps', { entries: config.optimizeDeps.entries, include: config.optimizeDeps.include })
26
+ if (debug.isEnabled)
27
+ debug('config.optimizeDeps', {
28
+ 'config.optimizeDeps.entries': config.optimizeDeps.entries,
29
+ 'config.optimizeDeps.include': config.optimizeDeps.include
30
+ });
25
31
  }
26
32
  async function getPageDeps(config, pageConfigs, isDev) {
27
33
  let entries = [];
@@ -35,7 +41,7 @@ async function getPageDeps(config, pageConfigs, isDev) {
35
41
  const { definedAt, configEnv } = configValueSource;
36
42
  if (!configEnv.client)
37
43
  return;
38
- if (definedAt.filePathRelativeToUserRootDir !== null) {
44
+ if (definedAt.filePathAbsoluteUserRootDir !== null) {
39
45
  const { filePathAbsoluteFilesystem } = definedAt;
40
46
  assert(filePathAbsoluteFilesystem);
41
47
  // Surprisingly Vite expects entries to be absolute paths
@@ -44,24 +50,10 @@ async function getPageDeps(config, pageConfigs, isDev) {
44
50
  else {
45
51
  // Adding definedAt.filePathAbsoluteFilesystem doesn't work for npm packages, I guess because of Vite's config.server.fs.allow
46
52
  const { importPathAbsolute } = definedAt;
47
- assert(importPathAbsolute);
48
- // We need to differentiate between npm package imports and path aliases.
49
- // There are path aliases that cannot be distinguished from npm package names.
50
- // We recommend users to use the '#' prefix convention for path aliases, see https://vike.dev/path-aliases#vite and assertResolveAlias()
51
- if (isNpmPackageImport(importPathAbsolute)) {
52
- // isNpmPackageImport() returns false for a path alias like #root/renderer/onRenderClient
53
- assert(!importPathAbsolute.startsWith('#'));
54
- include.push(importPathAbsolute);
55
- }
56
- else {
57
- /* Path aliases, e.g.:
58
- * ```js
59
- * // /renderer/+config.js
60
- * import onRenderClient from '#root/renderer/onRenderClient'
61
- * ```
62
- */
63
- entries.push(importPathAbsolute);
64
- }
53
+ assert(importPathAbsolute); // Help TS
54
+ // Shouldn't be a path alias, as path aliases would need to be added to config.optimizeDeps.entries instead of config.optimizeDeps.include
55
+ assertIsNpmPackageImport(importPathAbsolute);
56
+ include.push(importPathAbsolute);
65
57
  }
66
58
  });
67
59
  });
@@ -69,9 +61,12 @@ async function getPageDeps(config, pageConfigs, isDev) {
69
61
  // V0.4 design
70
62
  {
71
63
  const pageFiles = await findPageFiles(config, ['.page', '.page.client'], isDev);
72
- pageFiles.forEach((filePath) => {
73
- const entry = getFilePathAbsolute(filePath, config);
74
- entries.push(entry);
64
+ const userRootDir = config.root;
65
+ pageFiles.forEach((filePathAbsoluteUserRootDir) => {
66
+ const entry = getFilePathResolved({ filePathAbsoluteUserRootDir, userRootDir });
67
+ const { filePathAbsoluteFilesystem } = entry;
68
+ assert(filePathAbsoluteFilesystem);
69
+ entries.push(filePathAbsoluteFilesystem);
75
70
  });
76
71
  }
77
72
  entries = unique(entries);
@@ -2,8 +2,9 @@ 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, lowerFirst } from '../utils.js';
6
6
  import { sourceMapPassthrough } from '../shared/rollupSourceMap.js';
7
+ import { getModuleFilePath } from '../shared/getFilePath.js';
7
8
  function envVarsPlugin() {
8
9
  let envsAll;
9
10
  let config;
@@ -45,10 +46,10 @@ function envVarsPlugin() {
45
46
  if (isPrivate && isClientSide) {
46
47
  if (!code.includes(envStatement))
47
48
  return;
48
- const filePathToShowToUser = getFilePathRelativeToUserRootDir(id, config.root);
49
+ const modulePath = getModuleFilePath(id, config);
49
50
  const errMsgAddendum = isBuild ? '' : ' (Vike will prevent your app from building for production)';
50
51
  const keyPublic = `${publicPrefix}${envName}`;
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`;
52
+ const errMsg = `${envStatement} is used in client-side file ${modulePath} 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`;
52
53
  if (isBuild) {
53
54
  assertUsage(false, errMsg);
54
55
  }
@@ -119,12 +119,6 @@ function extractAssetsPlugin() {
119
119
  {
120
120
  name: 'vike:extractAssets-3',
121
121
  apply: 'build',
122
- async configResolved(config_) {
123
- configVike = await getConfigVike(config_);
124
- config = config_;
125
- vikeConfig = await getVikeConfig(config, false);
126
- isServerAssetsFixEnabled = fixServerAssets_isEnabled() && (await isV1Design(config, false));
127
- },
128
122
  load(id) {
129
123
  if (!isVirtualFileId(id))
130
124
  return undefined;
@@ -141,9 +135,15 @@ function extractAssetsPlugin() {
141
135
  },
142
136
  {
143
137
  name: 'vike:extractAssets-4',
144
- configResolved(config) {
145
- // https://github.com/vikejs/vike/issues/1060
146
- assertUsage(!config.plugins.find((p) => p.name === 'vite-tsconfig-paths'), 'vite-tsconfig-paths not supported, remove it and use vite.config.js#resolve.alias instead');
138
+ async configResolved(config_) {
139
+ configVike = await getConfigVike(config_);
140
+ config = config_;
141
+ vikeConfig = await getVikeConfig(config, false);
142
+ isServerAssetsFixEnabled = fixServerAssets_isEnabled() && (await isV1Design(config, false));
143
+ if (!isServerAssetsFixEnabled) {
144
+ // https://github.com/vikejs/vike/issues/1060
145
+ assertUsage(!config.plugins.find((p) => p.name === 'vite-tsconfig-paths'), 'vite-tsconfig-paths not supported, remove it and use vite.config.js#resolve.alias instead');
146
+ }
147
147
  }
148
148
  }
149
149
  ];
@@ -1,8 +1,9 @@
1
1
  export { fileEnv };
2
- import { assert, assertUsage, assertWarning, capitalizeFirstLetter, getFilePathRelativeToUserRootDir } from '../utils.js';
2
+ import { assert, assertUsage, assertWarning, capitalizeFirstLetter } from '../utils.js';
3
3
  import { extractAssetsRE } from './extractAssetsPlugin.js';
4
4
  import { extractExportNamesRE } from './extractExportNamesPlugin.js';
5
5
  import pc from '@brillout/picocolors';
6
+ import { getModuleFilePath } from '../shared/getFilePath.js';
6
7
  function fileEnv() {
7
8
  let config;
8
9
  let isDev = false;
@@ -39,11 +40,13 @@ function fileEnv() {
39
40
  // resolved is null when import path is erroneous and doesn't actually point to a file
40
41
  if (!resolved)
41
42
  return;
42
- const modulePath = resolved.id.split('?')[0];
43
+ const moduleId = resolved.id;
44
+ const modulePath = moduleId.split('?')[0];
43
45
  // `.server.js` and `.client.js` should only apply to user files
44
46
  if (modulePath.includes('/node_modules/'))
45
47
  return;
46
48
  // TODO/v1-release: remove
49
+ // - I don't remember exactly, but I think I've added `TODO/v1-release: remove` because I vaguely remember that we can remove this after we remove the 0.4 design.
47
50
  if (modulePath.endsWith('.css'))
48
51
  return;
49
52
  const isServerSide = options?.ssr;
@@ -55,7 +58,7 @@ function fileEnv() {
55
58
  return;
56
59
  // Show error message
57
60
  let errMsg;
58
- let modulePathPretty = getFilePathRelativeToUserRootDir(modulePath, config.root);
61
+ let modulePathPretty = getModuleFilePath(moduleId, config);
59
62
  modulePathPretty = modulePathPretty.replaceAll(suffix, pc.bold(suffix));
60
63
  errMsg = `${capitalizeFirstLetter(envExpect)}-only module ${modulePathPretty} (https://vike.dev/file-env) imported on the ${envActual}-side`;
61
64
  if (importer &&
@@ -63,7 +66,7 @@ function fileEnv() {
63
66
  !importer.includes('virtual:vike:') &&
64
67
  // I don't know why and who sets importer to '<stdin>' (I guess Vite?)
65
68
  importer !== '<stdin>') {
66
- const importerPath = getFilePathRelativeToUserRootDir(importer.split('?')[0], config.root);
69
+ const importerPath = getModuleFilePath(importer, config);
67
70
  errMsg += ` by ${importerPath}`;
68
71
  }
69
72
  if (isDev) {
@@ -3,12 +3,13 @@ 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, 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';
10
10
  import pc from '@brillout/picocolors';
11
11
  import { logConfigInfo, clearLogs } from '../../shared/loggerNotProd.js';
12
+ import { getFilePathResolved } from '../../shared/getFilePath.js';
12
13
  function importUserCode() {
13
14
  let config;
14
15
  let configVike;
@@ -118,8 +119,11 @@ function isVikeConfigModule(filePathAbsoluteFilesystem) {
118
119
  }
119
120
  function reloadConfig(filePath, config, op) {
120
121
  {
121
- const filePathToShowToUser = pc.dim(getFilePathRelativeToUserRootDir(filePath, config.root, true));
122
- const msg = `${op} ${filePathToShowToUser}`;
122
+ const { filePathToShowToUserResolved } = getFilePathResolved({
123
+ filePathAbsoluteFilesystem: filePath,
124
+ userRootDir: config.root
125
+ });
126
+ const msg = `${op} ${pc.dim(filePathToShowToUserResolved)}`;
123
127
  logConfigInfo(msg, 'info');
124
128
  }
125
129
  reloadVikeConfig(config.root, getOutDirs(config).outDirRoot);
@@ -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 } },