File tree 4 files changed +61
-3
lines changed
4 files changed +61
-3
lines changed Original file line number Diff line number Diff line change @@ -263,6 +263,13 @@ AutoImport({
263
263
type: true ,
264
264
},
265
265
],
266
+
267
+ // Array of strings of regexes that contains imports meant to be filtered out.
268
+ ignore: [
269
+ ' useMouse' ,
270
+ ' useFetch'
271
+ ],
272
+
266
273
// Enable auto import by filename for default module exports under directories
267
274
defaultExportByFilename: false ,
268
275
@@ -280,6 +287,14 @@ AutoImport({
280
287
// Set `false` to disable.
281
288
dts: ' ./auto-imports.d.ts' ,
282
289
290
+ // Array of strings of regexes that contains imports meant to be ignored during
291
+ // the declaration file generation. You may find this useful when you need to provide
292
+ // a custom signature for a function.
293
+ ignoreDts: [
294
+ ' ignoredFunction' ,
295
+ / ^ ignore_/
296
+ ],
297
+
283
298
// Auto import inside Vue template
284
299
// see https://github.com/unjs/unimport/pull/15 and https://github.com/unjs/unimport/pull/72
285
300
vueTemplate: false ,
Original file line number Diff line number Diff line change @@ -80,10 +80,20 @@ ${dts}`.trim()}\n`
80
80
if ( ! imports . length && ! resolvers . length && ! dirs ?. length )
81
81
console . warn ( '[auto-import] plugin installed but no imports has defined, see https://github.com/antfu/unplugin-auto-import#configurations for configurations' )
82
82
83
+ const compare = ( left : string | undefined , right : NonNullable < ( Options [ 'ignore' ] | Options [ 'ignoreDts' ] ) > [ number ] ) => {
84
+ return right instanceof RegExp
85
+ ? right . test ( left ! )
86
+ : right === left
87
+ }
88
+
83
89
options . ignore ?. forEach ( ( name ) => {
84
- const i = imports . find ( i => i . as === name )
85
- if ( i )
86
- i . disabled = true
90
+ const i = imports . find ( i => compare ( i . as , name ) )
91
+ if ( i ) i . disabled = true
92
+ } )
93
+
94
+ options . ignoreDts ?. forEach ( ( name ) => {
95
+ const i = imports . find ( i => compare ( i . as , name ) )
96
+ if ( i ) i . dtsDisabled = true
87
97
} )
88
98
89
99
return unimport . getInternalContext ( ) . replaceImports ( imports )
Original file line number Diff line number Diff line change @@ -93,6 +93,11 @@ export interface Options {
93
93
*/
94
94
ignore ?: ( string | RegExp ) [ ]
95
95
96
+ /**
97
+ * These identifiers won't be put on the DTS file
98
+ */
99
+ ignoreDts ?: ( string | RegExp ) [ ]
100
+
96
101
/**
97
102
* Inject the imports at the end of other imports
98
103
*
Original file line number Diff line number Diff line change
1
+ import { join } from 'node:path'
2
+ import { expect , it } from 'vitest'
3
+ import { createContext } from '../src/core/ctx'
4
+
5
+ it ( 'dts ignore' , async ( ) => {
6
+ const cwd = process . cwd ( )
7
+ const ctx = createContext ( {
8
+ imports : [ {
9
+ custom : [
10
+ 'shouldBePresent' ,
11
+ 'shouldAlsoBePresent' ,
12
+ 'shouldBeIgnored' ,
13
+ 'ignoreme_shoudAlsoBeIgnored'
14
+ ]
15
+ } ] ,
16
+ ignoreDts : [
17
+ 'shouldBeIgnored' ,
18
+ / ^ i g n o r e m e _ /
19
+ ]
20
+ } )
21
+
22
+ const dtsContent = await ctx . generateDTS ( join ( cwd , 'index.d.ts' ) )
23
+
24
+ expect ( dtsContent ) . toContain ( 'shouldBePresent' )
25
+ expect ( dtsContent ) . toContain ( 'shouldAlsoBePresent' )
26
+ expect ( dtsContent ) . not . toContain ( 'shouldBeIgnored' )
27
+ expect ( dtsContent ) . not . toContain ( 'ignoreme_shoudAlsoBeIgnored' )
28
+ } )
You can’t perform that action at this time.
0 commit comments