Skip to content

Commit

Permalink
Fix ignored workspace matching
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Nov 26, 2024
1 parent fc88c1a commit 1c6309d
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 5 deletions.
6 changes: 5 additions & 1 deletion packages/docs/src/content/docs/reference/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,11 @@ Array of workspaces to ignore, globs allowed. Example:

```json title="knip.json"
{
"ignoreWorkspaces": ["packages/ignore", "packages/examples/**"]
"ignoreWorkspaces": [
"packages/go-server",
"packages/flat/*"
"packages/deep/**"
]
}
```

Expand Down
6 changes: 5 additions & 1 deletion packages/knip/fixtures/workspaces-ignored/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
"packages/c",
"packages/d*",
"packages/f",
"packages/g"
"packages/g",
"packages/deep/**",
"packages/flat/*",
"packages/un/**/used",
"packages/wut/*"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "@workspaces-ignored/deep-h2",
"scripts": {
"start": "ignored"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "@workspaces-ignored/flat-i1",
"scripts": {
"start": "ignored"
}
}
2 changes: 2 additions & 0 deletions packages/knip/fixtures/workspaces-ignored/pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
packages:
- 'packages/*'
- 'packages/flat/*'
- 'packages/deep/er/*'
- '!packages/a'
- '!packages/b*'
3 changes: 1 addition & 2 deletions packages/knip/src/ConfigurationChief.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,7 @@ export class ConfigurationChief {
const ignoredWorkspacesManifest = this.getListedWorkspaces()
.filter(name => name.startsWith('!'))
.map(name => name.replace(/^!/, ''));
const ignoredWorkspacesConfig = this.config.ignoreWorkspaces.map(name => name.replace(/\/\*$/, ''));
return [...ignoredWorkspacesManifest, ...ignoredWorkspacesConfig];
return [...ignoredWorkspacesManifest, ...this.config.ignoreWorkspaces];
}

private getConfiguredWorkspaceKeys() {
Expand Down
9 changes: 8 additions & 1 deletion packages/knip/test/workspaces-ignored.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ test('Ignore workspaces', async () => {
assert.equal(Object.keys(issues.binaries).length, 1);
assert(issues.binaries['packages/e/package.json']['not-ignored']);

assert.deepEqual(configurationHints, new Set([{ type: 'ignoreWorkspaces', identifier: 'packages/f' }]));
assert.deepEqual(
configurationHints,
new Set([
{ type: 'ignoreWorkspaces', identifier: 'packages/f' },
{ type: 'ignoreWorkspaces', identifier: 'packages/wut/*' },
{ type: 'ignoreWorkspaces', identifier: 'packages/un/**/used' },
])
);

assert.deepEqual(counters, {
...baseCounters,
Expand Down

0 comments on commit 1c6309d

Please sign in to comment.