Skip to content

Commit

Permalink
Sprockets: Use the most recent manifest (#1064)
Browse files Browse the repository at this point in the history
When creating symlinks, use the most recent manifest found.

See #1023
  • Loading branch information
justin808 authored Apr 22, 2018
1 parent 0cb3768 commit 098b2d2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ Changes since last non-beta release.
the same exact versions so that we can be sure that the interaction between them is precise.
This is so that if a bug is detected after some update, it's critical that
both the gem and the node package get the updates. This change ensures that the package.json specification does not use a
~ or ^ as reported in [#1062](https://github.com/shakacode/react_on_rails/issues/1062). [PR 1063](https://github.com/shakacode/react_on_rails/pull/1063) by [justin808](https://github.com/justin808).
~ or ^ as reported in [issue #1062](https://github.com/shakacode/react_on_rails/issues/1062). [PR 1063](https://github.com/shakacode/react_on_rails/pull/1063) by [justin808](https://github.com/justin808).
- Sprockets: Now use the most recent manifest when creating symlinks. See [issue #1023](https://github.com/shakacode/react_on_rails/issues/1023). [PR 1064](https://github.com/shakacode/react_on_rails/pull/1064) by [justin808](https://github.com/justin808).

### [10.1.4] - 2018-04-11

Expand Down
6 changes: 5 additions & 1 deletion lib/react_on_rails/assets_precompile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def symlink_non_digested_assets
"or manifest.yml at #{@assets_path}, but found none. Canceling symlinking tasks."
return -1
end
manifest_path = manifest_glob.first
manifest_path = take_most_recent_manifest_path(manifest_glob)
manifest_file = File.new(manifest_path)
manifest_data = if File.extname(manifest_file) == ".json"
manifest_file_data = File.read(manifest_path)
Expand Down Expand Up @@ -128,6 +128,10 @@ def clobber

private

def take_most_recent_manifest_path(manifest_glob)
manifest_glob.max_by { |name| File.mtime(name) }
end

def symlink_and_points_to_existing_file?(symlink_path)
# File.exist?(symlink_path) will check the file the sym is pointing to is existing
# File.lstat(symlink_path).symlink? confirms that this is a symlink
Expand Down
19 changes: 19 additions & 0 deletions spec/react_on_rails/assets_precompile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ module ReactOnRails
let(:digest_filename) { "alfa.12345.js" }
let(:nondigest_filename) { "alfa.js" }

let(:create_old_json_manifest) do
file_path = assets_path.join("manifest-old.json")
File.open(file_path, "w") do |f|
f.write("{\"assets\":{\"#{nondigest_filename}\": \"#{digest_filename}-123\"}}")
end
FileUtils.touch file_path, mtime: Time.now - 1.day
end

let(:create_json_manifest) do
File.open(assets_path.join("manifest-alfa.json"), "w") do |f|
f.write("{\"assets\":{\"#{nondigest_filename}\": \"#{digest_filename}\"}}")
Expand All @@ -131,6 +139,17 @@ module ReactOnRails
symlink_non_digested_assets_regex: Regexp.new('.*\.js$'))
end

it "creates a symlink with the original filename that points to the digested filename" do
FileUtils.touch assets_path.join(digest_filename)
create_old_json_manifest
create_json_manifest
checker.symlink_non_digested_assets

expect(assets_path.join(nondigest_filename).lstat.symlink?).to be true
expect(File.identical?(assets_path.join(nondigest_filename),
assets_path.join(digest_filename))).to be true
end

it "creates a symlink with the original filename that points to the digested filename" do
FileUtils.touch assets_path.join(digest_filename)
create_json_manifest
Expand Down

0 comments on commit 098b2d2

Please sign in to comment.