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

Manage "phoenix_html": "file:../deps/phoenix_html", style dependencies #98

Open
happysalada opened this issue Aug 28, 2021 · 4 comments

Comments

@happysalada
Copy link

happysalada commented Aug 28, 2021

I'm just reporting, in case that is interesting.
in the package.json, you can have entries like
"phoenix_html": "file:../deps/phoenix_html",
This happens in the elixir ecosystem. Where the frontend dependencies are released with the backend dependencies. Therefore they just reference a file path.
Currently npmlock2nix will throw the following error

error: [npmlock2nix] A valid dependency consists of at least the resolved and integrity field. Missing one or both of them for `phoenix_html`. The object I got looks like this: {"version":"file:../deps/phoenix_html"}

just mentioning this is not critical since you can circumvent this by patching the version in the package.json, there is often an npm published version that corresponds. Just sometimes the exact version is different. For phoenix_html for example the npm package version is 3.0.0 where as the elixir package version is 3.0.2.
So just to say that this can be worked around if needed.

@pietdevries94
Copy link

This problem gets bigger when using npm workspaces https://docs.npmjs.com/cli/v7/using-npm/workspaces

The following package.json files result in a problematic lockfile

package.json

{
  "name": "my-workspaces-powered-project",
  "version": "1.0.0",
  "workspaces": [
    "web"
  ]
}

web/package.json

{
  "name": "web",
  "version": "1.0.0"
}

package-lock.json

{
  "name": "my-workspaces-powered-project",
  "version": "1.0.0",
  "lockfileVersion": 2,
  "requires": true,
  "packages": {
    "": {
      "name": "my-workspaces-powered-project",
      "version": "1.0.0",
      "workspaces": [
        "web"
      ]
    },
    "node_modules/web": {
      "resolved": "web",
      "link": true
    },
    "web": {
      "version": "1.0.0"
    }
  },
  "dependencies": {
    "web": {
      "version": "file:web"
    }
  }
}

@cideM
Copy link

cideM commented Oct 12, 2021

I also ran into this issue with a project that uses Lerna where I replaced the references to packages that only Lerna knows about with file paths, thinking this would work because NPM understands this.

@Quelklef
Copy link

Bump. Weirdness of Purescript necessitates use of file: packages in some cases, which then breaks npmlock2nix. So another vote of desire from a Purescript user!

@Quelklef
Copy link

FWIW, I was able to get around this by removing my file: package from package.json and package-lock.json before passing them into npmlock2nix, and then manually re-adding them after-the-fact.

My package was called js-lib and the working nix code looked something like this:

node_modules = let

  without-local-deps =
    pkgs.stdenv.mkDerivation {
      name = "my-project-without-local-deps";
      src = ./.;
      buildInputs = [ pkgs.jq ];
      installPhase = ''
        mkdir $out
        cat $src/package.json \
              | jq 'del( .dependencies."js-lib" )' \
              > $out/package.json
        cat $src/package-lock.json \
              | jq 'del( .packages."".dependencies."js-lib" )' \
              | jq 'del( .packages."js-lib" )' \
              | jq 'del( .packages."node_modules/js-lib" )' \
              > $out/package-lock.json
      '';
    };

  npmlock2nix-d =
    npmlock2nix.node_modules {
      src = without-local-deps;
    };

  with-local-deps =
    pkgs.runCommand "my-project-with-local-deps" {} ''
      mkdir $out
      cp -r -- ${npmlock2nix-d}/node_modules $out
      chmod +w -R $out/node_modules
      cp -r -- ${./js-lib} $out/node_modules/js-lib
    '';

  in with-local-deps;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants