Repository navigation
Resolve expanded package scripts against the directory of their manifest - #2209
Merged
Merged
Conversation
commit: |
webpro
approved these changes
Oct 25, 2026
webpro
left a comment
Member
There was a problem hiding this comment.
Thanks @fixfon, this is a tidy fix. Reproduced #2207 with your fixture: with the source change reverted it reports both scripts/build.mjs and tasks/pack.mjs as unresolved, with it the run is clean.
Carrying the manifest directory on the options and consuming it once in expandScript keeps the change out of the individual package manager resolvers, and clearing it after the first hop is what keeps the yarn --cwd chain in the right package. Nice that the fixture covers that case too.
Member
|
π This pull request is included in v6.44.0. See Release 6.44.0 for release notes. Using Knip in a commercial project? Please consider becoming a sponsor. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2207
When a script inside a source file runs a package script, for example
spawnSync('bun', ['run', 'build'])inscripts/dev/dev.mjswith"build": "bun run build:all"and"build:all": "bun scripts/build.mjs"in package.json, knip expanded the package script but kept the directory of the calling file as the working directory. Soscripts/build.mjswas looked up inscripts/dev/and reported as an unresolved import.The options for scripts found in source files now carry the workspace directory as
manifestDir.expandScriptuses it as the working directory of the expanded body and clears it, so a nested expansion (for example after yarn's--cwd) is not pushed back to the workspace root. Scripts written literally in a source file still resolve against that file's directory. Because every package manager resolver goes throughexpandScript, there is no change per resolver.The new test uses a fixture with the case from the issue, a workspace-local script chain, and a yarn
--cwdchain. On main it reportsscripts/build.mjsfromscripts/dev/dev.mjsandtasks/pack.mjsfrompackages/app/dev/dev.mjsas unresolved. With the change it passes, and so doget-inputs-from-scripts.test.ts(35 tests together) andpnpm run ci. With the source change removed and the test kept, it fails again.I also ran the CLI by hand on small fixtures: bun, pnpm and yarn (nested and shorthand) and npm with
--all reported the false unresolved import on main and are clean now. A script that really points to a missing file is still reported.npm run build:allwithout--is not expanded at all today, so I left it alone.