Skip to content

Commit 32464f3

Browse files
authored
fix: remove .json check from require_async, prevent child_process spawn (#18416)
1 parent c18b5e6 commit 32464f3

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

packages/server/lib/util/require_async.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import * as cp from 'child_process'
44
import * as inspector from 'inspector'
55
import * as util from '../plugins/util'
66
import * as errors from '../errors'
7-
import { fs } from '../util/fs'
87
import Debug from 'debug'
98

109
const debug = Debug('cypress:server:require_async')
@@ -33,10 +32,6 @@ export async function requireAsync (filePath: string, options: RequireAsyncOptio
3332
killChildProcess()
3433
}
3534

36-
if (/\.json$/.test(filePath)) {
37-
fs.readJson(path.resolve(options.projectRoot, filePath)).then((result) => resolve(result)).catch(reject)
38-
}
39-
4035
const childOptions: ChildOptions = {
4136
stdio: 'inherit',
4237
}

packages/server/lib/util/settings.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import _ from 'lodash'
22
import Promise from 'bluebird'
33
import path from 'path'
4+
45
import errors from '../errors'
56
import { fs } from '../util/fs'
67
import { requireAsync } from './require_async'
@@ -146,11 +147,12 @@ export function read (projectRoot, options: SettingsOptions = {}) {
146147

147148
const file = pathToConfigFile(projectRoot, options)
148149

149-
return requireAsync(file,
150-
{
151-
projectRoot,
152-
loadErrorCode: 'CONFIG_FILE_ERROR',
153-
})
150+
const readPromise = /\.json$/.test(file) ? fs.readJSON(path.resolve(projectRoot, file)) : requireAsync(file, {
151+
projectRoot,
152+
loadErrorCode: 'CONFIG_FILE_ERROR',
153+
})
154+
155+
return readPromise
154156
.catch((err) => {
155157
if (err.type === 'MODULE_NOT_FOUND' || err.code === 'ENOENT') {
156158
if (options.args?.runProject) {

0 commit comments

Comments
 (0)