vike 0.4.177 → 0.4.178
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 +131 -20
- package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +6 -9
- package/dist/cjs/node/runtime/html/injectAssets/{getViteDevScripts.js → getViteDevScript.js} +5 -5
- package/dist/cjs/node/runtime/html/injectAssets/injectHtmlTags.js +20 -18
- package/dist/cjs/node/runtime/html/injectAssets.js +13 -10
- package/dist/cjs/node/runtime/html/renderHtml.js +4 -4
- package/dist/cjs/node/runtime/html/stream/react-streaming.js +11 -10
- package/dist/cjs/node/runtime/html/stream.js +18 -10
- package/dist/cjs/node/runtime/utils.js +1 -0
- package/dist/cjs/utils/isVikeReactApp.js +9 -0
- package/dist/cjs/utils/parseUrl.js +17 -12
- 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 +132 -21
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.d.ts +2 -2
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +6 -9
- 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/injectHtmlTags.d.ts +5 -2
- package/dist/esm/node/runtime/html/injectAssets/injectHtmlTags.js +19 -17
- package/dist/esm/node/runtime/html/injectAssets.d.ts +2 -2
- package/dist/esm/node/runtime/html/injectAssets.js +14 -11
- package/dist/esm/node/runtime/html/renderHtml.js +5 -5
- package/dist/esm/node/runtime/html/stream/react-streaming.d.ts +16 -23
- package/dist/esm/node/runtime/html/stream/react-streaming.js +11 -10
- package/dist/esm/node/runtime/html/stream.d.ts +2 -2
- package/dist/esm/node/runtime/html/stream.js +19 -11
- package/dist/esm/node/runtime/utils.d.ts +1 -0
- package/dist/esm/node/runtime/utils.js +1 -0
- package/dist/esm/utils/isVikeReactApp.d.ts +1 -0
- package/dist/esm/utils/isVikeReactApp.js +5 -0
- package/dist/esm/utils/parseUrl.d.ts +1 -1
- package/dist/esm/utils/parseUrl.js +17 -12
- package/dist/esm/utils/projectInfo.d.ts +2 -2
- package/dist/esm/utils/projectInfo.js +1 -1
- package/package.json +3 -3
- package/dist/esm/node/runtime/html/injectAssets/getViteDevScripts.d.ts +0 -2
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// Zero-config support for https://www.npmjs.com/package/react-streaming
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
import { assert, hasProp } from '../../utils.js';
|
|
2
|
+
export { isStreamFromReactStreamingPackage };
|
|
3
|
+
export { streamFromReactStreamingPackageToString };
|
|
4
|
+
export { getStreamOfReactStreamingPackage };
|
|
5
|
+
import { assert, assertUsage, hasProp, isVikeReactApp } from '../../utils.js';
|
|
6
6
|
import { streamPipeNodeToString, streamReadableWebToString } from '../stream.js';
|
|
7
|
-
function
|
|
7
|
+
function streamFromReactStreamingPackageToString(stream) {
|
|
8
8
|
if (stream.pipe) {
|
|
9
9
|
return streamPipeNodeToString(stream.pipe);
|
|
10
10
|
}
|
|
@@ -13,17 +13,18 @@ function streamReactStreamingToString(stream) {
|
|
|
13
13
|
}
|
|
14
14
|
assert(false);
|
|
15
15
|
}
|
|
16
|
-
function
|
|
16
|
+
function isStreamFromReactStreamingPackage(thing) {
|
|
17
17
|
if (hasProp(thing, 'injectToStream', 'function')) {
|
|
18
|
+
assertUsage(hasProp(thing, 'hasStreamEnded', 'function'), isVikeReactApp()
|
|
19
|
+
? //
|
|
20
|
+
'Update vike-react to its latest version'
|
|
21
|
+
: 'Update react-streaming to its latest version');
|
|
18
22
|
return true;
|
|
19
23
|
}
|
|
20
|
-
// TODO
|
|
21
|
-
//if( isStreamPipeNode
|
|
22
24
|
return false;
|
|
23
25
|
}
|
|
24
|
-
function
|
|
26
|
+
function getStreamOfReactStreamingPackage(stream) {
|
|
25
27
|
if (stream.pipe) {
|
|
26
|
-
// TODO
|
|
27
28
|
return { __streamPipeNode: stream.pipe };
|
|
28
29
|
}
|
|
29
30
|
if (stream.readable) {
|
|
@@ -30,7 +30,7 @@ export type { StreamWritableNode };
|
|
|
30
30
|
export type { StreamPipeWeb };
|
|
31
31
|
export type { StreamPipeNode };
|
|
32
32
|
import { HtmlRender } from './renderHtml.js';
|
|
33
|
-
import {
|
|
33
|
+
import { StreamFromReactStreamingPackagePublic } from './stream/react-streaming.js';
|
|
34
34
|
import type { Readable as Readable_, Writable as Writable_ } from 'node:stream';
|
|
35
35
|
type StreamReadableWeb = ReadableStream;
|
|
36
36
|
type StreamReadableNode = Readable_;
|
|
@@ -39,7 +39,7 @@ type StreamWritableNode = Writable_;
|
|
|
39
39
|
type StreamPipeWeb = (writable: StreamWritableWeb) => void;
|
|
40
40
|
type StreamPipeNode = (writable: StreamWritableNode) => void;
|
|
41
41
|
type StreamProviderNormalized = StreamReadableWeb | StreamReadableNode | StreamPipeWeb | StreamPipeNode;
|
|
42
|
-
type StreamProviderAny = StreamProviderNormalized |
|
|
42
|
+
type StreamProviderAny = StreamProviderNormalized | StreamFromReactStreamingPackagePublic | StreamPipeWebWrapped | StreamPipeNodeWrapped;
|
|
43
43
|
type StreamTypePatch = NodeJS.ReadableStream;
|
|
44
44
|
declare function isStreamReadableWeb(thing: unknown): thing is StreamReadableWeb;
|
|
45
45
|
declare function isStreamWritableWeb(thing: unknown): thing is StreamWritableWeb;
|
|
@@ -20,7 +20,7 @@ export { streamPipeNodeToString };
|
|
|
20
20
|
export { isStreamWritableWeb };
|
|
21
21
|
export { isStreamWritableNode };
|
|
22
22
|
import { assert, assertUsage, checkType, isObject, hasProp, objectAssign, capitalizeFirstLetter, assertWarning, isCallable, createDebugger, isBug } from '../utils.js';
|
|
23
|
-
import {
|
|
23
|
+
import { getStreamOfReactStreamingPackage, isStreamFromReactStreamingPackage, streamFromReactStreamingPackageToString } from './stream/react-streaming.js';
|
|
24
24
|
import { import_ } from '@brillout/import';
|
|
25
25
|
import pc from '@brillout/picocolors';
|
|
26
26
|
const debug = createDebugger('vike:stream');
|
|
@@ -358,9 +358,9 @@ async function processStream(streamOriginal, { injectStringAtBegin, injectString
|
|
|
358
358
|
}
|
|
359
359
|
}
|
|
360
360
|
async function createStreamWrapper({ streamOriginal, onError, onData, onEnd, onFlush, onReadyToWrite }) {
|
|
361
|
-
if (
|
|
361
|
+
if (isStreamFromReactStreamingPackage(streamOriginal)) {
|
|
362
362
|
debug(`onRenderHtml() hook returned ${pc.cyan('react-streaming')} result`);
|
|
363
|
-
const stream =
|
|
363
|
+
const stream = getStreamOfReactStreamingPackage(streamOriginal);
|
|
364
364
|
streamOriginal = stream;
|
|
365
365
|
}
|
|
366
366
|
if (isStreamPipeNode(streamOriginal)) {
|
|
@@ -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
|
|
@@ -625,7 +625,7 @@ function isStream(something) {
|
|
|
625
625
|
isStreamReadableNode(something) ||
|
|
626
626
|
isStreamPipeNode(something) ||
|
|
627
627
|
isStreamPipeWeb(something) ||
|
|
628
|
-
|
|
628
|
+
isStreamFromReactStreamingPackage(something)) {
|
|
629
629
|
checkType(something);
|
|
630
630
|
return true;
|
|
631
631
|
}
|
|
@@ -730,8 +730,8 @@ async function streamToString(stream) {
|
|
|
730
730
|
if (isStreamPipeWeb(stream)) {
|
|
731
731
|
return await streamPipeWebToString(getStreamPipeWeb(stream));
|
|
732
732
|
}
|
|
733
|
-
if (
|
|
734
|
-
return await
|
|
733
|
+
if (isStreamFromReactStreamingPackage(stream)) {
|
|
734
|
+
return await streamFromReactStreamingPackageToString(stream);
|
|
735
735
|
}
|
|
736
736
|
assert(false);
|
|
737
737
|
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isVikeReactApp(): boolean;
|
|
@@ -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,17 +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
|
-
];
|
|
23
15
|
function isParsable(url) {
|
|
24
16
|
// `parseUrl()` works with these URLs
|
|
25
|
-
return (
|
|
17
|
+
return (isUrlWithProtocol(url) ||
|
|
26
18
|
url.startsWith('/') ||
|
|
27
19
|
url.startsWith('.') ||
|
|
28
20
|
url.startsWith('?') ||
|
|
@@ -137,7 +129,8 @@ function getPathname(url, baseServer) {
|
|
|
137
129
|
}
|
|
138
130
|
}
|
|
139
131
|
function parseOrigin(url) {
|
|
140
|
-
if (!
|
|
132
|
+
if (!isUrlWithProtocol(url)) {
|
|
133
|
+
assert(!isUriWithProtocol(url));
|
|
141
134
|
return { pathname: url, origin: null };
|
|
142
135
|
}
|
|
143
136
|
else {
|
|
@@ -235,7 +228,19 @@ function createUrlFromComponents(origin, pathname, searchOriginal, hashOriginal)
|
|
|
235
228
|
const urlRecreated = `${origin || ''}${pathname}${searchOriginal || ''}${hashOriginal || ''}`;
|
|
236
229
|
return urlRecreated;
|
|
237
230
|
}
|
|
238
|
-
function isUriWithProtocol(
|
|
231
|
+
function isUriWithProtocol(str) {
|
|
239
232
|
// https://en.wikipedia.org/wiki/List_of_URI_schemes
|
|
240
|
-
|
|
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);
|
|
241
246
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vike",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.178",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "tsc --watch",
|
|
6
6
|
"build": "rimraf dist/ && pnpm run build:esm && pnpm run build:cjs",
|
|
@@ -138,7 +138,7 @@
|
|
|
138
138
|
}
|
|
139
139
|
},
|
|
140
140
|
"peerDependencies": {
|
|
141
|
-
"react-streaming": ">=0.3.
|
|
141
|
+
"react-streaming": ">=0.3.36",
|
|
142
142
|
"vite": ">=4.4.0"
|
|
143
143
|
},
|
|
144
144
|
"peerDependenciesMeta": {
|
|
@@ -209,7 +209,7 @@
|
|
|
209
209
|
"es-module-lexer": "^1.4.1",
|
|
210
210
|
"esbuild": "^0.19.10",
|
|
211
211
|
"fast-glob": "^3.3.2",
|
|
212
|
-
"react-streaming": "^0.3.
|
|
212
|
+
"react-streaming": "^0.3.36",
|
|
213
213
|
"rimraf": "^5.0.5",
|
|
214
214
|
"sirv": "^2.0.4",
|
|
215
215
|
"source-map-support": "^0.5.21",
|