From 7637a809f625cbcf81c1d1e9bf4c9193008aa614 Mon Sep 17 00:00:00 2001 From: Timon Jurschitsch <103483059+DerTimonius@users.noreply.github.com> Date: Tue, 15 Nov 2022 19:36:42 +0100 Subject: [PATCH 01/13] Update 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 7e70c3c9..c46d3b5e 100644 --- a/source/npm/util.js +++ b/source/npm/util.js @@ -68,7 +68,7 @@ exports.collaborators = async pkg => { const packageName = pkg.name; ow(packageName, ow.string); - const args = ['access', 'ls-collaborators', packageName]; + const args = ['access', 'list collaborators', packageName]; if (exports.isExternalRegistry(pkg)) { args.push('--registry', pkg.publishConfig.registry); } From 5102bdbc7141789e079d4384497f74b48234445c Mon Sep 17 00:00:00 2001 From: Timon Jurschitsch <103483059+DerTimonius@users.noreply.github.com> Date: Tue, 15 Nov 2022 22:26:32 +0100 Subject: [PATCH 02/13] Fix npm access error --- source/npm/util.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/npm/util.js b/source/npm/util.js index c46d3b5e..35e6a581 100644 --- a/source/npm/util.js +++ b/source/npm/util.js @@ -68,13 +68,13 @@ exports.collaborators = async pkg => { const packageName = pkg.name; ow(packageName, ow.string); - const args = ['access', 'list collaborators', packageName]; + const args = [packageName]; if (exports.isExternalRegistry(pkg)) { args.push('--registry', pkg.publishConfig.registry); } try { - const {stdout} = await execa('npm', args); + const {stdout} = await execa('npm access list collaborators', args); return stdout; } catch (error) { // Ignore non-existing package error From 2b4cf8beef137dd56536c353509e3fbc95b7c4e4 Mon Sep 17 00:00:00 2001 From: Timon Jurschitsch Date: Wed, 16 Nov 2022 18:51:27 +0100 Subject: [PATCH 03/13] Fix npm access subcommands in tests --- source/npm/util.js | 2 +- test/prerequisite-tasks.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/source/npm/util.js b/source/npm/util.js index 7e70c3c9..4877953a 100644 --- a/source/npm/util.js +++ b/source/npm/util.js @@ -68,7 +68,7 @@ exports.collaborators = async pkg => { const packageName = pkg.name; ow(packageName, ow.string); - const args = ['access', 'ls-collaborators', packageName]; + const args = ['access', 'list', 'collaborators', packageName]; if (exports.isExternalRegistry(pkg)) { args.push('--registry', pkg.publishConfig.registry); } diff --git a/test/prerequisite-tasks.js b/test/prerequisite-tasks.js index 7c42f8ee..f68bafe9 100644 --- a/test/prerequisite-tasks.js +++ b/test/prerequisite-tasks.js @@ -109,7 +109,7 @@ test.serial('should fail when user is not authenticated at npm registry', async stdout: 'sindresorhus' }, { - command: 'npm access ls-collaborators test', + command: 'npm access list collaborators test', exitCode: 0, stdout: '{"sindresorhus": "read"}' } @@ -129,7 +129,7 @@ test.serial('should fail when user is not authenticated at external registry', a stdout: 'sindresorhus' }, { - command: 'npm access ls-collaborators test --registry http://my.io', + command: 'npm access list collaborators test --registry http://my.io', exitCode: 0, stdout: '{"sindresorhus": "read"}' } From 9853c16683bcdf6c6118cd35bf496cca78e62fb7 Mon Sep 17 00:00:00 2001 From: Timon Jurschitsch <103483059+DerTimonius@users.noreply.github.com> Date: Wed, 16 Nov 2022 19:34:47 +0100 Subject: [PATCH 04/13] Update prerequisite-tasks.js --- test/prerequisite-tasks.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/prerequisite-tasks.js b/test/prerequisite-tasks.js index 7c42f8ee..f68bafe9 100644 --- a/test/prerequisite-tasks.js +++ b/test/prerequisite-tasks.js @@ -109,7 +109,7 @@ test.serial('should fail when user is not authenticated at npm registry', async stdout: 'sindresorhus' }, { - command: 'npm access ls-collaborators test', + command: 'npm access list collaborators test', exitCode: 0, stdout: '{"sindresorhus": "read"}' } @@ -129,7 +129,7 @@ test.serial('should fail when user is not authenticated at external registry', a stdout: 'sindresorhus' }, { - command: 'npm access ls-collaborators test --registry http://my.io', + command: 'npm access list collaborators test --registry http://my.io', exitCode: 0, stdout: '{"sindresorhus": "read"}' } From 12232214c5bba31dd8879b0ecdf1522270c4af72 Mon Sep 17 00:00:00 2001 From: Timon Jurschitsch <103483059+DerTimonius@users.noreply.github.com> Date: Wed, 16 Nov 2022 19:36:10 +0100 Subject: [PATCH 05/13] Fix npm access subcommands --- source/npm/util.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/npm/util.js b/source/npm/util.js index 35e6a581..4877953a 100644 --- a/source/npm/util.js +++ b/source/npm/util.js @@ -68,13 +68,13 @@ exports.collaborators = async pkg => { const packageName = pkg.name; ow(packageName, ow.string); - const args = [packageName]; + const args = ['access', 'list', 'collaborators', packageName]; if (exports.isExternalRegistry(pkg)) { args.push('--registry', pkg.publishConfig.registry); } try { - const {stdout} = await execa('npm access list collaborators', args); + const {stdout} = await execa('npm', args); return stdout; } catch (error) { // Ignore non-existing package error From 14e7788c58534ccf365ea5f8515dc0f9c9c5cd4f Mon Sep 17 00:00:00 2001 From: Timon Jurschitsch <103483059+DerTimonius@users.noreply.github.com> Date: Fri, 18 Nov 2022 22:20:36 +0100 Subject: [PATCH 06/13] Add "--json" flag --- 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 4877953a..4b0a82aa 100644 --- a/source/npm/util.js +++ b/source/npm/util.js @@ -68,7 +68,7 @@ exports.collaborators = async pkg => { const packageName = pkg.name; ow(packageName, ow.string); - const args = ['access', 'list', 'collaborators', packageName]; + const args = ['access', 'list', 'collaborators', '--json', packageName]; if (exports.isExternalRegistry(pkg)) { args.push('--registry', pkg.publishConfig.registry); } From e0f2564f1edd73fddb137be4791a054c233c4057 Mon Sep 17 00:00:00 2001 From: Timon Jurschitsch Date: Mon, 21 Nov 2022 09:18:42 +0100 Subject: [PATCH 07/13] Add --json flag to tests --- test/prerequisite-tasks.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/prerequisite-tasks.js b/test/prerequisite-tasks.js index f68bafe9..511cd580 100644 --- a/test/prerequisite-tasks.js +++ b/test/prerequisite-tasks.js @@ -109,7 +109,7 @@ test.serial('should fail when user is not authenticated at npm registry', async stdout: 'sindresorhus' }, { - command: 'npm access list collaborators test', + command: 'npm access list collaborators test --json', exitCode: 0, stdout: '{"sindresorhus": "read"}' } @@ -129,7 +129,7 @@ test.serial('should fail when user is not authenticated at external registry', a stdout: 'sindresorhus' }, { - command: 'npm access list collaborators test --registry http://my.io', + command: 'npm access list collaborators test --registry http://my.io --json', exitCode: 0, stdout: '{"sindresorhus": "read"}' } From abfeed0e5577e15b3a5422406d6365deb01e7c94 Mon Sep 17 00:00:00 2001 From: Timon Jurschitsch <103483059+DerTimonius@users.noreply.github.com> Date: Mon, 21 Nov 2022 10:32:24 +0100 Subject: [PATCH 08/13] Add --json flag to tests --- test/prerequisite-tasks.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/prerequisite-tasks.js b/test/prerequisite-tasks.js index f68bafe9..511cd580 100644 --- a/test/prerequisite-tasks.js +++ b/test/prerequisite-tasks.js @@ -109,7 +109,7 @@ test.serial('should fail when user is not authenticated at npm registry', async stdout: 'sindresorhus' }, { - command: 'npm access list collaborators test', + command: 'npm access list collaborators test --json', exitCode: 0, stdout: '{"sindresorhus": "read"}' } @@ -129,7 +129,7 @@ test.serial('should fail when user is not authenticated at external registry', a stdout: 'sindresorhus' }, { - command: 'npm access list collaborators test --registry http://my.io', + command: 'npm access list collaborators test --registry http://my.io --json', exitCode: 0, stdout: '{"sindresorhus": "read"}' } From 888bc2ce50ac7d3c90942f3988ea93df573f1b5d Mon Sep 17 00:00:00 2001 From: Timon Jurschitsch Date: Wed, 23 Nov 2022 18:24:51 +0100 Subject: [PATCH 09/13] Add checks for npm version --- source/npm/util.js | 3 ++- test/prerequisite-tasks.js | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/source/npm/util.js b/source/npm/util.js index 4b0a82aa..dd961ac7 100644 --- a/source/npm/util.js +++ b/source/npm/util.js @@ -68,7 +68,8 @@ exports.collaborators = async pkg => { const packageName = pkg.name; ow(packageName, ow.string); - const args = ['access', 'list', 'collaborators', '--json', packageName]; + const npmVersion = await exports.version(); + const args = npmVersion >= '9.0.0' ? ['access', 'list', 'collaborators', '--json', packageName] : ['access', 'ls-collaborators', '--json', packageName]; if (exports.isExternalRegistry(pkg)) { args.push('--registry', pkg.publishConfig.registry); } diff --git a/test/prerequisite-tasks.js b/test/prerequisite-tasks.js index 511cd580..06bffd8e 100644 --- a/test/prerequisite-tasks.js +++ b/test/prerequisite-tasks.js @@ -3,9 +3,12 @@ import execaStub from 'execa_test_double'; import mockery from 'mockery'; import version from '../source/version'; import {SilentRenderer} from './fixtures/listr-renderer'; +import {version as versionNpm} from '../source/npm/util'; let testedModule; +const npmVersion = versionNpm(); + const run = async listr => { listr.setRenderer(SilentRenderer); await listr.run(); @@ -101,6 +104,7 @@ test.serial('should fail when yarn version does not match range in `package.json t.true(SilentRenderer.tasks.some(task => task.title === 'Check yarn version' && task.hasFailed())); }); +const testArgs = npmVersion >= '9.0.0' ? 'list collaborators' : 'ls-collaborators'; test.serial('should fail when user is not authenticated at npm registry', async t => { execaStub.createStub([ { @@ -109,7 +113,7 @@ test.serial('should fail when user is not authenticated at npm registry', async stdout: 'sindresorhus' }, { - command: 'npm access list collaborators test --json', + command: `npm access ${testArgs} test --json`, exitCode: 0, stdout: '{"sindresorhus": "read"}' } @@ -129,7 +133,7 @@ test.serial('should fail when user is not authenticated at external registry', a stdout: 'sindresorhus' }, { - command: 'npm access list collaborators test --registry http://my.io --json', + command: `npm access ${testArgs} test --registry http://my.io --json`, exitCode: 0, stdout: '{"sindresorhus": "read"}' } From 0744f218e99ff74020ed9f97634b78a5d21c96bb Mon Sep 17 00:00:00 2001 From: Timon Jurschitsch Date: Wed, 23 Nov 2022 21:30:14 +0100 Subject: [PATCH 10/13] Change npm version check to semver --- source/npm/util.js | 3 ++- test/prerequisite-tasks.js | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/source/npm/util.js b/source/npm/util.js index dd961ac7..ba020d0b 100644 --- a/source/npm/util.js +++ b/source/npm/util.js @@ -10,6 +10,7 @@ const pkgDir = require('pkg-dir'); const ignoreWalker = require('ignore-walk'); const minimatch = require('minimatch'); const {verifyRequirementSatisfied} = require('../version'); +const semver = require('semver'); // According to https://docs.npmjs.com/files/package.json#files // npm's default behavior is to ignore these files. @@ -69,7 +70,7 @@ exports.collaborators = async pkg => { ow(packageName, ow.string); const npmVersion = await exports.version(); - const args = npmVersion >= '9.0.0' ? ['access', 'list', 'collaborators', '--json', packageName] : ['access', 'ls-collaborators', '--json', packageName]; + const args = semver.satisfies(npmVersion, '>=9.0.0') ? ['access', 'list', 'collaborators', '--json', packageName] : ['access', 'ls-collaborators', '--json', packageName]; if (exports.isExternalRegistry(pkg)) { args.push('--registry', pkg.publishConfig.registry); } diff --git a/test/prerequisite-tasks.js b/test/prerequisite-tasks.js index 06bffd8e..6173e863 100644 --- a/test/prerequisite-tasks.js +++ b/test/prerequisite-tasks.js @@ -4,10 +4,14 @@ import mockery from 'mockery'; import version from '../source/version'; import {SilentRenderer} from './fixtures/listr-renderer'; import {version as versionNpm} from '../source/npm/util'; +import semver from 'semver'; let testedModule; -const npmVersion = versionNpm(); +const testArgs = async () => { + const npmVersion = await versionNpm(); + return semver.satisfies(npmVersion, '>=9.0.0') ? 'list collaborators' : 'ls-collaborators'; +}; const run = async listr => { listr.setRenderer(SilentRenderer); @@ -104,7 +108,6 @@ test.serial('should fail when yarn version does not match range in `package.json t.true(SilentRenderer.tasks.some(task => task.title === 'Check yarn version' && task.hasFailed())); }); -const testArgs = npmVersion >= '9.0.0' ? 'list collaborators' : 'ls-collaborators'; test.serial('should fail when user is not authenticated at npm registry', async t => { execaStub.createStub([ { From 7ab1b63cc9c6b734545cf27e361e11afd60d48ec Mon Sep 17 00:00:00 2001 From: Timon Jurschitsch Date: Fri, 25 Nov 2022 08:45:34 +0100 Subject: [PATCH 11/13] Remove --json flag on older npm versions --- source/npm/util.js | 2 +- test/prerequisite-tasks.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/source/npm/util.js b/source/npm/util.js index ba020d0b..2d27569e 100644 --- a/source/npm/util.js +++ b/source/npm/util.js @@ -70,7 +70,7 @@ exports.collaborators = async pkg => { ow(packageName, ow.string); const npmVersion = await exports.version(); - const args = semver.satisfies(npmVersion, '>=9.0.0') ? ['access', 'list', 'collaborators', '--json', packageName] : ['access', 'ls-collaborators', '--json', packageName]; + const args = semver.satisfies(npmVersion, '>=9.0.0') ? ['access', 'list', 'collaborators', '--json', packageName] : ['access', 'ls-collaborators', packageName]; if (exports.isExternalRegistry(pkg)) { args.push('--registry', pkg.publishConfig.registry); } diff --git a/test/prerequisite-tasks.js b/test/prerequisite-tasks.js index 6173e863..a62cc7cc 100644 --- a/test/prerequisite-tasks.js +++ b/test/prerequisite-tasks.js @@ -10,7 +10,7 @@ let testedModule; const testArgs = async () => { const npmVersion = await versionNpm(); - return semver.satisfies(npmVersion, '>=9.0.0') ? 'list collaborators' : 'ls-collaborators'; + return semver.satisfies(npmVersion, '>=9.0.0') ? ['list collaborators', '--json'] : ['ls-collaborators', '']; }; const run = async listr => { @@ -116,7 +116,7 @@ test.serial('should fail when user is not authenticated at npm registry', async stdout: 'sindresorhus' }, { - command: `npm access ${testArgs} test --json`, + command: `npm access ${testArgs[0]} test ${testArgs[1]}`, exitCode: 0, stdout: '{"sindresorhus": "read"}' } @@ -136,7 +136,7 @@ test.serial('should fail when user is not authenticated at external registry', a stdout: 'sindresorhus' }, { - command: `npm access ${testArgs} test --registry http://my.io --json`, + command: `npm access ${testArgs[0]} test --registry http://my.io ${testArgs[1]}`, exitCode: 0, stdout: '{"sindresorhus": "read"}' } From 6d4f03650d7c98ec2c352125eb783d64f2e00f39 Mon Sep 17 00:00:00 2001 From: Timon Jurschitsch Date: Fri, 25 Nov 2022 12:12:00 +0100 Subject: [PATCH 12/13] Move location of --json flag --- test/prerequisite-tasks.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/prerequisite-tasks.js b/test/prerequisite-tasks.js index a62cc7cc..fd49aa39 100644 --- a/test/prerequisite-tasks.js +++ b/test/prerequisite-tasks.js @@ -10,7 +10,7 @@ let testedModule; const testArgs = async () => { const npmVersion = await versionNpm(); - return semver.satisfies(npmVersion, '>=9.0.0') ? ['list collaborators', '--json'] : ['ls-collaborators', '']; + return semver.satisfies(npmVersion, '>=9.0.0') ? ['list collaborators', ' --json'] : ['ls-collaborators', '']; }; const run = async listr => { @@ -116,7 +116,7 @@ test.serial('should fail when user is not authenticated at npm registry', async stdout: 'sindresorhus' }, { - command: `npm access ${testArgs[0]} test ${testArgs[1]}`, + command: `npm access ${testArgs[0]} test${testArgs[1]}`, exitCode: 0, stdout: '{"sindresorhus": "read"}' } @@ -136,7 +136,7 @@ test.serial('should fail when user is not authenticated at external registry', a stdout: 'sindresorhus' }, { - command: `npm access ${testArgs[0]} test --registry http://my.io ${testArgs[1]}`, + command: `npm access ${testArgs[0]} test${testArgs[1]} --registry http://my.io`, exitCode: 0, stdout: '{"sindresorhus": "read"}' } From 5d2db24eeb698646ad9616eced41316f9693542d Mon Sep 17 00:00:00 2001 From: Timon Jurschitsch Date: Tue, 13 Dec 2022 16:44:56 +0100 Subject: [PATCH 13/13] Move --json flag to end of argument --- source/npm/util.js | 2 +- test/prerequisite-tasks.js | 11 ++--------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/source/npm/util.js b/source/npm/util.js index 2d27569e..2d594761 100644 --- a/source/npm/util.js +++ b/source/npm/util.js @@ -70,7 +70,7 @@ exports.collaborators = async pkg => { ow(packageName, ow.string); const npmVersion = await exports.version(); - const args = semver.satisfies(npmVersion, '>=9.0.0') ? ['access', 'list', 'collaborators', '--json', packageName] : ['access', 'ls-collaborators', packageName]; + const args = semver.satisfies(npmVersion, '>=9.0.0') ? ['access', 'list', 'collaborators', packageName, '--json'] : ['access', 'ls-collaborators', packageName]; if (exports.isExternalRegistry(pkg)) { args.push('--registry', pkg.publishConfig.registry); } diff --git a/test/prerequisite-tasks.js b/test/prerequisite-tasks.js index fd49aa39..7c42f8ee 100644 --- a/test/prerequisite-tasks.js +++ b/test/prerequisite-tasks.js @@ -3,16 +3,9 @@ import execaStub from 'execa_test_double'; import mockery from 'mockery'; import version from '../source/version'; import {SilentRenderer} from './fixtures/listr-renderer'; -import {version as versionNpm} from '../source/npm/util'; -import semver from 'semver'; let testedModule; -const testArgs = async () => { - const npmVersion = await versionNpm(); - return semver.satisfies(npmVersion, '>=9.0.0') ? ['list collaborators', ' --json'] : ['ls-collaborators', '']; -}; - const run = async listr => { listr.setRenderer(SilentRenderer); await listr.run(); @@ -116,7 +109,7 @@ test.serial('should fail when user is not authenticated at npm registry', async stdout: 'sindresorhus' }, { - command: `npm access ${testArgs[0]} test${testArgs[1]}`, + command: 'npm access ls-collaborators test', exitCode: 0, stdout: '{"sindresorhus": "read"}' } @@ -136,7 +129,7 @@ test.serial('should fail when user is not authenticated at external registry', a stdout: 'sindresorhus' }, { - command: `npm access ${testArgs[0]} test${testArgs[1]} --registry http://my.io`, + command: 'npm access ls-collaborators test --registry http://my.io', exitCode: 0, stdout: '{"sindresorhus": "read"}' }