Repository navigation
Report the real package name for aliased package-lock.json entries - #184
Open
abhinavgautam01 wants to merge 1 commit into
Open
abhinavgautam01 wants to merge 1 commit into
abhinavgautam01 wants to merge 1 commit into
Conversation
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #177.
Summary
An npm alias such as
"my-lodash": "npm:lodash@^4.17.21"installslodashatnode_modules/my-lodash. The lockfile parser named every entry after its install path, so the alias came out asmy-lodashwithpkg:npm/my-lodash@4.17.21, a different package on the registry.v2 / v3 lockfiles
npm records the real package in the entry's
namefield whenever it differs from the path.packageLockEntrynow readsname, in both the line scanner and the JSON decoder, and uses it forNamewhen present:Root
dependenciesare keyed by the alias, soDirectis still decided by the install name. Without that, aliased dependencies would turn indirect.v1 lockfiles
v1 keeps the alias in the version string (
"version": "npm:lodash@4.17.21"), which was reported as a version ofmy-lodash. It now goes through the existingparseNpmAlias, givinglodashat4.17.21, the same aspackage.jsonparsing.Line scanner
The scanner starts a fresh entry at every
: {line, so a dependency literally namednameinside an entry's nesteddependenciescannot rename the entry. The new fixture covers this.Tests
testdata/npm/npm-lockfile-alias/package-lock.jsonin npm's formatting: a plain alias, a scoped dev alias, a nested alias, a nested dependency namednameand an unaliased package. It is checked for name, version, scope and directness, and added toTestPackageLockPathsAgreeso the line scanner and the decoder must agree on it.TestPackageLockAliasCompactJSONuses the exact lockfile from the issue.TestPackageLockV1Aliascovers plain and scoped v1 aliases.npm_lock_alias_test.gocheckspkg:npm/lodash@4.17.21throughParseforpackage-lock.jsonandnpm-shrinkwrap.json.TestNpmPackageLockV3expected the install namealias-package-nameeven though its fixture records"name": "@some-scope/actual-package". It now expects the real name.go build ./...,go vet ./...,go test ./...andgolangci-lint run ./...all pass.Notes
yarn.lockreports the same alias under its install name (TestYarnLockexpectsalias-package-name). That is a separate parser, so I left it for a follow-up.toDependency, so whichever lands second will need a small rebase.