-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: switch to using
package_json
for interacting with `package.js…
…on` (#466) This allows us to support all of the major javascript package managers by relying on the [`package_json`](https://github.com/shakacode/package_json) gem to handle running and generating commands for a particular package manager. Currently I'm making our template actually agnostic and have setup to test that is the case by running against the major package managers + Yarn PnP, though I expect after landing this we'll decide on a single package manager to use going forward and remove code that is needed for the other package managers.
- Loading branch information
Showing
17 changed files
with
302 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/usr/bin/env ruby | ||
|
||
# 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 "fileutils" | ||
require "tmpdir" | ||
|
||
# setup the bin directory we want to use | ||
bin_dir = "tmp/fake-bin" | ||
|
||
if ENV["GITHUB_ACTIONS"] | ||
bin_dir = Dir.mktmpdir("rails-template-") | ||
|
||
puts "adding #{bin_dir} to GITHUB_PATH..." | ||
|
||
File.write(ENV.fetch("GITHUB_PATH"), "#{bin_dir}\n", mode: "a+") | ||
elsif system("direnv --version > /dev/null 2>&1") | ||
envrc_content = "PATH_add #{bin_dir}\n" | ||
|
||
if File.exist?(".envrc") && File.read(".envrc").include?(envrc_content) | ||
puts "'#{envrc_content.strip}' already exists in .envrc" | ||
else | ||
File.write(".envrc", envrc_content, mode: "a") | ||
puts "Added '#{envrc_content.strip}' to .envrc" | ||
end | ||
|
||
# ensure the .envrc is allowed | ||
system("direnv allow") | ||
end | ||
|
||
managers = %w[npm yarn pnpm bun] | ||
manager_in_use = ARGV[0] || "" | ||
|
||
if manager_in_use.empty? | ||
manager_in_use = ENV.fetch("PACKAGE_JSON_FALLBACK_MANAGER", "") | ||
.delete_suffix("_berry") | ||
.delete_suffix("_classic") | ||
end | ||
|
||
Dir.chdir(bin_dir) do | ||
managers.each do |manager| | ||
if manager == manager_in_use | ||
# ensure that the manager is not stubbed in case we've changed managers | ||
FileUtils.rm_f(manager) | ||
|
||
next | ||
end | ||
|
||
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 for..."); | ||
CONTENTS | ||
) | ||
File.chmod(0o755, manager) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
variants/backend-base/lib/tasks/assets.rake → ...nts/backend-base/lib/tasks/assets.rake.tt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
copy_file "variants/backend-base/lib/tasks/coverage.rake", "lib/tasks/coverage.rake" | ||
copy_file "variants/backend-base/lib/tasks/assets.rake", "lib/tasks/assets.rake" | ||
copy_file "variants/backend-base/lib/tasks/app.rake", "lib/tasks/app.rake" | ||
copy_file "variants/backend-base/lib/tasks/dev.rake", "lib/tasks/dev.rake" | ||
|
||
template "variants/backend-base/lib/tasks/assets.rake.tt", "lib/tasks/assets.rake", force: true |
Oops, something went wrong.