-
-
Notifications
You must be signed in to change notification settings - Fork 136
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
Node package-lock v2 #246
Open
wmertens
wants to merge
1
commit into
nix-community:main
Choose a base branch
from
wmertens:node-pkg-v2
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
Node package-lock v2 #246
Changes from all commits
Commits
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
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
174 changes: 174 additions & 0 deletions
174
src/subsystems/nodejs/translators/package-lock-v2/default.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
# TODO use translate2 | ||
# TODO use package.json for v1 lock files | ||
{ | ||
dlib, | ||
lib, | ||
... | ||
}: let | ||
b = builtins; | ||
l = lib // builtins; | ||
nodejsUtils = import ../utils.nix {inherit lib;}; | ||
|
||
translate = { | ||
translatorName, | ||
utils, | ||
pkgs, | ||
... | ||
}: { | ||
project, | ||
source, | ||
tree, | ||
# translator args | ||
# name | ||
# nodejs | ||
... | ||
} @ args: let | ||
b = builtins; | ||
|
||
name = | ||
if (args.name or "{automatic}") != "{automatic}" | ||
then args.name | ||
else project.name; | ||
tree = args.tree.getNodeFromPath project.relPath; | ||
relPath = project.relPath; | ||
source = "${args.source}/${relPath}"; | ||
workspaces = project.subsystemInfo.workspaces or []; | ||
|
||
getResolved = tree: project: let | ||
lock = | ||
(nodejsUtils.getWorkspaceLockFile tree project "package-lock.json").jsonContent; | ||
resolved = import ./v2-parse.nix {inherit lib lock source;}; | ||
in | ||
resolved; | ||
|
||
resolved = getResolved args.tree project; | ||
|
||
packageVersion = resolved.self.version or "unknown"; | ||
|
||
rootDependencies = resolved.self.deps; | ||
|
||
identifyGitSource = dep: | ||
# TODO: when integrity is there, and git url is github then use tarball instead | ||
# ! (dep ? integrity) && | ||
dlib.identifyGitUrl dep.url; | ||
|
||
getVersion = dep: dep.version; | ||
|
||
getPath = dep: | ||
lib.removePrefix "file:" dep.url; | ||
|
||
getSource = { | ||
url, | ||
hash, | ||
... | ||
}: {inherit url hash;}; | ||
|
||
# TODO check that this works with workspaces | ||
extraInfo = b.foldl' (acc: dep: | ||
if dep.extra != {} | ||
then l.recursiveUpdate acc {${dep.pname}.${dep.version} = dep.extra;} | ||
else acc) {} | ||
resolved.allDeps; | ||
|
||
# TODO workspaces | ||
hasBuildScript = let | ||
pkgJson = | ||
(nodejsUtils.getWorkspaceLockFile tree project "package.json").jsonContent; | ||
in | ||
(pkgJson.scripts or {}) ? build; | ||
in | ||
utils.simpleTranslate | ||
({ | ||
getDepByNameVer, | ||
dependenciesByOriginalID, | ||
... | ||
}: rec { | ||
inherit translatorName; | ||
location = relPath; | ||
|
||
# values | ||
inputData = resolved.allDeps; | ||
|
||
defaultPackage = name; | ||
|
||
packages = | ||
{"${defaultPackage}" = packageVersion;} | ||
// (nodejsUtils.getWorkspacePackages tree workspaces); | ||
|
||
mainPackageDependencies = resolved.self.deps; | ||
|
||
subsystemName = "nodejs"; | ||
|
||
subsystemAttrs = { | ||
inherit extraInfo hasBuildScript; | ||
nodejsVersion = args.nodejs; | ||
}; | ||
|
||
# functions | ||
serializePackages = inputData: inputData; | ||
|
||
getName = dep: dep.pname; | ||
|
||
inherit getVersion; | ||
|
||
# TODO handle npm link maybe? not sure what it looks like in lock | ||
getSourceType = dep: | ||
if lib.hasPrefix "file:" dep.url | ||
then "path" | ||
else if identifyGitSource dep | ||
then "git" | ||
else "http"; | ||
|
||
sourceConstructors = { | ||
git = dep: | ||
(getSource dep) | ||
// (dlib.parseGitUrl dep.url); | ||
|
||
http = dep: (getSource dep); | ||
|
||
path = dep: (dlib.construct.pathSource { | ||
path = getPath dep; | ||
rootName = project.name; | ||
rootVersion = packageVersion; | ||
}); | ||
}; | ||
|
||
getDependencies = dep: dep.deps; | ||
}); | ||
in rec { | ||
version = 2; | ||
|
||
type = "pure"; | ||
|
||
inherit translate; | ||
|
||
extraArgs = { | ||
name = { | ||
description = "The name of the main package"; | ||
examples = [ | ||
"react" | ||
"@babel/code-frame" | ||
]; | ||
default = "{automatic}"; | ||
type = "argument"; | ||
}; | ||
|
||
transitiveBinaries = { | ||
description = "Should all the binaries from all modules be available, or only those from dependencies"; | ||
default = false; | ||
type = "boolean"; | ||
}; | ||
|
||
# TODO: this should either be removed or only used to select | ||
# the nodejs version for translating, not for building. | ||
nodejs = { | ||
description = "nodejs version to use for building"; | ||
default = "16"; | ||
examples = [ | ||
"14" | ||
"16" | ||
]; | ||
type = "argument"; | ||
}; | ||
}; | ||
} |
Oops, something went wrong.
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.
I have spent a bit of time trying to understand why dream2nix main doesn'twork and seems like it is because it doesn't support lockVersion 2. I would have much preferred for dream2nix to just bail out with "unsupported lock file version". I would have earned quite some time and this PR is the opportunity to do so for unknown/unsupported lockVersions