diff --git a/lib/fs.js b/lib/fs.js index ac87e5c4..b15f1381 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -9,6 +9,7 @@ import which from 'which'; import glob from 'glob'; import crypto from 'crypto'; import klaw from 'klaw'; +import sanitize from 'sanitize-filename'; import { pluralize } from './util'; import log from './logger'; import Timer from './timing'; @@ -50,6 +51,7 @@ let fs = { mv: B.promisify(mv), which: B.promisify(which), glob: B.promisify(glob), + sanitizeName: sanitize, async hash (filePath, algorithm = 'sha1') { return await new B((resolve, reject) => { const fileHash = crypto.createHash(algorithm); diff --git a/package.json b/package.json index 977e8e1c..cc1f7946 100644 --- a/package.json +++ b/package.json @@ -54,6 +54,7 @@ "request": "^2.83.0", "request-promise": "^4.2.2", "rimraf": "^3.0.0", + "sanitize-filename": "^1.6.1", "semver": "^7.0.0", "shell-quote": "^1.7.2", "source-map-support": "^0.5.5", diff --git a/test/fs-specs.js b/test/fs-specs.js index 7bc2a5b2..357d284b 100644 --- a/test/fs-specs.js +++ b/test/fs-specs.js @@ -86,6 +86,11 @@ describe('fs', function () { await fs.rimraf(newPath); (await fs.exists(newPath)).should.be.false; }); + it('sanitizeName', function () { + fs.sanitizeName(':file?.txt', { + replacement: '-', + }).should.eql('-file-.txt'); + }); it('rimrafSync', async function () { let newPath = path.resolve(await tempDir.openDir(), 'fs-specs.js'); await fs.copyFile(existingPath, newPath);