Skip to content

Commit

Permalink
Use plugin names as binary name fallback (fixes #743)
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Nov 10, 2024
1 parent a12706d commit 57997e5
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lint-staged
Empty file.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions packages/knip/fixtures/plugins/husky-v9-1/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "@fixtures/husky-v9-1",
"scripts": {
"prepare": "husky"
},
"devDependencies": {
"husky": "^9.1.3",
"lint-staged": "^15.2.7"
}
}
6 changes: 5 additions & 1 deletion packages/knip/src/binaries/bash-parser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import parse, { type Assignment, type ExpansionNode, type Node, type Prefix } from '../../vendor/bash-parser/index.js';
import { pluginArgsMap } from '../plugins.js';
import { Plugins, pluginArgsMap } from '../plugins.js';
import type { GetInputsFromScriptsOptions } from '../types/config.js';
import { debugLogObject } from '../util/debug.js';
import { type Input, toBinary, toDeferResolve } from '../util/input.js';
Expand Down Expand Up @@ -84,6 +84,10 @@ export const getDependenciesFromScript = (script: string, options: GetInputsFrom
return [toBinary(binary), ...getDependenciesFromScript(command, options)];
}

if (binary in Plugins) {
return [...fallbackResolve(binary, args, { ...options, fromArgs }), ...fromNodeOptions];
}

// Before using the fallback resolver, we need a way to bail out for scripts in CI environments like GitHub
// Actions, which are provisioned with lots of unknown global binaries.
if (options.knownBinsOnly && !text?.startsWith('.')) return [];
Expand Down
19 changes: 19 additions & 0 deletions packages/knip/test/plugins/husky-v9-1.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { test } from 'bun:test';
import assert from 'node:assert/strict';
import { main } from '../../src/index.js';
import { resolve } from '../../src/util/path.js';
import baseArguments from '../helpers/baseArguments.js';
import baseCounters from '../helpers/baseCounters.js';

const cwd = resolve('fixtures/plugins/husky-v9-1');

test('Find dependencies with husky plugin (v9.1)', async () => {
const { counters } = await main({
...baseArguments,
cwd,
});

assert.deepEqual(counters, {
...baseCounters,
});
});

0 comments on commit 57997e5

Please sign in to comment.