vike 0.4.209 → 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 +17 -9
- 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/client/client-routing-runtime/renderPageClientSide.js +13 -2
- package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.js +28 -5
- package/dist/esm/node/plugin/plugins/commonConfig.js +18 -10
- 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/shared/types.d.ts +6 -0
- 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
|
@@ -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
|
-
|
|
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));
|
|
@@ -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';
|
|
@@ -48,14 +49,16 @@ async function copyAssets(filesToCopy, config) {
|
|
|
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
|
+
})));
|
|
56
58
|
/* 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
59
|
await fs.rm(assetsDirServer, { recursive: true })
|
|
58
60
|
*/
|
|
61
|
+
removeEmptyDirectories(assetsDirServer);
|
|
59
62
|
}
|
|
60
63
|
// Add serverManifest resources to clientManifest
|
|
61
64
|
function addServerAssets(clientManifest, serverManifest) {
|
|
@@ -189,3 +192,23 @@ async function fixServerAssets_assertCssTarget(config) {
|
|
|
189
192
|
function resolveCssTarget(target) {
|
|
190
193
|
return target.css ?? target.global;
|
|
191
194
|
}
|
|
195
|
+
/**
|
|
196
|
+
* Recursively remove all empty directories in a given directory.
|
|
197
|
+
*/
|
|
198
|
+
function removeEmptyDirectories(dirPath) {
|
|
199
|
+
// Read the directory contents
|
|
200
|
+
const files = fs_sync.readdirSync(dirPath);
|
|
201
|
+
// Iterate through the files and subdirectories
|
|
202
|
+
for (const file of files) {
|
|
203
|
+
const fullPath = path.join(dirPath, file);
|
|
204
|
+
// Check if it's a directory
|
|
205
|
+
if (fs_sync.statSync(fullPath).isDirectory()) {
|
|
206
|
+
// Recursively clean up the subdirectory
|
|
207
|
+
removeEmptyDirectories(fullPath);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
// Re-check the directory; remove it if it's now empty
|
|
211
|
+
if (fs_sync.readdirSync(dirPath).length === 0) {
|
|
212
|
+
fs_sync.rmdirSync(dirPath);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
@@ -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
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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 {
|
|
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
|
+
};
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export { resolvePointerImportOfConfig };
|
|
2
2
|
export { resolvePointerImport };
|
|
3
3
|
export { clearFilesEnvMap };
|
|
4
|
+
export { resolveConfigEnvWithFileName };
|
|
4
5
|
import pc from '@brillout/picocolors';
|
|
5
|
-
import { assert,
|
|
6
|
+
import { assert, assertPosixPath, assertUsage, deepEqual, isFilePathAbsolute, requireResolve } from '../../../../utils.js';
|
|
6
7
|
import { parsePointerImportData } from './transformPointerImports.js';
|
|
7
8
|
import path from 'path';
|
|
8
9
|
import { getFilePathAbsoluteUserRootDir, getFilePathResolved, getFilePathUnresolved } from '../../../../shared/getFilePath.js';
|
|
@@ -16,12 +17,16 @@ function resolvePointerImportOfConfig(configValue, importerFilePath, userRootDir
|
|
|
16
17
|
const { importPath, exportName } = pointerImportData;
|
|
17
18
|
const filePath = resolvePointerImport(pointerImportData, importerFilePath, userRootDir);
|
|
18
19
|
const fileExportPathToShowToUser = exportName === 'default' || exportName === configName ? [] : [exportName];
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
let configEnvResolved = configEnv;
|
|
21
|
+
if (filePath.filePathAbsoluteFilesystem)
|
|
22
|
+
configEnvResolved = resolveConfigEnvWithFileName(configEnv, filePath);
|
|
23
|
+
assertUsageFileEnv(filePath, importPath, configEnvResolved, configName);
|
|
24
|
+
const pointerImport = {
|
|
21
25
|
...filePath,
|
|
22
26
|
fileExportName: exportName,
|
|
23
27
|
fileExportPathToShowToUser
|
|
24
28
|
};
|
|
29
|
+
return { pointerImport, configEnvResolved };
|
|
25
30
|
}
|
|
26
31
|
function resolvePointerImport(pointerImportData, importerFilePath, userRootDir) {
|
|
27
32
|
// `importPath` should be one of the following:
|
|
@@ -34,7 +39,7 @@ function resolvePointerImport(pointerImportData, importerFilePath, userRootDir)
|
|
|
34
39
|
assertPosixPath(importPath);
|
|
35
40
|
if (importPath.startsWith('.') || isFilePathAbsolute(importPath)) {
|
|
36
41
|
if (importPath.startsWith('.')) {
|
|
37
|
-
assertUsage(
|
|
42
|
+
assertUsage(isRelativeImportPath(importPath), `Invalid relative import path ${pc.code(importPath)} defined by ${importerFilePath.filePathToShowToUser} because it should start with ${pc.code('./')} or ${pc.code('../')}, or use an npm package import instead.`);
|
|
38
43
|
}
|
|
39
44
|
// Pointer imports are included in virtual files, thus relative imports need to be resolved. (Virtual modules cannot contain relative imports.)
|
|
40
45
|
assertUsageResolutionSuccess(filePathAbsoluteFilesystem, pointerImportData, importerFilePath);
|
|
@@ -62,6 +67,7 @@ function resolvePointerImport(pointerImportData, importerFilePath, userRootDir)
|
|
|
62
67
|
});
|
|
63
68
|
}
|
|
64
69
|
else {
|
|
70
|
+
// We cannot resolve path aliases defined only in Vite
|
|
65
71
|
filePath = getFilePathUnresolved({
|
|
66
72
|
importPathAbsolute
|
|
67
73
|
});
|
|
@@ -89,7 +95,7 @@ function assertUsageResolutionSuccess(filePathAbsoluteFilesystem, pointerImportD
|
|
|
89
95
|
: `The import ${pc.code(importString)} defined by ${filePathToShowToUser}`;
|
|
90
96
|
const errIntro2 = `${errIntro} couldn't be resolved: does ${importPathString}`;
|
|
91
97
|
if (importPath.startsWith('.')) {
|
|
92
|
-
assert(
|
|
98
|
+
assert(isRelativeImportPath(importPath));
|
|
93
99
|
assertUsage(false, `${errIntro2} point to an existing file?`);
|
|
94
100
|
}
|
|
95
101
|
else {
|
|
@@ -97,13 +103,14 @@ function assertUsageResolutionSuccess(filePathAbsoluteFilesystem, pointerImportD
|
|
|
97
103
|
}
|
|
98
104
|
}
|
|
99
105
|
}
|
|
100
|
-
function assertUsageFileEnv(
|
|
106
|
+
function assertUsageFileEnv(filePath, importPath, configEnvResolved, configName) {
|
|
101
107
|
let key;
|
|
102
|
-
if (filePathAbsoluteFilesystem) {
|
|
103
|
-
key = filePathAbsoluteFilesystem;
|
|
108
|
+
if (filePath.filePathAbsoluteFilesystem) {
|
|
109
|
+
key = filePath.filePathAbsoluteFilesystem;
|
|
104
110
|
}
|
|
105
111
|
else {
|
|
106
|
-
|
|
112
|
+
// Path alias
|
|
113
|
+
assert(!isRelativeImportPath(importPath));
|
|
107
114
|
key = importPath;
|
|
108
115
|
}
|
|
109
116
|
assertPosixPath(key);
|
|
@@ -111,12 +118,12 @@ function assertUsageFileEnv(filePathAbsoluteFilesystem, importPath, configEnv, c
|
|
|
111
118
|
filesEnvMap.set(key, []);
|
|
112
119
|
}
|
|
113
120
|
const fileEnv = filesEnvMap.get(key);
|
|
114
|
-
fileEnv.push({
|
|
115
|
-
const configDifferentEnv = fileEnv.filter((c) => !deepEqual(c.
|
|
121
|
+
fileEnv.push({ configEnvResolved, configName });
|
|
122
|
+
const configDifferentEnv = fileEnv.filter((c) => !deepEqual(c.configEnvResolved, configEnvResolved))[0];
|
|
116
123
|
if (configDifferentEnv) {
|
|
117
124
|
assertUsage(false, [
|
|
118
125
|
`${key} defines the value of configs living in different environments:`,
|
|
119
|
-
...[configDifferentEnv, { configName,
|
|
126
|
+
...[configDifferentEnv, { configName, configEnvResolved }].map((c) => ` - config ${pc.code(c.configName)} which value lives in environment ${pc.code(JSON.stringify(c.configEnvResolved))}`),
|
|
120
127
|
'Defining config values in the same file is allowed only if they live in the same environment, see https://vike.dev/config#pointer-imports'
|
|
121
128
|
].join('\n'));
|
|
122
129
|
}
|
|
@@ -124,3 +131,23 @@ function assertUsageFileEnv(filePathAbsoluteFilesystem, importPath, configEnv, c
|
|
|
124
131
|
function clearFilesEnvMap() {
|
|
125
132
|
filesEnvMap.clear();
|
|
126
133
|
}
|
|
134
|
+
function resolveConfigEnvWithFileName(configEnv, filePath) {
|
|
135
|
+
const { fileName } = filePath;
|
|
136
|
+
const configEnvResolved = { ...configEnv };
|
|
137
|
+
if (fileName.includes('.server.')) {
|
|
138
|
+
configEnvResolved.server = true;
|
|
139
|
+
configEnvResolved.client = false;
|
|
140
|
+
}
|
|
141
|
+
else if (fileName.includes('.client.')) {
|
|
142
|
+
configEnvResolved.client = true;
|
|
143
|
+
configEnvResolved.server = false;
|
|
144
|
+
}
|
|
145
|
+
else if (fileName.includes('.shared.')) {
|
|
146
|
+
configEnvResolved.server = true;
|
|
147
|
+
configEnvResolved.client = true;
|
|
148
|
+
}
|
|
149
|
+
return configEnvResolved;
|
|
150
|
+
}
|
|
151
|
+
function isRelativeImportPath(importPath) {
|
|
152
|
+
return importPath.startsWith('./') || importPath.startsWith('../');
|
|
153
|
+
}
|
|
@@ -18,7 +18,7 @@ import { getConfigDefinedAt } from '../../../../../shared/page-configs/getConfig
|
|
|
18
18
|
import { crawlPlusFiles } from './getVikeConfig/crawlPlusFiles.js';
|
|
19
19
|
import { getConfigFileExport } from './getConfigFileExport.js';
|
|
20
20
|
import { loadConfigFile, loadImportedFile, loadValueFile } from './getVikeConfig/loadFileAtConfigTime.js';
|
|
21
|
-
import { clearFilesEnvMap, resolvePointerImportOfConfig } from './getVikeConfig/resolvePointerImport.js';
|
|
21
|
+
import { clearFilesEnvMap, resolveConfigEnvWithFileName, resolvePointerImportOfConfig } from './getVikeConfig/resolvePointerImport.js';
|
|
22
22
|
import { getFilePathResolved } from '../../../shared/getFilePath.js';
|
|
23
23
|
import { getConfigValueBuildTime } from '../../../../../shared/page-configs/getConfigValueBuildTime.js';
|
|
24
24
|
import { getConfigVike } from '../../../../shared/getConfigVike.js';
|
|
@@ -237,7 +237,7 @@ async function loadVikeConfig(userRootDir, outDirRoot, isDev, crawlWithGit) {
|
|
|
237
237
|
const importedFilesLoaded = {};
|
|
238
238
|
const { globalVikeConfig, pageConfigGlobal } = await getGlobalConfigs(interfaceFilesByLocationId, userRootDir, importedFilesLoaded);
|
|
239
239
|
const pageConfigs = await Promise.all(objectEntries(interfaceFilesByLocationId)
|
|
240
|
-
.filter(([
|
|
240
|
+
.filter(([_pageId, interfaceFiles]) => isDefiningPage(interfaceFiles))
|
|
241
241
|
.map(async ([locationId]) => {
|
|
242
242
|
const interfaceFilesRelevant = getInterfaceFilesRelevant(interfaceFilesByLocationId, locationId);
|
|
243
243
|
const interfaceFilesRelevantList = Object.values(interfaceFilesRelevant).flat(1);
|
|
@@ -333,22 +333,6 @@ function assertUsageGlobalConfigs(interfaceFilesRelevantList, configDefinitions,
|
|
|
333
333
|
});
|
|
334
334
|
});
|
|
335
335
|
}
|
|
336
|
-
function deriveConfigEnvFromFileName(env, fileName) {
|
|
337
|
-
env = { ...env };
|
|
338
|
-
if (fileName.includes('.server.')) {
|
|
339
|
-
env.server = true;
|
|
340
|
-
env.client = false;
|
|
341
|
-
}
|
|
342
|
-
else if (fileName.includes('.client.')) {
|
|
343
|
-
env.client = true;
|
|
344
|
-
env.server = false;
|
|
345
|
-
}
|
|
346
|
-
else if (fileName.includes('.shared.')) {
|
|
347
|
-
env.server = true;
|
|
348
|
-
env.client = true;
|
|
349
|
-
}
|
|
350
|
-
return env;
|
|
351
|
-
}
|
|
352
336
|
function assertPageConfigs(pageConfigs) {
|
|
353
337
|
pageConfigs.forEach((pageConfig) => {
|
|
354
338
|
assertOnBeforeRenderEnv(pageConfig);
|
|
@@ -529,7 +513,6 @@ function isInterfaceFileUserLand(interfaceFile) {
|
|
|
529
513
|
async function getConfigValueSource(configName, interfaceFile, configDef, userRootDir, importedFilesLoaded, isHighestInheritancePrecedence) {
|
|
530
514
|
const conf = interfaceFile.fileExportsByConfigName[configName];
|
|
531
515
|
assert(conf);
|
|
532
|
-
const configEnv = deriveConfigEnvFromFileName(configDef.env, interfaceFile.filePath.fileName);
|
|
533
516
|
const { locationId } = interfaceFile;
|
|
534
517
|
const definedAtFilePath_ = {
|
|
535
518
|
...interfaceFile.filePath,
|
|
@@ -541,14 +524,15 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
541
524
|
let definedAtFilePath;
|
|
542
525
|
let valueFilePath;
|
|
543
526
|
if (interfaceFile.isConfigFile) {
|
|
544
|
-
|
|
545
|
-
const
|
|
527
|
+
// Defined over pointer import
|
|
528
|
+
const resolved = resolvePointerImportOfConfig(conf.configValue, interfaceFile.filePath, userRootDir, configDef.env, configName);
|
|
546
529
|
const configDefinedAt = getConfigDefinedAt('Config', configName, definedAtFilePath_);
|
|
547
|
-
assertUsage(
|
|
548
|
-
valueFilePath = pointerImport.filePathAbsoluteVite;
|
|
549
|
-
definedAtFilePath = pointerImport;
|
|
530
|
+
assertUsage(resolved, `${configDefinedAt} should be an import`);
|
|
531
|
+
valueFilePath = resolved.pointerImport.filePathAbsoluteVite;
|
|
532
|
+
definedAtFilePath = resolved.pointerImport;
|
|
550
533
|
}
|
|
551
534
|
else {
|
|
535
|
+
// Defined by value file, i.e. +{configName}.js
|
|
552
536
|
assert(interfaceFile.isValueFile);
|
|
553
537
|
valueFilePath = interfaceFile.filePath.filePathAbsoluteVite;
|
|
554
538
|
definedAtFilePath = {
|
|
@@ -560,7 +544,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
560
544
|
locationId,
|
|
561
545
|
value: valueFilePath,
|
|
562
546
|
valueIsFilePath: true,
|
|
563
|
-
configEnv,
|
|
547
|
+
configEnv: configDef.env,
|
|
564
548
|
valueIsImportedAtRuntime: true,
|
|
565
549
|
valueIsDefinedByPlusFile: false,
|
|
566
550
|
isOverriden,
|
|
@@ -572,23 +556,23 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
572
556
|
if (interfaceFile.isConfigFile) {
|
|
573
557
|
assert('configValue' in conf);
|
|
574
558
|
const { configValue } = conf;
|
|
575
|
-
//
|
|
576
|
-
const
|
|
577
|
-
if (
|
|
559
|
+
// Defined over pointer import
|
|
560
|
+
const resolved = resolvePointerImportOfConfig(configValue, interfaceFile.filePath, userRootDir, configDef.env, configName);
|
|
561
|
+
if (resolved) {
|
|
578
562
|
const configValueSource = {
|
|
579
563
|
locationId,
|
|
580
|
-
configEnv,
|
|
564
|
+
configEnv: resolved.configEnvResolved,
|
|
581
565
|
valueIsImportedAtRuntime: true,
|
|
582
566
|
valueIsDefinedByPlusFile: false,
|
|
583
567
|
isOverriden,
|
|
584
|
-
definedAtFilePath: pointerImport
|
|
568
|
+
definedAtFilePath: resolved.pointerImport
|
|
585
569
|
};
|
|
586
570
|
// Load pointer import
|
|
587
571
|
if (isLoadableAtBuildTime(configDef) &&
|
|
588
572
|
// The value of `extends` was already loaded and already used: we don't need the value of `extends` anymore
|
|
589
573
|
configName !== 'extends') {
|
|
590
|
-
if (pointerImport.filePathAbsoluteFilesystem) {
|
|
591
|
-
const fileExport = await loadImportedFile(pointerImport, userRootDir, importedFilesLoaded);
|
|
574
|
+
if (resolved.pointerImport.filePathAbsoluteFilesystem) {
|
|
575
|
+
const fileExport = await loadImportedFile(resolved.pointerImport, userRootDir, importedFilesLoaded);
|
|
592
576
|
configValueSource.value = fileExport;
|
|
593
577
|
}
|
|
594
578
|
else {
|
|
@@ -598,11 +582,11 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
598
582
|
}
|
|
599
583
|
return configValueSource;
|
|
600
584
|
}
|
|
601
|
-
// Defined
|
|
585
|
+
// Defined inside +config.js
|
|
602
586
|
const configValueSource = {
|
|
603
587
|
locationId,
|
|
604
588
|
value: configValue,
|
|
605
|
-
configEnv,
|
|
589
|
+
configEnv: configDef.env,
|
|
606
590
|
valueIsImportedAtRuntime: false,
|
|
607
591
|
valueIsDefinedByPlusFile: false,
|
|
608
592
|
isOverriden,
|
|
@@ -612,11 +596,12 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
612
596
|
}
|
|
613
597
|
// Defined by value file, i.e. +{configName}.js
|
|
614
598
|
if (interfaceFile.isValueFile) {
|
|
599
|
+
const configEnvResolved = resolveConfigEnvWithFileName(configDef.env, interfaceFile.filePath);
|
|
615
600
|
const valueAlreadyLoaded = 'configValue' in conf;
|
|
616
|
-
assert(valueAlreadyLoaded === !!
|
|
601
|
+
assert(valueAlreadyLoaded === !!configEnvResolved.config);
|
|
617
602
|
const configValueSource = {
|
|
618
603
|
locationId,
|
|
619
|
-
configEnv,
|
|
604
|
+
configEnv: configEnvResolved,
|
|
620
605
|
valueIsImportedAtRuntime: !valueAlreadyLoaded,
|
|
621
606
|
valueIsDefinedByPlusFile: true,
|
|
622
607
|
isOverriden,
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
export { previewConfig };
|
|
2
|
-
import { assertUsage, getOutDirs, resolveOutDir, markEnvAsVitePreview } from '../utils.js';
|
|
3
|
-
import { getConfigVike } from '../../shared/getConfigVike.js';
|
|
2
|
+
import { assertUsage, getOutDirs, resolveOutDir, markEnvAsVitePreview, applyPreview } from '../utils.js';
|
|
4
3
|
import fs from 'fs';
|
|
5
4
|
import path from 'path';
|
|
6
5
|
import { addSsrMiddleware } from '../shared/addSsrMiddleware.js';
|
|
7
6
|
import pc from '@brillout/picocolors';
|
|
7
|
+
import { logDockerHint } from './devConfig/index.js';
|
|
8
8
|
function previewConfig() {
|
|
9
9
|
let config;
|
|
10
|
-
let configVike
|
|
10
|
+
// let configVike: ConfigVikeResolved
|
|
11
11
|
return {
|
|
12
12
|
name: 'vike:previewConfig',
|
|
13
|
-
apply:
|
|
13
|
+
apply: applyPreview,
|
|
14
14
|
config(config) {
|
|
15
15
|
return {
|
|
16
16
|
appType: 'custom',
|
|
@@ -21,7 +21,8 @@ function previewConfig() {
|
|
|
21
21
|
},
|
|
22
22
|
async configResolved(config_) {
|
|
23
23
|
config = config_;
|
|
24
|
-
|
|
24
|
+
logDockerHint(config.preview.host);
|
|
25
|
+
// configVike = await getConfigVike(config)
|
|
25
26
|
},
|
|
26
27
|
configurePreviewServer(server) {
|
|
27
28
|
/* - Couldn't make `appType: 'mpa'` work as of npm:@brillout/vite@5.0.0-beta.14.0426910c
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { setGlobalContext };
|
|
2
2
|
import { setGlobalContext_isDev, setGlobalContext_viteDevServer, setGlobalContext_viteConfig } from '../../runtime/globalContext.js';
|
|
3
|
-
import { assertFilePathAbsoluteFilesystem, getOutDirs,
|
|
3
|
+
import { assertFilePathAbsoluteFilesystem, getOutDirs, isDevCheck } from '../utils.js';
|
|
4
4
|
function setGlobalContext() {
|
|
5
5
|
return {
|
|
6
6
|
name: 'vike:setGlobalContext',
|
|
@@ -13,7 +13,7 @@ function setGlobalContext() {
|
|
|
13
13
|
},
|
|
14
14
|
config: {
|
|
15
15
|
handler(_, env) {
|
|
16
|
-
const isDev =
|
|
16
|
+
const isDev = isDevCheck(env);
|
|
17
17
|
setGlobalContext_isDev(isDev);
|
|
18
18
|
}
|
|
19
19
|
},
|