Skip to content

Commit

Permalink
Fix broken license check script (#61868)
Browse files Browse the repository at this point in the history
Co-authored-by: swissspidy <[email protected]>
Co-authored-by: gziolo <[email protected]>
  • Loading branch information
3 people authored Jul 16, 2024
1 parent e8cba7c commit 42e7777
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@
"lint:pkg-json": "wp-scripts lint-pkg-json . 'packages/*/package.json'",
"native": "npm run --prefix packages/react-native-editor",
"other:changelog": "node ./bin/plugin/cli.js changelog",
"other:check-licenses": "concurrently \"wp-scripts check-licenses --prod --gpl2 --ignore=@react-native-community/cli,@react-native-community/cli-platform-ios\" \"wp-scripts check-licenses --dev\"",
"other:check-licenses": "concurrently \"wp-scripts check-licenses --prod --gpl2 --ignore=@react-native-community/cli,@react-native-community/cli-platform-ios,@ampproject/remapping,human-signals,fb-watchman,bser,walker,chrome-launcher,lighthouse-logger,chromium-edge-launcher\" \"wp-scripts check-licenses --dev --ignore=jackspeak,path-scurry,package-json-from-dist\"",
"preother:check-local-changes": "npm run docs:build",
"other:check-local-changes": "node ./bin/check-local-changes.js",
"other:cherry-pick": "node ./bin/cherry-pick.mjs",
Expand Down
31 changes: 21 additions & 10 deletions packages/scripts/scripts/check-licenses.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ const child = spawn.sync(
'--json',
'--long',
'--all',
...( prod ? [ '--prod' ] : [] ),
...( dev ? [ '--dev' ] : [] ),
...( prod ? [ '--omit=dev' ] : [] ),
...( dev ? [ '--include=dev' ] : [] ),
],
/*
* Set the max buffer to ~157MB, since the output size for
Expand All @@ -198,10 +198,14 @@ function traverseDepTree( deps ) {
const dep = deps[ key ];

if ( ignored.includes( dep.name ) ) {
return;
continue;
}

if ( Object.keys( dep ).length === 0 ) {
continue;
}

if ( ! dep.hasOwnProperty( 'path' ) ) {
if ( ! dep.hasOwnProperty( 'path' ) && ! dep.missing ) {
if ( dep.hasOwnProperty( 'peerMissing' ) ) {
process.stdout.write(
`${ WARNING } Unable to locate path for missing peer dep ${ dep.name }@${ dep.version }. `
Expand All @@ -213,17 +217,15 @@ function traverseDepTree( deps ) {
);
}
} else if ( dep.missing ) {
process.stdout.write(
`${ WARNING } missing dep ${ dep.name }@${ dep.version }. `
);
for ( const problem of dep.problems ) {
process.stdout.write( `${ WARNING } ${ problem }.\n` );
}
} else {
checkDepLicense( dep.path );
}

if ( dep.hasOwnProperty( 'dependencies' ) ) {
traverseDepTree( dep.dependencies );
} else {
return;
}
}
}
Expand Down Expand Up @@ -272,6 +274,8 @@ function detectTypeFromLicenseText( licenseText ) {
);
}

const reportedPackages = new Set();

function checkDepLicense( path ) {
if ( ! path ) {
return;
Expand Down Expand Up @@ -333,7 +337,7 @@ function checkDepLicense( path ) {
}

let detectedLicenseTypes = [ detectedLicenseType ];
if ( detectedLicenseType.includes( ' AND ' ) ) {
if ( detectedLicenseType && detectedLicenseType.includes( ' AND ' ) ) {
detectedLicenseTypes = detectedLicenseType
.replace( /^\(*/g, '' )
.replace( /\)*$/, '' )
Expand All @@ -345,6 +349,13 @@ function checkDepLicense( path ) {
return;
}

// Do not report same package twice.
if ( reportedPackages.has( packageInfo.name ) ) {
return;
}

reportedPackages.add( packageInfo.name );

process.exitCode = 1;
process.stdout.write(
`${ ERROR } Module ${ packageInfo.name } has an incompatible license '${ licenseType }'.\n`
Expand Down

1 comment on commit 42e7777

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 42e7777.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/9952588802
📝 Reported issues:

Please sign in to comment.