Fix: Rewrite license check dependency resolution#74694
Fix: Rewrite license check dependency resolution#74694manzoorwanijk wants to merge 4 commits intotrunkfrom
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
There was a problem hiding this comment.
Copilot wasn't able to review any files in this pull request.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Copilot wasn't able to review any files in this pull request.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
I was a bit confused by this because that's what I understood the Example: Although all that being said, I think trying to make this package manager agnostic (in light of #74309) is an admirable goal above the narrower fix. A couple high-level thoughts I have before diving into the details:
|
Updated resolvePackagePath to use Node.js's findPackageJSON method when available (Node.js 22.14.0+), with a fallback to the previous resolution logic for older Node.js versions. This improves compatibility and reliability across different Node.js environments.
I think keeping them separate makes sense -
I made the change to use |
|
Size Change: 0 B Total Size: 2.98 MB ℹ️ View Unchanged
|
|
#75039 is an alternative to also fix it in the |
Refactored imports from 'module' to access createRequire and findPackageJSON dynamically. This ensures compatibility with Node.js versions where findPackageJSON may not be available.
|
Closing in favor of #75039 |
What?
Closes #74429, inspired by #74309
Rewrite the license check script (
bin/check-licenses.mjs) to properly handle dependency resolution, with some help from Claude Code.Why?
The current implementation uses
npm queryto find production dependencies, but the query logic has issues:Incorrect transitive dependency inclusion: The query captures all transitive dependencies, including those from dev-tool packages like Jest (via
@wordpress/scripts). This causes packages like@ampproject/remapping,webpack,bser,fb-watchman, andwalkerto be incorrectly flagged, requiring manual maintenance of anignoredlist.The root cause:
@wordpress/scriptslists dev tools (Jest, webpack, etc.) as production dependencies since it's a tooling package. The npm query then captures their transitive dependencies even though they're not actually distributed with WordPress.The new implementation:
wpScriptpackages (the ones actually shipped with WordPress)ignoredlist entirelyHow?
Instead of relying on
npm querywhich traverses all dependencies of all packages, the script now:wpScriptorwpScriptModuleExports(packages shipped with WordPress)require.resolveThis approach correctly scopes the check to only the dependencies that are actually bundled and distributed with WordPress, avoiding the false positives from dev tooling packages.
Testing Instructions
Test 1: Direct dependency with incompatible license
Add
typescript(Apache-2.0, not GPL-compatible) as a prod dependency:Run the license check - it should fail:
node bin/check-licenses.mjs # Should output an error about typescript having Apache-2.0 licenseMove typescript to devDependencies (which are not checked):
Run the license check again - it should pass:
node bin/check-licenses.mjs # Should pass since devDependencies are not checkedRestore:
Test 2: Transitive dependency with incompatible license
Add
jest(MIT license, but has transitive deps with Apache-2.0) as a prod dependency:Run the license check - it should fail due to transitive dependencies like
@ampproject/remapping(Apache-2.0):node bin/check-licenses.mjs # Should output an error about Apache-2.0 licenseMove jest to devDependencies (which are not checked):
Run the license check again - it should pass:
node bin/check-licenses.mjs # Should pass since devDependencies are not checkedRestore the original state:
Repeat the above steps for a package without
wpScriptorwpScriptModuleExports. For example,@wordpress/envand confirm that the license check doesn't fail in any case.Testing Instructions for Keyboard
N/A - This is a CLI script change with no UI impact.
Screenshots or screencast
N/A