Compare commits

...

11 Commits

Author SHA1 Message Date
6a3de7dba8 v3.3.0
Some checks failed
Default (tags) / security (push) Successful in 36s
Default (tags) / test (push) Failing after 4m2s
Default (tags) / release (push) Has been skipped
Default (tags) / metadata (push) Has been skipped
2026-03-10 15:54:55 +00:00
07cdee6bff feat(server): use UtilityWebsiteServer for dev server, add domain option, update docs, and bump dependencies 2026-03-10 15:54:55 +00:00
b62e380750 fix(deps): bump smartshell ^3.3.5 (detached:true) and smartexit ^2.0.2
Some checks failed
Default (tags) / security (push) Successful in 36s
Default (tags) / test (push) Failing after 39s
Default (tags) / release (push) Has been skipped
Default (tags) / metadata (push) Has been skipped
2026-03-04 00:50:14 +00:00
0eef560f1d fix(deps): pin smartexit to ^2.0.1 and smartshell to ^3.3.4 for PID tracking
Some checks failed
Default (tags) / security (push) Successful in 33s
Default (tags) / test (push) Failing after 39s
Default (tags) / release (push) Has been skipped
Default (tags) / metadata (push) Has been skipped
2026-03-04 00:17:35 +00:00
f7f42ff36c fix(watcher): always tree-kill on stop regardless of childProcess.killed flag
Some checks failed
Default (tags) / security (push) Successful in 33s
Default (tags) / test (push) Failing after 39s
Default (tags) / release (push) Has been skipped
Default (tags) / metadata (push) Has been skipped
The direct bash child may already be dead from terminal SIGINT while
grandchildren (tsrun, devserver) are still running. Removing the .killed
guard ensures tree-kill always runs to clean up the entire process tree.
2026-03-04 00:09:21 +00:00
77d2e6ee57 v3.2.2
Some checks failed
Default (tags) / security (push) Successful in 44s
Default (tags) / test (push) Failing after 4m3s
Default (tags) / release (push) Has been skipped
Default (tags) / metadata (push) Has been skipped
2026-03-03 23:43:39 +00:00
e8bd8da3c7 fix(lifecycle): use ProcessLifecycle for coordinated shutdown
Replace per-Watcher SIGINT handlers with a single ProcessLifecycle.install()
in TsWatch.start(). This eliminates competing signal handler races that left
orphaned child processes. Add @push.rocks/smartexit as direct dependency.
2026-03-03 23:43:26 +00:00
91b3e273de v3.2.1
Some checks failed
Default (tags) / security (push) Successful in 45s
Default (tags) / test (push) Failing after 4m3s
Default (tags) / release (push) Has been skipped
Default (tags) / metadata (push) Has been skipped
2026-03-03 22:38:31 +00:00
e6a7b352f3 fix(watcher): ensure child processes are killed and awaited during shutdown; improve cleanup handlers; bump smartshell dependency to ^3.3.2 2026-03-03 22:38:31 +00:00
8c1b306313 v3.2.0
Some checks failed
Default (tags) / security (push) Successful in 33s
Default (tags) / test (push) Failing after 4m5s
Default (tags) / release (push) Has been skipped
Default (tags) / metadata (push) Has been skipped
2026-02-24 19:02:39 +00:00
a893e7a771 feat(bundle): add configurable bundle output modes and bundler options (support base64ts, production builds, includeFiles, maxLineLength) and route non-default outputs to a CustomBundleHandler 2026-02-24 19:02:39 +00:00
10 changed files with 2643 additions and 3187 deletions

View File

