22
33import type { OutputFile } from "../transform.ts" ;
44import type { SourceMapOptions } from "./compiler.ts" ;
5- import { toDtsFilePath , toJsFilePath } from "./utils.ts" ;
5+ import { isDeclarationFilePath , toDtsFilePath , toJsFilePath } from "./utils.ts" ;
66
77export function getNpmIgnoreText ( options : {
88 sourceMap ?: SourceMapOptions ;
@@ -27,14 +27,22 @@ export function getNpmIgnoreText(options: {
2727
2828 function * getTestFileNames ( ) {
2929 for ( const file of options . testFiles ) {
30- const filePath = toJsFilePath ( file . filePath ) ;
31- const dtsFilePath = toDtsFilePath ( file . filePath ) ;
3230 // the whole directory is excluded above when it's not published
3331 if ( isReferencingSrcDir ( ) ) {
3432 yield `/src/${ file . filePath } ` ;
3533 }
34+ // A dependency can ship a declaration file directly (ex. a prebuilt
35+ // package published to JSR). The compiler copies it as-is beside the
36+ // emitted code rather than turning it into a `.js` + `.d.ts` pair, so it
37+ // has different output paths than a regular source file.
38+ if ( isDeclarationFilePath ( file . filePath ) ) {
39+ yield * getDeclarationTestFileNames ( file . filePath ) ;
40+ continue ;
41+ }
42+ const jsFilePath = toJsFilePath ( file . filePath ) ;
43+ const dtsFilePath = toDtsFilePath ( file . filePath ) ;
3644 if ( options . includeEsModule ) {
37- const esmFilePath = `/esm/${ filePath } ` ;
45+ const esmFilePath = `/esm/${ jsFilePath } ` ;
3846 yield esmFilePath ;
3947 if ( options . sourceMap === true ) {
4048 yield `${ esmFilePath } .map` ;
@@ -47,7 +55,7 @@ export function getNpmIgnoreText(options: {
4755 }
4856 }
4957 if ( options . includeScriptModule ) {
50- const scriptFilePath = `/script/${ filePath } ` ;
58+ const scriptFilePath = `/script/${ jsFilePath } ` ;
5159 yield scriptFilePath ;
5260 if ( options . sourceMap === true ) {
5361 yield `${ scriptFilePath } .map` ;
@@ -69,6 +77,31 @@ export function getNpmIgnoreText(options: {
6977 yield "/test_runner.cjs" ;
7078 }
7179
80+ /** A declaration file emits no `.js`, so the compiler only copies it where
81+ * declarations are output: beside the code when they're inlined, or the
82+ * `types` directory when they're kept separate. */
83+ function * getDeclarationTestFileNames ( dtsFilePath : string ) {
84+ if ( options . declaration === "inline" ) {
85+ if ( options . includeEsModule ) {
86+ yield `/esm/${ dtsFilePath } ` ;
87+ if ( options . declarationMap ) {
88+ yield `/esm/${ dtsFilePath } .map` ;
89+ }
90+ }
91+ if ( options . includeScriptModule ) {
92+ yield `/script/${ dtsFilePath } ` ;
93+ if ( options . declarationMap ) {
94+ yield `/script/${ dtsFilePath } .map` ;
95+ }
96+ }
97+ } else if ( options . declaration === "separate" ) {
98+ yield `/types/${ dtsFilePath } ` ;
99+ if ( options . declarationMap ) {
100+ yield `/types/${ dtsFilePath } .map` ;
101+ }
102+ }
103+ }
104+
72105 /** Whether any emitted map points back at the files in `/src/`, in which
73106 * case the directory needs to be published for the map to resolve. */
74107 function isReferencingSrcDir ( ) {
0 commit comments