From 0873f75b16a920de659c84a8e45f1af1df8a9b17 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Sun, 14 Feb 2021 20:52:57 +0200 Subject: [PATCH] Add graceful-fs. This fixes the `npm run deploy` `EMFILE: too many open files` error on Windows --- build.js | 13 +++++++++---- package-lock.json | 6 +++--- package.json | 1 + 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/build.js b/build.js index 476602b6c9810..19393d2b10c19 100755 --- a/build.js +++ b/build.js @@ -5,6 +5,7 @@ // BUILD.JS: This file is responsible for building static HTML pages const fs = require('fs') +const gracefulFs = require('graceful-fs') const path = require('path') const Metalsmith = require('metalsmith') const collections = require('metalsmith-collections') @@ -32,6 +33,10 @@ const anchorMarkdownHeadings = require('./scripts/plugins/anchor-markdown-headin const loadVersions = require('./scripts/load-versions') const latestVersion = require('./scripts/helpers/latestversion') +// This is needed at least on Windows to prevent the `EMFILE: too many open files` error +// https://github.com/isaacs/node-graceful-fs#global-patching +gracefulFs.gracefulify(fs) + // Set the default language, also functions as a fallback for properties which // are not defined in the given language. const DEFAULT_LANG = 'en' @@ -214,7 +219,7 @@ function buildCSS () { outputStyle: process.env.NODE_ENV !== 'development' ? 'compressed' : 'expanded' } - fs.mkdir(path.join(__dirname, 'build/static/css'), { recursive: true }, (err) => { + gracefulFs.mkdir(path.join(__dirname, 'build/static/css'), { recursive: true }, (err) => { if (err) { throw err } @@ -229,7 +234,7 @@ function buildCSS () { console.warn(warn.toString()) }) - fs.writeFile(dest, res.css, (err) => { + gracefulFs.writeFile(dest, res.css, (err) => { if (err) { throw err } @@ -247,7 +252,7 @@ function copyStatic () { console.log('[ncp] build/static started') const labelForBuild = '[ncp] build/static finished' console.time(labelForBuild) - fs.mkdir(path.join(__dirname, 'build/static'), { recursive: true }, (err) => { + gracefulFs.mkdir(path.join(__dirname, 'build/static'), { recursive: true }, (err) => { if (err) { throw err } @@ -300,7 +305,7 @@ function fullBuild (opts) { if (err) { throw err } // Executes the build cycle for every locale. - fs.readdir(path.join(__dirname, 'locale'), (e, locales) => { + gracefulFs.readdir(path.join(__dirname, 'locale'), (e, locales) => { if (e) { throw e } diff --git a/package-lock.json b/package-lock.json index 5c46ed82dfb26..d83ddcf9b21bf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3017,9 +3017,9 @@ } }, "graceful-fs": { - "version": "4.2.4", - "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.4.tgz", - "integrity": "sha512-WjKPNJF79dtJAVniUlGGWHYGz2jWxT6VhN/4m1NdkbZ2nOsEF+cI1Edgql5zCRhs/VsQYRvrXctxktVXZUkixw==" + "version": "4.2.6", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.6.tgz", + "integrity": "sha512-nTnJ528pbqxYanhpDYsi4Rd8MAeaBA67+RZ10CM1m3bTAVFEDcd5AuA4a6W5YkGZ1iNXHzZz8T6TBKLeBuNriQ==" }, "gray-matter": { "version": "2.1.1", diff --git a/package.json b/package.json index 4a91772fcb590..ac0a292863b15 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "autoprefixer": "^10.2.4", "cheerio": "^0.22.0", "fibers": "^5.0.0", + "graceful-fs": "^4.2.6", "handlebars": "^4.7.6", "jstransformer-handlebars": "^1.1.0", "junk": "^3.1.0",