rasengan 1.0.0-beta.50 → 1.0.0-beta.52

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 (202) hide show
  1. package/bin.js +13 -0
  2. package/lib/cjs/cli/index.js +45 -0
  3. package/lib/cjs/client.js +8 -0
  4. package/lib/cjs/core/config/index.js +7 -0
  5. package/lib/cjs/core/config/type.js +7 -0
  6. package/lib/cjs/core/config/utils/define-config.js +82 -0
  7. package/lib/cjs/core/config/utils/load-modules.js +120 -0
  8. package/lib/cjs/core/config/utils/path.js +19 -0
  9. package/lib/cjs/core/config/vite/defaults.js +93 -0
  10. package/lib/cjs/core/dynamic/index.js +24 -0
  11. package/lib/cjs/core/index.js +3 -0
  12. package/lib/cjs/core/middlewares/index.js +17 -0
  13. package/lib/cjs/core/middlewares/logger.js +10 -0
  14. package/lib/cjs/core/plugins/index.js +123 -0
  15. package/lib/cjs/core/types.js +2 -0
  16. package/lib/cjs/core/utils/log.js +17 -0
  17. package/lib/cjs/entries/client/render.js +19 -0
  18. package/lib/cjs/entries/server/entry.server.js +34 -0
  19. package/lib/cjs/entries/server/index.js +27 -0
  20. package/lib/cjs/index.js +22 -0
  21. package/lib/cjs/plugin.js +6 -0
  22. package/lib/cjs/routing/components/index.js +111 -0
  23. package/lib/cjs/routing/components/template.js +100 -0
  24. package/lib/cjs/routing/index.js +26 -0
  25. package/lib/cjs/routing/interfaces.js +108 -0
  26. package/lib/cjs/routing/types.js +2 -0
  27. package/lib/cjs/routing/utils/define-router.js +114 -0
  28. package/lib/cjs/routing/utils/define-routes-group.js +48 -0
  29. package/lib/cjs/routing/utils/generate-metadata.js +87 -0
  30. package/lib/cjs/routing/utils/generate-routes.js +175 -0
  31. package/lib/cjs/routing/utils/index.js +20 -0
  32. package/lib/cjs/scripts/build-command.js +22 -0
  33. package/lib/cjs/scripts/generate-package-json.js +28 -0
  34. package/lib/cjs/scripts/utils/check-os.js +14 -0
  35. package/lib/cjs/scripts/utils/copy.js +23 -0
  36. package/lib/cjs/server/build/index.js +15 -0
  37. package/lib/cjs/server/build/manifest.js +98 -0
  38. package/lib/cjs/server/dev/handlers.js +134 -0
  39. package/lib/cjs/server/dev/server.js +173 -0
  40. package/lib/cjs/server/dev/utils.js +204 -0
  41. package/lib/cjs/server/node/index.js +109 -0
  42. package/lib/cjs/server/node/rendering.js +52 -0
  43. package/lib/cjs/server/node/stream.js +136 -0
  44. package/lib/cjs/server/node/utils.js +96 -0
  45. package/lib/cjs/server/runtime/mode.js +18 -0
  46. package/lib/cjs/server/utils/handleError.js +59 -0
  47. package/lib/cjs/server/utils/handleRequest.js +224 -0
  48. package/lib/cjs/server/utils/index.js +6 -0
  49. package/lib/cjs/server/virtual/index.js +11 -0
  50. package/lib/cjs/server.js +22 -0
  51. package/lib/esm/cli/index.js +31 -129
  52. package/lib/esm/client.js +2 -0
  53. package/lib/esm/core/config/index.js +3 -0
  54. package/lib/esm/core/config/type.js +6 -0
  55. package/lib/esm/core/config/utils/define-config.js +78 -0
  56. package/lib/esm/core/config/utils/load-modules.js +78 -0
  57. package/lib/esm/core/config/utils/path.js +15 -0
  58. package/lib/esm/core/config/vite/defaults.js +89 -0
  59. package/lib/esm/core/dynamic/index.js +21 -0
  60. package/lib/esm/core/index.js +2 -1
  61. package/lib/esm/core/middlewares/index.js +1 -0
  62. package/lib/esm/core/middlewares/logger.js +6 -0
  63. package/lib/esm/core/plugins/index.js +116 -0
  64. package/lib/esm/core/utils/log.js +9 -0
  65. package/lib/esm/entries/client/render.js +16 -0
  66. package/lib/esm/entries/server/entry.server.js +30 -0
  67. package/lib/esm/entries/server/index.js +20 -0
  68. package/lib/esm/index.js +3 -6
  69. package/lib/esm/plugin.js +2 -0
  70. package/lib/esm/routing/components/index.js +72 -80
  71. package/lib/esm/routing/components/template.js +60 -0
  72. package/lib/esm/routing/index.js +4 -4
  73. package/lib/esm/routing/interfaces.js +100 -87
  74. package/lib/esm/routing/utils/define-router.js +57 -29
  75. package/lib/esm/routing/utils/define-routes-group.js +44 -0
  76. package/lib/esm/routing/utils/generate-metadata.js +29 -32
  77. package/lib/esm/routing/utils/generate-routes.js +118 -226
  78. package/lib/esm/routing/utils/index.js +4 -3
  79. package/lib/esm/scripts/build-command.js +17 -0
  80. package/lib/esm/scripts/generate-package-json.js +5 -5
  81. package/lib/esm/scripts/utils/check-os.js +2 -2
  82. package/lib/esm/scripts/utils/copy.js +8 -8
  83. package/lib/esm/server/build/index.js +11 -0
  84. package/lib/esm/server/build/manifest.js +91 -0
  85. package/lib/esm/server/dev/handlers.js +96 -0
  86. package/lib/esm/server/dev/server.js +168 -0
  87. package/lib/esm/server/dev/utils.js +190 -0
  88. package/lib/esm/server/node/index.js +68 -0
  89. package/lib/esm/server/node/rendering.js +44 -0
  90. package/lib/esm/server/node/stream.js +129 -0
  91. package/lib/esm/server/node/utils.js +91 -0
  92. package/lib/esm/server/runtime/mode.js +14 -0
  93. package/lib/esm/server/utils/handleError.js +15 -7
  94. package/lib/esm/server/utils/handleRequest.js +180 -208
  95. package/lib/esm/server/utils/index.js +2 -6
  96. package/lib/esm/server/virtual/index.js +8 -0
  97. package/lib/esm/server.js +4 -0
  98. package/lib/tsconfig.cjs.tsbuildinfo +1 -0
  99. package/lib/tsconfig.esm.tsbuildinfo +1 -1
  100. package/lib/tsconfig.types.tsbuildinfo +1 -1
  101. package/lib/types/cli/index.d.ts +0 -1
  102. package/lib/types/client.d.ts +2 -0
  103. package/lib/types/core/config/index.d.ts +3 -0
  104. package/lib/types/core/config/type.d.ts +65 -0
  105. package/lib/types/{config → core/config}/utils/define-config.d.ts +2 -2
  106. package/lib/types/core/config/utils/load-modules.d.ts +19 -0
  107. package/lib/types/{config → core/config}/utils/path.d.ts +0 -5
  108. package/lib/types/core/config/vite/defaults.d.ts +3 -0
  109. package/lib/types/core/dynamic/index.d.ts +13 -0
  110. package/lib/types/core/index.d.ts +1 -2
  111. package/lib/types/core/middlewares/index.d.ts +1 -0
  112. package/lib/types/core/middlewares/logger.d.ts +2 -0
  113. package/lib/types/core/plugins/index.d.ts +18 -0
  114. package/lib/types/core/types.d.ts +6 -151
  115. package/lib/types/core/utils/log.d.ts +2 -0
  116. package/lib/types/entries/client/render.d.ts +5 -0
  117. package/lib/types/entries/server/entry.server.d.ts +20 -0
  118. package/lib/types/entries/server/index.d.ts +13 -0
  119. package/lib/types/index.d.ts +6 -6
  120. package/lib/types/plugin.d.ts +3 -0
  121. package/lib/types/routing/components/index.d.ts +7 -26
  122. package/lib/types/routing/components/template.d.ts +41 -0
  123. package/lib/types/routing/index.d.ts +5 -5
  124. package/lib/types/routing/interfaces.d.ts +18 -5
  125. package/lib/types/routing/types.d.ts +138 -13
  126. package/lib/types/routing/utils/define-router.d.ts +3 -3
  127. package/lib/types/routing/utils/define-routes-group.d.ts +7 -0
  128. package/lib/types/routing/utils/generate-metadata.d.ts +2 -1
  129. package/lib/types/routing/utils/generate-routes.d.ts +4 -3
  130. package/lib/types/routing/utils/index.d.ts +4 -3
  131. package/lib/types/server/build/index.d.ts +13 -0
  132. package/lib/types/server/build/manifest.d.ts +27 -0
  133. package/lib/types/server/dev/handlers.d.ts +22 -0
  134. package/lib/types/server/dev/utils.d.ts +39 -0
  135. package/lib/types/server/node/index.d.ts +9 -0
  136. package/lib/types/server/node/rendering.d.ts +9 -0
  137. package/lib/types/server/node/stream.d.ts +7 -0
  138. package/lib/types/server/node/utils.d.ts +18 -0
  139. package/lib/types/server/runtime/mode.d.ts +9 -0
  140. package/lib/types/server/utils/handleError.d.ts +1 -1
  141. package/lib/types/server/utils/index.d.ts +2 -6
  142. package/lib/types/server/virtual/index.d.ts +5 -0
  143. package/lib/types/server.d.ts +4 -0
  144. package/package.json +63 -48
  145. package/tsconfig.base.json +1 -5
  146. package/tsconfig.esm.json +2 -2
  147. package/tsconfig.types.json +2 -2
  148. package/types/client.d.ts +48 -5
  149. package/vite.config.ts +28 -111
  150. package/lib/esm/cli/dirname.js +0 -14
  151. package/lib/esm/config/index.js +0 -2
  152. package/lib/esm/config/utils/define-config.js +0 -179
  153. package/lib/esm/config/utils/index.js +0 -3
  154. package/lib/esm/config/utils/load-modules.js +0 -114
  155. package/lib/esm/config/utils/path.js +0 -32
  156. package/lib/esm/core/components/index.js +0 -150
  157. package/lib/esm/decorators/index.js +0 -1
  158. package/lib/esm/decorators/route.js +0 -20
  159. package/lib/esm/decorators/router.js +0 -34
  160. package/lib/esm/entries/entry-client.js +0 -7
  161. package/lib/esm/entries/entry-server-stream.js +0 -112
  162. package/lib/esm/entries/entry-server.js +0 -92
  163. package/lib/esm/hooks/index.js +0 -0
  164. package/lib/esm/scripts/copy-extra-files.js +0 -29
  165. package/lib/esm/scripts/prepare-prod.js +0 -26
  166. package/lib/esm/scripts/refresh-hack.js +0 -5
  167. package/lib/esm/server/functions/netlify/netlify/functions/api.js +0 -232
  168. package/lib/esm/server/functions/netlify/netlify.toml +0 -26
  169. package/lib/esm/server/functions/vercel/api/index.js +0 -195
  170. package/lib/esm/server/functions/vercel/vercel.json +0 -16
  171. package/lib/esm/server/utils/createFetchRequest.js +0 -38
  172. package/lib/esm/server/utils/createReadableStream.js +0 -103
  173. package/lib/esm/server/utils/getIp.js +0 -29
  174. package/lib/esm/server/utils/log.js +0 -121
  175. package/lib/types/cli/dirname.d.ts +0 -2
  176. package/lib/types/config/index.d.ts +0 -2
  177. package/lib/types/config/type.d.ts +0 -110
  178. package/lib/types/config/utils/index.d.ts +0 -3
  179. package/lib/types/config/utils/load-modules.d.ts +0 -22
  180. package/lib/types/core/components/index.d.ts +0 -53
  181. package/lib/types/decorators/index.d.ts +0 -0
  182. package/lib/types/decorators/route.d.ts +0 -8
  183. package/lib/types/decorators/router.d.ts +0 -8
  184. package/lib/types/decorators/types.d.ts +0 -51
  185. package/lib/types/entries/entry-client.d.ts +0 -1
  186. package/lib/types/entries/entry-server-stream.d.ts +0 -4
  187. package/lib/types/entries/entry-server.d.ts +0 -13
  188. package/lib/types/hooks/index.d.ts +0 -0
  189. package/lib/types/scripts/copy-extra-files.d.ts +0 -1
  190. package/lib/types/scripts/prepare-prod.d.ts +0 -1
  191. package/lib/types/scripts/refresh-hack.d.ts +0 -1
  192. package/lib/types/server/functions/netlify/netlify/functions/api.d.ts +0 -3
  193. package/lib/types/server/functions/vercel/api/index.d.ts +0 -2
  194. package/lib/types/server/utils/createFetchRequest.d.ts +0 -5
  195. package/lib/types/server/utils/createReadableStream.d.ts +0 -11
  196. package/lib/types/server/utils/getIp.d.ts +0 -1
  197. package/lib/types/server/utils/log.d.ts +0 -7
  198. package/server.js +0 -243
  199. package/tsconfig.cjs.json +0 -8
  200. package/tsconfig.json +0 -33
  201. /package/lib/{esm/config/type.js → types/scripts/build-command.d.ts} +0 -0
  202. /package/lib/{esm/decorators/types.js → types/server/dev/server.d.ts} +0 -0
