Skip to content

Commit

Permalink
chore: Add cleanup comments
Browse files Browse the repository at this point in the history
  • Loading branch information
bigtimebuddy committed Dec 19, 2024
1 parent eb4c253 commit 2123c7f
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions lib/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const ensureTsconfig = async (tsconfigFile) =>
if (!(await pathExists(tsconfig)))
{
// eslint-disable-next-line no-console
console.log(chalk.red(`${prefix} Error: TypeScript configuration file "${tsconfigFile}"`
console.log(chalk.red(`${prefix} Error: TypeScript configuration file "${path.basename(tsconfig)}"`
+ ` not found but is required for linting and building.`));

process.exit(1);
Expand All @@ -47,7 +47,11 @@ const ensureTsconfig = async (tsconfigFile) =>
return tsconfig;
};

/** Wrapper for using typescript's CLI */
/**
* Wrapper for using typescript's CLI
* @param {string} tsconfigFile Optional absolute path to the tsconfig file
*
*/
const tsc = async (tsconfigFile, ...args) =>
spawn('tsc', ['-p', await ensureTsconfig(tsconfigFile), ...args]);

Expand Down Expand Up @@ -92,11 +96,14 @@ const test = async (additionalArgs) =>
]);
};

/** Export the types */
/** Generate the types into the lib folder */
const bundleTypes = async () =>
{
let tsconfigTypesFile = extensionConfig.tsconfigTypes;
let tsconfigTypesFile = extensionConfig.tsconfigTypes
? path.join(process.cwd(), extensionConfig.tsconfigTypes) : null;

// If no tsconfig types file is defined, we will create one
// based on the current tsconfig.json file
if (!tsconfigTypesFile)
{
const tsconfigFile = await ensureTsconfig();
Expand All @@ -108,10 +115,15 @@ const bundleTypes = async () =>
...config,
compilerOptions: {
...config.compilerOptions,
// Just emit the declaration files only
declaration: true,
emitDeclarationOnly: true,
outDir: './lib',
// make sure we exclude anything, such as scripts,
// outside of the src folder to avoid lib/src/index.d.ts
rootDir: './src',
},
// Make sure to exclude any Jest test files
exclude: ['**/*.test.ts']
}, null, 2), 'utf8');
}
Expand All @@ -122,6 +134,7 @@ const bundleTypes = async () =>
}
finally
{
// Clean up if the tsconfig file was generated
if (!extensionConfig.tsconfigTypes)
{
await promises.unlink(tsconfigTypesFile);
Expand Down

0 comments on commit 2123c7f

Please sign in to comment.