vike 0.4.225 → 0.4.226-commit-a0035ee
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/client/shared/getPageContextProxyForUser.js +3 -66
- package/dist/cjs/node/api/build.js +7 -7
- package/dist/cjs/node/api/dev.js +2 -2
- package/dist/cjs/node/api/prepareViteApiCall.js +55 -30
- package/dist/cjs/node/api/prerender.js +2 -3
- package/dist/cjs/node/api/preview.js +27 -6
- package/dist/cjs/node/api/utils.js +1 -0
- package/dist/cjs/node/cli/entry.js +4 -2
- package/dist/cjs/node/cli/parseCli.js +10 -4
- package/dist/cjs/node/plugin/plugins/build/pluginAutoFullBuild.js +3 -3
- package/dist/cjs/node/plugin/plugins/build/pluginModuleBanner.js +51 -0
- package/dist/cjs/node/plugin/plugins/build.js +3 -1
- package/dist/cjs/node/plugin/plugins/commonConfig.js +16 -8
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +5 -5
- package/dist/cjs/node/plugin/plugins/fileEnv.js +3 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/index.js +14 -10
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +5 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +11 -12
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +99 -85
- package/dist/cjs/node/plugin/plugins/setGlobalContext.js +10 -1
- package/dist/cjs/node/plugin/shared/getEnvVarObject.js +7 -0
- package/dist/cjs/node/prerender/resolvePrerenderConfig.js +3 -3
- package/dist/cjs/node/prerender/runPrerender.js +14 -19
- package/dist/cjs/node/prerender/utils.js +1 -1
- package/dist/cjs/node/runtime/globalContext.js +13 -8
- package/dist/cjs/node/runtime/html/injectAssets/getViteDevScript.js +6 -3
- package/dist/cjs/node/runtime/html/serializePageContextClientSide.js +67 -14
- package/dist/cjs/node/runtime/renderPage/createHttpResponse/assertNoInfiniteHttpRedirect.js +3 -2
- package/dist/cjs/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.js +3 -0
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +18 -12
- package/dist/cjs/node/runtime/renderPage.js +13 -28
- package/dist/cjs/node/runtime/utils.js +1 -1
- package/dist/cjs/node/runtime-dev/createDevMiddleware.js +2 -2
- package/dist/cjs/node/shared/assertV1Design.js +1 -1
- package/dist/cjs/node/shared/utils.js +1 -1
- package/dist/cjs/node/shared/virtual-files.js +14 -10
- package/dist/cjs/shared/NOT_SERIALIZABLE.js +5 -0
- package/dist/cjs/shared/modifyUrl.js +3 -5
- package/dist/cjs/shared/modifyUrlSameOrigin.js +42 -0
- package/dist/cjs/shared/page-configs/getConfigDefinedAt.js +3 -2
- package/dist/cjs/shared/page-configs/getConfigValueBuildTime.js +5 -5
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +9 -9
- package/dist/cjs/shared/utils.js +2 -1
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/assert.js +10 -3
- package/dist/cjs/utils/assertSetup.js +12 -8
- package/dist/cjs/utils/assertSingleInstance.js +19 -4
- package/dist/cjs/utils/getRandomId.js +1 -1
- package/dist/cjs/utils/isNullish.js +16 -0
- package/dist/cjs/utils/normalizeHeaders.js +1 -1
- package/dist/cjs/utils/objectAssign.js +7 -2
- package/dist/cjs/utils/objectFilter.js +10 -0
- package/dist/cjs/utils/pick.js +12 -0
- package/dist/esm/client/client-routing-runtime/createPageContext.d.ts +3 -1
- package/dist/esm/client/client-routing-runtime/createPageContext.js +4 -3
- package/dist/esm/client/client-routing-runtime/navigate.d.ts +6 -5
- package/dist/esm/client/client-routing-runtime/navigate.js +6 -2
- package/dist/esm/client/client-routing-runtime/normalizeUrlArgument.js +1 -1
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +1 -1
- package/dist/esm/client/server-routing-runtime/getPageContext.d.ts +6 -3
- package/dist/esm/client/server-routing-runtime/getPageContext.js +6 -3
- package/dist/esm/client/shared/getPageContextProxyForUser.d.ts +1 -11
- package/dist/esm/client/shared/getPageContextProxyForUser.js +4 -67
- package/dist/esm/client/shared/preparePageContextForUserConsumptionClientSide.d.ts +2 -2
- package/dist/esm/node/api/build.js +7 -7
- package/dist/esm/node/api/dev.js +2 -2
- package/dist/esm/node/api/prepareViteApiCall.d.ts +2 -1
- package/dist/esm/node/api/prepareViteApiCall.js +57 -32
- package/dist/esm/node/api/prerender.js +2 -3
- package/dist/esm/node/api/preview.d.ts +1 -1
- package/dist/esm/node/api/preview.js +24 -6
- package/dist/esm/node/api/utils.d.ts +1 -0
- package/dist/esm/node/api/utils.js +1 -0
- package/dist/esm/node/cli/entry.js +4 -2
- package/dist/esm/node/cli/parseCli.js +10 -4
- package/dist/esm/node/plugin/plugins/build/pluginAutoFullBuild.js +3 -3
- package/dist/esm/node/plugin/plugins/build/pluginModuleBanner.d.ts +3 -0
- package/dist/esm/node/plugin/plugins/build/pluginModuleBanner.js +49 -0
- package/dist/esm/node/plugin/plugins/build.js +3 -1
- package/dist/esm/node/plugin/plugins/commonConfig.d.ts +9 -2
- package/dist/esm/node/plugin/plugins/commonConfig.js +16 -8
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +5 -5
- package/dist/esm/node/plugin/plugins/fileEnv.js +3 -0
- package/dist/esm/node/plugin/plugins/importUserCode/index.js +15 -11
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +5 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.d.ts +5 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +11 -12
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +11 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +101 -86
- package/dist/esm/node/plugin/plugins/setGlobalContext.js +11 -2
- package/dist/esm/node/plugin/shared/getEnvVarObject.js +7 -0
- package/dist/esm/node/prerender/resolvePrerenderConfig.js +3 -3
- package/dist/esm/node/prerender/runPrerender.d.ts +1 -1
- package/dist/esm/node/prerender/runPrerender.js +14 -19
- package/dist/esm/node/prerender/utils.d.ts +1 -1
- package/dist/esm/node/prerender/utils.js +1 -1
- package/dist/esm/node/runtime/globalContext.d.ts +2 -3
- package/dist/esm/node/runtime/globalContext.js +13 -8
- package/dist/esm/node/runtime/html/injectAssets/getViteDevScript.js +6 -3
- package/dist/esm/node/runtime/html/serializePageContextClientSide.d.ts +2 -0
- package/dist/esm/node/runtime/html/serializePageContextClientSide.js +69 -15
- package/dist/esm/node/runtime/renderPage/createHttpResponse/assertNoInfiniteHttpRedirect.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/createHttpResponse/assertNoInfiniteHttpRedirect.js +3 -2
- package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.js +3 -0
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +27 -1
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +18 -12
- package/dist/esm/node/runtime/renderPage.js +14 -29
- package/dist/esm/node/runtime/utils.d.ts +1 -1
- package/dist/esm/node/runtime/utils.js +1 -1
- package/dist/esm/node/runtime-dev/createDevMiddleware.js +2 -2
- package/dist/esm/node/shared/assertV1Design.js +1 -1
- package/dist/esm/node/shared/utils.d.ts +1 -1
- package/dist/esm/node/shared/utils.js +1 -1
- package/dist/esm/node/shared/virtual-files.d.ts +2 -0
- package/dist/esm/node/shared/virtual-files.js +14 -10
- package/dist/esm/shared/NOT_SERIALIZABLE.d.ts +1 -0
- package/dist/esm/shared/NOT_SERIALIZABLE.js +2 -0
- package/dist/esm/shared/modifyUrl.d.ts +2 -2
- package/dist/esm/shared/modifyUrl.js +3 -5
- package/dist/esm/shared/modifyUrlSameOrigin.d.ts +9 -0
- package/dist/esm/shared/modifyUrlSameOrigin.js +40 -0
- package/dist/esm/shared/page-configs/Config.d.ts +11 -3
- package/dist/esm/shared/page-configs/PageConfig.d.ts +2 -2
- package/dist/esm/shared/page-configs/getConfigDefinedAt.d.ts +3 -1
- package/dist/esm/shared/page-configs/getConfigDefinedAt.js +3 -2
- package/dist/esm/shared/page-configs/getConfigValueBuildTime.js +5 -5
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +9 -9
- package/dist/esm/shared/route/abort.d.ts +2 -2
- package/dist/esm/shared/types.d.ts +39 -3
- package/dist/esm/shared/utils.d.ts +2 -1
- package/dist/esm/shared/utils.js +2 -1
- package/dist/esm/types/index.d.ts +0 -1
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/assert.d.ts +2 -1
- package/dist/esm/utils/assert.js +10 -3
- package/dist/esm/utils/assertSetup.d.ts +2 -2
- package/dist/esm/utils/assertSetup.js +12 -8
- package/dist/esm/utils/assertSingleInstance.js +19 -4
- package/dist/esm/utils/getRandomId.d.ts +1 -1
- package/dist/esm/utils/getRandomId.js +1 -1
- package/dist/esm/utils/isNullish.d.ts +3 -0
- package/dist/esm/utils/isNullish.js +11 -0
- package/dist/esm/utils/normalizeHeaders.js +1 -1
- package/dist/esm/utils/objectAssign.d.ts +1 -1
- package/dist/esm/utils/objectAssign.js +7 -2
- package/dist/esm/utils/objectFilter.d.ts +1 -0
- package/dist/esm/utils/objectFilter.js +7 -0
- package/dist/esm/utils/pick.d.ts +1 -0
- package/dist/esm/utils/pick.js +9 -0
- package/package.json +4 -2
- package/dist/cjs/shared/notSerializable.js +0 -5
- package/dist/cjs/utils/isNotNullish.js +0 -5
- package/dist/esm/shared/notSerializable.d.ts +0 -1
- package/dist/esm/shared/notSerializable.js +0 -2
- package/dist/esm/utils/isNotNullish.d.ts +0 -1
- package/dist/esm/utils/isNotNullish.js +0 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { modifyUrl };
|
|
2
|
+
import { type ModifyUrlSameOriginOptions } from './modifyUrlSameOrigin.js';
|
|
2
3
|
/**
|
|
3
4
|
* Modify a URL.
|
|
4
5
|
*
|
|
@@ -6,8 +7,7 @@ export { modifyUrl };
|
|
|
6
7
|
*
|
|
7
8
|
* https://vike.dev/modifyUrl
|
|
8
9
|
*/
|
|
9
|
-
declare function modifyUrl(url: string, modify: {
|
|
10
|
-
pathname?: string;
|
|
10
|
+
declare function modifyUrl(url: string, modify: ModifyUrlSameOriginOptions & {
|
|
11
11
|
hostname?: string;
|
|
12
12
|
port?: number;
|
|
13
13
|
protocol?: string;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { modifyUrl };
|
|
2
|
+
import { modifyUrlSameOrigin } from './modifyUrlSameOrigin.js';
|
|
2
3
|
import { createUrlFromComponents, parseUrl } from './utils.js';
|
|
3
4
|
/**
|
|
4
5
|
* Modify a URL.
|
|
@@ -8,9 +9,8 @@ import { createUrlFromComponents, parseUrl } from './utils.js';
|
|
|
8
9
|
* https://vike.dev/modifyUrl
|
|
9
10
|
*/
|
|
10
11
|
function modifyUrl(url, modify) {
|
|
12
|
+
url = modifyUrlSameOrigin(url, modify);
|
|
11
13
|
const urlParsed = parseUrl(url, '/');
|
|
12
|
-
// Pathname
|
|
13
|
-
const pathname = modify.pathname ?? urlParsed.pathname;
|
|
14
14
|
// Origin
|
|
15
15
|
const originParts = [
|
|
16
16
|
modify.protocol ?? urlParsed.protocol ?? '',
|
|
@@ -21,8 +21,6 @@ function modifyUrl(url, modify) {
|
|
|
21
21
|
originParts.push(`:${port}`);
|
|
22
22
|
}
|
|
23
23
|
const origin = originParts.join('');
|
|
24
|
-
const urlModified = createUrlFromComponents(origin, pathname,
|
|
25
|
-
// Should we also support modifying search and hash?
|
|
26
|
-
urlParsed.searchOriginal, urlParsed.hashOriginal);
|
|
24
|
+
const urlModified = createUrlFromComponents(origin, urlParsed.pathname, urlParsed.searchOriginal, urlParsed.hashOriginal);
|
|
27
25
|
return urlModified;
|
|
28
26
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { modifyUrlSameOrigin };
|
|
2
|
+
export { ModifyUrlSameOriginOptions };
|
|
3
|
+
type ModifyUrlSameOriginOptions = {
|
|
4
|
+
hash?: string | null;
|
|
5
|
+
search?: Search | null;
|
|
6
|
+
pathname?: string;
|
|
7
|
+
};
|
|
8
|
+
type Search = Record<string, string | null> | URLSearchParams;
|
|
9
|
+
declare function modifyUrlSameOrigin(url: string, modify: ModifyUrlSameOriginOptions): string;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export { modifyUrlSameOrigin };
|
|
2
|
+
import { createUrlFromComponents, isNotNullish_keyVal, parseUrl, objectFilter, assertUsageUrlPathnameAbsolute } from './utils.js';
|
|
3
|
+
function modifyUrlSameOrigin(url, modify) {
|
|
4
|
+
const urlParsed = parseUrl(url, '/');
|
|
5
|
+
// Pathname
|
|
6
|
+
const pathname = modify.pathname ?? urlParsed.pathnameOriginal;
|
|
7
|
+
assertUsageUrlPathnameAbsolute(pathname, 'modify.pathname');
|
|
8
|
+
// Search
|
|
9
|
+
let search = modify.search === null ? '' : !modify.search ? urlParsed.searchOriginal : resolveSearch(urlParsed, modify.search);
|
|
10
|
+
if (search === '?')
|
|
11
|
+
search = '';
|
|
12
|
+
// Hash
|
|
13
|
+
let hash;
|
|
14
|
+
if (modify.hash === null) {
|
|
15
|
+
hash = '';
|
|
16
|
+
}
|
|
17
|
+
else if (modify.hash === undefined) {
|
|
18
|
+
hash = urlParsed.hashOriginal ?? '';
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
hash = modify.hash;
|
|
22
|
+
if (!hash.startsWith('#'))
|
|
23
|
+
hash = '#' + hash;
|
|
24
|
+
}
|
|
25
|
+
const urlModified = createUrlFromComponents(urlParsed.origin, pathname, search, hash);
|
|
26
|
+
return urlModified;
|
|
27
|
+
}
|
|
28
|
+
function resolveSearch(urlParsed, search) {
|
|
29
|
+
let searchParams;
|
|
30
|
+
if (search instanceof URLSearchParams) {
|
|
31
|
+
// Overwrite
|
|
32
|
+
searchParams = search;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
// Merge
|
|
36
|
+
const searchMap = objectFilter({ ...urlParsed.search, ...search }, (isNotNullish_keyVal));
|
|
37
|
+
searchParams = new URLSearchParams(searchMap);
|
|
38
|
+
}
|
|
39
|
+
return '?' + searchParams.toString();
|
|
40
|
+
}
|
|
@@ -299,13 +299,15 @@ type ConfigBuiltIn = {
|
|
|
299
299
|
/**
|
|
300
300
|
* Whether to enable pre-rendering.
|
|
301
301
|
*
|
|
302
|
-
* Setting `
|
|
302
|
+
* Setting `enable: null` enables you to set prerender settings without enabling pre-rendering by default.
|
|
303
303
|
*
|
|
304
|
-
*
|
|
304
|
+
* This is useful, for example, if you want pre-rendering to stay opt-in instead of opt-out while setting pre-render settings globally.
|
|
305
|
+
*
|
|
306
|
+
* https://vike.dev/prerender#enable
|
|
305
307
|
*
|
|
306
308
|
* @default true
|
|
307
309
|
*/
|
|
308
|
-
|
|
310
|
+
enable?: boolean | null;
|
|
309
311
|
};
|
|
310
312
|
/**
|
|
311
313
|
* Install Vike extensions.
|
|
@@ -489,6 +491,12 @@ type ConfigBuiltIn = {
|
|
|
489
491
|
* https://vike.dev/port
|
|
490
492
|
*/
|
|
491
493
|
port?: number;
|
|
494
|
+
/**
|
|
495
|
+
* Set the mode to run in.
|
|
496
|
+
*
|
|
497
|
+
* https://vike.dev/mode
|
|
498
|
+
*/
|
|
499
|
+
mode?: string;
|
|
492
500
|
/** Where scripts are injected in the HTML.
|
|
493
501
|
*
|
|
494
502
|
* https://vike.dev/injectScriptsAt
|
|
@@ -92,12 +92,12 @@ type ConfigValueSources = Record<string, // configName
|
|
|
92
92
|
ConfigValueSource[]>;
|
|
93
93
|
type ConfigValueSource = {
|
|
94
94
|
configEnv: ConfigEnvInternal;
|
|
95
|
-
|
|
95
|
+
definedAt: DefinedAtFilePath | DefinedBy;
|
|
96
96
|
plusFile: PlusFile | null;
|
|
97
97
|
locationId: LocationId;
|
|
98
98
|
/** Wether the config value is loaded at runtime, for example config.Page or config.onBeforeRender */
|
|
99
99
|
valueIsLoadedWithImport: boolean;
|
|
100
|
-
/** Whether the config value is a file path, for
|
|
100
|
+
/** Whether the config value is a file path, this is currently only true for +client */
|
|
101
101
|
valueIsFilePath?: true;
|
|
102
102
|
/** Whether the config value is defined by a +{configName}.js file */
|
|
103
103
|
valueIsDefinedByPlusValueFile: boolean;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
export { getConfigDefinedAt };
|
|
2
2
|
export { getConfigDefinedAtOptional };
|
|
3
3
|
export { getDefinedAtString };
|
|
4
|
+
export { getDefinedByString };
|
|
4
5
|
export type { ConfigDefinedAt };
|
|
5
6
|
export type { ConfigDefinedAtOptional };
|
|
6
|
-
import type { DefinedAtData } from './PageConfig.js';
|
|
7
|
+
import type { DefinedAtData, DefinedBy } from './PageConfig.js';
|
|
7
8
|
type ConfigDefinedAtOptional = ConfigDefinedAt | `Config ${string} defined internally`;
|
|
8
9
|
type ConfigDefinedAt = `Config ${string} defined at ${string}`;
|
|
9
10
|
declare function getConfigDefinedAt<SentenceBegin extends 'Config' | 'config', ConfigName extends string>(sentenceBegin: SentenceBegin, configName: ConfigName, definedAtData: NonNullable<DefinedAtData>): `${SentenceBegin} ${ConfigName} defined at ${string}`;
|
|
10
11
|
declare function getConfigDefinedAtOptional<SentenceBegin extends 'Config' | 'config', ConfigName extends string>(sentenceBegin: SentenceBegin, configName: ConfigName, definedAtData: DefinedAtData): `${SentenceBegin} ${ConfigName} defined ${'internally' | `at ${string}`}`;
|
|
11
12
|
declare function getDefinedAtString(definedAtData: NonNullable<DefinedAtData>, configName: string): string;
|
|
13
|
+
declare function getDefinedByString(definedAt: DefinedBy, configName: string): `API call dev({ vikeConfig: { ${string} } })` | `API call build({ vikeConfig: { ${string} } })` | `API call preview({ vikeConfig: { ${string} } })` | `API call prerender({ vikeConfig: { ${string} } })` | `CLI option --${string}` | `environment variable VIKE_CONFIG="{${string}}"`;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { getConfigDefinedAt };
|
|
2
2
|
export { getConfigDefinedAtOptional };
|
|
3
3
|
export { getDefinedAtString };
|
|
4
|
+
export { getDefinedByString };
|
|
4
5
|
import { assert, checkType, isArray } from '../utils.js';
|
|
5
6
|
import pc from '@brillout/picocolors';
|
|
6
7
|
import { getExportPath } from './getExportPath.js';
|
|
@@ -44,14 +45,14 @@ function getDefinedAtString(definedAtData, configName) {
|
|
|
44
45
|
}
|
|
45
46
|
function getDefinedByString(definedAt, configName) {
|
|
46
47
|
if (definedAt.definedBy === 'api') {
|
|
47
|
-
return `API call ${pc.cyan(`${definedAt.operation}({${configName}})`)}`;
|
|
48
|
+
return `API call ${pc.cyan(`${definedAt.operation}({ vikeConfig: { ${configName} } })`)}`;
|
|
48
49
|
}
|
|
49
50
|
const { definedBy } = definedAt;
|
|
50
51
|
if (definedBy === 'cli') {
|
|
51
52
|
return `CLI option ${pc.cyan(`--${configName}`)}`;
|
|
52
53
|
}
|
|
53
54
|
if (definedBy === 'env') {
|
|
54
|
-
return `environment variable ${pc.cyan(`
|
|
55
|
+
return `environment variable ${pc.cyan(`VIKE_CONFIG="{${configName}}"`)}`;
|
|
55
56
|
}
|
|
56
57
|
checkType(definedBy);
|
|
57
58
|
assert(false);
|
|
@@ -56,11 +56,11 @@ function mergeCumulative(configValueSources) {
|
|
|
56
56
|
return { value, definedAtData };
|
|
57
57
|
}
|
|
58
58
|
function getDefinedAt(configValueSource) {
|
|
59
|
-
const {
|
|
60
|
-
if (
|
|
61
|
-
return
|
|
59
|
+
const { definedAt } = configValueSource;
|
|
60
|
+
if (definedAt.definedBy)
|
|
61
|
+
return definedAt;
|
|
62
62
|
return {
|
|
63
|
-
filePathToShowToUser:
|
|
64
|
-
fileExportPathToShowToUser:
|
|
63
|
+
filePathToShowToUser: definedAt.filePathToShowToUser,
|
|
64
|
+
fileExportPathToShowToUser: definedAt.fileExportPathToShowToUser
|
|
65
65
|
};
|
|
66
66
|
}
|
|
@@ -47,7 +47,7 @@ function serializeConfigValues(pageConfig, importStatements, filesEnv, isEnvMatc
|
|
|
47
47
|
function getValueSerializedFromSource(configValueSource, configName, importStatements, filesEnv) {
|
|
48
48
|
let valueData;
|
|
49
49
|
if (configValueSource.valueIsLoaded && !configValueSource.valueIsLoadedWithImport) {
|
|
50
|
-
valueData = getValueSerializedWithJson(configValueSource.value, configName, configValueSource.
|
|
50
|
+
valueData = getValueSerializedWithJson(configValueSource.value, configName, configValueSource.definedAt, importStatements, filesEnv, configValueSource.configEnv);
|
|
51
51
|
}
|
|
52
52
|
else {
|
|
53
53
|
valueData = getValueSerializedWithImport(configValueSource, importStatements, filesEnv, configName);
|
|
@@ -98,9 +98,9 @@ function serializeConfigValue(configValueBase, valueData, configName, lines, tab
|
|
|
98
98
|
}
|
|
99
99
|
function getValueSerializedWithImport(configValueSource, importStatements, filesEnv, configName) {
|
|
100
100
|
assert(!configValueSource.valueIsFilePath);
|
|
101
|
-
const { valueIsDefinedByPlusValueFile,
|
|
102
|
-
assert(!
|
|
103
|
-
const { filePathAbsoluteVite, fileExportName } =
|
|
101
|
+
const { valueIsDefinedByPlusValueFile, definedAt, configEnv } = configValueSource;
|
|
102
|
+
assert(!definedAt.definedBy);
|
|
103
|
+
const { filePathAbsoluteVite, fileExportName } = definedAt;
|
|
104
104
|
if (valueIsDefinedByPlusValueFile)
|
|
105
105
|
assert(fileExportName === undefined);
|
|
106
106
|
const { importName } = addImportStatement(importStatements, filePathAbsoluteVite, fileExportName || '*', filesEnv, configEnv, configName);
|
|
@@ -227,12 +227,12 @@ function getConfigValuesBase(pageConfig, isEnvMatch, isEager) {
|
|
|
227
227
|
return [...fromComputed, ...fromSources].filter((r) => r !== 'SKIP');
|
|
228
228
|
}
|
|
229
229
|
function getDefinedAtFileSource(source) {
|
|
230
|
-
const {
|
|
231
|
-
if (
|
|
232
|
-
return
|
|
230
|
+
const { definedAt } = source;
|
|
231
|
+
if (definedAt.definedBy)
|
|
232
|
+
return definedAt;
|
|
233
233
|
const definedAtFile = {
|
|
234
|
-
filePathToShowToUser:
|
|
235
|
-
fileExportPathToShowToUser:
|
|
234
|
+
filePathToShowToUser: definedAt.filePathToShowToUser,
|
|
235
|
+
fileExportPathToShowToUser: definedAt.fileExportPathToShowToUser
|
|
236
236
|
};
|
|
237
237
|
return definedAtFile;
|
|
238
238
|
}
|
|
@@ -100,9 +100,9 @@ declare function logAbortErrorHandled(err: ErrorAbort, isProduction: boolean, pa
|
|
|
100
100
|
}): void;
|
|
101
101
|
type PageContextFromRewrite = {
|
|
102
102
|
_urlRewrite: string;
|
|
103
|
-
}
|
|
103
|
+
};
|
|
104
104
|
type PageContextFromAllRewrites = {
|
|
105
105
|
_urlRewrite: null | string;
|
|
106
|
-
}
|
|
106
|
+
};
|
|
107
107
|
declare function getPageContextFromAllRewrites(pageContextsFromRewrite: PageContextFromRewrite[]): PageContextFromAllRewrites;
|
|
108
108
|
declare function assertNoInfiniteAbortLoop(rewriteCount: number, redirectCount: number): void;
|
|
@@ -138,8 +138,27 @@ type PageContextBuiltInCommon<Data> = {
|
|
|
138
138
|
*/
|
|
139
139
|
isBaseMissing?: true;
|
|
140
140
|
};
|
|
141
|
-
type PageContextBuiltInServer<Data> = PageContextBuiltInCommon<Data> & PageContextUrlServer
|
|
142
|
-
|
|
141
|
+
type PageContextBuiltInServer<Data> = PageContextBuiltInCommon<Data> & PageContextUrlServer & {
|
|
142
|
+
/**
|
|
143
|
+
* Whether the page is being rendered on the client-side, or rendered on the server-side / pre-rendered.
|
|
144
|
+
*
|
|
145
|
+
* In order to save client-side KBs, we recommend using `import.meta.env.SSR` whenever possible instead, see https://vike.dev/pageContext
|
|
146
|
+
*/
|
|
147
|
+
isClientSide: false;
|
|
148
|
+
/**
|
|
149
|
+
* Whether the page is being pre-rendered.
|
|
150
|
+
*
|
|
151
|
+
* The value is always `false` in development.
|
|
152
|
+
*
|
|
153
|
+
* https://vike.dev/pre-rendering
|
|
154
|
+
* https://vike.dev/pageContext
|
|
155
|
+
*/
|
|
156
|
+
isPrerendering: boolean;
|
|
157
|
+
isHydration?: undefined;
|
|
158
|
+
isBackwardNavigation?: undefined;
|
|
159
|
+
previousPageContext?: undefined;
|
|
160
|
+
};
|
|
161
|
+
type PageContextBuiltInClientWithClientRouting<Data> = Partial<PageContextBuiltInCommon<Data>> & Pick<PageContextBuiltInCommon<Data>, 'Page' | 'routeParams' | 'pageExports' | 'config' | 'configEntries' | 'exports' | 'exportsAll' | 'abortReason' | 'data' | 'pageId' | 'source' | 'sources' | 'from'> & PageContextClientCommon & {
|
|
143
162
|
/** Whether the current page is already rendered to HTML */
|
|
144
163
|
isHydration: boolean;
|
|
145
164
|
/**
|
|
@@ -155,7 +174,7 @@ type PageContextBuiltInClientWithClientRouting<Data> = Partial<PageContextBuiltI
|
|
|
155
174
|
*/
|
|
156
175
|
previousPageContext: PageContextClient<Data> | null;
|
|
157
176
|
} & PageContextUrlClient;
|
|
158
|
-
type PageContextBuiltInClientWithServerRouting<Data> = Partial<PageContextBuiltInCommon<Data>> & Pick<PageContextBuiltInCommon<Data>, 'Page' | 'pageExports' | 'exports' | 'abortReason' | 'pageId' | 'data'> & {
|
|
177
|
+
type PageContextBuiltInClientWithServerRouting<Data> = Partial<PageContextBuiltInCommon<Data>> & Pick<PageContextBuiltInCommon<Data>, 'Page' | 'pageExports' | 'exports' | 'abortReason' | 'pageId' | 'data'> & PageContextClientCommon & {
|
|
159
178
|
/**
|
|
160
179
|
* Whether the current page is already rendered to HTML.
|
|
161
180
|
*
|
|
@@ -169,6 +188,23 @@ type PageContextBuiltInClientWithServerRouting<Data> = Partial<PageContextBuiltI
|
|
|
169
188
|
*/
|
|
170
189
|
isBackwardNavigation: null;
|
|
171
190
|
};
|
|
191
|
+
type PageContextClientCommon = {
|
|
192
|
+
/**
|
|
193
|
+
* Whether the page is being rendered on the client-side, or rendered on the server-side / pre-rendered.
|
|
194
|
+
*
|
|
195
|
+
* In order to save client-side KBs, we recommend using `import.meta.env.SSR` whenever possible instead, see https://vike.dev/pageContext
|
|
196
|
+
*/
|
|
197
|
+
isClientSide: true;
|
|
198
|
+
/**
|
|
199
|
+
* Whether the page is being pre-rendered.
|
|
200
|
+
*
|
|
201
|
+
* The value is always `false` in development.
|
|
202
|
+
*
|
|
203
|
+
* https://vike.dev/pre-rendering
|
|
204
|
+
* https://vike.dev/pageContext
|
|
205
|
+
*/
|
|
206
|
+
isPrerendering: false;
|
|
207
|
+
};
|
|
172
208
|
/** For Vike internal use */
|
|
173
209
|
type PageContextBuiltInServerInternal = Omit<PageContextBuiltInCommon<unknown> & PageContextUrlInternal, 'data'>;
|
|
174
210
|
/** @deprecated
|
|
@@ -10,7 +10,7 @@ export * from '../utils/isBrowser.js';
|
|
|
10
10
|
export * from '../utils/hasProp.js';
|
|
11
11
|
export * from '../utils/isPlainObject.js';
|
|
12
12
|
export * from '../utils/compareString.js';
|
|
13
|
-
export * from '../utils/
|
|
13
|
+
export * from '../utils/isNullish.js';
|
|
14
14
|
export * from '../utils/stringifyStringArray.js';
|
|
15
15
|
export * from '../utils/cast.js';
|
|
16
16
|
export * from '../utils/isPropertyGetter.js';
|
|
@@ -22,3 +22,4 @@ export * from '../utils/isArray.js';
|
|
|
22
22
|
export * from '../utils/changeEnumerable.js';
|
|
23
23
|
export * from '../utils/objectDefineProperty.js';
|
|
24
24
|
export * from '../utils/isScriptFile.js';
|
|
25
|
+
export * from '../utils/objectFilter.js';
|
package/dist/esm/shared/utils.js
CHANGED
|
@@ -14,7 +14,7 @@ export * from '../utils/isBrowser.js';
|
|
|
14
14
|
export * from '../utils/hasProp.js';
|
|
15
15
|
export * from '../utils/isPlainObject.js';
|
|
16
16
|
export * from '../utils/compareString.js';
|
|
17
|
-
export * from '../utils/
|
|
17
|
+
export * from '../utils/isNullish.js';
|
|
18
18
|
export * from '../utils/stringifyStringArray.js';
|
|
19
19
|
export * from '../utils/cast.js';
|
|
20
20
|
export * from '../utils/isPropertyGetter.js';
|
|
@@ -26,3 +26,4 @@ export * from '../utils/isArray.js';
|
|
|
26
26
|
export * from '../utils/changeEnumerable.js';
|
|
27
27
|
export * from '../utils/objectDefineProperty.js';
|
|
28
28
|
export * from '../utils/isScriptFile.js';
|
|
29
|
+
export * from '../utils/objectFilter.js';
|
|
@@ -3,7 +3,6 @@ export type { PageContextServer } from '../shared/types.js';
|
|
|
3
3
|
export type { PageContextClient } from '../shared/types.js';
|
|
4
4
|
export type { PageContextWithServerRouting } from '../shared/types.js';
|
|
5
5
|
export type { PageContextClientWithServerRouting } from '../shared/types.js';
|
|
6
|
-
export type { ConfigVitePluginServerEntry } from '@brillout/vite-plugin-server-entry/plugin';
|
|
7
6
|
export type { PageContextBuiltInServer } from '../shared/types.js';
|
|
8
7
|
export type { PageContextBuiltInClientWithClientRouting } from '../shared/types.js';
|
|
9
8
|
export type { PageContextBuiltInClientWithServerRouting } from '../shared/types.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.226-commit-a0035ee";
|
|
@@ -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.226-commit-a0035ee';
|
|
@@ -10,8 +10,9 @@ export { isBug };
|
|
|
10
10
|
export { setAlwaysShowStackTrace };
|
|
11
11
|
type Logger = (msg: string | Error, logType: 'warn' | 'info') => void;
|
|
12
12
|
declare function assert(condition: unknown, debugInfo?: unknown): asserts condition;
|
|
13
|
-
declare function assertUsage(condition: unknown, errMsg: string, { showStackTrace }?: {
|
|
13
|
+
declare function assertUsage(condition: unknown, errMsg: string, { showStackTrace, exitOnError }?: {
|
|
14
14
|
showStackTrace?: true;
|
|
15
|
+
exitOnError?: boolean;
|
|
15
16
|
}): asserts condition;
|
|
16
17
|
declare function getProjectError(errMsg: string): Error;
|
|
17
18
|
declare function assertWarning(condition: unknown, msg: string, { onlyOnce, showStackTrace }: {
|
package/dist/esm/utils/assert.js
CHANGED
|
@@ -42,7 +42,7 @@ function assert(condition, debugInfo) {
|
|
|
42
42
|
const debugInfoSerialized = typeof debugInfo === 'string' ? debugInfo : JSON.stringify(debugInfo);
|
|
43
43
|
return pc.dim(`Debug info (for Vike maintainers; you can ignore this): ${debugInfoSerialized}`);
|
|
44
44
|
})();
|
|
45
|
-
const link = pc.
|
|
45
|
+
const link = pc.underline('https://github.com/vikejs/vike/issues/new?template=bug.yml');
|
|
46
46
|
let errMsg = [
|
|
47
47
|
`You stumbled upon a Vike bug. Go to ${link} and copy-paste this error. A maintainer will fix the bug (usually within 24 hours).`,
|
|
48
48
|
debugStr
|
|
@@ -56,7 +56,7 @@ function assert(condition, debugInfo) {
|
|
|
56
56
|
globalObject.onBeforeLog?.();
|
|
57
57
|
throw internalError;
|
|
58
58
|
}
|
|
59
|
-
function assertUsage(condition, errMsg, { showStackTrace } = {}) {
|
|
59
|
+
function assertUsage(condition, errMsg, { showStackTrace, exitOnError } = {}) {
|
|
60
60
|
if (condition)
|
|
61
61
|
return;
|
|
62
62
|
showStackTrace = showStackTrace || globalObject.alwaysShowStackTrace;
|
|
@@ -68,7 +68,13 @@ function assertUsage(condition, errMsg, { showStackTrace } = {}) {
|
|
|
68
68
|
globalObject.showStackTraceList.add(usageError);
|
|
69
69
|
}
|
|
70
70
|
globalObject.onBeforeLog?.();
|
|
71
|
-
|
|
71
|
+
if (!exitOnError) {
|
|
72
|
+
throw usageError;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
console.error(showStackTrace ? usageError : errMsg);
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
72
78
|
}
|
|
73
79
|
function getProjectError(errMsg) {
|
|
74
80
|
errMsg = addWhitespace(errMsg);
|
|
@@ -182,6 +188,7 @@ function overwriteAssertProductionLogger(logger) {
|
|
|
182
188
|
function isBug(err) {
|
|
183
189
|
return String(err).includes(`[${bugTag}]`);
|
|
184
190
|
}
|
|
191
|
+
// Called upon `DEBUG=vike:error`
|
|
185
192
|
function setAlwaysShowStackTrace() {
|
|
186
193
|
globalObject.alwaysShowStackTrace = true;
|
|
187
194
|
}
|
|
@@ -2,19 +2,19 @@ export { assertIsNotProductionRuntime };
|
|
|
2
2
|
export { onSetupRuntime };
|
|
3
3
|
export { onSetupBuild };
|
|
4
4
|
export { onSetupPrerender };
|
|
5
|
+
export { onSetupPreview };
|
|
5
6
|
export { setNodeEnvProduction };
|
|
6
7
|
export { markSetup_viteDevServer };
|
|
7
8
|
export { markSetup_vitePreviewServer };
|
|
8
9
|
export { markSetup_vikeVitePlugin };
|
|
9
10
|
export { markSetup_isViteDev };
|
|
10
|
-
export { markSetup_isPrerendering };
|
|
11
11
|
declare function assertIsNotProductionRuntime(): void | undefined;
|
|
12
12
|
declare function onSetupRuntime(): void | undefined;
|
|
13
13
|
declare function onSetupBuild(): void;
|
|
14
14
|
declare function onSetupPrerender(): void;
|
|
15
|
+
declare function onSetupPreview(): void;
|
|
15
16
|
declare function markSetup_viteDevServer(): void | undefined;
|
|
16
17
|
declare function markSetup_vitePreviewServer(): void | undefined;
|
|
17
18
|
declare function markSetup_vikeVitePlugin(): void;
|
|
18
19
|
declare function markSetup_isViteDev(isViteDev: boolean): void;
|
|
19
|
-
declare function markSetup_isPrerendering(): void;
|
|
20
20
|
declare function setNodeEnvProduction(): void | undefined;
|
|
@@ -2,12 +2,12 @@ export { assertIsNotProductionRuntime };
|
|
|
2
2
|
export { onSetupRuntime };
|
|
3
3
|
export { onSetupBuild };
|
|
4
4
|
export { onSetupPrerender };
|
|
5
|
+
export { onSetupPreview };
|
|
5
6
|
export { setNodeEnvProduction };
|
|
6
7
|
export { markSetup_viteDevServer };
|
|
7
8
|
export { markSetup_vitePreviewServer };
|
|
8
9
|
export { markSetup_vikeVitePlugin };
|
|
9
10
|
export { markSetup_isViteDev };
|
|
10
|
-
export { markSetup_isPrerendering };
|
|
11
11
|
import { assert, assertUsage, assertWarning } from './assert.js';
|
|
12
12
|
import { assertIsNotBrowser } from './assertIsNotBrowser.js';
|
|
13
13
|
import { createDebugger } from './debug.js';
|
|
@@ -29,7 +29,7 @@ function onSetupRuntime() {
|
|
|
29
29
|
if (isTest())
|
|
30
30
|
return;
|
|
31
31
|
assertNodeEnvIsNotUndefinedString();
|
|
32
|
-
if (!
|
|
32
|
+
if (!setup.viteDevServer && setup.isViteDev === undefined) {
|
|
33
33
|
// TODO: make it assertUsage() again once https://github.com/vikejs/vike/issues/1528 is implemented.
|
|
34
34
|
assertWarning(!isNodeEnvDev(), `The ${getEnvDescription()}, which is contradictory because the environment seems to be a production environment (Vite isn't loaded), see https://vike.dev/NODE_ENV`, { onlyOnce: true });
|
|
35
35
|
assertUsage(!setup.vikeVitePlugin, `Loading Vike's Vite plugin (the ${pc.cyan('vike/plugin')} module) is prohibited in production.`);
|
|
@@ -37,11 +37,10 @@ function onSetupRuntime() {
|
|
|
37
37
|
assert(!setup.shouldNotBeProduction);
|
|
38
38
|
}
|
|
39
39
|
else {
|
|
40
|
-
if (!setup.vitePreviewServer && !setup.isPrerendering) {
|
|
40
|
+
if (!setup.isPreview && !setup.vitePreviewServer && !setup.isPrerendering) {
|
|
41
41
|
// TODO: make it assertUsage() again once https://github.com/vikejs/vike/issues/1528 is implemented.
|
|
42
42
|
assertWarning(isNodeEnvDev(), `The ${getEnvDescription()}, but Vite is loaded which is prohibited in production, see https://vike.dev/NODE_ENV`, { onlyOnce: true });
|
|
43
43
|
}
|
|
44
|
-
// These two assert() calls aren't that interesting
|
|
45
44
|
assert(setup.vikeVitePlugin);
|
|
46
45
|
assert(setup.shouldNotBeProduction);
|
|
47
46
|
}
|
|
@@ -58,15 +57,16 @@ function onSetupBuild() {
|
|
|
58
57
|
setNodeEnvProduction()
|
|
59
58
|
*/
|
|
60
59
|
}
|
|
60
|
+
// Called by ../node/prerender/runPrerender.ts
|
|
61
61
|
function onSetupPrerender() {
|
|
62
62
|
markSetup_isPrerendering();
|
|
63
63
|
if (getNodeEnv())
|
|
64
64
|
assertUsageNodeEnvIsNotDev('pre-rendering');
|
|
65
65
|
setNodeEnvProduction();
|
|
66
66
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
// Called by ../node/api/preview.ts
|
|
68
|
+
function onSetupPreview() {
|
|
69
|
+
markSetup_isPreview();
|
|
70
70
|
}
|
|
71
71
|
function isTest() {
|
|
72
72
|
return isVitest() || isNodeEnv('test');
|
|
@@ -95,12 +95,16 @@ function markSetup_isViteDev(isViteDev) {
|
|
|
95
95
|
debug('markSetup_isViteDev()', new Error().stack);
|
|
96
96
|
setup.isViteDev = isViteDev;
|
|
97
97
|
}
|
|
98
|
-
// Called by ../node/prerender/runPrerender.ts
|
|
99
98
|
function markSetup_isPrerendering() {
|
|
100
99
|
if (debug.isActivated)
|
|
101
100
|
debug('markSetup_isPrerendering()', new Error().stack);
|
|
102
101
|
setup.isPrerendering = true;
|
|
103
102
|
}
|
|
103
|
+
function markSetup_isPreview() {
|
|
104
|
+
if (debug.isActivated)
|
|
105
|
+
debug('markSetup_isPreview()', new Error().stack);
|
|
106
|
+
setup.isPreview = true;
|
|
107
|
+
}
|
|
104
108
|
function assertUsageNodeEnvIsNotDev(operation) {
|
|
105
109
|
if (!isNodeEnvDev())
|
|
106
110
|
return;
|
|
@@ -11,13 +11,24 @@ import { PROJECT_VERSION } from './PROJECT_VERSION.js';
|
|
|
11
11
|
/* Use original assertWarning() after all CJS is removed from node_modules/vike/dist/
|
|
12
12
|
import { assertWarning } from './assert.js'
|
|
13
13
|
*/
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
let globalObject;
|
|
15
|
+
// getGlobalObjectSafe() can be called before this line
|
|
16
|
+
globalObject ?? (globalObject = genGlobalConfig());
|
|
17
|
+
function genGlobalConfig() {
|
|
18
|
+
return getGlobalObject('utils/assertSingleInstance.ts', {
|
|
19
|
+
instances: [],
|
|
20
|
+
alreadyLogged: new Set()
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
// We need getGlobalObjectSafe() because globalObject is `undefined` when exported functions are called before globalObject is initialized
|
|
24
|
+
function getGlobalObjectSafe() {
|
|
25
|
+
globalObject ?? (globalObject = genGlobalConfig());
|
|
26
|
+
return globalObject;
|
|
27
|
+
}
|
|
18
28
|
const clientRuntimesClonflict = 'Client runtime of both Server Routing and Client Routing loaded https://vike.dev/client-runtimes-conflict';
|
|
19
29
|
const clientNotSingleInstance = 'Client runtime loaded twice https://vike.dev/client-runtime-duplicated';
|
|
20
30
|
function assertSingleInstance() {
|
|
31
|
+
const globalObject = getGlobalObjectSafe();
|
|
21
32
|
{
|
|
22
33
|
const versions = unique(globalObject.instances);
|
|
23
34
|
assertWarning(versions.length <= 1,
|
|
@@ -34,6 +45,7 @@ function assertSingleInstance() {
|
|
|
34
45
|
}
|
|
35
46
|
}
|
|
36
47
|
function assertSingleInstance_onClientEntryServerRouting(isProduction) {
|
|
48
|
+
const globalObject = getGlobalObjectSafe();
|
|
37
49
|
assertWarning(globalObject.isClientRouting !== true, clientRuntimesClonflict, {
|
|
38
50
|
onlyOnce: true,
|
|
39
51
|
showStackTrace: true
|
|
@@ -48,6 +60,7 @@ function assertSingleInstance_onClientEntryServerRouting(isProduction) {
|
|
|
48
60
|
assertSingleInstance();
|
|
49
61
|
}
|
|
50
62
|
function assertSingleInstance_onClientEntryClientRouting(isProduction) {
|
|
63
|
+
const globalObject = getGlobalObjectSafe();
|
|
51
64
|
assertWarning(globalObject.isClientRouting !== false, clientRuntimesClonflict, {
|
|
52
65
|
onlyOnce: true,
|
|
53
66
|
showStackTrace: true
|
|
@@ -63,10 +76,12 @@ function assertSingleInstance_onClientEntryClientRouting(isProduction) {
|
|
|
63
76
|
}
|
|
64
77
|
// Called by utils/assert.ts which is (most certainly) loaded by all entries. That way we don't have to call a callback for every entry. (There are a lot of entries: `client/router/`, `client/`, `node/runtime/`, `node/plugin/`, `node/cli`.)
|
|
65
78
|
function assertSingleInstance_onAssertModuleLoad() {
|
|
79
|
+
const globalObject = getGlobalObjectSafe();
|
|
66
80
|
globalObject.instances.push(PROJECT_VERSION);
|
|
67
81
|
assertSingleInstance();
|
|
68
82
|
}
|
|
69
83
|
function assertWarning(condition, errorMessage, { onlyOnce, showStackTrace }) {
|
|
84
|
+
const globalObject = getGlobalObjectSafe();
|
|
70
85
|
if (condition) {
|
|
71
86
|
return;
|
|
72
87
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { getRandomId };
|
|
2
|
-
declare function getRandomId(length
|
|
2
|
+
declare function getRandomId(length?: number): string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { getRandomId };
|
|
2
2
|
import { assert } from './assert.js';
|
|
3
3
|
// https://stackoverflow.com/questions/1349404/generate-random-string-characters-in-javascript
|
|
4
|
-
function getRandomId(length) {
|
|
4
|
+
function getRandomId(length = 12) {
|
|
5
5
|
let randomId = '';
|
|
6
6
|
while (randomId.length < length) {
|
|
7
7
|
randomId += Math.random().toString(36).slice(2);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function isNullish(val) {
|
|
2
|
+
return val === null || val === undefined;
|
|
3
|
+
}
|
|
4
|
+
// someArray.filter(isNotNullish)
|
|
5
|
+
export function isNotNullish(p) {
|
|
6
|
+
return !isNullish(p);
|
|
7
|
+
}
|
|
8
|
+
// objectFilter(obj).filter(isNotNullish_keyVal)
|
|
9
|
+
export function isNotNullish_keyVal(arg) {
|
|
10
|
+
return !isNullish(arg[1]);
|
|
11
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { normalizeHeaders };
|
|
2
2
|
import { isObject } from './isObject.js';
|
|
3
3
|
function normalizeHeaders(
|
|
4
|
-
/* This type is
|
|
4
|
+
/* This type is too strict which is annoying: cannot pass `string[][]` because it doesn't match the more precise type `[string,string][]`.
|
|
5
5
|
headersOriginal ConstructorParameters<typeof Headers>[0]
|
|
6
6
|
*/
|
|
7
7
|
headersOriginal) {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { objectAssign };
|
|
2
|
-
declare function objectAssign<Obj extends object, ObjAddendum extends object | null>(obj: Obj, objAddendum: ObjAddendum): asserts obj is Obj & ObjAddendum;
|
|
2
|
+
declare function objectAssign<Obj extends object, ObjAddendum extends object | null>(obj: Obj, objAddendum: ObjAddendum, objAddendumCanBePageContextObject?: true): asserts obj is Obj & ObjAddendum;
|
|
@@ -3,9 +3,14 @@ import { assert } from './assert.js';
|
|
|
3
3
|
// Same as Object.assign() but:
|
|
4
4
|
// - With type inference
|
|
5
5
|
// - Preserves property descriptors, which we need for preserving the getters added by getPageContextUrlComputed()
|
|
6
|
-
function objectAssign(obj, objAddendum) {
|
|
6
|
+
function objectAssign(obj, objAddendum, objAddendumCanBePageContextObject) {
|
|
7
7
|
if (objAddendum) {
|
|
8
|
-
|
|
8
|
+
if (!objAddendumCanBePageContextObject) {
|
|
9
|
+
// We only need this assert() in the rare case when the user is expected to mutate `pageContext` after the Vike hook was executed (and its promise resolved).
|
|
10
|
+
// - The only use case I can think of is the user mutating `pageContext` after the onRenderClient() promise resolved (which can happen when client-side rendering finishes after onRenderClient() resolves). In that case, having Vike await async Vike hooks isn't enough.
|
|
11
|
+
// - IIRC this assert() was mostly needed for preserving the getters added by getPageContextUrlComputed() but we don't need this anymore.
|
|
12
|
+
assert(!('_isPageContextObject' in objAddendum));
|
|
13
|
+
}
|
|
9
14
|
Object.defineProperties(obj, Object.getOwnPropertyDescriptors(objAddendum));
|
|
10
15
|
}
|
|
11
16
|
}
|