Skip to content
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

Early fail for nodejs versions >= 15 #152

Merged
merged 2 commits into from
Mar 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions tests/examples-projects/single-dependency-lockfilev2/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "single-dependency",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"leftpad": "0.0.1"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{ pkgs ? import ../../../nix { } }:
pkgs.npmlock2nix.shell {
src = ./.;
}
40 changes: 39 additions & 1 deletion tests/integration-tests/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ npmlock2nix, testLib, callPackage, libwebp, runCommandNoCC, python3 }:
{ npmlock2nix, testLib, nodejs-16_x, callPackage, libwebp, runCommandNoCC, python3 }:
testLib.makeIntegrationTests {
leftpad = {
description = "Require a node dependency inside the shell environment";
Expand Down Expand Up @@ -246,4 +246,42 @@ testLib.makeIntegrationTests {
works
'';
};

npm7-old-lockfile = {
description = "NPM >= 7 isn't supported right now because it uses a newer lockfile version";
shell = npmlock2nix.shell {
src = ../examples-projects/single-dependency;
nodejs = nodejs-16_x;
};
evalFailure = true;
status = 1;
expected = "";
# 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 = {
description = "NPM >= 7 isn't supported right now because it uses a newer lockfile version";
shell = npmlock2nix.shell {
src = ../examples-projects/single-dependency-lockfilev2;
nodejs = nodejs-16_x;
};
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 = ''
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
'';
};
};
}
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