From e738dfe509bc44e685bcc6be690ee5fc943f86ff Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Mon, 14 Aug 2023 07:51:41 +1200 Subject: [PATCH] fix: ensure that `pnpm install` behaviour is consistent with other package managers, even in CI --- lib/package_json/managers/pnpm_like.rb | 10 +++++++++- spec/package_json/managers/pnpm_like_spec.rb | 16 ++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/lib/package_json/managers/pnpm_like.rb b/lib/package_json/managers/pnpm_like.rb index 4a068c4..7f6a319 100644 --- a/lib/package_json/managers/pnpm_like.rb +++ b/lib/package_json/managers/pnpm_like.rb @@ -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 diff --git a/spec/package_json/managers/pnpm_like_spec.rb b/spec/package_json/managers/pnpm_like_spec.rb index afeb34d..d004d47 100644 --- a/spec/package_json/managers/pnpm_like_spec.rb +++ b/spec/package_json/managers/pnpm_like_spec.rb @@ -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 @@ -42,7 +42,7 @@ 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 @@ -50,7 +50,7 @@ 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 @@ -58,7 +58,7 @@ 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 @@ -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 @@ -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