rasengan 1.0.0-beta.50 → 1.0.0-beta.51
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/bin.js +13 -0
- package/lib/esm/cli/index.js +31 -129
- package/lib/esm/client.js +2 -0
- package/lib/esm/core/config/index.js +3 -0
- package/lib/esm/core/config/type.js +6 -0
- package/lib/esm/core/config/utils/define-config.js +78 -0
- package/lib/esm/core/config/utils/load-modules.js +78 -0
- package/lib/esm/core/config/utils/path.js +15 -0
- package/lib/esm/core/config/vite/defaults.js +89 -0
- package/lib/esm/core/dynamic/index.js +21 -0
- package/lib/esm/core/index.js +2 -1
- package/lib/esm/core/middlewares/index.js +1 -0
- package/lib/esm/core/middlewares/logger.js +6 -0
- package/lib/esm/core/plugins/index.js +116 -0
- package/lib/esm/core/utils/log.js +9 -0
- package/lib/esm/entries/client/render.js +16 -0
- package/lib/esm/entries/server/entry.server.js +30 -0
- package/lib/esm/entries/server/index.js +20 -0
- package/lib/esm/index.js +3 -6
- package/lib/esm/plugin.js +2 -0
- package/lib/esm/routing/components/index.js +72 -80
- package/lib/esm/routing/components/template.js +60 -0
- package/lib/esm/routing/index.js +4 -4
- package/lib/esm/routing/interfaces.js +100 -87
- package/lib/esm/routing/utils/define-router.js +57 -29
- package/lib/esm/routing/utils/define-routes-group.js +44 -0
- package/lib/esm/routing/utils/generate-metadata.js +29 -32
- package/lib/esm/routing/utils/generate-routes.js +118 -226
- package/lib/esm/routing/utils/index.js +4 -3
- package/lib/esm/scripts/build-command.js +17 -0
- package/lib/esm/scripts/generate-package-json.js +5 -5
- package/lib/esm/scripts/utils/check-os.js +2 -2
- package/lib/esm/scripts/utils/copy.js +8 -8
- package/lib/esm/server/build/index.js +11 -0
- package/lib/esm/server/build/manifest.js +91 -0
- package/lib/esm/server/dev/handlers.js +96 -0
- package/lib/esm/server/dev/server.js +168 -0
- package/lib/esm/server/dev/utils.js +190 -0
- package/lib/esm/server/node/index.js +68 -0
- package/lib/esm/server/node/rendering.js +44 -0
- package/lib/esm/server/node/stream.js +129 -0
- package/lib/esm/server/node/utils.js +91 -0
- package/lib/esm/server/runtime/mode.js +14 -0
- package/lib/esm/server/utils/handleError.js +15 -7
- package/lib/esm/server/utils/handleRequest.js +180 -208
- package/lib/esm/server/utils/index.js +2 -6
- package/lib/esm/server/virtual/index.js +8 -0
- package/lib/esm/server.js +4 -0
- package/lib/tsconfig.esm.tsbuildinfo +1 -1
- package/lib/tsconfig.types.tsbuildinfo +1 -1
- package/lib/types/cli/index.d.ts +0 -1
- package/lib/types/client.d.ts +2 -0
- package/lib/types/core/config/index.d.ts +3 -0
- package/lib/types/core/config/type.d.ts +65 -0
- package/lib/types/{config → core/config}/utils/define-config.d.ts +2 -2
- package/lib/types/core/config/utils/load-modules.d.ts +19 -0
- package/lib/types/{config → core/config}/utils/path.d.ts +0 -5
- package/lib/types/core/config/vite/defaults.d.ts +3 -0
- package/lib/types/core/dynamic/index.d.ts +13 -0
- package/lib/types/core/index.d.ts +1 -2
- package/lib/types/core/middlewares/index.d.ts +1 -0
- package/lib/types/core/middlewares/logger.d.ts +2 -0
- package/lib/types/core/plugins/index.d.ts +18 -0
- package/lib/types/core/types.d.ts +6 -151
- package/lib/types/core/utils/log.d.ts +2 -0
- package/lib/types/entries/client/render.d.ts +5 -0
- package/lib/types/entries/server/entry.server.d.ts +20 -0
- package/lib/types/entries/server/index.d.ts +13 -0
- package/lib/types/index.d.ts +6 -6
- package/lib/types/plugin.d.ts +3 -0
- package/lib/types/routing/components/index.d.ts +7 -26
- package/lib/types/routing/components/template.d.ts +41 -0
- package/lib/types/routing/index.d.ts +5 -5
- package/lib/types/routing/interfaces.d.ts +18 -5
- package/lib/types/routing/types.d.ts +138 -13
- package/lib/types/routing/utils/define-router.d.ts +3 -3
- package/lib/types/routing/utils/define-routes-group.d.ts +7 -0
- package/lib/types/routing/utils/generate-metadata.d.ts +2 -1
- package/lib/types/routing/utils/generate-routes.d.ts +4 -3
- package/lib/types/routing/utils/index.d.ts +4 -3
- package/lib/types/server/build/index.d.ts +13 -0
- package/lib/types/server/build/manifest.d.ts +27 -0
- package/lib/types/server/dev/handlers.d.ts +22 -0
- package/lib/types/server/dev/utils.d.ts +39 -0
- package/lib/types/server/node/index.d.ts +9 -0
- package/lib/types/server/node/rendering.d.ts +9 -0
- package/lib/types/server/node/stream.d.ts +7 -0
- package/lib/types/server/node/utils.d.ts +18 -0
- package/lib/types/server/runtime/mode.d.ts +9 -0
- package/lib/types/server/utils/handleError.d.ts +1 -1
- package/lib/types/server/utils/index.d.ts +2 -6
- package/lib/types/server/virtual/index.d.ts +5 -0
- package/lib/types/server.d.ts +4 -0
- package/package.json +63 -48
- package/tsconfig.base.json +1 -5
- package/tsconfig.esm.json +2 -2
- package/tsconfig.types.json +2 -2
- package/types/client.d.ts +48 -5
- package/vite.config.ts +28 -111
- package/lib/esm/cli/dirname.js +0 -14
- package/lib/esm/config/index.js +0 -2
- package/lib/esm/config/utils/define-config.js +0 -179
- package/lib/esm/config/utils/index.js +0 -3
- package/lib/esm/config/utils/load-modules.js +0 -114
- package/lib/esm/config/utils/path.js +0 -32
- package/lib/esm/core/components/index.js +0 -150
- package/lib/esm/decorators/index.js +0 -1
- package/lib/esm/decorators/route.js +0 -20
- package/lib/esm/decorators/router.js +0 -34
- package/lib/esm/entries/entry-client.js +0 -7
- package/lib/esm/entries/entry-server-stream.js +0 -112
- package/lib/esm/entries/entry-server.js +0 -92
- package/lib/esm/hooks/index.js +0 -0
- package/lib/esm/scripts/copy-extra-files.js +0 -29
- package/lib/esm/scripts/prepare-prod.js +0 -26
- package/lib/esm/scripts/refresh-hack.js +0 -5
- package/lib/esm/server/functions/netlify/netlify/functions/api.js +0 -232
- package/lib/esm/server/functions/netlify/netlify.toml +0 -26
- package/lib/esm/server/functions/vercel/api/index.js +0 -195
- package/lib/esm/server/functions/vercel/vercel.json +0 -16
- package/lib/esm/server/utils/createFetchRequest.js +0 -38
- package/lib/esm/server/utils/createReadableStream.js +0 -103
- package/lib/esm/server/utils/getIp.js +0 -29
- package/lib/esm/server/utils/log.js +0 -121
- package/lib/types/cli/dirname.d.ts +0 -2
- package/lib/types/config/index.d.ts +0 -2
- package/lib/types/config/type.d.ts +0 -110
- package/lib/types/config/utils/index.d.ts +0 -3
- package/lib/types/config/utils/load-modules.d.ts +0 -22
- package/lib/types/core/components/index.d.ts +0 -53
- package/lib/types/decorators/index.d.ts +0 -0
- package/lib/types/decorators/route.d.ts +0 -8
- package/lib/types/decorators/router.d.ts +0 -8
- package/lib/types/decorators/types.d.ts +0 -51
- package/lib/types/entries/entry-client.d.ts +0 -1
- package/lib/types/entries/entry-server-stream.d.ts +0 -4
- package/lib/types/entries/entry-server.d.ts +0 -13
- package/lib/types/hooks/index.d.ts +0 -0
- package/lib/types/scripts/copy-extra-files.d.ts +0 -1
- package/lib/types/scripts/prepare-prod.d.ts +0 -1
- package/lib/types/scripts/refresh-hack.d.ts +0 -1
- package/lib/types/server/functions/netlify/netlify/functions/api.d.ts +0 -3
- package/lib/types/server/functions/vercel/api/index.d.ts +0 -2
- package/lib/types/server/utils/createFetchRequest.d.ts +0 -5
- package/lib/types/server/utils/createReadableStream.d.ts +0 -11
- package/lib/types/server/utils/getIp.d.ts +0 -1
- package/lib/types/server/utils/log.d.ts +0 -7
- package/server.js +0 -243
- package/tsconfig.cjs.json +0 -8
- package/tsconfig.json +0 -33
- /package/lib/{esm/config/type.js → types/scripts/build-command.d.ts} +0 -0
- /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
|
+
});
|
package/lib/esm/cli/index.js
CHANGED
|
@@ -1,138 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
24
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
-
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;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
import chalk from "chalk";
|
|
50
|
-
import { Command } from "commander";
|
|
51
|
-
import { execa } from "execa";
|
|
52
|
-
// @ts-ignore
|
|
53
|
-
import path from "node:path";
|
|
54
|
-
import { resolvePath } from "../config/index.js";
|
|
55
|
-
var program = new Command();
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import { execa } from 'execa';
|
|
4
|
+
const program = new Command();
|
|
56
5
|
program
|
|
57
|
-
.name(chalk.blue(
|
|
58
|
-
.version(
|
|
6
|
+
.name(chalk.blue('rasengan'))
|
|
7
|
+
.version('1.0.0', '-v, --version', 'Output the current version number');
|
|
59
8
|
// Handle the dev command
|
|
60
9
|
program
|
|
61
|
-
.command(
|
|
62
|
-
.option(
|
|
63
|
-
.description(
|
|
64
|
-
.action(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
convertedPort
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
});
|
|
81
|
-
return [2 /*return*/];
|
|
10
|
+
.command('dev')
|
|
11
|
+
.option('-p <port>')
|
|
12
|
+
.description('Start development server')
|
|
13
|
+
.action(async ({ p: port }) => {
|
|
14
|
+
const convertedPort = Number(port);
|
|
15
|
+
// Checking port
|
|
16
|
+
if (port &&
|
|
17
|
+
(isNaN(convertedPort) || convertedPort < 0 || convertedPort > 65535)) {
|
|
18
|
+
console.log('');
|
|
19
|
+
console.log(chalk.red('Please provide a valid port number between 0-65535'));
|
|
20
|
+
console.log('');
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
execa('node', ['node_modules/rasengan/lib/esm/server/dev/server'], {
|
|
24
|
+
stdio: 'inherit',
|
|
25
|
+
env: {
|
|
26
|
+
...process.env,
|
|
27
|
+
PORT: convertedPort ? convertedPort.toString() : undefined,
|
|
28
|
+
},
|
|
82
29
|
});
|
|
83
|
-
});
|
|
30
|
+
});
|
|
84
31
|
// Handle the build command
|
|
85
32
|
program
|
|
86
|
-
.command(
|
|
87
|
-
.description(
|
|
88
|
-
.action(
|
|
89
|
-
execa(
|
|
90
|
-
|
|
91
|
-
stdio: "inherit", // Pipe child process output to the parent process
|
|
33
|
+
.command('build')
|
|
34
|
+
.description('Build the project')
|
|
35
|
+
.action(async () => {
|
|
36
|
+
execa('node', ['node_modules/rasengan/lib/esm/scripts/build-command'], {
|
|
37
|
+
stdio: 'inherit',
|
|
92
38
|
});
|
|
93
39
|
});
|
|
94
|
-
// Handle the prebuild command
|
|
95
|
-
program
|
|
96
|
-
.command("prepare")
|
|
97
|
-
.description("Prepare the project")
|
|
98
|
-
.action(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
99
|
-
var configPath, appConfig, server, hostingStrategy;
|
|
100
|
-
var _a, _b;
|
|
101
|
-
return __generator(this, function (_c) {
|
|
102
|
-
switch (_c.label) {
|
|
103
|
-
case 0:
|
|
104
|
-
// Displaying the message
|
|
105
|
-
console.log("");
|
|
106
|
-
console.log(chalk.blue("Preparing your project for production..."));
|
|
107
|
-
console.log("");
|
|
108
|
-
configPath = resolvePath(path.join(process.cwd(), "rasengan.config.js"));
|
|
109
|
-
return [4 /*yield*/, import(configPath)];
|
|
110
|
-
case 1:
|
|
111
|
-
appConfig = (_c.sent()).default;
|
|
112
|
-
return [4 /*yield*/, appConfig];
|
|
113
|
-
case 2:
|
|
114
|
-
server = (_c.sent()).server;
|
|
115
|
-
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";
|
|
116
|
-
execa("node", ["node_modules/rasengan/lib/esm/scripts/prepare-prod"], {
|
|
117
|
-
stdio: "inherit",
|
|
118
|
-
// cwd: "node_modules/rasengan/lib/esm/scripts",
|
|
119
|
-
env: __assign(__assign({}, process.env), { HOSTING_STRATEGY: hostingStrategy })
|
|
120
|
-
});
|
|
121
|
-
return [2 /*return*/];
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
}); });
|
|
125
|
-
// Handle the start command
|
|
126
|
-
program
|
|
127
|
-
.command("start")
|
|
128
|
-
.description("Start the project in production mode")
|
|
129
|
-
.action(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
130
|
-
return __generator(this, function (_a) {
|
|
131
|
-
execa("npm", ["run", "preview"], {
|
|
132
|
-
cwd: "node_modules/rasengan",
|
|
133
|
-
stdio: "inherit", // Pipe child process output to the parent process
|
|
134
|
-
});
|
|
135
|
-
return [2 /*return*/];
|
|
136
|
-
});
|
|
137
|
-
}); });
|
|
138
40
|
program.parse(process.argv);
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Function to define the config for the app
|
|
3
|
+
* It will be used by vite.config.ts and other files in other to configure the app
|
|
4
|
+
* @param {AppConfig | AppConfigFunction | AppConfigFunctionAsync} loadedConfig
|
|
5
|
+
*/
|
|
6
|
+
export const defineConfig = async (loadedConfig) => {
|
|
7
|
+
return async () => {
|
|
8
|
+
let config;
|
|
9
|
+
// Check if the loadedConfig is a function
|
|
10
|
+
if (typeof loadedConfig === 'function') {
|
|
11
|
+
// Call the function to get the config
|
|
12
|
+
const result = loadedConfig();
|
|
13
|
+
// Check if it's a promise (asynchronous function)
|
|
14
|
+
if (result instanceof Promise) {
|
|
15
|
+
config = await result; // Await the promise result (AppConfigFunctionAsync)
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
config = result; // Synchronous function result (AppConfigFunction)
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
config = loadedConfig;
|
|
23
|
+
}
|
|
24
|
+
const { server, vite, redirects } = config;
|
|
25
|
+
// Define default values for vite config coming from loadedConfig.vite
|
|
26
|
+
const defaultViteConfig = {
|
|
27
|
+
...vite,
|
|
28
|
+
resolve: {
|
|
29
|
+
symbole: vite?.resolve?.symbole || '@',
|
|
30
|
+
alias: vite?.resolve?.alias || [],
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
// Define default values for server config coming from loadedConfig.server
|
|
34
|
+
const defaultServerConfig = {
|
|
35
|
+
development: {
|
|
36
|
+
port: server?.development?.port || undefined,
|
|
37
|
+
open: server?.development?.open || false,
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
// Define default values for redirects config coming from loadedConfig.redirects
|
|
41
|
+
const defaultRedirectsConfig = redirects || (() => new Promise((resolve) => resolve([])));
|
|
42
|
+
try {
|
|
43
|
+
const config = {
|
|
44
|
+
server: defaultServerConfig,
|
|
45
|
+
vite: {
|
|
46
|
+
...defaultViteConfig,
|
|
47
|
+
resolve: {
|
|
48
|
+
alias: [
|
|
49
|
+
{
|
|
50
|
+
find: defaultViteConfig.resolve.symbole,
|
|
51
|
+
replacement: './src',
|
|
52
|
+
},
|
|
53
|
+
...defaultViteConfig.resolve.alias,
|
|
54
|
+
],
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
redirects: defaultRedirectsConfig,
|
|
58
|
+
};
|
|
59
|
+
return config;
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
return {
|
|
63
|
+
vite: {
|
|
64
|
+
appType: 'custom',
|
|
65
|
+
resolve: {
|
|
66
|
+
alias: [
|
|
67
|
+
{
|
|
68
|
+
find: '@',
|
|
69
|
+
replacement: './src',
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
redirects: () => new Promise((resolve) => resolve([])),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { resolvePath } from './path.js';
|
|
2
|
+
import fs from 'fs/promises';
|
|
3
|
+
export const extensions = [
|
|
4
|
+
'.mjs',
|
|
5
|
+
'.js',
|
|
6
|
+
'.mts',
|
|
7
|
+
'.ts',
|
|
8
|
+
'.jsx',
|
|
9
|
+
'.tsx',
|
|
10
|
+
'.json',
|
|
11
|
+
];
|
|
12
|
+
/**
|
|
13
|
+
* Asynchronously loads a module from a file path only in the server-side environment.
|
|
14
|
+
*
|
|
15
|
+
* @param path - The path to the module.
|
|
16
|
+
* @returns The loaded module.
|
|
17
|
+
*/
|
|
18
|
+
export const loadModuleSSR = async (path) => {
|
|
19
|
+
try {
|
|
20
|
+
let modulePath = path;
|
|
21
|
+
// Check if the module path has an extension
|
|
22
|
+
const moduleExtension = path.split('.').pop(); // eg: js or ts
|
|
23
|
+
if (!moduleExtension || !extensions.includes(`.${moduleExtension}`)) {
|
|
24
|
+
const { path: newPath } = await findModulePath(path);
|
|
25
|
+
modulePath = newPath;
|
|
26
|
+
}
|
|
27
|
+
const module = await import(/* @vite-ignore */ resolvePath(modulePath));
|
|
28
|
+
return module;
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
throw new Error(error);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Finds the module path with the right extension.
|
|
36
|
+
*
|
|
37
|
+
* @param path - The path to the module.
|
|
38
|
+
* @returns The module path and extension.
|
|
39
|
+
*/
|
|
40
|
+
export const findModulePath = async (path) => {
|
|
41
|
+
try {
|
|
42
|
+
let modulePath = path;
|
|
43
|
+
let rightExtension = '';
|
|
44
|
+
// Check if the module path has an extension
|
|
45
|
+
const moduleExtension = path.split('.').pop(); // eg: js or ts
|
|
46
|
+
if (!moduleExtension || !extensions.includes(`.${moduleExtension}`)) {
|
|
47
|
+
for (let ext of extensions) {
|
|
48
|
+
const newModulePath = `${modulePath}${ext}`;
|
|
49
|
+
try {
|
|
50
|
+
await fs.access(newModulePath);
|
|
51
|
+
modulePath = newModulePath;
|
|
52
|
+
rightExtension = ext;
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (modulePath === path) {
|
|
60
|
+
throw new Error(`Module "${path}" not found`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
path: modulePath,
|
|
65
|
+
extension: rightExtension,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
throw new Error(error);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
export const getDirname = async (url) => {
|
|
73
|
+
// Load the dirname function from the path module
|
|
74
|
+
// and return the dirname of the file URL
|
|
75
|
+
const { dirname } = await import('node:path');
|
|
76
|
+
const { fileURLToPath } = await import('node:url');
|
|
77
|
+
return dirname(fileURLToPath(url));
|
|
78
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adapts the provided file path to a valid URL format based on the operating system.
|
|
3
|
+
*
|
|
4
|
+
* @param path - The file path to be adapted.
|
|
5
|
+
* @returns The adapted file path in a valid URL format.
|
|
6
|
+
*/
|
|
7
|
+
export const resolvePath = (path) => {
|
|
8
|
+
// Check the OS
|
|
9
|
+
const isWindows = process.platform === 'win32';
|
|
10
|
+
// Adapt the path
|
|
11
|
+
if (isWindows) {
|
|
12
|
+
return `file:///${path}`;
|
|
13
|
+
}
|
|
14
|
+
return path;
|
|
15
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// core/config/defaults.ts
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
// Define core external packages
|
|
4
|
+
const CORE_EXTERNALS = [
|
|
5
|
+
// '@rasenganjs/mdx',
|
|
6
|
+
// '@rasenganjs/vercel',
|
|
7
|
+
// '@rasenganjs/netlify',
|
|
8
|
+
];
|
|
9
|
+
export const createDefaultViteConfig = (rootPath, __dirname, mode, config) => {
|
|
10
|
+
// Combine core externals with user-defined externals
|
|
11
|
+
const externals = [
|
|
12
|
+
...CORE_EXTERNALS,
|
|
13
|
+
...(Array.isArray(config.vite?.build?.external)
|
|
14
|
+
? config.vite.build.external
|
|
15
|
+
: []),
|
|
16
|
+
];
|
|
17
|
+
return {
|
|
18
|
+
...config.vite,
|
|
19
|
+
root: rootPath,
|
|
20
|
+
build: {
|
|
21
|
+
sourcemap: mode === 'development',
|
|
22
|
+
rollupOptions: {
|
|
23
|
+
external: externals,
|
|
24
|
+
input: './src/index',
|
|
25
|
+
output: {
|
|
26
|
+
manualChunks(id) {
|
|
27
|
+
if (id.includes('node_modules'))
|
|
28
|
+
return 'vendor';
|
|
29
|
+
if (id.includes('src/components'))
|
|
30
|
+
return 'shared-components';
|
|
31
|
+
if (id.includes('src/app') && id.includes('.page.')) {
|
|
32
|
+
const parts = id.split('src/app')[1]?.split('/');
|
|
33
|
+
if (parts?.length) {
|
|
34
|
+
const pageName = parts.pop()?.split('.')[0];
|
|
35
|
+
return pageName ? `page-${pageName}` : undefined;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return undefined;
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
outDir: 'dist',
|
|
43
|
+
chunkSizeWarningLimit: 1000,
|
|
44
|
+
},
|
|
45
|
+
environments: {
|
|
46
|
+
client: {
|
|
47
|
+
build: {
|
|
48
|
+
manifest: true,
|
|
49
|
+
outDir: 'dist/client',
|
|
50
|
+
rollupOptions: {
|
|
51
|
+
input: './src/index',
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
ssr: {
|
|
56
|
+
build: {
|
|
57
|
+
outDir: 'dist/server',
|
|
58
|
+
rollupOptions: {
|
|
59
|
+
input: {
|
|
60
|
+
'entry.server': join(__dirname, './lib/esm/entries/server/entry.server.js'),
|
|
61
|
+
'app.router': './src/app/app.router',
|
|
62
|
+
main: './src/main',
|
|
63
|
+
template: './src/template',
|
|
64
|
+
config: './rasengan.config.js',
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
ssrEmitAssets: false,
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
resolve: {
|
|
72
|
+
alias: Array.isArray(config.vite?.resolve?.alias)
|
|
73
|
+
? config.vite.resolve.alias.map(({ find, replacement }) => ({
|
|
74
|
+
find,
|
|
75
|
+
replacement: join(rootPath, replacement),
|
|
76
|
+
}))
|
|
77
|
+
: [],
|
|
78
|
+
},
|
|
79
|
+
builder: {
|
|
80
|
+
buildApp: async (builder) => {
|
|
81
|
+
await builder.build(builder.environments.ssr);
|
|
82
|
+
await builder.build(builder.environments.client);
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
cacheDir: '.rasengan/',
|
|
86
|
+
envPrefix: 'RASENGAN_',
|
|
87
|
+
appType: 'custom',
|
|
88
|
+
};
|
|
89
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Suspense, lazy } from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* It allows you to defer loading of Client Components,
|
|
5
|
+
* and only include them in the client bundle when they're needed
|
|
6
|
+
* @param load
|
|
7
|
+
* @param fallback
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export function dynamicLoad(load, fallback = _jsx(_Fragment, {}) // Default pending UI element
|
|
11
|
+
) {
|
|
12
|
+
try {
|
|
13
|
+
const LazyComponent = lazy(load);
|
|
14
|
+
// Return a functional component preserving the exact props type
|
|
15
|
+
const WrappedComponent = (props) => (_jsx(Suspense, { fallback: fallback, children: _jsx(LazyComponent, { ...props }) }));
|
|
16
|
+
return WrappedComponent;
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
throw new Error(error);
|
|
20
|
+
}
|
|
21
|
+
}
|
package/lib/esm/core/index.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
// export { defineConfig, resolvePath } from "./config/index.js";
|
|
2
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './logger.js';
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { resolve } from 'path';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import { loadModuleSSR } from '../config/utils/load-modules.js';
|
|
4
|
+
function loadRasenganConfig() {
|
|
5
|
+
return {
|
|
6
|
+
name: 'vite-plugin-rasengan-config',
|
|
7
|
+
async config(_, { command }) {
|
|
8
|
+
if (command !== 'build')
|
|
9
|
+
return;
|
|
10
|
+
const configPath = resolve(process.cwd(), 'rasengan.config.js');
|
|
11
|
+
if (!fs.existsSync(configPath)) {
|
|
12
|
+
throw new Error(`Configuration file not found at: ${configPath}`);
|
|
13
|
+
}
|
|
14
|
+
const rasenganConfig = await (await loadModuleSSR(configPath)).default;
|
|
15
|
+
const partialConfig = {
|
|
16
|
+
server: rasenganConfig.server ?? {},
|
|
17
|
+
redirects: rasenganConfig.redirects
|
|
18
|
+
? await rasenganConfig.redirects()
|
|
19
|
+
: [],
|
|
20
|
+
};
|
|
21
|
+
// Inject the configuration as a global constant
|
|
22
|
+
return {
|
|
23
|
+
define: {
|
|
24
|
+
['__RASENGAN_CONFIG__']: JSON.stringify(partialConfig),
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function rasenganConfigPlugin() {
|
|
31
|
+
const virtualModuleId = 'virtual:rasengan-config';
|
|
32
|
+
const resolvedVirtualModuleId = '\0' + virtualModuleId;
|
|
33
|
+
return {
|
|
34
|
+
name: 'vite-plugin-rasengan-config',
|
|
35
|
+
resolveId(id) {
|
|
36
|
+
if (id === virtualModuleId) {
|
|
37
|
+
return resolvedVirtualModuleId;
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
async load(id) {
|
|
41
|
+
if (id === resolvedVirtualModuleId) {
|
|
42
|
+
// if (command !== "build") return;
|
|
43
|
+
const configPath = resolve(process.cwd(), 'rasengan.config.js');
|
|
44
|
+
if (!fs.existsSync(configPath)) {
|
|
45
|
+
throw new Error(`Configuration file not found at: ${configPath}`);
|
|
46
|
+
}
|
|
47
|
+
const rasenganConfig = await (await loadModuleSSR(configPath)).default;
|
|
48
|
+
const partialConfig = {
|
|
49
|
+
server: rasenganConfig.server ?? {},
|
|
50
|
+
redirects: rasenganConfig.redirects
|
|
51
|
+
? await rasenganConfig.redirects()
|
|
52
|
+
: [],
|
|
53
|
+
};
|
|
54
|
+
return `
|
|
55
|
+
export const __RASENGAN_CONFIG__ = ${JSON.stringify(partialConfig)};
|
|
56
|
+
`;
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function buildOutputInformation() {
|
|
62
|
+
const virtualModuleId = 'virtual:rasengan-build-info';
|
|
63
|
+
const resolvedVirtualModuleId = '\0' + virtualModuleId;
|
|
64
|
+
return {
|
|
65
|
+
name: 'vite-plugin-rasengan-build-info',
|
|
66
|
+
resolveId(id) {
|
|
67
|
+
if (id === virtualModuleId) {
|
|
68
|
+
return resolvedVirtualModuleId;
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
async load(id) {
|
|
72
|
+
if (id === resolvedVirtualModuleId) {
|
|
73
|
+
return `
|
|
74
|
+
export const resolveBuildOptions = (buildPath) => {
|
|
75
|
+
return {
|
|
76
|
+
buildDirectory: buildPath,
|
|
77
|
+
manifestPathDirectory: 'client/.vite',
|
|
78
|
+
assetPathDirectory: 'client/assets',
|
|
79
|
+
entryServerPath: 'server/entry.server.js',
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
`;
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
export const Adapters = {
|
|
88
|
+
VERCEL: 'vercel',
|
|
89
|
+
DEFAULT: '',
|
|
90
|
+
};
|
|
91
|
+
export function rasengan({ adapter = { name: Adapters.DEFAULT, prepare: async () => { } }, }) {
|
|
92
|
+
let config = {};
|
|
93
|
+
return {
|
|
94
|
+
name: 'vite-plugin-rasengan',
|
|
95
|
+
configResolved(resolvedConfig) {
|
|
96
|
+
config = resolvedConfig;
|
|
97
|
+
},
|
|
98
|
+
async closeBundle() {
|
|
99
|
+
// We check here if the environment is client has been built because it's the
|
|
100
|
+
// last environment to be built in the Vite build process
|
|
101
|
+
if (this.environment.name === 'client') {
|
|
102
|
+
// Preparing app for deployment
|
|
103
|
+
switch (adapter.name) {
|
|
104
|
+
case Adapters.VERCEL: {
|
|
105
|
+
console.log('Preparing app for deployment to Vercel');
|
|
106
|
+
await adapter.prepare();
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
default:
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
export const plugins = [];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
export const logRedirection = (source, destination) => {
|
|
3
|
+
const time = new Date().toLocaleTimeString();
|
|
4
|
+
console.log(`${chalk.grey(time)} ${chalk.blue('[Rasengan]')} ${chalk.green('REDIRECT')}: ${chalk.grey(source)} ${chalk.green('->')} ${chalk.grey(destination)}`);
|
|
5
|
+
};
|
|
6
|
+
export const logGetRequest = (url) => {
|
|
7
|
+
const time = new Date().toLocaleTimeString();
|
|
8
|
+
console.log(`${chalk.grey(time)} ${chalk.blue('[Rasengan]')} ${chalk.green('GET')}: ${chalk.grey(url)}`);
|
|
9
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { hydrateRoot } from 'react-dom/client';
|
|
3
|
+
import { StrictMode } from 'react';
|
|
4
|
+
import { RootComponent } from '../../routing/components/template.js';
|
|
5
|
+
export default function renderApp(App, options) {
|
|
6
|
+
const root = document.getElementById('root');
|
|
7
|
+
if (!root) {
|
|
8
|
+
throw new Error('Root element not found');
|
|
9
|
+
}
|
|
10
|
+
if (options.reactStrictMode) {
|
|
11
|
+
hydrateRoot(root, _jsx(StrictMode, { children: _jsx(App, { Component: RootComponent }) }));
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
hydrateRoot(root, _jsx(App, { Component: RootComponent }));
|
|
15
|
+
}
|
|
16
|
+
}
|