Created
April 15, 2022 16:51
-
-
Save pdehaan/c9e8f5b788b014bfbee92b32824df8cb to your computer and use it in GitHub Desktop.
Linting all the FxA https: dependencies
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const axios = require("axios"); | |
const glob = require("fast-glob"); | |
const parse = require("parse-github-repo-url"); | |
glob("./packages/*/package.json").then(files => { | |
for (const file of files) { | |
const pkg = require(file); | |
const allDeps = Object.assign({}, pkg.dependencies, pkg.devDependencies); | |
const httpDeps = Object.entries(allDeps) | |
.filter(([name, version]) => version.startsWith("https://")); | |
new Map(httpDeps).forEach(async (version, name) => { | |
const res = parse(version); | |
const {commit} = await fetchCommit(...res); | |
const pkgJson = await fetchPackageJson(...res); | |
const npmMeta = await fetchNpmPackage(name); | |
let npm; | |
if (npmMeta) { | |
npm = { | |
version: npmMeta.version, | |
date: npmMeta.date, | |
}; | |
} | |
console.log(JSON.stringify({ | |
package: pkg.name, | |
name, | |
uri: version, | |
github: { | |
author: commit.author.name, | |
version: pkgJson.version, | |
date: commit.author.date, | |
}, | |
npm, | |
}, null, 2)); | |
}); | |
} | |
}); | |
async function fetchCommit(org, repo, sha) { | |
const headers = { | |
Authorization: `token ${process.env.GITHUB_TOKEN}` | |
}; | |
const {data} = await axios.get(`https://api.github.com/repos/${org}/${repo}/commits/${sha}?per_page=1`, {headers}); | |
return data; | |
} | |
async function fetchPackageJson(org, repo, sha) { | |
const {data} = await axios.get(`https://raw.githubusercontent.com/${org}/${repo}/${sha}/package.json`); | |
return data; | |
} | |
async function fetchNpmPackage(name) { | |
try { | |
const {data} = await axios.get(`https://api.npms.io/v2/package/${name}`); | |
return data.collected.metadata; | |
} catch (err) { | |
console.error(`[${name}] ${err.message}`); | |
return {}; | |
} | |
} |
Author
pdehaan
commented
Apr 15, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment