jsbundling-rails 1.2.2 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3cd9756300244b2e031344a063f93d4e6ed124fc2cb324a6d70ee6e69385304f
4
- data.tar.gz: 2618a978134e255ec4b69a6cefddeb593ba0c8dfba9d1e12fc37215b556968bb
3
+ metadata.gz: c5eb0a7f2f82b82a508d4640babe1980234db73e9f97f2bcdd08db417ad1dfee
4
+ data.tar.gz: 9ba266bcf549a314d0968705626021566c993a1c7e771ecf886627c307c0300a
5
5
  SHA512:
6
- metadata.gz: dbcf7c0772469872dfea9667f852a0dc64012b55896c3a8cef480a57ae49adbd7d8e001faee1b48c8b99de659e39e27c45e1b086470c4d7070fbec442735c8b8
7
- data.tar.gz: 07d134a6c2b6765c83cac64b85314ceb91666ef6ca93c7d997c820e6c588f7085be61bbad3a0fae8c250be8cb29ed314dbf76890bb975b8b64b998b70fef7ebc
6
+ metadata.gz: b9f055b3a8a676d91e3fb421e757a5e81e6b01b4c165c8f45f889de1a2c0bbdcf574c6934d17c7b39006ad05a87b52be9e5c4429f0265ddd87888129fc472c3c
7
+ data.tar.gz: a07320167dc646b5b9792e8d02c770b2e4c40283a5219baf92cfca6b29ae04c54b2d2ab7e0c995514b4bf646b092272f9a3133cd46b0571ebd9190d57682a3d2
data/README.md CHANGED
@@ -6,7 +6,7 @@ You develop using this approach by running the bundler in watch mode in a termin
6
6
 
7
7
  Whenever the bundler detects changes to any of the JavaScript files in your project, it'll bundle `app/javascript/application.js` into `app/assets/builds/application.js` (and all other entry points configured). You can refer to the build output in your layout using the standard asset pipeline approach with `<%= javascript_include_tag "application", defer: true %>`.
8
8
 
