Skip to content

Commit

Permalink
fix(plugin/babel): bypass directly required plugins or presets in bab…
Browse files Browse the repository at this point in the history
…el config (#590)
  • Loading branch information
mridgway authored Apr 9, 2024
1 parent dbcc599 commit 77329af
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/knip/fixtures/plugins/babel/.babelrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const config = {
},
},
],
// Simulates a required plugin, should not be added to the unspecified plugins array
function myCustomPlugin() {}
],
};

Expand Down
2 changes: 1 addition & 1 deletion packages/knip/src/plugins/babel/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const isEnabled: IsPluginEnabled = ({ dependencies }) => hasDependency(dependenc
const config = ['babel.config.{json,js,cjs,mjs,cts}', '.babelrc.{json,js,cjs,mjs,cts}', '.babelrc', 'package.json'];

const getName = (value: string | [string, unknown]) =>
typeof value === 'string' ? [value] : Array.isArray(value) ? [value[0]] : [];
[Array.isArray(value) ? value[0] : value].filter(name => typeof name === 'string');

export const getDependenciesFromConfig = (config: BabelConfigObj): string[] => {
const presets = config.presets?.flatMap(getName).map(name => resolveName(name, 'preset')) ?? [];
Expand Down

0 comments on commit 77329af

Please sign in to comment.