Skip to content

Commit 57997e5

Browse files
committedNov 10, 2024·
Use plugin names as binary name fallback (fixes #743)
1 parent a12706d commit 57997e5

File tree

8 files changed

+43
-1
lines changed

8 files changed

+43
-1
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lint-staged

‎packages/knip/fixtures/plugins/husky-v9-1/node_modules/husky/cli.js

Whitespace-only changes.

‎packages/knip/fixtures/plugins/husky-v9-1/node_modules/husky/package.json

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/knip/fixtures/plugins/husky-v9-1/node_modules/lint-staged/cli.js

Whitespace-only changes.

‎packages/knip/fixtures/plugins/husky-v9-1/node_modules/lint-staged/package.json

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "@fixtures/husky-v9-1",
3+
"scripts": {
4+
"prepare": "husky"
5+
},
6+
"devDependencies": {
7+
"husky": "^9.1.3",
8+
"lint-staged": "^15.2.7"
9+
}
10+
}

‎packages/knip/src/binaries/bash-parser.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import parse, { type Assignment, type ExpansionNode, type Node, type Prefix } from '../../vendor/bash-parser/index.js';
2-
import { pluginArgsMap } from '../plugins.js';
2+
import { Plugins, pluginArgsMap } from '../plugins.js';
33
import type { GetInputsFromScriptsOptions } from '../types/config.js';
44
import { debugLogObject } from '../util/debug.js';
55
import { type Input, toBinary, toDeferResolve } from '../util/input.js';
@@ -84,6 +84,10 @@ export const getDependenciesFromScript = (script: string, options: GetInputsFrom
8484
return [toBinary(binary), ...getDependenciesFromScript(command, options)];
8585
}
8686

87+
if (binary in Plugins) {
88+
return [...fallbackResolve(binary, args, { ...options, fromArgs }), ...fromNodeOptions];
89+
}
90+
8791
// Before using the fallback resolver, we need a way to bail out for scripts in CI environments like GitHub
8892
// Actions, which are provisioned with lots of unknown global binaries.
8993
if (options.knownBinsOnly && !text?.startsWith('.')) return [];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { test } from 'bun:test';
2+
import assert from 'node:assert/strict';
3+
import { main } from '../../src/index.js';
4+
import { resolve } from '../../src/util/path.js';
5+
import baseArguments from '../helpers/baseArguments.js';
6+
import baseCounters from '../helpers/baseCounters.js';
7+
8+
const cwd = resolve('fixtures/plugins/husky-v9-1');
9+
10+
test('Find dependencies with husky plugin (v9.1)', async () => {
11+
const { counters } = await main({
12+
...baseArguments,
13+
cwd,
14+
});
15+
16+
assert.deepEqual(counters, {
17+
...baseCounters,
18+
});
19+
});

0 commit comments

Comments
 (0)
Please sign in to comment.