knip 1.13.0 → 1.14.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,6 +1,6 @@
1
- import { SourceFile } from 'ts-morph';
2
1
  import { LineRewriter } from './util/log.js';
3
2
  import type { Issue, Report } from './types/issues.js';
3
+ import type { SourceFile } from 'ts-morph';
4
4
  type IssueCollectorOptions = {
5
5
  cwd: string;
6
6
  isShowProgress?: boolean;
@@ -1,8 +1,8 @@
1
- import { ESLint } from 'eslint';
2
1
  import { compact } from '../../util/array.js';
3
2
  import { getPackageName } from '../../util/modules.js';
4
3
  import { resolvePluginPackageName, getDependenciesFromSettings } from './helpers.js';
5
4
  export const fallback = async (configFilePath, { cwd }) => {
5
+ const { ESLint } = await import('eslint');
6
6
  const engine = new ESLint({ cwd, overrideConfigFile: configFilePath, useEslintrc: false });
7
7
  const jsConfig = await engine.calculateConfigForFile('__placeholder__.js');
8
8
  const tsConfig = await engine.calculateConfigForFile('__placeholder__.ts');
@@ -2,6 +2,7 @@ import path from 'node:path';
2
2
  import { compact } from '../../util/array.js';
3
3
  import { _load } from '../../util/loader.js';
4
4
  import { getPackageName } from '../../util/modules.js';
5
+ import { isAbsolute } from '../../util/path.js';
5
6
  import { require } from '../../util/require.js';
6
7
  const getDependencies = (config) => {
7
8
  const extend = config.extends ? [config.extends].flat().map(customResolvePluginPackageNames) : [];
@@ -18,8 +19,8 @@ export const getDependenciesDeep = async (configFilePath, dependencies = new Set
18
19
  const config = await _load(configFilePath);
19
20
  if (config.extends) {
20
21
  for (const extend of [config.extends].flat()) {
21
- if (extend.startsWith('.') || (extend.startsWith('/') && !extend.includes('/node_modules/'))) {
22
- const extendConfigFilePath = extend.startsWith('/')
22
+ if (extend.startsWith('.') || (isAbsolute(extend) && !extend.includes('/node_modules/'))) {
23
+ const extendConfigFilePath = isAbsolute(extend)
23
24
  ? extend
24
25
  : require.resolve(path.join(path.dirname(configFilePath), extend));
25
26
  addAll(await getDependenciesDeep(extendConfigFilePath));
@@ -43,7 +44,7 @@ export const resolvePluginPackageName = (pluginName) => resolvePackageName('esli
43
44
  const customResolvePluginPackageNames = (extend) => {
44
45
  if (extend.includes('/node_modules/'))
45
46
  return getPackageName(extend);
46
- if (extend.startsWith('/') || extend.startsWith('.'))
47
+ if (isAbsolute(extend) || extend.startsWith('.'))
47
48
  return;
48
49
  if (extend.includes(':')) {
49
50
  const pluginName = extend.replace(/^plugin:/, '').replace(/(\/|:).+$/, '');
@@ -1,6 +1,7 @@
1
1
  import path from 'node:path';
2
2
  import { _load } from '../../util/loader.js';
3
3
  import { getPackageName } from '../../util/modules.js';
4
+ import { isAbsolute } from '../../util/path.js';
4
5
  import { timerify } from '../../util/performance.js';
5
6
  import { hasDependency } from '../../util/plugin.js';
6
7
  import { require } from '../../util/require.js';
@@ -13,8 +14,8 @@ const resolveExtensibleConfig = async (configFilePath) => {
13
14
  const config = await _load(configFilePath);
14
15
  if (config?.preset) {
15
16
  const { preset } = config;
16
- if (preset.startsWith('.') || preset.startsWith('/')) {
17
- const presetConfigPath = preset.startsWith('/') ? preset : path.join(path.dirname(configFilePath), preset);
17
+ if (preset.startsWith('.') || isAbsolute(preset)) {
18
+ const presetConfigPath = isAbsolute(preset) ? preset : path.join(path.dirname(configFilePath), preset);
18
19
  const presetConfig = await resolveExtensibleConfig(presetConfigPath);
19
20
  Object.assign(config, presetConfig);
20
21
  }
@@ -32,7 +33,7 @@ const findJestDependencies = async (configFilePath, { cwd }) => {
32
33
  if (name.startsWith('.')) {
33
34
  entryFiles.push(require.resolve(path.join(path.dirname(configFilePath), name)));
34
35
  }
35
- else if (name.startsWith('/')) {
36
+ else if (isAbsolute(name)) {
36
37
  entryFiles.push(name);
37
38
  }
38
39
  else {
@@ -1,6 +1,7 @@
1
1
  import path from 'node:path';
2
2
  import { _load } from '../../util/loader.js';
3
3
  import { getPackageName } from '../../util/modules.js';
4
+ import { isAbsolute } from '../../util/path.js';
4
5
  import { timerify } from '../../util/performance.js';
5
6
  import { hasDependency } from '../../util/plugin.js';
6
7
  import { require } from '../../util/require.js';
@@ -21,7 +22,7 @@ const findStorybookDependencies = async (configFilePath) => {
21
22
  if (name.startsWith('.')) {
22
23
  entryFiles.push(require.resolve(path.join(path.dirname(configFilePath), name)));
23
24
  }
24
- else if (name.startsWith('/')) {
25
+ else if (isAbsolute(name)) {
25
26
  entryFiles.push(configFilePath);
26
27
  }
27
28
  else {
@@ -2,6 +2,7 @@ import path from 'node:path';
2
2
  import { compact } from '../../util/array.js';
3
3
  import { _load } from '../../util/loader.js';
4
4
  import { getPackageName } from '../../util/modules.js';
5
+ import { isAbsolute } from '../../util/path.js';
5
6
  import { timerify } from '../../util/performance.js';
6
7
  import { hasDependency } from '../../util/plugin.js';
7
8
  import { getDependenciesFromConfig } from '../babel/index.js';
@@ -61,7 +62,7 @@ const findWebpackDependencies = async (configFilePath, { cwd, manifest, isProduc
61
62
  ? cfg.entry
62
63
  : Object.values(cfg.entry).map(entry => (typeof entry === 'string' ? entry : entry.filename));
63
64
  entries.forEach(entry => {
64
- entryFiles.add(entry.startsWith('/') ? entry : path.join(cwd, entry));
65
+ entryFiles.add(isAbsolute(entry) ? entry : path.join(cwd, entry));
65
66
  });
66
67
  }
67
68
  return dependencies;
@@ -1,5 +1,4 @@
1
- import { Project, SourceFile } from 'ts-morph';
2
- import type { ProjectOptions } from 'ts-morph';
1
+ import type { Project, ProjectOptions, SourceFile } from 'ts-morph';
3
2
  import type { TsConfigJson } from 'type-fest';
4
3
  export default class ProjectPrincipal {
5
4
  projectOptions?: ProjectOptions;
@@ -1,5 +1,5 @@
1
- import { SourceFile } from 'ts-morph';
2
1
  import type { Report, Issue } from './types/issues.js';
2
+ import type { SourceFile } from 'ts-morph';
3
3
  type FileLabOptions = {
4
4
  report: Report;
5
5
  workspaceDirs: string[];
@@ -1,11 +1,12 @@
1
1
  import { IGNORED_GLOBAL_BINARIES } from '../../constants.js';
2
2
  import { compact } from '../array.js';
3
3
  import { getPackageNameFromModuleSpecifier, stripBinary } from '../modules.js';
4
+ import { isAbsolute } from '../path.js';
4
5
  import { timerify } from '../performance.js';
5
6
  import { getBinariesFromScript } from './bash-parser.js';
6
7
  const defaultCwd = process.cwd();
7
8
  const partition = (values) => values.reduce((acc, value) => {
8
- acc[/^(\/|[A-Z]:)/.test(value) ? 1 : 0].push(value);
9
+ acc[isAbsolute(value) ? 1 : 0].push(value);
9
10
  return acc;
10
11
  }, [[], []]);
11
12
  const getReferencesFromScripts = (npmScripts, options = {}) => {
@@ -1,2 +1,3 @@
1
1
  export declare const toPosixPath: (value: string) => string;
2
2
  export declare const relativePosix: (from: string, to?: string) => string;
3
+ export declare const isAbsolute: (value: string) => boolean;
package/dist/util/path.js CHANGED
@@ -2,3 +2,4 @@ import path from 'node:path';
2
2
  const cwd = process.cwd();
3
3
  export const toPosixPath = (value) => value.split(path.sep).join(path.posix.sep);
4
4
  export const relativePosix = (from, to) => toPosixPath(path.relative(to ? from : cwd, to ?? from));
5
+ export const isAbsolute = (value) => /^(\/|[A-Z]:)/.test(value);
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "1.13.0";
1
+ export declare const version = "1.14.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '1.13.0';
1
+ export const version = '1.14.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "1.13.0",
3
+ "version": "1.14.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",
@@ -47,7 +47,6 @@
47
47
  "easy-table": "^1.2.0",
48
48
  "esbuild": "^0.17.10",
49
49
  "esbuild-register": "3.4.2",
50
- "eslint": "^8.34.0",
51
50
  "fast-glob": "^3.2.12",
52
51
  "get-tsconfig": "^4.4.0",
53
52
  "globby": "^13.1.3",
@@ -71,20 +70,21 @@
71
70
  "@types/js-yaml": "4.0.5",
72
71
  "@types/micromatch": "4.0.2",
73
72
  "@types/minimist": "1.2.2",
74
- "@types/node": "18.14.0",
73
+ "@types/node": "18.14.2",
75
74
  "@types/npmcli__map-workspaces": "3.0.0",
76
75
  "@types/webpack": "5.28.0",
77
- "@typescript-eslint/eslint-plugin": "5.53.0",
78
- "@typescript-eslint/parser": "5.53.0",
76
+ "@typescript-eslint/eslint-plugin": "5.54.0",
77
+ "@typescript-eslint/parser": "5.54.0",
78
+ "eslint": "8.35.0",
79
79
  "eslint-import-resolver-typescript": "3.5.3",
80
80
  "eslint-plugin-import": "2.27.5",
81
81
  "globstar": "1.0.0",
82
82
  "prettier": "2.8.4",
83
- "release-it": "15.6.0",
83
+ "release-it": "^15.6.1",
84
84
  "remark-cli": "11.0.0",
85
85
  "remark-preset-webpro": "0.0.1",
86
86
  "tsx": "3.12.3",
87
- "type-fest": "3.6.0",
87
+ "type-fest": "3.6.1",
88
88
  "typescript": "4.9.5"
89
89
  },
90
90
  "engines": {