Skip to content

Conversation

@fightZy
Copy link

@fightZy fightZy commented Jan 9, 2026

Feature #1441

Filter the workspace by package names, directory paths, globs and Git ranges.

Key Changes

  • Multiple Selectors: Support multiple --workspace (-W) arguments.
  • Negated Patterns: Ability to exclude workspaces using !.
  • Glob Support: Match package names and directories using wildcards.
  • Git Integration: Select workspaces based on changed files in a Git range (e.g., [main...HEAD]).

Copy link
Member

@webpro webpro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the pull request! This is a valuable feature for large projects indeed. Happy to review, but given the size of the changeset and the fact I'm not sure we should include the Git-based range filter (at least not yet), could you please remove that part?

if (this.workspace) {
const dir = path.resolve(this.cwd, this.workspace);
if (!isDirectory(dir)) throw new ConfigurationError('Workspace is not a directory');
if (!isFile(dir, 'package.json')) throw new ConfigurationError('Unable to find package.json in workspace');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we giving up on this? If someone does knip -W ./not-found or if there's no package.json then Knip should err.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const isSelectedFilePath = createWorkspaceFilePathFilter(this.cwd, selectedWorkspaces, availableWorkspaceNames);
if (!isSelectedFilePath) return;
this.workspaceFilter = (filePath: string) => !isSelectedFilePath(filePath);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about creating the filter earlier on, e.g. in createOptions? Then we can set in the constructor directly. Perhaps same for as much as possible for the logic happening in ConfigurationChief.

@fightZy
Copy link
Author

fightZy commented Jan 10, 2026

Thanks for the pull request! This is a valuable feature for large projects indeed. Happy to review, but given the size of the changeset and the fact I'm not sure we should include the Git-based range filter (at least not yet), could you please remove that part?

Regarding Git range filtering, my consideration is that it can conveniently check and report the scope of changes in the CI environment of monorepo projects, thus shortening the execution time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants