Skip to content

Commit

Permalink
fix: incorrect updated packages list (#372)
Browse files Browse the repository at this point in the history
  • Loading branch information
ybiquitous authored Apr 5, 2021
1 parent 6f268a5 commit 7c502cc
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 7 deletions.
17 changes: 14 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4052,16 +4052,27 @@ const npmArgs = __webpack_require__(510);
/**
* @returns {Promise<Map<string, string>>}
*/
module.exports = async function listPackages() {
module.exports = async function listPackages({ silent } = { silent: false }) {
let lines = "";
await exec("npm", npmArgs("ls", "--parseable", "--long"), {
let stderr = "";
const returnCode = await exec("npm", npmArgs("ls", "--parseable", "--long", "--all"), {
listeners: {
stdout: (data) => {
lines += data.toString();
},
stderr: (data) => {
stderr += data.toString();
},
},
silent,
ignoreReturnCode: true,
});

// NOTE: Ignore missing peer deps error.
if (returnCode !== 0 && !stderr.includes("npm ERR! missing:")) {
throw new Error(`"npm ls" failed`);
}

const packages = /** @type {Map<string, string>} */ new Map();
lines
.split("\n")
Expand Down Expand Up @@ -8451,7 +8462,7 @@ module.exports = async function aggregateReport(audit, beforePackages, afterPack
const updated = [];
afterPackages.forEach((version, name) => {
const previousVersion = beforePackages.get(name);
if (previousVersion != null) {
if (version !== previousVersion && previousVersion != null) {
const info = audit.get(name);
const severity = info == null ? null : capitalize(info.severity);
const title = info == null ? null : info.title;
Expand Down
2 changes: 2 additions & 0 deletions lib/__tests__/aggregateReport.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ test("aggregateReport()", async () => {
const before = new Map();
before.set("y18n", "4.0.0");
before.set("xmldom", "0.5.0");
before.set("rimraf", "3.0.2");

const after = new Map();
after.set("y18n", "4.0.1");
after.set("arrify", "2.0.1");
after.set("rimraf", "3.0.2");

const result = await aggregateReport(audit, before, after);
expect(result).toMatchSnapshot();
Expand Down
2 changes: 1 addition & 1 deletion lib/__tests__/listPackages.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const listPackages = require("../listPackages");

test("listPackages()", async () => {
const packages = await listPackages();
const packages = await listPackages({ silent: true });
expect(packages.size).not.toEqual(0);
expect(packages.get("jest")).toMatch(/^\d+\.\d+\.\d+$/u);
expect(packages.get("@actions/core")).toMatch(/^\d+\.\d+\.\d+$/u);
Expand Down
2 changes: 1 addition & 1 deletion lib/aggregateReport.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ module.exports = async function aggregateReport(audit, beforePackages, afterPack
const updated = [];
afterPackages.forEach((version, name) => {
const previousVersion = beforePackages.get(name);
if (previousVersion != null) {
if (version !== previousVersion && previousVersion != null) {
const info = audit.get(name);
const severity = info == null ? null : capitalize(info.severity);
const title = info == null ? null : info.title;
Expand Down
15 changes: 13 additions & 2 deletions lib/listPackages.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,27 @@ const npmArgs = require("./npmArgs");
/**
* @returns {Promise<Map<string, string>>}
*/
module.exports = async function listPackages() {
module.exports = async function listPackages({ silent } = { silent: false }) {
let lines = "";
await exec("npm", npmArgs("ls", "--parseable", "--long"), {
let stderr = "";
const returnCode = await exec("npm", npmArgs("ls", "--parseable", "--long", "--all"), {
listeners: {
stdout: (data) => {
lines += data.toString();
},
stderr: (data) => {
stderr += data.toString();
},
},
silent,
ignoreReturnCode: true,
});

// NOTE: Ignore missing peer deps error.
if (returnCode !== 0 && !stderr.includes("npm ERR! missing:")) {
throw new Error(`"npm ls" failed`);
}

const packages = /** @type {Map<string, string>} */ new Map();
lines
.split("\n")
Expand Down

0 comments on commit 7c502cc

Please sign in to comment.