webpacker-pnpm 1.2.1 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.gitattributes +0 -0
  3. data/.github/FUNDING.yml +3 -0
  4. data/.github/workflows/ci.yaml +51 -0
  5. data/.gitignore +3 -5
  6. data/.rubocop.yml +23 -5
  7. data/CHANGELOG.md +76 -63
  8. data/Gemfile +8 -8
  9. data/LICENSE +29 -0
  10. data/README.md +44 -37
  11. data/bin/console +15 -15
  12. data/bin/setup +8 -8
  13. data/gemfiles/Gemfile-rails.5.2.x +0 -0
  14. data/gemfiles/Gemfile-rails.6.0.x +0 -0
  15. data/lib/webpacker/pnpm/patches.rb +83 -53
  16. data/lib/webpacker/pnpm/railtie.rb +34 -33
  17. data/lib/webpacker/pnpm/version.rb +9 -9
  18. data/lib/webpacker/pnpm.rb +5 -5
  19. data/lib/webpacker/tasks/check_pnpm.rake +42 -42
  20. data/lib/webpacker/tasks/env.rake +22 -22
  21. data/lib/webpacker/tasks/pnpm_install.rake +14 -14
  22. data/test_app/.gitignore +6 -0
  23. data/test_app/Gemfile +5 -0
  24. data/test_app/Gemfile.lock +175 -0
  25. data/{Rakefile → test_app/Rakefile} +12 -11
  26. data/test_app/app/javascript/packs/application.js +10 -0
  27. data/{test/test_app → test_app}/app/javascript/packs/multi_entry.css +3 -3
  28. data/{test/test_app → test_app}/app/javascript/packs/multi_entry.js +4 -4
  29. data/{test/test_app → test_app}/bin/rails +0 -0
  30. data/{test/test_app → test_app}/bin/rake +0 -0
  31. data/{test/test_app → test_app}/bin/setup +0 -0
  32. data/{test/test_app → test_app}/bin/webpack +15 -15
  33. data/{test/test_app → test_app}/bin/webpack-dev-server +15 -15
  34. data/{test/test_app → test_app}/config/application.rb +13 -13
  35. data/{test/test_app → test_app}/config/boot.rb +5 -5
  36. data/{test/test_app → test_app}/config/environment.rb +6 -6
  37. data/{test/test_app → test_app}/config/webpack/development.js +0 -0
  38. data/{test/test_app → test_app}/config/webpack/environment.js +0 -0
  39. data/test_app/config/webpack/production.js +0 -0
  40. data/{test/test_app → test_app}/config/webpacker.yml +0 -0
  41. data/{test/test_app → test_app}/config/webpacker_public_root.yml +19 -19
  42. data/{test/test_app → test_app}/config.ru +7 -7
  43. data/{test/test_app → test_app}/package.json +3 -1
  44. data/test_app/pnpm-lock.yaml +6756 -0
  45. data/{test/test_app → test_app}/public/packs/manifest.json +31 -31
  46. data/test_app/src/index.js +0 -0
  47. data/{test → test_app/test}/rake_tasks_test.rb +108 -97
  48. data/{test → test_app/test}/test_helper.rb +61 -61
  49. data/webpacker-pnpm.gemspec +44 -44
  50. metadata +41 -59
  51. data/.travis.yml +0 -42
  52. data/test/test_app/.gitignore +0 -7
  53. data/test/test_app/Rakefile +0 -5
  54. data/test/test_app/app/javascript/packs/application.js +0 -10
  55. data/test/test_app/pnpm-lock.yaml +0 -20
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9ccdea9b9cf8d7a874d90f5bb13f6f20f9229bfcc232085f8d48ec4fb657168e
4
- data.tar.gz: bc53eb621ea514efaf2da1891a0e6dcc4c9dad43f217b923ddb479de705b3104
3
+ metadata.gz: 85df72b48e172802a711481f7f54ea75410cde46e7df8a68e2dd8f1772faa711
4
+ data.tar.gz: b82b39eb173396c7bb03b49a934a1e9811d2c82a9d608a7ef00ea33565424dca
5
5
  SHA512:
