File tree 9 files changed +90
-0
lines changed
9 files changed +90
-0
lines changed Original file line number Diff line number Diff line change @@ -304,6 +304,7 @@ Knip contains a growing list of plugins:
304
304
- [ Stylelint] [ plugin-stylelint ]
305
305
- [ Svelte] [ plugin-svelte ]
306
306
- [ Tailwind] [ plugin-tailwind ]
307
+ - [ tsup] [ plugin-tsup ]
307
308
- [ TypeDoc] [ plugin-typedoc ]
308
309
- [ TypeScript] [ plugin-typescript ]
309
310
- [ Vite] [ plugin-vite ]
@@ -956,6 +957,7 @@ Special thanks to the wonderful people who have contributed to this project:
956
957
[ plugin-stylelint ] : ./src/plugins/stylelint
957
958
[ plugin-svelte ] : ./src/plugins/svelte
958
959
[ plugin-tailwind ] : ./src/plugins/tailwind
960
+ [ plugin-tsup ] : ./src/plugins/tsup
959
961
[ plugin-typedoc ] : ./src/plugins/typedoc
960
962
[ plugin-typescript ] : ./src/plugins/typescript
961
963
[ plugin-vite ] : ./src/plugins/vite
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " @fixtures/tsup" ,
3
+ "version" : " *"
4
+ }
Original file line number Diff line number Diff line change 384
384
"title" : " tailwind plugin configuration (https://github.com/webpro/knip/blob/main/src/plugins/tailwind/README.md)" ,
385
385
"$ref" : " #/definitions/plugin"
386
386
},
387
+ "tsup" : {
388
+ "title" : " tsup plugin configuration (https://github.com/webpro/knip/blob/main/src/plugins/tsup/README.md)" ,
389
+ "$ref" : " #/definitions/plugin"
390
+ },
387
391
"typedoc" : {
388
392
"title" : " typedoc plugin configuration (https://github.com/webpro/knip/blob/main/src/plugins/typedoc/README.md)" ,
389
393
"$ref" : " #/definitions/plugin"
Original file line number Diff line number Diff line change @@ -111,6 +111,7 @@ const pluginsSchema = z.object({
111
111
stryker : pluginSchema ,
112
112
stylelint : pluginSchema ,
113
113
tailwind : pluginSchema ,
114
+ tsup : pluginSchema ,
114
115
typedoc : pluginSchema ,
115
116
typescript : pluginSchema ,
116
117
vite : pluginSchema ,
Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ export * as stryker from './stryker/index.js';
39
39
export * as stylelint from './stylelint/index.js' ;
40
40
export * as svelte from './svelte/index.js' ;
41
41
export * as tailwind from './tailwind/index.js' ;
42
+ export * as tsup from './tsup/index.js' ;
42
43
export * as typedoc from './typedoc/index.js' ;
43
44
export * as typescript from './typescript/index.js' ;
44
45
export * as vite from './vite/index.js' ;
Original file line number Diff line number Diff line change
1
+ # tsup
2
+
3
+ ## Enabled
4
+
5
+ This plugin is enabled when any of the following package names and/or regular expressions has a match in ` dependencies `
6
+ or ` devDependencies ` :
7
+
8
+ - ` tsup `
9
+
10
+ ## Default configuration
11
+
12
+ ``` json
13
+ {
14
+ "tsup" : {
15
+ "config" : [" tsup.config.js" ]
16
+ }
17
+ }
18
+ ```
19
+
20
+ Also see [ Knip plugins] [ 1 ] for more information about plugins.
21
+
22
+ [ 1 ] : https://github.com/webpro/knip/blob/main/README.md#plugins
Original file line number Diff line number Diff line change
1
+ import { timerify } from '../../util/Performance.js' ;
2
+ import { hasDependency , load } from '../../util/plugin.js' ;
3
+ import { toEntryPattern } from '../../util/protocols.js' ;
4
+ import type { TsupConfig } from './types.js' ;
5
+ import type { IsPluginEnabledCallback , GenericPluginCallback } from '../../types/plugins.js' ;
6
+
7
+ // https://paka.dev/npm/tsup/api
8
+
9
+ export const NAME = 'tsup' ;
10
+
11
+ /** @public */
12
+ export const ENABLERS = [ 'tsup' ] ;
13
+
14
+ export const isEnabled : IsPluginEnabledCallback = ( { dependencies } ) => hasDependency ( dependencies , ENABLERS ) ;
15
+
16
+ export const CONFIG_FILE_PATTERNS = [ 'tsup.config.js' ] ;
17
+
18
+ const findTsupDependencies : GenericPluginCallback = async configFilePath => {
19
+ let localConfig : TsupConfig | undefined = await load ( configFilePath ) ;
20
+ if ( typeof localConfig === 'function' ) localConfig = await localConfig ( { } ) ;
21
+
22
+ if ( ! localConfig ) return [ ] ;
23
+
24
+ const entryPatterns = [ localConfig ] . flat ( ) . flatMap ( config => {
25
+ if ( ! config . entry ) return [ ] ;
26
+ if ( Array . isArray ( config . entry ) ) return config . entry . map ( toEntryPattern ) ;
27
+ return Object . values ( config . entry ) . map ( toEntryPattern ) ;
28
+ } ) ;
29
+
30
+ return entryPatterns ;
31
+ } ;
32
+
33
+ export const findDependencies = timerify ( findTsupDependencies ) ;
Original file line number Diff line number Diff line change
1
+ type Entry = string [ ] | Record < string , string > ;
2
+
3
+ type Options = {
4
+ entry ?: Entry ;
5
+ } ;
6
+
7
+ type MaybePromise < T > = T | Promise < T > ;
8
+
9
+ export type TsupConfig = Options | Options [ ] | ( ( overrideOptions : Options ) => MaybePromise < Options | Options [ ] > ) ;
Original file line number Diff line number Diff line change
1
+ import assert from 'node:assert/strict' ;
2
+ import test from 'node:test' ;
3
+ import * as tsup from '../../src/plugins/tsup/index.js' ;
4
+ import { resolve , join } from '../../src/util/path.js' ;
5
+ import { getManifest , pluginConfig as config } from '../helpers/index.js' ;
6
+
7
+ const cwd = resolve ( 'fixtures/plugins/tsup' ) ;
8
+ const manifest = getManifest ( cwd ) ;
9
+
10
+ test ( 'Find dependencies in tsup configuration (json)' , async ( ) => {
11
+ const configFilePath = join ( cwd , 'package.json' ) ;
12
+ const dependencies = await tsup . findDependencies ( configFilePath , { manifest, config } ) ;
13
+ assert . deepEqual ( dependencies , [ ] ) ;
14
+ } ) ;
You can’t perform that action at this time.
0 commit comments