knip 4.0.2 → 4.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@ import { basename } from '../../util/path.js';
2
2
  import { timerify } from '../../util/Performance.js';
3
3
  import { hasDependency, load } from '../../util/plugin.js';
4
4
  const NAME = 'PostCSS';
5
- const ENABLERS = ['postcss', 'next'];
5
+ const ENABLERS = ['postcss', 'postcss-cli', 'next'];
6
6
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
7
7
  const CONFIG_FILE_PATTERNS = ['postcss.config.{cjs,js}', 'postcss.config.json', 'package.json'];
8
8
  const findPostCSSDependencies = async (configFilePath, options) => {
@@ -5,6 +5,12 @@ const NAME = 'Stylelint';
5
5
  const ENABLERS = ['stylelint'];
6
6
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
7
7
  const CONFIG_FILE_PATTERNS = ['.stylelintrc', '.stylelintrc.{cjs,js,json,yaml,yml}', 'stylelint.config.{cjs,mjs,js}'];
8
+ const findDependenciesInConfig = (config) => {
9
+ const extend = config.extends ? [config.extends].flat().filter(id => !isInternal(id)) : [];
10
+ const plugins = config.plugins ? [config.plugins].flat().filter(id => !isInternal(id)) : [];
11
+ const overrideConfigs = 'overrides' in config ? config.overrides.flatMap(findDependenciesInConfig) : [];
12
+ return [...extend, ...plugins, ...overrideConfigs];
13
+ };
8
14
  const findPluginDependencies = async (configFilePath, options) => {
9
15
  const { manifest, isProduction } = options;
10
16
  if (isProduction)
@@ -12,9 +18,7 @@ const findPluginDependencies = async (configFilePath, options) => {
12
18
  const localConfig = basename(configFilePath) === 'package.json' ? manifest.stylelint : await load(configFilePath);
13
19
  if (!localConfig)
14
20
  return [];
15
- const extend = localConfig.extends ? [localConfig.extends].flat().filter(extend => !isInternal(extend)) : [];
16
- const plugins = localConfig.plugins ? [localConfig.plugins].flat().filter(plugin => !isInternal(plugin)) : [];
17
- return [...extend, ...plugins];
21
+ return findDependenciesInConfig(localConfig);
18
22
  };
19
23
  const findDependencies = timerify(findPluginDependencies);
20
24
  export default {
@@ -1,4 +1,7 @@
1
- export type PluginConfig = {
1
+ export type BaseStyleLintConfig = {
2
2
  extends?: string | string[];
3
3
  plugins?: string[];
4
4
  };
5
+ export type StyleLintConfig = BaseStyleLintConfig & {
6
+ overrides: BaseStyleLintConfig[];
7
+ };
@@ -1,5 +1,5 @@
1
1
  import { compact } from '../../util/array.js';
2
- import { join, relative } from '../../util/path.js';
2
+ import { isInternal, join, relative } from '../../util/path.js';
3
3
  import { timerify } from '../../util/Performance.js';
4
4
  import { hasDependency, load } from '../../util/plugin.js';
5
5
  import { toEntryPattern, toProductionEntryPattern } from '../../util/protocols.js';
@@ -23,16 +23,16 @@ const resolveRuleSetDependencies = (rule) => {
23
23
  let useItem = rule.use ?? rule.loader ?? rule;
24
24
  if (typeof useItem === 'function')
25
25
  useItem = useItem(info);
26
- return [useItem].flat().flatMap((useItem) => {
27
- if (!useItem)
26
+ if (typeof useItem === 'string' && hasBabelOptions(rule)) {
27
+ return [useItem, ...getDependenciesFromConfig(rule.options)];
28
+ }
29
+ return [useItem].flat().flatMap((item) => {
30
+ if (!item)
28
31
  return [];
29
- if (hasBabelOptions(useItem)) {
30
- return [
31
- ...resolveUseItem(useItem),
32
- ...getDependenciesFromConfig(useItem.options),
33
- ];
32
+ if (hasBabelOptions(item)) {
33
+ return [...resolveUseItem(item), ...getDependenciesFromConfig(item.options)];
34
34
  }
35
- return resolveUseItem(useItem);
35
+ return resolveUseItem(item);
36
36
  });
37
37
  };
38
38
  const resolveUseItem = (use) => {
@@ -74,9 +74,14 @@ export const findWebpackDependenciesFromConfig = async ({ config, cwd }) => {
74
74
  });
75
75
  }
76
76
  entries.forEach(entry => {
77
- const item = relative(cwd, join(options.context ? options.context : cwd, entry));
78
- const value = options.mode === 'development' ? toEntryPattern(item) : toProductionEntryPattern(item);
79
- entryPatterns.add(value);
77
+ if (!isInternal(entry)) {
78
+ dependencies.add(entry);
79
+ }
80
+ else {
81
+ const item = relative(cwd, join(options.context ? options.context : cwd, entry));
82
+ const value = options.mode === 'development' ? toEntryPattern(item) : toProductionEntryPattern(item);
83
+ entryPatterns.add(value);
84
+ }
80
85
  });
81
86
  }
82
87
  }
@@ -7,7 +7,7 @@ const getImportSpecifiers = (node) => {
7
7
  const importClause = node.argument;
8
8
  if (ts.isLiteralTypeNode(importClause) && ts.isStringLiteral(importClause.literal)) {
9
9
  const identifier = node.qualifier && ts.isIdentifier(node.qualifier) ? String(node.qualifier.escapedText) : 'default';
10
- imports.push({ specifier: importClause.literal.text, identifier, pos: undefined });
10
+ imports.push({ specifier: importClause.literal.text, identifier, pos: importClause.literal.pos });
11
11
  }
12
12
  }
13
13
  ts.forEachChild(node, visit);
@@ -26,11 +26,11 @@ export default visit(isJS, (node, { isFixExports }) => {
26
26
  if (ts.isObjectLiteralExpression(expr) && expr.properties.every(ts.isShorthandPropertyAssignment)) {
27
27
  return expr.properties.map(node => {
28
28
  const fix = isFixExports ? [node.getStart(), node.getEnd()] : undefined;
29
- return { node, identifier: node.getText(), type: SymbolType.UNKNOWN, pos: node.pos, fix };
29
+ return { node, identifier: node.getText(), type: SymbolType.UNKNOWN, pos: node.getStart(), fix };
30
30
  });
31
31
  }
32
32
  else {
33
- return { node, identifier: 'default', type: SymbolType.UNKNOWN, pos: expr.pos, fix: undefined };
33
+ return { node, identifier: 'default', type: SymbolType.UNKNOWN, pos: expr.pos + 1, fix: undefined };
34
34
  }
35
35
  }
36
36
  }
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "4.0.2";
1
+ export declare const version = "4.0.3";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '4.0.2';
1
+ export const version = '4.0.3';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "4.0.2",
3
+ "version": "4.0.3",
4
4
  "description": "Find unused files, dependencies and exports in your TypeScript and JavaScript projects",
5
5
  "homepage": "https://knip.dev",
6
6
  "repository": {