From a61508dcaf13fba3720c3b8e40009d595496f7aa Mon Sep 17 00:00:00 2001 From: Justin Gordon Date: Sat, 21 Apr 2018 12:34:02 -1000 Subject: [PATCH] Sprockets: Use the most recent manifest When creating symlinks, use the most recent manifest found. See https://github.com/shakacode/react_on_rails/issues/1023 --- CHANGELOG.md | 3 ++- lib/react_on_rails/assets_precompile.rb | 6 +++++- spec/react_on_rails/assets_precompile_spec.rb | 19 +++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a912da5ed..198eb6ba75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/react_on_rails/assets_precompile.rb b/lib/react_on_rails/assets_precompile.rb index 489e9d495b..16662e7448 100644 --- a/lib/react_on_rails/assets_precompile.rb +++ b/lib/react_on_rails/assets_precompile.rb @@ -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) @@ -128,6 +128,10 @@ def clobber private + def take_most_recent_manifest_path(manifest_glob) + manifest_glob.sort_by { |name| File.mtime(name) }.last + 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 diff --git a/spec/react_on_rails/assets_precompile_spec.rb b/spec/react_on_rails/assets_precompile_spec.rb index a0bfc9a1f2..6719077040 100644 --- a/spec/react_on_rails/assets_precompile_spec.rb +++ b/spec/react_on_rails/assets_precompile_spec.rb @@ -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}\"}}") @@ -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