Skip to content

Commit

Permalink
Some plugins only need to run in root
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Nov 10, 2024
1 parent 98318d7 commit 811af53
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/knip/src/WorkspaceWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export class WorkspaceWorker {

for (const [pluginName, plugin] of PluginEntries) {
if (this.config[pluginName] === false) continue;
if (this.cwd !== this.dir && plugin.isRootOnly) continue;
if (this.config[pluginName]) {
this.enabledPluginsMap[pluginName] = true;
continue;
Expand Down
3 changes: 3 additions & 0 deletions packages/knip/src/plugins/changesets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const enablers = ['@changesets/cli'];

const isEnabled: IsPluginEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);

const isRootOnly = true;

const config = ['.changeset/config.json'];

const resolveConfig: ResolveConfig<ChangesetsConfig> = config => {
Expand All @@ -27,6 +29,7 @@ export default {
title,
enablers,
isEnabled,
isRootOnly,
config,
resolveConfig,
} satisfies Plugin;
3 changes: 3 additions & 0 deletions packages/knip/src/plugins/commitizen/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const enablers = ['commitizen'];

const isEnabled: IsPluginEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);

const isRootOnly = true;

const packageJsonPath = 'config.commitizen';

const config = ['.czrc', '.cz.json', 'package.json'];
Expand All @@ -23,6 +25,7 @@ export default {
title,
enablers,
isEnabled,
isRootOnly,
packageJsonPath,
config,
resolveConfig,
Expand Down
3 changes: 3 additions & 0 deletions packages/knip/src/plugins/github-actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const enablers = 'This plugin is enabled when a `.yml` or `.yaml` file is found
const isEnabled: IsPluginEnabled = async ({ cwd }) =>
Boolean(await _firstGlob({ cwd, patterns: ['.github/workflows/*.{yml,yaml}'] }));

const isRootOnly = true;

const config = ['.github/workflows/*.{yml,yaml}', '.github/**/action.{yml,yaml}'];

const isString = (value: unknown): value is string => typeof value === 'string';
Expand Down Expand Up @@ -73,6 +75,7 @@ export default {
title,
enablers,
isEnabled,
isRootOnly,
config,
resolveConfig,
} satisfies Plugin;
3 changes: 3 additions & 0 deletions packages/knip/src/plugins/husky/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const enablers = ['husky'];

const isEnabled: IsPluginEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);

const isRootOnly = true;

// husky v9 registers hooks in .husky/_/, so need to set "false" here to get same lookup as in v8
const gitHookPaths = getGitHookPaths('.husky', false);

Expand All @@ -35,6 +37,7 @@ export default {
title,
enablers,
isEnabled,
isRootOnly,
config,
resolveConfig,
} satisfies Plugin;
3 changes: 3 additions & 0 deletions packages/knip/src/plugins/semantic-release/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const enablers = ['semantic-release'];

const isEnabled: IsPluginEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);

const isRootOnly = true;

const packageJsonPath = 'release';

const config = ['package.json', ...toCosmiconfig('release')];
Expand All @@ -25,6 +27,7 @@ export default {
title,
enablers,
isEnabled,
isRootOnly,
packageJsonPath,
config,
resolveConfig,
Expand Down
3 changes: 3 additions & 0 deletions packages/knip/src/plugins/travis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const enablers = 'This plugin is enabled when a `.travis.yml` file is found in t

const isEnabled: IsPluginEnabled = async ({ cwd }) => (await _glob({ cwd, patterns: ['.travis.yml'] })).length > 0;

const isRootOnly = true;

const config = ['.travis.yml'];

const resolveConfig: ResolveConfig = async (config, options) => {
Expand All @@ -27,6 +29,7 @@ export default {
title,
enablers,
isEnabled,
isRootOnly,
config,
resolveConfig,
} satisfies Plugin;
1 change: 1 addition & 0 deletions packages/knip/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export interface Plugin {
packageJsonPath?: string | ((manifest: PackageJson) => string);
enablers?: IgnorePatterns | string;
isEnabled?: IsPluginEnabled;
isRootOnly?: boolean;
config?: string[];
entry?: string[];
production?: string[];
Expand Down

0 comments on commit 811af53

Please sign in to comment.