NPM
| source | condition | target |
|---|---|---|
✔ | ✔ | ✗ |
Description
The npm resource queries an npm registry for the versions of a package.
- source
Returns the version of the package matching
versionfilter.- condition
Checks that
versionis published for the package.- target
Not supported - a registry is not something Updatecli publishes to. A target fails with
Target not supported for the plugin Npm. To bump a dependency in a file, use the "JSON" resource againstpackage.json, or the npm autodiscovery crawler.
Note | An scm attached to a condition is ignored, with a warning (the lookup always goes to the registry). |
Parameters
| Name | Type | Description | Required |
|---|---|---|---|
| name | string | Defines the specific npm package name | |
| npmrcpath | string | NpmrcPath defines the path to the .npmrc file | |
| registrytoken | string | RegistryToken defines the token to use when connection to the registry | |
| url | string | URL defines the registry url (defaults to https://registry.npmjs.org/) | |
| version | string | Defines a specific package version | |
| versionfilter | object | VersionFilter provides parameters to specify version pattern and its type like regex, semver, or just latest. | |
| kind | string | specifies the version kind such as semver, regex, or latest | |
| pattern | string | specifies the version pattern according the version kind for semver, it is a semver constraint for regex, it is a regex pattern for time, it is a date format | |
| regex | string | specifies the regex pattern, used for regex/semver and regex/time. Output of the first capture group will be used. | |
| replaceall | object | replaceAll applies a regex replacement to version strings before filtering. This is useful for transforming versions (e.g., curl-8_15_0 to curl-8.15.0) before regex extraction. | |
| strict | boolean | strict enforce strict versioning rule. Only used for semantic versioning at this time |
nameThe package name, scope included:
@updatecli/updateclias well asexpress.urlDefaults to
https://registry.npmjs.org/.versionCondition only - the version whose existence is being checked.
Version selection
versionfilter behaves differently here than on most resources: with kind: latest, the value is taken from the registry’s own dist-tags.latest, which is what npm install <pkg> would give you (not the highest version number).
Every other filter kind sorts the full version list and applies the pattern. That distinction matters for packages that publish patches for older majors after a new major: latest follows the maintainer’s tag, semver follows the numbering. See the "Version Filtering" page.
Authentication
Private registries are reached in one of two ways.
registrytoken sets the bearer token directly, keep it out of the manifest:
spec:
name: "@acme/widget"
url: "https://npm.acme.example.com"
registrytoken: '{{ requiredEnv "NPM_TOKEN" }}'npmrcpath points at an .npmrc file instead. Its handling has a fallback worth knowing about:
Important | When |
From an .npmrc, Updatecli reads two kinds of entry:
//registry.example.com/:_authToken=xxx- a token per registry@scope:registry=https://registry.example.com- a registry per scope
Example
# updatecli.yaml
name: NPM resource example
sources:
axios:
name: Get latest axios version from npm registry
kind: npm
spec:
name: axios
yaml:
name: get latest yaml version matching ~0
kind: npm
spec:
name: yaml
versionfilter:
kind: semver
pattern: ~0
conditions:
axios:
name: Test that axios version 1.0.0 exists on the NPM registry
kind: npm
disablesourceinput: true
spec:
name: axios
version: 1.0.0
yaml:
name: Test that that YAML version matching ~0 exist on registry
kind: npm
sourceid: yaml
spec:
name: yaml
targets:
# Targets are not supported