Skip to content

Commit

Permalink
fix(pnpm): absolute cwd path matched workspace exclude rules (#121) (#…
Browse files Browse the repository at this point in the history
…122)

* fix(pnpm): absolute path matched exclude rules

* chore(changeset): add changesets for fix

* chore: remove console.log

* Update .changeset/fair-days-rest.md

Co-authored-by: Mateusz Burzyński <[email protected]>

Co-authored-by: Mateusz Burzyński <[email protected]>
  • Loading branch information
fz6m and Andarist authored Nov 9, 2021
1 parent 8f9db7a commit 7bd4f34
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .changeset/fair-days-rest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@manypkg/cli": patch
"@manypkg/get-packages": patch
---

Fixed getting correct packages in pnpm workspaces with exclude rules.
6 changes: 6 additions & 0 deletions __fixtures__/pnpm-exclude-workspace-case/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"private": true,
"name": "pnpm-exclude-workspace-case",
"description": "pnpm exclude rule workspace work",
"version": "1.0.0"
}
Original file line number Diff line number Diff line change
@@ -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"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

{
"name": "pnpm-exclude-workspace-case-pkg-b",
"version": "1.0.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

{
"name": "pnpm-exclude-workspace-case-excluded-pkg",
"version": "1.0.0"
}
5 changes: 5 additions & 0 deletions __fixtures__/pnpm-exclude-workspace-case/pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
packages:
- 'packages/**'
# exclude packages that are inside myself name directories
- '!**/pnpm-exclude-workspace-case/**'

13 changes: 13 additions & 0 deletions packages/get-packages/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"));

Expand Down
8 changes: 4 additions & 4 deletions packages/get-packages/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,13 @@ export async function getPackages(dir: string): Promise<Packages> {
};
}

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<string> = [];

Expand Down Expand Up @@ -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<string> = [];

Expand Down

0 comments on commit 7bd4f34

Please sign in to comment.