Skip to content

Commit

Permalink
feat: dep-check tsx and jsx
Browse files Browse the repository at this point in the history
  • Loading branch information
SgtPooki committed Oct 28, 2024
1 parent 257909b commit 1de3b7e
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/dependency-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ const tasks = new Listr(
const productionOnlyResult = await depcheck(cwd(), {
parsers: {
'**/*.js': depcheck.parser.es6,
'**/*.jsx': depcheck.parser.jsx,
'**/*.ts': depcheck.parser.typescript,
'**/*.tsx': depcheck.parser.jsx,
'**/*.cjs': depcheck.parser.es6,
'**/*.mjs': depcheck.parser.es6
},
Expand Down
38 changes: 38 additions & 0 deletions test/dependency-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,42 @@ describe('dependency check', () => {
})
).to.eventually.be.fulfilled()
})

it('should pass for jsx files', async () => {
await expect(
execa(bin, ['dependency-check'], {
cwd: path.join(__dirname, 'fixtures/dependency-check/jsx-pass')
})
).to.eventually.be.fulfilled()
})

it('should fail for jsx files', async () => {
await expect(
execa(bin, ['dependency-check'], {
cwd: path.join(__dirname, 'fixtures/dependency-check/jsx-fail')
})
).to.eventually.be.rejected()
.with.property('message')
.that.matches(/react-icons$/mg)
.and.include('react-icons')
})

it('should pass for tsx files', async () => {
await expect(
execa(bin, ['dependency-check'], {
cwd: path.join(__dirname, 'fixtures/dependency-check/tsx-pass')
})
).to.eventually.be.fulfilled()
})

it('should fail for tsx files', async () => {
await expect(
execa(bin, ['dependency-check'], {
cwd: path.join(__dirname, 'fixtures/dependency-check/tsx-fail')
})
).to.eventually.be.rejected()
.with.property('message')
.that.matches(/react-icons$/mg)
.and.include('react-icons')
})
})
13 changes: 13 additions & 0 deletions test/fixtures/dependency-check/jsx-fail/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "jsx-dep-check-fail",
"version": "1.0.0",
"main": "index.jsx",
"type": "module",
"dependencies": {
"react": "18.3.1",
"react-icons": "5.3.0"
},
"devDependencies": {
"@types/react": "^18.3.12"
}
}
10 changes: 10 additions & 0 deletions test/fixtures/dependency-check/jsx-fail/src/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// @ts-expect-error - not installed
// eslint-disable-next-line no-unused-vars
import React from 'react'

// @ts-expect-error - not installed
// eslint-disable-next-line no-unused-vars
const Component = () => (<div>Hello, world!</div>)
const App = () => (<Component />)

export default App
12 changes: 12 additions & 0 deletions test/fixtures/dependency-check/jsx-pass/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "jsx-dep-check-fail",
"version": "1.0.0",
"main": "index.jsx",
"type": "module",
"dependencies": {
"react": "18.3.1"
},
"devDependencies": {
"@types/react": "^18.3.12"
}
}
10 changes: 10 additions & 0 deletions test/fixtures/dependency-check/jsx-pass/src/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// @ts-expect-error - not installed
// eslint-disable-next-line no-unused-vars
import React from 'react'

// @ts-expect-error - not installed
// eslint-disable-next-line no-unused-vars
const Component = () => (<div>Hello, world!</div>)
const App = () => (<Component />)

export default App
13 changes: 13 additions & 0 deletions test/fixtures/dependency-check/tsx-fail/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "tsx-dep-check-fail",
"version": "1.0.0",
"main": "index.tsx",
"type": "module",
"dependencies": {
"react": "18.3.1",
"react-icons": "5.3.0"
},
"devDependencies": {
"@types/react": "^18.3.12"
}
}
8 changes: 8 additions & 0 deletions test/fixtures/dependency-check/tsx-fail/src/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// @ts-expect-error - not installed
import React from 'react'

// @ts-expect-error - not installed
const Component: React.FC = () => (<div>Hello, world!</div>)
const App: React.FC = () => (<Component />)

export default App
12 changes: 12 additions & 0 deletions test/fixtures/dependency-check/tsx-pass/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "tsx-dep-check-pass",
"version": "1.0.0",
"main": "index.tsx",
"type": "module",
"dependencies": {
"react": "18.3.1"
},
"devDependencies": {
"@types/react": "^18.3.12"
}
}
8 changes: 8 additions & 0 deletions test/fixtures/dependency-check/tsx-pass/src/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// @ts-expect-error - not installed
import React from 'react'

// @ts-expect-error - not installed
const Component: React.FC = () => (<div>Hello, world!</div>)
const App: React.FC = () => (<Component />)

export default App
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"extends": "./src/config/tsconfig.aegir.json",
"compilerOptions": {
"outDir": "dist",
"emitDeclarationOnly": true
"emitDeclarationOnly": true,
"jsx": "preserve"
},
"include": [
"package.json",
Expand Down

0 comments on commit 1de3b7e

Please sign in to comment.