Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure all packages correctly downlevel TS files #9715

Merged
merged 6 commits into from
Mar 26, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### Fixes

- `[*]` Verify all packages are properly downleveled for older versions of TypeScript

### Chore & Maintenance

### Performance
Expand All @@ -12,7 +14,7 @@

### Fixes

- `[jest-environment-node]` Remove `getVmContext` from Node env on older versions of Node ([#9706](https://github.com/facebook/jest/pull/9706))
- `[jest-environment-node]` Remove `getVmContext` from Node env on older versions of Node ([#9708](https://github.com/facebook/jest/pull/9708))
- `[jest-runtime]` Return constructable class from `require('module')` ([#9711](https://github.com/facebook/jest/pull/9711))

## 25.2.1
Expand Down
3 changes: 2 additions & 1 deletion packages/jest-console/src/CustomConsole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ export default class CustomConsole extends Console {
);
}

assert(value: unknown, message?: string | Error): asserts value {
// use `asserts` when https://github.com/sandersn/downlevel-dts/issues/32 is fixed
assert(value: unknown, message?: string | Error): void {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try {
assert(value, message);
} catch (error) {
Expand Down
7 changes: 7 additions & 0 deletions packages/jest-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
"version": "25.2.2",
"main": "build/jest.js",
"types": "build/jest.d.ts",
"typesVersions": {
"<3.8": {
"build/*": [
"build/ts3.4/*"
]
}
},
"dependencies": {
"@jest/console": "^25.2.1",
"@jest/reporters": "^25.2.1",
Expand Down
8 changes: 8 additions & 0 deletions packages/jest-docblock/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
},
"license": "MIT",
"main": "build/index.js",
"types": "build/index.d.ts",
"typesVersions": {
"<3.8": {
"build/*": [
"build/ts3.4/*"
]
}
},
"dependencies": {
"detect-newline": "^3.0.0"
},
Expand Down
7 changes: 7 additions & 0 deletions packages/jest-phabricator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
"directory": "packages/jest-phabricator"
},
"types": "build/index.d.ts",
"typesVersions": {
"<3.8": {
"build/*": [
"build/ts3.4/*"
]
}
},
"dependencies": {
"@jest/test-result": "^25.2.1"
},
Expand Down
8 changes: 8 additions & 0 deletions packages/jest-transform/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
},
"license": "MIT",
"main": "build/index.js",
"types": "build/index.d.ts",
"typesVersions": {
"<3.8": {
"build/*": [
"build/ts3.4/*"
]
}
},
"dependencies": {
"@babel/core": "^7.1.0",
"@jest/types": "^25.2.1",
Expand Down
5 changes: 4 additions & 1 deletion packages/jest-transform/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ export type Options = ShouldInstrumentOptions &
isInternalModule: boolean;
}>;

// extends directly after https://github.com/sandersn/downlevel-dts/issues/33 is fixed
type SourceMapWithVersion = Omit<RawSourceMap, 'version'>;

// This is fixed in source-map@0.7.x, but we can't upgrade yet since it's async
interface FixedRawSourceMap extends Omit<RawSourceMap, 'version'> {
interface FixedRawSourceMap extends SourceMapWithVersion {
version: number;
}

Expand Down
8 changes: 5 additions & 3 deletions packages/jest-types/src/Global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,10 @@ export interface GlobalAdditions {
spyOn: () => void;
spyOnProperty: () => void;
}
export interface Global
extends GlobalAdditions,
Omit<NodeJS.Global, keyof GlobalAdditions> {

// extends directly after https://github.com/sandersn/downlevel-dts/issues/33 is fixed
type NodeGlobalWithoutAdditions = Omit<NodeJS.Global, keyof GlobalAdditions>;

export interface Global extends GlobalAdditions, NodeGlobalWithoutAdditions {
[extras: string]: any;
}
8 changes: 8 additions & 0 deletions packages/jest-watcher/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
"description": "Delightful JavaScript Testing.",
"version": "25.2.1",
"main": "build/index.js",
"types": "build/index.d.ts",
"typesVersions": {
"<3.8": {
"build/*": [
"build/ts3.4/*"
]
}
},
"dependencies": {
"@jest/test-result": "^25.2.1",
"@jest/types": "^25.2.1",
Expand Down
7 changes: 7 additions & 0 deletions packages/jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
"version": "25.2.2",
"main": "build/jest.js",
"types": "build/jest.d.ts",
"typesVersions": {
"<3.8": {
"build/*": [
"build/ts3.4/*"
]
}
},
"dependencies": {
"@jest/core": "^25.2.2",
"import-local": "^3.0.2",
Expand Down
19 changes: 19 additions & 0 deletions scripts/buildTs.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,31 @@ try {
);
console.error(e.stack);
process.exitCode = 1;
return;
}

const downlevelArgs = ['--silent', 'downlevel-dts', 'build', 'build/ts3.4'];

console.log(chalk.inverse(' Downleveling TypeScript definition files '));

packagesWithTs.forEach(pkgDir => {
const pkg = require(pkgDir + '/package.json');

if (!pkg.types) {
throw new Error(`Package ${pkg.name} is missing \`types\` field`);
}

if (!pkg.typesVersions) {
throw new Error(`Package ${pkg.name} is missing \`typesVersions\` field`);
}

if (pkg.main.replace(/\.js$/, '.d.ts') !== pkg.types) {
throw new Error(
`\`main\` and \`types\` field of ${pkg.name} does not match`
);
}
});

// we want to limit the number of processes we spawn
const cpus = Math.max(1, os.cpus().length - 1);

Expand Down