Skip to content

Commit

Permalink
fix: bugfix (#367)
Browse files Browse the repository at this point in the history
  • Loading branch information
ybiquitous committed Apr 5, 2021
1 parent 46f8a79 commit 35cc9be
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
15 changes: 11 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2104,7 +2104,7 @@ module.exports = async function updateNpm(version) {
await exec("sudo", ["npm", ...npmArgs("install", "--global", `npm@${version}`)]);

let actualVersion = "";
exec("npm", ["--version"], {
await exec("npm", ["--version"], {
listeners: {
stdout: (data) => {
actualVersion += data.toString();
Expand Down Expand Up @@ -4065,14 +4065,21 @@ module.exports = async function listPackages() {
const packages = /** @type {Map<string, string>} */ new Map();
lines
.split("\n")
.filter(Boolean)
.filter((line) => line.trim())
.forEach((line) => {
const [, pkg] = line.split(":");
const [, pkg] = line.split(":", 2);
if (pkg == null) {
throw new Error(`Invalid line: "${line}"`);
}

const [name, version] = pkg.split("@");
const match = /^(?<name>@?\S+)@(?<version>\S+)$/u.exec(pkg);
if (match == null || match.groups == null) {
throw new Error(`Invalid line: "${line}"`);
}
/* eslint-disable dot-notation, prefer-destructuring -- Prevent TS4111 */
const name = match.groups["name"];
const version = match.groups["version"];
/* eslint-enable */
if (name == null || version == null) {
throw new Error(`Invalid name and version: "${line}"`);
}
Expand Down
1 change: 1 addition & 0 deletions lib/__tests__/listPackages.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ test("listPackages()", async () => {
const packages = await listPackages();
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);
});
13 changes: 10 additions & 3 deletions lib/listPackages.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,21 @@ module.exports = async function listPackages() {
const packages = /** @type {Map<string, string>} */ new Map();
lines
.split("\n")
.filter(Boolean)
.filter((line) => line.trim())
.forEach((line) => {
const [, pkg] = line.split(":");
const [, pkg] = line.split(":", 2);
if (pkg == null) {
throw new Error(`Invalid line: "${line}"`);
}

const [name, version] = pkg.split("@");
const match = /^(?<name>@?\S+)@(?<version>\S+)$/u.exec(pkg);
if (match == null || match.groups == null) {
throw new Error(`Invalid line: "${line}"`);
}
/* eslint-disable dot-notation, prefer-destructuring -- Prevent TS4111 */
const name = match.groups["name"];
const version = match.groups["version"];
/* eslint-enable */
if (name == null || version == null) {
throw new Error(`Invalid name and version: "${line}"`);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/updateNpm.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = async function updateNpm(version) {
await exec("sudo", ["npm", ...npmArgs("install", "--global", `npm@${version}`)]);

let actualVersion = "";
exec("npm", ["--version"], {
await exec("npm", ["--version"], {
listeners: {
stdout: (data) => {
actualVersion += data.toString();
Expand Down

0 comments on commit 35cc9be

Please sign in to comment.