rasengan 1.0.0-beta.35 → 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.
Files changed (33) hide show
  1. package/lib/esm/cli/index.js +42 -63
  2. package/lib/esm/config/index.js +27 -10
  3. package/lib/esm/core/components/index.js +3 -3
  4. package/lib/esm/entries/entry-server-stream.js +112 -0
  5. package/lib/esm/entries/entry-server.js +57 -4
  6. package/lib/esm/routing/components/index.js +5 -4
  7. package/lib/esm/routing/utils/index.js +41 -43
  8. package/lib/esm/scripts/prepare-prod.js +37 -0
  9. package/lib/esm/scripts/refresh-hack.js +3 -20
  10. package/lib/esm/server/functions/vercel/api/index.js +26 -22
  11. package/lib/esm/server/utils/createFetchRequest.js +1 -0
  12. package/lib/esm/server/utils/createReadableStream.js +103 -0
  13. package/lib/esm/server/utils/handleRequest.js +1 -1
  14. package/lib/esm/server/utils/index.js +2 -1
  15. package/lib/esm/server/utils/log.js +3 -3
  16. package/lib/types/config/index.d.ts +6 -0
  17. package/lib/types/config/type.d.ts +13 -0
  18. package/lib/types/core/components/index.d.ts +3 -2
  19. package/lib/types/core/index.d.ts +0 -1
  20. package/lib/types/decorators/route.d.ts +1 -1
  21. package/lib/types/entries/entry-server-stream.d.ts +4 -0
  22. package/lib/types/entries/entry-server.d.ts +3 -4
  23. package/lib/types/routing/components/index.d.ts +2 -2
  24. package/lib/types/scripts/prepare-prod.d.ts +1 -0
  25. package/lib/types/server/utils/createFetchRequest.d.ts +1 -1
  26. package/lib/types/server/utils/createReadableStream.d.ts +12 -0
  27. package/lib/types/server/utils/index.d.ts +2 -1
  28. package/package.json +6 -6
  29. package/server.js +237 -217
  30. package/types/client.d.ts +18 -0
  31. package/vite.config.ts +94 -71
  32. package/lib/esm/core/interfaces.js +0 -183
  33. package/lib/types/core/interfaces.d.ts +0 -93
@@ -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 config from "../../../../../rasengan.config.js";
53
+ import path from "node:path";
55
54
  var program = new Command();
56
55
  program
57
56
  .name(chalk.blue("rasengan"))
@@ -61,28 +60,26 @@ program
61
60
  .command("dev")
62
61
  .option("-p <port>")
63
62
  .description("Start development server")
64
- .action(function (_a) {
65
- var port = _a.p;
66
- return __awaiter(void 0, void 0, void 0, function () {
67
- var convertedPort;
68
- return __generator(this, function (_b) {
69
- convertedPort = Number(port);
70
- // Checking port
71
- if (port &&
72
- (isNaN(convertedPort) || convertedPort < 0 || convertedPort > 65535)) {
73
- console.log("");
74
- console.log(chalk.red("Please provide a valid port number between 0-65535"));
75
- console.log("");
76
- process.exit(1);
77
- }
78
- execa("node", ["node_modules/rasengan/server"], {
79
- stdio: "inherit",
80
- env: __assign(__assign({}, process.env), { PORT: convertedPort ? convertedPort.toString() : undefined }),
81
- });
82
- return [2 /*return*/];
63
+ .action(function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
64
+ var convertedPort;
65
+ var port = _b.p;
66
+ return __generator(this, function (_c) {
67
+ convertedPort = Number(port);
68
+ // Checking port
69
+ if (port &&
70
+ (isNaN(convertedPort) || convertedPort < 0 || convertedPort > 65535)) {
71
+ console.log("");
72
+ console.log(chalk.red("Please provide a valid port number between 0-65535"));
73
+ console.log("");
74
+ process.exit(1);
75
+ }
76
+ execa("node", ["node_modules/rasengan/server"], {
77
+ stdio: "inherit",
78
+ env: __assign(__assign({}, process.env), { PORT: convertedPort ? convertedPort.toString() : undefined }),
83
79
  });
80
+ return [2 /*return*/];
84
81
  });
85
- });
82
+ }); });
86
83
  // Handle the build command
87
84
  program
88
85
  .command("build")
@@ -97,48 +94,30 @@ program
97
94
  program
98
95
  .command("prepare")
99
96
  .description("Prepare the project")
100
- .action(function () {
97
+ .action(function () { return __awaiter(void 0, void 0, void 0, function () {
98
+ var appConfig, server, hostingStrategy;
101
99
  var _a, _b;
102
- // Displaying the message
103
- console.log("");
104
- console.log(chalk.blue("Preparing your project for production..."));
105
- console.log("");
106
- // Checking the config file in order to know about hosting strategy
107
- var server = config.server;
108
- var 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";
109
- if (hostingStrategy === "vercel") {
110
- // Displaying the message
111
- console.log("Your project is configured to be hosted on ".concat(chalk.bold.blue(hostingStrategy), "\n"));
112
- // Copying the api folder to the root directory
113
- execa("cp", ["-r", "node_modules/rasengan/lib/esm/server/functions/vercel/api", "."], {
114
- stdio: "inherit",
115
- });
116
- // Copying the vercel.json file to the root directory
117
- execa("cp", ["node_modules/rasengan/lib/esm/server/functions/vercel/vercel.json", "."], {
118
- stdio: "inherit",
119
- });
120
- }
121
- else if (hostingStrategy === "netlify") {
122
- // Displaying the message
123
- console.log("Your project is configured to be hosted on ".concat(chalk.bold.blue(hostingStrategy), "\n"));
124
- // create a netlify folder at the root
125
- execa("mkdir", ["-p", "netlify"], {
126
- stdio: "inherit",
127
- });
128
- // Copying the netlify folder to the root directory
129
- execa("cp", [
130
- "-r",
131
- "node_modules/rasengan/lib/esm/server/functions/netlify/functions",
132
- "./netlify",
133
- ], {
134
- stdio: "inherit",
135
- });
136
- // Copying the netlify.toml file to the root directory
137
- execa("cp", ["node_modules/rasengan/lib/esm/server/functions/netlify/netlify.toml", "."], {
138
- stdio: "inherit",
139
- });
140
- }
141
- });
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
+ }); });
142
121
  // Handle the start command
143
122
  program
144
123
  .command("start")
@@ -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
- alias: ((_e = vite === null || vite === void 0 ? void 0 : vite.resolve) === null || _e === void 0 ? void 0 : _e.alias) || [],
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: ((_f = server === null || server === void 0 ? void 0 : server.development) === null || _f === void 0 ? void 0 : _f.port) || undefined,
39
- open: ((_g = server === null || server === void 0 ? void 0 : server.development) === null || _g === void 0 ? void 0 : _g.open) || false,
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: ((_h = server === null || server === void 0 ? void 0 : server.production) === null || _h === void 0 ? void 0 : _h.hosting) || "custom",
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(router, context, helmetContext) {
41
- if (helmetContext === void 0) { helmetContext = {}; }
42
- var 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 }) }) }) })));
43
- return { html: html };
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
@@ -155,43 +155,41 @@ export var generateStaticRoutes = function (router, isRoot) {
155
155
  var finalProps = __assign(__assign({}, props), { params: params });
156
156
  return _jsx(Layout, __assign({}, finalProps));
157
157
  },
