Skip to content

Commit

Permalink
Allow workspace patterns to be relative (fixes #617)
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed May 3, 2024
1 parent 386e395 commit 6c71399
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
4 changes: 1 addition & 3 deletions packages/knip/fixtures/workspaces-tooling/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
"name": "@workspaces-tooling/root",
"workspaces": [
"packages/*"
]
"workspaces": ["./packages/*"]
}
3 changes: 2 additions & 1 deletion packages/knip/src/ConfigurationChief.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,12 @@ export class ConfigurationChief {
}

private getListedWorkspaces() {
return this.manifest?.workspaces
const workspaces = this.manifest?.workspaces
? Array.isArray(this.manifest.workspaces)
? this.manifest.workspaces
: this.manifest.workspaces.packages ?? []
: [];
return workspaces.map(pattern => pattern.replace(/(?<=!?)\.\//, ''));
}

private getIgnoredWorkspacePatterns() {
Expand Down
2 changes: 1 addition & 1 deletion packages/knip/src/util/map-workspaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { join } from './path.js';
import { _require } from './require.js';

export default async function mapWorkspaces(cwd: string, workspaces: string[]) {
const [negatedPatterns, patterns] = partition(workspaces, p => p.match(/^!+/));
const [negatedPatterns, patterns] = partition(workspaces, p => p.match(/^!/));
const byPkgDir = new Map<string, Package>();
const byPkgName = new Map<string, Package>();

Expand Down

0 comments on commit 6c71399

Please sign in to comment.