Giter VIP home page Giter VIP logo

update-check's Introduction

update-check

npm version install size

This is a very minimal approach to update checking for globally installed packages.

Because it's so simple, the error surface is very tiny and your user's are guaranteed to receive the update message if there's a new version.

You can read more about the reasoning behind this project here.

Usage

Firstly, install the package with yarn...

yarn add update-check

...or npm:

npm install update-check

Next, initialize it.

If there's a new update available, the package will return the content of latest version's package.json file:

const pkg = require('./package');
const checkForUpdate = require('update-check');

let update = null;

try {
	update = await checkForUpdate(pkg);
} catch (err) {
	console.error(`Failed to check for updates: ${err}`);
}

if (update) {
	console.log(`The latest version is ${update.latest}. Please update!`);
}

That's it! You're done.

Configuration

If you want, you can also pass options to customize the package's behavior:

const pkg = require('./package');
const checkForUpdate = require('update-check');

let update = null;

try {
	update = await checkForUpdate(pkg, {
		interval: 3600000,  // For how long to cache latest version (default: 1 day)
		distTag: 'canary'   // A npm distribution tag for comparision (default: 'latest')
	});
} catch (err) {
	console.error(`Failed to check for updates: ${err}`);
}

if (update) {
	console.log(`The latest version is ${update.latest}. Please update!`);
}

Contributing

  1. Fork this repository to your own GitHub account and then clone it to your local device
  2. Link the package to the global module directory: npm link
  3. Within the module you want to test your local development instance of the package, just link it: npm link update-check. Instead of the default one from npm, node will now use your clone.

Author

Leo Lamprecht (@notquiteleo) - ZEIT

update-check's People

Contributors

ansballard avatar leo avatar leolabs avatar luksm avatar styfle avatar timneutkens avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

update-check's Issues

Upgrade to next 6 is throwing a SyntaxError in this library.

Can’t figure out what’s causing it.

.../node_modules/update-check/index.js:18
const getFile = async (details, distTag) => {
                      ^

SyntaxError: Unexpected token (
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Server._callee$ (.../node_modules/next/dist/server/index.js:194:34)
    at tryCatch (.../node_modules/regenerator-runtime/runtime.js:62:40)
    at GeneratorFunctionPrototype.invoke [as _invoke] (.../node_modules/regenerator-runtime/runtime.js:296:22)
    at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (.../node_modules/regenerator-runtime/runtime.js:114:21)
    at step (.../node_modules/@babel/runtime/helpers/asyncToGenerator.js:12:30)
    at _next (.../node_modules/@babel/runtime/helpers/asyncToGenerator.js:27:9)
    at .../node_modules/@babel/runtime/helpers/asyncToGenerator.js:34:7

Here’s the horrible horrible dependencies/.babelrc I have trying to get babel 7 working

  "babel": {
    "presets": [
      "@babel/preset-env",
      "@babel/preset-stage-1",
      "@babel/preset-react",
      "next/babel"
    ],
    "plugins": [
      "@babel/plugin-transform-runtime",
      [
        "styled-jsx/babel",
        {
          "plugins": [
            "styled-jsx-plugin-postcss"
          ]
        }
      ]
    ]
  },
  "devDependencies": {
    "@babel/core": "^7.0.0-beta.46",
    "@babel/node": "^7.0.0-beta.46",
    "@babel/preset-env": "^7.0.0-beta.46",
    "@babel/preset-react": "^7.0.0-beta.46",
    "@babel/preset-stage-2": "^7.0.0-beta.46",
    "@babel/register": "^7.0.0-beta.46",
    "babel-eslint": "^8.2.2",
    "babel-loader": "^8.0.0-beta.2",

File already exists error

We are getting user reports from an error like this:

EEXIST: file already exists, mkdir '/var/folders/b4/n_nm8w3941n1gk3bd5tn4fxm0000gn/T/update-check'

{
code: EEXIST, 
errno: -17, 
path: /var/folders/b4/n_nm8w3941n1gk3bd5tn4fxm0000gn/T/update-check, 
syscall: mkdir
}

Most worryingly, it's an unhandled promise rejection.

update-check stalls when WiFi is disabled.

I want to be able to disable update-check on the vercel package because it takes 5ish minutes to serve something in the event I have no WiFi due to the update check.

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on all branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please delete the greenkeeper/initial branch in this repository, and then remove and re-add this repository to the Greenkeeper App’s white list on Github. You'll find this list on your repo or organization’s settings page, under Installed GitHub Apps.

Should I mount /tmp with dockerized cli to avoid too many update check?

My node cli is dockerized, and I run it like this:

docker run --interactive --tty --rm -v $(pwd):/project -w /project dockerhub/mycli

What is the recommended solution to avoid checking the most recent version at each run of the CLI?
Should I mount the host OS /tmp directory?
Thanks!

Using https prevents custom http registries from being used

https://github.com/zeit/update-check/blob/859dde951dc6177af1446f4ce9e1a5ad6e2e3893/index.js#L2

On the case the user has a private registry running on http only, this request will fail.

> [email protected] dev /home/user/learnnextjs-demo
> next

{ Error: connect ECONNREFUSED 127.0.0.1:443
    at Object._errnoException (util.js:1022:11)
    at _exceptionWithHostPort (util.js:1044:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1198:14)
  code: 'ECONNREFUSED',
  errno: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.01',
  port: 443 }

Update check causes a crash in Travis CI

I ran into a really weird error a couple of times with Travis CI, running on Node v8;

$ now -t ${NOW_TOKEN} -T volst --no-verify
> Error! An unexpected error occurred!
  Error: ENOENT: no such file or directory, open '/tmp/update-check/now-latest.json' Error: ENOENT: no such file or directory, open '/tmp/update-check/now-latest.json'

The app is open source, so you can find the Travis CI logs here. What makes it difficult to debug though is that it doesn't happen always. And a link to the travis.yml file.

I don't know why this happens, but I guess update-check should gracefully handle that file not existing, even though it may be because there is some exotic config going in a CI, right?

update-check doesn't use proxy from environment

Not sure if this is one for here or https://github.com/zeit/serve but it looks like update-check doesn't pick up the proxy from the $HTTP_PROXY/$HTTPS_PROXY env vars, or anywhere else as far as I can tell (possibly because http/https don't do it automatically?)
As a result serve takes a very long time before the update check times out when behind a proxy, which I'm sure it didn't used to? Much as in an ideal world there wouldn't be any proxies, the reality of corporate networks is far from ideal!

I've tried this on Ubuntu 16.04.1 (node v8.12.0) and macOS 10.13.6 (node v9.11.2)

serve is a brilliant little tool by the way!

update-check module throwing error - [non-breaking]

update-check module is throwing non-breaking error at the initial stage of 'next' script run.

To Reproduce
run 'npm run dev'

Expected behavior
should check for updates among the dependencies

Screenshots
$ next
Error checking updates SyntaxError: Unexpected end of JSON input
at JSON.parse ()
at IncomingMessage.response.on (/home/razi/extras/test/node_modules/update-check/index.js:102:29)
at emitNone (events.js:111:20)
at IncomingMessage.emit (events.js:208:7)
at endReadableNT (_stream_readable.js:1064:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)

System information

OS: Ubuntu 16.04
Version of Next.js: 6.0.3
Additional context
reaching 'JSON.parse' before the completion of reading the previous stream of data viz., 'rawData'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.