npminstall
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -18,7 +18,10 @@ #!/usr/bin/env node | ||
const co = require('co'); | ||
const npminstall = require('../'); | ||
const npa = require('npm-package-arg'); | ||
const chalk = require('chalk'); | ||
const path = require('path'); | ||
const exec = require('child_process').execSync; | ||
const execSync = require('child_process').execSync; | ||
const fs = require('mz/fs'); | ||
const utils = require('../lib/utils'); | ||
const npminstall = require('../'); | ||
const names = process.argv.slice(2); | ||
@@ -40,3 +43,3 @@ const pkgs = []; | ||
const cacheDir = process.argv.indexOf('--no-cache') > 0 ? '' : null; | ||
const isGlobal = process.argv.indexOf('-g') >= 0; | ||
const isGlobal = process.argv.indexOf('-g') >= 0 || process.argv.indexOf('--global') >= 0; | ||
@@ -63,2 +66,13 @@ if (process.argv.indexOf('-v') > 0 || process.argv.indexOf('--version') > 0) { | ||
yield npminstall(config); | ||
if (!isGlobal && pkgs.length > 0) { | ||
// support --save, --save-dev and --save-optional | ||
if (process.argv.indexOf('--save') >= 0) { | ||
yield updateDependencies(root, pkgs, 'dependencies'); | ||
} else if (process.argv.indexOf('--save-dev') >= 0) { | ||
yield updateDependencies(root, pkgs, 'devDependencies'); | ||
} else if (process.argv.indexOf('--save-optional') >= 0) { | ||
yield updateDependencies(root, pkgs, 'optionalDependencies'); | ||
} | ||
} | ||
}).catch(function(err) { | ||
@@ -72,3 +86,3 @@ console.error(chalk.red(err)); | ||
try { | ||
return exec('npm config get prefix').toString().trim(); | ||
return execSync('npm config get prefix').toString().trim(); | ||
} catch (err) { | ||
@@ -78,1 +92,22 @@ throw new Error(`exec npm config get prefix ERROR: ${err.message}`); | ||
} | ||
function getVersionSavePrefix() { | ||
try { | ||
return execSync('npm config get save-prefix').toString().trim(); | ||
} catch (err) { | ||
console.error(`exec npm config get save-prefix ERROR: ${err.message}`); | ||
return '^'; | ||
} | ||
} | ||
function* updateDependencies(root, pkgs, propName) { | ||
const savePrefix = getVersionSavePrefix(); | ||
const pkgFile = path.join(root, 'package.json'); | ||
const pkg = yield utils.readJSON(pkgFile); | ||
const deps = pkg[propName] = pkg[propName] || {}; | ||
for (const item of pkgs) { | ||
const itemPkg = yield utils.readJSON(path.join(root, 'node_modules', item.name, 'package.json')); | ||
deps[item.name] = `${savePrefix}${itemPkg.version}`; | ||
} | ||
yield fs.writeFile(pkgFile, JSON.stringify(pkg, null, 2)); | ||
} |
1.0.3 / 2016-02-25 | ||
================== | ||
* chore: add different with npm | ||
* test: add npm_registry env for ci | ||
* feat(bin): support --save, --save-dev and --save-optional | ||
1.0.2 / 2016-02-24 | ||
@@ -3,0 +10,0 @@ ================== |
{ | ||
"name": "npminstall", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Let npm install fast and easy", | ||
@@ -47,2 +47,3 @@ "main": "lib/index.js", | ||
"autod": "*", | ||
"coffee": "3", | ||
"eslint": "1", | ||
@@ -49,0 +50,0 @@ "eslint-config-egg": "1", |
@@ -59,2 +59,12 @@ # npminstall | ||
## Different with NPM | ||
This project is inspired by [pnpm](https://github.com/rstacruz/pnpm), and has a similar store structure like pnpm. You can read [pnpm vs npm](https://github.com/rstacruz/pnpm/blob/master/docs/vs-npm.md) to see the different with npm. | ||
### Limitations | ||
- You can't install from [shrinkwrap](https://docs.npmjs.com/cli/shrinkwrap)(and don't want to support for now). | ||
- Peer dependencies are a little trickier to deal with(see rule 1 below). | ||
- You can't publish npm modules with bundleDependencies managed by npminstall(because of rule 2 below). | ||
## `node_modules` directory | ||
@@ -64,4 +74,4 @@ | ||
- The latest version of modules will link at `options.storeDir`'s `node_modules`. | ||
- Module's dependencies will link at module's `node_modules`. | ||
1. The latest version of modules will link at `options.storeDir`'s `node_modules`. | ||
2. Module's dependencies will link at module's `node_modules`. | ||
@@ -68,0 +78,0 @@ e.g.: |
52750
1320
123
8