webpacker-pnpm 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) 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 +50 -0
  5. data/.gitignore +0 -0
  6. data/.rubocop.yml +4 -5
  7. data/CHANGELOG.md +69 -63
  8. data/Gemfile +8 -8
  9. data/LICENSE +29 -0
  10. data/README.md +33 -37
  11. data/Rakefile +11 -11
  12. data/bin/console +15 -15
  13. data/bin/setup +8 -8
  14. data/gemfiles/Gemfile-rails.5.2.x +0 -0
  15. data/gemfiles/Gemfile-rails.6.0.x +0 -0
  16. data/lib/webpacker/pnpm/patches.rb +61 -53
  17. data/lib/webpacker/pnpm/railtie.rb +33 -33
  18. data/lib/webpacker/pnpm/version.rb +9 -9
  19. data/lib/webpacker/pnpm.rb +5 -5
  20. data/lib/webpacker/tasks/check_pnpm.rake +42 -42
  21. data/lib/webpacker/tasks/env.rake +22 -22
  22. data/lib/webpacker/tasks/pnpm_install.rake +14 -14
  23. data/test/rake_tasks_test.rb +97 -97
  24. data/test/test_app/.gitignore +6 -6
  25. data/test/test_app/Rakefile +5 -5
  26. data/test/test_app/app/javascript/packs/application.js +10 -10
  27. data/test/test_app/app/javascript/packs/multi_entry.css +3 -3
  28. data/test/test_app/app/javascript/packs/multi_entry.js +4 -4
  29. data/test/test_app/bin/rails +0 -0
  30. data/test/test_app/bin/rake +0 -0
  31. data/test/test_app/bin/setup +0 -0
  32. data/test/test_app/bin/webpack +15 -15
  33. data/test/test_app/bin/webpack-dev-server +15 -15
  34. data/test/test_app/config/application.rb +13 -13
  35. data/test/test_app/config/boot.rb +5 -5
  36. data/test/test_app/config/environment.rb +6 -6
  37. data/test/test_app/config/webpack/development.js +0 -0
  38. data/test/test_app/config/webpack/environment.js +0 -0
  39. data/test/test_app/config/webpacker.yml +0 -0
  40. data/test/test_app/config/webpacker_public_root.yml +19 -19
  41. data/test/test_app/config.ru +7 -7
  42. data/test/test_app/package.json +0 -0
  43. data/test/test_app/pnpm-lock.yaml +0 -0
  44. data/test/test_app/public/packs/manifest.json +31 -31
  45. data/test/test_helper.rb +61 -61
  46. data/webpacker-pnpm.gemspec +44 -44
  47. metadata +9 -7
  48. data/.travis.yml +0 -42
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9ccdea9b9cf8d7a874d90f5bb13f6f20f9229bfcc232085f8d48ec4fb657168e
4
- data.tar.gz: bc53eb621ea514efaf2da1891a0e6dcc4c9dad43f217b923ddb479de705b3104
3
+ metadata.gz: 5e158c9136e7684be56fce973c9272ec8ab16ff20d6c08c5949e0c9f13f2c0e3
4
+ data.tar.gz: bf02dcac8a0165359548569f6fd73c44decd31a9cd05393d35ae0a81377f7bdf
5
5
  SHA512:
6
- metadata.gz: c2091d6c417fcaf65e24bb54f8402001f049b7efa5e4d1bde7594a80f0f87fc5d1a97ea6272012042b3ee1f7980244b728c13b5bdc5ead9b1e69af7a3f4de3b4
7
- data.tar.gz: 9932710c5d083577ad15eac9f9086da2355e810e58e84a5d5a4dbda7db9925f14da97c6d6f8c6070f8b33428ede8433ed3a30ddcd2bfd934034b6a32d6d0faff
6
+ metadata.gz: '058a4834ac5ff8dd02fdc5dfab8253888500c06d0420dfe1643dab0cfc1cb7e50c3157556c34eb8b71b720f5a97e55b2f712be2f0d1d5a7125924024d0ebe885'
7
+ data.tar.gz: 6ced6827e35f59e42f1f979dbadddb54d2eb54f039c7aff2fc25a0de2b0450c7149fe39c6f7a98abc224fb54245d001443280982f82020e163a00bc362cc0e49
data/.gitattributes CHANGED
File without changes
@@ -0,0 +1,3 @@
1
+ # These are supported funding model platforms
2
+
3
+ github: thearchitector
@@ -0,0 +1,50 @@
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
+ - run: pnpm install --frozen-lockfile
46
+ working-directory: ./test/test_app
47
+ - name: Check formatting and syntax
48
+ run: bundle exec rubocop
49
+ - name: Run tests
50
+ run: bundle exec rake test
data/.gitignore CHANGED
File without changes
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,8 +14,8 @@ 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:
21
20
  Exclude:
