Skip to content

Commit c9c178e

Browse files
committed
feat: inline chai types instead of using @types/chai
1 parent 8e5e42d commit c9c178e

File tree

10 files changed

+149
-66
lines changed

10 files changed

+149
-66
lines changed

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@
8282
"ignoreMissing": [
8383
"@algolia/client-search"
8484
]
85+
},
86+
"patchedDependencies": {
87+
"@types/chai@4.3.6": "patches/@types__chai@4.3.6.patch"
8588
}
8689
},
8790
"simple-git-hooks": {

packages/expect/index.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import './dist/chai'
2+
3+
export * from './dist/index'

packages/expect/package.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
"sideEffects": false,
1818
"exports": {
1919
".": {
20-
"types": "./dist/index.d.ts",
20+
"types": "./index.d.ts",
2121
"import": "./dist/index.js"
2222
},
2323
"./*": "./*"
2424
},
2525
"main": "./dist/index.js",
2626
"module": "./dist/index.js",
27-
"types": "./dist/index.d.ts",
27+
"types": "./index.d.ts",
2828
"files": [
2929
"dist"
3030
],
@@ -39,7 +39,9 @@
3939
"chai": "^4.3.10"
4040
},
4141
"devDependencies": {
42+
"@types/chai": "^4.3.6",
4243
"@vitest/runner": "workspace:*",
43-
"picocolors": "^1.0.0"
44+
"picocolors": "^1.0.0",
45+
"rollup-plugin-copy": "^3.5.0"
4446
}
4547
}

packages/expect/rollup.config.js

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { builtinModules } from 'node:module'
22
import esbuild from 'rollup-plugin-esbuild'
33
import dts from 'rollup-plugin-dts'
44
import { defineConfig } from 'rollup'
5+
import copy from 'rollup-plugin-copy'
56
import pkg from './package.json' assert { type: 'json' }
67

78
const external = [
@@ -16,6 +17,11 @@ const plugins = [
1617
esbuild({
1718
target: 'node14',
1819
}),
20+
copy({
21+
targets: [
22+
{ src: 'node_modules/@types/chai/index.d.ts', dest: 'dist', rename: 'chai.d.ts' },
23+
],
24+
}),
1925
]
2026

2127
export default defineConfig([

packages/expect/src/types.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import type { use as chaiUse } from 'chai'
2-
31
/**
42
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
53
*
@@ -12,8 +10,7 @@ import type { Formatter } from 'picocolors/types'
1210
import type { Constructable } from '@vitest/utils'
1311
import type { diff, getMatcherUtils, stringify } from './jest-matcher-utils'
1412

15-
export type FirstFunctionArgument<T> = T extends (arg: infer A) => unknown ? A : never
16-
export type ChaiPlugin = FirstFunctionArgument<typeof chaiUse>
13+
export type ChaiPlugin = Chai.ChaiPlugin
1714

1815
export type Tester = (a: any, b: any) => boolean | undefined
1916

packages/vitest/package.json

-2
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,6 @@
142142
}
143143
},
144144
"dependencies": {
145-
"@types/chai": "^4.3.5",
146-
"@types/chai-subset": "^1.3.3",
147145
"@types/node": "*",
148146
"@vitest/expect": "workspace:*",
149147
"@vitest/runner": "workspace:*",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
declare module 'chai-subset' {
2+
const chaiSubset: Chai.ChaiPlugin
3+
export = chaiSubset
4+
}

packages/vitest/src/types/global.ts

+12
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@ import type { UserConsoleLog } from './general'
55
import type { VitestEnvironment } from './config'
66
import type { BenchmarkResult } from './benchmark'
77

8+
declare global {
9+
// eslint-disable-next-line @typescript-eslint/no-namespace
10+
namespace Chai {
11+
interface Assertion {
12+
containSubset(expected: any): Assertion
13+
}
14+
interface Assert {
15+
containSubset(val: any, exp: any, msg?: string): void
16+
}
17+
}
18+
}
19+
820
declare module '@vitest/expect' {
921
interface MatcherState {
1022
environment: VitestEnvironment

patches/@types__chai@4.3.6.patch

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
diff --git a/index.d.ts b/index.d.ts
2+
index 9f5cb99cdc30c0ceee9c4bb2d866030cfe7b889e..7e231313ed85b703d70ec44778a96e7f3ff4f98e 100755
3+
--- a/index.d.ts
4+
+++ b/index.d.ts
5+
@@ -1963,6 +1963,6 @@ declare module "chai" {
6+
export = chai;
7+
}
8+
9+
-interface Object {
10+
- should: Chai.Assertion;
11+
-}
12+
+// interface Object {
13+
+// should: Chai.Assertion;
14+
+// }

0 commit comments

Comments
 (0)