Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use most recent sprockets manifest #1064

Merged
merged 1 commit into from
Apr 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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