npm-pin-versions
What it does
Section titled “What it does”Reports an npm install (also npm i and npm add) of a package without a version: express instead of express@4.18.2, @scope/name instead of @scope/name@1.2.0. A path, a tarball (.tgz, .tar.gz) or a git URL with a #ref counts as pinned. The value of --loglevel or --registry is not taken for a package, and an npm install with no package (it reads package.json) is not reported.
Why it matters
Section titled “Why it matters”Without a version npm installs the latest release on the day of the build, so a new major version of the package can break the image and two builds of one Dockerfile differ.
Pin the version in the command, or keep it in package.json with a lock file and use npm ci.
Example
Section titled “Example”...RUN pip install git+https://github.com/a/b@v1RUN npm installRUN npm install expressRUN npm install express@4 @scope/pkg@1RUN npm install --loglevel verbose express@4RUN npm install ./localRUN npm i expressRUN npm add express@4...Configuration
Section titled “Configuration”dockerfile: lint: rules: npm-pin-versions: warn # off (default), warn, errorEnabled by the presets: dockerfile/hadolint.
Suppress one line with sudsy-disable-next-line npm-pin-versions in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.
| Tool | Rule | Match | What differs |
|---|---|---|---|
| hadolint | DL3016 |
partial | A package is judged by its text (@, #, tarball, path); git and scoped forms follow hadolint’s cases only. |