vike 0.4.210 → 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.
- package/dist/cjs/node/plugin/plugins/buildConfig/fixServerAssets.js +81 -26
- package/dist/cjs/node/plugin/plugins/buildConfig.js +1 -1
- package/dist/cjs/node/plugin/plugins/commonConfig.js +13 -7
- package/dist/cjs/node/plugin/plugins/config/index.js +9 -3
- package/dist/cjs/node/plugin/plugins/devConfig/index.js +14 -6
- package/dist/cjs/node/plugin/plugins/importUserCode/index.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +3 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js +38 -11
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +20 -35
- package/dist/cjs/node/plugin/plugins/previewConfig.js +5 -4
- package/dist/cjs/node/plugin/plugins/setGlobalContext.js +1 -1
- package/dist/cjs/node/plugin/utils.js +1 -0
- package/dist/cjs/node/runtime/renderPage/getPageAssets/retrieveAssetsDev.js +7 -7
- package/dist/cjs/node/runtime/renderPage/logErrorHint.js +11 -7
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/assertVersion.js +2 -0
- package/dist/cjs/utils/isDev.js +11 -16
- package/dist/cjs/utils/isDocker.js +45 -0
- package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.d.ts +4 -1
- package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.js +79 -24
- package/dist/esm/node/plugin/plugins/buildConfig.js +1 -1
- package/dist/esm/node/plugin/plugins/commonConfig.js +14 -8
- package/dist/esm/node/plugin/plugins/config/index.js +10 -4
- package/dist/esm/node/plugin/plugins/devConfig/index.d.ts +3 -1
- package/dist/esm/node/plugin/plugins/devConfig/index.js +12 -7
- package/dist/esm/node/plugin/plugins/importUserCode/index.js +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.d.ts +11 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js +39 -12
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +21 -36
- package/dist/esm/node/plugin/plugins/previewConfig.js +6 -5
- package/dist/esm/node/plugin/plugins/setGlobalContext.js +2 -2
- package/dist/esm/node/plugin/utils.d.ts +1 -0
- package/dist/esm/node/plugin/utils.js +1 -0
- package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsDev.js +7 -7
- package/dist/esm/node/runtime/renderPage/logErrorHint.js +11 -7
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/assertVersion.js +2 -0
- package/dist/esm/utils/isDev.d.ts +6 -5
- package/dist/esm/utils/isDev.js +11 -16
- package/dist/esm/utils/isDocker.d.ts +2 -0
- package/dist/esm/utils/isDocker.js +40 -0
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/package.json +2 -2
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
114
|
+
if (knownErorr.mustMentionNodeModules !== false && !includesLowercase(anywhere, 'node_modules'))
|
|
111
115
|
return false;
|
|
112
116
|
return true;
|
|
113
117
|
});
|
|
@@ -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) {
|
package/dist/cjs/utils/isDev.js
CHANGED
|
@@ -1,23 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.
|
|
3
|
+
exports.isDevCheck = isDevCheck;
|
|
4
|
+
exports.applyDev = applyDev;
|
|
5
|
+
exports.applyPreview = applyPreview;
|
|
5
6
|
const assert_js_1 = require("./assert.js");
|
|
6
|
-
function
|
|
7
|
+
function isDevCheck(configEnv) {
|
|
7
8
|
const { isPreview, command } = configEnv;
|
|
8
|
-
|
|
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
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
+
}
|
|
@@ -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<
|
|
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
|
-
|
|
53
|
-
|
|
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
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
.
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
.
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
|
|
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
|
-
(
|
|
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
|
-
|
|
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';
|
|
@@ -33,18 +33,24 @@ function commonConfig() {
|
|
|
33
33
|
// Override Vite's default port without overriding the user
|
|
34
34
|
config: {
|
|
35
35
|
order: 'post',
|
|
36
|
-
handler(
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return
|
|
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
43
|
}
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
];
|
|
47
47
|
}
|
|
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;
|
|
53
|
+
}
|
|
48
54
|
/*
|
|
49
55
|
import { version } from 'vite'
|
|
50
56
|
function overrideViteDefaultSsrExternal(config: ResolvedConfig) {
|
|
@@ -1,22 +1,28 @@
|
|
|
1
1
|
export { resolveVikeConfig };
|
|
2
2
|
import { assertVikeConfig } from './assertVikeConfig.js';
|
|
3
|
-
import {
|
|
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
|
-
|
|
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,
|
|
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,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,
|
|
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,
|
|
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 =
|
|
21
|
+
isDev = isDevCheck(env);
|
|
22
22
|
},
|
|
23
23
|
async configResolved(config_) {
|
|
24
24
|
configVike = await getConfigVike(config_);
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js
CHANGED
|
@@ -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
|
-
|
|
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 |
|
|
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
|
+
};
|