license-cop 1.2.0 → 1.3.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/README.md CHANGED
@@ -6,6 +6,10 @@ Yet another license checker tool for your dependencies; focused on simplicity.
6
6
  <img alt="npm" src="https://img.shields.io/npm/v/license-cop?logo=npm">
7
7
  </a>
8
8
 
9
+ <a href="https://app.codecov.io/gh/tobysmith568/license-cop">
10
+ <img alt="Codecov" src="https://img.shields.io/codecov/c/github/tobysmith568/license-cop?logo=codecov&label=Coverage">
11
+ </a>
12
+
9
13
  <a href="https://license-cop.js.org">
10
14
  <img alt="Protected by: License-Cop" src="https://license-cop.js.org/shield.svg">
11
15
  </a>
@@ -21,7 +25,7 @@ npm install license-cop --save-dev
21
25
  Make a config file
22
26
 
23
27
  ```bash
24
- npx license-cop --init
28
+ npx license-cop init
25
29
  ```
26
30
 
27
31
  Run license-cop
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "license-cop",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "type": "commonjs",
5
5
  "bin": {
6
6
  "license-cop": "./src/bin/license-cop"
@@ -31,23 +31,18 @@
31
31
  "oss"
32
32
  ],
33
33
  "dependencies": {
34
- "@commander-js/extra-typings": "11.0.0",
35
- "@npmcli/arborist": "6.2.5",
36
- "axios": "1.3.4",
37
- "compare-versions": "6.0.0-rc.1",
38
- "cosmiconfig": "8.1.3",
39
- "deepmerge": "4.3.1",
40
- "git-filesystem": "0.0.2",
41
- "json5": "2.2.3",
42
- "zod": "3.21.4"
34
+ "@commander-js/extra-typings": "^11.0.0",
35
+ "@npmcli/arborist": "^7.0.0",
36
+ "axios": "^1.3.4",
37
+ "compare-versions": "^6.0.0-rc.1",
38
+ "cosmiconfig": "^8.1.3",
39
+ "deepmerge": "^4.3.1",
40
+ "git-filesystem": "^0.0.2",
41
+ "json5": "^2.2.3",
42
+ "zod": "^3.21.4"
43
43
  },
44
44
  "peerDependencies": {
45
45
  "@swc/helpers": "0.5.1"
46
46
  },
47
- "main": "./src/index.js",
48
- "exports": {
49
- ".": {
50
- "require": "./src/index.js"
51
- }
52
- }
47
+ "main": "./src/index.js"
53
48
  }
@@ -2,3 +2,4 @@ export declare const initCommand: import("@commander-js/extra-typings").Command<
2
2
  verbose?: true | undefined;
3
3
  directory: string;
4
4
  }>;