158
- loader: function (_a) {
159
- var params = _a.params, request = _a.request;
160
- return __awaiter(void 0, void 0, void 0, function () {
161
- var response, formData, error_1;
162
- return __generator(this, function (_b) {
163
- switch (_b.label) {
164
- case 0:
165
- _b.trys.push([0, 2, , 3]);
166
- // Check if the loader is defined
167
- if (!Layout.loader) {
168
- throw new Error("Missing loader function");
169
- }
170
- return [4 /*yield*/, Layout.loader({ params: params, request: request })];
171
- case 1:
172
- response = _b.sent();
173
- // Handle redirection
174
- if (response.redirect) {
175
- formData = new FormData();
176
- formData.append("redirect", response.redirect);
177
- return [2 /*return*/, new Response(formData, {
178
- status: 302,
179
- headers: {
180
- Location: response.redirect,
181
- },
182
- })];
183
- }
184
- return [2 /*return*/, response];
185
- case 2:
186
- error_1 = _b.sent();
187
- return [2 /*return*/, {
188
- props: {},
189
- }];
190
- case 3: return [2 /*return*/];
191
- }
192
- });
158
+ loader: function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
159
+ var response, formData, error_1;
160
+ var params = _b.params, request = _b.request;
161
+ return __generator(this, function (_c) {
162
+ switch (_c.label) {
163
+ case 0:
164
+ _c.trys.push([0, 2, , 3]);
165
+ // Check if the loader is defined
166
+ if (!Layout.loader) {
167
+ throw new Error("Missing loader function");
168
+ }
169
+ return [4 /*yield*/, Layout.loader({ params: params, request: request })];
170
+ case 1:
171
+ response = _c.sent();
172
+ // Handle redirection
173
+ if (response.redirect) {
174
+ formData = new FormData();
175
+ formData.append("redirect", response.redirect);
176
+ return [2 /*return*/, new Response(formData, {
177
+ status: 302,
178
+ headers: {
179
+ Location: response.redirect,
180
+ },
181
+ })];
182
+ }
183
+ return [2 /*return*/, response];
184
+ case 2:
185
+ error_1 = _c.sent();
186
+ return [2 /*return*/, {
187
+ props: {},
188
+ }];
189
+ case 3: return [2 /*return*/];
190
+ }
193
191
  });
194
- },
192
+ }); },
195
193
  children: [],
196
194
  };
197
195
  // Defining the page not found route
@@ -215,20 +213,20 @@ export var generateStaticRoutes = function (router, isRoot) {
215
213
  return {
216
214
  path: path,
217
215
  loader: function (_a) {
218
- var params = _a.params, request = _a.request;
219
- return __awaiter(this, void 0, void 0, function () {
216
+ return __awaiter(this, arguments, void 0, function (_b) {
220
217
  var response, formData, error_2;
221
- return __generator(this, function (_b) {
222
- switch (_b.label) {
218
+ var params = _b.params, request = _b.request;
219
+ return __generator(this, function (_c) {
220
+ switch (_c.label) {
223
221
  case 0:
224
- _b.trys.push([0, 2, , 3]);
222
+ _c.trys.push([0, 2, , 3]);
225
223
  // Check if the loader is defined
226
224
  if (!Page.loader) {
227
225
  throw new Error("Missing loader function");
228
226
  }
229
227
  return [4 /*yield*/, Page.loader({ params: params, request: request })];
230
228
  case 1:
231
- response = _b.sent();
229
+ response = _c.sent();
232
230
  // Handle redirection
233
231
  if (response.redirect) {
234
232
  formData = new FormData();
@@ -242,7 +240,7 @@ export var generateStaticRoutes = function (router, isRoot) {
242
240
  }
243
241
  return [2 /*return*/, response];
244
242
  case 2:
245
- error_2 = _b.sent();
243
+ error_2 = _c.sent();
246
244
  return [2 /*return*/, {
247
245
  props: {},
248
246
  }];
@@ -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
+ })();