├── .gitignore ├── package.json ├── LICENSE ├── README.md └── src └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # nyc test coverage 18 | .nyc_output 19 | 20 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 21 | .grunt 22 | 23 | # node-waf configuration 24 | .lock-wscript 25 | 26 | # Compiled binary addons (http://nodejs.org/api/addons.html) 27 | build/Release 28 | 29 | # Dependency directories 30 | node_modules 31 | jspm_packages 32 | 33 | # Optional npm cache directory 34 | .npm 35 | 36 | # Optional REPL history 37 | .node_repl_history 38 | 39 | # Intellij 40 | .idea 41 | *.iml -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "yarnpm", 3 | "version": "0.0.6", 4 | "description": "Yarn Wrapper for NPM!", 5 | "main": "src/index.js", 6 | "preferGlobal": true, 7 | "scripts": { 8 | "install:npm": "npm install --global file:.", 9 | "install:global": "node ./src/index.js yarnpm install" 10 | }, 11 | "bin": { 12 | "yarnpm": "./src/index.js" 13 | }, 14 | "repository": { 15 | "type": "git", 16 | "url": "git+https://github.com/pi0/yarnpm.git" 17 | }, 18 | "keywords": [ 19 | "yarn", 20 | "npm", 21 | "node", 22 | "package", 23 | "wrapper", 24 | "script", 25 | "global" 26 | ], 27 | "author": "Pooya Parsa", 28 | "license": "BSD-2-Clause", 29 | "bugs": { 30 | "url": "https://github.com/pi0/yarnpm/issues" 31 | }, 32 | "homepage": "https://github.com/pi0/yarnpm#readme" 33 | } 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 2-Clause License 2 | 3 | Copyright (c) 2016, Pooya Parsa 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | * Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # YarNPM 2 | YarNPM is a [YARN](https://github.com/yarnpkg/yarn) wrapper which transforms `npm` commands to `yarn`, use `npm` as `yarn`! 3 | 4 | 5 | **WARNING: PLEASE DON'T USE THIS PACKAGE FOR NOW, IT MAY BREAK YOUR NPM, A BETTER INSTALLER APPROACH IS COMMING SOON :)** 6 | 7 | [![NPM](https://nodei.co/npm/yarnpm.png?downloads=true&downloadRank=true&stars=true)](https://npmjs.com/yarnpm/) 8 | 9 | ## What is Yarn ? 10 | Yarn is a Fast, reliable, and secure dependency management that can be used as a replacement of NPM and other tools. 11 | 12 | ## So Why do i need this? 13 | Yarn is great, but many tools still (and maybe for months) are depending on `npm` command, this tool adds a global `npm` 14 | wrapper binary which: 15 | + Automatically converts args from `npm` to `yarn` (for example `npm install`=>`yarn add`) 16 | + Detects currently unsupported features of yarn and fall backs to `npm` 17 | - Scoped packages 18 | + Allows you to to specify which tool to use, still using `npm` command 19 | 20 | **Related Topics** 21 | - [Support Yarn #371](https://github.com/lerna/lerna/issues/371) 22 | - [Use Yarn instead of npm for installing packages #4](https://github.com/motion/lerna/pull/4) 23 | - [Yarn #4713](https://github.com/babel/babel/pull/4713) 24 | 25 | ## Usage 26 | 27 | Install global binary: 28 | ``` 29 | npm install --global yarnpm 30 | ``` 31 | Install a syslink from `yarnpm` to `/usr/local/bin/npm` or `%WINDOWS%/system32/npm` : 32 | ``` 33 | ### RUN ME AS ROOT/AMINISTRATOR ### 34 | yarnpm yarnpm install 35 | ``` 36 | 37 | 38 | **Check npm command in a NEW Terminal** 39 | ``` 40 | $ npm --help 41 | 42 | Usage: yarn install [flags] 43 | 44 | Options: 45 | 46 | -h, --help output usage information 47 | -V, --version output the version number 48 | ``` 49 | 50 | **Additional Steps if it does not works** 51 | 52 | **Force Using NPM Or Yarn** 53 | Use `--npm` or `--yarn` flag 54 | 55 | ## Development 56 | 57 | ``` 58 | npm run install:npm 59 | npm run install:global 60 | ``` 61 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | const WIN32 = process.platform.indexOf("win32") !== -1; 3 | const Spawn = require('child_process').spawn; 4 | const Path = require('path'); 5 | const FS = require('fs'); 6 | 7 | // NPM -> Yarn Arguments Mapping 8 | const _map = { 9 | 'install': 'add', 10 | }; 11 | 12 | const _need_tty = [ 13 | 'publish', 14 | ]; 15 | 16 | // Extract Command Line Args 17 | const args = process.argv ? process.argv.splice(2) : []; 18 | 19 | // Check for internal commands 20 | if (args[0] === 'yarnpm') { 21 | switch (args[1]) { 22 | case 'install': 23 | installBin(); 24 | break; 25 | default: 26 | console.log('YARNPM::Invalid action'); 27 | } 28 | return; 29 | } 30 | 31 | // Let's go 32 | var npm = useNPM(); 33 | var command = npm ? 'npm' : 'yarn'; 34 | var _args = npm ? args.map(npm2yarn) : args; 35 | var detached = needsTTY(_args); 36 | Exec(command, _args, detached); 37 | 38 | // Check if we Should NPM instead of Yarn 39 | function useNPM() { 40 | if (args.indexOf('--npm') !== -1) 41 | return true; 42 | 43 | if (args.indexOf('--yarn') !== -1) 44 | return false; 45 | 46 | // Scoped packages are not currently working with YARN 47 | for (var arg in args) 48 | if (arg.indexOf('@') === 0) 49 | return true; 50 | 51 | return false; 52 | } 53 | 54 | // Convert argument from NPM to Yarn 55 | function npm2yarn(arg) { 56 | 57 | // Check for arguments mapping 58 | if (_map[arg]) 59 | return _map[arg]; 60 | 61 | // Filter out and don't pass --npm and --yarn options! 62 | if (['--npm', '--yarn'].indexOf(arg) !== -1) 63 | return ''; 64 | 65 | return arg; 66 | } 67 | 68 | // Spawn and allocate TTY is detached==true 69 | function Exec(cmd, args, detached) { 70 | Spawn(cmd + ' ' + args.join(' '), [], { 71 | shell: true, 72 | stdio: 'inherit', 73 | detached: detached 74 | }); 75 | } 76 | 77 | // Check if command needs to run in detached mode and needs tty 78 | function needsTTY(arg) { 79 | for (var cmd in _need_tty) 80 | if (arg.indexOf(cmd) !== -1) 81 | return true; 82 | return false; 83 | } 84 | 85 | // DOC ME 86 | function installBin() { 87 | var dest = Path.resolve(Path.dirname(process.env.ComSpec),'npm'); 88 | if(WIN32) { 89 | // On windows systems we need to make a .bat file 90 | dest = dest + '.bat'; 91 | console.log('Writing to ' + dest); 92 | FS.writeFileSync(dest, '@"'+process.argv[0]+'"' + ' "' + process.argv[1] + '" %*'); 93 | } else { 94 | // On Unix systems we can directly execute script 95 | var src = process.argv[1]; 96 | console.log('Making syslink' + src + ' -> ' + dest); 97 | FS.symlinkSync(src, dest); 98 | } 99 | } 100 | --------------------------------------------------------------------------------