@nitronjs/framework 0.2.4 → 0.2.6

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 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",
@@ -54,7 +54,6 @@ export default async function migrateFresh(options = {}) {
54
54
 
55
55
  }
56
56
  catch (error) {
57
- Output.newline();
58
57
  Output.error(`Fresh migration error: ${error.message}`);
59
58
  await DB.close();
60
59
  return false;
@@ -90,7 +90,6 @@ const dropTablesSuccess = (count) => {
90
90
  log(` ${LINE}`);
91
91
  log(` ${C.green}${I.success}${C.reset} ${C.dim}Dropped ${count} table(s)${C.reset}`);
92
92
  log();
93
- log();
94
93
  };
95
94
 
96
95
  // Rollback
package/lib/HMR/Server.js CHANGED
@@ -2,6 +2,9 @@ import { Server as SocketServer } from "socket.io";
2
2
  import { createRequire } from "module";
3
3
  import path from "path";
4
4
  import fs from "fs";
5
+ import { fileURLToPath } from "url";
6
+
7
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
5
8
 
6
9
  /**
7
10
  * HMR (Hot Module Replacement) server for development mode.
@@ -29,14 +32,11 @@ class HMRServer {
29
32
  * @param {import("fastify").FastifyInstance} fastify
30
33
  */
31
34
  registerRoutes(fastify) {
32
- const require = createRequire(import.meta.url);
33
- const socketIoDir = path.dirname(require.resolve("socket.io/package.json"));
34
-
35
- this.#clientScript = path.join(socketIoDir, "client-dist", "socket.io.min.js");
35
+ this.#clientScript = this.#findSocketIoClient();
36
36
 
37
37
  fastify.get("/__nitron_hmr/socket.io.js", (req, reply) => {
38
- if (!this.#clientScript || !fs.existsSync(this.#clientScript)) {
39
- return reply.code(404).send("Socket.io client not found");
38
+ if (!this.#clientScript) {
39
+ return reply.code(503).send("// HMR disabled: socket.io client not found");
40
40
  }
41
41
 
42
42
  reply.type("application/javascript").send(fs.readFileSync(this.#clientScript, "utf-8"));
@@ -52,11 +52,12 @@ class HMRServer {
52
52
 
53
53
  this.#io = new SocketServer(httpServer, {
54
54
  path: "/__nitron_hmr",
55
- transports: ["websocket", "polling"],
55
+ transports: ["websocket"],
56
56
  cors: { origin: "*" },
57
57
  pingTimeout: 60000,
58
58
  pingInterval: 25000,
59
- serveClient: false
59
+ serveClient: false,
60
+ allowEIO3: true
60
61
  });
61
62
 
62
63
  this.#io.on("connection", (socket) => {
@@ -152,6 +153,63 @@ class HMRServer {
152
153
 
153
154
  this.#connections = 0;
154
155
  }
156
+
157
+ // Private Methods
158
+
159
+ /**
160
+ * Finds socket.io client script from multiple possible locations.
161
+ * Searches in order: createRequire resolution, cwd node_modules,
162
+ * parent directories, and monorepo root.
163
+ * @returns {string|null} Path to socket.io.min.js or null if not found
164
+ */
165
+ #findSocketIoClient() {
166
+ const clientFile = "client-dist/socket.io.min.js";
167
+ const possiblePaths = [];
168
+
169
+ // 1. Try resolving from framework package location
170
+ try {
171
+ const frameworkRequire = createRequire(import.meta.url);
172
+ const socketIoDir = path.dirname(frameworkRequire.resolve("socket.io/package.json"));
173
+ possiblePaths.push(path.join(socketIoDir, clientFile));
174
+ }
175
+ catch {}
176
+
177
+ // 2. Try resolving from project's node_modules
178
+ try {
179
+ const projectRequire = createRequire(path.join(process.cwd(), "package.json"));
180
+ const socketIoDir = path.dirname(projectRequire.resolve("socket.io/package.json"));
181
+ possiblePaths.push(path.join(socketIoDir, clientFile));
182
+ }
183
+ catch {}
184
+
185
+ // 3. Walk up from cwd looking for node_modules/socket.io
186
+ let currentDir = process.cwd();
187
+ for (let i = 0; i < 5; i++) {
188
+ possiblePaths.push(path.join(currentDir, "node_modules", "socket.io", clientFile));
189
+ const parentDir = path.dirname(currentDir);
190
+ if (parentDir === currentDir) break;
191
+ currentDir = parentDir;
192
+ }
193
+
194
+ // 4. Walk up from framework package location
195
+ currentDir = __dirname;
196
+ for (let i = 0; i < 5; i++) {
197
+ possiblePaths.push(path.join(currentDir, "node_modules", "socket.io", clientFile));
198
+ const parentDir = path.dirname(currentDir);
199
+ if (parentDir === currentDir) break;
200
+ currentDir = parentDir;
201
+ }
202
+
203
+ // Find first existing path
204
+ for (const p of possiblePaths) {
205
+ if (fs.existsSync(p)) {
206
+ return p;
207
+ }
208
+ }
209
+
210
+ console.warn("[HMR] socket.io client not found. Searched paths:", possiblePaths);
211
+ return null;
212
+ }
155
213
  }
156
214
 
157
215
  export default new HMRServer();
@@ -21,8 +21,11 @@
21
21
  try {
22
22
  socket = io({
23
23
  path: "/__nitron_hmr",
24
- transports: ["websocket", "polling"],
25
- reconnection: true
24
+ transports: ["websocket"],
25
+ reconnection: true,
26
+ reconnectionAttempts: 5,
27
+ reconnectionDelay: 1000,
28
+ timeout: 5000
26
29
  });
27
30
  }
28
31
  catch (e) {
@@ -38,6 +41,10 @@
38
41
  window.__nitron_hmr_connected__ = false;
39
42
  });
40
43
 
44
+ socket.on("connect_error", function() {
45
+ window.__nitron_hmr_connected__ = false;
46
+ });
47
+
41
48
  socket.on("hmr:update", function() {
42
49
  refetchPage();
43
50
  });
@@ -198,5 +205,5 @@
198
205
  else {
199
206
  connect();
200
207
  }
201
-
208
+
202
209
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nitronjs/framework",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
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"