@@ -6,7 +6,7 @@ import PackageReader from './package-reader';
66import Package from './package' ;
77import stubModule from './stub-module' ;
88import { info , error , warn } from './log' ;
9- import { stripJsExtension , resolvePackagePath , contentOrFile } from './shared' ;
9+ import { generateHash , stripJsExtension , resolvePackagePath , contentOrFile } from './shared' ;
1010import * as cache from './cache/default' ;
1111import path from 'path' ;
1212import mergeTransformed from './transformers/merge' ;
@@ -120,6 +120,23 @@ export default class Bundler {
120120 }
121121
122122 capture ( unit ) {
123+ const hash = generateHash ( JSON . stringify ( unit ) ) ;
124+
125+ if ( this . _inWatchMode && ! unit . packageName ) {
126+ if ( this . _unitsMap [ unit . path ] ) {
127+ const oldHash = this . _unitsMap [ unit . path ] . hash ;
128+
129+ if ( oldHash === hash ) {
130+ // ignore unchanged file in watch mode
131+ return Promise . resolve ( this . _unitsMap [ unit . path ] ) ;
132+ }
133+
134+ info ( `Update ${ unit . path } ` ) ;
135+ } else {
136+ info ( `Add ${ unit . path } ` ) ;
137+ }
138+ }
139+
123140 if ( unit . packageName ) {
124141 unit . shim = this . shimFor ( unit . packageName ) ;
125142 }
@@ -129,7 +146,10 @@ export default class Bundler {
129146 cache : this . _cache ,
130147 depsFinder : this . _depsFinder
131148 } ) . then (
132- tracedUnit => this . _capture ( tracedUnit ) ,
149+ tracedUnit => {
150+ tracedUnit . hash = hash ;
151+ return this . _capture ( tracedUnit ) ;
152+ } ,
133153 err => {
134154 // just print error, but not stopping
135155 error ( 'Tracing failed for ' + unit . path ) ;
@@ -147,13 +167,6 @@ export default class Bundler {
147167 }
148168
149169 _capture ( tracedUnit ) {
150- if ( this . _inWatchMode && ! tracedUnit . packageName ) {
151- if ( this . _unitsMap [ tracedUnit . path ] ) {
152- info ( `Update ${ tracedUnit . path } ` ) ;
153- } else {
154- info ( `Add ${ tracedUnit . path } ` ) ;
155- }
156- }
157170 this . _unitsMap [ tracedUnit . path ] = tracedUnit ;
158171
159172 // mark as done.
0 commit comments