@@ -38,7 +38,7 @@ const ensureTsconfig = async (tsconfigFile) =>
38
38
if ( ! ( await pathExists ( tsconfig ) ) )
39
39
{
40
40
// eslint-disable-next-line no-console
41
- console . log ( chalk . red ( `${ prefix } Error: TypeScript configuration file "${ tsconfigFile } "`
41
+ console . log ( chalk . red ( `${ prefix } Error: TypeScript configuration file "${ path . basename ( tsconfig ) } "`
42
42
+ ` not found but is required for linting and building.` ) ) ;
43
43
44
44
process . exit ( 1 ) ;
@@ -47,7 +47,11 @@ const ensureTsconfig = async (tsconfigFile) =>
47
47
return tsconfig ;
48
48
} ;
49
49
50
- /** Wrapper for using typescript's CLI */
50
+ /**
51
+ * Wrapper for using typescript's CLI
52
+ * @param {string } tsconfigFile Optional absolute path to the tsconfig file
53
+ *
54
+ */
51
55
const tsc = async ( tsconfigFile , ...args ) =>
52
56
spawn ( 'tsc' , [ '-p' , await ensureTsconfig ( tsconfigFile ) , ...args ] ) ;
53
57
@@ -92,11 +96,14 @@ const test = async (additionalArgs) =>
92
96
] ) ;
93
97
} ;
94
98
95
- /** Export the types */
99
+ /** Generate the types into the lib folder */
96
100
const bundleTypes = async ( ) =>
97
101
{
98
- let tsconfigTypesFile = extensionConfig . tsconfigTypes ;
102
+ let tsconfigTypesFile = extensionConfig . tsconfigTypes
103
+ ? path . join ( process . cwd ( ) , extensionConfig . tsconfigTypes ) : null ;
99
104
105
+ // If no tsconfig types file is defined, we will create one
106
+ // based on the current tsconfig.json file
100
107
if ( ! tsconfigTypesFile )
101
108
{
102
109
const tsconfigFile = await ensureTsconfig ( ) ;
@@ -108,10 +115,15 @@ const bundleTypes = async () =>
108
115
...config ,
109
116
compilerOptions : {
110
117
...config . compilerOptions ,
118
+ // Just emit the declaration files only
111
119
declaration : true ,
112
120
emitDeclarationOnly : true ,
113
121
outDir : './lib' ,
122
+ // make sure we exclude anything, such as scripts,
123
+ // outside of the src folder to avoid lib/src/index.d.ts
124
+ rootDir : './src' ,
114
125
} ,
126
+ // Make sure to exclude any Jest test files
115
127
exclude : [ '**/*.test.ts' ]
116
128
} , null , 2 ) , 'utf8' ) ;
117
129
}
@@ -122,6 +134,7 @@ const bundleTypes = async () =>
122
134
}
123
135
finally
124
136
{
137
+ // Clean up if the tsconfig file was generated
125
138
if ( ! extensionConfig . tsconfigTypes )
126
139
{
127
140
await promises . unlink ( tsconfigTypesFile ) ;
0 commit comments