Fix: Rewrite the license check scripts to use Node's native module resolution#75039
Fix: Rewrite the license check scripts to use Node's native module resolution#75039manzoorwanijk merged 6 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. |
|
Size Change: 0 B Total Size: 8.75 MB ℹ️ View Unchanged
|
8914fd0 to
0424708
Compare
|
This works better than |
55bf3ed to
08e4b02
Compare
|
@aduth any feedback on this? |
|
Hey @manzoorwanijk , sorry I haven't had a chance to look at this yet. It's been sitting in my "todo" pile but I've had other obligations that have kept me from reviewing it. I'll try to find some time next week to give it a proper review. |
Included 'MIT-0' in the gpl2CompatibleLicenses array to recognize it as a GPL-2 compatible license.
08e4b02 to
edede87
Compare
|
Flaky tests detected in edede87. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/22922222988
|
Closes #74429, inspired by #74309
What?
Alternative to #74694, fixing the issue in the
scriptspackage itself.Rewrite the license check scripts to use Node's native module resolution, with support for
findPackageJSON(Node.js 22.14.0+).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,bser,fb-watchman, andwalkerto be incorrectly flagged, requiring manual maintenance of anignoredlist.Package manager dependency: The
npm queryapproach only works with npm, not with pnpm or yarn.The new implementation:
findPackageJSONwhen available, with fallback)node_modules)packages/scripts/utils/license.jsfor reuseignoredlistHow?
Added shared utilities to
packages/scripts/utils/license.js:resolvePackagePath()- resolves a package usingfindPackageJSON(Node 22.14+) orcreateRequirefallbackreadPackageJson()- reads and parses package.json from a directoryUpdated
bin/check-licenses.mjs(Gutenberg CI):npm querywpScript/wpScriptModuleExportsUpdated
packages/scripts/scripts/check-licenses.js(wp-scripts check-licenses):npm queryAdded
MIT-0to GPL2-compatible licenses: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.Test 3: wp-scripts check-licenses
wp-scripts check-licensesalso works:cd packages/a11y node ../../packages/scripts/scripts/check-licenses.js --prod --gpl2