diff --git a/build.js b/build.js index 43d290f1553c9..885891b68b906 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 ebfea105a6110..5d60060daf82e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3073,9 +3073,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 eae0767a6dd7a..b67f0e3e5a9f4 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "autoprefixer": "^10.2.5", "cheerio": "^0.22.0", "fibers": "^5.0.0", + "graceful-fs": "^4.2.6", "handlebars": "^4.7.7", "jstransformer-handlebars": "^1.1.0", "junk": "^3.1.0",