From 4c1bf413c76fa7c62036574fc8f8f5e15704c3e6 Mon Sep 17 00:00:00 2001 From: Nico Jansen Date: Thu, 26 Jan 2017 17:41:25 +0100 Subject: [PATCH] fix(fs): Use graceful-fs instead of fs directly (#221) Prevent `'EMFILE'` errors amongst others by using graceful-fs as a drop-in replacement for file system IO. --- package.json | 2 ++ src/PluginLoader.ts | 2 +- src/utils/StrykerTempFolder.ts | 4 ++-- src/utils/fileUtils.ts | 8 +++----- test/integration/utils/fileUtilsSpec.ts | 2 +- test/unit/PluginLoaderSpec.ts | 8 ++++---- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index 7f1b804516..10fc50c4f6 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "escodegen": "^1.8.0", "esprima": "^2.7.0", "glob": "^7.0.3", + "graceful-fs": "^4.1.11", "istanbul": "^0.4.5", "lodash": "^3.10.1", "log4js": "^0.6.33", @@ -62,6 +63,7 @@ "@types/esprima": "^2.1.31", "@types/estree": "0.0.32", "@types/glob": "^5.0.29", + "@types/graceful-fs": "^2.0.29", "@types/istanbul": "^0.4.29", "@types/karma": "^0.13.32", "@types/lodash": "^4.14.34", diff --git a/src/PluginLoader.ts b/src/PluginLoader.ts index 79732023e6..71529c8f68 100644 --- a/src/PluginLoader.ts +++ b/src/PluginLoader.ts @@ -1,4 +1,4 @@ -import * as fs from 'fs'; +import * as fs from 'graceful-fs'; import * as path from 'path'; import * as log4js from 'log4js'; import * as _ from 'lodash'; diff --git a/src/utils/StrykerTempFolder.ts b/src/utils/StrykerTempFolder.ts index ed231c9018..9770707256 100644 --- a/src/utils/StrykerTempFolder.ts +++ b/src/utils/StrykerTempFolder.ts @@ -1,5 +1,5 @@ import * as os from 'os'; -import * as fs from 'fs'; +import * as fs from 'graceful-fs'; import * as path from 'path'; import * as mkdirp from 'mkdirp'; import * as fileUtils from './fileUtils'; @@ -77,7 +77,7 @@ function writeFile(filename: string, data: string): Promise { * Copies a file. * @param fromFilename The path to the existing file. * @param toFilename The path to copy the file to. - * @param instrumenter An optional additional intrumenter to stream the file through + * @param instrumenter An optional additional instrumenter to stream the file through * @returns A promise to eventually copy the file. */ function copyFile(fromFilename: string, toFilename: string, instrumenter?: NodeJS.ReadWriteStream): Promise { diff --git a/src/utils/fileUtils.ts b/src/utils/fileUtils.ts index 21e04636e7..022d5a89b7 100644 --- a/src/utils/fileUtils.ts +++ b/src/utils/fileUtils.ts @@ -1,9 +1,7 @@ -'use strict'; - +import * as path from 'path'; +import * as os from 'os'; +import * as fs from 'graceful-fs'; import * as _ from 'lodash'; -import fs = require('fs'); -import os = require('os'); -import path = require('path'); import * as nodeGlob from 'glob'; import * as mkdirp from 'mkdirp'; diff --git a/test/integration/utils/fileUtilsSpec.ts b/test/integration/utils/fileUtilsSpec.ts index a867b7fcd1..1210f41037 100644 --- a/test/integration/utils/fileUtilsSpec.ts +++ b/test/integration/utils/fileUtilsSpec.ts @@ -1,4 +1,4 @@ -import * as fs from 'fs'; +import * as fs from 'graceful-fs'; import { expect } from 'chai'; import * as sinon from 'sinon'; import * as fileUtils from '../../../src/utils/fileUtils'; diff --git a/test/unit/PluginLoaderSpec.ts b/test/unit/PluginLoaderSpec.ts index d43ab064e1..c9266ec9cf 100644 --- a/test/unit/PluginLoaderSpec.ts +++ b/test/unit/PluginLoaderSpec.ts @@ -1,10 +1,10 @@ -import PluginLoader from '../../src/PluginLoader'; -import {expect} from 'chai'; +import * as path from 'path'; +import * as fs from 'graceful-fs'; import * as sinon from 'sinon'; +import { expect } from 'chai'; import * as fileUtils from '../../src/utils/fileUtils'; +import PluginLoader from '../../src/PluginLoader'; import log from '../helpers/log4jsMock'; -import * as fs from 'fs'; -import * as path from 'path'; describe('PluginLoader', () => { let sut: PluginLoader;