forked from jprichardson/node-fs-extra
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Upgrade jsonfile Fixes jprichardson#745 * Test from main entry point * Make outputJson() mutation-proof Fixes jprichardson#702 * Update outputJsonSync() to match async implementation
- Loading branch information
Showing
7 changed files
with
38 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
'use strict' | ||
|
||
const u = require('universalify').fromCallback | ||
const jsonFile = require('jsonfile') | ||
|
||
module.exports = { | ||
// jsonfile exports | ||
readJson: u(jsonFile.readFile), | ||
readJson: jsonFile.readFile, | ||
readJsonSync: jsonFile.readFileSync, | ||
writeJson: u(jsonFile.writeFile), | ||
writeJson: jsonFile.writeFile, | ||
writeJsonSync: jsonFile.writeFileSync | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,12 @@ | ||
'use strict' | ||
|
||
const fs = require('graceful-fs') | ||
const path = require('path') | ||
const mkdir = require('../mkdirs') | ||
const jsonFile = require('./jsonfile') | ||
const { stringify } = require('jsonfile/utils') | ||
const { outputFileSync } = require('../output') | ||
|
||
function outputJsonSync (file, data, options) { | ||
const dir = path.dirname(file) | ||
const str = stringify(data, options) | ||
|
||
if (!fs.existsSync(dir)) { | ||
mkdir.mkdirsSync(dir) | ||
} | ||
|
||
jsonFile.writeJsonSync(file, data, options) | ||
outputFileSync(file, str, options) | ||
} | ||
|
||
module.exports = outputJsonSync |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,12 @@ | ||
'use strict' | ||
|
||
const path = require('path') | ||
const mkdir = require('../mkdirs') | ||
const pathExists = require('../path-exists').pathExists | ||
const jsonFile = require('./jsonfile') | ||
const { stringify } = require('jsonfile/utils') | ||
const { outputFile } = require('../output') | ||
|
||
function outputJson (file, data, options, callback) { | ||
if (typeof options === 'function') { | ||
callback = options | ||
options = {} | ||
} | ||
async function outputJson (file, data, options = {}) { | ||
const str = stringify(data, options) | ||
|
||
const dir = path.dirname(file) | ||
|
||
pathExists(dir, (err, itDoes) => { | ||
if (err) return callback(err) | ||
if (itDoes) return jsonFile.writeJson(file, data, options, callback) | ||
|
||
mkdir.mkdirs(dir, err => { | ||
if (err) return callback(err) | ||
jsonFile.writeJson(file, data, options, callback) | ||
}) | ||
}) | ||
await outputFile(file, str, options) | ||
} | ||
|
||
module.exports = outputJson |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters