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

Close #605: Disable type check for test, start, build commands in CI #606

Merged
merged 16 commits into from
Jul 20, 2021
Merged
5 changes: 5 additions & 0 deletions .changeset/cyan-moose-judge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'modular-scripts': minor
---

Disable typechecking for modular start, test, build commands in CI environments
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ const ModuleNotFoundPlugin = require('react-dev-utils/ModuleNotFoundPlugin');
const ForkTsCheckerWebpackPlugin = require('react-dev-utils/ForkTsCheckerWebpackPlugin');
const typescriptFormatter = require('react-dev-utils/typescriptFormatter');
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');

const postcssNormalize = require('postcss-normalize');
const isCI = require('is-ci');

const appPackageJson = require(paths.appPackageJson);

Expand Down Expand Up @@ -634,8 +634,9 @@ module.exports = function (webpackEnv) {
// See https://github.com/cra-template/pwa/issues/13#issuecomment-722667270
maximumFileSizeToCacheInBytes: 5 * 1024 * 1024,
}),
// TypeScript type checking
// TypeScript type checking for non CI envs
LukeSheard marked this conversation as resolved.
Show resolved Hide resolved
useTypeScript &&
!isCI &&
new ForkTsCheckerWebpackPlugin({
typescript: resolve.sync('typescript', {
basedir: paths.appNodeModules,
Expand Down
5 changes: 4 additions & 1 deletion packages/modular-scripts/react-scripts/scripts/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const {
} = require('react-dev-utils/WebpackDevServerUtils');
const openBrowser = require('react-dev-utils/openBrowser');
const semver = require('semver');
const isCI = require('is-ci');

const paths = require('../config/paths');
const configFactory = require('../config/webpack.config');
const createDevServerConfig = require('../config/webpackDevServer.config');
Expand Down Expand Up @@ -83,7 +85,7 @@ checkBrowsers(paths.appPath, isInteractive)
const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
const appName = require(paths.appPackageJson).name;

const useTypeScript = fs.existsSync(paths.appTsConfig);
const useTypeScript = !isCI && fs.existsSync(paths.appTsConfig);
const tscCompileOnError = process.env.TSC_COMPILE_ON_ERROR === 'true';
const urls = prepareUrls(
protocol,
Expand All @@ -98,6 +100,7 @@ checkBrowsers(paths.appPath, isInteractive)
devServer.sockWrite(devServer.sockets, 'errors', errors),
};
// Create a webpack compiler that is configured with custom messages.
// Only run typecheck if not in CI env
const compiler = createCompiler({
appName,
config,
Expand Down
8 changes: 8 additions & 0 deletions packages/modular-scripts/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,14 @@ program
await port(relativePath);
});

program
.command('typecheck')
.description('Typechecks the entire project')
.action(async () => {
const { typecheck } = await import('./typecheck');
await typecheck();
});

void startupCheck()
.then(() => {
return program.parseAsync(process.argv);
Expand Down
12 changes: 12 additions & 0 deletions packages/modular-scripts/src/config/jest/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as fs from 'fs-extra';
import path from 'path';
import chalk from 'chalk';
import glob from 'glob';
import isCi from 'is-ci';
import type { Config } from '@jest/types';
import { defaults } from 'jest-config';
import getModularRoot from '../../utils/getModularRoot';
Expand Down Expand Up @@ -195,5 +196,16 @@ export function createJestConfig(
moduleNameMapper: mergedMapper,
});
}

// don't typecheck tests in CI
if (isCi) {
jestConfig.globals = {
'ts-jest': {
diagnostics: false,
isolatedModules: true,
LukeSheard marked this conversation as resolved.
Show resolved Hide resolved
},
};
}

return jestConfig;
}
13 changes: 13 additions & 0 deletions packages/modular-scripts/src/typecheck.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import isCI from 'is-ci';
import execa from 'execa';
import getModularRoot from './utils/getModularRoot';

export async function typecheck(): Promise<void> {
const options = ['--pretty'];
if (isCI) {
options.push('--noEmit');
}
await execa('tsc', options, {
LukeSheard marked this conversation as resolved.
Show resolved Hide resolved
cwd: getModularRoot(),
});
}