Skip to content

Commit 2a06e33

Browse files
authored
build: resolve EMFILE build errors on Windows (#10100)
**Related Issue:** #9938 ## Summary I resolved the issue linked above in #10024, but it created a new error on Windows machines: ```text @esri/calcite-ui-icons:build: 🚨 Error while generating icons.json @esri/calcite-ui-icons:build: Error: EMFILE: too many open files, open 'C:\Dev\calcite-design-system\packages\calcite-ui-icons\js\cursorMinus16.json' @esri/calcite-ui-icons:build: at async open (node:internal/fs/promises:639:25) @esri/calcite-ui-icons:build: at async writeFile (node:internal/fs/promises:1219:14) @esri/calcite-ui-icons:build: at async Promise.all (index 8189) { @esri/calcite-ui-icons:build: errno: -4066, @esri/calcite-ui-icons:build: code: 'EMFILE', @esri/calcite-ui-icons:build: syscall: 'open', @esri/calcite-ui-icons:build: path: 'C:\\Dev\\calcite-design-system\\packages\\calcite-ui-icons\\js\\cursorMinus16.json' @esri/calcite-ui-icons:build: } ``` This adds back `fs-extra`, which uses `graceful-fs` to prevent EMFILE errors, as mentioned in their [README](https://github.com/isaacs/node-graceful-fs#improvements-over-fs-module): > Queues up open and readdir calls, and retries them once something closes if there is an EMFILE error from too many file descriptors.
1 parent 20ccbaa commit 2a06e33

File tree

8 files changed

+24
-21
lines changed

8 files changed

+24
-21
lines changed

package-lock.json

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

packages/calcite-ui-icons/bin/build.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { existsSync, mkdirSync } = require("fs");
1+
const { existsSync, mkdirSync } = require("fs-extra");
22
const optimize = require("./optimize");
33
const generatePathFile = require("./path-data");
44

packages/calcite-ui-icons/bin/convert-mobile.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env node
22

3-
const fs = require("fs");
3+
const { readdir, writeFile, readFile, mkdirSync, writeFileSync, existsSync } = require("fs-extra");
44
const svg2img = require("svg2img");
55
const path = require("path");
66
const yargs = require("yargs");
@@ -41,8 +41,8 @@ const options = yargs
4141
*/
4242
function convertSingleIconToPng(svgFilePath, width, height, outputBasePath, outputName, outputSuffix = null) {
4343
// make sure output base path exists
44-
if (!fs.existsSync(outputBasePath)) {
45-
fs.mkdirSync(outputBasePath, {
44+
if (!existsSync(outputBasePath)) {
45+
mkdirSync(outputBasePath, {
4646
recursive: true,
4747
});
4848
}
@@ -58,7 +58,7 @@ function convertSingleIconToPng(svgFilePath, width, height, outputBasePath, outp
5858
console.log(error);
5959
process.exit(1);
6060
}
61-
fs.writeFileSync(real_output_path, buffer);
61+
writeFileSync(real_output_path, buffer);
6262
});
6363
}
6464

@@ -81,14 +81,14 @@ function convertIconToXcodeImageSet(svgFilePath, width, height, outputBasePath,
8181
// read template
8282
const imagesetTemplatePath = path.join(__dirname, "templates", "imageset.json");
8383
// create Contents.json for asset catalog asset
84-
fs.readFile(imagesetTemplatePath, "utf8", function (error, buffer) {
84+
readFile(imagesetTemplatePath, "utf8", function (error, buffer) {
8585
if (error) {
8686
console.log(error);
8787
process.exit(1);
8888
}
8989
const contentsJsonBuffer = buffer.replace(/\$\{NAME\}/g, outputName);
9090
const contentsJsonOutputPath = path.join(outputImagesetPath, "Contents.json");
91-
fs.writeFileSync(contentsJsonOutputPath, contentsJsonBuffer);
91+
writeFileSync(contentsJsonOutputPath, contentsJsonBuffer);
9292
});
9393
}
9494

@@ -99,7 +99,7 @@ function convertIconToXcodeImageSet(svgFilePath, width, height, outputBasePath,
9999
async function indexCalciteIcons(baseIconPath) {
100100
return new Promise((resolve) => {
101101
var iconIndex = {};
102-
fs.readdir(baseIconPath, function (error, files) {
102+
readdir(baseIconPath, function (error, files) {
103103
if (error) {
104104
console.log(error);
105105
process.exit(1);
@@ -138,21 +138,21 @@ async function createCalciteXCAssets(xcAssetsBaseDirectory) {
138138
// Put in .xcassets folder
139139
var directory = path.join(xcAssetsBaseDirectory, "calcite.xcassets");
140140
// Make sure dir exists
141-
if (!fs.existsSync(directory)) {
142-
fs.mkdirSync(directory, {
141+
if (!existsSync(directory)) {
142+
mkdirSync(directory, {
143143
recursive: true,
144144
});
145145
}
146146
// read contents.json template
147147
let template_path = path.join(__dirname, "templates", "xcassets.json");
148148
// write out file
149-
fs.readFile(template_path, "utf8", function (error, buffer) {
149+
readFile(template_path, "utf8", function (error, buffer) {
150150
if (error) {
151151
console.log(error);
152152
process.exit(1);
153153
}
154154
const contents_output_path = path.join(directory, "Contents.json");
155-
fs.writeFile(contents_output_path, buffer, function (error) {
155+
writeFile(contents_output_path, buffer, function (error) {
156156
resolve(directory);
157157
});
158158
});

packages/calcite-ui-icons/bin/optimize.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { readFile, writeFile } = require("fs/promises");
1+
const { readFile, writeFile } = require("fs-extra");
22
const { glob } = require("glob");
33
const SVGO = require("svgo");
44
const progress = require("cli-progress");

packages/calcite-ui-icons/bin/path-data.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
const camelCase = require("camelcase");
2-
const {
3-
promises: { writeFile, readFile },
4-
readFileSync,
5-
} = require("fs");
2+
const { writeFile, readFile, readFileSync } = require("fs-extra");
63
const { glob } = require("glob");
74
const { parse } = require("svgson");
85
const path = require("path");

packages/calcite-ui-icons/lib/spriter/cli.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use strict";
22

33
const spriter = require("./index");
4-
const fs = require("fs");
4+
const { readFileSync } = require("fs");
55
const args = process.argv.slice(2); // skip runtime & script args
66

77
function hasArg(name, shorthand) {
@@ -31,7 +31,7 @@ function getConfig() {
3131

3232
if (input) {
3333
try {
34-
const configFileContents = fs.readFileSync(input);
34+
const configFileContents = readFileSync(input);
3535
input = JSON.parse(configFileContents).input;
3636
} catch (error) {
3737
process.stderr.write(`config - could not read input: ${error}`);

packages/calcite-ui-icons/lib/spriter/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22

3-
const { readdir, mkdir, writeFile, readFile } = require("fs/promises");
3+
const { readdir, mkdir, writeFile, readFile, lstatSync } = require("fs-extra");
44
const path = require("path");
55

66
const ICONS = path.resolve(path.dirname(process.argv[1]), "../icons");
@@ -11,7 +11,7 @@ const SIZES = [16, 24, 32];
1111
const OUTLINE = "outline";
1212
const FILL = "fill";
1313

14-
const isDir = (file) => fs.lstatSync(`${ICONS}/${file}`).isDirectory();
14+
const isDir = (file) => lstatSync(`${ICONS}/${file}`).isDirectory();
1515
const readSVG = (icon) => readFile(`${ICONS}/${icon.fileName}`, { encoding: "utf-8" });
1616
const has = (haystack, needle) => haystack.indexOf(needle) > -1;
1717

packages/calcite-ui-icons/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"camelcase": "6.3.0",
5959
"cli-progress": "^3.12.0",
6060
"debounce": "^2.1.0",
61+
"fs-extra": "11.2.0",
6162
"glob": "^11.0.0",
6263
"svg2img": "1.0.0-beta.2",
6364
"svgo": "^1.3.0",

0 commit comments

Comments
 (0)