vike 0.4.238-commit-5762291 → 0.4.238
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/node/runtime/html/injectAssets/getHtmlTags.js +7 -10
- package/dist/cjs/node/runtime/html/injectAssets/inferHtmlTags.js +2 -5
- package/dist/cjs/node/runtime/html/injectAssets/mergeScriptTags.js +2 -4
- package/dist/cjs/node/runtime/renderPage/loadPageConfigsLazyServerSide.js +0 -4
- package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +0 -3
- package/dist/cjs/shared/page-configs/resolveVikeConfigPublic.js +1 -2
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/node/prerender/runPrerender.d.ts +0 -2
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +7 -10
- package/dist/esm/node/runtime/html/injectAssets/inferHtmlTags.d.ts +1 -2
- package/dist/esm/node/runtime/html/injectAssets/inferHtmlTags.js +2 -5
- package/dist/esm/node/runtime/html/injectAssets/mergeScriptTags.d.ts +1 -2
- package/dist/esm/node/runtime/html/injectAssets/mergeScriptTags.js +2 -4
- package/dist/esm/node/runtime/html/serializeContext.d.ts +1 -2
- package/dist/esm/node/runtime/renderPage/loadPageConfigsLazyServerSide.d.ts +0 -2
- package/dist/esm/node/runtime/renderPage/loadPageConfigsLazyServerSide.js +0 -4
- package/dist/esm/node/runtime/renderPage/renderPageAfterRoute.d.ts +0 -4
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +0 -3
- package/dist/esm/shared/page-configs/resolveVikeConfigPublic.js +1 -2
- package/dist/esm/types/Config.d.ts +0 -8
- package/dist/esm/types/PageContext.d.ts +0 -6
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/package.json +1 -1
- package/dist/cjs/node/runtime/csp.js +0 -46
- package/dist/esm/node/runtime/csp.d.ts +0 -12
- package/dist/esm/node/runtime/csp.js +0 -44
|
@@ -15,7 +15,6 @@ const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
|
15
15
|
const getConfigDefinedAt_js_1 = require("../../../../shared/page-configs/getConfigDefinedAt.js");
|
|
16
16
|
const htmlElementIds_js_1 = require("../../../../shared/htmlElementIds.js");
|
|
17
17
|
const isFontFallback_js_1 = require("../../renderPage/isFontFallback.js");
|
|
18
|
-
const csp_js_1 = require("../../csp.js");
|
|
19
18
|
const stamp = '__injectFilterEntry';
|
|
20
19
|
async function getHtmlTags(pageContext, streamFromReactStreamingPackage, injectFilter, pageAssets, viteDevScript, isStream) {
|
|
21
20
|
(0, utils_js_1.assert)([true, false].includes(pageContext._isHtmlOnly));
|
|
@@ -82,7 +81,7 @@ async function getHtmlTags(pageContext, streamFromReactStreamingPackage, injectF
|
|
|
82
81
|
.forEach((asset) => {
|
|
83
82
|
if (!asset.inject)
|
|
84
83
|
return;
|
|
85
|
-
const htmlTag = asset.isEntry ? (0, inferHtmlTags_js_1.inferAssetTag)(asset
|
|
84
|
+
const htmlTag = asset.isEntry ? (0, inferHtmlTags_js_1.inferAssetTag)(asset) : (0, inferHtmlTags_js_1.inferPreloadTag)(asset);
|
|
86
85
|
htmlTags.push({ htmlTag, position: asset.inject });
|
|
87
86
|
});
|
|
88
87
|
// ==========
|
|
@@ -143,7 +142,7 @@ async function getHtmlTags(pageContext, streamFromReactStreamingPackage, injectF
|
|
|
143
142
|
});
|
|
144
143
|
}
|
|
145
144
|
// The JavaScript entry <script> tag
|
|
146
|
-
const scriptEntry = mergeScriptEntries(pageAssets, viteDevScript
|
|
145
|
+
const scriptEntry = mergeScriptEntries(pageAssets, viteDevScript);
|
|
147
146
|
if (scriptEntry) {
|
|
148
147
|
htmlTags.push({
|
|
149
148
|
htmlTag: scriptEntry,
|
|
@@ -164,9 +163,9 @@ async function getHtmlTags(pageContext, streamFromReactStreamingPackage, injectF
|
|
|
164
163
|
});
|
|
165
164
|
return htmlTags;
|
|
166
165
|
}
|
|
167
|
-
function mergeScriptEntries(pageAssets, viteDevScript
|
|
166
|
+
function mergeScriptEntries(pageAssets, viteDevScript) {
|
|
168
167
|
const scriptEntries = pageAssets.filter((pageAsset) => pageAsset.isEntry && pageAsset.assetType === 'script');
|
|
169
|
-
let scriptEntry = `${viteDevScript}${scriptEntries.map((asset) => (0, inferHtmlTags_js_1.inferAssetTag)(asset
|
|
168
|
+
let scriptEntry = `${viteDevScript}${scriptEntries.map((asset) => (0, inferHtmlTags_js_1.inferAssetTag)(asset)).join('')}`;
|
|
170
169
|
// We merge scripts to avoid the infamous HMR preamble error.
|
|
171
170
|
// - Infamous HMR preamble error:
|
|
172
171
|
// ```browser-console
|
|
@@ -184,13 +183,12 @@ function mergeScriptEntries(pageAssets, viteDevScript, pageContext) {
|
|
|
184
183
|
// ```
|
|
185
184
|
// - Maybe an alternative would be to make Vike's client runtime entry <script> tag non-async. Would that work? Would it be a performance issue?
|
|
186
185
|
// - The entry <script> shouldn't be `<script defer>` upon HTML streaming, otherwise progressive hydration while SSR streaming won't work.
|
|
187
|
-
scriptEntry = (0, mergeScriptTags_js_1.mergeScriptTags)(scriptEntry
|
|
186
|
+
scriptEntry = (0, mergeScriptTags_js_1.mergeScriptTags)(scriptEntry);
|
|
188
187
|
return scriptEntry;
|
|
189
188
|
}
|
|
190
189
|
function getPageContextJsonScriptTag(pageContext) {
|
|
191
190
|
const pageContextClientSerialized = (0, sanitizeJson_js_1.sanitizeJson)((0, serializeContext_js_1.getPageContextClientSerialized)(pageContext, true));
|
|
192
|
-
const
|
|
193
|
-
const htmlTag = `<script id="${htmlElementIds_js_1.htmlElementId_pageContext}" type="application/json"${nonceAttr}>${pageContextClientSerialized}</script>`;
|
|
191
|
+
const htmlTag = `<script id="${htmlElementIds_js_1.htmlElementId_pageContext}" type="application/json">${pageContextClientSerialized}</script>`;
|
|
194
192
|
// Used by contra.com https://github.com/gajus
|
|
195
193
|
// @ts-expect-error
|
|
196
194
|
pageContext._pageContextHtmlTag = htmlTag;
|
|
@@ -198,8 +196,7 @@ function getPageContextJsonScriptTag(pageContext) {
|
|
|
198
196
|
}
|
|
199
197
|
function getGlobalContextJsonScriptTag(pageContext) {
|
|
200
198
|
const globalContextClientSerialized = (0, sanitizeJson_js_1.sanitizeJson)((0, serializeContext_js_1.getGlobalContextClientSerialized)(pageContext, true));
|
|
201
|
-
const
|
|
202
|
-
const htmlTag = `<script id="${htmlElementIds_js_1.htmlElementId_globalContext}" type="application/json"${nonceAttr}>${globalContextClientSerialized}</script>`;
|
|
199
|
+
const htmlTag = `<script id="${htmlElementIds_js_1.htmlElementId_globalContext}" type="application/json">${globalContextClientSerialized}</script>`;
|
|
203
200
|
return htmlTag;
|
|
204
201
|
}
|
|
205
202
|
function assertInjectFilterEntries(injectFilterEntries) {
|
|
@@ -5,8 +5,6 @@ exports.inferAssetTag = inferAssetTag;
|
|
|
5
5
|
exports.inferPreloadTag = inferPreloadTag;
|
|
6
6
|
exports.inferEarlyHintLink = inferEarlyHintLink;
|
|
7
7
|
const utils_js_1 = require("../../utils.js");
|
|
8
|
-
const csp_js_1 = require("../../csp.js");
|
|
9
|
-
// TODO/now rename scriptAttrs scriptCommonAttrs
|
|
10
8
|
// We can't use `defer` here. With `defer`, the entry script won't start before `</body>` has been parsed, preventing progressive hydration during SSR streaming, see https://github.com/vikejs/vike/pull/1271
|
|
11
9
|
const scriptAttrs = 'type="module" async';
|
|
12
10
|
exports.scriptAttrs = scriptAttrs;
|
|
@@ -25,12 +23,11 @@ function inferPreloadTag(pageAsset) {
|
|
|
25
23
|
.join(' ');
|
|
26
24
|
return `<link ${attributes}>`;
|
|
27
25
|
}
|
|
28
|
-
function inferAssetTag(pageAsset
|
|
26
|
+
function inferAssetTag(pageAsset) {
|
|
29
27
|
const { src, assetType, mediaType } = pageAsset;
|
|
30
28
|
if (assetType === 'script') {
|
|
31
29
|
(0, utils_js_1.assert)(mediaType === 'text/javascript');
|
|
32
|
-
|
|
33
|
-
return `<script src="${src}" ${scriptAttrs}${nonceAttr}></script>`;
|
|
30
|
+
return `<script src="${src}" ${scriptAttrs}></script>`;
|
|
34
31
|
}
|
|
35
32
|
if (assetType === 'style') {
|
|
36
33
|
// WARNING: if changing following line, then also update https://github.com/vikejs/vike/blob/fae90a15d88e5e87ca9fcbb54cf2dc8773d2f229/vike/client/shared/removeFoucBuster.ts#L29
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.mergeScriptTags = mergeScriptTags;
|
|
4
|
-
const csp_js_1 = require("../../csp.js");
|
|
5
4
|
const utils_js_1 = require("../../utils.js");
|
|
6
5
|
const inferHtmlTags_js_1 = require("./inferHtmlTags.js");
|
|
7
6
|
const scriptRE = /(<script\b(?:\s[^>]*>|>))(.*?)<\/script>/gims;
|
|
8
7
|
const srcRE = /\bsrc\s*=\s*(?:"([^"]+)"|'([^']+)'|([^\s'">]+))/im;
|
|
9
8
|
const typeRE = /\btype\s*=\s*(?:"([^"]+)"|'([^']+)'|([^\s'">]+))/im;
|
|
10
|
-
function mergeScriptTags(scriptTagsHtml
|
|
9
|
+
function mergeScriptTags(scriptTagsHtml) {
|
|
11
10
|
let scriptTag = '';
|
|
12
11
|
const scripts = parseScripts(scriptTagsHtml);
|
|
13
12
|
// We need to merge module scripts to ensure execution order
|
|
@@ -36,8 +35,7 @@ function mergeScriptTags(scriptTagsHtml, pageContext) {
|
|
|
36
35
|
}
|
|
37
36
|
});
|
|
38
37
|
if (contents.length > 0) {
|
|
39
|
-
|
|
40
|
-
scriptTag += `<script ${inferHtmlTags_js_1.scriptAttrs}${nonceAttr}>\n${contents.join('\n')}\n</script>`;
|
|
38
|
+
scriptTag += `<script ${inferHtmlTags_js_1.scriptAttrs}>\n${contents.join('\n')}\n</script>`;
|
|
41
39
|
}
|
|
42
40
|
}
|
|
43
41
|
}
|
|
@@ -11,7 +11,6 @@ const analyzePage_js_1 = require("./analyzePage.js");
|
|
|
11
11
|
const loadAndParseVirtualFilePageEntry_js_1 = require("../../../shared/page-configs/loadAndParseVirtualFilePageEntry.js");
|
|
12
12
|
const execHookServer_js_1 = require("./execHookServer.js");
|
|
13
13
|
const getCacheControl_js_1 = require("./getCacheControl.js");
|
|
14
|
-
const csp_js_1 = require("../csp.js");
|
|
15
14
|
async function loadPageConfigsLazyServerSide(pageContext) {
|
|
16
15
|
(0, utils_js_1.objectAssign)(pageContext, {
|
|
17
16
|
_pageConfig: (0, findPageConfig_js_1.findPageConfig)(pageContext._globalContext._pageConfigs, pageContext.pageId),
|
|
@@ -56,7 +55,6 @@ async function resolvePageContext(pageContext) {
|
|
|
56
55
|
passToClient.push(...valS);
|
|
57
56
|
});
|
|
58
57
|
}
|
|
59
|
-
(0, utils_js_1.objectAssign)(pageContext, await (0, csp_js_1.resolvePageContextCspNone)(pageContext));
|
|
60
58
|
(0, utils_js_1.objectAssign)(pageContext, {
|
|
61
59
|
Page: pageContext.exports.Page,
|
|
62
60
|
_isHtmlOnly: isHtmlOnly,
|
|
@@ -127,7 +125,6 @@ async function loadPageUserFiles_v1Design(pageContext) {
|
|
|
127
125
|
pageFilesLoaded: pageFilesServerSide,
|
|
128
126
|
};
|
|
129
127
|
}
|
|
130
|
-
// TODO/now: move all response headers code to headersResponse.ts
|
|
131
128
|
function resolveHeadersResponse(pageContext) {
|
|
132
129
|
const headersResponse = mergeHeaders(pageContext.config.headersResponse);
|
|
133
130
|
if (!headersResponse.get('Cache-Control')) {
|
|
@@ -135,7 +132,6 @@ function resolveHeadersResponse(pageContext) {
|
|
|
135
132
|
if (cacheControl)
|
|
136
133
|
headersResponse.set('Cache-Control', cacheControl);
|
|
137
134
|
}
|
|
138
|
-
(0, csp_js_1.addCspHeader)(pageContext, headersResponse);
|
|
139
135
|
return headersResponse;
|
|
140
136
|
}
|
|
141
137
|
function mergeHeaders(headersList = []) {
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
//
|
|
2
|
+
// TO-DO/soon: rename PageConfig names
|
|
3
3
|
// - Use `Internal` suffix, i.e. {Page,Global}ConfigInternal
|
|
4
4
|
// - While keeping {Page,Global}ConfigPublic or remove Public suffix and rename it to {Page,Global}Config ?
|
|
5
5
|
// - rename EagerLoaded EagerlyLoaded
|
|
6
6
|
// - remove `LazyLoaded` suffix
|
|
7
|
-
// TODO/now: rename VikeConfigPublicPageLazyLoaded PageContextSomething (for `pageContext: PageContextSomething` usage)
|
|
8
7
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
8
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
9
|
};
|
|
@@ -174,8 +174,6 @@ declare function createPageContextPrerendering(urlOriginal: string, prerenderCon
|
|
|
174
174
|
_pageConfig: null | import("../../types/PageConfig.js").PageConfigRuntime;
|
|
175
175
|
} & import("../../shared/getPageFiles.js").VikeConfigPublicPageLazyLoaded & {
|
|
176
176
|
_pageConfig: null | import("../../types/PageConfig.js").PageConfigRuntime;
|
|
177
|
-
} & {
|
|
178
|
-
cspNonce: string;
|
|
179
177
|
} & {
|
|
180
178
|
Page: unknown;
|
|
181
179
|
_isHtmlOnly: boolean;
|
|
@@ -10,7 +10,6 @@ import pc from '@brillout/picocolors';
|
|
|
10
10
|
import { getConfigDefinedAt } from '../../../../shared/page-configs/getConfigDefinedAt.js';
|
|
11
11
|
import { htmlElementId_globalContext, htmlElementId_pageContext } from '../../../../shared/htmlElementIds.js';
|
|
12
12
|
import { isFontFallback } from '../../renderPage/isFontFallback.js';
|
|
13
|
-
import { inferNonceAttr } from '../../csp.js';
|
|
14
13
|
const stamp = '__injectFilterEntry';
|
|
15
14
|
async function getHtmlTags(pageContext, streamFromReactStreamingPackage, injectFilter, pageAssets, viteDevScript, isStream) {
|
|
16
15
|
assert([true, false].includes(pageContext._isHtmlOnly));
|
|
@@ -77,7 +76,7 @@ async function getHtmlTags(pageContext, streamFromReactStreamingPackage, injectF
|
|
|
77
76
|
.forEach((asset) => {
|
|
78
77
|
if (!asset.inject)
|
|
79
78
|
return;
|
|
80
|
-
const htmlTag = asset.isEntry ? inferAssetTag(asset
|
|
79
|
+
const htmlTag = asset.isEntry ? inferAssetTag(asset) : inferPreloadTag(asset);
|
|
81
80
|
htmlTags.push({ htmlTag, position: asset.inject });
|
|
82
81
|
});
|
|
83
82
|
// ==========
|
|
@@ -138,7 +137,7 @@ async function getHtmlTags(pageContext, streamFromReactStreamingPackage, injectF
|
|
|
138
137
|
});
|
|
139
138
|
}
|
|
140
139
|
// The JavaScript entry <script> tag
|
|
141
|
-
const scriptEntry = mergeScriptEntries(pageAssets, viteDevScript
|
|
140
|
+
const scriptEntry = mergeScriptEntries(pageAssets, viteDevScript);
|
|
142
141
|
if (scriptEntry) {
|
|
143
142
|
htmlTags.push({
|
|
144
143
|
htmlTag: scriptEntry,
|
|
@@ -159,9 +158,9 @@ async function getHtmlTags(pageContext, streamFromReactStreamingPackage, injectF
|
|
|
159
158
|
});
|
|
160
159
|
return htmlTags;
|
|
161
160
|
}
|
|
162
|
-
function mergeScriptEntries(pageAssets, viteDevScript
|
|
161
|
+
function mergeScriptEntries(pageAssets, viteDevScript) {
|
|
163
162
|
const scriptEntries = pageAssets.filter((pageAsset) => pageAsset.isEntry && pageAsset.assetType === 'script');
|
|
164
|
-
let scriptEntry = `${viteDevScript}${scriptEntries.map((asset) => inferAssetTag(asset
|
|
163
|
+
let scriptEntry = `${viteDevScript}${scriptEntries.map((asset) => inferAssetTag(asset)).join('')}`;
|
|
165
164
|
// We merge scripts to avoid the infamous HMR preamble error.
|
|
166
165
|
// - Infamous HMR preamble error:
|
|
167
166
|
// ```browser-console
|
|
@@ -179,13 +178,12 @@ function mergeScriptEntries(pageAssets, viteDevScript, pageContext) {
|
|
|
179
178
|
// ```
|
|
180
179
|
// - Maybe an alternative would be to make Vike's client runtime entry <script> tag non-async. Would that work? Would it be a performance issue?
|
|
181
180
|
// - The entry <script> shouldn't be `<script defer>` upon HTML streaming, otherwise progressive hydration while SSR streaming won't work.
|
|
182
|
-
scriptEntry = mergeScriptTags(scriptEntry
|
|
181
|
+
scriptEntry = mergeScriptTags(scriptEntry);
|
|
183
182
|
return scriptEntry;
|
|
184
183
|
}
|
|
185
184
|
function getPageContextJsonScriptTag(pageContext) {
|
|
186
185
|
const pageContextClientSerialized = sanitizeJson(getPageContextClientSerialized(pageContext, true));
|
|
187
|
-
const
|
|
188
|
-
const htmlTag = `<script id="${htmlElementId_pageContext}" type="application/json"${nonceAttr}>${pageContextClientSerialized}</script>`;
|
|
186
|
+
const htmlTag = `<script id="${htmlElementId_pageContext}" type="application/json">${pageContextClientSerialized}</script>`;
|
|
189
187
|
// Used by contra.com https://github.com/gajus
|
|
190
188
|
// @ts-expect-error
|
|
191
189
|
pageContext._pageContextHtmlTag = htmlTag;
|
|
@@ -193,8 +191,7 @@ function getPageContextJsonScriptTag(pageContext) {
|
|
|
193
191
|
}
|
|
194
192
|
function getGlobalContextJsonScriptTag(pageContext) {
|
|
195
193
|
const globalContextClientSerialized = sanitizeJson(getGlobalContextClientSerialized(pageContext, true));
|
|
196
|
-
const
|
|
197
|
-
const htmlTag = `<script id="${htmlElementId_globalContext}" type="application/json"${nonceAttr}>${globalContextClientSerialized}</script>`;
|
|
194
|
+
const htmlTag = `<script id="${htmlElementId_globalContext}" type="application/json">${globalContextClientSerialized}</script>`;
|
|
198
195
|
return htmlTag;
|
|
199
196
|
}
|
|
200
197
|
function assertInjectFilterEntries(injectFilterEntries) {
|
|
@@ -3,8 +3,7 @@ export { inferPreloadTag };
|
|
|
3
3
|
export { inferEarlyHintLink };
|
|
4
4
|
export { scriptAttrs };
|
|
5
5
|
import type { PageAsset } from '../../renderPage/getPageAssets.js';
|
|
6
|
-
import { type PageContextCspNonce } from '../../csp.js';
|
|
7
6
|
declare const scriptAttrs = "type=\"module\" async";
|
|
8
7
|
declare function inferPreloadTag(pageAsset: PageAsset): string;
|
|
9
|
-
declare function inferAssetTag(pageAsset: PageAsset
|
|
8
|
+
declare function inferAssetTag(pageAsset: PageAsset): string;
|
|
10
9
|
declare function inferEarlyHintLink(pageAsset: PageAsset): string;
|
|
@@ -3,8 +3,6 @@ export { inferPreloadTag };
|
|
|
3
3
|
export { inferEarlyHintLink };
|
|
4
4
|
export { scriptAttrs };
|
|
5
5
|
import { assert } from '../../utils.js';
|
|
6
|
-
import { inferNonceAttr } from '../../csp.js';
|
|
7
|
-
// TODO/now rename scriptAttrs scriptCommonAttrs
|
|
8
6
|
// We can't use `defer` here. With `defer`, the entry script won't start before `</body>` has been parsed, preventing progressive hydration during SSR streaming, see https://github.com/vikejs/vike/pull/1271
|
|
9
7
|
const scriptAttrs = 'type="module" async';
|
|
10
8
|
function inferPreloadTag(pageAsset) {
|
|
@@ -22,12 +20,11 @@ function inferPreloadTag(pageAsset) {
|
|
|
22
20
|
.join(' ');
|
|
23
21
|
return `<link ${attributes}>`;
|
|
24
22
|
}
|
|
25
|
-
function inferAssetTag(pageAsset
|
|
23
|
+
function inferAssetTag(pageAsset) {
|
|
26
24
|
const { src, assetType, mediaType } = pageAsset;
|
|
27
25
|
if (assetType === 'script') {
|
|
28
26
|
assert(mediaType === 'text/javascript');
|
|
29
|
-
|
|
30
|
-
return `<script src="${src}" ${scriptAttrs}${nonceAttr}></script>`;
|
|
27
|
+
return `<script src="${src}" ${scriptAttrs}></script>`;
|
|
31
28
|
}
|
|
32
29
|
if (assetType === 'style') {
|
|
33
30
|
// WARNING: if changing following line, then also update https://github.com/vikejs/vike/blob/fae90a15d88e5e87ca9fcbb54cf2dc8773d2f229/vike/client/shared/removeFoucBuster.ts#L29
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
export { mergeScriptTags };
|
|
2
|
-
import { inferNonceAttr } from '../../csp.js';
|
|
3
2
|
import { assert } from '../../utils.js';
|
|
4
3
|
import { scriptAttrs } from './inferHtmlTags.js';
|
|
5
4
|
const scriptRE = /(<script\b(?:\s[^>]*>|>))(.*?)<\/script>/gims;
|
|
6
5
|
const srcRE = /\bsrc\s*=\s*(?:"([^"]+)"|'([^']+)'|([^\s'">]+))/im;
|
|
7
6
|
const typeRE = /\btype\s*=\s*(?:"([^"]+)"|'([^']+)'|([^\s'">]+))/im;
|
|
8
|
-
function mergeScriptTags(scriptTagsHtml
|
|
7
|
+
function mergeScriptTags(scriptTagsHtml) {
|
|
9
8
|
let scriptTag = '';
|
|
10
9
|
const scripts = parseScripts(scriptTagsHtml);
|
|
11
10
|
// We need to merge module scripts to ensure execution order
|
|
@@ -34,8 +33,7 @@ function mergeScriptTags(scriptTagsHtml, pageContext) {
|
|
|
34
33
|
}
|
|
35
34
|
});
|
|
36
35
|
if (contents.length > 0) {
|
|
37
|
-
|
|
38
|
-
scriptTag += `<script ${scriptAttrs}${nonceAttr}>\n${contents.join('\n')}\n</script>`;
|
|
36
|
+
scriptTag += `<script ${scriptAttrs}>\n${contents.join('\n')}\n</script>`;
|
|
39
37
|
}
|
|
40
38
|
}
|
|
41
39
|
}
|
|
@@ -8,7 +8,6 @@ import type { UrlRedirect } from '../../../shared/route/abort.js';
|
|
|
8
8
|
import type { GlobalContextServerInternal } from '../globalContext.js';
|
|
9
9
|
import type { PageContextCreated } from '../renderPage/createPageContextServerSide.js';
|
|
10
10
|
import type { PageContextBegin } from '../renderPage.js';
|
|
11
|
-
import type { PageContextCspNonce } from '../csp.js';
|
|
12
11
|
type PageContextSerialization = PageContextCreated & {
|
|
13
12
|
pageId: string;
|
|
14
13
|
routeParams: Record<string, string>;
|
|
@@ -18,7 +17,7 @@ type PageContextSerialization = PageContextCreated & {
|
|
|
18
17
|
_pageContextInit: Record<string, unknown>;
|
|
19
18
|
_globalContext: GlobalContextServerInternal;
|
|
20
19
|
_isPageContextJsonRequest: null | PageContextBegin['_isPageContextJsonRequest'];
|
|
21
|
-
}
|
|
20
|
+
};
|
|
22
21
|
declare function getPageContextClientSerialized(pageContext: PageContextSerialization, isHtmlJsonScript: boolean): string;
|
|
23
22
|
declare function getGlobalContextClientSerialized(pageContext: PageContextSerialization, isHtmlJsonScript: boolean): string;
|
|
24
23
|
type PassToClient = string[];
|
|
@@ -111,8 +111,6 @@ declare function loadPageConfigsLazyServerSide(pageContext: PageContext_loadPage
|
|
|
111
111
|
_pageConfig: null | PageConfigRuntime;
|
|
112
112
|
} & VikeConfigPublicPageLazyLoaded & {
|
|
113
113
|
_pageConfig: null | PageConfigRuntime;
|
|
114
|
-
} & {
|
|
115
|
-
cspNonce: string;
|
|
116
114
|
} & {
|
|
117
115
|
Page: unknown;
|
|
118
116
|
_isHtmlOnly: boolean;
|
|
@@ -9,7 +9,6 @@ import { analyzePage } from './analyzePage.js';
|
|
|
9
9
|
import { loadAndParseVirtualFilePageEntry } from '../../../shared/page-configs/loadAndParseVirtualFilePageEntry.js';
|
|
10
10
|
import { execHookServer } from './execHookServer.js';
|
|
11
11
|
import { getCacheControl } from './getCacheControl.js';
|
|
12
|
-
import { addCspHeader, resolvePageContextCspNone } from '../csp.js';
|
|
13
12
|
async function loadPageConfigsLazyServerSide(pageContext) {
|
|
14
13
|
objectAssign(pageContext, {
|
|
15
14
|
_pageConfig: findPageConfig(pageContext._globalContext._pageConfigs, pageContext.pageId),
|
|
@@ -54,7 +53,6 @@ async function resolvePageContext(pageContext) {
|
|
|
54
53
|
passToClient.push(...valS);
|
|
55
54
|
});
|
|
56
55
|
}
|
|
57
|
-
objectAssign(pageContext, await resolvePageContextCspNone(pageContext));
|
|
58
56
|
objectAssign(pageContext, {
|
|
59
57
|
Page: pageContext.exports.Page,
|
|
60
58
|
_isHtmlOnly: isHtmlOnly,
|
|
@@ -125,7 +123,6 @@ async function loadPageUserFiles_v1Design(pageContext) {
|
|
|
125
123
|
pageFilesLoaded: pageFilesServerSide,
|
|
126
124
|
};
|
|
127
125
|
}
|
|
128
|
-
// TODO/now: move all response headers code to headersResponse.ts
|
|
129
126
|
function resolveHeadersResponse(pageContext) {
|
|
130
127
|
const headersResponse = mergeHeaders(pageContext.config.headersResponse);
|
|
131
128
|
if (!headersResponse.get('Cache-Control')) {
|
|
@@ -133,7 +130,6 @@ function resolveHeadersResponse(pageContext) {
|
|
|
133
130
|
if (cacheControl)
|
|
134
131
|
headersResponse.set('Cache-Control', cacheControl);
|
|
135
132
|
}
|
|
136
|
-
addCspHeader(pageContext, headersResponse);
|
|
137
133
|
return headersResponse;
|
|
138
134
|
}
|
|
139
135
|
function mergeHeaders(headersList = []) {
|
|
@@ -127,8 +127,6 @@ declare function prerenderPage(pageContext: PageContextCreated & PageConfigsLazy
|
|
|
127
127
|
_pageConfig: null | import("../../../types/PageConfig.js").PageConfigRuntime;
|
|
128
128
|
} & import("../../../shared/getPageFiles.js").VikeConfigPublicPageLazyLoaded & {
|
|
129
129
|
_pageConfig: null | import("../../../types/PageConfig.js").PageConfigRuntime;
|
|
130
|
-
} & {
|
|
131
|
-
cspNonce: string;
|
|
132
130
|
} & {
|
|
133
131
|
Page: unknown;
|
|
134
132
|
_isHtmlOnly: boolean;
|
|
@@ -248,8 +246,6 @@ declare function prerenderPage(pageContext: PageContextCreated & PageConfigsLazy
|
|
|
248
246
|
_pageConfig: null | import("../../../types/PageConfig.js").PageConfigRuntime;
|
|
249
247
|
} & import("../../../shared/getPageFiles.js").VikeConfigPublicPageLazyLoaded & {
|
|
250
248
|
_pageConfig: null | import("../../../types/PageConfig.js").PageConfigRuntime;
|
|
251
|
-
} & {
|
|
252
|
-
cspNonce: string;
|
|
253
249
|
} & {
|
|
254
250
|
Page: unknown;
|
|
255
251
|
_isHtmlOnly: boolean;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
//
|
|
1
|
+
// TO-DO/soon: rename PageConfig names
|
|
2
2
|
// - Use `Internal` suffix, i.e. {Page,Global}ConfigInternal
|
|
3
3
|
// - While keeping {Page,Global}ConfigPublic or remove Public suffix and rename it to {Page,Global}Config ?
|
|
4
4
|
// - rename EagerLoaded EagerlyLoaded
|
|
5
5
|
// - remove `LazyLoaded` suffix
|
|
6
|
-
// TODO/now: rename VikeConfigPublicPageLazyLoaded PageContextSomething (for `pageContext: PageContextSomething` usage)
|
|
7
6
|
// TO-DO/soon/same-api: use public API internally?
|
|
8
7
|
// TO-DO/soon/flat-pageContext: rename definedAt => definedBy
|
|
9
8
|
export { resolveVikeConfigPublicGlobal };
|
|
@@ -468,14 +468,6 @@ type ConfigBuiltIn = {
|
|
|
468
468
|
* https://vike.dev/mode
|
|
469
469
|
*/
|
|
470
470
|
mode?: string;
|
|
471
|
-
/**
|
|
472
|
-
* Content Security Policy (CSP).
|
|
473
|
-
*
|
|
474
|
-
* https://vike.dev/csp
|
|
475
|
-
*/
|
|
476
|
-
csp?: {
|
|
477
|
-
nonce: boolean | ((pageContext: PageContextServer) => string | Promise<string>);
|
|
478
|
-
};
|
|
479
471
|
/** Where scripts are injected in the HTML.
|
|
480
472
|
*
|
|
481
473
|
* https://vike.dev/injectScriptsAt
|
|
@@ -183,12 +183,6 @@ type PageContextBuiltInServer<Data> = PageContextBuiltInCommon<Data> & PageConte
|
|
|
183
183
|
* https://vike.dev/pageContext#globalContext
|
|
184
184
|
*/
|
|
185
185
|
globalContext: GlobalContextServer;
|
|
186
|
-
/**
|
|
187
|
-
* The CSP nonce.
|
|
188
|
-
*
|
|
189
|
-
* https://vike.dev/csp
|
|
190
|
-
*/
|
|
191
|
-
cspNonce?: string;
|
|
192
186
|
isHydration?: undefined;
|
|
193
187
|
isBackwardNavigation?: undefined;
|
|
194
188
|
previousPageContext?: undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.238
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.238";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Automatically updated by @brillout/release-me
|
|
2
|
-
export const PROJECT_VERSION = '0.4.238
|
|
2
|
+
export const PROJECT_VERSION = '0.4.238';
|
package/package.json
CHANGED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolvePageContextCspNone = resolvePageContextCspNone;
|
|
4
|
-
exports.inferNonceAttr = inferNonceAttr;
|
|
5
|
-
exports.addCspHeader = addCspHeader;
|
|
6
|
-
const import_1 = require("@brillout/import");
|
|
7
|
-
async function resolvePageContextCspNone(pageContext) {
|
|
8
|
-
if (pageContext.cspNonce)
|
|
9
|
-
return; // already set by user e.g. `renderPage({ cspNonce: '123456789' })`
|
|
10
|
-
const { csp } = pageContext.config;
|
|
11
|
-
if (!csp?.nonce)
|
|
12
|
-
return;
|
|
13
|
-
let cspNonce;
|
|
14
|
-
if (csp.nonce === true) {
|
|
15
|
-
cspNonce = await generateNonce();
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
cspNonce = await csp.nonce(pageContext);
|
|
19
|
-
}
|
|
20
|
-
const pageContextAddendum = { cspNonce };
|
|
21
|
-
return pageContextAddendum;
|
|
22
|
-
}
|
|
23
|
-
// Generate a cryptographically secure nonce for Content Security Policy (CSP).
|
|
24
|
-
// Returns a base64url-encoded nonce string (URL-safe, no padding).
|
|
25
|
-
// https://github.com/vikejs/vike/issues/1554#issuecomment-3181128304
|
|
26
|
-
async function generateNonce() {
|
|
27
|
-
let cryptoModule;
|
|
28
|
-
try {
|
|
29
|
-
cryptoModule = (await (0, import_1.import_)('crypto')).default;
|
|
30
|
-
}
|
|
31
|
-
catch {
|
|
32
|
-
return Math.random().toString(36).substring(2, 18);
|
|
33
|
-
}
|
|
34
|
-
return cryptoModule.randomBytes(16).toString('base64url');
|
|
35
|
-
}
|
|
36
|
-
function inferNonceAttr(pageContext) {
|
|
37
|
-
const nonceAttr = pageContext.cspNonce ? ` nonce="${pageContext.cspNonce}"` : '';
|
|
38
|
-
return nonceAttr;
|
|
39
|
-
}
|
|
40
|
-
function addCspHeader(pageContext, headersResponse) {
|
|
41
|
-
if (!pageContext.cspNonce)
|
|
42
|
-
return;
|
|
43
|
-
if (headersResponse.get('Content-Security-Policy'))
|
|
44
|
-
return;
|
|
45
|
-
headersResponse.set('Content-Security-Policy', `script-src 'self' 'nonce-${pageContext.cspNonce}'`);
|
|
46
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export { resolvePageContextCspNone };
|
|
2
|
-
export { inferNonceAttr };
|
|
3
|
-
export { addCspHeader };
|
|
4
|
-
export type { PageContextCspNonce };
|
|
5
|
-
import type { VikeConfigPublicPageLazyLoaded } from '../../shared/getPageFiles.js';
|
|
6
|
-
import type { PageContextServer } from '../../types/PageContext.js';
|
|
7
|
-
declare function resolvePageContextCspNone(pageContext: VikeConfigPublicPageLazyLoaded & PageContextCspNonce): Promise<{
|
|
8
|
-
cspNonce: string;
|
|
9
|
-
} | undefined>;
|
|
10
|
-
type PageContextCspNonce = Pick<PageContextServer, 'cspNonce'>;
|
|
11
|
-
declare function inferNonceAttr(pageContext: PageContextCspNonce): string;
|
|
12
|
-
declare function addCspHeader(pageContext: PageContextCspNonce, headersResponse: Headers): void;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
export { resolvePageContextCspNone };
|
|
2
|
-
export { inferNonceAttr };
|
|
3
|
-
export { addCspHeader };
|
|
4
|
-
import { import_ } from '@brillout/import';
|
|
5
|
-
async function resolvePageContextCspNone(pageContext) {
|
|
6
|
-
if (pageContext.cspNonce)
|
|
7
|
-
return; // already set by user e.g. `renderPage({ cspNonce: '123456789' })`
|
|
8
|
-
const { csp } = pageContext.config;
|
|
9
|
-
if (!csp?.nonce)
|
|
10
|
-
return;
|
|
11
|
-
let cspNonce;
|
|
12
|
-
if (csp.nonce === true) {
|
|
13
|
-
cspNonce = await generateNonce();
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
cspNonce = await csp.nonce(pageContext);
|
|
17
|
-
}
|
|
18
|
-
const pageContextAddendum = { cspNonce };
|
|
19
|
-
return pageContextAddendum;
|
|
20
|
-
}
|
|
21
|
-
// Generate a cryptographically secure nonce for Content Security Policy (CSP).
|
|
22
|
-
// Returns a base64url-encoded nonce string (URL-safe, no padding).
|
|
23
|
-
// https://github.com/vikejs/vike/issues/1554#issuecomment-3181128304
|
|
24
|
-
async function generateNonce() {
|
|
25
|
-
let cryptoModule;
|
|
26
|
-
try {
|
|
27
|
-
cryptoModule = (await import_('crypto')).default;
|
|
28
|
-
}
|
|
29
|
-
catch {
|
|
30
|
-
return Math.random().toString(36).substring(2, 18);
|
|
31
|
-
}
|
|
32
|
-
return cryptoModule.randomBytes(16).toString('base64url');
|
|
33
|
-
}
|
|
34
|
-
function inferNonceAttr(pageContext) {
|
|
35
|
-
const nonceAttr = pageContext.cspNonce ? ` nonce="${pageContext.cspNonce}"` : '';
|
|
36
|
-
return nonceAttr;
|
|
37
|
-
}
|
|
38
|
-
function addCspHeader(pageContext, headersResponse) {
|
|
39
|
-
if (!pageContext.cspNonce)
|
|
40
|
-
return;
|
|
41
|
-
if (headersResponse.get('Content-Security-Policy'))
|
|
42
|
-
return;
|
|
43
|
-
headersResponse.set('Content-Security-Policy', `script-src 'self' 'nonce-${pageContext.cspNonce}'`);
|
|
44
|
-
}
|