mirror of
https://github.com/cypress-io/cypress.git
synced 2026-04-27 02:14:36 -05:00
Added TypeScript type checker + Fixed type errors. (#5780)
* Added type_check.js
* Now checks cli, too.
* Ignored a line that should fail.
* Removed cli shims and post-install.
* Updated @types/chai to fix type error.
* Fixed keyboard type errors.
* Updated typescript to 3.7.2 to fix window.Node error in dom/document.
* Removed tsconfig errors that caused type errors in reporter and runner.
* Ignored error test by dtslint. Becaust it's done by type_check.js
* Added npm command.
* Added it to CI.
* Added skipLibCheck option.
* Removed checking chai folder existence.
copy of chai is unnecessary.
* Added 'ignore-progress' option for CI.
* Show success message when type check is finished successfully.
* Use ignore-progress option on CI.
* Moved type definitions from devDependencies to dependencies.
* Fixed new type errors after rebase.
* Updated type errors.
* Removed cli. Because its types are checked by dtslint.
* type_check -> type-check for consistency.
* Updated json-schema.
* Updated blob-util.
* Fix wrong command in CI.
* Revert "Updated blob-util."
This reverts commit e46549af54.
Because it's a breaking change.
* Remove copies of @types if exists.
* Fix stream buffer type error.
* Fix type errors in ui-components.
* Fix type failure.
* Fix lint error.
* Fix type errors
* Regenerate yarn.lock
* Fix type error.
* Fix type failures.
Co-authored-by: Jennifer Shehane <jennifer@cypress.io>
Co-authored-by: Gleb Bahmutov <gleb.bahmutov@gmail.com>
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const execa = require('execa')
|
||||
const Listr = require('listr')
|
||||
const commander = require('commander')
|
||||
|
||||
const program = new commander.Command()
|
||||
|
||||
program.usage('[options]')
|
||||
|
||||
program
|
||||
.option('-p, --project <projects>', 'projects to check types (separated by commas)')
|
||||
.option('--skip-lib-check', 'skip type checking of all declaration files (*.d.ts)')
|
||||
.option('--ignore-progress', 'do not show progress')
|
||||
.action((...args) => {
|
||||
const projects = []
|
||||
const packageRoot = path.join(__dirname, '../packages')
|
||||
const getPackagePath = (name) => {
|
||||
if (name !== 'cli') {
|
||||
return path.join(packageRoot, name)
|
||||
}
|
||||
|
||||
throw new Error(`type-check command doesn't check cli types. Use "npm run dtslint" in "cli" directory instead.`)
|
||||
}
|
||||
const addProject = (name) => {
|
||||
return projects.push({
|
||||
name,
|
||||
path: getPackagePath(name),
|
||||
})
|
||||
}
|
||||
|
||||
if (program.project) {
|
||||
program.project.split(',').forEach((p) => addProject(p))
|
||||
} else {
|
||||
fs.readdirSync(packageRoot).forEach((file) => {
|
||||
const packagePath = getPackagePath(file)
|
||||
|
||||
if (fs.lstatSync(packagePath).isDirectory() && fs.existsSync(path.join(packagePath, 'tsconfig.json'))) {
|
||||
addProject(file)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const options = ['--noEmit', '--pretty']
|
||||
|
||||
if (program.skipLibCheck) {
|
||||
options.push('--skipLibCheck')
|
||||
}
|
||||
|
||||
const tasks = new Listr(projects.map((proj) => {
|
||||
return {
|
||||
title: proj.name,
|
||||
task: () => {
|
||||
const cwd = proj.path
|
||||
const tsc = require.resolve('typescript/bin/tsc')
|
||||
|
||||
return execa(tsc, options, {
|
||||
cwd,
|
||||
}).catch((err) => {
|
||||
throw {
|
||||
name: proj.name,
|
||||
err,
|
||||
}
|
||||
})
|
||||
},
|
||||
}
|
||||
}), {
|
||||
concurrent: 4,
|
||||
exitOnError: false,
|
||||
renderer: program.ignoreProgress ? 'silent' : 'default',
|
||||
})
|
||||
|
||||
tasks.run()
|
||||
.then(() => {
|
||||
log('')
|
||||
log('Type check passed successfully.')
|
||||
})
|
||||
.catch((err) => {
|
||||
process.exitCode = 1
|
||||
|
||||
err.errors.forEach((e) => {
|
||||
log('')
|
||||
log(`${e.name} failed\n${e.err.stdout}`)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
const log = (msg) => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(msg)
|
||||
}
|
||||
|
||||
program.parse(process.argv)
|
||||
Reference in New Issue
Block a user