-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added build --as-needed to watch and rebuild
- Loading branch information
Showing
6 changed files
with
357 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* @flow */ | ||
import Watchpack from 'watchpack'; | ||
import debounce from 'debounce'; | ||
|
||
import {createLogger} from './util/logger'; | ||
|
||
const log = createLogger(__filename); | ||
|
||
|
||
export default function onSourceChange( | ||
{sourceDir, artifactsDir, onChange, shouldWatchFile}: Object): Watchpack { | ||
// TODO: For network disks, we would need to add {poll: true}. | ||
const watcher = new Watchpack(); | ||
|
||
const onFileChange = (filePath) => { | ||
proxyFileChanges({artifactsDir, onChange, filePath, shouldWatchFile}); | ||
}; | ||
const executeImmediately = true; | ||
watcher.on('change', debounce(onFileChange, 1000, executeImmediately)); | ||
|
||
log.debug(`Watching for file changes in ${sourceDir}`); | ||
watcher.watch([], [sourceDir], Date.now()); | ||
|
||
// TODO: support windows See: | ||
// http://stackoverflow.com/questions/10021373/what-is-the-windows-equivalent-of-process-onsigint-in-node-js | ||
process.on('SIGINT', () => watcher.close()); | ||
return watcher; | ||
} | ||
|
||
|
||
export function proxyFileChanges( | ||
{artifactsDir, onChange, filePath, shouldWatchFile=() => true} | ||
: Object) { | ||
if (filePath.indexOf(artifactsDir) === 0 || !shouldWatchFile(filePath)) { | ||
log.debug(`Ignoring change to: ${filePath}`); | ||
} else { | ||
log.info(`Changed: ${filePath}`); | ||
log.debug(`Last change detection: ${(new Date()).toTimeString()}`); | ||
onChange(); | ||
} | ||
} |
Oops, something went wrong.