-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Expand file tree
/
Copy paththirdPartyChecker.ts
More file actions
59 lines (54 loc) · 1.8 KB
/
thirdPartyChecker.ts
File metadata and controls
59 lines (54 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* eslint-disable @typescript-eslint/ban-ts-comment, @typescript-eslint/no-require-imports */
// @ts-nocheck
'use strict'
const path = require('path')
const checker = require('license-checker')
// license-checker keys packages as "<name>@<version>", and excludePackages
// matches that string exactly — name-only entries don't match. Build the
// workspace exclusions at runtime from each package's own package.json so
// version bumps stay in sync automatically. @marktext/file-icons stays
// pinned because it's a published third-party dep that license-checker
// fails to detect (MIT).
const repoRoot = path.resolve(__dirname, '..')
const workspaceExclusions = ['packages/desktop', 'packages/muyajs', 'packages/muya']
.map((rel) => {
const { name, version } = require(path.join(repoRoot, rel, 'package.json'))
return `${name}@${version}`
})
.concat('@marktext/file-icons')
.join(';')
const getLicenses = (rootDir, callback) => {
checker.init(
{
start: rootDir,
production: true,
development: false,
direct: true,
excludePackages: workspaceExclusions,
json: true,
onlyAllow:
'Unlicense;WTFPL;ISC;MIT;BSD;Apache-2.0;MIT*;Apache;Apache*;BSD*;CC0-1.0;CC-BY-4.0;CC-BY-3.0'
},
function(err, packages) {
callback(err, packages, checker)
}
)
}
// Check that all production dependencies are allowed.
const validateLicenses = (rootDir) => {
getLicenses(rootDir, (err, packages, checker) => {
if (err) {
console.log(`[ERROR] ${err}`)
process.exit(1)
}
if (!packages || Object.keys(packages).length === 0) {
console.log('[ERROR] No packages found — check your start path and filters.')
process.exit(1)
}
console.log(checker.asSummary(packages))
})
}
module.exports = {
getLicenses,
validateLicenses
}