license-cop 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +5 -0
- package/README.md +105 -0
- package/package.json +44 -0
- package/src/bin/license-cop +4 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +8 -0
- package/src/index.js.map +1 -0
- package/src/lib/cli/arguments.d.ts +18 -0
- package/src/lib/cli/arguments.js +23 -0
- package/src/lib/cli/arguments.js.map +1 -0
- package/src/lib/cli/index.d.ts +1 -0
- package/src/lib/cli/index.js +67 -0
- package/src/lib/cli/index.js.map +1 -0
- package/src/lib/cli/init.d.ts +1 -0
- package/src/lib/cli/init.js +24 -0
- package/src/lib/cli/init.js.map +1 -0
- package/src/lib/cli/version.d.ts +1 -0
- package/src/lib/cli/version.js +17 -0
- package/src/lib/cli/version.js.map +1 -0
- package/src/lib/config/config.d.ts +39 -0
- package/src/lib/config/config.js +34 -0
- package/src/lib/config/config.js.map +1 -0
- package/src/lib/config/find-config.d.ts +1 -0
- package/src/lib/config/find-config.js +64 -0
- package/src/lib/config/find-config.js.map +1 -0
- package/src/lib/config/load-config.d.ts +7 -0
- package/src/lib/config/load-config.js +26 -0
- package/src/lib/config/load-config.js.map +1 -0
- package/src/lib/config/load-parent-config.d.ts +1 -0
- package/src/lib/config/load-parent-config.js +30 -0
- package/src/lib/config/load-parent-config.js.map +1 -0
- package/src/lib/config/parent-resolutions/github.d.ts +1 -0
- package/src/lib/config/parent-resolutions/github.js +23 -0
- package/src/lib/config/parent-resolutions/github.js.map +1 -0
- package/src/lib/config/parent-resolutions/http.d.ts +1 -0
- package/src/lib/config/parent-resolutions/http.js +16 -0
- package/src/lib/config/parent-resolutions/http.js.map +1 -0
- package/src/lib/config/parent-resolutions/npm.d.ts +2 -0
- package/src/lib/config/parent-resolutions/npm.js +29 -0
- package/src/lib/config/parent-resolutions/npm.js.map +1 -0
- package/src/lib/license-cop.d.ts +8 -0
- package/src/lib/license-cop.js +66 -0
- package/src/lib/license-cop.js.map +1 -0
- package/src/lib/package-json.d.ts +6 -0
- package/src/lib/package-json.js +30 -0
- package/src/lib/package-json.js.map +1 -0
- package/src/lib/package-rules.d.ts +2 -0
- package/src/lib/package-rules.js +34 -0
- package/src/lib/package-rules.js.map +1 -0
- package/src/lib/violations-error.d.ts +9 -0
- package/src/lib/violations-error.js +16 -0
- package/src/lib/violations-error.js.map +1 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
Copyright (c) 2023, [Toby Smith](https://tobysmith.uk), tobysmith568@hotmail.co.uk
|
|
2
|
+
|
|
3
|
+
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
|
|
4
|
+
|
|
5
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# LicenseCop
|
|
2
|
+
|
|
3
|
+
Yet another license checker tool for your dependencies; focused on simplicity.
|
|
4
|
+
|
|
5
|
+
<a href="https://www.npmjs.com/package/license-cop">
|
|
6
|
+
<img alt="npm" src="https://img.shields.io/npm/v/license-cop?logo=npm">
|
|
7
|
+
</a>
|
|
8
|
+
|
|
9
|
+
## Setup
|
|
10
|
+
|
|
11
|
+
Install license-cop
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install license-cop --save-dev
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Make a config file
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npx license-cop --init
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Run license-cop
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npx license-cop
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
The `license-cop` command will use an exit code of 0 if all your dependencies conform to the settings in your config file.
|
|
30
|
+
|
|
31
|
+
## Config File
|
|
32
|
+
|
|
33
|
+
By default the `--init` flag will make a `.licenses.json` file, however you can use many different variations of file name and file type including:
|
|
34
|
+
|
|
35
|
+
<!--- cspell:disable-next-line --->
|
|
36
|
+
|
|
37
|
+
- Spelling `licenses` as `licences`
|
|
38
|
+
- Ending `licenses` with `rc`
|
|
39
|
+
- Having the file be in a `.config/` directory
|
|
40
|
+
- Using: `.json`, `.jsonc`, `.json5`, `.yaml`, `.yml`, `.js`, or `.cjs`
|
|
41
|
+
- Using a `licensecop` key in a `package.json` file
|
|
42
|
+
|
|
43
|
+
### Config file options
|
|
44
|
+
|
|
45
|
+
#### `licenses`
|
|
46
|
+
|
|
47
|
+
Specify all of the [SPDX license codes](https://spdx.org/licenses/) that you're allowing in your dependency tree. E.g.
|
|
48
|
+
|
|
49
|
+
```json
|
|
50
|
+
{
|
|
51
|
+
"licenses": ["MIT", "ISC", "Apache-2.0"]
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
#### `packages`
|
|
56
|
+
|
|
57
|
+
Specify all of the packages you're allowing, no matter what the license is. You can optionally lock packages by npm version ranges. E.g.
|
|
58
|
+
|
|
59
|
+
```json
|
|
60
|
+
{
|
|
61
|
+
"packages": ["lodash", "axios@^2.0.0", "react@<16"]
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
#### `extends`
|
|
66
|
+
|
|
67
|
+
Specify another license-cop config file that this file should extend.
|
|
68
|
+
|
|
69
|
+
```json
|
|
70
|
+
{
|
|
71
|
+
"extends": "@license-cop/permissive"
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Values can be:
|
|
76
|
+
|
|
77
|
+
- The name of an installed npm package (optionally prefixed with `npm:`) that contains a license-cop config file.
|
|
78
|
+
`@license-cop/permissive`
|
|
79
|
+
`npm:@license-cop/permissive`
|
|
80
|
+
|
|
81
|
+
> [@license-cop/permissive](https://www.npmjs.com/package/@license-cop/permissive) is a base config provided by us containing a curated list of permissive licenses. We think it's a good starting point for all configs!
|
|
82
|
+
|
|
83
|
+
- The name of a public github repository (prefixed with `github:`) that contains a license-cop config file. This currently only supports config files called exactly `.licenses.json`.
|
|
84
|
+
`github:tobysmith568/license-cop-config`
|
|
85
|
+
|
|
86
|
+
- A URL to a license-cop config file. Currently this only supports json config files.
|
|
87
|
+
`https://raw.githubusercontent.com/tobysmith568/license-cop-config/main/license-cop.json`
|
|
88
|
+
|
|
89
|
+
**Caveats**
|
|
90
|
+
|
|
91
|
+
If you extend a remote file, and that in-turn extends an npm package, then you're going to need to have that npm package installed locally. They're not resolved dynamically from npmjs.com.
|
|
92
|
+
|
|
93
|
+
#### `includeDevDependencies`
|
|
94
|
+
|
|
95
|
+
`false` by default.
|
|
96
|
+
Set to `true` to make license-cop also check your dev-dependencies.
|
|
97
|
+
|
|
98
|
+
#### `devDependenciesOnly`
|
|
99
|
+
|
|
100
|
+
`false` by default.
|
|
101
|
+
Set to `true` to make license-cop only check your dev-dependencies.
|
|
102
|
+
|
|
103
|
+
## License
|
|
104
|
+
|
|
105
|
+
License-cop itself is licensed under the [ISC license](./LICENSE.md).
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "license-cop",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "commonjs",
|
|
5
|
+
"bin": {
|
|
6
|
+
"license-cop": "./src/bin/license-cop"
|
|
7
|
+
},
|
|
8
|
+
"author": {
|
|
9
|
+
"name": "Toby Smith",
|
|
10
|
+
"email": "tobysmith568@hotmail.co.uk",
|
|
11
|
+
"url": "https://tobysmith.uk"
|
|
12
|
+
},
|
|
13
|
+
"license": "ISC",
|
|
14
|
+
"description": "Yet another license checker tool for your dependencies; focused on simplicity.",
|
|
15
|
+
"homepage": "https://github.com/tobysmith568/license-cop#readme",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/tobysmith568/license-cop.git",
|
|
19
|
+
"directory": "packages/license-cop"
|
|
20
|
+
},
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/tobysmith568/license-cop/issues"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@npmcli/arborist": "6.2.5",
|
|
26
|
+
"arg": "5.0.2",
|
|
27
|
+
"axios": "1.3.4",
|
|
28
|
+
"compare-versions": "6.0.0-rc.1",
|
|
29
|
+
"cosmiconfig": "8.1.3",
|
|
30
|
+
"deepmerge": "4.3.1",
|
|
31
|
+
"git-filesystem": "0.0.2",
|
|
32
|
+
"json5": "2.2.3",
|
|
33
|
+
"zod": "3.21.4"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@swc/helpers": "0.4.14"
|
|
37
|
+
},
|
|
38
|
+
"main": "./src/index.js",
|
|
39
|
+
"exports": {
|
|
40
|
+
".": {
|
|
41
|
+
"require": "./src/index.js"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./lib/license-cop";
|
package/src/index.js
ADDED
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../packages/license-cop/src/index.ts"],"sourcesContent":["export * from \"./lib/license-cop\";\n"],"names":[],"mappings":";;;;;oBAAc"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Spec } from "arg";
|
|
2
|
+
export interface UserInputs {
|
|
3
|
+
version?: boolean;
|
|
4
|
+
}
|
|
5
|
+
export interface ArgumentsWithAliases extends Spec {
|
|
6
|
+
"--init": typeof Boolean;
|
|
7
|
+
"--directory": typeof String;
|
|
8
|
+
"--dir": "--directory";
|
|
9
|
+
"-d": "--directory";
|
|
10
|
+
"--include-dev-dependencies": typeof Boolean;
|
|
11
|
+
"--dev": "--include-dev-dependencies";
|
|
12
|
+
"-D": "--include-dev-dependencies";
|
|
13
|
+
"--dev-dependencies-only": typeof Boolean;
|
|
14
|
+
"--dev-only": "--dev-dependencies-only";
|
|
15
|
+
"--version": typeof Boolean;
|
|
16
|
+
"-v": "--version";
|
|
17
|
+
}
|
|
18
|
+
export declare const argumentsWithAliases: ArgumentsWithAliases;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "argumentsWithAliases", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: ()=>argumentsWithAliases
|
|
8
|
+
});
|
|
9
|
+
const argumentsWithAliases = {
|
|
10
|
+
"--init": Boolean,
|
|
11
|
+
"--directory": String,
|
|
12
|
+
"--dir": "--directory",
|
|
13
|
+
"-d": "--directory",
|
|
14
|
+
"--include-dev-dependencies": Boolean,
|
|
15
|
+
"--dev": "--include-dev-dependencies",
|
|
16
|
+
"-D": "--include-dev-dependencies",
|
|
17
|
+
"--dev-dependencies-only": Boolean,
|
|
18
|
+
"--dev-only": "--dev-dependencies-only",
|
|
19
|
+
"--version": Boolean,
|
|
20
|
+
"-v": "--version"
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=arguments.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/license-cop/src/lib/cli/arguments.ts"],"sourcesContent":["import { Spec } from \"arg\";\n\nexport interface UserInputs {\n version?: boolean;\n}\n\nexport interface ArgumentsWithAliases extends Spec {\n \"--init\": typeof Boolean;\n\n \"--directory\": typeof String;\n \"--dir\": \"--directory\";\n \"-d\": \"--directory\";\n\n \"--include-dev-dependencies\": typeof Boolean;\n \"--dev\": \"--include-dev-dependencies\";\n \"-D\": \"--include-dev-dependencies\";\n\n \"--dev-dependencies-only\": typeof Boolean;\n \"--dev-only\": \"--dev-dependencies-only\";\n\n \"--version\": typeof Boolean;\n \"-v\": \"--version\";\n}\n\nexport const argumentsWithAliases: ArgumentsWithAliases = {\n \"--init\": Boolean,\n\n \"--directory\": String,\n \"--dir\": \"--directory\",\n \"-d\": \"--directory\",\n\n \"--include-dev-dependencies\": Boolean,\n \"--dev\": \"--include-dev-dependencies\",\n \"-D\": \"--include-dev-dependencies\",\n\n \"--dev-dependencies-only\": Boolean,\n \"--dev-only\": \"--dev-dependencies-only\",\n\n \"--version\": Boolean,\n \"-v\": \"--version\"\n};\n"],"names":["argumentsWithAliases","Boolean","String"],"mappings":";;;;+BAwBaA;;aAAAA;;AAAN,MAAMA,uBAA6C;IACxD,UAAUC;IAEV,eAAeC;IACf,SAAS;IACT,MAAM;IAEN,8BAA8BD;IAC9B,SAAS;IACT,MAAM;IAEN,2BAA2BA;IAC3B,cAAc;IAEd,aAAaA;IACb,MAAM;AACR"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function main(args: string[]): Promise<void>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "main", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: ()=>main
|
|
8
|
+
});
|
|
9
|
+
const _interopRequireDefault = require("@swc/helpers/lib/_interop_require_default.js").default;
|
|
10
|
+
const _arg = /*#__PURE__*/ _interopRequireDefault(require("arg"));
|
|
11
|
+
const _loadConfig = require("../config/load-config");
|
|
12
|
+
const _licenseCop = require("../license-cop");
|
|
13
|
+
const _violationsError = require("../violations-error");
|
|
14
|
+
const _arguments = require("./arguments");
|
|
15
|
+
const _init = require("./init");
|
|
16
|
+
const _version = require("./version");
|
|
17
|
+
async function main(args) {
|
|
18
|
+
try {
|
|
19
|
+
await cli(args);
|
|
20
|
+
} catch (e) {
|
|
21
|
+
if (e instanceof _violationsError.ViolationsError) {
|
|
22
|
+
reportViolations(e.violations);
|
|
23
|
+
} else if (e instanceof Error) {
|
|
24
|
+
console.error(e.message);
|
|
25
|
+
} else {
|
|
26
|
+
console.error(e);
|
|
27
|
+
}
|
|
28
|
+
process.exitCode = 1;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const cli = async (args)=>{
|
|
32
|
+
const givenUserInputs = parseUserInputs(args);
|
|
33
|
+
if (givenUserInputs["--version"]) {
|
|
34
|
+
await (0, _version.printPackageVersion)();
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
var _givenUserInputs_directory;
|
|
38
|
+
const directory = (_givenUserInputs_directory = givenUserInputs["--directory"]) != null ? _givenUserInputs_directory : process.cwd();
|
|
39
|
+
if (givenUserInputs["--init"]) {
|
|
40
|
+
await (0, _init.init)(directory);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const config = await (0, _loadConfig.loadConfig)(directory);
|
|
44
|
+
var _givenUserInputs_includedevdependencies, _givenUserInputs_devdependenciesonly;
|
|
45
|
+
const options = {
|
|
46
|
+
allowedLicenses: config.licenses,
|
|
47
|
+
allowedPackages: config.packages,
|
|
48
|
+
workingDirectory: directory,
|
|
49
|
+
includeDevDependencies: (_givenUserInputs_includedevdependencies = givenUserInputs["--include-dev-dependencies"]) != null ? _givenUserInputs_includedevdependencies : config.includeDevDependencies,
|
|
50
|
+
devDependenciesOnly: (_givenUserInputs_devdependenciesonly = givenUserInputs["--dev-dependencies-only"]) != null ? _givenUserInputs_devdependenciesonly : config.devDependenciesOnly
|
|
51
|
+
};
|
|
52
|
+
await (0, _licenseCop.checkLicenses)(options);
|
|
53
|
+
};
|
|
54
|
+
const parseUserInputs = (rawArgs)=>{
|
|
55
|
+
return (0, _arg.default)(_arguments.argumentsWithAliases, {
|
|
56
|
+
argv: rawArgs.slice(2)
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
const reportViolations = (violations)=>{
|
|
60
|
+
console.log("Issues:");
|
|
61
|
+
for (const violation of violations){
|
|
62
|
+
const { packageName , packageVersion , license } = violation;
|
|
63
|
+
console.log(`${packageName}@${packageVersion} - ${license}`);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/license-cop/src/lib/cli/index.ts"],"sourcesContent":["import arg, { Result } from \"arg\";\nimport { loadConfig } from \"../config/load-config\";\nimport { checkLicenses, LicenseCopOptions } from \"../license-cop\";\nimport { Violation, ViolationsError } from \"../violations-error\";\nimport { argumentsWithAliases, ArgumentsWithAliases } from \"./arguments\";\nimport { init } from \"./init\";\nimport { printPackageVersion } from \"./version\";\n\nexport async function main(args: string[]): Promise<void> {\n try {\n await cli(args);\n } catch (e: unknown) {\n if (e instanceof ViolationsError) {\n reportViolations(e.violations);\n } else if (e instanceof Error) {\n console.error(e.message);\n } else {\n console.error(e);\n }\n\n process.exitCode = 1;\n }\n}\n\nconst cli = async (args: string[]) => {\n const givenUserInputs = parseUserInputs(args);\n\n if (givenUserInputs[\"--version\"]) {\n await printPackageVersion();\n return;\n }\n\n const directory = givenUserInputs[\"--directory\"] ?? process.cwd();\n\n if (givenUserInputs[\"--init\"]) {\n await init(directory);\n return;\n }\n\n const config = await loadConfig(directory);\n\n const options: LicenseCopOptions = {\n allowedLicenses: config.licenses,\n allowedPackages: config.packages,\n\n workingDirectory: directory,\n includeDevDependencies:\n givenUserInputs[\"--include-dev-dependencies\"] ?? config.includeDevDependencies,\n devDependenciesOnly: givenUserInputs[\"--dev-dependencies-only\"] ?? config.devDependenciesOnly\n };\n\n await checkLicenses(options);\n};\n\nconst parseUserInputs = (rawArgs: string[]): Result<ArgumentsWithAliases> => {\n return arg(argumentsWithAliases, {\n argv: rawArgs.slice(2)\n });\n};\n\nconst reportViolations = (violations: Set<Violation>): void => {\n console.log(\"Issues:\");\n for (const violation of violations) {\n const { packageName, packageVersion, license } = violation;\n console.log(`${packageName}@${packageVersion} - ${license}`);\n }\n};\n"],"names":["main","args","cli","e","ViolationsError","reportViolations","violations","Error","console","error","message","process","exitCode","givenUserInputs","parseUserInputs","printPackageVersion","directory","cwd","init","config","loadConfig","options","allowedLicenses","licenses","allowedPackages","packages","workingDirectory","includeDevDependencies","devDependenciesOnly","checkLicenses","rawArgs","arg","argumentsWithAliases","argv","slice","log","violation","packageName","packageVersion","license"],"mappings":";;;;+BAQsBA;;aAAAA;;;0DARM;4BACD;4BACsB;iCACN;2BACgB;sBACtC;yBACe;AAE7B,eAAeA,KAAKC,IAAc,EAAiB;IACxD,IAAI;QACF,MAAMC,IAAID;IACZ,EAAE,OAAOE,GAAY;QACnB,IAAIA,aAAaC,gCAAe,EAAE;YAChCC,iBAAiBF,EAAEG,UAAU;QAC/B,OAAO,IAAIH,aAAaI,OAAO;YAC7BC,QAAQC,KAAK,CAACN,EAAEO,OAAO;QACzB,OAAO;YACLF,QAAQC,KAAK,CAACN;QAChB,CAAC;QAEDQ,QAAQC,QAAQ,GAAG;IACrB;AACF;AAEA,MAAMV,MAAM,OAAOD,OAAmB;IACpC,MAAMY,kBAAkBC,gBAAgBb;IAExC,IAAIY,eAAe,CAAC,YAAY,EAAE;QAChC,MAAME,IAAAA,4BAAmB;QACzB;IACF,CAAC;QAEiBF;IAAlB,MAAMG,YAAYH,CAAAA,6BAAAA,eAAe,CAAC,cAAc,YAA9BA,6BAAkCF,QAAQM,GAAG,EAAE;IAEjE,IAAIJ,eAAe,CAAC,SAAS,EAAE;QAC7B,MAAMK,IAAAA,UAAI,EAACF;QACX;IACF,CAAC;IAED,MAAMG,SAAS,MAAMC,IAAAA,sBAAU,EAACJ;QAQ5BH,yCACmBA;IAPvB,MAAMQ,UAA6B;QACjCC,iBAAiBH,OAAOI,QAAQ;QAChCC,iBAAiBL,OAAOM,QAAQ;QAEhCC,kBAAkBV;QAClBW,wBACEd,CAAAA,0CAAAA,eAAe,CAAC,6BAA6B,YAA7CA,0CAAiDM,OAAOQ,sBAAsB;QAChFC,qBAAqBf,CAAAA,uCAAAA,eAAe,CAAC,0BAA0B,YAA1CA,uCAA8CM,OAAOS,mBAAmB;IAC/F;IAEA,MAAMC,IAAAA,yBAAa,EAACR;AACtB;AAEA,MAAMP,kBAAkB,CAACgB,UAAoD;IAC3E,OAAOC,IAAAA,YAAG,EAACC,+BAAoB,EAAE;QAC/BC,MAAMH,QAAQI,KAAK,CAAC;IACtB;AACF;AAEA,MAAM7B,mBAAmB,CAACC,aAAqC;IAC7DE,QAAQ2B,GAAG,CAAC;IACZ,KAAK,MAAMC,aAAa9B,WAAY;QAClC,MAAM,EAAE+B,YAAW,EAAEC,eAAc,EAAEC,QAAO,EAAE,GAAGH;QACjD5B,QAAQ2B,GAAG,CAAC,CAAC,EAAEE,YAAY,CAAC,EAAEC,eAAe,GAAG,EAAEC,QAAQ,CAAC;IAC7D;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const init: (rootDir: string) => Promise<void>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "init", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: ()=>init
|
|
8
|
+
});
|
|
9
|
+
const _promises = require("fs/promises");
|
|
10
|
+
const _path = require("path");
|
|
11
|
+
const defaultConfig = `{
|
|
12
|
+
"licenses": ["MIT", "ISC", "Apache-2.0"],
|
|
13
|
+
"packages": []
|
|
14
|
+
}
|
|
15
|
+
`;
|
|
16
|
+
const init = async (rootDir)=>{
|
|
17
|
+
console.log("Setting up a new license-cop config file...");
|
|
18
|
+
const configPath = (0, _path.join)(rootDir, ".licenses.json");
|
|
19
|
+
(0, _promises.writeFile)(configPath, defaultConfig);
|
|
20
|
+
console.log("Done!");
|
|
21
|
+
console.log("Run `npx license-cop` to check your dependencies");
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=init.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/license-cop/src/lib/cli/init.ts"],"sourcesContent":["import { writeFile } from \"fs/promises\";\nimport { join } from \"path\";\n\nconst defaultConfig = `{\n \"licenses\": [\"MIT\", \"ISC\", \"Apache-2.0\"],\n \"packages\": []\n}\n`;\n\nexport const init = async (rootDir: string) => {\n console.log(\"Setting up a new license-cop config file...\");\n\n const configPath = join(rootDir, \".licenses.json\");\n writeFile(configPath, defaultConfig);\n\n console.log(\"Done!\");\n console.log(\"Run `npx license-cop` to check your dependencies\");\n};\n"],"names":["init","defaultConfig","rootDir","console","log","configPath","join","writeFile"],"mappings":";;;;+BASaA;;aAAAA;;0BATa;sBACL;AAErB,MAAMC,gBAAgB,CAAC;;;;AAIvB,CAAC;AAEM,MAAMD,OAAO,OAAOE,UAAoB;IAC7CC,QAAQC,GAAG,CAAC;IAEZ,MAAMC,aAAaC,IAAAA,UAAI,EAACJ,SAAS;IACjCK,IAAAA,mBAAS,EAACF,YAAYJ;IAEtBE,QAAQC,GAAG,CAAC;IACZD,QAAQC,GAAG,CAAC;AACd"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const printPackageVersion: () => Promise<void>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "printPackageVersion", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: ()=>printPackageVersion
|
|
8
|
+
});
|
|
9
|
+
const _path = require("path");
|
|
10
|
+
const _packageJson = require("../package-json");
|
|
11
|
+
const printPackageVersion = async ()=>{
|
|
12
|
+
const packageJsonLocation = (0, _path.join)(__dirname, "../../../package.json");
|
|
13
|
+
const { version } = await (0, _packageJson.readPackageJson)(packageJsonLocation);
|
|
14
|
+
console.log(`v${version}`);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=version.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/license-cop/src/lib/cli/version.ts"],"sourcesContent":["import { join } from \"path\";\nimport { readPackageJson } from \"../package-json\";\n\nexport const printPackageVersion = async (): Promise<void> => {\n const packageJsonLocation = join(__dirname, \"../../../package.json\");\n const { version } = await readPackageJson(packageJsonLocation);\n console.log(`v${version}`);\n};\n"],"names":["printPackageVersion","packageJsonLocation","join","__dirname","version","readPackageJson","console","log"],"mappings":";;;;+BAGaA;;aAAAA;;sBAHQ;6BACW;AAEzB,MAAMA,sBAAsB,UAA2B;IAC5D,MAAMC,sBAAsBC,IAAAA,UAAI,EAACC,WAAW;IAC5C,MAAM,EAAEC,QAAO,EAAE,GAAG,MAAMC,IAAAA,4BAAe,EAACJ;IAC1CK,QAAQC,GAAG,CAAC,CAAC,CAAC,EAAEH,QAAQ,CAAC;AAC3B"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
declare const configParser: z.ZodEffects<z.ZodObject<{
|
|
3
|
+
extends: z.ZodOptional<z.ZodString>;
|
|
4
|
+
licenses: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
5
|
+
packages: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
6
|
+
includeDevDependencies: z.ZodOptional<z.ZodBoolean>;
|
|
7
|
+
devDependenciesOnly: z.ZodOptional<z.ZodBoolean>;
|
|
8
|
+
directory: z.ZodOptional<z.ZodString>;
|
|
9
|
+
}, "strip", z.ZodTypeAny, {
|
|
10
|
+
extends?: string | undefined;
|
|
11
|
+
licenses?: string[] | undefined;
|
|
12
|
+
packages?: string[] | undefined;
|
|
13
|
+
includeDevDependencies?: boolean | undefined;
|
|
14
|
+
devDependenciesOnly?: boolean | undefined;
|
|
15
|
+
directory?: string | undefined;
|
|
16
|
+
}, {
|
|
17
|
+
extends?: string | undefined;
|
|
18
|
+
licenses?: string[] | undefined;
|
|
19
|
+
packages?: string[] | undefined;
|
|
20
|
+
includeDevDependencies?: boolean | undefined;
|
|
21
|
+
devDependenciesOnly?: boolean | undefined;
|
|
22
|
+
directory?: string | undefined;
|
|
23
|
+
}>, {
|
|
24
|
+
extends: string | undefined;
|
|
25
|
+
licenses: string[];
|
|
26
|
+
packages: string[];
|
|
27
|
+
includeDevDependencies: boolean;
|
|
28
|
+
devDependenciesOnly: boolean;
|
|
29
|
+
}, {
|
|
30
|
+
extends?: string | undefined;
|
|
31
|
+
licenses?: string[] | undefined;
|
|
32
|
+
packages?: string[] | undefined;
|
|
33
|
+
includeDevDependencies?: boolean | undefined;
|
|
34
|
+
devDependenciesOnly?: boolean | undefined;
|
|
35
|
+
directory?: string | undefined;
|
|
36
|
+
}>;
|
|
37
|
+
export type Config = z.infer<typeof configParser>;
|
|
38
|
+
export declare const parseConfig: (config: unknown) => Config;
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "parseConfig", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: ()=>parseConfig
|
|
8
|
+
});
|
|
9
|
+
const _zod = require("zod");
|
|
10
|
+
var _c_licenses, _c_packages, _c_includeDevDependencies, _c_devDependenciesOnly;
|
|
11
|
+
const configParser = _zod.z.object({
|
|
12
|
+
extends: _zod.z.string().optional(),
|
|
13
|
+
licenses: _zod.z.array(_zod.z.string()).optional(),
|
|
14
|
+
packages: _zod.z.array(_zod.z.string()).optional(),
|
|
15
|
+
includeDevDependencies: _zod.z.boolean().optional(),
|
|
16
|
+
devDependenciesOnly: _zod.z.boolean().optional(),
|
|
17
|
+
directory: _zod.z.string().optional()
|
|
18
|
+
}).transform((c)=>({
|
|
19
|
+
extends: c.extends,
|
|
20
|
+
licenses: (_c_licenses = c.licenses) != null ? _c_licenses : [],
|
|
21
|
+
packages: (_c_packages = c.packages) != null ? _c_packages : [],
|
|
22
|
+
includeDevDependencies: (_c_includeDevDependencies = c.includeDevDependencies) != null ? _c_includeDevDependencies : false,
|
|
23
|
+
devDependenciesOnly: (_c_devDependenciesOnly = c.devDependenciesOnly) != null ? _c_devDependenciesOnly : false
|
|
24
|
+
}));
|
|
25
|
+
const parseConfig = (config)=>{
|
|
26
|
+
const parseResult = configParser.safeParse(config);
|
|
27
|
+
if (!parseResult.success) {
|
|
28
|
+
console.error("Invalid config file");
|
|
29
|
+
throw new Error(parseResult.error.message);
|
|
30
|
+
}
|
|
31
|
+
return parseResult.data;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/license-cop/src/lib/config/config.ts"],"sourcesContent":["import { z } from \"zod\";\n\nconst configParser = z\n .object({\n extends: z.string().optional(),\n licenses: z.array(z.string()).optional(),\n packages: z.array(z.string()).optional(),\n includeDevDependencies: z.boolean().optional(),\n devDependenciesOnly: z.boolean().optional(),\n directory: z.string().optional()\n })\n .transform(c => ({\n extends: c.extends,\n licenses: c.licenses ?? [],\n packages: c.packages ?? [],\n includeDevDependencies: c.includeDevDependencies ?? false,\n devDependenciesOnly: c.devDependenciesOnly ?? false\n }));\n\nexport type Config = z.infer<typeof configParser>;\n\nexport const parseConfig = (config: unknown): Config => {\n const parseResult = configParser.safeParse(config);\n\n if (!parseResult.success) {\n console.error(\"Invalid config file\");\n throw new Error(parseResult.error.message);\n }\n\n return parseResult.data;\n};\n"],"names":["parseConfig","c","configParser","z","object","extends","string","optional","licenses","array","packages","includeDevDependencies","boolean","devDependenciesOnly","directory","transform","config","parseResult","safeParse","success","console","error","Error","message","data"],"mappings":";;;;+BAqBaA;;aAAAA;;qBArBK;IAaJC,aACAA,aACcA,2BACHA;AAdzB,MAAMC,eAAeC,MAAC,CACnBC,MAAM,CAAC;IACNC,SAASF,MAAC,CAACG,MAAM,GAAGC,QAAQ;IAC5BC,UAAUL,MAAC,CAACM,KAAK,CAACN,MAAC,CAACG,MAAM,IAAIC,QAAQ;IACtCG,UAAUP,MAAC,CAACM,KAAK,CAACN,MAAC,CAACG,MAAM,IAAIC,QAAQ;IACtCI,wBAAwBR,MAAC,CAACS,OAAO,GAAGL,QAAQ;IAC5CM,qBAAqBV,MAAC,CAACS,OAAO,GAAGL,QAAQ;IACzCO,WAAWX,MAAC,CAACG,MAAM,GAAGC,QAAQ;AAChC,GACCQ,SAAS,CAACd,CAAAA,IAAM,CAAA;QACfI,SAASJ,EAAEI,OAAO;QAClBG,UAAUP,CAAAA,cAAAA,EAAEO,QAAQ,YAAVP,cAAc,EAAE;QAC1BS,UAAUT,CAAAA,cAAAA,EAAES,QAAQ,YAAVT,cAAc,EAAE;QAC1BU,wBAAwBV,CAAAA,4BAAAA,EAAEU,sBAAsB,YAAxBV,4BAA4B,KAAK;QACzDY,qBAAqBZ,CAAAA,yBAAAA,EAAEY,mBAAmB,YAArBZ,yBAAyB,KAAK;IACrD,CAAA;AAIK,MAAMD,cAAc,CAACgB,SAA4B;IACtD,MAAMC,cAAcf,aAAagB,SAAS,CAACF;IAE3C,IAAI,CAACC,YAAYE,OAAO,EAAE;QACxBC,QAAQC,KAAK,CAAC;QACd,MAAM,IAAIC,MAAML,YAAYI,KAAK,CAACE,OAAO,EAAE;IAC7C,CAAC;IAED,OAAON,YAAYO,IAAI;AACzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const findConfig: (rootDir: string) => Promise<unknown>;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "findConfig", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: ()=>findConfig
|
|
8
|
+
});
|
|
9
|
+
const _interopRequireDefault = require("@swc/helpers/lib/_interop_require_default.js").default;
|
|
10
|
+
const _cosmiconfig = require("cosmiconfig");
|
|
11
|
+
const _json5 = /*#__PURE__*/ _interopRequireDefault(require("json5"));
|
|
12
|
+
// cspell:disable-next-line
|
|
13
|
+
const moduleNames = [
|
|
14
|
+
"licenses",
|
|
15
|
+
"licences",
|
|
16
|
+
"licensesrc",
|
|
17
|
+
"licencesrc"
|
|
18
|
+
];
|
|
19
|
+
const generateSearchPlaces = (moduleName)=>[
|
|
20
|
+
`.${moduleName}`,
|
|
21
|
+
`.${moduleName}.json`,
|
|
22
|
+
`.${moduleName}.jsonc`,
|
|
23
|
+
`.${moduleName}.json5`,
|
|
24
|
+
`.${moduleName}.yaml`,
|
|
25
|
+
`.${moduleName}.yml`,
|
|
26
|
+
`.${moduleName}.js`,
|
|
27
|
+
`.${moduleName}.cjs`,
|
|
28
|
+
`.config/${moduleName}`,
|
|
29
|
+
`.config/${moduleName}.json`,
|
|
30
|
+
`.config/${moduleName}.jsonc`,
|
|
31
|
+
`.config/${moduleName}.json5`,
|
|
32
|
+
`.config/${moduleName}.yaml`,
|
|
33
|
+
`.config/${moduleName}.yml`,
|
|
34
|
+
`.config/${moduleName}.js`,
|
|
35
|
+
`.config/${moduleName}.cjs`,
|
|
36
|
+
`${moduleName}.config.js`,
|
|
37
|
+
`${moduleName}.config.cjs`
|
|
38
|
+
];
|
|
39
|
+
const searchPlaces = [
|
|
40
|
+
"package.json"
|
|
41
|
+
];
|
|
42
|
+
for (const moduleName of moduleNames){
|
|
43
|
+
searchPlaces.push(...generateSearchPlaces(moduleName));
|
|
44
|
+
}
|
|
45
|
+
const json5Loader = (filepath, content)=>Promise.resolve(_json5.default.parse(content));
|
|
46
|
+
const findConfig = async (rootDir)=>{
|
|
47
|
+
const options = {
|
|
48
|
+
stopDir: rootDir,
|
|
49
|
+
searchPlaces,
|
|
50
|
+
loaders: {
|
|
51
|
+
".json": json5Loader,
|
|
52
|
+
".jsonc": json5Loader,
|
|
53
|
+
".json5": json5Loader
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
const explorer = (0, _cosmiconfig.cosmiconfig)("licensecop", options);
|
|
57
|
+
const result = await explorer.search(rootDir);
|
|
58
|
+
if (!(result == null ? void 0 : result.config)) {
|
|
59
|
+
throw new Error("No config file found");
|
|
60
|
+
}
|
|
61
|
+
return result.config;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
//# sourceMappingURL=find-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/license-cop/src/lib/config/find-config.ts"],"sourcesContent":["import { cosmiconfig, Options as CosmiconfigOptions, Loader } from \"cosmiconfig\";\nimport JSON5 from \"json5\";\n\n// cspell:disable-next-line\nconst moduleNames = [\"licenses\", \"licences\", \"licensesrc\", \"licencesrc\"];\n\nconst generateSearchPlaces = (moduleName: string): string[] => [\n `.${moduleName}`,\n `.${moduleName}.json`,\n `.${moduleName}.jsonc`,\n `.${moduleName}.json5`,\n `.${moduleName}.yaml`,\n `.${moduleName}.yml`,\n `.${moduleName}.js`,\n `.${moduleName}.cjs`,\n `.config/${moduleName}`,\n `.config/${moduleName}.json`,\n `.config/${moduleName}.jsonc`,\n `.config/${moduleName}.json5`,\n `.config/${moduleName}.yaml`,\n `.config/${moduleName}.yml`,\n `.config/${moduleName}.js`,\n `.config/${moduleName}.cjs`,\n `${moduleName}.config.js`,\n `${moduleName}.config.cjs`\n];\n\nconst searchPlaces: string[] = [\"package.json\"];\n\nfor (const moduleName of moduleNames) {\n searchPlaces.push(...generateSearchPlaces(moduleName));\n}\n\nconst json5Loader: Loader = (filepath, content) => Promise.resolve(JSON5.parse(content));\n\nexport const findConfig = async (rootDir: string): Promise<unknown> => {\n const options: CosmiconfigOptions = {\n stopDir: rootDir,\n searchPlaces,\n loaders: {\n \".json\": json5Loader,\n \".jsonc\": json5Loader,\n \".json5\": json5Loader\n }\n };\n\n const explorer = cosmiconfig(\"licensecop\", options);\n\n const result = await explorer.search(rootDir);\n\n if (!result?.config) {\n throw new Error(\"No config file found\");\n }\n\n return result.config;\n};\n"],"names":["findConfig","moduleNames","generateSearchPlaces","moduleName","searchPlaces","push","json5Loader","filepath","content","Promise","resolve","JSON5","parse","rootDir","options","stopDir","loaders","explorer","cosmiconfig","result","search","config","Error"],"mappings":";;;;+BAmCaA;;aAAAA;;;6BAnCsD;4DACjD;AAElB,2BAA2B;AAC3B,MAAMC,cAAc;IAAC;IAAY;IAAY;IAAc;CAAa;AAExE,MAAMC,uBAAuB,CAACC,aAAiC;QAC7D,CAAC,CAAC,EAAEA,WAAW,CAAC;QAChB,CAAC,CAAC,EAAEA,WAAW,KAAK,CAAC;QACrB,CAAC,CAAC,EAAEA,WAAW,MAAM,CAAC;QACtB,CAAC,CAAC,EAAEA,WAAW,MAAM,CAAC;QACtB,CAAC,CAAC,EAAEA,WAAW,KAAK,CAAC;QACrB,CAAC,CAAC,EAAEA,WAAW,IAAI,CAAC;QACpB,CAAC,CAAC,EAAEA,WAAW,GAAG,CAAC;QACnB,CAAC,CAAC,EAAEA,WAAW,IAAI,CAAC;QACpB,CAAC,QAAQ,EAAEA,WAAW,CAAC;QACvB,CAAC,QAAQ,EAAEA,WAAW,KAAK,CAAC;QAC5B,CAAC,QAAQ,EAAEA,WAAW,MAAM,CAAC;QAC7B,CAAC,QAAQ,EAAEA,WAAW,MAAM,CAAC;QAC7B,CAAC,QAAQ,EAAEA,WAAW,KAAK,CAAC;QAC5B,CAAC,QAAQ,EAAEA,WAAW,IAAI,CAAC;QAC3B,CAAC,QAAQ,EAAEA,WAAW,GAAG,CAAC;QAC1B,CAAC,QAAQ,EAAEA,WAAW,IAAI,CAAC;QAC3B,CAAC,EAAEA,WAAW,UAAU,CAAC;QACzB,CAAC,EAAEA,WAAW,WAAW,CAAC;KAC3B;AAED,MAAMC,eAAyB;IAAC;CAAe;AAE/C,KAAK,MAAMD,cAAcF,YAAa;IACpCG,aAAaC,IAAI,IAAIH,qBAAqBC;AAC5C;AAEA,MAAMG,cAAsB,CAACC,UAAUC,UAAYC,QAAQC,OAAO,CAACC,cAAK,CAACC,KAAK,CAACJ;AAExE,MAAMR,aAAa,OAAOa,UAAsC;IACrE,MAAMC,UAA8B;QAClCC,SAASF;QACTT;QACAY,SAAS;YACP,SAASV;YACT,UAAUA;YACV,UAAUA;QACZ;IACF;IAEA,MAAMW,WAAWC,IAAAA,wBAAW,EAAC,cAAcJ;IAE3C,MAAMK,SAAS,MAAMF,SAASG,MAAM,CAACP;IAErC,IAAI,CAACM,CAAAA,iBAAAA,KAAAA,IAAAA,OAAQE,MAAM,AAAD,GAAG;QACnB,MAAM,IAAIC,MAAM,wBAAwB;IAC1C,CAAC;IAED,OAAOH,OAAOE,MAAM;AACtB"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "loadConfig", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: ()=>loadConfig
|
|
8
|
+
});
|
|
9
|
+
const _interopRequireDefault = require("@swc/helpers/lib/_interop_require_default.js").default;
|
|
10
|
+
const _config = require("./config");
|
|
11
|
+
const _loadParentConfig = require("./load-parent-config");
|
|
12
|
+
const _deepmerge = /*#__PURE__*/ _interopRequireDefault(require("deepmerge"));
|
|
13
|
+
const _findConfig = require("./find-config");
|
|
14
|
+
const loadConfig = async (rootDir)=>{
|
|
15
|
+
const foundConfig = await (0, _findConfig.findConfig)(rootDir);
|
|
16
|
+
let config = (0, _config.parseConfig)(foundConfig);
|
|
17
|
+
while(config.extends){
|
|
18
|
+
const loadedParentConfig = await (0, _loadParentConfig.loadParentConfig)(config.extends, rootDir);
|
|
19
|
+
const parsedParentConfig = (0, _config.parseConfig)(loadedParentConfig);
|
|
20
|
+
config = (0, _deepmerge.default)(parsedParentConfig, config);
|
|
21
|
+
config.extends = parsedParentConfig.extends;
|
|
22
|
+
}
|
|
23
|
+
return config;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=load-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/license-cop/src/lib/config/load-config.ts"],"sourcesContent":["import { parseConfig } from \"./config\";\nimport { loadParentConfig } from \"./load-parent-config\";\nimport deepMerge from \"deepmerge\";\nimport { findConfig } from \"./find-config\";\n\nexport const loadConfig = async (rootDir: string) => {\n const foundConfig = await findConfig(rootDir);\n\n let config = parseConfig(foundConfig);\n\n while (config.extends) {\n const loadedParentConfig = await loadParentConfig(config.extends, rootDir);\n const parsedParentConfig = parseConfig(loadedParentConfig);\n\n config = deepMerge(parsedParentConfig, config);\n config.extends = parsedParentConfig.extends;\n }\n\n return config;\n};\n"],"names":["loadConfig","rootDir","foundConfig","findConfig","config","parseConfig","extends","loadedParentConfig","loadParentConfig","parsedParentConfig","deepMerge"],"mappings":";;;;+BAKaA;;aAAAA;;;wBALe;kCACK;gEACX;4BACK;AAEpB,MAAMA,aAAa,OAAOC,UAAoB;IACnD,MAAMC,cAAc,MAAMC,IAAAA,sBAAU,EAACF;IAErC,IAAIG,SAASC,IAAAA,mBAAW,EAACH;IAEzB,MAAOE,OAAOE,OAAO,CAAE;QACrB,MAAMC,qBAAqB,MAAMC,IAAAA,kCAAgB,EAACJ,OAAOE,OAAO,EAAEL;QAClE,MAAMQ,qBAAqBJ,IAAAA,mBAAW,EAACE;QAEvCH,SAASM,IAAAA,kBAAS,EAACD,oBAAoBL;QACvCA,OAAOE,OAAO,GAAGG,mBAAmBH,OAAO;IAC7C;IAEA,OAAOF;AACT"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const loadParentConfig: (parentConfigPath: string, rootDir: string) => Promise<unknown>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "loadParentConfig", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: ()=>loadParentConfig
|
|
8
|
+
});
|
|
9
|
+
const _github = require("./parent-resolutions/github");
|
|
10
|
+
const _npm = require("./parent-resolutions/npm");
|
|
11
|
+
const _http = require("./parent-resolutions/http");
|
|
12
|
+
const loadParentConfig = async (parentConfigPath, rootDir)=>{
|
|
13
|
+
if (parentConfigPath.startsWith("npm:")) {
|
|
14
|
+
const packageName = parentConfigPath.substring(4);
|
|
15
|
+
return await (0, _npm.npmResolution)(packageName, rootDir);
|
|
16
|
+
}
|
|
17
|
+
if (parentConfigPath.startsWith("github:")) {
|
|
18
|
+
const repo = parentConfigPath.substring(7);
|
|
19
|
+
return await (0, _github.githubResolution)(repo);
|
|
20
|
+
}
|
|
21
|
+
if (parentConfigPath.startsWith("http")) {
|
|
22
|
+
return await (0, _http.httpResolution)(parentConfigPath);
|
|
23
|
+
}
|
|
24
|
+
if (await (0, _npm.nodeModuleExists)(parentConfigPath, rootDir)) {
|
|
25
|
+
return await (0, _npm.npmResolution)(parentConfigPath, rootDir);
|
|
26
|
+
}
|
|
27
|
+
throw new Error(`Invalid parent config location: ${parentConfigPath}`);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=load-parent-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/license-cop/src/lib/config/load-parent-config.ts"],"sourcesContent":["import { githubResolution } from \"./parent-resolutions/github\";\nimport { nodeModuleExists, npmResolution } from \"./parent-resolutions/npm\";\nimport { httpResolution } from \"./parent-resolutions/http\";\n\nexport const loadParentConfig = async (\n parentConfigPath: string,\n rootDir: string\n): Promise<unknown> => {\n if (parentConfigPath.startsWith(\"npm:\")) {\n const packageName = parentConfigPath.substring(4);\n return await npmResolution(packageName, rootDir);\n }\n\n if (parentConfigPath.startsWith(\"github:\")) {\n const repo = parentConfigPath.substring(7);\n return await githubResolution(repo);\n }\n\n if (parentConfigPath.startsWith(\"http\")) {\n return await httpResolution(parentConfigPath);\n }\n\n if (await nodeModuleExists(parentConfigPath, rootDir)) {\n return await npmResolution(parentConfigPath, rootDir);\n }\n\n throw new Error(`Invalid parent config location: ${parentConfigPath}`);\n};\n"],"names":["loadParentConfig","parentConfigPath","rootDir","startsWith","packageName","substring","npmResolution","repo","githubResolution","httpResolution","nodeModuleExists","Error"],"mappings":";;;;+BAIaA;;aAAAA;;wBAJoB;qBACe;sBACjB;AAExB,MAAMA,mBAAmB,OAC9BC,kBACAC,UACqB;IACrB,IAAID,iBAAiBE,UAAU,CAAC,SAAS;QACvC,MAAMC,cAAcH,iBAAiBI,SAAS,CAAC;QAC/C,OAAO,MAAMC,IAAAA,kBAAa,EAACF,aAAaF;IAC1C,CAAC;IAED,IAAID,iBAAiBE,UAAU,CAAC,YAAY;QAC1C,MAAMI,OAAON,iBAAiBI,SAAS,CAAC;QACxC,OAAO,MAAMG,IAAAA,wBAAgB,EAACD;IAChC,CAAC;IAED,IAAIN,iBAAiBE,UAAU,CAAC,SAAS;QACvC,OAAO,MAAMM,IAAAA,oBAAc,EAACR;IAC9B,CAAC;IAED,IAAI,MAAMS,IAAAA,qBAAgB,EAACT,kBAAkBC,UAAU;QACrD,OAAO,MAAMI,IAAAA,kBAAa,EAACL,kBAAkBC;IAC/C,CAAC;IAED,MAAM,IAAIS,MAAM,CAAC,gCAAgC,EAAEV,iBAAiB,CAAC,EAAE;AACzE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const githubResolution: (repoId: string) => Promise<any>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "githubResolution", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: ()=>githubResolution
|
|
8
|
+
});
|
|
9
|
+
const _interopRequireDefault = require("@swc/helpers/lib/_interop_require_default.js").default;
|
|
10
|
+
const _gitFilesystem = require("git-filesystem");
|
|
11
|
+
const _json5 = /*#__PURE__*/ _interopRequireDefault(require("json5"));
|
|
12
|
+
const githubResolution = async (repoId)=>{
|
|
13
|
+
const parts = repoId.split("/");
|
|
14
|
+
if (parts.length !== 2 || parts[0].length === 0 || parts[1].length === 0) {
|
|
15
|
+
throw new Error(`Invalid GitHub repo ID: ${repoId}`);
|
|
16
|
+
}
|
|
17
|
+
const [owner, repoName] = parts;
|
|
18
|
+
const repo = new _gitFilesystem.GitHubClient(owner, "", "license-cop").getReadonlyRepository(repoName);
|
|
19
|
+
const fileContent = await repo.readFile(".licenses.json");
|
|
20
|
+
return _json5.default.parse(fileContent);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=github.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../packages/license-cop/src/lib/config/parent-resolutions/github.ts"],"sourcesContent":["import { GitHubClient } from \"git-filesystem\";\nimport JSON5 from \"json5\";\n\nexport const githubResolution = async (repoId: string) => {\n const parts = repoId.split(\"/\");\n\n if (parts.length !== 2 || parts[0].length === 0 || parts[1].length === 0) {\n throw new Error(`Invalid GitHub repo ID: ${repoId}`);\n }\n\n const [owner, repoName] = parts;\n\n const repo = new GitHubClient(owner, \"\", \"license-cop\").getReadonlyRepository(repoName);\n const fileContent = await repo.readFile(\".licenses.json\");\n\n return JSON5.parse(fileContent);\n};\n"],"names":["githubResolution","repoId","parts","split","length","Error","owner","repoName","repo","GitHubClient","getReadonlyRepository","fileContent","readFile","JSON5","parse"],"mappings":";;;;+BAGaA;;aAAAA;;;+BAHgB;4DACX;AAEX,MAAMA,mBAAmB,OAAOC,SAAmB;IACxD,MAAMC,QAAQD,OAAOE,KAAK,CAAC;IAE3B,IAAID,MAAME,MAAM,KAAK,KAAKF,KAAK,CAAC,EAAE,CAACE,MAAM,KAAK,KAAKF,KAAK,CAAC,EAAE,CAACE,MAAM,KAAK,GAAG;QACxE,MAAM,IAAIC,MAAM,CAAC,wBAAwB,EAAEJ,OAAO,CAAC,EAAE;IACvD,CAAC;IAED,MAAM,CAACK,OAAOC,SAAS,GAAGL;IAE1B,MAAMM,OAAO,IAAIC,2BAAY,CAACH,OAAO,IAAI,eAAeI,qBAAqB,CAACH;IAC9E,MAAMI,cAAc,MAAMH,KAAKI,QAAQ,CAAC;IAExC,OAAOC,cAAK,CAACC,KAAK,CAACH;AACrB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const httpResolution: (url: string) => Promise<any>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "httpResolution", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: ()=>httpResolution
|
|
8
|
+
});
|
|
9
|
+
const _interopRequireDefault = require("@swc/helpers/lib/_interop_require_default.js").default;
|
|
10
|
+
const _axios = /*#__PURE__*/ _interopRequireDefault(require("axios"));
|
|
11
|
+
const httpResolution = async (url)=>{
|
|
12
|
+
const response = await _axios.default.get(url);
|
|
13
|
+
return response.data;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=http.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../packages/license-cop/src/lib/config/parent-resolutions/http.ts"],"sourcesContent":["import axios from \"axios\";\n\nexport const httpResolution = async (url: string) => {\n const response = await axios.get(url);\n return response.data;\n};\n"],"names":["httpResolution","url","response","axios","get","data"],"mappings":";;;;+BAEaA;;aAAAA;;;4DAFK;AAEX,MAAMA,iBAAiB,OAAOC,MAAgB;IACnD,MAAMC,WAAW,MAAMC,cAAK,CAACC,GAAG,CAACH;IACjC,OAAOC,SAASG,IAAI;AACtB"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
npmResolution: ()=>npmResolution,
|
|
13
|
+
nodeModuleExists: ()=>nodeModuleExists
|
|
14
|
+
});
|
|
15
|
+
const _promises = require("fs/promises");
|
|
16
|
+
const _path = require("path");
|
|
17
|
+
const _findConfig = require("../find-config");
|
|
18
|
+
const npmResolution = async (packageName, rootDir)=>{
|
|
19
|
+
const packagePath = getPackagePath(rootDir, packageName);
|
|
20
|
+
return await (0, _findConfig.findConfig)(packagePath);
|
|
21
|
+
};
|
|
22
|
+
const nodeModuleExists = async (packageName, rootDir)=>{
|
|
23
|
+
const packagePath = getPackagePath(rootDir, packageName);
|
|
24
|
+
const statResult = await (0, _promises.stat)(packagePath);
|
|
25
|
+
return statResult.isDirectory();
|
|
26
|
+
};
|
|
27
|
+
const getPackagePath = (rootDir, packageName)=>(0, _path.join)(rootDir, "node_modules", packageName);
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=npm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../packages/license-cop/src/lib/config/parent-resolutions/npm.ts"],"sourcesContent":["import { stat } from \"fs/promises\";\nimport { join } from \"path\";\nimport { findConfig } from \"../find-config\";\n\nexport const npmResolution = async (packageName: string, rootDir: string) => {\n const packagePath = getPackagePath(rootDir, packageName);\n return await findConfig(packagePath);\n};\n\nexport const nodeModuleExists = async (packageName: string, rootDir: string) => {\n const packagePath = getPackagePath(rootDir, packageName);\n\n const statResult = await stat(packagePath);\n return statResult.isDirectory();\n};\n\nconst getPackagePath = (rootDir: string, packageName: string) =>\n join(rootDir, \"node_modules\", packageName);\n"],"names":["npmResolution","nodeModuleExists","packageName","rootDir","packagePath","getPackagePath","findConfig","statResult","stat","isDirectory","join"],"mappings":";;;;;;;;;;;IAIaA,aAAa,MAAbA;IAKAC,gBAAgB,MAAhBA;;0BATQ;sBACA;4BACM;AAEpB,MAAMD,gBAAgB,OAAOE,aAAqBC,UAAoB;IAC3E,MAAMC,cAAcC,eAAeF,SAASD;IAC5C,OAAO,MAAMI,IAAAA,sBAAU,EAACF;AAC1B;AAEO,MAAMH,mBAAmB,OAAOC,aAAqBC,UAAoB;IAC9E,MAAMC,cAAcC,eAAeF,SAASD;IAE5C,MAAMK,aAAa,MAAMC,IAAAA,cAAI,EAACJ;IAC9B,OAAOG,WAAWE,WAAW;AAC/B;AAEA,MAAMJ,iBAAiB,CAACF,SAAiBD,cACvCQ,IAAAA,UAAI,EAACP,SAAS,gBAAgBD"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface LicenseCopOptions {
|
|
2
|
+
allowedLicenses: string[];
|
|
3
|
+
allowedPackages: string[];
|
|
4
|
+
workingDirectory?: string;
|
|
5
|
+
includeDevDependencies?: boolean;
|
|
6
|
+
devDependenciesOnly?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare const checkLicenses: (options: LicenseCopOptions) => Promise<void>;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "checkLicenses", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: ()=>checkLicenses
|
|
8
|
+
});
|
|
9
|
+
const _interopRequireDefault = require("@swc/helpers/lib/_interop_require_default.js").default;
|
|
10
|
+
const _arborist = /*#__PURE__*/ _interopRequireDefault(require("@npmcli/arborist"));
|
|
11
|
+
const _path = require("path");
|
|
12
|
+
const _packageJson = require("./package-json");
|
|
13
|
+
const _packageRules = require("./package-rules");
|
|
14
|
+
const _violationsError = require("./violations-error");
|
|
15
|
+
const checkLicenses = async (options)=>{
|
|
16
|
+
const { workingDirectory , allowedLicenses , allowedPackages , includeDevDependencies , devDependenciesOnly } = options;
|
|
17
|
+
const allLicenses = new Set();
|
|
18
|
+
const packageViolations = new Set();
|
|
19
|
+
const path = resolvePath(workingDirectory);
|
|
20
|
+
const arborist = new _arborist.default({
|
|
21
|
+
path
|
|
22
|
+
});
|
|
23
|
+
const topNode = await arborist.loadActual();
|
|
24
|
+
console.log("Scanning dependencies of:", topNode.name);
|
|
25
|
+
const parseNodes = async (nodes)=>{
|
|
26
|
+
for (const node of nodes){
|
|
27
|
+
const isDevDependency = node.dev || node.devOptional;
|
|
28
|
+
if (!includeDevDependencies && !devDependenciesOnly && isDevDependency) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (devDependenciesOnly && !isDevDependency) {
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
const packageJsonPath = (0, _path.join)(node.realpath, "package.json");
|
|
35
|
+
const packageJson = await (0, _packageJson.readPackageJson)(packageJsonPath);
|
|
36
|
+
var _packageJson_license;
|
|
37
|
+
const license = (_packageJson_license = packageJson.license) != null ? _packageJson_license : "UNLICENSED";
|
|
38
|
+
allLicenses.add(license);
|
|
39
|
+
if ((0, _packageRules.isAllowedPackage)(node.name, packageJson.version, allowedPackages)) {
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (!(0, _packageRules.isAllowedLicense)(license, allowedLicenses)) {
|
|
43
|
+
packageViolations.add({
|
|
44
|
+
packageName: node.name,
|
|
45
|
+
packageVersion: packageJson.version,
|
|
46
|
+
license
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
if (node.children.size > 0) {
|
|
50
|
+
parseNodes(node.children.values());
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
await parseNodes(topNode.children.values());
|
|
55
|
+
if (packageViolations.size > 0) {
|
|
56
|
+
throw new _violationsError.ViolationsError(packageViolations);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
const resolvePath = (path)=>{
|
|
60
|
+
if (!path) {
|
|
61
|
+
return process.cwd();
|
|
62
|
+
}
|
|
63
|
+
return (0, _path.isAbsolute)(path) ? path : (0, _path.join)(process.cwd(), path);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
//# sourceMappingURL=license-cop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../packages/license-cop/src/lib/license-cop.ts"],"sourcesContent":["import Arborist, { Node, Link } from \"@npmcli/arborist\";\nimport { isAbsolute, join } from \"path\";\nimport { readPackageJson } from \"./package-json\";\nimport { isAllowedLicense, isAllowedPackage } from \"./package-rules\";\nimport { Violation, ViolationsError } from \"./violations-error\";\n\nexport interface LicenseCopOptions {\n allowedLicenses: string[];\n allowedPackages: string[];\n workingDirectory?: string;\n includeDevDependencies?: boolean;\n devDependenciesOnly?: boolean;\n}\n\nexport const checkLicenses = async (options: LicenseCopOptions): Promise<void> => {\n const {\n workingDirectory,\n allowedLicenses,\n allowedPackages,\n includeDevDependencies,\n devDependenciesOnly\n } = options;\n\n const allLicenses = new Set<string>();\n const packageViolations = new Set<Violation>();\n\n const path = resolvePath(workingDirectory);\n\n const arborist = new Arborist({\n path\n });\n\n const topNode = await arborist.loadActual();\n\n console.log(\"Scanning dependencies of:\", topNode.name);\n\n const parseNodes = async (nodes: IterableIterator<Node | Link>) => {\n for (const node of nodes) {\n const isDevDependency = node.dev || node.devOptional;\n\n if (!includeDevDependencies && !devDependenciesOnly && isDevDependency) {\n continue;\n }\n\n if (devDependenciesOnly && !isDevDependency) {\n continue;\n }\n\n const packageJsonPath = join(node.realpath, \"package.json\");\n const packageJson = await readPackageJson(packageJsonPath);\n\n const license = packageJson.license ?? \"UNLICENSED\";\n\n allLicenses.add(license);\n\n if (isAllowedPackage(node.name, packageJson.version, allowedPackages)) {\n continue;\n }\n\n if (!isAllowedLicense(license, allowedLicenses)) {\n packageViolations.add({\n packageName: node.name,\n packageVersion: packageJson.version,\n license\n });\n }\n\n if (node.children.size > 0) {\n parseNodes(node.children.values());\n }\n }\n };\n\n await parseNodes(topNode.children.values());\n\n if (packageViolations.size > 0) {\n throw new ViolationsError(packageViolations);\n }\n};\n\nconst resolvePath = (path?: string): string => {\n if (!path) {\n return process.cwd();\n }\n\n return isAbsolute(path) ? path : join(process.cwd(), path);\n};\n"],"names":["checkLicenses","options","workingDirectory","allowedLicenses","allowedPackages","includeDevDependencies","devDependenciesOnly","allLicenses","Set","packageViolations","path","resolvePath","arborist","Arborist","topNode","loadActual","console","log","name","parseNodes","nodes","node","isDevDependency","dev","devOptional","packageJsonPath","join","realpath","packageJson","readPackageJson","license","add","isAllowedPackage","version","isAllowedLicense","packageName","packageVersion","children","size","values","ViolationsError","process","cwd","isAbsolute"],"mappings":";;;;+BAcaA;;aAAAA;;;+DAdwB;sBACJ;6BACD;8BACmB;iCACR;AAUpC,MAAMA,gBAAgB,OAAOC,UAA8C;IAChF,MAAM,EACJC,iBAAgB,EAChBC,gBAAe,EACfC,gBAAe,EACfC,uBAAsB,EACtBC,oBAAmB,EACpB,GAAGL;IAEJ,MAAMM,cAAc,IAAIC;IACxB,MAAMC,oBAAoB,IAAID;IAE9B,MAAME,OAAOC,YAAYT;IAEzB,MAAMU,WAAW,IAAIC,iBAAQ,CAAC;QAC5BH;IACF;IAEA,MAAMI,UAAU,MAAMF,SAASG,UAAU;IAEzCC,QAAQC,GAAG,CAAC,6BAA6BH,QAAQI,IAAI;IAErD,MAAMC,aAAa,OAAOC,QAAyC;QACjE,KAAK,MAAMC,QAAQD,MAAO;YACxB,MAAME,kBAAkBD,KAAKE,GAAG,IAAIF,KAAKG,WAAW;YAEpD,IAAI,CAACnB,0BAA0B,CAACC,uBAAuBgB,iBAAiB;gBACtE,QAAS;YACX,CAAC;YAED,IAAIhB,uBAAuB,CAACgB,iBAAiB;gBAC3C,QAAS;YACX,CAAC;YAED,MAAMG,kBAAkBC,IAAAA,UAAI,EAACL,KAAKM,QAAQ,EAAE;YAC5C,MAAMC,cAAc,MAAMC,IAAAA,4BAAe,EAACJ;gBAE1BG;YAAhB,MAAME,UAAUF,CAAAA,uBAAAA,YAAYE,OAAO,YAAnBF,uBAAuB,YAAY;YAEnDrB,YAAYwB,GAAG,CAACD;YAEhB,IAAIE,IAAAA,8BAAgB,EAACX,KAAKH,IAAI,EAAEU,YAAYK,OAAO,EAAE7B,kBAAkB;gBACrE,QAAS;YACX,CAAC;YAED,IAAI,CAAC8B,IAAAA,8BAAgB,EAACJ,SAAS3B,kBAAkB;gBAC/CM,kBAAkBsB,GAAG,CAAC;oBACpBI,aAAad,KAAKH,IAAI;oBACtBkB,gBAAgBR,YAAYK,OAAO;oBACnCH;gBACF;YACF,CAAC;YAED,IAAIT,KAAKgB,QAAQ,CAACC,IAAI,GAAG,GAAG;gBAC1BnB,WAAWE,KAAKgB,QAAQ,CAACE,MAAM;YACjC,CAAC;QACH;IACF;IAEA,MAAMpB,WAAWL,QAAQuB,QAAQ,CAACE,MAAM;IAExC,IAAI9B,kBAAkB6B,IAAI,GAAG,GAAG;QAC9B,MAAM,IAAIE,gCAAe,CAAC/B,mBAAmB;IAC/C,CAAC;AACH;AAEA,MAAME,cAAc,CAACD,OAA0B;IAC7C,IAAI,CAACA,MAAM;QACT,OAAO+B,QAAQC,GAAG;IACpB,CAAC;IAED,OAAOC,IAAAA,gBAAU,EAACjC,QAAQA,OAAOgB,IAAAA,UAAI,EAACe,QAAQC,GAAG,IAAIhC,KAAK;AAC5D"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "readPackageJson", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: ()=>readPackageJson
|
|
8
|
+
});
|
|
9
|
+
const _promises = require("fs/promises");
|
|
10
|
+
const readPackageJson = async (pathToPackageJson)=>{
|
|
11
|
+
const doesPackageJsonExist = await doesFileExist(pathToPackageJson);
|
|
12
|
+
if (!doesPackageJsonExist) {
|
|
13
|
+
throw new Error(`Cannot find the file: '${pathToPackageJson}'`);
|
|
14
|
+
}
|
|
15
|
+
const packageJsonAsString = await (0, _promises.readFile)(pathToPackageJson, {
|
|
16
|
+
encoding: "utf8"
|
|
17
|
+
});
|
|
18
|
+
const packageJson = JSON.parse(packageJsonAsString);
|
|
19
|
+
return packageJson;
|
|
20
|
+
};
|
|
21
|
+
const doesFileExist = async (path)=>{
|
|
22
|
+
try {
|
|
23
|
+
const stats = await (0, _promises.stat)(path);
|
|
24
|
+
return stats.isFile();
|
|
25
|
+
} catch (e) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=package-json.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../packages/license-cop/src/lib/package-json.ts"],"sourcesContent":["import { Stats } from \"fs\";\nimport { readFile, stat } from \"fs/promises\";\n\ninterface PackageJson {\n version: string;\n license?: string;\n}\n\nexport const readPackageJson = async (pathToPackageJson: string): Promise<PackageJson> => {\n const doesPackageJsonExist = await doesFileExist(pathToPackageJson);\n if (!doesPackageJsonExist) {\n throw new Error(`Cannot find the file: '${pathToPackageJson}'`);\n }\n\n const packageJsonAsString: string = await readFile(pathToPackageJson, { encoding: \"utf8\" });\n\n const packageJson: PackageJson = JSON.parse(packageJsonAsString);\n return packageJson;\n};\n\nconst doesFileExist = async (path: string): Promise<boolean> => {\n try {\n const stats: Stats = await stat(path);\n return stats.isFile();\n } catch {\n return false;\n }\n};\n"],"names":["readPackageJson","pathToPackageJson","doesPackageJsonExist","doesFileExist","Error","packageJsonAsString","readFile","encoding","packageJson","JSON","parse","path","stats","stat","isFile"],"mappings":";;;;+BAQaA;;aAAAA;;0BAPkB;AAOxB,MAAMA,kBAAkB,OAAOC,oBAAoD;IACxF,MAAMC,uBAAuB,MAAMC,cAAcF;IACjD,IAAI,CAACC,sBAAsB;QACzB,MAAM,IAAIE,MAAM,CAAC,uBAAuB,EAAEH,kBAAkB,CAAC,CAAC,EAAE;IAClE,CAAC;IAED,MAAMI,sBAA8B,MAAMC,IAAAA,kBAAQ,EAACL,mBAAmB;QAAEM,UAAU;IAAO;IAEzF,MAAMC,cAA2BC,KAAKC,KAAK,CAACL;IAC5C,OAAOG;AACT;AAEA,MAAML,gBAAgB,OAAOQ,OAAmC;IAC9D,IAAI;QACF,MAAMC,QAAe,MAAMC,IAAAA,cAAI,EAACF;QAChC,OAAOC,MAAME,MAAM;IACrB,EAAE,UAAM;QACN,OAAO,KAAK;IACd;AACF"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
isAllowedPackage: ()=>isAllowedPackage,
|
|
13
|
+
isAllowedLicense: ()=>isAllowedLicense
|
|
14
|
+
});
|
|
15
|
+
const _compareVersions = require("compare-versions");
|
|
16
|
+
const isAllowedPackage = (packageName, packageVersion, allowedPackages)=>{
|
|
17
|
+
for (const allowedPackage of allowedPackages){
|
|
18
|
+
if (allowedPackage === packageName) {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
if (allowedPackage.startsWith(packageName + "@")) {
|
|
22
|
+
const allowedPackageVersion = allowedPackage.substring(packageName.length + 1);
|
|
23
|
+
if ((0, _compareVersions.satisfies)(packageVersion, allowedPackageVersion)) {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return false;
|
|
29
|
+
};
|
|
30
|
+
const isAllowedLicense = (license, allowedLicenses)=>{
|
|
31
|
+
return allowedLicenses.includes(license);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=package-rules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../packages/license-cop/src/lib/package-rules.ts"],"sourcesContent":["import { satisfies } from \"compare-versions\";\n\nexport const isAllowedPackage = (\n packageName: string,\n packageVersion: string,\n allowedPackages: string[]\n) => {\n for (const allowedPackage of allowedPackages) {\n if (allowedPackage === packageName) {\n return true;\n }\n\n if (allowedPackage.startsWith(packageName + \"@\")) {\n const allowedPackageVersion = allowedPackage.substring(packageName.length + 1);\n\n if (satisfies(packageVersion, allowedPackageVersion)) {\n return true;\n }\n }\n }\n\n return false;\n};\n\nexport const isAllowedLicense = (license: string, allowedLicenses: string[]) => {\n return allowedLicenses.includes(license);\n};\n"],"names":["isAllowedPackage","isAllowedLicense","packageName","packageVersion","allowedPackages","allowedPackage","startsWith","allowedPackageVersion","substring","length","satisfies","license","allowedLicenses","includes"],"mappings":";;;;;;;;;;;IAEaA,gBAAgB,MAAhBA;IAsBAC,gBAAgB,MAAhBA;;iCAxBa;AAEnB,MAAMD,mBAAmB,CAC9BE,aACAC,gBACAC,kBACG;IACH,KAAK,MAAMC,kBAAkBD,gBAAiB;QAC5C,IAAIC,mBAAmBH,aAAa;YAClC,OAAO,IAAI;QACb,CAAC;QAED,IAAIG,eAAeC,UAAU,CAACJ,cAAc,MAAM;YAChD,MAAMK,wBAAwBF,eAAeG,SAAS,CAACN,YAAYO,MAAM,GAAG;YAE5E,IAAIC,IAAAA,0BAAS,EAACP,gBAAgBI,wBAAwB;gBACpD,OAAO,IAAI;YACb,CAAC;QACH,CAAC;IACH;IAEA,OAAO,KAAK;AACd;AAEO,MAAMN,mBAAmB,CAACU,SAAiBC,kBAA8B;IAC9E,OAAOA,gBAAgBC,QAAQ,CAACF;AAClC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "ViolationsError", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: ()=>ViolationsError
|
|
8
|
+
});
|
|
9
|
+
let ViolationsError = class ViolationsError extends Error {
|
|
10
|
+
constructor(violations){
|
|
11
|
+
super();
|
|
12
|
+
this.violations = violations;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=violations-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../packages/license-cop/src/lib/violations-error.ts"],"sourcesContent":["export class ViolationsError extends Error {\n constructor(public readonly violations: Set<Violation>) {\n super();\n }\n}\n\nexport interface Violation {\n packageName: string;\n packageVersion: string;\n license: string;\n}\n"],"names":["ViolationsError","Error","constructor","violations"],"mappings":";;;;+BAAaA;;aAAAA;;AAAN,IAAA,AAAMA,kBAAN,MAAMA,wBAAwBC;IACnCC,YAA4BC,WAA4B;QACtD,KAAK;0BADqBA;IAE5B;AACF"}
|