vike 0.4.252-commit-4fa40ed → 0.4.253-commit-1658209
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 -0
- package/dist/node/prerender/runPrerender.d.ts +3 -1
- package/dist/node/vite/plugins/pluginReplaceConstantsEnvVars.js +20 -3
- package/dist/node/vite/plugins/pluginReplaceConstantsGlobalThis.d.ts +2 -0
- package/dist/node/vite/plugins/pluginReplaceConstantsGlobalThis.js +1 -0
- package/dist/server/runtime/renderPageServer/addErrorHint.js +2 -1
- package/dist/server/runtime/renderPageServer/createPageContextServer.d.ts +6 -2
- package/dist/server/runtime/renderPageServer/loadPageConfigsLazyServerSide.d.ts +3 -1
- package/dist/server/runtime/renderPageServer/renderPageServerAfterRoute.d.ts +12 -4
- package/dist/server/runtime/renderPageServer.d.ts +3 -1
- package/dist/shared-server-client/route/abort.js +1 -4
- package/dist/types/PageContext.d.ts +2 -1
- package/dist/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/utils/PROJECT_VERSION.js +1 -1
- package/package.json +1 -1
|
@@ -202,6 +202,8 @@ declare function getPageContextFromHooksClient_firstRender(pageContext: PageCont
|
|
|
202
202
|
}, "exports" | "pageId" | "config" | "Page" | "data" | "source" | "sources" | "from" | "configEntries" | "exportsAll" | "pageExports" | "routeParams" | "abortReason"> & {
|
|
203
203
|
isClientSide: true;
|
|
204
204
|
isPrerendering: false;
|
|
205
|
+
cspNonce?: undefined;
|
|
206
|
+
headers?: undefined;
|
|
205
207
|
} & {
|
|
206
208
|
urlOriginal: string;
|
|
207
209
|
isHydration: boolean;
|
|
@@ -263,6 +265,8 @@ declare function getPageContextFromHooksClient_firstRender(pageContext: PageCont
|
|
|
263
265
|
}, "exports" | "pageId" | "config" | "Page" | "data" | "source" | "sources" | "from" | "configEntries" | "exportsAll" | "pageExports" | "routeParams" | "abortReason"> & {
|
|
264
266
|
isClientSide: true;
|
|
265
267
|
isPrerendering: false;
|
|
268
|
+
cspNonce?: undefined;
|
|
269
|
+
headers?: undefined;
|
|
266
270
|
} & {
|
|
267
271
|
urlOriginal: string;
|
|
268
272
|
isHydration: boolean;
|
|
@@ -484,6 +488,8 @@ declare function getPageContextFromHooksClient(pageContext: {
|
|
|
484
488
|
}, "exports" | "pageId" | "config" | "Page" | "data" | "source" | "sources" | "from" | "configEntries" | "exportsAll" | "pageExports" | "routeParams" | "abortReason"> & {
|
|
485
489
|
isClientSide: true;
|
|
486
490
|
isPrerendering: false;
|
|
491
|
+
cspNonce?: undefined;
|
|
492
|
+
headers?: undefined;
|
|
487
493
|
} & {
|
|
488
494
|
urlOriginal: string;
|
|
489
495
|
isHydration: boolean;
|
|
@@ -543,6 +549,8 @@ declare function getPageContextFromHooksClient(pageContext: {
|
|
|
543
549
|
}, "exports" | "pageId" | "config" | "Page" | "data" | "source" | "sources" | "from" | "configEntries" | "exportsAll" | "pageExports" | "routeParams" | "abortReason"> & {
|
|
544
550
|
isClientSide: true;
|
|
545
551
|
isPrerendering: false;
|
|
552
|
+
cspNonce?: undefined;
|
|
553
|
+
headers?: undefined;
|
|
546
554
|
} & {
|
|
547
555
|
urlOriginal: string;
|
|
548
556
|
isHydration: boolean;
|
|
@@ -167,7 +167,9 @@ declare function createPageContextPrerendering(urlOriginal: string, prerenderCon
|
|
|
167
167
|
_pageFilesAll: PageFile[];
|
|
168
168
|
_baseServer: string;
|
|
169
169
|
_baseAssets: string;
|
|
170
|
-
_pageContextInit: import("../../types/PageContext.js").PageContextInit
|
|
170
|
+
_pageContextInit: import("../../types/PageContext.js").PageContextInit & {
|
|
171
|
+
headers?: Record<string, unknown>;
|
|
172
|
+
};
|
|
171
173
|
_urlHandler: ((url: string) => string) | null;
|
|
172
174
|
isClientSideNavigation: boolean;
|
|
173
175
|
} & {
|
|
@@ -5,12 +5,13 @@ import { escapeRegex } from '../../../utils/escapeRegex.js';
|
|
|
5
5
|
import { isNotNullish } from '../../../utils/isNullish.js';
|
|
6
6
|
import { assert, assertUsage, assertWarning } from '../../../utils/assert.js';
|
|
7
7
|
import { isArray } from '../../../utils/isArray.js';
|
|
8
|
-
import {
|
|
8
|
+
import { makeLast } from '../../../utils/sorter.js';
|
|
9
9
|
import { assertPosixPath } from '../../../utils/path.js';
|
|
10
10
|
import { getFilePathToShowToUserModule } from '../shared/getFilePath.js';
|
|
11
11
|
import { normalizeId } from '../shared/normalizeId.js';
|
|
12
12
|
import { isViteServerSide_extraSafe } from '../shared/isViteServerSide.js';
|
|
13
13
|
import { getMagicString } from '../shared/getMagicString.js';
|
|
14
|
+
import pc from '@brillout/picocolors';
|
|
14
15
|
const PUBLIC_ENV_PREFIX = 'PUBLIC_ENV__';
|
|
15
16
|
const PUBLIC_ENV_ALLOWLIST = [
|
|
16
17
|
// https://github.com/vikejs/vike/issues/1724
|
|
@@ -23,7 +24,7 @@ const PUBLIC_ENV_ALLOWLIST = [
|
|
|
23
24
|
// - For it to work, we'll probably need the user to define the settings (e.g. `envDir`) for loadEnv() inside vike.config.js instead of vite.config.js
|
|
24
25
|
// - Or stop using Vite's `mode` implementation and have Vike implement its own `mode` feature? (So that the only dependencies are `$ vike build --mode staging` and `$ MODE=staging vike build`.)
|
|
25
26
|
// === Rolldown filter
|
|
26
|
-
const skipIrrelevant = 'import.meta.env
|
|
27
|
+
const skipIrrelevant = 'import.meta.env';
|
|
27
28
|
const filterRolldown = {
|
|
28
29
|
/* We don't do that, because vike-react-sentry uses import.meta.env.PUBLIC_ENV__SENTRY_DSN
|
|
29
30
|
id: {
|
|
@@ -47,6 +48,11 @@ function pluginReplaceConstantsEnvVars() {
|
|
|
47
48
|
return [
|
|
48
49
|
{
|
|
49
50
|
name: 'vike:pluginReplaceConstantsEnvVars',
|
|
51
|
+
// Correct order:
|
|
52
|
+
// 1. @vitejs/plugin-vue
|
|
53
|
+
// 2. vike:pluginExtractAssets and vike:pluginExtractExportNames [needs to be applied after @vitejs/plugin-vue]
|
|
54
|
+
// 3. vike:pluginReplaceConstantsEnvVars [needs to be applied after vike:pluginExtractAssets and vike:pluginExtractExportNames]
|
|
55
|
+
// 4. vite:define (Vite built-in plugin) [needs to be applied after vike:pluginReplaceConstantsEnvVars]
|
|
50
56
|
enforce: 'post',
|
|
51
57
|
configResolved: {
|
|
52
58
|
handler(config_) {
|
|
@@ -55,7 +61,7 @@ function pluginReplaceConstantsEnvVars() {
|
|
|
55
61
|
// Add process.env values defined by .env files
|
|
56
62
|
Object.entries(envVarsAll).forEach(([key, val]) => { var _a; return ((_a = process.env)[key] ?? (_a[key] = val)); });
|
|
57
63
|
envPrefix = getEnvPrefix(config);
|
|
58
|
-
config.plugins.sort(
|
|
64
|
+
config.plugins.sort(makeLast((plugin) => plugin.name === 'vite:define'));
|
|
59
65
|
},
|
|
60
66
|
},
|
|
61
67
|
transform: {
|
|
@@ -97,6 +103,17 @@ function pluginReplaceConstantsEnvVars() {
|
|
|
97
103
|
replacements.forEach(({ regExpStr, replacement }) => {
|
|
98
104
|
magicString.replaceAll(new RegExp(regExpStr, 'g'), JSON.stringify(replacement));
|
|
99
105
|
});
|
|
106
|
+
// Replace bare `import.meta.env` expression with `null` in the user-land.
|
|
107
|
+
// - Otherwise Vite replaces it with an object missing PUBLIC_ENV__ variables which is confusing for users.
|
|
108
|
+
// - We purposely don't support replacing `import.meta.env` with an object to incentivize users to write tree-shaking friendly code.
|
|
109
|
+
// - `define: { 'import.meta.env': JSON.stringify(null) }` doesn't work because it also replaces `import.meta.env` inside `import.meta.env.SONE_ENV`
|
|
110
|
+
const bareImportMetaEnvRegex = /\bimport\.meta\.env(?!\.)/g;
|
|
111
|
+
const isUserLand = !id.includes('node_modules') && id.startsWith(config.root); // skip node_modules/ as well as linked dependencies
|
|
112
|
+
if (isUserLand && bareImportMetaEnvRegex.test(code)) {
|
|
113
|
+
assertWarning(false, `The bare ${pc.cyan('import.meta.env')} expression in ${getFilePathToShowToUserModule(id, config)} is replaced with ${pc.cyan('null')} — use ${pc.cyan('import.meta.env.SONE_ENV')} instead ${pc.underline('https://vike.dev/env')}`, { onlyOnce: true });
|
|
114
|
+
bareImportMetaEnvRegex.lastIndex = 0; // Reset state after .test() since the /g flag makes the RegExp stateful
|
|
115
|
+
magicString.replaceAll(bareImportMetaEnvRegex, JSON.stringify(null));
|
|
116
|
+
}
|
|
100
117
|
return getMagicStringResult();
|
|
101
118
|
},
|
|
102
119
|
},
|
|
@@ -9,6 +9,8 @@ declare global {
|
|
|
9
9
|
/** Like `import.meta.env.SSR` but works for `node_modules/` packages with `ssr.external` */
|
|
10
10
|
var __VIKE__IS_CLIENT: boolean;
|
|
11
11
|
var __VIKE__IS_DEBUG: boolean;
|
|
12
|
+
/** Whether the code is processed by Vite, e.g. `true` when server code is `ssr.noExternal` */
|
|
13
|
+
var __VIKE__NO_EXTERNAL: true | undefined;
|
|
12
14
|
}
|
|
13
15
|
declare const VIRTUAL_FILE_ID_constantsGlobalThis = "virtual:vike:server:constantsGlobalThis";
|
|
14
16
|
declare function pluginReplaceConstantsGlobalThis(): Plugin[];
|
|
@@ -91,7 +91,8 @@ function addErrorHint(error) {
|
|
|
91
91
|
const hint = getErrorHint(error);
|
|
92
92
|
if (!hint)
|
|
93
93
|
return error;
|
|
94
|
-
const
|
|
94
|
+
const color = hint === hintDefault ? pc.gray : pc.bold;
|
|
95
|
+
const append = `\n${color(formatHintLog(hint))}`;
|
|
95
96
|
return getBetterError(error, { message: { append } });
|
|
96
97
|
}
|
|
97
98
|
function getErrorHint(error) {
|
|
@@ -6,7 +6,9 @@ export type { PageContextCreatedServerWithoutGlobalContext };
|
|
|
6
6
|
import type { GlobalContextServerInternal } from '../globalContext.js';
|
|
7
7
|
import type { PageContextInit } from '../renderPageServer.js';
|
|
8
8
|
type PageContextCreatedServer = Awaited<ReturnType<typeof createPageContextServer>>;
|
|
9
|
-
declare function createPageContextServer(pageContextInit: PageContextInit
|
|
9
|
+
declare function createPageContextServer(pageContextInit: PageContextInit & {
|
|
10
|
+
headers?: Record<string, unknown>;
|
|
11
|
+
}, globalContext: GlobalContextServerInternal, args: {
|
|
10
12
|
requestId: number;
|
|
11
13
|
} & ({
|
|
12
14
|
isPrerendering: true;
|
|
@@ -116,7 +118,9 @@ declare function createPageContextServer(pageContextInit: PageContextInit, globa
|
|
|
116
118
|
_pageFilesAll: import("../../__internal/index.js").PageFile[];
|
|
117
119
|
_baseServer: string;
|
|
118
120
|
_baseAssets: string;
|
|
119
|
-
_pageContextInit: PageContextInit
|
|
121
|
+
_pageContextInit: PageContextInit & {
|
|
122
|
+
headers?: Record<string, unknown>;
|
|
123
|
+
};
|
|
120
124
|
_urlHandler: ((url: string) => string) | null;
|
|
121
125
|
isClientSideNavigation: boolean;
|
|
122
126
|
} & {
|
|
@@ -117,7 +117,9 @@ declare function loadPageConfigsLazyServerSide(pageContext: PageContext_loadPage
|
|
|
117
117
|
_pageFilesAll: import("../../../shared-server-client/getPageFiles.js").PageFile[];
|
|
118
118
|
_baseServer: string;
|
|
119
119
|
_baseAssets: string;
|
|
120
|
-
_pageContextInit: import("../renderPageServer.js").PageContextInit
|
|
120
|
+
_pageContextInit: import("../renderPageServer.js").PageContextInit & {
|
|
121
|
+
headers?: Record<string, unknown>;
|
|
122
|
+
};
|
|
121
123
|
_urlHandler: ((url: string) => string) | null;
|
|
122
124
|
isClientSideNavigation: boolean;
|
|
123
125
|
} & {
|
|
@@ -125,7 +125,9 @@ declare function prerenderPage(pageContext: Parameters<typeof prerenderPageEntry
|
|
|
125
125
|
_pageFilesAll: import("../../__internal/index.js").PageFile[];
|
|
126
126
|
_baseServer: string;
|
|
127
127
|
_baseAssets: string;
|
|
128
|
-
_pageContextInit: import("../renderPageServer.js").PageContextInit
|
|
128
|
+
_pageContextInit: import("../renderPageServer.js").PageContextInit & {
|
|
129
|
+
headers?: Record<string, unknown>;
|
|
130
|
+
};
|
|
129
131
|
_urlHandler: ((url: string) => string) | null;
|
|
130
132
|
isClientSideNavigation: boolean;
|
|
131
133
|
} & {
|
|
@@ -286,7 +288,9 @@ declare function prerenderPage(pageContext: Parameters<typeof prerenderPageEntry
|
|
|
286
288
|
_pageFilesAll: import("../../__internal/index.js").PageFile[];
|
|
287
289
|
_baseServer: string;
|
|
288
290
|
_baseAssets: string;
|
|
289
|
-
_pageContextInit: import("../renderPageServer.js").PageContextInit
|
|
291
|
+
_pageContextInit: import("../renderPageServer.js").PageContextInit & {
|
|
292
|
+
headers?: Record<string, unknown>;
|
|
293
|
+
};
|
|
290
294
|
_urlHandler: ((url: string) => string) | null;
|
|
291
295
|
isClientSideNavigation: boolean;
|
|
292
296
|
} & {
|
|
@@ -455,7 +459,9 @@ declare function prerenderPageEntry(pageContext: PageContextCreatedServer & Page
|
|
|
455
459
|
_pageFilesAll: import("../../__internal/index.js").PageFile[];
|
|
456
460
|
_baseServer: string;
|
|
457
461
|
_baseAssets: string;
|
|
458
|
-
_pageContextInit: import("../renderPageServer.js").PageContextInit
|
|
462
|
+
_pageContextInit: import("../renderPageServer.js").PageContextInit & {
|
|
463
|
+
headers?: Record<string, unknown>;
|
|
464
|
+
};
|
|
459
465
|
_urlHandler: ((url: string) => string) | null;
|
|
460
466
|
isClientSideNavigation: boolean;
|
|
461
467
|
} & {
|
|
@@ -616,7 +622,9 @@ declare function prerenderPageEntry(pageContext: PageContextCreatedServer & Page
|
|
|
616
622
|
_pageFilesAll: import("../../__internal/index.js").PageFile[];
|
|
617
623
|
_baseServer: string;
|
|
618
624
|
_baseAssets: string;
|
|
619
|
-
_pageContextInit: import("../renderPageServer.js").PageContextInit
|
|
625
|
+
_pageContextInit: import("../renderPageServer.js").PageContextInit & {
|
|
626
|
+
headers?: Record<string, unknown>;
|
|
627
|
+
};
|
|
620
628
|
_urlHandler: ((url: string) => string) | null;
|
|
621
629
|
isClientSideNavigation: boolean;
|
|
622
630
|
} & {
|
|
@@ -116,7 +116,9 @@ declare function getPageContextBegin(pageContextInit: PageContextInit, globalCon
|
|
|
116
116
|
_pageFilesAll: import("../__internal/index.js").PageFile[];
|
|
117
117
|
_baseServer: string;
|
|
118
118
|
_baseAssets: string;
|
|
119
|
-
_pageContextInit: PageContextInit
|
|
119
|
+
_pageContextInit: PageContextInit & {
|
|
120
|
+
headers?: Record<string, unknown>;
|
|
121
|
+
};
|
|
120
122
|
_urlHandler: ((url: string) => string) | null;
|
|
121
123
|
isClientSideNavigation: boolean;
|
|
122
124
|
} & {
|
|
@@ -163,15 +163,12 @@ function assertStatusCode(statusCode, expected, caller) {
|
|
|
163
163
|
}
|
|
164
164
|
else {
|
|
165
165
|
assert(!isBrowser());
|
|
166
|
-
if (
|
|
166
|
+
if (globalThis.__VIKE__NO_EXTERNAL) {
|
|
167
167
|
assert(typeof globalThis.__VIKE__IS_DEV === 'boolean');
|
|
168
168
|
assert(typeof globalThis.__VIKE__IS_CLIENT === 'boolean');
|
|
169
169
|
assert(import.meta.env.SSR === true);
|
|
170
170
|
assert(import.meta.env.DEV === globalThis.__VIKE__IS_DEV);
|
|
171
171
|
}
|
|
172
|
-
else {
|
|
173
|
-
// import.meta.env isn't defined when 'vike' is ssr.external
|
|
174
|
-
}
|
|
175
172
|
}
|
|
176
173
|
const expectedEnglish = joinEnglish(expected.map((s) => pc.bold(String(s))), 'or');
|
|
177
174
|
const statusCodeWithColor = pc.bold(String(statusCode));
|
|
@@ -131,7 +131,6 @@ type PageContextInit = {
|
|
|
131
131
|
*/
|
|
132
132
|
headersOriginal?: unknown;
|
|
133
133
|
/** @deprecated Set `pageContextInit.urlOriginal` instead */ url?: string;
|
|
134
|
-
/** @deprecated Set pageContextInit.headersOriginal instead */ headers?: Record<string, string>;
|
|
135
134
|
};
|
|
136
135
|
type PageContextBuiltInServer<Data> = PageContextBuiltInCommon<Data> & PageContextInit & PageContextUrlServer & {
|
|
137
136
|
/**
|
|
@@ -270,6 +269,8 @@ type PageContextClientCommon = {
|
|
|
270
269
|
* https://vike.dev/pageContext#isPrerendering
|
|
271
270
|
*/
|
|
272
271
|
isPrerendering: false;
|
|
272
|
+
cspNonce?: undefined;
|
|
273
|
+
headers?: undefined;
|
|
273
274
|
};
|
|
274
275
|
type PageContextInternalServer = Omit<PageContextBuiltInCommon<unknown> & PageContextUrlInternal, 'data' | 'globalContext'>;
|
|
275
276
|
type OnlyUsers = 'data' | 'Page' | 'globalContext';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.253-commit-1658209";
|
|
@@ -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.253-commit-1658209';
|