Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)

doc/javascript: document yarn{Config,Build}Hook

+67 -2
+66
doc/languages-frameworks/javascript.section.md
··· 375 375 pnpmRoot = "frontend"; 376 376 ``` 377 377 378 + ### Yarn {#javascript-yarn} 379 + 380 + Yarn based projects use a `yarn.lock` file instead of a `package-lock.json` to pin dependencies. Nixpkgs provides the Nix function `fetchYarnDeps` which fetches an offline cache suitable for running `yarn install` before building the project. In addition, Nixpkgs provides the hooks: 381 + 382 + - `yarnConfigHook`: Fetches the dependencies from the offline cache and installs them into `node_modules`. 383 + - `yarnBuildHook`: Runs `yarn build` or a specified `yarn` command that builds the project. 384 + 385 + An example usage of the above attributes is: 386 + 387 + ```nix 388 + { 389 + lib, 390 + stdenv, 391 + fetchFromGitHub, 392 + fetchYarnDeps, 393 + yarnConfigHook, 394 + yarnBuildHook, 395 + nodejs, 396 + npmHooks, 397 + }: 398 + 399 + stdenv.mkDerivation (finalAttrs: { 400 + pname = "..."; 401 + version = "..."; 402 + 403 + src = fetchFromGitHub { 404 + owner = "..."; 405 + repo = "..."; 406 + rev = "v${finalAttrs.version}"; 407 + hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="; 408 + }; 409 + 410 + yarnOfflineCache = fetchYarnDeps { 411 + yarnLock = finalAttrs.src + "/yarn.lock"; 412 + hash = "sha256-mo8urQaWIHu33+r0Y7mL9mJ/aSe/5CihuIetTeDHEUQ="; 413 + }; 414 + 415 + nativeBuildInputs = [ 416 + yarnConfigHook 417 + yarnBuildHook 418 + # Needed for executing package.json scripts 419 + nodejs 420 + npmHooks.npmInstallHook 421 + ]; 422 + 423 + meta = { 424 + # ... 425 + }; 426 + }) 427 + ``` 428 + 429 + Note that there is no setup hook for installing yarn based packages - `npmHooks.npmInstallHook` should fit most cases, but sometimes you may need to override the `installPhase` completely. 430 + 431 + #### `yarnConfigHook` arguments {#javascript-yarnconfighook} 432 + 433 + By default, `yarnConfigHook` relies upon the attribute `${yarnOfflineCache}` (or `${offlineCache}` if the former is not set) to find the location of the offline cache produced by `fetchYarnDeps`. To disable this phase, you can set `dontYarnInstallDeps = true` or override the `configurePhase`. 434 + 435 + #### `yarnBuildHook` arguments {#javascript-yarnbuildhook} 436 + 437 + This script by default runs `yarn --offline build`, and it relies upon the project's dependencies installed at `node_modules`. Below is a list of additional `mkDerivation` arguments read by this hook: 438 + 439 + - `yarnBuildScript`: Sets a different `yarn --offline` subcommand (defaults to `build`). 440 + - `yarnBuildFlags`: Single string list of additional flags to pass the above command, or a Nix list of such additional flags. 441 + 378 442 ### yarn2nix {#javascript-yarn2nix} 443 + 444 + WARNING: The `yarn2nix` functions have been deprecated in favor of the new `yarnConfigHook` and `yarnBuildHook`. Documentation for them still appears here for the sake of the packages that still use them. See also a tracking issue [#324246](https://github.com/NixOS/nixpkgs/issues/324246). 379 445 380 446 #### Preparation {#javascript-yarn2nix-preparation} 381 447
+1 -2
pkgs/build-support/node/fetch-yarn-deps/yarn-build-hook.sh
··· 13 13 for Nodejs related tools. 14 14 fi 15 15 16 - yarn --offline "$yarnBuildScript" \ 17 - $yarnBuildFlags "${yarnBuildFlagsArray[@]}" 16 + yarn --offline "$yarnBuildScript" $yarnBuildFlags 18 17 19 18 echo "finished yarnBuildHook" 20 19 runHook postBuild