Skip to content

Commit 76b0318

Browse files
authored
chore: remove empty directories from build/ (#14550)
1 parent d12cbf1 commit 76b0318

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
### Performance
1717

18-
- `[*]` [**BREAKING**] Bundle all of Jest's modules into `index.js` ([#12348](https://github.com/jestjs/jest/pull/12348))
18+
- `[*]` [**BREAKING**] Bundle all of Jest's modules into `index.js` ([#12348](https://github.com/jestjs/jest/pull/12348) & [#14550](https://github.com/jestjs/jest/pull/14550))
1919

2020
### Chore & Maintenance
2121

scripts/bundleTs.mjs

+29-6
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,19 @@ import {
1414
ExtractorConfig,
1515
} from '@microsoft/api-extractor';
1616
import chalk from 'chalk';
17+
import {glob} from 'glob';
1718
import fs from 'graceful-fs';
18-
import {sync as pkgDir} from 'pkg-dir';
19+
import pkgDir from 'pkg-dir';
1920
import prettier from 'prettier';
2021
import {rimraf} from 'rimraf';
2122
import {copyrightSnippet, getPackages} from './buildUtils.mjs';
2223

23-
const prettierConfig = prettier.resolveConfig.sync(
24+
const prettierConfig = await prettier.resolveConfig(
2425
fileURLToPath(import.meta.url).replace(/\.js$/, '.d.ts'),
2526
);
2627

2728
const require = createRequire(import.meta.url);
28-
const typescriptCompilerFolder = pkgDir(require.resolve('typescript'));
29+
const typescriptCompilerFolder = await pkgDir(require.resolve('typescript'));
2930

3031
const typesNodeReferenceDirective = '/// <reference types="node" />';
3132

@@ -156,17 +157,39 @@ await Promise.all(
156157

157158
let definitionFile = await fs.promises.readFile(filepath, 'utf8');
158159

159-
rimraf.sync(path.resolve(packageDir, 'build/**/*.d.ts'), {glob: true});
160-
fs.rmSync(path.resolve(packageDir, 'dist/'), {
160+
await rimraf(path.resolve(packageDir, 'build/**/*.d.ts'), {glob: true});
161+
await fs.promises.rm(path.resolve(packageDir, 'dist/'), {
161162
force: true,
162163
recursive: true,
163164
});
164165
// this is invalid now, so remove it to not confuse `tsc`
165-
fs.rmSync(path.resolve(packageDir, 'tsconfig.tsbuildinfo'), {
166+
await fs.promises.rm(path.resolve(packageDir, 'tsconfig.tsbuildinfo'), {
166167
force: true,
167168
recursive: true,
168169
});
169170

171+
const dirsInBuild = await glob('**/', {
172+
cwd: path.resolve(packageDir, 'build'),
173+
});
174+
175+
await Promise.all(
176+
dirsInBuild
177+
.filter(dir => dir !== '.')
178+
// reverse to delete deep directories first
179+
.reverse()
180+
.map(async dir => {
181+
const dirToDelete = path.resolve(packageDir, 'build', dir);
182+
try {
183+
await fs.promises.rmdir(dirToDelete);
184+
} catch (error) {
185+
// e.g. `jest-jasmine2/build/jasmine` is not empty - ignore those errors
186+
if (error.code !== 'ENOTEMPTY') {
187+
throw error;
188+
}
189+
}
190+
}),
191+
);
192+
170193
definitionFile = definitionFile.replace(/\r\n/g, '\n');
171194

172195
const hasNodeTypesReference = definitionFile.includes(

0 commit comments

Comments
 (0)