@@ -166,6 +166,64 @@ describe('detectTypesStatus', () => {
166166 it ( 'returns none when no types detected' , ( ) => {
167167 expect ( detectTypesStatus ( { } ) ) . toEqual ( { kind : 'none' } )
168168 } )
169+
170+ it ( 'detects included types when declaration file exists in files' , ( ) => {
171+ expect (
172+ detectTypesStatus (
173+ { type : 'module' , exports : { '.' : './dist/index.mjs' } } ,
174+ undefined ,
175+ new Set ( [ 'dist/index.mjs' , 'dist/index.d.mts' ] ) ,
176+ ) ,
177+ ) . toEqual ( { kind : 'included' } )
178+ } )
179+ } )
180+
181+ describe ( 'detectTypesStatus implicit types (path derivation)' , ( ) => {
182+ it ( 'derives .d.mts from .mjs in exports' , ( ) => {
183+ expect (
184+ detectTypesStatus (
185+ { type : 'module' , exports : { '.' : './dist/index.mjs' } } ,
186+ undefined ,
187+ new Set ( [ 'dist/index.d.mts' ] ) ,
188+ ) ,
189+ ) . toEqual ( { kind : 'included' } )
190+ } )
191+
192+ it ( 'derives .d.cts from .cjs in exports' , ( ) => {
193+ expect (
194+ detectTypesStatus (
195+ { exports : { '.' : { require : './dist/index.cjs' } } } ,
196+ undefined ,
197+ new Set ( [ 'dist/index.d.cts' ] ) ,
198+ ) ,
199+ ) . toEqual ( { kind : 'included' } )
200+ } )
201+
202+ it ( 'derives .d.mts from main when type is module' , ( ) => {
203+ expect (
204+ detectTypesStatus (
205+ { type : 'module' , main : 'dist/index.mjs' } ,
206+ undefined ,
207+ new Set ( [ 'dist/index.d.mts' ] ) ,
208+ ) ,
209+ ) . toEqual ( { kind : 'included' } )
210+ } )
211+ } )
212+
213+ describe ( 'analyzePackage with files (implicit types)' , ( ) => {
214+ it ( 'detects included types when declaration file exists in files' , ( ) => {
215+ const pkg = { type : 'module' as const , exports : { '.' : './dist/index.mjs' } }
216+ const files = new Set ( [ 'dist/index.mjs' , 'dist/index.d.mts' ] )
217+ const result = analyzePackage ( pkg , { files } )
218+ expect ( result . types ) . toEqual ( { kind : 'included' } )
219+ } )
220+
221+ it ( 'returns none when declaration file does not exist in files' , ( ) => {
222+ const pkg = { type : 'module' as const , exports : { '.' : './dist/index.mjs' } }
223+ const files = new Set ( [ 'dist/index.mjs' ] )
224+ const result = analyzePackage ( pkg , { files } )
225+ expect ( result . types ) . toEqual ( { kind : 'none' } )
226+ } )
169227} )
170228
171229describe ( 'getTypesPackageName' , ( ) => {
0 commit comments