vike 0.4.248 → 0.4.249
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/getPageContextFromHooks.d.ts +8 -8
- package/dist/client/runtime-client-routing/renderPageClient.d.ts +4 -4
- package/dist/node/api/utils.d.ts +2 -2
- package/dist/node/api/utils.js +2 -2
- package/dist/node/vite/plugins/build/pluginBuildConfig.js +2 -2
- package/dist/node/vite/shared/loggerDev.d.ts +3 -0
- package/dist/node/vite/shared/loggerDev.js +29 -13
- package/dist/node/vite/shared/loggerVite.js +3 -3
- package/dist/server/runtime/asyncHook.d.ts +2 -2
- package/dist/server/runtime/asyncHook.js +2 -2
- package/dist/server/utils.d.ts +2 -2
- package/dist/server/utils.js +2 -2
- package/dist/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/utils/PROJECT_VERSION.js +1 -1
- package/dist/utils/assert.d.ts +7 -4
- package/dist/utils/assert.js +65 -50
- package/dist/utils/colorsClient.d.ts +6 -0
- package/dist/utils/colorsClient.js +16 -0
- package/dist/utils/{colors.js → colorsServer.js} +2 -0
- package/dist/utils/formatHintLog.js +1 -1
- package/dist/utils/getBetterError.js +11 -7
- package/dist/utils/shallowClone.d.ts +2 -0
- package/dist/utils/shallowClone.js +11 -0
- package/dist/utils/trimWithAnsi.js +1 -1
- package/package.json +2 -2
- package/dist/utils/colorVike.d.ts +0 -2
- package/dist/utils/colorVike.js +0 -5
- /package/dist/utils/{colors.d.ts → colorsServer.d.ts} +0 -0
|
@@ -136,7 +136,7 @@ declare function getPageContextFromHooksClient_firstRender(pageContext: PageCont
|
|
|
136
136
|
url: string;
|
|
137
137
|
pageExports: Record<string, unknown>;
|
|
138
138
|
isBaseMissing?: true;
|
|
139
|
-
}, "
|
|
139
|
+
}, "pageExports" | "exports" | "pageId" | "config" | "Page" | "data" | "routeParams" | "source" | "sources" | "from" | "configEntries" | "exportsAll" | "abortReason"> & {
|
|
140
140
|
isClientSide: true;
|
|
141
141
|
isPrerendering: false;
|
|
142
142
|
} & {
|
|
@@ -152,7 +152,7 @@ declare function getPageContextFromHooksClient_firstRender(pageContext: PageCont
|
|
|
152
152
|
urlParsed: import("./utils.js").UrlPublic;
|
|
153
153
|
urlPathname: string;
|
|
154
154
|
url: string;
|
|
155
|
-
},
|
|
155
|
+
}, "pageContextsAborted" | "previousPageContext" | ("globalContext" | "Page" | "data")> & {
|
|
156
156
|
previousPageContext: {
|
|
157
157
|
pageId: string;
|
|
158
158
|
} | null;
|
|
@@ -204,7 +204,7 @@ declare function getPageContextFromHooksClient_firstRender(pageContext: PageCont
|
|
|
204
204
|
url: string;
|
|
205
205
|
pageExports: Record<string, unknown>;
|
|
206
206
|
isBaseMissing?: true;
|
|
207
|
-
}, "
|
|
207
|
+
}, "pageExports" | "exports" | "pageId" | "config" | "Page" | "data" | "routeParams" | "source" | "sources" | "from" | "configEntries" | "exportsAll" | "abortReason"> & {
|
|
208
208
|
isClientSide: true;
|
|
209
209
|
isPrerendering: false;
|
|
210
210
|
} & {
|
|
@@ -220,7 +220,7 @@ declare function getPageContextFromHooksClient_firstRender(pageContext: PageCont
|
|
|
220
220
|
urlParsed: import("./utils.js").UrlPublic;
|
|
221
221
|
urlPathname: string;
|
|
222
222
|
url: string;
|
|
223
|
-
},
|
|
223
|
+
}, "pageContextsAborted" | "previousPageContext" | ("globalContext" | "Page" | "data")> & {
|
|
224
224
|
previousPageContext: {
|
|
225
225
|
pageId: string;
|
|
226
226
|
} | null;
|
|
@@ -362,7 +362,7 @@ declare function getPageContextFromHooksClient(pageContext: {
|
|
|
362
362
|
url: string;
|
|
363
363
|
pageExports: Record<string, unknown>;
|
|
364
364
|
isBaseMissing?: true;
|
|
365
|
-
}, "
|
|
365
|
+
}, "pageExports" | "exports" | "pageId" | "config" | "Page" | "data" | "routeParams" | "source" | "sources" | "from" | "configEntries" | "exportsAll" | "abortReason"> & {
|
|
366
366
|
isClientSide: true;
|
|
367
367
|
isPrerendering: false;
|
|
368
368
|
} & {
|
|
@@ -378,7 +378,7 @@ declare function getPageContextFromHooksClient(pageContext: {
|
|
|
378
378
|
urlParsed: import("./utils.js").UrlPublic;
|
|
379
379
|
urlPathname: string;
|
|
380
380
|
url: string;
|
|
381
|
-
},
|
|
381
|
+
}, "pageContextsAborted" | "previousPageContext" | ("globalContext" | "Page" | "data")> & {
|
|
382
382
|
previousPageContext: {
|
|
383
383
|
pageId: string;
|
|
384
384
|
} | null;
|
|
@@ -428,7 +428,7 @@ declare function getPageContextFromHooksClient(pageContext: {
|
|
|
428
428
|
url: string;
|
|
429
429
|
pageExports: Record<string, unknown>;
|
|
430
430
|
isBaseMissing?: true;
|
|
431
|
-
}, "
|
|
431
|
+
}, "pageExports" | "exports" | "pageId" | "config" | "Page" | "data" | "routeParams" | "source" | "sources" | "from" | "configEntries" | "exportsAll" | "abortReason"> & {
|
|
432
432
|
isClientSide: true;
|
|
433
433
|
isPrerendering: false;
|
|
434
434
|
} & {
|
|
@@ -444,7 +444,7 @@ declare function getPageContextFromHooksClient(pageContext: {
|
|
|
444
444
|
urlParsed: import("./utils.js").UrlPublic;
|
|
445
445
|
urlPathname: string;
|
|
446
446
|
url: string;
|
|
447
|
-
},
|
|
447
|
+
}, "pageContextsAborted" | "previousPageContext" | ("globalContext" | "Page" | "data")> & {
|
|
448
448
|
previousPageContext: {
|
|
449
449
|
pageId: string;
|
|
450
450
|
} | null;
|
|
@@ -149,7 +149,7 @@ declare function renderPageClient(renderArgs: RenderArgs): Promise<({
|
|
|
149
149
|
url: string;
|
|
150
150
|
pageExports: Record<string, unknown>;
|
|
151
151
|
isBaseMissing?: true;
|
|
152
|
-
}, "
|
|
152
|
+
}, "pageExports" | "exports" | "pageId" | "config" | "Page" | "data" | "routeParams" | "source" | "sources" | "from" | "configEntries" | "exportsAll" | "abortReason"> & {
|
|
153
153
|
isClientSide: true;
|
|
154
154
|
isPrerendering: false;
|
|
155
155
|
} & {
|
|
@@ -165,7 +165,7 @@ declare function renderPageClient(renderArgs: RenderArgs): Promise<({
|
|
|
165
165
|
urlParsed: import("./utils.js").UrlPublic;
|
|
166
166
|
urlPathname: string;
|
|
167
167
|
url: string;
|
|
168
|
-
},
|
|
168
|
+
}, "pageContextsAborted" | "previousPageContext" | ("globalContext" | "Page" | "data")> & {
|
|
169
169
|
previousPageContext: {
|
|
170
170
|
pageId: string;
|
|
171
171
|
} | null;
|
|
@@ -300,7 +300,7 @@ declare function getPageContextBegin(isForErrorPage: boolean, { urlOriginal, isB
|
|
|
300
300
|
url: string;
|
|
301
301
|
pageExports: Record<string, unknown>;
|
|
302
302
|
isBaseMissing?: true;
|
|
303
|
-
}, "
|
|
303
|
+
}, "pageExports" | "exports" | "pageId" | "config" | "Page" | "data" | "routeParams" | "source" | "sources" | "from" | "configEntries" | "exportsAll" | "abortReason"> & {
|
|
304
304
|
isClientSide: true;
|
|
305
305
|
isPrerendering: false;
|
|
306
306
|
} & {
|
|
@@ -316,7 +316,7 @@ declare function getPageContextBegin(isForErrorPage: boolean, { urlOriginal, isB
|
|
|
316
316
|
urlParsed: import("./utils.js").UrlPublic;
|
|
317
317
|
urlPathname: string;
|
|
318
318
|
url: string;
|
|
319
|
-
},
|
|
319
|
+
}, "pageContextsAborted" | "previousPageContext" | ("globalContext" | "Page" | "data")> & {
|
|
320
320
|
previousPageContext: {
|
|
321
321
|
pageId: string;
|
|
322
322
|
} | null;
|
package/dist/node/api/utils.d.ts
CHANGED
|
@@ -6,6 +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/
|
|
10
|
-
export * from '../../utils/
|
|
9
|
+
export * from '../../utils/colorsServer.js';
|
|
10
|
+
export * from '../../utils/colorsClient.js';
|
|
11
11
|
export * from '../../utils/PROJECT_VERSION.js';
|
package/dist/node/api/utils.js
CHANGED
|
@@ -10,6 +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/
|
|
14
|
-
export * from '../../utils/
|
|
13
|
+
export * from '../../utils/colorsServer.js';
|
|
14
|
+
export * from '../../utils/colorsClient.js';
|
|
15
15
|
export * from '../../utils/PROJECT_VERSION.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { pluginBuildConfig };
|
|
2
2
|
export { assertRollupInput };
|
|
3
3
|
export { analyzeClientEntries };
|
|
4
|
-
import { assert,
|
|
4
|
+
import { assert, setAssertOnBeforeLog, removeFileExtension, unique, assertUsage, injectRollupInputs, normalizeRollupInput, onSetupBuild, assertIsImportPathNpmPackage, requireResolveDistFile, } from '../../utils.js';
|
|
5
5
|
import { getVikeConfigInternal } from '../../shared/resolveVikeConfigInternal.js';
|
|
6
6
|
import { findPageFiles } from '../../shared/findPageFiles.js';
|
|
7
7
|
import { generateVirtualFileId } from '../../../../shared-server-node/virtualFileId.js';
|
|
@@ -203,7 +203,7 @@ function addLogHook() {
|
|
|
203
203
|
'rendering chunks (',
|
|
204
204
|
'computing gzip size ('
|
|
205
205
|
];
|
|
206
|
-
|
|
206
|
+
setAssertOnBeforeLog(() => {
|
|
207
207
|
// Using viteTransientLogs is very conservative as clearing the current line is low risk. (We can assume that important messages, such as errors, include a trailing new line. Usually, only transient messages have no trailing new lines.)
|
|
208
208
|
if (viteTransientLogs.some((s) => lastLog?.startsWith(s))) {
|
|
209
209
|
process.stdout.clearLine(0);
|
|
@@ -2,8 +2,11 @@ export { logVite };
|
|
|
2
2
|
export { logConfigInfo };
|
|
3
3
|
export { logErrorServerDev };
|
|
4
4
|
export type { LogType };
|
|
5
|
+
export type { AddTagsDev };
|
|
5
6
|
import { type PageContext_logRuntime } from '../../../server/runtime/loggerRuntime.js';
|
|
6
7
|
type LogType = 'info' | 'warn' | 'error' | 'error-resolve';
|
|
7
8
|
declare function logConfigInfo(msg: string, logType: LogType): void;
|
|
8
9
|
declare function logVite(msg: string, logType: LogType, requestId: number | null, prependViteTag: boolean): void;
|
|
9
10
|
declare function logErrorServerDev(err: unknown, pageContext: PageContext_logRuntime, errorComesFromVite?: boolean): void;
|
|
11
|
+
type AddTagsDev = typeof addTagsDev;
|
|
12
|
+
declare function addTagsDev<TagVike extends string, TagType extends string>(tagVike: TagVike, tagType: TagType): `1:37:00 PM ${TagVike}[request(n)]${TagType}`;
|
|
@@ -12,7 +12,7 @@ export { logErrorServerDev };
|
|
|
12
12
|
import { isAbortError } from '../../../shared-server-client/route/abort.js';
|
|
13
13
|
import { getViteConfig } from '../../../server/runtime/globalContext.js';
|
|
14
14
|
import { assertPageContext_logRuntime, setLogRuntimeDev, } from '../../../server/runtime/loggerRuntime.js';
|
|
15
|
-
import {
|
|
15
|
+
import { setAssertOnBeforeErr, assert, assertIsNotProductionRuntime, colorVike, colorVite, formatHintLog, hasGreen, hasProp, hasRed, hasYellow, isDebugError, stripAnsi, colorError, colorWarning, setAssertAddTagsDev, } from '../utils.js';
|
|
16
16
|
import { isErrorWithCodeSnippet, getPrettyErrorWithCodeSnippet } from './loggerDev/errorWithCodeSnippet.js';
|
|
17
17
|
import { getConfigExecutionErrorIntroMsg, getConfigBuildErrorFormatted, } from './resolveVikeConfigInternal/transpileAndExecuteFile.js';
|
|
18
18
|
import pc from '@brillout/picocolors';
|
|
@@ -20,13 +20,14 @@ import { isUserHookError } from '../../../shared-server-client/hooks/execHook.js
|
|
|
20
20
|
import { getViteDevServer } from '../../../server/runtime/globalContext.js';
|
|
21
21
|
import { logErrorServer } from '../../../server/runtime/logErrorServer.js';
|
|
22
22
|
import { getBetterError } from '../../../utils/getBetterError.js';
|
|
23
|
-
import {
|
|
23
|
+
import { getRequestId_withAsyncHook } from '../../../server/runtime/asyncHook.js';
|
|
24
24
|
assertIsNotProductionRuntime();
|
|
25
25
|
setLogRuntimeDev(logErrorServerDev, logRuntimeInfoDev);
|
|
26
|
-
|
|
26
|
+
setAssertOnBeforeErr((err) => {
|
|
27
27
|
// We must directly apply vite.ssrFixStacktrace() to `assertWarning(..., { showStackTrace: true })` because warnings aren't caught by the try-catch of renderPageServer()
|
|
28
|
-
|
|
28
|
+
applyViteSourceMap(err);
|
|
29
29
|
});
|
|
30
|
+
setAssertAddTagsDev(addTagsDev);
|
|
30
31
|
// Note shown to user when Vike completely modifies the error message (which is somewhat risky)
|
|
31
32
|
const errorDebugNote = pc.dim(formatHintLog("Error isn't helpful? See https://vike.dev/debug#verbose-errors"));
|
|
32
33
|
function logRuntimeInfoDev(msg, pageContext, logType) {
|
|
@@ -44,7 +45,7 @@ function logVite(msg, logType, requestId, prependViteTag) {
|
|
|
44
45
|
}
|
|
45
46
|
function logErrorServerDev(err, pageContext, errorComesFromVite = false) {
|
|
46
47
|
assertPageContext_logRuntime(pageContext);
|
|
47
|
-
|
|
48
|
+
applyViteSourceMap(err);
|
|
48
49
|
// Skip `throw render()` / `throw redirect()`
|
|
49
50
|
if (isAbortError(err) && !isDebugError()) {
|
|
50
51
|
return;
|
|
@@ -96,7 +97,7 @@ function logErrorServerDev(err, pageContext, errorComesFromVite = false) {
|
|
|
96
97
|
}
|
|
97
98
|
}
|
|
98
99
|
if (tagSource) {
|
|
99
|
-
const errIntro =
|
|
100
|
+
const errIntro = colorError(`[Error] ${errorComesFromVite ? 'Transpilation error' : 'An error was thrown'}:`);
|
|
100
101
|
const prepend = `${getTagsError(errIntro, tagSource)}${errIntro}\n`;
|
|
101
102
|
const errBetter = getBetterError(err, { message: { prepend } });
|
|
102
103
|
logErr(errBetter);
|
|
@@ -128,7 +129,7 @@ function logDev(msg, logType, tagSource, tagTool, doNotAddTags) {
|
|
|
128
129
|
assert(false);
|
|
129
130
|
}
|
|
130
131
|
function getTagSource(requestId = null) {
|
|
131
|
-
const requestIdFromStore =
|
|
132
|
+
const requestIdFromStore = getRequestId_withAsyncHook();
|
|
132
133
|
if (requestIdFromStore !== null) {
|
|
133
134
|
if (requestId === null) {
|
|
134
135
|
requestId = requestIdFromStore;
|
|
@@ -143,7 +144,7 @@ function getTagSource(requestId = null) {
|
|
|
143
144
|
const tagSource = `request-${requestId}`;
|
|
144
145
|
return tagSource;
|
|
145
146
|
}
|
|
146
|
-
function
|
|
147
|
+
function applyViteSourceMap(thing) {
|
|
147
148
|
if (isDebugError())
|
|
148
149
|
return;
|
|
149
150
|
if (!hasProp(thing, 'stack'))
|
|
@@ -160,20 +161,35 @@ function getTagsError(msg, tagSource) {
|
|
|
160
161
|
function getTags(msg, tagTool, tagSource, logType) {
|
|
161
162
|
const tagToolColored = (() => {
|
|
162
163
|
if (logType === 'error' && !hasRed(msg))
|
|
163
|
-
return
|
|
164
|
+
return colorError(tagTool);
|
|
164
165
|
if (logType === 'error-resolve' && !hasGreen(msg))
|
|
165
166
|
return pc.bold(pc.green(tagTool));
|
|
166
167
|
if (logType === 'warn' && !hasYellow(msg))
|
|
167
|
-
return
|
|
168
|
+
return colorWarning(tagTool);
|
|
168
169
|
if (tagTool === '[vite]')
|
|
169
170
|
return colorVite(tagTool);
|
|
170
171
|
if (tagTool === '[vike]')
|
|
171
172
|
return colorVike(tagTool);
|
|
172
173
|
assert(false);
|
|
173
174
|
})();
|
|
174
|
-
const timestamp =
|
|
175
|
+
const timestamp = getTagTimestamp();
|
|
175
176
|
const whitespace = (/\s|\[/.test(stripAnsi(msg)[0]) ? '' : ' ');
|
|
176
|
-
const
|
|
177
|
-
const tags = `${timestamp} ${tagToolColored}${
|
|
177
|
+
const tagSourceOuter = getTagSourceOuter(tagSource);
|
|
178
|
+
const tags = `${timestamp} ${tagToolColored}${tagSourceOuter}${whitespace}`;
|
|
178
179
|
return tags;
|
|
179
180
|
}
|
|
181
|
+
function getTagTimestamp() {
|
|
182
|
+
const timestamp = pc.dim(new Date().toLocaleTimeString());
|
|
183
|
+
return timestamp;
|
|
184
|
+
}
|
|
185
|
+
function getTagSourceOuter(tagSource) {
|
|
186
|
+
const tagSourceOuter = (!tagSource ? '' : pc.dim(`[${tagSource}]`));
|
|
187
|
+
return tagSourceOuter;
|
|
188
|
+
}
|
|
189
|
+
function addTagsDev(tagVike, tagType) {
|
|
190
|
+
const timestamp = getTagTimestamp();
|
|
191
|
+
const tagSource = getTagSource();
|
|
192
|
+
const tagSourceOuter = getTagSourceOuter(tagSource);
|
|
193
|
+
const tagsDev = `${timestamp} ${tagVike}${tagSourceOuter}${tagType}`;
|
|
194
|
+
return tagsDev;
|
|
195
|
+
}
|
|
@@ -5,7 +5,7 @@ export { swallowViteLogForceOptimization_disable };
|
|
|
5
5
|
export { swallowViteLogConnected };
|
|
6
6
|
export { swallowViteLogConnected_clean };
|
|
7
7
|
import { assert, getGlobalObject, isDebugError, removeEmptyLines, trimWithAnsi, trimWithAnsiTrailOnly, } from '../utils.js';
|
|
8
|
-
import {
|
|
8
|
+
import { getRequestId_withAsyncHook } from '../../../server/runtime/asyncHook.js';
|
|
9
9
|
import { logErrorServerDev, logVite } from './loggerDev.js';
|
|
10
10
|
const globalObject = getGlobalObject('vite/shared/loggerDev.ts', {
|
|
11
11
|
processStartupLog_isCompact: null,
|
|
@@ -43,7 +43,7 @@ function intercept(loggerType, config) {
|
|
|
43
43
|
// - It doesn't format error code snippets.
|
|
44
44
|
// - It only shows error.message which means that crucial information such as error.id isn't shown to the user.
|
|
45
45
|
logErrorServerDev(options.error, null, true);
|
|
46
|
-
// We swallow Vite's message:
|
|
46
|
+
// We swallow Vite's message: it doesn't seem to add any value.
|
|
47
47
|
// - It can even be confusing, such as the following:
|
|
48
48
|
// ```
|
|
49
49
|
// Error when evaluating SSR module virtual:vike:page-entry:server:/pages/abort: failed to import "/pages/abort/+Page.mdx"
|
|
@@ -51,7 +51,7 @@ function intercept(loggerType, config) {
|
|
|
51
51
|
assert(!isDebugError());
|
|
52
52
|
return;
|
|
53
53
|
}
|
|
54
|
-
const requestId =
|
|
54
|
+
const requestId = getRequestId_withAsyncHook();
|
|
55
55
|
// Vite's default logger preprends the "[vite]" tag if and only if options.timestamp is true
|
|
56
56
|
const prependViteTag = options.timestamp || typeof requestId === 'number';
|
|
57
57
|
// If it's an actual error => options.error is set => it's handled with logErrorServerDev() above
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { getPageContext_withAsyncHook };
|
|
2
|
-
export {
|
|
2
|
+
export { getRequestId_withAsyncHook };
|
|
3
3
|
export { getAsyncLocalStorage };
|
|
4
4
|
export type { AsyncStore };
|
|
5
5
|
import type { AsyncLocalStorage as AsyncLocalStorageType } from 'node:async_hooks';
|
|
@@ -8,5 +8,5 @@ type AsyncStore = null | {
|
|
|
8
8
|
pageContext?: Record<string, unknown>;
|
|
9
9
|
};
|
|
10
10
|
declare function getAsyncLocalStorage(): Promise<AsyncLocalStorageType<AsyncStore> | null>;
|
|
11
|
-
declare function
|
|
11
|
+
declare function getRequestId_withAsyncHook(): number | null;
|
|
12
12
|
declare function getPageContext_withAsyncHook(): any;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { getPageContext_withAsyncHook };
|
|
2
|
-
export {
|
|
2
|
+
export { getRequestId_withAsyncHook };
|
|
3
3
|
export { getAsyncLocalStorage };
|
|
4
4
|
import { preparePageContextForPublicUsageServer } from './renderPageServer/preparePageContextForPublicUsageServer.js';
|
|
5
5
|
import { assert, assertIsNotBrowser, getGlobalObject, isObject } from '../utils.js';
|
|
@@ -30,7 +30,7 @@ function getAsyncStore() {
|
|
|
30
30
|
assert(asyncStore === undefined || isObject(asyncStore));
|
|
31
31
|
return asyncStore ?? null;
|
|
32
32
|
}
|
|
33
|
-
function
|
|
33
|
+
function getRequestId_withAsyncHook() {
|
|
34
34
|
const asyncStore = getAsyncStore();
|
|
35
35
|
return asyncStore?.requestId ?? null;
|
|
36
36
|
}
|
package/dist/server/utils.d.ts
CHANGED
|
@@ -42,8 +42,8 @@ export * from '../utils/assertSetup.js';
|
|
|
42
42
|
export * from '../utils/path.js';
|
|
43
43
|
export * from '../utils/isHtml.js';
|
|
44
44
|
export * from '../utils/virtualFileId.js';
|
|
45
|
-
export * from '../utils/
|
|
46
|
-
export * from '../utils/
|
|
45
|
+
export * from '../utils/colorsServer.js';
|
|
46
|
+
export * from '../utils/colorsClient.js';
|
|
47
47
|
export * from '../utils/getTerminalWidth.js';
|
|
48
48
|
export * from '../utils/truncateString.js';
|
|
49
49
|
export * from '../utils/formatHintLog.js';
|
package/dist/server/utils.js
CHANGED
|
@@ -46,8 +46,8 @@ export * from '../utils/assertSetup.js';
|
|
|
46
46
|
export * from '../utils/path.js';
|
|
47
47
|
export * from '../utils/isHtml.js';
|
|
48
48
|
export * from '../utils/virtualFileId.js';
|
|
49
|
-
export * from '../utils/
|
|
50
|
-
export * from '../utils/
|
|
49
|
+
export * from '../utils/colorsServer.js';
|
|
50
|
+
export * from '../utils/colorsClient.js';
|
|
51
51
|
export * from '../utils/getTerminalWidth.js';
|
|
52
52
|
export * from '../utils/truncateString.js';
|
|
53
53
|
export * from '../utils/formatHintLog.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.249";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Automatically updated by @brillout/release-me
|
|
2
|
-
export const PROJECT_VERSION = '0.4.
|
|
2
|
+
export const PROJECT_VERSION = '0.4.249';
|
package/dist/utils/assert.d.ts
CHANGED
|
@@ -3,10 +3,12 @@ export { assertUsage };
|
|
|
3
3
|
export { assertWarning };
|
|
4
4
|
export { assertInfo };
|
|
5
5
|
export { getProjectError };
|
|
6
|
-
export { addOnBeforeAssertLog };
|
|
7
|
-
export { addOnBeforeAssertErr };
|
|
8
6
|
export { isVikeBug };
|
|
7
|
+
export { setAssertOnBeforeLog };
|
|
8
|
+
export { setAssertOnBeforeErr };
|
|
9
9
|
export { setAlwaysShowStackTrace };
|
|
10
|
+
export { setAssertAddTagsDev };
|
|
11
|
+
import type { AddTagsDev } from '../node/vite/shared/loggerDev.js';
|
|
10
12
|
declare function assert(condition: unknown, debugInfo?: unknown): asserts condition;
|
|
11
13
|
declare function assertUsage(condition: unknown, errMsg: string, { showStackTrace, exitOnError }?: {
|
|
12
14
|
showStackTrace?: true;
|
|
@@ -20,7 +22,8 @@ declare function assertWarning(condition: unknown, msg: string, { onlyOnce, show
|
|
|
20
22
|
declare function assertInfo(condition: unknown, msg: string, { onlyOnce }: {
|
|
21
23
|
onlyOnce: boolean;
|
|
22
24
|
}): void;
|
|
23
|
-
declare function
|
|
24
|
-
declare function
|
|
25
|
+
declare function setAssertOnBeforeLog(onBeforeAssertLog: () => void): void;
|
|
26
|
+
declare function setAssertOnBeforeErr(onBeforeAssertErr: (err: unknown) => void): void;
|
|
27
|
+
declare function setAssertAddTagsDev(addTagsDev: AddTagsDev): void;
|
|
25
28
|
declare function isVikeBug(err: unknown): boolean;
|
|
26
29
|
declare function setAlwaysShowStackTrace(): void;
|
package/dist/utils/assert.js
CHANGED
|
@@ -3,24 +3,24 @@ export { assertUsage };
|
|
|
3
3
|
export { assertWarning };
|
|
4
4
|
export { assertInfo };
|
|
5
5
|
export { getProjectError };
|
|
6
|
-
export { addOnBeforeAssertLog };
|
|
7
|
-
export { addOnBeforeAssertErr };
|
|
8
6
|
export { isVikeBug };
|
|
7
|
+
export { setAssertOnBeforeLog };
|
|
8
|
+
export { setAssertOnBeforeErr };
|
|
9
9
|
export { setAlwaysShowStackTrace };
|
|
10
|
+
export { setAssertAddTagsDev };
|
|
10
11
|
import { assertSingleInstance_onAssertModuleLoad } from './assertSingleInstance.js';
|
|
11
12
|
import { createErrorWithCleanStackTrace } from './createErrorWithCleanStackTrace.js';
|
|
12
13
|
import { getGlobalObject } from './getGlobalObject.js';
|
|
13
14
|
import { PROJECT_VERSION } from './PROJECT_VERSION.js';
|
|
14
|
-
import { colorVike } from './
|
|
15
|
+
import { colorVike, colorWarning, colorError } from './colorsClient.js';
|
|
15
16
|
import pc from '@brillout/picocolors';
|
|
16
17
|
const globalObject = getGlobalObject('utils/assert.ts', {
|
|
17
18
|
alreadyLogged: new Set(),
|
|
18
19
|
});
|
|
19
20
|
assertSingleInstance_onAssertModuleLoad();
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const numberOfStackTraceLinesToRemove = 2;
|
|
21
|
+
const tagVike = `[vike]`;
|
|
22
|
+
const tagVikeWithVersion = `[vike@${PROJECT_VERSION}]`;
|
|
23
|
+
const tagTypeBug = 'Bug';
|
|
24
24
|
function assert(condition, debugInfo) {
|
|
25
25
|
if (condition)
|
|
26
26
|
return;
|
|
@@ -38,24 +38,20 @@ function assert(condition, debugInfo) {
|
|
|
38
38
|
]
|
|
39
39
|
.filter(Boolean)
|
|
40
40
|
.join(' ');
|
|
41
|
-
errMsg =
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
globalObject.onBeforeAssertLog?.();
|
|
46
|
-
globalObject.onBeforeAssertErr?.(internalError);
|
|
41
|
+
errMsg = addTags(errMsg, tagTypeBug, true);
|
|
42
|
+
const internalError = createError(errMsg);
|
|
43
|
+
globalObject.onBeforeLog?.();
|
|
44
|
+
globalObject.onBeforeErr?.(internalError);
|
|
47
45
|
throw internalError;
|
|
48
46
|
}
|
|
49
47
|
function assertUsage(condition, errMsg, { showStackTrace, exitOnError } = {}) {
|
|
50
48
|
if (condition)
|
|
51
49
|
return;
|
|
52
50
|
showStackTrace = showStackTrace || globalObject.alwaysShowStackTrace;
|
|
53
|
-
errMsg =
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
globalObject.onBeforeAssertLog?.();
|
|
58
|
-
globalObject.onBeforeAssertErr?.(usageError);
|
|
51
|
+
errMsg = addTags(errMsg, 'Wrong Usage');
|
|
52
|
+
const usageError = createError(errMsg);
|
|
53
|
+
globalObject.onBeforeLog?.();
|
|
54
|
+
globalObject.onBeforeErr?.(usageError);
|
|
59
55
|
if (!exitOnError) {
|
|
60
56
|
throw usageError;
|
|
61
57
|
}
|
|
@@ -65,19 +61,14 @@ function assertUsage(condition, errMsg, { showStackTrace, exitOnError } = {}) {
|
|
|
65
61
|
}
|
|
66
62
|
}
|
|
67
63
|
function getProjectError(errMsg) {
|
|
68
|
-
errMsg =
|
|
69
|
-
|
|
70
|
-
errMsg = addPrefixProjectName(errMsg);
|
|
71
|
-
const projectError = createErrorWithCleanStackTrace(errMsg, numberOfStackTraceLinesToRemove);
|
|
64
|
+
errMsg = addTags(errMsg, 'Error');
|
|
65
|
+
const projectError = createError(errMsg);
|
|
72
66
|
return projectError;
|
|
73
67
|
}
|
|
74
68
|
function assertWarning(condition, msg, { onlyOnce, showStackTrace }) {
|
|
75
69
|
if (condition)
|
|
76
70
|
return;
|
|
77
71
|
showStackTrace = showStackTrace || globalObject.alwaysShowStackTrace;
|
|
78
|
-
msg = addWhitespace(msg);
|
|
79
|
-
msg = addPrefixAssertType(msg, 'Warning');
|
|
80
|
-
msg = addPrefixProjectName(msg);
|
|
81
72
|
if (onlyOnce) {
|
|
82
73
|
const { alreadyLogged } = globalObject;
|
|
83
74
|
const key = onlyOnce === true ? msg : onlyOnce;
|
|
@@ -85,22 +76,22 @@ function assertWarning(condition, msg, { onlyOnce, showStackTrace }) {
|
|
|
85
76
|
return;
|
|
86
77
|
alreadyLogged.add(key);
|
|
87
78
|
}
|
|
88
|
-
|
|
79
|
+
const msgWithTags = addTags(msg, 'Warning');
|
|
80
|
+
globalObject.onBeforeLog?.();
|
|
89
81
|
if (showStackTrace) {
|
|
90
|
-
const err =
|
|
91
|
-
globalObject.
|
|
82
|
+
const err = createError(msgWithTags);
|
|
83
|
+
globalObject.onBeforeErr?.(err);
|
|
92
84
|
console.warn(err);
|
|
93
85
|
}
|
|
94
86
|
else {
|
|
95
|
-
console.warn(
|
|
87
|
+
console.warn(msgWithTags);
|
|
96
88
|
}
|
|
97
89
|
}
|
|
98
90
|
function assertInfo(condition, msg, { onlyOnce }) {
|
|
99
91
|
if (condition) {
|
|
100
92
|
return;
|
|
101
93
|
}
|
|
102
|
-
msg =
|
|
103
|
-
msg = addPrefixProjectName(msg);
|
|
94
|
+
msg = addTags(msg, null);
|
|
104
95
|
if (onlyOnce) {
|
|
105
96
|
const { alreadyLogged } = globalObject;
|
|
106
97
|
const key = msg;
|
|
@@ -111,41 +102,65 @@ function assertInfo(condition, msg, { onlyOnce }) {
|
|
|
111
102
|
alreadyLogged.add(key);
|
|
112
103
|
}
|
|
113
104
|
}
|
|
114
|
-
globalObject.
|
|
105
|
+
globalObject.onBeforeLog?.();
|
|
115
106
|
console.log(msg);
|
|
116
107
|
}
|
|
117
|
-
function
|
|
118
|
-
globalObject.
|
|
108
|
+
function setAssertOnBeforeLog(onBeforeAssertLog) {
|
|
109
|
+
globalObject.onBeforeLog = onBeforeAssertLog;
|
|
119
110
|
}
|
|
120
|
-
function
|
|
121
|
-
globalObject.
|
|
111
|
+
function setAssertOnBeforeErr(onBeforeAssertErr) {
|
|
112
|
+
globalObject.onBeforeErr = onBeforeAssertErr;
|
|
122
113
|
}
|
|
123
|
-
function
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
114
|
+
function setAssertAddTagsDev(addTagsDev) {
|
|
115
|
+
globalObject.addTagsDev = addTagsDev;
|
|
116
|
+
}
|
|
117
|
+
function addTags(msg, tagType, showProjectVersion = false) {
|
|
118
|
+
const tagVike = getTagVike(showProjectVersion);
|
|
119
|
+
const tagTypeOuter = getTagType(tagType);
|
|
120
|
+
const whitespace = getTagWhitespace(msg);
|
|
121
|
+
if (globalObject.addTagsDev) {
|
|
122
|
+
const tagsDev = globalObject.addTagsDev(tagVike, tagTypeOuter);
|
|
123
|
+
return `${tagsDev}${whitespace}${msg}`;
|
|
127
124
|
}
|
|
128
125
|
else {
|
|
129
|
-
|
|
126
|
+
const tags = `${tagVike}${tagTypeOuter}`;
|
|
127
|
+
return `${tags}${whitespace}${msg}`;
|
|
130
128
|
}
|
|
131
|
-
return `${prefix}${msg}`;
|
|
132
129
|
}
|
|
133
|
-
function
|
|
130
|
+
function getTagWhitespace(msg) {
|
|
134
131
|
if (msg.startsWith('[')) {
|
|
135
|
-
return
|
|
132
|
+
return '';
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
return ' ';
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function getTagType(tagType) {
|
|
139
|
+
if (!tagType)
|
|
140
|
+
return '';
|
|
141
|
+
let tag = `[${tagType}]`;
|
|
142
|
+
if (tagType === 'Warning') {
|
|
143
|
+
tag = colorWarning(tag);
|
|
136
144
|
}
|
|
137
145
|
else {
|
|
138
|
-
|
|
146
|
+
tag = colorError(tag);
|
|
139
147
|
}
|
|
148
|
+
return tag;
|
|
140
149
|
}
|
|
141
|
-
function
|
|
142
|
-
const
|
|
143
|
-
return
|
|
150
|
+
function getTagVike(showProjectVersion = false) {
|
|
151
|
+
const tag = showProjectVersion ? tagVikeWithVersion : tagVike;
|
|
152
|
+
return colorVike(tag);
|
|
144
153
|
}
|
|
145
154
|
function isVikeBug(err) {
|
|
146
|
-
return String(err).includes(`[${
|
|
155
|
+
return String(err).includes(`[${tagTypeBug}]`);
|
|
147
156
|
}
|
|
148
157
|
// Called upon `DEBUG=vike:error`
|
|
149
158
|
function setAlwaysShowStackTrace() {
|
|
150
159
|
globalObject.alwaysShowStackTrace = true;
|
|
151
160
|
}
|
|
161
|
+
function createError(errMsg) {
|
|
162
|
+
const err = createErrorWithCleanStackTrace(errMsg, 3);
|
|
163
|
+
if (globalObject.addTagsDev)
|
|
164
|
+
err.stack = err.stack?.replace(/^Error:\s*/, '');
|
|
165
|
+
return err;
|
|
166
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { colorVike };
|
|
2
|
+
export { colorError };
|
|
3
|
+
export { colorWarning };
|
|
4
|
+
declare function colorVike<Str extends string>(str: Str): Str;
|
|
5
|
+
declare function colorError<Str extends string>(str: Str): Str;
|
|
6
|
+
declare function colorWarning<Str extends string>(str: Str): Str;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// ./colorsServer.js => server only
|
|
2
|
+
// ./colorsClient.js => server & client
|
|
3
|
+
// !!!WARNING!!! KEEP THIS FILE MINIMAL: to save KBs sent to the browser
|
|
4
|
+
export { colorVike };
|
|
5
|
+
export { colorError };
|
|
6
|
+
export { colorWarning };
|
|
7
|
+
import pc from '@brillout/picocolors';
|
|
8
|
+
function colorVike(str) {
|
|
9
|
+
return pc.bold(pc.yellow(str));
|
|
10
|
+
}
|
|
11
|
+
function colorError(str) {
|
|
12
|
+
return pc.bold(pc.red(str));
|
|
13
|
+
}
|
|
14
|
+
function colorWarning(str) {
|
|
15
|
+
return pc.yellow(str);
|
|
16
|
+
}
|
|
@@ -6,20 +6,24 @@ export { getBetterError };
|
|
|
6
6
|
import { isObject } from './isObject.js';
|
|
7
7
|
import { assertIsNotBrowser } from './assertIsNotBrowser.js';
|
|
8
8
|
import { objectAssign } from './objectAssign.js';
|
|
9
|
+
import { shallowClone } from './shallowClone.js';
|
|
9
10
|
assertIsNotBrowser();
|
|
10
11
|
function getBetterError(err, modifications) {
|
|
12
|
+
const errOriginal = shallowClone(err);
|
|
11
13
|
let errBetter;
|
|
12
14
|
// Normalize
|
|
13
15
|
if (!isObject(err)) {
|
|
14
|
-
warnMalformed(
|
|
16
|
+
warnMalformed(errOriginal);
|
|
15
17
|
errBetter = new Error(String(err));
|
|
16
18
|
}
|
|
17
19
|
else {
|
|
18
|
-
|
|
20
|
+
// We mutate instead of structuredClone(err) to avoid breaking Vite's ssrFixStacktrace() internal rewroteStacktraces.has(err) check
|
|
21
|
+
// https://github.com/vitejs/vite/blob/dafd726032daa98d0e614f97aebe9d4dbffe2ea7/packages/vite/src/node/ssr/ssrStacktrace.ts#L95
|
|
22
|
+
errBetter = err;
|
|
19
23
|
}
|
|
20
24
|
errBetter.message ?? (errBetter.message = '');
|
|
21
25
|
if (!errBetter.stack) {
|
|
22
|
-
warnMalformed(
|
|
26
|
+
warnMalformed(errOriginal);
|
|
23
27
|
errBetter.stack = new Error(errBetter.message).stack;
|
|
24
28
|
}
|
|
25
29
|
// Modifications: err.hideStack and err.stack
|
|
@@ -40,7 +44,7 @@ function getBetterError(err, modifications) {
|
|
|
40
44
|
errBetter.stack = messageNext + stack;
|
|
41
45
|
}
|
|
42
46
|
else {
|
|
43
|
-
warnMalformed(
|
|
47
|
+
warnMalformed(errOriginal);
|
|
44
48
|
}
|
|
45
49
|
}
|
|
46
50
|
else {
|
|
@@ -57,10 +61,10 @@ function getBetterError(err, modifications) {
|
|
|
57
61
|
}
|
|
58
62
|
}
|
|
59
63
|
// Enable users to retrieve the original error
|
|
60
|
-
objectAssign(errBetter, { getOriginalError: () =>
|
|
64
|
+
objectAssign(errBetter, { getOriginalError: () => errOriginal?.getOriginalError?.() ?? errOriginal });
|
|
61
65
|
return errBetter;
|
|
62
66
|
}
|
|
63
67
|
// TO-DO/eventually: think about whether logging this warning is a good idea
|
|
64
|
-
function warnMalformed(
|
|
65
|
-
console.warn('Malformed error: ',
|
|
68
|
+
function warnMalformed(errOriginal) {
|
|
69
|
+
console.warn('Malformed error: ', errOriginal);
|
|
66
70
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { shallowClone };
|
|
2
|
+
import { isObject } from './isObject.js';
|
|
3
|
+
// - AFAICT it's the most accurate.
|
|
4
|
+
// - The structuredClone() built-in isn't usable: https://www.typescriptlang.org/play/?ssl=7&ssc=1&pln=9&pc=1#code/G4QwTgBApmkLwQHZQO4QKKwPZgBQHIBhAVwGcAXLAW2mzHwEoIRTnEBPAKAh95jAB0AYywATKBAT50AfUIBVAMoAVAPIBZfN149+AiiHJlCYiQgCsABkucRiCrTCEANlmSjJECmGJCjYKFEXNyhcfgZOAHpIiAAZLABzVgADYkRxADMAS3dk2zdSLGcoAVcEgn5g92FTfAAaRyrAmvEIqJjlAAswLBRWEERHHE5vX39AptwAby9qKAAxNKFcJimAXzWGIA
|
|
5
|
+
function shallowClone(obj) {
|
|
6
|
+
if (!isObject(obj))
|
|
7
|
+
return obj;
|
|
8
|
+
const clone = Object.create(Object.getPrototypeOf(obj));
|
|
9
|
+
Object.defineProperties(clone, Object.getOwnPropertyDescriptors(obj));
|
|
10
|
+
return clone;
|
|
11
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { trimWithAnsi };
|
|
2
2
|
export { trimWithAnsiTrailOnly };
|
|
3
3
|
import { assert } from './assert.js';
|
|
4
|
-
import { stripAnsi } from './
|
|
4
|
+
import { stripAnsi } from './colorsServer.js';
|
|
5
5
|
const whitespaceRegex = /(\s+)/; // Capturing parathesis so that split preserves separator
|
|
6
6
|
/* Same as trim() but works with ANSI escape codes */
|
|
7
7
|
function trimWithAnsi(str) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vike",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.249",
|
|
4
4
|
"repository": "https://github.com/vikejs/vike",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./server": {
|
|
@@ -244,7 +244,7 @@
|
|
|
244
244
|
"./universal-middleware.js"
|
|
245
245
|
],
|
|
246
246
|
"devDependencies": {
|
|
247
|
-
"@brillout/release-me": "^0.4.
|
|
247
|
+
"@brillout/release-me": "^0.4.11",
|
|
248
248
|
"@types/estree": "^1.0.5",
|
|
249
249
|
"@types/node": "^20.10.5",
|
|
250
250
|
"@types/picomatch": "^3.0.2",
|
package/dist/utils/colorVike.js
DELETED
|
File without changes
|