vike 0.4.171-commit-e429162 → 0.4.171-commit-2e4e1ce
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/plugin/plugins/extractAssetsPlugin.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +1 -1
- package/dist/cjs/node/plugin/shared/addSsrMiddleware.js +9 -2
- package/dist/cjs/node/runtime/html/renderHtml.js +1 -11
- package/dist/cjs/node/runtime/html/stream.js +9 -9
- package/dist/cjs/node/runtime/renderPage/getHttpResponseBody.js +2 -2
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +6 -5
- package/dist/cjs/node/runtime/renderPage.js +17 -13
- package/dist/cjs/node/runtime/utils.js +1 -0
- package/dist/cjs/shared/getPageFiles/getExports.js +10 -10
- package/dist/cjs/shared/hooks/executeHook.js +10 -6
- package/dist/cjs/shared/page-configs/serialize/parseConfigValuesImported.js +1 -1
- package/dist/cjs/shared/sortPageContext.js +4 -8
- package/dist/cjs/utils/escapeHtml.js +14 -0
- package/dist/cjs/utils/objectKeys.js +8 -4
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.js +1 -1
- package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +1 -1
- package/dist/esm/node/plugin/shared/addSsrMiddleware.js +9 -2
- package/dist/esm/node/runtime/html/renderHtml.js +1 -11
- package/dist/esm/node/runtime/html/stream.d.ts +1 -1
- package/dist/esm/node/runtime/html/stream.js +9 -9
- package/dist/esm/node/runtime/renderPage/getHttpResponseBody.js +2 -2
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +10 -5
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +6 -5
- package/dist/esm/node/runtime/renderPage.js +17 -13
- package/dist/esm/node/runtime/utils.d.ts +1 -0
- package/dist/esm/node/runtime/utils.js +1 -0
- package/dist/esm/shared/VikeNamespace.d.ts +9 -0
- package/dist/esm/shared/getPageFiles/getExports.d.ts +5 -5
- package/dist/esm/shared/getPageFiles/getExports.js +10 -10
- package/dist/esm/shared/hooks/executeHook.d.ts +6 -1
- package/dist/esm/shared/hooks/executeHook.js +10 -6
- package/dist/esm/shared/page-configs/Config/PageContextConfig.d.ts +2 -2
- package/dist/esm/shared/page-configs/PageConfig.d.ts +4 -4
- package/dist/esm/shared/page-configs/serialize/PageConfigSerialized.d.ts +2 -2
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.js +1 -1
- package/dist/esm/shared/sortPageContext.js +4 -8
- package/dist/esm/utils/escapeHtml.d.ts +1 -0
- package/dist/esm/utils/escapeHtml.js +10 -0
- package/dist/esm/utils/objectKeys.d.ts +1 -3
- package/dist/esm/utils/objectKeys.js +8 -4
- package/dist/esm/utils/projectInfo.d.ts +2 -2
- package/dist/esm/utils/projectInfo.js +1 -1
- package/package.json +1 -1
|
@@ -102,7 +102,7 @@ function extractAssetsPlugin() {
|
|
|
102
102
|
}
|
|
103
103
|
// If the import path resolves to a file in `node_modules/`, we ignore that file:
|
|
104
104
|
// - Direct CSS dependencies are included though, such as `import 'bootstrap/theme/dark.css'`. (Because the above if-branch for CSS files will add the file.)
|
|
105
|
-
// - Loading CSS from a library (living in `node_modules/`) in a non-direct way is
|
|
105
|
+
// - Loading CSS from a library (living in `node_modules/`) in a non-direct way is unconventional; we can safely not support this case. (I'm not aware of any library that does this.)
|
|
106
106
|
(0, utils_js_1.assertPosixPath)(file);
|
|
107
107
|
if (file.includes('/node_modules/')) {
|
|
108
108
|
return emptyModule(file, importer);
|
|
@@ -898,7 +898,7 @@ function getConfigValues(configValueSources, configValuesComputed, configDefinit
|
|
|
898
898
|
const configValueSource = sources[0];
|
|
899
899
|
if ('value' in configValueSource) {
|
|
900
900
|
configValues[configName] = {
|
|
901
|
-
type: '
|
|
901
|
+
type: 'standard',
|
|
902
902
|
value: configValueSource.value,
|
|
903
903
|
definedAtData: getDefinedAtFile(configValueSource)
|
|
904
904
|
};
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.addSsrMiddleware = void 0;
|
|
4
4
|
const renderPage_js_1 = require("../../runtime/renderPage.js");
|
|
5
|
+
const utils_js_1 = require("../utils.js");
|
|
5
6
|
function addSsrMiddleware(middlewares) {
|
|
6
7
|
middlewares.use(async (req, res, next) => {
|
|
7
8
|
if (res.headersSent)
|
|
@@ -10,10 +11,16 @@ function addSsrMiddleware(middlewares) {
|
|
|
10
11
|
if (!url)
|
|
11
12
|
return next();
|
|
12
13
|
const { headers } = req;
|
|
13
|
-
const userAgent = headers['user-agent'];
|
|
14
14
|
const pageContextInit = {
|
|
15
15
|
urlOriginal: url,
|
|
16
|
-
userAgent
|
|
16
|
+
get userAgent() {
|
|
17
|
+
(0, utils_js_1.assertWarning)(false, "pageContext.userAgent is deprecated in favor of pageContext.headers['user-agent']", {
|
|
18
|
+
showStackTrace: true,
|
|
19
|
+
onlyOnce: true
|
|
20
|
+
});
|
|
21
|
+
return headers['user-agent'];
|
|
22
|
+
},
|
|
23
|
+
headers
|
|
17
24
|
};
|
|
18
25
|
let pageContext;
|
|
19
26
|
try {
|
|
@@ -198,7 +198,7 @@ async function renderTemplate(templateContent, pageContext) {
|
|
|
198
198
|
}
|
|
199
199
|
}
|
|
200
200
|
// Escape untrusted template variable
|
|
201
|
-
addHtmlPart(escapeHtml(templateVar));
|
|
201
|
+
addHtmlPart((0, utils_js_1.escapeHtml)(templateVar));
|
|
202
202
|
}
|
|
203
203
|
(0, utils_js_1.assert)(templateStrings.length === templateVariables.length + 1);
|
|
204
204
|
addHtmlPart(templateStrings[templateStrings.length - 1]);
|
|
@@ -214,16 +214,6 @@ async function renderTemplate(templateContent, pageContext) {
|
|
|
214
214
|
htmlPartsEnd
|
|
215
215
|
};
|
|
216
216
|
}
|
|
217
|
-
function escapeHtml(unsafeString) {
|
|
218
|
-
// Source: https://stackoverflow.com/questions/6234773/can-i-escape-html-special-chars-in-javascript/6234804#6234804
|
|
219
|
-
const safe = unsafeString
|
|
220
|
-
.replace(/&/g, '&')
|
|
221
|
-
.replace(/</g, '<')
|
|
222
|
-
.replace(/>/g, '>')
|
|
223
|
-
.replace(/"/g, '"')
|
|
224
|
-
.replace(/'/g, ''');
|
|
225
|
-
return safe;
|
|
226
|
-
}
|
|
227
217
|
async function getHtmlString(htmlRender) {
|
|
228
218
|
if (typeof htmlRender === 'string') {
|
|
229
219
|
return htmlRender;
|
|
@@ -762,17 +762,17 @@ async function loadStreamNodeModule() {
|
|
|
762
762
|
const { Readable, Writable } = streamModule;
|
|
763
763
|
return { Readable, Writable };
|
|
764
764
|
}
|
|
765
|
-
function getStreamName(
|
|
766
|
-
let
|
|
767
|
-
if (
|
|
768
|
-
|
|
765
|
+
function getStreamName(kind, type) {
|
|
766
|
+
let typeName = (0, utils_js_1.capitalizeFirstLetter)(type);
|
|
767
|
+
if (typeName === 'Node') {
|
|
768
|
+
typeName = 'Node.js';
|
|
769
769
|
}
|
|
770
|
-
const
|
|
771
|
-
if (
|
|
772
|
-
return `a ${
|
|
770
|
+
const kindName = (0, utils_js_1.capitalizeFirstLetter)(kind);
|
|
771
|
+
if (kind !== 'pipe') {
|
|
772
|
+
return `a ${kindName} ${typeName} Stream`;
|
|
773
773
|
}
|
|
774
|
-
if (
|
|
775
|
-
return `a ${
|
|
774
|
+
if (kind === 'pipe') {
|
|
775
|
+
return `a ${typeName} Stream Pipe`;
|
|
776
776
|
}
|
|
777
777
|
(0, utils_js_1.assert)(false);
|
|
778
778
|
}
|
|
@@ -100,8 +100,8 @@ function getHttpResponseBodyStreamHandlers(htmlRender, renderHook) {
|
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
};
|
|
103
|
-
function getFixMsg(
|
|
104
|
-
const streamName = (0, stream_js_1.getStreamName)(
|
|
103
|
+
function getFixMsg(kind, type) {
|
|
104
|
+
const streamName = (0, stream_js_1.getStreamName)(kind, type);
|
|
105
105
|
(0, utils_js_1.assert)(['a ', 'an ', 'the '].some((s) => streamName.startsWith(s)));
|
|
106
106
|
(0, utils_js_1.assert)(renderHook);
|
|
107
107
|
const { hookFilePath, hookName } = renderHook;
|
|
@@ -109,9 +109,9 @@ async function prerender404Page(renderContext, pageContextInit_) {
|
|
|
109
109
|
_debugRouteMatches: []
|
|
110
110
|
};
|
|
111
111
|
const pageContextInit = {
|
|
112
|
-
urlOriginal: '/fake-404-url'
|
|
113
|
-
...pageContextInit_
|
|
112
|
+
urlOriginal: '/fake-404-url' // A URL is needed for `applyViteHtmlTransform`
|
|
114
113
|
};
|
|
114
|
+
(0, utils_js_1.objectAssign)(pageContextInit, pageContextInit_);
|
|
115
115
|
{
|
|
116
116
|
const pageContextInitEnhanced = getPageContextInitEnhanced(pageContextInit, renderContext);
|
|
117
117
|
(0, utils_js_1.objectAssign)(pageContext, pageContextInitEnhanced);
|
|
@@ -127,8 +127,9 @@ function getPageContextInitEnhanced(pageContextInit, renderContext, { urlCompute
|
|
|
127
127
|
} } = {}) {
|
|
128
128
|
(0, utils_js_1.assert)(pageContextInit.urlOriginal);
|
|
129
129
|
const globalContext = (0, globalContext_js_1.getGlobalContext)();
|
|
130
|
-
const pageContextInitEnhanced = {
|
|
131
|
-
|
|
130
|
+
const pageContextInitEnhanced = {};
|
|
131
|
+
(0, utils_js_1.objectAssign)(pageContextInitEnhanced, pageContextInit);
|
|
132
|
+
(0, utils_js_1.objectAssign)(pageContextInitEnhanced, {
|
|
132
133
|
_objectCreatedByVike: true,
|
|
133
134
|
// The following is defined on `pageContext` because we can eventually make these non-global (e.g. sot that two pages can have different includeAssetsImportedByServer settings)
|
|
134
135
|
_baseServer: globalContext.baseServer,
|
|
@@ -145,7 +146,7 @@ function getPageContextInitEnhanced(pageContextInit, renderContext, { urlCompute
|
|
|
145
146
|
_urlRewrite: urlRewrite,
|
|
146
147
|
_urlHandler: urlHandler,
|
|
147
148
|
isClientSideNavigation
|
|
148
|
-
};
|
|
149
|
+
});
|
|
149
150
|
(0, addUrlComputedProps_js_1.addUrlComputedProps)(pageContextInitEnhanced, !urlComputedPropsNonEnumerable);
|
|
150
151
|
return pageContextInitEnhanced;
|
|
151
152
|
}
|
|
@@ -289,12 +289,13 @@ async function renderPageNominal(pageContext) {
|
|
|
289
289
|
async function getPageContextErrorPageInit(pageContextInit, errNominalPage, pageContextNominalPagePartial, renderContext, httpRequestId) {
|
|
290
290
|
const pageContextInitEnhanced = getPageContextInitEnhancedSSR(pageContextInit, renderContext, null, httpRequestId);
|
|
291
291
|
(0, utils_js_1.assert)(errNominalPage);
|
|
292
|
-
const pageContext = {
|
|
293
|
-
|
|
292
|
+
const pageContext = {};
|
|
293
|
+
(0, utils_js_1.objectAssign)(pageContext, pageContextInitEnhanced);
|
|
294
|
+
(0, utils_js_1.objectAssign)(pageContext, {
|
|
294
295
|
is404: false,
|
|
295
296
|
errorWhileRendering: errNominalPage,
|
|
296
297
|
routeParams: {}
|
|
297
|
-
};
|
|
298
|
+
});
|
|
298
299
|
(0, utils_js_1.objectAssign)(pageContext, {
|
|
299
300
|
_debugRouteMatches: pageContextNominalPagePartial._debugRouteMatches || 'ROUTING_ERROR'
|
|
300
301
|
});
|
|
@@ -346,7 +347,9 @@ function normalizeUrl(pageContextInit, httpRequestId) {
|
|
|
346
347
|
return null;
|
|
347
348
|
(0, loggerRuntime_js_1.logRuntimeInfo)?.(`URL normalized from ${picocolors_1.default.cyan(urlOriginal)} to ${picocolors_1.default.cyan(urlNormalized)} (https://vike.dev/url-normalization)`, httpRequestId, 'info');
|
|
348
349
|
const httpResponse = (0, createHttpResponseObject_js_1.createHttpResponseObjectRedirect)({ url: urlNormalized, statusCode: 301 }, pageContextInit.urlOriginal);
|
|
349
|
-
const pageContextHttpResponse = {
|
|
350
|
+
const pageContextHttpResponse = {};
|
|
351
|
+
(0, utils_js_1.objectAssign)(pageContextHttpResponse, pageContextInit);
|
|
352
|
+
(0, utils_js_1.objectAssign)(pageContextHttpResponse, { httpResponse });
|
|
350
353
|
return pageContextHttpResponse;
|
|
351
354
|
}
|
|
352
355
|
function getPermanentRedirect(pageContextInit, httpRequestId) {
|
|
@@ -381,7 +384,9 @@ function getPermanentRedirect(pageContextInit, httpRequestId) {
|
|
|
381
384
|
}
|
|
382
385
|
(0, loggerRuntime_js_1.logRuntimeInfo)?.(`Permanent redirect defined by your config.redirects (https://vike.dev/redirects)`, httpRequestId, 'info');
|
|
383
386
|
const httpResponse = (0, createHttpResponseObject_js_1.createHttpResponseObjectRedirect)({ url: urlTarget, statusCode: 301 }, urlWithoutBase);
|
|
384
|
-
const pageContextHttpResponse = {
|
|
387
|
+
const pageContextHttpResponse = {};
|
|
388
|
+
(0, utils_js_1.objectAssign)(pageContextHttpResponse, pageContextInit);
|
|
389
|
+
(0, utils_js_1.objectAssign)(pageContextHttpResponse, { httpResponse });
|
|
385
390
|
return pageContextHttpResponse;
|
|
386
391
|
}
|
|
387
392
|
async function handleAbortError(errAbort, pageContextsFromRewrite, pageContextInit,
|
|
@@ -397,11 +402,11 @@ pageContextNominalPageInit, httpRequestId, renderContext, pageContextErrorPageIn
|
|
|
397
402
|
(0, utils_js_1.assert)(abortCall);
|
|
398
403
|
(0, utils_js_1.assertUsage)(errorPageId, `You called ${picocolors_1.default.cyan(abortCall)} but you didn't define an error page, make sure to define one https://vike.dev/error-page`);
|
|
399
404
|
const pageContext = {
|
|
400
|
-
_pageId: errorPageId
|
|
401
|
-
...pageContextAbort,
|
|
402
|
-
...pageContextErrorPageInit,
|
|
403
|
-
...renderContext
|
|
405
|
+
_pageId: errorPageId
|
|
404
406
|
};
|
|
407
|
+
(0, utils_js_1.objectAssign)(pageContext, pageContextAbort);
|
|
408
|
+
(0, utils_js_1.objectAssign)(pageContext, pageContextErrorPageInit);
|
|
409
|
+
(0, utils_js_1.objectAssign)(pageContext, renderContext);
|
|
405
410
|
(0, utils_js_1.objectAssign)(pageContext, await (0, loadUserFilesServerSide_js_1.loadUserFilesServerSide)(pageContext));
|
|
406
411
|
// We include pageContextInit: we don't only serialize pageContextAbort because the error page may need to access pageContextInit
|
|
407
412
|
pageContextSerialized = (0, serializePageContextClientSide_js_1.serializePageContextClientSide)(pageContext);
|
|
@@ -422,10 +427,9 @@ pageContextNominalPageInit, httpRequestId, renderContext, pageContextErrorPageIn
|
|
|
422
427
|
return { pageContextReturn };
|
|
423
428
|
}
|
|
424
429
|
if (pageContextAbort._urlRedirect) {
|
|
425
|
-
const pageContextReturn = {
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
};
|
|
430
|
+
const pageContextReturn = {};
|
|
431
|
+
(0, utils_js_1.objectAssign)(pageContextReturn, pageContextInit);
|
|
432
|
+
(0, utils_js_1.objectAssign)(pageContextReturn, pageContextAbort);
|
|
429
433
|
const httpResponse = (0, createHttpResponseObject_js_1.createHttpResponseObjectRedirect)(pageContextAbort._urlRedirect, (() => {
|
|
430
434
|
const { pathname, searchOriginal } = pageContextNominalPageInit.urlParsed;
|
|
431
435
|
const urlLogical = (0, utils_js_1.createUrlFromComponents)(null, pathname, searchOriginal,
|
|
@@ -68,3 +68,4 @@ __exportStar(require("../../utils/truncateString.js"), exports);
|
|
|
68
68
|
__exportStar(require("../../utils/formatHintLog.js"), exports);
|
|
69
69
|
__exportStar(require("../../utils/joinEnglish.js"), exports);
|
|
70
70
|
__exportStar(require("../../utils/isArrayOfStrings.js"), exports);
|
|
71
|
+
__exportStar(require("../../utils/escapeHtml.js"), exports);
|
|
@@ -40,7 +40,7 @@ function getPageContextExports(pageFiles, pageConfig) {
|
|
|
40
40
|
sources[configName].push(src);
|
|
41
41
|
};
|
|
42
42
|
const from = {
|
|
43
|
-
|
|
43
|
+
configsStandard: {},
|
|
44
44
|
configsCumulative: {},
|
|
45
45
|
configsComputed: {}
|
|
46
46
|
};
|
|
@@ -58,6 +58,15 @@ function getPageContextExports(pageFiles, pageConfig) {
|
|
|
58
58
|
configDefinedAt,
|
|
59
59
|
configDefinedByFile: configValueFilePathToShowToUser
|
|
60
60
|
});
|
|
61
|
+
if (configValue.type === 'standard') {
|
|
62
|
+
const src = {
|
|
63
|
+
type: 'configsStandard',
|
|
64
|
+
value: configValue.value,
|
|
65
|
+
definedAt: (0, getConfigDefinedAt_js_1.getDefinedAtString)(configValue.definedAtData, configName)
|
|
66
|
+
};
|
|
67
|
+
addSrc(src, configName);
|
|
68
|
+
from.configsStandard[configName] = src;
|
|
69
|
+
}
|
|
61
70
|
if (configValue.type === 'cumulative') {
|
|
62
71
|
const src = {
|
|
63
72
|
type: 'configsCumulative',
|
|
@@ -74,15 +83,6 @@ function getPageContextExports(pageFiles, pageConfig) {
|
|
|
74
83
|
addSrc(src, configName);
|
|
75
84
|
from.configsCumulative[configName] = src;
|
|
76
85
|
}
|
|
77
|
-
if (configValue.type === 'classic') {
|
|
78
|
-
const src = {
|
|
79
|
-
type: 'configsOverridable',
|
|
80
|
-
value: configValue.value,
|
|
81
|
-
definedAt: (0, getConfigDefinedAt_js_1.getDefinedAtString)(configValue.definedAtData, configName)
|
|
82
|
-
};
|
|
83
|
-
addSrc(src, configName);
|
|
84
|
-
from.configsOverridable[configName] = src;
|
|
85
|
-
}
|
|
86
86
|
if (configValue.type === 'computed') {
|
|
87
87
|
const src = {
|
|
88
88
|
type: 'configsComputed',
|
|
@@ -5,7 +5,6 @@ const assert_js_1 = require("../../utils/assert.js");
|
|
|
5
5
|
const getGlobalObject_js_1 = require("../../utils/getGlobalObject.js");
|
|
6
6
|
const humanizeTime_js_1 = require("../../utils/humanizeTime.js");
|
|
7
7
|
const isObject_js_1 = require("../../utils/isObject.js");
|
|
8
|
-
const utils_js_1 = require("../utils.js");
|
|
9
8
|
const globalObject = (0, getGlobalObject_js_1.getGlobalObject)('utils/executeHook.ts', {
|
|
10
9
|
userHookErrors: new WeakMap(),
|
|
11
10
|
pageContext: null
|
|
@@ -64,15 +63,20 @@ exports.executeHook = executeHook;
|
|
|
64
63
|
function isNotDisabled(timeout) {
|
|
65
64
|
return !!timeout && timeout !== Infinity;
|
|
66
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Access `pageContext` object inside Vike hooks, in order to create universal hooks.
|
|
68
|
+
*
|
|
69
|
+
* https://vike.dev/getPageContext
|
|
70
|
+
*/
|
|
67
71
|
function getPageContext() {
|
|
68
72
|
return globalObject.pageContext;
|
|
69
73
|
}
|
|
70
74
|
exports.getPageContext = getPageContext;
|
|
71
75
|
function providePageContext(pageContext) {
|
|
72
76
|
globalObject.pageContext = pageContext;
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
77
|
+
// Promise.resolve() is quicker than process.nextTick() and setImmediate()
|
|
78
|
+
// https://stackoverflow.com/questions/67949576/process-nexttick-before-promise-resolve-then
|
|
79
|
+
Promise.resolve().then(() => {
|
|
80
|
+
globalObject.pageContext = null;
|
|
81
|
+
});
|
|
78
82
|
}
|
|
@@ -53,7 +53,7 @@ function parseConfigValuesImported(configValuesImported) {
|
|
|
53
53
|
(0, utils_js_1.assert)(val);
|
|
54
54
|
const { value, importPath, exportName } = val;
|
|
55
55
|
configValues[configName] = {
|
|
56
|
-
type: '
|
|
56
|
+
type: 'standard',
|
|
57
57
|
value,
|
|
58
58
|
definedAtData: {
|
|
59
59
|
// importPath cannot be relative to the current file, since the current file is a virtual file
|
|
@@ -4,14 +4,10 @@ exports.sortPageContext = void 0;
|
|
|
4
4
|
const utils_js_1 = require("./utils.js");
|
|
5
5
|
// Sort `pageContext` keys alphabetically, in order to make reading `console.log(pageContext)` easier
|
|
6
6
|
function sortPageContext(pageContext) {
|
|
7
|
-
|
|
8
|
-
for (const key
|
|
7
|
+
let descriptors = Object.getOwnPropertyDescriptors(pageContext);
|
|
8
|
+
for (const key of Object.keys(pageContext))
|
|
9
9
|
delete pageContext[key];
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
.sort(([key1], [key2]) => (0, utils_js_1.compareString)(key1, key2))
|
|
13
|
-
.forEach(([key, val]) => {
|
|
14
|
-
pageContext[key] = val;
|
|
15
|
-
});
|
|
10
|
+
descriptors = Object.fromEntries(Object.entries(descriptors).sort(([key1], [key2]) => (0, utils_js_1.compareString)(key1, key2)));
|
|
11
|
+
Object.defineProperties(pageContext, descriptors);
|
|
16
12
|
}
|
|
17
13
|
exports.sortPageContext = sortPageContext;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.escapeHtml = void 0;
|
|
4
|
+
// Copied from https://stackoverflow.com/questions/6234773/can-i-escape-html-special-chars-in-javascript/6234804#6234804
|
|
5
|
+
function escapeHtml(unsafeString) {
|
|
6
|
+
const safe = unsafeString
|
|
7
|
+
.replace(/&/g, '&')
|
|
8
|
+
.replace(/</g, '<')
|
|
9
|
+
.replace(/>/g, '>')
|
|
10
|
+
.replace(/"/g, '"')
|
|
11
|
+
.replace(/'/g, ''');
|
|
12
|
+
return safe;
|
|
13
|
+
}
|
|
14
|
+
exports.escapeHtml = escapeHtml;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.objectKeys = exports.objectFromEntries = exports.objectEntries = void 0;
|
|
4
|
+
// export { forEach }
|
|
4
5
|
// https://stackoverflow.com/questions/60141960/typescript-key-value-relation-preserving-object-entries-type/75337277#75337277
|
|
5
6
|
/** Same as Object.entries() but with type inference */
|
|
6
7
|
function objectEntries(obj) {
|
|
@@ -19,8 +20,11 @@ function objectKeys(obj) {
|
|
|
19
20
|
return Object.keys(obj);
|
|
20
21
|
}
|
|
21
22
|
exports.objectKeys = objectKeys;
|
|
22
|
-
/*
|
|
23
|
-
function
|
|
24
|
-
|
|
23
|
+
/* Not used yet, but can be quite useful.
|
|
24
|
+
function forEach<Obj extends object>(
|
|
25
|
+
obj: Obj,
|
|
26
|
+
iterator: <Key extends keyof Obj>(key: Key, val: Obj[Key]) => void
|
|
27
|
+
): void {
|
|
28
|
+
Object.entries(obj).forEach(([key, val]) => iterator(key as keyof Obj, val))
|
|
25
29
|
}
|
|
26
|
-
|
|
30
|
+
//*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PROJECT_VERSION = exports.projectInfo = void 0;
|
|
4
|
-
const PROJECT_VERSION = '0.4.171-commit-
|
|
4
|
+
const PROJECT_VERSION = '0.4.171-commit-2e4e1ce';
|
|
5
5
|
exports.PROJECT_VERSION = PROJECT_VERSION;
|
|
6
6
|
const projectInfo = {
|
|
7
7
|
projectName: 'Vike',
|
|
@@ -221,7 +221,7 @@ async function fetchPageContextFromServer(pageContext) {
|
|
|
221
221
|
}
|
|
222
222
|
// Is there a reason for having two different properties? Can't we use only one property? I guess/think the isServerSideError property was an attempt (a bad idea really) for rendering the error page even though an error occured on the server-side (which is a bad idea because the added complexity is non-negligible while the added value is minuscule since the error page usually doesn't have any (meaningful / server-side) hooks).
|
|
223
223
|
if ('serverSideError' in pageContextFromServer || isServerSideError in pageContextFromServer) {
|
|
224
|
-
throw getProjectError(`
|
|
224
|
+
throw getProjectError(`pageContext couldn't be fetched from server: an error occurred on the server-side (see your server logs)`);
|
|
225
225
|
}
|
|
226
226
|
assert(hasProp(pageContextFromServer, '_pageId', 'string'));
|
|
227
227
|
processPageContextFromServer(pageContextFromServer);
|
|
@@ -101,7 +101,7 @@ function extractAssetsPlugin() {
|
|
|
101
101
|
}
|
|
102
102
|
// If the import path resolves to a file in `node_modules/`, we ignore that file:
|
|
103
103
|
// - Direct CSS dependencies are included though, such as `import 'bootstrap/theme/dark.css'`. (Because the above if-branch for CSS files will add the file.)
|
|
104
|
-
// - Loading CSS from a library (living in `node_modules/`) in a non-direct way is
|
|
104
|
+
// - Loading CSS from a library (living in `node_modules/`) in a non-direct way is unconventional; we can safely not support this case. (I'm not aware of any library that does this.)
|
|
105
105
|
assertPosixPath(file);
|
|
106
106
|
if (file.includes('/node_modules/')) {
|
|
107
107
|
return emptyModule(file, importer);
|
|
@@ -892,7 +892,7 @@ function getConfigValues(configValueSources, configValuesComputed, configDefinit
|
|
|
892
892
|
const configValueSource = sources[0];
|
|
893
893
|
if ('value' in configValueSource) {
|
|
894
894
|
configValues[configName] = {
|
|
895
|
-
type: '
|
|
895
|
+
type: 'standard',
|
|
896
896
|
value: configValueSource.value,
|
|
897
897
|
definedAtData: getDefinedAtFile(configValueSource)
|
|
898
898
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { addSsrMiddleware };
|
|
2
2
|
import { renderPage } from '../../runtime/renderPage.js';
|
|
3
|
+
import { assertWarning } from '../utils.js';
|
|
3
4
|
function addSsrMiddleware(middlewares) {
|
|
4
5
|
middlewares.use(async (req, res, next) => {
|
|
5
6
|
if (res.headersSent)
|
|
@@ -8,10 +9,16 @@ function addSsrMiddleware(middlewares) {
|
|
|
8
9
|
if (!url)
|
|
9
10
|
return next();
|
|
10
11
|
const { headers } = req;
|
|
11
|
-
const userAgent = headers['user-agent'];
|
|
12
12
|
const pageContextInit = {
|
|
13
13
|
urlOriginal: url,
|
|
14
|
-
userAgent
|
|
14
|
+
get userAgent() {
|
|
15
|
+
assertWarning(false, "pageContext.userAgent is deprecated in favor of pageContext.headers['user-agent']", {
|
|
16
|
+
showStackTrace: true,
|
|
17
|
+
onlyOnce: true
|
|
18
|
+
});
|
|
19
|
+
return headers['user-agent'];
|
|
20
|
+
},
|
|
21
|
+
headers
|
|
15
22
|
};
|
|
16
23
|
let pageContext;
|
|
17
24
|
try {
|
|
@@ -3,7 +3,7 @@ export { dangerouslySkipEscape };
|
|
|
3
3
|
export { renderDocumentHtml };
|
|
4
4
|
export { isDocumentHtml };
|
|
5
5
|
export { getHtmlString };
|
|
6
|
-
import { assert, assertUsage, assertWarning, checkType, hasProp, isHtml, isPromise, objectAssign } from '../utils.js';
|
|
6
|
+
import { assert, assertUsage, assertWarning, checkType, escapeHtml, hasProp, isHtml, isPromise, objectAssign } from '../utils.js';
|
|
7
7
|
import { injectHtmlTagsToString, injectHtmlTagsToStream } from './injectAssets.js';
|
|
8
8
|
import { processStream, isStream, streamToString } from './stream.js';
|
|
9
9
|
import { isStreamReactStreaming } from './stream/react-streaming.js';
|
|
@@ -209,16 +209,6 @@ async function renderTemplate(templateContent, pageContext) {
|
|
|
209
209
|
htmlPartsEnd
|
|
210
210
|
};
|
|
211
211
|
}
|
|
212
|
-
function escapeHtml(unsafeString) {
|
|
213
|
-
// Source: https://stackoverflow.com/questions/6234773/can-i-escape-html-special-chars-in-javascript/6234804#6234804
|
|
214
|
-
const safe = unsafeString
|
|
215
|
-
.replace(/&/g, '&')
|
|
216
|
-
.replace(/</g, '<')
|
|
217
|
-
.replace(/>/g, '>')
|
|
218
|
-
.replace(/"/g, '"')
|
|
219
|
-
.replace(/'/g, ''');
|
|
220
|
-
return safe;
|
|
221
|
-
}
|
|
222
212
|
async function getHtmlString(htmlRender) {
|
|
223
213
|
if (typeof htmlRender === 'string') {
|
|
224
214
|
return htmlRender;
|
|
@@ -80,5 +80,5 @@ type StreamPipeWrapped = {
|
|
|
80
80
|
};
|
|
81
81
|
declare function pipeStream(pipe: StreamPipe): StreamPipeWrapped;
|
|
82
82
|
declare function streamToString(stream: StreamProviderAny): Promise<string>;
|
|
83
|
-
declare function getStreamName(
|
|
83
|
+
declare function getStreamName(kind: 'pipe' | 'readable' | 'writable', type: 'web' | 'node'): `a ${string} Stream` | `a ${string} Stream Pipe`;
|
|
84
84
|
declare function inferStreamName(stream: StreamProviderNormalized): `a ${string} Stream` | `a ${string} Stream Pipe`;
|
|
@@ -758,17 +758,17 @@ async function loadStreamNodeModule() {
|
|
|
758
758
|
const { Readable, Writable } = streamModule;
|
|
759
759
|
return { Readable, Writable };
|
|
760
760
|
}
|
|
761
|
-
function getStreamName(
|
|
762
|
-
let
|
|
763
|
-
if (
|
|
764
|
-
|
|
761
|
+
function getStreamName(kind, type) {
|
|
762
|
+
let typeName = capitalizeFirstLetter(type);
|
|
763
|
+
if (typeName === 'Node') {
|
|
764
|
+
typeName = 'Node.js';
|
|
765
765
|
}
|
|
766
|
-
const
|
|
767
|
-
if (
|
|
768
|
-
return `a ${
|
|
766
|
+
const kindName = capitalizeFirstLetter(kind);
|
|
767
|
+
if (kind !== 'pipe') {
|
|
768
|
+
return `a ${kindName} ${typeName} Stream`;
|
|
769
769
|
}
|
|
770
|
-
if (
|
|
771
|
-
return `a ${
|
|
770
|
+
if (kind === 'pipe') {
|
|
771
|
+
return `a ${typeName} Stream Pipe`;
|
|
772
772
|
}
|
|
773
773
|
assert(false);
|
|
774
774
|
}
|
|
@@ -95,8 +95,8 @@ function getHttpResponseBodyStreamHandlers(htmlRender, renderHook) {
|
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
};
|
|
98
|
-
function getFixMsg(
|
|
99
|
-
const streamName = getStreamName(
|
|
98
|
+
function getFixMsg(kind, type) {
|
|
99
|
+
const streamName = getStreamName(kind, type);
|
|
100
100
|
assert(['a ', 'an ', 'the '].some((s) => streamName.startsWith(s)));
|
|
101
101
|
assert(renderHook);
|
|
102
102
|
const { hookFilePath, hookName } = renderHook;
|
|
@@ -37,6 +37,8 @@ declare function prerenderPage(pageContext: PageContextInitEnhanced & PageFiles
|
|
|
37
37
|
documentHtml: string;
|
|
38
38
|
pageContextSerialized: null;
|
|
39
39
|
pageContext: {
|
|
40
|
+
urlOriginal: string;
|
|
41
|
+
} & {
|
|
40
42
|
_objectCreatedByVike: boolean;
|
|
41
43
|
_baseServer: string;
|
|
42
44
|
_baseAssets: string | null;
|
|
@@ -53,7 +55,6 @@ declare function prerenderPage(pageContext: PageContextInitEnhanced & PageFiles
|
|
|
53
55
|
_urlRewrite: string | null;
|
|
54
56
|
_urlHandler: ((url: string) => string) | null;
|
|
55
57
|
isClientSideNavigation: boolean;
|
|
56
|
-
urlOriginal: string;
|
|
57
58
|
} & import("../../../shared/addUrlComputedProps.js").PageContextUrlComputedPropsClient & {
|
|
58
59
|
_urlRewrite: string | null;
|
|
59
60
|
} & {
|
|
@@ -87,6 +88,8 @@ declare function prerenderPage(pageContext: PageContextInitEnhanced & PageFiles
|
|
|
87
88
|
documentHtml: string;
|
|
88
89
|
pageContextSerialized: string;
|
|
89
90
|
pageContext: {
|
|
91
|
+
urlOriginal: string;
|
|
92
|
+
} & {
|
|
90
93
|
_objectCreatedByVike: boolean;
|
|
91
94
|
_baseServer: string;
|
|
92
95
|
_baseAssets: string | null;
|
|
@@ -103,7 +106,6 @@ declare function prerenderPage(pageContext: PageContextInitEnhanced & PageFiles
|
|
|
103
106
|
_urlRewrite: string | null;
|
|
104
107
|
_urlHandler: ((url: string) => string) | null;
|
|
105
108
|
isClientSideNavigation: boolean;
|
|
106
|
-
urlOriginal: string;
|
|
107
109
|
} & import("../../../shared/addUrlComputedProps.js").PageContextUrlComputedPropsClient & {
|
|
108
110
|
_urlRewrite: string | null;
|
|
109
111
|
} & {
|
|
@@ -138,6 +140,8 @@ declare function prerender404Page(renderContext: RenderContext, pageContextInit_
|
|
|
138
140
|
documentHtml: string;
|
|
139
141
|
pageContextSerialized: null;
|
|
140
142
|
pageContext: {
|
|
143
|
+
urlOriginal: string;
|
|
144
|
+
} & {
|
|
141
145
|
_objectCreatedByVike: boolean;
|
|
142
146
|
_baseServer: string;
|
|
143
147
|
_baseAssets: string | null;
|
|
@@ -154,7 +158,6 @@ declare function prerender404Page(renderContext: RenderContext, pageContextInit_
|
|
|
154
158
|
_urlRewrite: string | null;
|
|
155
159
|
_urlHandler: ((url: string) => string) | null;
|
|
156
160
|
isClientSideNavigation: boolean;
|
|
157
|
-
urlOriginal: string;
|
|
158
161
|
} & import("../../../shared/addUrlComputedProps.js").PageContextUrlComputedPropsClient & {
|
|
159
162
|
_urlRewrite: string | null;
|
|
160
163
|
} & {
|
|
@@ -188,6 +191,8 @@ declare function prerender404Page(renderContext: RenderContext, pageContextInit_
|
|
|
188
191
|
documentHtml: string;
|
|
189
192
|
pageContextSerialized: string;
|
|
190
193
|
pageContext: {
|
|
194
|
+
urlOriginal: string;
|
|
195
|
+
} & {
|
|
191
196
|
_objectCreatedByVike: boolean;
|
|
192
197
|
_baseServer: string;
|
|
193
198
|
_baseAssets: string | null;
|
|
@@ -204,7 +209,6 @@ declare function prerender404Page(renderContext: RenderContext, pageContextInit_
|
|
|
204
209
|
_urlRewrite: string | null;
|
|
205
210
|
_urlHandler: ((url: string) => string) | null;
|
|
206
211
|
isClientSideNavigation: boolean;
|
|
207
|
-
urlOriginal: string;
|
|
208
212
|
} & import("../../../shared/addUrlComputedProps.js").PageContextUrlComputedPropsClient & {
|
|
209
213
|
_urlRewrite: string | null;
|
|
210
214
|
} & {
|
|
@@ -246,6 +250,8 @@ declare function getPageContextInitEnhanced(pageContextInit: {
|
|
|
246
250
|
isClientSideNavigation: boolean;
|
|
247
251
|
};
|
|
248
252
|
}): {
|
|
253
|
+
urlOriginal: string;
|
|
254
|
+
} & {
|
|
249
255
|
_objectCreatedByVike: boolean;
|
|
250
256
|
_baseServer: string;
|
|
251
257
|
_baseAssets: string | null;
|
|
@@ -262,7 +268,6 @@ declare function getPageContextInitEnhanced(pageContextInit: {
|
|
|
262
268
|
_urlRewrite: string | null;
|
|
263
269
|
_urlHandler: ((url: string) => string) | null;
|
|
264
270
|
isClientSideNavigation: boolean;
|
|
265
|
-
urlOriginal: string;
|
|
266
271
|
} & import("../../../shared/addUrlComputedProps.js").PageContextUrlComputedPropsClient & {
|
|
267
272
|
_urlRewrite: string | null;
|
|
268
273
|
};
|
|
@@ -106,9 +106,9 @@ async function prerender404Page(renderContext, pageContextInit_) {
|
|
|
106
106
|
_debugRouteMatches: []
|
|
107
107
|
};
|
|
108
108
|
const pageContextInit = {
|
|
109
|
-
urlOriginal: '/fake-404-url'
|
|
110
|
-
...pageContextInit_
|
|
109
|
+
urlOriginal: '/fake-404-url' // A URL is needed for `applyViteHtmlTransform`
|
|
111
110
|
};
|
|
111
|
+
objectAssign(pageContextInit, pageContextInit_);
|
|
112
112
|
{
|
|
113
113
|
const pageContextInitEnhanced = getPageContextInitEnhanced(pageContextInit, renderContext);
|
|
114
114
|
objectAssign(pageContext, pageContextInitEnhanced);
|
|
@@ -123,8 +123,9 @@ function getPageContextInitEnhanced(pageContextInit, renderContext, { urlCompute
|
|
|
123
123
|
} } = {}) {
|
|
124
124
|
assert(pageContextInit.urlOriginal);
|
|
125
125
|
const globalContext = getGlobalContext();
|
|
126
|
-
const pageContextInitEnhanced = {
|
|
127
|
-
|
|
126
|
+
const pageContextInitEnhanced = {};
|
|
127
|
+
objectAssign(pageContextInitEnhanced, pageContextInit);
|
|
128
|
+
objectAssign(pageContextInitEnhanced, {
|
|
128
129
|
_objectCreatedByVike: true,
|
|
129
130
|
// The following is defined on `pageContext` because we can eventually make these non-global (e.g. sot that two pages can have different includeAssetsImportedByServer settings)
|
|
130
131
|
_baseServer: globalContext.baseServer,
|
|
@@ -141,7 +142,7 @@ function getPageContextInitEnhanced(pageContextInit, renderContext, { urlCompute
|
|
|
141
142
|
_urlRewrite: urlRewrite,
|
|
142
143
|
_urlHandler: urlHandler,
|
|
143
144
|
isClientSideNavigation
|
|
144
|
-
};
|
|
145
|
+
});
|
|
145
146
|
addUrlComputedProps(pageContextInitEnhanced, !urlComputedPropsNonEnumerable);
|
|
146
147
|
return pageContextInitEnhanced;
|
|
147
148
|
}
|
|
@@ -283,12 +283,13 @@ async function renderPageNominal(pageContext) {
|
|
|
283
283
|
async function getPageContextErrorPageInit(pageContextInit, errNominalPage, pageContextNominalPagePartial, renderContext, httpRequestId) {
|
|
284
284
|
const pageContextInitEnhanced = getPageContextInitEnhancedSSR(pageContextInit, renderContext, null, httpRequestId);
|
|
285
285
|
assert(errNominalPage);
|
|
286
|
-
const pageContext = {
|
|
287
|
-
|
|
286
|
+
const pageContext = {};
|
|
287
|
+
objectAssign(pageContext, pageContextInitEnhanced);
|
|
288
|
+
objectAssign(pageContext, {
|
|
288
289
|
is404: false,
|
|
289
290
|
errorWhileRendering: errNominalPage,
|
|
290
291
|
routeParams: {}
|
|
291
|
-
};
|
|
292
|
+
});
|
|
292
293
|
objectAssign(pageContext, {
|
|
293
294
|
_debugRouteMatches: pageContextNominalPagePartial._debugRouteMatches || 'ROUTING_ERROR'
|
|
294
295
|
});
|
|
@@ -340,7 +341,9 @@ function normalizeUrl(pageContextInit, httpRequestId) {
|
|
|
340
341
|
return null;
|
|
341
342
|
logRuntimeInfo?.(`URL normalized from ${pc.cyan(urlOriginal)} to ${pc.cyan(urlNormalized)} (https://vike.dev/url-normalization)`, httpRequestId, 'info');
|
|
342
343
|
const httpResponse = createHttpResponseObjectRedirect({ url: urlNormalized, statusCode: 301 }, pageContextInit.urlOriginal);
|
|
343
|
-
const pageContextHttpResponse = {
|
|
344
|
+
const pageContextHttpResponse = {};
|
|
345
|
+
objectAssign(pageContextHttpResponse, pageContextInit);
|
|
346
|
+
objectAssign(pageContextHttpResponse, { httpResponse });
|
|
344
347
|
return pageContextHttpResponse;
|
|
345
348
|
}
|
|
346
349
|
function getPermanentRedirect(pageContextInit, httpRequestId) {
|
|
@@ -375,7 +378,9 @@ function getPermanentRedirect(pageContextInit, httpRequestId) {
|
|
|
375
378
|
}
|
|
376
379
|
logRuntimeInfo?.(`Permanent redirect defined by your config.redirects (https://vike.dev/redirects)`, httpRequestId, 'info');
|
|
377
380
|
const httpResponse = createHttpResponseObjectRedirect({ url: urlTarget, statusCode: 301 }, urlWithoutBase);
|
|
378
|
-
const pageContextHttpResponse = {
|
|
381
|
+
const pageContextHttpResponse = {};
|
|
382
|
+
objectAssign(pageContextHttpResponse, pageContextInit);
|
|
383
|
+
objectAssign(pageContextHttpResponse, { httpResponse });
|
|
379
384
|
return pageContextHttpResponse;
|
|
380
385
|
}
|
|
381
386
|
async function handleAbortError(errAbort, pageContextsFromRewrite, pageContextInit,
|
|
@@ -391,11 +396,11 @@ pageContextNominalPageInit, httpRequestId, renderContext, pageContextErrorPageIn
|
|
|
391
396
|
assert(abortCall);
|
|
392
397
|
assertUsage(errorPageId, `You called ${pc.cyan(abortCall)} but you didn't define an error page, make sure to define one https://vike.dev/error-page`);
|
|
393
398
|
const pageContext = {
|
|
394
|
-
_pageId: errorPageId
|
|
395
|
-
...pageContextAbort,
|
|
396
|
-
...pageContextErrorPageInit,
|
|
397
|
-
...renderContext
|
|
399
|
+
_pageId: errorPageId
|
|
398
400
|
};
|
|
401
|
+
objectAssign(pageContext, pageContextAbort);
|
|
402
|
+
objectAssign(pageContext, pageContextErrorPageInit);
|
|
403
|
+
objectAssign(pageContext, renderContext);
|
|
399
404
|
objectAssign(pageContext, await loadUserFilesServerSide(pageContext));
|
|
400
405
|
// We include pageContextInit: we don't only serialize pageContextAbort because the error page may need to access pageContextInit
|
|
401
406
|
pageContextSerialized = serializePageContextClientSide(pageContext);
|
|
@@ -416,10 +421,9 @@ pageContextNominalPageInit, httpRequestId, renderContext, pageContextErrorPageIn
|
|
|
416
421
|
return { pageContextReturn };
|
|
417
422
|
}
|
|
418
423
|
if (pageContextAbort._urlRedirect) {
|
|
419
|
-
const pageContextReturn = {
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
};
|
|
424
|
+
const pageContextReturn = {};
|
|
425
|
+
objectAssign(pageContextReturn, pageContextInit);
|
|
426
|
+
objectAssign(pageContextReturn, pageContextAbort);
|
|
423
427
|
const httpResponse = createHttpResponseObjectRedirect(pageContextAbort._urlRedirect, (() => {
|
|
424
428
|
const { pathname, searchOriginal } = pageContextNominalPageInit.urlParsed;
|
|
425
429
|
const urlLogical = createUrlFromComponents(null, pathname, searchOriginal,
|
|
@@ -9,6 +9,7 @@ declare global {
|
|
|
9
9
|
* - You can refine the type of `Config['Page']`.
|
|
10
10
|
* - You can define the type of custom configurations created with `config.meta` (https://vike.dev/meta)
|
|
11
11
|
*
|
|
12
|
+
* https://vike.dev/meta#typescript
|
|
12
13
|
*/
|
|
13
14
|
interface Config {
|
|
14
15
|
}
|
|
@@ -22,6 +23,14 @@ declare global {
|
|
|
22
23
|
*/
|
|
23
24
|
interface PageContext {
|
|
24
25
|
}
|
|
26
|
+
/** Refine the `pageContext.config` type.
|
|
27
|
+
*
|
|
28
|
+
* It's used for cumulative configs: the `pageContext.config[configName]` type is an `array` whereas `Config[configName]` isn't.
|
|
29
|
+
*
|
|
30
|
+
* https://vike.dev/meta#typescript
|
|
31
|
+
*/
|
|
32
|
+
interface ConfigResolved {
|
|
33
|
+
}
|
|
25
34
|
}
|
|
26
35
|
/** This namespace is only used by:
|
|
27
36
|
* - `vike-react`
|
|
@@ -41,8 +41,8 @@ type PageContextExports = {
|
|
|
41
41
|
pageExports: Record<string, unknown>;
|
|
42
42
|
};
|
|
43
43
|
type From = {
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
configsStandard: Record<string, // configName
|
|
45
|
+
SourceConfigsStandard>;
|
|
46
46
|
configsCumulative: Record<string, // configName
|
|
47
47
|
SourceConfigsCumulative>;
|
|
48
48
|
configsComputed: Record<string, // configName
|
|
@@ -53,9 +53,9 @@ SourceAny>;
|
|
|
53
53
|
type Sources = Record<string, // configName
|
|
54
54
|
SourceAny[]>;
|
|
55
55
|
type SourceAny = SourceConfigs;
|
|
56
|
-
type SourceConfigs =
|
|
57
|
-
type
|
|
58
|
-
type: '
|
|
56
|
+
type SourceConfigs = SourceConfigsStandard | SourceConfigsCumulative | SourceConfigsComputed;
|
|
57
|
+
type SourceConfigsStandard = {
|
|
58
|
+
type: 'configsStandard';
|
|
59
59
|
value: unknown;
|
|
60
60
|
definedAt: string;
|
|
61
61
|
};
|
|
@@ -35,7 +35,7 @@ function getPageContextExports(pageFiles, pageConfig) {
|
|
|
35
35
|
sources[configName].push(src);
|
|
36
36
|
};
|
|
37
37
|
const from = {
|
|
38
|
-
|
|
38
|
+
configsStandard: {},
|
|
39
39
|
configsCumulative: {},
|
|
40
40
|
configsComputed: {}
|
|
41
41
|
};
|
|
@@ -53,6 +53,15 @@ function getPageContextExports(pageFiles, pageConfig) {
|
|
|
53
53
|
configDefinedAt,
|
|
54
54
|
configDefinedByFile: configValueFilePathToShowToUser
|
|
55
55
|
});
|
|
56
|
+
if (configValue.type === 'standard') {
|
|
57
|
+
const src = {
|
|
58
|
+
type: 'configsStandard',
|
|
59
|
+
value: configValue.value,
|
|
60
|
+
definedAt: getDefinedAtString(configValue.definedAtData, configName)
|
|
61
|
+
};
|
|
62
|
+
addSrc(src, configName);
|
|
63
|
+
from.configsStandard[configName] = src;
|
|
64
|
+
}
|
|
56
65
|
if (configValue.type === 'cumulative') {
|
|
57
66
|
const src = {
|
|
58
67
|
type: 'configsCumulative',
|
|
@@ -69,15 +78,6 @@ function getPageContextExports(pageFiles, pageConfig) {
|
|
|
69
78
|
addSrc(src, configName);
|
|
70
79
|
from.configsCumulative[configName] = src;
|
|
71
80
|
}
|
|
72
|
-
if (configValue.type === 'classic') {
|
|
73
|
-
const src = {
|
|
74
|
-
type: 'configsOverridable',
|
|
75
|
-
value: configValue.value,
|
|
76
|
-
definedAt: getDefinedAtString(configValue.definedAtData, configName)
|
|
77
|
-
};
|
|
78
|
-
addSrc(src, configName);
|
|
79
|
-
from.configsOverridable[configName] = src;
|
|
80
|
-
}
|
|
81
81
|
if (configValue.type === 'computed') {
|
|
82
82
|
const src = {
|
|
83
83
|
type: 'configsComputed',
|
|
@@ -6,4 +6,9 @@ import type { Hook, HookLoc } from './getHook.js';
|
|
|
6
6
|
type PageContextUnknown = null | Record<string, unknown>;
|
|
7
7
|
declare function isUserHookError(err: unknown): false | HookLoc;
|
|
8
8
|
declare function executeHook<T = unknown>(hookFnCaller: () => T, hook: Omit<Hook, 'hookFn'>, pageContext: PageContextUnknown): Promise<T>;
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Access `pageContext` object inside Vike hooks, in order to create universal hooks.
|
|
11
|
+
*
|
|
12
|
+
* https://vike.dev/getPageContext
|
|
13
|
+
*/
|
|
14
|
+
declare function getPageContext<PageContext = PageContextClient | PageContextServer>(): null | PageContext;
|
|
@@ -5,7 +5,6 @@ import { getProjectError, assertWarning } from '../../utils/assert.js';
|
|
|
5
5
|
import { getGlobalObject } from '../../utils/getGlobalObject.js';
|
|
6
6
|
import { humanizeTime } from '../../utils/humanizeTime.js';
|
|
7
7
|
import { isObject } from '../../utils/isObject.js';
|
|
8
|
-
import { isBrowser } from '../utils.js';
|
|
9
8
|
const globalObject = getGlobalObject('utils/executeHook.ts', {
|
|
10
9
|
userHookErrors: new WeakMap(),
|
|
11
10
|
pageContext: null
|
|
@@ -62,14 +61,19 @@ function executeHook(hookFnCaller, hook, pageContext) {
|
|
|
62
61
|
function isNotDisabled(timeout) {
|
|
63
62
|
return !!timeout && timeout !== Infinity;
|
|
64
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Access `pageContext` object inside Vike hooks, in order to create universal hooks.
|
|
66
|
+
*
|
|
67
|
+
* https://vike.dev/getPageContext
|
|
68
|
+
*/
|
|
65
69
|
function getPageContext() {
|
|
66
70
|
return globalObject.pageContext;
|
|
67
71
|
}
|
|
68
72
|
function providePageContext(pageContext) {
|
|
69
73
|
globalObject.pageContext = pageContext;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
74
|
+
// Promise.resolve() is quicker than process.nextTick() and setImmediate()
|
|
75
|
+
// https://stackoverflow.com/questions/67949576/process-nexttick-before-promise-resolve-then
|
|
76
|
+
Promise.resolve().then(() => {
|
|
77
|
+
globalObject.pageContext = null;
|
|
78
|
+
});
|
|
75
79
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export type { PageContextConfig };
|
|
2
2
|
import type { VikePackages } from '../../VikeNamespace.js';
|
|
3
3
|
import type { ConfigBuiltIn } from '../Config.js';
|
|
4
|
-
import type { Combine, IsNotEmpty, XOR5 } from './helpers.
|
|
5
|
-
type PageContextConfig = ConfigBuiltIn & Vike.Config & (ConfigVikePackagesNotEmptyXor extends true ? ConfigVikePackagesIntersection : ConfigVikePackagesCombined);
|
|
4
|
+
import type { Combine, IsNotEmpty, XOR5 } from './helpers.js';
|
|
5
|
+
type PageContextConfig = ConfigBuiltIn & Vike.ConfigResolved & Omit<Vike.Config, keyof Vike.ConfigResolved> & (ConfigVikePackagesNotEmptyXor extends true ? ConfigVikePackagesIntersection : ConfigVikePackagesCombined);
|
|
6
6
|
type ConfigVikePackagesIntersection = VikePackages.ConfigVikeReact & VikePackages.ConfigVikeVue & VikePackages.ConfigVikeSolid & VikePackages.ConfigVikeSvelte & VikePackages.ConfigVikeAngular;
|
|
7
7
|
type ConfigVikePackagesCombined = Combine<VikePackages.ConfigVikeReact, Combine<VikePackages.ConfigVikeVue, Combine<VikePackages.ConfigVikeSolid, Combine<VikePackages.ConfigVikeSvelte, VikePackages.ConfigVikeAngular>>>>;
|
|
8
8
|
type ConfigVikePackagesNotEmptyXor = XOR5<IsNotEmpty<VikePackages.ConfigVikeReact>, IsNotEmpty<VikePackages.ConfigVikeVue>, IsNotEmpty<VikePackages.ConfigVikeSolid>, IsNotEmpty<VikePackages.ConfigVikeSvelte>, IsNotEmpty<VikePackages.ConfigVikeAngular>>;
|
|
@@ -6,7 +6,7 @@ export type { ConfigEnvInternal };
|
|
|
6
6
|
export type { PageConfigGlobalRuntime };
|
|
7
7
|
export type { PageConfigGlobalBuildTime };
|
|
8
8
|
export type { ConfigValue };
|
|
9
|
-
export type {
|
|
9
|
+
export type { ConfigValueStandard };
|
|
10
10
|
export type { ConfigValueCumulative };
|
|
11
11
|
export type { ConfigValueComputed };
|
|
12
12
|
export type { ConfigValues };
|
|
@@ -86,10 +86,10 @@ type ConfigValuesComputed = Record<string, {
|
|
|
86
86
|
configEnv: ConfigEnvInternal;
|
|
87
87
|
value: unknown;
|
|
88
88
|
}>;
|
|
89
|
-
type ConfigValue =
|
|
89
|
+
type ConfigValue = ConfigValueStandard | ConfigValueCumulative | ConfigValueComputed;
|
|
90
90
|
/** Defined by a unique source (thus unique file path). */
|
|
91
|
-
type
|
|
92
|
-
type: '
|
|
91
|
+
type ConfigValueStandard = {
|
|
92
|
+
type: 'standard';
|
|
93
93
|
value: unknown;
|
|
94
94
|
definedAtData: DefinedAtFile;
|
|
95
95
|
};
|
|
@@ -2,7 +2,7 @@ export type { PageConfigRuntimeSerialized };
|
|
|
2
2
|
export type { PageConfigGlobalRuntimeSerialized };
|
|
3
3
|
export type { ConfigValueSerialized };
|
|
4
4
|
export type { ConfigValueImported };
|
|
5
|
-
import type {
|
|
5
|
+
import type { ConfigValueStandard, ConfigValueComputed, ConfigValueCumulative, PageConfigRuntime } from '../PageConfig.js';
|
|
6
6
|
/** Page config data structure serialized in virtual files: parsing it results in PageConfigRuntime */
|
|
7
7
|
type PageConfigRuntimeSerialized = Omit<PageConfigRuntime, 'configValues'> & {
|
|
8
8
|
/** Config values that are serializable and loaded eagerly such as config.passToClient */
|
|
@@ -14,7 +14,7 @@ type PageConfigGlobalRuntimeSerialized = {
|
|
|
14
14
|
configValuesImported: ConfigValueImported[];
|
|
15
15
|
};
|
|
16
16
|
/** Value is serialized */
|
|
17
|
-
type ConfigValueSerialized = (Omit<
|
|
17
|
+
type ConfigValueSerialized = (Omit<ConfigValueStandard, 'value'> & {
|
|
18
18
|
valueSerialized: string;
|
|
19
19
|
}) | (Omit<ConfigValueCumulative, 'value'> & {
|
|
20
20
|
valueSerialized: string;
|
|
@@ -51,7 +51,7 @@ function parseConfigValuesImported(configValuesImported) {
|
|
|
51
51
|
assert(val);
|
|
52
52
|
const { value, importPath, exportName } = val;
|
|
53
53
|
configValues[configName] = {
|
|
54
|
-
type: '
|
|
54
|
+
type: 'standard',
|
|
55
55
|
value,
|
|
56
56
|
definedAtData: {
|
|
57
57
|
// importPath cannot be relative to the current file, since the current file is a virtual file
|
|
@@ -2,13 +2,9 @@ import { compareString } from './utils.js';
|
|
|
2
2
|
export { sortPageContext };
|
|
3
3
|
// Sort `pageContext` keys alphabetically, in order to make reading `console.log(pageContext)` easier
|
|
4
4
|
function sortPageContext(pageContext) {
|
|
5
|
-
|
|
6
|
-
for (const key
|
|
5
|
+
let descriptors = Object.getOwnPropertyDescriptors(pageContext);
|
|
6
|
+
for (const key of Object.keys(pageContext))
|
|
7
7
|
delete pageContext[key];
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
.sort(([key1], [key2]) => compareString(key1, key2))
|
|
11
|
-
.forEach(([key, val]) => {
|
|
12
|
-
pageContext[key] = val;
|
|
13
|
-
});
|
|
8
|
+
descriptors = Object.fromEntries(Object.entries(descriptors).sort(([key1], [key2]) => compareString(key1, key2)));
|
|
9
|
+
Object.defineProperties(pageContext, descriptors);
|
|
14
10
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function escapeHtml(unsafeString: string): string;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Copied from https://stackoverflow.com/questions/6234773/can-i-escape-html-special-chars-in-javascript/6234804#6234804
|
|
2
|
+
export function escapeHtml(unsafeString) {
|
|
3
|
+
const safe = unsafeString
|
|
4
|
+
.replace(/&/g, '&')
|
|
5
|
+
.replace(/</g, '<')
|
|
6
|
+
.replace(/>/g, '>')
|
|
7
|
+
.replace(/"/g, '"')
|
|
8
|
+
.replace(/'/g, ''');
|
|
9
|
+
return safe;
|
|
10
|
+
}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
export { objectEntries };
|
|
2
2
|
export { objectFromEntries };
|
|
3
3
|
export { objectKeys };
|
|
4
|
-
type ValueOf<T> = T[keyof T];
|
|
5
|
-
type Entries<T> = [keyof T, ValueOf<T>][];
|
|
6
4
|
/** Same as Object.entries() but with type inference */
|
|
7
|
-
declare function objectEntries<T extends object>(obj: T):
|
|
5
|
+
declare function objectEntries<T extends object>(obj: T): [keyof T, T[keyof T]][];
|
|
8
6
|
/** Same as Object.fromEntries() but with type inference */
|
|
9
7
|
declare function objectFromEntries<T extends [PropertyKey, unknown][]>(arr: T): Record<T[number][0], T[number][1]>;
|
|
10
8
|
/** Same as Object.keys() but with type inference */
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { objectEntries };
|
|
2
2
|
export { objectFromEntries };
|
|
3
3
|
export { objectKeys };
|
|
4
|
+
// export { forEach }
|
|
4
5
|
// https://stackoverflow.com/questions/60141960/typescript-key-value-relation-preserving-object-entries-type/75337277#75337277
|
|
5
6
|
/** Same as Object.entries() but with type inference */
|
|
6
7
|
function objectEntries(obj) {
|
|
@@ -16,8 +17,11 @@ function objectFromEntries(arr) {
|
|
|
16
17
|
function objectKeys(obj) {
|
|
17
18
|
return Object.keys(obj);
|
|
18
19
|
}
|
|
19
|
-
/*
|
|
20
|
-
function
|
|
21
|
-
|
|
20
|
+
/* Not used yet, but can be quite useful.
|
|
21
|
+
function forEach<Obj extends object>(
|
|
22
|
+
obj: Obj,
|
|
23
|
+
iterator: <Key extends keyof Obj>(key: Key, val: Obj[Key]) => void
|
|
24
|
+
): void {
|
|
25
|
+
Object.entries(obj).forEach(([key, val]) => iterator(key as keyof Obj, val))
|
|
22
26
|
}
|
|
23
|
-
|
|
27
|
+
//*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { projectInfo };
|
|
2
2
|
export { PROJECT_VERSION };
|
|
3
|
-
declare const PROJECT_VERSION: "0.4.171-commit-
|
|
3
|
+
declare const PROJECT_VERSION: "0.4.171-commit-2e4e1ce";
|
|
4
4
|
declare const projectInfo: {
|
|
5
5
|
projectName: "Vike";
|
|
6
|
-
projectVersion: "0.4.171-commit-
|
|
6
|
+
projectVersion: "0.4.171-commit-2e4e1ce";
|
|
7
7
|
};
|