diff --git a/lib/index.js b/lib/index.js index d25fd544..88ad4642 100644 --- a/lib/index.js +++ b/lib/index.js @@ -24,14 +24,3 @@ assign(fs, require('./ensure')) assign(fs, require('./output')) module.exports = fs - -// maintain backwards compatibility for awhile -const jsonfile = {} -Object.defineProperty(jsonfile, 'spaces', { - get: () => fs.spaces, // found in ./json - set: val => { - fs.spaces = val - } -}) - -module.exports.jsonfile = jsonfile // so users of fs-extra can modify jsonFile.spaces diff --git a/lib/json/__tests__/jsonfile-integration.test.js b/lib/json/__tests__/jsonfile-integration.test.js index 27f76654..dde424fc 100644 --- a/lib/json/__tests__/jsonfile-integration.test.js +++ b/lib/json/__tests__/jsonfile-integration.test.js @@ -25,15 +25,10 @@ describe('jsonfile-integration', () => { lastName: 'Richardson' } - const oldSpaces = fse.jsonfile.spaces - fse.jsonfile.spaces = 4 - const file = path.join(TEST_DIR, 'file.json') fse.writeJsonSync(file, obj1) const data = fs.readFileSync(file, 'utf8') - assert.strictEqual(data, JSON.stringify(obj1, null, 4) + '\n') - - fse.jsonfile.spaces = oldSpaces + assert.strictEqual(data, JSON.stringify(obj1, null, 2) + '\n') }) }) }) diff --git a/lib/json/__tests__/spaces.test.js b/lib/json/__tests__/spaces.test.js index ab428c87..27e863d0 100644 --- a/lib/json/__tests__/spaces.test.js +++ b/lib/json/__tests__/spaces.test.js @@ -20,9 +20,6 @@ describe('json spaces', () => { afterEach(done => fse.remove(TEST_DIR, done)) it('should write out the file with appropriate spacing (2)', () => { - fse.spaces = 2 // for legacy compatibility - assert.strictEqual(fse.spaces, 2) - const tempFile = path.join(TEST_DIR, 'temp.json') const data = { first: 'JP', last: 'Richardson' } diff --git a/lib/json/jsonfile.js b/lib/json/jsonfile.js index e3630ee8..8c03f04f 100644 --- a/lib/json/jsonfile.js +++ b/lib/json/jsonfile.js @@ -2,15 +2,21 @@ const jsonFile = require('jsonfile') +function write () { + jsonFile.writeFile.apply({ spaces: 2 }, arguments) +} +function writeSync () { + jsonFile.writeFileSync.apply({ spaces: 2 }, arguments) +} + module.exports = { // jsonfile exports readJson: jsonFile.readFile, readJSON: jsonFile.readFile, readJsonSync: jsonFile.readFileSync, readJSONSync: jsonFile.readFileSync, - writeJson: jsonFile.writeFile, - writeJSON: jsonFile.writeFile, - writeJsonSync: jsonFile.writeFileSync, - writeJSONSync: jsonFile.writeFileSync, - spaces: 2 // default in fs-extra + writeJson: write, + writeJSON: write, + writeJsonSync: writeSync, + writeJSONSync: writeSync }