vike 0.4.210 → 0.4.211
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 +30 -7
- 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/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.js +28 -5
- 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/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
|
@@ -9,8 +9,9 @@ exports.fixServerAssets_assertCssCodeSplit = fixServerAssets_assertCssCodeSplit;
|
|
|
9
9
|
exports.fixServerAssets_assertCssTarget = fixServerAssets_assertCssTarget;
|
|
10
10
|
exports.fixServerAssets_assertCssTarget_populate = fixServerAssets_assertCssTarget_populate;
|
|
11
11
|
const promises_1 = __importDefault(require("fs/promises"));
|
|
12
|
+
const fs_1 = __importDefault(require("fs"));
|
|
12
13
|
const path_1 = __importDefault(require("path"));
|
|
13
|
-
const
|
|
14
|
+
const fs_2 = require("fs");
|
|
14
15
|
const utils_js_1 = require("../../utils.js");
|
|
15
16
|
const virtualFilePageConfigValuesAll_js_1 = require("../../../shared/virtual-files/virtualFilePageConfigValuesAll.js");
|
|
16
17
|
const buildConfig_js_1 = require("../buildConfig.js");
|
|
@@ -51,16 +52,18 @@ async function copyAssets(filesToCopy, config) {
|
|
|
51
52
|
const assetsDirServer = path_1.default.posix.join(outDirServer, assetsDir);
|
|
52
53
|
if (!filesToCopy.length)
|
|
53
54
|
return;
|
|
54
|
-
(0, utils_js_1.assert)((0,
|
|
55
|
+
(0, utils_js_1.assert)((0, fs_2.existsSync)(assetsDirServer));
|
|
55
56
|
const concurrencyLimit = (0, utils_js_1.pLimit)(10);
|
|
56
|
-
await Promise.all(filesToCopy.map((file) => concurrencyLimit(() =>
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
recursive: true
|
|
60
|
-
|
|
57
|
+
await Promise.all(filesToCopy.map((file) => concurrencyLimit(async () => {
|
|
58
|
+
const source = path_1.default.posix.join(outDirServer, file);
|
|
59
|
+
const target = path_1.default.posix.join(outDirClient, file);
|
|
60
|
+
await promises_1.default.mkdir(path_1.default.posix.dirname(target), { recursive: true });
|
|
61
|
+
await promises_1.default.rename(source, target);
|
|
62
|
+
})));
|
|
61
63
|
/* 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
|
|
62
64
|
await fs.rm(assetsDirServer, { recursive: true })
|
|
63
65
|
*/
|
|
66
|
+
removeEmptyDirectories(assetsDirServer);
|
|
64
67
|
}
|
|
65
68
|
// Add serverManifest resources to clientManifest
|
|
66
69
|
function addServerAssets(clientManifest, serverManifest) {
|
|
@@ -194,3 +197,23 @@ async function fixServerAssets_assertCssTarget(config) {
|
|
|
194
197
|
function resolveCssTarget(target) {
|
|
195
198
|
return target.css ?? target.global;
|
|
196
199
|
}
|
|
200
|
+
/**
|
|
201
|
+
* Recursively remove all empty directories in a given directory.
|
|
202
|
+
*/
|
|
203
|
+
function removeEmptyDirectories(dirPath) {
|
|
204
|
+
// Read the directory contents
|
|
205
|
+
const files = fs_1.default.readdirSync(dirPath);
|
|
206
|
+
// Iterate through the files and subdirectories
|
|
207
|
+
for (const file of files) {
|
|
208
|
+
const fullPath = path_1.default.join(dirPath, file);
|
|
209
|
+
// Check if it's a directory
|
|
210
|
+
if (fs_1.default.statSync(fullPath).isDirectory()) {
|
|
211
|
+
// Recursively clean up the subdirectory
|
|
212
|
+
removeEmptyDirectories(fullPath);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
// Re-check the directory; remove it if it's now empty
|
|
216
|
+
if (fs_1.default.readdirSync(dirPath).length === 0) {
|
|
217
|
+
fs_1.default.rmdirSync(dirPath);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
@@ -38,18 +38,24 @@ function commonConfig() {
|
|
|
38
38
|
// Override Vite's default port without overriding the user
|
|
39
39
|
config: {
|
|
40
40
|
order: 'post',
|
|
41
|
-
handler(
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return
|
|
41
|
+
handler(configFromUser) {
|
|
42
|
+
const configFromVike = { server: {}, preview: {} };
|
|
43
|
+
setDefault('port', 3000, configFromUser, configFromVike);
|
|
44
|
+
if ((0, utils_js_1.isDocker)()) {
|
|
45
|
+
setDefault('host', true, configFromUser, configFromVike);
|
|
46
|
+
}
|
|
47
|
+
return configFromVike;
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
];
|
|
52
52
|
}
|
|
53
|
+
function setDefault(setting, value, configFromUser, configFromVike) {
|
|
54
|
+
if (configFromUser.server?.[setting] === undefined)
|
|
55
|
+
configFromVike.server[setting] = value;
|
|
56
|
+
if (configFromUser.preview?.[setting] === undefined)
|
|
57
|
+
configFromVike.preview[setting] = value;
|
|
58
|
+
}
|
|
53
59
|
/*
|
|
54
60
|
import { version } from 'vite'
|
|
55
61
|
function overrideViteDefaultSsrExternal(config: ResolvedConfig) {
|
|
@@ -11,17 +11,23 @@ const resolveBase_js_1 = require("./resolveBase.js");
|
|
|
11
11
|
const getVikeConfig_js_1 = require("../importUserCode/v1-design/getVikeConfig.js");
|
|
12
12
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
13
13
|
function resolveVikeConfig(vikeConfig) {
|
|
14
|
+
let isDev;
|
|
14
15
|
return {
|
|
15
16
|
name: 'vike:resolveVikeConfig',
|
|
16
17
|
enforce: 'pre',
|
|
18
|
+
apply(_config, env) {
|
|
19
|
+
isDev = (0, utils_js_1.isDevCheck)(env);
|
|
20
|
+
return true;
|
|
21
|
+
},
|
|
17
22
|
async configResolved(config) {
|
|
18
|
-
|
|
23
|
+
(0, utils_js_1.assert)(typeof isDev === 'boolean');
|
|
24
|
+
const promise = getConfigVikPromise(vikeConfig, config, isDev);
|
|
19
25
|
config.configVikePromise = promise;
|
|
20
26
|
await promise;
|
|
21
27
|
}
|
|
22
28
|
};
|
|
23
29
|
}
|
|
24
|
-
async function getConfigVikPromise(vikeConfig, config) {
|
|
30
|
+
async function getConfigVikPromise(vikeConfig, config, isDev) {
|
|
25
31
|
const fromPluginOptions = (vikeConfig ?? {});
|
|
26
32
|
const fromViteConfig = (config.vike ?? {});
|
|
27
33
|
const configs = [fromPluginOptions, fromViteConfig];
|
|
@@ -29,7 +35,7 @@ async function getConfigVikPromise(vikeConfig, config) {
|
|
|
29
35
|
// TODO/v1-release: deprecate this
|
|
30
36
|
(0, assertVikeConfig_js_1.assertVikeConfig)(fromPluginOptions, ({ prop, errMsg }) => `vite.config.js > vike option ${prop} ${errMsg}`);
|
|
31
37
|
const crawlWithGit = fromPluginOptions.crawl?.git ?? null;
|
|
32
|
-
const { globalVikeConfig: fromPlusConfigFile } = await (0, getVikeConfig_js_1.getVikeConfig)(config,
|
|
38
|
+
const { globalVikeConfig: fromPlusConfigFile } = await (0, getVikeConfig_js_1.getVikeConfig)(config, isDev, { crawlWithGit });
|
|
33
39
|
configs.push(fromPlusConfigFile);
|
|
34
40
|
(0, assertVikeConfig_js_1.assertVikeConfig)(fromPlusConfigFile, ({ prop, errMsg }) => {
|
|
35
41
|
// TODO: add config file path ?
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.devConfig = devConfig;
|
|
7
|
+
exports.logDockerHint = logDockerHint;
|
|
4
8
|
const determineOptimizeDeps_js_1 = require("./determineOptimizeDeps.js");
|
|
5
9
|
const determineFsAllowList_js_1 = require("./determineFsAllowList.js");
|
|
6
10
|
const addSsrMiddleware_js_1 = require("../../shared/addSsrMiddleware.js");
|
|
@@ -8,18 +12,16 @@ const utils_js_1 = require("../../utils.js");
|
|
|
8
12
|
const loggerVite_js_1 = require("../../shared/loggerVite.js");
|
|
9
13
|
const isErrorDebug_js_1 = require("../../../shared/isErrorDebug.js");
|
|
10
14
|
const getHttpRequestAsyncStore_js_1 = require("../../shared/getHttpRequestAsyncStore.js");
|
|
15
|
+
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
11
16
|
if ((0, isErrorDebug_js_1.isErrorDebug)()) {
|
|
12
17
|
Error.stackTraceLimit = Infinity;
|
|
13
18
|
}
|
|
14
|
-
// There doesn't seem to be a straightforward way to discriminate between `$ vite preview` and `$ vite dev`
|
|
15
|
-
const apply = 'serve';
|
|
16
|
-
const isDev = true;
|
|
17
19
|
function devConfig() {
|
|
18
20
|
let config;
|
|
19
21
|
return [
|
|
20
22
|
{
|
|
21
23
|
name: 'vike:devConfig',
|
|
22
|
-
apply,
|
|
24
|
+
apply: utils_js_1.applyDev,
|
|
23
25
|
config() {
|
|
24
26
|
return {
|
|
25
27
|
appType: 'custom',
|
|
@@ -61,12 +63,13 @@ function devConfig() {
|
|
|
61
63
|
},
|
|
62
64
|
async configResolved(config_) {
|
|
63
65
|
config = config_;
|
|
64
|
-
await (0, determineOptimizeDeps_js_1.determineOptimizeDeps)(config,
|
|
66
|
+
await (0, determineOptimizeDeps_js_1.determineOptimizeDeps)(config, true);
|
|
65
67
|
await (0, determineFsAllowList_js_1.determineFsAllowList)(config);
|
|
66
68
|
if (!(0, isErrorDebug_js_1.isErrorDebug)()) {
|
|
67
69
|
await (0, getHttpRequestAsyncStore_js_1.installHttpRequestAsyncStore)();
|
|
68
70
|
(0, loggerVite_js_1.improveViteLogs)(config);
|
|
69
71
|
}
|
|
72
|
+
logDockerHint(config.server.host);
|
|
70
73
|
},
|
|
71
74
|
configureServer() {
|
|
72
75
|
(0, utils_js_1.markEnvAsViteDev)();
|
|
@@ -74,7 +77,7 @@ function devConfig() {
|
|
|
74
77
|
},
|
|
75
78
|
{
|
|
76
79
|
name: 'vike:devConfig:addSsrMiddleware',
|
|
77
|
-
apply,
|
|
80
|
+
apply: utils_js_1.applyDev,
|
|
78
81
|
// The SSR middleware should be last middleware
|
|
79
82
|
enforce: 'post',
|
|
80
83
|
configureServer: {
|
|
@@ -100,3 +103,8 @@ function devConfig() {
|
|
|
100
103
|
}
|
|
101
104
|
];
|
|
102
105
|
}
|
|
106
|
+
function logDockerHint(configHost) {
|
|
107
|
+
if ((0, utils_js_1.isDocker)()) {
|
|
108
|
+
(0, utils_js_1.assertWarning)(configHost, `Your app seems to be running inside a Docker or Podman container but ${picocolors_1.default.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 });
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -23,7 +23,7 @@ function importUserCode() {
|
|
|
23
23
|
return {
|
|
24
24
|
name: 'vike:importUserCode',
|
|
25
25
|
config(_, env) {
|
|
26
|
-
isDev = (0, utils_js_1.
|
|
26
|
+
isDev = (0, utils_js_1.isDevCheck)(env);
|
|
27
27
|
},
|
|
28
28
|
async configResolved(config_) {
|
|
29
29
|
configVike = await (0, getConfigVike_js_1.getConfigVike)(config_);
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js
CHANGED
|
@@ -67,11 +67,11 @@ async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir
|
|
|
67
67
|
(0, utils_js_1.assert)(filePath.filePathAbsoluteFilesystem);
|
|
68
68
|
extendsConfigFiles.push(filePath);
|
|
69
69
|
});
|
|
70
|
-
await Promise.all(extendsConfigFiles.map(async (configFilePath) =>
|
|
71
|
-
|
|
70
|
+
const results = await Promise.all(extendsConfigFiles.map(async (configFilePath) => await loadConfigFile(configFilePath, userRootDir, visited, true)));
|
|
71
|
+
results.forEach((result) => {
|
|
72
72
|
extendsConfigs.push(result.configFile);
|
|
73
73
|
extendsConfigs.push(...result.extendsConfigs);
|
|
74
|
-
})
|
|
74
|
+
});
|
|
75
75
|
const extendsFilePaths = extendsConfigFiles.map((f) => f.filePathAbsoluteFilesystem);
|
|
76
76
|
return { extendsConfigs, extendsFilePaths };
|
|
77
77
|
}
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.resolvePointerImportOfConfig = resolvePointerImportOfConfig;
|
|
7
7
|
exports.resolvePointerImport = resolvePointerImport;
|
|
8
8
|
exports.clearFilesEnvMap = clearFilesEnvMap;
|
|
9
|
+
exports.resolveConfigEnvWithFileName = resolveConfigEnvWithFileName;
|
|
9
10
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
10
11
|
const utils_js_1 = require("../../../../utils.js");
|
|
11
12
|
const transformPointerImports_js_1 = require("./transformPointerImports.js");
|
|
@@ -21,12 +22,16 @@ function resolvePointerImportOfConfig(configValue, importerFilePath, userRootDir
|
|
|
21
22
|
const { importPath, exportName } = pointerImportData;
|
|
22
23
|
const filePath = resolvePointerImport(pointerImportData, importerFilePath, userRootDir);
|
|
23
24
|
const fileExportPathToShowToUser = exportName === 'default' || exportName === configName ? [] : [exportName];
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
let configEnvResolved = configEnv;
|
|
26
|
+
if (filePath.filePathAbsoluteFilesystem)
|
|
27
|
+
configEnvResolved = resolveConfigEnvWithFileName(configEnv, filePath);
|
|
28
|
+
assertUsageFileEnv(filePath, importPath, configEnvResolved, configName);
|
|
29
|
+
const pointerImport = {
|
|
26
30
|
...filePath,
|
|
27
31
|
fileExportName: exportName,
|
|
28
32
|
fileExportPathToShowToUser
|
|
29
33
|
};
|
|
34
|
+
return { pointerImport, configEnvResolved };
|
|
30
35
|
}
|
|
31
36
|
function resolvePointerImport(pointerImportData, importerFilePath, userRootDir) {
|
|
32
37
|
// `importPath` should be one of the following:
|
|
@@ -39,7 +44,7 @@ function resolvePointerImport(pointerImportData, importerFilePath, userRootDir)
|
|
|
39
44
|
(0, utils_js_1.assertPosixPath)(importPath);
|
|
40
45
|
if (importPath.startsWith('.') || (0, utils_js_1.isFilePathAbsolute)(importPath)) {
|
|
41
46
|
if (importPath.startsWith('.')) {
|
|
42
|
-
(0, utils_js_1.assertUsage)(
|
|
47
|
+
(0, utils_js_1.assertUsage)(isRelativeImportPath(importPath), `Invalid relative import path ${picocolors_1.default.code(importPath)} defined by ${importerFilePath.filePathToShowToUser} because it should start with ${picocolors_1.default.code('./')} or ${picocolors_1.default.code('../')}, or use an npm package import instead.`);
|
|
43
48
|
}
|
|
44
49
|
// Pointer imports are included in virtual files, thus relative imports need to be resolved. (Virtual modules cannot contain relative imports.)
|
|
45
50
|
assertUsageResolutionSuccess(filePathAbsoluteFilesystem, pointerImportData, importerFilePath);
|
|
@@ -67,6 +72,7 @@ function resolvePointerImport(pointerImportData, importerFilePath, userRootDir)
|
|
|
67
72
|
});
|
|
68
73
|
}
|
|
69
74
|
else {
|
|
75
|
+
// We cannot resolve path aliases defined only in Vite
|
|
70
76
|
filePath = (0, getFilePath_js_1.getFilePathUnresolved)({
|
|
71
77
|
importPathAbsolute
|
|
72
78
|
});
|
|
@@ -94,7 +100,7 @@ function assertUsageResolutionSuccess(filePathAbsoluteFilesystem, pointerImportD
|
|
|
94
100
|
: `The import ${picocolors_1.default.code(importString)} defined by ${filePathToShowToUser}`;
|
|
95
101
|
const errIntro2 = `${errIntro} couldn't be resolved: does ${importPathString}`;
|
|
96
102
|
if (importPath.startsWith('.')) {
|
|
97
|
-
(0, utils_js_1.assert)(
|
|
103
|
+
(0, utils_js_1.assert)(isRelativeImportPath(importPath));
|
|
98
104
|
(0, utils_js_1.assertUsage)(false, `${errIntro2} point to an existing file?`);
|
|
99
105
|
}
|
|
100
106
|
else {
|
|
@@ -102,13 +108,14 @@ function assertUsageResolutionSuccess(filePathAbsoluteFilesystem, pointerImportD
|
|
|
102
108
|
}
|
|
103
109
|
}
|
|
104
110
|
}
|
|
105
|
-
function assertUsageFileEnv(
|
|
111
|
+
function assertUsageFileEnv(filePath, importPath, configEnvResolved, configName) {
|
|
106
112
|
let key;
|
|
107
|
-
if (filePathAbsoluteFilesystem) {
|
|
108
|
-
key = filePathAbsoluteFilesystem;
|
|
113
|
+
if (filePath.filePathAbsoluteFilesystem) {
|
|
114
|
+
key = filePath.filePathAbsoluteFilesystem;
|
|
109
115
|
}
|
|
110
116
|
else {
|
|
111
|
-
|
|
117
|
+
// Path alias
|
|
118
|
+
(0, utils_js_1.assert)(!isRelativeImportPath(importPath));
|
|
112
119
|
key = importPath;
|
|
113
120
|
}
|
|
114
121
|
(0, utils_js_1.assertPosixPath)(key);
|
|
@@ -116,12 +123,12 @@ function assertUsageFileEnv(filePathAbsoluteFilesystem, importPath, configEnv, c
|
|
|
116
123
|
filesEnvMap.set(key, []);
|
|
117
124
|
}
|
|
118
125
|
const fileEnv = filesEnvMap.get(key);
|
|
119
|
-
fileEnv.push({
|
|
120
|
-
const configDifferentEnv = fileEnv.filter((c) => !(0, utils_js_1.deepEqual)(c.
|
|
126
|
+
fileEnv.push({ configEnvResolved, configName });
|
|
127
|
+
const configDifferentEnv = fileEnv.filter((c) => !(0, utils_js_1.deepEqual)(c.configEnvResolved, configEnvResolved))[0];
|
|
121
128
|
if (configDifferentEnv) {
|
|
122
129
|
(0, utils_js_1.assertUsage)(false, [
|
|
123
130
|
`${key} defines the value of configs living in different environments:`,
|
|
124
|
-
...[configDifferentEnv, { configName,
|
|
131
|
+
...[configDifferentEnv, { configName, configEnvResolved }].map((c) => ` - config ${picocolors_1.default.code(c.configName)} which value lives in environment ${picocolors_1.default.code(JSON.stringify(c.configEnvResolved))}`),
|
|
125
132
|
'Defining config values in the same file is allowed only if they live in the same environment, see https://vike.dev/config#pointer-imports'
|
|
126
133
|
].join('\n'));
|
|
127
134
|
}
|
|
@@ -129,3 +136,23 @@ function assertUsageFileEnv(filePathAbsoluteFilesystem, importPath, configEnv, c
|
|
|
129
136
|
function clearFilesEnvMap() {
|
|
130
137
|
filesEnvMap.clear();
|
|
131
138
|
}
|
|
139
|
+
function resolveConfigEnvWithFileName(configEnv, filePath) {
|
|
140
|
+
const { fileName } = filePath;
|
|
141
|
+
const configEnvResolved = { ...configEnv };
|
|
142
|
+
if (fileName.includes('.server.')) {
|
|
143
|
+
configEnvResolved.server = true;
|
|
144
|
+
configEnvResolved.client = false;
|
|
145
|
+
}
|
|
146
|
+
else if (fileName.includes('.client.')) {
|
|
147
|
+
configEnvResolved.client = true;
|
|
148
|
+
configEnvResolved.server = false;
|
|
149
|
+
}
|
|
150
|
+
else if (fileName.includes('.shared.')) {
|
|
151
|
+
configEnvResolved.server = true;
|
|
152
|
+
configEnvResolved.client = true;
|
|
153
|
+
}
|
|
154
|
+
return configEnvResolved;
|
|
155
|
+
}
|
|
156
|
+
function isRelativeImportPath(importPath) {
|
|
157
|
+
return importPath.startsWith('./') || importPath.startsWith('../');
|
|
158
|
+
}
|
|
@@ -243,7 +243,7 @@ async function loadVikeConfig(userRootDir, outDirRoot, isDev, crawlWithGit) {
|
|
|
243
243
|
const importedFilesLoaded = {};
|
|
244
244
|
const { globalVikeConfig, pageConfigGlobal } = await getGlobalConfigs(interfaceFilesByLocationId, userRootDir, importedFilesLoaded);
|
|
245
245
|
const pageConfigs = await Promise.all((0, utils_js_1.objectEntries)(interfaceFilesByLocationId)
|
|
246
|
-
.filter(([
|
|
246
|
+
.filter(([_pageId, interfaceFiles]) => isDefiningPage(interfaceFiles))
|
|
247
247
|
.map(async ([locationId]) => {
|
|
248
248
|
const interfaceFilesRelevant = getInterfaceFilesRelevant(interfaceFilesByLocationId, locationId);
|
|
249
249
|
const interfaceFilesRelevantList = Object.values(interfaceFilesRelevant).flat(1);
|
|
@@ -339,22 +339,6 @@ function assertUsageGlobalConfigs(interfaceFilesRelevantList, configDefinitions,
|
|
|
339
339
|
});
|
|
340
340
|
});
|
|
341
341
|
}
|
|
342
|
-
function deriveConfigEnvFromFileName(env, fileName) {
|
|
343
|
-
env = { ...env };
|
|
344
|
-
if (fileName.includes('.server.')) {
|
|
345
|
-
env.server = true;
|
|
346
|
-
env.client = false;
|
|
347
|
-
}
|
|
348
|
-
else if (fileName.includes('.client.')) {
|
|
349
|
-
env.client = true;
|
|
350
|
-
env.server = false;
|
|
351
|
-
}
|
|
352
|
-
else if (fileName.includes('.shared.')) {
|
|
353
|
-
env.server = true;
|
|
354
|
-
env.client = true;
|
|
355
|
-
}
|
|
356
|
-
return env;
|
|
357
|
-
}
|
|
358
342
|
function assertPageConfigs(pageConfigs) {
|
|
359
343
|
pageConfigs.forEach((pageConfig) => {
|
|
360
344
|
assertOnBeforeRenderEnv(pageConfig);
|
|
@@ -535,7 +519,6 @@ function isInterfaceFileUserLand(interfaceFile) {
|
|
|
535
519
|
async function getConfigValueSource(configName, interfaceFile, configDef, userRootDir, importedFilesLoaded, isHighestInheritancePrecedence) {
|
|
536
520
|
const conf = interfaceFile.fileExportsByConfigName[configName];
|
|
537
521
|
(0, utils_js_1.assert)(conf);
|
|
538
|
-
const configEnv = deriveConfigEnvFromFileName(configDef.env, interfaceFile.filePath.fileName);
|
|
539
522
|
const { locationId } = interfaceFile;
|
|
540
523
|
const definedAtFilePath_ = {
|
|
541
524
|
...interfaceFile.filePath,
|
|
@@ -547,14 +530,15 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
547
530
|
let definedAtFilePath;
|
|
548
531
|
let valueFilePath;
|
|
549
532
|
if (interfaceFile.isConfigFile) {
|
|
550
|
-
|
|
551
|
-
const
|
|
533
|
+
// Defined over pointer import
|
|
534
|
+
const resolved = (0, resolvePointerImport_js_1.resolvePointerImportOfConfig)(conf.configValue, interfaceFile.filePath, userRootDir, configDef.env, configName);
|
|
552
535
|
const configDefinedAt = (0, getConfigDefinedAt_js_1.getConfigDefinedAt)('Config', configName, definedAtFilePath_);
|
|
553
|
-
(0, utils_js_1.assertUsage)(
|
|
554
|
-
valueFilePath = pointerImport.filePathAbsoluteVite;
|
|
555
|
-
definedAtFilePath = pointerImport;
|
|
536
|
+
(0, utils_js_1.assertUsage)(resolved, `${configDefinedAt} should be an import`);
|
|
537
|
+
valueFilePath = resolved.pointerImport.filePathAbsoluteVite;
|
|
538
|
+
definedAtFilePath = resolved.pointerImport;
|
|
556
539
|
}
|
|
557
540
|
else {
|
|
541
|
+
// Defined by value file, i.e. +{configName}.js
|
|
558
542
|
(0, utils_js_1.assert)(interfaceFile.isValueFile);
|
|
559
543
|
valueFilePath = interfaceFile.filePath.filePathAbsoluteVite;
|
|
560
544
|
definedAtFilePath = {
|
|
@@ -566,7 +550,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
566
550
|
locationId,
|
|
567
551
|
value: valueFilePath,
|
|
568
552
|
valueIsFilePath: true,
|
|
569
|
-
configEnv,
|
|
553
|
+
configEnv: configDef.env,
|
|
570
554
|
valueIsImportedAtRuntime: true,
|
|
571
555
|
valueIsDefinedByPlusFile: false,
|
|
572
556
|
isOverriden,
|
|
@@ -578,23 +562,23 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
578
562
|
if (interfaceFile.isConfigFile) {
|
|
579
563
|
(0, utils_js_1.assert)('configValue' in conf);
|
|
580
564
|
const { configValue } = conf;
|
|
581
|
-
//
|
|
582
|
-
const
|
|
583
|
-
if (
|
|
565
|
+
// Defined over pointer import
|
|
566
|
+
const resolved = (0, resolvePointerImport_js_1.resolvePointerImportOfConfig)(configValue, interfaceFile.filePath, userRootDir, configDef.env, configName);
|
|
567
|
+
if (resolved) {
|
|
584
568
|
const configValueSource = {
|
|
585
569
|
locationId,
|
|
586
|
-
configEnv,
|
|
570
|
+
configEnv: resolved.configEnvResolved,
|
|
587
571
|
valueIsImportedAtRuntime: true,
|
|
588
572
|
valueIsDefinedByPlusFile: false,
|
|
589
573
|
isOverriden,
|
|
590
|
-
definedAtFilePath: pointerImport
|
|
574
|
+
definedAtFilePath: resolved.pointerImport
|
|
591
575
|
};
|
|
592
576
|
// Load pointer import
|
|
593
577
|
if (isLoadableAtBuildTime(configDef) &&
|
|
594
578
|
// The value of `extends` was already loaded and already used: we don't need the value of `extends` anymore
|
|
595
579
|
configName !== 'extends') {
|
|
596
|
-
if (pointerImport.filePathAbsoluteFilesystem) {
|
|
597
|
-
const fileExport = await (0, loadFileAtConfigTime_js_1.loadImportedFile)(pointerImport, userRootDir, importedFilesLoaded);
|
|
580
|
+
if (resolved.pointerImport.filePathAbsoluteFilesystem) {
|
|
581
|
+
const fileExport = await (0, loadFileAtConfigTime_js_1.loadImportedFile)(resolved.pointerImport, userRootDir, importedFilesLoaded);
|
|
598
582
|
configValueSource.value = fileExport;
|
|
599
583
|
}
|
|
600
584
|
else {
|
|
@@ -604,11 +588,11 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
604
588
|
}
|
|
605
589
|
return configValueSource;
|
|
606
590
|
}
|
|
607
|
-
// Defined
|
|
591
|
+
// Defined inside +config.js
|
|
608
592
|
const configValueSource = {
|
|
609
593
|
locationId,
|
|
610
594
|
value: configValue,
|
|
611
|
-
configEnv,
|
|
595
|
+
configEnv: configDef.env,
|
|
612
596
|
valueIsImportedAtRuntime: false,
|
|
613
597
|
valueIsDefinedByPlusFile: false,
|
|
614
598
|
isOverriden,
|
|
@@ -618,11 +602,12 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
618
602
|
}
|
|
619
603
|
// Defined by value file, i.e. +{configName}.js
|
|
620
604
|
if (interfaceFile.isValueFile) {
|
|
605
|
+
const configEnvResolved = (0, resolvePointerImport_js_1.resolveConfigEnvWithFileName)(configDef.env, interfaceFile.filePath);
|
|
621
606
|
const valueAlreadyLoaded = 'configValue' in conf;
|
|
622
|
-
(0, utils_js_1.assert)(valueAlreadyLoaded === !!
|
|
607
|
+
(0, utils_js_1.assert)(valueAlreadyLoaded === !!configEnvResolved.config);
|
|
623
608
|
const configValueSource = {
|
|
624
609
|
locationId,
|
|
625
|
-
configEnv,
|
|
610
|
+
configEnv: configEnvResolved,
|
|
626
611
|
valueIsImportedAtRuntime: !valueAlreadyLoaded,
|
|
627
612
|
valueIsDefinedByPlusFile: true,
|
|
628
613
|
isOverriden,
|
|
@@ -5,17 +5,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.previewConfig = previewConfig;
|
|
7
7
|
const utils_js_1 = require("../utils.js");
|
|
8
|
-
const getConfigVike_js_1 = require("../../shared/getConfigVike.js");
|
|
9
8
|
const fs_1 = __importDefault(require("fs"));
|
|
10
9
|
const path_1 = __importDefault(require("path"));
|
|
11
10
|
const addSsrMiddleware_js_1 = require("../shared/addSsrMiddleware.js");
|
|
12
11
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
12
|
+
const index_js_1 = require("./devConfig/index.js");
|
|
13
13
|
function previewConfig() {
|
|
14
14
|
let config;
|
|
15
|
-
let configVike
|
|
15
|
+
// let configVike: ConfigVikeResolved
|
|
16
16
|
return {
|
|
17
17
|
name: 'vike:previewConfig',
|
|
18
|
-
apply:
|
|
18
|
+
apply: utils_js_1.applyPreview,
|
|
19
19
|
config(config) {
|
|
20
20
|
return {
|
|
21
21
|
appType: 'custom',
|
|
@@ -26,7 +26,8 @@ function previewConfig() {
|
|
|
26
26
|
},
|
|
27
27
|
async configResolved(config_) {
|
|
28
28
|
config = config_;
|
|
29
|
-
|
|
29
|
+
(0, index_js_1.logDockerHint)(config.preview.host);
|
|
30
|
+
// configVike = await getConfigVike(config)
|
|
30
31
|
},
|
|
31
32
|
configurePreviewServer(server) {
|
|
32
33
|
/* - Couldn't make `appType: 'mpa'` work as of npm:@brillout/vite@5.0.0-beta.14.0426910c
|
|
@@ -44,3 +44,4 @@ __exportStar(require("../../utils/isFilePathAbsoluteFilesystem.js"), exports);
|
|
|
44
44
|
__exportStar(require("../../utils/isArray.js"), exports);
|
|
45
45
|
__exportStar(require("../../utils/PROJECT_VERSION.js"), exports);
|
|
46
46
|
__exportStar(require("../../utils/isEqualStringList.js"), exports);
|
|
47
|
+
__exportStar(require("../../utils/isDocker.js"), exports);
|
|
@@ -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
|
}
|