Skip to content

Commit

Permalink
Use fs.promises
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Dec 22, 2019
1 parent 736dca0 commit b60691b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 15 deletions.
7 changes: 2 additions & 5 deletions src/report/insert.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { readFile } from 'fs'
import { promisify } from 'util'
import { promises } from 'fs'

import writeFileAtomic from 'write-file-atomic'

const pReadFile = promisify(readFile)

// Use the `insert` option to insert content inside a file.
// We insert between any two lines with the tokens "spyd-start" and "spyd-end".
// This:
Expand All @@ -25,7 +22,7 @@ export const insertContent = async function({ content, insert: file }) {

const getFileContent = async function(file) {
try {
return await pReadFile(file, 'utf8')
return await promises.readFile(file, 'utf8')
} catch (error) {
throw new Error(`Could not read file '${file}'\n${error.message}`)
}
Expand Down
7 changes: 2 additions & 5 deletions src/store/stores/file/fs.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { promisify } from 'util'
import { readFile, promises } from 'fs'
import { promises } from 'fs'

import writeFileAtomic from 'write-file-atomic'
import pathExists from 'path-exists'

const pReadFile = promisify(readFile)

// Retrieve benchmarks from filesystem
export const getBenchmarks = async function(dir) {
const dataFile = await getDataFile(dir)
Expand All @@ -14,7 +11,7 @@ export const getBenchmarks = async function(dir) {
return []
}

const content = await pReadFile(dataFile, 'utf-8')
const content = await promises.readFile(dataFile, 'utf8')
const benchmarks = JSON.parse(content)
return benchmarks
}
Expand Down
7 changes: 2 additions & 5 deletions src/utils/yaml.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { readFile } from 'fs'
import { promisify } from 'util'
import { promises } from 'fs'

import { load as loadYaml, JSON_SCHEMA } from 'js-yaml'

const pReadFile = promisify(readFile)

// Load and parse YAML file
export const loadYamlFile = async function(path) {
const string = await readYamlFile(path)
Expand All @@ -14,7 +11,7 @@ export const loadYamlFile = async function(path) {

const readYamlFile = async function(path) {
try {
return await pReadFile(path, 'utf8')
return await promises.readFile(path, 'utf8')
} catch (error) {
throw new Error(`Could not read file '${path}'\n\n${error.stack}`)
}
Expand Down

0 comments on commit b60691b

Please sign in to comment.