vike 0.4.247-commit-14351e3 → 0.4.247-commit-9b74d50
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/client/runtime-client-routing/history.d.ts +5 -2
- package/dist/client/runtime-client-routing/history.js +52 -29
- package/dist/client/runtime-client-routing/initOnPopState.js +5 -3
- package/dist/node/api/dev.d.ts +4 -1
- package/dist/node/api/dev.js +55 -3
- package/dist/node/api/utils.d.ts +3 -0
- package/dist/node/api/utils.js +3 -0
- package/dist/node/cli/entry.js +1 -17
- package/dist/node/vite/plugins/build/pluginModuleBanner.js +20 -8
- package/dist/node/vite/plugins/pluginCommon.d.ts +1 -0
- package/dist/node/vite/plugins/pluginCommon.js +2 -0
- package/dist/node/vite/plugins/pluginDev.js +11 -8
- package/dist/node/vite/plugins/pluginReplaceConstantsGlobalThis.d.ts +2 -0
- package/dist/node/vite/plugins/pluginReplaceConstantsGlobalThis.js +5 -4
- package/dist/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntry.js +3 -2
- package/dist/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntryWithOldDesign.js +2 -1
- package/dist/node/vite/shared/loggerDev/errorWithCodeSnippet.d.ts +2 -1
- package/dist/node/vite/shared/loggerDev/errorWithCodeSnippet.js +5 -8
- package/dist/node/vite/shared/loggerDev.js +32 -43
- package/dist/node/vite/shared/loggerVite.d.ts +15 -2
- package/dist/node/vite/shared/loggerVite.js +108 -11
- package/dist/node/vite/shared/resolveVikeConfigInternal/transpileAndExecuteFile.d.ts +3 -2
- package/dist/node/vite/shared/resolveVikeConfigInternal/transpileAndExecuteFile.js +4 -2
- package/dist/node/vite/shared/resolveVikeConfigInternal.js +3 -3
- package/dist/server/{runtime/onLoad.js → onLoad.js} +8 -5
- package/dist/server/runtime/renderPageServer/addErrorHint.d.ts +1 -1
- package/dist/server/runtime/renderPageServer/addErrorHint.js +4 -8
- package/dist/server/runtime/renderPageServer.js +10 -3
- package/dist/server/utils.d.ts +1 -0
- package/dist/server/utils.js +2 -1
- package/dist/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/utils/PROJECT_VERSION.js +1 -1
- package/dist/utils/assert.js +8 -4
- package/dist/utils/colorVike.d.ts +2 -0
- package/dist/utils/colorVike.js +5 -0
- package/dist/utils/colors.d.ts +2 -0
- package/dist/utils/colors.js +5 -0
- package/dist/utils/debug.js +13 -9
- package/dist/utils/formatHintLog.d.ts +1 -1
- package/dist/utils/formatHintLog.js +6 -8
- package/dist/utils/getBetterError.d.ts +7 -1
- package/dist/utils/getBetterError.js +38 -10
- package/package.json +2 -2
- package/dist/node/vite/shared/loggerVite/removeSuperfluousViteLog.d.ts +0 -6
- package/dist/node/vite/shared/loggerVite/removeSuperfluousViteLog.js +0 -24
- /package/dist/server/{runtime/onLoad.d.ts → onLoad.d.ts} +0 -0
|
@@ -5,11 +5,14 @@ export { saveScrollPosition };
|
|
|
5
5
|
export { initHistory };
|
|
6
6
|
export type { HistoryInfo };
|
|
7
7
|
export type { ScrollPosition };
|
|
8
|
-
type
|
|
8
|
+
type VikeHistoryData = {
|
|
9
9
|
timestamp: number;
|
|
10
10
|
scrollPosition: null | ScrollPosition;
|
|
11
11
|
triggeredBy: 'user' | 'vike' | 'browser';
|
|
12
|
-
|
|
12
|
+
};
|
|
13
|
+
type StateEnhanced = {
|
|
14
|
+
_isVikeEnhanced: VikeHistoryData;
|
|
15
|
+
[key: string]: unknown;
|
|
13
16
|
};
|
|
14
17
|
type ScrollPosition = {
|
|
15
18
|
x: number;
|
|
@@ -4,7 +4,7 @@ export { onPopStateBegin };
|
|
|
4
4
|
export { saveScrollPosition };
|
|
5
5
|
export { initHistory };
|
|
6
6
|
import { getCurrentUrl } from '../shared/getCurrentUrl.js';
|
|
7
|
-
import { assert, assertUsage, getGlobalObject, isObject, deepEqual,
|
|
7
|
+
import { assert, assertUsage, getGlobalObject, isObject, deepEqual, redirectHard } from './utils.js';
|
|
8
8
|
const globalObject = getGlobalObject('history.ts', {
|
|
9
9
|
monkeyPatched: false,
|
|
10
10
|
previous: undefined,
|
|
@@ -28,20 +28,36 @@ function enhance(stateNotEnhanced) {
|
|
|
28
28
|
let stateVikeEnhanced;
|
|
29
29
|
if (!stateNotEnhanced) {
|
|
30
30
|
stateVikeEnhanced = {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
_isVikeEnhanced: {
|
|
32
|
+
timestamp,
|
|
33
|
+
scrollPosition,
|
|
34
|
+
triggeredBy,
|
|
35
|
+
},
|
|
35
36
|
};
|
|
36
37
|
}
|
|
37
38
|
else {
|
|
38
39
|
// State information may be incomplete if `window.history.state` is set by an old Vike version. (E.g. `state.timestamp` was introduced for `pageContext.isBackwardNavigation` in `0.4.19`.)
|
|
39
|
-
|
|
40
|
+
let oldVikeData;
|
|
41
|
+
if (isObject(stateNotEnhanced) && '_isVikeEnhanced' in stateNotEnhanced) {
|
|
42
|
+
if (isObject(stateNotEnhanced._isVikeEnhanced)) {
|
|
43
|
+
// New format: _isVikeEnhanced is an object with nested properties
|
|
44
|
+
oldVikeData = stateNotEnhanced._isVikeEnhanced;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
// Old format: _isVikeEnhanced is true, properties are on state root
|
|
48
|
+
oldVikeData = stateNotEnhanced;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
oldVikeData = {};
|
|
53
|
+
}
|
|
40
54
|
stateVikeEnhanced = {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
55
|
+
...stateNotEnhanced,
|
|
56
|
+
_isVikeEnhanced: {
|
|
57
|
+
timestamp: oldVikeData.timestamp ?? timestamp,
|
|
58
|
+
scrollPosition: oldVikeData.scrollPosition ?? scrollPosition,
|
|
59
|
+
triggeredBy: oldVikeData.triggeredBy ?? triggeredBy,
|
|
60
|
+
},
|
|
45
61
|
};
|
|
46
62
|
}
|
|
47
63
|
assertIsVikeEnhanced(stateVikeEnhanced);
|
|
@@ -71,16 +87,17 @@ function saveScrollPosition() {
|
|
|
71
87
|
if (!isVikeEnhanced(window.history.state))
|
|
72
88
|
return;
|
|
73
89
|
const state = getState();
|
|
74
|
-
replaceHistoryState({ ...state, scrollPosition });
|
|
90
|
+
replaceHistoryState({ ...state, _isVikeEnhanced: { ...state._isVikeEnhanced, scrollPosition } });
|
|
75
91
|
}
|
|
76
92
|
function pushHistoryState(url, overwriteLastHistoryEntry) {
|
|
77
93
|
if (!overwriteLastHistoryEntry) {
|
|
78
94
|
const state = {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
95
|
+
_isVikeEnhanced: {
|
|
96
|
+
timestamp: getTimestamp(),
|
|
97
|
+
// I don't remember why I set it to `null`, maybe because setting it now would be too early? (Maybe there is a delay between renderPageClient() is finished and the browser updating the scroll position.) Anyways, it seems like autoSaveScrollPosition() is enough.
|
|
98
|
+
scrollPosition: null,
|
|
99
|
+
triggeredBy: 'vike',
|
|
100
|
+
},
|
|
84
101
|
};
|
|
85
102
|
// Calling the monkey patched history.pushState() (and not the original) so that other tools (e.g. user tracking) can listen to Vike's pushState() calls.
|
|
86
103
|
// - https://github.com/vikejs/vike/issues/1582
|
|
@@ -114,37 +131,43 @@ function monkeyPatchHistoryAPI() {
|
|
|
114
131
|
const stateEnhanced = isVikeEnhanced(stateOriginal)
|
|
115
132
|
? stateOriginal
|
|
116
133
|
: {
|
|
117
|
-
_isVikeEnhanced: true,
|
|
118
|
-
scrollPosition: getScrollPosition(),
|
|
119
|
-
timestamp: getTimestamp(),
|
|
120
|
-
triggeredBy: 'user',
|
|
121
134
|
...stateOriginal,
|
|
135
|
+
_isVikeEnhanced: {
|
|
136
|
+
scrollPosition: getScrollPosition(),
|
|
137
|
+
timestamp: getTimestamp(),
|
|
138
|
+
triggeredBy: 'user',
|
|
139
|
+
...stateOriginal?._isVikeEnhanced,
|
|
140
|
+
},
|
|
122
141
|
};
|
|
123
142
|
assertIsVikeEnhanced(stateEnhanced);
|
|
124
143
|
funcOriginal(stateEnhanced, ...rest);
|
|
125
|
-
assert(
|
|
144
|
+
assert(isEqual(stateEnhanced, window.history.state));
|
|
126
145
|
globalObject.previous = getHistoryInfo();
|
|
127
146
|
// Workaround https://github.com/vikejs/vike/issues/2504#issuecomment-3149764736
|
|
128
147
|
queueMicrotask(() => {
|
|
129
|
-
if (
|
|
148
|
+
if (isEqual(stateEnhanced, window.history.state))
|
|
130
149
|
return;
|
|
131
150
|
Object.assign(stateEnhanced, window.history.state);
|
|
132
151
|
assertIsVikeEnhanced(stateEnhanced);
|
|
133
152
|
replaceHistoryStateOriginal(stateEnhanced, rest[1]);
|
|
134
|
-
assert(
|
|
153
|
+
assert(isEqual(stateEnhanced, window.history.state));
|
|
135
154
|
});
|
|
136
155
|
};
|
|
137
156
|
});
|
|
138
157
|
}
|
|
158
|
+
function isEqual(state1, state2) {
|
|
159
|
+
return isObject(state1) && isObject(state2) && deepEqual(state1._isVikeEnhanced, state2._isVikeEnhanced);
|
|
160
|
+
}
|
|
139
161
|
function isVikeEnhanced(state) {
|
|
140
162
|
if (isObject(state) && '_isVikeEnhanced' in state) {
|
|
141
163
|
/* We don't use the assert() below to save client-side KBs.
|
|
142
|
-
|
|
143
|
-
assert(
|
|
144
|
-
assert(hasProp(
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
assert(hasProp(
|
|
164
|
+
const vikeData = state._isVikeEnhanced
|
|
165
|
+
assert(isObject(vikeData))
|
|
166
|
+
assert(hasProp(vikeData, 'timestamp', 'number'))
|
|
167
|
+
assert(hasProp(vikeData, 'scrollPosition'))
|
|
168
|
+
if (vikeData.scrollPosition !== null) {
|
|
169
|
+
assert(hasProp(vikeData, 'scrollPosition', 'object'))
|
|
170
|
+
assert(hasProp(vikeData.scrollPosition, 'x', 'number') && hasProp(vikeData.scrollPosition, 'y', 'number'))
|
|
148
171
|
}
|
|
149
172
|
//*/
|
|
150
173
|
return true;
|
|
@@ -37,16 +37,18 @@ async function onPopState() {
|
|
|
37
37
|
await handleHistoryNavigation(previous, current);
|
|
38
38
|
}
|
|
39
39
|
async function handleHistoryNavigation(previous, current) {
|
|
40
|
-
const scrollTarget = current.state.scrollPosition || undefined;
|
|
40
|
+
const scrollTarget = current.state._isVikeEnhanced.scrollPosition || undefined;
|
|
41
41
|
const isHashNavigation = removeHash(current.url) === removeHash(previous.url) && current.url !== previous.url;
|
|
42
42
|
if (isHashNavigation) {
|
|
43
43
|
// We have to scroll ourselves because we have set `window.history.scrollRestoration = 'manual'`
|
|
44
44
|
setScrollPosition(scrollTarget);
|
|
45
45
|
return;
|
|
46
46
|
}
|
|
47
|
-
const isUserPushStateNavigation = current.state.triggeredBy === 'user' || previous.state.triggeredBy === 'user';
|
|
47
|
+
const isUserPushStateNavigation = current.state._isVikeEnhanced.triggeredBy === 'user' || previous.state._isVikeEnhanced.triggeredBy === 'user';
|
|
48
48
|
const doNotRenderIfSamePage = isUserPushStateNavigation;
|
|
49
|
-
const isBackwardNavigation = !current.state.timestamp || !previous.state.
|
|
49
|
+
const isBackwardNavigation = !current.state._isVikeEnhanced.timestamp || !previous.state._isVikeEnhanced.timestamp
|
|
50
|
+
? null
|
|
51
|
+
: current.state._isVikeEnhanced.timestamp < previous.state._isVikeEnhanced.timestamp;
|
|
50
52
|
await renderPageClient({ scrollTarget, isBackwardNavigation, doNotRenderIfSamePage, isHistoryNavigation: true });
|
|
51
53
|
}
|
|
52
54
|
function removeHash(url) {
|
package/dist/node/api/dev.d.ts
CHANGED
|
@@ -6,7 +6,10 @@ import type { ApiOptions } from './types.js';
|
|
|
6
6
|
*
|
|
7
7
|
* https://vike.dev/api#dev
|
|
8
8
|
*/
|
|
9
|
-
declare function dev(options?: ApiOptions
|
|
9
|
+
declare function dev(options?: ApiOptions & {
|
|
10
|
+
startupLog?: boolean;
|
|
11
|
+
}): Promise<{
|
|
10
12
|
viteServer: ViteDevServer;
|
|
11
13
|
viteConfig: ResolvedConfig;
|
|
14
|
+
viteVersion: string;
|
|
12
15
|
}>;
|
package/dist/node/api/dev.js
CHANGED
|
@@ -1,16 +1,68 @@
|
|
|
1
1
|
export { dev };
|
|
2
2
|
import { prepareViteApiCall } from './prepareViteApiCall.js';
|
|
3
|
-
import { createServer } from 'vite';
|
|
3
|
+
import { createServer, version as viteVersionVike } from 'vite';
|
|
4
|
+
import { viteVersionUser } from '../vite/plugins/pluginCommon.js';
|
|
5
|
+
import { colorVike, colorVite, PROJECT_VERSION } from './utils.js';
|
|
6
|
+
import pc from '@brillout/picocolors';
|
|
7
|
+
import { processStartupLog } from '../vite/shared/loggerVite.js';
|
|
4
8
|
/**
|
|
5
9
|
* Programmatically trigger `$ vike dev`
|
|
6
10
|
*
|
|
7
11
|
* https://vike.dev/api#dev
|
|
8
12
|
*/
|
|
9
13
|
async function dev(options = {}) {
|
|
14
|
+
const startTime = performance.now();
|
|
10
15
|
const { viteConfigFromUserResolved } = await prepareViteApiCall(options, 'dev');
|
|
11
16
|
const server = await createServer(viteConfigFromUserResolved);
|
|
17
|
+
const viteVersion = viteVersionUser ?? viteVersionVike;
|
|
18
|
+
const viteServer = server;
|
|
19
|
+
const viteConfig = server.config;
|
|
20
|
+
if (viteServer.httpServer)
|
|
21
|
+
await viteServer.listen();
|
|
22
|
+
if (options.startupLog)
|
|
23
|
+
printStartupLog(viteServer, viteConfig, viteVersion, startTime);
|
|
12
24
|
return {
|
|
13
|
-
viteServer
|
|
14
|
-
viteConfig
|
|
25
|
+
viteServer,
|
|
26
|
+
viteConfig,
|
|
27
|
+
viteVersion,
|
|
15
28
|
};
|
|
16
29
|
}
|
|
30
|
+
async function printStartupLog(viteServer, viteConfig, viteVersion, startTime) {
|
|
31
|
+
const startupDurationString = pc.dim(`ready in ${pc.reset(pc.bold(String(Math.ceil(performance.now() - startTime))))} ms`);
|
|
32
|
+
const sep = pc.dim('·');
|
|
33
|
+
const firstLine = `\n ${colorVike('Vike')} ${pc.yellow(`v${PROJECT_VERSION}`)} ${sep} ${colorVite('Vite')} ${pc.cyan(`v${viteVersion}`)} ${sep} ${startupDurationString}\n`;
|
|
34
|
+
const ret = processStartupLog(firstLine, viteConfig);
|
|
35
|
+
console.log(ret.firstLine);
|
|
36
|
+
const { isCompact } = ret;
|
|
37
|
+
// We don't call viteServer.printUrls() because Vite throws an error if `resolvedUrls` is missing:
|
|
38
|
+
// https://github.com/vitejs/vite/blob/df5a30d2690a2ebc4824a79becdcef30538dc602/packages/vite/src/node/server/index.ts#L745
|
|
39
|
+
printServerUrls(viteServer.resolvedUrls || { local: ['http://localhost:3000'], network: [] }, viteConfig.server.host);
|
|
40
|
+
viteServer.bindCLIShortcuts({ print: true });
|
|
41
|
+
if (!isCompact)
|
|
42
|
+
console.log();
|
|
43
|
+
}
|
|
44
|
+
// Copied & adapted from Vite
|
|
45
|
+
// https://github.com/vitejs/vite/blob/df5a30d2690a2ebc4824a79becdcef30538dc602/packages/vite/src/node/logger.ts#L168-L188
|
|
46
|
+
function printServerUrls(urls, optionsHost) {
|
|
47
|
+
// [Begin] interop
|
|
48
|
+
const colors = pc;
|
|
49
|
+
const info = (msg) => console.log(msg);
|
|
50
|
+
// [End] interop
|
|
51
|
+
const colorUrl = (url) => colors.underline(removeTrailingSlash(url));
|
|
52
|
+
for (const url of urls.local) {
|
|
53
|
+
info(` ${colors.green('➜')} ${colors.bold('Local')}: ${colorUrl(url)}`);
|
|
54
|
+
}
|
|
55
|
+
for (const url of urls.network) {
|
|
56
|
+
info(` ${colors.green('➜')} ${colors.bold('Network')}: ${colorUrl(url)}`);
|
|
57
|
+
}
|
|
58
|
+
if (urls.network.length === 0 && optionsHost === undefined) {
|
|
59
|
+
info(colors.dim(` ${colors.green('➜')} ${colors.bold('Network')}: use `) +
|
|
60
|
+
colors.bold('--host') +
|
|
61
|
+
colors.dim(' to expose'));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function removeTrailingSlash(url) {
|
|
65
|
+
if (url.endsWith('/'))
|
|
66
|
+
return url.slice(0, -1); // remove trailing slash
|
|
67
|
+
return url;
|
|
68
|
+
}
|
package/dist/node/api/utils.d.ts
CHANGED
|
@@ -6,3 +6,6 @@ export * from '../../utils/assertVersion.js';
|
|
|
6
6
|
export * from '../../utils/pick.js';
|
|
7
7
|
export * from '../../utils/assertSetup.js';
|
|
8
8
|
export * from '../../utils/isCallable.js';
|
|
9
|
+
export * from '../../utils/colors.js';
|
|
10
|
+
export * from '../../utils/colorVike.js';
|
|
11
|
+
export * from '../../utils/PROJECT_VERSION.js';
|
package/dist/node/api/utils.js
CHANGED
|
@@ -10,3 +10,6 @@ export * from '../../utils/assertVersion.js';
|
|
|
10
10
|
export * from '../../utils/pick.js';
|
|
11
11
|
export * from '../../utils/assertSetup.js';
|
|
12
12
|
export * from '../../utils/isCallable.js';
|
|
13
|
+
export * from '../../utils/colors.js';
|
|
14
|
+
export * from '../../utils/colorVike.js';
|
|
15
|
+
export * from '../../utils/PROJECT_VERSION.js';
|
package/dist/node/cli/entry.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { PROJECT_VERSION } from './utils.js';
|
|
2
1
|
import { dev, build, preview } from '../api/index.js';
|
|
3
2
|
import pc from '@brillout/picocolors';
|
|
4
3
|
import { parseCli } from './parseCli.js';
|
|
@@ -21,23 +20,8 @@ async function cli() {
|
|
|
21
20
|
}
|
|
22
21
|
}
|
|
23
22
|
async function cmdDev() {
|
|
24
|
-
const startTime = performance.now();
|
|
25
23
|
try {
|
|
26
|
-
|
|
27
|
-
if (viteServer.httpServer) {
|
|
28
|
-
await viteServer.listen();
|
|
29
|
-
const info = viteServer.config.logger.info;
|
|
30
|
-
const startupDurationString = pc.dim(`ready in ${pc.reset(pc.bold(String(Math.ceil(performance.now() - startTime))))} ms`);
|
|
31
|
-
const hasExistingLogs = process.stdout.bytesWritten > 0 || process.stderr.bytesWritten > 0;
|
|
32
|
-
info(` ${pc.yellow(`${pc.bold('Vike')} v${PROJECT_VERSION}`)} ${startupDurationString}\n`, {
|
|
33
|
-
clear: !hasExistingLogs,
|
|
34
|
-
});
|
|
35
|
-
viteServer.printUrls();
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
// vike-server => middleware mode => `viteServer.httpServer === null`
|
|
39
|
-
}
|
|
40
|
-
viteServer.bindCLIShortcuts({ print: true });
|
|
24
|
+
await dev({ startupLog: true });
|
|
41
25
|
}
|
|
42
26
|
catch (err) {
|
|
43
27
|
console.error(pc.red(`Error while starting dev server:`));
|
|
@@ -5,29 +5,31 @@ import { getMagicString } from '../../shared/getMagicString.js';
|
|
|
5
5
|
// But, anyways, we want to prepend the banner at the beginning of each module, not at the beginning of each file (I believe that's what Rollup's banner feature does).
|
|
6
6
|
function pluginModuleBanner() {
|
|
7
7
|
let config;
|
|
8
|
+
let isEnabled = false;
|
|
8
9
|
return [
|
|
9
10
|
{
|
|
10
11
|
name: 'vike:build:pluginModuleBanner',
|
|
11
12
|
enforce: 'post',
|
|
12
13
|
apply: 'build',
|
|
13
14
|
applyToEnvironment(environment) {
|
|
14
|
-
|
|
15
|
-
const { consumer } = config;
|
|
16
|
-
const { minify } = config.build;
|
|
17
|
-
assert(minify === false || minify, { minify, consumer });
|
|
18
|
-
return !minify;
|
|
15
|
+
return checkIsEnabled(environment.config);
|
|
19
16
|
},
|
|
20
17
|
configResolved: {
|
|
21
18
|
handler(config_) {
|
|
22
19
|
config = config_;
|
|
20
|
+
isEnabled = checkIsEnabled(config);
|
|
23
21
|
},
|
|
24
22
|
},
|
|
25
23
|
transform: {
|
|
26
24
|
order: 'post',
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
filter: {
|
|
26
|
+
get id() {
|
|
27
|
+
return isEnabled ? undefined : 'this-module-id-does-not-exist-and-never-matches-any-module';
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
30
|
handler(code, id) {
|
|
31
|
+
if (!isEnabled)
|
|
32
|
+
return undefined;
|
|
31
33
|
const { minify } = this.environment.config.build;
|
|
32
34
|
assert(minify === false, { minify });
|
|
33
35
|
if (id.startsWith('\0'))
|
|
@@ -47,3 +49,13 @@ function pluginModuleBanner() {
|
|
|
47
49
|
},
|
|
48
50
|
];
|
|
49
51
|
}
|
|
52
|
+
function checkIsEnabled(config) {
|
|
53
|
+
const { minify } = config.build;
|
|
54
|
+
assert(minify === false || minify, { minify });
|
|
55
|
+
const isEnabled = !minify;
|
|
56
|
+
// Avoid the legal comments inserted in the transform() hook to be removed.
|
|
57
|
+
// https://github.com/vitejs/vite/issues/21085#issuecomment-3502781005
|
|
58
|
+
if (isEnabled && config.esbuild)
|
|
59
|
+
config.esbuild.legalComments = 'inline';
|
|
60
|
+
return isEnabled;
|
|
61
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { pluginCommon };
|
|
2
|
+
export let viteVersionUser = null;
|
|
2
3
|
import { assert, assertUsage, assertWarning, hasProp, isDevCheck, isDocker, isExactlyOneTruthy, isObject, isVitest, } from '../utils.js';
|
|
3
4
|
import { assertRollupInput } from './build/pluginBuildConfig.js';
|
|
4
5
|
import { installRequireShim_setUserRootDir } from '@brillout/require-shim';
|
|
@@ -19,6 +20,7 @@ function pluginCommon(vikeVitePluginOptions) {
|
|
|
19
20
|
config: {
|
|
20
21
|
order: 'pre',
|
|
21
22
|
async handler(configFromUser, env) {
|
|
23
|
+
viteVersionUser = this?.meta?.viteVersion; // is `undefined` on old Vite versions
|
|
22
24
|
const isDev = isDevCheck(env);
|
|
23
25
|
const isBuild = env.command === 'build';
|
|
24
26
|
const isPreview = env.isPreview;
|
|
@@ -4,11 +4,9 @@ import { determineOptimizeDeps } from './pluginDev/determineOptimizeDeps.js';
|
|
|
4
4
|
import { determineFsAllowList } from './pluginDev/determineFsAllowList.js';
|
|
5
5
|
import { addSsrMiddleware } from '../shared/addSsrMiddleware.js';
|
|
6
6
|
import { applyDev, assertWarning, isDocker, isDebugError } from '../utils.js';
|
|
7
|
-
import {
|
|
7
|
+
import { interceptViteLogs } from '../shared/loggerVite.js';
|
|
8
8
|
import pc from '@brillout/picocolors';
|
|
9
|
-
|
|
10
|
-
Error.stackTraceLimit = Infinity;
|
|
11
|
-
}
|
|
9
|
+
import { swallowViteLogConnected, swallowViteLogConnected_clean } from '../shared/loggerVite.js';
|
|
12
10
|
function pluginDev() {
|
|
13
11
|
let config;
|
|
14
12
|
return [
|
|
@@ -44,21 +42,20 @@ function pluginDev() {
|
|
|
44
42
|
config = config_;
|
|
45
43
|
await determineOptimizeDeps(config);
|
|
46
44
|
await determineFsAllowList(config);
|
|
47
|
-
|
|
48
|
-
improveViteLogs(config);
|
|
49
|
-
}
|
|
45
|
+
interceptViteLogs(config);
|
|
50
46
|
logDockerHint(config.server.host);
|
|
51
47
|
},
|
|
52
48
|
},
|
|
53
49
|
},
|
|
54
50
|
{
|
|
55
|
-
name: 'vike:pluginDev:
|
|
51
|
+
name: 'vike:pluginDev:post',
|
|
56
52
|
apply: applyDev,
|
|
57
53
|
// The SSR middleware should be last middleware
|
|
58
54
|
enforce: 'post',
|
|
59
55
|
configureServer: {
|
|
60
56
|
order: 'post',
|
|
61
57
|
handler(server) {
|
|
58
|
+
swallowViteLogConnected_clean(); // If inside a configureServer() `pre` hook => too early
|
|
62
59
|
const hasHonoViteDevServer = !!config.plugins.find((p) => p.name === '@hono/vite-dev-server');
|
|
63
60
|
if (config.server.middlewareMode || hasHonoViteDevServer)
|
|
64
61
|
return;
|
|
@@ -76,6 +73,12 @@ function pluginDev() {
|
|
|
76
73
|
}
|
|
77
74
|
},
|
|
78
75
|
},
|
|
76
|
+
configResolved: {
|
|
77
|
+
order: 'post',
|
|
78
|
+
handler() {
|
|
79
|
+
swallowViteLogConnected();
|
|
80
|
+
},
|
|
81
|
+
},
|
|
79
82
|
},
|
|
80
83
|
];
|
|
81
84
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { pluginReplaceConstantsGlobalThis };
|
|
2
|
+
export { VIRTUAL_FILE_ID_constantsGlobalThis };
|
|
2
3
|
export type _LoadDeclareGlobal__VIKE__IS = never;
|
|
3
4
|
import type { Plugin } from 'vite';
|
|
4
5
|
declare global {
|
|
@@ -8,4 +9,5 @@ declare global {
|
|
|
8
9
|
var __VIKE__IS_CLIENT: boolean;
|
|
9
10
|
var __VIKE__IS_DEBUG: boolean;
|
|
10
11
|
}
|
|
12
|
+
declare const VIRTUAL_FILE_ID_constantsGlobalThis = "virtual:vike:server:constantsGlobalThis";
|
|
11
13
|
declare function pluginReplaceConstantsGlobalThis(): Plugin[];
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
export { pluginReplaceConstantsGlobalThis };
|
|
2
|
+
export { VIRTUAL_FILE_ID_constantsGlobalThis };
|
|
2
3
|
import { assert, isDebug, addVirtualFileIdPrefix, escapeRegex } from '../utils.js';
|
|
3
4
|
import { isViteServerSide_applyToEnvironment, isViteServerSide_configEnvironment, isViteServerSide_extraSafe, } from '../shared/isViteServerSide.js';
|
|
4
5
|
const isDebugVal = isDebug();
|
|
5
6
|
globalThis.__VIKE__IS_CLIENT = false;
|
|
6
7
|
globalThis.__VIKE__IS_DEBUG = isDebugVal;
|
|
7
|
-
const
|
|
8
|
+
const VIRTUAL_FILE_ID_constantsGlobalThis = 'virtual:vike:server:constantsGlobalThis';
|
|
8
9
|
const filterRolldown = {
|
|
9
10
|
id: {
|
|
10
|
-
include: new RegExp(escapeRegex(
|
|
11
|
+
include: new RegExp(escapeRegex(VIRTUAL_FILE_ID_constantsGlobalThis)),
|
|
11
12
|
},
|
|
12
13
|
};
|
|
13
|
-
const filterFunction = (id) => id ===
|
|
14
|
+
const filterFunction = (id) => id === VIRTUAL_FILE_ID_constantsGlobalThis || id === addVirtualFileIdPrefix(VIRTUAL_FILE_ID_constantsGlobalThis);
|
|
14
15
|
function pluginReplaceConstantsGlobalThis() {
|
|
15
16
|
let config;
|
|
16
17
|
let isDev;
|
|
@@ -54,7 +55,7 @@ function pluginReplaceConstantsGlobalThis() {
|
|
|
54
55
|
filter: filterRolldown,
|
|
55
56
|
handler(id) {
|
|
56
57
|
assert(filterFunction(id));
|
|
57
|
-
assert(id ===
|
|
58
|
+
assert(id === VIRTUAL_FILE_ID_constantsGlobalThis);
|
|
58
59
|
return addVirtualFileIdPrefix(id);
|
|
59
60
|
},
|
|
60
61
|
},
|
|
@@ -3,6 +3,7 @@ import { generateVirtualFileId } from '../../../../shared-server-node/virtualFil
|
|
|
3
3
|
import { debug } from './debug.js';
|
|
4
4
|
import { getVikeConfigInternal } from '../../shared/resolveVikeConfigInternal.js';
|
|
5
5
|
import { serializeConfigValues, } from '../../../../shared-server-client/page-configs/serialize/serializeConfigValues.js';
|
|
6
|
+
import { VIRTUAL_FILE_ID_constantsGlobalThis } from '../pluginReplaceConstantsGlobalThis.js';
|
|
6
7
|
async function generateVirtualFileGlobalEntry(isForClientSide, isDev, id, isClientRouting) {
|
|
7
8
|
const vikeConfig = await getVikeConfigInternal(true);
|
|
8
9
|
const { _pageConfigs: pageConfigs, _pageConfigGlobal: pageConfigGlobal } = vikeConfig;
|
|
@@ -13,7 +14,7 @@ function getCode(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, isCl
|
|
|
13
14
|
const importStatements = [];
|
|
14
15
|
const filesEnv = new Map();
|
|
15
16
|
if (!isForClientSide) {
|
|
16
|
-
importStatements.push(
|
|
17
|
+
importStatements.push(`import '${VIRTUAL_FILE_ID_constantsGlobalThis}';`);
|
|
17
18
|
}
|
|
18
19
|
lines.push('export const pageConfigsSerialized = [');
|
|
19
20
|
lines.push(getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRouting, isDev, importStatements, filesEnv));
|
|
@@ -27,7 +28,7 @@ function getCode(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, isCl
|
|
|
27
28
|
}
|
|
28
29
|
let code = [...importStatements, ...lines].join('\n');
|
|
29
30
|
if (!isForClientSide) {
|
|
30
|
-
code =
|
|
31
|
+
code = `import '${VIRTUAL_FILE_ID_constantsGlobalThis}';\n` + code;
|
|
31
32
|
}
|
|
32
33
|
debug(id, isForClientSide ? 'CLIENT-SIDE' : 'SERVER-SIDE', code);
|
|
33
34
|
return code;
|
package/dist/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntryWithOldDesign.js
CHANGED
|
@@ -9,6 +9,7 @@ import { getVikeConfigInternal, isV1Design as isV1Design_ } from '../../shared/r
|
|
|
9
9
|
import { getOutDirs } from '../../shared/getOutDirs.js';
|
|
10
10
|
import { isViteServerSide_extraSafe } from '../../shared/isViteServerSide.js';
|
|
11
11
|
import { resolveIncludeAssetsImportedByServer } from '../../../../server/runtime/renderPageServer/getPageAssets/retrievePageAssetsProd.js';
|
|
12
|
+
import { VIRTUAL_FILE_ID_constantsGlobalThis } from '../pluginReplaceConstantsGlobalThis.js';
|
|
12
13
|
async function generateVirtualFileGlobalEntryWithOldDesign(id, options, config, env, isDev) {
|
|
13
14
|
const idParsed = parseVirtualFileId(id);
|
|
14
15
|
assert(idParsed && idParsed.type === 'global-entry');
|
|
@@ -24,7 +25,7 @@ async function getCode(config, isForClientSide, isClientRouting, isDev, id) {
|
|
|
24
25
|
assert(isDev === !isBuild);
|
|
25
26
|
let content = '';
|
|
26
27
|
if (!isForClientSide) {
|
|
27
|
-
content +=
|
|
28
|
+
content += `import '${VIRTUAL_FILE_ID_constantsGlobalThis}';\n`;
|
|
28
29
|
}
|
|
29
30
|
{
|
|
30
31
|
const globRoots = getGlobRoots(config);
|
|
@@ -10,6 +10,7 @@ type ErrorWithCodeSnippet = {
|
|
|
10
10
|
plugin?: string;
|
|
11
11
|
};
|
|
12
12
|
declare function isErrorWithCodeSnippet(err: unknown): err is ErrorWithCodeSnippet;
|
|
13
|
-
declare function getPrettyErrorWithCodeSnippet(err: ErrorWithCodeSnippet, userRootDir: string): string
|
|
13
|
+
declare function getPrettyErrorWithCodeSnippet(err: ErrorWithCodeSnippet, userRootDir: string): `Failed to transpile ${string} because:
|
|
14
|
+
${string}`;
|
|
14
15
|
declare function getPrettyErrMessage(err: ErrorWithCodeSnippet): string | null;
|
|
15
16
|
declare function isEquivalentErrorWithCodeSnippet(err1: unknown, err2: unknown): boolean;
|
|
@@ -45,11 +45,7 @@ function getPrettyErrorWithCodeSnippet(err, userRootDir) {
|
|
|
45
45
|
//*/
|
|
46
46
|
assert(isErrorWithCodeSnippet(err));
|
|
47
47
|
let { id, frame } = err;
|
|
48
|
-
const msgFirstLine =
|
|
49
|
-
pc.red('Failed to transpile'),
|
|
50
|
-
pc.bold(pc.red(getFilePathToShowToUserUnknown(id, userRootDir))),
|
|
51
|
-
pc.red('because:'),
|
|
52
|
-
].join(' ');
|
|
48
|
+
const msgFirstLine = `${pc.red('Failed to transpile')} ${pc.bold(pc.red(getFilePathToShowToUserUnknown(id, userRootDir)))} ${pc.red('because:')}`;
|
|
53
49
|
const errMsg = getPrettyErrMessage(err);
|
|
54
50
|
if (errMsg && containsCodeSnippet(errMsg)) {
|
|
55
51
|
// Conditionally swallowing frame is a risky move but worth it thanks to logErrorDebugNote()
|
|
@@ -65,15 +61,16 @@ function getPrettyErrorWithCodeSnippet(err, userRootDir) {
|
|
|
65
61
|
assert(frame);
|
|
66
62
|
frame = pc.yellow(frame);
|
|
67
63
|
}
|
|
68
|
-
let
|
|
69
|
-
|
|
64
|
+
let errMsgCodeSnippet = [errMsg, frame].filter(Boolean).join('\n');
|
|
65
|
+
errMsgCodeSnippet = removeEmptyLines(errMsgCodeSnippet);
|
|
66
|
+
const errMsgFormatted = `${msgFirstLine}\n${errMsgCodeSnippet}`;
|
|
70
67
|
/* Vite already does a fairly good job at showing a concise error in the layover
|
|
71
68
|
server.ws.send({
|
|
72
69
|
type: 'error',
|
|
73
70
|
err: msg
|
|
74
71
|
})
|
|
75
72
|
*/
|
|
76
|
-
return
|
|
73
|
+
return errMsgFormatted;
|
|
77
74
|
}
|
|
78
75
|
function getPrettyErrMessage(err) {
|
|
79
76
|
const { id, frame } = err;
|