Installations
npm install @poppinss/chokidar-ts
Developer Guide
Typescript
Yes
Module System
ESM
Min. Node Version
>=18.16.0
Node Version
20.18.1
NPM Version
10.8.2
Score
91.4
Supply Chain
100
Quality
83.8
Maintenance
100
Vulnerability
99.6
License
Releases
Update dependencies
Updated on Dec 28, 2024
Update dependencies
Updated on Mar 28, 2024
Remove deprecated packages
Updated on Dec 18, 2023
Update dependencies
Updated on Dec 16, 2023
Publish source maps and use TSC for generating types
Updated on Nov 06, 2023
Breaking changes + ESM only
Updated on Oct 14, 2023
Contributors
Unable to fetch Contributors
Languages
TypeScript (99.51%)
JavaScript (0.49%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
poppinss
Download Statistics
Total Downloads
2,669,574
Last Day
4,625
Last Week
32,434
Last Month
126,526
Last Year
1,136,742
GitHub Statistics
MIT License
13 Stars
162 Commits
4 Forks
3 Watchers
1 Branches
5 Contributors
Updated on Feb 04, 2025
Package Meta Information
Latest Version
4.1.5
Package Id
@poppinss/chokidar-ts@4.1.5
Unpacked Size
19.20 kB
Size
6.08 kB
File Count
11
NPM Version
10.8.2
Node Version
20.18.1
Published on
Dec 28, 2024
Total Downloads
Cumulative downloads
Total Downloads
2,669,574
Last Day
-7.6%
4,625
Compared to previous day
Last Week
11.5%
32,434
Compared to previous week
Last Month
47.2%
126,526
Compared to previous month
Last Year
74.5%
1,136,742
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Peer Dependencies
1
Chokidar TS
A thin wrapper on top of chokidar file watcher that relies on the
tsconfig.json
file to distinguish between the TypeScript source files and other files.
Why does this package exists?
When running a Node.js backend development server with a file watcher, we need to know whether a newly added or changed file is part of our TypeScript project.
The best way to establish if a file is part of a TypeScript project is to rely on the tsconfig.json
file.
This is precisely what this package does. It will create a file watcher using chokidar and then uses the includes
and excludes
patterns from the tsconfig.json
file to know if a changed file is part of a TypeScript project.
Setup
Install the package from the npm packages registry. In addition, the package has a peer dependency on the typescript
package, so make sure to install that as well.
1npm i @poppinss/chokidar-ts
1yarn add @poppinss/chokidar-ts
1pnpm add @poppinss/chokidar-ts
And use it as follows.
1import typescript from 'typescript' 2import { ConfigParser, Watcher } from '@poppinss/chokidar-ts' 3 4const projectRoot = new URL('./', import.meta.url) 5const configFileName = 'tsconfig.json' 6 7const { config } = new ConfigParser( 8 projectRoot, 9 configFileName, 10 typescript, 11).parse() 12 13if (config) { 14 const watcher = new Watcher(projectRoot, config) 15 watcher.watch(['.']) 16}
Listening for events
The Watcher
class emits the following events. Events prefixed with source
refers to files included by the tsconfig.json
file, and other events refer to non-typescript or files excluded by the tsconfig.json
file.
add
: A new file has been added. The file is either not a TypeScript file or is excluded by thetsconfig.json
file.source:add
: A new TypeScript source file has been added.change
: An existing file has been updated. The file is either not a TypeScript file or is excluded by thetsconfig.json
file.source:change
: An existing TypeScript source file has been changed.unlink
: An existing file has been deleted. The file is not a TypeScript source file.source:unlink
: An existing TypeScript source file has been deleted.
1const watcher = new Watcher(projectRoot, config) 2 3watcher.on('add', (file) => { 4 console.log(file.absPath) 5 console.log(file.relativePath) 6}) 7 8watcher.on('source:add', (file) => { 9 console.log(file.absPath) 10 console.log(file.relativePath) 11}) 12 13watcher.on('change', (file) => { 14 console.log(file.absPath) 15 console.log(file.relativePath) 16}) 17 18watcher.on('source:change', (file) => { 19 console.log(file.absPath) 20 console.log(file.relativePath) 21}) 22 23watcher.on('unlink', (file) => { 24 console.log(file.absPath) 25 console.log(file.relativePath) 26}) 27 28watcher.on('source:unlink', (file) => { 29 console.log(file.absPath) 30 console.log(file.relativePath) 31}) 32 33watcher.watch(['.'])
Handling config parser errors
Parsing the tsconfig.json
file can produce errors, and you can display them using the TypeScript compiler as follows.
1import typescript from 'typescript' 2const { error, config } = new ConfigParser( 3 projectRoot, 4 configFileName, 5 typescript, 6).parse() 7 8if (error) { 9 const compilerHost = typescript.createCompilerHost({}) 10 console.log( 11 typescript.formatDiagnosticsWithColorAndContext([error], compilerHost) 12 ) 13 14 return 15} 16 17if (!config) { 18 return 19} 20 21if (config.errors) { 22 const compilerHost = typescript.createCompilerHost({}) 23 console.log( 24 typescript.formatDiagnosticsWithColorAndContext(config.errors, compilerHost) 25 ) 26 27 return 28}

No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE.md:0
- Info: FSF or OSI recognized license: MIT License: LICENSE.md:0
Reason
security policy file detected
Details
- Info: security policy file detected: github.com/poppinss/.github/docs/SECURITY.md:1
- Info: Found linked content: github.com/poppinss/.github/docs/SECURITY.md:1
- Info: Found disclosure, vulnerability, and/or timelines in security policy: github.com/poppinss/.github/docs/SECURITY.md:1
- Info: Found text in security policy: github.com/poppinss/.github/docs/SECURITY.md:1
Reason
7 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 5
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/labels.yml:10: update your workflow using https://app.stepsecurity.io/secureworkflow/poppinss/chokidar-ts/labels.yml/4.x?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/labels.yml:11: update your workflow using https://app.stepsecurity.io/secureworkflow/poppinss/chokidar-ts/labels.yml/4.x?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:13: update your workflow using https://app.stepsecurity.io/secureworkflow/poppinss/chokidar-ts/release.yml/4.x?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/poppinss/chokidar-ts/release.yml/4.x?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/stale.yml:10: update your workflow using https://app.stepsecurity.io/secureworkflow/poppinss/chokidar-ts/stale.yml/4.x?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/release.yml:28
- Info: 0 out of 4 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 third-party GitHubAction dependencies pinned
- Info: 0 out of 1 npmCommand dependencies pinned
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/checks.yml:1
- Warn: topLevel 'contents' permission set to 'write': .github/workflows/release.yml:4
- Warn: no topLevel permission defined: .github/workflows/stale.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 1 are checked with a SAST tool
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch '4.x'
Score
4.5
/10
Last Scanned on 2025-02-10
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More