vike 0.4.171-commit-2e4e1ce → 0.4.171-commit-42245b5
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/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js +38 -4
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +1 -1
- package/dist/cjs/node/plugin/shared/addSsrMiddleware.js +2 -8
- package/dist/cjs/node/runtime/html/renderHtml.js +18 -9
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js +39 -5
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +1 -1
- package/dist/esm/node/plugin/shared/addSsrMiddleware.js +2 -8
- package/dist/esm/node/runtime/html/renderHtml.js +18 -9
- package/dist/esm/utils/projectInfo.d.ts +2 -2
- package/dist/esm/utils/projectInfo.js +1 -1
- package/package.json +1 -1
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js
CHANGED
|
@@ -13,7 +13,7 @@ const transformFileImports_js_1 = require("./transformFileImports.js");
|
|
|
13
13
|
const getConfigFileExport_js_1 = require("../getConfigFileExport.js");
|
|
14
14
|
const resolvePointerImport_js_1 = require("./resolvePointerImport.js");
|
|
15
15
|
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
16
|
-
// Load
|
|
16
|
+
// Load pointer import
|
|
17
17
|
async function loadImportedFile(import_, userRootDir, importedFilesLoaded) {
|
|
18
18
|
const f = import_.filePathAbsoluteFilesystem;
|
|
19
19
|
if (!importedFilesLoaded[f]) {
|
|
@@ -35,7 +35,7 @@ async function loadValueFile(interfaceValueFile, configName, userRootDir) {
|
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
exports.loadValueFile = loadValueFile;
|
|
38
|
-
// Load +config.js, including all its extends
|
|
38
|
+
// Load +config.js, including all its extends pointer imports
|
|
39
39
|
async function loadConfigFile(configFilePath, userRootDir, visited, isExtensionConfig) {
|
|
40
40
|
const { filePathAbsoluteFilesystem } = configFilePath;
|
|
41
41
|
assertNoInfiniteLoop(visited, filePathAbsoluteFilesystem);
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js
CHANGED
|
@@ -11,11 +11,19 @@ const path_1 = __importDefault(require("path"));
|
|
|
11
11
|
const getFilePath_js_1 = require("../../../../shared/getFilePath.js");
|
|
12
12
|
const filesEnvMap = new Map();
|
|
13
13
|
function resolvePointerImportOfConfig(configValue, importerFilePath, userRootDir, configEnv, configName) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
const pointerImportData = typeof configValue === 'string' && (0, transformFileImports_js_1.parsePointerImportData)(configValue);
|
|
15
|
+
if (!pointerImportData) {
|
|
16
|
+
// Temporary workaround to support document.title config.
|
|
17
|
+
// - We'll be able to remove that workaround once Vike supports custom nested configs (being able to define document.title and document.description as two different configs).
|
|
18
|
+
replaceStringValues(configValue, (str) => {
|
|
19
|
+
const pointerImportData = (0, transformFileImports_js_1.parsePointerImportData)(str);
|
|
20
|
+
if (pointerImportData) {
|
|
21
|
+
const filePath = resolvePointerImport(pointerImportData, importerFilePath, userRootDir);
|
|
22
|
+
return filePath.filePathAbsoluteVite;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
18
25
|
return null;
|
|
26
|
+
}
|
|
19
27
|
const { importPath, exportName } = pointerImportData;
|
|
20
28
|
const filePath = resolvePointerImport(pointerImportData, importerFilePath, userRootDir);
|
|
21
29
|
const fileExportPathToShowToUser = exportName === 'default' || exportName === configName ? [] : [exportName];
|
|
@@ -127,3 +135,29 @@ function clearFilesEnvMap() {
|
|
|
127
135
|
filesEnvMap.clear();
|
|
128
136
|
}
|
|
129
137
|
exports.clearFilesEnvMap = clearFilesEnvMap;
|
|
138
|
+
function replaceStringValues(obj, replacer) {
|
|
139
|
+
const visited = new WeakSet();
|
|
140
|
+
return traverse(obj, replacer);
|
|
141
|
+
function traverse(obj, replacer) {
|
|
142
|
+
// Check if the input is an object
|
|
143
|
+
if ((0, utils_js_1.isObject)(obj)) {
|
|
144
|
+
if (visited.has(obj))
|
|
145
|
+
return;
|
|
146
|
+
visited.add(obj);
|
|
147
|
+
for (const key in obj) {
|
|
148
|
+
if (!obj.hasOwnProperty(key))
|
|
149
|
+
continue;
|
|
150
|
+
const val = obj[key];
|
|
151
|
+
if (typeof val !== 'string') {
|
|
152
|
+
traverse(val, replacer);
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
const replacement = replacer(val);
|
|
156
|
+
if (replacement) {
|
|
157
|
+
obj[key] = replacement;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
@@ -552,7 +552,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
552
552
|
valueIsDefinedByValueFile: false,
|
|
553
553
|
definedAtFilePath: pointerImport
|
|
554
554
|
};
|
|
555
|
-
// Load
|
|
555
|
+
// Load pointer import
|
|
556
556
|
if (isConfigEnv(configDef, configName) &&
|
|
557
557
|
// The value of `extends` was already loaded and already used: we don't need the value of `extends` anymore
|
|
558
558
|
configName !== 'extends') {
|
|
@@ -2,7 +2,6 @@
|
|
|
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");
|
|
6
5
|
function addSsrMiddleware(middlewares) {
|
|
7
6
|
middlewares.use(async (req, res, next) => {
|
|
8
7
|
if (res.headersSent)
|
|
@@ -11,15 +10,10 @@ function addSsrMiddleware(middlewares) {
|
|
|
11
10
|
if (!url)
|
|
12
11
|
return next();
|
|
13
12
|
const { headers } = req;
|
|
13
|
+
const userAgent = headers['user-agent'];
|
|
14
14
|
const pageContextInit = {
|
|
15
15
|
urlOriginal: url,
|
|
16
|
-
|
|
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
|
-
},
|
|
16
|
+
userAgent,
|
|
23
17
|
headers
|
|
24
18
|
};
|
|
25
19
|
let pageContext;
|
|
@@ -170,31 +170,40 @@ async function renderTemplate(templateContent, pageContext) {
|
|
|
170
170
|
setStream(templateVar);
|
|
171
171
|
continue;
|
|
172
172
|
}
|
|
173
|
-
const getErrMsg = (
|
|
173
|
+
const getErrMsg = (msg) => {
|
|
174
174
|
const { hookName, hookFilePath } = pageContext._renderHook;
|
|
175
175
|
const nth = (i === 0 && '1st') || (i === 1 && '2nd') || (i === 2 && '3rd') || `${i}-th`;
|
|
176
|
-
return [
|
|
176
|
+
return [
|
|
177
|
+
`The ${nth} HTML variable is ${msg}`,
|
|
178
|
+
`The HTML was provided by the ${hookName}() hook at ${hookFilePath}.`
|
|
179
|
+
]
|
|
177
180
|
.filter(Boolean)
|
|
178
181
|
.join(' ');
|
|
179
182
|
};
|
|
180
|
-
(0, utils_js_1.assertUsage)(!(0, utils_js_1.isPromise)(templateVar), getErrMsg(
|
|
183
|
+
(0, utils_js_1.assertUsage)(!(0, utils_js_1.isPromise)(templateVar), getErrMsg(`a promise, did you forget to ${picocolors_1.default.cyan('await')} the promise?`));
|
|
181
184
|
if (templateVar === undefined || templateVar === null) {
|
|
182
|
-
|
|
185
|
+
const msgVal = picocolors_1.default.cyan(String(templateVar));
|
|
186
|
+
const msgEmptyString = picocolors_1.default.cyan("''");
|
|
187
|
+
const msg = `${msgVal} which will be converted to an empty string. Pass the empty string ${msgEmptyString} instead of ${msgVal} to remove this warning.`;
|
|
188
|
+
(0, utils_js_1.assertWarning)(false, getErrMsg(msg), { onlyOnce: false });
|
|
183
189
|
templateVar = '';
|
|
184
190
|
}
|
|
185
191
|
{
|
|
186
192
|
const varType = typeof templateVar;
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
193
|
+
if (varType !== 'string') {
|
|
194
|
+
const msgType = picocolors_1.default.cyan(`typeof htmlVariable === "${varType}"`);
|
|
195
|
+
const msg = `${msgType} but a string or stream (https://vike.dev/streaming) is expected instead.`;
|
|
196
|
+
(0, utils_js_1.assertUsage)(false, getErrMsg(msg));
|
|
197
|
+
}
|
|
191
198
|
}
|
|
192
199
|
{
|
|
193
200
|
const { isProduction } = (0, globalContext_js_1.getGlobalContext)();
|
|
194
201
|
if ((0, utils_js_1.isHtml)(templateVar) &&
|
|
195
202
|
// We don't show this warning in production because it's expected that some users may (un)willingly do some XSS injection: we avoid flooding the production logs.
|
|
196
203
|
!isProduction) {
|
|
197
|
-
|
|
204
|
+
const msgVal = picocolors_1.default.cyan(String(templateVar));
|
|
205
|
+
const msg = `${msgVal} which seems to be HTML code. Did you forget to wrap the value with dangerouslySkipEscape()?`;
|
|
206
|
+
(0, utils_js_1.assertWarning)(false, getErrMsg(msg), { onlyOnce: false });
|
|
198
207
|
}
|
|
199
208
|
}
|
|
200
209
|
// Escape untrusted template variable
|
|
@@ -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-42245b5';
|
|
5
5
|
exports.PROJECT_VERSION = PROJECT_VERSION;
|
|
6
6
|
const projectInfo = {
|
|
7
7
|
projectName: 'Vike',
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js
CHANGED
|
@@ -10,7 +10,7 @@ import { parsePointerImportData } from './transformFileImports.js';
|
|
|
10
10
|
import { getConfigFileExport } from '../getConfigFileExport.js';
|
|
11
11
|
import { resolvePointerImport } from './resolvePointerImport.js';
|
|
12
12
|
assertIsNotProductionRuntime();
|
|
13
|
-
// Load
|
|
13
|
+
// Load pointer import
|
|
14
14
|
async function loadImportedFile(import_, userRootDir, importedFilesLoaded) {
|
|
15
15
|
const f = import_.filePathAbsoluteFilesystem;
|
|
16
16
|
if (!importedFilesLoaded[f]) {
|
|
@@ -30,7 +30,7 @@ async function loadValueFile(interfaceValueFile, configName, userRootDir) {
|
|
|
30
30
|
interfaceValueFile.fileExportsByConfigName[configName_] = { configValue };
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
|
-
// Load +config.js, including all its extends
|
|
33
|
+
// Load +config.js, including all its extends pointer imports
|
|
34
34
|
async function loadConfigFile(configFilePath, userRootDir, visited, isExtensionConfig) {
|
|
35
35
|
const { filePathAbsoluteFilesystem } = configFilePath;
|
|
36
36
|
assertNoInfiniteLoop(visited, filePathAbsoluteFilesystem);
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js
CHANGED
|
@@ -2,17 +2,25 @@ export { resolvePointerImportOfConfig };
|
|
|
2
2
|
export { resolvePointerImport };
|
|
3
3
|
export { clearFilesEnvMap };
|
|
4
4
|
import pc from '@brillout/picocolors';
|
|
5
|
-
import { assert, assertIsNpmPackageImport, assertPosixPath, assertUsage, deepEqual, isPathFilesystemAbsolute, requireResolve } from '../../../../utils.js';
|
|
5
|
+
import { assert, assertIsNpmPackageImport, assertPosixPath, assertUsage, deepEqual, isObject, isPathFilesystemAbsolute, requireResolve } from '../../../../utils.js';
|
|
6
6
|
import { parsePointerImportData } from './transformFileImports.js';
|
|
7
7
|
import path from 'path';
|
|
8
8
|
import { getFilePathAbsoluteUserRootDir, getFilePathResolved, getFilePathUnresolved } from '../../../../shared/getFilePath.js';
|
|
9
9
|
const filesEnvMap = new Map();
|
|
10
10
|
function resolvePointerImportOfConfig(configValue, importerFilePath, userRootDir, configEnv, configName) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
const pointerImportData = typeof configValue === 'string' && parsePointerImportData(configValue);
|
|
12
|
+
if (!pointerImportData) {
|
|
13
|
+
// Temporary workaround to support document.title config.
|
|
14
|
+
// - We'll be able to remove that workaround once Vike supports custom nested configs (being able to define document.title and document.description as two different configs).
|
|
15
|
+
replaceStringValues(configValue, (str) => {
|
|
16
|
+
const pointerImportData = parsePointerImportData(str);
|
|
17
|
+
if (pointerImportData) {
|
|
18
|
+
const filePath = resolvePointerImport(pointerImportData, importerFilePath, userRootDir);
|
|
19
|
+
return filePath.filePathAbsoluteVite;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
15
22
|
return null;
|
|
23
|
+
}
|
|
16
24
|
const { importPath, exportName } = pointerImportData;
|
|
17
25
|
const filePath = resolvePointerImport(pointerImportData, importerFilePath, userRootDir);
|
|
18
26
|
const fileExportPathToShowToUser = exportName === 'default' || exportName === configName ? [] : [exportName];
|
|
@@ -121,3 +129,29 @@ function assertFileEnv(filePathAbsoluteFilesystem, importPath, configEnv, config
|
|
|
121
129
|
function clearFilesEnvMap() {
|
|
122
130
|
filesEnvMap.clear();
|
|
123
131
|
}
|
|
132
|
+
function replaceStringValues(obj, replacer) {
|
|
133
|
+
const visited = new WeakSet();
|
|
134
|
+
return traverse(obj, replacer);
|
|
135
|
+
function traverse(obj, replacer) {
|
|
136
|
+
// Check if the input is an object
|
|
137
|
+
if (isObject(obj)) {
|
|
138
|
+
if (visited.has(obj))
|
|
139
|
+
return;
|
|
140
|
+
visited.add(obj);
|
|
141
|
+
for (const key in obj) {
|
|
142
|
+
if (!obj.hasOwnProperty(key))
|
|
143
|
+
continue;
|
|
144
|
+
const val = obj[key];
|
|
145
|
+
if (typeof val !== 'string') {
|
|
146
|
+
traverse(val, replacer);
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
const replacement = replacer(val);
|
|
150
|
+
if (replacement) {
|
|
151
|
+
obj[key] = replacement;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
@@ -547,7 +547,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
547
547
|
valueIsDefinedByValueFile: false,
|
|
548
548
|
definedAtFilePath: pointerImport
|
|
549
549
|
};
|
|
550
|
-
// Load
|
|
550
|
+
// Load pointer import
|
|
551
551
|
if (isConfigEnv(configDef, configName) &&
|
|
552
552
|
// The value of `extends` was already loaded and already used: we don't need the value of `extends` anymore
|
|
553
553
|
configName !== 'extends') {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export { addSsrMiddleware };
|
|
2
2
|
import { renderPage } from '../../runtime/renderPage.js';
|
|
3
|
-
import { assertWarning } from '../utils.js';
|
|
4
3
|
function addSsrMiddleware(middlewares) {
|
|
5
4
|
middlewares.use(async (req, res, next) => {
|
|
6
5
|
if (res.headersSent)
|
|
@@ -9,15 +8,10 @@ function addSsrMiddleware(middlewares) {
|
|
|
9
8
|
if (!url)
|
|
10
9
|
return next();
|
|
11
10
|
const { headers } = req;
|
|
11
|
+
const userAgent = headers['user-agent'];
|
|
12
12
|
const pageContextInit = {
|
|
13
13
|
urlOriginal: url,
|
|
14
|
-
|
|
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
|
-
},
|
|
14
|
+
userAgent,
|
|
21
15
|
headers
|
|
22
16
|
};
|
|
23
17
|
let pageContext;
|
|
@@ -165,31 +165,40 @@ async function renderTemplate(templateContent, pageContext) {
|
|
|
165
165
|
setStream(templateVar);
|
|
166
166
|
continue;
|
|
167
167
|
}
|
|
168
|
-
const getErrMsg = (
|
|
168
|
+
const getErrMsg = (msg) => {
|
|
169
169
|
const { hookName, hookFilePath } = pageContext._renderHook;
|
|
170
170
|
const nth = (i === 0 && '1st') || (i === 1 && '2nd') || (i === 2 && '3rd') || `${i}-th`;
|
|
171
|
-
return [
|
|
171
|
+
return [
|
|
172
|
+
`The ${nth} HTML variable is ${msg}`,
|
|
173
|
+
`The HTML was provided by the ${hookName}() hook at ${hookFilePath}.`
|
|
174
|
+
]
|
|
172
175
|
.filter(Boolean)
|
|
173
176
|
.join(' ');
|
|
174
177
|
};
|
|
175
|
-
assertUsage(!isPromise(templateVar), getErrMsg(
|
|
178
|
+
assertUsage(!isPromise(templateVar), getErrMsg(`a promise, did you forget to ${pc.cyan('await')} the promise?`));
|
|
176
179
|
if (templateVar === undefined || templateVar === null) {
|
|
177
|
-
|
|
180
|
+
const msgVal = pc.cyan(String(templateVar));
|
|
181
|
+
const msgEmptyString = pc.cyan("''");
|
|
182
|
+
const msg = `${msgVal} which will be converted to an empty string. Pass the empty string ${msgEmptyString} instead of ${msgVal} to remove this warning.`;
|
|
183
|
+
assertWarning(false, getErrMsg(msg), { onlyOnce: false });
|
|
178
184
|
templateVar = '';
|
|
179
185
|
}
|
|
180
186
|
{
|
|
181
187
|
const varType = typeof templateVar;
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
188
|
+
if (varType !== 'string') {
|
|
189
|
+
const msgType = pc.cyan(`typeof htmlVariable === "${varType}"`);
|
|
190
|
+
const msg = `${msgType} but a string or stream (https://vike.dev/streaming) is expected instead.`;
|
|
191
|
+
assertUsage(false, getErrMsg(msg));
|
|
192
|
+
}
|
|
186
193
|
}
|
|
187
194
|
{
|
|
188
195
|
const { isProduction } = getGlobalContext();
|
|
189
196
|
if (isHtml(templateVar) &&
|
|
190
197
|
// We don't show this warning in production because it's expected that some users may (un)willingly do some XSS injection: we avoid flooding the production logs.
|
|
191
198
|
!isProduction) {
|
|
192
|
-
|
|
199
|
+
const msgVal = pc.cyan(String(templateVar));
|
|
200
|
+
const msg = `${msgVal} which seems to be HTML code. Did you forget to wrap the value with dangerouslySkipEscape()?`;
|
|
201
|
+
assertWarning(false, getErrMsg(msg), { onlyOnce: false });
|
|
193
202
|
}
|
|
194
203
|
}
|
|
195
204
|
// Escape untrusted template variable
|
|
@@ -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-42245b5";
|
|
4
4
|
declare const projectInfo: {
|
|
5
5
|
projectName: "Vike";
|
|
6
|
-
projectVersion: "0.4.171-commit-
|
|
6
|
+
projectVersion: "0.4.171-commit-42245b5";
|
|
7
7
|
};
|