### Unix Path Setup Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/_installations/gentoo.md This snippet is a placeholder for Unix path setup instructions, typically used when direct package installation is not available or for specific build types. ```sh #!/bin/sh # Add Yarn to your PATH export PATH=$(yarn global bin):$PATH ``` -------------------------------- ### Example .gitlab-ci.yml for Testing with Yarn Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/_ci/gitlab.md A complete example of a `.gitlab-ci.yml` file that uses Yarn to install dependencies and run tests, including caching `node_modules` and `.yarn`. ```yml # .gitlab-ci.yml image: node:9.11.1 before_script: - yarn install --cache-folder .yarn test: stage: test cache: paths: - node_modules/ - .yarn ``` -------------------------------- ### Install package by tag Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/cli/tag.md Use tags to install specific versions of a package. For example, 'stable' or 'canary' can be used instead of a version number. ```sh yarn add your-package-name@stable yarn add your-package-name@canary ``` -------------------------------- ### Install All Project Dependencies Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/installing-dependencies.md Use `yarn` or `yarn install` to install all dependencies listed in your project's `package.json` file. This is the most common command for setting up a project. ```bash yarn install ``` ```bash yarn ``` -------------------------------- ### Define a Workspace Package (workspace-a) Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/workspaces.md Example package.json for a workspace. Dependencies are installed at the root level and linked via symlinks. ```json { "name": "workspace-a", "version": "1.0.0", "dependencies": { "cross-env": "5.0.5" } } ``` -------------------------------- ### Install All Project Dependencies Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/usage.md Install all dependencies listed in your package.json file. ```shell yarn ``` ```shell yarn install ``` -------------------------------- ### Install Yarn via Tarball on Solus Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/_installations/solus.md For RC or nightly builds not available in the Solus repository, download and extract the tarball. Follow the instructions in the included tarball installation guide for path setup. ```sh # Instructions for tarball installation will be included here. # Please refer to the tarball.md for details. ``` -------------------------------- ### Query Package Installation Reason Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/cli/why.md Use `yarn why` with a package name to see why it was installed. This command details dependencies and installation reasons. ```bash yarn why jest ``` ```text yarn why vx.x.x [1/4] 🤔 Why do we have the module "jest"...? [2/4] 🚚 Initializing dependency graph... [3/4] 🔍 Finding dependency... [4/4] 🚡 Calculating file sizes... info Has been hoisted to "jest" info This module exists because it's specified in "devDependencies". info Disk size without dependencies: "1.29kB" info Disk size with unique dependencies: "101.31kB" info Disk size with transitive dependencies: "20.35MB" info Amount of shared dependencies: 125 ``` -------------------------------- ### Install a package by tag Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/cli/add.md Installs a package based on a specific tag, such as 'beta' or 'next'. ```bash yarn add package-name@tag ``` -------------------------------- ### Directories Field in package.json Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/package-json.md Defines specific locations for installing binary files, man pages, documentation, and examples. ```json { "directories": { "lib": "path/to/lib/", "bin": "path/to/bin/", "man": "path/to/man/", "doc": "path/to/doc/", "example": "path/to/example/" } } ``` -------------------------------- ### Configure Yarn Repository and Install Version on Semaphore Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/_ci/semaphore.md Add these commands to your Semaphore CI setup to ensure the correct Yarn version is installed and cached. This involves adding the Yarn GPG key, the Yarn repository to apt sources, and then using `install-package` to manage the Yarn installation. ```bash curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - echo "deb http://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list # install-package is a tool for caching APT installations in Semaphore # defining a package version is optional install-package --update-new yarn= ``` -------------------------------- ### Get basic package info Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/cli/info.md Fetches and displays general information about a package in a tree format. The package does not need to be installed locally. ```bash yarn info react ``` -------------------------------- ### Install a Package Globally Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/cli/global.md Use this command to install a package globally. The `--prefix` flag specifies the installation directory. After installation, the package's executables become available system-wide. ```sh $ yarn global add nodemon --prefix /usr/local # the `nodemon` command is now available globally: $ which nodemon $ /usr/local/bin/nodemon $ nodemon ``` -------------------------------- ### Install Node.js via Scoop Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/_installations/windows.md If Node.js is not installed, Scoop can assist with its installation. ```sh scoop install nodejs ``` -------------------------------- ### Example package.json before version update Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/cli/version.md This is an example of a package.json file before running the `yarn version` command. ```json { "name": "example-yarn-package", "version": "1.0.1", "description": "An example package to demonstrate Yarn" } ``` -------------------------------- ### Example Package Information Object Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/publishing-a-package.md This is an example of the JSON object returned when querying package information. ```json { "name": "my-new-project", "description": "My New Project description.", "dist-tags": { "latest": "1.0.0" }, "versions": [ "1.0.0" ], "maintainers": [ { "name": "Your Name", "email": "you@example.com" } ], "time": { "modified": "{{ site.time | date_to_xmlschema }}", "created": "{{ site.time | date_to_xmlschema }}", "1.0.0": "{{ site.time | date_to_xmlschema }}" }, "homepage": "https://my-new-project-website.com/", "keywords": [ "cool", "useful", "stuff" ], "repository": { "url": "https://example.com/your-username/my-new-project", "type": "git" }, "contributors": [ { "name": "Your Friend", "email": "their-email@example.com", "url": "http://their-website.com" }, { "name": "Another Friend", "email": "another-email@example.com", "url": "https://another-website.org" } ], "author": { "name": "Your Name", "email": "you@example.com" }, "bugs": { "url": "https://github.com/you/my-new-project/issues" }, "license": "MIT", "readmeFilename": "README.md", "version": "1.0.0", "main": "index.js", "files": [ "index.js", "lib/*.js", "bin/*.js" ], "bin": { "my-new-project-cli": "bin/my-new-project-cli.js" }, "dist": { "shasum": "908bc9a06fa4421e96ceda243c1ee1789b0dc763", "tarball": "https://registry.npmjs.org/my-new-project/-/my-new-project-1.0.0.tgz" }, "directories": {} } ``` -------------------------------- ### Install Yarn via Scoop Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/_installations/windows.md Use this command to install Yarn using the Scoop command-line installer. Scoop may suggest installing Node.js if it's not present. ```sh scoop install yarn ``` -------------------------------- ### Example package.json File Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/creating-a-project.md This is an example of a package.json file generated after running `yarn init`. It stores project metadata and dependencies. ```json { "name": "my-new-project", "version": "1.0.0", "description": "My New Project description.", "main": "index.js", "repository": { "url": "https://example.com/your-username/my-new-project", "type": "git" }, "author": "Your Name ", "license": "MIT" } ``` -------------------------------- ### Create Next App with Yarn Source: https://github.com/yarnpkg/website/blob/master/_posts/2017-05-12-introducing-yarn.md Start a new Next.js project with `yarn create`. This command ensures the `create-next-app` package is installed and executed. ```bash yarn create next-app my-app ``` -------------------------------- ### Example package.json after version update Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/cli/version.md This is an example of a package.json file after successfully running the `yarn version` command and updating to a new version. ```json { "name": "example-yarn-package", "version": "1.0.2", "description": "An example package to demonstrate Yarn" } ``` -------------------------------- ### Example package.json Dependencies Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/dependency-versions.md Illustrates how dependencies with different version ranges are declared in a package.json file. ```json { "dependencies": { "package-1": ">=2.0.0 <3.1.4", "package-2": "^0.4.2", "package-3": "~2.7.1" } } ``` -------------------------------- ### Install Yarn on Solus using eopkg Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/_installations/solus.md Use this command to install the stable version of Yarn from the Solus repository. ```sh sudo eopkg install yarn ``` -------------------------------- ### Install Yarn Package Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/_installations/debian.md After configuring the repository, update your package list and install the Yarn package using APT. ```bash sudo apt update && sudo apt install yarn ``` -------------------------------- ### Install Yarn on openSUSE Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/_installations/opensuse.md Add the Yarn RPM repository and install the yarn package. This is the recommended method for installing stable versions of Yarn on openSUSE. ```bash sudo rpm --import https://dl.yarnpkg.com/rpm/pubkey.gpg ``` ```bash sudo zypper ar -f https://dl.yarnpkg.com/rpm/ Yarn ``` ```bash sudo zypper in yarn ``` -------------------------------- ### Install Yarn with Homebrew Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/_installations/mac.md Use this command to install Yarn via the Homebrew package manager. This will also install Node.js if it's not already present. ```shell brew install yarn ``` -------------------------------- ### Install a package from a Git repository Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/cli/add.md Installs a package directly from a remote Git repository URL. ```bash yarn add ``` -------------------------------- ### Execute Package Install Scripts in Node.js Source: https://github.com/yarnpkg/website/blob/master/_posts/2017-07-11-lets-dev-a-package-manager.md Adds support for executing package installation scripts (preinstall, install, postinstall). It uses Node.js child_process to run these scripts in the package's directory. ```javascript import cp from 'child_process'; import util from 'util'; const exec = util.promisify(cp.exec); async function linkPackages({ name, reference, dependencies }, cwd) { // ... same code as before except the end: await Promise.all( dependencies.map(async ({ name, reference, dependencies }) => { // ... same code as before if (dependencyPackageJson.scripts) { for (let scriptName of [`preinstall`, `install`, `postinstall`]) { let script = dependencyPackageJson.scripts[scriptName]; if (!script) continue; await exec(script, { cwd: target, env: Object.assign({}, process.env, { PATH: `${target}/node_modules/.bin:${process.env.PATH}`, }), }); } } }) ); } ``` -------------------------------- ### Install as peer dependencies Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/cli/add.md Installs packages into the `peerDependencies` section of your `package.json`. Use the `--peer` or `-P` flag. ```bash yarn add [--peer/-P] ``` -------------------------------- ### Install Yarn Nightly via Shell Script Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/_installations/nightly.md Use this command to download and execute the installation script for nightly builds. ```sh curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --nightly ``` -------------------------------- ### Install a local package from a folder Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/cli/add.md Installs a package directly from a folder on your local file system. This is useful for testing unpublished packages. ```bash yarn add file:/path/to/local/folder ``` -------------------------------- ### Install as dev dependencies Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/cli/add.md Installs packages into the `devDependencies` section of your `package.json`. Use the `--dev` or `-D` flag. ```bash yarn add [--dev/-D] ``` -------------------------------- ### Install as optional dependencies Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/cli/add.md Installs packages into the `optionalDependencies` section of your `package.json`. Use the `--optional` or `-O` flag. ```bash yarn add [--optional/-O] ``` -------------------------------- ### Install Yarn using yum or dnf Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/_installations/centos.md Install Yarn after configuring the necessary repositories. Use 'yum' for older systems or 'dnf' for newer ones. ```bash sudo yum install yarn ``` ```bash sudo dnf install yarn ``` -------------------------------- ### Install a package from a remote tarball URL Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/cli/add.md Installs a package from a gzipped tarball hosted at a remote URL. ```bash yarn add https://my-project.org/package.tgz ``` -------------------------------- ### Install a specific version of a package Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/cli/add.md Installs a specific version of a package from the registry using its version number. ```bash yarn add package-name@1.2.3 ``` -------------------------------- ### Focused Yarn Workspaces Installation Source: https://github.com/yarnpkg/website/blob/master/_posts/2018-05-18-focused-workspaces.md Demonstrates the `node_modules` structure after running `yarn install --focus` within a specific workspace (e.g., `packages/A`). Dependencies like `B` are installed directly from the registry, avoiding the need to build un-changed sibling packages. ```bash my_project/ package.json node_modules/ A/ (symlink to packages/A) B/ (symlink to packages/B) External/ packages/ A/ node_modules/ B/ (not a symlink. Pulled from registry. No need to build.) B/ node_modules/ (empty) ``` -------------------------------- ### Example Output of Yarn Info Command Source: https://github.com/yarnpkg/website/blob/master/_posts/2017-06-19-adding-command-line-aliases-for-yarn.md This is an example of the output you can expect when running the aliased Yarn command, showing package distribution tags. ```text yarn info v0.24.6 verbose 0.261 Checking for configuration file "/Users/gsklee/.npmrc". verbose 0.262 Checking for configuration file "/Users/gsklee/.npmrc". verbose 0.262 Checking for configuration file "/Users/gsklee/.nvm/versions/node/v8.1.2/.npmrc". verbose 0.263 Checking for configuration file "/Users/gsklee/.npmrc". verbose 0.263 Checking for configuration file "/Users/.npmrc". verbose 0.265 Checking for configuration file "/Users/gsklee/.yarnrc". verbose 0.265 Found configuration file "/Users/gsklee/.yarnrc". verbose 0.267 Checking for configuration file "/Users/gsklee/.yarnrc". verbose 0.267 Found configuration file "/Users/gsklee/.yarnrc". verbose 0.268 Checking for configuration file "/Users/gsklee/.nvm/versions/node/v8.1.2/.yarnrc". verbose 0.268 Checking for configuration file "/Users/gsklee/.yarnrc". verbose 0.268 Found configuration file "/Users/gsklee/.yarnrc". verbose 0.27 Checking for configuration file "/Users/.yarnrc". verbose 0.274 current time: 2017-06-16T09:43:50.256Z verbose 0.339 Performing "GET" request to "https://registry.yarnpkg.com/react". verbose 0.488 Request "https://registry.yarnpkg.com/react" finished with status code 200. { latest: '15.6.1', '0.10.0-rc1': '0.10.0-rc1', '0.11.0-rc1': '0.11.0-rc1', next: '16.0.0-alpha.13', dev: '15.5.0-rc.2', '0.14-stable': '0.14.9', '15-next': '15.6.0-rc.1' } Done in 0.28s. ``` -------------------------------- ### Install Yarn with npm Source: https://github.com/yarnpkg/website/blob/master/_layouts/pages/install.html Use npm to install Yarn globally. This is a common method for Node.js users. ```bash npm install --global yarn ``` -------------------------------- ### Package JSON Configuration Example Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/configuration.md This is an example of a `package.json` file used by Yarn to configure package behavior. It includes package name, version, main entry point, and dependencies. ```json { "name": "pet-kitten", "version": "0.1.0", "main": "pet.js", "dependencies": { "hand": "1.0.0" } } ``` -------------------------------- ### Install with Flat Dependencies Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/cli/install.md Installs dependencies, allowing only one version per package. Prompts to choose versions for conflicting dependencies, which are then added to the `resolutions` field in `package.json`. ```bash yarn install --flat ``` ```json "resolutions": { "package-a": "2.0.0", "package-b": "5.0.0", "package-c": "1.5.2" } ``` -------------------------------- ### Install Bundler Source: https://github.com/yarnpkg/website/blob/master/README.md Install the Bundler dependency manager, which is required for managing Ruby gems for the website. ```sh $ gem install bundler ``` -------------------------------- ### Using `yarn create` for Starter Kits Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/cli/create.md This command installs a starter kit package globally and then runs its executable, passing along any arguments. Use this to quickly scaffold new projects from predefined templates. ```bash $ yarn global add create-react-app $ create-react-app my-app ``` -------------------------------- ### Install Dependencies with Yarn Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/migrating-from-npm.md Run this command in your existing npm project to install dependencies using Yarn's resolution algorithm. ```shell yarn ``` -------------------------------- ### Install Yarn in Travis CI Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/_ci/travis.md Use this configuration in your `.travis.yml` file to manually install a specific version of Yarn before the build process. This is useful if you need Yarn before it's pre-installed on the build image or if you're overriding the default install command. ```yml before_install: # Repo for Yarn - sudo apt-key adv --fetch-keys http://dl.yarnpkg.com/debian/pubkey.gpg - echo "deb http://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list - sudo apt-get update -qq - sudo apt-get install -y -qq yarn cache: yarn: true ``` -------------------------------- ### Install a package from the npm registry Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/cli/add.md Installs the latest version of a package from the npm registry. This is the most common way to add dependencies. ```bash yarn add react ``` -------------------------------- ### Example: Unlinking 'react' from the 'react' package directory Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/cli/unlink.md This example demonstrates unlinking the 'react' package when you are inside the 'react' package's directory. ```bash $ cd react $ yarn unlink yarn link vx.x.x success Unregistered "react". ``` -------------------------------- ### Example package.json Structure Source: https://github.com/yarnpkg/website/blob/master/_posts/2017-07-11-lets-dev-a-package-manager.md Illustrates a typical package.json file, highlighting the 'dependencies' section with package names and version specifiers. ```json { "dependencies": { "react": "^15.5.4", "babel-core": "6.25.0" } } ``` -------------------------------- ### Install Packages with Offline Flag Source: https://github.com/yarnpkg/website/blob/master/_posts/2016-11-24-offline-mirror.md Installs project dependencies using only the local offline cache. This command is useful for testing the offline mirror setup or performing installations in environments without network access. ```bash yarn install --offline ``` -------------------------------- ### Example yarn.lock File Structure Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/yarn-lock.md This is an example of the structure of a yarn.lock file, which specifies exact versions and sources for all dependencies. ```yaml # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. yarn lockfile v1 package-1@^1.0.0: version "1.0.3" resolved "https://registry.npmjs.org/package-1/-/package-1-1.0.3.tgz#a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0" package-2@^2.0.0: version "2.0.1" resolved "https://registry.npmjs.org/package-2/-/package-2-2.0.1.tgz#a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0" dependencies: package-4 "^4.0.0" package-3@^3.0.0: version "3.1.9" resolved "https://registry.npmjs.org/package-3/-/package-3-3.1.9.tgz#a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0" dependencies: package-4 "^4.5.0" package-4@^4.0.0, package-4@^4.5.0: version "4.6.3" resolved "https://registry.npmjs.org/package-4/-/package-4-2.6.3.tgz#a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0" ``` -------------------------------- ### Install Yarn on Gentoo Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/_installations/gentoo.md Use this command to install the stable version of Yarn on Gentoo Linux via Portage. ```sh sudo emerge --ask sys-apps/yarn ``` -------------------------------- ### Example Package JSON for Dependency Tree Generation Source: https://github.com/yarnpkg/website/blob/master/_posts/2017-07-11-lets-dev-a-package-manager.md This is an example package.json file used to test the dependency tree generation. It includes a single dependency 'tar-stream' with a wildcard version. ```json { "name": "my-awesome-package", "dependencies": { "tar-stream": "*" } } ``` -------------------------------- ### Regular Install Structure Source: https://github.com/yarnpkg/website/blob/master/_posts/2018-05-18-focused-workspaces.md Illustrates the node_modules structure after a regular Yarn install when workspaces have conflicting dependencies on an external package. ```text | my_project/ | package.json | node_modules/ | A/ (symlink to packages/A) | B/ (symlink to packages/B) | External/ (v2) | packages/ | A/ | node_modules/ | External (v1) | B/ | node_modules/ (empty) ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/cli/install.md Installs all dependencies listed in `package.json`. If `yarn.lock` exists and is sufficient, it uses exact versions from the lockfile. Otherwise, it finds the newest versions satisfying `package.json` constraints and updates `yarn.lock`. ```bash yarn install ``` -------------------------------- ### Example package.json with version lifecycle scripts Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/cli/version.md This package.json includes `preversion` and `postversion` scripts. The `preversion` script runs tests, and the `postversion` script handles pushing tags, publishing, and pushing to the remote repository. ```json { "name": "example-yarn-package", "version": "1.0.2", "description": "An example package to demonstrate Yarn", "scripts": { "test": "echo \"Running tests for version $npm_package_version...\"", "preversion": "yarn test", "postversion": "git push --tags && yarn publish . --tag $npm_package_version && git push && echo \"Successfully released version $npm_package_version!\"" } } ``` -------------------------------- ### Install a local package from a tarball Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/cli/add.md Installs a package from a gzipped tarball file on your local system. This can be used to share packages before publishing. ```bash yarn add file:/path/to/local/tarball.tgz ``` -------------------------------- ### Example: Unlinking 'react' from the 'react-relay' project directory Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/cli/unlink.md This example shows how to unlink a specific package ('react') from a project ('react-relay') where it was previously linked. ```bash $ cd ../react-relay $ yarn unlink react yarn link vx.x.x success Unregistered "react". ``` -------------------------------- ### Install Yarn with Shell Script Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/_installations/tarball.md Installs Yarn using a shell script. Use the --rc flag for release candidates or --nightly for the latest nightly build. ```bash curl -o- -L https://yarnpkg.com/install.sh | bash ``` ```bash curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --rc ``` ```bash curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --nightly ``` ```bash curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version [version] ``` -------------------------------- ### Install Package Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/package-json.md Command to add a package to your project using Yarn. ```sh yarn add [name] ``` -------------------------------- ### Configure files to clean in .yarnclean Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/cli/autoclean.md Example of a `.yarnclean` file configuration. This example specifies that all YAML and Markdown files within `node_modules` should be deleted. After creating or modifying this file, run `yarn install` or `yarn autoclean --force` to apply the changes. ```glob *.yaml *.md ``` -------------------------------- ### Re-initialize Lockfile and Install Dependencies Source: https://github.com/yarnpkg/website/blob/master/_posts/2016-11-24-offline-mirror.md Removes existing node_modules and yarn.lock, then runs `yarn install` to generate a new lockfile and populate the offline mirror. This ensures the project uses the configured offline mirror. ```bash $ rm -rf node_modules/ yarn.lock $ yarn install yarn install v0.17.8 [1/4] 🔍 Resolving packages... [2/4] 🚚 Fetching packages... [3/4] 🔗 Linking dependencies... [4/4] 📃 Building fresh packages... success Saved lockfile. ✨ Done in 0.57s. ``` -------------------------------- ### Install a local package using a symlink Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/cli/add.md Installs a package by creating a symbolic link to a local folder. This is particularly useful in monorepo environments for developing related packages. ```bash yarn add link:/path/to/local/folder ``` -------------------------------- ### Unix Path Setup for Yarn Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/_installations/arch.md Follow these instructions to add Yarn to your system's PATH if you installed it manually or if it's not automatically recognized. ```sh #!/bin/sh # Add Yarn to PATH export PATH=$(yarn global bin):$PATH ``` -------------------------------- ### Build and Serve Yarn Website (Windows) Source: https://github.com/yarnpkg/website/blob/master/README.md Commands to install dependencies and serve the Yarn website locally on Windows using Bundler and Jekyll. ```sh bundle install bundle exec jekyll serve --incremental ``` -------------------------------- ### Focused Workspace Installation Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/cli/install.md Shallowly installs sibling workspace dependencies into the current workspace's `node_modules`. This allows running a workspace without building its dependencies. Must be run within an individual workspace, not at the root. ```bash yarn install --frozen-lockfile ``` ```bash yarn install --focus ``` -------------------------------- ### Display specific executable path Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/cli/bin.md Use `yarn bin ` to get the full path to a specific executable file installed by Yarn. This is helpful for directly referencing or executing scripts. ```bash $ yarn bin gettext-compile /home/emillumine/Code/Funkwhale/funkwhale/front/node_modules/.bin/gettext-compile ``` -------------------------------- ### Package Directory Structure Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/package-json.md Illustrates the typical directory structure for installed packages within node_modules. ```text node_modules/[name] ``` -------------------------------- ### Add Global Bin Directory to PATH Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/cli/global.md To make globally installed executables accessible from your shell, add the Yarn global bin directory to your system's PATH environment variable. This example shows how to do it for bash. ```sh export PATH="$(yarn global bin):$PATH" ``` -------------------------------- ### Initialize Yarn project with defaults Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/creating-a-package.md Use the `--yes` flag with `yarn init` to automatically accept all default values and skip the interactive prompts. ```sh yarn init --yes ``` -------------------------------- ### Set Up Yarn Nightly Debian/Ubuntu Repository Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/_installations/nightly.md Add the nightly build repository to your system and install Yarn. This involves adding a GPG key, configuring the sources list, and updating your package index. ```sh sudo apt-key adv --fetch-keys http://dl.yarnpkg.com/debian/pubkey.gpg echo "deb http://nightly.yarnpkg.com/debian/ nightly main" | sudo tee /etc/apt/sources.list.d/yarn-nightly.list sudo apt update && sudo apt install yarn ``` -------------------------------- ### Example Bash Test Script Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/cli/test.md A simple bash script that can be executed as a test script. ```bash #!/bin/bash echo "Hello, world!" ``` -------------------------------- ### Create React App with Yarn Source: https://github.com/yarnpkg/website/blob/master/_posts/2017-05-12-introducing-yarn.md Use `yarn create` to initialize a new React application. This command installs the `create-react-app` package and runs its executable. ```bash yarn create react-app my-app ``` -------------------------------- ### Install Only Production Dependencies Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/installing-dependencies.md Use the `--production` flag with `yarn install` to install only the dependencies required for production, excluding development dependencies. ```bash yarn install --production ``` -------------------------------- ### Install Yarn via Chocolatey Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/_installations/windows.md Use this command to install Yarn using the Chocolatey package manager. This also ensures Node.js is installed. ```sh choco install yarn ``` -------------------------------- ### Yarn Login with Credentials Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/cli/login.md An example of the `yarn login` command in action, showing prompts for username and email, and the successful completion message. ```bash yarn login vx.x.x question npm username: my-username question npm email: my-username@example.com ✨ Done in 6.03s. ``` -------------------------------- ### Install Yarn with MacPorts Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/_installations/mac.md Use this command to install Yarn via the MacPorts package manager. This will also install Node.js if it's not already present. ```shell sudo port install yarn ``` -------------------------------- ### Interactive `yarn init` Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/cli/init.md Run `yarn init` to start an interactive session for creating a `package.json`. This is useful for new projects or when you want to manually define all package details. ```sh $ yarn init ``` ```sh question name (testdir): my-awesome-package question version (1.0.0): question description: The best package you will ever find. question entry point (index.js): question git repository: https://github.com/yarnpkg/example-yarn-package question author: Yarn Contributor question license (MIT): question private: success Saved package.json ✨ Done in 87.70s. ``` -------------------------------- ### List available package versions Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/cli/info.md Fetches and displays a list of all available versions for a given package. ```bash yarn info react versions ``` -------------------------------- ### Interactive Yarn project initialization prompts Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/creating-a-package.md When you run `yarn init`, you will be prompted to provide details for your package. You can type answers or press Enter to accept defaults. ```sh name (my-new-project): version (1.0.0): description: entry point (index.js): git repository: author: license (MIT): ``` -------------------------------- ### Install or Upgrade Yarn via npm Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/_installations/npm.md Use this command to install Yarn globally or to upgrade an existing installation to the latest version available via npm. ```bash npm install --global yarn@1 ``` -------------------------------- ### Install Only One Version of a Package Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/installing-dependencies.md Use the `--flat` flag with `yarn install` to ensure that only one version of each package is installed, preventing potential conflicts. ```bash yarn install --flat ``` -------------------------------- ### Enable Focused Installs by Default Source: https://github.com/yarnpkg/website/blob/master/_posts/2018-05-18-focused-workspaces.md Configure Yarn to always perform a focused install when running 'yarn install' from a specific workspace by adding this setting to its .yarnrc file. ```ini --install.focus true ``` -------------------------------- ### Example package.json for Babel Core Source: https://github.com/yarnpkg/website/blob/master/_posts/2017-07-11-lets-dev-a-package-manager.md This JSON file specifies `babel-core` as a dependency with a wildcard version, which can lead to issues if not handled properly. ```json { "dependencies": { "babel-core": "*" } } ``` -------------------------------- ### Check Installed Files Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/cli/install.md Verifies that files in `node_modules` have not been removed after installation. ```bash yarn install --check-files ``` -------------------------------- ### Non-interactive `yarn init --yes` Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/cli/init.md Use `yarn init --yes` to skip the interactive prompts and generate a `package.json` using default configurations. This is useful for automated setups or when you're confident with the default settings. ```sh $ yarn init --yes ``` ```sh warning The yes flag has been set. This will automatically answer yes to all questions which may have security implications. success Saved package.json ✨ Done in 0.09s. ``` -------------------------------- ### Build and Serve Yarn Website (Unix/macOS) Source: https://github.com/yarnpkg/website/blob/master/README.md Commands to build and serve the Yarn website locally on Unix-like systems using Make. ```sh $ make ``` ```sh $ make install $ make serve ``` -------------------------------- ### Initialize a New Yarn Project Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/creating-a-project.md Run this command in your project's root directory to start a new Yarn project. It will prompt you for project details. ```bash yarn init ``` -------------------------------- ### Pure Lockfile Installation Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/cli/install.md Installs dependencies without generating or updating the `yarn.lock` file. ```bash yarn install --pure-lockfile ``` -------------------------------- ### Authenticode Sign Windows Installer Source: https://github.com/yarnpkg/website/blob/master/lang/en/org/release-process.md Sign the Windows MSI installer using osslsigncode. This involves specifying the timestamp server, installer details, and certificate information. The first command signs with SHA1, and the second with SHA2. ```sh osslsigncode sign -t http://timestamp.digicert.com -n "Yarn Installer" -i https://yarnpkg.com/ -pkcs12 yarn-20161122.pfx -readpass yarn-20161122.key -h sha1 -in yarn-0.xx.xx-unsigned.msi -out yarn-0.xx.xx.msi ``` ```sh osslsigncode sign -t http://timestamp.digicert.com -n "Yarn Installer" -i https://yarnpkg.com/ -pkcs12 yarn-20161122.pfx -readpass yarn-20161122.key -nest -h sha2 -in yarn-0.xx.xx.msi -out yarn-0.xx.xx.msi ``` -------------------------------- ### Main Entry Point in package.json Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/package-json.md Specifies the primary entry point file for the package's functionality. ```json { "main": "filename.js" } ``` -------------------------------- ### Disable Self-Update Check Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/yarnrc.md Disable the check for outdated Yarn CLI installations during package installation. ```shell disable-self-update-check true ``` -------------------------------- ### Production Installation Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/cli/install.md Installs only `dependencies` (ignoring `devDependencies`). This flag overrides the `NODE_ENV` environment variable. ```bash yarn install --production[=true|false] ``` ```bash yarn install --prod ``` -------------------------------- ### Root package.json with Workspaces Source: https://github.com/yarnpkg/website/blob/master/_posts/2017-07-26-introducing-workspaces.md Example of a root package.json file that enables Workspaces by specifying the packages directory. It also defines development dependencies. ```json { "private": true, "name": "jest", "devDependencies": { "chalk": "^2.0.1" }, "workspaces": [ "packages/*" ] } ``` -------------------------------- ### Manual Install Stable Tarball Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/_installations/tarball.md Installs the stable version of Yarn by downloading and extracting a tarball to the /opt directory. ```bash cd /opt wget https://yarnpkg.com/latest.tar.gz tar zvxf latest.tar.gz # Yarn is now in /opt/yarn-[version]/ ``` -------------------------------- ### Run Yarn Login Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/cli/login.md Execute the `yarn login` command to initiate the process of storing your registry credentials. ```bash yarn login ``` -------------------------------- ### Install Yarn on Alpine Linux Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/_installations/alpine.md Use this command to install the stable version of Yarn on Alpine Linux (3.6+). ```sh apk add yarn ``` -------------------------------- ### Yarn Add Command Equivalents Source: https://github.com/yarnpkg/website/blob/master/lang/en/docs/migrating-from-npm.md Compares Yarn's `add` command options with their npm counterparts for installing packages. ```bash yarn add [package] ``` ```bash yarn add --flat [package] ``` ```bash yarn add --har [package] ``` ```bash yarn add --no-lockfile [package] ``` ```bash yarn add --pure-lockfile [package] ``` ```bash yarn add [package] --dev ``` ```bash yarn add [package] --peer ``` ```bash yarn add [package] --optional ``` ```bash yarn add [package] --exact ``` ```bash yarn add [package] --tilde ```