Skip to content

Commit 1c6309d

Browse files
committedNov 26, 2024
Fix ignored workspace matching
1 parent fc88c1a commit 1c6309d

File tree

7 files changed

+33
-5
lines changed

7 files changed

+33
-5
lines changed
 

‎packages/docs/src/content/docs/reference/configuration.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,11 @@ Array of workspaces to ignore, globs allowed. Example:
219219

220220
```json title="knip.json"
221221
{
222-
"ignoreWorkspaces": ["packages/ignore", "packages/examples/**"]
222+
"ignoreWorkspaces": [
223+
"packages/go-server",
224+
"packages/flat/*"
225+
"packages/deep/**"
226+
]
223227
}
224228
```
225229

‎packages/knip/fixtures/workspaces-ignored/package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
"packages/c",
66
"packages/d*",
77
"packages/f",
8-
"packages/g"
8+
"packages/g",
9+
"packages/deep/**",
10+
"packages/flat/*",
11+
"packages/un/**/used",
12+
"packages/wut/*"
913
]
1014
}
1115
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "@workspaces-ignored/deep-h2",
3+
"scripts": {
4+
"start": "ignored"
5+
}
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "@workspaces-ignored/flat-i1",
3+
"scripts": {
4+
"start": "ignored"
5+
}
6+
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
packages:
22
- 'packages/*'
3+
- 'packages/flat/*'
4+
- 'packages/deep/er/*'
35
- '!packages/a'
46
- '!packages/b*'

‎packages/knip/src/ConfigurationChief.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,7 @@ export class ConfigurationChief {
254254
const ignoredWorkspacesManifest = this.getListedWorkspaces()
255255
.filter(name => name.startsWith('!'))
256256
.map(name => name.replace(/^!/, ''));
257-
const ignoredWorkspacesConfig = this.config.ignoreWorkspaces.map(name => name.replace(/\/\*$/, ''));
258-
return [...ignoredWorkspacesManifest, ...ignoredWorkspacesConfig];
257+
return [...ignoredWorkspacesManifest, ...this.config.ignoreWorkspaces];
259258
}
260259

261260
private getConfiguredWorkspaceKeys() {

‎packages/knip/test/workspaces-ignored.test.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,14 @@ test('Ignore workspaces', async () => {
1616
assert.equal(Object.keys(issues.binaries).length, 1);
1717
assert(issues.binaries['packages/e/package.json']['not-ignored']);
1818

19-
assert.deepEqual(configurationHints, new Set([{ type: 'ignoreWorkspaces', identifier: 'packages/f' }]));
19+
assert.deepEqual(
20+
configurationHints,
21+
new Set([
22+
{ type: 'ignoreWorkspaces', identifier: 'packages/f' },
23+
{ type: 'ignoreWorkspaces', identifier: 'packages/wut/*' },
24+
{ type: 'ignoreWorkspaces', identifier: 'packages/un/**/used' },
25+
])
26+
);
2027

2128
assert.deepEqual(counters, {
2229
...baseCounters,

0 commit comments

Comments
 (0)
Please sign in to comment.