knip 2.42.0 → 2.43.0

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.
@@ -1,5 +1,4 @@
1
- export declare const resolvePluginName: (pluginName: string) => string;
2
- export declare const resolvePresetName: (pluginName: string) => string;
1
+ export declare const resolveName: (identifier: string, namespace: 'preset' | 'plugin') => string;
3
2
  export declare const api: {
4
3
  assertVersion: () => boolean;
5
4
  cache: {
@@ -1,24 +1,32 @@
1
- export const resolvePluginName = (pluginName) => {
2
- if (!/babel/.test(pluginName))
3
- return `babel-plugin-${pluginName}`;
4
- if (pluginName.startsWith('@babel/')) {
5
- if (pluginName.startsWith('@babel/plugin'))
6
- return pluginName;
7
- const [, name] = pluginName.split('/');
8
- return `@babel/plugin-${name}`;
1
+ import { isAbsolute, isInternal } from '../../util/path.js';
2
+ export const resolveName = (identifier, namespace) => {
3
+ if (isAbsolute(identifier) || isInternal(identifier))
4
+ return identifier;
5
+ if (identifier.startsWith('module:'))
6
+ return identifier.replace(/^module:/, '');
7
+ if (identifier.startsWith('@')) {
8
+ const [scope, name, ...rest] = identifier.split('/');
9
+ if (rest.length > 0)
10
+ return identifier;
11
+ if (scope) {
12
+ if (!name)
13
+ return [scope, `babel-${namespace}`].join('/');
14
+ if (scope === '@babel') {
15
+ if (name.startsWith(namespace))
16
+ return identifier;
17
+ return `@babel/${namespace}-${name}`;
18
+ }
19
+ if (name.includes(`babel-${namespace}`))
20
+ return identifier;
21
+ return [scope, `babel-${namespace}-${name}`].join('/');
22
+ }
9
23
  }
10
- return pluginName;
11
- };
12
- export const resolvePresetName = (pluginName) => {
13
- if (!/babel/.test(pluginName))
14
- return `babel-preset-${pluginName}`;
15
- if (pluginName.startsWith('@babel/')) {
16
- if (pluginName.startsWith('@babel/preset'))
17
- return pluginName;
18
- const [, name] = pluginName.split('/');
19
- return `@babel/preset-${name}`;
20
- }
21
- return pluginName;
24
+ const [name, ...rest] = identifier.split('/');
25
+ if (rest.length > 0)
26
+ return identifier;
27
+ if (name.startsWith(`babel-${namespace}`))
28
+ return identifier;
29
+ return `babel-${namespace}-${name}`;
22
30
  };
23
31
  const cacheFn = () => void 0;
24
32
  cacheFn.forever = () => cacheFn;
@@ -1,22 +1,20 @@
1
1
  import { compact } from '../../util/array.js';
2
2
  import { timerify } from '../../util/Performance.js';
3
3
  import { hasDependency, load } from '../../util/plugin.js';
4
- import { resolvePresetName, resolvePluginName, api } from './helpers.js';
4
+ import { resolveName, api } from './helpers.js';
5
5
  export const NAME = 'Babel';
6
6
  export const ENABLERS = [/^@babel\//];
7
7
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
8
8
  export const CONFIG_FILE_PATTERNS = [
9
- 'babel.config.json',
10
- 'babel.config.js',
11
- '.babelrc.json',
12
- '.babelrc.js',
9
+ 'babel.config.{json,js,cjs,mjs,cts}',
10
+ '.babelrc.{json,js,cjs,mjs,cts}',
13
11
  '.babelrc',
14
12
  'package.json',
15
13
  ];
16
- const getItemName = (value) => typeof value === 'string' ? [value] : Array.isArray(value) ? [value[0]] : [];
14
+ const getName = (value) => typeof value === 'string' ? [value] : Array.isArray(value) ? [value[0]] : [];
17
15
  export const getDependenciesFromConfig = (config) => {
18
- const presets = config.presets?.flatMap(getItemName).map(resolvePresetName) ?? [];
19
- const plugins = config.plugins?.flatMap(getItemName).map(resolvePluginName) ?? [];
16
+ const presets = config.presets?.flatMap(getName).map(name => resolveName(name, 'preset')) ?? [];
17
+ const plugins = config.plugins?.flatMap(getName).map(name => resolveName(name, 'plugin')) ?? [];
20
18
  const nested = config.env ? Object.values(config.env).flatMap(getDependenciesFromConfig) : [];
21
19
  return compact([...presets, ...plugins, ...nested]);
22
20
  };
@@ -7,4 +7,4 @@ export var SymbolType;
7
7
  SymbolType["CLASS"] = "class";
8
8
  SymbolType["MEMBER"] = "member";
9
9
  SymbolType["UNKNOWN"] = "unknown";
10
- })(SymbolType || (SymbolType = {}));
10
+ })(SymbolType = SymbolType || (SymbolType = {}));
@@ -6,7 +6,12 @@ export default visit(() => true, node => {
6
6
  if (node.exportClause && ts.isNamedExports(node.exportClause)) {
7
7
  const type = node.isTypeOnly ? SymbolType.TYPE : SymbolType.UNKNOWN;
8
8
  return node.exportClause.elements.map(element => {
9
- return { node: element, identifier: element.name.getText(), type, pos: element.name.pos };
9
+ return {
10
+ node: element,
11
+ identifier: element.name.getText(),
12
+ type,
13
+ pos: element.name.flowNode?.node?.pos ?? element.name.pos,
14
+ };
10
15
  });
11
16
  }
12
17
  }
@@ -1,3 +1,2 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
1
  declare let parseArgs: typeof import('node:util').parseArgs;
3
2
  export { parseArgs };
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "2.42.0";
1
+ export declare const version = "2.43.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '2.42.0';
1
+ export const version = '2.43.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "2.42.0",
3
+ "version": "2.43.0",
4
4
  "description": "Find unused files, dependencies and exports in your TypeScript and JavaScript projects",
5
5
  "homepage": "https://github.com/webpro/knip",
6
6
  "repository": "github:webpro/knip",