@nitronjs/framework 0.2.19 → 0.2.20
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 +19 -14
- package/lib/Build/jsxRuntime.js +25 -9
- package/lib/Console/UpdateChecker.js +118 -0
- package/lib/View/View.js +23 -8
- 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",
|
|
@@ -87,14 +87,18 @@ async function run() {
|
|
|
87
87
|
return;
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
+
let exitCode = null;
|
|
91
|
+
|
|
90
92
|
switch (command) {
|
|
91
93
|
case "dev": {
|
|
94
|
+
import("../lib/Console/UpdateChecker.js").then(m => m.default());
|
|
92
95
|
const { default: Dev } = await import("../lib/Console/Commands/DevCommand.js");
|
|
93
96
|
await Dev();
|
|
94
97
|
break;
|
|
95
98
|
}
|
|
96
99
|
|
|
97
100
|
case "start": {
|
|
101
|
+
import("../lib/Console/UpdateChecker.js").then(m => m.default());
|
|
98
102
|
const { default: Start } = await import("../lib/Console/Commands/StartCommand.js");
|
|
99
103
|
await Start();
|
|
100
104
|
break;
|
|
@@ -103,13 +107,13 @@ async function run() {
|
|
|
103
107
|
case "build": {
|
|
104
108
|
const { default: Build } = await import("../lib/Console/Commands/BuildCommand.js");
|
|
105
109
|
await Build();
|
|
110
|
+
exitCode = 0;
|
|
106
111
|
break;
|
|
107
112
|
}
|
|
108
113
|
|
|
109
114
|
case "migrate": {
|
|
110
115
|
const { default: Migrate } = await import("../lib/Console/Commands/MigrateCommand.js");
|
|
111
|
-
|
|
112
|
-
process.exit(success ? 0 : 1);
|
|
116
|
+
exitCode = (await Migrate({ seed: additionalArgs.includes("--seed") })) ? 0 : 1;
|
|
113
117
|
break;
|
|
114
118
|
}
|
|
115
119
|
|
|
@@ -118,37 +122,33 @@ async function run() {
|
|
|
118
122
|
const stepArg = additionalArgs.find(arg => arg.startsWith('--step='));
|
|
119
123
|
const step = stepArg ? parseInt(stepArg.split('=')[1], 10) : 1;
|
|
120
124
|
const all = additionalArgs.includes('--all');
|
|
121
|
-
|
|
122
|
-
process.exit(success ? 0 : 1);
|
|
125
|
+
exitCode = (await Rollback({ step, all })) ? 0 : 1;
|
|
123
126
|
break;
|
|
124
127
|
}
|
|
125
128
|
|
|
126
129
|
case "migrate:status": {
|
|
127
130
|
const { default: Status } = await import("../lib/Console/Commands/MigrateStatusCommand.js");
|
|
128
131
|
await Status();
|
|
129
|
-
|
|
132
|
+
exitCode = 0;
|
|
130
133
|
break;
|
|
131
134
|
}
|
|
132
135
|
|
|
133
136
|
case "migrate:fresh": {
|
|
134
137
|
const { default: MigrateFresh } = await import("../lib/Console/Commands/MigrateFreshCommand.js");
|
|
135
|
-
|
|
136
|
-
process.exit(success ? 0 : 1);
|
|
138
|
+
exitCode = (await MigrateFresh({ seed: additionalArgs.includes("--seed") })) ? 0 : 1;
|
|
137
139
|
break;
|
|
138
140
|
}
|
|
139
141
|
|
|
140
142
|
case "seed": {
|
|
141
143
|
const { default: Seed } = await import("../lib/Console/Commands/SeedCommand.js");
|
|
142
144
|
const seederName = additionalArgs.find(a => !a.startsWith('--')) || null;
|
|
143
|
-
|
|
144
|
-
process.exit(success ? 0 : 1);
|
|
145
|
+
exitCode = (await Seed(seederName)) ? 0 : 1;
|
|
145
146
|
break;
|
|
146
147
|
}
|
|
147
148
|
|
|
148
149
|
case "storage:link": {
|
|
149
150
|
const { default: StorageLink } = await import("../lib/Console/Commands/StorageLinkCommand.js");
|
|
150
|
-
|
|
151
|
-
process.exit(success ? 0 : 1);
|
|
151
|
+
exitCode = (await StorageLink()) ? 0 : 1;
|
|
152
152
|
break;
|
|
153
153
|
}
|
|
154
154
|
|
|
@@ -168,8 +168,7 @@ async function run() {
|
|
|
168
168
|
}
|
|
169
169
|
|
|
170
170
|
const { default: Make } = await import("../lib/Console/Commands/MakeCommand.js");
|
|
171
|
-
|
|
172
|
-
process.exit(success ? 0 : 1);
|
|
171
|
+
exitCode = (await Make(type, name)) ? 0 : 1;
|
|
173
172
|
break;
|
|
174
173
|
}
|
|
175
174
|
|
|
@@ -178,6 +177,12 @@ async function run() {
|
|
|
178
177
|
console.log(`${COLORS.dim}Run 'njs --help' for available commands${COLORS.reset}`);
|
|
179
178
|
process.exit(1);
|
|
180
179
|
}
|
|
180
|
+
|
|
181
|
+
if (exitCode !== null) {
|
|
182
|
+
const { default: checkForUpdates } = await import("../lib/Console/UpdateChecker.js");
|
|
183
|
+
await checkForUpdates();
|
|
184
|
+
process.exit(exitCode);
|
|
185
|
+
}
|
|
181
186
|
} catch (error) {
|
|
182
187
|
console.error(`${COLORS.red}Error: ${error.message}${COLORS.reset}`);
|
|
183
188
|
if (process.env.DEBUG) {
|
package/lib/Build/jsxRuntime.js
CHANGED
|
@@ -85,29 +85,45 @@ function wrapWithDepth(children) {
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
// Deep Proxy that tracks which prop paths are accessed during SSR
|
|
88
|
+
// Pre-wraps all nested objects so React's Object.freeze won't break Proxy invariants
|
|
88
89
|
function trackProps(obj) {
|
|
89
90
|
const accessed = new Set();
|
|
91
|
+
const cache = new WeakMap();
|
|
90
92
|
|
|
91
|
-
function wrap(
|
|
92
|
-
if (
|
|
93
|
+
function wrap(source, prefix) {
|
|
94
|
+
if (source === null || typeof source !== 'object') return source;
|
|
95
|
+
if (cache.has(source)) return cache.get(source);
|
|
93
96
|
|
|
94
|
-
|
|
97
|
+
const isArr = Array.isArray(source);
|
|
98
|
+
const copy = isArr ? [] : {};
|
|
99
|
+
|
|
100
|
+
for (const key of Object.keys(source)) {
|
|
101
|
+
const val = source[key];
|
|
102
|
+
|
|
103
|
+
if (val !== null && typeof val === 'object' && typeof val !== 'function') {
|
|
104
|
+
copy[key] = wrap(val, prefix ? prefix + '.' + key : key);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
copy[key] = val;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const proxy = new Proxy(copy, {
|
|
95
112
|
get(t, prop, receiver) {
|
|
96
113
|
if (typeof prop === 'symbol') return Reflect.get(t, prop, receiver);
|
|
97
114
|
|
|
98
115
|
const val = Reflect.get(t, prop, receiver);
|
|
99
|
-
if (typeof val === 'function') return val;
|
|
116
|
+
if (typeof val === 'function') return val.bind(receiver);
|
|
100
117
|
|
|
101
|
-
const currentPath =
|
|
118
|
+
const currentPath = prefix ? prefix + '.' + String(prop) : String(prop);
|
|
102
119
|
accessed.add(currentPath);
|
|
103
120
|
|
|
104
|
-
if (val !== null && typeof val === 'object') {
|
|
105
|
-
return wrap(val, currentPath);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
121
|
return val;
|
|
109
122
|
}
|
|
110
123
|
});
|
|
124
|
+
|
|
125
|
+
cache.set(source, proxy);
|
|
126
|
+
return proxy;
|
|
111
127
|
}
|
|
112
128
|
|
|
113
129
|
return { proxy: wrap(obj, ''), accessed };
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
|
+
import Output from "./Output.js";
|
|
5
|
+
|
|
6
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
const PKG_PATH = path.resolve(__dirname, "../../package.json");
|
|
8
|
+
const REGISTRY_URL = "https://registry.npmjs.org/@nitronjs/framework/latest";
|
|
9
|
+
const CHECK_INTERVAL = 24 * 60 * 60 * 1000;
|
|
10
|
+
const FETCH_TIMEOUT = 3000;
|
|
11
|
+
|
|
12
|
+
const C = Output.COLORS;
|
|
13
|
+
|
|
14
|
+
function getCachePath() {
|
|
15
|
+
const nitronDir = path.join(process.cwd(), ".nitron");
|
|
16
|
+
|
|
17
|
+
if (!fs.existsSync(nitronDir)) {
|
|
18
|
+
fs.mkdirSync(nitronDir, { recursive: true });
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return path.join(nitronDir, "update-check.json");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function getCurrentVersion() {
|
|
25
|
+
const pkg = JSON.parse(fs.readFileSync(PKG_PATH, "utf-8"));
|
|
26
|
+
return pkg.version;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function compareVersions(current, latest) {
|
|
30
|
+
const a = current.split(".").map(Number);
|
|
31
|
+
const b = latest.split(".").map(Number);
|
|
32
|
+
|
|
33
|
+
for (let i = 0; i < 3; i++) {
|
|
34
|
+
if ((b[i] || 0) > (a[i] || 0)) return 1;
|
|
35
|
+
if ((b[i] || 0) < (a[i] || 0)) return -1;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return 0;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function readCache(cachePath) {
|
|
42
|
+
try {
|
|
43
|
+
if (fs.existsSync(cachePath)) {
|
|
44
|
+
return JSON.parse(fs.readFileSync(cachePath, "utf-8"));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
catch {}
|
|
48
|
+
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function writeCache(cachePath, latestVersion) {
|
|
53
|
+
try {
|
|
54
|
+
fs.writeFileSync(cachePath, JSON.stringify({ lastCheck: Date.now(), latestVersion }));
|
|
55
|
+
}
|
|
56
|
+
catch {}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function fetchLatestVersion() {
|
|
60
|
+
const controller = new AbortController();
|
|
61
|
+
const timeout = setTimeout(() => controller.abort(), FETCH_TIMEOUT);
|
|
62
|
+
|
|
63
|
+
try {
|
|
64
|
+
const res = await fetch(REGISTRY_URL, { signal: controller.signal });
|
|
65
|
+
const data = await res.json();
|
|
66
|
+
return data.version || null;
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
finally {
|
|
72
|
+
clearTimeout(timeout);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
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
|
+
|
|
82
|
+
console.log();
|
|
83
|
+
console.log(`${C.yellow}╭${"─".repeat(maxLen)}╮${C.reset}`);
|
|
84
|
+
|
|
85
|
+
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}`);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
console.log(`${C.yellow}╰${"─".repeat(maxLen)}╯${C.reset}`);
|
|
92
|
+
console.log();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export default async function checkForUpdates() {
|
|
96
|
+
try {
|
|
97
|
+
const cachePath = getCachePath();
|
|
98
|
+
const current = getCurrentVersion();
|
|
99
|
+
const cache = readCache(cachePath);
|
|
100
|
+
|
|
101
|
+
let latestVersion = cache?.latestVersion || null;
|
|
102
|
+
const needsCheck = !cache || (Date.now() - cache.lastCheck) > CHECK_INTERVAL;
|
|
103
|
+
|
|
104
|
+
if (needsCheck) {
|
|
105
|
+
const fetched = await fetchLatestVersion();
|
|
106
|
+
|
|
107
|
+
if (fetched) {
|
|
108
|
+
latestVersion = fetched;
|
|
109
|
+
writeCache(cachePath, fetched);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (latestVersion && compareVersions(current, latestVersion) > 0) {
|
|
114
|
+
printUpdateNotice(current, latestVersion);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
catch {}
|
|
118
|
+
}
|
package/lib/View/View.js
CHANGED
|
@@ -40,27 +40,42 @@ function escapeHtml(str) {
|
|
|
40
40
|
|
|
41
41
|
function trackProps(obj) {
|
|
42
42
|
const accessed = new Set();
|
|
43
|
+
const cache = new WeakMap();
|
|
43
44
|
|
|
44
|
-
function wrap(
|
|
45
|
-
if (
|
|
45
|
+
function wrap(source, prefix) {
|
|
46
|
+
if (source === null || typeof source !== "object") return source;
|
|
47
|
+
if (cache.has(source)) return cache.get(source);
|
|
46
48
|
|
|
47
|
-
|
|
49
|
+
const isArr = Array.isArray(source);
|
|
50
|
+
const copy = isArr ? [] : {};
|
|
51
|
+
|
|
52
|
+
for (const key of Object.keys(source)) {
|
|
53
|
+
const val = source[key];
|
|
54
|
+
|
|
55
|
+
if (val !== null && typeof val === "object" && typeof val !== "function") {
|
|
56
|
+
copy[key] = wrap(val, prefix ? prefix + "." + key : key);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
copy[key] = val;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const proxy = new Proxy(copy, {
|
|
48
64
|
get(t, prop, receiver) {
|
|
49
65
|
if (typeof prop === "symbol") return Reflect.get(t, prop, receiver);
|
|
50
66
|
|
|
51
67
|
const val = Reflect.get(t, prop, receiver);
|
|
52
|
-
if (typeof val === "function") return val;
|
|
68
|
+
if (typeof val === "function") return val.bind(receiver);
|
|
53
69
|
|
|
54
70
|
const currentPath = prefix ? prefix + "." + String(prop) : String(prop);
|
|
55
71
|
accessed.add(currentPath);
|
|
56
72
|
|
|
57
|
-
if (val !== null && typeof val === "object") {
|
|
58
|
-
return wrap(val, currentPath);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
73
|
return val;
|
|
62
74
|
}
|
|
63
75
|
});
|
|
76
|
+
|
|
77
|
+
cache.set(source, proxy);
|
|
78
|
+
return proxy;
|
|
64
79
|
}
|
|
65
80
|
|
|
66
81
|
return { proxy: wrap(obj, ""), accessed };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nitronjs/framework",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.20",
|
|
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"
|