From d9aa2eaba290966ef5b0bd85d4e6632500646319 Mon Sep 17 00:00:00 2001 From: Shibesh Duwadi Date: Tue, 8 Oct 2024 10:30:30 +0200 Subject: [PATCH] stuff --- .github/actions/check-license/index.js | 13 +- package.json | 2 + pnpm-lock.yaml | 173 +++++++++++++++++++++++++ scripts/check-licenses.ts | 80 ++++++++++++ 4 files changed, 257 insertions(+), 11 deletions(-) create mode 100644 scripts/check-licenses.ts diff --git a/.github/actions/check-license/index.js b/.github/actions/check-license/index.js index c6dbc5e6..637605c4 100644 --- a/.github/actions/check-license/index.js +++ b/.github/actions/check-license/index.js @@ -1,12 +1,3 @@ -import * as core from '@actions/core'; import { checkLicenses } from '../../../scripts/check-licenses'; - -async function run() { - try { - await checkLicenses(); - } catch (error) { - if (error instanceof Error) core.setFailed(error.message); - } - } - - run(); \ No newline at end of file +await checkLicenses(); + \ No newline at end of file diff --git a/package.json b/package.json index 97d808c1..080cb74e 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ "@sap-cloud-sdk/util": "^3.21.0", "@types/jest": "^29.5.13", "@types/jsonwebtoken": "^9.0.7", + "@types/license-checker": "^25.0.6", "@types/mock-fs": "^4.13.4", "@types/node": "^20.16.10", "depcheck": "^1.4.7", @@ -53,6 +54,7 @@ "glob": "^11.0.0", "jest": "^30.0.0-alpha.6", "jsonwebtoken": "^9.0.2", + "license-checker": "^25.0.1", "mock-fs": "^5.3.0", "nock": "^13.5.5", "prettier": "^3.3.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index fa6c53ab..4912d3d6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -52,6 +52,9 @@ importers: '@types/jsonwebtoken': specifier: ^9.0.7 version: 9.0.7 + '@types/license-checker': + specifier: ^25.0.6 + version: 25.0.6 '@types/mock-fs': specifier: ^4.13.4 version: 4.13.4 @@ -73,6 +76,9 @@ importers: jsonwebtoken: specifier: ^9.0.2 version: 9.0.2 + license-checker: + specifier: ^25.0.1 + version: 25.0.1 mock-fs: specifier: ^5.3.0 version: 5.3.0 @@ -946,6 +952,9 @@ packages: '@types/jsonwebtoken@9.0.7': resolution: {integrity: sha512-ugo316mmTYBl2g81zDFnZ7cfxlut3o+/EQdaP7J8QN2kY6lJ22hmQYCK5EHcJHbrW+dkCGSCPgbG8JtYj6qSrg==} + '@types/license-checker@25.0.6': + resolution: {integrity: sha512-ju/75+YPkNE5vX1iPer+qtI1eI/LqJVYZgOsmSHI1iiEM1bQL5Gh1lEvyjR9T7ZXVE1FwJa2doWJEEmPNwbZkw==} + '@types/mime@1.3.5': resolution: {integrity: sha512-/pyBZWSLD2n0dcHE3hq8s8ZvcETHtEuF+3E7XVt0Ig2nvsVQXdghHVcEkIWjy9A0wKfTn97a/PSDYohKIlnP/w==} @@ -1093,6 +1102,9 @@ packages: '@vue/shared@3.5.6': resolution: {integrity: sha512-eidH0HInnL39z6wAt6SFIwBrvGOpDWsDxlw3rCgo1B+CQ1781WzQUSU3YjxgdkcJo9Q8S6LmXTkvI+cLHGkQfA==} + abbrev@1.1.1: + resolution: {integrity: sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==} + abort-controller@3.0.0: resolution: {integrity: sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==} engines: {node: '>=6.5'} @@ -1194,6 +1206,10 @@ packages: resolution: {integrity: sha512-THtfYS6KtME/yIAhKjZ2ul7XI96lQGHRputJQHO80LAWQnuGP4iCIN8vdMRboGbIEYBwU33q8Tch1os2+X0kMg==} engines: {node: '>=8'} + array-find-index@1.0.2: + resolution: {integrity: sha512-M1HQyIXcBGtVywBt8WVdim+lrNaK7VHp99Qt5pSNziXznKHViIBbXWtfRTpEFpF/c4FdfxNAsCCwPp5phBYJtw==} + engines: {node: '>=0.10.0'} + array-flatten@1.1.1: resolution: {integrity: sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==} @@ -1229,6 +1245,9 @@ packages: resolution: {integrity: sha512-3duEwti880xqi4eAMN8AyR4a0ByT90zoYdLlevfrvU43vb0YZwZVfxOgxWrLXXXpyugL0hNZc9G6BiB5B3nUug==} engines: {node: '>=8'} + asap@2.0.6: + resolution: {integrity: sha512-BSHWgDSAiKs50o2Re8ppvp3seVHXSRM44cdSsT9FfNEUUZLOGWVCsiWaRPWM1Znn+mqZ1OfVZ3z3DWEzSp7hRA==} + assert-plus@1.0.0: resolution: {integrity: sha512-NfJ4UzBCcQGLDlQq7nHxH+tv3kyZ0hHQqF5BO6J7tNJeP5do1llPr8dZ8zHonfhAu0PHAdMkSo+8o0wxg9lZWw==} engines: {node: '>=0.8'} @@ -1579,6 +1598,10 @@ packages: supports-color: optional: true + debuglog@1.0.1: + resolution: {integrity: sha512-syBZ+rnAK3EgMsH2aYEOLUW7mZSY9Gb+0wUMCFsZvcmiz+HigA0LOcq/HoQqVuGG+EKykunc7QG2bzrponfaSw==} + deprecated: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info. + decamelize-keys@1.1.1: resolution: {integrity: sha512-WiPxgEirIV0/eIOMcnFBA3/IJZAZqKnwAwWyvvdi4lsr1WCN22nhdf/3db3DoZcUjTV2SqfzIwNyp6y2xs3nmg==} engines: {node: '>=0.10.0'} @@ -1645,6 +1668,9 @@ packages: resolution: {integrity: sha512-TLz+x/vEXm/Y7P7wn1EJFNLxYpUD4TgMosxY6fAVJUnJMbupHBOncxyWUG9OpTaH9EBD7uFI5LfEgmMOc54DsA==} engines: {node: '>=8'} + dezalgo@1.0.4: + resolution: {integrity: sha512-rXSP0bf+5n0Qonsb+SVVfNfIsimO4HEtmnIpPHY8Q1UCzKlQrDMfdobr8nJOOsRgWCyMRqeSBQzmWUMq7zvVig==} + diff-sequences@29.6.3: resolution: {integrity: sha512-EjePK1srD3P08o2j4f0ExnylqRs5B9tJjcp9t1krH2qRi8CCdsYfwe9JgSLurFBWwq4uOlipzfk5fHNvwFKr8Q==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} @@ -2815,6 +2841,10 @@ packages: resolution: {integrity: sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==} engines: {node: '>= 0.8.0'} + license-checker@25.0.1: + resolution: {integrity: sha512-mET5AIwl7MR2IAKYYoVBBpV0OnkKQ1xGj2IMMeEFIs42QAkEVjRtFZGWmQ28WeU7MP779iAgOaOy93Mn44mn6g==} + hasBin: true + lilconfig@3.1.2: resolution: {integrity: sha512-eop+wDAvpItUys0FWkHIKeC9ybYrTGbU41U5K7+bttZZeohvnY7M9dZ5kB21GNWiFT2q1OoPTvncPCgSOVO5ow==} engines: {node: '>=14'} @@ -2987,6 +3017,10 @@ packages: resolution: {integrity: sha512-qOOzS1cBTWYF4BH8fVePDBOO9iptMnGUEZwNc/cMWnTV2nVLZ7VoNWEPHkYczZA0pdoA7dl6e7FL659nX9S2aw==} engines: {node: '>=16 || 14 >=14.17'} + mkdirp@0.5.6: + resolution: {integrity: sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==} + hasBin: true + mock-fs@5.3.0: resolution: {integrity: sha512-IMvz1X+RF7vf+ur7qUenXMR7/FSKSIqS3HqFHXcyNI7G0FbpFO8L5lfsUJhl+bhK1AiulVHWKUSxebWauPA+xQ==} engines: {node: '>=12.0.0'} @@ -3061,6 +3095,10 @@ packages: node-releases@2.0.14: resolution: {integrity: sha512-y10wOWt8yZpqXmOgRo77WaHEmhYQYGNA6y421PKsKYWEK8aW+cqAphborZDhqfyKrbZEN92CN1X2KbafY2s7Yw==} + nopt@4.0.3: + resolution: {integrity: sha512-CvaGwVMztSMJLOeXPrez7fyfObdZqNUK1cPAEzLHrTybIua9pMdmmPR5YwtfNftIOMv3DPUhFaxsZMNTQO20Kg==} + hasBin: true + normalize-package-data@2.5.0: resolution: {integrity: sha512-/5CMN3T0R4XTj4DcGaexo+roZSdSFW/0AOOTROrjxzCG1wrWXEsGbRKevjlIL+ZDE4sZlJr5ED4YW0yqmkK+eA==} @@ -3072,6 +3110,9 @@ packages: resolution: {integrity: sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==} engines: {node: '>=0.10.0'} + npm-normalize-package-bin@1.0.1: + resolution: {integrity: sha512-EPfafl6JL5/rU+ot6P3gRSCpPDW5VmIzX959Ob1+ySFUuuYHWHekXpwdUZcKP5C+DS4GEtdJluwBjnsNDl+fSA==} + npm-run-path@4.0.1: resolution: {integrity: sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==} engines: {node: '>=8'} @@ -3160,10 +3201,18 @@ packages: resolution: {integrity: sha512-5b6Y85tPxZZ7QytO+BQzysW31HJku27cRIlkbAXaNx+BdcVi+LlRFmVXzeF6a7JCwJpyw5c4b+YSVImQIrBpuQ==} engines: {node: '>=10'} + os-homedir@1.0.2: + resolution: {integrity: sha512-B5JU3cabzk8c67mRRd3ECmROafjYMXbuzlwtqdM8IbS8ktlTix8aFGb2bAGKrSRIlnfKwovGUUr72JUPyOb6kQ==} + engines: {node: '>=0.10.0'} + os-tmpdir@1.0.2: resolution: {integrity: sha512-D2FR03Vir7FIu45XBY20mTb+/ZSWB00sjU9jdQXt83gDrI4Ztz5Fs7/yy74g2N5SVQY4xY1qDr4rNddwYRVX0g==} engines: {node: '>=0.10.0'} + osenv@0.1.5: + resolution: {integrity: sha512-0CWcCECdMVc2Rw3U5w9ZjqX6ga6ubk1xDVKxtBQPK7wis/0F2r9T6k4ydGYhecl7YUBxBVxhL5oisPsNxAPe2g==} + deprecated: This package is no longer supported. + outdent@0.5.0: resolution: {integrity: sha512-/jHxFIzoMXdqPzTaCpFzAAWhpkSjZPF4Vsn6jAfNpmbH/ymsmd7Qc6VE9BGn0L6YMj6uwpQLxCECpus4ukKS9Q==} @@ -3388,6 +3437,14 @@ packages: react-is@18.3.1: resolution: {integrity: sha512-/LLMVyas0ljjAtoYiPqYiL8VWXzUUdThrmU5+n20DZv+a+ClRoevUzw5JxU+Ieh5/c87ytoTBV9G1FiKfNJdmg==} + read-installed@4.0.3: + resolution: {integrity: sha512-O03wg/IYuV/VtnK2h/KXEt9VIbMUFbk3ERG0Iu4FhLZw0EP0T9znqrYDGn6ncbEsXUFaUjiVAWXHzxwt3lhRPQ==} + deprecated: This package is no longer supported. + + read-package-json@2.1.2: + resolution: {integrity: sha512-D1KmuLQr6ZSJS0tW8hf3WGpRlwszJOXZ3E8Yd/DNRaM5d+1wVRZdHlpGBLAuovjr28LbWvjpWkBHMxpRGGjzNA==} + deprecated: This package is no longer supported. Please use @npmcli/package-json instead. + read-pkg-up@7.0.1: resolution: {integrity: sha512-zK0TB7Xd6JpCLmlLmufqykGE+/TlOePD6qKClNW7hHDKFh/J7/7gCWGR7joEQEW1bKq3a3yUZSObOoWLFQ4ohg==} engines: {node: '>=8'} @@ -3404,6 +3461,10 @@ packages: resolution: {integrity: sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==} engines: {node: '>= 6'} + readdir-scoped-modules@1.1.0: + resolution: {integrity: sha512-asaikDeqAQg7JifRsZn1NJZXo9E+VwlyCfbkZhwyISinqk5zNS6266HS5kah6P0SaQKGF6SkNnZVHUzHFYxYDw==} + deprecated: This functionality has been moved to @npmcli/fs + readdirp@3.6.0: resolution: {integrity: sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==} engines: {node: '>=8.10.0'} @@ -3587,6 +3648,9 @@ packages: slashes@3.0.12: resolution: {integrity: sha512-Q9VME8WyGkc7pJf6QEkj3wE+2CnvZMI+XJhwdTPR8Z/kWQRXi7boAWLDibRPyHRTUTPx5FaU7MsyrjI3yLB4HA==} + slide@1.1.6: + resolution: {integrity: sha512-NwrtjCg+lZoqhFU8fOwl4ay2ei8PaqCBOUV3/ektPY9trO1yQ1oXEfmHAhKArUVUr/hOHvy5f6AdP17dCM0zMw==} + source-map-js@1.2.1: resolution: {integrity: sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==} engines: {node: '>=0.10.0'} @@ -3601,6 +3665,9 @@ packages: spawndamnit@2.0.0: resolution: {integrity: sha512-j4JKEcncSjFlqIwU5L/rp2N5SIPsdxaRsIv678+TZxZ0SRDJTm8JrxJMjE/XuiEZNEir3S8l0Fa3Ke339WI4qA==} + spdx-compare@1.0.0: + resolution: {integrity: sha512-C1mDZOX0hnu0ep9dfmuoi03+eOdDoz2yvK79RxbcrVEG1NO1Ph35yW102DHWKN4pk80nwCgeMmSY5L25VE4D9A==} + spdx-correct@3.2.0: resolution: {integrity: sha512-kN9dJbvnySHULIluDHy32WHRUu3Og7B9sbY7tsFLctQkIqnMh3hErYgdMjTYuqmcXX+lK5T1lnUt3G7zNswmZA==} @@ -3616,6 +3683,12 @@ packages: spdx-license-ids@3.0.20: resolution: {integrity: sha512-jg25NiDV/1fLtSgEgyvVyDunvaNHbuwF9lfNV17gSmPFAlYzdfNBlLtLzXTevwkPj7DhGbmN9VnmJIgLnhvaBw==} + spdx-ranges@2.1.1: + resolution: {integrity: sha512-mcdpQFV7UDAgLpXEE/jOMqvK4LBoO0uTQg0uvXUewmEFhpiZx5yJSZITHB8w1ZahKdhfZqP5GPEOKLyEq5p8XA==} + + spdx-satisfies@4.0.1: + resolution: {integrity: sha512-WVzZ/cXAzoNmjCWiEluEA3BjHp5tiUmmhn9MK+X0tBbR9sOqtC6UQwmgCNrAIZvNlMuBUYAaHYfb2oqlF9SwKA==} + sprintf-js@1.0.3: resolution: {integrity: sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g==} @@ -3757,6 +3830,10 @@ packages: tr46@0.0.3: resolution: {integrity: sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==} + treeify@1.1.0: + resolution: {integrity: sha512-1m4RA7xVAJrSGrrXGs0L3YTwyvBs2S8PbRHaLZAkFw7JR8oIFwYtysxlBZhYIa7xSyiYJKZ3iGrrk55cGA3i9A==} + engines: {node: '>=0.6'} + trim-newlines@3.0.1: resolution: {integrity: sha512-c1PTsA3tYrIsLGkJkzHF+w9F2EyxfXGo4UyJc4pFL++FMjnq0HJS69T3M7d//gKrFKwy429bouPescbjecU+Zw==} engines: {node: '>=8'} @@ -3929,6 +4006,9 @@ packages: util-deprecate@1.0.2: resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==} + util-extend@1.0.3: + resolution: {integrity: sha512-mLs5zAK+ctllYBj+iAQvlDCwoxU/WDOUaJkcFudeiAX6OajC6BKXJUa9a+tbtkC11dz2Ufb7h0lyvIOVn4LADA==} + utils-merge@1.0.1: resolution: {integrity: sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==} engines: {node: '>= 0.4.0'} @@ -5208,6 +5288,8 @@ snapshots: dependencies: '@types/node': 20.16.10 + '@types/license-checker@25.0.6': {} + '@types/mime@1.3.5': {} '@types/minimatch@3.0.5': {} @@ -5394,6 +5476,8 @@ snapshots: '@vue/shared@3.5.6': {} + abbrev@1.1.1: {} + abort-controller@3.0.0: dependencies: event-target-shim: 5.0.1 @@ -5481,6 +5565,8 @@ snapshots: array-differ@3.0.0: {} + array-find-index@1.0.2: {} + array-flatten@1.1.1: {} array-includes@3.1.8: @@ -5532,6 +5618,8 @@ snapshots: arrify@2.0.1: {} + asap@2.0.6: {} + assert-plus@1.0.0: {} async-retry@1.3.3: @@ -5933,6 +6021,8 @@ snapshots: optionalDependencies: supports-color: 8.1.1 + debuglog@1.0.1: {} + decamelize-keys@1.1.1: dependencies: decamelize: 1.2.0 @@ -6004,6 +6094,11 @@ snapshots: detect-newline@3.1.0: {} + dezalgo@1.0.4: + dependencies: + asap: 2.0.6 + wrappy: 1.0.2 + diff-sequences@29.6.3: {} diff-sequences@30.0.0-alpha.6: {} @@ -7519,6 +7614,21 @@ snapshots: prelude-ls: 1.2.1 type-check: 0.4.0 + license-checker@25.0.1: + dependencies: + chalk: 2.4.2 + debug: 3.2.7 + mkdirp: 0.5.6 + nopt: 4.0.3 + read-installed: 4.0.3 + semver: 5.7.2 + spdx-correct: 3.2.0 + spdx-expression-parse: 3.0.1 + spdx-satisfies: 4.0.1 + treeify: 1.1.0 + transitivePeerDependencies: + - supports-color + lilconfig@3.1.2: {} lines-and-columns@1.2.4: {} @@ -7674,6 +7784,10 @@ snapshots: minipass@7.1.2: {} + mkdirp@0.5.6: + dependencies: + minimist: 1.2.8 + mock-fs@5.3.0: {} mri@1.2.0: {} @@ -7732,6 +7846,11 @@ snapshots: node-releases@2.0.14: {} + nopt@4.0.3: + dependencies: + abbrev: 1.1.1 + osenv: 0.1.5 + normalize-package-data@2.5.0: dependencies: hosted-git-info: 2.8.9 @@ -7748,6 +7867,8 @@ snapshots: normalize-path@3.0.0: {} + npm-normalize-package-bin@1.0.1: {} + npm-run-path@4.0.1: dependencies: path-key: 3.1.1 @@ -7877,8 +7998,15 @@ snapshots: strip-ansi: 6.0.1 wcwidth: 1.0.1 + os-homedir@1.0.2: {} + os-tmpdir@1.0.2: {} + osenv@0.1.5: + dependencies: + os-homedir: 1.0.2 + os-tmpdir: 1.0.2 + outdent@0.5.0: {} p-filter@2.1.0: @@ -8071,6 +8199,24 @@ snapshots: react-is@18.3.1: {} + read-installed@4.0.3: + dependencies: + debuglog: 1.0.1 + read-package-json: 2.1.2 + readdir-scoped-modules: 1.1.0 + semver: 5.7.2 + slide: 1.1.6 + util-extend: 1.0.3 + optionalDependencies: + graceful-fs: 4.2.11 + + read-package-json@2.1.2: + dependencies: + glob: 7.2.3 + json-parse-even-better-errors: 2.3.1 + normalize-package-data: 2.5.0 + npm-normalize-package-bin: 1.0.1 + read-pkg-up@7.0.1: dependencies: find-up: 4.1.0 @@ -8097,6 +8243,13 @@ snapshots: string_decoder: 1.3.0 util-deprecate: 1.0.2 + readdir-scoped-modules@1.1.0: + dependencies: + debuglog: 1.0.1 + dezalgo: 1.0.4 + graceful-fs: 4.2.11 + once: 1.4.0 + readdirp@3.6.0: dependencies: picomatch: 2.3.1 @@ -8292,6 +8445,8 @@ snapshots: slashes@3.0.12: {} + slide@1.1.6: {} + source-map-js@1.2.1: {} source-map-support@0.5.13: @@ -8306,6 +8461,12 @@ snapshots: cross-spawn: 5.1.0 signal-exit: 3.0.7 + spdx-compare@1.0.0: + dependencies: + array-find-index: 1.0.2 + spdx-expression-parse: 3.0.1 + spdx-ranges: 2.1.1 + spdx-correct@3.2.0: dependencies: spdx-expression-parse: 3.0.1 @@ -8325,6 +8486,14 @@ snapshots: spdx-license-ids@3.0.20: {} + spdx-ranges@2.1.1: {} + + spdx-satisfies@4.0.1: + dependencies: + spdx-compare: 1.0.0 + spdx-expression-parse: 3.0.1 + spdx-ranges: 2.1.1 + sprintf-js@1.0.3: {} stack-trace@0.0.10: {} @@ -8481,6 +8650,8 @@ snapshots: tr46@0.0.3: {} + treeify@1.1.0: {} + trim-newlines@3.0.1: {} triple-beam@1.4.1: {} @@ -8668,6 +8839,8 @@ snapshots: util-deprecate@1.0.2: {} + util-extend@1.0.3: {} + utils-merge@1.0.1: {} uuid@10.0.0: {} diff --git a/scripts/check-licenses.ts b/scripts/check-licenses.ts new file mode 100644 index 00000000..10e1fdff --- /dev/null +++ b/scripts/check-licenses.ts @@ -0,0 +1,80 @@ +import path, { resolve } from 'path'; +import { fileURLToPath } from 'url'; +import { ModuleInfos, init } from 'license-checker'; +import { createLogger } from '@sap-cloud-sdk/util'; + +const logger = createLogger('check-licenses'); + +// Here all permissive FLOSS licenses are ok, see https://en.wikipedia.org/wiki/Permissive_software_license +// We just added the most common ones here. If one is in the wiki list and not here add it. +const allowedLicenses = [ + 'MIT', + 'Apache', + 'ISC', + 'BSD', + 'WTFPL', + 'CC-BY', + 'CC0', + 'Unlicense', + 'Public Domain' +]; + +const __dirname = path.dirname(fileURLToPath(import.meta.url)); + +async function getLicenses(): Promise { + return new Promise((resolvePromise, reject) => { + init( + { + start: resolve(__dirname, '..'), + direct: true, + summary: true, + json: true, + production: true + }, + function (err, packages: ModuleInfos) { + if (err) { + reject(`Could not check licenses. Error: ${err}`); + } + resolvePromise(packages); + } + ); + }); +} + +function isAllowedLicense(licenses: string | string[] | undefined): Boolean { + return Array.isArray(licenses) + ? isAllowedLicense(licenses.join(',')) + : allowedLicenses.some(allowedLicense => licenses?.includes(allowedLicense)); +} + +function isSapDependency(dependency: string) { + // Exclude root package from license check + if (dependency.startsWith('sap-ai-sdk')) { + return true; + } + const [scope] = dependency.split('/'); + return scope === '@sap' || scope === '@sap-ai-sdk'; +} + +async function checkLicenses() { + const licenses = await getLicenses(); + const notAllowedDependencies = Object.entries(licenses) + .filter(([, licenseInfo]) => !isAllowedLicense(licenseInfo.licenses)) + .filter(([packageName]) => !isSapDependency(packageName)); + + if (notAllowedDependencies.length) { + notAllowedDependencies.forEach(notAllowedDependency => { + logger.error( + `Not allowed license ${notAllowedDependency[1].licenses} found for dependency: ${notAllowedDependency[0]}.` + ); + }); + logger.error( + 'Check if the faulty licenses are in the FLOSS list: https://en.wikipedia.org/wiki/Category:Free_and_open-source_software_licenses and update the check script accordingly.' + ); + process.exit(1); + } + + logger.info('License check completed.') +} + +checkLicenses();