package/bin.js ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env node
2
+
3
+ // Import `process` explicitly if needed (e.g., in certain runtime environments).
4
+ import process from 'process';
5
+
6
+ // If not already set, default `NODE_ENV=development`
7
+ process.env.NODE_ENV = process.env.NODE_ENV ?? 'development';
8
+
9
+ // Import and execute the CLI script
10
+ import('./lib/esm/cli/index.js').catch((err) => {
11
+ console.error('Failed to start the Rasengan CLI:', err);
12
+ process.exit(1);
13
+ });
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const chalk_1 = __importDefault(require("chalk"));
7
+ const commander_1 = require("commander");
8
+ const execa_1 = require("execa");
9
+ const program = new commander_1.Command();
10
+ program
11
+ .name(chalk_1.default.blue('rasengan'))
12
+ .version('1.0.0', '-v, --version', 'Output the current version number');
13
+ // Handle the dev command
14
+ program
15
+ .command('dev')
16
+ .option('-p <port>')
17
+ .description('Start development server')
18
+ .action(async ({ p: port }) => {
19
+ const convertedPort = Number(port);
20
+ // Checking port
21
+ if (port &&
22
+ (isNaN(convertedPort) || convertedPort < 0 || convertedPort > 65535)) {
23
+ console.log('');
24
+ console.log(chalk_1.default.red('Please provide a valid port number between 0-65535'));
25
+ console.log('');
26
+ process.exit(1);
27
+ }
28
+ (0, execa_1.execa)('node', ['node_modules/rasengan/lib/esm/server/dev/server'], {
29
+ stdio: 'inherit',
30
+ env: {
31
+ ...process.env,
32
+ PORT: convertedPort ? convertedPort.toString() : undefined,
33
+ },
34
+ });
35
+ });
36
+ // Handle the build command
37
+ program
38
+ .command('build')
39
+ .description('Build the project')
40
+ .action(async () => {
41
+ (0, execa_1.execa)('node', ['node_modules/rasengan/lib/esm/scripts/build-command'], {
42
+ stdio: 'inherit',
43
+ });
44
+ });
45
+ program.parse(process.argv);
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.renderApp = void 0;
7
+ const render_js_1 = __importDefault(require("./entries/client/render.js"));
8
+ exports.renderApp = render_js_1.default;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolvePath = exports.defineConfig = void 0;
4
+ const define_config_js_1 = require("./utils/define-config.js");
5
+ Object.defineProperty(exports, "defineConfig", { enumerable: true, get: function () { return define_config_js_1.defineConfig; } });
6
+ const path_js_1 = require("./utils/path.js");
7
+ Object.defineProperty(exports, "resolvePath", { enumerable: true, get: function () { return path_js_1.resolvePath; } });
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // export type ConfigOptions = {
4
+ // mode: 'development' | 'production' | 'test';
5
+ // command: 'serve' | 'build';
6
+ // isSsrBuild?: boolean;
7
+ // };
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defineConfig = void 0;
4
+ /**
5
+ * Function to define the config for the app
6
+ * It will be used by vite.config.ts and other files in other to configure the app
7
+ * @param {AppConfig | AppConfigFunction | AppConfigFunctionAsync} loadedConfig
8
+ */
9
+ const defineConfig = async (loadedConfig) => {
10
+ return async () => {
11
+ let config;
12
+ // Check if the loadedConfig is a function
13
+ if (typeof loadedConfig === 'function') {
14
+ // Call the function to get the config
15
+ const result = loadedConfig();
16
+ // Check if it's a promise (asynchronous function)
17
+ if (result instanceof Promise) {
18
+ config = await result; // Await the promise result (AppConfigFunctionAsync)
19
+ }
20
+ else {
21
+ config = result; // Synchronous function result (AppConfigFunction)
22
+ }
23
+ }
24
+ else {
25
+ config = loadedConfig;
26
+ }
27
+ const { server, vite, redirects } = config;
28
+ // Define default values for vite config coming from loadedConfig.vite
29
+ const defaultViteConfig = {
30
+ ...vite,
31
+ resolve: {
32
+ symbole: vite?.resolve?.symbole || '@',
33
+ alias: vite?.resolve?.alias || [],
34
+ },
35
+ };
36
+ // Define default values for server config coming from loadedConfig.server
37
+ const defaultServerConfig = {
38
+ development: {
39
+ port: server?.development?.port || undefined,
40
+ open: server?.development?.open || false,
41
+ },
42
+ };
43
+ // Define default values for redirects config coming from loadedConfig.redirects
44
+ const defaultRedirectsConfig = redirects || (() => new Promise((resolve) => resolve([])));
45
+ try {
46
+ const config = {
47
+ server: defaultServerConfig,
48
+ vite: {
49
+ ...defaultViteConfig,
50
+ resolve: {
51
+ alias: [
52
+ {
53
+ find: defaultViteConfig.resolve.symbole,
54
+ replacement: './src',
55
+ },
56
+ ...defaultViteConfig.resolve.alias,
57
+ ],
58
+ },
59
+ },
60
+ redirects: defaultRedirectsConfig,
61
+ };
62
+ return config;
63
+ }
64
+ catch (error) {
65
+ return {
66
+ vite: {
67
+ appType: 'custom',
68
+ resolve: {
69
+ alias: [
70
+ {
71
+ find: '@',
72
+ replacement: './src',
73
+ },
74
+ ],
75
+ },
76
+ },
77
+ redirects: () => new Promise((resolve) => resolve([])),
78
+ };
79
+ }
80
+ };
81
+ };
82
+ exports.defineConfig = defineConfig;
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.getDirname = exports.findModulePath = exports.loadModuleSSR = exports.extensions = void 0;
40
+ const path_js_1 = require("./path.js");
41
+ const promises_1 = __importDefault(require("fs/promises"));
42
+ exports.extensions = [
43
+ '.mjs',
44
+ '.js',
45
+ '.mts',
46
+ '.ts',
47
+ '.jsx',
48
+ '.tsx',
49
+ '.json',
50
+ ];
51
+ /**
52
+ * Asynchronously loads a module from a file path only in the server-side environment.
53
+ *
54
+ * @param path - The path to the module.
55
+ * @returns The loaded module.
56
+ */
57
+ const loadModuleSSR = async (path) => {
58
+ try {
59
+ let modulePath = path;
60
+ // Check if the module path has an extension
61
+ const moduleExtension = path.split('.').pop(); // eg: js or ts
62
+ if (!moduleExtension || !exports.extensions.includes(`.${moduleExtension}`)) {
63
+ const { path: newPath } = await (0, exports.findModulePath)(path);
64
+ modulePath = newPath;
65
+ }
66
+ const module = await Promise.resolve(`${(0, path_js_1.resolvePath)(modulePath)}`).then(s => __importStar(require(s)));
67
+ return module;
68
+ }
69
+ catch (error) {
70
+ throw new Error(error);
71
+ }
72
+ };
73
+ exports.loadModuleSSR = loadModuleSSR;
74
+ /**
75
+ * Finds the module path with the right extension.
76
+ *
77
+ * @param path - The path to the module.
78
+ * @returns The module path and extension.
79
+ */
80
+ const findModulePath = async (path) => {
81
+ try {
82
+ let modulePath = path;
83
+ let rightExtension = '';
84
+ // Check if the module path has an extension
85
+ const moduleExtension = path.split('.').pop(); // eg: js or ts
86
+ if (!moduleExtension || !exports.extensions.includes(`.${moduleExtension}`)) {
87
+ for (let ext of exports.extensions) {
88
+ const newModulePath = `${modulePath}${ext}`;
89
+ try {
90
+ await promises_1.default.access(newModulePath);
91
+ modulePath = newModulePath;
92
+ rightExtension = ext;
93
+ break;
94
+ }
95
+ catch (error) {
96
+ continue;
97
+ }
98
+ }
99
+ if (modulePath === path) {
100
+ throw new Error(`Module "${path}" not found`);
101
+ }
102
+ }
103
+ return {
104
+ path: modulePath,
105
+ extension: rightExtension,
106
+ };
107
+ }
108
+ catch (error) {
109
+ throw new Error(error);
110
+ }
111
+ };
112
+ exports.findModulePath = findModulePath;
113
+ const getDirname = async (url) => {
114
+ // Load the dirname function from the path module
115
+ // and return the dirname of the file URL
116
+ const { dirname } = await Promise.resolve().then(() => __importStar(require('node:path')));
117
+ const { fileURLToPath } = await Promise.resolve().then(() => __importStar(require('node:url')));
118
+ return dirname(fileURLToPath(url));
119
+ };
120
+ exports.getDirname = getDirname;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolvePath = void 0;
4
+ /**
5
+ * Adapts the provided file path to a valid URL format based on the operating system.
6
+ *
7
+ * @param path - The file path to be adapted.
8
+ * @returns The adapted file path in a valid URL format.
9
+ */
10
+ const resolvePath = (path) => {
11
+ // Check the OS
12
+ const isWindows = process.platform === 'win32';
13
+ // Adapt the path
14
+ if (isWindows) {
15
+ return `file:///${path}`;
16
+ }
17
+ return path;
18
+ };
19
+ exports.resolvePath = resolvePath;
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createDefaultViteConfig = void 0;
4
+ // core/config/defaults.ts
5
+ const node_path_1 = require("node:path");
6
+ // Define core external packages
7
+ const CORE_EXTERNALS = [
8
+ // '@rasenganjs/mdx',
9
+ // '@rasenganjs/vercel',
10
+ // '@rasenganjs/netlify',
11
+ ];
12
+ const createDefaultViteConfig = (rootPath, __dirname, mode, config) => {
13
+ // Combine core externals with user-defined externals
14
+ const externals = [
15
+ ...CORE_EXTERNALS,
16
+ ...(Array.isArray(config.vite?.build?.external)
17
+ ? config.vite.build.external
18
+ : []),
19
+ ];
20
+ return {
21
+ ...config.vite,
22
+ root: rootPath,
23
+ build: {
24
+ sourcemap: mode === 'development',
25
+ rollupOptions: {
26
+ external: externals,
27
+ input: './src/index',
28
+ output: {
29
+ manualChunks(id) {
30
+ if (id.includes('node_modules'))
31
+ return 'vendor';
32
+ if (id.includes('src/components'))
33
+ return 'shared-components';
34
+ if (id.includes('src/app') && id.includes('.page.')) {
35
+ const parts = id.split('src/app')[1]?.split('/');
36
+ if (parts?.length) {
37
+ const pageName = parts.pop()?.split('.')[0];
38
+ return pageName ? `page-${pageName}` : undefined;
39
+ }
40
+ }
41
+ return undefined;
42
+ },
43
+ },
44
+ },
45
+ outDir: 'dist',
46
+ chunkSizeWarningLimit: 1000,
47
+ },
48
+ environments: {
49
+ client: {
50
+ build: {
51
+ manifest: true,
52
+ outDir: 'dist/client',
53
+ rollupOptions: {
54
+ input: './src/index',
55
+ },
56
+ },
57
+ },
58
+ ssr: {
59
+ build: {
60
+ outDir: 'dist/server',
61
+ rollupOptions: {
62
+ input: {
63
+ 'entry.server': (0, node_path_1.join)(__dirname, './lib/esm/entries/server/entry.server.js'),
64
+ 'app.router': './src/app/app.router',
65
+ main: './src/main',
66
+ template: './src/template',
67
+ config: './rasengan.config.js',
68
+ },
69
+ },
70
+ ssrEmitAssets: false,
71
+ },
72
+ },
73
+ },
74
+ resolve: {
75
+ alias: Array.isArray(config.vite?.resolve?.alias)
76
+ ? config.vite.resolve.alias.map(({ find, replacement }) => ({
77
+ find,
78
+ replacement: (0, node_path_1.join)(rootPath, replacement),
79
+ }))
80
+ : [],
81
+ },
82
+ builder: {
83
+ buildApp: async (builder) => {
84
+ await builder.build(builder.environments.ssr);
85
+ await builder.build(builder.environments.client);
86
+ },
87
+ },
88
+ cacheDir: '.rasengan/',
89
+ envPrefix: 'RASENGAN_',
90
+ appType: 'custom',
91
+ };
92
+ };
93
+ exports.createDefaultViteConfig = createDefaultViteConfig;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.dynamicLoad = dynamicLoad;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
6
+ /**
7
+ * It allows you to defer loading of Client Components,
8
+ * and only include them in the client bundle when they're needed
9
+ * @param load
10
+ * @param fallback
11
+ * @returns
12
+ */
13
+ function dynamicLoad(load, fallback = (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {}) // Default pending UI element
14
+ ) {
15
+ try {
16
+ const LazyComponent = (0, react_1.lazy)(load);
17
+ // Return a functional component preserving the exact props type
18
+ const WrappedComponent = (props) => ((0, jsx_runtime_1.jsx)(react_1.Suspense, { fallback: fallback, children: (0, jsx_runtime_1.jsx)(LazyComponent, { ...props }) }));
19
+ return WrappedComponent;
20
+ }
21
+ catch (error) {
22
+ throw new Error(error);
23
+ }
24
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ // export { defineConfig, resolvePath } from "./config/index.js";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./logger.js"), exports);
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loggerMiddleware = void 0;
4
+ const log_js_1 = require("../utils/log.js");
5
+ const loggerMiddleware = (req, _, next) => {
6
+ const url = req.originalUrl;
7
+ (0, log_js_1.logGetRequest)(url);
8
+ next();
9
+ };
10
+ exports.loggerMiddleware = loggerMiddleware;
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.plugins = exports.Adapters = void 0;
7
+ exports.rasengan = rasengan;
8
+ const path_1 = require("path");
9
+ const fs_1 = __importDefault(require("fs"));
10
+ const load_modules_js_1 = require("../config/utils/load-modules.js");
11
+ function loadRasenganConfig() {
12
+ return {
13
+ name: 'vite-plugin-rasengan-config',
14
+ async config(_, { command }) {
15
+ if (command !== 'build')
16
+ return;
17
+ const configPath = (0, path_1.resolve)(process.cwd(), 'rasengan.config.js');
18
+ if (!fs_1.default.existsSync(configPath)) {
19
+ throw new Error(`Configuration file not found at: ${configPath}`);
20
+ }
21
+ const rasenganConfig = await (await (0, load_modules_js_1.loadModuleSSR)(configPath)).default;
22
+ const partialConfig = {
23
+ server: rasenganConfig.server ?? {},
24
+ redirects: rasenganConfig.redirects
25
+ ? await rasenganConfig.redirects()
26
+ : [],
27
+ };
28
+ // Inject the configuration as a global constant
29
+ return {
30
+ define: {
31
+ ['__RASENGAN_CONFIG__']: JSON.stringify(partialConfig),
32
+ },
33
+ };
34
+ },
35
+ };
36
+ }
37
+ function rasenganConfigPlugin() {
38
+ const virtualModuleId = 'virtual:rasengan-config';
39
+ const resolvedVirtualModuleId = '\0' + virtualModuleId;
40
+ return {
41
+ name: 'vite-plugin-rasengan-config',
42
+ resolveId(id) {
43
+ if (id === virtualModuleId) {
44
+ return resolvedVirtualModuleId;
45
+ }
46
+ },
47
+ async load(id) {
48
+ if (id === resolvedVirtualModuleId) {
49
+ // if (command !== "build") return;
50
+ const configPath = (0, path_1.resolve)(process.cwd(), 'rasengan.config.js');
51
+ if (!fs_1.default.existsSync(configPath)) {
52
+ throw new Error(`Configuration file not found at: ${configPath}`);
53
+ }
54
+ const rasenganConfig = await (await (0, load_modules_js_1.loadModuleSSR)(configPath)).default;
55
+ const partialConfig = {
56
+ server: rasenganConfig.server ?? {},
57
+ redirects: rasenganConfig.redirects
58
+ ? await rasenganConfig.redirects()
59
+ : [],
60
+ };
61
+ return `
62
+ export const __RASENGAN_CONFIG__ = ${JSON.stringify(partialConfig)};
63
+ `;
64
+ }
65
+ },
66
+ };
67
+ }
68
+ function buildOutputInformation() {
69
+ const virtualModuleId = 'virtual:rasengan-build-info';
70
+ const resolvedVirtualModuleId = '\0' + virtualModuleId;
71
+ return {
72
+ name: 'vite-plugin-rasengan-build-info',
73
+ resolveId(id) {
74
+ if (id === virtualModuleId) {
75
+ return resolvedVirtualModuleId;
76
+ }
77
+ },
78
+ async load(id) {
79
+ if (id === resolvedVirtualModuleId) {
80
+ return `
81
+ export const resolveBuildOptions = (buildPath) => {
82
+ return {
83
+ buildDirectory: buildPath,
84
+ manifestPathDirectory: 'client/.vite',
85
+ assetPathDirectory: 'client/assets',
86
+ entryServerPath: 'server/entry.server.js',
87
+ };
88
+ };
89
+ `;
90
+ }
91
+ },
92
+ };
93
+ }
94
+ exports.Adapters = {
95
+ VERCEL: 'vercel',
96
+ DEFAULT: '',
97
+ };
98
+ function rasengan({ adapter = { name: exports.Adapters.DEFAULT, prepare: async () => { } }, }) {
99
+ let config = {};
100
+ return {
101
+ name: 'vite-plugin-rasengan',
102
+ configResolved(resolvedConfig) {
103
+ config = resolvedConfig;
104
+ },
105
+ async closeBundle() {
106
+ // We check here if the environment is client has been built because it's the
107
+ // last environment to be built in the Vite build process
108
+ if (this.environment.name === 'client') {
109
+ // Preparing app for deployment
110
+ switch (adapter.name) {
111
+ case exports.Adapters.VERCEL: {
112
+ console.log('Preparing app for deployment to Vercel');
113
+ await adapter.prepare();
114
+ break;
115
+ }
116
+ default:
117
+ break;
118
+ }
119
+ }
120
+ },
121
+ };
122
+ }
123
+ exports.plugins = [];
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.logGetRequest = exports.logRedirection = void 0;
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ const logRedirection = (source, destination) => {
9
+ const time = new Date().toLocaleTimeString();
10
+ console.log(`${chalk_1.default.grey(time)} ${chalk_1.default.blue('[Rasengan]')} ${chalk_1.default.green('REDIRECT')}: ${chalk_1.default.grey(source)} ${chalk_1.default.green('->')} ${chalk_1.default.grey(destination)}`);
11
+ };
12
+ exports.logRedirection = logRedirection;
13
+ const logGetRequest = (url) => {
14
+ const time = new Date().toLocaleTimeString();
15
+ console.log(`${chalk_1.default.grey(time)} ${chalk_1.default.blue('[Rasengan]')} ${chalk_1.default.green('GET')}: ${chalk_1.default.grey(url)}`);
16
+ };
17
+ exports.logGetRequest = logGetRequest;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = renderApp;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const client_1 = require("react-dom/client");
6
+ const react_1 = require("react");
7
+ const template_js_1 = require("../../routing/components/template.js");
8
+ function renderApp(App, options) {
9
+ const root = document.getElementById('root');
10
+ if (!root) {
11
+ throw new Error('Root element not found');
12
+ }
13
+ if (options.reactStrictMode) {
14
+ (0, client_1.hydrateRoot)(root, (0, jsx_runtime_1.jsx)(react_1.StrictMode, { children: (0, jsx_runtime_1.jsx)(App, { Component: template_js_1.RootComponent }) }));
15
+ }
16
+ else {
17
+ (0, client_1.hydrateRoot)(root, (0, jsx_runtime_1.jsx)(App, { Component: template_js_1.RootComponent }));
18
+ }
19
+ }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.render = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const load_modules_js_1 = require("../../core/config/utils/load-modules.js");
6
+ const index_js_1 = require("./index.js");
7
+ const posix_1 = require("path/posix");
8
+ const rendering_js_1 = require("../../server/node/rendering.js");
9
+ /**
10
+ * Render the app to a stream
11
+ * @param StaticRouterComponent
12
+ * @param helmetContext
13
+ * @param res
14
+ * @returns
15
+ */
16
+ const render = async (StaticRouterComponent, res, options) => {
17
+ const { metadata, assets, buildOptions } = options;
18
+ // Root path
19
+ const rootPath = process.cwd();
20
+ let App;
21
+ let Template;
22
+ if (buildOptions) {
23
+ App = (await (0, load_modules_js_1.loadModuleSSR)(posix_1.posix.join(buildOptions.buildDirectory, buildOptions.serverPathDirectory, 'main.js'))).default;
24
+ Template = (await (0, load_modules_js_1.loadModuleSSR)((0, posix_1.join)(buildOptions.buildDirectory, buildOptions.serverPathDirectory, 'template.js'))).default;
25
+ }
26
+ else {
27
+ // Import Main App Component
28
+ App = (await (0, load_modules_js_1.loadModuleSSR)(`${rootPath}/src/main`)).default;
29
+ // Import Template
30
+ Template = (await (0, load_modules_js_1.loadModuleSSR)(`${rootPath}/src/template`)).default;
31
+ }
32
+ await (0, rendering_js_1.renderToStream)((0, jsx_runtime_1.jsx)(index_js_1.TemplateLayout, { StaticRouterComponent: StaticRouterComponent, metadata: metadata, assets: assets, App: App, Template: Template }), res);
33
+ };
34
+ exports.render = render;