Skip to content

Commit

Permalink
fix: remove .json check from require_async, prevent child_process spa…
Browse files Browse the repository at this point in the history
…wn (#18416)
  • Loading branch information
tgriesser authored and mjhenkes committed Jul 28, 2022
1 parent da1ab59 commit 2aaf8dd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
5 changes: 0 additions & 5 deletions packages/server/lib/util/require_async.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import * as cp from 'child_process'
import * as inspector from 'inspector'
import * as util from '../plugins/util'
import * as errors from '../errors'
import { fs } from '../util/fs'
import Debug from 'debug'

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

if (/\.json$/.test(filePath)) {
fs.readJson(path.resolve(options.projectRoot, filePath)).then((result) => resolve(result)).catch(reject)
}

const childOptions: ChildOptions = {
stdio: 'inherit',
}
Expand Down
12 changes: 7 additions & 5 deletions packages/server/lib/util/settings.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import _ from 'lodash'
import Promise from 'bluebird'
import path from 'path'

import errors from '../errors'
import { fs } from '../util/fs'
import { requireAsync } from './require_async'
Expand Down Expand Up @@ -146,11 +147,12 @@ export function read (projectRoot, options: SettingsOptions = {}) {

const file = pathToConfigFile(projectRoot, options)

return requireAsync(file,
{
projectRoot,
loadErrorCode: 'CONFIG_FILE_ERROR',
})
const readPromise = /\.json$/.test(file) ? fs.readJSON(path.resolve(projectRoot, file)) : requireAsync(file, {
projectRoot,
loadErrorCode: 'CONFIG_FILE_ERROR',
})

return readPromise
.catch((err) => {
if (err.type === 'MODULE_NOT_FOUND' || err.code === 'ENOENT') {
if (options.args?.runProject) {
Expand Down

0 comments on commit 2aaf8dd

Please sign in to comment.