vike 0.4.241-commit-60b0676 → 0.4.242-commit-33026dc
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/node/vite/plugins/pluginReplaceConstantsGlobalThis.d.ts +1 -0
- package/dist/esm/shared/modifyUrlSameOrigin.js +2 -2
- package/dist/esm/shared/route/abort.js +2 -2
- package/dist/esm/shared/route/execHookOnBeforeRoute.js +3 -3
- package/dist/esm/types/index.d.ts +1 -0
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/parseUrl.d.ts +4 -2
- package/dist/esm/utils/parseUrl.js +28 -25
- package/package.json +1 -1
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
export { modifyUrlSameOrigin };
|
|
2
2
|
// We don't move modifyUrlSameOrigin() to the modifyUrl.ts file because we plan to use modifyUrlSameOrigin() on the client-side:
|
|
3
3
|
// https://github.com/vikejs/vike/blob/c5a2de5e85262771f97851767c00ac35da69c64b/packages/vike/client/runtime-client-routing/navigate.ts#L4
|
|
4
|
-
import { createUrlFromComponents, isNotNullish_keyVal, parseUrl, objectFilter,
|
|
4
|
+
import { createUrlFromComponents, isNotNullish_keyVal, parseUrl, objectFilter, assertUsageUrlPathAbsolute, } from './utils.js';
|
|
5
5
|
function modifyUrlSameOrigin(url, modify) {
|
|
6
6
|
const urlParsed = parseUrl(url, '/');
|
|
7
7
|
// Pathname
|
|
8
8
|
const pathname = modify.pathname ?? urlParsed.pathnameOriginal;
|
|
9
|
-
|
|
9
|
+
assertUsageUrlPathAbsolute(pathname, 'modify.pathname');
|
|
10
10
|
// Search
|
|
11
11
|
let search = modify.search === null ? '' : !modify.search ? urlParsed.searchOriginal : resolveSearch(urlParsed, modify.search);
|
|
12
12
|
if (search === '?')
|
|
@@ -8,7 +8,7 @@ export { getPageContextFromAllRewrites };
|
|
|
8
8
|
export { AbortRender };
|
|
9
9
|
export { assertNoInfiniteAbortLoop };
|
|
10
10
|
import { isUserHookError } from '../hooks/execHook.js';
|
|
11
|
-
import { assert, assertInfo, assertUsage,
|
|
11
|
+
import { assert, assertInfo, assertUsage, assertUsageUrlPathAbsolute, assertUsageUrlRedirectTarget, assertWarning, checkType, hasProp, isBrowser, joinEnglish, objectAssign, truncateString, } from './utils.js';
|
|
12
12
|
import pc from '@brillout/picocolors';
|
|
13
13
|
/**
|
|
14
14
|
* Abort the rendering of the current page, and redirect the user to another URL instead.
|
|
@@ -66,7 +66,7 @@ function render_(urlOrStatusCode, abortReason, abortCall, abortCaller, pageConte
|
|
|
66
66
|
}
|
|
67
67
|
if (typeof urlOrStatusCode === 'string') {
|
|
68
68
|
const url = urlOrStatusCode;
|
|
69
|
-
|
|
69
|
+
assertUsageUrlPathAbsolute(url, getErrPrefix(abortCaller));
|
|
70
70
|
objectAssign(pageContextAbort, {
|
|
71
71
|
_urlRewrite: url,
|
|
72
72
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { execHookOnBeforeRoute };
|
|
2
2
|
import { assertPageContextProvidedByUser } from '../assertPageContextProvidedByUser.js';
|
|
3
|
-
import { assertUsage, hasProp, isObjectWithKeys, objectAssign, assertWarning,
|
|
3
|
+
import { assertUsage, hasProp, isObjectWithKeys, objectAssign, assertWarning, assertUsageUrlAbsolute, joinEnglish, assert, } from './utils.js';
|
|
4
4
|
import { assertRouteParams, assertSyncRouting } from './resolveRouteFunction.js';
|
|
5
5
|
import pc from '@brillout/picocolors';
|
|
6
6
|
import { execHookDirectSync } from '../hooks/execHook.js';
|
|
@@ -65,8 +65,8 @@ async function getPageContextFromHook(onBeforeRouteHook, pageContext) {
|
|
|
65
65
|
delete hookReturn.pageContext.urlOriginal;
|
|
66
66
|
}
|
|
67
67
|
if (hasProp(hookReturn.pageContext, 'urlLogical')) {
|
|
68
|
-
|
|
69
|
-
// We
|
|
68
|
+
assertUsageUrlAbsolute(
|
|
69
|
+
// We type-cast instead of assertUsage() validation in order to save client-side KBs
|
|
70
70
|
hookReturn.pageContext.urlLogical, `${errPrefix} returned ${pc.cyan('{ pageContext: { urlLogical } }')} and ${pc.cyan('urlLogical')}`);
|
|
71
71
|
}
|
|
72
72
|
assertPageContextProvidedByUser(hookReturn.pageContext, {
|
|
@@ -13,6 +13,7 @@ export type { VikeConfig } from '../node/vite/shared/resolveVikeConfigInternal.j
|
|
|
13
13
|
export type { UrlPublic as Url } from '../utils/parseUrl.js';
|
|
14
14
|
export type { InjectFilterEntry } from '../node/runtime/renderPage/html/injectAssets/getHtmlTags.js';
|
|
15
15
|
export { defineConfig } from './defineConfig.js';
|
|
16
|
+
export type { _LoadDeclareGlobal__VIKE__IS } from '../node/vite/plugins/pluginReplaceConstantsGlobalThis.js';
|
|
16
17
|
import type { ConfigEnv } from './PageConfig.js';
|
|
17
18
|
/** @deprecated Replace:
|
|
18
19
|
* `import type { Env } from 'vike/types'`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.242-commit-33026dc";
|
|
@@ -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.242-commit-33026dc';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { parseUrl };
|
|
2
|
-
export {
|
|
2
|
+
export { assertUsageUrlAbsolute };
|
|
3
|
+
export { assertUsageUrlPathAbsolute };
|
|
3
4
|
export { assertUsageUrlRedirectTarget };
|
|
4
5
|
export { isUrl };
|
|
5
6
|
export { isUri };
|
|
@@ -52,5 +53,6 @@ declare function isUrlRedirectTarget(url: string): boolean;
|
|
|
52
53
|
declare function isUrlRelative(url: string): boolean;
|
|
53
54
|
declare function isUrlExternal(url: string): boolean;
|
|
54
55
|
declare function isUri(uri: string): boolean;
|
|
55
|
-
declare function
|
|
56
|
+
declare function assertUsageUrlAbsolute(url: string, errPrefix: string): void;
|
|
57
|
+
declare function assertUsageUrlPathAbsolute(url: string, errPrefix: string): void;
|
|
56
58
|
declare function assertUsageUrlRedirectTarget(url: string, errPrefix: string, isUnresolved?: true): void;
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
// - It doesn't support the tauri:// protocol
|
|
4
4
|
// Unit tests at ./parseUrl.spec.ts
|
|
5
5
|
export { parseUrl };
|
|
6
|
-
export {
|
|
6
|
+
export { assertUsageUrlAbsolute };
|
|
7
|
+
export { assertUsageUrlPathAbsolute };
|
|
7
8
|
export { assertUsageUrlRedirectTarget };
|
|
8
9
|
export { isUrl };
|
|
9
10
|
export { isUri };
|
|
@@ -135,7 +136,7 @@ function getBaseURI() {
|
|
|
135
136
|
return baseURI;
|
|
136
137
|
}
|
|
137
138
|
function parseOrigin(url) {
|
|
138
|
-
if (!
|
|
139
|
+
if (!isUrlWithWebProtocol(url)) {
|
|
139
140
|
return { pathname: url, origin: null, protocol: null };
|
|
140
141
|
}
|
|
141
142
|
else {
|
|
@@ -181,7 +182,7 @@ function parseProtocol(uri) {
|
|
|
181
182
|
}
|
|
182
183
|
return { protocol, uriWithoutProtocol };
|
|
183
184
|
}
|
|
184
|
-
function
|
|
185
|
+
function isWebUrlProtocol(protocol) {
|
|
185
186
|
// Is there an alternative to having a blocklist?
|
|
186
187
|
// - If the blocklist becomes too big, maybe use a allowlist instead ['tauri://', 'file://', 'capacitor://', 'http://', 'https://']
|
|
187
188
|
const blocklist = [
|
|
@@ -264,10 +265,16 @@ function createUrlFromComponents(origin, pathname, search, hash) {
|
|
|
264
265
|
}
|
|
265
266
|
function isUrl(url) {
|
|
266
267
|
// parseUrl() works with these URLs
|
|
267
|
-
return
|
|
268
|
+
return isUrlAbsolute(url) || isUrlRelative(url);
|
|
268
269
|
}
|
|
269
270
|
function isUrlRedirectTarget(url) {
|
|
270
|
-
return url
|
|
271
|
+
return isUrlAbsolute(url) || isUri(url);
|
|
272
|
+
}
|
|
273
|
+
function isUrlAbsolute(url) {
|
|
274
|
+
return isUrlPathAbsolute(url) || isUrlWithWebProtocol(url);
|
|
275
|
+
}
|
|
276
|
+
function isUrlPathAbsolute(url) {
|
|
277
|
+
return url.startsWith('/');
|
|
271
278
|
}
|
|
272
279
|
function isUrlRelative(url) {
|
|
273
280
|
return ['.', '?', '#'].some((c) => url.startsWith(c)) || url === '';
|
|
@@ -288,9 +295,9 @@ URL with protocol.
|
|
|
288
295
|
[Electron (`file://`)](https://github.com/vikejs/vike/issues/1557)
|
|
289
296
|
[Capacitor](https://github.com/vikejs/vike/issues/1706)
|
|
290
297
|
*/
|
|
291
|
-
function
|
|
298
|
+
function isUrlWithWebProtocol(url) {
|
|
292
299
|
const { protocol } = parseProtocol(url);
|
|
293
|
-
return !!protocol &&
|
|
300
|
+
return !!protocol && isWebUrlProtocol(protocol);
|
|
294
301
|
}
|
|
295
302
|
/*
|
|
296
303
|
URIs that aren't URLs.
|
|
@@ -308,27 +315,23 @@ We need to treat URIs differently than URLs.
|
|
|
308
315
|
*/
|
|
309
316
|
function isUri(uri) {
|
|
310
317
|
const { protocol } = parseProtocol(uri);
|
|
311
|
-
return !!protocol && !
|
|
318
|
+
return !!protocol && !isWebUrlProtocol(protocol);
|
|
319
|
+
}
|
|
320
|
+
function assertUsageUrlAbsolute(url, errPrefix) {
|
|
321
|
+
assertUsage(isUrlAbsolute(url), getErrMsg(url, errPrefix, true));
|
|
312
322
|
}
|
|
313
|
-
function
|
|
314
|
-
|
|
323
|
+
function assertUsageUrlPathAbsolute(url, errPrefix) {
|
|
324
|
+
assertUsage(isUrlPathAbsolute(url), getErrMsg(url, errPrefix));
|
|
315
325
|
}
|
|
316
326
|
function assertUsageUrlRedirectTarget(url, errPrefix, isUnresolved) {
|
|
317
|
-
|
|
327
|
+
const errMsg = getErrMsg(url, errPrefix, true, isUnresolved);
|
|
328
|
+
assertUsage(isUrlRedirectTarget(url) || (isUnresolved && url === '*'), errMsg);
|
|
318
329
|
}
|
|
319
|
-
function
|
|
320
|
-
if (url.startsWith('/'))
|
|
321
|
-
return;
|
|
330
|
+
function getErrMsg(url, errPrefix, allowProtocol, allowUri) {
|
|
322
331
|
let errMsg = `${errPrefix} is ${pc.string(url)} but it should start with ${pc.string('/')}`;
|
|
323
|
-
if (
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
errMsg +=
|
|
327
|
-
|
|
328
|
-
if (url === '*')
|
|
329
|
-
return;
|
|
330
|
-
errMsg += `, or be ${pc.string('*')}`;
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
assertUsage(false, errMsg);
|
|
332
|
+
if (allowProtocol)
|
|
333
|
+
errMsg += ` or a protocol (e.g. ${pc.string('http://')})`;
|
|
334
|
+
if (allowUri)
|
|
335
|
+
errMsg += `, or be ${pc.string('*')}`;
|
|
336
|
+
return errMsg;
|
|
334
337
|
}
|