vike 0.4.209 → 0.4.211-commit-be2fe23

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 (47) hide show
  1. package/dist/cjs/node/plugin/plugins/buildConfig/fixServerAssets.js +81 -26
  2. package/dist/cjs/node/plugin/plugins/buildConfig.js +1 -1
  3. package/dist/cjs/node/plugin/plugins/commonConfig.js +17 -9
  4. package/dist/cjs/node/plugin/plugins/config/index.js +9 -3
  5. package/dist/cjs/node/plugin/plugins/devConfig/index.js +14 -6
  6. package/dist/cjs/node/plugin/plugins/importUserCode/index.js +1 -1
  7. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +3 -3
  8. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js +38 -11
  9. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +20 -35
  10. package/dist/cjs/node/plugin/plugins/previewConfig.js +5 -4
  11. package/dist/cjs/node/plugin/plugins/setGlobalContext.js +1 -1
  12. package/dist/cjs/node/plugin/utils.js +1 -0
  13. package/dist/cjs/node/runtime/renderPage/getPageAssets/retrieveAssetsDev.js +7 -7
  14. package/dist/cjs/node/runtime/renderPage/logErrorHint.js +11 -7
  15. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  16. package/dist/cjs/utils/assertVersion.js +2 -0
  17. package/dist/cjs/utils/isDev.js +11 -16
  18. package/dist/cjs/utils/isDocker.js +45 -0
  19. package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +13 -2
  20. package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.d.ts +4 -1
  21. package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.js +79 -24
  22. package/dist/esm/node/plugin/plugins/buildConfig.js +1 -1
  23. package/dist/esm/node/plugin/plugins/commonConfig.js +18 -10
  24. package/dist/esm/node/plugin/plugins/config/index.js +10 -4
  25. package/dist/esm/node/plugin/plugins/devConfig/index.d.ts +3 -1
  26. package/dist/esm/node/plugin/plugins/devConfig/index.js +12 -7
  27. package/dist/esm/node/plugin/plugins/importUserCode/index.js +2 -2
  28. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +3 -3
  29. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.d.ts +11 -1
  30. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js +39 -12
  31. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +21 -36
  32. package/dist/esm/node/plugin/plugins/previewConfig.js +6 -5
  33. package/dist/esm/node/plugin/plugins/setGlobalContext.js +2 -2
  34. package/dist/esm/node/plugin/utils.d.ts +1 -0
  35. package/dist/esm/node/plugin/utils.js +1 -0
  36. package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsDev.js +7 -7
  37. package/dist/esm/node/runtime/renderPage/logErrorHint.js +11 -7
  38. package/dist/esm/shared/types.d.ts +6 -0
  39. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  40. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  41. package/dist/esm/utils/assertVersion.js +2 -0
  42. package/dist/esm/utils/isDev.d.ts +6 -5
  43. package/dist/esm/utils/isDev.js +11 -16
  44. package/dist/esm/utils/isDocker.d.ts +2 -0
  45. package/dist/esm/utils/isDocker.js +40 -0
  46. package/dist/esm/utils/projectInfo.d.ts +1 -1
  47. package/package.json +2 -2
@@ -61,13 +61,13 @@ function collectCss(mod, styleUrls, visitedModules, importer) {
61
61
  });
62
62
  }
63
63
  function isStyle(mod) {
64
- if (utils_js_1.styleFileRE.test(mod.url) || (mod.id && /\?vue&type=style/.test(mod.id))) {
65
- // `mod.type` seems broken
66
- (0, utils_js_1.assert)(mod.type === 'js');
67
- // logModule(mod)
68
- return true;
69
- }
70
- return false;
64
+ return (
65
+ // CSS-in-JS libraries such as [wyw-in-js](https://github.com/vikejs/vike/issues/2039)
66
+ mod.type === 'css' ||
67
+ // .css, .less, ...
68
+ utils_js_1.styleFileRE.test(mod.url) ||
69
+ // CSS of .vue files
70
+ (mod.id && /\?vue&type=style/.test(mod.id)));
71
71
  }
