
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
@poppinss/chokidar-ts
Advanced tools
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.
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.
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.
npm i @poppinss/chokidar-ts
yarn add @poppinss/chokidar-ts
pnpm add @poppinss/chokidar-ts
And use it as follows.
import typescript from 'typescript'
import { ConfigParser, Watcher } from '@poppinss/chokidar-ts'
const projectRoot = new URL('./', import.meta.url)
const configFileName = 'tsconfig.json'
const { config } = new ConfigParser(
projectRoot,
configFileName,
typescript,
).parse()
if (config) {
const watcher = new Watcher(projectRoot, config)
watcher.watch(['.'])
}
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 the tsconfig.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 the tsconfig.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.const watcher = new Watcher(projectRoot, config)
watcher.on('add', (file) => {
console.log(file.absPath)
console.log(file.relativePath)
})
watcher.on('source:add', (file) => {
console.log(file.absPath)
console.log(file.relativePath)
})
watcher.on('change', (file) => {
console.log(file.absPath)
console.log(file.relativePath)
})
watcher.on('source:change', (file) => {
console.log(file.absPath)
console.log(file.relativePath)
})
watcher.on('unlink', (file) => {
console.log(file.absPath)
console.log(file.relativePath)
})
watcher.on('source:unlink', (file) => {
console.log(file.absPath)
console.log(file.relativePath)
})
watcher.watch(['.'])
Parsing the tsconfig.json
file can produce errors, and you can display them using the TypeScript compiler as follows.
import typescript from 'typescript'
const { error, config } = new ConfigParser(
projectRoot,
configFileName,
typescript,
).parse()
if (error) {
const compilerHost = typescript.createCompilerHost({})
console.log(
typescript.formatDiagnosticsWithColorAndContext([error], compilerHost)
)
return
}
if (!config) {
return
}
if (config.errors) {
const compilerHost = typescript.createCompilerHost({})
console.log(
typescript.formatDiagnosticsWithColorAndContext(config.errors, compilerHost)
)
return
}
FAQs
File watcher for TypeScript projects
The npm package @poppinss/chokidar-ts receives a total of 31,312 weekly downloads. As such, @poppinss/chokidar-ts popularity was classified as popular.
We found that @poppinss/chokidar-ts demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.