···161162`buildNpmPackage` allows you to package npm-based projects in Nixpkgs without the use of an auto-generated dependencies file (as used in [node2nix](#javascript-node2nix)). It works by utilizing npm's cache functionality -- creating a reproducible cache that contains the dependencies of a project, and pointing npm to it.
16300164```nix
165{ lib, buildNpmPackage, fetchFromGitHub }:
166···190 };
191}
192```
00193194#### Arguments {#javascript-buildNpmPackage-arguments}
195···204* `npmBuildFlags`: Flags to pass to `npm run ${npmBuildScript}`.
205* `npmPackFlags`: Flags to pass to `npm pack`.
206* `npmPruneFlags`: Flags to pass to `npm prune`. Defaults to the value of `npmInstallFlags`.
0207208#### prefetch-npm-deps {#javascript-buildNpmPackage-prefetch-npm-deps}
209210-`prefetch-npm-deps` can calculate the hash of the dependencies of an npm project ahead of time.
211212```console
213$ ls
···216...
217sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
218```
000000000219220### corepack {#javascript-corepack}
221
···161162`buildNpmPackage` allows you to package npm-based projects in Nixpkgs without the use of an auto-generated dependencies file (as used in [node2nix](#javascript-node2nix)). It works by utilizing npm's cache functionality -- creating a reproducible cache that contains the dependencies of a project, and pointing npm to it.
163164+Here's an example:
165+166```nix
167{ lib, buildNpmPackage, fetchFromGitHub }:
168···192 };
193}
194```
195+196+In the default `installPhase` set by `buildNpmPackage`, it uses `npm pack --json --dry-run` to decide what files to install in `$out/lib/node_modules/$name/`, where `$name` is the `name` string defined in the package's `package.json`. Additionally, the `bin` and `man` keys in the source's `package.json` are used to decide what binaries and manpages are supposed to be installed. If these are not defined, `npm pack` may miss some files, and no binaries will be produced.
197198#### Arguments {#javascript-buildNpmPackage-arguments}
199···208* `npmBuildFlags`: Flags to pass to `npm run ${npmBuildScript}`.
209* `npmPackFlags`: Flags to pass to `npm pack`.
210* `npmPruneFlags`: Flags to pass to `npm prune`. Defaults to the value of `npmInstallFlags`.
211+* `makeWrapperArgs`: Flags to pass to `makeWrapper`, added to executable calling the generated `.js` with `node` as an interpreter. These scripts are defined in `package.json`.
212213#### prefetch-npm-deps {#javascript-buildNpmPackage-prefetch-npm-deps}
214215+`prefetch-npm-deps` is a Nixpkgs package that calculates the hash of the dependencies of an npm project ahead of time.
216217```console
218$ ls
···221...
222sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
223```
224+225+#### fetchNpmDeps {#javascript-buildNpmPackage-fetchNpmDeps}
226+227+`fetchNpmDeps` is a Nix function that requires the following mandatory arguments:
228+229+- `src`: A directory / tarball with `package-lock.json` file
230+- `hash`: The output hash of the node dependencies defined in `package-lock.json`.
231+232+It returns a derivation with all `package-lock.json` dependencies downloaded into `$out/`, usable as an npm cache.
233234### corepack {#javascript-corepack}
235