Skip to content

Commit

Permalink
chore: remove empty directories from build/ (#14550)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB authored Sep 20, 2023
1 parent d12cbf1 commit 76b0318
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

### Performance

- `[*]` [**BREAKING**] Bundle all of Jest's modules into `index.js` ([#12348](https://github.com/jestjs/jest/pull/12348))
- `[*]` [**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))

### Chore & Maintenance

Expand Down
35 changes: 29 additions & 6 deletions scripts/bundleTs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,19 @@ import {
ExtractorConfig,
} from '@microsoft/api-extractor';
import chalk from 'chalk';
import {glob} from 'glob';
import fs from 'graceful-fs';
import {sync as pkgDir} from 'pkg-dir';
import pkgDir from 'pkg-dir';
import prettier from 'prettier';
import {rimraf} from 'rimraf';
import {copyrightSnippet, getPackages} from './buildUtils.mjs';

const prettierConfig = prettier.resolveConfig.sync(
const prettierConfig = await prettier.resolveConfig(
fileURLToPath(import.meta.url).replace(/\.js$/, '.d.ts'),
);

const require = createRequire(import.meta.url);
const typescriptCompilerFolder = pkgDir(require.resolve('typescript'));
const typescriptCompilerFolder = await pkgDir(require.resolve('typescript'));

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

Expand Down Expand Up @@ -156,17 +157,39 @@ await Promise.all(

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

rimraf.sync(path.resolve(packageDir, 'build/**/*.d.ts'), {glob: true});
fs.rmSync(path.resolve(packageDir, 'dist/'), {
await rimraf(path.resolve(packageDir, 'build/**/*.d.ts'), {glob: true});
await fs.promises.rm(path.resolve(packageDir, 'dist/'), {
force: true,
recursive: true,
});
// this is invalid now, so remove it to not confuse `tsc`
fs.rmSync(path.resolve(packageDir, 'tsconfig.tsbuildinfo'), {
await fs.promises.rm(path.resolve(packageDir, 'tsconfig.tsbuildinfo'), {
force: true,
recursive: true,
});

const dirsInBuild = await glob('**/', {
cwd: path.resolve(packageDir, 'build'),
});

await Promise.all(
dirsInBuild
.filter(dir => dir !== '.')
// reverse to delete deep directories first
.reverse()
.map(async dir => {
const dirToDelete = path.resolve(packageDir, 'build', dir);
try {
await fs.promises.rmdir(dirToDelete);
} catch (error) {
// e.g. `jest-jasmine2/build/jasmine` is not empty - ignore those errors
if (error.code !== 'ENOTEMPTY') {
throw error;
}
}
}),
);

definitionFile = definitionFile.replace(/\r\n/g, '\n');

const hasNodeTypesReference = definitionFile.includes(
Expand Down

0 comments on commit 76b0318

Please sign in to comment.