vike 0.4.177-commit-f4a92e0 → 0.4.177-commit-51d612a
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/envVars.js +7 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +2 -2
- package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +4 -7
- package/dist/cjs/node/runtime/html/injectAssets/{getViteDevScripts.js → getViteDevScript.js} +5 -5
- package/dist/cjs/node/runtime/html/injectAssets.js +5 -2
- package/dist/cjs/node/runtime/html/stream.js +13 -5
- package/dist/cjs/utils/parseUrl.js +17 -14
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.js +1 -0
- package/dist/esm/node/plugin/plugins/envVars.js +7 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +2 -2
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.d.ts +1 -1
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +4 -7
- package/dist/esm/node/runtime/html/injectAssets/getViteDevScript.d.ts +2 -0
- package/dist/esm/node/runtime/html/injectAssets/{getViteDevScripts.js → getViteDevScript.js} +4 -4
- package/dist/esm/node/runtime/html/injectAssets.js +5 -2
- package/dist/esm/node/runtime/html/stream.js +13 -5
- package/dist/esm/utils/parseUrl.d.ts +1 -1
- package/dist/esm/utils/parseUrl.js +17 -14
- package/dist/esm/utils/projectInfo.d.ts +2 -2
- package/dist/esm/utils/projectInfo.js +1 -1
- package/package.json +1 -1
- package/dist/esm/node/runtime/html/injectAssets/getViteDevScripts.d.ts +0 -2
|
@@ -5,6 +5,11 @@ const vite_1 = require("vite");
|
|
|
5
5
|
const utils_js_1 = require("../utils.js");
|
|
6
6
|
const rollupSourceMap_js_1 = require("../shared/rollupSourceMap.js");
|
|
7
7
|
const getFilePath_js_1 = require("../shared/getFilePath.js");
|
|
8
|
+
const PUBLIC_ENV_PREFIX = 'PUBLIC_ENV__';
|
|
9
|
+
const PUBLIC_ENV_WHITELIST = [
|
|
10
|
+
// https://github.com/vikejs/vike/issues/1724
|
|
11
|
+
'STORYBOOK'
|
|
12
|
+
];
|
|
8
13
|
function envVarsPlugin() {
|
|
9
14
|
let envsAll;
|
|
10
15
|
let config;
|
|
@@ -37,14 +42,13 @@ function envVarsPlugin() {
|
|
|
37
42
|
// Security check
|
|
38
43
|
{
|
|
39
44
|
const envStatement = getEnvStatement(envName);
|
|
40
|
-
const
|
|
41
|
-
const isPrivate = !envName.startsWith(publicPrefix);
|
|
45
|
+
const isPrivate = !envName.startsWith(PUBLIC_ENV_PREFIX) && !PUBLIC_ENV_WHITELIST.includes(envName);
|
|
42
46
|
if (isPrivate && isClientSide) {
|
|
43
47
|
if (!code.includes(envStatement))
|
|
44
48
|
return;
|
|
45
49
|
const modulePath = (0, getFilePath_js_1.getModuleFilePath)(id, config);
|
|
46
50
|
const errMsgAddendum = isBuild ? '' : ' (Vike will prevent your app from building for production)';
|
|
47
|
-
const keyPublic = `${
|
|
51
|
+
const keyPublic = `${PUBLIC_ENV_PREFIX}${envName}`;
|
|
48
52
|
const errMsg = `${envStatement} is used in client-side file ${modulePath} which means that the environment variable ${envName} will be included in client-side bundles and, therefore, ${envName} will be publicly exposed which can be a security leak${errMsgAddendum}. Use ${envStatement} only in server-side files, or rename ${envName} to ${keyPublic}, see https://vike.dev/env`;
|
|
49
53
|
if (isBuild) {
|
|
50
54
|
(0, utils_js_1.assertUsage)(false, errMsg);
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js
CHANGED
|
@@ -55,8 +55,8 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev, craw
|
|
|
55
55
|
if (isDev) {
|
|
56
56
|
// We only warn in dev, because while building it's expected to take a long time as crawling is competing for resources with other tasks.
|
|
57
57
|
// Although, in dev, it's also competing for resources e.g. with Vite's `optimizeDeps`.
|
|
58
|
-
(0, utils_js_1.assertWarning)(timeSpent < 3 * 1000, `Crawling your ${picocolors_1.default.cyan('+')} files took an unexpected long time (${(0, utils_js_1.humanizeTime)(timeSpent)}). If you
|
|
59
|
-
onlyOnce: 'slow-
|
|
58
|
+
(0, utils_js_1.assertWarning)(timeSpent < 3 * 1000, `Crawling your ${picocolors_1.default.cyan('+')} files took an unexpected long time (${(0, utils_js_1.humanizeTime)(timeSpent)}). If you consistently get this warning, then consider reaching out on GitHub.`, {
|
|
59
|
+
onlyOnce: 'slow-crawling'
|
|
60
60
|
});
|
|
61
61
|
}
|
|
62
62
|
}
|
|
@@ -8,16 +8,14 @@ const utils_js_1 = require("../../utils.js");
|
|
|
8
8
|
const serializePageContextClientSide_js_1 = require("../serializePageContextClientSide.js");
|
|
9
9
|
const sanitizeJson_js_1 = require("./sanitizeJson.js");
|
|
10
10
|
const inferHtmlTags_js_1 = require("./inferHtmlTags.js");
|
|
11
|
-
const getViteDevScripts_js_1 = require("./getViteDevScripts.js");
|
|
12
11
|
const mergeScriptTags_js_1 = require("./mergeScriptTags.js");
|
|
13
12
|
const globalContext_js_1 = require("../../globalContext.js");
|
|
14
13
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
15
14
|
const stamp = '__injectFilterEntry';
|
|
16
|
-
|
|
15
|
+
function getHtmlTags(pageContext, injectToStream, injectFilter, pageAssets, viteDevScript) {
|
|
17
16
|
(0, utils_js_1.assert)([true, false].includes(pageContext._isHtmlOnly));
|
|
18
17
|
const isHtmlOnly = pageContext._isHtmlOnly;
|
|
19
18
|
const { isProduction } = (0, globalContext_js_1.getGlobalContext)();
|
|
20
|
-
const pageAssets = await pageContext.__getPageAssets();
|
|
21
19
|
const injectFilterEntries = pageAssets
|
|
22
20
|
.filter((asset) => {
|
|
23
21
|
if (asset.isEntry && asset.assetType === 'script') {
|
|
@@ -112,7 +110,7 @@ async function getHtmlTags(pageContext, injectToStream, injectFilter) {
|
|
|
112
110
|
});
|
|
113
111
|
}
|
|
114
112
|
// The JavaScript entry <script> tag
|
|
115
|
-
const scriptEntry =
|
|
113
|
+
const scriptEntry = mergeScriptEntries(pageAssets, viteDevScript);
|
|
116
114
|
if (scriptEntry) {
|
|
117
115
|
htmlTags.push({
|
|
118
116
|
htmlTag: scriptEntry,
|
|
@@ -134,10 +132,9 @@ async function getHtmlTags(pageContext, injectToStream, injectFilter) {
|
|
|
134
132
|
return htmlTags;
|
|
135
133
|
}
|
|
136
134
|
exports.getHtmlTags = getHtmlTags;
|
|
137
|
-
|
|
135
|
+
function mergeScriptEntries(pageAssets, viteDevScript) {
|
|
138
136
|
const scriptEntries = pageAssets.filter((pageAsset) => pageAsset.isEntry && pageAsset.assetType === 'script');
|
|
139
|
-
const
|
|
140
|
-
const scriptTagsHtml = `${viteScripts}${scriptEntries.map((asset) => (0, inferHtmlTags_js_1.inferAssetTag)(asset)).join('')}`;
|
|
137
|
+
const scriptTagsHtml = `${viteDevScript}${scriptEntries.map((asset) => (0, inferHtmlTags_js_1.inferAssetTag)(asset)).join('')}`;
|
|
141
138
|
const scriptTag = (0, mergeScriptTags_js_1.mergeScriptTags)(scriptTagsHtml);
|
|
142
139
|
return scriptTag;
|
|
143
140
|
}
|
package/dist/cjs/node/runtime/html/injectAssets/{getViteDevScripts.js → getViteDevScript.js}
RENAMED
|
@@ -3,11 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.getViteDevScript = void 0;
|
|
7
7
|
const globalContext_js_1 = require("../../globalContext.js");
|
|
8
8
|
const utils_js_1 = require("../../utils.js");
|
|
9
9
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
10
|
-
async function
|
|
10
|
+
async function getViteDevScript() {
|
|
11
11
|
const globalContext = (0, globalContext_js_1.getGlobalContext)();
|
|
12
12
|
if (globalContext.isProduction) {
|
|
13
13
|
return '';
|
|
@@ -23,7 +23,7 @@ async function getViteDevScripts() {
|
|
|
23
23
|
const viteInjection = fakeHtml.slice(fakeHtmlBegin.length, -1 * fakeHtmlEnd.length);
|
|
24
24
|
(0, utils_js_1.assert)(viteInjection.includes('script'));
|
|
25
25
|
(0, utils_js_1.assertWarning)(!viteInjection.includes('import('), 'Unexpected Vite HMR code. Reach out to a Vike maintainer on GitHub.', { onlyOnce: true });
|
|
26
|
-
const
|
|
27
|
-
return
|
|
26
|
+
const viteDevScript = viteInjection;
|
|
27
|
+
return viteDevScript;
|
|
28
28
|
}
|
|
29
|
-
exports.
|
|
29
|
+
exports.getViteDevScript = getViteDevScript;
|
|
@@ -5,9 +5,11 @@ const utils_js_1 = require("../utils.js");
|
|
|
5
5
|
const assertPageContextProvidedByUser_js_1 = require("../../../shared/assertPageContextProvidedByUser.js");
|
|
6
6
|
const injectHtmlTags_js_1 = require("./injectAssets/injectHtmlTags.js");
|
|
7
7
|
const getHtmlTags_js_1 = require("./injectAssets/getHtmlTags.js");
|
|
8
|
+
const getViteDevScript_js_1 = require("./injectAssets/getViteDevScript.js");
|
|
8
9
|
async function injectHtmlTagsToString(htmlParts, pageContext, injectFilter) {
|
|
9
|
-
const htmlTags = await (0, getHtmlTags_js_1.getHtmlTags)(pageContext, null, injectFilter);
|
|
10
10
|
const pageAssets = await pageContext.__getPageAssets();
|
|
11
|
+
const viteDevScript = await (0, getViteDevScript_js_1.getViteDevScript)();
|
|
12
|
+
const htmlTags = (0, getHtmlTags_js_1.getHtmlTags)(pageContext, null, injectFilter, pageAssets, viteDevScript);
|
|
11
13
|
let htmlString = htmlPartsToString(htmlParts, pageAssets);
|
|
12
14
|
htmlString = injectToHtmlBegin(htmlString, htmlTags, null);
|
|
13
15
|
htmlString = injectToHtmlEnd(htmlString, htmlTags);
|
|
@@ -21,8 +23,9 @@ function injectHtmlTagsToStream(pageContext, injectToStream, injectFilter) {
|
|
|
21
23
|
injectAtStreamEnd
|
|
22
24
|
};
|
|
23
25
|
async function injectAtStreamBegin(htmlPartsBegin) {
|
|
24
|
-
htmlTags = await (0, getHtmlTags_js_1.getHtmlTags)(pageContext, injectToStream, injectFilter);
|
|
25
26
|
const pageAssets = await pageContext.__getPageAssets();
|
|
27
|
+
const viteDevScript = await (0, getViteDevScript_js_1.getViteDevScript)();
|
|
28
|
+
htmlTags = (0, getHtmlTags_js_1.getHtmlTags)(pageContext, injectToStream, injectFilter, pageAssets, viteDevScript);
|
|
26
29
|
let htmlBegin = htmlPartsToString(htmlPartsBegin, pageAssets);
|
|
27
30
|
htmlBegin = injectToHtmlBegin(htmlBegin, htmlTags, injectToStream);
|
|
28
31
|
return htmlBegin;
|
|
@@ -376,7 +376,7 @@ async function createStreamWrapper({ streamOriginal, onError, onData, onEnd, onF
|
|
|
376
376
|
(0, utils_js_1.assert)(writableOriginal);
|
|
377
377
|
writableOriginal.write(chunk);
|
|
378
378
|
if (debug.isActivated) {
|
|
379
|
-
debug('data written (Node.js Writable)',
|
|
379
|
+
debug('data written (Node.js Writable)', getChunkAsString(chunk));
|
|
380
380
|
}
|
|
381
381
|
};
|
|
382
382
|
// For libraries such as https://www.npmjs.com/package/compression
|
|
@@ -449,7 +449,7 @@ async function createStreamWrapper({ streamOriginal, onError, onData, onEnd, onF
|
|
|
449
449
|
(0, utils_js_1.assert)(writerOriginal);
|
|
450
450
|
writerOriginal.write(encodeForWebStream(chunk));
|
|
451
451
|
if (debug.isActivated) {
|
|
452
|
-
debug('data written (Web Writable)',
|
|
452
|
+
debug('data written (Web Writable)', getChunkAsString(chunk));
|
|
453
453
|
}
|
|
454
454
|
};
|
|
455
455
|
// Web Streams have compression built-in
|
|
@@ -542,12 +542,12 @@ async function createStreamWrapper({ streamOriginal, onError, onData, onEnd, onF
|
|
|
542
542
|
!controllerProxyIsClosed) {
|
|
543
543
|
controllerProxy.enqueue(encodeForWebStream(chunk));
|
|
544
544
|
if (debug.isActivated) {
|
|
545
|
-
debug('data written (Web Readable)',
|
|
545
|
+
debug('data written (Web Readable)', getChunkAsString(chunk));
|
|
546
546
|
}
|
|
547
547
|
}
|
|
548
548
|
else {
|
|
549
549
|
if (debug.isActivated) {
|
|
550
|
-
debug('data emitted but not written (Web Readable)',
|
|
550
|
+
debug('data emitted but not written (Web Readable)', getChunkAsString(chunk));
|
|
551
551
|
}
|
|
552
552
|
}
|
|
553
553
|
};
|
|
@@ -569,7 +569,7 @@ async function createStreamWrapper({ streamOriginal, onError, onData, onEnd, onF
|
|
|
569
569
|
const writeChunk = (chunk) => {
|
|
570
570
|
readableProxy.push(chunk);
|
|
571
571
|
if (debug.isActivated) {
|
|
572
|
-
debug('data written (Node.js Readable)',
|
|
572
|
+
debug('data written (Node.js Readable)', getChunkAsString(chunk));
|
|
573
573
|
}
|
|
574
574
|
};
|
|
575
575
|
// Readables don't have the notion of flushing
|
|
@@ -793,3 +793,11 @@ function inferStreamName(stream) {
|
|
|
793
793
|
(0, utils_js_1.assert)(false);
|
|
794
794
|
}
|
|
795
795
|
exports.inferStreamName = inferStreamName;
|
|
796
|
+
function getChunkAsString(chunk) {
|
|
797
|
+
try {
|
|
798
|
+
return new TextDecoder().decode(chunk);
|
|
799
|
+
}
|
|
800
|
+
catch (err) {
|
|
801
|
+
return String(chunk);
|
|
802
|
+
}
|
|
803
|
+
}
|
|
@@ -10,19 +10,9 @@ exports.isUriWithProtocol = exports.createUrlFromComponents = exports.assertUrlC
|
|
|
10
10
|
const slice_js_1 = require("./slice.js");
|
|
11
11
|
const assert_js_1 = require("./assert.js");
|
|
12
12
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
13
|
-
const PROTOCOLS = [
|
|
14
|
-
'http://',
|
|
15
|
-
'https://',
|
|
16
|
-
// For [Tauri](https://tauri.app/)
|
|
17
|
-
'tauri://',
|
|
18
|
-
// For Electron: https://github.com/vikejs/vike/issues/1557
|
|
19
|
-
'file://',
|
|
20
|
-
// For Capacitor: https://github.com/vikejs/vike/issues/1706
|
|
21
|
-
'capacitor://'
|
|
22
|
-
];
|
|
23
13
|
function isParsable(url) {
|
|
24
14
|
// `parseUrl()` works with these URLs
|
|
25
|
-
return (
|
|
15
|
+
return (isUrlWithProtocol(url) ||
|
|
26
16
|
url.startsWith('/') ||
|
|
27
17
|
url.startsWith('.') ||
|
|
28
18
|
url.startsWith('?') ||
|
|
@@ -140,7 +130,8 @@ function getPathname(url, baseServer) {
|
|
|
140
130
|
}
|
|
141
131
|
}
|
|
142
132
|
function parseOrigin(url) {
|
|
143
|
-
if (!
|
|
133
|
+
if (!isUrlWithProtocol(url)) {
|
|
134
|
+
(0, assert_js_1.assert)(!isUriWithProtocol(url));
|
|
144
135
|
return { pathname: url, origin: null };
|
|
145
136
|
}
|
|
146
137
|
else {
|
|
@@ -241,8 +232,20 @@ function createUrlFromComponents(origin, pathname, searchOriginal, hashOriginal)
|
|
|
241
232
|
return urlRecreated;
|
|
242
233
|
}
|
|
243
234
|
exports.createUrlFromComponents = createUrlFromComponents;
|
|
244
|
-
function isUriWithProtocol(
|
|
235
|
+
function isUriWithProtocol(str) {
|
|
245
236
|
// https://en.wikipedia.org/wiki/List_of_URI_schemes
|
|
246
|
-
|
|
237
|
+
// https://www.rfc-editor.org/rfc/rfc7595
|
|
238
|
+
// https://github.com/vikejs/vike/commit/886a99ff21e86a8ca699a25cee7edc184aa058e4#r143308934
|
|
239
|
+
// Examples:
|
|
240
|
+
// http://
|
|
241
|
+
// https://
|
|
242
|
+
// tauri:// # [Tauri](https://tauri.app)
|
|
243
|
+
// file:// # [Electron](https://github.com/vikejs/vike/issues/1557)
|
|
244
|
+
// capacitor:// # [Capacitor](https://github.com/vikejs/vike/issues/1706)
|
|
245
|
+
return /^[a-z][a-z0-9\+\-]*:/i.test(str);
|
|
247
246
|
}
|
|
248
247
|
exports.isUriWithProtocol = isUriWithProtocol;
|
|
248
|
+
// Same as isUriWithProtocol() but with trailing :// which is needed for parseOrigin()
|
|
249
|
+
function isUrlWithProtocol(str) {
|
|
250
|
+
return /^[a-z][a-z0-9\+\-]*:\/\//i.test(str);
|
|
251
|
+
}
|
|
@@ -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.177-commit-
|
|
4
|
+
const PROJECT_VERSION = '0.4.177-commit-51d612a';
|
|
5
5
|
exports.PROJECT_VERSION = PROJECT_VERSION;
|
|
6
6
|
const projectInfo = {
|
|
7
7
|
projectName: 'Vike',
|
|
@@ -19,6 +19,7 @@ import { isServerSideError } from '../../shared/misc/isServerSideError.js';
|
|
|
19
19
|
const globalObject = getGlobalObject('router/getPageContext.ts', {});
|
|
20
20
|
function getPageContextFromHooks_serialized() {
|
|
21
21
|
const pageContextSerialized = getPageContextSerializedInHtml();
|
|
22
|
+
assertUsage(!('urlOriginal' in pageContextSerialized), "Adding 'urlOriginal' to passToClient is forbidden");
|
|
22
23
|
processPageContextFromServer(pageContextSerialized);
|
|
23
24
|
objectAssign(pageContextSerialized, {
|
|
24
25
|
_hasPageContextFromServer: true
|
|
@@ -5,6 +5,11 @@ import { loadEnv } from 'vite';
|
|
|
5
5
|
import { assert, assertPosixPath, assertUsage, assertWarning, escapeRegex, isArray, lowerFirst } from '../utils.js';
|
|
6
6
|
import { sourceMapPassthrough } from '../shared/rollupSourceMap.js';
|
|
7
7
|
import { getModuleFilePath } from '../shared/getFilePath.js';
|
|
8
|
+
const PUBLIC_ENV_PREFIX = 'PUBLIC_ENV__';
|
|
9
|
+
const PUBLIC_ENV_WHITELIST = [
|
|
10
|
+
// https://github.com/vikejs/vike/issues/1724
|
|
11
|
+
'STORYBOOK'
|
|
12
|
+
];
|
|
8
13
|
function envVarsPlugin() {
|
|
9
14
|
let envsAll;
|
|
10
15
|
let config;
|
|
@@ -37,14 +42,13 @@ function envVarsPlugin() {
|
|
|
37
42
|
// Security check
|
|
38
43
|
{
|
|
39
44
|
const envStatement = getEnvStatement(envName);
|
|
40
|
-
const
|
|
41
|
-
const isPrivate = !envName.startsWith(publicPrefix);
|
|
45
|
+
const isPrivate = !envName.startsWith(PUBLIC_ENV_PREFIX) && !PUBLIC_ENV_WHITELIST.includes(envName);
|
|
42
46
|
if (isPrivate && isClientSide) {
|
|
43
47
|
if (!code.includes(envStatement))
|
|
44
48
|
return;
|
|
45
49
|
const modulePath = getModuleFilePath(id, config);
|
|
46
50
|
const errMsgAddendum = isBuild ? '' : ' (Vike will prevent your app from building for production)';
|
|
47
|
-
const keyPublic = `${
|
|
51
|
+
const keyPublic = `${PUBLIC_ENV_PREFIX}${envName}`;
|
|
48
52
|
const errMsg = `${envStatement} is used in client-side file ${modulePath} which means that the environment variable ${envName} will be included in client-side bundles and, therefore, ${envName} will be publicly exposed which can be a security leak${errMsgAddendum}. Use ${envStatement} only in server-side files, or rename ${envName} to ${keyPublic}, see https://vike.dev/env`;
|
|
49
53
|
if (isBuild) {
|
|
50
54
|
assertUsage(false, errMsg);
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js
CHANGED
|
@@ -50,8 +50,8 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev, craw
|
|
|
50
50
|
if (isDev) {
|
|
51
51
|
// We only warn in dev, because while building it's expected to take a long time as crawling is competing for resources with other tasks.
|
|
52
52
|
// Although, in dev, it's also competing for resources e.g. with Vite's `optimizeDeps`.
|
|
53
|
-
assertWarning(timeSpent < 3 * 1000, `Crawling your ${pc.cyan('+')} files took an unexpected long time (${humanizeTime(timeSpent)}). If you
|
|
54
|
-
onlyOnce: 'slow-
|
|
53
|
+
assertWarning(timeSpent < 3 * 1000, `Crawling your ${pc.cyan('+')} files took an unexpected long time (${humanizeTime(timeSpent)}). If you consistently get this warning, then consider reaching out on GitHub.`, {
|
|
54
|
+
onlyOnce: 'slow-crawling'
|
|
55
55
|
});
|
|
56
56
|
}
|
|
57
57
|
}
|
|
@@ -28,4 +28,4 @@ type HtmlTag = {
|
|
|
28
28
|
};
|
|
29
29
|
declare function getHtmlTags(pageContext: {
|
|
30
30
|
_isStream: boolean;
|
|
31
|
-
} & PageContextInjectAssets, injectToStream: null | InjectToStream, injectFilter: PreloadFilter):
|
|
31
|
+
} & PageContextInjectAssets, injectToStream: null | InjectToStream, injectFilter: PreloadFilter, pageAssets: PageAsset[], viteDevScript: string): HtmlTag[];
|
|
@@ -3,16 +3,14 @@ import { assert, assertWarning, assertUsage, isObject, freezePartial } from '../
|
|
|
3
3
|
import { serializePageContextClientSide } from '../serializePageContextClientSide.js';
|
|
4
4
|
import { sanitizeJson } from './sanitizeJson.js';
|
|
5
5
|
import { inferAssetTag, inferPreloadTag } from './inferHtmlTags.js';
|
|
6
|
-
import { getViteDevScripts } from './getViteDevScripts.js';
|
|
7
6
|
import { mergeScriptTags } from './mergeScriptTags.js';
|
|
8
7
|
import { getGlobalContext } from '../../globalContext.js';
|
|
9
8
|
import pc from '@brillout/picocolors';
|
|
10
9
|
const stamp = '__injectFilterEntry';
|
|
11
|
-
|
|
10
|
+
function getHtmlTags(pageContext, injectToStream, injectFilter, pageAssets, viteDevScript) {
|
|
12
11
|
assert([true, false].includes(pageContext._isHtmlOnly));
|
|
13
12
|
const isHtmlOnly = pageContext._isHtmlOnly;
|
|
14
13
|
const { isProduction } = getGlobalContext();
|
|
15
|
-
const pageAssets = await pageContext.__getPageAssets();
|
|
16
14
|
const injectFilterEntries = pageAssets
|
|
17
15
|
.filter((asset) => {
|
|
18
16
|
if (asset.isEntry && asset.assetType === 'script') {
|
|
@@ -107,7 +105,7 @@ async function getHtmlTags(pageContext, injectToStream, injectFilter) {
|
|
|
107
105
|
});
|
|
108
106
|
}
|
|
109
107
|
// The JavaScript entry <script> tag
|
|
110
|
-
const scriptEntry =
|
|
108
|
+
const scriptEntry = mergeScriptEntries(pageAssets, viteDevScript);
|
|
111
109
|
if (scriptEntry) {
|
|
112
110
|
htmlTags.push({
|
|
113
111
|
htmlTag: scriptEntry,
|
|
@@ -128,10 +126,9 @@ async function getHtmlTags(pageContext, injectToStream, injectFilter) {
|
|
|
128
126
|
});
|
|
129
127
|
return htmlTags;
|
|
130
128
|
}
|
|
131
|
-
|
|
129
|
+
function mergeScriptEntries(pageAssets, viteDevScript) {
|
|
132
130
|
const scriptEntries = pageAssets.filter((pageAsset) => pageAsset.isEntry && pageAsset.assetType === 'script');
|
|
133
|
-
const
|
|
134
|
-
const scriptTagsHtml = `${viteScripts}${scriptEntries.map((asset) => inferAssetTag(asset)).join('')}`;
|
|
131
|
+
const scriptTagsHtml = `${viteDevScript}${scriptEntries.map((asset) => inferAssetTag(asset)).join('')}`;
|
|
135
132
|
const scriptTag = mergeScriptTags(scriptTagsHtml);
|
|
136
133
|
return scriptTag;
|
|
137
134
|
}
|
package/dist/esm/node/runtime/html/injectAssets/{getViteDevScripts.js → getViteDevScript.js}
RENAMED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { getViteDevScript };
|
|
2
2
|
import { getGlobalContext } from '../../globalContext.js';
|
|
3
3
|
import { assert, assertUsage, assertWarning } from '../../utils.js';
|
|
4
4
|
import pc from '@brillout/picocolors';
|
|
5
|
-
async function
|
|
5
|
+
async function getViteDevScript() {
|
|
6
6
|
const globalContext = getGlobalContext();
|
|
7
7
|
if (globalContext.isProduction) {
|
|
8
8
|
return '';
|
|
@@ -18,6 +18,6 @@ async function getViteDevScripts() {
|
|
|
18
18
|
const viteInjection = fakeHtml.slice(fakeHtmlBegin.length, -1 * fakeHtmlEnd.length);
|
|
19
19
|
assert(viteInjection.includes('script'));
|
|
20
20
|
assertWarning(!viteInjection.includes('import('), 'Unexpected Vite HMR code. Reach out to a Vike maintainer on GitHub.', { onlyOnce: true });
|
|
21
|
-
const
|
|
22
|
-
return
|
|
21
|
+
const viteDevScript = viteInjection;
|
|
22
|
+
return viteDevScript;
|
|
23
23
|
}
|
|
@@ -4,9 +4,11 @@ import { assert, isCallable, isPromise } from '../utils.js';
|
|
|
4
4
|
import { assertPageContextProvidedByUser } from '../../../shared/assertPageContextProvidedByUser.js';
|
|
5
5
|
import { injectHtmlTags, createHtmlHeadIfMissing } from './injectAssets/injectHtmlTags.js';
|
|
6
6
|
import { getHtmlTags } from './injectAssets/getHtmlTags.js';
|
|
7
|
+
import { getViteDevScript } from './injectAssets/getViteDevScript.js';
|
|
7
8
|
async function injectHtmlTagsToString(htmlParts, pageContext, injectFilter) {
|
|
8
|
-
const htmlTags = await getHtmlTags(pageContext, null, injectFilter);
|
|
9
9
|
const pageAssets = await pageContext.__getPageAssets();
|
|
10
|
+
const viteDevScript = await getViteDevScript();
|
|
11
|
+
const htmlTags = getHtmlTags(pageContext, null, injectFilter, pageAssets, viteDevScript);
|
|
10
12
|
let htmlString = htmlPartsToString(htmlParts, pageAssets);
|
|
11
13
|
htmlString = injectToHtmlBegin(htmlString, htmlTags, null);
|
|
12
14
|
htmlString = injectToHtmlEnd(htmlString, htmlTags);
|
|
@@ -19,8 +21,9 @@ function injectHtmlTagsToStream(pageContext, injectToStream, injectFilter) {
|
|
|
19
21
|
injectAtStreamEnd
|
|
20
22
|
};
|
|
21
23
|
async function injectAtStreamBegin(htmlPartsBegin) {
|
|
22
|
-
htmlTags = await getHtmlTags(pageContext, injectToStream, injectFilter);
|
|
23
24
|
const pageAssets = await pageContext.__getPageAssets();
|
|
25
|
+
const viteDevScript = await getViteDevScript();
|
|
26
|
+
htmlTags = getHtmlTags(pageContext, injectToStream, injectFilter, pageAssets, viteDevScript);
|
|
24
27
|
let htmlBegin = htmlPartsToString(htmlPartsBegin, pageAssets);
|
|
25
28
|
htmlBegin = injectToHtmlBegin(htmlBegin, htmlTags, injectToStream);
|
|
26
29
|
return htmlBegin;
|
|
@@ -380,7 +380,7 @@ async function createStreamWrapper({ streamOriginal, onError, onData, onEnd, onF
|
|
|
380
380
|
assert(writableOriginal);
|
|
381
381
|
writableOriginal.write(chunk);
|
|
382
382
|
if (debug.isActivated) {
|
|
383
|
-
debug('data written (Node.js Writable)',
|
|
383
|
+
debug('data written (Node.js Writable)', getChunkAsString(chunk));
|
|
384
384
|
}
|
|
385
385
|
};
|
|
386
386
|
// For libraries such as https://www.npmjs.com/package/compression
|
|
@@ -453,7 +453,7 @@ async function createStreamWrapper({ streamOriginal, onError, onData, onEnd, onF
|
|
|
453
453
|
assert(writerOriginal);
|
|
454
454
|
writerOriginal.write(encodeForWebStream(chunk));
|
|
455
455
|
if (debug.isActivated) {
|
|
456
|
-
debug('data written (Web Writable)',
|
|
456
|
+
debug('data written (Web Writable)', getChunkAsString(chunk));
|
|
457
457
|
}
|
|
458
458
|
};
|
|
459
459
|
// Web Streams have compression built-in
|
|
@@ -546,12 +546,12 @@ async function createStreamWrapper({ streamOriginal, onError, onData, onEnd, onF
|
|
|
546
546
|
!controllerProxyIsClosed) {
|
|
547
547
|
controllerProxy.enqueue(encodeForWebStream(chunk));
|
|
548
548
|
if (debug.isActivated) {
|
|
549
|
-
debug('data written (Web Readable)',
|
|
549
|
+
debug('data written (Web Readable)', getChunkAsString(chunk));
|
|
550
550
|
}
|
|
551
551
|
}
|
|
552
552
|
else {
|
|
553
553
|
if (debug.isActivated) {
|
|
554
|
-
debug('data emitted but not written (Web Readable)',
|
|
554
|
+
debug('data emitted but not written (Web Readable)', getChunkAsString(chunk));
|
|
555
555
|
}
|
|
556
556
|
}
|
|
557
557
|
};
|
|
@@ -573,7 +573,7 @@ async function createStreamWrapper({ streamOriginal, onError, onData, onEnd, onF
|
|
|
573
573
|
const writeChunk = (chunk) => {
|
|
574
574
|
readableProxy.push(chunk);
|
|
575
575
|
if (debug.isActivated) {
|
|
576
|
-
debug('data written (Node.js Readable)',
|
|
576
|
+
debug('data written (Node.js Readable)', getChunkAsString(chunk));
|
|
577
577
|
}
|
|
578
578
|
};
|
|
579
579
|
// Readables don't have the notion of flushing
|
|
@@ -787,3 +787,11 @@ function inferStreamName(stream) {
|
|
|
787
787
|
}
|
|
788
788
|
assert(false);
|
|
789
789
|
}
|
|
790
|
+
function getChunkAsString(chunk) {
|
|
791
|
+
try {
|
|
792
|
+
return new TextDecoder().decode(chunk);
|
|
793
|
+
}
|
|
794
|
+
catch (err) {
|
|
795
|
+
return String(chunk);
|
|
796
|
+
}
|
|
797
|
+
}
|
|
@@ -21,4 +21,4 @@ declare function parseUrl(url: string, baseServer: string): {
|
|
|
21
21
|
declare function isBaseServer(baseServer: string): boolean;
|
|
22
22
|
declare function assertUrlComponents(url: string, origin: string | null, pathname: string, searchOriginal: string | null, hashOriginal: string | null): void;
|
|
23
23
|
declare function createUrlFromComponents(origin: string | null, pathname: string, searchOriginal: string | null, hashOriginal: string | null): string;
|
|
24
|
-
declare function isUriWithProtocol(
|
|
24
|
+
declare function isUriWithProtocol(str: string): boolean;
|
|
@@ -12,19 +12,9 @@ export { isUriWithProtocol };
|
|
|
12
12
|
import { slice } from './slice.js';
|
|
13
13
|
import { assert, assertUsage } from './assert.js';
|
|
14
14
|
import pc from '@brillout/picocolors';
|
|
15
|
-
const PROTOCOLS = [
|
|
16
|
-
'http://',
|
|
17
|
-
'https://',
|
|
18
|
-
// For [Tauri](https://tauri.app/)
|
|
19
|
-
'tauri://',
|
|
20
|
-
// For Electron: https://github.com/vikejs/vike/issues/1557
|
|
21
|
-
'file://',
|
|
22
|
-
// For Capacitor: https://github.com/vikejs/vike/issues/1706
|
|
23
|
-
'capacitor://'
|
|
24
|
-
];
|
|
25
15
|
function isParsable(url) {
|
|
26
16
|
// `parseUrl()` works with these URLs
|
|
27
|
-
return (
|
|
17
|
+
return (isUrlWithProtocol(url) ||
|
|
28
18
|
url.startsWith('/') ||
|
|
29
19
|
url.startsWith('.') ||
|
|
30
20
|
url.startsWith('?') ||
|
|
@@ -139,7 +129,8 @@ function getPathname(url, baseServer) {
|
|
|
139
129
|
}
|
|
140
130
|
}
|
|
141
131
|
function parseOrigin(url) {
|
|
142
|
-
if (!
|
|
132
|
+
if (!isUrlWithProtocol(url)) {
|
|
133
|
+
assert(!isUriWithProtocol(url));
|
|
143
134
|
return { pathname: url, origin: null };
|
|
144
135
|
}
|
|
145
136
|
else {
|
|
@@ -237,7 +228,19 @@ function createUrlFromComponents(origin, pathname, searchOriginal, hashOriginal)
|
|
|
237
228
|
const urlRecreated = `${origin || ''}${pathname}${searchOriginal || ''}${hashOriginal || ''}`;
|
|
238
229
|
return urlRecreated;
|
|
239
230
|
}
|
|
240
|
-
function isUriWithProtocol(
|
|
231
|
+
function isUriWithProtocol(str) {
|
|
241
232
|
// https://en.wikipedia.org/wiki/List_of_URI_schemes
|
|
242
|
-
|
|
233
|
+
// https://www.rfc-editor.org/rfc/rfc7595
|
|
234
|
+
// https://github.com/vikejs/vike/commit/886a99ff21e86a8ca699a25cee7edc184aa058e4#r143308934
|
|
235
|
+
// Examples:
|
|
236
|
+
// http://
|
|
237
|
+
// https://
|
|
238
|
+
// tauri:// # [Tauri](https://tauri.app)
|
|
239
|
+
// file:// # [Electron](https://github.com/vikejs/vike/issues/1557)
|
|
240
|
+
// capacitor:// # [Capacitor](https://github.com/vikejs/vike/issues/1706)
|
|
241
|
+
return /^[a-z][a-z0-9\+\-]*:/i.test(str);
|
|
242
|
+
}
|
|
243
|
+
// Same as isUriWithProtocol() but with trailing :// which is needed for parseOrigin()
|
|
244
|
+
function isUrlWithProtocol(str) {
|
|
245
|
+
return /^[a-z][a-z0-9\+\-]*:\/\//i.test(str);
|
|
243
246
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { projectInfo };
|
|
2
2
|
export { PROJECT_VERSION };
|
|
3
|
-
declare const PROJECT_VERSION: "0.4.177-commit-
|
|
3
|
+
declare const PROJECT_VERSION: "0.4.177-commit-51d612a";
|
|
4
4
|
declare const projectInfo: {
|
|
5
5
|
projectName: "Vike";
|
|
6
|
-
projectVersion: "0.4.177-commit-
|
|
6
|
+
projectVersion: "0.4.177-commit-51d612a";
|
|
7
7
|
};
|
package/package.json
CHANGED