Skip to content

Commit

Permalink
chore: ensure all exported files have a consistent filename
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Feb 8, 2022
1 parent 55caeb7 commit a40c5dc
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 13 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -15,6 +15,8 @@
### Chore & Maintenance

- `[*]` Avoid anonymous default exports ([#12313](https://github.com/facebook/jest/pull/12313))
- `[@jest/core]` Use `index.ts` instead of `jest.ts` as main export ([#12329](https://github.com/facebook/jest/pull/12329))
- `[jest]` Use `index.ts` instead of `jest.ts` as main export ([#12329](https://github.com/facebook/jest/pull/12329))

### Performance

Expand Down
8 changes: 4 additions & 4 deletions packages/jest-core/package.json
Expand Up @@ -2,12 +2,12 @@
"name": "@jest/core",
"description": "Delightful JavaScript Testing.",
"version": "27.5.0",
"main": "./build/jest.js",
"types": "./build/jest.d.ts",
"main": "./build/index.js",
"types": "./build/index.d.ts",
"exports": {
".": {
"types": "./build/jest.d.ts",
"default": "./build/jest.js"
"types": "./build/index.d.ts",
"default": "./build/index.js"
},
"./package.json": "./package.json"
},
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions packages/jest/package.json
Expand Up @@ -2,12 +2,12 @@
"name": "jest",
"description": "Delightful JavaScript Testing.",
"version": "27.5.0",
"main": "./build/jest.js",
"types": "./build/jest.d.ts",
"main": "./build/index.js",
"types": "./build/index.d.ts",
"exports": {
".": {
"types": "./build/jest.d.ts",
"default": "./build/jest.js"
"types": "./build/index.d.ts",
"default": "./build/index.js"
},
"./package.json": "./package.json",
"./bin/jest": "./bin/jest.js"
Expand Down
File renamed without changes.
32 changes: 27 additions & 5 deletions scripts/buildUtils.js
Expand Up @@ -31,16 +31,19 @@ module.exports.getPackages = function getPackages() {
return packages.map(packageDir => {
const pkg = readPkg({cwd: packageDir});

assert.ok(pkg.engines, `Engine requirement in ${pkg.name} should exist`);
assert.ok(pkg.engines, `Engine requirement in "${pkg.name}" should exist`);

assert.strictEqual(
pkg.engines.node,
// TODO: remove special casing for Jest 28
pkg.name === 'jest-worker' ? '>= 10.13.0' : nodeEngineRequirement,
`Engine requirement in ${pkg.name} should match root`,
`Engine requirement in "${pkg.name}" should match root`,
);

assert.ok(pkg.exports, `Package ${pkg.name} is missing \`exports\` field`);
assert.ok(
pkg.exports,
`Package "${pkg.name}" is missing \`exports\` field`,
);
assert.deepStrictEqual(
pkg.exports,
{
Expand Down Expand Up @@ -69,16 +72,35 @@ module.exports.getPackages = function getPackages() {
? {'./ConvertAnsi': './build/plugins/ConvertAnsi.js'}
: {}),
},
`Package ${pkg.name} does not export correct files`,
`Package "${pkg.name}" does not export correct files`,
);

if (pkg.types) {
assert.strictEqual(
pkg.main,
'./build/index.js',
`Package "${pkg.name}" should have "./build/index.js" as main`,
);
assert.strictEqual(
pkg.types,
'./build/index.d.ts',
`Package "${pkg.name}" should have "./build/index.d.ts" as types`,
);
} else {
assert.strictEqual(
pkg.main,
'./index.js',
`Package "${pkg.name}" should have "./index.js" as main`,
);
}

if (pkg.bin) {
Object.entries(pkg.bin).forEach(([binName, binPath]) => {
const fullBinPath = path.resolve(packageDir, binPath);

if (!fs.existsSync(fullBinPath)) {
throw new Error(
`Binary in package ${pkg.name} with name "${binName}" at ${binPath} does not exist`,
`Binary in package "${pkg.name}" with name "${binName}" at ${binPath} does not exist`,
);
}
});
Expand Down

0 comments on commit a40c5dc

Please sign in to comment.