72
72
  /*
73
73
  function logModule(mod: ModuleNode) {
@@ -10,10 +10,15 @@ const picocolors_1 = __importDefault(require("@brillout/picocolors"));
10
10
  const hintDefault = 'The error could be a CJS/ESM issue, see https://vike.dev/broken-npm-package';
11
11
  const hintLinkPrefix = 'To fix this error, see ';
12
12
  const errorsMisc = [
13
+ {
14
+ errMsg: 'window is not defined',
15
+ link: 'https://vike.dev/hints#window-is-not-defined',
16
+ mustMentionNodeModules: false
17
+ },
13
18
  {
14
19
  errMsg: 'jsxDEV is not a function',
15
20
  link: 'https://github.com/vikejs/vike/issues/1469#issuecomment-1919518096',
16
- shouldMentionNodeModules: false
21
+ mustMentionNodeModules: false
17
22
  },
18
23
  {
19
24
  // ```
@@ -21,7 +26,7 @@ const errorsMisc = [
21
26
  // ```
22
27
  errMsg: 'assets.json',
23
28
  link: 'https://vike.dev/getGlobalContext',
24
- shouldMentionNodeModules: false
29
+ mustMentionNodeModules: false
25
30
  }
26
31
  ];
27
32
  const errorsReact = [
@@ -29,7 +34,7 @@ const errorsReact = [
29
34
  errMsg: 'Element type is invalid: expected a string (for built-in components) or a class/function (for composite components)',
30
35
  link: 'https://vike.dev/broken-npm-package#react-invalid-component',
31
36
  // The stack trace can be user-land while the import is coming from node_modules
32
- shouldMentionNodeModules: false
37
+ mustMentionNodeModules: false
33
38
  },
34
39
  {
35
40
  // React's "Invalid hook call.", see https://github.com/vikejs/vike/discussions/1637#discussioncomment-9424712
@@ -42,7 +47,7 @@ const errorsCjsEsm_withPreciseLink = [
42
47
  errMsg: /Named export.*not found/i,
43
48
  link: 'https://vike.dev/broken-npm-package#named-export-not-found',
44
49
  // It seems that this always points to an npm package import.
45
- shouldMentionNodeModules: false
50
+ mustMentionNodeModules: false
46
51
  }
47
52
  ];
48
53
  const errorsCjsEsm = [
@@ -56,7 +61,7 @@ const errorsCjsEsm = [
56
61
  {
57
62
  errMsg: 'Cannot use import statement',
58
63
  // Since user code is always ESM, this error must always originate from an npm package.
59
- shouldMentionNodeModules: false
64
+ mustMentionNodeModules: false
60
65
  },
61
66
  { errMsg: 'is not exported' },
62
67
  { errMsg: 'Cannot read properties of undefined' },
@@ -65,7 +70,6 @@ const errorsCjsEsm = [
65
70
  { errMsg: 'require is not a function' },
66
71
  { errMsg: 'exports is not defined' },
67
72
  { errMsg: 'module is not defined' },
68
- { errMsg: 'window is not defined' },
69
73
  { errMsg: 'not defined in ES' },
70
74
  { errMsg: "Unexpected token 'export'" }
71
75
  ];
@@ -107,7 +111,7 @@ function isKnownError(error) {
107
111
  ].find((knownErorr) => {
108
112
  if (!includesLowercase(anywhere, knownErorr.errMsg))
109
113
  return false;
110
- if (knownErorr.shouldMentionNodeModules !== false && !includesLowercase(anywhere, 'node_modules'))
114
+ if (knownErorr.mustMentionNodeModules !== false && !includesLowercase(anywhere, 'node_modules'))
111
115
  return false;
112
116
  return true;
113
117
  });
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PROJECT_VERSION = void 0;
4
4
  // Automatically updated by @brillout/release-me
5
- exports.PROJECT_VERSION = '0.4.209';
5
+ exports.PROJECT_VERSION = '0.4.211-commit-be2fe23';
@@ -4,6 +4,8 @@ exports.assertVersion = assertVersion;
4
4
  exports.isVersionOrAbove = isVersionOrAbove;
5
5
  const assert_js_1 = require("./assert.js");
6
6
  function assertVersion(dependencyName, versionActual, versionExpected) {
7
+ (0, assert_js_1.assert)(versionActual);
8
+ (0, assert_js_1.assert)(versionExpected);
7
9
  (0, assert_js_1.assertUsage)(isVersionOrAbove(versionActual, versionExpected), `${dependencyName} ${versionActual} isn't supported, use ${dependencyName} >= ${versionExpected} instead.`);
8
10
  }
9
11
  function isVersionOrAbove(versionActual, versionExpected) {
@@ -1,23 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isDev2 = isDev2;
4
- exports.isDev3 = isDev3;
3
+ exports.isDevCheck = isDevCheck;
4
+ exports.applyDev = applyDev;
5
+ exports.applyPreview = applyPreview;
5
6
  const assert_js_1 = require("./assert.js");
6
- function isDev3(configEnv) {
7
+ function isDevCheck(configEnv) {
7
8
  const { isPreview, command } = configEnv;
8
- if (command !== 'serve')
9
- return false;
10
- // `isPreview` is `undefined` in older Vite versions.
11
- // https://github.com/vitejs/vite/pull/14855
12
- // https://github.com/vitejs/vite/pull/15695O
13
- // - Released at `vite@5.1.0`: https://github.com/vitejs/vite/blob/main/packages/vite/CHANGELOG.md#510-beta4-2024-01-26:~:text=fix(preview)%3A%20set%20isPreview%20true%20(%2315695)%20(93fce55)%2C%20closes%20%2315695
9
+ // Released at vite@5.1.0 which is guaranteed with `assertVersion('Vite', version, '5.1.0')`
14
10
  (0, assert_js_1.assert)(typeof isPreview === 'boolean');
15
- return !isPreview;
11
+ return command === 'serve' && !isPreview;
16
12
  }
17
- function isDev2(config) {
18
- const isDev = config.command === 'serve' &&
19
- // Mode is 'development' by default: https://github.com/vitejs/vite/blob/bf9c49f521b7a6730231c35754d5e1f9c3a6a16e/packages/vite/src/node/config.ts#L383
20
- // Note that user can override this: https://github.com/vitejs/vite/blob/bf9c49f521b7a6730231c35754d5e1f9c3a6a16e/packages/vite/src/node/cli.ts#L126
21
- config.mode === 'development';
22
- return isDev;
13
+ function applyDev(_, env) {
14
+ return isDevCheck(env);
15
+ }
16
+ function applyPreview(_, env) {
17
+ return env.command == 'serve' && !isDevCheck(env);
23
18
  }
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.isDocker = isDocker;
7
+ const node_fs_1 = __importDefault(require("node:fs"));
8
+ const assertIsNotProductionRuntime_js_1 = require("./assertIsNotProductionRuntime.js");
9
+ (0, assertIsNotProductionRuntime_js_1.assertIsNotProductionRuntime)();
10
+ function isDocker() {
11
+ return hasContainerEnv() || isDockerContainer();
12
+ }
13
+ // Podman detection
14
+ // https://github.com/sindresorhus/is-inside-container/blob/7f0dc884bda6b368d89ec90e77f2bef3b87e6f09/index.js
15
+ function hasContainerEnv() {
16
+ try {
17
+ node_fs_1.default.statSync('/run/.containerenv');
18
+ return true;
19
+ }
20
+ catch {
21
+ return false;
22
+ }
23
+ }
24
+ // Docker detection
25
+ // https://github.com/sindresorhus/is-docker/blob/1cfd2b5bfa9fbd87d2b22e6f514e7d5cc60a794b/index.js
26
+ function isDockerContainer() {
27
+ return hasDockerEnv() || hasDockerCGroup();
28
+ }
29
+ function hasDockerEnv() {
30
+ try {
31
+ node_fs_1.default.statSync('/.dockerenv');
32
+ return true;
33
+ }
34
+ catch {
35
+ return false;
36
+ }
37
+ }
38
+ function hasDockerCGroup() {
39
+ try {
40
+ return node_fs_1.default.readFileSync('/proc/self/cgroup', 'utf8').includes('docker');
41
+ }
42
+ catch {
43
+ return false;
44
+ }
45
+ }
@@ -23,6 +23,7 @@ import { getCurrentUrl } from '../shared/getCurrentUrl.js';
23
23
  const globalObject = getGlobalObject('renderPageClientSide.ts', (() => {
24
24
  const { promise: firstRenderStartPromise, resolve: firstRenderStartPromiseResolve } = genPromise();
25
25
  return {
26
+ previousPageContext: null,
26
27
  renderCounter: 0,
27
28
  firstRenderStartPromise,
28
29
  firstRenderStartPromiseResolve
@@ -218,10 +219,20 @@ async function renderPageClientSide(renderArgs) {
218
219
  isBackwardNavigation,
219
220
  isClientSideNavigation,
220
221
  isHydration: isFirstRender && !isForErrorPage,
221
- // Make it public as `pageContext.previous`? Maybe after https://github.com/vikejs/vike/issues/1268
222
- _previousPageContext: previousPageContext,
222
+ previousPageContext,
223
223
  ...pageContextInitClient
224
224
  });
225
+ // TODO/next-major-release: remove
226
+ Object.defineProperty(pageContext, '_previousPageContext', {
227
+ get() {
228
+ assertWarning(false, 'pageContext._previousPageContext has been renamed pageContext.previousPageContext', {
229
+ showStackTrace: true,
230
+ onlyOnce: true
231
+ });
232
+ return previousPageContext;
233
+ },
234
+ enumerable: false
235
+ });
225
236
  {
226
237
  const pageContextFromAllRewrites = getPageContextFromAllRewrites(pageContextsFromRewrite);
227
238
  assert(!('urlOriginal' in pageContextFromAllRewrites));
@@ -13,7 +13,10 @@ import { ResolvedConfig } from 'vite';
13
13
  */
