Run named project tasks and understand reproducible dependency installation.

Before starting: Node.js, JSON and a terminal.

Practice project: Extend the examples into a small Yarn study demo. Explain the setup, one normal case and one failure or boundary case.

Start here: concepts and guided practice

  1. Yarn: name a repeatable command

    A package.json script gives a project command a memorable name. This example needs Node but no external package. The package manager runs the command; it is not a programming language.

    Node.js and Yarn installed; use a new project directory.

    {
      "name": "study-demo",
      "private": true,
      "scripts": {"check": "node -e \"console.log(6 * 7)\""}
    }
    Check the output
    yarn run check prints 42, along with any package-manager status lines.

    Change the arithmetic expression and rerun check.

  2. Yarn: keep dependency versions reproducible

    A manifest records dependency choices and a lock file records resolved versions. Commit the appropriate lock file for an application. Use the project’s chosen package manager rather than mixing lock files.

    Node.js and Yarn installed; use a new project directory.

    yarn install --immutable
    Check the output
    Requires a valid, matching lock file; fails rather than silently updating it when changes are needed. Yarn example targets modern Yarn, not Yarn Classic.

    Explain why deleting the lock file changes what a reproducible install can guarantee.

Open the Yarn learning path on DevStudyHub · Play coding games on this blog

logoblog

No comments:

Post a Comment

Please do not enter any spam link in the comment box.