55// BUILD.JS: This file is responsible for building static HTML pages
66
77const fs = require ( 'fs' )
8+ const gracefulFs = require ( 'graceful-fs' )
89const path = require ( 'path' )
910const Metalsmith = require ( 'metalsmith' )
1011const collections = require ( 'metalsmith-collections' )
@@ -32,6 +33,10 @@ const anchorMarkdownHeadings = require('./scripts/plugins/anchor-markdown-headin
3233const loadVersions = require ( './scripts/load-versions' )
3334const 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.
3742const 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 }
0 commit comments