@laphilosophia/steady-watch 1.0.0
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/LICENSE +21 -0
- package/README.md +87 -0
- package/dist/index.js +121 -0
- package/package.json +49 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Erdem Arslan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# π Steady Watch
|
|
2
|
+
|
|
3
|
+
> Intelligent file watcher with content hashing and debouncing. No more ghost rebuilds.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@laphilosophia/steady-watch)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
## The Problem
|
|
9
|
+
|
|
10
|
+
Standard file watchers trigger on every save, including:
|
|
11
|
+
- Editor auto-saves that don't change content
|
|
12
|
+
- IDE temp file operations
|
|
13
|
+
- Multiple rapid saves
|
|
14
|
+
|
|
15
|
+
This leads to unnecessary rebuilds, wasted CPU cycles, and noisy logs.
|
|
16
|
+
|
|
17
|
+
## The Solution
|
|
18
|
+
|
|
19
|
+
**Steady Watch** uses MD5 content hashing to detect *actual* changes. If the file content hasn't changed, no rebuild is triggered. Period.
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install -g @laphilosophia/steady-watch
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
steady-watch "src/**/*.ts" -c "npm run build"
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Or use the short alias:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
sw "src/**/*.ts" -c "npm run build"
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Options
|
|
40
|
+
|
|
41
|
+
| Option | Description | Default |
|
|
42
|
+
|--------|-------------|---------|
|
|
43
|
+
| `-c, --cmd <command>` | Command to execute on change | *required* |
|
|
44
|
+
| `-d, --delay <ms>` | Debounce delay in milliseconds | `300` |
|
|
45
|
+
| `-v, --verbose` | Show hash calculations and file indexing | `false` |
|
|
46
|
+
|
|
47
|
+
### Examples
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
# TypeScript build
|
|
51
|
+
sw "src/**/*.ts" -c "npm run build"
|
|
52
|
+
|
|
53
|
+
# Run tests on change
|
|
54
|
+
sw "src/**/*.{ts,tsx}" -c "npm test" -d 500
|
|
55
|
+
|
|
56
|
+
# Verbose mode to see what's happening
|
|
57
|
+
sw "lib/**/*.js" -c "node build.js" -v
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Features
|
|
61
|
+
|
|
62
|
+
- π― **Content Hashing** β Only triggers when file content actually changes
|
|
63
|
+
- β±οΈ **Debouncing** β Batches rapid changes into single rebuilds
|
|
64
|
+
- π **Process Management** β Won't start new build while previous is running
|
|
65
|
+
- π« **Smart Ignores** β Auto-ignores `node_modules`, `.git`, `dist`, `build`
|
|
66
|
+
- π¨ **Pretty Output** β Color-coded, timestamped logs
|
|
67
|
+
|
|
68
|
+
## Output Example
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
π Steady Watch Initialized
|
|
72
|
+
Pattern: src/**/*.ts
|
|
73
|
+
Command: npm run build
|
|
74
|
+
Delay: 300ms
|
|
75
|
+
|
|
76
|
+
ποΈ Watcher ready. Monitoring for changes...
|
|
77
|
+
Tracking 12 file(s)
|
|
78
|
+
|
|
79
|
+
[9:53:26 PM] β‘ Change detected: index.ts
|
|
80
|
+
[9:53:26 PM] π Triggering: npm run build
|
|
81
|
+
[9:53:28 PM] β Done in 2.14s
|
|
82
|
+
ββββββββββββββββββββββββββββββββββββββββ
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## License
|
|
86
|
+
|
|
87
|
+
MIT Β© [Erdem Arslan](https://github.com/laphilosophia)
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
18
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
19
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
20
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
21
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
22
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
|
+
mod
|
|
24
|
+
));
|
|
25
|
+
|
|
26
|
+
// src/index.ts
|
|
27
|
+
var import_chalk = __toESM(require("chalk"));
|
|
28
|
+
var import_child_process = require("child_process");
|
|
29
|
+
var import_chokidar = __toESM(require("chokidar"));
|
|
30
|
+
var import_commander = require("commander");
|
|
31
|
+
var import_crypto = __toESM(require("crypto"));
|
|
32
|
+
var import_fs = __toESM(require("fs"));
|
|
33
|
+
var import_path = __toESM(require("path"));
|
|
34
|
+
import_commander.program.name("steady-watch").description("Intelligent file watcher with debouncing and content hashing.").argument("<files>", 'Glob pattern to watch (e.g., "src/**/*.ts")').requiredOption("-c, --cmd <command>", "Command to execute on change").option("-d, --delay <ms>", "Debounce delay in milliseconds", "300").option("-v, --verbose", "Show hash calculations", false).version("1.0.0").parse();
|
|
35
|
+
var options = import_commander.program.opts();
|
|
36
|
+
var args = import_commander.program.args;
|
|
37
|
+
var filePattern = args[0];
|
|
38
|
+
var command = options.cmd;
|
|
39
|
+
var delay = parseInt(options.delay);
|
|
40
|
+
var verbose = options.verbose;
|
|
41
|
+
var timeout;
|
|
42
|
+
var isRunning = false;
|
|
43
|
+
var activeProcess = null;
|
|
44
|
+
var fileHashes = /* @__PURE__ */ new Map();
|
|
45
|
+
var getHash = (filePath) => {
|
|
46
|
+
try {
|
|
47
|
+
if (!import_fs.default.existsSync(filePath)) return null;
|
|
48
|
+
const content = import_fs.default.readFileSync(filePath);
|
|
49
|
+
return import_crypto.default.createHash("md5").update(content).digest("hex");
|
|
50
|
+
} catch (e) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
var timestamp = () => import_chalk.default.gray(`[${(/* @__PURE__ */ new Date()).toLocaleTimeString()}]`);
|
|
55
|
+
var runCommand = () => {
|
|
56
|
+
if (isRunning) {
|
|
57
|
+
if (verbose) console.log(import_chalk.default.yellow("\u26A0\uFE0F Previous command still running, skipping..."));
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
isRunning = true;
|
|
61
|
+
console.log(`${timestamp()} ${import_chalk.default.cyan("\u{1F680} Triggering:")} ${import_chalk.default.bold(command)}`);
|
|
62
|
+
const [cmd, ...cmdArgs] = command.split(" ");
|
|
63
|
+
const startTime = Date.now();
|
|
64
|
+
activeProcess = (0, import_child_process.spawn)(cmd, cmdArgs, {
|
|
65
|
+
stdio: "inherit",
|
|
66
|
+
shell: true
|
|
67
|
+
});
|
|
68
|
+
activeProcess.on("close", (code) => {
|
|
69
|
+
isRunning = false;
|
|
70
|
+
activeProcess = null;
|
|
71
|
+
const duration = ((Date.now() - startTime) / 1e3).toFixed(2);
|
|
72
|
+
if (code === 0) {
|
|
73
|
+
console.log(`${timestamp()} ${import_chalk.default.green("\u2714 Done")} in ${duration}s`);
|
|
74
|
+
} else {
|
|
75
|
+
console.log(`${timestamp()} ${import_chalk.default.red("\u2718 Failed")} (Exit code: ${code})`);
|
|
76
|
+
}
|
|
77
|
+
console.log(import_chalk.default.dim("\u2500".repeat(40)));
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
console.log(import_chalk.default.bold.blue("\n\u{1F52D} Steady Watch Initialized"));
|
|
81
|
+
console.log(` ${import_chalk.default.dim("Pattern:")} ${filePattern}`);
|
|
82
|
+
console.log(` ${import_chalk.default.dim("Command:")} ${command}`);
|
|
83
|
+
console.log(` ${import_chalk.default.dim("Delay:")} ${delay}ms
|
|
84
|
+
`);
|
|
85
|
+
var watcher = import_chokidar.default.watch(filePattern, {
|
|
86
|
+
ignored: [/node_modules/, /\.git/, /dist/, /build/],
|
|
87
|
+
ignoreInitial: false
|
|
88
|
+
// BaΕta dosyalarΔ± indexle
|
|
89
|
+
});
|
|
90
|
+
watcher.on("ready", () => {
|
|
91
|
+
console.log(import_chalk.default.green("\u{1F441}\uFE0F Watcher ready. Monitoring for changes..."));
|
|
92
|
+
if (verbose) console.log(import_chalk.default.dim(` Tracking ${fileHashes.size} file(s)`));
|
|
93
|
+
});
|
|
94
|
+
watcher.on("error", (error) => {
|
|
95
|
+
console.error(import_chalk.default.red("Watcher error:"), error);
|
|
96
|
+
});
|
|
97
|
+
watcher.on("add", (filePath) => {
|
|
98
|
+
const hash = getHash(filePath);
|
|
99
|
+
if (hash) fileHashes.set(filePath, hash);
|
|
100
|
+
if (verbose) console.log(import_chalk.default.dim(`Indexed: ${import_path.default.basename(filePath)}`));
|
|
101
|
+
});
|
|
102
|
+
watcher.on("change", (filePath) => {
|
|
103
|
+
const currentHash = getHash(filePath);
|
|
104
|
+
const lastHash = fileHashes.get(filePath);
|
|
105
|
+
if (currentHash === lastHash) {
|
|
106
|
+
if (verbose) console.log(import_chalk.default.gray(`Skipping ghost change: ${import_path.default.basename(filePath)}`));
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (currentHash) {
|
|
110
|
+
fileHashes.set(filePath, currentHash);
|
|
111
|
+
}
|
|
112
|
+
clearTimeout(timeout);
|
|
113
|
+
timeout = setTimeout(() => {
|
|
114
|
+
console.log(`${timestamp()} ${import_chalk.default.yellow("\u26A1 Change detected:")} ${import_path.default.basename(filePath)}`);
|
|
115
|
+
runCommand();
|
|
116
|
+
}, delay);
|
|
117
|
+
});
|
|
118
|
+
watcher.on("unlink", (filePath) => {
|
|
119
|
+
fileHashes.delete(filePath);
|
|
120
|
+
if (verbose) console.log(import_chalk.default.dim(`Removed: ${import_path.default.basename(filePath)}`));
|
|
121
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@laphilosophia/steady-watch",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Intelligent file watcher with content hashing and debouncing. No more ghost rebuilds.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "tsup src/index.ts --format cjs --clean",
|
|
8
|
+
"prepublishOnly": "npm run build"
|
|
9
|
+
},
|
|
10
|
+
"bin": {
|
|
11
|
+
"steady-watch": "dist/index.js",
|
|
12
|
+
"sw": "dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"keywords": [
|
|
18
|
+
"watch",
|
|
19
|
+
"watcher",
|
|
20
|
+
"file-watcher",
|
|
21
|
+
"build",
|
|
22
|
+
"dev",
|
|
23
|
+
"cli",
|
|
24
|
+
"debounce",
|
|
25
|
+
"hash",
|
|
26
|
+
"content-hash"
|
|
27
|
+
],
|
|
28
|
+
"author": "Erdem Arslan",
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/laphilosophia/steady-watch.git"
|
|
33
|
+
},
|
|
34
|
+
"bugs": {
|
|
35
|
+
"url": "https://github.com/laphilosophia/steady-watch/issues"
|
|
36
|
+
},
|
|
37
|
+
"homepage": "https://github.com/laphilosophia/steady-watch#readme",
|
|
38
|
+
"type": "commonjs",
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"chalk": "^5.6.2",
|
|
41
|
+
"chokidar": "^3.6.0",
|
|
42
|
+
"commander": "^14.0.2"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@types/node": "^25.0.8",
|
|
46
|
+
"tsup": "^8.5.1",
|
|
47
|
+
"typescript": "^5.9.3"
|
|
48
|
+
}
|
|
49
|
+
}
|