Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support --omit options in npm outdated #1892

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/outdated.js
Expand Up @@ -130,6 +130,12 @@ async function outdated_ (tree, deps, opts) {
: edge.dev ? 'devDependencies'
: 'dependencies'

for (const omitType of opts.omit || []) {
if (node[omitType]) {
return
}
}

// deps different from prod not currently
// on disk are not included in the output
if (edge.error === 'MISSING' && type !== 'dependencies') return
Expand Down
25 changes: 25 additions & 0 deletions tap-snapshots/test-lib-outdated.js-TAP.test.js
Expand Up @@ -91,6 +91,31 @@ gamma 1.0.1 1.0.1 2.0.0 node_modules/gamma outdated-should-display-ou
theta MISSING 1.0.1 1.0.1 - outdated-should-display-outdated-deps dependencies
`

exports[`test/lib/outdated.js TAP should display outdated deps outdated --omit=dev --omit=peer > must match snapshot 1`] = `

Package Current Wanted Latest Location Depended by
alpha 1.0.0 1.0.1 1.0.1 node_modules/alpha outdated-should-display-outdated-deps
gamma 1.0.1 1.0.1 2.0.0 node_modules/gamma outdated-should-display-outdated-deps
theta MISSING 1.0.1 1.0.1 - outdated-should-display-outdated-deps
`

exports[`test/lib/outdated.js TAP should display outdated deps outdated --omit=dev > must match snapshot 1`] = `

Package Current Wanted Latest Location Depended by
alpha 1.0.0 1.0.1 1.0.1 node_modules/alpha outdated-should-display-outdated-deps
beta 1.0.0 1.0.1 1.0.1 node_modules/beta outdated-should-display-outdated-deps
gamma 1.0.1 1.0.1 2.0.0 node_modules/gamma outdated-should-display-outdated-deps
theta MISSING 1.0.1 1.0.1 - outdated-should-display-outdated-deps
`

exports[`test/lib/outdated.js TAP should display outdated deps outdated --omit=prod > must match snapshot 1`] = `

Package Current Wanted Latest Location Depended by
alpha 1.0.0 1.0.1 1.0.1 node_modules/alpha outdated-should-display-outdated-deps
beta 1.0.0 1.0.1 1.0.1 node_modules/beta outdated-should-display-outdated-deps
gamma 1.0.1 1.0.1 2.0.0 node_modules/gamma outdated-should-display-outdated-deps
`

exports[`test/lib/outdated.js TAP should display outdated deps outdated --parseable --long > must match snapshot 1`] = `

{CWD}/test/lib/outdated-should-display-outdated-deps/node_modules/alpha:alpha@1.0.1:alpha@1.0.0:alpha@1.0.1:outdated-should-display-outdated-deps:dependencies:
Expand Down
33 changes: 33 additions & 0 deletions test/lib/outdated.js
Expand Up @@ -194,6 +194,39 @@ t.test('should display outdated deps', t => {
})
})

t.test('outdated --omit=dev', t => {
outdated(testDir, {
global: false,
color: true,
omit: ['dev']
})([], () => {
t.matchSnapshot(logs)
t.end()
})
})

t.test('outdated --omit=dev --omit=peer', t => {
outdated(testDir, {
global: false,
color: true,
omit: ['dev', 'peer']
})([], () => {
t.matchSnapshot(logs)
t.end()
})
})

t.test('outdated --omit=prod', t => {
outdated(testDir, {
global: false,
color: true,
omit: ['prod']
})([], () => {
t.matchSnapshot(logs)
t.end()
})
})

t.test('outdated --long', t => {
outdated(testDir, {
global: false,
Expand Down