Skip to content

Commit

Permalink
Add graceful-fs. (#3700)
Browse files Browse the repository at this point in the history
This fixes the `npm run deploy` `EMFILE: too many open files` error on Windows

Co-authored-by: Myles Borins <mylesborins@github.com>
  • Loading branch information
XhmikosR and MylesBorins authored Apr 29, 2021
1 parent a15b03d commit ef6cf1f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
13 changes: 9 additions & 4 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit ef6cf1f

Please sign in to comment.