write-pkg
Advanced tools
Comparing version 2.0.0 to 2.1.0
22
index.js
'use strict'; | ||
const path = require('path'); | ||
const writeJsonFile = require('write-json-file'); | ||
const sortKeys = require('sort-keys'); | ||
const opts = {indent: 2}; | ||
const dependencyKeys = new Set([ | ||
'dependencies', | ||
'devDependencies', | ||
'optionalDependencies', | ||
'peerDependencies' | ||
]); | ||
function normalize(pkg) { | ||
const ret = {}; | ||
for (const key of Object.keys(pkg)) { | ||
ret[key] = dependencyKeys.has(key) ? sortKeys(pkg[key]) : pkg[key]; | ||
} | ||
return ret; | ||
} | ||
module.exports = (fp, data) => { | ||
@@ -15,2 +33,4 @@ if (typeof fp !== 'string') { | ||
data = normalize(data); | ||
return writeJsonFile(fp, data, opts); | ||
@@ -27,3 +47,5 @@ }; | ||
data = normalize(data); | ||
writeJsonFile.sync(fp, data, opts); | ||
}; |
{ | ||
"name": "write-pkg", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Write a package.json file", | ||
@@ -32,2 +32,3 @@ "license": "MIT", | ||
"dependencies": { | ||
"sort-keys": "^1.1.2", | ||
"write-json-file": "^2.0.0" | ||
@@ -40,6 +41,3 @@ }, | ||
"xo": "*" | ||
}, | ||
"xo": { | ||
"esnext": true | ||
} | ||
} |
@@ -5,3 +5,3 @@ # write-pkg [![Build Status](https://travis-ci.org/sindresorhus/write-pkg.svg?branch=master)](https://travis-ci.org/sindresorhus/write-pkg) | ||
Writes atomically and creates directories for you as needed. | ||
Writes atomically and creates directories for you as needed. Sorts dependencies when writing. | ||
@@ -8,0 +8,0 @@ |
3917
36
2
+ Addedsort-keys@^1.1.2
+ Addedsort-keys@1.1.2(transitive)