Code Monkey home page Code Monkey logo

plugin-warn-if-update-available's Introduction

@oclif/plugin-warn-if-update-available

warns if there is a newer version of CLI released

Version Downloads/week License

What is this?

This plugin shows a warning message if a user is running an out of date CLI.

screenshot

How it works

This checks the version against the npm registry asynchronously in a forked process once every 60 days by default (see Configuration for how to configure this). It then saves a version file to the cache directory that will enable the warning. The upside of this method is that it won't block a user while they're using your CLIβ€”the downside is that it will only display after running a command that fetches the new version.

Installation

Add the plugin to your project with yarn add @oclif/plugin-warn-if-update-available, then add it to the package.json of the oclif CLI:

{
  "name": "mycli",
  "version": "0.0.0",
  // ...
  "oclif": {
    "plugins": ["@oclif/plugin-help", "@oclif/plugin-warn-if-update-available"]
  }
}

Configuration

In package.json, set oclif['warn-if-update-available'] to an object with any of the following configuration properties:

  • timeoutInDays - Duration between update checks. Defaults to 60.
  • message - Customize update message.
  • registry - URL of registry. Defaults to the public npm registry: https://registry.npmjs.org
  • authorization - Authorization header value for registries that require auth.
  • frequency - The frequency that the new version warning should be shown.
  • frequencyUnit - The unit of time that should be used to calculate the frequency (days, hours, minutes, seconds, milliseconds). Defaults to minutes.

Example configuration

{
  "oclif": {
    "plugins": ["@oclif/plugin-warn-if-update-available"],
    "warn-if-update-available": {
      "timeoutInDays": 7,
      "message": "<%= config.name %> update available from <%= chalk.greenBright(config.version) %> to <%= chalk.greenBright(latest) %>.",
      "registry": "https://my.example.com/module/registry",
      "authorization": "Basic <SOME READ ONLY AUTH TOKEN>"
    }
  }
}

Notification Frequency

Once a new version has been found, the default behavior is to notify the user on every command execution. You can modify this by setting the frequency and frequencyUnit options.

Examples

Once every 10 minutes.

{
  "oclif": {
    "warn-if-update-available": {
      "frequency": 10
    }
  }
}

Once every 6 hours.

{
  "oclif": {
    "warn-if-update-available": {
      "frequency": 6,
      "frequencyUnit": "hours"
    }
  }
}

Once a day.

{
  "oclif": {
    "warn-if-update-available": {
      "frequency": 1,
      "frequencyUnit": "days"
    }
  }
}

Once every 30 seconds.

{
  "oclif": {
    "warn-if-update-available": {
      "frequency": 30,
      "frequencyUnit": "seconds"
    }
  }
}

Environment Variables

  • <CLI>_SKIP_NEW_VERSION_CHECK: Skip this version check
  • <CLI>_FORCE_VERSION_CACHE_UPDATE: Force the version cache to update
  • <CLI>_NEW_VERSION_CHECK_FREQ: environment variable override for frequency setting
  • <CLI>_NEW_VERSION_CHECK_FREQ_UNIT: environment variable override for frequencyUnit setting

Contributing

See contributing guide

plugin-warn-if-update-available's People

Contributors

aghassi avatar dependabot[bot] avatar greenkeeper[bot] avatar jdx avatar k80bowman avatar kinetifex avatar mdonnalley avatar mshanemc avatar oclif-bot avatar peternhale avatar rasphilco avatar rodesp avatar shetzel avatar svc-cli-bot 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

Watchers

 avatar  avatar  avatar

plugin-warn-if-update-available's Issues

lodash.template security vulnerability

Describe the bug

A high severity security vulnerability exists in the lodash.template dependency of this project (version 4.5.0). The suggested fix by npm audit is to downgrade the oclif package to v3. The lodash.template dependency does not have a patch, and should probably be replaced by either lodash or lodash-es in this project.

More info: GHSA-35jh-r3h4-6jhm

To Reproduce
Steps to reproduce the behavior:
Run npm audit in a project that uses this package.

Expected behavior
There are no security vulnerabilities.

Screenshots
image

Environment (please complete the following information):

        "@oclif/core": "^3.26.4",
        "@oclif/plugin-help": "^6.0.21",
        "@oclif/plugin-plugins": "^5.0.14",
        "oclif": "^4.8.8",

Additional context
Add any other context about the problem here.

An alternative implementation

Hi there! I've been working on a CLI tool with Oclif for my company and needed update warnings, however, wasn't able to directly use this package due to our CLI being hosted on a private npm registry; So I wrote a quick little alternative implementation, building off several other building blocks that already exist:

import { Hook } from "@oclif/config";
import libnpm, { Manifest } from "libnpm";
import semver from "semver";
import fs from "fs-extra";
import path from "path";
import cli from "cli-ux";

const timeoutInDays = 10;

const hook: Hook<"init"> = async function({ config }) {
  const { name: packageName, version: currentVersion } = config;
  const updateCheckPath = path.join(config.cacheDir, "last-update-check");

  const refreshNeeded = async () => {
    try {
      const { mtime } = await fs.stat(updateCheckPath);
      const staleAt = new Date(
        mtime.valueOf() + 1000 * 60 * 60 * 24 * timeoutInDays
      );
      return staleAt < new Date();
    } catch (err) {
      return true;
    }
  };

  const checkForUpdate = async () => {
    try {
      cli.action.start("checking for updates");

      const latestManifest: Manifest = await libnpm.manifest(
        `${packageName}@latest`,
        libnpm.config.read()
      );

      await fs.writeFile(updateCheckPath, JSON.stringify(latestManifest), {
        encoding: "utf8"
      });
    } finally {
      cli.action.stop();
    }

    await checkVersion(true);
  };

  const readLatestManifest = async (): Promise<Manifest | null> => {
    try {
      return JSON.parse(
        await fs.readFile(updateCheckPath, {
          encoding: "utf8"
        })
      );
    } catch (err) {
      return null;
    }
  };

  const checkVersion = async (printStatus?: boolean) => {
    const latestManifest = await readLatestManifest();

    // No version check has happened, so we can't tell if we're the latest version:
    if (latestManifest === null) {
      return null;
    }

    if (semver.lt(currentVersion, latestManifest.version)) {
      this.warn(
        `Update needed, please run \`yarn global add ${packageName}@latest\`\n`
      );
    } else if (printStatus) {
      this.log("All up-to-date!\n");
    }
  };

  if (await refreshNeeded()) {
    await checkForUpdate();
  } else {
    await checkVersion();
  }
};

export default hook;

I figure it might be of interest to the authors, as it uses libnpm for interacting with npm and follows semver semantics.

Ability to conditionally disable?

We have a CLI created with oclif which uses this plugin. The CLI is for an application shell framework we developed. The version check has been great for development-time prompts to help people get up-to-date with the CLI, but the version check is causing application crashes when it tries to writes out version information to a /.cache directory.

At runtime we don't want this version check to occur. Is there a way to disable the check dynamically so we can suppress the side effect?

An in-range update of @types/node is breaking the build 🚨

The devDependency @types/node was updated from 10.10.0 to 10.10.1.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

@types/node is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • βœ… ci/circleci: node-latest: Your tests passed on CircleCI! (Details).
  • βœ… ci/circleci: node-8: Your tests passed on CircleCI! (Details).
  • βœ… codecov/project: No report found to compare against (Details).
  • βœ… codecov/patch: Coverage not affected. (Details).
  • ❌ Build: We could not find a valid build file. Please ensure that your repo contains a cloudbuild or a Dockerfile.

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


The push permission to the Git repository is required.

semantic-release cannot push the version tag to the branch master on remote Git repository.

Please refer to the authentication configuration documentation to configure the Git credentials on your CI environment.


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

An in-range update of @oclif/config is breaking the build 🚨

