Skip to content

Commit

Permalink
Early fail for nodejs versions >= 15
Browse files Browse the repository at this point in the history
nodejs versions >= 15 use npm >= 7, which uses a new lockfile version
that's currently not supported by npmlock2nix. Hook scripts, which
npmlock2nix relies on are also removed
  • Loading branch information
infinisil committed Mar 22, 2022
1 parent 4b6879c commit b5d0baa
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
8 changes: 6 additions & 2 deletions internal.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{ nodejs, stdenv, mkShell, lib, fetchurl, writeText, writeTextFile, runCommand, fetchFromGitHub }:
{ nodejs-14_x, stdenv, mkShell, lib, fetchurl, writeText, writeTextFile, runCommand, fetchFromGitHub }:
rec {
default_nodejs = nodejs;
# Versions >= 15 use npm >= 7, which uses npm lockfile version 2, which we don't support yet
# See the assertion in the node_modules function
default_nodejs = nodejs-14_x;


# builtins.fetchGit wrapper that ensures compatibility with Nix 2.3 and Nix 2.4
Expand Down Expand Up @@ -318,6 +320,8 @@ rec {
, passthru ? { }
, ...
}@args:
assert lib.versionAtLeast nodejs.version "15.0" ->
throw "npmlock2nix is called with nodejs version ${nodejs.version}, which is currently not supported, see https://github.com/nix-community/npmlock2nix/issues/153 for more information";
assert (builtins.typeOf preInstallLinks != "set") ->
throw "`preInstallLinks` must be an attributeset of attributesets";
let
Expand Down
26 changes: 12 additions & 14 deletions tests/integration-tests/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -256,19 +256,15 @@ testLib.makeIntegrationTests {
evalFailure = true;
status = 1;
expected = "";
expected-stderr = [
{
contains = ''
npm WARN old lockfile The package-lock.json file was created with an old version of npm,
npm WARN old lockfile so supplemental metadata must be fetched from the registry.
'';
}
{
contains = ''
npm ERR! Error: EACCES: permission denied, open '/build/package-lock.json'
'';
}
];
# Would fail with
# npm WARN old lockfile The package-lock.json file was created with an old version of npm,
# npm WARN old lockfile so supplemental metadata must be fetched from the registry.
# npm ERR! Error: EACCES: permission denied, open '/build/package-lock.json'
expected-stderr = {
contains = ''
error: [npmlock2nix] npmlock2nix is called with nodejs version 16.13.0, which is currently not supported, see https://github.com/nix-community/npmlock2nix/issues/153 for more information
'';
};
};

npm7-new-lockfile = {
Expand All @@ -280,9 +276,11 @@ testLib.makeIntegrationTests {
evalFailure = true;
status = 1;
expected = "";
# Would fail with
# npm ERR! request to https://registry.npmjs.org/leftpad/-/leftpad-0.0.1.tgz failed: cache mode is 'only-if-cached' but no cached response is available.
expected-stderr = {
contains = ''
npm ERR! request to https://registry.npmjs.org/leftpad/-/leftpad-0.0.1.tgz failed: cache mode is 'only-if-cached' but no cached response is available.
error: [npmlock2nix] npmlock2nix is called with nodejs version 16.13.0, which is currently not supported, see https://github.com/nix-community/npmlock2nix/issues/153 for more information
'';
};
};
Expand Down
10 changes: 8 additions & 2 deletions tests/node-modules.nix
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,15 @@ testLib.runTests {
testNodeModulesAcceptsCustomNodejs = {
expr = (npmlock2nix.node_modules {
src = ./examples-projects/no-dependencies;
nodejs = "our-custom-nodejs-package";
nodejs = {
pname = "our-custom-nodejs-package";
version = "14.12.34";
};
}).nodejs;
expected = "our-custom-nodejs-package";
expected = {
pname = "our-custom-nodejs-package";
version = "14.12.34";
};
};

testNodeModulesPropagatesNodejs =
Expand Down

0 comments on commit b5d0baa

Please sign in to comment.