Skip to content

Commit

Permalink
refactor: remove Ramda (#18723)
Browse files Browse the repository at this point in the history
  • Loading branch information
tgriesser authored Nov 1, 2021
1 parent 4cb97b3 commit c0d781d
Show file tree
Hide file tree
Showing 45 changed files with 205 additions and 191 deletions.
16 changes: 10 additions & 6 deletions cli/lib/cli.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// @ts-check
const _ = require('lodash')
const R = require('ramda')
const commander = require('commander')
const { stripIndent } = require('common-tags')
const logSymbols = require('log-symbols')
Expand Down Expand Up @@ -279,12 +278,17 @@ const castCypressRunOptions = (opts) => {
// only properties that have type "string | false" in our TS definition
// require special handling, because CLI parsing takes care of purely
// boolean arguments
const result = R.evolve({
port: coerceAnyStringToInt,
configFile: coerceFalseOrString,
})(opts)
const castOpts = { ...opts }

return result
if (_.has(opts, 'port')) {
castOpts.port = coerceAnyStringToInt(opts.port)
}

if (_.has(opts, 'configFile')) {
castOpts.configFile = coerceFalseOrString(opts.configFile)
}

return castOpts
}

module.exports = {
Expand Down
3 changes: 1 addition & 2 deletions cli/lib/errors.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const chalk = require('chalk')
const { stripIndent, stripIndents } = require('common-tags')
const { merge } = require('ramda')
const la = require('lazy-ass')
const is = require('check-more-types')

Expand Down Expand Up @@ -241,7 +240,7 @@ const CYPRESS_RUN_BINARY = {

function addPlatformInformation (info) {
return util.getPlatformInfo().then((platform) => {
return merge(info, { platform })
return { ...info, platform }
})
}

Expand Down
15 changes: 10 additions & 5 deletions cli/lib/exec/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const os = require('os')
const chalk = require('chalk')
const prettyBytes = require('pretty-bytes')
const _ = require('lodash')
const R = require('ramda')

// color for numbers and show values
const g = chalk.green
Expand All @@ -22,14 +21,20 @@ methods.findProxyEnvironmentVariables = () => {
return _.pick(process.env, ['HTTP_PROXY', 'HTTPS_PROXY', 'NO_PROXY'])
}

const maskSensitiveVariables = R.evolve({
CYPRESS_RECORD_KEY: R.always('<redacted>'),
})
const maskSensitiveVariables = (obj) => {
const masked = { ...obj }

if (masked.CYPRESS_RECORD_KEY) {
masked.CYPRESS_RECORD_KEY = '<redacted>'
}

return masked
}

methods.findCypressEnvironmentVariables = () => {
const isCyVariable = (val, key) => key.startsWith('CYPRESS_')

return R.pickBy(isCyVariable)(process.env)
return _.pickBy(process.env, isCyVariable)
}

const formatCypressVariables = () => {
Expand Down
5 changes: 3 additions & 2 deletions cli/lib/logger.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const R = require('ramda')
const chalk = require('chalk')

let logs = []
Expand Down Expand Up @@ -36,7 +35,9 @@ const always = (...messages) => {
const logLines = (text) => {
const lines = text.split('\n')

R.forEach(log, lines)
for (const line of lines) {
log(line)
}
}

const print = () => {
Expand Down
7 changes: 3 additions & 4 deletions cli/lib/tasks/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const _ = require('lodash')
const os = require('os')
const path = require('path')
const untildify = require('untildify')
const R = require('ramda')
const debug = require('debug')('cypress:cli')

const fs = require('../fs')
Expand Down Expand Up @@ -179,9 +178,9 @@ const getBinaryPkgAsync = (binaryDir) => {
})
}

const getBinaryPkgVersion = R.propOr(null, 'version')
const getBinaryElectronVersion = R.propOr(null, 'electronVersion')
const getBinaryElectronNodeVersion = R.propOr(null, 'electronNodeVersion')
const getBinaryPkgVersion = (o) => _.get(o, 'version', null)
const getBinaryElectronVersion = (o) => _.get(o, 'electronVersion', null)
const getBinaryElectronNodeVersion = (o) => _.get(o, 'electronNodeVersion', null)

module.exports = {
getPathToExecutable,
Expand Down
17 changes: 9 additions & 8 deletions cli/lib/util.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const _ = require('lodash')
const R = require('ramda')
const os = require('os')
const ospath = require('ospath')
const crypto = require('crypto')
Expand Down Expand Up @@ -114,10 +113,9 @@ const logBrokenGtkDisplayWarning = () => {
}

function stdoutLineMatches (expectedLine, stdout) {
const lines = stdout.split('\n').map(R.trim)
const lineMatches = R.equals(expectedLine)
const lines = stdout.split('\n').map((val) => val.trim())

return lines.some(lineMatches)
return lines.some((line) => line === expectedLine)
}

/**
Expand Down Expand Up @@ -229,11 +227,14 @@ const parseOpts = (opts) => {

// some options might be quoted - which leads to unexpected results
// remove double quotes from certain options
const removeQuotes = {
group: dequote,
ciBuildId: dequote,
const cleanOpts = { ...opts }
const toDequote = ['group', 'ciBuildId']

for (const prop of toDequote) {
if (_.has(opts, prop)) {
cleanOpts[prop] = dequote(opts[prop])
}
}
const cleanOpts = R.evolve(removeQuotes, opts)

debug('parsed cli options %o', cleanOpts)

Expand Down
1 change: 0 additions & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
"ospath": "^1.2.2",
"pretty-bytes": "^5.6.0",
"proxy-from-env": "1.0.0",
"ramda": "~0.27.1",
"request-progress": "^3.0.0",
"supports-color": "^8.1.1",
"tmp": "~0.2.1",
Expand Down
3 changes: 1 addition & 2 deletions cli/test/lib/build_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ const makeUserPackageFile = require('../../scripts/build')
const snapshot = require('../support/snapshot')
const la = require('lazy-ass')
const is = require('check-more-types')
const R = require('ramda')

const hasVersion = (json) => {
return la(is.semver(json.version), 'cannot find version', json)
}

const changeVersion = R.assoc('version', 'x.y.z')
const changeVersion = (o) => ({ ...o, version: 'x.y.z' })

describe('package.json build', () => {
beforeEach(function () {
Expand Down
8 changes: 3 additions & 5 deletions cli/test/lib/cypress_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ require('../spec_helper')

const os = require('os')
const path = require('path')
const R = require('ramda')
const _ = require('lodash')
const snapshot = require('../support/snapshot')
const Promise = require('bluebird')
const tmp = Promise.promisifyAll(require('tmp'))
Expand All @@ -27,11 +27,10 @@ describe('cypress', function () {
sinon.stub(open, 'start').resolves()
})

const getCallArgs = R.path(['lastCall', 'args', 0])
const getStartArgs = () => {
expect(open.start).to.be.called

return getCallArgs(open.start)
return _.get(open.start, ['lastCall', 'args', 0])
}

it('calls open#start, passing in options', function () {
Expand Down Expand Up @@ -100,7 +99,6 @@ describe('cypress', function () {
})
})

const getCallArgs = R.path(['lastCall', 'args', 0])
const normalizeCallArgs = (args) => {
expect(args.outputPath).to.equal(outputPath)
delete args.outputPath
Expand All @@ -110,7 +108,7 @@ describe('cypress', function () {
const getStartArgs = () => {
expect(run.start).to.be.called

return normalizeCallArgs(getCallArgs(run.start))
return normalizeCallArgs(_.get(run.start, ['lastCall', 'args', 0]))
}

it('calls run#start, passing in options', () => {
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@
"@types/mocha": "8.0.3",
"@types/node": "14.14.31",
"@types/prismjs": "1.16.0",
"@types/ramda": "0.25.47",
"@types/react": "16.9.50",
"@types/react-dom": "16.9.8",
"@types/request-promise": "4.1.45",
Expand Down Expand Up @@ -173,7 +172,6 @@
"pretty-ms": "7.0.0",
"print-arch": "1.0.0",
"proxyquire": "2.1.3",
"ramda": "0.27.1",
"semantic-release": "17.2.3",
"semantic-release-monorepo": "7.0.3",
"semver": "7.3.2",
Expand Down
3 changes: 1 addition & 2 deletions packages/launcher/lib/darwin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { findApp, FindAppParams } from './util'
import type { Browser, DetectedBrowser } from '../types'
import * as linuxHelper from '../linux'
import { log } from '../log'
import { merge } from 'ramda'
import { get } from 'lodash'

type Detectors = {
Expand Down Expand Up @@ -105,7 +104,7 @@ export function detect (browser: Browser): Promise<DetectedBrowser> {
}

return findApp(findAppParams)
.then(merge({ name: browser.name }))
.then((val) => ({ name: browser.name, ...val }))
.catch(() => {
log('could not detect %s using traditional Mac methods', browser.name)
log('trying linux search')
Expand Down
13 changes: 9 additions & 4 deletions packages/launcher/lib/darwin/util.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { log } from '../log'
import { notInstalledErr } from '../errors'
import { prop, tap } from 'ramda'
import { utils } from '../utils'
import * as fs from 'fs-extra'
import * as os from 'os'
Expand All @@ -27,7 +26,7 @@ export function parsePlist (p: string, property: string): Promise<string> {
return fs
.readFile(pl, 'utf8')
.then(plist.parse)
.then(prop(property))
.then((val) => val[property])
.then(String) // explicitly convert value to String type
.catch(failed) // to make TS compiler happy
}
Expand All @@ -50,8 +49,14 @@ export function mdfind (id: string): Promise<string> {
}

return utils.execa(cmd)
.then(prop('stdout'))
.then(tap(logFound))
.then((val) => {
return val.stdout
})
.then((val) => {
logFound(val)

return val
})
.catch(failedToFind)
}

Expand Down
33 changes: 19 additions & 14 deletions packages/launcher/lib/detect.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Bluebird from 'bluebird'
import { compact, extend, find } from 'lodash'
import _, { compact, extend, find } from 'lodash'
import os from 'os'
import { flatten, merge, pick, props, tap, uniqBy } from 'ramda'
import { browsers } from './browsers'
import * as darwinHelper from './darwin'
import { needsDarwinWorkaround, darwinDetectionWorkaround } from './darwin/util'
Expand All @@ -17,7 +16,7 @@ import type {
} from './types'
import * as windowsHelper from './windows'

type HasVersion = Partial<FoundBrowser> & {
type HasVersion = Omit<Partial<FoundBrowser>, 'version' | 'name'> & {
version: string
name: string
}
Expand Down Expand Up @@ -85,7 +84,7 @@ function lookup (
* one for each binary. If Windows is detected, only one `checkOneBrowser` will be called, because
* we don't use the `binary` field on Windows.
*/
function checkBrowser (browser: Browser): Bluebird<(boolean | FoundBrowser)[]> {
function checkBrowser (browser: Browser): Bluebird<(boolean | HasVersion)[]> {
if (Array.isArray(browser.binary) && os.platform() !== 'win32') {
return Bluebird.map(browser.binary, (binary: string) => {
return checkOneBrowser(extend({}, browser, { binary }))
Expand All @@ -95,9 +94,9 @@ function checkBrowser (browser: Browser): Bluebird<(boolean | FoundBrowser)[]> {
return Bluebird.map([browser], checkOneBrowser)
}

function checkOneBrowser (browser: Browser): Promise<boolean | FoundBrowser> {
function checkOneBrowser (browser: Browser): Promise<boolean | HasVersion> {
const platform = os.platform()
const pickBrowserProps = pick([
const pickBrowserProps = [
'name',
'family',
'channel',
Expand All @@ -111,7 +110,7 @@ function checkOneBrowser (browser: Browser): Promise<boolean | FoundBrowser> {
'info',
'minSupportedVersion',
'unsupportedVersion',
])
] as const

const logBrowser = (props: any) => {
log('setting major version for %j', props)
Expand All @@ -130,9 +129,13 @@ function checkOneBrowser (browser: Browser): Promise<boolean | FoundBrowser> {
log('checking one browser %s', browser.name)

return lookup(platform, browser)
.then(merge(browser))
.then(pickBrowserProps)
.then(tap(logBrowser))
.then((val) => ({ ...browser, ...val }))
.then((val) => _.pick(val, pickBrowserProps) as HasVersion)
.then((val) => {
logBrowser(val)

return val
})
.then((browser) => setMajorVersion(browser))
.catch(failed)
}
Expand Down Expand Up @@ -176,17 +179,19 @@ export const detect = (goalBrowsers?: Browser[], useDarwinWorkaround = true): Bl
})
}

const removeDuplicates = uniqBy((browser: FoundBrowser) => {
return props(['name', 'version'], browser)
})
const removeDuplicates = (val) => {
return _.uniqBy(val, (browser: FoundBrowser) => {
return `${browser.name}-${browser.version}`
})
}
const compactFalse = (browsers: any[]) => {
return compact(browsers) as FoundBrowser[]
}

log('detecting if the following browsers are present %o', goalBrowsers)

return Bluebird.mapSeries(goalBrowsers, checkBrowser)
.then(flatten)
.then((val) => _.flatten(val))
.then(compactFalse)
.then(removeDuplicates)
}
Expand Down
11 changes: 7 additions & 4 deletions packages/launcher/lib/linux/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { log } from '../log'
import { partial, trim, tap, prop } from 'ramda'
import type { FoundBrowser, Browser, PathData } from '../types'
import { notInstalledErr } from '../errors'
import { utils } from '../utils'
Expand Down Expand Up @@ -68,9 +67,13 @@ export function getVersionString (path: string) {

return Bluebird.resolve(utils.getOutput(path, ['--version']))
.timeout(30000, `Timed out after 30 seconds getting browser version for ${path}`)
.then(prop('stdout'))
.then(trim)
.then(tap(partial(log, ['stdout: "%s"'])))
.then((val) => val.stdout)
.then((val) => val.trim())
.then((val) => {
log('stdout: %s', val)

return val
})
}

export function getVersionNumber (version: string, browser: Browser) {
Expand Down
Loading

3 comments on commit c0d781d

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on c0d781d Nov 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/8.7.1/circle-develop-c0d781d28fad4a8100d47d34a703ec6fb205eaae/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on c0d781d Nov 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 ia32 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/8.7.1/appveyor-develop-c0d781d28fad4a8100d47d34a703ec6fb205eaae/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on c0d781d Nov 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/8.7.1/appveyor-develop-c0d781d28fad4a8100d47d34a703ec6fb205eaae/cypress.tgz

Please sign in to comment.