6
- metadata.gz: c2091d6c417fcaf65e24bb54f8402001f049b7efa5e4d1bde7594a80f0f87fc5d1a97ea6272012042b3ee1f7980244b728c13b5bdc5ead9b1e69af7a3f4de3b4
7
- data.tar.gz: 9932710c5d083577ad15eac9f9086da2355e810e58e84a5d5a4dbda7db9925f14da97c6d6f8c6070f8b33428ede8433ed3a30ddcd2bfd934034b6a32d6d0faff
6
+ metadata.gz: e121ebbbb865ba38282969ea40d278964ebfec79109e9287c90e2d8cc0898ceeef34a58cbc1906d341f032308f7958985183bfc4f0fc73a4a1ed3ffbd061ff3a
7
+ data.tar.gz: 95a7cf3b7e5b59e9db88aeacfedf98590e10cdf288029755925895107e06f6ec402292983533faf1cdd3d2058b870f8254bd8d9e21a9ebe23187e8817edb93a3
data/.gitattributes CHANGED
File without changes
@@ -0,0 +1,3 @@
1
+ # These are supported funding model platforms
2
+
3
+ github: thearchitector
@@ -0,0 +1,51 @@
1
+ name: CI
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ test:
7
+ strategy:
8
+ fail-fast: false
9
+ matrix:
10
+ ruby: [ '2.4', '2.5', '2.6', '2.7' ]
11
+ gemfile: [ '5.2.x', '6.0.x' ]
12
+ exclude:
13
+ - ruby: '2.4'
14
+ gemfile: '6.0.x'
15
+ runs-on: ubuntu-latest
16
+ env:
17
+ BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/Gemfile-rails.${{ matrix.gemfile }}
18
+ steps:
19
+ - uses: actions/checkout@v3
20
+ - name: Setup Ruby
21
+ uses: ruby/setup-ruby@v1
22
+ with:
23
+ ruby-version: ${{ matrix.ruby }}
24
+ bundler-cache: true
25
+ - name: Setup Node
26
+ uses: actions/setup-node@v3
27
+ with:
28
+ node-version: 14
29
+ - name: Setup pnpm
30
+ uses: pnpm/action-setup@v2
31
+ id: pnpm-install
32
+ with:
33
+ version: 7
34
+ run_install: false
35
+ - name: Define pnpm cache
36
+ id: pnpm-cache
37
+ shell: bash
38
+ run: echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
39
+ - uses: actions/cache@v3
40
+ with:
41
+ path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
42
+ key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
43
+ restore-keys: |
44
+ ${{ runner.os }}-pnpm-store-
45
+ - name: Check formatting and syntax
46
+ run: bundle exec rubocop
47
+ - name: Run tests
48
+ working-directory: ./test_app
49
+ run: |
50
+ pnpm i --frozen-lockfile --shamefully-hoist
51
+ bundle exec rake test
data/.gitignore CHANGED
@@ -1,6 +1,4 @@
1
- /tmp/
2
- **/log
1
+ .pnpm-store
2
+
3
3
  Gemfile.lock
