-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[dev/license_checker][dev/npm] reactor, ts-ify, de-grunt (#37807)
- Loading branch information
Spencer
authored
Jun 6, 2019
1 parent
a1ecfff
commit 5973c2a
Showing
24 changed files
with
318 additions
and
354 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
require('../src/setup_node_env'); | ||
require('../src/dev/license_checker/run_check_licenses_cli'); |
This file contains 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
File renamed without changes.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { getInstalledPackages } from '../npm'; | ||
import { run } from '../run'; | ||
|
||
import { LICENSE_WHITELIST, DEV_ONLY_LICENSE_WHITELIST, LICENSE_OVERRIDES } from './config'; | ||
import { assertLicensesValid } from './valid'; | ||
import { REPO_ROOT } from '../constants'; | ||
|
||
run( | ||
async ({ log, flags }) => { | ||
const packages = await getInstalledPackages({ | ||
directory: REPO_ROOT, | ||
licenseOverrides: LICENSE_OVERRIDES, | ||
includeDev: !!flags.dev, | ||
}); | ||
|
||
// Assert if the found licenses in the production | ||
// packages are valid | ||
assertLicensesValid({ | ||
packages: packages.filter(pkg => !pkg.isDevOnly), | ||
validLicenses: LICENSE_WHITELIST, | ||
}); | ||
log.success('All production dependency licenses are allowed'); | ||
|
||
// Do the same as above for the packages only used in development | ||
// if the dev flag is found | ||
if (flags.dev) { | ||
assertLicensesValid({ | ||
packages: packages.filter(pkg => pkg.isDevOnly), | ||
validLicenses: LICENSE_WHITELIST.concat(DEV_ONLY_LICENSE_WHITELIST), | ||
}); | ||
log.success('All development dependency licenses are allowed'); | ||
} | ||
}, | ||
{ | ||
flags: { | ||
boolean: ['dev'], | ||
help: ` | ||
--dev Also check dev dependencies | ||
`, | ||
}, | ||
} | ||
); |
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import dedent from 'dedent'; | ||
import { createFailError } from '../run'; | ||
|
||
interface Options { | ||
packages: Array<{ | ||
name: string; | ||
version: string; | ||
relative: string; | ||
licenses: string[]; | ||
}>; | ||
validLicenses: string[]; | ||
} | ||
|
||
/** | ||
* When given a list of packages and the valid license | ||
* options, either throws an error with details about | ||
* violations or returns undefined. | ||
*/ | ||
export function assertLicensesValid({ packages, validLicenses }: Options) { | ||
const invalidMsgs = packages.reduce( | ||
(acc, pkg) => { | ||
const invalidLicenses = pkg.licenses.filter(license => !validLicenses.includes(license)); | ||
|
||
if (pkg.licenses.length && !invalidLicenses.length) { | ||
return acc; | ||
} | ||
|
||
return acc.concat(dedent` | ||
${pkg.name} | ||
version: ${pkg.version} | ||
all licenses: ${pkg.licenses} | ||
invalid licenses: ${invalidLicenses.join(', ')} | ||
path: ${pkg.relative} | ||
`); | ||
}, | ||
[] as string[] | ||
); | ||
|
||
if (invalidMsgs.length) { | ||
throw createFailError( | ||
`Non-conforming licenses:\n${invalidMsgs | ||
.join('\n') | ||
.split('\n') | ||
.map(l => ` ${l}`) | ||
.join('\n')}` | ||
); | ||
} | ||
} |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.