Skip to content

Commit ab707b0

Browse files
authored
fix: ensure all packages correctly downlevel TS files (#9715)
1 parent 96aaf89 commit ab707b0

File tree

15 files changed

+155
-7
lines changed

15 files changed

+155
-7
lines changed

.github/workflows/nodejs.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ jobs:
4141
run: node scripts/build.js
4242
- name: run tsc
4343
run: yarn build:ts
44+
- name: verify ts 3.4 compatibility
45+
run: yarn verify-old-ts
4446
- name: run eslint
4547
run: yarn lint
4648
- name: run eslint on browser builds

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
### Fixes
66

7+
- `[*]` Verify all packages are properly downleveled for older versions of TypeScript
8+
79
### Chore & Maintenance
810

911
### Performance
@@ -12,7 +14,7 @@
1214

1315
### Fixes
1416

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

1820
## 25.2.1

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
"slash": "^3.0.0",
7878
"string-length": "^3.1.0",
7979
"strip-ansi": "^6.0.0",
80+
"tempy": "~0.3.0",
8081
"throat": "^5.0.0",
8182
"typescript": "^3.8.2",
8283
"webpack": "^4.28.4",
@@ -106,6 +107,7 @@
106107
"test-pretty-format-perf": "node packages/pretty-format/perf/test.js",
107108
"test-leak": "yarn jest -i --detectLeaks jest-mock jest-diff jest-repl",
108109
"test": "yarn lint && yarn jest",
110+
"verify-old-ts": "node ./scripts/verifyOldTs.js",
109111
"watch": "yarn build && node ./scripts/watch.js",
110112
"watch:ts": "yarn build:ts --watch"
111113
},

packages/jest-console/src/CustomConsole.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ export default class CustomConsole extends Console {
5151
);
5252
}
5353