The dependency @oclif/config was updated from 1.7.4 to 1.7.5.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

@oclif/config is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • ❌ ci/circleci: node-8: Your tests failed on CircleCI (Details).
  • ❌ ci/circleci: node-latest: Your tests failed on CircleCI (Details).

Release Notes for v1.7.5

1.7.5 (2018-09-13)

Bug Fixes

Commits

The new version differs by 2 commits.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Does not seem to work with scoped packages

The plugin does not show any messages in my application after switching to use scoped package. I used to get a message to update my application because there was an other package with the same name (pdftools) on npm!

{
	"name": "@bader-nasser/pdftools",
	"bin": {
		"pdftools": "bin/run.js",
		"pdf-tools": "bin/run.js"
	},
	"repository": "bader-nasser/pdftools",
        "dependencies": {
		"@oclif/core": "^2.15.0",
		"@oclif/plugin-autocomplete": "^2.3.8",
		"@oclif/plugin-help": "^5.2.19",
		"@oclif/plugin-not-found": "^2.4.1",
		"@oclif/plugin-plugins": "^3.4.2",
		"@oclif/plugin-warn-if-update-available": "^2.1.0",
	},
	"devDependencies": {
		"@oclif/test": "^2.5.3",
		"oclif": "^3.15.0",
	},
	"files": [
		"/bin",
		"/dist",
		"/npm-shrinkwrap.json",
		"/oclif.manifest.json",
		"/data.schema.json"
	],
	"oclif": {
		"bin": "pdftools",
		"binAliases": [
			"pdftools",
			"pdf-tools"
		],
                // not sure about this property, and couldn't find any docs if it affects the plugin
		"scope": "bader-nasser",
		"dirname": "pdftools",
		"commands": "./dist/commands",
		"additionalHelpFlags": [
			"-h"
		],
		"additionalVersionFlags": [
			"-v"
		],
		"plugins": [
			"@oclif/plugin-help",
			"@oclif/plugin-plugins",
			"@oclif/plugin-autocomplete",
			"@oclif/plugin-not-found",
			"@oclif/plugin-warn-if-update-available"
		],
		"warn-if-update-available": {
			"timeoutInDays": 7
		},
		"topicSeparator": " "
	}
}

OS: Ubuntu 23.04

My cli: https://github.com/bader-nasser/pdftools

I'm not sure if this is a bug or I'm missing something!

not working on windows

some brief testing seems to make it seem as this isn't working on windows

screen shot 2018-03-24 at 2 28 14 pm

The file never seems to get created. I think it's either because the parent is closing before it has time to make the request, or something is failing inside the get_version script.

Setting up

The README says

In package.json, set oclif['warn-if-update-available'].timeoutInDays to change the timeout duration between checks.

Where does this go exactly in the package.json?

support for distribution via `oclif-dev publish` and S3?

Is there any support for checking for updates based on a project published via oclif-dev publish as opposed to npm? It seems like it shouldn't be necessary to publish to two places in order to get upgrade warnings working.

Publishing the shrinkwrap makes npm unnecessarily install the dev dependencies

Describe the bug

As of 3.0.13, the dev dependencies of @oclif/plugin-warn-if-update-available end up in the end user's node_modules

To Reproduce

devel/experiments/tmp
❯ npm i @oclif/plugin-warn-if-update-available

added 1057 packages in 4s

14 packages are looking for funding
  run `npm fund` for details

devel/experiments/tmp via  v20.11.1 took 4s
❯ npm ls mocha
tmp@ /Users/Dominykas_Blyze/devel/experiments/tmp
└─┬ @oclif/[email protected]
  └── [email protected] extraneous


devel/experiments/tmp via  v20.11.1
❯ rm -rf node_modules

devel/experiments/tmp via  v20.11.1 took 4s
❯ npm i @oclif/[email protected]

added 107 packages, and audited 108 packages in 962ms

18 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

devel/experiments/tmp via  v20.11.1
❯ npm ls mocha
tmp@ /Users/Dominykas_Blyze/devel/experiments/tmp
└── (empty)

