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

ReactOnRails::Utils.bundle_js_file_path returns incorrect path for manifest.json #1011

Closed
elstgav opened this issue Jan 10, 2018 · 1 comment

Comments

@elstgav
Copy link
Contributor

elstgav commented Jan 10, 2018

I noticed that ReactOnRails::TestHelper.ensure_assets_compiled always reports that manifest.json is stale when running tests, even when the file exists and is up to date:

Detected the following stale generated files:
  manifest.json

After investigating, I believe this is because ReactOnRails::Utils.bundle_js_file_path() does not return the correct file path for 'manifest.json', so ReactOnRails::TestHelper.ensure_assets_compiled can’t accurately check if the file exists and is up to date.

Thanks to line 89 of lib/react_on_rails/utils.rb, it will always return 'manifest.json' instead of the correct path (e.g. '/path/to/rails/public/packs-test/manifest.json'):

def self.bundle_js_file_path(bundle_name)
  if using_webpacker?
    return bundle_name if bundle_name == "manifest.json"

So in summary:

Problem:

ReactOnRails::Utils.bundle_js_file_path('manifest.json')
returns 'manifest.json'

Expected:

ReactOnRails::Utils.bundle_js_file_path('manifest.json')
returns '/path/to/rails/public/packs-test/manifest.json'

Proposed Solution:

Change ReactOnRails::Utils.bundle_js_file_path to

def self.bundle_js_file_path(bundle_name)
  if using_webpacker? && bundle_name != "manifest.json"
    bundle_js_file_path_from_webpacker(bundle_name)
  else
    # Default to the non-hashed name in the specified output directory, which, for legacy
    # React on Rails, this is the output directory picked up by the asset pipeline.
    File.join(ReactOnRails.configuration.generated_assets_dir, bundle_name)
  end
end
@justin808
Copy link
Member

@elstgav good work. Please submit a PR.

justin808 pushed a commit that referenced this issue Jan 11, 2018
…#1012)

* Fix Utils.bundle_js_file_path for manifest.json in webpacker projects

Utils.bundle_js_file_path was incorrectly returning
`'manifest.json'`
instead of, say,
`'/path/to/rails/public/packs/manifest.json'`

Fixes #1011

* Make issue link explicit
justin808 pushed a commit that referenced this issue Jan 24, 2018
…#1012)

* Fix Utils.bundle_js_file_path for manifest.json in webpacker projects

Utils.bundle_js_file_path was incorrectly returning
`'manifest.json'`
instead of, say,
`'/path/to/rails/public/packs/manifest.json'`

Fixes #1011

* Make issue link explicit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants