From a126be80514b77133aa5aeed66a233239ed847d7 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Sat, 12 Aug 2023 15:48:03 +1200 Subject: [PATCH 1/9] feat: use `package_json` for interacting with `package.json` --- .github/workflows/ruby.yml | 2 ++ Gemfile | 3 +++ Gemfile.lock | 12 +++++----- Rakefile | 27 +++++++++++++---------- lib/generators/react/install_generator.rb | 14 +++++++++++- 5 files changed, 40 insertions(+), 18 deletions(-) diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 1b9039467..8e2b3fc32 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -20,6 +20,8 @@ jobs: matrix: ruby: [2.7] runs-on: ubuntu-latest + env: + PACKAGE_JSON_FALLBACK_MANAGER: yarn_classic steps: - uses: actions/checkout@v4 with: diff --git a/Gemfile b/Gemfile index 8926579c4..595301235 100644 --- a/Gemfile +++ b/Gemfile @@ -3,4 +3,7 @@ source "http://rubygems.org" gemspec + +gem "package_json", github: "G-Rath/package_json" + # This is an optional dev-dependency, required whenever sprockets is required diff --git a/Gemfile.lock b/Gemfile.lock index 164b2b8ff..beaa7f707 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,9 @@ +GIT + remote: https://github.com/G-Rath/package_json.git + revision: d48f2c0db14bb1305f249fffb52fd2e0065678ee + specs: + package_json (0.1.0) + PATH remote: . specs: @@ -102,12 +108,8 @@ GEM matrix (0.4.2) method_source (1.0.0) mini_mime (1.0.2) - mini_portile2 (2.8.4) minitest (5.17.0) nenv (0.3.0) - nokogiri (1.14.3) - mini_portile2 (~> 2.8.0) - racc (~> 1.4) nokogiri (1.14.3-x86_64-darwin) racc (~> 1.4) nokogiri (1.14.3-x86_64-linux) @@ -166,7 +168,6 @@ GEM zeitwerk (2.6.6) PLATFORMS - ruby x86_64-darwin-20 x86_64-linux @@ -182,6 +183,7 @@ DEPENDENCIES guard-minitest jbuilder listen (~> 3.0.0) + package_json! pry-byebug react-rails! selenium-webdriver diff --git a/Rakefile b/Rakefile index 76112a049..c29ab8c92 100644 --- a/Rakefile +++ b/Rakefile @@ -14,25 +14,22 @@ def copy_react_asset(webpack_file, destination_file) FileUtils.cp(full_webpack_path, full_destination_path) end -# Move to `dirname` and execute `yarn {cmd}` -def yarn_run_in(dirname, cmd) - Dir.chdir(dirname) do - `yarn #{cmd}` - end -end - namespace :react do desc "Run the JS build process to put files in the gem source" task update: %i[install build copy] desc "Install the JavaScript dependencies" task :install do - yarn_run_in("react-builds", "install") + require "package_json" + + PackageJson.read("react-builds").manager.install end desc "Build the JS bundles with Webpack" task :build do - yarn_run_in("react-builds", "build") + require "package_json" + + PackageJson.read("react-builds").manager.run("build") end desc "Copy browser-ready JS files to the gem's asset paths" @@ -51,12 +48,16 @@ namespace :ujs do desc "Install the JavaScript dependencies" task :install do - `yarn install` + require "package_json" + + PackageJson.read.manager.install end desc "Build the JS bundles with Webpack" task :build do - `yarn build` + require "package_json" + + PackageJson.read.manager.run("build") end desc "Copy browser-ready JS files to the gem's asset paths" @@ -87,7 +88,9 @@ task default: :test task :test_setup do Dir.chdir("./test/dummy") do - `yarn install` + require "package_json" + + PackageJson.read.manager.install end end diff --git a/lib/generators/react/install_generator.rb b/lib/generators/react/install_generator.rb index a64320bfe..7af4f61a5 100644 --- a/lib/generators/react/install_generator.rb +++ b/lib/generators/react/install_generator.rb @@ -103,8 +103,20 @@ def setup_react_sprockets ReactRailsUJS.useContext(componentRequireContext); JS + # TODO: replace with standard "require" call once gem is published + def require_package_json_gem + require "bundler/inline" + + gemfile { gem "package_json", github: "G-Rath/package_json" } + + puts "using package_json v#{PackageJson::VERSION}" + end + def setup_react_shakapacker - `yarn add react_ujs` + require_package_json_gem + + PackageJson.read.manager.add(["react_ujs"]) + if manifest.exist? append_file(manifest, SHAKAPACKER_SETUP_UJS) else From d6bdc579bb34639c3b5bac571670d7eeac560211 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Sun, 20 Aug 2023 08:51:34 +1200 Subject: [PATCH 2/9] fix: try this --- Rakefile | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Rakefile b/Rakefile index c29ab8c92..ffb771562 100644 --- a/Rakefile +++ b/Rakefile @@ -8,6 +8,14 @@ end Bundler::GemHelper.install_tasks +def require_package_json_gem + require "bundler/inline" + + gemfile { gem "package_json", github: "G-Rath/package_json" } + + puts "using package_json v#{PackageJson::VERSION}" +end + def copy_react_asset(webpack_file, destination_file) full_webpack_path = File.expand_path("../react-builds/build/#{webpack_file}", __FILE__) full_destination_path = File.expand_path("../lib/assets/react-source/#{destination_file}", __FILE__) @@ -20,14 +28,14 @@ namespace :react do desc "Install the JavaScript dependencies" task :install do - require "package_json" + require_package_json_gem PackageJson.read("react-builds").manager.install end desc "Build the JS bundles with Webpack" task :build do - require "package_json" + require_package_json_gem PackageJson.read("react-builds").manager.run("build") end @@ -48,14 +56,14 @@ namespace :ujs do desc "Install the JavaScript dependencies" task :install do - require "package_json" + require_package_json_gem PackageJson.read.manager.install end desc "Build the JS bundles with Webpack" task :build do - require "package_json" + require_package_json_gem PackageJson.read.manager.run("build") end @@ -88,7 +96,7 @@ task default: :test task :test_setup do Dir.chdir("./test/dummy") do - require "package_json" + require_package_json_gem PackageJson.read.manager.install end From 5374d6a2389da8555f7d8b9788487816f57c7906 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Sun, 20 Aug 2023 09:04:47 +1200 Subject: [PATCH 3/9] ci: test against the different package managers --- .github/workflows/ruby.yml | 13 +++++++-- test/bin/create-fake-js-package-managers | 36 ++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100755 test/bin/create-fake-js-package-managers diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 8e2b3fc32..c6cf591dd 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -58,6 +58,13 @@ jobs: strategy: fail-fast: false matrix: + js_package_manager: + - name: npm + installer: npm + - name: yarn_classic + installer: yarn + - name: pnpm + installer: pnpm ruby: [2.7] gemfile: # These have shakapacker: @@ -73,12 +80,13 @@ jobs: # Workaround b/c upgrading Minitest broke some mocking expectations # having to do with automatic kwarg splatting MT_KWARGS_HACK: 1 + PACKAGE_JSON_FALLBACK_MANAGER: ${{ matrix.js_package_manager.name }} steps: - uses: actions/checkout@v4 with: persist-credentials: false - uses: actions/setup-node@v3 - - run: npm -g install yalc + - run: npm -g install yalc ${{ matrix.js_package_manager.installer }} - run: yalc publish - name: Save root node_modules to cache uses: actions/cache@v3 @@ -94,6 +102,7 @@ jobs: with: bundler: 2.4.9 ruby-version: ${{ matrix.ruby }} + - run: ./test/bin/create-fake-js-package-managers ${{ matrix.js_package_manager.installer }} - name: Save dummy app ruby gems to cache uses: actions/cache@v3 with: @@ -101,7 +110,7 @@ jobs: key: dummy-app-gem-cache-${{ hashFiles('${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile.lock') }} - name: Install Ruby Gems for dummy app run: bundle lock --add-platform 'x86_64-linux' && bundle check --path=test/dummy/vendor/bundle || bundle _2.4.9_ install --frozen --path=test/dummy/vendor/bundle --jobs=4 --retry=3 - - run: cd test/dummy && yalc add react_ujs && yarn + - run: cd test/dummy && yalc add react_ujs && ${{ matrix.js_package_manager.installer }} install - run: bundle exec rake test env: NODE_OPTIONS: --openssl-legacy-provider diff --git a/test/bin/create-fake-js-package-managers b/test/bin/create-fake-js-package-managers new file mode 100755 index 000000000..cb3c361fc --- /dev/null +++ b/test/bin/create-fake-js-package-managers @@ -0,0 +1,36 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# creates a set of fake JavaScript package managers in a temporary bin +# directory for GitHub Actions, _excluding_ the one passed in as an +# argument in order to assert that only that package manager is used + +require "tmpdir" + +# setup the bin directory we want to use +bin_dir = Dir.mktmpdir("react-rails-") + +if ENV["GITHUB_ACTIONS"] + puts "adding #{bin_dir} to GITHUB_PATH..." + File.write(ENV.fetch("GITHUB_PATH"), "#{bin_dir}\n", mode: "a+") +end + +managers = %w[npm yarn pnpm] +manager_in_use = ARGV[0] + +Dir.chdir(bin_dir) do + managers.each do |manager| + next if manager == manager_in_use + + puts "creating #{bin_dir}/#{manager}..." + File.write( + manager, + <<~CONTENTS + #!/usr/bin/env node + + throw new Error("(#{manager}) this is not the package manager you're looking..."); + CONTENTS + ) + File.chmod(0o755, manager) + end +end From 1ccd2ff61ae27dbf5b04d0349bc00ed14dd7f0ff Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Sun, 20 Aug 2023 09:18:27 +1200 Subject: [PATCH 4/9] fix: pull in fork of shakapacker --- .github/workflows/ruby.yml | 1 + Appraisals | 2 +- gemfiles/base.gemfile | 1 + gemfiles/base.gemfile.lock | 7 +++++++ gemfiles/shakapacker.gemfile | 3 ++- gemfiles/shakapacker.gemfile.lock | 25 +++++++++++++++++++------ gemfiles/sprockets_3.gemfile | 1 + gemfiles/sprockets_3.gemfile.lock | 7 +++++++ gemfiles/sprockets_4.gemfile | 1 + gemfiles/sprockets_4.gemfile.lock | 7 +++++++ 10 files changed, 47 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index c6cf591dd..3abc001d5 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -81,6 +81,7 @@ jobs: # having to do with automatic kwarg splatting MT_KWARGS_HACK: 1 PACKAGE_JSON_FALLBACK_MANAGER: ${{ matrix.js_package_manager.name }} + SHAKAPACKER_USE_PACKAGE_JSON_GEM: true steps: - uses: actions/checkout@v4 with: diff --git a/Appraisals b/Appraisals index a28c31403..afbe6dd11 100644 --- a/Appraisals +++ b/Appraisals @@ -16,7 +16,7 @@ end appraise 'shakapacker' do gem 'rails', '~> 7.0.x' - gem 'shakapacker', '7.0.2' + gem 'shakapacker', github: 'G-Rath/shakapacker', branch: 'use-package_json' end appraise 'base' do diff --git a/gemfiles/base.gemfile b/gemfiles/base.gemfile index dbd7ec2d2..9a4f7da50 100644 --- a/gemfiles/base.gemfile +++ b/gemfiles/base.gemfile @@ -2,6 +2,7 @@ source "http://rubygems.org" +gem "package_json", github: "G-Rath/package_json" gem "rails", "~> 7.0.x" gemspec path: "../" diff --git a/gemfiles/base.gemfile.lock b/gemfiles/base.gemfile.lock index 3fd3b9201..91ebc1b94 100644 --- a/gemfiles/base.gemfile.lock +++ b/gemfiles/base.gemfile.lock @@ -1,3 +1,9 @@ +GIT + remote: https://github.com/G-Rath/package_json.git + revision: d48f2c0db14bb1305f249fffb52fd2e0065678ee + specs: + package_json (0.1.0) + PATH remote: .. specs: @@ -258,6 +264,7 @@ DEPENDENCIES guard-minitest jbuilder listen (~> 3.0.0) + package_json! pry-byebug rails (~> 7.0.x) react-rails! diff --git a/gemfiles/shakapacker.gemfile b/gemfiles/shakapacker.gemfile index 86c2338d1..96009bbd3 100644 --- a/gemfiles/shakapacker.gemfile +++ b/gemfiles/shakapacker.gemfile @@ -2,7 +2,8 @@ source "http://rubygems.org" +gem "package_json", github: "G-Rath/package_json" gem "rails", "~> 7.0.x" -gem "shakapacker", "7.0.2" +gem "shakapacker", github: "G-Rath/shakapacker", branch: "use-package_json" gemspec path: "../" diff --git a/gemfiles/shakapacker.gemfile.lock b/gemfiles/shakapacker.gemfile.lock index 4fb41f942..abf426118 100644 --- a/gemfiles/shakapacker.gemfile.lock +++ b/gemfiles/shakapacker.gemfile.lock @@ -1,3 +1,20 @@ +GIT + remote: https://github.com/G-Rath/package_json.git + revision: d48f2c0db14bb1305f249fffb52fd2e0065678ee + specs: + package_json (0.1.0) + +GIT + remote: https://github.com/G-Rath/shakapacker.git + revision: 8e9db60edd13429bdae9783d7f37bac70470870c + branch: use-package_json + specs: + shakapacker (7.0.3) + activesupport (>= 5.2) + rack-proxy (>= 0.6.1) + railties (>= 5.2) + semantic_range (>= 2.3.0) + PATH remote: .. specs: @@ -227,11 +244,6 @@ GEM rubyzip (>= 1.2.2, < 3.0) websocket (~> 1.0) semantic_range (3.0.0) - shakapacker (7.0.2) - activesupport (>= 5.2) - rack-proxy (>= 0.6.1) - railties (>= 5.2) - semantic_range (>= 2.3.0) shellany (0.0.1) simplecov (0.13.0) docile (~> 1.1.0) @@ -268,11 +280,12 @@ DEPENDENCIES guard-minitest jbuilder listen (~> 3.0.0) + package_json! pry-byebug rails (~> 7.0.x) react-rails! selenium-webdriver - shakapacker (= 7.0.2) + shakapacker! test-unit (~> 2.5) BUNDLED WITH diff --git a/gemfiles/sprockets_3.gemfile b/gemfiles/sprockets_3.gemfile index ca312487d..7f7f28621 100644 --- a/gemfiles/sprockets_3.gemfile +++ b/gemfiles/sprockets_3.gemfile @@ -2,6 +2,7 @@ source "http://rubygems.org" +gem "package_json", github: "G-Rath/package_json" gem "rails", "~> 7.0.x" gem "sprockets", "~> 3.5" gem "sprockets-rails" diff --git a/gemfiles/sprockets_3.gemfile.lock b/gemfiles/sprockets_3.gemfile.lock index 8e044462c..d45fd7d7b 100644 --- a/gemfiles/sprockets_3.gemfile.lock +++ b/gemfiles/sprockets_3.gemfile.lock @@ -1,3 +1,9 @@ +GIT + remote: https://github.com/G-Rath/package_json.git + revision: d48f2c0db14bb1305f249fffb52fd2e0065678ee + specs: + package_json (0.1.0) + PATH remote: .. specs: @@ -270,6 +276,7 @@ DEPENDENCIES jbuilder listen (~> 3.0.0) mini_racer + package_json! pry-byebug rails (~> 7.0.x) react-rails! diff --git a/gemfiles/sprockets_4.gemfile b/gemfiles/sprockets_4.gemfile index 245032a24..a8b163a50 100644 --- a/gemfiles/sprockets_4.gemfile +++ b/gemfiles/sprockets_4.gemfile @@ -2,6 +2,7 @@ source "http://rubygems.org" +gem "package_json", github: "G-Rath/package_json" gem "rails", "~> 7.0.x" gem "sprockets", "~> 4.0.x" gem "sprockets-rails" diff --git a/gemfiles/sprockets_4.gemfile.lock b/gemfiles/sprockets_4.gemfile.lock index 815347067..a34231649 100644 --- a/gemfiles/sprockets_4.gemfile.lock +++ b/gemfiles/sprockets_4.gemfile.lock @@ -1,3 +1,9 @@ +GIT + remote: https://github.com/G-Rath/package_json.git + revision: d48f2c0db14bb1305f249fffb52fd2e0065678ee + specs: + package_json (0.1.0) + PATH remote: .. specs: @@ -270,6 +276,7 @@ DEPENDENCIES jbuilder listen (~> 3.0.0) mini_racer + package_json! pry-byebug rails (~> 7.0.x) react-rails! From 8c4e9c9ad7907e3f9e5620b9f9b2f0ffde809d65 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Fri, 15 Sep 2023 14:17:46 +1200 Subject: [PATCH 5/9] feat: support bun --- .github/workflows/ruby.yml | 2 ++ Gemfile | 2 +- Gemfile.lock | 3 ++- Rakefile | 2 +- gemfiles/base.gemfile | 2 +- gemfiles/base.gemfile.lock | 3 ++- gemfiles/shakapacker.gemfile | 2 +- gemfiles/shakapacker.gemfile.lock | 3 ++- gemfiles/sprockets_3.gemfile | 2 +- gemfiles/sprockets_3.gemfile.lock | 3 ++- gemfiles/sprockets_4.gemfile | 2 +- gemfiles/sprockets_4.gemfile.lock | 3 ++- lib/generators/react/install_generator.rb | 2 +- test/bin/create-fake-js-package-managers | 2 +- 14 files changed, 20 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 3abc001d5..23d3f4c35 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -65,6 +65,8 @@ jobs: installer: yarn - name: pnpm installer: pnpm + - name: bun + installer: bun ruby: [2.7] gemfile: # These have shakapacker: diff --git a/Gemfile b/Gemfile index 595301235..02b670654 100644 --- a/Gemfile +++ b/Gemfile @@ -4,6 +4,6 @@ source "http://rubygems.org" gemspec -gem "package_json", github: "G-Rath/package_json" +gem "package_json", github: "G-Rath/package_json", branch: "add-bun-support" # This is an optional dev-dependency, required whenever sprockets is required diff --git a/Gemfile.lock b/Gemfile.lock index beaa7f707..3d1c4aff3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,7 @@ GIT remote: https://github.com/G-Rath/package_json.git - revision: d48f2c0db14bb1305f249fffb52fd2e0065678ee + revision: 72e742afb7ea8c19369fa9a4ce0d74ce098e2678 + branch: add-bun-support specs: package_json (0.1.0) diff --git a/Rakefile b/Rakefile index ffb771562..12b65ac18 100644 --- a/Rakefile +++ b/Rakefile @@ -11,7 +11,7 @@ Bundler::GemHelper.install_tasks def require_package_json_gem require "bundler/inline" - gemfile { gem "package_json", github: "G-Rath/package_json" } + gemfile { gem "package_json", github: "G-Rath/package_json", branch: "add-bun-support" } puts "using package_json v#{PackageJson::VERSION}" end diff --git a/gemfiles/base.gemfile b/gemfiles/base.gemfile index 9a4f7da50..e7513b5d3 100644 --- a/gemfiles/base.gemfile +++ b/gemfiles/base.gemfile @@ -2,7 +2,7 @@ source "http://rubygems.org" -gem "package_json", github: "G-Rath/package_json" +gem "package_json", github: "G-Rath/package_json", branch: "add-bun-support" gem "rails", "~> 7.0.x" gemspec path: "../" diff --git a/gemfiles/base.gemfile.lock b/gemfiles/base.gemfile.lock index 91ebc1b94..58e7fca9e 100644 --- a/gemfiles/base.gemfile.lock +++ b/gemfiles/base.gemfile.lock @@ -1,6 +1,7 @@ GIT remote: https://github.com/G-Rath/package_json.git - revision: d48f2c0db14bb1305f249fffb52fd2e0065678ee + revision: 72e742afb7ea8c19369fa9a4ce0d74ce098e2678 + branch: add-bun-support specs: package_json (0.1.0) diff --git a/gemfiles/shakapacker.gemfile b/gemfiles/shakapacker.gemfile index 96009bbd3..382d4b684 100644 --- a/gemfiles/shakapacker.gemfile +++ b/gemfiles/shakapacker.gemfile @@ -2,7 +2,7 @@ source "http://rubygems.org" -gem "package_json", github: "G-Rath/package_json" +gem "package_json", github: "G-Rath/package_json", branch: "add-bun-support" gem "rails", "~> 7.0.x" gem "shakapacker", github: "G-Rath/shakapacker", branch: "use-package_json" diff --git a/gemfiles/shakapacker.gemfile.lock b/gemfiles/shakapacker.gemfile.lock index abf426118..fed71ed0f 100644 --- a/gemfiles/shakapacker.gemfile.lock +++ b/gemfiles/shakapacker.gemfile.lock @@ -1,6 +1,7 @@ GIT remote: https://github.com/G-Rath/package_json.git - revision: d48f2c0db14bb1305f249fffb52fd2e0065678ee + revision: 72e742afb7ea8c19369fa9a4ce0d74ce098e2678 + branch: add-bun-support specs: package_json (0.1.0) diff --git a/gemfiles/sprockets_3.gemfile b/gemfiles/sprockets_3.gemfile index 7f7f28621..52aaf1e71 100644 --- a/gemfiles/sprockets_3.gemfile +++ b/gemfiles/sprockets_3.gemfile @@ -2,7 +2,7 @@ source "http://rubygems.org" -gem "package_json", github: "G-Rath/package_json" +gem "package_json", github: "G-Rath/package_json", branch: "add-bun-support" gem "rails", "~> 7.0.x" gem "sprockets", "~> 3.5" gem "sprockets-rails" diff --git a/gemfiles/sprockets_3.gemfile.lock b/gemfiles/sprockets_3.gemfile.lock index d45fd7d7b..ccfd9165c 100644 --- a/gemfiles/sprockets_3.gemfile.lock +++ b/gemfiles/sprockets_3.gemfile.lock @@ -1,6 +1,7 @@ GIT remote: https://github.com/G-Rath/package_json.git - revision: d48f2c0db14bb1305f249fffb52fd2e0065678ee + revision: 72e742afb7ea8c19369fa9a4ce0d74ce098e2678 + branch: add-bun-support specs: package_json (0.1.0) diff --git a/gemfiles/sprockets_4.gemfile b/gemfiles/sprockets_4.gemfile index a8b163a50..e6650a0cc 100644 --- a/gemfiles/sprockets_4.gemfile +++ b/gemfiles/sprockets_4.gemfile @@ -2,7 +2,7 @@ source "http://rubygems.org" -gem "package_json", github: "G-Rath/package_json" +gem "package_json", github: "G-Rath/package_json", branch: "add-bun-support" gem "rails", "~> 7.0.x" gem "sprockets", "~> 4.0.x" gem "sprockets-rails" diff --git a/gemfiles/sprockets_4.gemfile.lock b/gemfiles/sprockets_4.gemfile.lock index a34231649..59db14871 100644 --- a/gemfiles/sprockets_4.gemfile.lock +++ b/gemfiles/sprockets_4.gemfile.lock @@ -1,6 +1,7 @@ GIT remote: https://github.com/G-Rath/package_json.git - revision: d48f2c0db14bb1305f249fffb52fd2e0065678ee + revision: 72e742afb7ea8c19369fa9a4ce0d74ce098e2678 + branch: add-bun-support specs: package_json (0.1.0) diff --git a/lib/generators/react/install_generator.rb b/lib/generators/react/install_generator.rb index 7af4f61a5..f5b202b4f 100644 --- a/lib/generators/react/install_generator.rb +++ b/lib/generators/react/install_generator.rb @@ -107,7 +107,7 @@ def setup_react_sprockets def require_package_json_gem require "bundler/inline" - gemfile { gem "package_json", github: "G-Rath/package_json" } + gemfile { gem "package_json", github: "G-Rath/package_json", branch: "add-bun-support" } puts "using package_json v#{PackageJson::VERSION}" end diff --git a/test/bin/create-fake-js-package-managers b/test/bin/create-fake-js-package-managers index cb3c361fc..d911151fa 100755 --- a/test/bin/create-fake-js-package-managers +++ b/test/bin/create-fake-js-package-managers @@ -15,7 +15,7 @@ if ENV["GITHUB_ACTIONS"] File.write(ENV.fetch("GITHUB_PATH"), "#{bin_dir}\n", mode: "a+") end -managers = %w[npm yarn pnpm] +managers = %w[npm yarn pnpm bun] manager_in_use = ARGV[0] Dir.chdir(bin_dir) do From 35c23bb0d04d5ef416f4c1d7b0b93a7f7abcb507 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Sat, 16 Sep 2023 08:39:50 +1200 Subject: [PATCH 6/9] feat: use `package_json` from RubyGems --- Gemfile | 3 --- Gemfile.lock | 10 ++-------- Rakefile | 18 +----------------- gemfiles/base.gemfile | 1 - gemfiles/base.gemfile.lock | 8 -------- gemfiles/shakapacker.gemfile | 1 - gemfiles/shakapacker.gemfile.lock | 12 +++--------- gemfiles/sprockets_3.gemfile | 1 - gemfiles/sprockets_3.gemfile.lock | 8 -------- gemfiles/sprockets_4.gemfile | 1 - gemfiles/sprockets_4.gemfile.lock | 8 -------- lib/generators/react/install_generator.rb | 3 +-- react-rails.gemspec | 1 + 13 files changed, 8 insertions(+), 67 deletions(-) diff --git a/Gemfile b/Gemfile index 02b670654..8926579c4 100644 --- a/Gemfile +++ b/Gemfile @@ -3,7 +3,4 @@ source "http://rubygems.org" gemspec - -gem "package_json", github: "G-Rath/package_json", branch: "add-bun-support" - # This is an optional dev-dependency, required whenever sprockets is required diff --git a/Gemfile.lock b/Gemfile.lock index 3d1c4aff3..e109d23ef 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,10 +1,3 @@ -GIT - remote: https://github.com/G-Rath/package_json.git - revision: 72e742afb7ea8c19369fa9a4ce0d74ce098e2678 - branch: add-bun-support - specs: - package_json (0.1.0) - PATH remote: . specs: @@ -118,6 +111,7 @@ GEM notiffany (0.1.3) nenv (~> 0.1) shellany (~> 0.0) + package_json (0.1.0) pry (0.14.2) coderay (~> 1.1) method_source (~> 1.0) @@ -184,7 +178,7 @@ DEPENDENCIES guard-minitest jbuilder listen (~> 3.0.0) - package_json! + package_json pry-byebug react-rails! selenium-webdriver diff --git a/Rakefile b/Rakefile index 12b65ac18..de4274c86 100644 --- a/Rakefile +++ b/Rakefile @@ -8,13 +8,7 @@ end Bundler::GemHelper.install_tasks -def require_package_json_gem - require "bundler/inline" - - gemfile { gem "package_json", github: "G-Rath/package_json", branch: "add-bun-support" } - - puts "using package_json v#{PackageJson::VERSION}" -end +require "package_json" def copy_react_asset(webpack_file, destination_file) full_webpack_path = File.expand_path("../react-builds/build/#{webpack_file}", __FILE__) @@ -28,15 +22,11 @@ namespace :react do desc "Install the JavaScript dependencies" task :install do - require_package_json_gem - PackageJson.read("react-builds").manager.install end desc "Build the JS bundles with Webpack" task :build do - require_package_json_gem - PackageJson.read("react-builds").manager.run("build") end @@ -56,15 +46,11 @@ namespace :ujs do desc "Install the JavaScript dependencies" task :install do - require_package_json_gem - PackageJson.read.manager.install end desc "Build the JS bundles with Webpack" task :build do - require_package_json_gem - PackageJson.read.manager.run("build") end @@ -96,8 +82,6 @@ task default: :test task :test_setup do Dir.chdir("./test/dummy") do - require_package_json_gem - PackageJson.read.manager.install end end diff --git a/gemfiles/base.gemfile b/gemfiles/base.gemfile index e7513b5d3..dbd7ec2d2 100644 --- a/gemfiles/base.gemfile +++ b/gemfiles/base.gemfile @@ -2,7 +2,6 @@ source "http://rubygems.org" -gem "package_json", github: "G-Rath/package_json", branch: "add-bun-support" gem "rails", "~> 7.0.x" gemspec path: "../" diff --git a/gemfiles/base.gemfile.lock b/gemfiles/base.gemfile.lock index 58e7fca9e..3fd3b9201 100644 --- a/gemfiles/base.gemfile.lock +++ b/gemfiles/base.gemfile.lock @@ -1,10 +1,3 @@ -GIT - remote: https://github.com/G-Rath/package_json.git - revision: 72e742afb7ea8c19369fa9a4ce0d74ce098e2678 - branch: add-bun-support - specs: - package_json (0.1.0) - PATH remote: .. specs: @@ -265,7 +258,6 @@ DEPENDENCIES guard-minitest jbuilder listen (~> 3.0.0) - package_json! pry-byebug rails (~> 7.0.x) react-rails! diff --git a/gemfiles/shakapacker.gemfile b/gemfiles/shakapacker.gemfile index 382d4b684..c699a83c4 100644 --- a/gemfiles/shakapacker.gemfile +++ b/gemfiles/shakapacker.gemfile @@ -2,7 +2,6 @@ source "http://rubygems.org" -gem "package_json", github: "G-Rath/package_json", branch: "add-bun-support" gem "rails", "~> 7.0.x" gem "shakapacker", github: "G-Rath/shakapacker", branch: "use-package_json" diff --git a/gemfiles/shakapacker.gemfile.lock b/gemfiles/shakapacker.gemfile.lock index fed71ed0f..2d484e5f7 100644 --- a/gemfiles/shakapacker.gemfile.lock +++ b/gemfiles/shakapacker.gemfile.lock @@ -1,17 +1,11 @@ -GIT - remote: https://github.com/G-Rath/package_json.git - revision: 72e742afb7ea8c19369fa9a4ce0d74ce098e2678 - branch: add-bun-support - specs: - package_json (0.1.0) - GIT remote: https://github.com/G-Rath/shakapacker.git - revision: 8e9db60edd13429bdae9783d7f37bac70470870c + revision: 992f156694499f62f35ddd32bb6d53597a78c453 branch: use-package_json specs: shakapacker (7.0.3) activesupport (>= 5.2) + package_json rack-proxy (>= 0.6.1) railties (>= 5.2) semantic_range (>= 2.3.0) @@ -194,6 +188,7 @@ GEM notiffany (0.1.3) nenv (~> 0.1) shellany (~> 0.0) + package_json (0.1.0) pry (0.14.2) coderay (~> 1.1) method_source (~> 1.0) @@ -281,7 +276,6 @@ DEPENDENCIES guard-minitest jbuilder listen (~> 3.0.0) - package_json! pry-byebug rails (~> 7.0.x) react-rails! diff --git a/gemfiles/sprockets_3.gemfile b/gemfiles/sprockets_3.gemfile index 52aaf1e71..ca312487d 100644 --- a/gemfiles/sprockets_3.gemfile +++ b/gemfiles/sprockets_3.gemfile @@ -2,7 +2,6 @@ source "http://rubygems.org" -gem "package_json", github: "G-Rath/package_json", branch: "add-bun-support" gem "rails", "~> 7.0.x" gem "sprockets", "~> 3.5" gem "sprockets-rails" diff --git a/gemfiles/sprockets_3.gemfile.lock b/gemfiles/sprockets_3.gemfile.lock index ccfd9165c..8e044462c 100644 --- a/gemfiles/sprockets_3.gemfile.lock +++ b/gemfiles/sprockets_3.gemfile.lock @@ -1,10 +1,3 @@ -GIT - remote: https://github.com/G-Rath/package_json.git - revision: 72e742afb7ea8c19369fa9a4ce0d74ce098e2678 - branch: add-bun-support - specs: - package_json (0.1.0) - PATH remote: .. specs: @@ -277,7 +270,6 @@ DEPENDENCIES jbuilder listen (~> 3.0.0) mini_racer - package_json! pry-byebug rails (~> 7.0.x) react-rails! diff --git a/gemfiles/sprockets_4.gemfile b/gemfiles/sprockets_4.gemfile index e6650a0cc..245032a24 100644 --- a/gemfiles/sprockets_4.gemfile +++ b/gemfiles/sprockets_4.gemfile @@ -2,7 +2,6 @@ source "http://rubygems.org" -gem "package_json", github: "G-Rath/package_json", branch: "add-bun-support" gem "rails", "~> 7.0.x" gem "sprockets", "~> 4.0.x" gem "sprockets-rails" diff --git a/gemfiles/sprockets_4.gemfile.lock b/gemfiles/sprockets_4.gemfile.lock index 59db14871..815347067 100644 --- a/gemfiles/sprockets_4.gemfile.lock +++ b/gemfiles/sprockets_4.gemfile.lock @@ -1,10 +1,3 @@ -GIT - remote: https://github.com/G-Rath/package_json.git - revision: 72e742afb7ea8c19369fa9a4ce0d74ce098e2678 - branch: add-bun-support - specs: - package_json (0.1.0) - PATH remote: .. specs: @@ -277,7 +270,6 @@ DEPENDENCIES jbuilder listen (~> 3.0.0) mini_racer - package_json! pry-byebug rails (~> 7.0.x) react-rails! diff --git a/lib/generators/react/install_generator.rb b/lib/generators/react/install_generator.rb index f5b202b4f..5c48e5e7d 100644 --- a/lib/generators/react/install_generator.rb +++ b/lib/generators/react/install_generator.rb @@ -103,11 +103,10 @@ def setup_react_sprockets ReactRailsUJS.useContext(componentRequireContext); JS - # TODO: replace with standard "require" call once gem is published def require_package_json_gem require "bundler/inline" - gemfile { gem "package_json", github: "G-Rath/package_json", branch: "add-bun-support" } + gemfile(true) { gem "package_json" } puts "using package_json v#{PackageJson::VERSION}" end diff --git a/react-rails.gemspec b/react-rails.gemspec index fc5755456..39f06120e 100644 --- a/react-rails.gemspec +++ b/react-rails.gemspec @@ -28,6 +28,7 @@ Gem::Specification.new do |s| s.add_development_dependency 'selenium-webdriver' s.add_development_dependency 'test-unit', '~> 2.5' s.add_development_dependency 'pry-byebug' + s.add_development_dependency 'package_json' s.add_dependency 'connection_pool' From 988b717329d1e7efb8765f48a12717d8f4492398 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Fri, 8 Dec 2023 11:19:53 +1300 Subject: [PATCH 7/9] chore: use rc version of shakapacker --- Appraisals | 2 +- gemfiles/base.gemfile.lock | 2 ++ gemfiles/shakapacker.gemfile | 2 +- gemfiles/shakapacker.gemfile.lock | 23 +++++++++-------------- gemfiles/sprockets_3.gemfile.lock | 2 ++ gemfiles/sprockets_4.gemfile.lock | 2 ++ 6 files changed, 17 insertions(+), 16 deletions(-) diff --git a/Appraisals b/Appraisals index afbe6dd11..78543579b 100644 --- a/Appraisals +++ b/Appraisals @@ -16,7 +16,7 @@ end appraise 'shakapacker' do gem 'rails', '~> 7.0.x' - gem 'shakapacker', github: 'G-Rath/shakapacker', branch: 'use-package_json' + gem 'shakapacker', '7.2.0.rc.0' end appraise 'base' do diff --git a/gemfiles/base.gemfile.lock b/gemfiles/base.gemfile.lock index 3fd3b9201..a21eb747e 100644 --- a/gemfiles/base.gemfile.lock +++ b/gemfiles/base.gemfile.lock @@ -174,6 +174,7 @@ GEM notiffany (0.1.3) nenv (~> 0.1) shellany (~> 0.0) + package_json (0.1.0) pry (0.14.2) coderay (~> 1.1) method_source (~> 1.0) @@ -258,6 +259,7 @@ DEPENDENCIES guard-minitest jbuilder listen (~> 3.0.0) + package_json pry-byebug rails (~> 7.0.x) react-rails! diff --git a/gemfiles/shakapacker.gemfile b/gemfiles/shakapacker.gemfile index c699a83c4..d2205e1d1 100644 --- a/gemfiles/shakapacker.gemfile +++ b/gemfiles/shakapacker.gemfile @@ -3,6 +3,6 @@ source "http://rubygems.org" gem "rails", "~> 7.0.x" -gem "shakapacker", github: "G-Rath/shakapacker", branch: "use-package_json" +gem "shakapacker", "7.2.0.rc.0" gemspec path: "../" diff --git a/gemfiles/shakapacker.gemfile.lock b/gemfiles/shakapacker.gemfile.lock index 2d484e5f7..1e83aa42b 100644 --- a/gemfiles/shakapacker.gemfile.lock +++ b/gemfiles/shakapacker.gemfile.lock @@ -1,15 +1,3 @@ -GIT - remote: https://github.com/G-Rath/shakapacker.git - revision: 992f156694499f62f35ddd32bb6d53597a78c453 - branch: use-package_json - specs: - shakapacker (7.0.3) - activesupport (>= 5.2) - package_json - rack-proxy (>= 0.6.1) - railties (>= 5.2) - semantic_range (>= 2.3.0) - PATH remote: .. specs: @@ -198,7 +186,7 @@ GEM public_suffix (5.0.1) racc (1.6.2) rack (2.2.7) - rack-proxy (0.7.6) + rack-proxy (0.7.7) rack rack-test (2.1.0) rack (>= 1.3) @@ -240,6 +228,12 @@ GEM rubyzip (>= 1.2.2, < 3.0) websocket (~> 1.0) semantic_range (3.0.0) + shakapacker (7.2.0.rc.0) + activesupport (>= 5.2) + package_json + rack-proxy (>= 0.6.1) + railties (>= 5.2) + semantic_range (>= 2.3.0) shellany (0.0.1) simplecov (0.13.0) docile (~> 1.1.0) @@ -276,11 +270,12 @@ DEPENDENCIES guard-minitest jbuilder listen (~> 3.0.0) + package_json pry-byebug rails (~> 7.0.x) react-rails! selenium-webdriver - shakapacker! + shakapacker (= 7.2.0.rc.0) test-unit (~> 2.5) BUNDLED WITH diff --git a/gemfiles/sprockets_3.gemfile.lock b/gemfiles/sprockets_3.gemfile.lock index 8e044462c..d6c114564 100644 --- a/gemfiles/sprockets_3.gemfile.lock +++ b/gemfiles/sprockets_3.gemfile.lock @@ -178,6 +178,7 @@ GEM notiffany (0.1.3) nenv (~> 0.1) shellany (~> 0.0) + package_json (0.1.0) pry (0.12.2) coderay (~> 1.1.0) method_source (~> 0.9.0) @@ -270,6 +271,7 @@ DEPENDENCIES jbuilder listen (~> 3.0.0) mini_racer + package_json pry-byebug rails (~> 7.0.x) react-rails! diff --git a/gemfiles/sprockets_4.gemfile.lock b/gemfiles/sprockets_4.gemfile.lock index 815347067..0de2c85bf 100644 --- a/gemfiles/sprockets_4.gemfile.lock +++ b/gemfiles/sprockets_4.gemfile.lock @@ -178,6 +178,7 @@ GEM notiffany (0.1.3) nenv (~> 0.1) shellany (~> 0.0) + package_json (0.1.0) pry (0.12.2) coderay (~> 1.1.0) method_source (~> 0.9.0) @@ -270,6 +271,7 @@ DEPENDENCIES jbuilder listen (~> 3.0.0) mini_racer + package_json pry-byebug rails (~> 7.0.x) react-rails! From c15e6e795bdb8ac1bb2334e8871b83fc6e25ff16 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Fri, 8 Dec 2023 11:27:15 +1300 Subject: [PATCH 8/9] docs: add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a01f77c21..d2f8204de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ _Please add entries here for your pull requests that are not yet released._ #### Changed - Make es6 and ts usable at same time. #1299 +- Support other JS package managers using `package_json` gem #1306 ## [3.1.1] - 2023-08-16 From d29a7a445a9f42d59179db896d396885c9b99b59 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Sat, 30 Dec 2023 07:56:54 +1300 Subject: [PATCH 9/9] chore: use stable version of `shakapacker` --- Appraisals | 2 +- gemfiles/shakapacker.gemfile | 2 +- gemfiles/shakapacker.gemfile.lock | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Appraisals b/Appraisals index 78543579b..967ed8ecb 100644 --- a/Appraisals +++ b/Appraisals @@ -16,7 +16,7 @@ end appraise 'shakapacker' do gem 'rails', '~> 7.0.x' - gem 'shakapacker', '7.2.0.rc.0' + gem 'shakapacker', '7.2.0' end appraise 'base' do diff --git a/gemfiles/shakapacker.gemfile b/gemfiles/shakapacker.gemfile index d2205e1d1..bbd6c5b47 100644 --- a/gemfiles/shakapacker.gemfile +++ b/gemfiles/shakapacker.gemfile @@ -3,6 +3,6 @@ source "http://rubygems.org" gem "rails", "~> 7.0.x" -gem "shakapacker", "7.2.0.rc.0" +gem "shakapacker", "7.2.0" gemspec path: "../" diff --git a/gemfiles/shakapacker.gemfile.lock b/gemfiles/shakapacker.gemfile.lock index 1e83aa42b..7c2d64807 100644 --- a/gemfiles/shakapacker.gemfile.lock +++ b/gemfiles/shakapacker.gemfile.lock @@ -228,7 +228,7 @@ GEM rubyzip (>= 1.2.2, < 3.0) websocket (~> 1.0) semantic_range (3.0.0) - shakapacker (7.2.0.rc.0) + shakapacker (7.2.0) activesupport (>= 5.2) package_json rack-proxy (>= 0.6.1) @@ -275,7 +275,7 @@ DEPENDENCIES rails (~> 7.0.x) react-rails! selenium-webdriver - shakapacker (= 7.2.0.rc.0) + shakapacker (= 7.2.0) test-unit (~> 2.5) BUNDLED WITH