rasengan 1.0.0-beta.36 → 1.0.0-beta.37
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/lib/esm/cli/index.js +24 -43
- package/lib/esm/config/index.js +27 -10
- package/lib/esm/core/components/index.js +3 -3
- package/lib/esm/entries/entry-server-stream.js +112 -0
- package/lib/esm/entries/entry-server.js +57 -4
- package/lib/esm/routing/components/index.js +5 -4
- package/lib/esm/scripts/prepare-prod.js +37 -0
- package/lib/esm/scripts/refresh-hack.js +3 -20
- package/lib/esm/server/utils/createReadableStream.js +103 -0
- package/lib/esm/server/utils/index.js +2 -1
- package/lib/types/config/index.d.ts +6 -0
- package/lib/types/config/type.d.ts +13 -0
- package/lib/types/core/components/index.d.ts +3 -2
- package/lib/types/core/index.d.ts +0 -1
- package/lib/types/decorators/route.d.ts +1 -1
- package/lib/types/entries/entry-server-stream.d.ts +4 -0
- package/lib/types/entries/entry-server.d.ts +3 -4
- package/lib/types/routing/components/index.d.ts +2 -2
- package/lib/types/scripts/prepare-prod.d.ts +1 -0
- package/lib/types/server/utils/createFetchRequest.d.ts +1 -1
- package/lib/types/server/utils/createReadableStream.d.ts +12 -0
- package/lib/types/server/utils/index.d.ts +2 -1
- package/package.json +127 -126
- package/server.js +237 -217
- package/types/client.d.ts +18 -0
- package/vite.config.ts +94 -71
- package/lib/esm/core/interfaces.js +0 -183
- package/lib/types/core/interfaces.d.ts +0 -93
package/lib/esm/cli/index.js
CHANGED
|
@@ -49,9 +49,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
49
49
|
import chalk from "chalk";
|
|
50
50
|
import { Command } from "commander";
|
|
51
51
|
import { execa } from "execa";
|
|
52
|
-
// Config
|
|
53
52
|
// @ts-ignore
|
|
54
|
-
import
|
|
53
|
+
import path from "node:path";
|
|
55
54
|
var program = new Command();
|
|
56
55
|
program
|
|
57
56
|
.name(chalk.blue("rasengan"))
|
|
@@ -95,48 +94,30 @@ program
|
|
|
95
94
|
program
|
|
96
95
|
.command("prepare")
|
|
97
96
|
.description("Prepare the project")
|
|
98
|
-
.action(function () {
|
|
97
|
+
.action(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
98
|
+
var appConfig, server, hostingStrategy;
|
|
99
99
|
var _a, _b;
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
console.log("Your project is configured to be hosted on ".concat(chalk.bold.blue(hostingStrategy), "\n"));
|
|
122
|
-
// create a netlify folder at the root
|
|
123
|
-
execa("mkdir", ["-p", "netlify"], {
|
|
124
|
-
stdio: "inherit",
|
|
125
|
-
});
|
|
126
|
-
// Copying the netlify folder to the root directory
|
|
127
|
-
execa("cp", [
|
|
128
|
-
"-r",
|
|
129
|
-
"node_modules/rasengan/lib/esm/server/functions/netlify/functions",
|
|
130
|
-
"./netlify",
|
|
131
|
-
], {
|
|
132
|
-
stdio: "inherit",
|
|
133
|
-
});
|
|
134
|
-
// Copying the netlify.toml file to the root directory
|
|
135
|
-
execa("cp", ["node_modules/rasengan/lib/esm/server/functions/netlify/netlify.toml", "."], {
|
|
136
|
-
stdio: "inherit",
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
});
|
|
100
|
+
return __generator(this, function (_c) {
|
|
101
|
+
switch (_c.label) {
|
|
102
|
+
case 0:
|
|
103
|
+
// Displaying the message
|
|
104
|
+
console.log("");
|
|
105
|
+
console.log(chalk.blue("Preparing your project for production..."));
|
|
106
|
+
console.log("");
|
|
107
|
+
return [4 /*yield*/, import(path.join(process.cwd(), "rasengan.config.js"))];
|
|
108
|
+
case 1:
|
|
109
|
+
appConfig = _c.sent();
|
|
110
|
+
server = appConfig.server;
|
|
111
|
+
hostingStrategy = (_b = (_a = server === null || server === void 0 ? void 0 : server.production) === null || _a === void 0 ? void 0 : _a.hosting) !== null && _b !== void 0 ? _b : "custom";
|
|
112
|
+
execa("node", ["node_modules/rasengan/lib/esm/scripts/prepare-prod"], {
|
|
113
|
+
stdio: "inherit",
|
|
114
|
+
// cwd: "node_modules/rasengan/lib/esm/scripts",
|
|
115
|
+
env: __assign(__assign({}, process.env), { HOSTING_STRATEGY: hostingStrategy })
|
|
116
|
+
});
|
|
117
|
+
return [2 /*return*/];
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}); });
|
|
140
121
|
// Handle the start command
|
|
141
122
|
program
|
|
142
123
|
.command("start")
|
package/lib/esm/config/index.js
CHANGED
|
@@ -13,8 +13,8 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
13
13
|
* @param {AppConfig} loadedConfig
|
|
14
14
|
*/
|
|
15
15
|
export var defineConfig = function (loadedConfig) {
|
|
16
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
17
|
-
var reactStrictMode = loadedConfig.reactStrictMode, server = loadedConfig.server, vite = loadedConfig.vite;
|
|
16
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
17
|
+
var reactStrictMode = loadedConfig.reactStrictMode, server = loadedConfig.server, vite = loadedConfig.vite, experimental = loadedConfig.experimental;
|
|
18
18
|
// Define default values for vite config coming from loadedConfig.vite
|
|
19
19
|
var defaultViteConfig = {
|
|
20
20
|
plugins: (vite === null || vite === void 0 ? void 0 : vite.plugins) || [],
|
|
@@ -29,19 +29,24 @@ export var defineConfig = function (loadedConfig) {
|
|
|
29
29
|
external: ((_d = vite === null || vite === void 0 ? void 0 : vite.build) === null || _d === void 0 ? void 0 : _d.external) || [],
|
|
30
30
|
},
|
|
31
31
|
resolve: {
|
|
32
|
-
|
|
32
|
+
symbole: ((_e = vite === null || vite === void 0 ? void 0 : vite.resolve) === null || _e === void 0 ? void 0 : _e.symbole) || '@',
|
|
33
|
+
alias: ((_f = vite === null || vite === void 0 ? void 0 : vite.resolve) === null || _f === void 0 ? void 0 : _f.alias) || [],
|
|
33
34
|
},
|
|
34
35
|
};
|
|
35
36
|
// Define default values for server config coming from loadedConfig.server
|
|
36
37
|
var defaultServerConfig = {
|
|
37
38
|
development: {
|
|
38
|
-
port: ((
|
|
39
|
-
open: ((
|
|
39
|
+
port: ((_g = server === null || server === void 0 ? void 0 : server.development) === null || _g === void 0 ? void 0 : _g.port) || undefined,
|
|
40
|
+
open: ((_h = server === null || server === void 0 ? void 0 : server.development) === null || _h === void 0 ? void 0 : _h.open) || false,
|
|
40
41
|
},
|
|
41
42
|
production: {
|
|
42
|
-
hosting: ((
|
|
43
|
+
hosting: ((_j = server === null || server === void 0 ? void 0 : server.production) === null || _j === void 0 ? void 0 : _j.hosting) || "custom",
|
|
43
44
|
},
|
|
44
45
|
};
|
|
46
|
+
// Define default values for experimentals features coming from loadedConfig.experimentals
|
|
47
|
+
var defaultExperimentalFeaturesConfig = {
|
|
48
|
+
stream: (experimental === null || experimental === void 0 ? void 0 : experimental.stream) || false
|
|
49
|
+
};
|
|
45
50
|
try {
|
|
46
51
|
var config = {
|
|
47
52
|
reactStrictMode: reactStrictMode === undefined ? true : reactStrictMode,
|
|
@@ -74,13 +79,18 @@ export var defineConfig = function (loadedConfig) {
|
|
|
74
79
|
// concat two arrays
|
|
75
80
|
alias: __spreadArray([
|
|
76
81
|
{
|
|
77
|
-
find:
|
|
78
|
-
replacement: "src
|
|
82
|
+
find: defaultViteConfig.resolve.symbole,
|
|
83
|
+
replacement: "./src",
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
find: "path",
|
|
87
|
+
replacement: "node_modules/path-browserify",
|
|
79
88
|
}
|
|
80
89
|
], defaultViteConfig.resolve.alias, true),
|
|
81
90
|
},
|
|
82
91
|
appType: "custom",
|
|
83
92
|
},
|
|
93
|
+
experimental: defaultExperimentalFeaturesConfig,
|
|
84
94
|
// More config options...
|
|
85
95
|
};
|
|
86
96
|
return config;
|
|
@@ -107,12 +117,19 @@ export var defineConfig = function (loadedConfig) {
|
|
|
107
117
|
resolve: {
|
|
108
118
|
alias: [
|
|
109
119
|
{
|
|
110
|
-
find: "
|
|
111
|
-
replacement: "src
|
|
120
|
+
find: "@",
|
|
121
|
+
replacement: "./src",
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
find: "path",
|
|
125
|
+
replacement: "node_modules/path-browserify",
|
|
112
126
|
},
|
|
113
127
|
],
|
|
114
128
|
},
|
|
115
129
|
},
|
|
130
|
+
experimental: {
|
|
131
|
+
stream: false
|
|
132
|
+
},
|
|
116
133
|
};
|
|
117
134
|
}
|
|
118
135
|
};
|
|
@@ -24,7 +24,7 @@ var __assign = (this && this.__assign) || function () {
|
|
|
24
24
|
};
|
|
25
25
|
return __assign.apply(this, arguments);
|
|
26
26
|
};
|
|
27
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
27
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
28
28
|
import React from "react";
|
|
29
29
|
import { generateMetadata, getRouter } from "../../routing/utils/index.js";
|
|
30
30
|
import { Outlet, useParams } from "react-router-dom";
|
|
@@ -124,10 +124,10 @@ export var Heads = function (_a) {
|
|
|
124
124
|
* Body component
|
|
125
125
|
*/
|
|
126
126
|
export var Body = function (_a) {
|
|
127
|
-
var _b = _a.children, children = _b === void 0 ? undefined : _b;
|
|
127
|
+
var _b = _a.children, children = _b === void 0 ? undefined : _b, _c = _a.asChild, asChild = _c === void 0 ? false : _c;
|
|
128
128
|
return (_jsxs("body", { children: [_jsx("noscript", { dangerouslySetInnerHTML: {
|
|
129
129
|
__html: "<b>Enable JavaScript to run this app.</b>",
|
|
130
|
-
} }), _jsx("div", { id: "root", children: "rasengan-body-app" }), children] }));
|
|
130
|
+
} }), asChild ? (_jsx("div", { id: 'root', children: children })) : (_jsxs(_Fragment, { children: [_jsx("div", { id: "root", children: "rasengan-body-app" }), children] }))] }));
|
|
131
131
|
};
|
|
132
132
|
/**
|
|
133
133
|
* Scripts component
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
38
|
+
import React from "react";
|
|
39
|
+
import { renderToPipeableStream } from "react-dom/server";
|
|
40
|
+
// @ts-ignore
|
|
41
|
+
import App from "./../../../../../src/main";
|
|
42
|
+
// @ts-ignore
|
|
43
|
+
import Template from "./../../../../../src/template";
|
|
44
|
+
import { Component, ErrorBoundary, Heads, Body, Scripts, } from "../core/components/index.js";
|
|
45
|
+
import { StaticRouterProvider, } from "react-router-dom/server";
|
|
46
|
+
import * as HelmetAsync from "react-helmet-async";
|
|
47
|
+
import refreshScript from "../scripts/refresh-hack.js?raw";
|
|
48
|
+
// @ts-ignore
|
|
49
|
+
var H = HelmetAsync.default ? HelmetAsync.default : HelmetAsync;
|
|
50
|
+
var ABORT_DELAY = 5000;
|
|
51
|
+
var RenderApp = function (_a) {
|
|
52
|
+
var router = _a.router, context = _a.context, helmetContext = _a.helmetContext, styles = _a.styles, bootstrap = _a.bootstrap;
|
|
53
|
+
// inject vite refresh script to avoid "React refresh preamble was not loaded"
|
|
54
|
+
var viteScripts = _jsx(React.Fragment, {});
|
|
55
|
+
if (process.env.NODE_ENV !== "production") {
|
|
56
|
+
viteScripts = (_jsxs(React.Fragment, { children: [_jsx("script", { type: "module", src: "/@vite/client" }), _jsx("script", { type: "module", dangerouslySetInnerHTML: { __html: refreshScript } })] }));
|
|
57
|
+
}
|
|
58
|
+
return (_jsx(H.HelmetProvider, { context: helmetContext, children: _jsx(ErrorBoundary, { children: _jsx(Template, { Head: function (_a) {
|
|
59
|
+
var children = _a.children;
|
|
60
|
+
return (_jsxs(Heads, { data: helmetContext, styles: styles, bootstrap: bootstrap, children: [viteScripts, children] }));
|
|
61
|
+
}, Body: function (_a) {
|
|
62
|
+
var children = _a.children;
|
|
63
|
+
return _jsx(Body, { asChild: true, children: children });
|
|
64
|
+
}, Script: function (_a) {
|
|
65
|
+
var children = _a.children;
|
|
66
|
+
return _jsx(Scripts, { bootstrap: bootstrap, children: children });
|
|
67
|
+
}, children: _jsx(App, { Component: Component, children: _jsx(StaticRouterProvider, { router: router, context: context }) }) }) }) }));
|
|
68
|
+
};
|
|
69
|
+
export default function renderStream(router_1, context_1) {
|
|
70
|
+
return __awaiter(this, arguments, void 0, function (router, context, helmetContext, bootstrap, styles, res) {
|
|
71
|
+
if (helmetContext === void 0) { helmetContext = {}; }
|
|
72
|
+
return __generator(this, function (_a) {
|
|
73
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
74
|
+
var shellRendered = false;
|
|
75
|
+
var responseStatusCode = 200;
|
|
76
|
+
var _a = renderToPipeableStream(_jsx(RenderApp, { router: router, context: context, helmetContext: helmetContext, bootstrap: bootstrap, styles: styles }), {
|
|
77
|
+
// bootstrapModules: [bootstrap],
|
|
78
|
+
onShellReady: function () {
|
|
79
|
+
// console.log("hummm")
|
|
80
|
+
shellRendered = true;
|
|
81
|
+
// const body = new PassThrough();
|
|
82
|
+
// const stream = createReadableStreamFromReadable(body);
|
|
83
|
+
// console.log({
|
|
84
|
+
// body,
|
|
85
|
+
// stream
|
|
86
|
+
// })
|
|
87
|
+
res.status(200).set({
|
|
88
|
+
"Content-Type": "text/html",
|
|
89
|
+
"Cache-Control": "max-age=31536000",
|
|
90
|
+
});
|
|
91
|
+
resolve(res);
|
|
92
|
+
pipe(res);
|
|
93
|
+
},
|
|
94
|
+
onShellError: function (error) {
|
|
95
|
+
console.log({ error: error });
|
|
96
|
+
reject(error);
|
|
97
|
+
},
|
|
98
|
+
onError: function (error) {
|
|
99
|
+
responseStatusCode = 500;
|
|
100
|
+
// Log streaming rendering errors from inside the shell. Don't log
|
|
101
|
+
// errors encountered during initial shell rendering since they'll
|
|
102
|
+
// reject and get logged in handleDocumentRequest.
|
|
103
|
+
if (shellRendered) {
|
|
104
|
+
console.error(error);
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
}), pipe = _a.pipe, abort = _a.abort;
|
|
108
|
+
setTimeout(abort, ABORT_DELAY);
|
|
109
|
+
})];
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
}
|
|
@@ -1,3 +1,39 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
1
37
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
38
|
import React from "react";
|
|
3
39
|
import ReactDOMServer from "react-dom/server";
|
|
@@ -14,6 +50,7 @@ import { StaticRouterProvider, } from "react-router-dom/server.js";
|
|
|
14
50
|
import config from "./../../../../../rasengan.config.js";
|
|
15
51
|
import { Component, ErrorBoundary, Heads, Body, Scripts, } from "../core/components/index.js";
|
|
16
52
|
import * as HelmetAsync from "react-helmet-async";
|
|
53
|
+
import renderStream from "./entry-server-stream.js";
|
|
17
54
|
// @ts-ignore
|
|
18
55
|
var H = HelmetAsync.default ? HelmetAsync.default : HelmetAsync;
|
|
19
56
|
// const ABORT_DELAY = 5000;
|
|
@@ -37,10 +74,26 @@ var TemplateHtml = function (_a) {
|
|
|
37
74
|
* @param helmetContext
|
|
38
75
|
* @returns
|
|
39
76
|
*/
|
|
40
|
-
export function render(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
77
|
+
export function render(router_1, context_1) {
|
|
78
|
+
return __awaiter(this, arguments, void 0, function (router, context, helmetContext, bootstrap, styles, res) {
|
|
79
|
+
var html;
|
|
80
|
+
if (helmetContext === void 0) { helmetContext = {}; }
|
|
81
|
+
if (bootstrap === void 0) { bootstrap = ""; }
|
|
82
|
+
if (styles === void 0) { styles = ""; }
|
|
83
|
+
return __generator(this, function (_a) {
|
|
84
|
+
switch (_a.label) {
|
|
85
|
+
case 0:
|
|
86
|
+
if (!config.experimental.stream) return [3 /*break*/, 2];
|
|
87
|
+
if (!res)
|
|
88
|
+
return [2 /*return*/];
|
|
89
|
+
return [4 /*yield*/, renderStream(router, context, helmetContext, bootstrap, styles, res)];
|
|
90
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
91
|
+
case 2:
|
|
92
|
+
html = ReactDOMServer.renderToString(config.reactStrictMode ? (_jsx(React.StrictMode, { children: _jsx(H.HelmetProvider, { context: helmetContext, children: _jsx(ErrorBoundary, { children: _jsx(App, { Component: Component, children: _jsx(StaticRouterProvider, { router: router, context: context }) }) }) }) })) : (_jsx(H.HelmetProvider, { context: helmetContext, children: _jsx(ErrorBoundary, { children: _jsx(App, { Component: Component, children: _jsx(StaticRouterProvider, { router: router, context: context }) }) }) })));
|
|
93
|
+
return [2 /*return*/, { html: html }];
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
});
|
|
44
97
|
}
|
|
45
98
|
export var staticRoutes = generateStaticRoutes(AppRouter);
|
|
46
99
|
export var loadTemplateHtml = function (helmetContext, bootstrap, styles) {
|
|
@@ -21,6 +21,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
21
21
|
return t;
|
|
22
22
|
};
|
|
23
23
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
24
|
+
import { Suspense } from "react";
|
|
24
25
|
import { Link, useLoaderData, useRouteError } from "react-router-dom";
|
|
25
26
|
import { PageToRender } from "../../core/components/index.js";
|
|
26
27
|
/**
|
|
@@ -37,7 +38,7 @@ export function ErrorBoundary() {
|
|
|
37
38
|
* @returns React.ReactNode
|
|
38
39
|
*/
|
|
39
40
|
export var ServerComponent = function (_a) {
|
|
40
|
-
var page = _a.page, layoutMetadata = _a.layoutMetadata;
|
|
41
|
+
var page = _a.page, layoutMetadata = _a.layoutMetadata, loader = _a.loader;
|
|
41
42
|
// Default data
|
|
42
43
|
var defaultData = {
|
|
43
44
|
props: {
|
|
@@ -45,14 +46,14 @@ export var ServerComponent = function (_a) {
|
|
|
45
46
|
},
|
|
46
47
|
};
|
|
47
48
|
var data = useLoaderData() || defaultData;
|
|
48
|
-
return (_jsx(PageToRender, { page: page, data: data, layoutMetadata: layoutMetadata }));
|
|
49
|
+
return (_jsx(Suspense, { fallback: loader, children: _jsx(PageToRender, { page: page, data: data, layoutMetadata: layoutMetadata }) }));
|
|
49
50
|
};
|
|
50
51
|
/**
|
|
51
52
|
* Component that will be displayed during a routing on the client side
|
|
52
53
|
* @returns React.ReactNode
|
|
53
54
|
*/
|
|
54
55
|
export var ClientComponent = function (_a) {
|
|
55
|
-
var page = _a.page, layoutMetadata = _a.layoutMetadata;
|
|
56
|
+
var page = _a.page, layoutMetadata = _a.layoutMetadata, loader = _a.loader;
|
|
56
57
|
// Default data
|
|
57
58
|
var defaultData = {
|
|
58
59
|
props: {
|
|
@@ -60,7 +61,7 @@ export var ClientComponent = function (_a) {
|
|
|
60
61
|
},
|
|
61
62
|
};
|
|
62
63
|
var data = useLoaderData() || defaultData;
|
|
63
|
-
return (_jsx(PageToRender, { page: page, data: data, layoutMetadata: layoutMetadata }));
|
|
64
|
+
return (_jsx(Suspense, { fallback: loader, children: _jsx(PageToRender, { page: page, data: data, layoutMetadata: layoutMetadata }) }));
|
|
64
65
|
};
|
|
65
66
|
/**
|
|
66
67
|
* Component that will be displayed when a page is not found
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { execa } from "execa";
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
var hostingStrategy = process.env.HOSTING_STRATEGY || "custom";
|
|
4
|
+
(function () {
|
|
5
|
+
if (hostingStrategy === "vercel") {
|
|
6
|
+
// Displaying the message
|
|
7
|
+
console.log("Your project is configured to be hosted on ".concat(chalk.bold.blue(hostingStrategy), "\n"));
|
|
8
|
+
// Copying the api folder to the root directory
|
|
9
|
+
execa("cp", ["-r", "node_modules/rasengan/lib/esm/server/functions/vercel/api", "."], {
|
|
10
|
+
stdio: "inherit",
|
|
11
|
+
});
|
|
12
|
+
// Copying the vercel.json file to the root directory
|
|
13
|
+
execa("cp", ["node_modules/rasengan/lib/esm/server/functions/vercel/vercel.json", "."], {
|
|
14
|
+
stdio: "inherit",
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
else if (hostingStrategy === "netlify") {
|
|
18
|
+
// Displaying the message
|
|
19
|
+
console.log("Your project is configured to be hosted on ".concat(chalk.bold.blue(hostingStrategy), "\n"));
|
|
20
|
+
// create a netlify folder at the root
|
|
21
|
+
execa("mkdir", ["-p", "netlify"], {
|
|
22
|
+
stdio: "inherit",
|
|
23
|
+
});
|
|
24
|
+
// Copying the netlify folder to the root directory
|
|
25
|
+
execa("cp", [
|
|
26
|
+
"-r",
|
|
27
|
+
"node_modules/rasengan/lib/esm/server/functions/netlify/functions",
|
|
28
|
+
"./netlify",
|
|
29
|
+
], {
|
|
30
|
+
stdio: "inherit",
|
|
31
|
+
});
|
|
32
|
+
// Copying the netlify.toml file to the root directory
|
|
33
|
+
execa("cp", ["node_modules/rasengan/lib/esm/server/functions/netlify/netlify.toml", "."], {
|
|
34
|
+
stdio: "inherit",
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
})();
|
|
@@ -1,22 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
injectIntoGlobalHook(window);
|
|
4
|
-
var globalHook = window.__REACT_DEVTOOLS_GLOBAL_HOOK__;
|
|
5
|
-
var oldCommit = globalHook.onCommitFiberRoot;
|
|
6
|
-
globalHook.onCommitFiberRoot = function (id, root, maybePriorityLevel, didError) {
|
|
7
|
-
try {
|
|
8
|
-
if (!root.containerInfo.dataset.hacked) {
|
|
9
|
-
// In SSR context, the root is considered mounted and waiting for hydration.
|
|
10
|
-
// Old commit function from react-refresh would not track this root, thus,
|
|
11
|
-
// disable vite hot reload. We clears the element to work around that.
|
|
12
|
-
root.current.alternate.memoizedState.element = null;
|
|
13
|
-
// remember this root node, as if we keep reseting, react-dev-tools won't
|
|
14
|
-
// be able to work properly.
|
|
15
|
-
root.containerInfo.dataset.hacked = true;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
catch (ignored) { }
|
|
19
|
-
oldCommit(id, root, maybePriorityLevel, didError);
|
|
20
|
-
};
|
|
1
|
+
import RefreshRuntime from "/@react-refresh";
|
|
2
|
+
RefreshRuntime.injectIntoGlobalHook(window);
|
|
21
3
|
window.$RefreshReg$ = function () { };
|
|
22
4
|
window.$RefreshSig$ = function () { return function (type) { return type; }; };
|
|
5
|
+
window.__vite_plugin_react_preamble_installed__ = true;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a ReadableStream from a Readable or PassThrough stream.
|
|
3
|
+
*
|
|
4
|
+
* The returned ReadableStream will emit the same data events as the input stream,
|
|
5
|
+
* and will close or error out when the input stream does.
|
|
6
|
+
*
|
|
7
|
+
* @param readable The Readable or PassThrough stream to convert to a ReadableStream.
|
|
8
|
+
* @returns A new ReadableStream instance that wraps the input stream.
|
|
9
|
+
*/
|
|
10
|
+
export function createReadableStreamFromReadable(readable) {
|
|
11
|
+
return new ReadableStream({
|
|
12
|
+
start: function (controller) {
|
|
13
|
+
readable.on("data", function (chunk) {
|
|
14
|
+
controller.enqueue(chunk);
|
|
15
|
+
});
|
|
16
|
+
readable.on("end", function () {
|
|
17
|
+
controller.close();
|
|
18
|
+
});
|
|
19
|
+
readable.on("error", function (err) {
|
|
20
|
+
controller.error(err);
|
|
21
|
+
});
|
|
22
|
+
},
|
|
23
|
+
cancel: function () {
|
|
24
|
+
readable.destroy();
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
// export function createReadableStreamFromReadable2(
|
|
29
|
+
// source: Readable
|
|
30
|
+
// ) {
|
|
31
|
+
// let pump = new StreamPump(source);
|
|
32
|
+
// let stream = new ReadableStream(pump, pump);
|
|
33
|
+
// return stream;
|
|
34
|
+
// }
|
|
35
|
+
// class StreamPump {
|
|
36
|
+
// constructor(stream: Readable) {
|
|
37
|
+
// this.highWaterMark = stream.readableHighWaterMark || new Stream.Readable().readableHighWaterMark;
|
|
38
|
+
// this.accumalatedSize = 0;
|
|
39
|
+
// this.stream = stream;
|
|
40
|
+
// this.enqueue = this.enqueue.bind(this);
|
|
41
|
+
// this.error = this.error.bind(this);
|
|
42
|
+
// this.close = this.close.bind(this);
|
|
43
|
+
// }
|
|
44
|
+
// size(chunk) {
|
|
45
|
+
// return (chunk === null || chunk === void 0 ? void 0 : chunk.byteLength) || 0;
|
|
46
|
+
// }
|
|
47
|
+
// start(controller) {
|
|
48
|
+
// this.controller = controller;
|
|
49
|
+
// this.stream.on("data", this.enqueue);
|
|
50
|
+
// this.stream.once("error", this.error);
|
|
51
|
+
// this.stream.once("end", this.close);
|
|
52
|
+
// this.stream.once("close", this.close);
|
|
53
|
+
// }
|
|
54
|
+
// pull() {
|
|
55
|
+
// this.resume();
|
|
56
|
+
// }
|
|
57
|
+
// cancel(reason) {
|
|
58
|
+
// if (this.stream.destroy) {
|
|
59
|
+
// this.stream.destroy(reason);
|
|
60
|
+
// }
|
|
61
|
+
// this.stream.off("data", this.enqueue);
|
|
62
|
+
// this.stream.off("error", this.error);
|
|
63
|
+
// this.stream.off("end", this.close);
|
|
64
|
+
// this.stream.off("close", this.close);
|
|
65
|
+
// }
|
|
66
|
+
// enqueue(chunk) {
|
|
67
|
+
// if (this.controller) {
|
|
68
|
+
// try {
|
|
69
|
+
// let bytes = chunk instanceof Uint8Array ? chunk : Buffer.from(chunk);
|
|
70
|
+
// let available = (this.controller.desiredSize || 0) - bytes.byteLength;
|
|
71
|
+
// this.controller.enqueue(bytes);
|
|
72
|
+
// if (available <= 0) {
|
|
73
|
+
// this.pause();
|
|
74
|
+
// }
|
|
75
|
+
// } catch (error) {
|
|
76
|
+
// this.controller.error(new Error("Could not create Buffer, chunk must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object"));
|
|
77
|
+
// this.cancel();
|
|
78
|
+
// }
|
|
79
|
+
// }
|
|
80
|
+
// }
|
|
81
|
+
// pause() {
|
|
82
|
+
// if (this.stream.pause) {
|
|
83
|
+
// this.stream.pause();
|
|
84
|
+
// }
|
|
85
|
+
// }
|
|
86
|
+
// resume() {
|
|
87
|
+
// if (this.stream.readable && this.stream.resume) {
|
|
88
|
+
// this.stream.resume();
|
|
89
|
+
// }
|
|
90
|
+
// }
|
|
91
|
+
// close() {
|
|
92
|
+
// if (this.controller) {
|
|
93
|
+
// this.controller.close();
|
|
94
|
+
// delete this.controller;
|
|
95
|
+
// }
|
|
96
|
+
// }
|
|
97
|
+
// error(error) {
|
|
98
|
+
// if (this.controller) {
|
|
99
|
+
// this.controller.error(error);
|
|
100
|
+
// delete this.controller;
|
|
101
|
+
// }
|
|
102
|
+
// }
|
|
103
|
+
// }
|
|
@@ -3,5 +3,6 @@ import createFetchRequest from "./createFetchRequest.js";
|
|
|
3
3
|
import getIP from "./getIp.js";
|
|
4
4
|
import { logServerInfo } from "./log.js";
|
|
5
5
|
import { fix404 } from "./handleError.js";
|
|
6
|
+
import { createReadableStreamFromReadable } from "./createReadableStream.js";
|
|
6
7
|
// Export section
|
|
7
|
-
export { createFetchRequest, getIP, logServerInfo, fix404, };
|
|
8
|
+
export { createFetchRequest, getIP, logServerInfo, fix404, createReadableStreamFromReadable, };
|
|
@@ -37,6 +37,9 @@ export declare const defineConfig: (loadedConfig: AppConfig) => {
|
|
|
37
37
|
};
|
|
38
38
|
appType: string;
|
|
39
39
|
};
|
|
40
|
+
experimental: {
|
|
41
|
+
stream: boolean;
|
|
42
|
+
};
|
|
40
43
|
} | {
|
|
41
44
|
reactStrictMode: boolean;
|
|
42
45
|
vite: {
|
|
@@ -52,6 +55,9 @@ export declare const defineConfig: (loadedConfig: AppConfig) => {
|
|
|
52
55
|
}[];
|
|
53
56
|
};
|
|
54
57
|
};
|
|
58
|
+
experimental: {
|
|
59
|
+
stream: boolean;
|
|
60
|
+
};
|
|
55
61
|
};
|
|
56
62
|
/**
|
|
57
63
|
* Function to adapt the path for dev and prod
|
|
@@ -76,6 +76,10 @@ export type AppConfig = {
|
|
|
76
76
|
* Configure resolve options
|
|
77
77
|
*/
|
|
78
78
|
resolve?: {
|
|
79
|
+
/**
|
|
80
|
+
* Configure the starting point of the aliases
|
|
81
|
+
*/
|
|
82
|
+
symbole?: string;
|
|
79
83
|
/**
|
|
80
84
|
* Configure aliases
|
|
81
85
|
*/
|
|
@@ -85,6 +89,15 @@ export type AppConfig = {
|
|
|
85
89
|
}>;
|
|
86
90
|
};
|
|
87
91
|
};
|
|
92
|
+
/**
|
|
93
|
+
* List of experimental features
|
|
94
|
+
*/
|
|
95
|
+
experimental?: {
|
|
96
|
+
/**
|
|
97
|
+
* Enable stream mode in order to use suspense feature of react
|
|
98
|
+
*/
|
|
99
|
+
stream?: boolean;
|
|
100
|
+
};
|
|
88
101
|
};
|
|
89
102
|
/**
|
|
90
103
|
* Hosting strategy
|