@@ -1,5 +1,30 @@
# Changelog
## 2026-03-10 - 3.3.0 - feat(server)
use UtilityWebsiteServer for dev server, add domain option, update docs, and bump dependencies
- Replace TypedServer with UtilityWebsiteServer in TsWatch (start/stop/reload adapted)
- Add server.domain config option and update interfaces
- Update readme to document UtilityWebsiteServer features (PWA, brotli+gzip, service worker, live reload via WebSocket) and add bundle config hints (outputMode, bundler, production)
- Bump dependencies and devDependencies (notable: @api.global/typedserver ^8.4.2, @git.zone/tsbundle ^2.9.1, @push.rocks/* updates)
- Remove unused taskbuffer export from tswatch.plugins.ts
## 2026-03-03 - 3.2.1 - fix(watcher)
ensure child processes are killed and awaited during shutdown; improve cleanup handlers; bump smartshell dependency to ^3.3.2
- Await child process kill() calls in restart and stop to avoid race conditions and ensure proper termination.
- Add last-resort synchronous SIGKILL in process 'exit' handler to terminate orphaned child processes.
- Make SIGINT and timeout handlers async and await stop() to perform a clean shutdown before exiting.
- Bump @push.rocks/smartshell from ^3.3.0 to ^3.3.2 in package.json.
## 2026-02-24 - 3.2.0 - feat(bundle)
add configurable bundle output modes and bundler options (support base64ts, production builds, includeFiles, maxLineLength) and route non-default outputs to a CustomBundleHandler
- Added new ITswatchConfig fields: outputMode, bundler, production, includeFiles, maxLineLength
- tswatch now creates a CustomBundleHandler and uses it when outputMode is not 'bundle' (e.g. base64ts)
- Default bundling path now reads bundler and production from bundleConfig (defaults to 'esbuild' and false)
- Bumped dependency @git.zone/tsbundle to ^2.9.0
## 2026-02-05 - 3.1.0 - feat(dev-server)
add no-cache headers to built-in development server; update docs and bump dependencies

View File

@@ -1,6 +1,6 @@
{
"name": "@git.zone/tswatch",
"version": "3.1.0",
"version": "3.3.0",
"private": false,
"description": "A development tool for automatically watching and re-compiling TypeScript projects upon detecting file changes, enhancing developer workflows.",
"exports": {
@@ -18,26 +18,26 @@
"buildDocs": "tsdoc"
},
"devDependencies": {
"@git.zone/tsbuild": "^4.1.2",
"@git.zone/tstest": "^3.1.8",
"@types/node": "^25.2.1"
"@git.zone/tsbuild": "^4.3.0",
"@git.zone/tstest": "^3.3.2",
"@types/node": "^25.4.0"
},
"dependencies": {
"@api.global/typedserver": "^8.3.0",
"@git.zone/tsbundle": "^2.8.3",
"@api.global/typedserver": "^8.4.2",
"@git.zone/tsbundle": "^2.9.1",
"@git.zone/tsrun": "^2.0.1",
"@push.rocks/early": "^4.0.4",
"@push.rocks/lik": "^6.2.2",
"@push.rocks/lik": "^6.3.1",
"@push.rocks/npmextra": "^5.3.3",
"@push.rocks/smartcli": "^4.0.20",
"@push.rocks/smartdelay": "^3.0.5",
"@push.rocks/smartfs": "^1.3.1",
"@push.rocks/smartexit": "^2.0.3",
"@push.rocks/smartfs": "^1.5.0",
"@push.rocks/smartinteract": "^2.0.16",
"@push.rocks/smartlog": "^3.1.10",
"@push.rocks/smartlog": "^3.2.1",
"@push.rocks/smartlog-destination-local": "^9.0.2",
"@push.rocks/smartshell": "^3.3.0",
"@push.rocks/smartwatch": "^6.3.0",
"@push.rocks/taskbuffer": "^4.2.0"
"@push.rocks/smartshell": "^3.3.7",
"@push.rocks/smartwatch": "^6.3.0"
},
"files": [
"ts/**/*",

5654
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -66,7 +66,7 @@ tswatch is now a config-driven TypeScript file watcher. Configuration is read fr
- Uses `@push.rocks/npmextra` for reading npmextra.json config
- Uses `@push.rocks/smartinteract` for the init wizard
- Uses `@git.zone/tsbundle` for bundling with esbuild
- Uses `@api.global/typedserver` for development server
- Uses `@api.global/typedserver` `UtilityWebsiteServer` for development server (wraps TypedServer with service worker, PWA manifest, and live reload)
### Watcher Features
@@ -77,12 +77,16 @@ tswatch is now a config-driven TypeScript file watcher. Configuration is read fr
### Server Features
- Uses `UtilityWebsiteServer` from `@api.global/typedserver` (not raw `TypedServer`)
- Port configurable (default: 3002)
- CORS enabled
- Gzip compression
- Live reload injection (configurable)
- Compression (brotli + gzip)
- Live reload via WebSocket (service worker + devtools injection)
- SPA fallback support
- No-cache headers (prevents browser caching during development)
- PWA manifest auto-generated
- Service worker version info handler
- Domain configurable (default: 'localhost')
## Project Structure

View File

@@ -153,6 +153,7 @@ tswatch uses `npmextra.json` for configuration. Add your config under the `@git.
| `port` | `number` | `3002` | Server port |
| `serveDir` | `string` | `./dist_watch/` | Directory to serve |
| `liveReload` | `boolean` | `true` | Inject live reload script |
| `domain` | `string` | `localhost` | Domain name for the dev server |
#### `IBundleConfig`
@@ -163,6 +164,9 @@ tswatch uses `npmextra.json` for configuration. Add your config under the `@git.
| `to` | `string` | *required* | Output file |
| `watchPatterns` | `string[]` | - | Additional patterns to watch |
| `triggerReload` | `boolean` | `true` | Trigger server reload after bundling |
| `outputMode` | `'bundle' \| 'base64ts'` | `'bundle'` | Output mode for the bundle |
| `bundler` | `'esbuild' \| 'rolldown' \| 'rspack'` | `'esbuild'` | Bundler to use |
| `production` | `boolean` | `false` | Produce a production build |
## 🛠️ CLI Commands
@@ -368,19 +372,22 @@ Config:
## 🌐 Development Server
The built-in development server (enabled in `element` and `website` presets) features:
The built-in development server (powered by `@api.global/typedserver`'s `UtilityWebsiteServer`) is enabled in `element` and `website` presets:
- **Live Reload** - Automatically refreshes browser on changes
- **No Caching** - Prevents browser caching during development (sends `Cache-Control: no-store, no-cache` headers)
- **CORS** - Cross-origin requests enabled
- **Compression** - Gzip compression for faster loading
- **SPA Fallback** - Single-page application routing support
- **Security Headers** - Cross-origin isolation headers
- 🔄 **Live Reload** - WebSocket-based instant browser refresh on changes (via service worker + devtools injection)
- 🚫 **No Caching** - Prevents browser caching during development (`Cache-Control: no-store, no-cache` headers)
- 🌍 **CORS** - Cross-origin requests enabled
- 🗜️ **Compression** - Brotli + gzip compression for faster loading
- 📱 **SPA Fallback** - Single-page application routing support
- 🔒 **Security Headers** - Cross-origin isolation (`COOP`, `COEP`)
- 📦 **PWA Manifest** - Auto-generated Progressive Web App manifest
-**Service Worker** - Built-in service worker version info for cache busting
Default configuration:
- **Port**: 3002
- **Serve Directory**: `./dist_watch/`
- **Live Reload**: Enabled
- **Domain**: `localhost`
## 🔧 Configuration Tips

View File

@@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@git.zone/tswatch',
version: '3.1.0',
version: '3.3.0',
description: 'A development tool for automatically watching and re-compiling TypeScript projects upon detecting file changes, enhancing developer workflows.'
}

View File

@@ -28,6 +28,8 @@ export interface IServerConfig {
serveDir?: string;
/** Whether to inject live reload script (default: true) */
liveReload?: boolean;
/** Domain name for the dev server (default: 'localhost') */
domain?: string;
}
/**
@@ -44,6 +46,16 @@ export interface IBundleConfig {
watchPatterns?: string[];
/** If true, trigger server reload after bundling (default: true) */
triggerReload?: boolean;
/** Output mode: 'bundle' writes JS, 'base64ts' writes base64-encoded TS (default: 'bundle') */
outputMode?: 'bundle' | 'base64ts';
/** Bundler to use (default: 'esbuild') */
bundler?: 'esbuild' | 'rolldown' | 'rspack';
/** Whether to produce a production build (default: false) */
production?: boolean;
/** Files to include alongside the bundle */
includeFiles?: (string | { from: string; to: string })[];
/** Max chars per line for base64ts output. 0 or undefined = unlimited */
maxLineLength?: number;
}
/**

View File

@@ -15,9 +15,10 @@ import { logger } from './tswatch.logging.js';
export class TsWatch {
public config: interfaces.ITswatchConfig;
public watcherMap = new plugins.lik.ObjectMap<Watcher>();
public typedserver: plugins.typedserver.TypedServer | null = null;
public utilityWebsiteServer: plugins.typedserver.utilityservers.UtilityWebsiteServer | null = null;
private tsbundle = new plugins.tsbundle.TsBundle();
private customBundleHandler = new plugins.tsbundle.CustomBundleHandler();
private htmlHandler = new plugins.tsbundle.HtmlHandler();
private assetsHandler = new plugins.tsbundle.AssetsHandler();
@@ -45,6 +46,14 @@ export class TsWatch {
public async start() {
logger.log('info', 'Starting tswatch with config-driven mode');
// Install global process lifecycle handlers (SIGINT, SIGTERM, etc.)
// This is the single authority for signal handling — no per-watcher handlers.
plugins.smartexit.ProcessLifecycle.install();
const exitInstance = new plugins.smartexit.SmartExit({ silent: true });
exitInstance.addCleanupFunction(async () => {
await this.stop();
});
// Start server if configured
if (this.config.server?.enabled) {
await this.startServer();
@@ -66,8 +75,8 @@ export class TsWatch {
});
// Start server after watchers are ready
if (this.typedserver) {
await this.typedserver.start();
if (this.utilityWebsiteServer) {
await this.utilityWebsiteServer.start(this.config.server?.port || 3002);
logger.log('ok', `Dev server started on port ${this.config.server?.port || 3002}`);
}
}
@@ -82,14 +91,14 @@ export class TsWatch {
logger.log('info', `Setting up dev server on port ${port}, serving ${serveDir}`);
this.typedserver = new plugins.typedserver.TypedServer({
cors: true,
injectReload: serverConfig.liveReload !== false,
this.utilityWebsiteServer = new plugins.typedserver.utilityservers.UtilityWebsiteServer({
domain: serverConfig.domain || 'localhost',
serveDir: plugins.path.join(paths.cwd, serveDir),
port: port,
compression: true,
cors: true,
spaFallback: true,
noCache: true,
injectReload: serverConfig.liveReload !== false,
securityHeaders: {
crossOriginOpenerPolicy: 'same-origin',
crossOriginEmbedderPolicy: 'require-corp',
@@ -128,18 +137,30 @@ export class TsWatch {
} else if (fromPath.endsWith('/') || !fromPath.includes('.')) {
// Assets directory copy
await this.assetsHandler.processAssets();
} else if (bundleConfig.outputMode && bundleConfig.outputMode !== 'bundle') {
// Non-default outputMode (e.g. base64ts) — use CustomBundleHandler
await this.customBundleHandler.processSingleBundle({
from: bundleConfig.from,
to: bundleConfig.to,
outputMode: bundleConfig.outputMode,
bundler: bundleConfig.bundler || 'esbuild',
production: bundleConfig.production || false,
includeFiles: bundleConfig.includeFiles,
maxLineLength: bundleConfig.maxLineLength,
});
} else {
// TypeScript bundling
// Standard TypeScript bundling (default)
await this.tsbundle.build(paths.cwd, fromPath, toPath, {
bundler: 'esbuild',
bundler: bundleConfig.bundler || 'esbuild',
production: bundleConfig.production || false,
});
}
logger.log('ok', `[${name}] bundle complete`);
// Trigger reload if configured and server is running
if (bundleConfig.triggerReload !== false && this.typedserver) {
await this.typedserver.reload();
if (bundleConfig.triggerReload !== false && this.utilityWebsiteServer?.typedserver) {
await this.utilityWebsiteServer.typedserver.reload();
}
};
@@ -190,8 +211,8 @@ export class TsWatch {
* stops the execution of any active Watchers
*/
public async stop() {
if (this.typedserver) {
await this.typedserver.stop();
if (this.utilityWebsiteServer) {
await this.utilityWebsiteServer.stop();
}
await this.watcherMap.forEach(async (watcher) => {
await watcher.stop();

View File

@@ -154,7 +154,7 @@ export class Watcher {
if (this.options.commandToExecute) {
if (this.currentExecution && this.options.restart) {
logger.log('ok', `[${name}] restarting: ${this.options.commandToExecute}`);
this.currentExecution.kill();
await this.currentExecution.kill();
} else if (!this.currentExecution) {
logger.log('ok', `[${name}] executing: ${this.options.commandToExecute}`);
}
@@ -181,27 +181,14 @@ export class Watcher {
}
/**
* this method sets up a clean exit strategy
* Sets up timeout-based cleanup if configured.
* Signal handling (SIGINT/SIGTERM) is managed globally by ProcessLifecycle in TsWatch.
*/
private async setupCleanup() {
process.on('exit', () => {
console.log('');
console.log('now exiting!');
this.stop();
process.exit(0);
});
process.on('SIGINT', () => {
console.log('');
console.log('ok! got SIGINT We are exiting! Just cleaning up to exit neatly :)');
this.stop();
process.exit(0);
});
// handle timeout
if (this.options.timeout) {
plugins.smartdelay.delayFor(this.options.timeout).then(() => {
console.log(`timed out afer ${this.options.timeout} milliseconds! exiting!`);
this.stop();
plugins.smartdelay.delayFor(this.options.timeout).then(async () => {
console.log(`timed out after ${this.options.timeout} milliseconds! exiting!`);
await this.stop();
process.exit(0);
});
}
@@ -215,8 +202,10 @@ export class Watcher {
clearTimeout(this.debounceTimer);
}
await this.smartwatchInstance.stop();
if (this.currentExecution && !this.currentExecution.childProcess.killed) {
this.currentExecution.kill();
if (this.currentExecution) {
// Always tree-kill — even if the direct child is dead (.killed === true),
// grandchildren (e.g. tsrun, devserver) may still be running.
await this.currentExecution.kill();
}
}
}

View File

@@ -16,24 +16,24 @@ import * as lik from '@push.rocks/lik';
import * as npmextra from '@push.rocks/npmextra';
import * as smartcli from '@push.rocks/smartcli';
import * as smartdelay from '@push.rocks/smartdelay';
import * as smartexit from '@push.rocks/smartexit';
import * as smartfs from '@push.rocks/smartfs';
import * as smartinteract from '@push.rocks/smartinteract';
import * as smartlog from '@push.rocks/smartlog';
import * as smartlogDestinationLocal from '@push.rocks/smartlog-destination-local';
import * as smartshell from '@push.rocks/smartshell';
import * as smartwatch from '@push.rocks/smartwatch';
import * as taskbuffer from '@push.rocks/taskbuffer';
export {
lik,
npmextra,
smartcli,
smartdelay,
smartexit,
smartfs,
smartinteract,
smartlog,
smartlogDestinationLocal,
smartshell,
smartwatch,
taskbuffer,
};