File tree Expand file tree Collapse file tree 2 files changed +33
-3
lines changed Expand file tree Collapse file tree 2 files changed +33
-3
lines changed Original file line number Diff line number Diff line change @@ -83,8 +83,11 @@ export class DtsContent {
8383 }
8484
8585 public get outputFilePath ( ) : string {
86- const outputFileName = this . dropExtension ? removeExtension ( this . rInputPath ) : this . rInputPath ;
87- return path . join ( this . rootDir , this . outDir , outputFileName + '.d.ts' ) ;
86+ return path . join ( this . rootDir , this . outDir , this . outputFileName ) ;
87+ }
88+
89+ public get relativeOutputFilePath ( ) : string {
90+ return path . join ( this . outDir , this . outputFileName ) ;
8891 }
8992
9093 public get inputFilePath ( ) : string {
@@ -105,7 +108,7 @@ export class DtsContent {
105108 const fileContent = ( await readFile ( this . outputFilePath ) ) . toString ( ) ;
106109
107110 if ( fileContent !== finalOutput ) {
108- console . error ( chalk . red ( `[ERROR] Check type definitions for '${ this . outputFilePath } '` ) ) ;
111+ console . error ( chalk . red ( `[ERROR] Check type definitions for '${ this . relativeOutputFilePath } '` ) ) ;
109112 return false ;
110113 }
111114 return true ;
@@ -168,6 +171,11 @@ export class DtsContent {
168171 return firstLetter . toUpperCase ( ) ;
169172 } ) ;
170173 }
174+
175+ private get outputFileName ( ) : string {
176+ const outputFileName = this . dropExtension ? removeExtension ( this . rInputPath ) : this . rInputPath ;
177+ return outputFileName + '.d.ts' ;
178+ }
171179}
172180
173181function removeExtension ( filePath : string ) : string {
Original file line number Diff line number Diff line change @@ -116,6 +116,28 @@ describe('DtsContent', () => {
116116 } ) ;
117117 } ) ;
118118
119+ describe ( '#relativeOutputFilePath' , ( ) => {
120+ it ( 'adds d.ts to the original filename' , done => {
121+ new DtsCreator ( ) . create ( path . normalize ( 'test/testStyle.css' ) ) . then ( content => {
122+ assert . equal (
123+ path . relative ( process . cwd ( ) , content . relativeOutputFilePath ) ,
124+ path . normalize ( 'test/testStyle.css.d.ts' ) ,
125+ ) ;
126+ done ( ) ;
127+ } ) ;
128+ } ) ;
129+
130+ it ( 'can drop the original extension when asked' , done => {
131+ new DtsCreator ( { dropExtension : true } ) . create ( path . normalize ( 'test/testStyle.css' ) ) . then ( content => {
132+ assert . equal (
133+ path . relative ( process . cwd ( ) , content . relativeOutputFilePath ) ,
134+ path . normalize ( 'test/testStyle.d.ts' ) ,
135+ ) ;
136+ done ( ) ;
137+ } ) ;
138+ } ) ;
139+ } ) ;
140+
119141 describe ( '#formatted' , ( ) => {
120142 it ( 'returns formatted .d.ts string' , done => {
121143 new DtsCreator ( ) . create ( 'test/testStyle.css' ) . then ( content => {
You can’t perform that action at this time.
0 commit comments