@laphilosophia/steady-watch 1.0.1 → 2.0.1
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 -21
- package/README.md +107 -1
- package/bin/steady-watch +3 -0
- package/dist/index.d.mts +122 -0
- package/dist/index.d.ts +122 -0
- package/dist/index.js +483 -84
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +485 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +59 -49
package/LICENSE
CHANGED
|
@@ -1,21 +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.
|
|
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
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
## The Problem
|
|
9
9
|
|
|
10
10
|
Standard file watchers trigger on every save, including:
|
|
11
|
+
|
|
11
12
|
- Editor auto-saves that don't change content
|
|
12
13
|
- IDE temp file operations
|
|
13
14
|
- Multiple rapid saves
|
|
@@ -24,6 +25,35 @@ This leads to unnecessary rebuilds, wasted CPU cycles, and noisy logs.
|
|
|
24
25
|
npm install -g @laphilosophia/steady-watch
|
|
25
26
|
```
|
|
26
27
|
|
|
28
|
+
## Configuration File
|
|
29
|
+
|
|
30
|
+
You can also use a config file instead of CLI options. Supported files:
|
|
31
|
+
|
|
32
|
+
- `.steady-watchrc`
|
|
33
|
+
- `.steady-watchrc.json`
|
|
34
|
+
- `steady-watch.config.json`
|
|
35
|
+
|
|
36
|
+
Example `steady-watch.config.json`:
|
|
37
|
+
|
|
38
|
+
```json
|
|
39
|
+
{
|
|
40
|
+
"pattern": "src/**/*.ts",
|
|
41
|
+
"cmd": "npm run build",
|
|
42
|
+
"delay": 300,
|
|
43
|
+
"verbose": false,
|
|
44
|
+
"quiet": false,
|
|
45
|
+
"ignore": ["*.test.ts"],
|
|
46
|
+
"ext": [".ts", ".tsx"],
|
|
47
|
+
"killTimeout": 10000,
|
|
48
|
+
"retry": 3,
|
|
49
|
+
"hash": "sha256",
|
|
50
|
+
"mtimeOnly": false,
|
|
51
|
+
"clearScreen": false,
|
|
52
|
+
"json": false,
|
|
53
|
+
"theme": "default"
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
27
57
|
## Usage
|
|
28
58
|
|
|
29
59
|
```bash
|
|
@@ -40,9 +70,21 @@ sw "src/**/*.ts" -c "npm run build"
|
|
|
40
70
|
|
|
41
71
|
| Option | Description | Default |
|
|
42
72
|
|--------|-------------|---------|
|
|
43
|
-
|
|
|
73
|
+
| `files` | Glob pattern to watch (e.g., `"src/**/*.ts"`) | *required* |
|
|
74
|
+
| `-c, --cmd <command>` | Command(s) to execute on change (supports `&&`) | *required* |
|
|
44
75
|
| `-d, --delay <ms>` | Debounce delay in milliseconds | `300` |
|
|
45
76
|
| `-v, --verbose` | Show hash calculations and file indexing | `false` |
|
|
77
|
+
| `-q, --quiet` | Minimize output | `false` |
|
|
78
|
+
| `--ignore <patterns>` | Additional ignore patterns (comma-separated) | `node_modules, .git, dist, build` |
|
|
79
|
+
| `--ext <extensions>` | Filter by file extensions (e.g., `.ts,.tsx`) | *none* |
|
|
80
|
+
| `--config <path>` | Path to config file | auto-detect |
|
|
81
|
+
| `--kill-timeout <ms>` | Force kill process after timeout (0 = disabled) | `0` |
|
|
82
|
+
| `--retry <count>` | Retry failed command (0 = disabled) | `0` |
|
|
83
|
+
| `--hash <algo>` | Hash algorithm (md5, sha1, sha256) | `md5` |
|
|
84
|
+
| `--no-hash` | Use mtime only instead of content hash (fastest) | `false` |
|
|
85
|
+
| `--clear` | Clear screen on each trigger | `false` |
|
|
86
|
+
| `--json` | Output in JSON format | `false` |
|
|
87
|
+
| `--theme <theme>` | Color theme (default, minimal, none) | `default` |
|
|
46
88
|
|
|
47
89
|
### Examples
|
|
48
90
|
|
|
@@ -55,8 +97,72 @@ sw "src/**/*.{ts,tsx}" -c "npm test" -d 500
|
|
|
55
97
|
|
|
56
98
|
# Verbose mode to see what's happening
|
|
57
99
|
sw "lib/**/*.js" -c "node build.js" -v
|
|
100
|
+
|
|
101
|
+
# Quiet mode (minimal output)
|
|
102
|
+
sw "src/**/*.ts" -c "npm run build" -q
|
|
103
|
+
|
|
104
|
+
# Filter by extensions
|
|
105
|
+
sw "src/**/*" -c "npm run build" --ext .ts,.tsx
|
|
106
|
+
|
|
107
|
+
# Custom ignore patterns
|
|
108
|
+
sw "src/**/*" -c "npm run build" --ignore "*.test.ts,tmp/*"
|
|
109
|
+
|
|
110
|
+
# Kill stuck processes after 10 seconds
|
|
111
|
+
sw "src/**/*.ts" -c "npm run build" --kill-timeout 10000
|
|
112
|
+
|
|
113
|
+
# Retry failed commands up to 3 times
|
|
114
|
+
sw "src/**/*.ts" -c "npm run build" --retry 3
|
|
115
|
+
|
|
116
|
+
# Multiple commands (using &&)
|
|
117
|
+
sw "src/**/*.ts" -c "npm run build && npm run test"
|
|
118
|
+
|
|
119
|
+
# Use config file
|
|
120
|
+
sw --config .steady-watchrc
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Programmatic API
|
|
124
|
+
|
|
125
|
+
You can also use Steady Watch as a library in your Node.js code:
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
import { SteadyWatcher, steadyWatch } from '@laphilosophia/steady-watch';
|
|
129
|
+
|
|
130
|
+
// Using the function
|
|
131
|
+
const watcher = steadyWatch({
|
|
132
|
+
pattern: 'src/**/*.ts',
|
|
133
|
+
cmd: 'npm run build',
|
|
134
|
+
delay: 300
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
// Or using the class
|
|
138
|
+
const watcher = new SteadyWatcher({
|
|
139
|
+
pattern: 'src/**/*.ts',
|
|
140
|
+
cmd: 'npm run build',
|
|
141
|
+
delay: 300
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
// Listen to events
|
|
145
|
+
watcher.on('ready', () => console.log('Ready!'));
|
|
146
|
+
watcher.on('change', (file) => console.log(`Changed: ${file}`));
|
|
147
|
+
watcher.on('trigger', (cmd) => console.log(`Running: ${cmd}`));
|
|
148
|
+
watcher.on('done', (duration) => console.log(`Done in ${duration}s`));
|
|
149
|
+
watcher.on('fail', (code) => console.log(`Failed: ${code}`));
|
|
150
|
+
|
|
151
|
+
await watcher.start();
|
|
152
|
+
|
|
153
|
+
// Get tracked files
|
|
154
|
+
console.log(watcher.getTrackedFiles());
|
|
155
|
+
|
|
156
|
+
// Stop watching
|
|
157
|
+
await watcher.close();
|
|
58
158
|
```
|
|
59
159
|
|
|
160
|
+
## Themes
|
|
161
|
+
|
|
162
|
+
- `default` - Full color output
|
|
163
|
+
- `minimal` - Monochrome output
|
|
164
|
+
- `none` - No colors at all
|
|
165
|
+
|
|
60
166
|
## Features
|
|
61
167
|
|
|
62
168
|
- 🎯 **Content Hashing** — Only triggers when file content actually changes
|
package/bin/steady-watch
ADDED
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
|
|
3
|
+
interface SteadyWatchOptions {
|
|
4
|
+
pattern: string;
|
|
5
|
+
cmd: string;
|
|
6
|
+
delay?: number;
|
|
7
|
+
verbose?: boolean;
|
|
8
|
+
quiet?: boolean;
|
|
9
|
+
ignore?: (string | RegExp)[];
|
|
10
|
+
ext?: string[];
|
|
11
|
+
killTimeout?: number;
|
|
12
|
+
retry?: number;
|
|
13
|
+
hash?: HashAlgorithm;
|
|
14
|
+
mtimeOnly?: boolean;
|
|
15
|
+
clearScreen?: boolean;
|
|
16
|
+
json?: boolean;
|
|
17
|
+
theme?: ThemeName;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface SteadyWatchEvents {
|
|
21
|
+
ready: () => void;
|
|
22
|
+
change: (file: string) => void;
|
|
23
|
+
trigger: (cmd: string) => void;
|
|
24
|
+
done: (duration: number) => void;
|
|
25
|
+
fail: (exitCode: number | null, signal?: string) => void;
|
|
26
|
+
error: (error: Error) => void;
|
|
27
|
+
skip: (reason: string, file?: string) => void;
|
|
28
|
+
}
|
|
29
|
+
type HashAlgorithm = 'md5' | 'sha1' | 'sha256';
|
|
30
|
+
type ThemeName = 'default' | 'minimal' | 'none';
|
|
31
|
+
interface NormalizedOptions {
|
|
32
|
+
pattern: string;
|
|
33
|
+
cmd: string;
|
|
34
|
+
delay: number;
|
|
35
|
+
verbose: boolean;
|
|
36
|
+
quiet: boolean;
|
|
37
|
+
ignore: (string | RegExp)[];
|
|
38
|
+
ext: string[];
|
|
39
|
+
killTimeout: number;
|
|
40
|
+
retry: number;
|
|
41
|
+
hash: HashAlgorithm;
|
|
42
|
+
mtimeOnly: boolean;
|
|
43
|
+
clearScreen: boolean;
|
|
44
|
+
json: boolean;
|
|
45
|
+
theme: ThemeName;
|
|
46
|
+
}
|
|
47
|
+
interface ValidationResult {
|
|
48
|
+
valid: boolean;
|
|
49
|
+
errors: string[];
|
|
50
|
+
}
|
|
51
|
+
interface CliOptions {
|
|
52
|
+
cmd?: string;
|
|
53
|
+
config?: string;
|
|
54
|
+
delay?: string;
|
|
55
|
+
verbose?: boolean;
|
|
56
|
+
quiet?: boolean;
|
|
57
|
+
ignore?: string;
|
|
58
|
+
ext?: string;
|
|
59
|
+
killTimeout?: string;
|
|
60
|
+
retry?: string;
|
|
61
|
+
hash?: string;
|
|
62
|
+
noHash?: boolean;
|
|
63
|
+
clear?: boolean;
|
|
64
|
+
json?: boolean;
|
|
65
|
+
theme?: string;
|
|
66
|
+
}
|
|
67
|
+
interface CliArgs {
|
|
68
|
+
pattern: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
type ChalkStyle = (s: string) => string;
|
|
72
|
+
interface Theme {
|
|
73
|
+
blue: ChalkStyle;
|
|
74
|
+
green: ChalkStyle;
|
|
75
|
+
yellow: ChalkStyle;
|
|
76
|
+
red: ChalkStyle;
|
|
77
|
+
cyan: ChalkStyle;
|
|
78
|
+
gray: ChalkStyle;
|
|
79
|
+
dim: ChalkStyle;
|
|
80
|
+
bold: ChalkStyle;
|
|
81
|
+
}
|
|
82
|
+
declare const themes: Record<ThemeName, Theme>;
|
|
83
|
+
declare function getTheme(name: ThemeName): Theme;
|
|
84
|
+
|
|
85
|
+
declare class SteadyWatcher extends EventEmitter {
|
|
86
|
+
private options;
|
|
87
|
+
private watcher;
|
|
88
|
+
private fileHashes;
|
|
89
|
+
private timeout;
|
|
90
|
+
private isRunning;
|
|
91
|
+
private activeProcess;
|
|
92
|
+
private killTimer;
|
|
93
|
+
private retryCount;
|
|
94
|
+
private disposed;
|
|
95
|
+
private t;
|
|
96
|
+
private static readonly DEFAULT_IGNORE;
|
|
97
|
+
private static readonly VALID_HASH_ALGORITHMS;
|
|
98
|
+
private static readonly VALID_THEMES;
|
|
99
|
+
constructor(options: SteadyWatchOptions);
|
|
100
|
+
private normalizeOptions;
|
|
101
|
+
private normalizeIgnorePatterns;
|
|
102
|
+
validate(): ValidationResult;
|
|
103
|
+
private getEffectivePattern;
|
|
104
|
+
private getHash;
|
|
105
|
+
private log;
|
|
106
|
+
private logVerbose;
|
|
107
|
+
private logJson;
|
|
108
|
+
private timestamp;
|
|
109
|
+
private parseCommand;
|
|
110
|
+
private runCommand;
|
|
111
|
+
private handleFileChange;
|
|
112
|
+
start(): Promise<void>;
|
|
113
|
+
close(): Promise<void>;
|
|
114
|
+
getTrackedFiles(): string[];
|
|
115
|
+
isCurrentlyRunning(): boolean;
|
|
116
|
+
isDisposed(): boolean;
|
|
117
|
+
}
|
|
118
|
+
declare function steadyWatch(options: SteadyWatchOptions): SteadyWatcher;
|
|
119
|
+
|
|
120
|
+
declare function runCli(): void;
|
|
121
|
+
|
|
122
|
+
export { type ChalkStyle, type CliArgs, type CliOptions, type HashAlgorithm, type NormalizedOptions, type SteadyWatchEvents, type SteadyWatchOptions, SteadyWatcher, type Theme, type ThemeName, type ValidationResult, getTheme, runCli, steadyWatch, themes };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
|
|
3
|
+
interface SteadyWatchOptions {
|
|
4
|
+
pattern: string;
|
|
5
|
+
cmd: string;
|
|
6
|
+
delay?: number;
|
|
7
|
+
verbose?: boolean;
|
|
8
|
+
quiet?: boolean;
|
|
9
|
+
ignore?: (string | RegExp)[];
|
|
10
|
+
ext?: string[];
|
|
11
|
+
killTimeout?: number;
|
|
12
|
+
retry?: number;
|
|
13
|
+
hash?: HashAlgorithm;
|
|
14
|
+
mtimeOnly?: boolean;
|
|
15
|
+
clearScreen?: boolean;
|
|
16
|
+
json?: boolean;
|
|
17
|
+
theme?: ThemeName;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface SteadyWatchEvents {
|
|
21
|
+
ready: () => void;
|
|
22
|
+
change: (file: string) => void;
|
|
23
|
+
trigger: (cmd: string) => void;
|
|
24
|
+
done: (duration: number) => void;
|
|
25
|
+
fail: (exitCode: number | null, signal?: string) => void;
|
|
26
|
+
error: (error: Error) => void;
|
|
27
|
+
skip: (reason: string, file?: string) => void;
|
|
28
|
+
}
|
|
29
|
+
type HashAlgorithm = 'md5' | 'sha1' | 'sha256';
|
|
30
|
+
type ThemeName = 'default' | 'minimal' | 'none';
|
|
31
|
+
interface NormalizedOptions {
|
|
32
|
+
pattern: string;
|
|
33
|
+
cmd: string;
|
|
34
|
+
delay: number;
|
|
35
|
+
verbose: boolean;
|
|
36
|
+
quiet: boolean;
|
|
37
|
+
ignore: (string | RegExp)[];
|
|
38
|
+
ext: string[];
|
|
39
|
+
killTimeout: number;
|
|
40
|
+
retry: number;
|
|
41
|
+
hash: HashAlgorithm;
|
|
42
|
+
mtimeOnly: boolean;
|
|
43
|
+
clearScreen: boolean;
|
|
44
|
+
json: boolean;
|
|
45
|
+
theme: ThemeName;
|
|
46
|
+
}
|
|
47
|
+
interface ValidationResult {
|
|
48
|
+
valid: boolean;
|
|
49
|
+
errors: string[];
|
|
50
|
+
}
|
|
51
|
+
interface CliOptions {
|
|
52
|
+
cmd?: string;
|
|
53
|
+
config?: string;
|
|
54
|
+
delay?: string;
|
|
55
|
+
verbose?: boolean;
|
|
56
|
+
quiet?: boolean;
|
|
57
|
+
ignore?: string;
|
|
58
|
+
ext?: string;
|
|
59
|
+
killTimeout?: string;
|
|
60
|
+
retry?: string;
|
|
61
|
+
hash?: string;
|
|
62
|
+
noHash?: boolean;
|
|
63
|
+
clear?: boolean;
|
|
64
|
+
json?: boolean;
|
|
65
|
+
theme?: string;
|
|
66
|
+
}
|
|
67
|
+
interface CliArgs {
|
|
68
|
+
pattern: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
type ChalkStyle = (s: string) => string;
|
|
72
|
+
interface Theme {
|
|
73
|
+
blue: ChalkStyle;
|
|
74
|
+
green: ChalkStyle;
|
|
75
|
+
yellow: ChalkStyle;
|
|
76
|
+
red: ChalkStyle;
|
|
77
|
+
cyan: ChalkStyle;
|
|
78
|
+
gray: ChalkStyle;
|
|
79
|
+
dim: ChalkStyle;
|
|
80
|
+
bold: ChalkStyle;
|
|
81
|
+
}
|
|
82
|
+
declare const themes: Record<ThemeName, Theme>;
|
|
83
|
+
declare function getTheme(name: ThemeName): Theme;
|
|
84
|
+
|
|
85
|
+
declare class SteadyWatcher extends EventEmitter {
|
|
86
|
+
private options;
|
|
87
|
+
private watcher;
|
|
88
|
+
private fileHashes;
|
|
89
|
+
private timeout;
|
|
90
|
+
private isRunning;
|
|
91
|
+
private activeProcess;
|
|
92
|
+
private killTimer;
|
|
93
|
+
private retryCount;
|
|
94
|
+
private disposed;
|
|
95
|
+
private t;
|
|
96
|
+
private static readonly DEFAULT_IGNORE;
|
|
97
|
+
private static readonly VALID_HASH_ALGORITHMS;
|
|
98
|
+
private static readonly VALID_THEMES;
|
|
99
|
+
constructor(options: SteadyWatchOptions);
|
|
100
|
+
private normalizeOptions;
|
|
101
|
+
private normalizeIgnorePatterns;
|
|
102
|
+
validate(): ValidationResult;
|
|
103
|
+
private getEffectivePattern;
|
|
104
|
+
private getHash;
|
|
105
|
+
private log;
|
|
106
|
+
private logVerbose;
|
|
107
|
+
private logJson;
|
|
108
|
+
private timestamp;
|
|
109
|
+
private parseCommand;
|
|
110
|
+
private runCommand;
|
|
111
|
+
private handleFileChange;
|
|
112
|
+
start(): Promise<void>;
|
|
113
|
+
close(): Promise<void>;
|
|
114
|
+
getTrackedFiles(): string[];
|
|
115
|
+
isCurrentlyRunning(): boolean;
|
|
116
|
+
isDisposed(): boolean;
|
|
117
|
+
}
|
|
118
|
+
declare function steadyWatch(options: SteadyWatchOptions): SteadyWatcher;
|
|
119
|
+
|
|
120
|
+
declare function runCli(): void;
|
|
121
|
+
|
|
122
|
+
export { type ChalkStyle, type CliArgs, type CliOptions, type HashAlgorithm, type NormalizedOptions, type SteadyWatchEvents, type SteadyWatchOptions, SteadyWatcher, type Theme, type ThemeName, type ValidationResult, getTheme, runCli, steadyWatch, themes };
|