@@ -167,7 +167,7 @@ describe('detectTypesStatus', () => {
167167 expect ( detectTypesStatus ( { } ) ) . toEqual ( { kind : 'none' } )
168168 } )
169169
170- it ( 'detects included types when declaration file exists in files ' , ( ) => {
170+ it ( 'detects included types when matching declaration file exists for entry point ' , ( ) => {
171171 expect (
172172 detectTypesStatus (
173173 { type : 'module' , exports : { '.' : './dist/index.mjs' } } ,
@@ -176,10 +176,20 @@ describe('detectTypesStatus', () => {
176176 ) ,
177177 ) . toEqual ( { kind : 'included' } )
178178 } )
179+
180+ it ( 'does not detect types from unrelated .d.ts files in the package' , ( ) => {
181+ expect (
182+ detectTypesStatus (
183+ { type : 'module' , exports : { '.' : './dist/index.mjs' } } ,
184+ undefined ,
185+ new Set ( [ 'dist/index.mjs' , 'env.d.ts' , 'shims-vue.d.ts' ] ) ,
186+ ) ,
187+ ) . toEqual ( { kind : 'none' } )
188+ } )
179189} )
180190
181- describe ( 'detectTypesStatus implicit types (path derivation) ' , ( ) => {
182- it ( 'derives .d.mts from .mjs in exports ' , ( ) => {
191+ describe ( 'detectTypesStatus implicit types from entry points ' , ( ) => {
192+ it ( 'finds .d.mts matching .mjs export entry point ' , ( ) => {
183193 expect (
184194 detectTypesStatus (
185195 { type : 'module' , exports : { '.' : './dist/index.mjs' } } ,
@@ -189,7 +199,7 @@ describe('detectTypesStatus implicit types (path derivation)', () => {
189199 ) . toEqual ( { kind : 'included' } )
190200 } )
191201
192- it ( 'derives .d.cts from .cjs in exports ' , ( ) => {
202+ it ( 'finds .d.cts matching .cjs export entry point ' , ( ) => {
193203 expect (
194204 detectTypesStatus (
195205 { exports : { '.' : { require : './dist/index.cjs' } } } ,
@@ -199,7 +209,17 @@ describe('detectTypesStatus implicit types (path derivation)', () => {
199209 ) . toEqual ( { kind : 'included' } )
200210 } )
201211
202- it ( 'derives .d.mts from main when type is module' , ( ) => {
212+ it ( 'finds .d.ts matching .js export entry point' , ( ) => {
213+ expect (
214+ detectTypesStatus (
215+ { exports : { '.' : './dist/index.js' } } ,
216+ undefined ,
217+ new Set ( [ 'dist/index.d.ts' ] ) ,
218+ ) ,
219+ ) . toEqual ( { kind : 'included' } )
220+ } )
221+
222+ it ( 'finds .d.mts matching .mjs main entry point' , ( ) => {
203223 expect (
204224 detectTypesStatus (
205225 { type : 'module' , main : 'dist/index.mjs' } ,
@@ -208,22 +228,45 @@ describe('detectTypesStatus implicit types (path derivation)', () => {
208228 ) ,
209229 ) . toEqual ( { kind : 'included' } )
210230 } )
231+
232+ it ( 'finds .d.ts matching .js module entry point' , ( ) => {
233+ expect (
234+ detectTypesStatus ( { module : './dist/index.js' } , undefined , new Set ( [ 'dist/index.d.ts' ] ) ) ,
235+ ) . toEqual ( { kind : 'included' } )
236+ } )
237+
238+ it ( 'returns none when no declaration file matches any entry point' , ( ) => {
239+ expect (
240+ detectTypesStatus (
241+ { type : 'module' , exports : { '.' : './dist/index.mjs' } } ,
242+ undefined ,
243+ new Set ( [ 'dist/other.d.mts' , 'types/env.d.ts' ] ) ,
244+ ) ,
245+ ) . toEqual ( { kind : 'none' } )
246+ } )
211247} )
212248
213249describe ( 'analyzePackage with files (implicit types)' , ( ) => {
214- it ( 'detects included types when declaration file exists in files ' , ( ) => {
250+ it ( 'detects included types when matching declaration file exists for entry point ' , ( ) => {
215251 const pkg = { type : 'module' as const , exports : { '.' : './dist/index.mjs' } }
216252 const files = new Set ( [ 'dist/index.mjs' , 'dist/index.d.mts' ] )
217253 const result = analyzePackage ( pkg , { files } )
218254 expect ( result . types ) . toEqual ( { kind : 'included' } )
219255 } )
220256
221- it ( 'returns none when declaration file does not exist in files ' , ( ) => {
257+ it ( 'returns none when no declaration file matches entry point ' , ( ) => {
222258 const pkg = { type : 'module' as const , exports : { '.' : './dist/index.mjs' } }
223259 const files = new Set ( [ 'dist/index.mjs' ] )
224260 const result = analyzePackage ( pkg , { files } )
225261 expect ( result . types ) . toEqual ( { kind : 'none' } )
226262 } )
263+
264+ it ( 'returns none when only unrelated .d.ts files exist' , ( ) => {
265+ const pkg = { type : 'module' as const , exports : { '.' : './dist/index.mjs' } }
266+ const files = new Set ( [ 'dist/index.mjs' , 'env.d.ts' ] )
267+ const result = analyzePackage ( pkg , { files } )
268+ expect ( result . types ) . toEqual ( { kind : 'none' } )
269+ } )
227270} )
228271
229272describe ( 'getTypesPackageName' , ( ) => {
0 commit comments