Skip to content

feat: detect execaNode scripts in execa visitor#1824

Merged
webpro merged 1 commit into
webpro-nl:mainfrom
gwagjiug:fix/execa-node-script-visitor
Jun 27, 2026
Merged

feat: detect execaNode scripts in execa visitor#1824
webpro merged 1 commit into
webpro-nl:mainfrom
gwagjiug:fix/execa-node-script-visitor

Conversation

@gwagjiug

Copy link
Copy Markdown
Contributor

Problem

The Execa script visitor did not detect Node.js scripts executed with execaNode.

For example:

await execaNode('build.mjs');
await execaNode`build.mjs`;

Both calls execute build.mjs as a Node.js script, so Knip should treat build.mjs as a used entry file. Without this handling, files executed only through execaNode could be reported as unused.

Cause

Knip collects scripts from Execa APIs in packages/knip/src/plugins/execa/visitors/execa.ts.

The visitor already handled APIs such as:

execa(...)
execaSync(...)
execaCommand(...)
execaCommandSync(...)
$sync(...)
$`...`

However, it did not handle execaNode.

This looks like an omission rather than intentional behavior. The existing fixture in packages/knip/fixtures/plugin-config/script-visitors-execa/methods.mjs already imported execaNode, but it did not include any actual execaNode call:

import { execa, execaSync, execaCommand, execaCommandSync, execaNode, $sync } from 'execa';

So the fixture acknowledged the API, but the visitor did not verify that scripts executed through that API were collected.

The Execa API reference documents execaNode(scriptPath, arguments?, options?) as the preferred API for executing Node.js files. It runs a Node.js file as node scriptPath ...arguments.

References:

Because of this, execaNode('build.mjs') and execaNode\build.mjs`` should be treated as script entry usage by Knip.

Changes

This PR adds execaNode support to the Execa script visitor.

  • Detects execaNode('file.mjs').
  • Detects execaNode\file.mjs``.
  • Converts those calls to node file.mjs before passing them to the existing script parser.
  • Keeps the existing $ and $sync tagged template handling unchanged.
  • Extends the existing Execa fixture with execaNode call and tagged template cases.
  • Adds assertions to verify that files executed through execaNode are not reported as unused.

Impact

Files executed through execaNode will no longer be reported as unused files.

This reduces false positives in projects that use Execa to run build scripts, release scripts, code generation scripts, or other local Node.js entry files.

Verification

node_modules/.bin/tsx --test test/plugin-config/script-visitors-execa.test.ts

The related Execa script visitor test passes.

@pkg-pr-new

pkg-pr-new Bot commented Jun 27, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/knip@1824
npm i https://pkg.pr.new/@knip/language-server@1824
npm i https://pkg.pr.new/@knip/mcp@1824

commit: a210cd9

@webpro
webpro merged commit 5095ae1 into webpro-nl:main Jun 27, 2026
30 checks passed
@webpro

webpro commented Jun 27, 2026

Copy link
Copy Markdown
Member

Thank you! ✨

@webpro

webpro commented Jun 27, 2026

Copy link
Copy Markdown
Member

🚀 This pull request is included in v6.22.0. See Release 6.22.0 for release notes.

Using Knip in a commercial project? Please consider becoming a sponsor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants