knip 5.76.0 → 5.76.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,7 +1,7 @@
1
1
  import parseArgs from 'minimist';
2
- import { isFile } from '../../util/fs.js';
3
2
  import { toEntry } from '../../util/input.js';
4
3
  import { isAbsolute, join } from '../../util/path.js';
4
+ import { _resolveSync } from '../../util/resolve.js';
5
5
  import { resolveX } from './bunx.js';
6
6
  const commands = [
7
7
  'add',
@@ -46,9 +46,12 @@ export const resolve = (_binary, args, options) => {
46
46
  if (command !== 'run' && commands.includes(command))
47
47
  return [];
48
48
  const filePath = command === 'run' ? script : command;
49
- const absFilePath = isAbsolute(filePath) ? filePath : join(cwd, filePath);
50
- if (isFile(absFilePath))
51
- return [toEntry(absFilePath)];
49
+ if (!filePath)
50
+ return [];
51
+ const _cwd = parsed.cwd ? join(cwd, parsed.cwd) : cwd;
52
+ const resolved = _resolveSync(isAbsolute(filePath) ? filePath : join(_cwd, filePath), _cwd);
53
+ if (resolved)
54
+ return [toEntry(resolved)];
52
55
  const dir = parsed.cwd ? join(cwd, parsed.cwd) : undefined;
53
56
  const opts = dir ? { cwd: dir } : {};
54
57
  return command === 'run' ? [] : fromArgs(args, opts);
@@ -1,7 +1,12 @@
1
1
  import parseArgs from 'minimist';
2
2
  export const resolve = (_binary, args, options) => {
3
- const { fromArgs } = options;
4
- const parsed = parseArgs(args);
5
- const [command] = parsed._;
6
- return command !== 'exec' ? [] : fromArgs(parsed._.slice(1));
3
+ const { fromArgs, manifestScriptNames } = options;
4
+ const parsed = parseArgs(args, { '--': true });
5
+ const [command, script] = parsed._;
6
+ const _childArgs = parsed['--'] && parsed['--'].length > 0 ? fromArgs(parsed['--']) : [];
7
+ if (command === 'exec')
8
+ return _childArgs;
9
+ if (command === 'run' && manifestScriptNames.has(script))
10
+ return _childArgs;
11
+ return [];
7
12
  };
@@ -64,6 +64,7 @@ export const resolve = (_binary, args, options) => {
64
64
  const parsed = parseArgs(args, {
65
65
  boolean: ['recursive', 'silent', 'shell-mode'],
66
66
  alias: { recursive: 'r', silent: 's', 'shell-mode': 'c', filter: 'F' },
67
+ '--': true,
67
68
  });
68
69
  const [command] = parsed._;
69
70
  if (command === 'dlx') {
@@ -73,9 +74,12 @@ export const resolve = (_binary, args, options) => {
73
74
  const { manifestScriptNames, fromArgs } = options;
74
75
  if (parsed.filter && !parsed.recursive)
75
76
  return [];
76
- if (manifestScriptNames.has(command) || commands.includes(command))
77
- return [];
78
- if (command === 'exec')
79
- return fromArgs(parsed._.slice(1));
77
+ const childInputs = parsed['--'] && parsed['--'].length > 0 ? fromArgs(parsed['--']) : [];
78
+ if (command === 'exec') {
79
+ return childInputs.length > 0 ? childInputs : fromArgs(parsed._.slice(1));
80
+ }
81
+ const isScript = manifestScriptNames.has(command);
82
+ if (isScript || commands.includes(command))
83
+ return childInputs;
80
84
  return command ? [toBinary(command)] : [];
81
85
  };
@@ -50,18 +50,19 @@ const resolveDlx = (args, options) => {
50
50
  };
51
51
  export const resolve = (_binary, args, options) => {
52
52
  const { manifestScriptNames, fromArgs, cwd, rootCwd } = options;
53
- const parsed = parseArgs(args, { boolean: ['top-level'], string: ['cwd'] });
53
+ const parsed = parseArgs(args, { boolean: ['top-level'], string: ['cwd'], '--': true });
54
54
  const dir = parsed['top-level'] ? rootCwd : parsed.cwd ? join(cwd, parsed.cwd) : undefined;
55
55
  const [command, binary] = parsed._;
56
56
  if (!command && !binary)
57
57
  return [];
58
+ const _childArgs = parsed['--'] && parsed['--'].length > 0 ? fromArgs(parsed['--']) : [];
58
59
  if (command === 'run') {
59
60
  if (manifestScriptNames.has(binary))
60
- return [];
61
+ return _childArgs;
61
62
  const bin = toBinary(binary, { optional: true });
62
63
  if (dir)
63
64
  Object.assign(bin, { dir });
64
- return [bin];
65
+ return [bin, ..._childArgs];
65
66
  }
66
67
  if (command === 'node')
67
68
  return fromArgs(parsed._);
@@ -70,7 +71,7 @@ export const resolve = (_binary, args, options) => {
70
71
  return resolveDlx(argsForDlx, options);
71
72
  }
72
73
  if ((!dir && manifestScriptNames.has(command)) || commands.includes(command))
73
- return [];
74
+ return _childArgs;
74
75
  const opts = dir ? { cwd: dir } : {};
75
76
  return fromArgs(argsFrom(args, command === 'exec' ? binary : command), opts);
76
77
  };
package/dist/cli.js CHANGED
@@ -30,7 +30,7 @@ const run = async () => {
30
30
  console.log(version);
31
31
  process.exit(0);
32
32
  }
33
- const { issues, counters, tagHints, configurationHints, includedWorkspaceDirs } = await main(options);
33
+ const { issues, counters, tagHints, configurationHints, includedWorkspaceDirs, enabledPlugins } = await main(options);
34
34
  if (options.isWatch || options.isTrace)
35
35
  return;
36
36
  const initialData = {
@@ -39,6 +39,7 @@ const run = async () => {
39
39
  counters,
40
40
  tagHints,
41
41
  configurationHints,
42
+ enabledPlugins,
42
43
  includedWorkspaceDirs,
43
44
  cwd: options.cwd,
44
45
  configFilePath: options.configFilePath,
@@ -24,5 +24,6 @@ export declare function build({ chief, collector, counselor, deputy, factory, is
24
24
  analyzedFiles: Set<string>;
25
25
  unreferencedFiles: Set<string>;
26
26
  analyzeSourceFile: (filePath: string, principal: ProjectPrincipal) => void;
27
+ enabledPluginsStore: Map<string, string[]>;
27
28
  }>;
28
29
  export {};
@@ -397,5 +397,6 @@ export async function build({ chief, collector, counselor, deputy, factory, isGi
397
397
  analyzedFiles,
398
398
  unreferencedFiles,
399
399
  analyzeSourceFile,
400
+ enabledPluginsStore,
400
401
  };
401
402
  }
@@ -49,7 +49,7 @@ export const walkDown = (graph, filePath, identifier, visitor, entryPaths, visit
49
49
  done = true;
50
50
  break;
51
51
  }
52
- if (!isEntry && walkDown(graph, reExportingFile, identifier, visitor, entryPaths, visited)) {
52
+ if (walkDown(graph, reExportingFile, identifier, visitor, entryPaths, visited)) {
53
53
  done = true;
54
54
  break;
55
55
  }
@@ -66,12 +66,9 @@ export const walkDown = (graph, filePath, identifier, visitor, entryPaths, visit
66
66
  done = true;
67
67
  break;
68
68
  }
69
- if (!isEntry) {
70
- const ref = [alias, ...restIds].join('.');
71
- if (walkDown(graph, reExportingFile, ref, visitor, entryPaths, visited)) {
72
- done = true;
73
- break;
74
- }
69
+ if (walkDown(graph, reExportingFile, [alias, ...restIds].join('.'), visitor, entryPaths, visited)) {
70
+ done = true;
71
+ break;
75
72
  }
76
73
  }
77
74
  if (done)
@@ -87,7 +84,7 @@ export const walkDown = (graph, filePath, identifier, visitor, entryPaths, visit
87
84
  done = true;
88
85
  break;
89
86
  }
90
- if (!isEntry && walkDown(graph, reExportingFile, `${namespace}.${identifier}`, visitor, entryPaths, visited)) {
87
+ if (walkDown(graph, reExportingFile, `${namespace}.${identifier}`, visitor, entryPaths, visited)) {
91
88
  done = true;
92
89
  break;
93
90
  }
@@ -105,7 +102,7 @@ export const walkDown = (graph, filePath, identifier, visitor, entryPaths, visit
105
102
  done = true;
106
103
  break;
107
104
  }
108
- if (!isEntry && walkDown(graph, reExportingFile, identifier, visitor, entryPaths, visited)) {
105
+ if (walkDown(graph, reExportingFile, identifier, visitor, entryPaths, visited)) {
109
106
  done = true;
110
107
  break;
111
108
  }
package/dist/index.d.ts CHANGED
@@ -5,4 +5,7 @@ export declare const main: (options: MainOptions) => Promise<{
5
5
  tagHints: Set<import("./types/issues.js").TagHint>;
6
6
  configurationHints: Set<import("./types/issues.js").ConfigurationHint>;
7
7
  includedWorkspaceDirs: string[];
8
+ enabledPlugins: {
9
+ [k: string]: string[];
10
+ };
8
11
  }>;
@@ -1,3 +1,6 @@
1
1
  import type { Plugin } from '../../types/config.js';
2
+ export declare const docs: {
3
+ note: string;
4
+ };
2
5
  declare const plugin: Plugin;
3
6
  export default plugin;
@@ -51,6 +51,9 @@ const resolveConfig = async (localConfig, options) => {
51
51
  const args = {
52
52
  fromArgs: (parsed) => (parsed._[0] === 'exec' ? parsed._.slice(1) : []),
53
53
  };
54
+ export const docs = {
55
+ note: `Also see [integrated monorepos](/features/integrated-monorepos) and the note regarding internal workspace dependencies.`,
56
+ };
54
57
  const plugin = {
55
58
  title,
56
59
  enablers,
@@ -19,4 +19,4 @@ export declare const finalizeConfigurationHints: (results: Results, options: {
19
19
  cwd: string;
20
20
  configFilePath?: string;
21
21
  }) => ProcessedHint[];
22
- export declare const printConfigurationHints: ({ cwd, counters, issues, tagHints, configurationHints, isTreatConfigHintsAsErrors, includedWorkspaceDirs, configFilePath, }: ReporterOptions) => void;
22
+ export declare const printConfigurationHints: ({ cwd, counters, issues, tagHints, configurationHints, enabledPlugins, isTreatConfigHintsAsErrors, includedWorkspaceDirs, configFilePath, }: ReporterOptions) => void;
@@ -102,8 +102,8 @@ export const finalizeConfigurationHints = (results, options) => {
102
102
  return row;
103
103
  }));
104
104
  };
105
- export const printConfigurationHints = ({ cwd, counters, issues, tagHints, configurationHints, isTreatConfigHintsAsErrors, includedWorkspaceDirs, configFilePath, }) => {
106
- const rows = finalizeConfigurationHints({ issues, counters, configurationHints, tagHints, includedWorkspaceDirs }, { cwd, configFilePath });
105
+ export const printConfigurationHints = ({ cwd, counters, issues, tagHints, configurationHints, enabledPlugins, isTreatConfigHintsAsErrors, includedWorkspaceDirs, configFilePath, }) => {
106
+ const rows = finalizeConfigurationHints({ issues, counters, configurationHints, tagHints, includedWorkspaceDirs, enabledPlugins }, { cwd, configFilePath });
107
107
  if (rows.length > 0) {
108
108
  const getTitle = isTreatConfigHintsAsErrors ? getColoredTitle : getDimmedTitle;
109
109
  console.log(getTitle('Configuration hints', configurationHints.size));
package/dist/run.d.ts CHANGED
@@ -8,6 +8,9 @@ export declare const run: (options: MainOptions) => Promise<{
8
8
  tagHints: Set<import("./types/issues.js").TagHint>;
9
9
  configurationHints: Set<import("./types/issues.js").ConfigurationHint>;
10
10
  includedWorkspaceDirs: string[];
11
+ enabledPlugins: {
12
+ [k: string]: string[];
13
+ };
11
14
  };
12
15
  session: {
13
16
  listener: import("fs").WatchListener<string | Buffer<ArrayBufferLike>>;
package/dist/run.js CHANGED
@@ -29,7 +29,7 @@ export const run = async (options) => {
29
29
  collector.setIgnoreIssues(chief.config.ignoreIssues);
30
30
  debugLogObject('*', 'Included workspaces', () => workspaces.map(w => w.pkgName));
31
31
  debugLogObject('*', 'Included workspace configs', () => workspaces.map(w => ({ pkgName: w.pkgName, name: w.name, config: w.config, ancestors: w.ancestors })));
32
- const { graph, entryPaths, analyzedFiles, unreferencedFiles, analyzeSourceFile } = await build({
32
+ const { graph, entryPaths, analyzedFiles, unreferencedFiles, analyzeSourceFile, enabledPluginsStore } = await build({
33
33
  chief,
34
34
  collector,
35
35
  counselor,
@@ -100,6 +100,7 @@ export const run = async (options) => {
100
100
  tagHints,
101
101
  configurationHints,
102
102
  includedWorkspaceDirs: chief.includedWorkspaces.map(w => w.dir),
103
+ enabledPlugins: Object.fromEntries(enabledPluginsStore),
103
104
  },
104
105
  session,
105
106
  streamer,
@@ -55,6 +55,7 @@ export type ReporterOptions = {
55
55
  counters: Counters;
56
56
  tagHints: TagHints;
57
57
  configurationHints: Set<ConfigurationHint>;
58
+ enabledPlugins: Record<string, string[]>;
58
59
  isDisableConfigHints: boolean;
59
60
  isTreatConfigHintsAsErrors: boolean;
60
61
  cwd: string;
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "5.76.0";
1
+ export declare const version = "5.76.2";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '5.76.0';
1
+ export const version = '5.76.2';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "5.76.0",
3
+ "version": "5.76.2",
4
4
  "description": "Find and fix unused dependencies, exports and files in your TypeScript and JavaScript projects",
5
5
  "homepage": "https://knip.dev",
6
6
  "repository": {