Skip to content

Commit 6f4be76

Browse files
authored
feat(watcher): accept poll flag for polling file system changes
* fix(watcher): make watcher respect excluded directories Make watcher respect excluded directories set in configuration file * fix(watcher): add polling option to watcher Add commandline flag to use polling instead of filesystem events to detect file changes
1 parent f5390c5 commit 6f4be76

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

commands/Serve.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ export default class Serve extends BaseCommand {
2323
@flags.boolean({ description: 'Watch for file changes and re-build the project', alias: 'w' })
2424
public watch: boolean
2525

26+
/**
27+
* Detect changes by polling files
28+
*/
29+
@flags.boolean({
30+
description: 'Detect file changes by polling files instead of listening to filesystem events',
31+
alias: 'p',
32+
})
33+
public poll: boolean
34+
2635
/**
2736
* Allows watching for file changes
2837
*/
@@ -73,9 +82,9 @@ export default class Serve extends BaseCommand {
7382

7483
try {
7584
if (this.compile === false) {
76-
await new BuildWatcher(cwd, this.nodeArgs, this.logger).watch(ADONIS_BUILD_DIR() || './')
85+
await new BuildWatcher(cwd, this.nodeArgs, this.logger).watch(ADONIS_BUILD_DIR() || './', this.poll)
7786
} else if (this.watch) {
78-
await new Watcher(cwd, true, this.nodeArgs, this.logger).watch()
87+
await new Watcher(cwd, true, this.nodeArgs, this.logger).watch(this.poll)
7988
} else {
8089
await new Compiler(cwd, true, this.nodeArgs, this.logger).compile()
8190
}

src/BuildWatcher/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class BuildWatcher {
4141
/**
4242
* Watch for compiled output changes
4343
*/
44-
public async watch (buildDir: string) {
44+
public async watch (buildDir: string, poll = false) {
4545
const absPath = join(this.buildRoot, buildDir)
4646
const hasBuildDir = await pathExists(absPath)
4747
if (!hasBuildDir) {
@@ -58,6 +58,7 @@ export class BuildWatcher {
5858
*/
5959
const watcher = chokidar.watch(['.'], {
6060
ignoreInitial: true,
61+
usePolling: poll,
6162
cwd: absPath,
6263
ignored: [
6364
'node_modules/**',

src/Watcher/index.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class Watcher {
3838
/**
3939
* Build and watch for file changes
4040
*/
41-
public async watch () {
41+
public async watch (poll = false) {
4242
const config = this.compiler.parseConfig()
4343
if (!config) {
4444
return
@@ -204,10 +204,8 @@ export class Watcher {
204204
* Start the watcher
205205
*/
206206
watcher.watch(['.'], {
207-
ignored: [
208-
'node_modules/**',
209-
`${config.options.outDir}/**`,
210-
],
207+
ignored: config.raw.exclude,
208+
usePolling: poll,
211209
})
212210
}
213211
}

0 commit comments

Comments
 (0)