@@ -45,6 +45,7 @@ const licensesWhitelist = [
45
45
'(AFL-2.1 OR BSD-2-Clause)' ,
46
46
'(MIT OR CC-BY-3.0)' ,
47
47
'(MIT OR Apache-2.0)' ,
48
+ '(MIT OR BSD-3-Clause)' ,
48
49
] ;
49
50
50
51
// Name variations of SPDX licenses that some packages have.
@@ -53,6 +54,7 @@ const licenseReplacements: { [key: string]: string } = {
53
54
// Just a longer string that our script catches. SPDX official name is the shorter one.
54
55
'Apache License, Version 2.0' : 'Apache-2.0' ,
55
56
'Apache2' : 'Apache-2.0' ,
57
+ 'Apache 2.0' : 'Apache-2.0' ,
56
58
'AFLv2.1' : 'AFL-2.1' ,
57
59
// BSD is BSD-2-clause by default.
58
60
'BSD' : 'BSD-2-Clause' ,
@@ -61,6 +63,7 @@ const licenseReplacements: { [key: string]: string } = {
61
63
// Specific packages to ignore, add a reason in a comment. Format: package-name@version.
62
64
const ignoredPackages = [
63
65
'[email protected] ' , // CC0 but it's content only (index.json, no code) and not distributed.
66
+ '[email protected] ' , // CC0 but it's content only (index.json, no code) and not distributed.
64
67
'[email protected] ' , // MIT, license but it's not listed in package.json.
65
68
'[email protected] ' , // LGPL,MIT but has a broken licenses array.
66
69
'[email protected] ' , // Apache-2.0 but broken license in package.json
@@ -73,54 +76,62 @@ const ignoredPackages = [
73
76
// TODO(filipesilva): remove this when spec_large is moved to e2e tests.
74
77
'[email protected] ' , // (OFL-1.1 AND MIT)
75
78
79
+ '@webassemblyjs/[email protected] ' , // MIT but no LICENSE file. `license` field in package.json.
80
+ '@webassemblyjs/[email protected] ' , // Apache 2.0 license, but get discovered as "Apache".
76
81
] ;
77
82
78
83
// Find all folders directly under a `node_modules` that have a package.json.
79
84
const checker = require ( 'license-checker' ) ;
80
85
81
86
82
- export default function ( _options : { } , logger : logging . Logger ) {
83
- checker . init ( { start : path . join ( __dirname , '..' ) } , ( err : Error , json : JsonObject ) => {
84
- if ( err ) {
85
- logger . fatal ( `Something happened:\n${ err . message } ` ) ;
86
- } else {
87
- logger . info ( `Testing ${ Object . keys ( json ) . length } packages.\n` ) ;
88
-
89
- // Packages with bad licenses are those that neither pass SPDX nor are ignored.
90
- const badLicensePackages = Object . keys ( json )
91
- . map ( key => ( {
92
- id : key ,
93
- licenses : ( [ ] as string [ ] )
94
- // tslint:disable-next-line:non-null-operator
95
- . concat ( ( json [ key ] ! as JsonObject ) . licenses as string [ ] )
96
- // `*` is used when the license is guessed.
97
- . map ( x => x . replace ( / \* $ / , '' ) )
98
- . map ( x => x in licenseReplacements ? licenseReplacements [ x ] : x ) ,
99
- } ) )
100
- . filter ( pkg => ! passesSpdx ( pkg . licenses , licensesWhitelist ) )
101
- . filter ( pkg => ! ignoredPackages . find ( ignored => ignored === pkg . id ) ) ;
102
-
103
- // Report packages with bad licenses
104
- if ( badLicensePackages . length > 0 ) {
105
- logger . error ( 'Invalid package licences found:' ) ;
106
- badLicensePackages . forEach ( pkg => {
107
- logger . error ( `${ pkg . id } : ${ JSON . stringify ( pkg . licenses ) } ` ) ;
108
- } ) ;
109
- logger . fatal ( `\n${ badLicensePackages . length } total packages with invalid licenses.` ) ;
110
- } else {
111
- logger . info ( 'All package licenses are valid.' ) ;
112
- }
87
+ // Check if a license is accepted by an array of accepted licenses
88
+ function _passesSpdx ( licenses : string [ ] , accepted : string [ ] ) {
89
+ return accepted . some ( l => {
90
+ try {
91
+ return spdxSatisfies ( licenses . join ( ' AND ' ) , l ) ;
92
+ } catch ( _ ) {
93
+ return false ;
113
94
}
114
95
} ) ;
96
+ }
115
97
116
- // Check if a license is accepted by an array of accepted licenses
117
- function passesSpdx ( licenses : string [ ] , accepted : string [ ] ) {
118
- return accepted . some ( l => {
119
- try {
120
- return spdxSatisfies ( licenses . join ( ' AND ' ) , l ) ;
121
- } catch ( _ ) {
122
- return false ;
98
+
99
+ export default function ( _options : { } , logger : logging . Logger ) : Promise < number > {
100
+ return new Promise ( resolve => {
101
+ checker . init ( { start : path . join ( __dirname , '..' ) } , ( err : Error , json : JsonObject ) => {
102
+ if ( err ) {
103
+ logger . fatal ( `Something happened:\n${ err . message } ` ) ;
104
+ resolve ( 1 ) ;
105
+ } else {
106
+ logger . info ( `Testing ${ Object . keys ( json ) . length } packages.\n` ) ;
107
+
108
+ // Packages with bad licenses are those that neither pass SPDX nor are ignored.
109
+ const badLicensePackages = Object . keys ( json )
110
+ . map ( key => ( {
111
+ id : key ,
112
+ licenses : ( [ ] as string [ ] )
113
+ // tslint:disable-next-line:non-null-operator
114
+ . concat ( ( json [ key ] ! as JsonObject ) . licenses as string [ ] )
115
+ // `*` is used when the license is guessed.
116
+ . map ( x => x . replace ( / \* $ / , '' ) )
117
+ . map ( x => x in licenseReplacements ? licenseReplacements [ x ] : x ) ,
118
+ } ) )
119
+ . filter ( pkg => ! _passesSpdx ( pkg . licenses , licensesWhitelist ) )
120
+ . filter ( pkg => ! ignoredPackages . find ( ignored => ignored === pkg . id ) ) ;
121
+
122
+ // Report packages with bad licenses
123
+ if ( badLicensePackages . length > 0 ) {
124
+ logger . error ( 'Invalid package licences found:' ) ;
125
+ badLicensePackages . forEach ( pkg => {
126
+ logger . error ( `${ pkg . id } : ${ JSON . stringify ( pkg . licenses ) } ` ) ;
127
+ } ) ;
128
+ logger . fatal ( `\n${ badLicensePackages . length } total packages with invalid licenses.` ) ;
129
+ resolve ( 2 ) ;
130
+ } else {
131
+ logger . info ( 'All package licenses are valid.' ) ;
132
+ resolve ( 0 ) ;
133
+ }
123
134
}
124
135
} ) ;
125
- }
136
+ } ) ;
126
137
}
0 commit comments