npm-update
Advanced tools
Comparing version 2.1.0 to 3.0.0
@@ -9,59 +9,55 @@ 'use strict'; | ||
module.exports = options => { | ||
return npmUpdate(options) | ||
.then(res => res) | ||
.catch(e => { | ||
throw e; | ||
}); | ||
async function npmUpdate (options = {}) { | ||
const pkg = options.pkg || {}; | ||
const packageName = pkg.name; | ||
const packageVersion = pkg.version; | ||
assert(packageName, 'can\'t get package.json name'); | ||
assert(packageVersion, 'can\'t get package.json version'); | ||
const protocol = options.protocol || 'http'; | ||
const host = options.host || 'registry.npmjs.org'; | ||
const version = typeof options.version !== 'undefined' ? options.version : 'latest'; | ||
let silent = false; | ||
if (typeof options.silent !== 'undefined') { | ||
silent = options.silent; | ||
} | ||
async function npmUpdate(options = {}) { | ||
const pkg = options.pkg || {}; | ||
const packageName = pkg.name; | ||
const packageVersion = pkg.version; | ||
assert(packageName, 'can\'t get package.json name'); | ||
assert(packageVersion, 'can\'t get package.json version'); | ||
const protocol = options.protocol || 'https'; | ||
const host = options.host || 'registry.npmjs.org'; | ||
const version = typeof options.version !== 'undefined' ? options.version : 'latest'; | ||
let silent = false; | ||
const url = `${protocol}://${host}/${packageName}/${version}`; | ||
const opt = { | ||
timeout: options.timeout || 3000, | ||
dataType: 'json', | ||
}; | ||
if (typeof options.silent !== 'undefined') { | ||
silent = options.silent; | ||
} | ||
const result = await urllib.request(url, opt); | ||
const latestVersion = result.data.version; | ||
const url = `${protocol}://${host}/${packageName}/${version}`; | ||
const opt = { | ||
timeout: options.timeout || 3000, | ||
dataType: 'json', | ||
}; | ||
if (!latestVersion) { | ||
return { | ||
needUpdate: false, | ||
}; | ||
} | ||
if (semver.gt(latestVersion, packageVersion)) { | ||
if (!silent) { | ||
console.log(boxen( | ||
`new version ${chalk.cyan(latestVersion)} found | ||
const result = await urllib.request(url, opt); | ||
const latestVersion = result.data.version; | ||
if (!latestVersion) { | ||
return { | ||
needUpdate: false, | ||
}; | ||
} | ||
if (semver.gt(latestVersion, packageVersion)) { | ||
if (!silent) { | ||
console.log(boxen( | ||
`new version ${chalk.cyan(latestVersion)} found | ||
run ${chalk.cyan(`npm i ${packageName}@${semver.major(latestVersion)} -g`)}`, | ||
{ | ||
padding: 1, | ||
borderStyle: 'round', | ||
borderColor: 'cyan', | ||
} | ||
)); | ||
} | ||
return { | ||
needUpdate: true, | ||
version: latestVersion, | ||
}; | ||
{ | ||
padding: 1, | ||
borderStyle: 'round', | ||
borderColor: 'cyan', | ||
} | ||
)); | ||
} | ||
return { | ||
needUpdate: false, | ||
needUpdate: true, | ||
version: latestVersion, | ||
}; | ||
} | ||
}; | ||
return { | ||
needUpdate: false, | ||
}; | ||
} | ||
module.exports = npmUpdate; |
{ | ||
"name": "npm-update", | ||
"version": "2.1.0", | ||
"version": "3.0.0", | ||
"description": "npm update", | ||
@@ -10,5 +10,9 @@ "keywords": [ | ||
"main": "index.js", | ||
"files": [ | ||
"index.js", | ||
"lib/*.js" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/macacajs/npm-update.git" | ||
"url": "git://github.com/xudafeng/npm-update.git" | ||
}, | ||
@@ -38,4 +42,3 @@ "dependencies": { | ||
], | ||
"homepage": "https://github.com/macacajs/npm-update", | ||
"license": "MIT" | ||
} |
# npm-update | ||
--- | ||
[![NPM version][npm-image]][npm-url] | ||
[![build status][travis-image]][travis-url] | ||
[![Test coverage][coveralls-image]][coveralls-url] | ||
[![Test coverage][codecov-image]][codecov-url] | ||
[![node version][node-image]][node-url] | ||
[![npm download][download-image]][download-url] | ||
[npm-image]: https://img.shields.io/npm/v/npm-update.svg?style=flat-square | ||
[npm-image]: https://img.shields.io/npm/v/npm-update.svg | ||
[npm-url]: https://npmjs.org/package/npm-update | ||
[travis-image]: https://img.shields.io/travis/macacajs/npm-update.svg?style=flat-square | ||
[travis-url]: https://travis-ci.org/macacajs/npm-update | ||
[coveralls-image]: https://img.shields.io/coveralls/macacajs/npm-update.svg?style=flat-square | ||
[coveralls-url]: https://coveralls.io/r/macacajs/npm-update?branch=master | ||
[node-image]: https://img.shields.io/badge/node.js-%3E=_8-green.svg?style=flat-square | ||
[travis-image]: https://img.shields.io/travis/xudafeng/npm-update.svg | ||
[travis-url]: https://travis-ci.org/xudafeng/npm-update | ||
[coveralls-image]: https://img.shields.io/coveralls/xudafeng/npm-update.svg | ||
[coveralls-url]: https://coveralls.io/r/xudafeng/npm-update?branch=master | ||
[codecov-image]: https://img.shields.io/codecov/c/github/xudafeng/npm-update.svg | ||
[codecov-url]: https://codecov.io/gh/xudafeng/npm-update/branch/master | ||
[node-image]: https://img.shields.io/badge/node.js-%3E=_8-green.svg | ||
[node-url]: http://nodejs.org/download/ | ||
[download-image]: https://img.shields.io/npm/dm/npm-update.svg?style=flat-square | ||
[download-image]: https://img.shields.io/npm/dm/npm-update.svg | ||
[download-url]: https://npmjs.org/package/npm-update | ||
@@ -31,10 +35,10 @@ | ||
```javascript | ||
const update = require('npm-update') | ||
const npmUpdate = require('npm-update') | ||
const pkg = require('../package.json') | ||
(async () => { | ||
const { needUpdate } = await update({ pkg }) | ||
if (needUpdate) return | ||
const { needUpdate } = await npmUpdate({ pkg }); | ||
if (needUpdate) return; | ||
// do some stuff | ||
})() | ||
})(); | ||
``` | ||
@@ -60,11 +64,11 @@ | ||
version: latestVersion, // return version if needUpdate | ||
} = await update(options) | ||
} = await update(options); | ||
``` | ||
- options {object} | ||
- **pkg** {object} package.json object. | ||
- **host** {String} registry host, default is **registry.npmjs.org**. | ||
- **timeout** {Number} request registry timeout, default is **3000ms**. | ||
- **version** {String} base version for comparing, can be npm tag or npm version, default is **latest**. | ||
- **silent** {Boolean} if slient is true, will not print message, default is false. | ||
- options {Object} | ||
- **pkg** `Object` package.json object. | ||
- **host** `string` registry host, default is **registry.npmjs.org**. | ||
- **timeout** `number` request registry timeout, default is **3000ms**. | ||
- **version** `string` base version for comparing, can be npm tag or npm version, default is **latest**. | ||
- **silent** `boolean` if slient is true, will not print message, default is **false**. | ||
@@ -75,7 +79,7 @@ <!-- GITCONTRIBUTOR_START --> | ||
|[<img src="https://avatars1.githubusercontent.com/u/1011681?v=4" width="100px;"/><br/><sub><b>xudafeng</b></sub>](https://github.com/xudafeng)<br/>|[<img src="https://avatars3.githubusercontent.com/u/5086369?v=4" width="100px;"/><br/><sub><b>brunoyang</b></sub>](https://github.com/brunoyang)<br/>|[<img src="https://avatars1.githubusercontent.com/u/2139038?v=4" width="100px;"/><br/><sub><b>zhangyuheng</b></sub>](https://github.com/zhangyuheng)<br/> | ||
|[<img src="https://avatars.githubusercontent.com/u/1011681?v=4" width="100px;"/><br/><sub><b>xudafeng</b></sub>](https://github.com/xudafeng)<br/>|[<img src="https://avatars.githubusercontent.com/u/2139038?v=4" width="100px;"/><br/><sub><b>zhangyuheng</b></sub>](https://github.com/zhangyuheng)<br/>|[<img src="https://avatars.githubusercontent.com/u/5086369?v=4" width="100px;"/><br/><sub><b>brunoyang</b></sub>](https://github.com/brunoyang)<br/>| | ||
| :---: | :---: | :---: | | ||
This project follows the git-contributor [spec](https://github.com/xudafeng/git-contributor), auto upated at `Tue Jun 26 2018 22:22:45 GMT+0800`. | ||
This project follows the git-contributor [spec](https://github.com/xudafeng/git-contributor), auto updated at `Fri Nov 04 2022 13:38:18 GMT+0800`. | ||
@@ -82,0 +86,0 @@ <!-- GITCONTRIBUTOR_END --> |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
88
5600
4
55
1