File tree Expand file tree Collapse file tree 4 files changed +31
-22
lines changed Expand file tree Collapse file tree 4 files changed +31
-22
lines changed Original file line number Diff line number Diff line change 3737
3838 getTranslatorNames = path : let
3939 nodes = l . readDir path ;
40- packageJson = l . fromJSON ( l . readFile " ${ path } /package.json" ) ;
40+ packageJson = getPackageJson path ;
4141 translators =
4242 # if the package has no dependencies we use the
4343 # package-lock translator with `packageLock = null`
4646 && ( packageJson . devDependencies or { } == { } )
4747 && ( packageJson . workspaces or [ ] == [ ] )
4848 then [ "package-lock" ]
49+ else if nodes ? "package-lock.json"
50+ then let
51+ # Wish there was a way to get the version without reading a 2MB file
52+ lockJson = getLockJson path ;
53+ lockVersion = lockJson . lockfileVersion or 0 ;
54+ in
55+ if lockVersion == 1
56+ then [ "package-lock" ]
57+ else if lockVersion == 2
58+ then [ "resolved-json" ]
59+ else [ "package-json" ]
4960 else
5061 l . optionals ( nodes ? "yarn.lock" ) [ "yarn-lock" ]
5162 ++ [ "package-json" ] ;
5263 in
5364 translators ;
5465
5566 # returns the parsed package.json of a given directory
56- getPackageJson = dirPath :
57- l . fromJSON ( l . readFile "${ dirPath } /package.json" ) ;
67+ getJson = jsonPath : l . fromJSON ( l . readFile jsonPath ) ;
68+ getPackageJson = dirPath : getJson "${ dirPath } /package.json" ;
69+ getLockJson = dirPath : getJson "${ dirPath } /package-lock.json" ;
5870
5971 # returns all relative paths to workspaces defined by a glob
6072 getWorkspacePaths = glob : tree :
Original file line number Diff line number Diff line change 2929 git
3030 jq
3131 nodejs-18_x
32- # nodejs-18_x.pkgs.npm
3332 openssh
3433 ]
3534 ''
4948
5049 cd ./$relPath
5150
52- # create package lock if missing or old
53- if ! [ -r package-lock.json ] || [ $(jq '.lockfileVersion' -r package-lock.json) != 2 ]; then
54- rm -f package-lock.json
51+ rm -f package-lock.json
52+ echo Generating temporary package-lock.json with npm
5553
56- # TODO: some easy way to add --offline, maybe separate flake run script? Speeds up enormously when cached.
57- npm install --package-lock-only $npmArgs
58- fi
59-
60- # resolve packages - TODO move to RunCommandLocal
61- node ${ ./resolver.cjs } package-lock.json resolved.json
54+ npm install --package-lock-only $npmArgs
6255
6356 jq ".source = \"$newSource\"" -c -r $jsonInput > $TMPDIR/newJsonInput
6457
Original file line number Diff line number Diff line change 77 l = lib // builtins ;
88 nodejsUtils = import ../utils.nix { inherit lib ; } ;
99
10- getResolved = tree : project :
11- nodejsUtils . getWorkspaceLockFile tree project "resolved.json" ;
12-
1310 translate = {
1411 translatorName ,
1512 utils ,
13+ pkgs ,
1614 ...
1715 } : {
1816 project ,
1917 source ,
2018 tree ,
2119 # translator args
22- noDev ,
20+ name ? project . name or "untitled" ,
2321 nodejs ,
2422 ...
2523 } @ args : let
2624 b = builtins ;
2725
28- # TODO only dev for devShell
29- dev = ! noDev ;
30- name = project . name ;
3126 tree = args . tree . getNodeFromPath project . relPath ;
3227 relPath = project . relPath ;
3328 source = "${ args . source } /${ relPath } " ;
3429 workspaces = project . subsystemInfo . workspaces or [ ] ;
3530
36- lock = ( getResolved args . tree project ) . jsonContent or null ;
31+ getResolved = tree : project : let
32+ lock =
33+ nodejsUtils . getWorkspaceLockFile tree project "package-lock.json" ;
34+ resolved = pkgs . runCommandLocal "resolved.json" { } ''
35+ ${ nodejs } /bin/node ${ ./resolver.cjs } ${ lock . fullPath } $out
36+ '' ;
37+ in
38+ l . fromJSON ( l . readFile resolved ) ;
39+
40+ lock = getResolved args . tree project ;
3741
3842 packageVersion = lock . version or "unknown" ;
3943
113117in rec {
114118 version = 2 ;
115119
116- type = "pure " ;
120+ type = "ifd " ;
117121
118122 inherit translate ;
119123
File renamed without changes.
You can’t perform that action at this time.
0 commit comments