svanderburg / node2nix

Generate Nix expressions to build NPM packages
MIT License
508 stars 98 forks source link

Breaks when using `npm:...` version syntax #231

Open ursi opened 3 years ago

ursi commented 3 years ago

This dependency would not get picked up for me.

"latest-snabbdom-release": "npm:snabbdom@2.1.0"

When I run node2nix -l package-lock.json on this package.json after generating package-lock.json using npm i

{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "latest-snabbdom-release": "npm:snabbdom@2.1.0"
  }
}

then run nix-build -A nodeDependencies, the result/lib/node_modules folder is not made. If other dependencies are added, the node_modules folder will be in the derivation, and contain everything except latest-snabbdom-release.

datakurre commented 3 years ago

For me, a patch like this, seems to work

+++ b/nix/node-env.nix
@@ -135,6 +135,9 @@ let
           function replaceDependencies(dependencies) {
               if(typeof dependencies == "object" && dependencies !== null) {
                   for(var dependency in dependencies) {
+                      if (dependencies[dependency].startsWith("npm:")) {
+                        dependency = dependencies[dependency].substring(4).split("@")[0];
+                      }
                       var resolvedVersion = resolveDependencyVersion(process.cwd(), dependency);

                       if(resolvedVersion === null) 
svanderburg commented 2 years ago

There are 2 PRs for introducing npm: aliases, but the problem is that they extend the functionality on the wrong level causing them also to be used as version specifiers.

The proper solution is to change the functionality that treats all package specifiers as dependency specifiers, and interpret the aliases there.

towry commented 1 month ago

2024 now, can not use @vue/language-service because it use npm:....