Skip to content

Commit

Permalink
fix(watch): resolve issue where changes are not detected
Browse files Browse the repository at this point in the history
closes #675
  • Loading branch information
JeroenVinke committed Aug 12, 2017
1 parent 7f5e84c commit 9146da2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 28 deletions.
35 changes: 21 additions & 14 deletions lib/resources/tasks/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,29 @@ if (typeof project.build.copyFiles === 'object') {

let watch = (callback) => {
watchCallback = callback || watchCallback;
return gulpWatch(
Object.keys(watches),
{
read: false, // performance optimization: do not read actual file contents
verbose: true
},
(vinyl) => {
if (vinyl.path && vinyl.cwd && vinyl.path.startsWith(vinyl.cwd)) {
let pathToAdd = vinyl.path.substr(vinyl.cwd.length + 1);
log(`Watcher: Adding path ${pathToAdd} to pending build changes...`);
pendingRefreshPaths.push(pathToAdd);
refresh();
}
});

const watchPaths = Object.keys(watches);

for(let i = 0; i < watchPaths.length; i++) {
gulpWatch(
watchPaths[i],
{
read: false, // performance optimization: do not read actual file contents
verbose: true
},
(vinyl) => processChange(vinyl));
}
};

let processChange = (vinyl) => {
if (vinyl.path && vinyl.cwd && vinyl.path.startsWith(vinyl.cwd)) {
let pathToAdd = vinyl.path.substr(vinyl.cwd.length + 1);
log(`Watcher: Adding path ${pathToAdd} to pending build changes...`);
pendingRefreshPaths.push(pathToAdd);
refresh();
}
}

let refresh = debounce(() => {
if (isBuilding) {
log('Watcher: A build is already in progress, deferring change detection...');
Expand Down
35 changes: 21 additions & 14 deletions lib/resources/tasks/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,29 @@ if (typeof project.build.copyFiles === 'object') {

let watch = (callback?) => {
watchCallback = callback || watchCallback;
return gulpWatch(
Object.keys(watches),
{
read: false, // performance optimization: do not read actual file contents
verbose: true
},
(vinyl) => {
if (vinyl.path && vinyl.cwd && vinyl.path.startsWith(vinyl.cwd)) {
let pathToAdd = vinyl.path.substr(vinyl.cwd.length + 1);
log(`Watcher: Adding path ${pathToAdd} to pending build changes...`);
pendingRefreshPaths.push(pathToAdd);
refresh();
}
});

const watchPaths = Object.keys(watches);

for(let i = 0; i < watchPaths.length; i++) {
gulpWatch(
watchPaths[i],
{
read: false, // performance optimization: do not read actual file contents
verbose: true
},
(vinyl) => processChange(vinyl));
}
};

let processChange = (vinyl) => {
if (vinyl.path && vinyl.cwd && vinyl.path.startsWith(vinyl.cwd)) {
let pathToAdd = vinyl.path.substr(vinyl.cwd.length + 1);
log(`Watcher: Adding path ${pathToAdd} to pending build changes...`);
pendingRefreshPaths.push(pathToAdd);
refresh();
}
}

let refresh = debounce(() => {
if (isBuilding) {
log('Watcher: A build is already in progress, deferring change detection...');
Expand Down

0 comments on commit 9146da2

Please sign in to comment.