A lightweight file watcher that executes commands as soon as files change.
as-soon is a command-line tool that watches specified files or directories and automatically executes a command whenever changes are detected. It's perfect for development workflows where you need to rebuild, test, or restart processes whenever your code changes.
- Simple and fast - Watch files and execute commands with minimal configuration
- Flexible watching - Watch specific directories or the current working directory
- Debounced execution - Commands are debounced (200ms) to avoid excessive runs during rapid file changes
- File creation support - Can watch for files that don't exist yet and automatically start watching them once created
-
Environment variables - Loads environment variables from
.envfiles automatically - Directory recreation handling - Automatically re-subscribes when watched directories are deleted and recreated
npm install -g as-soon
# or
pnpm add -g as-soonOr use it locally in your project:
npm install -D as-soon
# or
pnpm add -D as-soonWatch the current directory and execute a command on any file change:
as-soon commandUse the -w flag to watch specific directories:
as-soon -w src -w public pnpm buildYou can also watch specific files:
as-soon -w package.json -w tsconfig.json pnpm buildAny arguments after the command are passed through:
as-soon pnpm test -- --watchWatch multiple directories:
as-soon -w src -w test pnpm build- Initial Execution: The command runs immediately when you start as-soon
- File Watching: It watches the specified directories (or current directory by default)
- Change Detection: When files are added, modified, or deleted, it detects the changes
- Debounced Execution: After a 200ms debounce period, the command executes again
- Continuous Watching: The process continues until you stop it (Ctrl+C)
Watch your source files and rebuild on changes:
as-soon -w src pnpm buildRun tests whenever test files change:
as-soon -w test pnpm testRun TypeScript type checking on file changes:
as-soon -w src tsc --noEmitWatch multiple directories in a monorepo:
as-soon -w packages/app/src -w packages/lib/src pnpm buildYou can even watch for files that don't exist yet:
as-soon -w ./config/dev.ts pnpm buildThis is useful for configuration files that might be created later.
-
-w <path>- Specify a directory or file to watch (can be used multiple times) - All other arguments are treated as the command to execute
as-soon automatically loads environment variables from .env files using ldenv.
MIT