Git Product home page Git Product logo

Comments (8)

offlinehacker avatar offlinehacker commented on July 18, 2024

There's one other issue, the format of dependencies github:owner/name produces different directory layout in node_packages(owner/name instead of only name), i also have to handle this in nix.

from npm2nix.

bobvanderlinden avatar bobvanderlinden commented on July 18, 2024

Ouch, I wonder how this works for npm ls.

from npm2nix.

bobvanderlinden avatar bobvanderlinden commented on July 18, 2024

So I dug a little again, but isn't npm shrinkwrap what we want?

For instance:

cd popcorntime
npm install
npm shrinkwrap
cp npm-shrinkwrap.json nixpkgs/pkgs/applications/video/popcorntime/

Inside fetchnpm.nix:

stdenv.mkDerivation {
  builder = ''
    cp ${./npm-shrinkwrap.json} ./
    npm install
    cp -r node_modules $out
  '';
  outputHash = "...";
}

In default.nix link node_modules to the result of fetchnpm.
EDIT: I'm also wondering whether the result of installing shrinkwrapped dependencies will always result in the same node_modules (same hash). Do you know, or is this something to just try?
It's just an example, but is this a viable direction?

from npm2nix.

bobvanderlinden avatar bobvanderlinden commented on July 18, 2024

I did an experiment with npm-shrinkwrap. I ran npm shrinkwrap in popcorntime's repository and used the resulting file in a nix-expression where it runs npm install. There was some hackery, but it seems to be creating the same node_modules directory each time it is called here.

See here: https://gist.github.com/bobvanderlinden/05cb8e4b4400618ee487

from npm2nix.

wmertens avatar wmertens commented on July 18, 2024

The problem with shrinkwrap is that it uses the currently installed modules. If you run it against a fresh source without node_modules, it is empty.

Basically we need something that gets a package.json and dumps out the resolution. This resolution is the description nix needs to build the packages.

Then each of the packages in the resolution can be built, using the resolved dependencies. To get around the symlinked-dependencies-use-real-location-for-dependencies problem simply symlink one level down.

from npm2nix.

bobvanderlinden avatar bobvanderlinden commented on July 18, 2024

It might be a side-effect, but isn't the result of npm install && npm shrinkwrap the resolution you're looking for? It outputs a shrinkwrap file that contains the package names and versions of that time. Npm knows where to get those exact files. If that ran when you're packaging an application and include the shrinkwrap file in the nix package, it'll result in the exact same node_modules contents. A hash for the resulting node_modules directory will assert it is indeed always the same (it should be because that is what shrinkwrap is meant for).

Additionally, in an ideal situation the devs of an application itself include their version of the shrinkwrap file upon releasing stable versions. This can be reused, so that the package will include the exact packages the developers intended the application to use.

It's probably less space efficient and cost more time building than using npm2nix, but it might be more practical for maintaining some huge and complex packages.

from npm2nix.

dzmitry-lahoda avatar dzmitry-lahoda commented on July 18, 2024

may be it can be closed?

from npm2nix.

bobvanderlinden avatar bobvanderlinden commented on July 18, 2024

I haven't used npm2nix for quite a while, I'll close it. 👍

from npm2nix.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.