diff --git a/examples/cactus-check-connection-ethereum-validator/package.json b/examples/cactus-check-connection-ethereum-validator/package.json index 2db7a8d36c..59709083c4 100644 --- a/examples/cactus-check-connection-ethereum-validator/package.json +++ b/examples/cactus-check-connection-ethereum-validator/package.json @@ -1,6 +1,7 @@ { "name": "@hyperledger/cactus-examples-check-connection-ethereum-validator", "version": "2.0.0-alpha.1", + "license": "Apache-2.0", "private": true, "scripts": { "start": "node ../../dist/packages/cactus-cmd-socketio-server/src/main/typescript/routing-interface/www.js", diff --git a/examples/cactus-example-electricity-trade/tools/periodicExecuter/package.json b/examples/cactus-example-electricity-trade/tools/periodicExecuter/package.json index e7718664d3..514e2e7cae 100644 --- a/examples/cactus-example-electricity-trade/tools/periodicExecuter/package.json +++ b/examples/cactus-example-electricity-trade/tools/periodicExecuter/package.json @@ -1,6 +1,7 @@ { "name": "periodicExecuter", "version": "0.0.1", + "license": "Apache-2.0", "private": true, "scripts": { "build": "npm run build-ts", diff --git a/examples/cactus-example-electricity-trade/tools/transferNumericAsset/package.json b/examples/cactus-example-electricity-trade/tools/transferNumericAsset/package.json index 9f8263ca6a..b61f5e4013 100644 --- a/examples/cactus-example-electricity-trade/tools/transferNumericAsset/package.json +++ b/examples/cactus-example-electricity-trade/tools/transferNumericAsset/package.json @@ -1,6 +1,7 @@ { "name": "transferNumericAsset", "version": "0.0.0", + "license": "Apache-2.0", "private": true, "scripts": { "build": "npm run build-ts && npm run copy-static-assets", diff --git a/examples/cactus-example-tcs-huawei/tools/periodicExecuter/package.json b/examples/cactus-example-tcs-huawei/tools/periodicExecuter/package.json index e7718664d3..514e2e7cae 100644 --- a/examples/cactus-example-tcs-huawei/tools/periodicExecuter/package.json +++ b/examples/cactus-example-tcs-huawei/tools/periodicExecuter/package.json @@ -1,6 +1,7 @@ { "name": "periodicExecuter", "version": "0.0.1", + "license": "Apache-2.0", "private": true, "scripts": { "build": "npm run build-ts", diff --git a/examples/cactus-example-tcs-huawei/tools/transferNumericAsset/package.json b/examples/cactus-example-tcs-huawei/tools/transferNumericAsset/package.json index 5d0ac2231f..e17b1b94bc 100644 --- a/examples/cactus-example-tcs-huawei/tools/transferNumericAsset/package.json +++ b/examples/cactus-example-tcs-huawei/tools/transferNumericAsset/package.json @@ -1,6 +1,7 @@ { "name": "transferNumericAsset", "version": "0.0.0", + "license": "Apache-2.0", "private": true, "scripts": { "build": "npm run build-ts && npm run copy-static-assets", diff --git a/examples/test-run-transaction/package.json b/examples/test-run-transaction/package.json index 746d9db363..3d9c47298c 100644 --- a/examples/test-run-transaction/package.json +++ b/examples/test-run-transaction/package.json @@ -1,5 +1,6 @@ { "name": "test-run-transaction", + "license": "Apache-2.0", "private": true, "scripts": { "start": "node ../../dist/packages/cactus-cmd-socketio-server/src/main/typescript/routing-interface/www.js", diff --git a/package.json b/package.json index 6e8826eddc..dcd442ebb2 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,6 @@ { "name": "@hyperledger/cactus", + "license": "Apache-2.0", "private": true, "description": "Root project for Cactus which contains all core components and plugins developed by the project.", "workspaces": { diff --git a/packages-python/cactus_validator_socketio_indy/testcli/package.json b/packages-python/cactus_validator_socketio_indy/testcli/package.json index 8b5b41098f..a007de9995 100644 --- a/packages-python/cactus_validator_socketio_indy/testcli/package.json +++ b/packages-python/cactus_validator_socketio_indy/testcli/package.json @@ -1,5 +1,6 @@ { "name": "testcli", + "license": "Apache-2.0", "version": "0.0.0", "private": true, "dependencies": { diff --git a/packages-python/cactus_validator_socketio_iroha/testcli/package.json b/packages-python/cactus_validator_socketio_iroha/testcli/package.json index d64cd4668a..45b42b4288 100644 --- a/packages-python/cactus_validator_socketio_iroha/testcli/package.json +++ b/packages-python/cactus_validator_socketio_iroha/testcli/package.json @@ -1,5 +1,6 @@ { "name": "testcli", + "license": "Apache-2.0", "version": "0.0.0", "private": true, "dependencies": { diff --git a/packages/cactus-cmd-api-server/src/test/resources/cactus-dummy-package/package.json b/packages/cactus-cmd-api-server/src/test/resources/cactus-dummy-package/package.json index 24e2e2f91c..72b49a239a 100644 --- a/packages/cactus-cmd-api-server/src/test/resources/cactus-dummy-package/package.json +++ b/packages/cactus-cmd-api-server/src/test/resources/cactus-dummy-package/package.json @@ -1,6 +1,7 @@ { "name": "@hyperledger/cactus-dummy-package", "version": "2.0.0-alpha.1", + "license": "Apache-2.0", "description": "Dummy package for testing.", "main": "index.js" } \ No newline at end of file diff --git a/packages/cactus-plugin-ledger-connector-fabric-socketio/src/test/typescript/unit-test/package.json b/packages/cactus-plugin-ledger-connector-fabric-socketio/src/test/typescript/unit-test/package.json index 8083b47f5d..8523041d5a 100644 --- a/packages/cactus-plugin-ledger-connector-fabric-socketio/src/test/typescript/unit-test/package.json +++ b/packages/cactus-plugin-ledger-connector-fabric-socketio/src/test/typescript/unit-test/package.json @@ -1,6 +1,7 @@ { "name": "validatorDriver", "version": "0.0.0", + "license": "Apache-2.0", "private": true, "scripts": { "build": "npm run build-ts && npm run copy-static-assets", diff --git a/packages/cactus-plugin-ledger-connector-go-ethereum-socketio/src/test/typescript/unit-test/package.json b/packages/cactus-plugin-ledger-connector-go-ethereum-socketio/src/test/typescript/unit-test/package.json index 261691e33d..15d0d131cc 100644 --- a/packages/cactus-plugin-ledger-connector-go-ethereum-socketio/src/test/typescript/unit-test/package.json +++ b/packages/cactus-plugin-ledger-connector-go-ethereum-socketio/src/test/typescript/unit-test/package.json @@ -1,6 +1,7 @@ { "name": "validatorDriver", "version": "0.0.0", + "license": "Apache-2.0", "private": true, "scripts": { "build": "npm run build-ts && npm run copy-static-assets", diff --git a/tools/custom-checks/check-pkg-licenses.ts b/tools/custom-checks/check-pkg-licenses.ts new file mode 100644 index 0000000000..8a1d9b779a --- /dev/null +++ b/tools/custom-checks/check-pkg-licenses.ts @@ -0,0 +1,84 @@ +import fs from "fs-extra"; +import path from "path"; +import { fileURLToPath } from "url"; +import { globby, Options as GlobbyOptions } from "globby"; +import { RuntimeError } from "run-time-error"; +import { isStdLibRecord } from "./is-std-lib-record"; + +export interface ICheckPkgLicensesRequest { + readonly argv: string[]; + readonly env: NodeJS.ProcessEnv; + readonly expectedLicenseSpdx?: string; +} + +export const DEFAULT_EXPECTED_LICENSE_SPDX = "Apache-2.0" as const; + +/** + * @returns An array with the first item being a boolean indicating + * 1) success (`true`) or 2) failure (`false`) and the second item being an + * array of strings which contain all the errors found (if any). + */ +export async function checkPkgLicenses( + req: ICheckPkgLicensesRequest, +): Promise<[boolean, string[]]> { + const TAG = "[tools/check-pkg-licenses.ts]"; + const __filename = fileURLToPath(import.meta.url); + const __dirname = path.dirname(__filename); + const SCRIPT_DIR = __dirname; + const PROJECT_DIR = path.join(SCRIPT_DIR, "../../"); + console.log(`${TAG} SCRIPT_DIR=${SCRIPT_DIR}`); + console.log(`${TAG} PROJECT_DIR=${PROJECT_DIR}`); + if (!req) { + throw new RuntimeError(`req parameter cannot be falsy.`); + } + if (!req.argv) { + throw new RuntimeError(`req.argv cannot be falsy.`); + } + if (!req.env) { + throw new RuntimeError(`req.env cannot be falsy.`); + } + + const expectedLicenseSpdx = + req.expectedLicenseSpdx ?? DEFAULT_EXPECTED_LICENSE_SPDX; + + console.log(`${TAG} req.expectedLicenseSpdx=${req.expectedLicenseSpdx}`); + console.log( + `${TAG} DEFAULT_EXPECTED_LICENSE_SPDX=${DEFAULT_EXPECTED_LICENSE_SPDX}`, + ); + console.log(`${TAG} Concluded expectedLicenseSpdx=${expectedLicenseSpdx}`); + + const globbyOpts: GlobbyOptions = { + cwd: PROJECT_DIR, + ignore: ["**/node_modules"], + }; + const DEFAULT_GLOB = "**/package.json"; + + console.log(`${TAG} Glob pattern=%s - options=%o`, DEFAULT_GLOB, globbyOpts); + const pkgJsonPaths = await globby(DEFAULT_GLOB, globbyOpts); + console.log(`${TAG} Glob found %o package.json files.`, pkgJsonPaths.length); + + const errors: string[] = []; + const checks = pkgJsonPaths.map(async (pathRel) => { + const filePathAbs = path.join(PROJECT_DIR, pathRel); + const pkgJson: unknown = await fs.readJSON(filePathAbs); + if (typeof pkgJson !== "object") { + errors.push(`ERROR: ${pathRel} package.json cannot be empty.`); + return; + } + if (!pkgJson) { + errors.push(`ERROR: ${pathRel} package.json cannot be empty.`); + return; + } + if (!isStdLibRecord(pkgJson)) { + return; + } + const { license } = pkgJson; + if (license !== expectedLicenseSpdx) { + const eMsg = `${TAG} Error: ${pathRel} has incorrect license SPDX. Expected ${expectedLicenseSpdx}, got ${license} instead.`; + console.log(eMsg); + errors.push(eMsg); + } + }); + await Promise.all(checks); + return [errors.length === 0, errors]; +} diff --git a/tools/custom-checks/check-sibling-dep-version-consistency.ts b/tools/custom-checks/check-sibling-dep-version-consistency.ts index 1f0ab2cc5a..a6ae25ea10 100644 --- a/tools/custom-checks/check-sibling-dep-version-consistency.ts +++ b/tools/custom-checks/check-sibling-dep-version-consistency.ts @@ -63,7 +63,7 @@ export async function checkSiblingDepVersionConsistency( const pkgJsonPaths = await globby(DEFAULT_GLOB, globbyOpts); console.log(`${TAG} package.json paths: (${pkgJsonPaths.length}): `); - + const lernaJsonPathAbs = path.join(PROJECT_DIR, "./lerna.json"); console.log(`${TAG} Reading root lerna.json at ${lernaJsonPathAbs}`); const lernaJson = await fs.readJSON(lernaJsonPathAbs); diff --git a/tools/custom-checks/package.json b/tools/custom-checks/package.json index aead43de36..2024f0601d 100644 --- a/tools/custom-checks/package.json +++ b/tools/custom-checks/package.json @@ -1,3 +1,4 @@ { + "license": "Apache-2.0", "type": "module" } \ No newline at end of file diff --git a/tools/custom-checks/run-custom-checks.ts b/tools/custom-checks/run-custom-checks.ts index 770e1b4524..452f8354da 100644 --- a/tools/custom-checks/run-custom-checks.ts +++ b/tools/custom-checks/run-custom-checks.ts @@ -1,6 +1,7 @@ import esMain from "es-main"; import { checkOpenApiJsonSpecs } from "./check-open-api-json-specs"; import { checkPackageJsonSort } from "./check-package-json-sort"; +import { checkPkgLicenses } from "./check-pkg-licenses"; import { checkSiblingDepVersionConsistency } from "./check-sibling-dep-version-consistency"; import { checkPkgNpmScope } from "./check-pkg-npm-scope"; @@ -50,6 +51,11 @@ export async function runCustomChecks( overallSuccess = overallSuccess && success; } + { + const [success, errors] = await checkPkgLicenses({ argv, env }); + overallErrors = overallErrors.concat(errors); + overallSuccess = overallSuccess && success; + } if (!overallSuccess) { overallErrors.forEach((it) => console.error(it)); } else { diff --git a/tools/package.json b/tools/package.json index 472002573e..fc60e76c75 100644 --- a/tools/package.json +++ b/tools/package.json @@ -1,3 +1,4 @@ { + "license": "Apache-2.0", "type": "module" } diff --git a/weaver/common/policy-dsl/package.json b/weaver/common/policy-dsl/package.json index db27abf8a6..d4a5f95b9a 100644 --- a/weaver/common/policy-dsl/package.json +++ b/weaver/common/policy-dsl/package.json @@ -23,7 +23,7 @@ "url": "git@github.ibm.com:dlt-interoperability/policy-dsl.git" }, "author": "", - "license": "ISC", + "license": "Apache-2.0", "devDependencies": { "ava": "4.3.3", "jest": "29.6.2" diff --git a/weaver/docs/package.json b/weaver/docs/package.json index 14dd132413..f9c06e3e12 100644 --- a/weaver/docs/package.json +++ b/weaver/docs/package.json @@ -1,6 +1,7 @@ { "name": "weaver-dlt-interoperability", "version": "0.0.0", + "license": "Apache-2.0", "private": true, "scripts": { "docusaurus": "docusaurus",