Skip to content

Commit

Permalink
feat: merge with existing package.json rather than replacing it com…
Browse files Browse the repository at this point in the history
…pletely
  • Loading branch information
G-Rath committed Mar 24, 2024
1 parent fe27b43 commit 617c98a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
14 changes: 13 additions & 1 deletion lib/install/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,24 @@ def package_json
if @package_json.nil?
require "package_json"

@package_json = PackageJson.read
@package_json = PackageJson.new
end

@package_json
end

# setup the package manager with default values
package_json.merge! do |pj|
{
"name" => "app",
"private" => true,
"version" => "0.1.0",
"browserslist" => [
"defaults"
]
}.merge(pj)
end

# Ensure there is `system!("bin/yarn")` command in `./bin/setup` file
if (setup_path = Rails.root.join("bin/setup")).exist?
native_install_command = package_json.manager.native_install_command.join(" ")
Expand Down
2 changes: 1 addition & 1 deletion spec/generator_specs/generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
expect(actual_content).to eq expected_content
end

it "replaces package.json with the template file" do
it "replaces the package.json completely" do
package_json = PackageJson.read(path_in_the_app)

expect(package_json.fetch("name", "")).to eq("app")
Expand Down

0 comments on commit 617c98a

Please sign in to comment.