Comparing version 3.2.0 to 4.0.0
58
index.js
@@ -13,46 +13,54 @@ 'use strict'; | ||
function normalize(pkg) { | ||
const ret = {}; | ||
function normalize(packageJson) { | ||
const result = {}; | ||
for (const key of Object.keys(pkg)) { | ||
for (const key of Object.keys(packageJson)) { | ||
if (!dependencyKeys.has(key)) { | ||
ret[key] = pkg[key]; | ||
} else if (Object.keys(pkg[key]).length !== 0) { | ||
ret[key] = sortKeys(pkg[key]); | ||
result[key] = packageJson[key]; | ||
} else if (Object.keys(packageJson[key]).length !== 0) { | ||
result[key] = sortKeys(packageJson[key]); | ||
} | ||
} | ||
return ret; | ||
return result; | ||
} | ||
module.exports = (fp, data, opts) => { | ||
if (typeof fp !== 'string') { | ||
opts = data; | ||
data = fp; | ||
fp = '.'; | ||
module.exports = async (filePath, data, options) => { | ||
if (typeof filePath !== 'string') { | ||
options = data; | ||
data = filePath; | ||
filePath = '.'; | ||
} | ||
opts = Object.assign({normalize: true}, opts, {detectIndent: true}); | ||
options = { | ||
normalize: true, | ||
...options, | ||
detectIndent: true | ||
}; | ||
fp = path.basename(fp) === 'package.json' ? fp : path.join(fp, 'package.json'); | ||
filePath = path.basename(filePath) === 'package.json' ? filePath : path.join(filePath, 'package.json'); | ||
data = opts.normalize ? normalize(data) : data; | ||
data = options.normalize ? normalize(data) : data; | ||
return writeJsonFile(fp, data, opts); | ||
return writeJsonFile(filePath, data, options); | ||
}; | ||
module.exports.sync = (fp, data, opts) => { | ||
if (typeof fp !== 'string') { | ||
opts = data; | ||
data = fp; | ||
fp = '.'; | ||
module.exports.sync = (filePath, data, options) => { | ||
if (typeof filePath !== 'string') { | ||
options = data; | ||
data = filePath; | ||
filePath = '.'; | ||
} | ||
opts = Object.assign({normalize: true}, opts, {detectIndent: true}); | ||
options = { | ||
normalize: true, | ||
...options, | ||
detectIndent: true | ||
}; | ||
fp = path.basename(fp) === 'package.json' ? fp : path.join(fp, 'package.json'); | ||
filePath = path.basename(filePath) === 'package.json' ? filePath : path.join(filePath, 'package.json'); | ||
data = opts.normalize ? normalize(data) : data; | ||
data = options.normalize ? normalize(data) : data; | ||
writeJsonFile.sync(fp, data, opts); | ||
writeJsonFile.sync(filePath, data, options); | ||
}; |
{ | ||
"name": "write-pkg", | ||
"version": "3.2.0", | ||
"description": "Write a package.json file", | ||
"license": "MIT", | ||
"repository": "sindresorhus/write-pkg", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=4" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"json", | ||
"write", | ||
"stringify", | ||
"file", | ||
"fs", | ||
"graceful", | ||
"pkg", | ||
"package" | ||
], | ||
"dependencies": { | ||
"sort-keys": "^2.0.0", | ||
"write-json-file": "^2.2.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "*", | ||
"read-pkg": "^2.0.0", | ||
"tempfile": "^2.0.0", | ||
"xo": "*" | ||
} | ||
"name": "write-pkg", | ||
"version": "4.0.0", | ||
"description": "Write a package.json file", | ||
"license": "MIT", | ||
"repository": "sindresorhus/write-pkg", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=8" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava && tsd" | ||
}, | ||
"files": [ | ||
"index.js", | ||
"index.d.ts" | ||
], | ||
"keywords": [ | ||
"json", | ||
"write", | ||
"stringify", | ||
"file", | ||
"fs", | ||
"graceful", | ||
"package" | ||
], | ||
"dependencies": { | ||
"sort-keys": "^2.0.0", | ||
"type-fest": "^0.4.1", | ||
"write-json-file": "^3.2.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^1.4.1", | ||
"read-pkg": "^5.1.1", | ||
"tempfile": "^3.0.0", | ||
"tsd": "^0.7.2", | ||
"xo": "^0.24.0" | ||
} | ||
} |
@@ -19,15 +19,14 @@ # write-pkg [![Build Status](https://travis-ci.org/sindresorhus/write-pkg.svg?branch=master)](https://travis-ci.org/sindresorhus/write-pkg) | ||
const path = require('path'); | ||
const writePkg = require('write-pkg'); | ||
const writePackage = require('write-pkg'); | ||
writePkg({foo: true}).then(() => { | ||
(async () => { | ||
await writePackage({foo: true}); | ||
console.log('done'); | ||
}); | ||
writePkg(__dirname, {foo: true}).then(() => { | ||
await writePackage(__dirname, {foo: true}); | ||
console.log('done'); | ||
}); | ||
writePkg(path.join('unicorn', 'package.json'), {foo: true}).then(() => { | ||
await writePackage(path.join('unicorn', 'package.json'), {foo: true}); | ||
console.log('done'); | ||
}); | ||
})(); | ||
``` | ||
@@ -38,7 +37,7 @@ | ||
### writePkg([path], data, [options]) | ||
### writePackage([path], data, [options]) | ||
Returns a `Promise`. | ||
### writePkg.sync([path], data, [options]) | ||
### writePackage.sync([path], data, [options]) | ||
@@ -54,3 +53,3 @@ #### path | ||
Type: `Object` | ||
Type: `object` | ||
@@ -64,2 +63,3 @@ ##### normalize | ||
## Related | ||
@@ -66,0 +66,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6510
5
102
3
5
+ Addedtype-fest@^0.4.1
+ Addedmake-dir@2.1.0(transitive)
+ Addedpify@4.0.1(transitive)
+ Addedsemver@5.7.2(transitive)
+ Addedtype-fest@0.4.1(transitive)
+ Addedwrite-json-file@3.2.0(transitive)
- Removedmake-dir@1.3.0(transitive)
- Removedpify@3.0.0(transitive)
- Removedwrite-json-file@2.3.0(transitive)
Updatedwrite-json-file@^3.2.0