Skip to content

Commit 326e281

Browse files
authored
fix!: dep-check tsx and jsx (#1661)
Adds configuration to dependency-check command to check for unused dependencies properly in jsx & tsx files. BREAKING CHANGE: `.tsx` and `.jsx` files are now checked for missing/unused dependencies
1 parent 257909b commit 326e281

File tree

11 files changed

+126
-1
lines changed

11 files changed

+126
-1
lines changed

src/dependency-check.js

+2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ const tasks = new Listr(
4141
const productionOnlyResult = await depcheck(cwd(), {
4242
parsers: {
4343
'**/*.js': depcheck.parser.es6,
44+
'**/*.jsx': depcheck.parser.jsx,
4445
'**/*.ts': depcheck.parser.typescript,
46+
'**/*.tsx': depcheck.parser.jsx,
4547
'**/*.cjs': depcheck.parser.es6,
4648
'**/*.mjs': depcheck.parser.es6
4749
},

test/dependency-check.js

+36
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,40 @@ describe('dependency check', () => {
137137
})
138138
).to.eventually.be.fulfilled()
139139
})
140+
141+
it('should pass for jsx files', async () => {
142+
await expect(
143+
execa(bin, ['dependency-check'], {
144+
cwd: path.join(__dirname, 'fixtures/dependency-check/jsx-pass')
145+
})
146+
).to.eventually.be.fulfilled()
147+
})
148+
149+
it('should fail for jsx files', async () => {
150+
await expect(
151+
execa(bin, ['dependency-check'], {
152+
cwd: path.join(__dirname, 'fixtures/dependency-check/jsx-fail')
153+
})
154+
).to.eventually.be.rejected()
155+
.with.property('message')
156+
.that.include('react-icons')
157+
})
158+
159+
it('should pass for tsx files', async () => {
160+
await expect(
161+
execa(bin, ['dependency-check'], {
162+
cwd: path.join(__dirname, 'fixtures/dependency-check/tsx-pass')
163+
})
164+
).to.eventually.be.fulfilled()
165+
})
166+
167+
it('should fail for tsx files', async () => {
168+
await expect(
169+
execa(bin, ['dependency-check'], {
170+
cwd: path.join(__dirname, 'fixtures/dependency-check/tsx-fail')
171+
})
172+
).to.eventually.be.rejected()
173+
.with.property('message')
174+
.that.include('react-icons')
175+
})
140176
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "jsx-dep-check-fail",
3+
"version": "1.0.0",
4+
"main": "index.jsx",
5+
"type": "module",
6+
"dependencies": {
7+
"react": "18.3.1",
8+
"react-icons": "5.3.0"
9+
},
10+
"devDependencies": {
11+
"@types/react": "^18.3.12"
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// @ts-expect-error - not installed
2+
// eslint-disable-next-line no-unused-vars
3+
import React from 'react'
4+
5+
// @ts-expect-error - not installed
6+
// eslint-disable-next-line no-unused-vars
7+
const Component = () => (<div>Hello, world!</div>)
8+
const App = () => (<Component />)
9+
10+
export default App
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "jsx-dep-check-fail",
3+
"version": "1.0.0",
4+
"main": "index.jsx",
5+
"type": "module",
6+
"dependencies": {
7+
"react": "18.3.1"
8+
},
9+
"devDependencies": {
10+
"@types/react": "^18.3.12"
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// @ts-expect-error - not installed
2+
// eslint-disable-next-line no-unused-vars
3+
import React from 'react'
4+
5+
// @ts-expect-error - not installed
6+
// eslint-disable-next-line no-unused-vars
7+
const Component = () => (<div>Hello, world!</div>)
8+
const App = () => (<Component />)
9+
10+
export default App
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "tsx-dep-check-fail",
3+
"version": "1.0.0",
4+
"main": "index.tsx",
5+
"type": "module",
6+
"dependencies": {
7+
"react": "18.3.1",
8+
"react-icons": "5.3.0"
9+
},
10+
"devDependencies": {
11+
"@types/react": "^18.3.12"
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// @ts-expect-error - not installed
2+
import React from 'react'
3+
4+
// @ts-expect-error - not installed
5+
const Component: React.FC = () => (<div>Hello, world!</div>)
6+
const App: React.FC = () => (<Component />)
7+
8+
export default App
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "tsx-dep-check-pass",
3+
"version": "1.0.0",
4+
"main": "index.tsx",
5+
"type": "module",
6+
"dependencies": {
7+
"react": "18.3.1"
8+
},
9+
"devDependencies": {
10+
"@types/react": "^18.3.12"
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// @ts-expect-error - not installed
2+
import React from 'react'
3+
4+
// @ts-expect-error - not installed
5+
const Component: React.FC = () => (<div>Hello, world!</div>)
6+
const App: React.FC = () => (<Component />)
7+
8+
export default App

tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"extends": "./src/config/tsconfig.aegir.json",
33
"compilerOptions": {
44
"outDir": "dist",
5-
"emitDeclarationOnly": true
5+
"emitDeclarationOnly": true,
6+
"jsx": "preserve"
67
},
78
"include": [
89
"package.json",

0 commit comments

Comments
 (0)