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

chore: run typescript build as part of typecheck, not normal build #7855

Merged
merged 3 commits into from
Feb 13, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

### Chore & Maintenance

- `[*]`: Setup building, linting and testing of TypeScript ([#7808](https://github.com/facebook/jest/pull/7808))
- `[*]`: Setup building, linting and testing of TypeScript ([#7808](https://github.com/facebook/jest/pull/7808), [#7855](https://github.com/facebook/jest/pull/7855))
- `[pretty-format]`: Migrate to TypeScript ([#7809](https://github.com/facebook/jest/pull/7809))
- `[diff-sequences]`: Migrate to Typescript ([#7820](https://github.com/facebook/jest/pull/7820))
- `[jest-get-type]`: Migrate to TypeScript ([#7818](https://github.com/facebook/jest/pull/7818))
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@
"lint:md": "yarn --silent lint:md:ci --fix",
"lint:md:ci": "prettylint '**/*.{md,yml,yaml}' --ignore-path .gitignore",
"postinstall": "opencollective postinstall && yarn build",
"publish": "yarn build-clean && yarn build && lerna publish --silent",
"publish": "yarn build-clean && yarn typecheck && yarn build && lerna publish --silent",
SimenB marked this conversation as resolved.
Show resolved Hide resolved
"test-ci-es5-build-in-browser": "karma start --single-run",
"test-ci": "yarn jest-coverage -i --config jest.config.ci.js && yarn test-leak && node scripts/mapCoverage.js && codecov",
"test-ci-partial": "yarn jest -i --config jest.config.ci.js",
"test-pretty-format-perf": "node packages/pretty-format/perf/test.js",
"test-leak": "yarn jest -i --detectLeaks jest-mock jest-diff jest-repl",
"test": "yarn typecheck && yarn lint && yarn jest",
"typecheck": "flow check --include-warnings",
"typecheck": "node scripts/buildTs.js && flow check --include-warnings",
"watch": "yarn build && node ./scripts/watch.js"
},
"workspaces": {
Expand Down
30 changes: 1 addition & 29 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,14 @@ const fs = require('fs');
const path = require('path');
const glob = require('glob');
const mkdirp = require('mkdirp');
const execa = require('execa');

const babel = require('@babel/core');
const chalk = require('chalk');
const micromatch = require('micromatch');
const prettier = require('prettier');
const stringLength = require('string-length');
const getPackages = require('./getPackages');
const {getPackages, adjustToTerminalWidth, OK} = require('./buildUtils');
const browserBuild = require('./browserBuild');

const OK = chalk.reset.inverse.bold.green(' DONE ');
const SRC_DIR = 'src';
const BUILD_DIR = 'build';
const BUILD_ES5_DIR = 'build-es5';
Expand All @@ -51,20 +48,6 @@ const prettierConfig = prettier.resolveConfig.sync(__filename);
prettierConfig.trailingComma = 'none';
prettierConfig.parser = 'babel';

const adjustToTerminalWidth = str => {
const columns = process.stdout.columns || 80;
const WIDTH = columns - stringLength(OK) + 1;
const strs = str.match(new RegExp(`(.{1,${WIDTH}})`, 'g'));
let lastString = strs[strs.length - 1];
if (lastString.length < WIDTH) {
lastString += Array(WIDTH - lastString.length).join(chalk.dim('.'));
}
return strs
.slice(0, -1)
.concat(lastString)
.join('\n');
};

function getPackageName(file) {
return path.relative(PACKAGES_DIR, file).split(path.sep)[0];
}
Expand Down Expand Up @@ -191,21 +174,10 @@ function buildFile(file, silent) {

const files = process.argv.slice(2);

function compileTypes(packages) {
const packageWithTs = packages.filter(p =>
fs.existsSync(path.resolve(p, 'tsconfig.json'))
);

execa.sync('tsc', ['-b', ...packageWithTs], {stdio: 'inherit'});
}

if (files.length) {
files.forEach(buildFile);
} else {
const packages = getPackages();
process.stdout.write(chalk.inverse(' Typechecking \n'));
compileTypes(packages);
process.stdout.write(`${OK}\n\n`);
process.stdout.write(chalk.inverse(' Building packages \n'));
packages.forEach(buildNodePackage);
process.stdout.write('\n');
Expand Down
38 changes: 38 additions & 0 deletions scripts/buildTs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

const fs = require('fs');
const path = require('path');

const chalk = require('chalk');
const execa = require('execa');
const {getPackages, adjustToTerminalWidth, OK} = require('./buildUtils');

const packages = getPackages();

const packagesWithTs = packages.filter(p =>
fs.existsSync(path.resolve(p, 'tsconfig.json'))
);

const args = ['-b', ...packagesWithTs, ...process.argv.slice(2)];

console.log(chalk.inverse('Building TypeScript definition files'));
process.stdout.write(adjustToTerminalWidth('Building\n'));

try {
execa.sync('tsc', args, {stdio: 'inherit'});
process.stdout.write(`${OK}\n`);
} catch (e) {
process.stdout.write('\n');
console.error(
chalk.inverse.red('Unable to build TypeScript definition files')
);
console.error(e.stack);
process.exitCode = 1;
}
39 changes: 39 additions & 0 deletions scripts/buildUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

const fs = require('fs');
const path = require('path');
const chalk = require('chalk');
const stringLength = require('string-length');

const PACKAGES_DIR = path.resolve(__dirname, '../packages');

const OK = chalk.reset.inverse.bold.green(' DONE ');

// Get absolute paths of all directories under packages/*
module.exports.getPackages = function getPackages() {
return fs
.readdirSync(PACKAGES_DIR)
.map(file => path.resolve(PACKAGES_DIR, file))
.filter(f => fs.lstatSync(path.resolve(f)).isDirectory());
};

module.exports.adjustToTerminalWidth = function adjustToTerminalWidth(str) {
const columns = process.stdout.columns || 80;
const WIDTH = columns - stringLength(OK) + 1;
const strs = str.match(new RegExp(`(.{1,${WIDTH}})`, 'g'));
let lastString = strs[strs.length - 1];
if (lastString.length < WIDTH) {
lastString += Array(WIDTH - lastString.length).join(chalk.dim('.'));
}
return strs
.slice(0, -1)
.concat(lastString)
.join('\n');
};

module.exports.OK = OK;
19 changes: 0 additions & 19 deletions scripts/getPackages.js

This file was deleted.

7 changes: 0 additions & 7 deletions scripts/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const fs = require('fs');
const {execSync} = require('child_process');
const path = require('path');
const chalk = require('chalk');
const execa = require('execa');
const getPackages = require('./getPackages');

const BUILD_CMD = `node ${path.resolve(__dirname, './build.js')}`;
Expand Down Expand Up @@ -57,12 +56,6 @@ packages.forEach(p => {
}
});

const packageWithTs = packages.filter(p =>
fs.existsSync(path.resolve(p, 'tsconfig.json'))
);

execa('tsc', ['-b', ...packageWithTs, '--watch'], {stdio: 'inherit'});

setInterval(() => {
const files = Array.from(filesToBuild.keys());
if (files.length) {
Expand Down