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

fix(ls): respect prod config for workspaces deps #3429

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/ls.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ class LS extends ArboristWorkspaceCmd {
: [...(node.target || node).edgesOut.values()]
.filter(filterBySelectedWorkspaces)
.filter(filterByEdgesTypes({
currentDepth,
dev,
development,
link,
Expand Down Expand Up @@ -387,6 +388,7 @@ const getJsonOutputItem = (node, { global, long }) => {
}

const filterByEdgesTypes = ({
currentDepth,
dev,
development,
link,
Expand All @@ -398,11 +400,11 @@ const filterByEdgesTypes = ({
}) => {
// filter deps by type, allows for: `npm ls --dev`, `npm ls --prod`,
// `npm ls --link`, `npm ls --only=dev`, etc
const filterDev = node === tree &&
const filterDev = currentDepth === 0 &&
(dev || development || /^dev(elopment)?$/.test(only))
const filterProd = node === tree &&
const filterProd = currentDepth === 0 &&
(prod || production || /^prod(uction)?$/.test(only))
const filterLink = node === tree && link
const filterLink = currentDepth === 0 && link

return (edge) =>
(filterDev ? edge.dev : true) &&
Expand Down
17 changes: 17 additions & 0 deletions tap-snapshots/test/lib/ls.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ [email protected] {CWD}/tap-testdir-ls-ls-loading-a-tree-containing-workspac
exports[`test/lib/ls.js TAP ls loading a tree containing workspaces > should filter using workspace config 1`] = `
[email protected] {CWD}/tap-testdir-ls-ls-loading-a-tree-containing-workspaces
\`-- [email protected] -> ./a
+-- [email protected]
+-- [email protected]
\`-- [email protected] -> ./d
\`-- [email protected]
Expand All @@ -506,6 +507,21 @@ [email protected] {CWD}/tap-testdir-ls-ls-loading-a-tree-containing-workspac
exports[`test/lib/ls.js TAP ls loading a tree containing workspaces > should list --all workspaces properly 1`] = `
[email protected] {CWD}/tap-testdir-ls-ls-loading-a-tree-containing-workspaces
+-- [email protected] -> ./a
| +-- [email protected]
| +-- [email protected]
| \`-- [email protected] deduped -> ./d
+-- [email protected] -> ./b
+-- [email protected] -> ./d
| \`-- [email protected]
| \`-- [email protected]
+-- [email protected] -> ./group/e
\`-- [email protected] -> ./group/f
`

exports[`test/lib/ls.js TAP ls loading a tree containing workspaces > should list only prod deps of workspaces 1`] = `
[email protected] {CWD}/tap-testdir-ls-ls-loading-a-tree-containing-workspaces
+-- [email protected] -> ./a
| +-- [email protected]
| \`-- [email protected] deduped -> ./d
+-- [email protected] -> ./b
Expand All @@ -520,6 +536,7 @@ [email protected] {CWD}/tap-testdir-ls-ls-loading-a-tree-containing-workspac
exports[`test/lib/ls.js TAP ls loading a tree containing workspaces > should list workspaces properly with default configs 1`] = `
[[email protected] {CWD}/tap-testdir-ls-ls-loading-a-tree-containing-workspaces
+-- [[email protected] -> ./a
| +-- [email protected]
| +-- [email protected]
| \`-- [email protected] deduped -> ./d
+-- [[email protected] -> ./b
Expand Down
21 changes: 21 additions & 0 deletions test/lib/ls.js
Original file line number Diff line number Diff line change
Expand Up @@ -1449,6 +1449,9 @@ t.test('ls', (t) => {
bar: {
'package.json': JSON.stringify({ name: 'bar', version: '1.0.0' }),
},
baz: {
'package.json': JSON.stringify({ name: 'baz', version: '1.0.0' }),
},
},
a: {
'package.json': JSON.stringify({
Expand All @@ -1458,6 +1461,9 @@ t.test('ls', (t) => {
c: '^1.0.0',
d: '^1.0.0',
},
devDependencies: {
baz: '^1.0.0',
},
}),
},
b: {
Expand Down Expand Up @@ -1520,6 +1526,21 @@ t.test('ls', (t) => {
})
})

// --production
await new Promise((res, rej) => {
config.production = true
ls.exec([], (err) => {
if (err)
rej(err)

t.matchSnapshot(redactCwd(result),
'should list only prod deps of workspaces')

config.production = false
res()
})
})

// filter out a single workspace using args
await new Promise((res, rej) => {
ls.exec(['d'], (err) => {
Expand Down