Files
cypress/cli/lib/exec/open.ts
Bill Glesias 3481d1acaf chore: refactor cypress/cli to TypeScript (#32063)
* migrate cli scripts to TypeScript

* convert all javascript source files in the CLI to TypeScript

rebase into first

* chore: refactor all tests to TypeScript

rebase into second

* add npmignore for cli for typescript files

* update build process

* fix publically available exports

* Fix cy-in-cy tests

* add ts-expect-error to failing files

* fix projectConfigIpc failures as there are now multiple installs of tsx

* fix after-pack hook

* fix binary script

* chore: update publish binary to account for CLI being an ESModule compiled down to CommonJS

* does this work?

* fix the verify spec by making the listr2 renderer silent as it behaves differently since the refactor and is printing non deterministic outputs into our tests that do not have a large impact on the area we are testing and mostly served to actually test the renders of the listr2 framework itself

* empty commit

* additional refactor to code to remove strange any typing and exporting

* bump cache and build binaries

* fix CLI exports to keep backwards compatibility

* fix unit-tests

* turn on mac jobs

* fix group name rename in CLI

* remove babel deps from cli and explicitly install typescript

* address feedback from code review

* dont just falsy check results and instead explicitly check for null or undefined

* add ts-expect-error

* additional pass on cleaning up dynamic require / import from global lib references

* annotate ts-expect-errors with reason for why error is expected

* add rest of ts-expect-error comments

* removing hardcoded branch to publish binary chore/migrate_cli_to_typescript
2025-09-02 17:52:45 -04:00

107 lines
2.4 KiB
TypeScript

import Debug from 'debug'
import util from '../util'
import spawn from './spawn'
import verifyModule from '../tasks/verify'
import { processTestingType, checkConfigFile } from './shared'
import { exitWithError } from '../errors'
const debug = Debug('cypress:cli')
/**
* Maps options collected by the CLI
* and forms list of CLI arguments to the server.
*
* Note: there is lightweight validation, with errors
* thrown synchronously.
*
* @returns {string[]} list of CLI arguments
*/
export const processOpenOptions = (options: any = {}): string[] => {
// In addition to setting the project directory, setting the project option
// here ultimately decides whether cypress is run in global mode or not.
// It's first based off whether it's installed globally by npm/yarn (-g).
// A global install can be overridden by the --project flag, putting Cypress
// in project mode. A non-global install can be overridden by the --global
// flag, putting it in global mode.
if (!util.isInstalledGlobally() && !options.global && !options.project) {
options.project = process.cwd()
}
const args: string[] = []
if (options.config) {
args.push('--config', options.config)
}
if (options.configFile !== undefined) {
checkConfigFile(options)
args.push('--config-file', options.configFile)
}
if (options.browser) {
args.push('--browser', options.browser)
}
if (options.env) {
args.push('--env', options.env)
}
if (options.port) {
args.push('--port', options.port)
}
if (options.project) {
args.push('--project', options.project)
}
if (options.global) {
args.push('--global', options.global)
}
if (options.inspect) {
args.push('--inspect')
}
if (options.inspectBrk) {
args.push('--inspectBrk')
}
args.push(...processTestingType(options))
debug('opening from options %j', options)
debug('command line arguments %j', args)
return args
}
export const start = (options: any = {}): any => {
function open (): any {
try {
const args = processOpenOptions(options)
return spawn.start(args, {
dev: options.dev,
detached: Boolean(options.detached),
})
} catch (err: any) {
if (err.details) {
return exitWithError(err.details)()
}
throw err
}
}
if (options.dev) {
return open()
}
return verifyModule.start()
.then(open)
}
export default {
start,
processOpenOptions,
}