22
21
  - "**/config/initializers/**/*"
data/CHANGELOG.md CHANGED
@@ -1,63 +1,69 @@
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.2] - 2023-01-13
8
+
9
+ ### Fixed
10
+
11
+ - Watched paths for cross-version compatibility. (credit: [HipsterBrown](https://github.com/thearchitector/webpacker-pnpm/pull/4))
12
+
13
+ ## [v1.2.1] - 2020-05-16
14
+
15
+ ### Added
16
+
17
+ - Informative error messages when pnpm is not installed.
18
+ - Pessimistic gem dependency version specifications to avoid installation conflicts.
19
+ - Full-length gem description.
20
+ - Forced shameful hoisting of installed pnpm dependencies via `webpacker:pnpm_install`.
21
+ - Practical Pig development dependency for external RuboCop linting.
22
+
23
+ ### Changed
24
+
25
+ - Commented and adjusted RuboCop formatting rules to clarify design decisions.
26
+
27
+ ### Removed
28
+
29
+ - Testing configs for bleeding-edge Rails.
30
+
31
+ ## [v1.2.0] - 2020-05-14
32
+
33
+ ### Added
34
+
35
+ - Compatibility with Rails' Template API via command execution hooks and keyword substitution.
36
+ - Support for existing Yarn Rake task dependence through task aliasing and redirection.
37
+ - Additional Rake tasks to test injection and interception logic.
38
+ - Utility method for concurrent and scoped `chdir` calls.
39
+
40
+ ### Changed
41
+
42
+ - Gem dependencies to reflect up-to-date versions.
43
+ - RuboCop formatting rules to support latest versions of Ruby.
44
+ - Test application structure to allow application booting.
45
+ - Rake task tests to utilize concurrent `chdir` calls.
46
+ - Tests to support Rails <6.x `[bugfix]`.
47
+ - Tests to support Ruby 2.4.9 `[bugfix]`.
48
+
49
+ ### Removed
50
+
51
+ - Webpacker git submodule as method for replacing default Rails' rake tasks.
52
+ - Dependence on a specific version of Webpacker.
53
+
54
+ ## [v1.1.0] - 2020-04-19
55
+
56
+ ### Changed
57
+
58
+ - RuboCop formatting rules to more align with Rails' style guide.
59
+ - TypeScript installation tasks based on Webpacker v5.1.0.
60
+ - Rake tasks to extend ActiveSupport and utilize concurrent threading.
61
+
62
+ ## [v1.0.0] - 2020-04-17
63
+
64
+ ### Added
65
+
66
+ - Gem specifications and foundational files, generated by Bundler v2.0.2, for defining a Ruby gem.
67
+ - Hook into Rails' engine loader for conditional task loading.
68
+ - Tasks replacing Yarn with pnpm for Webpacker v5.0.1, included as a submodule.
69
+ - 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,33 @@
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 seamless replacement for Yarn, no config required
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). After installing `pnpm`, simply add `webpacker-pnpm` to your app's `Gemfile`.
24
+
25
+ ```ruby
26
+ gem "webpacker-pnpm"
27
+ ```
28
+
29
+ ## License
30
+
31
+ This software is licensed under the [BSD 3-Clause License](LICENSE).
32
+
33
+ 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/Rakefile CHANGED
@@ -1,11 +1,11 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/gem_tasks"
4
- require "rake/testtask"
5
-
6
- Rake::TestTask.new do |t|
7
- t.libs << "test"
8
- t.test_files = FileList["test/**/*_test.rb"]
9
- end
10
-
11
- task(default: :test)
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.libs << "test"
8
+ t.test_files = FileList["test/**/*_test.rb"]
9
+ end
10
+
11
+ task(default: :test)
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,61 @@
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 "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
+ *configured_paths,
15
+ config.source_path_globbed,
16
+ "pnpm-lock.yaml", "package.json",
17
+ "config/webpack/**/*"
18
+ ].freeze
19
+ end
20
+
21
+ def configured_paths
22
+ if config.method_defined?(:additional_paths_globbed)
23
+ config.additional_paths_globbed
24
+ else
25
+ config.resolved_paths_globbed
26
+ end
27
+ end
28
+ end
29
+
30
+ # intercept command execution via Thor to replace yarn with pnpm. this exists in
31
+ # order to patch existing Webpacker installation templates that make direct
32
+ # calls to install Yarn dependencies. as a result, this isn't a robust patch
33
+ Rails::Generators::Actions.module_eval do
34
+ def run(command, config = {})
35
+ cmd = command.to_s
36
+
37
+ if cmd.include?("yarn")
38
+ cmd.gsub!("yarn", "pnpm")
39
+ cmd.gsub!("--dev", "--save-dev")
40
+ end
41
+
42
+ super(cmd, config)
43
+ end
44
+ end
45
+
46
+ # intercept generic task loading to clear and alias Yarn tasks
47
+ Rails::Engine.class_eval do
48
+ alias_method :unfiltered_tasks, :load_tasks
49
+
50
+ def load_tasks(_app = self)
51
+ unfiltered_tasks
52
+ # rather than clear the tasks, alias them to the new pnpm tasks so
53
+ # that any external code will still run
54
+ Rake::Task["webpacker:check_yarn"].clear.enhance(["webpacker:check_pnpm"])
55
+ Rake::Task["webpacker:yarn_install"].clear.enhance(["webpacker:pnpm_install"])
56
+ Rake::Task["webpacker:info"].clear.enhance(["webpacker:env"])
57
+ Rake::Task["yarn:install"].clear.enhance(["webpacker:pnpm_install"])
58
+ end
59
+ end
60
+ end
61
+ end
@@ -1,33 +1,33 @@
1
- # frozen_string_literal: true
2
-
3
- require "rails/railtie"
4
-
5
- module Webpacker
6
- module PNPM
7
- class Railtie < Rails::Railtie
8
- rake_tasks do
9
- # load all the rake tasks within the `tasks` directory
10
- Dir[File.join(File.dirname(__FILE__), "../tasks/**/*.rake")].each do |task|
11
- load task
12
- end
13
- end
14
-
15
- # manually specify node_modules bin path to skip Yarn execution during
16
- # Webpack runner initialization
17
- config.before_configuration do
18
- begin
19
- ENV["WEBPACKER_NODE_MODULES_BIN_PATH"] ||= File.join(`pnpm root`.chomp, ".bin")
20
- rescue Errno::ENOENT
21
- # use abort instead of Rails' logger because it doesn't show up when
22
- # run within Rake tasks
23
- abort(
24
- <<~HEREDOC.squish
25
- \e[31m[FATAL] pnpm is not installed or not present in $PATH.
26
- Install pnpm and try again.\e[0m
27
- HEREDOC
28
- )
29
- end
30
- end
31
- end
32
- end
33
- end
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/railtie"
4
+
5
+ module Webpacker
6
+ module PNPM
7
+ class Railtie < Rails::Railtie
8
+ rake_tasks do
9
+ # load all the rake tasks within the `tasks` directory
10
+ Dir[File.join(File.dirname(__FILE__), "../tasks/**/*.rake")].each do |task|
11
+ load task
12
+ end
13
+ end
14
+
15
+ # manually specify node_modules bin path to skip Yarn execution during
16
+ # Webpack runner initialization
17
+ config.before_configuration do
18
+ begin
19
+ ENV["WEBPACKER_NODE_MODULES_BIN_PATH"] ||= File.join(`pnpm root`.chomp, ".bin")
20
+ rescue Errno::ENOENT
21
+ # use abort instead of Rails' logger because it doesn't show up when
22
+ # run within Rake tasks
23
+ abort(
24
+ <<~HEREDOC.squish
25
+ \e[31m[FATAL] pnpm is not installed or not present in $PATH.
26
+ Install pnpm and try again.\e[0m
27
+ HEREDOC
28
+ )
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -1,9 +1,9 @@
1
- # frozen_string_literal: true
2
-
3
- module Webpacker
4
- module PNPM
5
- VERSION = "1.2.1"
6
-
7
- public_constant :VERSION
8
- end
9
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Webpacker
4
+ module PNPM
5
+ VERSION = "1.2.2"
6
+
7
+ public_constant :VERSION
8
+ end
9
+ end
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "pnpm/version"
4
- require_relative "pnpm/railtie"
5
- require_relative "pnpm/patches"
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "pnpm/version"
4
+ require_relative "pnpm/railtie"
5
+ require_relative "pnpm/patches"