-
-
Notifications
You must be signed in to change notification settings - Fork 126
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
feat/nodejs_sanitize_lockfile #665
Open
hsjobeki
wants to merge
7
commits into
nix-community:main
Choose a base branch
from
hsjobeki:feat/cleanup-v3
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
753b3f9
cleanup work
hsjobeki efe16f8
add basic lockfile check
hsjobeki 9233de8
add sanitizeLockfile smoke validator
hsjobeki 267ed15
add lockfile tests
hsjobeki fe14519
Merge branch 'main' into feat/cleanup-v3
hsjobeki 2760d68
add more unit tests for catching invalid lockfiles early
hsjobeki 4c58eeb
just check the lockfileVersion
hsjobeki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,31 +11,42 @@ | |
|
||
nodejsLockUtils = import ../../../lib/internal/nodejsLockUtils.nix {inherit lib;}; | ||
|
||
isLink = plent: plent ? link && plent.link; | ||
# Collection of sanitized functions that always return the same type | ||
isLink = pent: pent.link or false; | ||
|
||
parseSource = plent: | ||
if isLink plent | ||
# isDev = pent: pent.dev or false; | ||
# isOptional = pent: pent.optional or false; | ||
# isInBundle = pent: pent.inBundle or false; | ||
# hasInstallScript = pent: pent.hasInstallScript or false; | ||
# getBin = pent: pent.bin or {}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can these be removed? |
||
|
||
/* | ||
Pent :: { | ||
See: https://docs.npmjs.com/cli/v9/configuring-npm/package-lock-json#packages | ||
} | ||
> We should mention that docs are imcomplete on npmjs.com | ||
pent is one entry of 'packages' | ||
*/ | ||
parseSource = pent: | ||
if isLink pent | ||
then | ||
# entry is local file | ||
(builtins.dirOf config.nodejs-package-lock-v3.packageLockFile) + "/${plent.resolved}" | ||
(builtins.dirOf config.nodejs-package-lock-v3.packageLockFile) + "/${pent.resolved}" | ||
else | ||
fetchurl { | ||
url = plent.resolved; | ||
hash = plent.integrity; | ||
url = pent.resolved; | ||
hash = pent.integrity; | ||
}; | ||
|
||
getDependencies = lock: path: plent: | ||
l.mapAttrs (name: _descriptor: { | ||
dev = plent.dev or false; | ||
version = let | ||
# Need this util as dependencies no explizitly locked version | ||
# This findEntry is needed to find the exact locked version | ||
packageIdent = nodejsLockUtils.findEntry lock path name; | ||
in | ||
# Read version from package-lock entry for the resolved package | ||
lock.packages.${packageIdent}.version; | ||
getDependencies = lock: path: pent: | ||
l.mapAttrs (depName: _semverConstraint: let | ||
packageIdent = nodejsLockUtils.findEntry lock path depName; | ||
depPent = lock.packages.${packageIdent}; | ||
in { | ||
dev = pent.dev or false; | ||
version = depPent.version; | ||
}) | ||
(plent.dependencies or {} // plent.devDependencies or {} // plent.optionalDependencies or {}); | ||
(pent.dependencies or {} // pent.devDependencies or {} // pent.optionalDependencies or {}); | ||
|
||
# Takes one entry of "package" from package-lock.json | ||
parseEntry = lock: path: entry: | ||
|
@@ -70,18 +81,21 @@ | |
}; | ||
}; | ||
|
||
parse = lock: | ||
mergePdefs = | ||
builtins.foldl' | ||
(acc: entry: | ||
acc | ||
// { | ||
${entry.name} = acc.${entry.name} or {} // entry.value; | ||
}) | ||
{} | ||
# [{name=; value=;} ...] | ||
{}; | ||
|
||
parse = lock: | ||
mergePdefs | ||
# type: [ { name :: String; value :: {...}; } ] | ||
(l.mapAttrsToList (parseEntry lock) lock.packages); | ||
|
||
pdefs = parse config.nodejs-package-lock-v3.packageLock; | ||
pdefs = parse (nodejsLockUtils.sanitizeLockfile config.nodejs-package-lock-v3.packageLock); | ||
in { | ||
imports = [ | ||
./interface.nix | ||
|
This file contains 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
This file contains 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
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sanitizeLockFile -> ensureLockFileVersion?