Skip to content

Commit

Permalink
fix: ensure that pnpm install behaviour is consistent with other pa…
Browse files Browse the repository at this point in the history
…ckage managers, even in CI
  • Loading branch information
G-Rath committed Aug 13, 2023
1 parent d737e2e commit e738dfe
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
10 changes: 9 additions & 1 deletion lib/package_json/managers/pnpm_like.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,15 @@ def with_native_args(
)
args = [*extra_args]

args << "--frozen-lockfile" if frozen
# we make frozen lockfile behaviour consistent with the other package managers
# as pnpm automatically enables frozen lockfile if it detects it's running in CI
unless frozen.nil?
flag = "--no-frozen-lockfile"
flag = "--frozen-lockfile" if frozen

args << flag
end

args << "--ignore-scripts" if ignore_scripts
args << "--no-optional" if omit_optional_deps

Expand Down
16 changes: 8 additions & 8 deletions spec/package_json/managers/pnpm_like_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
with_package_json_file do
manager.install

expect_manager_to_be_invoked_with("install")
expect_manager_to_be_invoked_with("install --no-frozen-lockfile")
end
end

Expand All @@ -42,23 +42,23 @@
with_package_json_file do
manager.install(ignore_scripts: true)

expect_manager_to_be_invoked_with("install --ignore-scripts")
expect_manager_to_be_invoked_with("install --no-frozen-lockfile --ignore-scripts")
end
end

it "supports legacy_peer_deps" do
with_package_json_file do
manager.install(legacy_peer_deps: true)

expect_manager_to_be_invoked_with("install")
expect_manager_to_be_invoked_with("install --no-frozen-lockfile")
end
end

it "supports omit_optional_deps" do
with_package_json_file do
manager.install(omit_optional_deps: true)

expect_manager_to_be_invoked_with("install --no-optional")
expect_manager_to_be_invoked_with("install --no-frozen-lockfile --no-optional")
end
end

Expand All @@ -82,7 +82,7 @@

describe "#native_install_command" do
it "returns the full command" do
expect(manager.native_install_command).to eq("#{package_manager_cmd} install")
expect(manager.native_install_command).to eq("#{package_manager_cmd} install --no-frozen-lockfile")
end

context "when passing the usual options" do
Expand All @@ -94,19 +94,19 @@

it "supports ignore_scripts" do
expect(manager.native_install_command(ignore_scripts: true)).to eq(
"#{package_manager_cmd} install --ignore-scripts"
"#{package_manager_cmd} install --no-frozen-lockfile --ignore-scripts"
)
end

it "supports legacy_peer_deps" do
expect(manager.native_install_command(legacy_peer_deps: true)).to eq(
"#{package_manager_cmd} install"
"#{package_manager_cmd} install --no-frozen-lockfile"
)
end

it "supports omit_optional_deps" do
expect(manager.native_install_command(omit_optional_deps: true)).to eq(
"#{package_manager_cmd} install --no-optional"
"#{package_manager_cmd} install --no-frozen-lockfile --no-optional"
)
end

Expand Down

0 comments on commit e738dfe

Please sign in to comment.