Skip to content

Instantly share code, notes, and snippets.

@pdehaan
Created April 15, 2022 16:51
Show Gist options
  • Save pdehaan/c9e8f5b788b014bfbee92b32824df8cb to your computer and use it in GitHub Desktop.
Save pdehaan/c9e8f5b788b014bfbee92b32824df8cb to your computer and use it in GitHub Desktop.
Linting all the FxA https: dependencies
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 {};
}
}
@pdehaan
Copy link
Author

pdehaan commented Apr 15, 2022

{
  "package": "fxa-payments-server",
  "name": "jquery-modal",
  "uri": "https://github.com/mozilla-fxa/jquery-modal.git#0576775d1b4590314b114386019f4c7421c77503",
  "github": {
    "author": "Shane Tomlinson",
    "version": "0.7.1",
    "date": "2016-09-05T10:35:02Z"
  },
  "npm": {
    "version": "0.9.2",
    "date": "2019-02-25T02:45:28.660Z"
  }
}

{
  "package": "fxa-shared",
  "name": "node-uap",
  "uri": "https://github.com/mozilla-fxa/node-uap.git#96dc1f9f224422ec184395b6408cd1fc40ee452a",
  "github": {
    "author": "Danny Coates",
    "version": "0.0.3",
    "date": "2020-04-21T17:27:10Z"
  },
  "npm": {
    "version": "0.0.3",
    "date": "2016-02-16T10:54:32.285Z"
  }
}

[legal-docs] Request failed with status code 404
{
  "package": "fxa-content-server",
  "name": "legal-docs",
  "uri": "https://github.com/mozilla/legal-docs.git#569f5c812ef288c4ebf19b8d521ba90b99e99cfc",
  "github": {
    "author": "Peiying",
    "version": "1.0.0",
    "date": "2021-05-06T22:31:47Z"
  },
  "npm": {}
}

{
  "package": "fxa-content-server",
  "name": "chosen-js",
  "uri": "https://github.com/mozilla-fxa/chosen.git#3bea55b356c249ae82980c04f67ccc98ff3b28b0",
  "github": {
    "author": "Danny Coates",
    "version": "1.8.7",
    "date": "2020-05-14T21:27:22Z"
  },
  "npm": {
    "version": "1.8.7",
    "date": "2018-06-29T19:16:34.944Z"
  }
}

{
  "package": "fxa-content-server",
  "name": "jquery-modal",
  "uri": "https://github.com/mozilla-fxa/jquery-modal.git#0576775d1b4590314b114386019f4c7421c77503",
  "github": {
    "author": "Shane Tomlinson",
    "version": "0.7.1",
    "date": "2016-09-05T10:35:02Z"
  },
  "npm": {
    "version": "0.9.2",
    "date": "2019-02-25T02:45:28.660Z"
  }
}

{
  "package": "fxa-content-server",
  "name": "xmlhttprequest",
  "uri": "https://github.com/mozilla-fxa/node-XMLHttpRequest.git#onerror",
  "github": {
    "author": "Zachary Carter",
    "version": "1.5.1",
    "date": "2013-11-07T02:06:07Z"
  },
  "npm": {
    "version": "1.8.0",
    "date": "2015-10-11T20:15:32.925Z"
  }
}

{
  "package": "fxa-content-server",
  "name": "webcrypto-liner",
  "uri": "https://github.com/mozilla-fxa/webcrypto-liner.git#6b3ad971b3b1f0d4da3855c6ceee9b3afa9f0eeb",
  "github": {
    "author": "Danny Coates",
    "version": "0.1.36",
    "date": "2020-05-15T03:52:43Z"
  },
  "npm": {
    "version": "1.3.1",
    "date": "2021-12-09T16:13:27.394Z"
  }
}

{
  "package": "fxa-auth-server",
  "name": "node-uap",
  "uri": "https://github.com/mozilla-fxa/node-uap.git#96dc1f9f224422ec184395b6408cd1fc40ee452a",
  "github": {
    "author": "Danny Coates",
    "version": "0.0.3",
    "date": "2020-04-21T17:27:10Z"
  },
  "npm": {
    "version": "0.0.3",
    "date": "2016-02-16T10:54:32.285Z"
  }
}

{
  "package": "fxa-content-server",
  "name": "grunt-po2json",
  "uri": "https://github.com/mozilla-fxa/grunt-po2json.git#2f415c8ac0435bf8942dc7131c3916ecd1684a46",
  "github": {
    "author": "vladikoff",
    "version": "0.2.0",
    "date": "2016-04-12T22:34:42Z"
  },
  "npm": {
    "version": "0.3.0",
    "date": "2015-02-23T15:47:07.380Z"
  }
}

{
  "package": "fxa-auth-client",
  "name": "webcrypto-liner",
  "uri": "https://github.com/mozilla-fxa/webcrypto-liner.git#6b3ad971b3b1f0d4da3855c6ceee9b3afa9f0eeb",
  "github": {
    "author": "Danny Coates",
    "version": "0.1.36",
    "date": "2020-05-15T03:52:43Z"
  },
  "npm": {
    "version": "1.3.1",
    "date": "2021-12-09T16:13:27.394Z"
  }
}

{
  "package": "fxa-content-server",
  "name": "ua-parser-js",
  "uri": "https://github.com/mozilla-fxa/ua-parser-js.git#fxa-version",
  "github": {
    "author": "Vlad Filippov",
    "version": "0.7.10",
    "date": "2016-11-04T18:28:11Z"
  },
  "npm": {
    "version": "1.0.2",
    "date": "2021-10-27T10:24:04.532Z"
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment