From 8d0115ea8b2b2e0c0072c8f69898e65a5a7aebd3 Mon Sep 17 00:00:00 2001 From: mino Date: Sat, 29 Oct 2022 17:19:27 +0800 Subject: [PATCH] Fixed an issue with private packages with versions being included in the CLI prompt despite the `privatePackages.version: false` setting (#985) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix(cli): the problem of isListablePackage condition * Test(cli): should not include private packages with a version in the prompt * Update packages/cli/src/commands/add/__tests__/add.ts * Create blue-geckos-guess.md Co-authored-by: Mateusz BurzyƄski --- .changeset/blue-geckos-guess.md | 5 +++++ .../.changeset/config.json | 1 + .../package.json | 9 ++++++++ .../packages/pkg-a/package.json | 4 ++++ .../packages/pkg-b/package.json | 5 +++++ .../packages/pkg-c/package.json | 4 ++++ .../cli/src/commands/add/__tests__/add.ts | 21 +++++++++++++++++++ .../cli/src/commands/add/isListablePackage.ts | 2 +- 8 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 .changeset/blue-geckos-guess.md create mode 100644 __fixtures__/private-package-with-version-field/.changeset/config.json create mode 100644 __fixtures__/private-package-with-version-field/package.json create mode 100644 __fixtures__/private-package-with-version-field/packages/pkg-a/package.json create mode 100644 __fixtures__/private-package-with-version-field/packages/pkg-b/package.json create mode 100644 __fixtures__/private-package-with-version-field/packages/pkg-c/package.json diff --git a/.changeset/blue-geckos-guess.md b/.changeset/blue-geckos-guess.md new file mode 100644 index 000000000..f255ac798 --- /dev/null +++ b/.changeset/blue-geckos-guess.md @@ -0,0 +1,5 @@ +--- +"@changesets/cli": patch +--- + +Fixed an issue with private packages with versions being included in the CLI prompt despite the `privatePackages.version: false` setting. diff --git a/__fixtures__/private-package-with-version-field/.changeset/config.json b/__fixtures__/private-package-with-version-field/.changeset/config.json new file mode 100644 index 000000000..0967ef424 --- /dev/null +++ b/__fixtures__/private-package-with-version-field/.changeset/config.json @@ -0,0 +1 @@ +{} diff --git a/__fixtures__/private-package-with-version-field/package.json b/__fixtures__/private-package-with-version-field/package.json new file mode 100644 index 000000000..14d4d5c5c --- /dev/null +++ b/__fixtures__/private-package-with-version-field/package.json @@ -0,0 +1,9 @@ +{ + "private": true, + "name": "private-package-with-version-field", + "description": "Base yarn workspace work", + "version": "1.0.0", + "workspaces": [ + "packages/*" + ] +} diff --git a/__fixtures__/private-package-with-version-field/packages/pkg-a/package.json b/__fixtures__/private-package-with-version-field/packages/pkg-a/package.json new file mode 100644 index 000000000..ee09b194d --- /dev/null +++ b/__fixtures__/private-package-with-version-field/packages/pkg-a/package.json @@ -0,0 +1,4 @@ +{ + "name": "pkg-a", + "version": "1.0.0" +} diff --git a/__fixtures__/private-package-with-version-field/packages/pkg-b/package.json b/__fixtures__/private-package-with-version-field/packages/pkg-b/package.json new file mode 100644 index 000000000..f1b81eab5 --- /dev/null +++ b/__fixtures__/private-package-with-version-field/packages/pkg-b/package.json @@ -0,0 +1,5 @@ +{ + "name": "pkg-b", + "version": "1.0.0", + "private": true +} diff --git a/__fixtures__/private-package-with-version-field/packages/pkg-c/package.json b/__fixtures__/private-package-with-version-field/packages/pkg-c/package.json new file mode 100644 index 000000000..888ba5c7e --- /dev/null +++ b/__fixtures__/private-package-with-version-field/packages/pkg-c/package.json @@ -0,0 +1,4 @@ +{ + "name": "pkg-c", + "version": "1.0.0" +} diff --git a/packages/cli/src/commands/add/__tests__/add.ts b/packages/cli/src/commands/add/__tests__/add.ts index 833e2ce30..5e62b4506 100644 --- a/packages/cli/src/commands/add/__tests__/add.ts +++ b/packages/cli/src/commands/add/__tests__/add.ts @@ -230,4 +230,25 @@ describe("Changesets", () => { const { choices } = askCheckboxPlus.mock.calls[0][1][0]; expect(choices).toEqual(["pkg-a", "pkg-c"]); }); + + it("should not include private packages with a version in the prompt if private packages are configured to be not versionable", async () => { + const cwd = f.copy("private-package-with-version-field"); + + mockUserResponses({ releases: { "pkg-a": "patch" } }); + await addChangeset( + cwd, + { empty: false }, + { + ...defaultConfig, + privatePackages: { + version: false, + tag: false, + }, + } + ); + + // @ts-ignore + const { choices } = askCheckboxPlus.mock.calls[0][1][0]; + expect(choices).toEqual(["pkg-a", "pkg-c"]); + }); }); diff --git a/packages/cli/src/commands/add/isListablePackage.ts b/packages/cli/src/commands/add/isListablePackage.ts index 16d17c177..9b11b1fdf 100644 --- a/packages/cli/src/commands/add/isListablePackage.ts +++ b/packages/cli/src/commands/add/isListablePackage.ts @@ -8,7 +8,7 @@ export function isListablePackage(config: Config, packageJson: PackageJSON) { return false; } - if (!config.privatePackages && packageJson.private) { + if (!config.privatePackages.version && packageJson.private) { return false; }