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

feat: pass through hot: only to webpack-dev-server #378

Merged
merged 5 commits into from
Dec 15, 2023
Merged

feat: pass through hot: only to webpack-dev-server #378

merged 5 commits into from
Dec 15, 2023

Conversation

SimenB
Copy link
Contributor

@SimenB SimenB commented Nov 17, 2023

Summary

Webpack devServer.hot property can be set to the string only if you don't want an automatic refresh of the page it the update isn't accepted.

https://webpack.js.org/configuration/dev-server/#devserverhot

This PR adds support for that setting in shakapacker.yml.

I tried adding tests, but changing e.g.

verify_command(cmd, argv: (["--https"]))

to verify_command(cmd, argv: (["--nope, not here"])) does not fail the test - it still passes. So I'm not sure how to test it 😅

It does work though - I've verified in my own project.

Pull Request checklist

  • Add/update test to cover these changes
  • Update documentation
  • Update CHANGELOG file

Copy link
Contributor

@G-Rath G-Rath left a comment

Choose a reason for hiding this comment

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

Yeah it looks like those tests are pretty busted - this patch looks to be roughly what's needed to fix them:

Index: spec/shakapacker/dev_server_runner_spec.rb
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/spec/shakapacker/dev_server_runner_spec.rb b/spec/shakapacker/dev_server_runner_spec.rb
--- a/spec/shakapacker/dev_server_runner_spec.rb	(revision 93d92f521c291c20531e1539e4981e77197f35d2)
+++ b/spec/shakapacker/dev_server_runner_spec.rb	(date 1700249852510)
@@ -107,6 +107,38 @@
       end.and_return(dev_server)
     end
 
+    it "supports --hot" do
+      cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--hot"]
+
+      dev_server = double()
+      allow(dev_server).to receive(:host).and_return("localhost")
+      allow(dev_server).to receive(:port).and_return("3035")
+      allow(dev_server).to receive(:protocol).and_return("https")
+      allow(dev_server).to receive(:pretty?).and_return(false)
+      allow(dev_server).to receive(:https?).and_return(false)
+      allow(dev_server).to receive(:hmr?).and_return(true)
+
+      allow(Shakapacker::DevServer).to receive(:new).and_return(dev_server)
+
+      verify_command(cmd, argv: [])
+    end
+
+    it "supports --hot being 'only'" do
+      cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--hot", "only"]
+
+      dev_server = double()
+      allow(dev_server).to receive(:host).and_return("localhost")
+      allow(dev_server).to receive(:port).and_return("3035")
+      allow(dev_server).to receive(:protocol).and_return("https")
+      allow(dev_server).to receive(:pretty?).and_return(false)
+      allow(dev_server).to receive(:https?).and_return(false)
+      allow(dev_server).to receive(:hmr?).and_return("only")
+
+      allow(Shakapacker::DevServer).to receive(:new).and_return(dev_server)
+
+      verify_command(cmd, argv: [])
+    end
+
     it "accepts environment variables" do
       cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]
       env = Shakapacker::Compiler.env.dup

That gets it passing, but it probably means there's some refactoring that could be done to simplify the setup across all the tests.

I think it would be best to fix all the tests in that file in a dedicated PR so this change should be fine to land with or without my patch above

@G-Rath G-Rath mentioned this pull request Nov 17, 2023
3 tasks
@justin808
Copy link
Member

@G-Rath I merged your other chanegs. Please suggest the next steps on this one.

@G-Rath
Copy link
Contributor

G-Rath commented Nov 23, 2023

@SimenB should be able to rebase and add tests now, which should also pretty much be the patch I've written up anyway - also happy to just merge as-is and I can do a new PR adding tests as I know how busy you can get Simen 🙂

@SimenB
Copy link
Contributor Author

SimenB commented Nov 23, 2023

Hey Gareth! 😀

I'm fine to add tests here - this is for work, so easier to prioritize 🙂 Lemme give it a whack. Especially as it's probably just copying on what you wrote down 👍

@SimenB
Copy link
Contributor Author

SimenB commented Nov 23, 2023

Pushed up a test. Just tweaking supports hot module reloading was quick 👍

Copy link
Contributor

@G-Rath G-Rath left a comment

Choose a reason for hiding this comment

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

LGTM!

@justin808
Copy link
Member

@SimenB @ahangarha @G-Rath
Failing rspec on dummy.
Any idea?
https://github.com/shakacode/shakapacker/actions/runs/6966397018/job/19314434626?pr=378

Please ensure that your Gemfiles and .gemspecs are suitably restrictive
to avoid an unexpected breakage when 3.0 is released (e.g. ~> 2.3.0).
See https://github.com/rubyzip/rubyzip for details. The Changelog also
lists other enhancements and bugfixes that have been implemented since
version 2.3.0.
cd '/home/runner/work/shakapacker/shakapacker/spec/dummy' && yalc link shakapacker
Package [email protected] linked ==> /home/runner/work/shakapacker/shakapacker/spec/dummy/node_modules/shakapacker
cd '/home/runner/work/shakapacker/shakapacker/spec/dummy' && yarn install
error This project's package.json defines "packageManager": "[email protected]". However the current global version of Yarn is 1.22.21.

Presence of the "packageManager" field indicates that the project is meant to be used with Corepack, a tool included by default with all official Node.js distributions starting from 16.9 and 14.19.
Corepack must currently be enabled by running corepack enable in your terminal. For more information, check out https://yarnpkg.com/corepack.
rake aborted!
Command failed with status (1): [cd '/home/runner/work/shakapacker/shakapacker/spec/dummy' && yarn install]
/home/runner/work/shakapacker/shakapacker/lib/shakapacker/utils/misc.rb:44:in `block in sh_in_dir'
/home/runner/work/shakapacker/shakapacker/lib/shakapacker/utils/misc.rb:44:in `each'
/home/runner/work/shakapacker/shakapacker/lib/shakapacker/utils/misc.rb:44:in `sh_in_dir'
/home/runner/work/shakapacker/shakapacker/Rakefile:50:in `sh_in_dir'
/home/runner/work/shakapacker/shakapacker/Rakefile:29:in `block (3 levels) in <top (required)>'
/home/runner/work/shakapacker/shakapacker/Rakefile:27:in `block (2 levels) in <top (required)>'
/opt/hostedtoolcache/Ruby/3.1.2/x64/bin/bundle:25:in `load'
/opt/hostedtoolcache/Ruby/3.1.2/x64/bin/bundle:25:in `<main>'
Tasks: TOP => run_spec:dummy
(See full trace by running task with --trace)
Error: Process completed with exit code 1.

@G-Rath
Copy link
Contributor

G-Rath commented Dec 15, 2023

@justin808 I've already fixed that in #383, the branch is just out of date - so it should be fine to be merged in

@SimenB
Copy link
Contributor Author

SimenB commented Dec 15, 2023

I merged in master, so hopefully this is good to go now

@Judahmeek Judahmeek merged commit 0b0e1c7 into shakacode:master Dec 15, 2023
41 checks passed
@Judahmeek
Copy link
Contributor

@SimenB thanks for your contribution! 🌺

@SimenB SimenB deleted the hot-only branch December 15, 2023 20:17
@SimenB SimenB restored the hot-only branch December 15, 2023 20:17
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