├── examples ├── link.js ├── outdated.js ├── why.js ├── global.js ├── yarn.js ├── upgrade.js ├── peer.js ├── add.js ├── install.js └── dependencies.js ├── .travis.yml ├── .gitattributes ├── .verb.md ├── .editorconfig ├── .gitignore ├── test └── test.js ├── package.json ├── LICENSE ├── .github └── contributing.md ├── .eslintrc.json ├── index.js └── README.md /examples/link.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var yarn = require('..'); 4 | 5 | yarn.link(function(err) { 6 | if (err) return console.error(err); 7 | console.log('done'); 8 | }); 9 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | os: 3 | - linux 4 | - osx 5 | language: node_js 6 | node_js: 7 | - node 8 | - '7' 9 | - '6' 10 | - '5' 11 | - '4' 12 | - '0.12' 13 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Enforce Unix newlines 2 | * text eol=lf 3 | 4 | # binaries 5 | *.ai binary 6 | *.psd binary 7 | *.jpg binary 8 | *.gif binary 9 | *.png binary 10 | *.jpeg binary 11 | -------------------------------------------------------------------------------- /examples/outdated.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var yarn = require('..'); 4 | 5 | yarn.outdated(function(err) { 6 | if (err) return console.error(err); 7 | console.log('done'); 8 | }); 9 | -------------------------------------------------------------------------------- /examples/why.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var yarn = require('..'); 4 | 5 | yarn.why('find-pkg', function(err) { 6 | if (err) return console.error(err); 7 | console.log('done'); 8 | }); 9 | -------------------------------------------------------------------------------- /examples/global.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var yarn = require('..'); 4 | 5 | yarn.global('isobject', function(err) { 6 | if (err) return console.error(err); 7 | console.log('done'); 8 | }); 9 | -------------------------------------------------------------------------------- /examples/yarn.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var yarn = require('..'); 4 | 5 | yarn(['why', 'find-pkg'], function(err) { 6 | if (err) return console.error(err); 7 | console.log('done'); 8 | }); 9 | -------------------------------------------------------------------------------- /examples/upgrade.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var yarn = require('..'); 4 | 5 | yarn.upgrade(['isobject'], function(err) { 6 | if (err) return console.error(err); 7 | console.log('done'); 8 | }); 9 | -------------------------------------------------------------------------------- /examples/peer.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var yarn = require('..'); 4 | 5 | yarn.peerDependencies(['isobject'], function(err) { 6 | if (err) return console.error(err); 7 | console.log('done'); 8 | }); 9 | -------------------------------------------------------------------------------- /examples/add.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var yarn = require('..'); 4 | 5 | yarn.add(['isobject', 'is-valid-app'], function(err) { 6 | if (err) return console.error(err); 7 | console.log('done'); 8 | }); 9 | -------------------------------------------------------------------------------- /examples/install.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var yarn = require('..'); 4 | 5 | yarn.install(['--force', '--har'], function(err) { 6 | if (err) return console.error(err); 7 | console.log('done'); 8 | }); 9 | -------------------------------------------------------------------------------- /examples/dependencies.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var yarn = require('..'); 4 | 5 | yarn.dependencies(function(err, args) { 6 | if (err) return console.error(err); 7 | console.log('done', args); 8 | }); 9 | 10 | -------------------------------------------------------------------------------- /.verb.md: -------------------------------------------------------------------------------- 1 | ## Usage 2 | 3 | ```js 4 | var yarn = require('{%= name %}'); 5 | 6 | yarn(['why', 'isobject'], function(err) { 7 | if (err) throw err; 8 | }); 9 | ``` 10 | 11 | ## API 12 | 13 | {%= apidocs("index.js") %} 14 | 15 | 16 | [cli]: https://yarnpkg.com/en/docs/cli/ -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | end_of_line = lf 6 | charset = utf-8 7 | indent_size = 2 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [{**/{actual,fixtures,expected,templates}/**,*.md}] 12 | trim_trailing_whitespace = false 13 | insert_final_newline = false -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # always ignore files 2 | *.DS_Store 3 | *.sublime-* 4 | 5 | # test related, or directories generated by tests 6 | test/actual 7 | actual 8 | coverage 9 | .nyc* 10 | 11 | # npm 12 | node_modules 13 | npm-debug.log 14 | 15 | # yarn 16 | yarn.lock 17 | yarn-error.log 18 | 19 | # misc 20 | _gh_pages 21 | _draft 22 | _drafts 23 | bower_components 24 | vendor 25 | temp 26 | tmp 27 | TODO.md 28 | -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | require('mocha'); 4 | var assert = require('assert'); 5 | var yarn = require('..'); 6 | 7 | describe('yarn', function() { 8 | it('should export a function', function() { 9 | assert.equal(typeof yarn, 'function'); 10 | }); 11 | 12 | it('should expose methods', function() { 13 | assert.equal(typeof yarn.add, 'function'); 14 | assert.equal(typeof yarn.dependencies, 'function'); 15 | assert.equal(typeof yarn.devDependencies, 'function'); 16 | assert.equal(typeof yarn.global, 'function'); 17 | assert.equal(typeof yarn.install, 'function'); 18 | assert.equal(typeof yarn.link, 'function'); 19 | assert.equal(typeof yarn.optionalDependencies, 'function'); 20 | assert.equal(typeof yarn.outdated, 'function'); 21 | assert.equal(typeof yarn.peerDependencies, 'function'); 22 | assert.equal(typeof yarn.unlink, 'function'); 23 | assert.equal(typeof yarn.upgrade, 'function'); 24 | }); 25 | 26 | it('should throw an error when invalid args are passed', function() { 27 | assert.throws(function() { 28 | sortBy(); 29 | }); 30 | }); 31 | }); 32 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "yarn-api", 3 | "description": "Basic API for yarn.", 4 | "version": "1.1.0", 5 | "homepage": "https://github.com/jonschlinkert/yarn-api", 6 | "author": "Jon Schlinkert (https://github.com/jonschlinkert)", 7 | "repository": "jonschlinkert/yarn-api", 8 | "bugs": { 9 | "url": "https://github.com/jonschlinkert/yarn-api/issues" 10 | }, 11 | "license": "MIT", 12 | "files": [ 13 | "index.js" 14 | ], 15 | "main": "index.js", 16 | "engines": { 17 | "node": ">=0.12.0" 18 | }, 19 | "scripts": { 20 | "test": "mocha" 21 | }, 22 | "dependencies": { 23 | "arr-flatten": "^1.0.3", 24 | "cross-spawn": "^5.1.0", 25 | "find-pkg": "^0.1.2" 26 | }, 27 | "devDependencies": { 28 | "gulp-format-md": "^0.1.12", 29 | "mocha": "^3.3.0" 30 | }, 31 | "keywords": [ 32 | "api", 33 | "yarn" 34 | ], 35 | "verb": { 36 | "toc": false, 37 | "layout": "default", 38 | "tasks": [ 39 | "readme" 40 | ], 41 | "plugins": [ 42 | "gulp-format-md" 43 | ], 44 | "lint": { 45 | "reflinks": true 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Jon Schlinkert 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.github/contributing.md: -------------------------------------------------------------------------------- 1 | # Contributing to yarn 2 | 3 | First and foremost, thank you! We appreciate that you want to contribute to yarn, your time is valuable, and your contributions mean a lot to us. 4 | 5 | **What does "contributing" mean?** 6 | 7 | Creating an issue is the simplest form of contributing to a project. But there are many ways to contribute, including the following: 8 | 9 | - Updating or correcting documentation 10 | - Feature requests 11 | - Bug reports 12 | 13 | If you'd like to learn more about contributing in general, the [Guide to Idiomatic Contributing](https://github.com/jonschlinkert/idiomatic-contributing) has a lot of useful information. 14 | 15 | **Showing support for yarn** 16 | 17 | Please keep in mind that open source software is built by people like you, who spend their free time creating things the rest the community can use. 18 | 19 | Don't have time to contribute? No worries, here are some other ways to show your support for yarn: 20 | 21 | - star the [project](https://github.com/jonschlinkert/yarn) 22 | - tweet your support for yarn 23 | 24 | ## Issues 25 | 26 | ### Before creating an issue 27 | 28 | Please try to determine if the issue is caused by an underlying library, and if so, create the issue there. Sometimes this is difficult to know. We only ask that you attempt to give a reasonable attempt to find out. Oftentimes the readme will have advice about where to go to create issues. 29 | 30 | Try to follow these guidelines 31 | 32 | - **Investigate the issue**: 33 | - **Check the readme** - oftentimes you will find notes about creating issues, and where to go depending on the type of issue. 34 | - Create the issue in the appropriate repository. 35 | 36 | ### Creating an issue 37 | 38 | Please be as descriptive as possible when creating an issue. Give us the information we need to successfully answer your question or address your issue by answering the following in your issue: 39 | 40 | - **version**: please note the version of yarn are you using 41 | - **extensions, plugins, helpers, etc** (if applicable): please list any extensions you're using 42 | - **error messages**: please paste any error messages into the issue, or a [gist](https://gist.github.com/) 43 | 44 | ## Above and beyond 45 | 46 | Here are some tips for creating idiomatic issues. Taking just a little bit extra time will make your issue easier to read, easier to resolve, more likely to be found by others who have the same or similar issue in the future. 47 | 48 | - read the [Guide to Idiomatic Contributing](https://github.com/jonschlinkert/idiomatic-contributing) 49 | - take some time to learn basic markdown. This [markdown cheatsheet](https://gist.github.com/jonschlinkert/5854601) is super helpful, as is the GitHub guide to [basic markdown](https://help.github.com/articles/markdown-basics/). 50 | - Learn about [GitHub Flavored Markdown](https://help.github.com/articles/github-flavored-markdown/). And if you want to really go above and beyond, read [mastering markdown](https://guides.github.com/features/mastering-markdown/). 51 | - use backticks to wrap code. This ensures that code will retain its format, making it much more readable to others 52 | - use syntax highlighting by adding the correct language name after the first "code fence" 53 | 54 | 55 | [node-glob]: https://github.com/isaacs/node-glob 56 | [micromatch]: https://github.com/jonschlinkert/micromatch 57 | [so]: http://stackoverflow.com/questions/tagged/yarn -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "ecmaFeatures": { 3 | "modules": true, 4 | "experimentalObjectRestSpread": true 5 | }, 6 | 7 | "env": { 8 | "browser": false, 9 | "es6": true, 10 | "node": true, 11 | "mocha": true 12 | }, 13 | 14 | "globals": { 15 | "document": false, 16 | "navigator": false, 17 | "window": false 18 | }, 19 | 20 | "rules": { 21 | "accessor-pairs": 2, 22 | "arrow-spacing": [2, { "before": true, "after": true }], 23 | "block-spacing": [2, "always"], 24 | "brace-style": [2, "1tbs", { "allowSingleLine": true }], 25 | "comma-dangle": [2, "never"], 26 | "comma-spacing": [2, { "before": false, "after": true }], 27 | "comma-style": [2, "last"], 28 | "constructor-super": 2, 29 | "curly": [2, "multi-line"], 30 | "dot-location": [2, "property"], 31 | "eol-last": 2, 32 | "eqeqeq": [2, "allow-null"], 33 | "generator-star-spacing": [2, { "before": true, "after": true }], 34 | "handle-callback-err": [2, "^(err|error)$" ], 35 | "indent": [2, 2, { "SwitchCase": 1 }], 36 | "key-spacing": [2, { "beforeColon": false, "afterColon": true }], 37 | "keyword-spacing": [2, { "before": true, "after": true }], 38 | "new-cap": [2, { "newIsCap": true, "capIsNew": false }], 39 | "new-parens": 2, 40 | "no-array-constructor": 2, 41 | "no-caller": 2, 42 | "no-class-assign": 2, 43 | "no-cond-assign": 2, 44 | "no-const-assign": 2, 45 | "no-control-regex": 2, 46 | "no-debugger": 2, 47 | "no-delete-var": 2, 48 | "no-dupe-args": 2, 49 | "no-dupe-class-members": 2, 50 | "no-dupe-keys": 2, 51 | "no-duplicate-case": 2, 52 | "no-empty-character-class": 2, 53 | "no-eval": 2, 54 | "no-ex-assign": 2, 55 | "no-extend-native": 2, 56 | "no-extra-bind": 2, 57 | "no-extra-boolean-cast": 2, 58 | "no-extra-parens": [2, "functions"], 59 | "no-fallthrough": 2, 60 | "no-floating-decimal": 2, 61 | "no-func-assign": 2, 62 | "no-implied-eval": 2, 63 | "no-inner-declarations": [2, "functions"], 64 | "no-invalid-regexp": 2, 65 | "no-irregular-whitespace": 2, 66 | "no-iterator": 2, 67 | "no-label-var": 2, 68 | "no-labels": 2, 69 | "no-lone-blocks": 2, 70 | "no-mixed-spaces-and-tabs": 2, 71 | "no-multi-spaces": 2, 72 | "no-multi-str": 2, 73 | "no-multiple-empty-lines": [2, { "max": 1 }], 74 | "no-native-reassign": 0, 75 | "no-negated-in-lhs": 2, 76 | "no-new": 2, 77 | "no-new-func": 2, 78 | "no-new-object": 2, 79 | "no-new-require": 2, 80 | "no-new-wrappers": 2, 81 | "no-obj-calls": 2, 82 | "no-octal": 2, 83 | "no-octal-escape": 2, 84 | "no-proto": 0, 85 | "no-redeclare": 2, 86 | "no-regex-spaces": 2, 87 | "no-return-assign": 2, 88 | "no-self-compare": 2, 89 | "no-sequences": 2, 90 | "no-shadow-restricted-names": 2, 91 | "no-spaced-func": 2, 92 | "no-sparse-arrays": 2, 93 | "no-this-before-super": 2, 94 | "no-throw-literal": 2, 95 | "no-trailing-spaces": 0, 96 | "no-undef": 2, 97 | "no-undef-init": 2, 98 | "no-unexpected-multiline": 2, 99 | "no-unneeded-ternary": [2, { "defaultAssignment": false }], 100 | "no-unreachable": 2, 101 | "no-unused-vars": [2, { "vars": "all", "args": "none" }], 102 | "no-useless-call": 0, 103 | "no-with": 2, 104 | "one-var": [0, { "initialized": "never" }], 105 | "operator-linebreak": [0, "after", { "overrides": { "?": "before", ":": "before" } }], 106 | "padded-blocks": [0, "never"], 107 | "quotes": [2, "single", "avoid-escape"], 108 | "radix": 2, 109 | "semi": [2, "always"], 110 | "semi-spacing": [2, { "before": false, "after": true }], 111 | "space-before-blocks": [2, "always"], 112 | "space-before-function-paren": [2, "never"], 113 | "space-in-parens": [2, "never"], 114 | "space-infix-ops": 2, 115 | "space-unary-ops": [2, { "words": true, "nonwords": false }], 116 | "spaced-comment": [0, "always", { "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!", ","] }], 117 | "use-isnan": 2, 118 | "valid-typeof": 2, 119 | "wrap-iife": [2, "any"], 120 | "yoda": [2, "never"] 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * yarn-api 3 | * 4 | * Copyright (c) 2017, Jon Schlinkert. 5 | * Released under the MIT License. 6 | */ 7 | 8 | 'use strict'; 9 | 10 | var fs = require('fs'); 11 | var path = require('path'); 12 | var spawn = require('cross-spawn'); 13 | var findPkg = require('find-pkg'); 14 | var flatten = require('arr-flatten'); 15 | var pkgPath = findPkg.sync(process.cwd(), 1); 16 | var cwd = path.dirname(pkgPath); 17 | 18 | /** 19 | * Run `yarn` with the given `cmds`, `args` and callback. 20 | * 21 | * ```js 22 | * yarn(['add', 'isobject'], function(err) { 23 | * if (err) throw err; 24 | * }); 25 | * ``` 26 | * @param {String|Array} `cmds` 27 | * @param {String|Array} `args` 28 | * @param {Function} `cb` Callback 29 | * @details false 30 | * @api public 31 | */ 32 | 33 | function yarn(cmds, args, cb) { 34 | if (typeof args === 'function') { 35 | return yarn(cmds, [], args); 36 | } 37 | 38 | args = arrayify(cmds).concat(arrayify(args)); 39 | spawn('yarn', args, {cwd: cwd, stdio: 'inherit'}) 40 | .on('error', cb) 41 | .on('close', function(code, err) { 42 | cb(err, code); 43 | }); 44 | }; 45 | 46 | /** 47 | * Symlink the current project to global `node_modules`. 48 | * Visit the yarn docs for [link][cli]{link}. 49 | * 50 | * ```js 51 | * yarn.link(function(err) { 52 | * if (err) throw err; 53 | * }); 54 | * ``` 55 | * @param {Function} `cb` Callback 56 | * @api public 57 | */ 58 | 59 | yarn.link = function(args, cb) { 60 | yarn('link', args, cb); 61 | }; 62 | 63 | /** 64 | * Unlink a previously created symlink for a package. 65 | * Visit the yarn docs for [unlink][cli]{unlink}. 66 | * 67 | * ```js 68 | * yarn.unlink(function(err) { 69 | * if (err) throw err; 70 | * }); 71 | * ``` 72 | * @param {Function} `cb` Callback 73 | * @api public 74 | */ 75 | 76 | yarn.unlink = function(args, cb) { 77 | yarn('unlink', args, cb); 78 | }; 79 | 80 | /** 81 | * Installs one or more packages and any packages they depend on. 82 | * 83 | * Visit the yarn docs for [add][cli]{add}. 84 | * 85 | * ```js 86 | * yarn.add('isobject', function(err) { 87 | * if (err) throw err; 88 | * }); 89 | * ``` 90 | * @param {String|Array} `names` package names 91 | * @param {Function} `cb` Callback 92 | * @api public 93 | */ 94 | 95 | yarn.add = function(args, cb) { 96 | yarn('add', args, cb); 97 | }; 98 | 99 | /** 100 | * Execute `yarn add --global` with one or more package `names`. 101 | * 102 | * ```js 103 | * yarn.global('mocha', function(err) { 104 | * if (err) throw err; 105 | * }); 106 | * ``` 107 | * @name .global 108 | * @param {String|Array} `names` One or more package names to install 109 | * @param {Function} `cb` Callback 110 | * @api public 111 | */ 112 | 113 | yarn.global = function(names, cb) { 114 | yarn('global', ['add'].concat(names), cb); 115 | }; 116 | 117 | /** 118 | * Install all dependencies for a project. This is most commonly used when 119 | * you have just checked out code for a project, or when another developer 120 | * on the project has added a new dependency that you need to pick up. 121 | * 122 | * Visit the yarn docs for [install][cli]{install}. 123 | * 124 | * ```js 125 | * yarn.install(function(err) { 126 | * if (err) throw err; 127 | * }); 128 | * ``` 129 | * @param {Function} `cb` Callback 130 | * @api public 131 | */ 132 | 133 | yarn.install = function(args, cb) { 134 | yarn('install', args, cb); 135 | }; 136 | 137 | /** 138 | * Checks for outdated package dependencies. 139 | * 140 | * Visit the yarn docs for [outdated][cli]{outdated} 141 | * 142 | * ```js 143 | * yarn.outdated('isobject', function(err) { 144 | * if (err) throw err; 145 | * }); 146 | * ``` 147 | * @param {String|Array} `names` package names 148 | * @param {Function} `cb` Callback 149 | * @api public 150 | */ 151 | 152 | yarn.outdated = function(args, cb) { 153 | yarn('outdated', args, cb); 154 | }; 155 | 156 | /** 157 | * Updates all dependencies to their latest version based on the version 158 | * range specified in the package.json file. The `yarn.lock` file will be 159 | * (re)created as well. 160 | * 161 | * Visit the yarn docs for [upgrade][cli]{upgrade}. 162 | * 163 | * ```js 164 | * yarn.upgrade(function(err) { 165 | * if (err) throw err; 166 | * }); 167 | * ``` 168 | * @param {Function} `cb` Callback 169 | * @api public 170 | */ 171 | 172 | yarn.upgrade = function(args, cb) { 173 | yarn('upgrade', args, cb); 174 | }; 175 | 176 | /** 177 | * Remove a package from your direct dependencies, updating 178 | * your package.json and yarn.lock files in the process. 179 | * 180 | * Visit the yarn docs for [remove][cli]{remove}. 181 | * 182 | * ```js 183 | * yarn.remove('isobject', function(err) { 184 | * if (err) throw err; 185 | * }); 186 | * ``` 187 | * @param {Function} `args` 188 | * @param {Function} `cb` Callback 189 | * @api public 190 | */ 191 | 192 | yarn.remove = function(args, cb) { 193 | yarn('remove', args, cb); 194 | }; 195 | 196 | /** 197 | * Show information about why a package is installed. 198 | * 199 | * Visit the yarn docs for [why][cli]{why}. 200 | * 201 | * ```js 202 | * yarn.why('isobject', function(err) { 203 | * if (err) throw err; 204 | * }); 205 | * ``` 206 | * @param {Function} `args` 207 | * @param {Function} `cb` Callback 208 | * @api public 209 | */ 210 | 211 | yarn.why = function(args, cb) { 212 | yarn('why', args, cb); 213 | }; 214 | 215 | /** 216 | * Execute `yarn add` with one or more package `names`. 217 | * Updates `dependencies` in package.json. 218 | * 219 | * ```js 220 | * yarn.dependencies('micromatch', function(err) { 221 | * if (err) throw err; 222 | * }); 223 | * ``` 224 | * @param {String|Array} `names` One or more package names to install 225 | * @param {Function} `cb` Callback 226 | * @api public 227 | */ 228 | 229 | yarn.dependencies = function(names, cb) { 230 | deps('dependencies', null, names, cb); 231 | }; 232 | 233 | /** 234 | * Execute `yarn add --dev` with one or more package `names`. 235 | * Updates `devDependencies` in package.json. 236 | * 237 | * ```js 238 | * // defined as a string 239 | * yarn.devDependencies('micromatch', function(err) { 240 | * if (err) throw err; 241 | * }); 242 | * 243 | * // or as an array 244 | * yarn.devDependencies(['micromatch', 'is-glob'], function(err) { 245 | * if (err) throw err; 246 | * }); 247 | * ``` 248 | * @param {String|Array} `names` One or more package names to install 249 | * @param {Function} `cb` Callback 250 | * @api public 251 | */ 252 | 253 | yarn.devDependencies = function(names, cb) { 254 | deps('devDependencies', '-D', names, cb); 255 | }; 256 | 257 | /** 258 | * Execute `yarn add --peer` with one or more package `names`. 259 | * Updates `peerDependencies` in package.json. 260 | * 261 | * ```js 262 | * yarn.peerDependencies('isobject', function(err) { 263 | * if (err) throw err; 264 | * }); 265 | * ``` 266 | * @param {String|Array} `names` One or more package names to install 267 | * @param {Function} `cb` Callback 268 | * @api public 269 | */ 270 | 271 | yarn.peerDependencies = function(names, cb) { 272 | deps('peerDependencies', '-P', names, cb); 273 | }; 274 | 275 | /** 276 | * Execute `yarn add --optional` with one or more package `names`. 277 | * Updates `optionalDependencies` in package.json. 278 | * 279 | * ```js 280 | * yarn.optionalDependencies('isobject', function(err) { 281 | * if (err) throw err; 282 | * }); 283 | * ``` 284 | * @param {String|Array} `names` One or more package names to install 285 | * @param {Function} `cb` Callback 286 | * @api public 287 | */ 288 | 289 | yarn.optionalDependencies = function(names, cb) { 290 | deps('optionalDependencies', '-O', names, cb); 291 | }; 292 | 293 | /** 294 | * Install the given `type` of dependencies, 295 | * with the specified `flags` 296 | */ 297 | 298 | function deps(type, flags, names, cb) { 299 | names = flatten([].slice.call(arguments, 2)); 300 | cb = names.pop(); 301 | 302 | if (type && names.length === 0) { 303 | names = keys(type); 304 | } 305 | 306 | if (!names.length) { 307 | cb(); 308 | return; 309 | } 310 | 311 | yarn.add(arrayify(flags).concat(names), cb); 312 | } 313 | 314 | /** 315 | * Get the keys from package.json 316 | */ 317 | 318 | function keys(prop) { 319 | return Object.keys(loadPkg()[prop] || {}); 320 | } 321 | 322 | /** 323 | * Get the package.json for the current project 324 | */ 325 | 326 | function loadPkg() { 327 | return JSON.parse(fs.readFileSync(pkgPath, 'utf8')); 328 | } 329 | 330 | /** 331 | * Cast `val` to an array 332 | */ 333 | 334 | function arrayify(val) { 335 | return val ? (Array.isArray(val) ? val : [val]) : []; 336 | } 337 | 338 | /** 339 | * Expose `yarn` 340 | */ 341 | 342 | module.exports = yarn; 343 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # yarn-api [![NPM version](https://img.shields.io/npm/v/yarn-api.svg?style=flat)](https://www.npmjs.com/package/yarn-api) [![NPM monthly downloads](https://img.shields.io/npm/dm/yarn-api.svg?style=flat)](https://npmjs.org/package/yarn-api) [![NPM total downloads](https://img.shields.io/npm/dt/yarn-api.svg?style=flat)](https://npmjs.org/package/yarn-api) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/yarn-api.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/yarn-api) 2 | 3 | > Basic API for yarn. 4 | 5 | ## Install 6 | 7 | Install with [npm](https://www.npmjs.com/): 8 | 9 | ```sh 10 | $ npm install --save yarn-api 11 | ``` 12 | 13 | Install with [yarn](https://yarnpkg.com): 14 | 15 | ```sh 16 | $ yarn add yarn-api 17 | ``` 18 | 19 | ## Usage 20 | 21 | ```js 22 | var yarn = require('yarn-api'); 23 | 24 | yarn(['why', 'isobject'], function(err) { 25 | if (err) throw err; 26 | }); 27 | ``` 28 | 29 | ## API 30 | 31 | ### [yarn](index.js#L33) 32 | 33 | Run `yarn` with the given `cmds`, `args` and callback. 34 | 35 | **Params** 36 | 37 | * `cmds` **{String|Array}** 38 | * `args` **{String|Array}** 39 | * `cb` **{Function}**: Callback 40 | 41 | **Example** 42 | 43 | ```js 44 | yarn(['add', 'isobject'], function(err) { 45 | if (err) throw err; 46 | }); 47 | ``` 48 | 49 |
50 | .link 51 | 52 | ### [.link](index.js#L59) 53 | 54 | Symlink the current project to global `node_modules`. Visit the yarn docs for [link](https://yarnpkg.com/en/docs/cli/link). 55 | 56 | **Params** 57 | 58 | * `cb` **{Function}**: Callback 59 | 60 | **Example** 61 | 62 | ```js 63 | yarn.link(function(err) { 64 | if (err) throw err; 65 | }); 66 | ``` 67 | 68 |
69 | 70 |
71 | .unlink 72 | 73 | ### [.unlink](index.js#L76) 74 | 75 | Unlink a previously created symlink for a package. Visit the yarn docs for [unlink](https://yarnpkg.com/en/docs/cli/unlink). 76 | 77 | **Params** 78 | 79 | * `cb` **{Function}**: Callback 80 | 81 | **Example** 82 | 83 | ```js 84 | yarn.unlink(function(err) { 85 | if (err) throw err; 86 | }); 87 | ``` 88 | 89 |
90 | 91 |
92 | .add 93 | 94 | ### [.add](index.js#L95) 95 | 96 | Installs one or more packages and any packages they depend on. 97 | 98 | Visit the yarn docs for [add](https://yarnpkg.com/en/docs/cli/add). 99 | 100 | **Params** 101 | 102 | * `names` **{String|Array}**: package names 103 | * `cb` **{Function}**: Callback 104 | 105 | **Example** 106 | 107 | ```js 108 | yarn.add('isobject', function(err) { 109 | if (err) throw err; 110 | }); 111 | ``` 112 | 113 |
114 | 115 |
116 | .global 117 | 118 | ### [.global](index.js#L113) 119 | 120 | Execute `yarn add --global` with one or more package `names`. 121 | 122 | **Params** 123 | 124 | * `names` **{String|Array}**: One or more package names to install 125 | * `cb` **{Function}**: Callback 126 | 127 | **Example** 128 | 129 | ```js 130 | yarn.global('mocha', function(err) { 131 | if (err) throw err; 132 | }); 133 | ``` 134 | 135 |
136 | 137 |
138 | .install 139 | 140 | ### [.install](index.js#L133) 141 | 142 | Install all dependencies for a project. This is most commonly used when you have just checked out code for a project, or when another developer on the project has added a new dependency that you need to pick up. 143 | 144 | Visit the yarn docs for [install](https://yarnpkg.com/en/docs/cli/install). 145 | 146 | **Params** 147 | 148 | * `cb` **{Function}**: Callback 149 | 150 | **Example** 151 | 152 | ```js 153 | yarn.install(function(err) { 154 | if (err) throw err; 155 | }); 156 | ``` 157 | 158 |
159 | 160 |
161 | .outdated 162 | 163 | ### [.outdated](index.js#L152) 164 | 165 | Checks for outdated package dependencies. 166 | 167 | Visit the yarn docs for [outdated](https://yarnpkg.com/en/docs/cli/outdated) 168 | 169 | **Params** 170 | 171 | * `names` **{String|Array}**: package names 172 | * `cb` **{Function}**: Callback 173 | 174 | **Example** 175 | 176 | ```js 177 | yarn.outdated('isobject', function(err) { 178 | if (err) throw err; 179 | }); 180 | ``` 181 | 182 |
183 | 184 |
185 | .upgrade 186 | 187 | ### [.upgrade](index.js#L172) 188 | 189 | Updates all dependencies to their latest version based on the version range specified in the package.json file. The `yarn.lock` file will be (re)created as well. 190 | 191 | Visit the yarn docs for [upgrade](https://yarnpkg.com/en/docs/cli/upgrade). 192 | 193 | **Params** 194 | 195 | * `cb` **{Function}**: Callback 196 | 197 | **Example** 198 | 199 | ```js 200 | yarn.upgrade(function(err) { 201 | if (err) throw err; 202 | }); 203 | ``` 204 | 205 |
206 | 207 |
208 | .remove 209 | 210 | ### [.remove](index.js#L192) 211 | 212 | Remove a package from your direct dependencies, updating your package.json and yarn.lock files in the process. 213 | 214 | Visit the yarn docs for [remove](https://yarnpkg.com/en/docs/cli/remove). 215 | 216 | **Params** 217 | 218 | * `args` **{Function}** 219 | * `cb` **{Function}**: Callback 220 | 221 | **Example** 222 | 223 | ```js 224 | yarn.remove('isobject', function(err) { 225 | if (err) throw err; 226 | }); 227 | ``` 228 | 229 |
230 | 231 |
232 | .why 233 | 234 | ### [.why](index.js#L211) 235 | 236 | Show information about why a package is installed. 237 | 238 | Visit the yarn docs for [why](https://yarnpkg.com/en/docs/cli/why). 239 | 240 | **Params** 241 | 242 | * `args` **{Function}** 243 | * `cb` **{Function}**: Callback 244 | 245 | **Example** 246 | 247 | ```js 248 | yarn.why('isobject', function(err) { 249 | if (err) throw err; 250 | }); 251 | ``` 252 | 253 |
254 | 255 |
256 | .dependencies 257 | 258 | ### [.dependencies](index.js#L229) 259 | 260 | Execute `yarn add` with one or more package `names`. Updates `dependencies` in package.json. 261 | 262 | **Params** 263 | 264 | * `names` **{String|Array}**: One or more package names to install 265 | * `cb` **{Function}**: Callback 266 | 267 | **Example** 268 | 269 | ```js 270 | yarn.dependencies('micromatch', function(err) { 271 | if (err) throw err; 272 | }); 273 | ``` 274 | 275 |
276 | 277 |
278 | .devDependencies 279 | 280 | ### [.devDependencies](index.js#L253) 281 | 282 | Execute `yarn add --dev` with one or more package `names`. Updates `devDependencies` in package.json. 283 | 284 | **Params** 285 | 286 | * `names` **{String|Array}**: One or more package names to install 287 | * `cb` **{Function}**: Callback 288 | 289 | **Example** 290 | 291 | ```js 292 | // defined as a string 293 | yarn.devDependencies('micromatch', function(err) { 294 | if (err) throw err; 295 | }); 296 | 297 | // or as an array 298 | yarn.devDependencies(['micromatch', 'is-glob'], function(err) { 299 | if (err) throw err; 300 | }); 301 | ``` 302 | 303 |
304 | 305 |
306 | .peerDependencies 307 | 308 | ### [.peerDependencies](index.js#L271) 309 | 310 | Execute `yarn add --peer` with one or more package `names`. Updates `peerDependencies` in package.json. 311 | 312 | **Params** 313 | 314 | * `names` **{String|Array}**: One or more package names to install 315 | * `cb` **{Function}**: Callback 316 | 317 | **Example** 318 | 319 | ```js 320 | yarn.peerDependencies('isobject', function(err) { 321 | if (err) throw err; 322 | }); 323 | ``` 324 | 325 |
326 | 327 |
328 | .optionalDependencies 329 | 330 | ### [.optionalDependencies](index.js#L289) 331 | 332 | Execute `yarn add --optional` with one or more package `names`. Updates `optionalDependencies` in package.json. 333 | 334 | **Params** 335 | 336 | * `names` **{String|Array}**: One or more package names to install 337 | * `cb` **{Function}**: Callback 338 | 339 | **Example** 340 | 341 | ```js 342 | yarn.optionalDependencies('isobject', function(err) { 343 | if (err) throw err; 344 | }); 345 | ``` 346 | 347 |
348 | 349 | ## About 350 | 351 | ### Contributing 352 | 353 | Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new). 354 | 355 | Please read the [contributing guide](.github/contributing.md) for advice on opening issues, pull requests, and coding standards. 356 | 357 | ### Building docs 358 | 359 | _(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_ 360 | 361 | To generate the readme, run the following command: 362 | 363 | ```sh 364 | $ npm install -g verbose/verb#dev verb-generate-readme && verb 365 | ``` 366 | 367 | ### Running tests 368 | 369 | Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command: 370 | 371 | ```sh 372 | $ npm install && npm test 373 | ``` 374 | 375 | ### Author 376 | 377 | **Jon Schlinkert** 378 | 379 | * [github/jonschlinkert](https://github.com/jonschlinkert) 380 | * [twitter/jonschlinkert](https://twitter.com/jonschlinkert) 381 | 382 | ### License 383 | 384 | Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert). 385 | Released under the [MIT License](LICENSE). 386 | 387 | *** 388 | 389 | _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on April 27, 2017._ --------------------------------------------------------------------------------