Skip to content

Commit

Permalink
[test] Test against typescript nightlies (mui#19857)
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon authored and EsoterikStare committed Mar 30, 2020
1 parent 98266f5 commit ba2521f
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
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);
});

0 comments on commit ba2521f

Please sign in to comment.