Skip to content

Commit

Permalink
chore: do not bundle type definitions for packages which have only on…
Browse files Browse the repository at this point in the history
…e `.d.ts` file (jestjs#12718)
  • Loading branch information
mrazauskas authored and F3n67u committed May 2, 2022
1 parent 7bee3a1 commit df7bfec
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions scripts/bundleTs.mjs
Expand Up @@ -39,8 +39,16 @@ const copyrightSnippet = `
(async () => {
const packages = getPackages();

const packagesWithTs = packages.filter(p =>
fs.existsSync(path.resolve(p.packageDir, 'tsconfig.json')),
const isTsPackage = p =>
fs.existsSync(path.resolve(p.packageDir, 'tsconfig.json'));

const hasMoreThanOneDefinitionFile = p =>
fs
.readdirSync(path.resolve(p.packageDir, 'build'))
.filter(f => f.endsWith('.d.ts')).length > 1;

const packagesToBundle = packages.filter(
p => isTsPackage(p) && hasMoreThanOneDefinitionFile(p),
);

const typesNodeReferenceDirective = '/// <reference types="node" />';
Expand Down Expand Up @@ -115,7 +123,7 @@ const copyrightSnippet = `
let compilerState;

await Promise.all(
packagesWithTs.map(async ({packageDir, pkg}) => {
packagesToBundle.map(async ({packageDir, pkg}) => {
const configFile = path.resolve(packageDir, 'api-extractor.json');

await fs.promises.writeFile(
Expand All @@ -134,7 +142,7 @@ const copyrightSnippet = `

if (!compilerState) {
compilerState = CompilerState.create(extractorConfig, {
additionalEntryPoints: packagesWithTs.map(({pkg, packageDir}) =>
additionalEntryPoints: packagesToBundle.map(({pkg, packageDir}) =>
path.resolve(packageDir, pkg.types),
),
typescriptCompilerFolder,
Expand Down

0 comments on commit df7bfec

Please sign in to comment.