From c0f56eed29a7d3d922129d3d11e992946eace1cb Mon Sep 17 00:00:00 2001 From: RyanZim Date: Sat, 8 Apr 2017 19:43:53 -0400 Subject: [PATCH] BREAKING: Don't use spaces for JSON writing, remove global setting --- lib/index.js | 11 ------ .../__tests__/jsonfile-integration.test.js | 7 +--- lib/json/__tests__/spaces.test.js | 34 ------------------- lib/json/jsonfile.js | 3 +- 4 files changed, 2 insertions(+), 53 deletions(-) delete mode 100644 lib/json/__tests__/spaces.test.js 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..64177de4 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) + '\n') }) }) }) diff --git a/lib/json/__tests__/spaces.test.js b/lib/json/__tests__/spaces.test.js deleted file mode 100644 index ab428c87..00000000 --- a/lib/json/__tests__/spaces.test.js +++ /dev/null @@ -1,34 +0,0 @@ -'use strict' - -const fs = require('fs') -const os = require('os') -const fse = require('../../') -const path = require('path') -const assert = require('assert') - -/* global afterEach, beforeEach, describe, it */ -// trinity: mocha - -describe('json spaces', () => { - let TEST_DIR - - beforeEach(done => { - TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'json-spaces') - fse.emptyDir(TEST_DIR, done) - }) - - 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' } - fse.outputJsonSync(tempFile, data) - - const dataRead = fs.readFileSync(tempFile, 'utf8') - assert.strictEqual(dataRead, JSON.stringify(data, null, 2) + '\n') - }) -}) diff --git a/lib/json/jsonfile.js b/lib/json/jsonfile.js index e3630ee8..ad235eba 100644 --- a/lib/json/jsonfile.js +++ b/lib/json/jsonfile.js @@ -11,6 +11,5 @@ module.exports = { writeJson: jsonFile.writeFile, writeJSON: jsonFile.writeFile, writeJsonSync: jsonFile.writeFileSync, - writeJSONSync: jsonFile.writeFileSync, - spaces: 2 // default in fs-extra + writeJSONSync: jsonFile.writeFileSync }