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

Convert to all peer dependencies #3234

Closed
Closed
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ environment.loaders.append('nodeModules', nodeModules)
- Adds experimental Yarn 2 support. Note you must manually set `nodeLinker: node-modules` in your `.yarnrc.yml`.
- Fixes dev server issues [#2898](https://github.com/rails/webpacker/pull/2898)
- Update static files path to from `media/` to `static/`.
- Changed all package.json dependencies to peerDependencies, so upgrading requires adding the dependencies, per the [UPGRADE GUIDE](./docs/v6_upgrade.md).

### Breaking changes
- Removed integration installers
Expand Down
10 changes: 10 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,13 @@ bundle exec rake test TEST=test/rake_tasks_test.rb
```
ruby -I test test/rake_tasks_test.rb -n test_rake_webpacker_install
```

# Testing the generator
If you change the generator, check that install instructions work.

1. Update the gemfile so that gem "webpacker" has a line like this, pointing to your install of webpacker
```ruby
gem 'webpacker', path: "~/shakacode/forks/webpacker"
```
2. `bundle`
3. Run the generator confirm that you got the right changes.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,17 @@ When `package.json` and/or `yarn.lock` changes, such as when pulling down change
yarn install
```

Note, in v6, most JS packages are peer dependencies. Thus, the installer will add the packages:

```bash
yarn add @babel/core @babel/plugin-transform-runtime @babel/preset-env @babel/runtime babel-loader \
compression-webpack-plugin pnp-webpack-plugin terser-webpack-plugin \
webpack webpack-assets-manifest webpack-cli webpack-merge webpack-sources webpack-dev-server
```

Previously, these "webpack" and "babel" packages were direct dependencies for `@rails/webpacker`. By
making these peer dependencies, you have control over the versions used in your webpack and babel configs.

### Usage

Once installed, you can start writing modern ES6-flavored JavaScript apps right away:
Expand Down
12 changes: 10 additions & 2 deletions docs/v6_upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,28 @@ Example going to a specific version:

```ruby
# Gemfile
gem 'webpacker', '6.0.0.rc.5'
gem 'webpacker', '6.0.0.rc.6'
```

```bash
bundle install
```

```bash
yarn add @rails/[email protected].5 --exact
yarn add @rails/[email protected].6 --exact
```

```bash
bundle exec rails webpacker:install
```

Overwrite all files and check what changed.


Note, the webpacker:install will install the peer dependencies:
```bash
yarn add @babel/core @babel/plugin-transform-runtime @babel/preset-env @babel/runtime babel-loader compression-webpack-plugin pnp-webpack-plugin terser-webpack-plugin webpack webpack-assets-manifest webpack-cli webpack-merge webpack-sources webpack-dev-server
```

7. Update API usage of the view helpers by changing `javascript_packs_with_chunks_tag` and `stylesheet_packs_with_chunks_tag` to `javascript_pack_tag` and `stylesheet_pack_tag`. Ensure that your layouts and views will only have **at most one call** to `javascript_pack_tag` and **at most one call** to `stylesheet_pack_tag`. You can now pass multiple bundles to these view helper methods. If you fail to changes this, you may experience performance issues, and other bugs related to multiple copies of React, like [issue 2932](https://github.com/rails/webpacker/issues/2932). If you expose jquery globally with `expose-loader,` by using `import $ from "expose-loader?exposes=$,jQuery!jquery"` in your `app/javascript/application.js`, pass the option `defer: false` to your `javascript_pack_tag`.

Expand Down
20 changes: 11 additions & 9 deletions lib/install/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,25 @@

Dir.chdir(Rails.root) do
if Webpacker::VERSION.match?(/^[0-9]+\.[0-9]+\.[0-9]+$/)
say "Installing all JavaScript dependencies [#{Webpacker::VERSION}]"
say "Installing @rails/webpacker@#{Webpacker::VERSION}"
results << run("yarn add @rails/webpacker@#{Webpacker::VERSION}")
else
say "Installing all JavaScript dependencies [from prerelease rails/webpacker]"
say "Installing @rails/webpacker@next"
results << run("yarn add @rails/webpacker@next")
end

package_json = File.read("#{__dir__}/../../package.json")
webpack_version = package_json.match(/"webpack": "(.*)"/)[1]
webpack_cli_version = package_json.match(/"webpack-cli": "(.*)"/)[1]
peers = JSON.parse(package_json)["peerDependencies"]
peers_to_add = peers.reduce([]) do |result, (package, version)|
major_version = version.match(/(\d+)/)[1]
result << "#{package}@#{major_version}"
end.join(" ")

# needed for experimental Yarn 2 support and should not harm Yarn 1
say "Installing webpack and webpack-cli as direct dependencies"
results << run("yarn add webpack@#{webpack_version} webpack-cli@#{webpack_cli_version}")
say "Adding @rails/webpacker peerDependencies"
results << run("yarn add #{peers_to_add}")

say "Installing dev server for live reloading"
results << run("yarn add --dev webpack-dev-server @webpack-cli/serve")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@webpack-cli/serve should not be directly installed per docs.

say "Installing webpack-dev-server for live reloading as a development dependency"
results << run("yarn add --dev webpack-dev-server")
end

if Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR > 1
Expand Down
21 changes: 14 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,39 @@
"node": ">= 12.13.0 || >=14",
"yarn": ">=1 <4"
},
"dependencies": {
"peerDependencies": {
"@babel/core": "^7.15.5",
"@babel/plugin-transform-runtime": "^7.15.0",
"@babel/preset-env": "^7.15.6",
"@babel/runtime": "^7.15.4",
"babel-loader": "^8.2.2",
"compression-webpack-plugin": "^9.0.0",
"glob": "^7.2.0",
"js-yaml": "^4.1.0",
"path-complete-extname": "^1.0.0",
"pnp-webpack-plugin": "^1.7.0",
"terser-webpack-plugin": "^5.2.4",
"webpack": "^5.53.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we can leave these as regular dependencies.

  1. glob
  2. js-yaml
  3. path-complete-extname

For sure, anything with the name webpack or babel in it should be a peer.

"webpack-assets-manifest": "^5.0.6",
"webpack-cli": "^4.8.0",
"webpack-merge": "^5.8.0",
"webpack-sources": "^3.2.1"
"webpack-merge": "^5.8.0"
},
"dependencies": {
"glob": "^7.2.0",
"js-yaml": "^4.1.0",
"path-complete-extname": "^1.0.0"
},
"devDependencies": {
"babel-loader": "^8.2.2",
"compression-webpack-plugin": "^9.0.0",
"eslint": "^7.32.0",
"eslint-config-airbnb": "^18.2.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.24.2",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-react": "^7.26.0",
"jest": "^27.2.1"
"jest": "^27.2.1",
"pnp-webpack-plugin": "^1.7.0",
"webpack": "^5.53.0",
"webpack-assets-manifest": "^5.0.6",
"webpack-merge": "^5.8.0"
},
"jest": {
"testRegex": "(/__tests__/.*|(\\.|/))\\.jsx?$",
Expand Down
Loading