knip 1.0.1 → 1.0.2

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,2 +1,15 @@
1
1
  export declare const resolvePluginName: (pluginName: string) => string;
2
2
  export declare const resolvePresetName: (pluginName: string) => string;
3
+ export declare const api: {
4
+ assertVersion: () => boolean;
5
+ cache: {
6
+ (): undefined;
7
+ forever(): any;
8
+ never(): any;
9
+ using(): any;
10
+ invalidate(): any;
11
+ };
12
+ caller: () => boolean;
13
+ env: () => boolean;
14
+ version: string;
15
+ };
@@ -20,3 +20,15 @@ export const resolvePresetName = (pluginName) => {
20
20
  }
21
21
  return pluginName;
22
22
  };
23
+ const cacheFn = () => void 0;
24
+ cacheFn.forever = () => cacheFn;
25
+ cacheFn.never = () => cacheFn;
26
+ cacheFn.using = () => cacheFn;
27
+ cacheFn.invalidate = () => cacheFn;
28
+ export const api = {
29
+ assertVersion: () => true,
30
+ cache: cacheFn,
31
+ caller: () => true,
32
+ env: () => true,
33
+ version: '0.0.0',
34
+ };
@@ -3,7 +3,7 @@ import { _load } from '../../util/loader.js';
3
3
  import { getPackageName } from '../../util/modules.js';
4
4
  import { timerify } from '../../util/performance.js';
5
5
  import { hasDependency } from '../../util/plugin.js';
6
- import { resolvePresetName, resolvePluginName } from './helpers.js';
6
+ import { resolvePresetName, resolvePluginName, api } from './helpers.js';
7
7
  export const NAME = 'Babel';
8
8
  export const ENABLERS = [/^@babel\//];
9
9
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
@@ -15,12 +15,10 @@ export const CONFIG_FILE_PATTERNS = [
15
15
  '.babelrc',
16
16
  'package.json',
17
17
  ];
18
- const api = {
19
- caller: () => true,
20
- };
18
+ const getItemName = (value) => typeof value === 'string' ? [value] : Array.isArray(value) ? [value[0]] : [];
21
19
  export const getDependenciesFromConfig = (config) => {
22
- const presets = config.presets?.map(preset => (typeof preset === 'string' ? preset : preset[0])).map(resolvePresetName) ?? [];
23
- const plugins = config.plugins?.map(plugin => (typeof plugin === 'string' ? plugin : plugin[0])).map(resolvePluginName) ?? [];
20
+ const presets = config.presets?.flatMap(getItemName).map(resolvePresetName) ?? [];
21
+ const plugins = config.plugins?.flatMap(getItemName).map(resolvePluginName) ?? [];
24
22
  const nested = config.env ? Object.values(config.env).flatMap(getDependenciesFromConfig) : [];
25
23
  return compact([...presets, ...plugins, ...nested]).map(getPackageName);
26
24
  };
@@ -1,3 +1,5 @@
1
+ import { api } from './helpers.js';
2
+ export type BabelConfigFn = (options: typeof api) => BabelConfig;
1
3
  export type BabelConfig = {
2
4
  plugins?: (string | [string, unknown])[];
3
5
  presets?: (string | [string, unknown])[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
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",
@@ -68,9 +68,9 @@
68
68
  "@types/node": "18.11.18",
69
69
  "@types/npmcli__map-workspaces": "3.0.0",
70
70
  "@types/webpack": "5.28.0",
71
- "@typescript-eslint/eslint-plugin": "5.48.0",
72
- "@typescript-eslint/parser": "5.48.0",
73
- "eslint-import-resolver-typescript": "3.5.2",
71
+ "@typescript-eslint/eslint-plugin": "5.48.1",
72
+ "@typescript-eslint/parser": "5.48.1",
73
+ "eslint-import-resolver-typescript": "3.5.3",
74
74
  "eslint-plugin-import": "2.26.0",
75
75
  "globstar": "1.0.0",
76
76
  "release-it": "15.6.0",