5
+ export declare const initCommandAction: (rootDir: string) => Promise<void>;
@@ -1,7 +1,13 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "initCommand", {
3
- enumerable: true,
4
- get: ()=>initCommand
2
+ function _export(target, all) {
3
+ for(var name in all)Object.defineProperty(target, name, {
4
+ enumerable: true,
5
+ get: all[name]
6
+ });
7
+ }
8
+ _export(exports, {
9
+ initCommand: ()=>initCommand,
10
+ initCommandAction: ()=>initCommandAction
5
11
  });
6
12
  const _promises = require("fs/promises");
7
13
  const _path = require("path");
@@ -13,11 +19,11 @@ const defaultConfig = `{
13
19
  "packages": []
14
20
  }
15
21
  `;
16
- const initCommand = (0, _createCommand.createCommandWithGlobalOptions)().name("--init").description("Create a new license-cop configuration file").action(async (options)=>{
22
+ const initCommand = (0, _createCommand.createCommandWithGlobalOptions)().name("init").description("Create a new license-cop configuration file").action(async (options)=>{
17
23
  const { directory } = options;
18
- await init(directory);
24
+ await initCommandAction(directory);
19
25
  });
20
- const init = async (rootDir)=>{
26
+ const initCommandAction = async (rootDir)=>{
21
27
  _logger.default.log("Setting up a new license-cop config file...");
22
28
  const configPath = (0, _path.join)(rootDir, ".licenses.json");
23
29
  _logger.default.verbose(`Writing config file to: ${configPath}`);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../packages/license-cop/src/lib/cli/commands/init.ts"],"sourcesContent":["import { writeFile } from \"fs/promises\";\nimport { join } from \"path\";\nimport logger from \"../../logger\";\nimport { createCommandWithGlobalOptions } from \"../create-command\";\n\nconst defaultConfig = `{\n \"$schema\": \"https://license-cop.js.org/schema.json\",\n \"licenses\": [\"MIT\", \"ISC\", \"Apache-2.0\"],\n \"packages\": []\n}\n`;\n\nexport const initCommand = createCommandWithGlobalOptions()\n .name(\"--init\")\n .description(\"Create a new license-cop configuration file\")\n .action(async options => {\n const { directory } = options;\n\n await init(directory);\n });\n\nconst init = async (rootDir: string) => {\n logger.log(\"Setting up a new license-cop config file...\");\n\n const configPath = join(rootDir, \".licenses.json\");\n logger.verbose(`Writing config file to: ${configPath}`);\n await writeFile(configPath, defaultConfig);\n\n logger.log(\"Done!\");\n logger.log(\"Run `npx license-cop` to check your dependencies\");\n};\n"],"names":["initCommand","defaultConfig","createCommandWithGlobalOptions","name","description","action","options","directory","init","rootDir","logger","log","configPath","join","verbose","writeFile"],"mappings":";+BAYaA;;aAAAA;;0BAZa;sBACL;wBACF;+BAC4B;AAE/C,MAAMC,gBAAgB,CAAC;;;;;AAKvB,CAAC;AAEM,MAAMD,cAAcE,IAAAA,6CAA8B,IACtDC,IAAI,CAAC,UACLC,WAAW,CAAC,+CACZC,MAAM,CAAC,OAAMC,UAAW;IACvB,MAAM,EAAEC,UAAS,EAAE,GAAGD;IAEtB,MAAME,KAAKD;AACb;AAEF,MAAMC,OAAO,OAAOC,UAAoB;IACtCC,eAAM,CAACC,GAAG,CAAC;IAEX,MAAMC,aAAaC,IAAAA,UAAI,EAACJ,SAAS;IACjCC,eAAM,CAACI,OAAO,CAAC,CAAC,wBAAwB,EAAEF,WAAW,CAAC;IACtD,MAAMG,IAAAA,mBAAS,EAACH,YAAYX;IAE5BS,eAAM,CAACC,GAAG,CAAC;IACXD,eAAM,CAACC,GAAG,CAAC;AACb"}
1
+ {"version":3,"sources":["../../../../../../../packages/license-cop/src/lib/cli/commands/init.ts"],"sourcesContent":["import { writeFile } from \"fs/promises\";\nimport { join } from \"path\";\nimport logger from \"../../logger\";\nimport { createCommandWithGlobalOptions } from \"../create-command\";\n\nconst defaultConfig = `{\n \"$schema\": \"https://license-cop.js.org/schema.json\",\n \"licenses\": [\"MIT\", \"ISC\", \"Apache-2.0\"],\n \"packages\": []\n}\n`;\n\nexport const initCommand = createCommandWithGlobalOptions()\n .name(\"init\")\n .description(\"Create a new license-cop configuration file\")\n .action(async options => {\n const { directory } = options;\n\n await initCommandAction(directory);\n });\n\nexport const initCommandAction = async (rootDir: string) => {\n logger.log(\"Setting up a new license-cop config file...\");\n\n const configPath = join(rootDir, \".licenses.json\");\n logger.verbose(`Writing config file to: ${configPath}`);\n await writeFile(configPath, defaultConfig);\n\n logger.log(\"Done!\");\n logger.log(\"Run `npx license-cop` to check your dependencies\");\n};\n"],"names":["initCommand","initCommandAction","defaultConfig","createCommandWithGlobalOptions","name","description","action","options","directory","rootDir","logger","log","configPath","join","verbose","writeFile"],"mappings":";;;;;;;;IAYaA,WAAW,MAAXA;IASAC,iBAAiB,MAAjBA;;0BArBa;sBACL;wBACF;+BAC4B;AAE/C,MAAMC,gBAAgB,CAAC;;;;;AAKvB,CAAC;AAEM,MAAMF,cAAcG,IAAAA,6CAA8B,IACtDC,IAAI,CAAC,QACLC,WAAW,CAAC,+CACZC,MAAM,CAAC,OAAMC,UAAW;IACvB,MAAM,EAAEC,UAAS,EAAE,GAAGD;IAEtB,MAAMN,kBAAkBO;AAC1B;AAEK,MAAMP,oBAAoB,OAAOQ,UAAoB;IAC1DC,eAAM,CAACC,GAAG,CAAC;IAEX,MAAMC,aAAaC,IAAAA,UAAI,EAACJ,SAAS;IACjCC,eAAM,CAACI,OAAO,CAAC,CAAC,wBAAwB,EAAEF,WAAW,CAAC;IACtD,MAAMG,IAAAA,mBAAS,EAACH,YAAYV;IAE5BQ,eAAM,CAACC,GAAG,CAAC;IACXD,eAAM,CAACC,GAAG,CAAC;AACb"}
@@ -3,4 +3,5 @@ export declare const mainCommand: import("@commander-js/extra-typings").Command<
3
3
  directory: string;
4
4
  includeDev: boolean;
5
5
  devOnly: boolean;
6
+ init: boolean;
6
7
  }>;
@@ -11,8 +11,13 @@ const _packageJson = require("../../package-json");
11
11
  const _createCommand = require("../create-command");
12
12
  const _reportFailure = require("../report-failure");
13
13
  const _reportSuccess = require("../report-success");
14
- const mainCommand = (0, _createCommand.createCommandWithGlobalOptions)().name("license-cop").description("Yet another license checker tool for your dependencies; focused on simplicity").option("-D,--include-dev", "Include dev dependencies", false).option("--dev-only", "Only check dev dependencies", false).action(async (options)=>{
14
+ const _init = require("./init");
15
+ const mainCommand = (0, _createCommand.createCommandWithGlobalOptions)().name("license-cop").description("Yet another license checker tool for your dependencies; focused on simplicity").option("-D,--include-dev", "Include dev dependencies", false).option("--dev-only", "Only check dev dependencies", false).option("--init", "An alias for 'license-cop init'", false).action(async (options)=>{
15
16
  const { directory , includeDev , devOnly } = options;
17
+ if (options.init) {
18
+ await (0, _init.initCommandAction)(directory);
19
+ return;
20
+ }
16
21
  await runLicenseCop(directory, includeDev, devOnly);
17
22
  });
18
23
  const runLicenseCop = async (directory, includeDevDependencies, devDependenciesOnly)=>{
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../packages/license-cop/src/lib/cli/commands/main.ts"],"sourcesContent":["import { join } from \"path\";\nimport { loadConfig } from \"../../config/load-config\";\nimport { checkLicenses, LicenseCopOptions } from \"../../license-cop\";\nimport logger from \"../../logger\";\nimport { readPackageJson } from \"../../package-json\";\nimport { createCommandWithGlobalOptions } from \"../create-command\";\nimport { reportFailure } from \"../report-failure\";\nimport { reportSuccess } from \"../report-success\";\n\nexport const mainCommand = createCommandWithGlobalOptions()\n .name(\"license-cop\")\n .description(\"Yet another license checker tool for your dependencies; focused on simplicity\")\n .option(\"-D,--include-dev\", \"Include dev dependencies\", false)\n .option(\"--dev-only\", \"Only check dev dependencies\", false)\n .action(async options => {\n const { directory, includeDev, devOnly } = options;\n\n await runLicenseCop(directory, includeDev, devOnly);\n });\n\nconst runLicenseCop = async (\n directory: string,\n includeDevDependencies: boolean,\n devDependenciesOnly: boolean\n) => {\n logger.verbose(`Using directory: ${directory}`);\n\n const productName = await getProductName(directory);\n logger.log(`Scanning dependencies of: ${productName}`);\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: includeDevDependencies ?? config.includeDevDependencies,\n devDependenciesOnly: devDependenciesOnly ?? config.devDependenciesOnly\n };\n\n const result = await checkLicenses(options);\n\n if (result.noLicenses.size > 0 || result.forbiddenLicenses.size > 0) {\n reportFailure(result);\n process.exitCode = 1;\n } else {\n reportSuccess(result);\n }\n};\n\nconst getProductName = async (directory: string): Promise<string> => {\n const packageJsonPath = join(directory, \"package.json\");\n const packageJson = await readPackageJson(packageJsonPath);\n return packageJson.name;\n};\n"],"names":["mainCommand","createCommandWithGlobalOptions","name","description","option","action","options","directory","includeDev","devOnly","runLicenseCop","includeDevDependencies","devDependenciesOnly","logger","verbose","productName","getProductName","log","config","loadConfig","allowedLicenses","licenses","allowedPackages","packages","workingDirectory","result","checkLicenses","noLicenses","size","forbiddenLicenses","reportFailure","process","exitCode","reportSuccess","packageJsonPath","join","packageJson","readPackageJson"],"mappings":";+BASaA;;aAAAA;;sBATQ;4BACM;4BACsB;wBAC9B;6BACa;+BACe;+BACjB;+BACA;AAEvB,MAAMA,cAAcC,IAAAA,6CAA8B,IACtDC,IAAI,CAAC,eACLC,WAAW,CAAC,iFACZC,MAAM,CAAC,oBAAoB,4BAA4B,KAAK,EAC5DA,MAAM,CAAC,cAAc,+BAA+B,KAAK,EACzDC,MAAM,CAAC,OAAMC,UAAW;IACvB,MAAM,EAAEC,UAAS,EAAEC,WAAU,EAAEC,QAAO,EAAE,GAAGH;IAE3C,MAAMI,cAAcH,WAAWC,YAAYC;AAC7C;AAEF,MAAMC,gBAAgB,OACpBH,WACAI,wBACAC,sBACG;IACHC,eAAM,CAACC,OAAO,CAAC,CAAC,iBAAiB,EAAEP,UAAU,CAAC;IAE9C,MAAMQ,cAAc,MAAMC,eAAeT;IACzCM,eAAM,CAACI,GAAG,CAAC,CAAC,0BAA0B,EAAEF,YAAY,CAAC;IAErD,MAAMG,SAAS,MAAMC,IAAAA,sBAAU,EAACZ;IAEhC,MAAMD,UAA6B;QACjCc,iBAAiBF,OAAOG,QAAQ;QAChCC,iBAAiBJ,OAAOK,QAAQ;QAEhCC,kBAAkBjB;QAClBI,wBAAwBA,iCAAAA,yBAA0BO,OAAOP,sBAAsB;QAC/EC,qBAAqBA,8BAAAA,sBAAuBM,OAAON,mBAAmB;IACxE;IAEA,MAAMa,SAAS,MAAMC,IAAAA,yBAAa,EAACpB;IAEnC,IAAImB,OAAOE,UAAU,CAACC,IAAI,GAAG,KAAKH,OAAOI,iBAAiB,CAACD,IAAI,GAAG,GAAG;QACnEE,IAAAA,4BAAa,EAACL;QACdM,QAAQC,QAAQ,GAAG;IACrB,OAAO;QACLC,IAAAA,4BAAa,EAACR;IAChB,CAAC;AACH;AAEA,MAAMT,iBAAiB,OAAOT,YAAuC;IACnE,MAAM2B,kBAAkBC,IAAAA,UAAI,EAAC5B,WAAW;IACxC,MAAM6B,cAAc,MAAMC,IAAAA,4BAAe,EAACH;IAC1C,OAAOE,YAAYlC,IAAI;AACzB"}
1
+ {"version":3,"sources":["../../../../../../../packages/license-cop/src/lib/cli/commands/main.ts"],"sourcesContent":["import { join } from \"path\";\nimport { loadConfig } from \"../../config/load-config\";\nimport { checkLicenses, LicenseCopOptions } from \"../../license-cop\";\nimport logger from \"../../logger\";\nimport { readPackageJson } from \"../../package-json\";\nimport { createCommandWithGlobalOptions } from \"../create-command\";\nimport { reportFailure } from \"../report-failure\";\nimport { reportSuccess } from \"../report-success\";\nimport { initCommandAction } from \"./init\";\n\nexport const mainCommand = createCommandWithGlobalOptions()\n .name(\"license-cop\")\n .description(\"Yet another license checker tool for your dependencies; focused on simplicity\")\n .option(\"-D,--include-dev\", \"Include dev dependencies\", false)\n .option(\"--dev-only\", \"Only check dev dependencies\", false)\n .option(\"--init\", \"An alias for 'license-cop init'\", false)\n .action(async options => {\n const { directory, includeDev, devOnly } = options;\n\n if (options.init) {\n await initCommandAction(directory);\n return;\n }\n\n await runLicenseCop(directory, includeDev, devOnly);\n });\n\nconst runLicenseCop = async (\n directory: string,\n includeDevDependencies: boolean,\n devDependenciesOnly: boolean\n) => {\n logger.verbose(`Using directory: ${directory}`);\n\n const productName = await getProductName(directory);\n logger.log(`Scanning dependencies of: ${productName}`);\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: includeDevDependencies ?? config.includeDevDependencies,\n devDependenciesOnly: devDependenciesOnly ?? config.devDependenciesOnly\n };\n\n const result = await checkLicenses(options);\n\n if (result.noLicenses.size > 0 || result.forbiddenLicenses.size > 0) {\n reportFailure(result);\n process.exitCode = 1;\n } else {\n reportSuccess(result);\n }\n};\n\nconst getProductName = async (directory: string): Promise<string> => {\n const packageJsonPath = join(directory, \"package.json\");\n const packageJson = await readPackageJson(packageJsonPath);\n return packageJson.name;\n};\n"],"names":["mainCommand","createCommandWithGlobalOptions","name","description","option","action","options","directory","includeDev","devOnly","init","initCommandAction","runLicenseCop","includeDevDependencies","devDependenciesOnly","logger","verbose","productName","getProductName","log","config","loadConfig","allowedLicenses","licenses","allowedPackages","packages","workingDirectory","result","checkLicenses","noLicenses","size","forbiddenLicenses","reportFailure","process","exitCode","reportSuccess","packageJsonPath","join","packageJson","readPackageJson"],"mappings":";+BAUaA;;aAAAA;;sBAVQ;4BACM;4BACsB;wBAC9B;6BACa;+BACe;+BACjB;+BACA;sBACI;AAE3B,MAAMA,cAAcC,IAAAA,6CAA8B,IACtDC,IAAI,CAAC,eACLC,WAAW,CAAC,iFACZC,MAAM,CAAC,oBAAoB,4BAA4B,KAAK,EAC5DA,MAAM,CAAC,cAAc,+BAA+B,KAAK,EACzDA,MAAM,CAAC,UAAU,mCAAmC,KAAK,EACzDC,MAAM,CAAC,OAAMC,UAAW;IACvB,MAAM,EAAEC,UAAS,EAAEC,WAAU,EAAEC,QAAO,EAAE,GAAGH;IAE3C,IAAIA,QAAQI,IAAI,EAAE;QAChB,MAAMC,IAAAA,uBAAiB,EAACJ;QACxB;IACF,CAAC;IAED,MAAMK,cAAcL,WAAWC,YAAYC;AAC7C;AAEF,MAAMG,gBAAgB,OACpBL,WACAM,wBACAC,sBACG;IACHC,eAAM,CAACC,OAAO,CAAC,CAAC,iBAAiB,EAAET,UAAU,CAAC;IAE9C,MAAMU,cAAc,MAAMC,eAAeX;IACzCQ,eAAM,CAACI,GAAG,CAAC,CAAC,0BAA0B,EAAEF,YAAY,CAAC;IAErD,MAAMG,SAAS,MAAMC,IAAAA,sBAAU,EAACd;IAEhC,MAAMD,UAA6B;QACjCgB,iBAAiBF,OAAOG,QAAQ;QAChCC,iBAAiBJ,OAAOK,QAAQ;QAEhCC,kBAAkBnB;QAClBM,wBAAwBA,iCAAAA,yBAA0BO,OAAOP,sBAAsB;QAC/EC,qBAAqBA,8BAAAA,sBAAuBM,OAAON,mBAAmB;IACxE;IAEA,MAAMa,SAAS,MAAMC,IAAAA,yBAAa,EAACtB;IAEnC,IAAIqB,OAAOE,UAAU,CAACC,IAAI,GAAG,KAAKH,OAAOI,iBAAiB,CAACD,IAAI,GAAG,GAAG;QACnEE,IAAAA,4BAAa,EAACL;QACdM,QAAQC,QAAQ,GAAG;IACrB,OAAO;QACLC,IAAAA,4BAAa,EAACR;IAChB,CAAC;AACH;AAEA,MAAMT,iBAAiB,OAAOX,YAAuC;IACnE,MAAM6B,kBAAkBC,IAAAA,UAAI,EAAC9B,WAAW;IACxC,MAAM+B,cAAc,MAAMC,IAAAA,4BAAe,EAACH;IAC1C,OAAOE,YAAYpC,IAAI;AACzB"}
@@ -6,11 +6,13 @@ Object.defineProperty(exports, "parseTokens", {
6
6
  const parseTokens = (tokens, originalInput)=>{
7
7
  let index = 0;
8
8
  const throwNotValid = ()=>{
9
+ console.trace();
9
10
  throw new Error(`'${originalInput}' is not a valid SPDX expression`);
10
11
  };
11
12
  const hasMore = ()=>index < tokens.length;
12
13
  const getCurrentToken = ()=>hasMore() ? tokens[index] : null;
13
14
  const moveToNextToken = ()=>{
15
+ // istanbul ignore next
14
16
  if (!hasMore()) {
15
17
  throwNotValid();
16
18
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../packages/license-cop/src/lib/spdx/parse-tokens.ts"],"sourcesContent":["import { Identifier, SpdxExpression } from \"./types/spdx-expression\";\nimport { Token, Parenthesis, Operator } from \"./types/token\";\n\nexport const parseTokens = (tokens: Token[], originalInput: string): SpdxExpression => {\n let index = 0;\n\n const throwNotValid = () => {\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 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","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;;aAAAA;;AAAN,MAAMA,cAAc,CAACC,QAAiBC,gBAA0C;IACrF,IAAIC,QAAQ;IAEZ,MAAMC,gBAAgB,IAAM;QAC1B,MAAM,IAAIC,MAAM,CAAC,CAAC,EAAEH,cAAc,gCAAgC,CAAC,EAAE;IACvE;IAEA,MAAMI,UAAU,IAAeH,QAAQF,OAAOM,MAAM;IAEpD,MAAMC,kBAAkB,IAAqBF,YAAYL,MAAM,CAACE,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AW;gBAC/B,OAAOgB;YACT,CAAC;YAED,MAAMC,QAAQF;YACd,IAAI,CAACE,OAAO;gBACV,OAAOxB;YACT,CAAC;YAED,OAAO;gBACLS,MAAMF;gBACNkB,aAAa;oBAACF;oBAAMC;iBAAM;YAC5B;QACF;QAEA,OAAOF;IACT;IAEA,MAAMI,eAAe,IAAkC;QACrD,MAAMH,OAAOT;QAEb,IAAI,CAACS,MAAM;YACT,OAAOV;QACT,CAAC;QAED,IAAI,CAACF,qBAAqB;YACxB,OAAOY;QACT,CAAC;QAED,MAAMC,QAAQV;QACd,IAAI,CAACU,OAAO;YACV,OAAOxB;QACT,CAAC;QAED,OAAO;YACLS,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,OAAOF;IACT,CAAC;IAED,OAAO4B;AACT"}
1
+ {"version":3,"sources":["../../../../../../packages/license-cop/src/lib/spdx/parse-tokens.ts"],"sourcesContent":["import { Identifier, SpdxExpression } from \"./types/spdx-expression\";\nimport { Token, Parenthesis, Operator } 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;;aAAAA;;AAAN,MAAMA,cAAc,CAACC,QAAiBC,gBAA0C;IACrF,IAAIC,QAAQ;IAEZ,MAAMC,gBAAgB,IAAM;QAC1BC,QAAQC,KAAK;QACb,MAAM,IAAIC,MAAM,CAAC,CAAC,EAAEL,cAAc,gCAAgC,CAAC,EAAE;IACvE;IAEA,MAAMM,UAAU,IAAeL,QAAQF,OAAOQ,MAAM;IAEpD,MAAMC,kBAAkB,IAAqBF,YAAYP,MAAM,CAACE,MAAM,GAAG,IAAI;IAE7E,MAAMQ,kBAAkB,IAAM;QAC5B,uBAAuB;QACvB,IAAI,CAACH,WAAW;YACdJ;QACF,CAAC;QAEDD;IACF;IAEA,MAAMS,sBAAsB,CAACC,WAAmC;QAC9D,MAAMC,eAAeJ;QAErB,IAAII,gBAAgBA,aAAaC,IAAI,KAAK,iBAAiBF,aAAaC,aAAaE,KAAK,EAAE;YAC1FL;YACA,OAAO,IAAI;QACb,CAAC;QAED,OAAO,KAAK;IACd;IAEA,MAAMM,oBAAoB,IAAe;QACvC,MAAMH,eAAeJ;QAErB,IAAII,gBAAgBA,aAAaC,IAAI,KAAK,QAAQ;YAChDJ;YACA,OAAO,IAAI;QACb,CAAC;QAED,OAAO,KAAK;IACd;IAEA,MAAMO,mBAAmB,CAACL,WAA6C;QACrE,MAAMC,eAAeJ;QAErB,IAAII,gBAAgBA,aAAaC,IAAI,KAAK,cAAcF,aAAaC,aAAaE,KAAK,EAAE;YACvFL;YACA,OAAOG,aAAaE,KAAK;QAC3B,CAAC;QAED,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