From ac2ae7251def3ea06edb13cc4255fd9a9b0a8830 Mon Sep 17 00:00:00 2001 From: James Jensen Date: Sat, 19 Jan 2019 10:03:48 +0800 Subject: [PATCH 1/7] Fix #179 --- source/npm-util.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/source/npm-util.js b/source/npm-util.js index 34cb59af..56e94189 100644 --- a/source/npm-util.js +++ b/source/npm-util.js @@ -44,10 +44,14 @@ exports.collaborators = async packageName => { exports.prereleaseTags = async packageName => { ow(packageName, ow.string); - const stdout = await execa.stdout('npm', ['view', '--json', packageName, 'dist-tags']); - - const tags = Object.keys(JSON.parse(stdout)) - .filter(tag => tag !== 'latest'); + let tags; + try { + const stdout = await execa.stdout('npm', ['view', '--json', packageName, 'dist-tags']) || {}; + tags = Object.keys(JSON.parse(stdout)) + .filter(tag => tag !== 'latest'); + } catch (_) { + tags = {}; + } if (tags.length === 0) { tags.push('next'); From a4080605e1e1d513d6527ae82505600d3f364ba9 Mon Sep 17 00:00:00 2001 From: James Jensen Date: Sat, 19 Jan 2019 10:10:54 +0800 Subject: [PATCH 2/7] Update npm-util.js --- source/npm-util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/npm-util.js b/source/npm-util.js index 56e94189..88078f0b 100644 --- a/source/npm-util.js +++ b/source/npm-util.js @@ -50,7 +50,7 @@ exports.prereleaseTags = async packageName => { tags = Object.keys(JSON.parse(stdout)) .filter(tag => tag !== 'latest'); } catch (_) { - tags = {}; + tags = []; } if (tags.length === 0) { From 6739c093822043acc1dcd159f96233e092295d1a Mon Sep 17 00:00:00 2001 From: James Jensen Date: Sat, 19 Jan 2019 11:40:14 +0800 Subject: [PATCH 3/7] Check for error "...is not in the npm registry..." --- source/npm-util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/npm-util.js b/source/npm-util.js index b4acdea5..fe747740 100644 --- a/source/npm-util.js +++ b/source/npm-util.js @@ -50,7 +50,7 @@ exports.prereleaseTags = async packageName => { tags = Object.keys(JSON.parse(stdout)) .filter(tag => tag !== 'latest'); } catch (error) { - if (error.code === 'E404') { + if (/is not in the npm registry\./.test(error.details) { tags = []; } else { throw error; From 8a87eaaed9da1cc03907bc64fa9ab50a597984dc Mon Sep 17 00:00:00 2001 From: James Jensen Date: Sat, 19 Jan 2019 11:43:09 +0800 Subject: [PATCH 4/7] Fix stupid mistake --- source/npm-util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/npm-util.js b/source/npm-util.js index fe747740..b3277cd0 100644 --- a/source/npm-util.js +++ b/source/npm-util.js @@ -50,7 +50,7 @@ exports.prereleaseTags = async packageName => { tags = Object.keys(JSON.parse(stdout)) .filter(tag => tag !== 'latest'); } catch (error) { - if (/is not in the npm registry\./.test(error.details) { + if (/is not in the npm registry\./.test(JSON.parse(error.stdout).detail)) { tags = []; } else { throw error; From db3444cfb908b429239644474d687f0b298d35a3 Mon Sep 17 00:00:00 2001 From: Itai Steinherz Date: Mon, 21 Jan 2019 08:11:49 +0800 Subject: [PATCH 5/7] Refactor npm-util.js Co-Authored-By: jajaperson --- source/npm-util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/npm-util.js b/source/npm-util.js index b3277cd0..13c28393 100644 --- a/source/npm-util.js +++ b/source/npm-util.js @@ -46,7 +46,7 @@ exports.prereleaseTags = async packageName => { let tags; try { - const stdout = await execa.stdout('npm', ['view', '--json', packageName, 'dist-tags']); + const {stdout} = await execa('npm', ['view', '--json', packageName, 'dist-tags']); tags = Object.keys(JSON.parse(stdout)) .filter(tag => tag !== 'latest'); } catch (error) { From f76f8a6faf7c02f2999a4755bcb7beacb8a69ca9 Mon Sep 17 00:00:00 2001 From: James Jensen Date: Tue, 22 Jan 2019 17:23:08 +0800 Subject: [PATCH 6/7] Revert back to checking for `E404` --- source/npm-util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/npm-util.js b/source/npm-util.js index 13c28393..5ab1a014 100644 --- a/source/npm-util.js +++ b/source/npm-util.js @@ -50,7 +50,7 @@ exports.prereleaseTags = async packageName => { tags = Object.keys(JSON.parse(stdout)) .filter(tag => tag !== 'latest'); } catch (error) { - if (/is not in the npm registry\./.test(JSON.parse(error.stdout).detail)) { + if (JSON.parse(error.stdout).code === 'E404') { tags = []; } else { throw error; From d90531065b2ae42a5cf664dbc6232e9589b35b97 Mon Sep 17 00:00:00 2001 From: James Jensen Date: Tue, 22 Jan 2019 17:32:33 +0800 Subject: [PATCH 7/7] Refactor as per @bfed-it --- source/npm-util.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/source/npm-util.js b/source/npm-util.js index 5ab1a014..7e2f44f5 100644 --- a/source/npm-util.js +++ b/source/npm-util.js @@ -44,15 +44,13 @@ exports.collaborators = async packageName => { exports.prereleaseTags = async packageName => { ow(packageName, ow.string); - let tags; + let tags = []; try { const {stdout} = await execa('npm', ['view', '--json', packageName, 'dist-tags']); tags = Object.keys(JSON.parse(stdout)) .filter(tag => tag !== 'latest'); } catch (error) { - if (JSON.parse(error.stdout).code === 'E404') { - tags = []; - } else { + if (JSON.parse(error.stdout).code !== 'E404') { throw error; } }