Skip to content

Commit

Permalink
chore: fix license validate check
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed May 2, 2024
1 parent 2d1abcd commit edac6ae
Show file tree
Hide file tree
Showing 3 changed files with 970 additions and 22 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"cross-env": "^7.0.3",
"lerna": "^8.1.2",
"rimraf": "^5.0.5",
"snyk-nodejs-lockfile-parser": "^1.53.2",
"ts-loader": "^9.5.1",
"ts-node": "^10.9.2",
"typescript": "~5.0.4",
Expand All @@ -32,8 +33,8 @@
"bump": "lerna version --exact --conventional-commits --no-push -m \"chore(release): publish %s\"",
"graduate": "run bump --conventional-graduate",
"publish2": "run build && lerna publish from-package --pre-dist-tag next",
"validate:dependencies": "yarn npm audit --groups dependencies && run license-validate",
"license-validate": "sofie-licensecheck --allowPackages \"@loupedeck/web-demo@$(node -p \"require('./packages/web-demo/package.json').version\");[email protected];[email protected];[email protected]\"",
"validate:dependencies": "yarn npm audit && run license-validate",
"license-validate": "node ./scripts/license-check.mjs",
"g:husky": "./node_modules/.bin/husky",
"g:lint-staged": "./node_modules/.bin/lint-staged"
},
Expand Down
63 changes: 63 additions & 0 deletions scripts/license-check.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import cp from 'child_process'
import fs from 'fs/promises'
import { buildDepTreeFromFiles } from 'snyk-nodejs-lockfile-parser'

const allDepVersions = new Map()

async function addDepsForRoot(root, subdir) {
const tree = await buildDepTreeFromFiles(
root,
subdir ? `packages/${subdir}/package.json` : 'package.json',
'yarn.lock',
true,
false
)

function flattenAndAddDeps(node) {
let entry = allDepVersions.get(node.name)
if (!entry) {
entry = new Set()
allDepVersions.set(node.name, entry)
}

if (!entry.has(node.version)) {
entry.add(node.version)

if (node.dependencies) {
for (const obj of Object.values(node.dependencies)) {
flattenAndAddDeps(obj)
}
}
}
}

flattenAndAddDeps(tree)
}

await addDepsForRoot('.')
for (const dirname of await fs.readdir(new URL('../packages', import.meta.url))) {
await addDepsForRoot('.', dirname)
}

const allowPackages = []
for (const [name, versions] of allDepVersions) {
if (name.startsWith('@img/sharp') || name === '@loupedeck/web-demo') {
for (const version of versions) {
allowPackages.push(`${name}@${version}`)
}
}
}

cp.exec(`yarn sofie-licensecheck --allowPackages "${allowPackages.join(';')}"`, (error, stdout, stderr) => {
if (error) {
console.error(`error: ${error.message}`)
return
}

if (stderr) {
console.error(stderr)
return
}

console.log(stdout)
})
Loading

0 comments on commit edac6ae

Please sign in to comment.