You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`importNpmLock` is a Nix function that requires the following optional arguments:
261
+
This function replaces the npm dependency references in `package.json` and `package-lock.json` with paths to the Nix store.
262
+
How each dependency is fetched can be customized with the `fetcherOpts` argument.
262
263
263
-
-`npmRoot`: Path to package directory containing the source tree
264
+
This is a simpler and more convenient alternative to [`fetchNpmDeps`](#javascript-buildNpmPackage-fetchNpmDeps) for managing npm dependencies in Nixpkgs.
265
+
There is no need to specify a `hash`, since it relies entirely on the integrity hashes already present in the `package-lock.json` file.
266
+
267
+
##### Inputs {#javascript-buildNpmPackage-inputs}
268
+
269
+
-`npmRoot`: Path to package directory containing the source tree.
270
+
If this is omitted, the `package` and `packageLock` arguments must be specified instead.
264
271
-`package`: Parsed contents of `package.json`
265
272
-`packageLock`: Parsed contents of `package-lock.json`
266
273
-`pname`: Package name
267
274
-`version`: Package version
275
+
-`fetcherOpts`: An attribute set of arguments forwarded to the underlying fetcher.
268
276
269
277
It returns a derivation with a patched `package.json` & `package-lock.json` with all dependencies resolved to Nix store paths.
270
278
271
-
This function is analogous to using `fetchNpmDeps`, but instead of specifying `hash` it uses metadata from `package.json` & `package-lock.json`.
279
+
:::{.note}
280
+
`npmHooks.npmConfigHook` cannot be used with `importNpmLock`.
281
+
Use `importNpmLock.npmConfigHook` instead.
282
+
:::
283
+
284
+
:::{.example}
285
+
286
+
##### `pkgs.importNpmLock` usage example {#javascript-buildNpmPackage-example}
287
+
```nix
288
+
{ buildNpmPackage, importNpmLock }:
289
+
290
+
buildNpmPackage {
291
+
pname = "hello";
292
+
version = "0.1.0";
293
+
src = ./.;
294
+
295
+
npmDeps = importNpmLock {
296
+
npmRoot = ./.;
297
+
};
272
298
273
-
Note that `npmHooks.npmConfigHook` cannot be used with `importNpmLock`. You will instead need to use `importNpmLock.npmConfigHook`:
299
+
npmConfigHook = importNpmLock.npmConfigHook;
300
+
}
301
+
```
302
+
:::
303
+
304
+
:::{.example}
305
+
##### `pkgs.importNpmLock` usage example with `fetcherOpts` {#javascript-buildNpmPackage-example-fetcherOpts}
306
+
307
+
`importNpmLock` uses the following fetchers:
308
+
309
+
-`pkgs.fetchurl` for `http(s)` dependencies
310
+
-`builtins.fetchGit` for `git` dependencies
311
+
312
+
It is possible to provide additional arguments to individual fetchers as needed:
274
313
275
314
```nix
276
315
{ buildNpmPackage, importNpmLock }:
277
316
278
317
buildNpmPackage {
279
318
pname = "hello";
280
319
version = "0.1.0";
320
+
src = ./.;
281
321
282
322
npmDeps = importNpmLock {
283
323
npmRoot = ./.;
324
+
fetcherOpts = {
325
+
# Pass 'curlOptsList' to 'pkgs.fetchurl' while fetching 'axios'
0 commit comments