vike 0.4.240 → 0.4.241-commit-60b0676
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/esm/client/runtime-client-routing/getPageContextFromHooks.d.ts +1 -1
- package/dist/esm/client/runtime-client-routing/getPageContextFromHooks.js +1 -1
- package/dist/esm/client/runtime-client-routing/logErrorClient.d.ts +2 -0
- package/dist/esm/client/runtime-client-routing/logErrorClient.js +11 -0
- package/dist/esm/client/runtime-client-routing/renderPageClientSide.js +95 -84
- package/dist/esm/client/runtime-client-routing/utils.d.ts +0 -1
- package/dist/esm/client/runtime-client-routing/utils.js +0 -1
- package/dist/esm/node/api/build.js +6 -6
- package/dist/esm/node/api/dev.js +2 -2
- package/dist/esm/node/api/prepareViteApiCall.d.ts +2 -9
- package/dist/esm/node/api/prepareViteApiCall.js +4 -156
- package/dist/esm/node/api/prerender.js +2 -2
- package/dist/esm/node/api/preview.js +2 -2
- package/dist/esm/node/api/resolveViteConfigFromUser.d.ts +20 -0
- package/dist/esm/node/api/resolveViteConfigFromUser.js +207 -0
- package/dist/esm/node/cli/parseCli.js +10 -6
- package/dist/esm/node/prerender/runPrerender.js +2 -1
- package/dist/esm/node/prerender/runPrerenderEntry.js +4 -4
- package/dist/esm/node/runtime/globalContext.d.ts +92 -0
- package/dist/esm/node/runtime/globalContext.js +12 -3
- package/dist/esm/node/runtime/logErrorServer.d.ts +2 -0
- package/dist/esm/node/runtime/logErrorServer.js +18 -0
- package/dist/esm/node/runtime/renderPage/execHookOnError.d.ts +2 -0
- package/dist/esm/node/runtime/renderPage/execHookOnError.js +26 -0
- package/dist/esm/node/runtime/renderPage/execHookServer.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/loggerProd.js +3 -5
- package/dist/esm/node/runtime/renderPage.js +8 -7
- package/dist/esm/node/runtime-dev/createDevMiddleware.js +2 -2
- package/dist/esm/node/vite/index.d.ts +1 -1
- package/dist/esm/node/vite/index.js +55 -24
- package/dist/esm/node/vite/onLoad.js +3 -8
- package/dist/esm/node/vite/plugins/build/handleAssetsManifest.js +0 -1
- package/dist/esm/node/vite/plugins/build/pluginBuildApp.js +6 -6
- package/dist/esm/node/vite/plugins/build/pluginDistFileNames.js +2 -2
- package/dist/esm/node/vite/plugins/pluginCommon.d.ts +1 -1
- package/dist/esm/node/vite/plugins/pluginCommon.js +22 -9
- package/dist/esm/node/vite/plugins/pluginFileEnv.js +9 -6
- package/dist/esm/node/vite/plugins/pluginReplaceConstantsEnvVars.d.ts +3 -0
- package/dist/esm/node/vite/plugins/pluginReplaceConstantsEnvVars.js +129 -0
- package/dist/esm/node/vite/plugins/pluginReplaceConstantsGlobalThis.d.ts +10 -0
- package/dist/esm/node/vite/plugins/pluginReplaceConstantsGlobalThis.js +77 -0
- package/dist/esm/node/vite/plugins/pluginReplaceConstantsPageContext.d.ts +3 -0
- package/dist/esm/node/vite/plugins/{pluginReplaceIsClientSide.js → pluginReplaceConstantsPageContext.js} +5 -3
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntry.js +7 -1
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntryWithOldDesign.js +3 -0
- package/dist/esm/node/vite/plugins/pluginVirtualFiles.js +2 -2
- package/dist/esm/node/vite/plugins/pluginViteConfigVikeExtensions.d.ts +3 -0
- package/dist/esm/node/vite/plugins/pluginViteConfigVikeExtensions.js +32 -0
- package/dist/esm/node/vite/shared/getFilePath.d.ts +4 -6
- package/dist/esm/node/vite/shared/getFilePath.js +6 -11
- package/dist/esm/node/vite/shared/isViteCli.d.ts +13 -0
- package/dist/esm/node/vite/shared/isViteCli.js +143 -0
- package/dist/esm/node/vite/shared/isViteServerSide.d.ts +6 -3
- package/dist/esm/node/vite/shared/isViteServerSide.js +13 -4
- package/dist/esm/node/vite/shared/loggerNotProd/errorWithCodeSnippet.js +2 -2
- package/dist/esm/node/vite/shared/loggerNotProd/log.js +8 -2
- package/dist/esm/node/vite/shared/loggerNotProd.d.ts +1 -1
- package/dist/esm/node/vite/shared/loggerNotProd.js +11 -11
- package/dist/esm/node/vite/shared/loggerVite.js +4 -2
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +12 -2
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal/transpileAndExecuteFile.js +12 -8
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal.d.ts +2 -0
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal.js +4 -0
- package/dist/esm/node/vite/utils.d.ts +1 -0
- package/dist/esm/node/vite/utils.js +1 -0
- package/dist/esm/shared/createGlobalContextShared.d.ts +2 -1
- package/dist/esm/shared/createGlobalContextShared.js +1 -1
- package/dist/esm/shared/hooks/execHook.d.ts +1 -1
- package/dist/esm/shared/hooks/getHook.d.ts +5 -4
- package/dist/esm/shared/route/abort.d.ts +1 -0
- package/dist/esm/shared/route/abort.js +12 -4
- package/dist/esm/shared/route/index.js +13 -4
- package/dist/esm/shared/route/utils.d.ts +1 -0
- package/dist/esm/shared/route/utils.js +1 -0
- package/dist/esm/types/Config.d.ts +14 -3
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/assert.js +1 -0
- package/dist/esm/utils/assertNodeVersion.js +1 -1
- package/dist/esm/utils/assertViteVersion.d.ts +2 -0
- package/dist/esm/utils/assertViteVersion.js +11 -0
- package/dist/esm/utils/debug.d.ts +5 -3
- package/dist/esm/utils/debug.js +20 -16
- package/dist/esm/utils/getGlobalObject.d.ts +5 -1
- package/dist/esm/utils/getGlobalObject.js +5 -1
- package/dist/esm/utils/isExactlyOneTruthy.d.ts +1 -0
- package/dist/esm/utils/isExactlyOneTruthy.js +4 -0
- package/dist/esm/utils/isVikeReactApp.js +2 -1
- package/dist/esm/utils/requireResolve.js +1 -1
- package/package.json +3 -3
- package/dist/esm/node/vite/plugins/pluginEnvVars.d.ts +0 -3
- package/dist/esm/node/vite/plugins/pluginEnvVars.js +0 -110
- package/dist/esm/node/vite/plugins/pluginReplaceGlobalThisConstants.d.ts +0 -9
- package/dist/esm/node/vite/plugins/pluginReplaceGlobalThisConstants.js +0 -45
- package/dist/esm/node/vite/plugins/pluginReplaceIsClientSide.d.ts +0 -3
- package/dist/esm/node/vite/shared/isViteCliCall.d.ts +0 -10
- package/dist/esm/node/vite/shared/isViteCliCall.js +0 -81
- package/dist/esm/shared/route/debug.d.ts +0 -6
- package/dist/esm/shared/route/debug.js +0 -21
|
@@ -7,7 +7,7 @@ import { parseVirtualFileId } from '../../shared/virtualFileId.js';
|
|
|
7
7
|
import { reloadVikeConfig, isV1Design, getVikeConfigInternalOptional } from '../shared/resolveVikeConfigInternal.js';
|
|
8
8
|
import pc from '@brillout/picocolors';
|
|
9
9
|
import { logConfigInfo } from '../shared/loggerNotProd.js';
|
|
10
|
-
import {
|
|
10
|
+
import { getFilePathToShowToUserModule } from '../shared/getFilePath.js';
|
|
11
11
|
import { isRunnable, updateUserFiles } from '../../runtime/globalContext.js';
|
|
12
12
|
import { isPlusFile } from '../shared/resolveVikeConfigInternal/crawlPlusFiles.js';
|
|
13
13
|
import { isTemporaryBuildFile } from '../shared/resolveVikeConfigInternal/transpileAndExecuteFile.js';
|
|
@@ -176,7 +176,7 @@ function reloadConfig(filePath, config, op, server) {
|
|
|
176
176
|
// Ensure server.ssrLoadModule() loads fresh Vike virtual files (`reloadConfig()` > `updateUserFiles()` > `server.ssrLoadModule()`)
|
|
177
177
|
invalidateVikeVirtualFiles(server);
|
|
178
178
|
{
|
|
179
|
-
const filePathToShowToUserResolved =
|
|
179
|
+
const filePathToShowToUserResolved = getFilePathToShowToUserModule(filePath, config);
|
|
180
180
|
const msg = `${op} ${pc.dim(filePathToShowToUserResolved)}`;
|
|
181
181
|
logConfigInfo(msg, 'info');
|
|
182
182
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export { pluginViteConfigVikeExtensions };
|
|
2
|
+
import { mergeConfig } from 'vite';
|
|
3
|
+
import { assertUsage, isObject } from '../utils.js';
|
|
4
|
+
import { getVikeConfigInternalEarly } from '../../api/resolveViteConfigFromUser.js';
|
|
5
|
+
// Apply +vite
|
|
6
|
+
// - For example, Vike extensions adding Vite plugins
|
|
7
|
+
async function pluginViteConfigVikeExtensions() {
|
|
8
|
+
const vikeConfig = await getVikeConfigInternalEarly();
|
|
9
|
+
if (vikeConfig === null)
|
|
10
|
+
return [];
|
|
11
|
+
let viteConfigFromExtensions = {};
|
|
12
|
+
const viteConfigsExtensions = vikeConfig._from.configsCumulative.vite;
|
|
13
|
+
if (!viteConfigsExtensions)
|
|
14
|
+
return [];
|
|
15
|
+
viteConfigsExtensions.values.forEach((v) => {
|
|
16
|
+
assertUsage(isObject(v.value), `${v.definedAt} should be an object`);
|
|
17
|
+
viteConfigFromExtensions = mergeConfig(viteConfigFromExtensions, v.value);
|
|
18
|
+
});
|
|
19
|
+
const pluginsFromExtensions = (viteConfigFromExtensions.plugins ?? []);
|
|
20
|
+
delete viteConfigFromExtensions.plugins;
|
|
21
|
+
return [
|
|
22
|
+
...pluginsFromExtensions,
|
|
23
|
+
{
|
|
24
|
+
name: 'vike:pluginViteConfigVikeExtensions',
|
|
25
|
+
config: {
|
|
26
|
+
handler(_config) {
|
|
27
|
+
return viteConfigFromExtensions;
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
];
|
|
32
|
+
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
export { getFilePathResolved };
|
|
2
2
|
export { getFilePathUnresolved };
|
|
3
3
|
export { getFilePathAbsoluteUserRootDir };
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export { getModuleFilePathRelative };
|
|
4
|
+
export { getFilePathToShowToUserUnknown };
|
|
5
|
+
export { getFilePathToShowToUserModule };
|
|
7
6
|
export { cleanFilePathUnknown };
|
|
8
7
|
export { assertModuleId };
|
|
9
8
|
import type { FilePathResolved, FilePathUnresolved } from '../../../types/FilePath.js';
|
|
@@ -24,8 +23,7 @@ declare function getFilePathAbsoluteUserRootDir({ filePathAbsoluteFilesystem, us
|
|
|
24
23
|
filePathAbsoluteFilesystem: string;
|
|
25
24
|
userRootDir: string;
|
|
26
25
|
}): string | null;
|
|
27
|
-
declare function
|
|
28
|
-
declare function getModuleFilePathRelative(moduleId: string, config: ResolvedConfig): string;
|
|
26
|
+
declare function getFilePathToShowToUserModule(moduleId: string, config: ResolvedConfig): string;
|
|
29
27
|
declare function assertModuleId(moduleId: string): void;
|
|
30
|
-
declare function
|
|
28
|
+
declare function getFilePathToShowToUserUnknown(filePathUnknown: string, userRootDir: string): string;
|
|
31
29
|
declare function cleanFilePathUnknown(filePathUnknown: string): string;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
export { getFilePathResolved };
|
|
2
2
|
export { getFilePathUnresolved };
|
|
3
3
|
export { getFilePathAbsoluteUserRootDir };
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export { getModuleFilePathRelative };
|
|
4
|
+
export { getFilePathToShowToUserUnknown };
|
|
5
|
+
export { getFilePathToShowToUserModule };
|
|
7
6
|
export { cleanFilePathUnknown };
|
|
8
7
|
export { assertModuleId };
|
|
9
8
|
import path from 'node:path';
|
|
@@ -107,15 +106,11 @@ function getFilePathRelative({ filePathAbsoluteFilesystem, userRootDir, }) {
|
|
|
107
106
|
return { filePathAbsoluteUserRootDir, filePathRelativeUserRootDir };
|
|
108
107
|
}
|
|
109
108
|
}
|
|
110
|
-
function
|
|
111
|
-
const { filePathAbsoluteUserRootDir, filePathAbsoluteFilesystem } =
|
|
109
|
+
function getFilePathToShowToUserModule(moduleId, config) {
|
|
110
|
+
const { filePathAbsoluteUserRootDir, filePathAbsoluteFilesystem } = getFilePathModule(moduleId, config);
|
|
112
111
|
return filePathAbsoluteUserRootDir || filePathAbsoluteFilesystem;
|
|
113
112
|
}
|
|
114
|
-
function
|
|
115
|
-
const { filePathRelativeUserRootDir } = getModuleFilePath(moduleId, config);
|
|
116
|
-
return filePathRelativeUserRootDir;
|
|
117
|
-
}
|
|
118
|
-
function getModuleFilePath(moduleId, config) {
|
|
113
|
+
function getFilePathModule(moduleId, config) {
|
|
119
114
|
const userRootDir = config.root;
|
|
120
115
|
assertModuleId(moduleId);
|
|
121
116
|
assertPosixPath(userRootDir);
|
|
@@ -132,7 +127,7 @@ function assertModuleId(moduleId) {
|
|
|
132
127
|
assertPosixPath(moduleId);
|
|
133
128
|
assertFilePathAbsoluteFilesystem(moduleId); // Can moduleId be something else than the filesystem absolute path?
|
|
134
129
|
}
|
|
135
|
-
function
|
|
130
|
+
function getFilePathToShowToUserUnknown(
|
|
136
131
|
// We don't have any guarantee about filePath, e.g. about whether is filePathAbsoluteFilesystem or filePathAbsoluteUserRootDir
|
|
137
132
|
filePathUnknown, userRootDir) {
|
|
138
133
|
assertPosixPath(userRootDir);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { isViteCli };
|
|
2
|
+
export { getViteConfigForBuildFromCli };
|
|
3
|
+
export { getViteCommandFromCli };
|
|
4
|
+
declare function isViteCli(): boolean;
|
|
5
|
+
type ConfigFromCli = {
|
|
6
|
+
root: undefined | string;
|
|
7
|
+
configFile: undefined | string;
|
|
8
|
+
} & Record<string, unknown> & {
|
|
9
|
+
build: Record<string, unknown>;
|
|
10
|
+
};
|
|
11
|
+
type ViteCommand = 'dev' | 'build' | 'optimize' | 'preview';
|
|
12
|
+
declare function getViteCommandFromCli(): ViteCommand | null;
|
|
13
|
+
declare function getViteConfigForBuildFromCli(): null | ConfigFromCli;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
export { isViteCli };
|
|
2
|
+
export { getViteConfigForBuildFromCli };
|
|
3
|
+
export { getViteCommandFromCli };
|
|
4
|
+
import { assert, isObject, toPosixPath } from '../utils.js';
|
|
5
|
+
import { cac } from 'cac';
|
|
6
|
+
const desc = 'vike:vite-cli-simulation';
|
|
7
|
+
function isViteCli() {
|
|
8
|
+
let execPath = process.argv[1];
|
|
9
|
+
assert(execPath);
|
|
10
|
+
execPath = toPosixPath(execPath);
|
|
11
|
+
return (
|
|
12
|
+
// pnpm
|
|
13
|
+
execPath.endsWith('/bin/vite.js') ||
|
|
14
|
+
// npm & yarn
|
|
15
|
+
execPath.endsWith('/.bin/vite') ||
|
|
16
|
+
// Global install
|
|
17
|
+
execPath.endsWith('/bin/vite'));
|
|
18
|
+
}
|
|
19
|
+
function getViteCommandFromCli() {
|
|
20
|
+
if (!isViteCli())
|
|
21
|
+
return null;
|
|
22
|
+
let command;
|
|
23
|
+
const setCommand = (cmd) => {
|
|
24
|
+
assert(command === undefined);
|
|
25
|
+
command = cmd;
|
|
26
|
+
};
|
|
27
|
+
// Copied & adapted from Vite
|
|
28
|
+
// https://github.com/vitejs/vite/blob/d3e7eeefa91e1992f47694d16fe4dbe708c4d80e/packages/vite/src/node/cli.ts#L186-L188
|
|
29
|
+
const cli = cac(desc);
|
|
30
|
+
// dev
|
|
31
|
+
cli
|
|
32
|
+
.command('[root]', desc)
|
|
33
|
+
.alias('serve')
|
|
34
|
+
.alias('dev')
|
|
35
|
+
.action(() => {
|
|
36
|
+
setCommand('dev');
|
|
37
|
+
});
|
|
38
|
+
// build
|
|
39
|
+
cli.command('build [root]', desc).action(() => {
|
|
40
|
+
setCommand('build');
|
|
41
|
+
});
|
|
42
|
+
// optimize
|
|
43
|
+
cli.command('optimize [root]', desc).action(() => {
|
|
44
|
+
setCommand('optimize');
|
|
45
|
+
});
|
|
46
|
+
// preview
|
|
47
|
+
cli.command('preview [root]', desc).action(() => {
|
|
48
|
+
setCommand('preview');
|
|
49
|
+
});
|
|
50
|
+
cli.parse();
|
|
51
|
+
assert(command);
|
|
52
|
+
return command;
|
|
53
|
+
}
|
|
54
|
+
function getViteConfigForBuildFromCli() {
|
|
55
|
+
if (!isViteCli())
|
|
56
|
+
return null;
|
|
57
|
+
// Copied & adapted from Vite
|
|
58
|
+
const cli = cac(desc);
|
|
59
|
+
// Common configs
|
|
60
|
+
// https://github.com/vitejs/vite/blob/d3e7eeefa91e1992f47694d16fe4dbe708c4d80e/packages/vite/src/node/cli.ts#L169-L182
|
|
61
|
+
cli
|
|
62
|
+
.option('-c, --config <file>', desc)
|
|
63
|
+
.option('--base <path>', desc)
|
|
64
|
+
.option('-l, --logLevel <level>', desc)
|
|
65
|
+
.option('--clearScreen', desc)
|
|
66
|
+
.option('--configLoader <loader>', desc)
|
|
67
|
+
.option('-d, --debug [feat]', desc)
|
|
68
|
+
.option('-f, --filter <filter>', desc)
|
|
69
|
+
.option('-m, --mode <mode>', desc);
|
|
70
|
+
// Build configs
|
|
71
|
+
// https://github.com/vitejs/vite/blob/d3e7eeefa91e1992f47694d16fe4dbe708c4d80e/packages/vite/src/node/cli.ts#L286-L322
|
|
72
|
+
cli
|
|
73
|
+
.command('build [root]', desc)
|
|
74
|
+
.option('--target <target>', desc)
|
|
75
|
+
.option('--outDir <dir>', desc)
|
|
76
|
+
.option('--assetsDir <dir>', desc)
|
|
77
|
+
.option('--assetsInlineLimit <number>', desc)
|
|
78
|
+
.option('--ssr [entry]', desc)
|
|
79
|
+
.option('--sourcemap', desc)
|
|
80
|
+
.option('--minify [minifier]', desc)
|
|
81
|
+
.option('--manifest [name]', desc)
|
|
82
|
+
.option('--ssrManifest [name]', desc)
|
|
83
|
+
.option('--emptyOutDir', desc)
|
|
84
|
+
.option('-w, --watch', desc)
|
|
85
|
+
.option('--app', desc)
|
|
86
|
+
.action((root, options) => {
|
|
87
|
+
assert(isObject(options));
|
|
88
|
+
assert(root === undefined || typeof root === 'string');
|
|
89
|
+
assert(options.config === undefined || typeof options.config === 'string');
|
|
90
|
+
// https://github.com/vitejs/vite/blob/d3e7eeefa91e1992f47694d16fe4dbe708c4d80e/packages/vite/src/node/cli.ts#L331-L346
|
|
91
|
+
const buildOptions = cleanGlobalCLIOptions(cleanBuilderCLIOptions(options));
|
|
92
|
+
configFromCli = {
|
|
93
|
+
root,
|
|
94
|
+
base: options.base,
|
|
95
|
+
mode: options.mode,
|
|
96
|
+
configFile: options.config,
|
|
97
|
+
configLoader: options.configLoader,
|
|
98
|
+
logLevel: options.logLevel,
|
|
99
|
+
clearScreen: options.clearScreen,
|
|
100
|
+
build: buildOptions,
|
|
101
|
+
...(options.app ? { builder: {} } : {}),
|
|
102
|
+
};
|
|
103
|
+
});
|
|
104
|
+
let configFromCli = null;
|
|
105
|
+
cli.parse();
|
|
106
|
+
return configFromCli;
|
|
107
|
+
// https://github.com/vitejs/vite/blob/d3e7eeefa91e1992f47694d16fe4dbe708c4d80e/packages/vite/src/node/cli.ts#L99
|
|
108
|
+
function cleanGlobalCLIOptions(options) {
|
|
109
|
+
const ret = { ...options };
|
|
110
|
+
delete ret['--'];
|
|
111
|
+
delete ret.c;
|
|
112
|
+
delete ret.config;
|
|
113
|
+
delete ret.base;
|
|
114
|
+
delete ret.l;
|
|
115
|
+
delete ret.logLevel;
|
|
116
|
+
delete ret.clearScreen;
|
|
117
|
+
delete ret.configLoader;
|
|
118
|
+
delete ret.d;
|
|
119
|
+
delete ret.debug;
|
|
120
|
+
delete ret.f;
|
|
121
|
+
delete ret.filter;
|
|
122
|
+
delete ret.m;
|
|
123
|
+
delete ret.mode;
|
|
124
|
+
delete ret.force;
|
|
125
|
+
delete ret.w;
|
|
126
|
+
// convert the sourcemap option to a boolean if necessary
|
|
127
|
+
if ('sourcemap' in ret) {
|
|
128
|
+
const sourcemap = ret.sourcemap;
|
|
129
|
+
ret.sourcemap = sourcemap === 'true' ? true : sourcemap === 'false' ? false : ret.sourcemap;
|
|
130
|
+
}
|
|
131
|
+
if ('watch' in ret) {
|
|
132
|
+
const watch = ret.watch;
|
|
133
|
+
ret.watch = watch ? {} : undefined;
|
|
134
|
+
}
|
|
135
|
+
return ret;
|
|
136
|
+
}
|
|
137
|
+
// https://github.com/vitejs/vite/blob/d3e7eeefa91e1992f47694d16fe4dbe708c4d80e/packages/vite/src/node/cli.ts#L141
|
|
138
|
+
function cleanBuilderCLIOptions(options) {
|
|
139
|
+
const ret = { ...options };
|
|
140
|
+
delete ret.app;
|
|
141
|
+
return ret;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
export { isViteServerSide };
|
|
2
|
-
export { isViteClientSide };
|
|
3
2
|
export { isViteServerSide_viteEnvOptional };
|
|
4
3
|
export { isViteServerSide_onlySsrEnv };
|
|
5
4
|
export { isViteServerSide_extraSafe };
|
|
5
|
+
export { isViteServerSide_applyToEnvironment };
|
|
6
|
+
export { isViteServerSide_configEnvironment };
|
|
6
7
|
export type { ViteEnv };
|
|
7
|
-
import type { Environment, EnvironmentOptions, ResolvedConfig, UserConfig } from 'vite';
|
|
8
|
+
import type { Environment, EnvironmentOptions, ResolvedConfig, UserConfig, Plugin } from 'vite';
|
|
8
9
|
type ViteEnv = {
|
|
9
10
|
name?: string;
|
|
10
11
|
config: EnvironmentOptions | Environment['config'];
|
|
11
12
|
};
|
|
12
13
|
declare function isViteServerSide(configGlobal: ResolvedConfig | UserConfig, viteEnv: ViteEnv): boolean;
|
|
13
14
|
declare function isViteServerSide_viteEnvOptional(configGlobal: ResolvedConfig | UserConfig, viteEnv?: ViteEnv | undefined): boolean;
|
|
14
|
-
declare function isViteClientSide(configGlobal: ResolvedConfig, viteEnv: ViteEnv): boolean;
|
|
15
15
|
declare function isViteServerSide_onlySsrEnv(configGlobal: ResolvedConfig, viteEnv: ViteEnv): boolean;
|
|
16
16
|
declare function isViteServerSide_extraSafe(config: ResolvedConfig, viteEnv: ViteEnv, options: {
|
|
17
17
|
ssr?: boolean;
|
|
18
18
|
} | undefined): boolean;
|
|
19
|
+
type PartialEnvironment = Parameters<NonNullable<Plugin['applyToEnvironment']>>[0];
|
|
20
|
+
declare function isViteServerSide_applyToEnvironment(env: PartialEnvironment): boolean;
|
|
21
|
+
declare function isViteServerSide_configEnvironment(name: string, config: EnvironmentOptions): boolean;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export { isViteServerSide };
|
|
2
|
-
export { isViteClientSide };
|
|
3
2
|
export { isViteServerSide_viteEnvOptional };
|
|
4
3
|
export { isViteServerSide_onlySsrEnv };
|
|
5
4
|
export { isViteServerSide_extraSafe };
|
|
5
|
+
export { isViteServerSide_applyToEnvironment };
|
|
6
|
+
export { isViteServerSide_configEnvironment };
|
|
6
7
|
import { assert } from '../../../utils/assert.js';
|
|
7
8
|
function isViteServerSide_impl(configGlobal, viteEnv) {
|
|
8
9
|
assert(!('consumer' in configGlobal)); // make sure configGlobal isn't viteEnv.config
|
|
@@ -42,9 +43,6 @@ function isViteServerSide(configGlobal, viteEnv) {
|
|
|
42
43
|
function isViteServerSide_viteEnvOptional(configGlobal, viteEnv) {
|
|
43
44
|
return isViteServerSide_impl(configGlobal, viteEnv);
|
|
44
45
|
}
|
|
45
|
-
function isViteClientSide(configGlobal, viteEnv) {
|
|
46
|
-
return !isViteServerSide(configGlobal, viteEnv);
|
|
47
|
-
}
|
|
48
46
|
// Only `ssr` env: for example don't include `vercel_edge` nor `vercel_node`.
|
|
49
47
|
function isViteServerSide_onlySsrEnv(configGlobal, viteEnv) {
|
|
50
48
|
return viteEnv.name ? viteEnv.name === 'ssr' : isViteServerSide(configGlobal, viteEnv);
|
|
@@ -64,3 +62,14 @@ function isViteServerSide_extraSafe(config, viteEnv, options) {
|
|
|
64
62
|
assert(options.ssr === isServerSide, debug);
|
|
65
63
|
return isServerSide;
|
|
66
64
|
}
|
|
65
|
+
function isViteServerSide_applyToEnvironment(env) {
|
|
66
|
+
const { consumer } = env.config;
|
|
67
|
+
return isViteServerSide_consumer(consumer);
|
|
68
|
+
}
|
|
69
|
+
function isViteServerSide_configEnvironment(name, config) {
|
|
70
|
+
const consumer = config.consumer ?? (name === 'client' ? 'client' : 'server');
|
|
71
|
+
return isViteServerSide_consumer(consumer);
|
|
72
|
+
}
|
|
73
|
+
function isViteServerSide_consumer(consumer) {
|
|
74
|
+
return consumer !== 'client';
|
|
75
|
+
}
|
|
@@ -8,7 +8,7 @@ export { getPrettyErrMessage };
|
|
|
8
8
|
// Copied & adapted from https://github.com/vitejs/vite/blob/9c114c5c72a6af87e3330d5573362554b4511265/packages/vite/src/node/server/middlewares/error.ts
|
|
9
9
|
import pc from '@brillout/picocolors';
|
|
10
10
|
import { assert, escapeRegex, isObject, removeEmptyLines, stripAnsi } from '../../utils.js';
|
|
11
|
-
import { cleanFilePathUnknown,
|
|
11
|
+
import { cleanFilePathUnknown, getFilePathToShowToUserUnknown } from '../getFilePath.js';
|
|
12
12
|
function isErrorWithCodeSnippet(err) {
|
|
13
13
|
if (!isObject(err)) {
|
|
14
14
|
return false;
|
|
@@ -47,7 +47,7 @@ function getPrettyErrorWithCodeSnippet(err, userRootDir) {
|
|
|
47
47
|
let { id, frame } = err;
|
|
48
48
|
const msgFirstLine = [
|
|
49
49
|
pc.red('Failed to transpile'),
|
|
50
|
-
pc.bold(pc.red(
|
|
50
|
+
pc.bold(pc.red(getFilePathToShowToUserUnknown(id, userRootDir))),
|
|
51
51
|
pc.red('because:'),
|
|
52
52
|
].join(' ');
|
|
53
53
|
const errMsg = getPrettyErrMessage(err);
|
|
@@ -6,6 +6,7 @@ import { assert, stripAnsi, hasProp, assertIsNotProductionRuntime, PROJECT_VERSI
|
|
|
6
6
|
import pc from '@brillout/picocolors';
|
|
7
7
|
import { isErrorDebug } from '../../../shared/isErrorDebug.js';
|
|
8
8
|
import { getViteDevServer } from '../../../runtime/globalContext.js';
|
|
9
|
+
import { logErrorServer } from '../../../runtime/logErrorServer.js';
|
|
9
10
|
assertIsNotProductionRuntime();
|
|
10
11
|
function logWithVikeTag(msg, logType, category, showVikeVersion = false) {
|
|
11
12
|
const projectTag = getProjectTag(showVikeVersion);
|
|
@@ -39,10 +40,15 @@ function logDirectly(thing, logType) {
|
|
|
39
40
|
console.warn(thing);
|
|
40
41
|
return;
|
|
41
42
|
}
|
|
42
|
-
if (logType === 'error') {
|
|
43
|
+
if (logType === 'error-note') {
|
|
43
44
|
console.error(thing);
|
|
44
45
|
return;
|
|
45
46
|
}
|
|
47
|
+
if (logType === 'error-thrown') {
|
|
48
|
+
// console.error()
|
|
49
|
+
logErrorServer(thing);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
46
52
|
if (logType === 'error-recover') {
|
|
47
53
|
// stderr because user will most likely want to know about error recovering
|
|
48
54
|
console.error(thing);
|
|
@@ -63,7 +69,7 @@ function applyViteSourceMapToStackTrace(thing) {
|
|
|
63
69
|
}
|
|
64
70
|
function prependTags(msg, projectTag, category, logType) {
|
|
65
71
|
const color = (s) => {
|
|
66
|
-
if (logType === 'error' && !hasRed(msg))
|
|
72
|
+
if (logType === 'error-thrown' && !hasRed(msg))
|
|
67
73
|
return pc.bold(pc.red(s));
|
|
68
74
|
if (logType === 'error-recover' && !hasGreen(msg))
|
|
69
75
|
return pc.bold(pc.green(s));
|
|
@@ -10,7 +10,7 @@ export type { LogError };
|
|
|
10
10
|
export type { LogErrorArgs };
|
|
11
11
|
export type { LogType };
|
|
12
12
|
export type { LogCategory };
|
|
13
|
-
type LogType = 'info' | 'warn' | 'error' | 'error-recover';
|
|
13
|
+
type LogType = 'info' | 'warn' | 'error-thrown' | 'error-recover' | 'error-note';
|
|
14
14
|
type LogCategory = 'config' | `request(${number})`;
|
|
15
15
|
type LogInfo = (...args: LogInfoArgs) => void;
|
|
16
16
|
type LogInfoArgs = Parameters<typeof logRuntimeInfo>;
|
|
@@ -89,7 +89,7 @@ function logErr(err, httpRequestId = null, errorComesFromVite) {
|
|
|
89
89
|
assert(viteConfig);
|
|
90
90
|
const prettyErr = getPrettyErrorWithCodeSnippet(err, viteConfig.root);
|
|
91
91
|
assert(stripAnsi(prettyErr).startsWith('Failed to transpile'));
|
|
92
|
-
logWithViteTag(prettyErr, 'error', category);
|
|
92
|
+
logWithViteTag(prettyErr, 'error-thrown', category);
|
|
93
93
|
logErrorDebugNote();
|
|
94
94
|
return;
|
|
95
95
|
}
|
|
@@ -103,12 +103,12 @@ function logErr(err, httpRequestId = null, errorComesFromVite) {
|
|
|
103
103
|
const hook = isUserHookError(err);
|
|
104
104
|
if (hook) {
|
|
105
105
|
const { hookName, hookFilePath } = hook;
|
|
106
|
-
logWithVikeTag(pc.red(`Following error was thrown by the ${hookName}() hook defined at ${hookFilePath}`), 'error', category);
|
|
106
|
+
logWithVikeTag(pc.red(`Following error was thrown by the ${hookName}() hook defined at ${hookFilePath}`), 'error-note', category);
|
|
107
107
|
}
|
|
108
108
|
else if (category) {
|
|
109
109
|
logFallbackErrIntro(category, errorComesFromVite);
|
|
110
110
|
}
|
|
111
|
-
logDirectly(err, 'error');
|
|
111
|
+
logDirectly(err, 'error-thrown');
|
|
112
112
|
// Needs to be called after logging the error.
|
|
113
113
|
onRuntimeError(err);
|
|
114
114
|
}
|
|
@@ -119,8 +119,8 @@ function logConfigError(err) {
|
|
|
119
119
|
const errIntroMsg = getConfigExecutionErrorIntroMsg(err);
|
|
120
120
|
if (errIntroMsg) {
|
|
121
121
|
assert(stripAnsi(errIntroMsg).startsWith('Failed to execute'));
|
|
122
|
-
logWithVikeTag(errIntroMsg, 'error', category);
|
|
123
|
-
logDirectly(err, 'error');
|
|
122
|
+
logWithVikeTag(errIntroMsg, 'error-note', category);
|
|
123
|
+
logDirectly(err, 'error-thrown');
|
|
124
124
|
return;
|
|
125
125
|
}
|
|
126
126
|
}
|
|
@@ -129,10 +129,10 @@ function logConfigError(err) {
|
|
|
129
129
|
if (errMsgFormatted) {
|
|
130
130
|
assert(stripAnsi(errMsgFormatted).startsWith('Failed to transpile'));
|
|
131
131
|
if (!isErrorDebug()) {
|
|
132
|
-
logWithVikeTag(errMsgFormatted, 'error', category);
|
|
132
|
+
logWithVikeTag(errMsgFormatted, 'error-thrown', category);
|
|
133
133
|
}
|
|
134
134
|
else {
|
|
135
|
-
logDirectly(err, 'error');
|
|
135
|
+
logDirectly(err, 'error-thrown');
|
|
136
136
|
}
|
|
137
137
|
return;
|
|
138
138
|
}
|
|
@@ -144,11 +144,11 @@ function logConfigError(err) {
|
|
|
144
144
|
}
|
|
145
145
|
if (category)
|
|
146
146
|
logFallbackErrIntro(category, false);
|
|
147
|
-
logDirectly(err, 'error');
|
|
147
|
+
logDirectly(err, 'error-thrown');
|
|
148
148
|
}
|
|
149
149
|
function logFallbackErrIntro(category, errorComesFromVite) {
|
|
150
150
|
const msg = errorComesFromVite ? 'Transpilation error' : 'An error was thrown';
|
|
151
|
-
logWithVikeTag(pc.bold(pc.red(`[Error] ${msg}:`)), 'error', category);
|
|
151
|
+
logWithVikeTag(pc.bold(pc.red(`[Error] ${msg}:`)), 'error-note', category);
|
|
152
152
|
}
|
|
153
153
|
function getConfigCategory() {
|
|
154
154
|
const category = getCategory() ?? 'config';
|
|
@@ -159,7 +159,7 @@ function handleAssertMsg(err, category) {
|
|
|
159
159
|
if (!res)
|
|
160
160
|
return false;
|
|
161
161
|
const { assertMsg, showVikeVersion } = res;
|
|
162
|
-
logWithVikeTag(assertMsg, 'error', category, showVikeVersion);
|
|
162
|
+
logWithVikeTag(assertMsg, 'error-thrown', category, showVikeVersion);
|
|
163
163
|
return true;
|
|
164
164
|
}
|
|
165
165
|
function assertLogger(thing, logType) {
|
|
@@ -189,7 +189,7 @@ function logErrorDebugNote() {
|
|
|
189
189
|
store.errorDebugNoteAlreadyShown = true;
|
|
190
190
|
}
|
|
191
191
|
const msg = pc.dim(formatHintLog("Error isn't helpful? See https://vike.dev/debug#verbose-errors"));
|
|
192
|
-
logDirectly(msg, 'error');
|
|
192
|
+
logDirectly(msg, 'error-note');
|
|
193
193
|
}
|
|
194
194
|
function getCategory(httpRequestId = null) {
|
|
195
195
|
const store = getHttpRequestAsyncStore();
|
|
@@ -9,8 +9,8 @@ function improveViteLogs(config) {
|
|
|
9
9
|
intercept('warn', config);
|
|
10
10
|
intercept('error', config);
|
|
11
11
|
}
|
|
12
|
-
function intercept(
|
|
13
|
-
config.logger[
|
|
12
|
+
function intercept(loggerType, config) {
|
|
13
|
+
config.logger[loggerType] = (msg, options = {}) => {
|
|
14
14
|
assert(!isErrorDebug());
|
|
15
15
|
if (removeSuperfluousViteLog(msg))
|
|
16
16
|
return;
|
|
@@ -38,6 +38,8 @@ function intercept(logType, config) {
|
|
|
38
38
|
}
|
|
39
39
|
// Vite's default logger preprends the "[vite]" tag if and only if options.timestamp is true
|
|
40
40
|
const prependViteTag = options.timestamp || !!store?.httpRequestId;
|
|
41
|
+
// If it's an actual error => options.error is set => it's handled with logViteError() above
|
|
42
|
+
const logType = loggerType === 'error' ? 'error-note' : loggerType;
|
|
41
43
|
logViteAny(msg, logType, store?.httpRequestId ?? null, prependViteTag);
|
|
42
44
|
};
|
|
43
45
|
}
|
|
@@ -27,6 +27,11 @@ const configDefinitionsBuiltIn = {
|
|
|
27
27
|
global: true,
|
|
28
28
|
cumulative: true,
|
|
29
29
|
},
|
|
30
|
+
onError: {
|
|
31
|
+
env: { server: true },
|
|
32
|
+
global: true,
|
|
33
|
+
cumulative: true,
|
|
34
|
+
},
|
|
30
35
|
onBeforeRender: {
|
|
31
36
|
env: { server: true },
|
|
32
37
|
},
|
|
@@ -96,11 +101,11 @@ const configDefinitionsBuiltIn = {
|
|
|
96
101
|
meta: {
|
|
97
102
|
env: { config: true },
|
|
98
103
|
},
|
|
99
|
-
|
|
104
|
+
hasServerOnlyHook: {
|
|
100
105
|
env: { client: true },
|
|
101
106
|
eager: true,
|
|
102
107
|
_computed: (pageConfig) => {
|
|
103
|
-
const sources = ['data', 'onBeforeRender', 'onCreatePageContext']
|
|
108
|
+
const sources = ['data', 'onBeforeRender', 'onCreatePageContext', 'guard']
|
|
104
109
|
.map((hookName) => getConfigValueSourcesRelevant(hookName, {
|
|
105
110
|
isForClientSide: false,
|
|
106
111
|
// TO-DO/eventually/remove-server-router: let's eventually remove support for Server Routing
|
|
@@ -171,6 +176,10 @@ const configDefinitionsBuiltIn = {
|
|
|
171
176
|
env: { config: true },
|
|
172
177
|
global: true,
|
|
173
178
|
},
|
|
179
|
+
force: {
|
|
180
|
+
env: { config: true },
|
|
181
|
+
global: true,
|
|
182
|
+
},
|
|
174
183
|
csp: {
|
|
175
184
|
env: { server: true },
|
|
176
185
|
},
|
|
@@ -207,6 +216,7 @@ const configDefinitionsBuiltIn = {
|
|
|
207
216
|
env: { config: true },
|
|
208
217
|
global: true,
|
|
209
218
|
},
|
|
219
|
+
// This is deprecated (since Summer 2025). But don't remove this (yet) — otherwise it will break older Vike extensions that still use it.
|
|
210
220
|
vite6BuilderApp: {
|
|
211
221
|
env: { config: true },
|
|
212
222
|
global: true,
|
|
@@ -141,6 +141,15 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
|
|
|
141
141
|
return resolved;
|
|
142
142
|
}
|
|
143
143
|
assert(resolved.path);
|
|
144
|
+
// Built-in modules e.g. node:fs
|
|
145
|
+
if (resolved.path === args.path) {
|
|
146
|
+
const isPointerImport = false;
|
|
147
|
+
pointerImports[args.path] = isPointerImport;
|
|
148
|
+
if (debug.isActivated)
|
|
149
|
+
debug('onResolve() [built-in module]', { args, resolved });
|
|
150
|
+
assert(resolved.external);
|
|
151
|
+
return resolved;
|
|
152
|
+
}
|
|
144
153
|
const importPathResolved = toPosixPath(resolved.path);
|
|
145
154
|
const importPathOriginal = args.path;
|
|
146
155
|
// Esbuild resolves path aliases.
|
|
@@ -185,7 +194,7 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
|
|
|
185
194
|
// User-land config code (i.e. not runtime code) => let esbuild transpile it
|
|
186
195
|
assert(!isPointerImport && !isNpmPkgImport);
|
|
187
196
|
if (debug.isActivated)
|
|
188
|
-
debug('
|
|
197
|
+
debug('onResolve() [non-external]', { args, resolved, isPointerImport, isExternal });
|
|
189
198
|
return resolved;
|
|
190
199
|
}
|
|
191
200
|
let importPathTranspiled;
|
|
@@ -217,7 +226,7 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
|
|
|
217
226
|
}
|
|
218
227
|
}
|
|
219
228
|
if (debug.isActivated)
|
|
220
|
-
debug('
|
|
229
|
+
debug('onResolve() [external]', { args, resolved, importPathTranspiled, isPointerImport, isExternal });
|
|
221
230
|
assert(isExternal);
|
|
222
231
|
assert(
|
|
223
232
|
// Import of runtime code => handled by Vike
|
|
@@ -382,12 +391,7 @@ function triggerPrepareStackTrace(err) {
|
|
|
382
391
|
}
|
|
383
392
|
function getErrIntroMsg(operation, filePath) {
|
|
384
393
|
const { filePathToShowToUserResolved } = filePath;
|
|
385
|
-
const msg =
|
|
386
|
-
// prettier ignore
|
|
387
|
-
pc.red(`Failed to ${operation}`),
|
|
388
|
-
pc.bold(pc.red(filePathToShowToUserResolved)),
|
|
389
|
-
pc.red(`because:`),
|
|
390
|
-
].join(' ');
|
|
394
|
+
const msg = `${pc.red(`Failed to ${operation}`)} ${pc.bold(pc.red(filePathToShowToUserResolved))} ${pc.red(`because:`)}`;
|
|
391
395
|
return msg;
|
|
392
396
|
}
|
|
393
397
|
function cleanEsbuildErrors(errors) {
|
|
@@ -4,6 +4,7 @@ export { getVikeConfigInternal };
|
|
|
4
4
|
export { getVikeConfigInternalOptional };
|
|
5
5
|
export { getVikeConfigInternalSync };
|
|
6
6
|
export { setVikeConfigContext };
|
|
7
|
+
export { isVikeConfigContextSet };
|
|
7
8
|
export { reloadVikeConfig };
|
|
8
9
|
export { isV1Design };
|
|
9
10
|
export { getConfVal };
|
|
@@ -45,6 +46,7 @@ declare function getVikeConfigInternalSync(): VikeConfigInternal;
|
|
|
45
46
|
declare function getVikeConfig(config: ResolvedConfig | UserConfig): VikeConfig;
|
|
46
47
|
type VikeConfig = Pick<VikeConfigInternal, 'config' | 'pages' | 'prerenderContext'>;
|
|
47
48
|
declare function setVikeConfigContext(vikeConfigCtx_: VikeConfigContext): void;
|
|
49
|
+
declare function isVikeConfigContextSet(): boolean;
|
|
48
50
|
declare function getVikeConfigInternalOptional(): Promise<null | VikeConfigInternal>;
|
|
49
51
|
declare function isV1Design(): boolean;
|
|
50
52
|
declare function getVikeConfigFromCliOrEnv(): {
|
|
@@ -5,6 +5,7 @@ export { getVikeConfigInternal };
|
|
|
5
5
|
export { getVikeConfigInternalOptional };
|
|
6
6
|
export { getVikeConfigInternalSync };
|
|
7
7
|
export { setVikeConfigContext };
|
|
8
|
+
export { isVikeConfigContextSet };
|
|
8
9
|
export { reloadVikeConfig };
|
|
9
10
|
export { isV1Design };
|
|
10
11
|
export { getConfVal };
|
|
@@ -83,6 +84,9 @@ function setVikeConfigContext(vikeConfigCtx_) {
|
|
|
83
84
|
// If the user changes Vite's `config.root` => Vite completely reloads itself => setVikeConfigContext() is called again
|
|
84
85
|
globalObject.vikeConfigCtx = vikeConfigCtx_;
|
|
85
86
|
}
|
|
87
|
+
function isVikeConfigContextSet() {
|
|
88
|
+
return !!globalObject.vikeConfigCtx;
|
|
89
|
+
}
|
|
86
90
|
async function getOrResolveVikeConfig(userRootDir, isDev, vikeVitePluginOptions, doNotRestartViteOnError) {
|
|
87
91
|
if (!globalObject.vikeConfigPromise) {
|
|
88
92
|
resolveVikeConfigInternal_withErrorHandling(userRootDir, isDev, vikeVitePluginOptions, doNotRestartViteOnError);
|