diff --git a/packages/knip/fixtures/npm-scripts/package.json b/packages/knip/fixtures/npm-scripts/package.json index 25318f087..44108f9d7 100644 --- a/packages/knip/fixtures/npm-scripts/package.json +++ b/packages/knip/fixtures/npm-scripts/package.json @@ -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": "*", diff --git a/packages/knip/src/binaries/index.ts b/packages/knip/src/binaries/index.ts index 2f8711d14..65168e40a 100644 --- a/packages/knip/src/binaries/index.ts +++ b/packages/knip/src/binaries/index.ts @@ -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) => { @@ -9,7 +9,8 @@ const getInputsFromScripts: GetInputsFromScripts = (npmScripts, options) => { const inputs = new Set(); 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); } diff --git a/packages/knip/test/npm-scripts.test.ts b/packages/knip/test/npm-scripts.test.ts index af9466fb5..f6d74fe3f 100644 --- a/packages/knip/test/npm-scripts.test.ts +++ b/packages/knip/test/npm-scripts.test.ts @@ -63,6 +63,7 @@ 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']); @@ -70,7 +71,7 @@ test('Unused dependencies in npm scripts', async () => { ...baseCounters, dependencies: 1, devDependencies: 1, - binaries: 2, + binaries: 3, processed: 2, total: 2, });