Skip to content

Commit

Permalink
BREAKING: Remove support for setting spaces for JSON writing
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanZim committed Apr 8, 2017
1 parent b549b04 commit 8623e4e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 25 deletions.
11 changes: 0 additions & 11 deletions lib/index.js
Expand Up @@ -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
7 changes: 1 addition & 6 deletions lib/json/__tests__/jsonfile-integration.test.js
Expand Up @@ -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')
})
})
})
3 changes: 0 additions & 3 deletions lib/json/__tests__/spaces.test.js
Expand Up @@ -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' }
Expand Down
16 changes: 11 additions & 5 deletions lib/json/jsonfile.js
Expand Up @@ -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
}

0 comments on commit 8623e4e

Please sign in to comment.