license-cop 1.9.0 → 2.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 +1 -1
- package/README.md +25 -5
- package/dist/bin.js +545 -0
- package/dist/bin.js.map +1 -0
- package/package.json +21 -14
- package/src/bin/license-cop +0 -4
- package/src/index.d.ts +0 -3
- package/src/index.js +0 -10
- package/src/index.js.map +0 -1
- package/src/lib/cli/commands/init.d.ts +0 -5
- package/src/lib/cli/commands/init.js +0 -39
- package/src/lib/cli/commands/init.js.map +0 -1
- package/src/lib/cli/commands/main.d.ts +0 -7
- package/src/lib/cli/commands/main.js +0 -61
- package/src/lib/cli/commands/main.js.map +0 -1
- package/src/lib/cli/commands/version.d.ts +0 -4
- package/src/lib/cli/commands/version.js +0 -21
- package/src/lib/cli/commands/version.js.map +0 -1
- package/src/lib/cli/create-command.d.ts +0 -5
- package/src/lib/cli/create-command.js +0 -17
- package/src/lib/cli/create-command.js.map +0 -1
- package/src/lib/cli/index.d.ts +0 -1
- package/src/lib/cli/index.js +0 -18
- package/src/lib/cli/index.js.map +0 -1
- package/src/lib/cli/report-failure.d.ts +0 -2
- package/src/lib/cli/report-failure.js +0 -36
- package/src/lib/cli/report-failure.js.map +0 -1
- package/src/lib/cli/report-success.d.ts +0 -2
- package/src/lib/cli/report-success.js +0 -22
- package/src/lib/cli/report-success.js.map +0 -1
- package/src/lib/config/config-error.d.ts +0 -4
- package/src/lib/config/config-error.js +0 -27
- package/src/lib/config/config-error.js.map +0 -1
- package/src/lib/config/config.d.ts +0 -25
- package/src/lib/config/config.js +0 -35
- package/src/lib/config/config.js.map +0 -1
- package/src/lib/config/find-config.d.ts +0 -1
- package/src/lib/config/find-config.js +0 -67
- package/src/lib/config/find-config.js.map +0 -1
- package/src/lib/config/load-config.d.ts +0 -7
- package/src/lib/config/load-config.js +0 -26
- package/src/lib/config/load-config.js.map +0 -1
- package/src/lib/config/load-parent-config.d.ts +0 -1
- package/src/lib/config/load-parent-config.js +0 -30
- package/src/lib/config/load-parent-config.js.map +0 -1
- package/src/lib/config/parent-resolutions/github.d.ts +0 -1
- package/src/lib/config/parent-resolutions/github.js +0 -28
- package/src/lib/config/parent-resolutions/github.js.map +0 -1
- package/src/lib/config/parent-resolutions/http.d.ts +0 -1
- package/src/lib/config/parent-resolutions/http.js +0 -20
- package/src/lib/config/parent-resolutions/http.js.map +0 -1
- package/src/lib/config/parent-resolutions/npm.d.ts +0 -2
- package/src/lib/config/parent-resolutions/npm.js +0 -32
- package/src/lib/config/parent-resolutions/npm.js.map +0 -1
- package/src/lib/config/parsers/json5.d.ts +0 -1
- package/src/lib/config/parsers/json5.js +0 -11
- package/src/lib/config/parsers/json5.js.map +0 -1
- package/src/lib/dependency/get-package-manager.d.ts +0 -2
- package/src/lib/dependency/get-package-manager.js +0 -52
- package/src/lib/dependency/get-package-manager.js.map +0 -1
- package/src/lib/dependency/package-json.d.ts +0 -18
- package/src/lib/dependency/package-json.js +0 -75
- package/src/lib/dependency/package-json.js.map +0 -1
- package/src/lib/dependency/package-rules.d.ts +0 -1
- package/src/lib/dependency/package-rules.js +0 -24
- package/src/lib/dependency/package-rules.js.map +0 -1
- package/src/lib/dependency-scanning/npm.d.ts +0 -3
- package/src/lib/dependency-scanning/npm.js +0 -100
- package/src/lib/dependency-scanning/npm.js.map +0 -1
- package/src/lib/dependency-scanning/options.d.ts +0 -2
- package/src/lib/dependency-scanning/options.js +0 -3
- package/src/lib/dependency-scanning/options.js.map +0 -1
- package/src/lib/dependency-scanning/pnpm.d.ts +0 -3
- package/src/lib/dependency-scanning/pnpm.js +0 -103
- package/src/lib/dependency-scanning/pnpm.js.map +0 -1
- package/src/lib/license-cop.d.ts +0 -9
- package/src/lib/license-cop.js +0 -51
- package/src/lib/license-cop.js.map +0 -1
- package/src/lib/logger.d.ts +0 -8
- package/src/lib/logger.js +0 -41
- package/src/lib/logger.js.map +0 -1
- package/src/lib/result.d.ts +0 -27
- package/src/lib/result.js +0 -3
- package/src/lib/result.js.map +0 -1
- package/src/lib/spdx/calculate-issues.d.ts +0 -2
- package/src/lib/spdx/calculate-issues.js +0 -45
- package/src/lib/spdx/calculate-issues.js.map +0 -1
- package/src/lib/spdx/get-tokens.d.ts +0 -2
- package/src/lib/spdx/get-tokens.js +0 -54
- package/src/lib/spdx/get-tokens.js.map +0 -1
- package/src/lib/spdx/parse-license-expression.d.ts +0 -2
- package/src/lib/spdx/parse-license-expression.js +0 -20
- package/src/lib/spdx/parse-license-expression.js.map +0 -1
- package/src/lib/spdx/parse-tokens.d.ts +0 -3
- package/src/lib/spdx/parse-tokens.js +0 -122
- package/src/lib/spdx/parse-tokens.js.map +0 -1
- package/src/lib/spdx/types/spdx-expression.d.ts +0 -20
- package/src/lib/spdx/types/spdx-expression.js +0 -3
- package/src/lib/spdx/types/spdx-expression.js.map +0 -1
- package/src/lib/spdx/types/token.d.ts +0 -23
- package/src/lib/spdx/types/token.js +0 -29
- package/src/lib/spdx/types/token.js.map +0 -1
- package/src/lib/utils/join-string-array.d.ts +0 -1
- package/src/lib/utils/join-string-array.js +0 -28
- package/src/lib/utils/join-string-array.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../packages/license-cop/src/lib/dependency-scanning/options.ts"],"names":[],"mappings":""}
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "pnpmDependencyScanning", {
|
|
3
|
-
enumerable: true,
|
|
4
|
-
get: function() {
|
|
5
|
-
return pnpmDependencyScanning;
|
|
6
|
-
}
|
|
7
|
-
});
|
|
8
|
-
const _reviewingdependencieshierarchy = require("@pnpm/reviewing.dependencies-hierarchy");
|
|
9
|
-
const _nodepath = require("node:path");
|
|
10
|
-
const _packagejson = require("../dependency/package-json");
|
|
11
|
-
const _packagerules = require("../dependency/package-rules");
|
|
12
|
-
const _logger = require("../logger");
|
|
13
|
-
const _calculateissues = require("../spdx/calculate-issues");
|
|
14
|
-
const _parselicenseexpression = require("../spdx/parse-license-expression");
|
|
15
|
-
const _joinstringarray = require("../utils/join-string-array");
|
|
16
|
-
const pnpmDependencyScanning = async (options)=>{
|
|
17
|
-
const { workingDirectory, allowedLicenses, allowedPackages, includeDevDependencies, devDependenciesOnly } = options;
|
|
18
|
-
const foundAllowedPackages = new Map();
|
|
19
|
-
const packagesWithAllowedLicenses = new Map();
|
|
20
|
-
const packagesWithNoLicenses = new Map();
|
|
21
|
-
const packagesWithForbiddenLicenses = new Map();
|
|
22
|
-
const dependencyHierarchies = await (0, _reviewingdependencieshierarchy.buildDependenciesTree)([
|
|
23
|
-
workingDirectory
|
|
24
|
-
], {
|
|
25
|
-
depth: Infinity,
|
|
26
|
-
include: {
|
|
27
|
-
dependencies: !devDependenciesOnly,
|
|
28
|
-
devDependencies: includeDevDependencies,
|
|
29
|
-
optionalDependencies: false
|
|
30
|
-
},
|
|
31
|
-
lockfileDir: workingDirectory,
|
|
32
|
-
virtualStoreDirMaxLength: Infinity
|
|
33
|
-
});
|
|
34
|
-
// This function is very similar to the one in npm.ts
|
|
35
|
-
// If you change this, you probably want to change that one too
|
|
36
|
-
const parseNode = async (node)=>{
|
|
37
|
-
_logger.default.verbose(`Parsing node: ${node.name}`);
|
|
38
|
-
const pkgId = `${node.alias}@${node.version}`;
|
|
39
|
-
const packageJsonPath = (0, _nodepath.join)(node.path, "package.json");
|
|
40
|
-
const packageJson = await (0, _packagejson.readPackageJson)(packageJsonPath);
|
|
41
|
-
if ((0, _packagerules.isAllowedPackage)(packageJson.name, packageJson.version, allowedPackages)) {
|
|
42
|
-
_logger.default.verbose(`Package ${packageJson.name} is an allowed package`);
|
|
43
|
-
foundAllowedPackages.set(pkgId, {
|
|
44
|
-
name: packageJson.name,
|
|
45
|
-
version: packageJson.version
|
|
46
|
-
});
|
|
47
|
-
await parseNodes(node.dependencies);
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
const rawLicenseExpression = (0, _packagejson.getLicenseExpression)(packageJson);
|
|
51
|
-
const licenseExpression = (0, _parselicenseexpression.parseLicenseExpression)(rawLicenseExpression);
|
|
52
|
-
if (licenseExpression.type === "unlicensed") {
|
|
53
|
-
_logger.default.verbose(`Package ${packageJson.name} is unlicensed`);
|
|
54
|
-
packagesWithNoLicenses.set(pkgId, {
|
|
55
|
-
name: packageJson.name,
|
|
56
|
-
version: packageJson.version
|
|
57
|
-
});
|
|
58
|
-
await parseNodes(node.dependencies);
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
const licenseIssues = (0, _calculateissues.calculateIssues)(licenseExpression, allowedLicenses);
|
|
62
|
-
const joinedIssues = (0, _joinstringarray.joinStringArray)(licenseIssues);
|
|
63
|
-
if (licenseIssues.length > 0) {
|
|
64
|
-
_logger.default.verbose(`Package ${packageJson.name} has the forbidden license: ${joinedIssues}`);
|
|
65
|
-
packagesWithForbiddenLicenses.set(pkgId, {
|
|
66
|
-
name: packageJson.name,
|
|
67
|
-
version: packageJson.version,
|
|
68
|
-
licenseIdentifiers: joinedIssues,
|
|
69
|
-
spdxExpression: rawLicenseExpression
|
|
70
|
-
});
|
|
71
|
-
} else {
|
|
72
|
-
_logger.default.verbose(`Package ${packageJson.name} has the allowed license: ${rawLicenseExpression}`);
|
|
73
|
-
packagesWithAllowedLicenses.set(pkgId, {
|
|
74
|
-
name: packageJson.name,
|
|
75
|
-
version: packageJson.version,
|
|
76
|
-
spdxExpression: rawLicenseExpression,
|
|
77
|
-
licenses: licenseExpression
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
await parseNodes(node.dependencies);
|
|
81
|
-
};
|
|
82
|
-
const parseNodes = async (nodes)=>{
|
|
83
|
-
if (!nodes) {
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
for (const node of nodes){
|
|
87
|
-
await parseNode(node);
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
for (const hierarchies of Object.values(dependencyHierarchies)){
|
|
91
|
-
await parseNodes(hierarchies.dependencies);
|
|
92
|
-
await parseNodes(hierarchies.devDependencies);
|
|
93
|
-
await parseNodes(hierarchies.optionalDependencies);
|
|
94
|
-
}
|
|
95
|
-
return {
|
|
96
|
-
allowedPackages: new Set(foundAllowedPackages.values()),
|
|
97
|
-
allowedLicenses: new Set(packagesWithAllowedLicenses.values()),
|
|
98
|
-
noLicenses: new Set(packagesWithNoLicenses.values()),
|
|
99
|
-
forbiddenLicenses: new Set(packagesWithForbiddenLicenses.values())
|
|
100
|
-
};
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
//# sourceMappingURL=pnpm.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../packages/license-cop/src/lib/dependency-scanning/pnpm.ts"],"sourcesContent":["import { buildDependenciesTree, DependencyNode } from \"@pnpm/reviewing.dependencies-hierarchy\";\nimport { join } from \"node:path\";\nimport { getLicenseExpression, readPackageJson } from \"../dependency/package-json\";\nimport { isAllowedPackage } from \"../dependency/package-rules\";\nimport logger from \"../logger\";\nimport {\n AllowedPackage,\n CheckLicensesResult,\n ForbiddenLicenseResult,\n LicensedPackage,\n NoLicenseResult\n} from \"../result\";\nimport { calculateIssues } from \"../spdx/calculate-issues\";\nimport { parseLicenseExpression } from \"../spdx/parse-license-expression\";\nimport { joinStringArray } from \"../utils/join-string-array\";\nimport { DependencyScanningOptions } from \"./options\";\n\nexport const pnpmDependencyScanning = async (\n options: DependencyScanningOptions\n): Promise<CheckLicensesResult> => {\n const {\n workingDirectory,\n allowedLicenses,\n allowedPackages,\n includeDevDependencies,\n devDependenciesOnly\n } = options;\n\n const foundAllowedPackages = new Map<string, AllowedPackage>();\n const packagesWithAllowedLicenses = new Map<string, LicensedPackage>();\n const packagesWithNoLicenses = new Map<string, NoLicenseResult>();\n const packagesWithForbiddenLicenses = new Map<string, ForbiddenLicenseResult>();\n\n const dependencyHierarchies = await buildDependenciesTree([workingDirectory], {\n depth: Infinity,\n include: {\n dependencies: !devDependenciesOnly,\n devDependencies: includeDevDependencies,\n optionalDependencies: false\n },\n lockfileDir: workingDirectory,\n virtualStoreDirMaxLength: Infinity\n });\n\n // This function is very similar to the one in npm.ts\n // If you change this, you probably want to change that one too\n const parseNode = async (node: DependencyNode) => {\n logger.verbose(`Parsing node: ${node.name}`);\n\n const pkgId = `${node.alias}@${node.version}`;\n const packageJsonPath = join(node.path, \"package.json\");\n const packageJson = await readPackageJson(packageJsonPath);\n\n if (isAllowedPackage(packageJson.name, packageJson.version, allowedPackages)) {\n logger.verbose(`Package ${packageJson.name} is an allowed package`);\n foundAllowedPackages.set(pkgId, {\n name: packageJson.name,\n version: packageJson.version\n });\n\n await parseNodes(node.dependencies);\n return;\n }\n\n const rawLicenseExpression = getLicenseExpression(packageJson);\n const licenseExpression = parseLicenseExpression(rawLicenseExpression);\n\n if (licenseExpression.type === \"unlicensed\") {\n logger.verbose(`Package ${packageJson.name} is unlicensed`);\n packagesWithNoLicenses.set(pkgId, {\n name: packageJson.name,\n version: packageJson.version\n });\n\n await parseNodes(node.dependencies);\n return;\n }\n\n const licenseIssues = calculateIssues(licenseExpression, allowedLicenses);\n const joinedIssues = joinStringArray(licenseIssues);\n\n if (licenseIssues.length > 0) {\n logger.verbose(`Package ${packageJson.name} has the forbidden license: ${joinedIssues}`);\n packagesWithForbiddenLicenses.set(pkgId, {\n name: packageJson.name,\n version: packageJson.version,\n licenseIdentifiers: joinedIssues,\n spdxExpression: rawLicenseExpression\n });\n } else {\n logger.verbose(\n `Package ${packageJson.name} has the allowed license: ${rawLicenseExpression}`\n );\n packagesWithAllowedLicenses.set(pkgId, {\n name: packageJson.name,\n version: packageJson.version,\n spdxExpression: rawLicenseExpression,\n licenses: licenseExpression\n });\n }\n\n await parseNodes(node.dependencies);\n };\n\n const parseNodes = async (nodes: DependencyNode[] | undefined) => {\n if (!nodes) {\n return;\n }\n\n for (const node of nodes) {\n await parseNode(node);\n }\n };\n\n for (const hierarchies of Object.values(dependencyHierarchies)) {\n await parseNodes(hierarchies.dependencies);\n await parseNodes(hierarchies.devDependencies);\n await parseNodes(hierarchies.optionalDependencies);\n }\n\n return {\n allowedPackages: new Set(foundAllowedPackages.values()),\n allowedLicenses: new Set(packagesWithAllowedLicenses.values()),\n noLicenses: new Set(packagesWithNoLicenses.values()),\n forbiddenLicenses: new Set(packagesWithForbiddenLicenses.values())\n };\n};\n"],"names":["pnpmDependencyScanning","options","workingDirectory","allowedLicenses","allowedPackages","includeDevDependencies","devDependenciesOnly","foundAllowedPackages","Map","packagesWithAllowedLicenses","packagesWithNoLicenses","packagesWithForbiddenLicenses","dependencyHierarchies","buildDependenciesTree","depth","Infinity","include","dependencies","devDependencies","optionalDependencies","lockfileDir","virtualStoreDirMaxLength","parseNode","node","logger","verbose","name","pkgId","alias","version","packageJsonPath","join","path","packageJson","readPackageJson","isAllowedPackage","set","parseNodes","rawLicenseExpression","getLicenseExpression","licenseExpression","parseLicenseExpression","type","licenseIssues","calculateIssues","joinedIssues","joinStringArray","length","licenseIdentifiers","spdxExpression","licenses","nodes","hierarchies","Object","values","Set","noLicenses","forbiddenLicenses"],"mappings":"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"}
|
package/src/lib/license-cop.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { CheckLicensesResult } from "./result";
|
|
2
|
-
export type LicenseCopOptions = {
|
|
3
|
-
allowedLicenses: string[];
|
|
4
|
-
allowedPackages: string[];
|
|
5
|
-
workingDirectory?: string;
|
|
6
|
-
includeDevDependencies?: boolean;
|
|
7
|
-
devDependenciesOnly?: boolean;
|
|
8
|
-
};
|
|
9
|
-
export declare const checkLicenses: (options: LicenseCopOptions) => Promise<CheckLicensesResult>;
|
package/src/lib/license-cop.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "checkLicenses", {
|
|
3
|
-
enumerable: true,
|
|
4
|
-
get: function() {
|
|
5
|
-
return checkLicenses;
|
|
6
|
-
}
|
|
7
|
-
});
|
|
8
|
-
const _path = require("path");
|
|
9
|
-
const _npm = require("./dependency-scanning/npm");
|
|
10
|
-
const _pnpm = require("./dependency-scanning/pnpm");
|
|
11
|
-
const _getpackagemanager = require("./dependency/get-package-manager");
|
|
12
|
-
function _extends() {
|
|
13
|
-
_extends = Object.assign || function(target) {
|
|
14
|
-
for(var i = 1; i < arguments.length; i++){
|
|
15
|
-
var source = arguments[i];
|
|
16
|
-
for(var key in source){
|
|
17
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
18
|
-
target[key] = source[key];
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
return target;
|
|
23
|
-
};
|
|
24
|
-
return _extends.apply(this, arguments);
|
|
25
|
-
}
|
|
26
|
-
const checkLicenses = async (options)=>{
|
|
27
|
-
var _options_includeDevDependencies, _options_devDependenciesOnly;
|
|
28
|
-
const fullProjectPath = resolvePath(options.workingDirectory);
|
|
29
|
-
const includeDevDependencies = (_options_includeDevDependencies = options.includeDevDependencies) != null ? _options_includeDevDependencies : false;
|
|
30
|
-
const devDependenciesOnly = (_options_devDependenciesOnly = options.devDependenciesOnly) != null ? _options_devDependenciesOnly : false;
|
|
31
|
-
const dependencyScanningOptions = _extends({}, options, {
|
|
32
|
-
workingDirectory: fullProjectPath,
|
|
33
|
-
includeDevDependencies,
|
|
34
|
-
devDependenciesOnly
|
|
35
|
-
});
|
|
36
|
-
const packageManager = await (0, _getpackagemanager.getPackageManager)(fullProjectPath);
|
|
37
|
-
switch(packageManager){
|
|
38
|
-
case "pnpm":
|
|
39
|
-
return (0, _pnpm.pnpmDependencyScanning)(dependencyScanningOptions);
|
|
40
|
-
default:
|
|
41
|
-
return (0, _npm.npmDependencyScanning)(dependencyScanningOptions);
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
const resolvePath = (path)=>{
|
|
45
|
-
if (!path) {
|
|
46
|
-
return process.cwd();
|
|
47
|
-
}
|
|
48
|
-
return (0, _path.isAbsolute)(path) ? path : (0, _path.join)(process.cwd(), path);
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
//# sourceMappingURL=license-cop.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../packages/license-cop/src/lib/license-cop.ts"],"sourcesContent":["import { isAbsolute, join } from \"path\";\nimport { npmDependencyScanning } from \"./dependency-scanning/npm\";\nimport { DependencyScanningOptions } from \"./dependency-scanning/options\";\nimport { pnpmDependencyScanning } from \"./dependency-scanning/pnpm\";\nimport { getPackageManager } from \"./dependency/get-package-manager\";\nimport { CheckLicensesResult } from \"./result\";\n\nexport type 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<CheckLicensesResult> => {\n const fullProjectPath = resolvePath(options.workingDirectory);\n const includeDevDependencies = options.includeDevDependencies ?? false;\n const devDependenciesOnly = options.devDependenciesOnly ?? false;\n\n const dependencyScanningOptions: DependencyScanningOptions = {\n ...options,\n workingDirectory: fullProjectPath,\n includeDevDependencies,\n devDependenciesOnly\n };\n\n const packageManager = await getPackageManager(fullProjectPath);\n\n switch (packageManager) {\n case \"pnpm\":\n return pnpmDependencyScanning(dependencyScanningOptions);\n default:\n return npmDependencyScanning(dependencyScanningOptions);\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","fullProjectPath","resolvePath","workingDirectory","includeDevDependencies","devDependenciesOnly","dependencyScanningOptions","packageManager","getPackageManager","pnpmDependencyScanning","npmDependencyScanning","path","process","cwd","isAbsolute","join"],"mappings":";+BAeaA;;;eAAAA;;;sBAfoB;qBACK;sBAEC;mCACL;;;;;;;;;;;;;;;AAW3B,MAAMA,gBAAgB,OAAOC;QAEHA,iCACHA;IAF5B,MAAMC,kBAAkBC,YAAYF,QAAQG,gBAAgB;IAC5D,MAAMC,0BAAyBJ,kCAAAA,QAAQI,sBAAsB,YAA9BJ,kCAAkC;IACjE,MAAMK,uBAAsBL,+BAAAA,QAAQK,mBAAmB,YAA3BL,+BAA+B;IAE3D,MAAMM,4BAAuD,aACxDN;QACHG,kBAAkBF;QAClBG;QACAC;;IAGF,MAAME,iBAAiB,MAAMC,IAAAA,oCAAiB,EAACP;IAE/C,OAAQM;QACN,KAAK;YACH,OAAOE,IAAAA,4BAAsB,EAACH;QAChC;YACE,OAAOI,IAAAA,0BAAqB,EAACJ;IACjC;AACF;AAEA,MAAMJ,cAAc,CAACS;IACnB,IAAI,CAACA,MAAM;QACT,OAAOC,QAAQC,GAAG;IACpB;IAEA,OAAOC,IAAAA,gBAAU,EAACH,QAAQA,OAAOI,IAAAA,UAAI,EAACH,QAAQC,GAAG,IAAIF;AACvD"}
|
package/src/lib/logger.d.ts
DELETED
package/src/lib/logger.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "default", {
|
|
3
|
-
enumerable: true,
|
|
4
|
-
get: function() {
|
|
5
|
-
return _default;
|
|
6
|
-
}
|
|
7
|
-
});
|
|
8
|
-
let loggerEnabled = false;
|
|
9
|
-
let verboseEnabled = false;
|
|
10
|
-
const enableLogging = ()=>{
|
|
11
|
-
loggerEnabled = true;
|
|
12
|
-
};
|
|
13
|
-
const enableVerboseLogging = ()=>{
|
|
14
|
-
verboseEnabled = true;
|
|
15
|
-
verbose("Verbose logging enabled");
|
|
16
|
-
};
|
|
17
|
-
const log = (message)=>{
|
|
18
|
-
if (loggerEnabled) {
|
|
19
|
-
console.log(message);
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
const verbose = (message)=>{
|
|
23
|
-
if (loggerEnabled && verboseEnabled) {
|
|
24
|
-
log(message);
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
const error = (message)=>{
|
|
28
|
-
if (loggerEnabled) {
|
|
29
|
-
console.error(message);
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
const logger = {
|
|
33
|
-
enableLogging,
|
|
34
|
-
enableVerboseLogging,
|
|
35
|
-
log,
|
|
36
|
-
verbose,
|
|
37
|
-
error
|
|
38
|
-
};
|
|
39
|
-
const _default = logger;
|
|
40
|
-
|
|
41
|
-
//# sourceMappingURL=logger.js.map
|
package/src/lib/logger.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../packages/license-cop/src/lib/logger.ts"],"sourcesContent":["let loggerEnabled = false;\nlet verboseEnabled = false;\n\nconst enableLogging = () => {\n loggerEnabled = true;\n};\n\nconst enableVerboseLogging = () => {\n verboseEnabled = true;\n\n verbose(\"Verbose logging enabled\");\n};\n\nconst log = (message: string) => {\n if (loggerEnabled) {\n console.log(message);\n }\n};\n\nconst verbose = (message: string) => {\n if (loggerEnabled && verboseEnabled) {\n log(message);\n }\n};\n\nconst error = (message: string) => {\n if (loggerEnabled) {\n console.error(message);\n }\n};\n\nconst logger = {\n enableLogging,\n enableVerboseLogging,\n log,\n verbose,\n error\n};\n\nexport default logger;\n"],"names":["loggerEnabled","verboseEnabled","enableLogging","enableVerboseLogging","verbose","log","message","console","error","logger"],"mappings":";+BAuCA;;;eAAA;;;AAvCA,IAAIA,gBAAgB;AACpB,IAAIC,iBAAiB;AAErB,MAAMC,gBAAgB;IACpBF,gBAAgB;AAClB;AAEA,MAAMG,uBAAuB;IAC3BF,iBAAiB;IAEjBG,QAAQ;AACV;AAEA,MAAMC,MAAM,CAACC;IACX,IAAIN,eAAe;QACjBO,QAAQF,GAAG,CAACC;IACd;AACF;AAEA,MAAMF,UAAU,CAACE;IACf,IAAIN,iBAAiBC,gBAAgB;QACnCI,IAAIC;IACN;AACF;AAEA,MAAME,QAAQ,CAACF;IACb,IAAIN,eAAe;QACjBO,QAAQC,KAAK,CAACF;IAChB;AACF;AAEA,MAAMG,SAAS;IACbP;IACAC;IACAE;IACAD;IACAI;AACF;MAEA,WAAeC"}
|
package/src/lib/result.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { SpdxExpression } from "./spdx/types/spdx-expression";
|
|
2
|
-
export interface CheckLicensesResult {
|
|
3
|
-
allowedPackages: Set<AllowedPackage>;
|
|
4
|
-
allowedLicenses: Set<LicensedPackage>;
|
|
5
|
-
noLicenses: Set<NoLicenseResult>;
|
|
6
|
-
forbiddenLicenses: Set<ForbiddenLicenseResult>;
|
|
7
|
-
}
|
|
8
|
-
export interface AllowedPackage {
|
|
9
|
-
name: string;
|
|
10
|
-
version: string;
|
|
11
|
-
}
|
|
12
|
-
export interface LicensedPackage {
|
|
13
|
-
name: string;
|
|
14
|
-
version: string;
|
|
15
|
-
spdxExpression: string;
|
|
16
|
-
licenses: SpdxExpression;
|
|
17
|
-
}
|
|
18
|
-
export interface NoLicenseResult {
|
|
19
|
-
name: string;
|
|
20
|
-
version: string;
|
|
21
|
-
}
|
|
22
|
-
export interface ForbiddenLicenseResult {
|
|
23
|
-
name: string;
|
|
24
|
-
version: string;
|
|
25
|
-
spdxExpression: string;
|
|
26
|
-
licenseIdentifiers: string;
|
|
27
|
-
}
|
package/src/lib/result.js
DELETED
package/src/lib/result.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../packages/license-cop/src/lib/result.ts"],"names":[],"mappings":""}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "calculateIssues", {
|
|
3
|
-
enumerable: true,
|
|
4
|
-
get: function() {
|
|
5
|
-
return calculateIssues;
|
|
6
|
-
}
|
|
7
|
-
});
|
|
8
|
-
const calculateIssues = (license, allowedLicenses)=>{
|
|
9
|
-
const issues = [];
|
|
10
|
-
const parseNode = (node)=>{
|
|
11
|
-
switch(node.type){
|
|
12
|
-
case "identifier":
|
|
13
|
-
{
|
|
14
|
-
if (!allowedLicenses.includes(node.value)) {
|
|
15
|
-
issues.push(node.value);
|
|
16
|
-
}
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
case "AND":
|
|
20
|
-
case "OR":
|
|
21
|
-
{
|
|
22
|
-
parseNode(node.expressions[0]);
|
|
23
|
-
parseNode(node.expressions[1]);
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
case "WITH":
|
|
27
|
-
{
|
|
28
|
-
if (// TODO: Verify that all exceptions make licenses 'weaker'
|
|
29
|
-
!allowedLicenses.includes(node.expressions[0]) || !allowedLicenses.includes(`${node.expressions[0]} WITH ${node.expressions[1]}`)) {
|
|
30
|
-
issues.push(`${node.expressions[0]} WITH ${node.expressions[1]}`);
|
|
31
|
-
}
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
default:
|
|
35
|
-
{
|
|
36
|
-
const _exhaustiveCheck = node;
|
|
37
|
-
throw new Error(`Unhandled license expression type: ${_exhaustiveCheck}`);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
parseNode(license);
|
|
42
|
-
return issues;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
//# sourceMappingURL=calculate-issues.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../packages/license-cop/src/lib/spdx/calculate-issues.ts"],"sourcesContent":["import { SpdxExpression } from \"./types/spdx-expression\";\n\nexport const calculateIssues = (license: SpdxExpression, allowedLicenses: string[]): string[] => {\n const issues: string[] = [];\n\n const parseNode = (node: SpdxExpression): void => {\n switch (node.type) {\n case \"identifier\": {\n if (!allowedLicenses.includes(node.value)) {\n issues.push(node.value);\n }\n return;\n }\n\n case \"AND\":\n case \"OR\": {\n parseNode(node.expressions[0]);\n parseNode(node.expressions[1]);\n return;\n }\n\n case \"WITH\": {\n if (\n // TODO: Verify that all exceptions make licenses 'weaker'\n !allowedLicenses.includes(node.expressions[0]) ||\n !allowedLicenses.includes(`${node.expressions[0]} WITH ${node.expressions[1]}`)\n ) {\n issues.push(`${node.expressions[0]} WITH ${node.expressions[1]}`);\n }\n return;\n }\n\n default: {\n const _exhaustiveCheck: never = node;\n throw new Error(`Unhandled license expression type: ${_exhaustiveCheck}`);\n }\n }\n };\n\n parseNode(license);\n\n return issues;\n};\n"],"names":["calculateIssues","license","allowedLicenses","issues","parseNode","node","type","includes","value","push","expressions","_exhaustiveCheck","Error"],"mappings":";+BAEaA;;;eAAAA;;;AAAN,MAAMA,kBAAkB,CAACC,SAAyBC;IACvD,MAAMC,SAAmB,EAAE;IAE3B,MAAMC,YAAY,CAACC;QACjB,OAAQA,KAAKC,IAAI;YACf,KAAK;gBAAc;oBACjB,IAAI,CAACJ,gBAAgBK,QAAQ,CAACF,KAAKG,KAAK,GAAG;wBACzCL,OAAOM,IAAI,CAACJ,KAAKG,KAAK;oBACxB;oBACA;gBACF;YAEA,KAAK;YACL,KAAK;gBAAM;oBACTJ,UAAUC,KAAKK,WAAW,CAAC,EAAE;oBAC7BN,UAAUC,KAAKK,WAAW,CAAC,EAAE;oBAC7B;gBACF;YAEA,KAAK;gBAAQ;oBACX,IACE,0DAA0D;oBAC1D,CAACR,gBAAgBK,QAAQ,CAACF,KAAKK,WAAW,CAAC,EAAE,KAC7C,CAACR,gBAAgBK,QAAQ,CAAC,GAAGF,KAAKK,WAAW,CAAC,EAAE,CAAC,MAAM,EAAEL,KAAKK,WAAW,CAAC,EAAE,EAAE,GAC9E;wBACAP,OAAOM,IAAI,CAAC,GAAGJ,KAAKK,WAAW,CAAC,EAAE,CAAC,MAAM,EAAEL,KAAKK,WAAW,CAAC,EAAE,EAAE;oBAClE;oBACA;gBACF;YAEA;gBAAS;oBACP,MAAMC,mBAA0BN;oBAChC,MAAM,IAAIO,MAAM,CAAC,mCAAmC,EAAED,kBAAkB;gBAC1E;QACF;IACF;IAEAP,UAAUH;IAEV,OAAOE;AACT"}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "getTokens", {
|
|
3
|
-
enumerable: true,
|
|
4
|
-
get: function() {
|
|
5
|
-
return getTokens;
|
|
6
|
-
}
|
|
7
|
-
});
|
|
8
|
-
const _token = require("./types/token");
|
|
9
|
-
const getTokens = (input)=>{
|
|
10
|
-
const tokens = [];
|
|
11
|
-
let currentToken = "";
|
|
12
|
-
// Pushes the current token to the tokens array and resets the current token
|
|
13
|
-
const pushToken = ()=>{
|
|
14
|
-
if (currentToken.length === 0) {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
if (currentToken === "WITH") {
|
|
18
|
-
tokens.push({
|
|
19
|
-
type: "with"
|
|
20
|
-
});
|
|
21
|
-
} else if ((0, _token.isOperator)(currentToken)) {
|
|
22
|
-
tokens.push({
|
|
23
|
-
type: "operator",
|
|
24
|
-
value: currentToken
|
|
25
|
-
});
|
|
26
|
-
} else {
|
|
27
|
-
tokens.push({
|
|
28
|
-
type: "identifier",
|
|
29
|
-
value: currentToken
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
currentToken = "";
|
|
33
|
-
};
|
|
34
|
-
for(let i = 0; i < input.length; i++){
|
|
35
|
-
const currentChar = input[i];
|
|
36
|
-
if ((0, _token.isParenthesis)(currentChar)) {
|
|
37
|
-
pushToken();
|
|
38
|
-
tokens.push({
|
|
39
|
-
type: "parenthesis",
|
|
40
|
-
value: currentChar
|
|
41
|
-
});
|
|
42
|
-
continue;
|
|
43
|
-
}
|
|
44
|
-
if (currentChar === " ") {
|
|
45
|
-
pushToken();
|
|
46
|
-
continue;
|
|
47
|
-
}
|
|
48
|
-
currentToken += currentChar;
|
|
49
|
-
}
|
|
50
|
-
pushToken();
|
|
51
|
-
return tokens;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
//# sourceMappingURL=get-tokens.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../packages/license-cop/src/lib/spdx/get-tokens.ts"],"sourcesContent":["import { isOperator, isParenthesis, Token } from \"./types/token\";\n\nexport const getTokens = (input: string): Token[] => {\n const tokens: Token[] = [];\n let currentToken = \"\";\n\n // Pushes the current token to the tokens array and resets the current token\n const pushToken = () => {\n if (currentToken.length === 0) {\n return;\n }\n\n if (currentToken === \"WITH\") {\n tokens.push({\n type: \"with\"\n });\n } else if (isOperator(currentToken)) {\n tokens.push({\n type: \"operator\",\n value: currentToken\n });\n } else {\n tokens.push({\n type: \"identifier\",\n value: currentToken\n });\n }\n\n currentToken = \"\";\n };\n\n for (let i = 0; i < input.length; i++) {\n const currentChar = input[i];\n\n if (isParenthesis(currentChar)) {\n pushToken();\n\n tokens.push({\n type: \"parenthesis\",\n value: currentChar\n });\n\n continue;\n }\n\n if (currentChar === \" \") {\n pushToken();\n continue;\n }\n\n currentToken += currentChar;\n }\n\n pushToken();\n return tokens;\n};\n"],"names":["getTokens","input","tokens","currentToken","pushToken","length","push","type","isOperator","value","i","currentChar","isParenthesis"],"mappings":";+BAEaA;;;eAAAA;;;uBAFoC;AAE1C,MAAMA,YAAY,CAACC;IACxB,MAAMC,SAAkB,EAAE;IAC1B,IAAIC,eAAe;IAEnB,4EAA4E;IAC5E,MAAMC,YAAY;QAChB,IAAID,aAAaE,MAAM,KAAK,GAAG;YAC7B;QACF;QAEA,IAAIF,iBAAiB,QAAQ;YAC3BD,OAAOI,IAAI,CAAC;gBACVC,MAAM;YACR;QACF,OAAO,IAAIC,IAAAA,iBAAU,EAACL,eAAe;YACnCD,OAAOI,IAAI,CAAC;gBACVC,MAAM;gBACNE,OAAON;YACT;QACF,OAAO;YACLD,OAAOI,IAAI,CAAC;gBACVC,MAAM;gBACNE,OAAON;YACT;QACF;QAEAA,eAAe;IACjB;IAEA,IAAK,IAAIO,IAAI,GAAGA,IAAIT,MAAMI,MAAM,EAAEK,IAAK;QACrC,MAAMC,cAAcV,KAAK,CAACS,EAAE;QAE5B,IAAIE,IAAAA,oBAAa,EAACD,cAAc;YAC9BP;YAEAF,OAAOI,IAAI,CAAC;gBACVC,MAAM;gBACNE,OAAOE;YACT;YAEA;QACF;QAEA,IAAIA,gBAAgB,KAAK;YACvBP;YACA;QACF;QAEAD,gBAAgBQ;IAClB;IAEAP;IACA,OAAOF;AACT"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "parseLicenseExpression", {
|
|
3
|
-
enumerable: true,
|
|
4
|
-
get: function() {
|
|
5
|
-
return parseLicenseExpression;
|
|
6
|
-
}
|
|
7
|
-
});
|
|
8
|
-
const _gettokens = require("./get-tokens");
|
|
9
|
-
const _parsetokens = require("./parse-tokens");
|
|
10
|
-
const parseLicenseExpression = (input)=>{
|
|
11
|
-
if (input === "UNLICENSED") {
|
|
12
|
-
return {
|
|
13
|
-
type: "unlicensed"
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
const tokens = (0, _gettokens.getTokens)(input);
|
|
17
|
-
return (0, _parsetokens.parseTokens)(tokens, input);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
//# sourceMappingURL=parse-license-expression.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../packages/license-cop/src/lib/spdx/parse-license-expression.ts"],"sourcesContent":["import { getTokens } from \"./get-tokens\";\nimport { parseTokens } from \"./parse-tokens\";\nimport { SpdxExpression, Unlicensed } from \"./types/spdx-expression\";\n\nexport const parseLicenseExpression = (input: string): SpdxExpression | Unlicensed => {\n if (input === \"UNLICENSED\") {\n return {\n type: \"unlicensed\"\n };\n }\n\n const tokens = getTokens(input);\n return parseTokens(tokens, input);\n};\n"],"names":["parseLicenseExpression","input","type","tokens","getTokens","parseTokens"],"mappings":";+BAIaA;;;eAAAA;;;2BAJa;6BACE;AAGrB,MAAMA,yBAAyB,CAACC;IACrC,IAAIA,UAAU,cAAc;QAC1B,OAAO;YACLC,MAAM;QACR;IACF;IAEA,MAAMC,SAASC,IAAAA,oBAAS,EAACH;IACzB,OAAOI,IAAAA,wBAAW,EAACF,QAAQF;AAC7B"}
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "parseTokens", {
|
|
3
|
-
enumerable: true,
|
|
4
|
-
get: function() {
|
|
5
|
-
return parseTokens;
|
|
6
|
-
}
|
|
7
|
-
});
|
|
8
|
-
const parseTokens = (tokens, originalInput)=>{
|
|
9
|
-
let index = 0;
|
|
10
|
-
const throwNotValid = ()=>{
|
|
11
|
-
console.trace();
|
|
12
|
-
throw new Error(`'${originalInput}' is not a valid SPDX expression`);
|
|
13
|
-
};
|
|
14
|
-
const hasMore = ()=>index < tokens.length;
|
|
15
|
-
const getCurrentToken = ()=>hasMore() ? tokens[index] : null;
|
|
16
|
-
const moveToNextToken = ()=>{
|
|
17
|
-
// istanbul ignore next
|
|
18
|
-
if (!hasMore()) {
|
|
19
|
-
throwNotValid();
|
|
20
|
-
}
|
|
21
|
-
index++;
|
|
22
|
-
};
|
|
23
|
-
const tryParseParenthesis = (operator)=>{
|
|
24
|
-
const currentToken = getCurrentToken();
|
|
25
|
-
if (currentToken && currentToken.type === "parenthesis" && operator === currentToken.value) {
|
|
26
|
-
moveToNextToken();
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
|
-
return false;
|
|
30
|
-
};
|
|
31
|
-
const tryParseWithToken = ()=>{
|
|
32
|
-
const currentToken = getCurrentToken();
|
|
33
|
-
if (currentToken && currentToken.type === "with") {
|
|
34
|
-
moveToNextToken();
|
|
35
|
-
return true;
|
|
36
|
-
}
|
|
37
|
-
return false;
|
|
38
|
-
};
|
|
39
|
-
const tryParseOperator = (operator)=>{
|
|
40
|
-
const currentToken = getCurrentToken();
|
|
41
|
-
if (currentToken && currentToken.type === "operator" && operator === currentToken.value) {
|
|
42
|
-
moveToNextToken();
|
|
43
|
-
return currentToken.value;
|
|
44
|
-
}
|
|
45
|
-
return undefined;
|
|
46
|
-
};
|
|
47
|
-
const tryParseLicense = ()=>{
|
|
48
|
-
const currentToken = getCurrentToken();
|
|
49
|
-
if (currentToken && currentToken.type === "identifier") {
|
|
50
|
-
moveToNextToken();
|
|
51
|
-
return {
|
|
52
|
-
type: "identifier",
|
|
53
|
-
value: currentToken.value
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
return undefined;
|
|
57
|
-
};
|
|
58
|
-
const tryParseParenthesizedExpression = ()=>{
|
|
59
|
-
const startsWithParenthesis = tryParseParenthesis("(");
|
|
60
|
-
if (!startsWithParenthesis) {
|
|
61
|
-
return undefined;
|
|
62
|
-
}
|
|
63
|
-
const innerExpression = tryParseExpression();
|
|
64
|
-
const endsWithParenthesis = tryParseParenthesis(")");
|
|
65
|
-
if (!endsWithParenthesis) {
|
|
66
|
-
throwNotValid();
|
|
67
|
-
}
|
|
68
|
-
return innerExpression;
|
|
69
|
-
};
|
|
70
|
-
const binaryOperationFactory = (operator, tryNextParser)=>{
|
|
71
|
-
const tryParseBinaryOperation = ()=>{
|
|
72
|
-
const left = tryNextParser();
|
|
73
|
-
if (!left) {
|
|
74
|
-
return undefined;
|
|
75
|
-
}
|
|
76
|
-
if (!tryParseOperator(operator)) {
|
|
77
|
-
return left;
|
|
78
|
-
}
|
|
79
|
-
const right = tryParseBinaryOperation();
|
|
80
|
-
if (!right) {
|
|
81
|
-
return throwNotValid();
|
|
82
|
-
}
|
|
83
|
-
return {
|
|
84
|
-
type: operator,
|
|
85
|
-
expressions: [
|
|
86
|
-
left,
|
|
87
|
-
right
|
|
88
|
-
]
|
|
89
|
-
};
|
|
90
|
-
};
|
|
91
|
-
return tryParseBinaryOperation;
|
|
92
|
-
};
|
|
93
|
-
const tryParseWith = ()=>{
|
|
94
|
-
const left = tryParseLicense();
|
|
95
|
-
if (!left) {
|
|
96
|
-
return undefined;
|
|
97
|
-
}
|
|
98
|
-
if (!tryParseWithToken()) {
|
|
99
|
-
return left;
|
|
100
|
-
}
|
|
101
|
-
const right = tryParseLicense();
|
|
102
|
-
if (!right) {
|
|
103
|
-
return throwNotValid();
|
|
104
|
-
}
|
|
105
|
-
return {
|
|
106
|
-
type: "WITH",
|
|
107
|
-
expressions: [
|
|
108
|
-
left.value,
|
|
109
|
-
right.value
|
|
110
|
-
]
|
|
111
|
-
};
|
|
112
|
-
};
|
|
113
|
-
const parseAnd = binaryOperationFactory("AND", ()=>tryParseParenthesizedExpression() || tryParseWith());
|
|
114
|
-
const tryParseExpression = binaryOperationFactory("OR", parseAnd);
|
|
115
|
-
const node = tryParseExpression();
|
|
116
|
-
if (!node || hasMore()) {
|
|
117
|
-
return throwNotValid();
|
|
118
|
-
}
|
|
119
|
-
return node;
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
//# sourceMappingURL=parse-tokens.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../packages/license-cop/src/lib/spdx/parse-tokens.ts"],"sourcesContent":["import { Identifier, SpdxExpression } from \"./types/spdx-expression\";\nimport { Operator, Parenthesis, Token } from \"./types/token\";\n\nexport const parseTokens = (tokens: Token[], originalInput: string): SpdxExpression => {\n let index = 0;\n\n const throwNotValid = () => {\n console.trace();\n throw new Error(`'${originalInput}' is not a valid SPDX expression`);\n };\n\n const hasMore = (): boolean => index < tokens.length;\n\n const getCurrentToken = (): Token | null => (hasMore() ? tokens[index] : null);\n\n const moveToNextToken = () => {\n // istanbul ignore next\n if (!hasMore()) {\n throwNotValid();\n }\n\n index++;\n };\n\n const tryParseParenthesis = (operator: Parenthesis): boolean => {\n const currentToken = getCurrentToken();\n\n if (currentToken && currentToken.type === \"parenthesis\" && operator === currentToken.value) {\n moveToNextToken();\n return true;\n }\n\n return false;\n };\n\n const tryParseWithToken = (): boolean => {\n const currentToken = getCurrentToken();\n\n if (currentToken && currentToken.type === \"with\") {\n moveToNextToken();\n return true;\n }\n\n return false;\n };\n\n const tryParseOperator = (operator: Operator): Operator | undefined => {\n const currentToken = getCurrentToken();\n\n if (currentToken && currentToken.type === \"operator\" && operator === currentToken.value) {\n moveToNextToken();\n return currentToken.value;\n }\n\n return undefined;\n };\n\n const tryParseLicense = (): Identifier | undefined => {\n const currentToken = getCurrentToken();\n if (currentToken && currentToken.type === \"identifier\") {\n moveToNextToken();\n\n return {\n type: \"identifier\",\n value: currentToken.value\n };\n }\n\n return undefined;\n };\n\n const tryParseParenthesizedExpression = () => {\n const startsWithParenthesis = tryParseParenthesis(\"(\");\n if (!startsWithParenthesis) {\n return undefined;\n }\n\n const innerExpression = tryParseExpression();\n\n const endsWithParenthesis = tryParseParenthesis(\")\");\n if (!endsWithParenthesis) {\n throwNotValid();\n }\n\n return innerExpression;\n };\n\n const binaryOperationFactory = (\n operator: Exclude<Operator, \"WITH\">,\n tryNextParser: () => SpdxExpression | undefined\n ) => {\n const tryParseBinaryOperation = (): SpdxExpression | undefined => {\n const left = tryNextParser();\n\n if (!left) {\n return undefined;\n }\n\n if (!tryParseOperator(operator)) {\n return left;\n }\n\n const right = tryParseBinaryOperation();\n if (!right) {\n return throwNotValid();\n }\n\n return {\n type: operator,\n expressions: [left, right]\n };\n };\n\n return tryParseBinaryOperation;\n };\n\n const tryParseWith = (): SpdxExpression | undefined => {\n const left = tryParseLicense();\n\n if (!left) {\n return undefined;\n }\n\n if (!tryParseWithToken()) {\n return left;\n }\n\n const right = tryParseLicense();\n if (!right) {\n return throwNotValid();\n }\n\n return {\n type: \"WITH\",\n expressions: [left.value, right.value]\n };\n };\n\n const parseAnd = binaryOperationFactory(\n \"AND\",\n () => tryParseParenthesizedExpression() || tryParseWith()\n );\n const tryParseExpression = binaryOperationFactory(\"OR\", parseAnd);\n\n const node = tryParseExpression();\n if (!node || hasMore()) {\n return throwNotValid();\n }\n\n return node;\n};\n"],"names":["parseTokens","tokens","originalInput","index","throwNotValid","console","trace","Error","hasMore","length","getCurrentToken","moveToNextToken","tryParseParenthesis","operator","currentToken","type","value","tryParseWithToken","tryParseOperator","undefined","tryParseLicense","tryParseParenthesizedExpression","startsWithParenthesis","innerExpression","tryParseExpression","endsWithParenthesis","binaryOperationFactory","tryNextParser","tryParseBinaryOperation","left","right","expressions","tryParseWith","parseAnd","node"],"mappings":";+BAGaA;;;eAAAA;;;AAAN,MAAMA,cAAc,CAACC,QAAiBC;IAC3C,IAAIC,QAAQ;IAEZ,MAAMC,gBAAgB;QACpBC,QAAQC,KAAK;QACb,MAAM,IAAIC,MAAM,CAAC,CAAC,EAAEL,cAAc,gCAAgC,CAAC;IACrE;IAEA,MAAMM,UAAU,IAAeL,QAAQF,OAAOQ,MAAM;IAEpD,MAAMC,kBAAkB,IAAqBF,YAAYP,MAAM,CAACE,MAAM,GAAG;IAEzE,MAAMQ,kBAAkB;QACtB,uBAAuB;QACvB,IAAI,CAACH,WAAW;YACdJ;QACF;QAEAD;IACF;IAEA,MAAMS,sBAAsB,CAACC;QAC3B,MAAMC,eAAeJ;QAErB,IAAII,gBAAgBA,aAAaC,IAAI,KAAK,iBAAiBF,aAAaC,aAAaE,KAAK,EAAE;YAC1FL;YACA,OAAO;QACT;QAEA,OAAO;IACT;IAEA,MAAMM,oBAAoB;QACxB,MAAMH,eAAeJ;QAErB,IAAII,gBAAgBA,aAAaC,IAAI,KAAK,QAAQ;YAChDJ;YACA,OAAO;QACT;QAEA,OAAO;IACT;IAEA,MAAMO,mBAAmB,CAACL;QACxB,MAAMC,eAAeJ;QAErB,IAAII,gBAAgBA,aAAaC,IAAI,KAAK,cAAcF,aAAaC,aAAaE,KAAK,EAAE;YACvFL;YACA,OAAOG,aAAaE,KAAK;QAC3B;QAEA,OAAOG;IACT;IAEA,MAAMC,kBAAkB;QACtB,MAAMN,eAAeJ;QACrB,IAAII,gBAAgBA,aAAaC,IAAI,KAAK,cAAc;YACtDJ;YAEA,OAAO;gBACLI,MAAM;gBACNC,OAAOF,aAAaE,KAAK;YAC3B;QACF;QAEA,OAAOG;IACT;IAEA,MAAME,kCAAkC;QACtC,MAAMC,wBAAwBV,oBAAoB;QAClD,IAAI,CAACU,uBAAuB;YAC1B,OAAOH;QACT;QAEA,MAAMI,kBAAkBC;QAExB,MAAMC,sBAAsBb,oBAAoB;QAChD,IAAI,CAACa,qBAAqB;YACxBrB;QACF;QAEA,OAAOmB;IACT;IAEA,MAAMG,yBAAyB,CAC7Bb,UACAc;QAEA,MAAMC,0BAA0B;YAC9B,MAAMC,OAAOF;YAEb,IAAI,CAACE,MAAM;gBACT,OAAOV;YACT;YAEA,IAAI,CAACD,iBAAiBL,WAAW;gBAC/B,OAAOgB;YACT;YAEA,MAAMC,QAAQF;YACd,IAAI,CAACE,OAAO;gBACV,OAAO1B;YACT;YAEA,OAAO;gBACLW,MAAMF;gBACNkB,aAAa;oBAACF;oBAAMC;iBAAM;YAC5B;QACF;QAEA,OAAOF;IACT;IAEA,MAAMI,eAAe;QACnB,MAAMH,OAAOT;QAEb,IAAI,CAACS,MAAM;YACT,OAAOV;QACT;QAEA,IAAI,CAACF,qBAAqB;YACxB,OAAOY;QACT;QAEA,MAAMC,QAAQV;QACd,IAAI,CAACU,OAAO;YACV,OAAO1B;QACT;QAEA,OAAO;YACLW,MAAM;YACNgB,aAAa;gBAACF,KAAKb,KAAK;gBAAEc,MAAMd,KAAK;aAAC;QACxC;IACF;IAEA,MAAMiB,WAAWP,uBACf,OACA,IAAML,qCAAqCW;IAE7C,MAAMR,qBAAqBE,uBAAuB,MAAMO;IAExD,MAAMC,OAAOV;IACb,IAAI,CAACU,QAAQ1B,WAAW;QACtB,OAAOJ;IACT;IAEA,OAAO8B;AACT"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export type Identifier = {
|
|
2
|
-
type: "identifier";
|
|
3
|
-
value: string;
|
|
4
|
-
};
|
|
5
|
-
export type AndExpression = {
|
|
6
|
-
type: "AND";
|
|
7
|
-
expressions: [SpdxExpression, SpdxExpression];
|
|
8
|
-
};
|
|
9
|
-
export type OrExpression = {
|
|
10
|
-
type: "OR";
|
|
11
|
-
expressions: [SpdxExpression, SpdxExpression];
|
|
12
|
-
};
|
|
13
|
-
export type WithExpression = {
|
|
14
|
-
type: "WITH";
|
|
15
|
-
expressions: [string, string];
|
|
16
|
-
};
|
|
17
|
-
export type SpdxExpression = Identifier | AndExpression | OrExpression | WithExpression;
|
|
18
|
-
export type Unlicensed = {
|
|
19
|
-
type: "unlicensed";
|
|
20
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../packages/license-cop/src/lib/spdx/types/spdx-expression.ts"],"names":[],"mappings":""}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
declare const operators: readonly ["AND", "OR"];
|
|
2
|
-
export declare const isOperator: (value: string) => value is Operator;
|
|
3
|
-
export type Operator = (typeof operators)[number];
|
|
4
|
-
export type OperatorToken = {
|
|
5
|
-
type: "operator";
|
|
6
|
-
value: Operator;
|
|
7
|
-
};
|
|
8
|
-
export type WithToken = {
|
|
9
|
-
type: "with";
|
|
10
|
-
};
|
|
11
|
-
export type IdentifierToken = {
|
|
12
|
-
type: "identifier";
|
|
13
|
-
value: string;
|
|
14
|
-
};
|
|
15
|
-
declare const parenthesis: readonly ["(", ")"];
|
|
16
|
-
export declare const isParenthesis: (value: string) => value is Parenthesis;
|
|
17
|
-
export type Parenthesis = (typeof parenthesis)[number];
|
|
18
|
-
export type ParenthesisToken = {
|
|
19
|
-
type: "parenthesis";
|
|
20
|
-
value: Parenthesis;
|
|
21
|
-
};
|
|
22
|
-
export type Token = OperatorToken | WithToken | IdentifierToken | ParenthesisToken;
|
|
23
|
-
export {};
|