Expected behavior

Dev dependencies should not be installed

Screenshots

n/a

Environment (please complete the following information):

  • OS & version: macOS, Node 20.x, npm 10.x
  • Shell/terminal & version: should not matter

Additional context

FWIW, npm has never done a good job respecting the shrinkwraps included as part of dependencies - it does not work consistently or reliably (it can be ignored at times, pulling in latest dependencies, rather than what is pinned, etc).

Using a shrinkwrap also creates problems in deduplication, e.g. @oclif/plugin-plugins has [email protected], but latest is [email protected] and so you end up with two versions of oclif in your dependency tree.

An in-range update of debug is breaking the build 🚨

Version 3.2.0 of debug was just published.

Branch Build failing 🚨
Dependency debug
Current Version 3.1.0
Type dependency

This version is covered by your current version range and after updating it in your project the build failed.

debug is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • ❌ ci/circleci: node-8: Your tests failed on CircleCI (Details).
  • βœ… ci/circleci: node-latest: Your tests passed on CircleCI! (Details).

Release Notes 3.2.0

A long-awaited release to debug is available now: 3.2.0.

Due to the delay in release and the number of changes made (including bumping dependencies in order to mitigate vulnerabilities), it is highly recommended maintainers update to the latest package version and test thoroughly.


Minor Changes

Patches

Credits

Huge thanks to @DanielRuf, @EirikBirkeland, @KyleStay, @Qix-, @abenhamdine, @alexey-pelykh, @DiegoRBaquero, @febbraro, @kwolfy, and @TooTallNate for their help!

Commits

The new version differs by 25 commits.

There are 25 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

ChainAlert: npm package release (2.1.0) has no matching tag in this repo

Dear @expo/plugin-warn-if-update-available maintainers,
Thank you for your contribution to the open-source community.

This issue was automatically created to inform you a new version (2.1.0) of @expo/plugin-warn-if-update-available was published without a matching tag in this repo.

Our service monitors the open-source ecosystem and informs popular packages' owners in case of potentially harmful activity.
If you find this behavior legitimate, kindly close and ignore this issue. Read more

badge

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


The push permission to the Git repository is required.

semantic-release cannot push the version tag to the branch master on remote Git repository.

Please refer to the authentication configuration documentation to configure the Git credentials on your CI environment.


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

Can anyone please tell How the latest variable populating?

While showing the update message: '<%= config.name %> update available from <%= chalk.greenBright(config.version) %> to <%= chalk.greenBright(latest) %>.', from where latest variable is coming? I checked in this file, but I didn' get how it is populating.

Display warning less frequently

If a new version of the CLI is found, every subsequent command execution displays the warning message. I'd prefer an option to specify how often the warning message should be displayed.

How to pass npm token as env variable

I am trying to pass an npm token as env var because my CLI tool is private, I was wondering if it's possible to do that.
As I see from here authorization can only be passed as a string.

Use package.json registry key

Hi,

It will be useful for private npm repo that the plug-in checks if a registry key in package.json exists and uses it in this case to check the last update.

For example in my project :
"publishConfig": {
"registry": "https:/xxxx:yyyy/repository/npm-private/"
}

Prerelease tag warnings not working as expected

When working with prerelease tags, we've noticed that the the plugin will warn the first time when a prerelease version has been published, for example x.x.x to x.x.x-alpha.x.

However, after that when the version has been bumped to prerelease, due to https://github.com/oclif/plugin-warn-if-update-available/blob/master/src/hooks/init/check-update.ts#L27 , there seems to be an early return due to the existence of -and there appears to no longer be any warning shown for further updates whether a prerelease or not. https://github.com/oclif/plugin-warn-if-update-available/blob/master/src/hooks/init/check-update.ts#L31 seems to indicate the possibility of splitting on a - and comparing at least the first part.

We were wondering what the reasoning is for the early return or if this is a case of unfinished logic?

Thanks

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.