Skip to content

Commit

Permalink
Backport SHA digest file checking to 3-x-stable (#1749)
Browse files Browse the repository at this point in the history
See #1743
  • Loading branch information
ericboehs authored and gauravtiwari committed Oct 11, 2018
1 parent c00a2d6 commit 4103f4b
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 8 deletions.
3 changes: 0 additions & 3 deletions docs/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,3 @@ environment.plugins.append('ContextReplacement',
)
)
```

## Compilation triggered even when files haven't changed
Webpacker compares the modified times (mtimes) of files to see if they have changed & determine whether to recompile on-demand. For CI environments that clone the repository before running tests, the modified times will be set to when the repository was cloned, not when the file was last modified. To prevent unnecessary recompilation on CI, Webpacker watches for the `CI` environment variable, and instead compares the SHA hashes of all files to determine if they've actually changed. You can enable this behavior outside of CI environemnts, or in those that don't set the `CI` env var, by running `CI=true bin/webpack` (or `webpack-dev-server`).
6 changes: 1 addition & 5 deletions lib/webpacker/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ def last_compilation_digest

def watched_files_digest
files = Dir[*default_watched_paths, *watched_paths].reject { |f| File.directory?(f) }
file_ids = if ENV["CI"]
files.sort.map { |f| "#{File.basename(f)}/#{Digest::SHA1.file(f).hexdigest}" }
else
files.map { |f| "#{File.basename(f)}/#{File.mtime(f).utc.to_i}" }
end
file_ids = files.sort.map { |f| "#{File.basename(f)}/#{Digest::SHA1.file(f).hexdigest}" }
Digest::SHA1.hexdigest(file_ids.join("/"))
end

Expand Down

0 comments on commit 4103f4b

Please sign in to comment.