Skip to content
This repository has been archived by the owner on Jan 15, 2020. It is now read-only.

Review for buildNpmPackage #2

Closed
wants to merge 5 commits into from
Closed

Conversation

yorickvP
Copy link
Contributor

No description provided.

echo making cache
node ${./mkcache.js} ${npm-cache-input lock}
echo installing
npm ci --cache=./npm-cache --offline --script-shell=${shellWrap}/bin/npm-shell-wrap.sh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was about to tell you to use full command names instead of abbreviations in scripts, but it turns out npm ci is the full command name. Cue traditional npm-inspired facepalm.

Copy link
Contributor

@lukateras lukateras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will take another pass a bit later.

@@ -16,6 +16,8 @@ in
rev = "76dc0f06d21f6063cb7b7d2291b8623da24affa9";
}) {};

buildNpmPackage = callPackage ./buildNpmPackage {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nicer if this were a separate repo, I don't think it's right to commit JS code into a closure which is supposed to mostly point to stuff.

let
inherit (builtins) fromJSON toJSON readFile split head elemAt foldl';

deps-to-fetches = base: deps: builtins.foldl' (a: b: a // (dep-to-fetch b)) base (builtins.attrValues deps);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

builtins.foldl' -> foldl', builtins.attrValues -> attrValues, deps-to-fetches -> depsToFetches

@@ -0,0 +1,58 @@
{ stdenvNoCC, writeShellScriptBin, writeText, stdenv, fetchurl, makeWrapper, nodejs-10_x }:
let
inherit (builtins) fromJSON toJSON readFile split head elemAt foldl';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with lib;

in
args @ { lockfile, src, buildInputs ? [], ... }:
let lock = fromJSON (readFile lockfile); in
stdenv.mkDerivation ({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stdenv.mkDerivation ({ /* ... */ }) -> stdenv.mkDerivation { /* ... */ }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is stdenv.mkDerivation ({ ... } // { ... } // { ... })

'';
in
args @ { lockfile, src, buildInputs ? [], ... }:
let lock = fromJSON (readFile lockfile); in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let
  lock = fromJSON (readFile lockFile);
in

"${resolved}" = fetchurl {
url = resolved;
"${hashtype}" = hash;
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should rather return nameValuePair.

};

dep-to-fetch = args @ { resolved ? null, dependencies ? {}, ... }:
deps-to-fetches (if isNull resolved then {} else dep-own-fetch args) dependencies;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fromDeps (optionalAttrs (resolved != null) (dep2thing args)) dependencies

module.paths.push(path.join(process.argv[0], "../../lib/node_modules/npm/node_modules"))
const pacote = require('pacote')

function forall_deps(pkg, fn) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

traverseDeps, walkDeps? forall typically doesn't presume tree traversal.

buildPhase = ''
echo making cache
node ${./mkcache.js} ${npm-cache-input lock}
echo installing
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is install, everything below it should go into installPhase instead.

XDG_CONFIG_DIRS = ".";
NO_UPDATE_NOTIFIER = true;
buildPhase = ''
echo making cache
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Derivations shouldn't print that, it's phases job.

Copy link
Contributor

@lukateras lukateras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, this does not follow Nixpkgs style guidelines, and variable names could be better.

@yorickvP
Copy link
Contributor Author

yorickvP commented Oct 8, 2018 via email

exec bash "$@"
'';
in
args @ { lockfile, src, buildInputs ? [], npmFlags ? [], ... }:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is lockfile set?

inherit (builtins) fromJSON toJSON split;

depsToFetches = deps: concatMap depToFetch (attrValues deps);
depFetchOwn = { resolved, integrity, ... }: let
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't you also getting non-production dependencies here?

# unpack the .tgz into output directory and add npm wrapper
installPhase = ''
mkdir -p $out/bin
tar xzvf ./${lock.name}-${lock.version}.tgz -C $out --strip-components=1
Copy link
Contributor

@obfusk obfusk Oct 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use ${name} (= "${lock.name}-${lock.version}") here.

@obfusk
Copy link
Contributor

obfusk commented Oct 22, 2018

I suggest closing this in favor of a PR that uses serokell/nix-npm-buildpackage#2 when that's done.

@Lucus16
Copy link
Contributor

Lucus16 commented Oct 26, 2018

Closing in favor of #5

@Lucus16 Lucus16 closed this Oct 26, 2018
@serokell-bot serokell-bot deleted the yorickvp-review branch October 26, 2018 15:56
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants