diff --git a/src/webassets/script.py b/src/webassets/script.py index c1674fea..b0133f2e 100644 --- a/src/webassets/script.py +++ b/src/webassets/script.py @@ -231,7 +231,15 @@ def check_for_changes(): return changed_bundles try: - self.log.info("Watching %d bundles for changes..." % len(self.environment)) + # Before starting to watch for changes, also recognize changes + # made while we did not run, and apply those immediately. + for bundle in self.environment: + print 'Bringing up to date: %s' % bundle.output + bundle.build(force=False) + + self.log.info("Watching %d bundles for changes..." % + len(self.environment)) + while True: changed_bundles = check_for_changes() built = [] diff --git a/tests/test_script.py b/tests/test_script.py index d09d4a52..a790ed11 100644 --- a/tests/test_script.py +++ b/tests/test_script.py @@ -254,3 +254,26 @@ def test_same_file_multiple_bundles(self): # Both output files have been updated. assert self.get('out') == 'foo' assert self.get('out2') == 'foo' + + def test_initial_build(self): + """The watch command also detects changes that were made while it was + not running, and applies those right away on start. + """ + # Register a bundle to watch + bundle = self.mkbundle('in', output='out') + self.env.register('test', bundle) + + # Mark the input file has changed before we even run the command. + now = self.setmtime('in') + self.setmtime('out', mtime=now-100) + + # Assert initial state + assert self.get('out') == 'bar' + + # Run the watch command for a while, but don't make any changes. + with self: + time.sleep(0.2) + + # Output file has been updated, not due to a change detected by watch, + # but because watch recognized the initial requirement for a build. + assert self.get('out') == 'foo'