Skip to content

Commit 6b01e36

Browse files
feat!: check for unused dependencies by default (#1177)
To make the dependency check more thorough, check for unused deps by default. --------- Co-authored-by: Alex Potsides <[email protected]>
1 parent 15f01ea commit 6b01e36

File tree

5 files changed

+23
-15
lines changed

5 files changed

+23
-15
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@
212212
"lint": "node src/index.js lint",
213213
"test": "node src/index.js test",
214214
"docs": "node src/index.js docs",
215-
"dep-check": "node src/index.js dep-check",
215+
"dep-check": "node src/index.js dep-check --unused false",
216216
"doc-check": "node src/index.js doc-check",
217217
"test:node": "node src/index.js test -t node --cov",
218218
"test:chrome": "node src/index.js test -t browser --cov",

src/cmds/dependency-check.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export default {
3636
.option('u', {
3737
alias: 'unused',
3838
describe: 'Checks for unused dependencies',
39-
default: false,
39+
default: true,
4040
type: 'boolean'
4141
})
4242
},

src/config/user.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,7 @@ const defaults = {
112112
// dependency check cmd options
113113
dependencyCheck: {
114114
unused: false,
115-
ignore: [
116-
'@types/*',
117-
'aegir'
118-
]
115+
ignore: []
119116
},
120117
exec: {
121118
bail: true

src/dependency-check.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@ import Listr from 'listr'
22
import depcheck from 'depcheck'
33
import { cwd } from 'process'
44

5+
const ignoredDevDependencies = [
6+
'@types/*',
7+
'aegir',
8+
'mkdirp',
9+
'rimraf',
10+
'protons',
11+
'eslint*',
12+
'@types/*',
13+
'@semantic-release/*'
14+
]
15+
516
/**
617
* @typedef {import("listr").ListrTaskWrapper} Task
718
* @typedef {import("./types").GlobalOptions} GlobalOptions
@@ -24,7 +35,7 @@ const tasks = new Listr(
2435
'**/*.cjs': depcheck.parser.es6,
2536
'**/*.mjs': depcheck.parser.es6
2637
},
27-
ignoreMatches: ['eslint*', '@types/*', '@semantic-release/*'].concat(ctx.fileConfig.dependencyCheck.ignore).concat(ctx.ignore)
38+
ignoreMatches: ignoredDevDependencies.concat(ctx.fileConfig.dependencyCheck.ignore).concat(ctx.ignore)
2839
})
2940
if (Object.keys(result.missing).length > 0 || (ctx.unused && (result.dependencies.length > 0 || result.devDependencies.length > 0))) {
3041
throw new Error(

test/dependency-check.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ const bin = require.resolve('../src/index.js')
1313
describe('dependency check', () => {
1414
it('should fail for missing deps', async () => {
1515
await expect(
16-
execa(bin, ['dependency-check'], {
16+
execa(bin, ['dependency-check', '-u', 'false'], {
1717
cwd: path.join(__dirname, 'fixtures/dependency-check/fail')
1818
})
1919
).to.eventually.be.rejectedWith('execa')
2020
})
2121

2222
it('should fail for missing deps in an esm project', async () => {
2323
await expect(
24-
execa(bin, ['dependency-check'], {
24+
execa(bin, ['dependency-check', '-u', 'false'], {
2525
cwd: path.join(__dirname, 'fixtures/dependency-check/esm-fail')
2626
})
2727
).to.eventually.be.rejected()
@@ -32,7 +32,7 @@ describe('dependency check', () => {
3232

3333
it('should fail for missing deps in an ts project', async () => {
3434
await expect(
35-
execa(bin, ['dependency-check'], {
35+
execa(bin, ['dependency-check', '-u', 'false'], {
3636
cwd: path.join(__dirname, 'fixtures/dependency-check/ts-fail')
3737
})
3838
).to.eventually.be.rejected()
@@ -43,31 +43,31 @@ describe('dependency check', () => {
4343

4444
it('should pass when there are no missing deps', async () => {
4545
await expect(
46-
execa(bin, ['dependency-check'], {
46+
execa(bin, ['dependency-check', '-u', 'false'], {
4747
cwd: path.join(__dirname, 'fixtures/dependency-check/pass')
4848
})
4949
).to.eventually.be.fulfilled()
5050
})
5151

5252
it('should pass when there are no missing deps in an esm project', async () => {
5353
await expect(
54-
execa(bin, ['dependency-check'], {
54+
execa(bin, ['dependency-check', '-u', 'false'], {
5555
cwd: path.join(__dirname, 'fixtures/dependency-check/esm-pass')
5656
})
5757
).to.eventually.be.fulfilled()
5858
})
5959

6060
it('should pass when there are no missing deps in an ts project', async () => {
6161
await expect(
62-
execa(bin, ['dependency-check'], {
62+
execa(bin, ['dependency-check', '-u', 'false'], {
6363
cwd: path.join(__dirname, 'fixtures/dependency-check/ts-pass')
6464
})
6565
).to.eventually.be.fulfilled()
6666
})
6767

6868
it('should check unused', async () => {
6969
await expect(
70-
execa(bin, ['dependency-check', '--unused'], {
70+
execa(bin, ['dependency-check'], {
7171
cwd: path.join(__dirname, 'fixtures/dependency-check/pass')
7272
})
7373
).to.eventually.be.rejected.with.property('message').that.include(
@@ -131,7 +131,7 @@ describe('dependency check', () => {
131131

132132
it('should pass for modules used in .aegir.js', async () => {
133133
await expect(
134-
execa(bin, ['dependency-check', '--unused'], {
134+
execa(bin, ['dependency-check', '-u', 'false'], {
135135
cwd: path.join(
136136
__dirname,
137137
'fixtures/dependency-check/with-aegir-config'

0 commit comments

Comments
 (0)