Skip to content

Commit

Permalink
fix(log): pass in logger to more external modules
Browse files Browse the repository at this point in the history
We missed two commands in the last PR. This should complete the task
  • Loading branch information
wraithgar committed Feb 8, 2022
1 parent b836d59 commit fb6e2dd
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 29 deletions.
6 changes: 5 additions & 1 deletion lib/commands/org.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const liborg = require('libnpmorg')
const otplease = require('../utils/otplease.js')
const Table = require('cli-table3')
const BaseCommand = require('../base-command.js')
const log = require('../utils/log-shim.js')

class Org extends BaseCommand {
static description = 'Manage orgs'
Expand Down Expand Up @@ -32,7 +33,10 @@ class Org extends BaseCommand {
}

async exec ([cmd, orgname, username, role], cb) {
return otplease(this.npm.flatOptions, opts => {
return otplease({
...this.npm.flatOptions,
log,
}, opts => {
switch (cmd) {
case 'add':
case 'set':
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/unpublish.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class Unpublish extends BaseCommand {
)
}

const opts = this.npm.flatOptions
const opts = { ...this.npm.flatOptions, log }
if (!spec || path.resolve(spec.name) === this.npm.localPrefix) {
// if there's a package.json in the current folder, then
// read the package name and version out of that.
Expand Down
63 changes: 42 additions & 21 deletions test/lib/commands/org.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ t.test('npm org add', async t => {

await org.exec(['add', 'orgname', 'username'])

t.strictSame(
t.ok(orgSetArgs.opts.log, 'got passed a logger')
t.match(
orgSetArgs,
{
org: 'orgname',
Expand Down Expand Up @@ -148,7 +149,8 @@ t.test('npm org add - more users', async t => {
})

await org.exec(['add', 'orgname', 'username'])
t.strictSame(
t.ok(orgSetArgs.opts.log, 'got passed a logger')
t.match(
orgSetArgs,
{
org: 'orgname',
Expand All @@ -175,7 +177,8 @@ t.test('npm org add - json output', async t => {

await org.exec(['add', 'orgname', 'username'])

t.strictSame(
t.ok(orgSetArgs.opts.log, 'got passed a logger')
t.match(
orgSetArgs,
{
org: 'orgname',
Expand Down Expand Up @@ -209,7 +212,8 @@ t.test('npm org add - parseable output', async t => {

await org.exec(['add', 'orgname', 'username'])

t.strictSame(
t.ok(orgSetArgs.opts.log, 'got passed a logger')
t.match(
orgSetArgs,
{
org: 'orgname',
Expand Down Expand Up @@ -239,7 +243,8 @@ t.test('npm org add - silent output', async t => {

await org.exec(['add', 'orgname', 'username'])

t.strictSame(
t.ok(orgSetArgs.opts.log, 'got passed a logger')
t.match(
orgSetArgs,
{
org: 'orgname',
Expand All @@ -261,7 +266,8 @@ t.test('npm org rm', async t => {

await org.exec(['rm', 'orgname', 'username'])

t.strictSame(
t.ok(orgRmArgs.opts.log, 'got passed a logger')
t.match(
orgRmArgs,
{
org: 'orgname',
Expand All @@ -270,7 +276,8 @@ t.test('npm org rm', async t => {
},
'libnpmorg.rm received the correct args'
)
t.strictSame(
t.ok(orgLsArgs.opts.log, 'got passed a logger')
t.match(
orgLsArgs,
{
org: 'orgname',
Expand Down Expand Up @@ -323,7 +330,8 @@ t.test('npm org rm - one user left', async t => {

await org.exec(['rm', 'orgname', 'username'])

t.strictSame(
t.ok(orgRmArgs.opts.log, 'got passed a logger')
t.match(
orgRmArgs,
{
org: 'orgname',
Expand All @@ -332,7 +340,8 @@ t.test('npm org rm - one user left', async t => {
},
'libnpmorg.rm received the correct args'
)
t.strictSame(
t.ok(orgLsArgs.opts.log, 'got passed a logger')
t.match(
orgLsArgs,
{
org: 'orgname',
Expand All @@ -358,7 +367,8 @@ t.test('npm org rm - json output', async t => {

await org.exec(['rm', 'orgname', 'username'])

t.strictSame(
t.ok(orgRmArgs.opts.log, 'got passed a logger')
t.match(
orgRmArgs,
{
org: 'orgname',
Expand All @@ -367,7 +377,8 @@ t.test('npm org rm - json output', async t => {
},
'libnpmorg.rm received the correct args'
)
t.strictSame(
t.ok(orgLsArgs.opts.log, 'got passed a logger')
t.match(
orgLsArgs,
{
org: 'orgname',
Expand Down Expand Up @@ -398,7 +409,8 @@ t.test('npm org rm - parseable output', async t => {

await org.exec(['rm', 'orgname', 'username'])

t.strictSame(
t.ok(orgRmArgs.opts.log, 'got passed a logger')
t.match(
orgRmArgs,
{
org: 'orgname',
Expand All @@ -407,7 +419,8 @@ t.test('npm org rm - parseable output', async t => {
},
'libnpmorg.rm received the correct args'
)
t.strictSame(
t.ok(orgLsArgs.opts.log, 'got passed a logger')
t.match(
orgLsArgs,
{
org: 'orgname',
Expand Down Expand Up @@ -436,7 +449,8 @@ t.test('npm org rm - silent output', async t => {

await org.exec(['rm', 'orgname', 'username'])

t.strictSame(
t.ok(orgRmArgs.opts.log, 'got passed a logger')
t.match(
orgRmArgs,
{
org: 'orgname',
Expand All @@ -445,7 +459,8 @@ t.test('npm org rm - silent output', async t => {
},
'libnpmorg.rm received the correct args'
)
t.strictSame(
t.ok(orgLsArgs.opts.log, 'got passed a logger')
t.match(
orgLsArgs,
{
org: 'orgname',
Expand All @@ -470,7 +485,8 @@ t.test('npm org ls', async t => {

await org.exec(['ls', 'orgname'])

t.strictSame(
t.ok(orgLsArgs.opts.log, 'got passed a logger')
t.match(
orgLsArgs,
{
org: 'orgname',
Expand All @@ -497,7 +513,8 @@ t.test('npm org ls - user filter', async t => {

await org.exec(['ls', 'orgname', 'username'])

t.strictSame(
t.ok(orgLsArgs.opts.log, 'got passed a logger')
t.match(
orgLsArgs,
{
org: 'orgname',
Expand All @@ -522,7 +539,8 @@ t.test('npm org ls - user filter, missing user', async t => {

await org.exec(['ls', 'orgname', 'username'])

t.strictSame(
t.ok(orgLsArgs.opts.log, 'got passed a logger')
t.match(
orgLsArgs,
{
org: 'orgname',
Expand Down Expand Up @@ -560,7 +578,8 @@ t.test('npm org ls - json output', async t => {

await org.exec(['ls', 'orgname'])

t.strictSame(
t.ok(orgLsArgs.opts.log, 'got passed a logger')
t.match(
orgLsArgs,
{
org: 'orgname',
Expand All @@ -587,7 +606,8 @@ t.test('npm org ls - parseable output', async t => {

await org.exec(['ls', 'orgname'])

t.strictSame(
t.ok(orgLsArgs.opts.log, 'got passed a logger')
t.match(
orgLsArgs,
{
org: 'orgname',
Expand Down Expand Up @@ -623,7 +643,8 @@ t.test('npm org ls - silent output', async t => {

await org.exec(['ls', 'orgname'])

t.strictSame(
t.ok(orgLsArgs.opts.log, 'got passed a logger')
t.match(
orgLsArgs,
{
org: 'orgname',
Expand Down
9 changes: 3 additions & 6 deletions test/lib/commands/unpublish.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ t.test('no args --force', async t => {

const libnpmpublish = {
unpublish (spec, opts) {
t.ok(opts.log, 'gets passed a logger')
t.equal(spec.raw, 'pkg@1.0.0', 'should unpublish expected spec')
t.same(
t.match(
opts,
{
publishConfig: undefined,
Expand Down Expand Up @@ -177,12 +178,8 @@ t.test('unpublish <pkg>@version', async t => {

const libnpmpublish = {
unpublish (spec, opts) {
t.ok(opts.log, 'gets passed a logger')
t.equal(spec.raw, 'pkg@1.0.0', 'should unpublish expected parsed spec')
t.same(
opts,
{},
'should unpublish with expected opts'
)
},
}

Expand Down

0 comments on commit fb6e2dd

Please sign in to comment.