54-
assert(value: unknown, message?: string | Error): asserts value {
54+
// use `asserts` when https://github.com/sandersn/downlevel-dts/issues/32 is fixed
55+
assert(value: unknown, message?: string | Error): void {
5556
try {
5657
assert(value, message);
5758
} catch (error) {

packages/jest-core/package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
"version": "25.2.2",
55
"main": "build/jest.js",
66
"types": "build/jest.d.ts",
7+
"typesVersions": {
8+
"<3.8": {
9+
"build/*": [
10+
"build/ts3.4/*"
11+
]
12+
}
13+
},
714
"dependencies": {
815
"@jest/console": "^25.2.1",
916
"@jest/reporters": "^25.2.1",

packages/jest-docblock/package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
},
99
"license": "MIT",
1010
"main": "build/index.js",
11+
"types": "build/index.d.ts",
12+
"typesVersions": {
13+
"<3.8": {
14+
"build/*": [
15+
"build/ts3.4/*"
16+
]
17+
}
18+
},
1119
"dependencies": {
1220
"detect-newline": "^3.0.0"
1321
},

packages/jest-phabricator/package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
"directory": "packages/jest-phabricator"
88
},
99
"types": "build/index.d.ts",
10+
"typesVersions": {
11+
"<3.8": {
12+
"build/*": [
13+
"build/ts3.4/*"
14+
]
15+
}
16+
},
1017
"dependencies": {
1118
"@jest/test-result": "^25.2.1"
1219
},

packages/jest-transform/package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
},
99
"license": "MIT",
1010
"main": "build/index.js",
11+
"types": "build/index.d.ts",
12+
"typesVersions": {
13+
"<3.8": {
14+
"build/*": [
15+
"build/ts3.4/*"
16+
]
17+
}
18+
},
1119
"dependencies": {
1220
"@babel/core": "^7.1.0",
1321
"@jest/types": "^25.2.1",

packages/jest-transform/src/types.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ export type Options = ShouldInstrumentOptions &
2424
isInternalModule: boolean;
2525
}>;
2626

27+
// extends directly after https://github.com/sandersn/downlevel-dts/issues/33 is fixed
28+
type SourceMapWithVersion = Omit<RawSourceMap, 'version'>;
29+
2730
// This is fixed in [email protected], but we can't upgrade yet since it's async
28-
interface FixedRawSourceMap extends Omit<RawSourceMap, 'version'> {
31+
interface FixedRawSourceMap extends SourceMapWithVersion {
2932
version: number;
3033
}
3134

packages/jest-types/src/Global.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,10 @@ export interface GlobalAdditions {
8383
spyOn: () => void;
8484
spyOnProperty: () => void;
8585
}
86-
export interface Global
87-
extends GlobalAdditions,
88-
Omit<NodeJS.Global, keyof GlobalAdditions> {
86+
87+
// extends directly after https://github.com/sandersn/downlevel-dts/issues/33 is fixed
88+
type NodeGlobalWithoutAdditions = Omit<NodeJS.Global, keyof GlobalAdditions>;
89+
90+
export interface Global extends GlobalAdditions, NodeGlobalWithoutAdditions {
8991
[extras: string]: any;
9092
}

packages/jest-watcher/package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
"description": "Delightful JavaScript Testing.",
44
"version": "25.2.1",
55
"main": "build/index.js",
6+
"types": "build/index.d.ts",
7+
"typesVersions": {
8+
"<3.8": {
9+
"build/*": [
10+
"build/ts3.4/*"
11+
]
12+
}
13+
},
614
"dependencies": {
715
"@jest/test-result": "^25.2.1",
816
"@jest/types": "^25.2.1",

packages/jest/package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
"version": "25.2.2",
55
"main": "build/jest.js",
66
"types": "build/jest.d.ts",
7+
"typesVersions": {
8+
"<3.8": {
9+
"build/*": [
10+
"build/ts3.4/*"
11+
]
12+
}
13+
},
714
"dependencies": {
815
"@jest/core": "^25.2.2",
916
"import-local": "^3.0.2",

scripts/buildTs.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,31 @@ try {
4444
);
4545
console.error(e.stack);
4646
process.exitCode = 1;
47+
return;
4748
}
4849

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

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

54+
packagesWithTs.forEach(pkgDir => {
55+
const pkg = require(pkgDir + '/package.json');
56+
57+
if (!pkg.types) {
58+
throw new Error(`Package ${pkg.name} is missing \`types\` field`);
59+
}
60+
61+
if (!pkg.typesVersions) {
62+
throw new Error(`Package ${pkg.name} is missing \`typesVersions\` field`);
63+
}
64+
65+
if (pkg.main.replace(/\.js$/, '.d.ts') !== pkg.types) {
66+
throw new Error(
67+
`\`main\` and \`types\` field of ${pkg.name} does not match`
68+
);
69+
}
70+
});
71+
5372
// we want to limit the number of processes we spawn
5473
const cpus = Math.max(1, os.cpus().length - 1);
5574

scripts/verifyOldTs.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
'use strict';
9+
10+
const fs = require('fs');
11+
const path = require('path');
12+
13+
const chalk = require('chalk');
14+
const execa = require('execa');
15+
const rimraf = require('rimraf');
16+
const tempy = require('tempy');
17+
18+
const jestDirectory = path.resolve(__dirname, '../packages/jest');
19+
20+
const tsConfig = {
21+
compilerOptions: {
22+
esModuleInterop: false,
23+
lib: ['es2018'],
24+
module: 'commonjs',
25+
moduleResolution: 'node',
26+
noEmit: true,
27+
strict: true,
28+
target: 'es5',
29+
},
30+
};
31+
const cwd = tempy.directory();
32+
33+
try {
34+
execa.sync('yarn', ['init', '--yes'], {cwd, stdio: 'inherit'});
35+
execa.sync('yarn', ['add', 'typescript@~3.4'], {cwd, stdio: 'inherit'});
36+
fs.writeFileSync(
37+
path.join(cwd, 'tsconfig.json'),
38+
JSON.stringify(tsConfig, null, 2)
39+
);
40+
fs.writeFileSync(
41+
path.join(cwd, 'index.ts'),
42+
`import jest = require('${jestDirectory}');`
43+
);
44+
execa.sync('yarn', ['tsc', '--project', '.'], {cwd, stdio: 'inherit'});
45+
46+
console.log(
47+
chalk.inverse.green(' Successfully compiled Jest with TypeScript 3.4 ')
48+
);
49+
} finally {
50+
rimraf.sync(cwd);
51+
}

yarn.lock

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4931,6 +4931,11 @@ crypto-browserify@^3.11.0:
49314931
randombytes "^2.0.0"
49324932
randomfill "^1.0.3"
49334933

4934+
crypto-random-string@^1.0.0:
4935+
version "1.0.0"
4936+
resolved "https://registry.yarnpkg.com/crypto-random-string/-/crypto-random-string-1.0.0.tgz#a230f64f568310e1498009940790ec99545bca7e"
4937+
integrity sha1-ojD2T1aDEOFJgAmUB5DsmVRbyn4=
4938+
49344939
[email protected], css-color-names@^0.0.4:
49354940
version "0.0.4"
49364941
resolved "https://registry.yarnpkg.com/css-color-names/-/css-color-names-0.0.4.tgz#808adc2e79cf84738069b646cb20ec27beb629e0"
@@ -13908,6 +13913,15 @@ tempfile@^2.0.0:
1390813913
temp-dir "^1.0.0"
1390913914
uuid "^3.0.1"
1391013915

13916+
tempy@~0.3.0:
13917+
version "0.3.0"
13918+
resolved "https://registry.yarnpkg.com/tempy/-/tempy-0.3.0.tgz#6f6c5b295695a16130996ad5ab01a8bd726e8bf8"
13919+
integrity sha512-WrH/pui8YCwmeiAoxV+lpRH9HpRtgBhSR2ViBPgpGb/wnYDzp21R4MN45fsCGvLROvY67o3byhJRYRONJyImVQ==
13920+
dependencies:
13921+
temp-dir "^1.0.0"
13922+
type-fest "^0.3.1"
13923+
unique-string "^1.0.0"
13924+
1391113925
terminal-link@^2.0.0:
1391213926
version "2.1.1"
1391313927
resolved "https://registry.yarnpkg.com/terminal-link/-/terminal-link-2.1.1.tgz#14a64a27ab3c0df933ea546fba55f2d078edc994"
@@ -14245,7 +14259,7 @@ type-fest@^0.11.0:
1424514259
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.11.0.tgz#97abf0872310fed88a5c466b25681576145e33f1"
1424614260
integrity sha512-OdjXJxnCN1AvyLSzeKIgXTXxV+99ZuXl3Hpo9XpJAv9MBcHrrJOQ5kV7ypXOuQie+AmWG25hLbiKdwYTifzcfQ==
1424714261

14248-
type-fest@^0.3.0:
14262+
type-fest@^0.3.0, type-fest@^0.3.1:
1424914263
version "0.3.1"
1425014264
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.3.1.tgz#63d00d204e059474fe5e1b7c011112bbd1dc29e1"
1425114265
integrity sha512-cUGJnCdr4STbePCgqNFbpVNCepa+kAVohJs1sLhxzdH+gnEoOd8VhbYa7pD3zZYGiURWM2xzEII3fQcRizDkYQ==
@@ -14411,6 +14425,13 @@ unique-slug@^2.0.0:
1441114425
dependencies:
1441214426
imurmurhash "^0.1.4"
1441314427

14428+
unique-string@^1.0.0:
14429+
version "1.0.0"
14430+
resolved "https://registry.yarnpkg.com/unique-string/-/unique-string-1.0.0.tgz#9e1057cca851abb93398f8b33ae187b99caec11a"
14431+
integrity sha1-nhBXzKhRq7kzmPizOuGHuZyuwRo=
14432+
dependencies:
14433+
crypto-random-string "^1.0.0"
14434+
1441414435
unist-util-is@^3.0.0:
1441514436
version "3.0.0"
1441614437
resolved "https://registry.yarnpkg.com/unist-util-is/-/unist-util-is-3.0.0.tgz#d9e84381c2468e82629e4a5be9d7d05a2dd324cd"

0 commit comments

Comments
 (0)