diff --git a/lib/Server.js b/lib/Server.js index 898646266a..a3a4803cd2 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -545,11 +545,18 @@ class Server { if (!options.https.key || !options.https.cert) { const certificateDir = Server.findCacheDir(); const certificatePath = path.join(certificateDir, "server.pem"); - let certificateExists = fs.existsSync(certificatePath); + let certificateExists; + + try { + const certificate = await fs.promises.stat(certificatePath); + certificateExists = certificate.isFile(); + } catch { + certificateExists = false; + } if (certificateExists) { const certificateTtl = 1000 * 60 * 60 * 24; - const certificateStat = fs.statSync(certificatePath); + const certificateStat = await fs.promises.stat(certificatePath); const now = new Date(); @@ -561,7 +568,7 @@ class Server { "SSL Certificate is more than 30 days old. Removing..." ); - del.sync([certificatePath], { force: true }); + await del([certificatePath], { force: true }); certificateExists = false; } @@ -634,13 +641,18 @@ class Server { ], }); - fs.mkdirSync(certificateDir, { recursive: true }); - fs.writeFileSync(certificatePath, pems.private + pems.cert, { - encoding: "utf8", - }); + await fs.promises.mkdir(certificateDir, { recursive: true }); + + await fs.promises.writeFile( + certificatePath, + pems.private + pems.cert, + { + encoding: "utf8", + } + ); } - fakeCert = fs.readFileSync(certificatePath); + fakeCert = await fs.promises.readFile(certificatePath); this.logger.info(`SSL certificate: ${certificatePath}`); } @@ -1158,7 +1170,7 @@ class Server { app.get("/__webpack_dev_server__/sockjs.bundle.js", (req, res) => { res.setHeader("Content-Type", "application/javascript"); - const { createReadStream } = require("graceful-fs"); + const { createReadStream } = fs; const clientPath = path.join(__dirname, "..", "client"); createReadStream( @@ -2075,7 +2087,7 @@ class Server { // chmod 666 (rw rw rw) const READ_WRITE = 438; - fs.chmodSync(this.options.ipc, READ_WRITE); + await fs.promises.chmod(this.options.ipc, READ_WRITE); } if (this.options.webSocketServer) {