diff --git a/.changeset/fair-days-rest.md b/.changeset/fair-days-rest.md new file mode 100644 index 0000000..19e4d2a --- /dev/null +++ b/.changeset/fair-days-rest.md @@ -0,0 +1,6 @@ +--- +"@manypkg/cli": patch +"@manypkg/get-packages": patch +--- + +Fixed getting correct packages in pnpm workspaces with exclude rules. diff --git a/__fixtures__/pnpm-exclude-workspace-case/package.json b/__fixtures__/pnpm-exclude-workspace-case/package.json new file mode 100644 index 0000000..67f0141 --- /dev/null +++ b/__fixtures__/pnpm-exclude-workspace-case/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "name": "pnpm-exclude-workspace-case", + "description": "pnpm exclude rule workspace work", + "version": "1.0.0" +} diff --git a/__fixtures__/pnpm-exclude-workspace-case/packages/pkg-a/package.json b/__fixtures__/pnpm-exclude-workspace-case/packages/pkg-a/package.json new file mode 100644 index 0000000..d0375cd --- /dev/null +++ b/__fixtures__/pnpm-exclude-workspace-case/packages/pkg-a/package.json @@ -0,0 +1,7 @@ +{ + "name": "pnpm-exclude-workspace-case-pkg-a", + "version": "1.0.0", + "dependencies": { + "pnpm-exclude-workspace-case-pkg-b": "1.0.0" + } +} diff --git a/__fixtures__/pnpm-exclude-workspace-case/packages/pkg-b/package.json b/__fixtures__/pnpm-exclude-workspace-case/packages/pkg-b/package.json new file mode 100644 index 0000000..d093e10 --- /dev/null +++ b/__fixtures__/pnpm-exclude-workspace-case/packages/pkg-b/package.json @@ -0,0 +1,5 @@ + +{ + "name": "pnpm-exclude-workspace-case-pkg-b", + "version": "1.0.0" +} diff --git a/__fixtures__/pnpm-exclude-workspace-case/packages/pnpm-exclude-workspace-case/package.json b/__fixtures__/pnpm-exclude-workspace-case/packages/pnpm-exclude-workspace-case/package.json new file mode 100644 index 0000000..6a92fad --- /dev/null +++ b/__fixtures__/pnpm-exclude-workspace-case/packages/pnpm-exclude-workspace-case/package.json @@ -0,0 +1,5 @@ + +{ + "name": "pnpm-exclude-workspace-case-excluded-pkg", + "version": "1.0.0" +} diff --git a/__fixtures__/pnpm-exclude-workspace-case/pnpm-workspace.yaml b/__fixtures__/pnpm-exclude-workspace-case/pnpm-workspace.yaml new file mode 100644 index 0000000..4aa6ae4 --- /dev/null +++ b/__fixtures__/pnpm-exclude-workspace-case/pnpm-workspace.yaml @@ -0,0 +1,5 @@ +packages: + - 'packages/**' + # exclude packages that are inside myself name directories + - '!**/pnpm-exclude-workspace-case/**' + \ No newline at end of file diff --git a/packages/get-packages/src/index.test.ts b/packages/get-packages/src/index.test.ts index 5fb5eb7..03db99d 100644 --- a/packages/get-packages/src/index.test.ts +++ b/packages/get-packages/src/index.test.ts @@ -69,6 +69,19 @@ let runTests = (getPackages: GetPackages) => { expect(allPackages.tool).toEqual("pnpm"); }); + it("should resolve workspace for pnpm with exclude rules", async () => { + const allPackages = await getPackages(f.copy("pnpm-exclude-workspace-case")); + + expect(allPackages.packages[0].packageJson.name).toEqual( + "pnpm-exclude-workspace-case-pkg-a" + ); + expect(allPackages.packages[1].packageJson.name).toEqual( + "pnpm-exclude-workspace-case-pkg-b" + ); + expect(allPackages.packages.length).toEqual(2); + expect(allPackages.tool).toEqual("pnpm"); + }) + it("should resolve workspaces for lerna", async () => { const allPackages = await getPackages(f.copy("lerna-workspace-base")); diff --git a/packages/get-packages/src/index.ts b/packages/get-packages/src/index.ts index 78c8107..a281049 100644 --- a/packages/get-packages/src/index.ts +++ b/packages/get-packages/src/index.ts @@ -110,13 +110,13 @@ export async function getPackages(dir: string): Promise { }; } - const directories = await globby(tool.packageGlobs, { + const relativeDirectories = await globby(tool.packageGlobs, { cwd, onlyDirectories: true, - absolute: true, expandDirectories: false, ignore: ["**/node_modules"] }); + const directories = relativeDirectories.map(p => path.resolve(cwd, p)) let pkgJsonsMissingNameField: Array = []; @@ -234,13 +234,13 @@ export function getPackagesSync(dir: string): Packages { packages: [root] }; } - const directories = globbySync(tool.packageGlobs, { + const relativeDirectories = globbySync(tool.packageGlobs, { cwd, onlyDirectories: true, - absolute: true, expandDirectories: false, ignore: ["**/node_modules"] }); + const directories = relativeDirectories.map(p => path.resolve(cwd, p)) let pkgJsonsMissingNameField: Array = [];