Skip to content

Commit c0d781d

Browse files
authored
refactor: remove Ramda (#18723)
1 parent 4cb97b3 commit c0d781d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+205
-191
lines changed

cli/lib/cli.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// @ts-check
22
const _ = require('lodash')
3-
const R = require('ramda')
43
const commander = require('commander')
54
const { stripIndent } = require('common-tags')
65
const logSymbols = require('log-symbols')
@@ -279,12 +278,17 @@ const castCypressRunOptions = (opts) => {
279278
// only properties that have type "string | false" in our TS definition
280279
// require special handling, because CLI parsing takes care of purely
281280
// boolean arguments
282-
const result = R.evolve({
283-
port: coerceAnyStringToInt,
284-
configFile: coerceFalseOrString,
285-
})(opts)
281+
const castOpts = { ...opts }
286282

287-
return result
283+
if (_.has(opts, 'port')) {
284+
castOpts.port = coerceAnyStringToInt(opts.port)
285+
}
286+
287+
if (_.has(opts, 'configFile')) {
288+
castOpts.configFile = coerceFalseOrString(opts.configFile)
289+
}
290+
291+
return castOpts
288292
}
289293

290294
module.exports = {

cli/lib/errors.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const chalk = require('chalk')
22
const { stripIndent, stripIndents } = require('common-tags')
3-
const { merge } = require('ramda')
43
const la = require('lazy-ass')
54
const is = require('check-more-types')
65

@@ -241,7 +240,7 @@ const CYPRESS_RUN_BINARY = {
241240

242241
function addPlatformInformation (info) {
243242
return util.getPlatformInfo().then((platform) => {
244-
return merge(info, { platform })
243+
return { ...info, platform }
245244
})
246245
}
247246

cli/lib/exec/info.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const os = require('os')
66
const chalk = require('chalk')
77
const prettyBytes = require('pretty-bytes')
88
const _ = require('lodash')
9-
const R = require('ramda')
109

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

25-
const maskSensitiveVariables = R.evolve({
26-
CYPRESS_RECORD_KEY: R.always('<redacted>'),
27-
})
24+
const maskSensitiveVariables = (obj) => {
25+
const masked = { ...obj }
26+
27+
if (masked.CYPRESS_RECORD_KEY) {
28+
masked.CYPRESS_RECORD_KEY = '<redacted>'
29+
}
30+
31+
return masked
32+
}
2833

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

32-
return R.pickBy(isCyVariable)(process.env)
37+
return _.pickBy(process.env, isCyVariable)
3338
}
3439

3540
const formatCypressVariables = () => {

cli/lib/logger.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const R = require('ramda')
21
const chalk = require('chalk')
32

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

39-
R.forEach(log, lines)
38+
for (const line of lines) {
39+
log(line)
40+
}
4041
}
4142

4243
const print = () => {

cli/lib/tasks/state.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ const _ = require('lodash')
22
const os = require('os')
33
const path = require('path')
44
const untildify = require('untildify')
5-
const R = require('ramda')
65
const debug = require('debug')('cypress:cli')
76

87
const fs = require('../fs')
@@ -179,9 +178,9 @@ const getBinaryPkgAsync = (binaryDir) => {
179178
})
180179
}
181180

182-
const getBinaryPkgVersion = R.propOr(null, 'version')
183-
const getBinaryElectronVersion = R.propOr(null, 'electronVersion')
184-
const getBinaryElectronNodeVersion = R.propOr(null, 'electronNodeVersion')
181+
const getBinaryPkgVersion = (o) => _.get(o, 'version', null)
182+
const getBinaryElectronVersion = (o) => _.get(o, 'electronVersion', null)
183+
const getBinaryElectronNodeVersion = (o) => _.get(o, 'electronNodeVersion', null)
185184

186185
module.exports = {
187186
getPathToExecutable,

cli/lib/util.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const _ = require('lodash')
2-
const R = require('ramda')
32
const os = require('os')
43
const ospath = require('ospath')
54
const crypto = require('crypto')
@@ -114,10 +113,9 @@ const logBrokenGtkDisplayWarning = () => {
114113
}
115114

116115
function stdoutLineMatches (expectedLine, stdout) {
117-
const lines = stdout.split('\n').map(R.trim)
118-
const lineMatches = R.equals(expectedLine)
116+
const lines = stdout.split('\n').map((val) => val.trim())
119117

120-
return lines.some(lineMatches)
118+
return lines.some((line) => line === expectedLine)
121119
}
122120

123121
/**
@@ -229,11 +227,14 @@ const parseOpts = (opts) => {
229227

230228
// some options might be quoted - which leads to unexpected results
231229
// remove double quotes from certain options
232-
const removeQuotes = {
233-
group: dequote,
234-
ciBuildId: dequote,
230+
const cleanOpts = { ...opts }
231+
const toDequote = ['group', 'ciBuildId']
232+
233+
for (const prop of toDequote) {
234+
if (_.has(opts, prop)) {
235+
cleanOpts[prop] = dequote(opts[prop])
236+
}
235237
}
236-
const cleanOpts = R.evolve(removeQuotes, opts)
237238

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

cli/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
"ospath": "^1.2.2",
5656
"pretty-bytes": "^5.6.0",
5757
"proxy-from-env": "1.0.0",
58-
"ramda": "~0.27.1",
5958
"request-progress": "^3.0.0",
6059
"supports-color": "^8.1.1",
6160
"tmp": "~0.2.1",

cli/test/lib/build_spec.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@ const makeUserPackageFile = require('../../scripts/build')
55
const snapshot = require('../support/snapshot')
66
const la = require('lazy-ass')
77
const is = require('check-more-types')
8-
const R = require('ramda')
98

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

14-
const changeVersion = R.assoc('version', 'x.y.z')
13+
const changeVersion = (o) => ({ ...o, version: 'x.y.z' })
1514

1615
describe('package.json build', () => {
1716
beforeEach(function () {

cli/test/lib/cypress_spec.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ require('../spec_helper')
22

33
const os = require('os')
44
const path = require('path')
5-
const R = require('ramda')
5+
const _ = require('lodash')
66
const snapshot = require('../support/snapshot')
77
const Promise = require('bluebird')
88
const tmp = Promise.promisifyAll(require('tmp'))
@@ -27,11 +27,10 @@ describe('cypress', function () {
2727
sinon.stub(open, 'start').resolves()
2828
})
2929

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

34-
return getCallArgs(open.start)
33+
return _.get(open.start, ['lastCall', 'args', 0])
3534
}
3635

3736
it('calls open#start, passing in options', function () {
@@ -100,7 +99,6 @@ describe('cypress', function () {
10099
})
101100
})
102101

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

113-
return normalizeCallArgs(getCallArgs(run.start))
111+
return normalizeCallArgs(_.get(run.start, ['lastCall', 'args', 0]))
114112
}
115113

116114
it('calls run#start, passing in options', () => {

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@
9494
"@types/mocha": "8.0.3",
9595
"@types/node": "14.14.31",
9696
"@types/prismjs": "1.16.0",
97-
"@types/ramda": "0.25.47",
9897
"@types/react": "16.9.50",
9998
"@types/react-dom": "16.9.8",
10099
"@types/request-promise": "4.1.45",
@@ -173,7 +172,6 @@
173172
"pretty-ms": "7.0.0",
174173
"print-arch": "1.0.0",
175174
"proxyquire": "2.1.3",
176-
"ramda": "0.27.1",
177175
"semantic-release": "17.2.3",
178176
"semantic-release-monorepo": "7.0.3",
179177
"semver": "7.3.2",

packages/launcher/lib/darwin/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { findApp, FindAppParams } from './util'
22
import type { Browser, DetectedBrowser } from '../types'
33
import * as linuxHelper from '../linux'
44
import { log } from '../log'
5-
import { merge } from 'ramda'
65
import { get } from 'lodash'
76

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

107106
return findApp(findAppParams)
108-
.then(merge({ name: browser.name }))
107+
.then((val) => ({ name: browser.name, ...val }))
109108
.catch(() => {
110109
log('could not detect %s using traditional Mac methods', browser.name)
111110
log('trying linux search')

packages/launcher/lib/darwin/util.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { log } from '../log'
22
import { notInstalledErr } from '../errors'
3-
import { prop, tap } from 'ramda'
43
import { utils } from '../utils'
54
import * as fs from 'fs-extra'
65
import * as os from 'os'
@@ -27,7 +26,7 @@ export function parsePlist (p: string, property: string): Promise<string> {
2726
return fs
2827
.readFile(pl, 'utf8')
2928
.then(plist.parse)
30-
.then(prop(property))
29+
.then((val) => val[property])
3130
.then(String) // explicitly convert value to String type
3231
.catch(failed) // to make TS compiler happy
3332
}
@@ -50,8 +49,14 @@ export function mdfind (id: string): Promise<string> {
5049
}
5150

5251
return utils.execa(cmd)
53-
.then(prop('stdout'))
54-
.then(tap(logFound))
52+
.then((val) => {
53+
return val.stdout
54+
})
55+
.then((val) => {
56+
logFound(val)
57+
58+
return val
59+
})
5560
.catch(failedToFind)
5661
}
5762

packages/launcher/lib/detect.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import Bluebird from 'bluebird'
2-
import { compact, extend, find } from 'lodash'
2+
import _, { compact, extend, find } from 'lodash'
33
import os from 'os'
4-
import { flatten, merge, pick, props, tap, uniqBy } from 'ramda'
54
import { browsers } from './browsers'
65
import * as darwinHelper from './darwin'
76
import { needsDarwinWorkaround, darwinDetectionWorkaround } from './darwin/util'
@@ -17,7 +16,7 @@ import type {
1716
} from './types'
1817
import * as windowsHelper from './windows'
1918

20-
type HasVersion = Partial<FoundBrowser> & {
19+
type HasVersion = Omit<Partial<FoundBrowser>, 'version' | 'name'> & {
2120
version: string
2221
name: string
2322
}
@@ -85,7 +84,7 @@ function lookup (
8584
* one for each binary. If Windows is detected, only one `checkOneBrowser` will be called, because
8685
* we don't use the `binary` field on Windows.
8786
*/
88-
function checkBrowser (browser: Browser): Bluebird<(boolean | FoundBrowser)[]> {
87+
function checkBrowser (browser: Browser): Bluebird<(boolean | HasVersion)[]> {
8988
if (Array.isArray(browser.binary) && os.platform() !== 'win32') {
9089
return Bluebird.map(browser.binary, (binary: string) => {
9190
return checkOneBrowser(extend({}, browser, { binary }))
@@ -95,9 +94,9 @@ function checkBrowser (browser: Browser): Bluebird<(boolean | FoundBrowser)[]> {
9594
return Bluebird.map([browser], checkOneBrowser)
9695
}
9796

98-
function checkOneBrowser (browser: Browser): Promise<boolean | FoundBrowser> {
97+
function checkOneBrowser (browser: Browser): Promise<boolean | HasVersion> {
9998
const platform = os.platform()
100-
const pickBrowserProps = pick([
99+
const pickBrowserProps = [
101100
'name',
102101
'family',
103102
'channel',
@@ -111,7 +110,7 @@ function checkOneBrowser (browser: Browser): Promise<boolean | FoundBrowser> {
111110
'info',
112111
'minSupportedVersion',
113112
'unsupportedVersion',
114-
])
113+
] as const
115114

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

132131
return lookup(platform, browser)
133-
.then(merge(browser))
134-
.then(pickBrowserProps)
135-
.then(tap(logBrowser))
132+
.then((val) => ({ ...browser, ...val }))
133+
.then((val) => _.pick(val, pickBrowserProps) as HasVersion)
134+
.then((val) => {
135+
logBrowser(val)
136+
137+
return val
138+
})
136139
.then((browser) => setMajorVersion(browser))
137140
.catch(failed)
138141
}
@@ -176,17 +179,19 @@ export const detect = (goalBrowsers?: Browser[], useDarwinWorkaround = true): Bl
176179
})
177180
}
178181

179-
const removeDuplicates = uniqBy((browser: FoundBrowser) => {
180-
return props(['name', 'version'], browser)
181-
})
182+
const removeDuplicates = (val) => {
183+
return _.uniqBy(val, (browser: FoundBrowser) => {
184+
return `${browser.name}-${browser.version}`
185+
})
186+
}
182187
const compactFalse = (browsers: any[]) => {
183188
return compact(browsers) as FoundBrowser[]
184189
}
185190

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

188193
return Bluebird.mapSeries(goalBrowsers, checkBrowser)
189-
.then(flatten)
194+
.then((val) => _.flatten(val))
190195
.then(compactFalse)
191196
.then(removeDuplicates)
192197
}

packages/launcher/lib/linux/index.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { log } from '../log'
2-
import { partial, trim, tap, prop } from 'ramda'
32
import type { FoundBrowser, Browser, PathData } from '../types'
43
import { notInstalledErr } from '../errors'
54
import { utils } from '../utils'
@@ -68,9 +67,13 @@ export function getVersionString (path: string) {
6867

6968
return Bluebird.resolve(utils.getOutput(path, ['--version']))
7069
.timeout(30000, `Timed out after 30 seconds getting browser version for ${path}`)
71-
.then(prop('stdout'))
72-
.then(trim)
73-
.then(tap(partial(log, ['stdout: "%s"'])))
70+
.then((val) => val.stdout)
71+
.then((val) => val.trim())
72+
.then((val) => {
73+
log('stdout: %s', val)
74+
75+
return val
76+
})
7477
}
7578

7679
export function getVersionNumber (version: string, browser: Browser) {

0 commit comments

Comments
 (0)