tova 0.2.3 → 0.2.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/bin/tova.js +28 -14
- package/package.json +1 -1
- package/src/version.js +2 -0
package/bin/tova.js
CHANGED
|
@@ -4,7 +4,6 @@ import { resolve, basename, dirname, join, relative } from 'path';
|
|
|
4
4
|
import { readFileSync, writeFileSync, existsSync, mkdirSync, readdirSync, statSync, copyFileSync, rmSync, watch as fsWatch } from 'fs';
|
|
5
5
|
import { spawn } from 'child_process';
|
|
6
6
|
import { createHash } from 'crypto';
|
|
7
|
-
import { createRequire } from 'module';
|
|
8
7
|
import { Lexer } from '../src/lexer/lexer.js';
|
|
9
8
|
import { Parser } from '../src/parser/parser.js';
|
|
10
9
|
import { Analyzer } from '../src/analyzer/analyzer.js';
|
|
@@ -20,8 +19,7 @@ import { writePackageJson } from '../src/config/package-json.js';
|
|
|
20
19
|
import { addToSection, removeFromSection } from '../src/config/edit-toml.js';
|
|
21
20
|
import { stringifyTOML } from '../src/config/toml.js';
|
|
22
21
|
|
|
23
|
-
|
|
24
|
-
const { version: VERSION } = require('../package.json');
|
|
22
|
+
import { VERSION } from '../src/version.js';
|
|
25
23
|
|
|
26
24
|
const HELP = `
|
|
27
25
|
╦ ╦ ╦═╗ ╦
|
|
@@ -546,7 +544,7 @@ async function devServer(args) {
|
|
|
546
544
|
if (output.client) {
|
|
547
545
|
const p = join(outDir, `${outBaseName}.client.js`);
|
|
548
546
|
writeFileSync(p, output.client);
|
|
549
|
-
clientHTML = await generateDevHTML(output.client, srcDir,
|
|
547
|
+
clientHTML = await generateDevHTML(output.client, srcDir, actualReloadPort);
|
|
550
548
|
writeFileSync(join(outDir, 'index.html'), clientHTML);
|
|
551
549
|
hasClient = true;
|
|
552
550
|
}
|
|
@@ -626,11 +624,28 @@ async function devServer(args) {
|
|
|
626
624
|
console.log(` ✓ Client: ${relative('.', outDir)}/index.html`);
|
|
627
625
|
}
|
|
628
626
|
|
|
629
|
-
// Start live-reload SSE server
|
|
627
|
+
// Start live-reload SSE server — find an available port
|
|
630
628
|
const reloadClients = new Set();
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
629
|
+
let reloadServer;
|
|
630
|
+
let actualReloadPort = reloadPort;
|
|
631
|
+
for (let attempt = 0; attempt < 10; attempt++) {
|
|
632
|
+
try {
|
|
633
|
+
reloadServer = Bun.serve({
|
|
634
|
+
port: actualReloadPort,
|
|
635
|
+
fetch(req) {
|
|
636
|
+
return handleReloadFetch(req);
|
|
637
|
+
},
|
|
638
|
+
});
|
|
639
|
+
break;
|
|
640
|
+
} catch {
|
|
641
|
+
actualReloadPort++;
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
if (!reloadServer) {
|
|
645
|
+
console.log(' ⚠ Could not start live-reload server (ports in use)');
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
function handleReloadFetch(req) {
|
|
634
649
|
const url = new URL(req.url);
|
|
635
650
|
if (url.pathname === '/__tova_reload') {
|
|
636
651
|
const stream = new ReadableStream({
|
|
@@ -657,8 +672,7 @@ async function devServer(args) {
|
|
|
657
672
|
});
|
|
658
673
|
}
|
|
659
674
|
return new Response('Not Found', { status: 404 });
|
|
660
|
-
|
|
661
|
-
});
|
|
675
|
+
}
|
|
662
676
|
|
|
663
677
|
function notifyReload() {
|
|
664
678
|
const msg = new TextEncoder().encode('data: reload\n\n');
|
|
@@ -667,7 +681,7 @@ async function devServer(args) {
|
|
|
667
681
|
}
|
|
668
682
|
}
|
|
669
683
|
|
|
670
|
-
console.log(` ✓ Live reload on port ${
|
|
684
|
+
if (reloadServer) console.log(` ✓ Live reload on port ${actualReloadPort}`);
|
|
671
685
|
|
|
672
686
|
// Start file watcher for auto-rebuild
|
|
673
687
|
const watcher = startWatcher(srcDir, async () => {
|
|
@@ -700,7 +714,7 @@ async function devServer(args) {
|
|
|
700
714
|
}
|
|
701
715
|
if (output.client) {
|
|
702
716
|
writeFileSync(join(outDir, `${outBaseName}.client.js`), output.client);
|
|
703
|
-
rebuildClientHTML = await generateDevHTML(output.client, srcDir,
|
|
717
|
+
rebuildClientHTML = await generateDevHTML(output.client, srcDir, actualReloadPort);
|
|
704
718
|
writeFileSync(join(outDir, 'index.html'), rebuildClientHTML);
|
|
705
719
|
}
|
|
706
720
|
if (output.server) {
|
|
@@ -759,9 +773,9 @@ async function devServer(args) {
|
|
|
759
773
|
process.on('SIGINT', () => {
|
|
760
774
|
console.log('\n Shutting down...');
|
|
761
775
|
watcher.close();
|
|
762
|
-
reloadServer.stop();
|
|
776
|
+
if (reloadServer) reloadServer.stop();
|
|
763
777
|
for (const p of processes) {
|
|
764
|
-
p.child.kill('
|
|
778
|
+
try { p.child.kill('SIGKILL'); } catch {}
|
|
765
779
|
}
|
|
766
780
|
process.exit(0);
|
|
767
781
|
});
|
package/package.json
CHANGED
package/src/version.js
ADDED