Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

Commit 27b5069

Browse files
committed
fix(watch): fix watch code
1 parent 21ed803 commit 27b5069

File tree

1 file changed

+19
-25
lines changed

1 file changed

+19
-25
lines changed

src/watch.ts

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { build } from './build';
22
import { BuildContext, TaskInfo } from './util/interfaces';
33
import { BuildError, Logger } from './util/logger';
44
import { fillConfigDefaults, generateContext, getUserConfigFile, replacePathVars, setIonicEnvironment } from './util/config';
5-
import { normalize } from 'path';
5+
import { join, normalize } from 'path';
66
import * as chalk from 'chalk';
77
import * as chokidar from 'chokidar';
88

@@ -61,40 +61,34 @@ function startWatcher(index: number, watcher: Watcher, context: BuildContext, wa
6161
return;
6262
}
6363

64-
let taskPromise = Promise.resolve();
65-
let nextTask: any = null;
66-
6764
const chokidarWatcher = chokidar.watch(<any>watcher.paths, watcher.options);
6865

6966
chokidarWatcher.on('all', (event: string, filePath: string) => {
7067
setIonicEnvironment(context.isProd);
7168

69+
filePath = join(context.rootDir, filePath);
70+
71+
context.isUpdate = true;
72+
context.fileChanged = filePath;
73+
7274
Logger.debug(`watch callback start, id: ${watchCount}, isProd: ${context.isProd}, event: ${event}, path: ${filePath}`);
7375

7476
function taskDone() {
7577
Logger.info(chalk.green('watch ready'));
7678
}
7779

78-
nextTask = watcher.callback.bind(null, event, filePath, context);
79-
taskPromise.then(() => {
80-
Logger.debug(`watch callback complete, id: ${watchCount}, isProd: ${context.isProd}, event: ${event}, path: ${filePath}`);
81-
taskPromise = nextTask();
82-
taskPromise
83-
.then(taskDone, taskDone)
84-
.catch(taskDone);
85-
nextTask = null;
86-
watchCount++;
87-
88-
}).catch(err => {
89-
Logger.debug(`watch callback error, id: ${watchCount}, isProd: ${context.isProd}, event: ${event}, path: ${filePath}`);
90-
Logger.debug(`${err}`);
91-
taskPromise = nextTask();
92-
taskPromise
93-
.then(taskDone, taskDone)
94-
.catch(taskDone);
95-
nextTask = null;
96-
watchCount++;
97-
});
80+
watcher.callback(event, filePath, context)
81+
.then(() => {
82+
Logger.debug(`watch callback complete, id: ${watchCount}, isProd: ${context.isProd}, event: ${event}, path: ${filePath}`);
83+
watchCount++;
84+
taskDone();
85+
})
86+
.catch(err => {
87+
Logger.debug(`watch callback error, id: ${watchCount}, isProd: ${context.isProd}, event: ${event}, path: ${filePath}`);
88+
Logger.debug(`${err}`);
89+
watchCount++;
90+
taskDone();
91+
});
9892
});
9993

10094
chokidarWatcher.on('ready', () => {
@@ -156,7 +150,7 @@ export interface Watcher {
156150
cwd?: string;
157151
};
158152
callback?: {
159-
(event: string, filePath: string, context: BuildContext): void;
153+
(event: string, filePath: string, context: BuildContext): Promise<any>;
160154
};
161155
}
162156

0 commit comments

Comments
 (0)