14
14
  declare function fixServerAssets_isEnabled(): boolean;
15
15
  /** https://github.com/vikejs/vike/issues/1339 */
16
- declare function fixServerAssets(config: ResolvedConfig): Promise<ViteManifest>;
16
+ declare function fixServerAssets(config: ResolvedConfig): Promise<{
17
+ clientManifestMod: ViteManifest;
18
+ serverManifestMod: ViteManifest;
19
+ }>;
17
20
  declare function fixServerAssets_assertCssCodeSplit(config: ResolvedConfig): void;
18
21
  declare function fixServerAssets_assertCssTarget_populate(config: ResolvedConfig): void;
19
22
  declare function fixServerAssets_assertCssTarget(config: ResolvedConfig): Promise<void>;
@@ -4,6 +4,7 @@ export { fixServerAssets_assertCssCodeSplit };
4
4
  export { fixServerAssets_assertCssTarget };
5
5
  export { fixServerAssets_assertCssTarget_populate };
6
6
  import fs from 'fs/promises';
7
+ import fs_sync from 'fs';
7
8
  import path from 'path';
8
9
  import { existsSync } from 'fs';
9
10
  import { assert, assertWarning, getOutDirs, isEqualStringList, pLimit, unique, viteIsSSR } from '../../utils.js';
