diff options
Diffstat (limited to 'node_modules/write-pkg')
-rw-r--r-- | node_modules/write-pkg/index.js | 16 | ||||
-rw-r--r-- | node_modules/write-pkg/package.json | 2 | ||||
-rw-r--r-- | node_modules/write-pkg/readme.md | 14 |
3 files changed, 23 insertions, 9 deletions
diff --git a/node_modules/write-pkg/index.js b/node_modules/write-pkg/index.js index 981cc0b54..1c2033af9 100644 --- a/node_modules/write-pkg/index.js +++ b/node_modules/write-pkg/index.js @@ -3,8 +3,6 @@ const path = require('path'); const writeJsonFile = require('write-json-file'); const sortKeys = require('sort-keys'); -const opts = {detectIndent: true}; - const dependencyKeys = new Set([ 'dependencies', 'devDependencies', @@ -26,28 +24,34 @@ function normalize(pkg) { return ret; } -module.exports = (fp, data) => { +module.exports = (fp, data, opts) => { if (typeof fp !== 'string') { + opts = data; data = fp; fp = '.'; } + opts = Object.assign({normalize: true}, opts, {detectIndent: true}); + fp = path.basename(fp) === 'package.json' ? fp : path.join(fp, 'package.json'); - data = normalize(data); + data = opts.normalize ? normalize(data) : data; return writeJsonFile(fp, data, opts); }; -module.exports.sync = (fp, data) => { +module.exports.sync = (fp, data, opts) => { if (typeof fp !== 'string') { + opts = data; data = fp; fp = '.'; } + opts = Object.assign({normalize: true}, opts, {detectIndent: true}); + fp = path.basename(fp) === 'package.json' ? fp : path.join(fp, 'package.json'); - data = normalize(data); + data = opts.normalize ? normalize(data) : data; writeJsonFile.sync(fp, data, opts); }; diff --git a/node_modules/write-pkg/package.json b/node_modules/write-pkg/package.json index c0ca39a2c..4db1dfec3 100644 --- a/node_modules/write-pkg/package.json +++ b/node_modules/write-pkg/package.json @@ -1,6 +1,6 @@ { "name": "write-pkg", - "version": "3.1.0", + "version": "3.2.0", "description": "Write a package.json file", "license": "MIT", "repository": "sindresorhus/write-pkg", diff --git a/node_modules/write-pkg/readme.md b/node_modules/write-pkg/readme.md index a10a8b6d9..ad3ed1cd5 100644 --- a/node_modules/write-pkg/readme.md +++ b/node_modules/write-pkg/readme.md @@ -34,11 +34,11 @@ writePkg(path.join('unicorn', 'package.json'), {foo: true}).then(() => { ## API -### writePkg([path], data) +### writePkg([path], data, [options]) Returns a `Promise`. -### writePkg.sync([path], data) +### writePkg.sync([path], data, [options]) #### path @@ -47,6 +47,16 @@ Default: `process.cwd()` Path to where the `package.json` file should be written or its directory. +#### options + +Type: `Object` + +##### normalize + +Type: `boolean`<br> +Default: `true` + +Remove empty `dependencies`, `devDependencies`, `optionalDependencies` and `peerDependencies` objects. ## Related |