@nitronjs/framework 0.2.21 → 0.2.23

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
@@ -91,14 +91,16 @@ async function run() {
91
91
 
92
92
  switch (command) {
93
93
  case "dev": {
94
- import("../lib/Console/UpdateChecker.js").then(m => m.default());
94
+ const { startPeriodicCheck } = await import("../lib/Console/UpdateChecker.js");
95
+ startPeriodicCheck();
95
96
  const { default: Dev } = await import("../lib/Console/Commands/DevCommand.js");
96
97
  await Dev();
97
98
  break;
98
99
  }
99
100
 
100
101
  case "start": {
101
- import("../lib/Console/UpdateChecker.js").then(m => m.default());
102
+ const { startPeriodicCheck } = await import("../lib/Console/UpdateChecker.js");
103
+ startPeriodicCheck();
102
104
  const { default: Start } = await import("../lib/Console/Commands/StartCommand.js");
103
105
  await Start();
104
106
  break;
@@ -181,7 +183,7 @@ async function run() {
181
183
  if (exitCode !== null) {
182
184
  const { default: checkForUpdates } = await import("../lib/Console/UpdateChecker.js");
183
185
  await checkForUpdates();
184
- process.exit(exitCode);
186
+ process.exitCode = exitCode;
185
187
  }
186
188
  } catch (error) {
187
189
  console.error(`${COLORS.red}Error: ${error.message}${COLORS.reset}`);
@@ -49,9 +49,9 @@ function readCache(cachePath) {
49
49
  return null;
50
50
  }
51
51
 
52
- function writeCache(cachePath, latestVersion) {
52
+ function writeCache(cachePath, data) {
53
53
  try {
54
- fs.writeFileSync(cachePath, JSON.stringify({ lastCheck: Date.now(), latestVersion }));
54
+ fs.writeFileSync(cachePath, JSON.stringify(data));
55
55
  }
56
56
  catch {}
57
57
  }
@@ -73,22 +73,38 @@ async function fetchLatestVersion() {
73
73
  }
74
74
  }
75
75
 
76
+ function stripAnsi(str) {
77
+ return str.replace(/\x1b\[[\d;]*m/g, "");
78
+ }
79
+
76
80
  function printUpdateNotice(current, latest) {
77
- const msg = `Update available: ${C.dim}${current}${C.reset} ${C.cyan}→${C.reset} ${C.green}${C.bold}${latest}${C.reset}`;
78
- const cmd = `Run ${C.cyan}npm update @nitronjs/framework --save${C.reset} to update`;
79
- const lines = [msg, cmd];
80
- const maxLen = 52;
81
+ const title = `${C.yellow}${C.bold}Update available${C.reset}`;
82
+ const version = `${C.dim}${current}${C.reset} ${C.cyan}\u2192${C.reset} ${C.green}${C.bold}${latest}${C.reset}`;
83
+ const cmd = `${C.cyan}npm update @nitronjs/framework --save${C.reset}`;
84
+
85
+ const lines = [
86
+ "",
87
+ ` ${title}`,
88
+ ` ${version}`,
89
+ "",
90
+ ` ${cmd}`,
91
+ ""
92
+ ];
93
+
94
+ const boxWidth = 50;
95
+ const border = C.gray;
81
96
 
82
97
  console.log();
83
- console.log(`${C.yellow}╭${"".repeat(maxLen)}╮${C.reset}`);
98
+ console.log(` ${border}\u256D${"\u2500".repeat(boxWidth)}\u256E${C.reset}`);
84
99
 
85
100
  for (const line of lines) {
86
- const rawLen = line.replace(/\x1b\[\d+m/g, "").length;
87
- const pad = maxLen - 2 - rawLen;
88
- console.log(`${C.yellow}│${C.reset} ${line}${" ".repeat(Math.max(0, pad))} ${C.yellow}│${C.reset}`);
101
+ const rawLen = stripAnsi(line).length;
102
+ const pad = boxWidth - rawLen;
103
+
104
+ console.log(` ${border}\u2502${C.reset}${line}${" ".repeat(Math.max(0, pad))}${border}\u2502${C.reset}`);
89
105
  }
90
106
 
91
- console.log(`${C.yellow}╰${"".repeat(maxLen)}╯${C.reset}`);
107
+ console.log(` ${border}\u2570${"\u2500".repeat(boxWidth)}\u256F${C.reset}`);
92
108
  console.log();
93
109
  }
94
110
 
@@ -106,7 +122,7 @@ export default async function checkForUpdates() {
106
122
 
107
123
  if (fetched) {
108
124
  latestVersion = fetched;
109
- writeCache(cachePath, fetched);
125
+ writeCache(cachePath, { lastCheck: Date.now(), latestVersion: fetched });
110
126
  }
111
127
  }
112
128
 
@@ -116,3 +132,11 @@ export default async function checkForUpdates() {
116
132
  }
117
133
  catch {}
118
134
  }
135
+
136
+ export function startPeriodicCheck() {
137
+ const initial = setTimeout(() => checkForUpdates(), 10_000);
138
+ initial.unref();
139
+
140
+ const interval = setInterval(() => checkForUpdates(), CHECK_INTERVAL);
141
+ interval.unref();
142
+ }
@@ -109,7 +109,13 @@ class SessionManager {
109
109
  * @returns {Object}
110
110
  */
111
111
  get cookieConfig() {
112
- return { ...this.#config.cookie, signed: true };
112
+ const config = { ...this.#config.cookie, signed: true };
113
+
114
+ if (config.maxAge) {
115
+ config.maxAge = Math.floor(config.maxAge / 1000);
116
+ }
117
+
118
+ return config;
113
119
  }
114
120
 
115
121
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nitronjs/framework",
3
- "version": "0.2.21",
3
+ "version": "0.2.23",
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"