4
- **/*.gem
5
- gemfiles/vendor
6
- .bundle
4
+ *.gem
data/.rubocop.yml CHANGED
@@ -1,7 +1,6 @@
1
1
  #
2
- # RuboCop is a Ruby static code analyzer and code formatter that tries to enforce many of
3
- # the guidelines outlined in the community Ruby and Rails
4
- # style guides.
2
+ # RuboCop is a Ruby static code analyzer and code formatter that tries to enforce many
3
+ # of the guidelines outlined in the community Ruby and Rails style guides.
5
4
  #
6
5
  # https://docs.rubocop.org/en/latest/
7
6
  # https://rubystyle.guide/
@@ -15,11 +14,30 @@ inherit_mode:
15
14
  - IgnoredMethods
16
15
  - AllowedMethods
17
16
 
18
- # cop-specific excludes are not inherited for some reason (likely a bug in RuboCop) so we
19
- # need to manually re-omit the intended files and directories.
17
+ # cop-specific excludes are not inherited for some reason (likely a bug in RuboCop) so
18
+ # we need to manually re-omit the intended files and directories.
20
19
  Layout/LineLength:
20
+ Max: 88
21
21
  Exclude:
22
22
  - "**/config/initializers/**/*"
23
23
  Style/MethodCallWithArgsParentheses:
24
24
  Exclude:
25
25
  - "**/Gemfile"
