neutronium 3.4.3 → 3.4.5
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/README.md +2 -2
- package/cli/index.js +91 -16
- package/compiler/compiler.js +64 -11
- package/package.json +1 -1
- package/sandbox.mjs +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# ⚛️ Neutronium v3.4.
|
|
1
|
+
# ⚛️ Neutronium v3.4.5
|
|
2
2
|
|
|
3
3
|
**Ultra-dense JavaScript framework – maximum performance, minimal overhead**
|
|
4
4
|
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
---
|
|
13
13
|
|
|
14
|
-
## 🎉 What’s new in v3.4.
|
|
14
|
+
## 🎉 What’s new in v3.4.5
|
|
15
15
|
|
|
16
16
|
- ⚡ Faster compilation for complex projects
|
|
17
17
|
- ✨ `useState` and `useEffect` hooks
|
package/cli/index.js
CHANGED
|
@@ -8,6 +8,22 @@ const { transformSync } = require('@babel/core');
|
|
|
8
8
|
const { compileProject, compileProjectWatch } = require('../compiler/compiler');
|
|
9
9
|
const { zip } = require("zip-a-folder");
|
|
10
10
|
|
|
11
|
+
const pkgPath = path.join(__dirname, "..", "package.json");
|
|
12
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
|
|
13
|
+
|
|
14
|
+
const currentVersion = pkg.version;
|
|
15
|
+
const name = pkg.name;
|
|
16
|
+
|
|
17
|
+
async function getLatestVersion(pkgName) {
|
|
18
|
+
const res = await fetch(
|
|
19
|
+
`https://registry.npmjs.org/${encodeURIComponent(pkgName)}/latest`
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
if (!res.ok) return null;
|
|
23
|
+
const data = await res.json();
|
|
24
|
+
return data.version;
|
|
25
|
+
}
|
|
26
|
+
|
|
11
27
|
const [, , command, ...args] = process.argv;
|
|
12
28
|
|
|
13
29
|
const babelRc = `{
|
|
@@ -261,6 +277,7 @@ switch (command) {
|
|
|
261
277
|
|
|
262
278
|
console.log(`✅ Favicon set to: ${faviconUrl}`);
|
|
263
279
|
console.log('💡 Run "npm start" to see changes');
|
|
280
|
+
console.log('❗ Reminder: remember to put all the resources in the dist directory')
|
|
264
281
|
} catch (err) {
|
|
265
282
|
console.error('❌ Error setting favicon:', err.message);
|
|
266
283
|
}
|
|
@@ -274,30 +291,88 @@ switch (command) {
|
|
|
274
291
|
if (!path.join(process.cwd(), 'build')) {
|
|
275
292
|
fs.mkdir(path.join(process,cwd(), 'build'));
|
|
276
293
|
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
294
|
+
const pkgPath = path.join(process.cwd(), 'package.json');
|
|
295
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
296
|
+
|
|
297
|
+
// sanitize name for filesystem
|
|
298
|
+
const safeName = pkg.name.replace(/[\/@]/g, '-');
|
|
299
|
+
|
|
300
|
+
const distDir = path.join(process.cwd(), 'dist');
|
|
301
|
+
const buildDir = path.join(process.cwd(), 'build');
|
|
302
|
+
|
|
303
|
+
if (!fs.existsSync(buildDir)) {
|
|
304
|
+
fs.mkdirSync(buildDir);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
await zip(
|
|
308
|
+
distDir,
|
|
309
|
+
path.join(buildDir, `${safeName}.zip`)
|
|
310
|
+
);
|
|
311
|
+
|
|
312
|
+
console.log(`✅ Exported as build/${safeName}.zip`);
|
|
313
|
+
})();
|
|
280
314
|
} catch (err) {
|
|
281
|
-
|
|
315
|
+
console.error(err);
|
|
282
316
|
}
|
|
283
317
|
} else {
|
|
284
318
|
throw new Error("couldn't find folder 'dist'");
|
|
285
319
|
}
|
|
286
320
|
break;
|
|
321
|
+
case 'update':
|
|
322
|
+
(async () => {
|
|
323
|
+
const latest = await getLatestVersion(name);
|
|
324
|
+
|
|
325
|
+
if (!latest) {
|
|
326
|
+
console.log('⚠️ Could not check latest version');
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
if (latest === currentVersion) {
|
|
331
|
+
console.log('✅ neu-cli is already up to date');
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
console.log(`⬆️ Updating neu-cli ${currentVersion} → ${latest}`);
|
|
336
|
+
|
|
337
|
+
try {
|
|
338
|
+
execSync(`npm run update`, {
|
|
339
|
+
stdio: 'inherit'
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
console.log('✅ Update complete');
|
|
343
|
+
} catch (err) {
|
|
344
|
+
console.error('❌ Update failed');
|
|
345
|
+
}
|
|
346
|
+
})();
|
|
347
|
+
break;
|
|
287
348
|
default:
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
349
|
+
(async () => {
|
|
350
|
+
const latest = await getLatestVersion(name);
|
|
351
|
+
|
|
352
|
+
if (!latest) {
|
|
353
|
+
console.log(`Neutronium v${currentVersion}`);
|
|
354
|
+
} else if (latest !== currentVersion) {
|
|
355
|
+
console.log(
|
|
356
|
+
`Neutronium v${currentVersion} (update available → ${latest}, run: neu-cli update)`
|
|
357
|
+
);
|
|
358
|
+
} else {
|
|
359
|
+
console.log(`Neutronium v${currentVersion} (latest)`);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
console.log(`
|
|
363
|
+
Available Commands:
|
|
364
|
+
init | create-app | create-neutronium-app
|
|
365
|
+
👉 Initialize a new Neutronium project
|
|
293
366
|
|
|
294
|
-
|
|
295
|
-
|
|
367
|
+
start
|
|
368
|
+
👉 Compiles your app once
|
|
296
369
|
|
|
297
|
-
|
|
298
|
-
|
|
370
|
+
start --watch
|
|
371
|
+
👉 Start dev server and rebuild on changes
|
|
299
372
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
`);
|
|
373
|
+
--lang js | ts
|
|
374
|
+
👉 Switch between JS and TS
|
|
375
|
+
`);
|
|
376
|
+
})();
|
|
377
|
+
break;
|
|
303
378
|
}
|
package/compiler/compiler.js
CHANGED
|
@@ -8,6 +8,7 @@ const http = require('http');
|
|
|
8
8
|
const { default: Mime } = require('mime');
|
|
9
9
|
const WebSocket = require('ws');
|
|
10
10
|
const { execSync } = require('child_process');
|
|
11
|
+
let isShuttingDown = false;
|
|
11
12
|
|
|
12
13
|
async function compileProject(projectDir = process.cwd()) {
|
|
13
14
|
const distDir = path.join(projectDir, 'dist');
|
|
@@ -92,7 +93,7 @@ async function compileProject(projectDir = process.cwd()) {
|
|
|
92
93
|
}
|
|
93
94
|
|
|
94
95
|
function compileProjectWatch(projectDir = process.cwd(), port = 3000) {
|
|
95
|
-
const server = serveProject(projectDir, port);
|
|
96
|
+
const { server, wss, sockets } = serveProject(projectDir, port);
|
|
96
97
|
compileProject(projectDir);
|
|
97
98
|
|
|
98
99
|
log('👀 Watching project for changes...');
|
|
@@ -178,15 +179,61 @@ function compileProjectWatch(projectDir = process.cwd(), port = 3000) {
|
|
|
178
179
|
console.error('❌ Watcher error:', error);
|
|
179
180
|
});
|
|
180
181
|
|
|
181
|
-
const cleanup = () => {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
182
|
+
const cleanup = async () => {
|
|
183
|
+
if (isShuttingDown) return;
|
|
184
|
+
isShuttingDown = true;
|
|
185
|
+
|
|
186
|
+
// 🔑 Prevent Node from waiting for stdin
|
|
187
|
+
process.stdin.pause();
|
|
188
|
+
|
|
189
|
+
console.log('\n🔹 🛑 Shutting down Neutronium dev server...');
|
|
190
|
+
|
|
191
|
+
try {
|
|
192
|
+
if (watcher) {
|
|
193
|
+
await watcher.close();
|
|
194
|
+
log('👀 File watcher stopped');
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (wss) {
|
|
198
|
+
wss.clients.forEach(c => c.terminate());
|
|
199
|
+
wss.close();
|
|
200
|
+
log('🔌 WebSocket server closed');
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (sockets) {
|
|
204
|
+
sockets.forEach(s => s.destroy());
|
|
205
|
+
log('💣 HTTP sockets destroyed');
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (sockets.size) {
|
|
209
|
+
sockets.forEach(socket => socket.destroy());
|
|
210
|
+
sockets.clear();
|
|
211
|
+
log('💣 HTTP sockets destroyed');
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
if (server) {
|
|
216
|
+
server.close(() => {
|
|
217
|
+
log('🌐 HTTP server closed');
|
|
218
|
+
log("Ctrl + C once again to exit");
|
|
219
|
+
process.exit(0);
|
|
220
|
+
});
|
|
221
|
+
} else {
|
|
222
|
+
log("Ctrl + C once again");
|
|
223
|
+
process.exit(0);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// ⏱️ Safety kill (never needs second Ctrl+C)
|
|
227
|
+
setTimeout(() => process.exit(0), 200);
|
|
228
|
+
} catch (err) {
|
|
229
|
+
console.error('❌ Error during cleanup:', err);
|
|
230
|
+
process.exit(1);
|
|
231
|
+
}
|
|
186
232
|
};
|
|
187
233
|
|
|
188
|
-
process.on('SIGINT', cleanup);
|
|
189
|
-
process.on('SIGTERM', cleanup);
|
|
234
|
+
process.on('SIGINT', () => cleanup());
|
|
235
|
+
process.on('SIGTERM', () => cleanup());
|
|
236
|
+
process.on('SIGHUP', () => cleanup());
|
|
190
237
|
|
|
191
238
|
return { server, watcher, cleanup };
|
|
192
239
|
}
|
|
@@ -263,6 +310,13 @@ function serveProject(projectDir = process.cwd(), port = 3000) {
|
|
|
263
310
|
}
|
|
264
311
|
});
|
|
265
312
|
|
|
313
|
+
const sockets = new Set();
|
|
314
|
+
|
|
315
|
+
server.on('connection', socket => {
|
|
316
|
+
sockets.add(socket);
|
|
317
|
+
socket.on('close', () => sockets.delete(socket));
|
|
318
|
+
});
|
|
319
|
+
|
|
266
320
|
const wss = new WebSocket.Server({ server });
|
|
267
321
|
|
|
268
322
|
wss.on('connection', (ws) => {
|
|
@@ -276,13 +330,12 @@ function serveProject(projectDir = process.cwd(), port = 3000) {
|
|
|
276
330
|
}
|
|
277
331
|
});
|
|
278
332
|
};
|
|
279
|
-
|
|
333
|
+
server.broadcastReload = broadcastReload;
|
|
280
334
|
server.listen(port, () => {
|
|
281
335
|
log(`🌐 Open your browser and navigate to: http://localhost:${port}`);
|
|
282
336
|
});
|
|
283
337
|
|
|
284
|
-
return
|
|
285
|
-
|
|
338
|
+
return { server, wss, sockets };
|
|
286
339
|
}
|
|
287
340
|
|
|
288
341
|
module.exports = {
|
package/package.json
CHANGED
package/sandbox.mjs
CHANGED
|
@@ -16,7 +16,7 @@ export function compile(source) {
|
|
|
16
16
|
]]
|
|
17
17
|
});
|
|
18
18
|
|
|
19
|
-
const CDN = "https://esm.sh/neutronium@3.4.
|
|
19
|
+
const CDN = "https://esm.sh/neutronium@3.4.5/es2022/neutronium.mjs";
|
|
20
20
|
let compiledCode = result.code
|
|
21
21
|
// import { x } from "neutronium"
|
|
22
22
|
.replace(
|