@@ -28,9 +29,9 @@ async function fixServerAssets(config) {
28
29
  const outDirs = getOutDirs(config);
29
30
  const clientManifest = await loadManifest(outDirs.outDirClient);
30
31
  const serverManifest = await loadManifest(outDirs.outDirServer);
31
- const { clientManifestMod, filesToCopy } = addServerAssets(clientManifest, serverManifest);
32
- await copyAssets(filesToCopy, config);
33
- return clientManifestMod;
32
+ const { clientManifestMod, serverManifestMod, filesToCopy, filesToRemove } = addServerAssets(clientManifest, serverManifest);
33
+ await copyAssets(filesToCopy, filesToRemove, config);
34
+ return { clientManifestMod, serverManifestMod };
34
35
  }
35
36
  async function loadManifest(outDir) {
36
37
  const manifestFilePath = path.posix.join(outDir, manifestTempFile);
@@ -40,26 +41,32 @@ async function loadManifest(outDir) {
40
41
  assert(manifest);
41
42
  return manifest;
42
43
  }
43
- async function copyAssets(filesToCopy, config) {
44
+ async function copyAssets(filesToCopy, filesToRemove, config) {
44
45
  const { outDirClient, outDirServer } = getOutDirs(config);
45
46
  const assetsDir = getAssetsDir(config);
46
47
  const assetsDirServer = path.posix.join(outDirServer, assetsDir);
47
- if (!filesToCopy.length)
48
+ if (!filesToCopy.length && !filesToRemove.length && !existsSync(assetsDirServer))
48
49
  return;
49
50
  assert(existsSync(assetsDirServer));
50
51
  const concurrencyLimit = pLimit(10);
51
- await Promise.all(filesToCopy.map((file) => concurrencyLimit(() =>
52
- // TODO: move instead of copying
53
- fs.cp(path.posix.join(outDirServer, file), path.posix.join(outDirClient, file), {
54
- recursive: true
55
- }))));
52
+ await Promise.all(filesToCopy.map((file) => concurrencyLimit(async () => {
53
+ const source = path.posix.join(outDirServer, file);
54
+ const target = path.posix.join(outDirClient, file);
55
+ await fs.mkdir(path.posix.dirname(target), { recursive: true });
56
+ await fs.rename(source, target);
57
+ })));
58
+ filesToRemove.forEach((file) => {
59
+ const filePath = path.posix.join(outDirServer, file);
60
+ fs_sync.unlinkSync(filePath);
61
+ });
56
62
  /* 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
57
63
  await fs.rm(assetsDirServer, { recursive: true })
58
64
  */
65
+ removeEmptyDirectories(assetsDirServer);
59
66
  }
60
67
  // Add serverManifest resources to clientManifest
61
68
  function addServerAssets(clientManifest, serverManifest) {
62
- var _a, _b;
69
+ var _a, _b, _c, _d;
63
70
  const entriesClient = new Map();
64
71
  const entriesServer = new Map();
65
72
  for (const [key, entry] of Object.entries(clientManifest)) {
@@ -76,36 +83,64 @@ function addServerAssets(clientManifest, serverManifest) {
76
83
  continue;
77
84
  const resources = collectResources(entry, serverManifest);
78
85
  assert(!entriesServer.has(pageId));
79
- entriesServer.set(pageId, resources);
86
+ entriesServer.set(pageId, { key, ...resources });
80
87
  }
81
88
  let filesToCopy = [];
89
+ let filesToRemove = [];
82
90
  for (const [pageId, entryClient] of entriesClient.entries()) {
91
+ const entryServer = entriesServer.get(pageId);
92
+ if (!entryServer)
93
+ continue;
83
94
  const cssToAdd = [];
95
+ const cssToRemove = [];
84
96
  const assetsToAdd = [];
85
- const entryServer = entriesServer.get(pageId);
86
- if (entryServer) {
87
- cssToAdd.push(...entryServer.css
88
- .filter((cssServer) => !entryClient.css.some((cssClient) => cssServer.hash === cssClient.hash))
89
- .map((css) => css.src));
90
- assetsToAdd.push(...entryServer.assets
91
- .filter((assertServer) => !entryClient.assets.some((assetClient) => assertServer.hash === assetClient.hash))
92
- .map((asset) => asset.src));
93
- }
94
- const { key } = entryClient;
97
+ const assetsToRemove = [];
98
+ entryServer.css.forEach((cssServer) => {
99
+ if (!entryClient.css.some((cssClient) => cssServer.hash === cssClient.hash)) {
100
+ cssToAdd.push(cssServer.src);
101
+ }
102
+ else {
103
+ cssToRemove.push(cssServer.src);
104
+ }
105
+ });
106
+ entryServer.assets.forEach((assetServer) => {
107
+ if (!entryClient.assets.some((assetClient) => assetServer.hash === assetClient.hash)) {
108
+ assetsToAdd.push(assetServer.src);
109
+ }
110
+ else {
111
+ assetsToRemove.push(assetServer.src);
112
+ }
113
+ });
95
114
  if (cssToAdd.length) {
115
+ const { key } = entryClient;
96
116
  filesToCopy.push(...cssToAdd);
97
117
  (_a = clientManifest[key]).css ?? (_a.css = []);
98
118
  clientManifest[key].css?.push(...cssToAdd);
99
119
  }
120
+ if (cssToRemove.length) {
121
+ const { key } = entryServer;
122
+ filesToRemove.push(...cssToRemove);
123
+ (_b = serverManifest[key]).css ?? (_b.css = []);
124
+ serverManifest[key].css = serverManifest[key].css.filter((entry) => !cssToRemove.includes(entry));
125
+ }
100
126
  if (assetsToAdd.length) {
127
+ const { key } = entryClient;
101
128
  filesToCopy.push(...assetsToAdd);
102
- (_b = clientManifest[key]).assets ?? (_b.assets = []);
129
+ (_c = clientManifest[key]).assets ?? (_c.assets = []);
103
130
  clientManifest[key].assets?.push(...assetsToAdd);
104
131
  }
132
+ if (assetsToRemove.length) {
133
+ const { key } = entryServer;
134
+ filesToRemove.push(...assetsToRemove);
135
+ (_d = serverManifest[key]).assets ?? (_d.assets = []);
136
+ serverManifest[key].assets = serverManifest[key].assets.filter((entry) => !assetsToRemove.includes(entry));
137
+ }
105
138
  }
106
139
  const clientManifestMod = clientManifest;
140
+ const serverManifestMod = serverManifest;
107
141
  filesToCopy = unique(filesToCopy);
108
- return { clientManifestMod, filesToCopy };
142
+ filesToRemove = unique(filesToRemove).filter((file) => !filesToCopy.includes(file));
143
+ return { clientManifestMod, serverManifestMod, filesToCopy, filesToRemove };
109
144
  }
110
145
  function getPageId(key) {
111
146
  // Normalize from:
@@ -189,3 +224,23 @@ async function fixServerAssets_assertCssTarget(config) {
189
224
  function resolveCssTarget(target) {
190
225
  return target.css ?? target.global;
191
226
  }
227
+ /**
228
+ * Recursively remove all empty directories in a given directory.
229
+ */
230
+ function removeEmptyDirectories(dirPath) {
231
+ // Read the directory contents
232
+ const files = fs_sync.readdirSync(dirPath);
233
+ // Iterate through the files and subdirectories
234
+ for (const file of files) {
235
+ const fullPath = path.join(dirPath, file);
236
+ // Check if it's a directory
237
+ if (fs_sync.statSync(fullPath).isDirectory()) {
238
+ // Recursively clean up the subdirectory
239
+ removeEmptyDirectories(fullPath);
240
+ }
241
+ }
242
+ // Re-check the directory; remove it if it's now empty
243
+ if (fs_sync.readdirSync(dirPath).length === 0) {
244
+ fs_sync.rmdirSync(dirPath);
245
+ }
246
+ }
@@ -94,7 +94,7 @@ function buildConfig() {
94
94
  await fs.copyFile(clientManifestFilePath, assetsJsonFilePath);
95
95
  }
96
96
  else {
97
- const clientManifestMod = await fixServerAssets(config);
97
+ const { clientManifestMod } = await fixServerAssets(config);
98
98
  await fs.writeFile(assetsJsonFilePath, JSON.stringify(clientManifestMod, null, 2), 'utf-8');
99
99
  }
100
100
  await fs.rm(clientManifestFilePath);
@@ -1,5 +1,5 @@
1
1
  export { commonConfig };
2
- import { assert, assertUsage, assertWarning, findPackageJson } from '../utils.js';
2
+ import { assert, assertUsage, assertWarning, findPackageJson, isDocker } from '../utils.js';
3
3
  import { assertRollupInput } from './buildConfig.js';
4
4
  import { installRequireShim_setUserRootDir } from '@brillout/require-shim';
5
5
  import pc from '@brillout/picocolors';
@@ -21,7 +21,6 @@ function commonConfig() {
21
21
  configResolved: {
22
22
  order: 'post',
23
23
  handler(config) {
24
- overrideViteDefaultPort(config);
25
24
  /* TODO: do this after implementing vike.config.js and new setting transformLinkedDependencies (or probably a better name like transpileLinkedDependencies/bundleLinkedDependencies or something else)
26
25
  overrideViteDefaultSsrExternal(config)
27
26
  //*/
@@ -30,18 +29,27 @@ function commonConfig() {
30
29
  assertResolveAlias(config);
31
30
  assertEsm(config.root);
32
31
  }
32
+ },
33
+ // Override Vite's default port without overriding the user
34
+ config: {
35
+ order: 'post',
36
+ handler(configFromUser) {
37
+ const configFromVike = { server: {}, preview: {} };
38
+ setDefault('port', 3000, configFromUser, configFromVike);
39
+ if (isDocker()) {
40
+ setDefault('host', true, configFromUser, configFromVike);
41
+ }
42
+ return configFromVike;
43
+ }
33
44
  }
34
45
  }
35
46
  ];
36
47
  }
37
- function overrideViteDefaultPort(config) {
38
- var _a, _b;
39
- // @ts-ignore
40
- config.server ?? (config.server = {});
41
- (_a = config.server).port ?? (_a.port = 3000);
42
- // @ts-ignore
43
- config.preview ?? (config.preview = {});
44
- (_b = config.preview).port ?? (_b.port = 3000);
48
+ function setDefault(setting, value, configFromUser, configFromVike) {
49
+ if (configFromUser.server?.[setting] === undefined)
50
+ configFromVike.server[setting] = value;
51
+ if (configFromUser.preview?.[setting] === undefined)
52
+ configFromVike.preview[setting] = value;
45
53
  }
46
54
  /*
47
55
  import { version } from 'vite'
@@ -1,22 +1,28 @@
1
1
  export { resolveVikeConfig };
2
2
  import { assertVikeConfig } from './assertVikeConfig.js';
3
- import { isDev2 } from '../../utils.js';
3
+ import { assert, isDevCheck } from '../../utils.js';
4
4
  import { pickFirst } from './pickFirst.js';
5
5
  import { resolveBase } from './resolveBase.js';
6
6
  import { getVikeConfig } from '../importUserCode/v1-design/getVikeConfig.js';
7
7
  import pc from '@brillout/picocolors';
8
8
  function resolveVikeConfig(vikeConfig) {
9
+ let isDev;
9
10
  return {
10
11
  name: 'vike:resolveVikeConfig',
11
12
  enforce: 'pre',
13
+ apply(_config, env) {
14
+ isDev = isDevCheck(env);
15
+ return true;
16
+ },
12
17
  async configResolved(config) {
13
- const promise = getConfigVikPromise(vikeConfig, config);
18
+ assert(typeof isDev === 'boolean');
19
+ const promise = getConfigVikPromise(vikeConfig, config, isDev);
14
20
  config.configVikePromise = promise;
15
21
  await promise;
16
22
  }
17
23
  };
18
24
  }
19
- async function getConfigVikPromise(vikeConfig, config) {
25
+ async function getConfigVikPromise(vikeConfig, config, isDev) {
20
26
  const fromPluginOptions = (vikeConfig ?? {});
21
27
  const fromViteConfig = (config.vike ?? {});
22
28
  const configs = [fromPluginOptions, fromViteConfig];
@@ -24,7 +30,7 @@ async function getConfigVikPromise(vikeConfig, config) {
24
30
  // TODO/v1-release: deprecate this
25
31
  assertVikeConfig(fromPluginOptions, ({ prop, errMsg }) => `vite.config.js > vike option ${prop} ${errMsg}`);
26
32
  const crawlWithGit = fromPluginOptions.crawl?.git ?? null;
27
- const { globalVikeConfig: fromPlusConfigFile } = await getVikeConfig(config, isDev2(config), { crawlWithGit });
33
+ const { globalVikeConfig: fromPlusConfigFile } = await getVikeConfig(config, isDev, { crawlWithGit });
28
34
  configs.push(fromPlusConfigFile);
29
35
  assertVikeConfig(fromPlusConfigFile, ({ prop, errMsg }) => {
30
36
  // TODO: add config file path ?
@@ -1,3 +1,5 @@
1
1
  export { devConfig };
2
- import type { Plugin } from 'vite';
2
+ export { logDockerHint };
3
+ import type { Plugin, ResolvedConfig } from 'vite';
3
4
  declare function devConfig(): Plugin[];
5
+ declare function logDockerHint(configHost: ResolvedConfig['server']['host']): void;
@@ -1,23 +1,22 @@
1
1
  export { devConfig };
2
+ export { logDockerHint };
2
3
  import { determineOptimizeDeps } from './determineOptimizeDeps.js';
3
4
  import { determineFsAllowList } from './determineFsAllowList.js';
4
5
  import { addSsrMiddleware } from '../../shared/addSsrMiddleware.js';
5
- import { markEnvAsViteDev } from '../../utils.js';
6
+ import { applyDev, assertWarning, isDocker, markEnvAsViteDev } from '../../utils.js';
6
7
  import { improveViteLogs } from '../../shared/loggerVite.js';
7
8
  import { isErrorDebug } from '../../../shared/isErrorDebug.js';
8
9
  import { installHttpRequestAsyncStore } from '../../shared/getHttpRequestAsyncStore.js';
10
+ import pc from '@brillout/picocolors';
9
11
  if (isErrorDebug()) {
10
12
  Error.stackTraceLimit = Infinity;
11
13
  }
12
- // There doesn't seem to be a straightforward way to discriminate between `$ vite preview` and `$ vite dev`
13
- const apply = 'serve';
14
- const isDev = true;
15
14
  function devConfig() {
16
15
  let config;
17
16
  return [
18
17
  {
19
18
  name: 'vike:devConfig',
20
- apply,
19
+ apply: applyDev,
21
20
  config() {
22
21
  return {
23
22
  appType: 'custom',
@@ -59,12 +58,13 @@ function devConfig() {
59
58
  },
60
59
  async configResolved(config_) {
61
60
  config = config_;
62
- await determineOptimizeDeps(config, isDev);
61
+ await determineOptimizeDeps(config, true);
63
62
  await determineFsAllowList(config);
64
63
  if (!isErrorDebug()) {
65
64
  await installHttpRequestAsyncStore();
66
65
  improveViteLogs(config);
67
66
  }
67
+ logDockerHint(config.server.host);
68
68
  },
69
69
  configureServer() {
70
70
  markEnvAsViteDev();
@@ -72,7 +72,7 @@ function devConfig() {
72
72
  },
73
73
  {
74
74
  name: 'vike:devConfig:addSsrMiddleware',
75
- apply,
75
+ apply: applyDev,
76
76
  // The SSR middleware should be last middleware
77
77
  enforce: 'post',
78
78
  configureServer: {
@@ -98,3 +98,8 @@ function devConfig() {
98
98
  }
99
99
  ];
100
100
  }
101
+ function logDockerHint(configHost) {
102
+ if (isDocker()) {
103
+ assertWarning(configHost, `Your app seems to be running inside a Docker or Podman container but ${pc.cyan('--host')} isn't set which means that your Vike app won't be accessible from outside the container, see https://vike.dev/docker`, { onlyOnce: true });
104
+ }
105
+ }
@@ -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, getOutDirs, isDev3 } from '../../utils.js';
6
+ import { assert, assertPosixPath, getOutDirs, isDevCheck } from '../../utils.js';
7
7
  import { resolveVirtualFileId, isVirtualFileId, getVirtualFileId } from '../../../shared/virtual-files.js';
8
8
  import { isVirtualFileIdPageConfigValuesAll } from '../../../shared/virtual-files/virtualFilePageConfigValuesAll.js';
9
9
  import { isVirtualFileIdImportUserCode } from '../../../shared/virtual-files/virtualFileImportUserCode.js';
@@ -18,7 +18,7 @@ function importUserCode() {
18
18
  return {
19
19
  name: 'vike:importUserCode',
20
20
  config(_, env) {
21
- isDev = isDev3(env);
21
+ isDev = isDevCheck(env);
22
22
  },
23
23
  async configResolved(config_) {
24
24
  configVike = await getConfigVike(config_);
@@ -62,11 +62,11 @@ async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir
62
62
  assert(filePath.filePathAbsoluteFilesystem);
63
63
  extendsConfigFiles.push(filePath);
64
64
  });
65
- await Promise.all(extendsConfigFiles.map(async (configFilePath) => {
66
- const result = await loadConfigFile(configFilePath, userRootDir, visited, true);
65
+ const results = await Promise.all(extendsConfigFiles.map(async (configFilePath) => await loadConfigFile(configFilePath, userRootDir, visited, true)));
66
+ results.forEach((result) => {
67
67
  extendsConfigs.push(result.configFile);
68
68
  extendsConfigs.push(...result.extendsConfigs);
69
- }));
69
+ });
70
70
  const extendsFilePaths = extendsConfigFiles.map((f) => f.filePathAbsoluteFilesystem);
71
71
  return { extendsConfigs, extendsFilePaths };
72
72
  }
@@ -1,12 +1,22 @@
1
1
  export { resolvePointerImportOfConfig };
2
2
  export { resolvePointerImport };
3
3
  export { clearFilesEnvMap };
4
+ export { resolveConfigEnvWithFileName };
4
5
  import type { ConfigEnvInternal, DefinedAtFilePath } from '../../../../../../shared/page-configs/PageConfig.js';
5
6
  import { type PointerImportData } from './transformPointerImports.js';
6
7
  import type { FilePath, FilePathResolved } from '../../../../../../shared/page-configs/FilePath.js';
7
8
  type PointerImportResolved = DefinedAtFilePath & {
8
9
  fileExportName: string;
9
10
  };
10
- declare function resolvePointerImportOfConfig(configValue: unknown, importerFilePath: FilePathResolved, userRootDir: string, configEnv: ConfigEnvInternal, configName: string): null | PointerImportResolved;
11
+ declare function resolvePointerImportOfConfig(configValue: unknown, importerFilePath: FilePathResolved, userRootDir: string, configEnv: ConfigEnvInternal, configName: string): null | {
12
+ pointerImport: PointerImportResolved;
13
+ configEnvResolved: ConfigEnvInternal;
14
+ };
11
15
  declare function resolvePointerImport(pointerImportData: PointerImportData, importerFilePath: FilePathResolved, userRootDir: string): FilePath;
12
16
  declare function clearFilesEnvMap(): void;
17
+ declare function resolveConfigEnvWithFileName(configEnv: ConfigEnvInternal, filePath: FilePathResolved): {
18
+ server?: boolean | undefined;
19
+ config?: boolean | undefined;
20
+ client?: boolean | "if-client-routing";
21
+ production?: boolean;
22
+ };