@nitronjs/framework 0.2.14 → 0.2.15
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/cli/njs.js +3 -3
- package/lib/Console/Commands/StartCommand.js +24 -0
- package/lib/Http/Server.js +2 -1
- package/lib/Runtime/Entry.js +3 -2
- package/lib/View/View.js +18 -2
- package/package.json +1 -1
package/cli/njs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
1
|
+
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
const COLORS = {
|
|
4
4
|
reset: "\x1b[0m",
|
|
@@ -95,8 +95,8 @@ async function run() {
|
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
case "start": {
|
|
98
|
-
const {
|
|
99
|
-
await
|
|
98
|
+
const { default: Start } = await import("../lib/Console/Commands/StartCommand.js");
|
|
99
|
+
await Start();
|
|
100
100
|
break;
|
|
101
101
|
}
|
|
102
102
|
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import Paths from "../../Core/Paths.js";
|
|
4
|
+
import Output from "../Output.js";
|
|
5
|
+
|
|
6
|
+
export default async function Start() {
|
|
7
|
+
const manifestPath = path.join(Paths.build, "manifest.json");
|
|
8
|
+
|
|
9
|
+
if (!fs.existsSync(manifestPath)) {
|
|
10
|
+
Output.warn("Build artifacts not found. Running production build...");
|
|
11
|
+
Output.newline();
|
|
12
|
+
|
|
13
|
+
const { default: Build } = await import("./BuildCommand.js");
|
|
14
|
+
const success = await Build();
|
|
15
|
+
|
|
16
|
+
if (!success) {
|
|
17
|
+
Output.error("Build failed. Cannot start server.");
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const { start } = await import("../../Runtime/Entry.js");
|
|
23
|
+
await start();
|
|
24
|
+
}
|
package/lib/Http/Server.js
CHANGED
|
@@ -18,7 +18,6 @@ import Auth from "../Auth/Auth.js";
|
|
|
18
18
|
import SessionManager from "../Session/Manager.js";
|
|
19
19
|
import DB from "../Database/DB.js";
|
|
20
20
|
import Log from "../Logging/Log.js";
|
|
21
|
-
import HMRServer from "../HMR/Server.js";
|
|
22
21
|
|
|
23
22
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
24
23
|
const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, "../../package.json"), "utf8"));
|
|
@@ -304,6 +303,7 @@ class Server {
|
|
|
304
303
|
|
|
305
304
|
// Register HMR routes before Router (dev only)
|
|
306
305
|
if (Environment.isDev) {
|
|
306
|
+
const { default: HMRServer } = await import("../HMR/Server.js");
|
|
307
307
|
HMRServer.registerRoutes(this.#server);
|
|
308
308
|
}
|
|
309
309
|
|
|
@@ -319,6 +319,7 @@ class Server {
|
|
|
319
319
|
const address = await this.#server.listen({ host, port });
|
|
320
320
|
|
|
321
321
|
if (Environment.isDev) {
|
|
322
|
+
const { default: HMRServer } = await import("../HMR/Server.js");
|
|
322
323
|
HMRServer.setup(this.#server.server);
|
|
323
324
|
}
|
|
324
325
|
|
package/lib/Runtime/Entry.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import Server from "../Http/Server.js";
|
|
2
|
-
import HMRServer from "../HMR/Server.js";
|
|
3
2
|
import Environment from "../Core/Environment.js";
|
|
4
3
|
|
|
5
4
|
// Set development mode based on __NITRON_DEV__ env (set by DevCommand)
|
|
@@ -8,7 +7,9 @@ Environment.setDev(process.env.__NITRON_DEV__ === "true");
|
|
|
8
7
|
export async function start() {
|
|
9
8
|
await Server.start();
|
|
10
9
|
|
|
11
|
-
if (process.send) {
|
|
10
|
+
if (Environment.isDev && process.send) {
|
|
11
|
+
const { default: HMRServer } = await import("../HMR/Server.js");
|
|
12
|
+
|
|
12
13
|
process.on("message", (msg) => {
|
|
13
14
|
if (!msg?.type || !HMRServer.isReady) return;
|
|
14
15
|
|
package/lib/View/View.js
CHANGED
|
@@ -53,6 +53,7 @@ class View {
|
|
|
53
53
|
static #manifest = null;
|
|
54
54
|
static #routesCache = null;
|
|
55
55
|
static #manifestMtime = null;
|
|
56
|
+
static #moduleCache = new Map();
|
|
56
57
|
|
|
57
58
|
static get #isDev() {
|
|
58
59
|
return Environment.isDev;
|
|
@@ -311,7 +312,7 @@ class View {
|
|
|
311
312
|
};
|
|
312
313
|
|
|
313
314
|
return Context.run(ctx, async () => {
|
|
314
|
-
const mod = await
|
|
315
|
+
const mod = await this.#importModule(viewPath);
|
|
315
316
|
if (!mod.default) {
|
|
316
317
|
throw new Error("View must have a default export");
|
|
317
318
|
}
|
|
@@ -322,7 +323,7 @@ class View {
|
|
|
322
323
|
for (const layoutName of layoutChain) {
|
|
323
324
|
const layoutPath = path.join(baseDir, layoutName + ".js");
|
|
324
325
|
if (existsSync(layoutPath)) {
|
|
325
|
-
const layoutMod = await
|
|
326
|
+
const layoutMod = await this.#importModule(layoutPath);
|
|
326
327
|
if (layoutMod.default) {
|
|
327
328
|
layoutModules.push(layoutMod);
|
|
328
329
|
}
|
|
@@ -468,6 +469,21 @@ class View {
|
|
|
468
469
|
return result;
|
|
469
470
|
}
|
|
470
471
|
|
|
472
|
+
static async #importModule(filePath) {
|
|
473
|
+
const url = pathToFileURL(filePath).href;
|
|
474
|
+
|
|
475
|
+
if (this.#isDev) {
|
|
476
|
+
return import(url + `?t=${Date.now()}`);
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
let mod = this.#moduleCache.get(filePath);
|
|
480
|
+
if (!mod) {
|
|
481
|
+
mod = await import(url);
|
|
482
|
+
this.#moduleCache.set(filePath, mod);
|
|
483
|
+
}
|
|
484
|
+
return mod;
|
|
485
|
+
}
|
|
486
|
+
|
|
471
487
|
static #sanitizeProps(obj, seen = new WeakSet()) {
|
|
472
488
|
if (obj == null) {
|
|
473
489
|
return obj;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nitronjs/framework",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.15",
|
|
4
4
|
"description": "NitronJS is a modern and extensible Node.js MVC framework built on Fastify. It focuses on clean architecture, modular structure, and developer productivity, offering built-in routing, middleware, configuration management, CLI tooling, and native React integration for scalable full-stack applications.",
|
|
5
5
|
"bin": {
|
|
6
6
|
"njs": "./cli/njs.js"
|