Skip to content

Commit 0989d19

Browse files
committed
empty commit
1 parent 1fd4bad commit 0989d19

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

packages/server/lib/files.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
import path from 'path'
22
import { fs } from './util/fs'
33

4-
export async function readFile (projectRoot: string, options: { file: string, encoding?: string } = { file: '', encoding: 'utf8' }) {
4+
export async function readFile (projectRoot: string, options: { file: string, encoding?: BufferEncoding } = { file: '', encoding: 'utf8' }) {
55
const filePath = path.resolve(projectRoot, options.file)
6-
const readFn = (path.extname(filePath) === '.json' && options.encoding !== null) ? fs.readJsonAsync : fs.readFileAsync
76

87
// https://github.com/cypress-io/cypress/issues/1558
98
// If no encoding is specified, then Cypress has historically defaulted
109
// to `utf8`, because of it's focus on text files. This is in contrast to
1110
// NodeJs, which defaults to binary. We allow users to pass in `null`
1211
// to restore the default node behavior.
1312
try {
14-
// @ts-ignore as we are mixing types with fs
15-
const contents = await readFn(filePath, options.encoding === undefined ? 'utf8' : options.encoding)
13+
let contents
14+
15+
if (path.extname(filePath) === '.json' && options.encoding !== null) {
16+
contents = await fs.readJsonAsync(filePath, options.encoding === undefined ? 'utf8' : options.encoding)
17+
} else {
18+
contents = await fs.readFileAsync(filePath, {
19+
encoding: options.encoding === undefined ? 'utf8' : options.encoding,
20+
})
21+
}
1622

1723
return {
1824
contents,
@@ -25,7 +31,7 @@ export async function readFile (projectRoot: string, options: { file: string, en
2531
}
2632
}
2733

28-
export async function readFiles (projectRoot: string, options: { files: { path: string, encoding?: string }[] } = { files: [] }) {
34+
export async function readFiles (projectRoot: string, options: { files: { path: string, encoding?: BufferEncoding }[] } = { files: [] }) {
2935
const files = await Promise.all(options.files.map(async (file) => {
3036
const { contents, filePath } = await readFile(projectRoot, {
3137
file: file.path,
@@ -42,7 +48,7 @@ export async function readFiles (projectRoot: string, options: { files: { path:
4248
return files
4349
}
4450

45-
export async function writeFile (projectRoot: string, options: { fileName: string, contents: string, encoding?: string, flag?: string } = { fileName: '', contents: '', encoding: 'utf8', flag: 'w' }) {
51+
export async function writeFile (projectRoot: string, options: { fileName: string, contents: string, encoding?: BufferEncoding, flag?: string } = { fileName: '', contents: '', encoding: 'utf8', flag: 'w' }) {
4652
const filePath = path.resolve(projectRoot, options.fileName)
4753
const writeOptions = {
4854
encoding: options.encoding === undefined ? 'utf8' : options.encoding,

packages/server/test/unit/plugins/child/run_child_fixture.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const childProcess = require('child_process')
22
const path = require('path')
33

4-
// load with tsx?
54
const REQUIRE_ASYNC_CHILD_PATH = require.resolve('@packages/server/lib/plugins/child/require_async_child')
65

76
let proc
@@ -10,6 +9,7 @@ process.on('message', (msg) => {
109
if (msg.msg === 'spawn') {
1110
proc = childProcess.fork(REQUIRE_ASYNC_CHILD_PATH, ['--projectRoot', msg.data.projectRoot, '--file', path.join(msg.data.projectRoot, 'cypress.config.js')], {
1211
env: {
12+
// since some files are being converted to TypeScript AND we are using tsx to load the config process, we can reliably use it to load the async child here
1313
NODE_OPTIONS: '--import tsx',
1414
},
1515
})

0 commit comments

Comments
 (0)