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

[test] Test against typescript nightlies #19857

Merged
merged 1 commit into from
Feb 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
28 changes: 28 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,24 @@ jobs:
- run:
name: Tests TypeScript definitions
command: yarn typescript
test_types_next:
<<: *defaults
steps:
- checkout
- run:
name: Resolve typescript version
environment:
TYPESCRIPT_DIST_TAG: next
command: |
node scripts/use-typescript-dist-tag
# log a patch for maintainers who want to check out this change
git diff HEAD
- install_js
- run:
name: Tests TypeScript definitions
# we want to see errors in all packages.
# without --no-bail we only see at most a single failing package
command: yarn typescript --no-bail
test_browser:
<<: *defaults
steps:
Expand Down Expand Up @@ -215,3 +233,13 @@ workflows:
- test_unit
- test_browser
react-dist-tag: next
typescript-next:
triggers:
- schedule:
cron: '0 0 * * *'
filters:
branches:
only:
- master
jobs:
- test_types_next
54 changes: 54 additions & 0 deletions scripts/use-typescript-dist-tag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* Workaround for failing `yarn add -D -W typescript@next`
* See https://github.com/yarnpkg/yarn/issues/7935
*
* Given an environment variable called `TYPESCRIPT_DIST_TAG` fetch the corresponding
* version and make sure this version used in the worktree as well as in dtslint.
*
* If you work on this file:
* WARNING: This script can only use built-in modules since it has to run before
* `yarn install`
*/
const childProcess = require('child_process');
const fs = require('fs');
const os = require('os');
const path = require('path');
const { promisify } = require('util');

const exec = promisify(childProcess.exec);

async function main(distTag) {
if (typeof distTag !== 'string') {
throw new TypeError(`expected distTag: string but got '${distTag}'`);
}

if (distTag === 'stable') {
// eslint-disable-next-line no-console
console.log('nothing to do with stable');
return;
}

const { stdout: versions } = await exec(`npm dist-tag ls typescript ${distTag}`);
const tagMapping = versions.split('\n').find(mapping => {
return mapping.startsWith(`${distTag}: `);
});
if (tagMapping === undefined) {
throw new Error(`Could not find '${distTag}' in "${versions}"`);
}

const version = tagMapping.replace(`${distTag}: `, '');

const packageJsonPath = path.resolve(__dirname, '../package.json');
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, { encoding: 'utf8' }));

packageJson.devDependencies.typescript = version;
packageJson.resolutions['**/dtslint/typescript'] = version;

// CircleCI seemingly times out if it has a newline diff at the end
fs.writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}${os.EOL}`);
}

main(process.env.TYPESCRIPT_DIST_TAG).catch(error => {
console.error(error);
process.exit(1);
});