From 7fff4499fd915bcea3fa93b1aa8b35f4fe7a6027 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Sun, 28 May 2017 00:38:50 +0200 Subject: add linting (and some initial fixes) --- node_modules/write-pkg/index.js | 49 ++++++++++++++++++++++++++++++ node_modules/write-pkg/license | 21 +++++++++++++ node_modules/write-pkg/package.json | 41 ++++++++++++++++++++++++++ node_modules/write-pkg/readme.md | 59 +++++++++++++++++++++++++++++++++++++ 4 files changed, 170 insertions(+) create mode 100644 node_modules/write-pkg/index.js create mode 100644 node_modules/write-pkg/license create mode 100644 node_modules/write-pkg/package.json create mode 100644 node_modules/write-pkg/readme.md (limited to 'node_modules/write-pkg') diff --git a/node_modules/write-pkg/index.js b/node_modules/write-pkg/index.js new file mode 100644 index 000000000..262fa925a --- /dev/null +++ b/node_modules/write-pkg/index.js @@ -0,0 +1,49 @@ +'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) => { + if (typeof fp !== 'string') { + data = fp; + fp = '.'; + } + + fp = path.basename(fp) === 'package.json' ? fp : path.join(fp, 'package.json'); + + data = normalize(data); + + return writeJsonFile(fp, data, opts); +}; + +module.exports.sync = (fp, data) => { + if (typeof fp !== 'string') { + data = fp; + fp = '.'; + } + + fp = path.basename(fp) === 'package.json' ? fp : path.join(fp, 'package.json'); + + data = normalize(data); + + writeJsonFile.sync(fp, data, opts); +}; diff --git a/node_modules/write-pkg/license b/node_modules/write-pkg/license new file mode 100644 index 000000000..654d0bfe9 --- /dev/null +++ b/node_modules/write-pkg/license @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) Sindre Sorhus (sindresorhus.com) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/node_modules/write-pkg/package.json b/node_modules/write-pkg/package.json new file mode 100644 index 000000000..c3773513c --- /dev/null +++ b/node_modules/write-pkg/package.json @@ -0,0 +1,41 @@ +{ + "name": "write-pkg", + "version": "2.1.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": "^1.1.2", + "write-json-file": "^2.0.0" + }, + "devDependencies": { + "ava": "*", + "read-pkg": "^2.0.0", + "tempfile": "^1.1.1", + "xo": "*" + } +} diff --git a/node_modules/write-pkg/readme.md b/node_modules/write-pkg/readme.md new file mode 100644 index 000000000..fa51dad26 --- /dev/null +++ b/node_modules/write-pkg/readme.md @@ -0,0 +1,59 @@ +# write-pkg [![Build Status](https://travis-ci.org/sindresorhus/write-pkg.svg?branch=master)](https://travis-ci.org/sindresorhus/write-pkg) + +> Write a `package.json` file + +Writes atomically and creates directories for you as needed. Sorts dependencies when writing. + + +## Install + +``` +$ npm install --save write-pkg +``` + + +## Usage + +```js +const path = require('path'); +const writePkg = require('write-pkg'); + +writePkg({foo: true}).then(() => { + console.log('done'); +}); + +writePkg(__dirname, {foo: true}).then(() => { + console.log('done'); +}); + +writePkg(path.join('unicorn', 'package.json'), {foo: true}).then(() => { + console.log('done'); +}); +``` + + +## API + +### writePkg([path], data) + +Returns a `Promise`. + +### writePkg.sync([path], data) + +#### path + +Type: `string`
+Default: `process.cwd()` + +Path to where the `package.json` file should be written or its directory. + + +## Related + +- [read-pkg](https://github.com/sindresorhus/read-pkg) - Read a `package.json` file +- [write-json-file](https://github.com/sindresorhus/write-json-file) - Stringify and write JSON to a file atomically + + +## License + +MIT © [Sindre Sorhus](https://sindresorhus.com) -- cgit v1.2.3