9
- When you deploy your application to production, the `javascript:build` task attaches to the `assets:precompile` task to ensure that all your package dependencies from `package.json` have been installed via your javascript package manager (bun or yarn), and then runs the build script defined in `package.json` to process all the entry points, as it would in development. The latter files are then picked up by the asset pipeline, digested, and copied into public/assets, as any other asset pipeline file.
9
+ When you deploy your application to production, the `javascript:build` task attaches to the `assets:precompile` task to ensure that all your package dependencies from `package.json` have been installed via your javascript package manager ([bun](https://bun.sh), [npm](https://www.npmjs.com), [pnpm](https://pnpm.io), or [yarn](https://yarnpkg.com)), and then runs the build script defined in `package.json` to process all the entry points, as it would in development. The latter files are then picked up by the asset pipeline, digested, and copied into public/assets, as any other asset pipeline file.
10
10
 
11
11
  This also happens in testing where the bundler attaches to the `test:prepare` task to ensure the JavaScript has been bundled before testing commences. If your testing library of choice does not call the `test:prepare` Rake task, ensure that your test suite runs `javascript:build` to bundle JavaScript before testing commences.
12
12
 
@@ -19,8 +19,7 @@ If you're already using [`webpacker`](https://github.com/rails/webpacker) and yo
19
19
  If you want to use webpack features like [code splitting](https://webpack.js.org/guides/code-splitting/) and [hot module reloading](https://webpack.js.org/concepts/hot-module-replacement/), consider using the official fork of `webpacker`, [`shakapacker`](https://github.com/shakacode/shakapacker).
20
20
 
21
21
  ## Installation
22
- If you are installing esbuild, rollup, or webpack, you must already have node
23
- and yarn installed on your system. You will also need npx version 7.1.0 or later.
22
+ If you are installing esbuild, rollup, or webpack, you must already have node installed on your system. You will also need npx version 7.1.0 or later.
24
23
 
25
24
  If you are using Bun, then you must have the Bun runtime already installed on
26
25
  your system.
@@ -1,5 +1,7 @@
1
1
  require 'json'
2
2
 
3
+ apply "#{__dir__}/../install.rb"
4
+
3
5
  if Rails.root.join("Procfile.dev").exist?
4
6
  append_to_file "Procfile.dev", "js: bun run build --watch\n"
5
7
  else
@@ -1,3 +1,6 @@
1
+ apply "#{__dir__}/../install.rb"
2
+ apply "#{__dir__}/../install_procfile.rb"
3
+
1
4
  say "Install esbuild"
2
5
  run "yarn add esbuild"
3
6
 
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "app",
3
- "private": "true"
3
+ "private": true
4
4
  }
@@ -1,3 +1,6 @@
1
+ apply "#{__dir__}/../install.rb"
2
+ apply "#{__dir__}/../install_procfile.rb"
3
+
1
4
  say "Install rollup with config"
2
5
  copy_file "#{__dir__}/rollup.config.js", "rollup.config.js"
3
6
  run "yarn add rollup @rollup/plugin-node-resolve"
@@ -1,3 +1,6 @@
1
+ apply "#{__dir__}/../install.rb"
2
+ apply "#{__dir__}/../install_procfile.rb"
3
+
1
4
  say "Install Webpack with config"
2
5
  copy_file "#{__dir__}/webpack.config.js", "webpack.config.js"
3
6
  run "yarn add webpack webpack-cli"
@@ -1,3 +1,3 @@
1
1
  module Jsbundling
2
- VERSION = "1.2.2"
2
+ VERSION = "1.3.0"
3
3
  end
@@ -23,22 +23,41 @@ module Jsbundling
23
23
  extend self
24
24
 
25
25
  def install_command
26
- return "bun install" if File.exist?('bun.lockb') || (tool_exists?('bun') && !File.exist?('yarn.lock'))
27
- return "yarn install" if File.exist?('yarn.lock') || (tool_exists?('yarn') && !File.exist?('package-lock.json'))
28
- return "npm install" if File.exist?('package-lock.json') || tool_exists?('npm')
29
- raise "jsbundling-rails: No suitable tool found for installing JavaScript dependencies"
26
+ case tool
27
+ when :bun then "bun install"
28
+ when :yarn then "yarn install"
29
+ when :pnpm then "pnpm install"
30
+ when :npm then "npm install"
31
+ else raise "jsbundling-rails: No suitable tool found for installing JavaScript dependencies"
32
+ end
30
33
  end
31
34
 
32
35
  def build_command
33
- return "bun run build" if File.exist?('bun.lockb') || (tool_exists?('bun') && !File.exist?('yarn.lock'))
34
- return "yarn build" if File.exist?('yarn.lock') || (tool_exists?('yarn') && !File.exist?('package-lock.json'))
35
- return "npm run build" if File.exist?('package-lock.json') || tool_exists?('npm')
36
- raise "jsbundling-rails: No suitable tool found for building JavaScript"
36
+ case tool
37
+ when :bun then "bun run build"
38
+ when :yarn then "yarn build"
39
+ when :pnpm then "pnpm build"
40
+ when :npm then "npm run build"
41
+ else raise "jsbundling-rails: No suitable tool found for building JavaScript"
42
+ end
37
43
  end
38
44
 
39
45
  def tool_exists?(tool)
40
46
  system "command -v #{tool} > /dev/null"
41
47
  end
48
+
49
+ def tool
50
+ case
51
+ when File.exist?('bun.lockb') then :bun
52
+ when File.exist?('yarn.lock') then :yarn
53
+ when File.exist?('pnpm-lock.yaml') then :pnpm
54
+ when File.exist?('package-lock.json') then :npm
55
+ when tool_exists?('bun') then :bun
56
+ when tool_exists?('yarn') then :yarn
57
+ when tool_exists?('pnpm') then :pnpm
58
+ when tool_exists?('npm') then :npm
59
+ end
60
+ end
42
61
  end
43
62
  end
44
63
 
@@ -1,32 +1,22 @@
1
1
  namespace :javascript do
2
2
  namespace :install do
3
- desc "Install shared elements for all bundlers"
4
- task :shared do
5
- system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../../install/install.rb", __dir__)}"
6
- end
7
-
8
- desc "Install node-specific elements for bundlers that use node/yarn."
9
- task :node_shared do
10
- system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../../install/install_node.rb", __dir__)}"
11
- end
12
-
13
3
  desc "Install Bun"
14
- task bun: "javascript:install:shared" do
4
+ task :bun do
15
5
  system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../../install/bun/install.rb", __dir__)}"
16
6
  end
17
7
 
18
8
  desc "Install esbuild"
19
- task esbuild: ["javascript:install:shared", "javascript:install:node_shared"] do
9
+ task :esbuild do
20
10
  system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../../install/esbuild/install.rb", __dir__)}"
21
11
  end
22
12
 
23
13
  desc "Install rollup.js"
24
- task rollup: ["javascript:install:shared", "javascript:install:node_shared"] do
14
+ task :rollup do
25
15
  system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../../install/rollup/install.rb", __dir__)}"
26
16
  end
27
17
 
28
18
  desc "Install Webpack"
29
- task webpack: ["javascript:install:shared", "javascript:install:node_shared"] do
19
+ task :webpack do
30
20
  system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../../install/webpack/install.rb", __dir__)}"
31
21
  end
32
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsbundling-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-07 00:00:00.000000000 Z
11
+ date: 2024-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -40,7 +40,7 @@ files:
40
40
  - lib/install/dev
41
41
  - lib/install/esbuild/install.rb
42
42
  - lib/install/install.rb
43
- - lib/install/install_node.rb
43
+ - lib/install/install_procfile.rb
44
44
  - lib/install/package.json
45
45
  - lib/install/rollup/install.rb
46
46
  - lib/install/rollup/rollup.config.js
@@ -71,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
71
  - !ruby/object:Gem::Version
72
72
  version: '0'
73
73
  requirements: []
74
- rubygems_version: 3.4.14
74
+ rubygems_version: 3.4.20
75
75
  signing_key:
76
76
  specification_version: 4
77
77
  summary: Bundle and transpile JavaScript in Rails with bun, esbuild, rollup.js, or