Skip to content

Commit 2123c7f

Browse files
committed
chore: Add cleanup comments
1 parent eb4c253 commit 2123c7f

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

lib/index.mjs

+17-4
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const ensureTsconfig = async (tsconfigFile) =>
3838
if (!(await pathExists(tsconfig)))
3939
{
4040
// 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)}"`
4242
+ ` not found but is required for linting and building.`));
4343

4444
process.exit(1);
@@ -47,7 +47,11 @@ const ensureTsconfig = async (tsconfigFile) =>
4747
return tsconfig;
4848
};
4949

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+
*/
5155
const tsc = async (tsconfigFile, ...args) =>
5256
spawn('tsc', ['-p', await ensureTsconfig(tsconfigFile), ...args]);
5357

@@ -92,11 +96,14 @@ const test = async (additionalArgs) =>
9296
]);
9397
};
9498

95-
/** Export the types */
99+
/** Generate the types into the lib folder */
96100
const bundleTypes = async () =>
97101
{
98-
let tsconfigTypesFile = extensionConfig.tsconfigTypes;
102+
let tsconfigTypesFile = extensionConfig.tsconfigTypes
103+
? path.join(process.cwd(), extensionConfig.tsconfigTypes) : null;
99104

105+
// If no tsconfig types file is defined, we will create one
106+
// based on the current tsconfig.json file
100107
if (!tsconfigTypesFile)
101108
{
102109
const tsconfigFile = await ensureTsconfig();
@@ -108,10 +115,15 @@ const bundleTypes = async () =>
108115
...config,
109116
compilerOptions: {
110117
...config.compilerOptions,
118+
// Just emit the declaration files only
111119
declaration: true,
112120
emitDeclarationOnly: true,
113121
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',
114125
},
126+
// Make sure to exclude any Jest test files
115127
exclude: ['**/*.test.ts']
116128
}, null, 2), 'utf8');
117129
}
@@ -122,6 +134,7 @@ const bundleTypes = async () =>
122134
}
123135
finally
124136
{
137+
// Clean up if the tsconfig file was generated
125138
if (!extensionConfig.tsconfigTypes)
126139
{
127140
await promises.unlink(tsconfigTypesFile);

0 commit comments

Comments
 (0)