Skip to content

Commit 49e1adf

Browse files
authored
[test] Test against typescript nightlies (#19857)
1 parent 9532f26 commit 49e1adf

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

.circleci/config.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,24 @@ jobs:
141141
- run:
142142
name: Tests TypeScript definitions
143143
command: yarn typescript
144+
test_types_next:
145+
<<: *defaults
146+
steps:
147+
- checkout
148+
- run:
149+
name: Resolve typescript version
150+
environment:
151+
TYPESCRIPT_DIST_TAG: next
152+
command: |
153+
node scripts/use-typescript-dist-tag
154+
# log a patch for maintainers who want to check out this change
155+
git diff HEAD
156+
- install_js
157+
- run:
158+
name: Tests TypeScript definitions
159+
# we want to see errors in all packages.
160+
# without --no-bail we only see at most a single failing package
161+
command: yarn typescript --no-bail
144162
test_browser:
145163
<<: *defaults
146164
steps:
@@ -215,3 +233,13 @@ workflows:
215233
- test_unit
216234
- test_browser
217235
react-dist-tag: next
236+
typescript-next:
237+
triggers:
238+
- schedule:
239+
cron: '0 0 * * *'
240+
filters:
241+
branches:
242+
only:
243+
- master
244+
jobs:
245+
- test_types_next

scripts/use-typescript-dist-tag.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* Workaround for failing `yarn add -D -W typescript@next`
3+
* See https://github.com/yarnpkg/yarn/issues/7935
4+
*
5+
* Given an environment variable called `TYPESCRIPT_DIST_TAG` fetch the corresponding
6+
* version and make sure this version used in the worktree as well as in dtslint.
7+
*
8+
* If you work on this file:
9+
* WARNING: This script can only use built-in modules since it has to run before
10+
* `yarn install`
11+
*/
12+
const childProcess = require('child_process');
13+
const fs = require('fs');
14+
const os = require('os');
15+
const path = require('path');
16+
const { promisify } = require('util');
17+
18+
const exec = promisify(childProcess.exec);
19+
20+
async function main(distTag) {
21+
if (typeof distTag !== 'string') {
22+
throw new TypeError(`expected distTag: string but got '${distTag}'`);
23+
}
24+
25+
if (distTag === 'stable') {
26+
// eslint-disable-next-line no-console
27+
console.log('nothing to do with stable');
28+
return;
29+
}
30+
31+
const { stdout: versions } = await exec(`npm dist-tag ls typescript ${distTag}`);
32+
const tagMapping = versions.split('\n').find(mapping => {
33+
return mapping.startsWith(`${distTag}: `);
34+
});
35+
if (tagMapping === undefined) {
36+
throw new Error(`Could not find '${distTag}' in "${versions}"`);
37+
}
38+
39+
const version = tagMapping.replace(`${distTag}: `, '');
40+
41+
const packageJsonPath = path.resolve(__dirname, '../package.json');
42+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, { encoding: 'utf8' }));
43+
44+
packageJson.devDependencies.typescript = version;
45+
packageJson.resolutions['**/dtslint/typescript'] = version;
46+
47+
// CircleCI seemingly times out if it has a newline diff at the end
48+
fs.writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}${os.EOL}`);
49+
}
50+
51+
main(process.env.TYPESCRIPT_DIST_TAG).catch(error => {
52+
console.error(error);
53+
process.exit(1);
54+
});

0 commit comments

Comments
 (0)