CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-yarn

Fast, reliable, and secure dependency management tool for JavaScript/Node.js projects

Overview
Eval results
Files

project-management.mddocs/

Project Management

Commands for project initialization, script execution, and development workflow management.

Capabilities

Initialize Project

Create a new package.json file and initialize a new Node.js project.

yarn init [options]

-y, --yes               # Accept all defaults without prompting
--private               # Mark package as private (not publishable)

Usage Examples:

# Interactive initialization
yarn init

# Accept all defaults
yarn init -y

# Create private package
yarn init --private

# Create private package with defaults
yarn init -y --private

The init command prompts for:

  • Package name
  • Version (default: 1.0.0)
  • Description
  • Entry point (default: index.js)
  • Repository URL
  • Author
  • License (default: MIT)
  • Private status

Create Project from Template

Create a new project using a template package (create-* packages).

yarn create <starter-kit-package> [args]

Usage Examples:

# Create React app
yarn create react-app my-app

# Create Next.js app
yarn create next-app my-next-app

# Create Vue app
yarn create vue my-vue-app

# Create with additional arguments
yarn create react-app my-app --template typescript

# Equivalent to running:
# yarn global add create-react-app
# create-react-app my-app

Run Scripts

Execute scripts defined in package.json or run package binaries.

yarn run <script-name> [args]
yarn <script-name> [args]    # Shorthand for common scripts

# Built-in script shortcuts:
yarn start                   # Runs "start" script
yarn test                    # Runs "test" script  
yarn build                   # Runs "build" script

Usage Examples:

# Run custom script
yarn run dev
yarn run build:production

# Run with arguments
yarn run test -- --watch
yarn run build -- --mode production

# Shorthand for common scripts
yarn start
yarn test
yarn build

# List available scripts
yarn run

# Run script in specific workspace
yarn workspace my-package run build

Script Context:

Scripts run with:

  • node_modules/.bin in PATH
  • Access to all installed package binaries
  • Environment variables from .env files
  • Current working directory as project root

Execute Binaries

Execute package binaries directly without running them through npm scripts.

yarn exec <command> [args]

Usage Examples:

# Execute binary from node_modules/.bin
yarn exec eslint src/

# Execute with arguments
yarn exec webpack --mode production

# Execute binary that might not be in PATH
yarn exec @babel/cli --version

# Equivalent to npx
yarn exec create-react-app my-app

Run Node.js

Run Node.js with access to node_modules and yarn's environment.

yarn node [args]

Usage Examples:

# Run Node.js REPL
yarn node

# Execute JavaScript file
yarn node script.js

# Run with Node.js flags
yarn node --inspect script.js
yarn node --experimental-modules index.mjs

# Access to local modules
yarn node -e "console.log(require('lodash').version)"

Script Execution Context

When running scripts, yarn provides:

Environment Variables

# Package information
npm_package_name           # Package name from package.json
npm_package_version        # Package version
npm_package_description    # Package description

# Script context
npm_lifecycle_event        # Current script name being run
npm_lifecycle_script       # Current script command

# Paths
npm_config_cache          # Yarn cache directory
npm_config_prefix         # Global install directory
INIT_CWD                  # Original working directory

Script Hooks

Yarn supports lifecycle scripts that run automatically:

{
  "scripts": {
    "preinstall": "echo 'Before install'",
    "postinstall": "echo 'After install'",
    "prestart": "echo 'Before start'",
    "start": "node server.js",
    "poststart": "echo 'After start'",
    "pretest": "echo 'Before test'",
    "test": "jest",
    "posttest": "echo 'After test'"
  }
}

Lifecycle Order:

  1. preinstallinstallpostinstall
  2. prestartstartpoststart
  3. pretesttestposttest
  4. And so on for other scripts

Binary Access

Scripts automatically have access to:

  • All binaries from installed packages in node_modules/.bin
  • Global yarn binaries
  • System PATH binaries
{
  "scripts": {
    "lint": "eslint src/",           // Uses locally installed eslint
    "format": "prettier --write .", // Uses locally installed prettier
    "build": "webpack --mode prod"   // Uses locally installed webpack
  }
}

Script Best Practices

Cross-platform Commands

{
  "scripts": {
    "clean": "rimraf dist/",              // Cross-platform rm -rf
    "copy": "cpx 'src/**/*.json' dist/",  // Cross-platform cp
    "env": "cross-env NODE_ENV=prod node server.js"
  }
}

Chaining Commands

{
  "scripts": {
    "build": "yarn clean && yarn compile && yarn minify",
    "test:all": "yarn test:unit && yarn test:integration",
    "deploy": "yarn build && yarn test && yarn publish"
  }
}

Parallel Execution

{
  "scripts": {
    "dev": "concurrently 'yarn server' 'yarn client'",
    "test:parallel": "npm-run-all test:unit test:integration",
    "watch": "npm-run-all --parallel watch:*"
  }
}

Project Structure Integration

Yarn works seamlessly with common project structures:

Monorepo/Workspace Projects

# Run script in all workspaces
yarn workspaces run build

# Run script in specific workspace
yarn workspace @company/package-a run test

TypeScript Projects

# TypeScript compilation
yarn exec tsc
yarn run build  # if build script uses tsc

# Type checking
yarn exec tsc --noEmit

Modern JavaScript Projects

# ES modules with experimental flag
yarn node --experimental-modules index.mjs

# Module resolution
yarn node --es-module-specifier-resolution=node index.js

Install with Tessl CLI

npx tessl i tessl/npm-yarn

docs

cache-management.md

configuration.md

index.md

information-commands.md

package-management.md

project-management.md

registry-operations.md

utility-commands.md

workspace-management.md

tile.json