26
+
27
+ # cops to backfill into practical pig
28
+ Performance/AncestorsInclude:
29
+ Enabled: false
30
+ Performance/BigDecimalWithNumericArgument:
31
+ Enabled: true
32
+ Performance/RedundantSortBlock:
33
+ Enabled: true
34
+ Performance/RedundantStringChars:
35
+ Enabled: true
36
+ Performance/ReverseFirst:
37
+ Enabled: true
38
+ Performance/SortReverse:
39
+ Enabled: true
40
+ Performance/Squeeze:
41
+ Enabled: true
42
+ Performance/StringInclude:
43
+ Enabled: true
data/CHANGELOG.md CHANGED
@@ -1,63 +1,76 @@
1
- # Changelog
2
-
3
- All notable changes to this project will be documented in this file.
4
-
5
- The format is based on Keep a Changelog (<https://keepachangelog.com/en/1.0.0/>). This project adheres to Semantic Versioning (<https://semver.org/spec/v2.0.0.html>).
6
-
7
- ## [v1.2.1] - 2020-05-16
8
-
9
- ### Added
10
-
11
- - Informative error messages when pnpm is not installed.
12
- - Pessimistic gem dependency version specifications to avoid installation conflicts.
13
- - Full-length gem description.
14
- - Forced shameful hoisting of installed pnpm dependencies via `webpacker:pnpm_install`.
15
- - Practical Pig development dependency for external RuboCop linting.
16
-
17
- ### Changed
18
-
19
- - Commented and adjusted RuboCop formatting rules to clarify design decisions.
20
-
21
- ### Removed
22
-
23
- - Testing configs for bleeding-edge Rails.
24
-
25
- ## [v1.2.0] - 2020-05-14
26
-
27
- ### Added
28
-
29
- - Compatibility with Rails' Template API via command execution hooks and keyword substitution.
30
- - Support for existing Yarn Rake task dependence through task aliasing and redirection.
31
- - Additional Rake tasks to test injection and interception logic.
32
- - Utility method for concurrent and scoped `chdir` calls.
33
-
34
- ### Changed
35
-
36
- - Gem dependencies to reflect up-to-date versions.
37
- - RuboCop formatting rules to support latest versions of Ruby.
38
- - Test application structure to allow application booting.
39
- - Rake task tests to utilize concurrent `chdir` calls.
40
- - Tests to support Rails <6.x `[bugfix]`.
41
- - Tests to support Ruby 2.4.9 `[bugfix]`.
42
-
43
- ### Removed
44
-
45
- - Webpacker git submodule as method for replacing default Rails' rake tasks.
46
- - Dependence on a specific version of Webpacker.
47
-
48
- ## [v1.1.0] - 2020-04-19
49
-
50
- ### Changed
51
-
52
- - RuboCop formatting rules to more align with Rails' style guide.
53
- - TypeScript installation tasks based on Webpacker v5.1.0.
54
- - Rake tasks to extend ActiveSupport and utilize concurrent threading.
55
-
56
- ## [v1.0.0] - 2020-04-17
57
-
58
- ### Added
59
-
60
- - Gem specifications and foundational files, generated by Bundler v2.0.2, for defining a Ruby gem.
61
- - Hook into Rails' engine loader for conditional task loading.
62
- - Tasks replacing Yarn with pnpm for Webpacker v5.0.1, included as a submodule.
63
- - Test suite with dummy application.
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on Keep a Changelog (<https://keepachangelog.com/en/1.0.0/>). This project adheres to Semantic Versioning (<https://semver.org/spec/v2.0.0.html>).
6
+
7
+ ## [v1.2.3] - 2023-01-14
8
+
9
+ ### Fixed
10
+
11
+ - Actually fixed cross-version watched path compatibility.
12
+ - The previous v1.2.2 fix passed tests due to bad tests. Improved the test suite for real-life usage.
13
+
14
+ ## [v1.2.2] - 2023-01-13
15
+
16
+ ### Fixed
17
+
18
+ - Watched paths for cross-version compatibility. (credit: [HipsterBrown](https://github.com/thearchitector/webpacker-pnpm/pull/4))
19
+
20
+ ## [v1.2.1] - 2020-05-16
21
+
22
+ ### Added
23
+
24
+ - Informative error messages when pnpm is not installed.
25
+ - Pessimistic gem dependency version specifications to avoid installation conflicts.
26
+ - Full-length gem description.
27
+ - Forced shameful hoisting of installed pnpm dependencies via `webpacker:pnpm_install`.
28
+ - Practical Pig development dependency for external RuboCop linting.
29
+
30
+ ### Changed
31
+
32
+ - Commented and adjusted RuboCop formatting rules to clarify design decisions.
33
+
34
+ ### Removed
35
+
36
+ - Testing configs for bleeding-edge Rails.
37
+
38
+ ## [v1.2.0] - 2020-05-14
39
+
40
+ ### Added
41
+
42
+ - Compatibility with Rails' Template API via command execution hooks and keyword substitution.
43
+ - Support for existing Yarn Rake task dependence through task aliasing and redirection.
44
+ - Additional Rake tasks to test injection and interception logic.
45
+ - Utility method for concurrent and scoped `chdir` calls.
46
+
47
+ ### Changed
48
+
49
+ - Gem dependencies to reflect up-to-date versions.
50
+ - RuboCop formatting rules to support latest versions of Ruby.
51
+ - Test application structure to allow application booting.
52
+ - Rake task tests to utilize concurrent `chdir` calls.
53
+ - Tests to support Rails <6.x `[bugfix]`.
54
+ - Tests to support Ruby 2.4.9 `[bugfix]`.
55
+
56
+ ### Removed
57
+
58
+ - Webpacker git submodule as method for replacing default Rails' rake tasks.
59
+ - Dependence on a specific version of Webpacker.
60
+
61
+ ## [v1.1.0] - 2020-04-19
62
+
63
+ ### Changed
64
+
65
+ - RuboCop formatting rules to more align with Rails' style guide.
66
+ - TypeScript installation tasks based on Webpacker v5.1.0.
67
+ - Rake tasks to extend ActiveSupport and utilize concurrent threading.
68
+
69
+ ## [v1.0.0] - 2020-04-17
70
+
71
+ ### Added
72
+
73
+ - Gem specifications and foundational files, generated by Bundler v2.0.2, for defining a Ruby gem.
74
+ - Hook into Rails' engine loader for conditional task loading.
75
+ - Tasks replacing Yarn with pnpm for Webpacker v5.0.1, included as a submodule.
76
+ - Test suite with dummy application.
data/Gemfile CHANGED
@@ -1,8 +1,8 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
- gemspec
5
-
6
- install_if -> { Gem.win_platform? } do
7
- gem "tzinfo-data"
8
- end
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+ gemspec
5
+
6
+ install_if -> { Gem.win_platform? } do
7
+ gem "tzinfo-data"
8
+ end
data/LICENSE ADDED
@@ -0,0 +1,29 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2023, Elias Gabriel
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ 3. Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md CHANGED
@@ -1,37 +1,44 @@
1
- # webpacker-pnpm
2
-
3
- [![version](https://img.shields.io/gem/v/webpacker-pnpm?label=version&style=flat-square)](https://rubygems.org/gems/webpacker-pnpm)
4
- [![status](https://img.shields.io/travis/thearchitector/webpacker-pnpm?style=flat-square)](https://travis-ci.org/github/thearchitector/webpacker-pnpm)
5
- [![downloads](https://img.shields.io/gem/dt/webpacker-pnpm?style=flat-square)](https://rubygems.org/gems/webpacker-pnpm)
6
- [![license](https://img.shields.io/badge/license-CC--BY--NC--SA--4.0-green?style=flat-square)](https://creativecommons.org/licenses/by-nc-sa/4.0/)
7
-
8
- `webpacker-pnpm` replaces Rails' Yarn environment with [pnpm](https://pnpm.js.org/), a better, smarter, and more efficient Node.js package manager. As a result, applications become less prone to dependency hell, more functional, more stable, and more flexible. And as an added bonus, dependency resolution times and `node_modules` folder sizes reduce to within reasonable ranges (not 45 seconds and 10 GiB).
9
-
10
- You can read about the philosophy and technology behind `pnpm` in [this convincing blog post](https://www.kochan.io/nodejs/why-should-we-use-pnpm) by Zoltan Kochan (<https://www.kochan.io/nodejs/why-should-we-use-pnpm>).
11
-
12
- ## Features
13
-
14
- - Production-ready
15
- - Drop-in seamless replacement for Yarn, no config required
16
- - Supports Rails' Template API, including existing templates using Yarn
17
- - Independent of official Webpacker versions
18
- - Provides code sanity without the migraines
19
- - Gives you more disk space
20
-
21
- ## Installation
22
-
23
- In order to use `webpacker-pnpm`, you must install `pnpm`. The official instructions are [here](https://pnpm.js.org/en/installation), but all they say is to run the following command:
24
-
25
- ```sh
26
- $ curl -L https://raw.githubusercontent.com/pnpm/self-installer/master/install.js | node
27
- ```
28
-
29
- After installing `pnpm`, simply add `webpacker-pnpm` to your app's `Gemfile`. There is no need to worry about your official Webpacker gem version, as this gem should be version-agnostic.
30
-
31
- ```ruby
32
- gem "webpacker-pnpm"
33
- ```
34
-
35
- ## License
36
-
37
- This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. To view a copy of this license, visit <http://creativecommons.org/licenses/by-nc-sa/4.0/> or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.
1
+ # webpacker-pnpm
2
+
3
+ [![version](https://img.shields.io/gem/v/webpacker-pnpm?label=version&style=flat-square)](https://rubygems.org/gems/webpacker-pnpm)
4
+ [![status](https://img.shields.io/github/actions/workflow/status/thearchitector/webpacker-pnpm/ci.yaml?label=tests&style=flat-square)](https://travis-ci.org/github/thearchitector/webpacker-pnpm)
5
+ [![downloads](https://img.shields.io/gem/dt/webpacker-pnpm?style=flat-square)](https://rubygems.org/gems/webpacker-pnpm)
6
+ [![license](https://img.shields.io/github/license/thearchitector/webpacker-pnpm?style=flat-square)](LICENSE)
7
+ [![Buy a tree](https://img.shields.io/badge/Treeware-%F0%9F%8C%B3-lightgreen?style=flat-square)](https://ecologi.com/eliasgabriel?r=6128126916bfab8bd051026c)
8
+
9
+ `webpacker-pnpm` replaces Rails' Yarn environment with [pnpm](https://pnpm.io), a better, smarter, and more efficient Node.js package manager. As a result, applications become less prone to dependency hell, more functional, more stable, and more flexible. And as an added bonus, dependency resolution times and `node_modules` folder sizes reduce to within reasonable ranges (not 45 seconds and 10 GiB).
10
+
11
+ You can read about the philosophy and technology behind `pnpm` in [this convincing blog post](https://www.kochan.io/nodejs/why-should-we-use-pnpm) by Zoltan Kochan (<https://www.kochan.io/nodejs/why-should-we-use-pnpm>).
12
+
13
+ ## Features
14
+
15
+ - Production-ready
16
+ - Drop-in replacement for Yarn
17
+ - Supports Rails' Template API, including existing templates using Yarn
18
+ - Provides code sanity without the migraines
19
+ - Gives you more disk space
20
+
21
+ ## Installation
22
+
23
+ In order to use `webpacker-pnpm`, you must install `pnpm`. The official instructions are [here](https://pnpm.io/installation).
24
+
25
+ After installing `pnpm`, first add `webpacker-pnpm` to your app's `Gemfile`.
26
+
27
+ ```ruby
28
+ gem "webpacker-pnpm"
29
+ ```
30
+
31
+ Secondly, add the following line to your `./bin/webpack` so it looks like below (the order matters). This step is required as Webpacker spawns a new process isolated from the Rails server (and thus all auto-loaded patches) when compilation happens live.
32
+
33
+ ```ruby
34
+ require "webpacker/webpack_runner"
35
+ require "webpacker/pnpm/patches" if ENV["RAILS_ENV"] != "production"
36
+ ```
37
+
38
+ > _If you know of an automatic way of achieving a similar result, please open an Issue or PR with your suggestion._
39
+
40
+ ## License
41
+
42
+ This software is licensed under the [BSD 3-Clause License](LICENSE).
43
+
44
+ This package is Treeware. If you use it in production, consider buying the world a tree to thank me for my work. By contributing to my forest, you’ll be creating employment for local families and restoring wildlife habitats.
data/bin/console CHANGED
@@ -1,15 +1,15 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- require "bundler/setup"
5
- require "webpacker/pnpm"
6
-
7
- # You can add fixtures and/or initialization code here to make experimenting
8
- # with your gem easier. You can also use a different console, if you like.
9
-
10
- # (If you use this, don't forget to add pry to your Gemfile!)
11
- # require "pry"
12
- # Pry.start
13
-
14
- require "irb"
15
- IRB.start(__FILE__)
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "webpacker/pnpm"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup CHANGED
@@ -1,8 +1,8 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
File without changes
File without changes
@@ -1,53 +1,83 @@
1
- # frozen_string_literal: true
2
-
3
- require "rails/generators"
4
- require "webpacker/runner"
5
- require "webpacker/compiler"
6
-
7
- module Webpacker
8
- module PNPM
9
- # remove Yarn's lockfile from and add pnpm's lockfile to the default list of
10
- # watched paths
11
- Webpacker::Compiler.class_eval do
12
- def default_watched_paths
13
- [
14
- *config.resolved_paths_globbed,
15
- config.source_path_globbed,
16
- "pnpm-lock.yaml", "package.json",
17
- "config/webpack/**/*"
18
- ].freeze
19
- end
20
- end
21
-
22
- # intercept command execution via Thor to replace yarn with pnpm. this exists in
23
- # order to patch existing Webpacker installation templates that make direct
24
- # calls to install Yarn dependencies. as a result, this isn't a robust patch
25
- Rails::Generators::Actions.module_eval do
26
- def run(command, config = {})
27
- cmd = command.to_s
28
-
29
- if cmd.include?("yarn")
30
- cmd.gsub!("yarn", "pnpm")
31
- cmd.gsub!("--dev", "--save-dev")
32
- end
33
-
34
- super(cmd, config)
35
- end
36
- end
37
-
38
- # intercept generic task loading to clear and alias Yarn tasks
39
- Rails::Engine.class_eval do
40
- alias_method :unfiltered_tasks, :load_tasks
41
-
42
- def load_tasks(_app = self)
43
- unfiltered_tasks
44
- # rather than clear the tasks, alias them to the new pnpm tasks so
45
- # that any external code will still run
46
- Rake::Task["webpacker:check_yarn"].clear.enhance(["webpacker:check_pnpm"])
47
- Rake::Task["webpacker:yarn_install"].clear.enhance(["webpacker:pnpm_install"])
48
- Rake::Task["webpacker:info"].clear.enhance(["webpacker:env"])
49
- Rake::Task["yarn:install"].clear.enhance(["webpacker:pnpm_install"])
50
- end
51
- end
52
- end
53
- end
1
+ # frozen_string_literal: true
2
+
3
+ require "webpacker/compiler"
4
+ require "webpacker/webpack_runner"
5
+ require "rails/generators"
6
+ require "rails/engine"
7
+
8
+ module Webpacker
9
+ module PNPM
10
+ # remove Yarn's lockfile from and add pnpm's lockfile to the default list of
11
+ # watched paths
12
+ Webpacker::Compiler.class_eval do
13
+ def default_watched_paths
14
+ [
15
+ *configured_paths,
16
+ config.source_path_globbed,
17
+ "pnpm-lock.yaml", "package.json",
18
+ "config/webpack/**/*"
19
+ ].freeze
20
+ end
21
+
22
+ def configured_paths
23
+ if config.respond_to?(:additional_paths_globbed)
24
+ config.additional_paths_globbed
25
+ else
26
+ config.resolved_paths_globbed
27
+ end
28
+ end
29
+ end
30
+
31
+ Webpacker::WebpackRunner.class_eval do
32
+ def run
33
+ env = Webpacker::Compiler.env
34
+ env["WEBPACKER_CONFIG"] = @webpacker_config
35
+
36
+ cmd = if node_modules_bin_exist?
37
+ ["#{@node_modules_bin_path}/webpack"]
38
+ else
39
+ ["pnpm", "webpack"]
40
+ end
41
+
42
+ cmd = ["node", "--inspect-brk"] + cmd if @argv.include?("--debug-webpacker")
43
+
44
+ cmd += ["--config", @webpack_config] + @argv
45
+
46
+ Dir.chdir(@app_path) do
47
+ Kernel.exec(env, *cmd)
48
+ end
49
+ end
50
+ end
51
+
52
+ # intercept command execution via Thor to replace yarn with pnpm. this exists in
53
+ # order to patch existing Webpacker installation templates that make direct
54
+ # calls to install Yarn dependencies. as a result, this isn't a robust patch
55
+ Rails::Generators::Actions.module_eval do
56
+ def run(command, config = {})
57
+ cmd = command.to_s
58
+
59
+ if cmd.include?("yarn")
60
+ cmd.gsub!("yarn", "pnpm")
61
+ cmd.gsub!("--dev", "--save-dev")
62
+ end
63
+
64
+ super(cmd, config)
65
+ end
66
+ end
67
+
68
+ # intercept generic task loading to clear and alias Yarn tasks
69
+ Rails::Engine.class_eval do
70
+ alias_method :unfiltered_tasks, :load_tasks
71
+
72
+ def load_tasks(_app = self)
73
+ unfiltered_tasks
74
+ # rather than clear the tasks, alias them to the new pnpm tasks so
75
+ # that any external code will still run
76
+ Rake::Task["webpacker:check_yarn"].clear.enhance(["webpacker:check_pnpm"])
77
+ Rake::Task["webpacker:yarn_install"].clear.enhance(["webpacker:pnpm_install"])
78
+ Rake::Task["webpacker:info"].clear.enhance(["webpacker:env"])
79
+ Rake::Task["yarn:install"].clear.enhance(["webpacker:pnpm_install"])
80
+ end
81
+ end
82
+ end
83
+ end