Skip to content

Commit ef6cf1f

Browse files
Add graceful-fs. (#3700)
This fixes the `npm run deploy` `EMFILE: too many open files` error on Windows Co-authored-by: Myles Borins <[email protected]>
1 parent a15b03d commit ef6cf1f

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

build.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// BUILD.JS: This file is responsible for building static HTML pages
66

77
const fs = require('fs')
8+
const gracefulFs = require('graceful-fs')
89
const path = require('path')
910
const Metalsmith = require('metalsmith')
1011
const collections = require('metalsmith-collections')
@@ -32,6 +33,10 @@ const anchorMarkdownHeadings = require('./scripts/plugins/anchor-markdown-headin
3233
const loadVersions = require('./scripts/load-versions')
3334
const latestVersion = require('./scripts/helpers/latestversion')
3435

36+
// This is needed at least on Windows to prevent the `EMFILE: too many open files` error
37+
// https://github.com/isaacs/node-graceful-fs#global-patching
38+
gracefulFs.gracefulify(fs)
39+
3540
// Set the default language, also functions as a fallback for properties which
3641
// are not defined in the given language.
3742
const DEFAULT_LANG = 'en'
@@ -214,7 +219,7 @@ function buildCSS () {
214219
outputStyle: process.env.NODE_ENV !== 'development' ? 'compressed' : 'expanded'
215220
}
216221

217-
fs.mkdir(path.join(__dirname, 'build/static/css'), { recursive: true }, (err) => {
222+
gracefulFs.mkdir(path.join(__dirname, 'build/static/css'), { recursive: true }, (err) => {
218223
if (err) {
219224
throw err
220225
}
@@ -229,7 +234,7 @@ function buildCSS () {
229234
console.warn(warn.toString())
230235
})
231236

232-
fs.writeFile(dest, res.css, (err) => {
237+
gracefulFs.writeFile(dest, res.css, (err) => {
233238
if (err) {
234239
throw err
235240
}
@@ -247,7 +252,7 @@ function copyStatic () {
247252
console.log('[ncp] build/static started')
248253
const labelForBuild = '[ncp] build/static finished'
249254
console.time(labelForBuild)
250-
fs.mkdir(path.join(__dirname, 'build/static'), { recursive: true }, (err) => {
255+
gracefulFs.mkdir(path.join(__dirname, 'build/static'), { recursive: true }, (err) => {
251256
if (err) {
252257
throw err
253258
}
@@ -300,7 +305,7 @@ function fullBuild (opts) {
300305
if (err) { throw err }
301306

302307
// Executes the build cycle for every locale.
303-
fs.readdir(path.join(__dirname, 'locale'), (e, locales) => {
308+
gracefulFs.readdir(path.join(__dirname, 'locale'), (e, locales) => {
304309
if (e) {
305310
throw e
306311
}

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"autoprefixer": "^10.2.5",
4040
"cheerio": "^0.22.0",
4141
"fibers": "^5.0.0",
42+
"graceful-fs": "^4.2.6",
4243
"handlebars": "^4.7.7",
4344
"jstransformer-handlebars": "^1.1.0",
4445
"junk": "^3.1.0",

0 commit comments

Comments
 (0)