Skip to content

Commit

Permalink
Only ignore "http" if in dependency specifier (fixes #813)
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Oct 28, 2024
1 parent e028528 commit 9defcb9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/knip/fixtures/npm-scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"go": "runnable",
"go-live": "deploy -r repo_name",
"tsup": "tsup -c tsup.cool.json",
"tsuppy": "tsup --config tsup.cool.json"
"tsuppy": "tsup --config tsup.cool.json",
"serve": "http-server"
},
"dependencies": {
"express": "*",
Expand Down
5 changes: 3 additions & 2 deletions packages/knip/src/binaries/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { GetInputsFromScripts } from '../types/config.js';
import { timerify } from '../util/Performance.js';
import { type Input, fromBinary, isBinary } from '../util/input.js';
import { type Input, fromBinary, isBinary, isDependency } from '../util/input.js';
import { getDependenciesFromScript } from './bash-parser.js';

const getInputsFromScripts: GetInputsFromScripts = (npmScripts, options) => {
Expand All @@ -9,7 +9,8 @@ const getInputsFromScripts: GetInputsFromScripts = (npmScripts, options) => {
const inputs = new Set<Input>();

for (const input of results) {
if (!input.specifier || input.specifier.startsWith('http')) continue;
if (!input.specifier) continue;
if (isDependency(input) && input.specifier.startsWith('http')) continue;
if (isBinary(input) && !/^\b/.test(fromBinary(input))) continue;
inputs.add(input);
}
Expand Down
3 changes: 2 additions & 1 deletion packages/knip/test/npm-scripts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,15 @@ test('Unused dependencies in npm scripts', async () => {

assert(issues.binaries['package.json']['nodemon']);
assert(issues.binaries['package.json']['dotenv']);
assert(issues.binaries['package.json']['http-server']);
assert(!issues.binaries['package.json']['rm']);
assert(!issues.binaries['package.json']['bash']);

assert.deepEqual(counters, {
...baseCounters,
dependencies: 1,
devDependencies: 1,
binaries: 2,
binaries: 3,
processed: 2,
total: 2,
});
Expand Down

0 comments on commit 9defcb9

Please sign in to comment.