refactor: use fs.promises API, which is stable since Node 12 (#17999)
This commit is contained in:
parent
7574f91f31
commit
9714a91392
3 changed files with 9 additions and 35 deletions
|
@ -4,7 +4,6 @@ const electron = require('electron')
|
|||
const { EventEmitter } = require('events')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const util = require('util')
|
||||
|
||||
const v8Util = process.electronBinding('v8_util')
|
||||
const eventBinding = process.electronBinding('event')
|
||||
|
@ -499,13 +498,10 @@ ipcMainUtils.handle('ELECTRON_BROWSER_CLIPBOARD', function (event, method, ...ar
|
|||
return clipboardUtils.serialize(electron.clipboard[method](...clipboardUtils.deserialize(args)))
|
||||
})
|
||||
|
||||
const readFile = util.promisify(fs.readFile)
|
||||
const realpath = util.promisify(fs.realpath)
|
||||
|
||||
let absoluteAppPath
|
||||
const getAppPath = async function () {
|
||||
if (absoluteAppPath === undefined) {
|
||||
absoluteAppPath = await realpath(electron.app.getAppPath())
|
||||
absoluteAppPath = await fs.promises.realpath(electron.app.getAppPath())
|
||||
}
|
||||
return absoluteAppPath
|
||||
}
|
||||
|
@ -515,10 +511,10 @@ const getPreloadScript = async function (preloadPath) {
|
|||
let preloadError = null
|
||||
if (preloadPath) {
|
||||
try {
|
||||
if (!isParentDir(await getAppPath(), await realpath(preloadPath))) {
|
||||
if (!isParentDir(await getAppPath(), await fs.promises.realpath(preloadPath))) {
|
||||
throw new Error('Preload scripts outside of app path are not allowed')
|
||||
}
|
||||
preloadSrc = (await readFile(preloadPath)).toString()
|
||||
preloadSrc = (await fs.promises.readFile(preloadPath)).toString()
|
||||
} catch (err) {
|
||||
preloadError = errorUtils.serialize(err)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue