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

Binstubs #833

Merged
merged 12 commits into from
Sep 19, 2017
Merged

Binstubs #833

merged 12 commits into from
Sep 19, 2017

Conversation

rossta
Copy link
Member

@rossta rossta commented Sep 19, 2017

Converts bin/webpack-dev-server and bin/webpack to binstubs. This convention would make it easier to change the implementation of the two task runners without requiring devs to re-run the installer.

I'd expect it would be simple to merge changes from the configurable-dev-server-options branch.

Fixes #831

@gauravtiwari
Copy link
Member

thanks @rossta ❤️ 💯 for the PR

Looks like rubocop isn't letting travis pass so if you can fix the offences, I will merge 👍

def initialize(argv)
@argv = argv

@app_path = File.expand_path("../", __dir__)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does __dir__ work correctly here (in a file in the gem)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, good catch—error in local testing. I may need to pass the app_path into the runner which may mean keeping the install template with less code instead of using a bundler binstub.

require "shellwords"

module Webpacker
class Runner
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps Runner should be the base class that all runner classes inherit from.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like:

# lib/webpacker/runners/webpack.rb
class Webpacker::WebpackRunner < Webpacker::Runner

# lib/webpacker/runners/dev_server.rb
class Webpacker::DevServerRunner < Webpacker::Runner

exit!
end

def update_argv
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need this empty method here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, removing!

@app_path = File.expand_path("../", __dir__)
@config_file = File.join(@app_path, "config/webpacker.yml")
@node_modules_path = File.join(@app_path, "node_modules")
@webpack_config = File.join(@app_path, "config/webpack/#{ENV["NODE_ENV"]}.js")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be we can load options from Webpacker.config or dev_server itself instead of loading the yml again?

Copy link
Member Author

@rossta rossta Sep 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great to avoid that duplication. Currently, Webpacker.dev_server inherits form Webpacker::Instance which depends on Rails (for Rails.root here) and I think it would be preferable to avoid depending on Rails to execute these scripts. Perhaps a future improvement?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense 👍

def initialize(argv)
@argv = argv

@app_path = File.expand_path(".", Dir.pwd)
Copy link
Member Author

@rossta rossta Sep 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using Dir.pwd has pros and cons: we can install the executables as binstubs with bundler (which won't supply the application dir context) but we wouldn't be able to execute the binstubs from anywhere but the project root. I'm unsure of how this might affect various deployment scenarios.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah... maybe you can leverage the root_path accessor set via webpacker itself which defaults to Rails.root? Not sure what's best in this context?

Copy link
Member Author

@rossta rossta Sep 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rails.root would make it easy but I was hoping to avoid relying on loading rails since these are just thin wrappers around node executables.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some alternatives:

  • Re-instate the bin templates (backing out of the the bundler binstub change) so we can pass in the app path to the runner
  • Support an ENV var like APP_PATH to override the default

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, lets tackle that in another PR

@rossta
Copy link
Member Author

rossta commented Sep 19, 2017

I've created a test repo pointing to this branch to demonstrate behavior with the new binstubs: https://github.com/rossta/webpacker_test

Copy link
Contributor

@curvo curvo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rossta Awesome PR... glad to be a part of the conversation and to see something like this come together so quickly!

def initialize(argv)
@argv = argv

@app_path = File.expand_path(".", Dir.pwd)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah... maybe you can leverage the root_path accessor set via webpacker itself which defaults to Rails.root? Not sure what's best in this context?

class DevServerRunner < Webpacker::Runner
def run
load_config
check_server!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may be call this detect_port!?

@gauravtiwari
Copy link
Member

@rossta Ready to merge? Looks good to me

@rossta
Copy link
Member Author

rossta commented Sep 19, 2017

@gauravtiwari Ready!

@gauravtiwari gauravtiwari merged commit 8f48616 into rails:master Sep 19, 2017
@gauravtiwari
Copy link
Member

Merged 🎉 🍰

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

Successfully merging this pull request may close these issues.

4 participants