Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow simply showing notification for manual checks (with callback) #129

Open
jakub300 opened this issue Nov 29, 2017 · 1 comment
Open

Comments

@jakub300
Copy link

Currently to check and immediately show notification you have to do something like that:

const notifier = updateNotifier({
  pkg: packageJson,
  callback: (err, update) => {
    if(update && update.type && update.type != 'latest') {
      notifier.update = update;
      notifier.notify({defer: false});
    }
  },
})

The problem is that notifier.update = update; is undocumented hack so better alternative to do that should be provided.

@tunnckoCore
Copy link

tunnckoCore commented Nov 3, 2018

There is one more thing.

When the opts.callback is used, you do not create lastUpdateCheck so.. Never will be updated and neither can be detected. Because it even does not creates a config file?

I think that here in this .then should be added

this.config = new ConfigStore(`update-notifier-${this.packageName}`, {
  optOut: false,
  // Init with the current time so the first check is only
  // after the set interval, so not to bother users right away
  lastUpdateCheck: Date.now()
});

My use case scenario is that want to create a module that auto updates when needed.

Something like that

export default function autoUpdater(options) {
  const opts = Object.assign({}, options);

  if (!opts.pkg.name || !opts.pkg.version) {
    throw new Error('unpdateNotifier: pkg.name and pkg.version are required');
  }

  opts.callback = (err, info) => {
    if (err) {
      throw err;
    }
    if (isInstalledGlobally(opts.pkg.name) && info.type !== 'latest') {
      execSync(`npm install --global ${opts.pkg.name}`);
    }
  };

  return unpdateNotifier(opts);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants