This document describes all available fields in tasks.json for defining npm learning tasks.
- Type:
string - Description: Brief description of what the user should accomplish in this task
- Example:
"Install the lodash package into your project." - Usage: Displayed to the user as the task prompt
- Type:
string - Description: The exact npm command the user should enter to complete the task
- Example:
"npm install lodash" - Usage: Used to validate user input and provide hints
- Type:
string - Description: Detailed explanation of what the command does and why it's useful
- Example:
"Installs the lodash package and adds it to your dependencies in package.json." - Usage: Displayed when user types
explaincommand
- Type:
string - Description: Shell command to verify the task was completed successfully (Unix/Linux/Mac)
- Example:
"test -f package.json" - Usage: Runs after the main command to confirm it worked
- Platform: Unix-based systems (Mac, Linux)
- Type:
string - Description: Shell command to verify the task was completed successfully (Windows)
- Example:
"if exist package.json (exit 0) else (exit 1)" - Usage: Alternative to
checkCommandfor Windows systems - Platform: Windows only
- Type:
string - Description: Shell command to verify prerequisites before running the main command
- Example:
"test -f package-lock.json" - Usage: Runs before the main command; task is skipped if it fails
- Note: Useful for tasks that depend on previous task results
- Type:
string - Description: String that must appear in the command's stdout/stderr output
- Example:
"added" - Usage: Validates that the command produced expected output
- Note: Case-sensitive substring match
- Type:
string - Description: Shell command to run before the main command (setup)
- Example:
"rm -rf node_modules" - Usage: Prepares the environment for the task
- Execution: Runs before
preCheckCommandandexpectedCommand
- Type:
boolean - Description: Whether
beforeCommandneeds sudo on Linux - Example:
true - Usage: Automatically prepends
sudotobeforeCommandon Linux - Platform: Linux only (ignored on Mac/Windows)
- Default:
false
- Type:
string - Description: Shell command to run after the main command (cleanup)
- Example:
"rm my-npm-project-*.tgz" - Usage: Cleans up side effects or temporary files
- Execution: Runs after
expectedCommandandcheckCommand
- Type:
boolean - Description: Whether the main command needs sudo on Linux
- Example:
true - Usage: Automatically prepends
sudotoexpectedCommandon Linux - Platform: Linux only (ignored on Mac/Windows)
- Default:
false - Common Use Cases: Global npm installs, linking packages
- Type:
boolean - Description: Requires exact match of the command (no partial matches)
- Example:
true - Usage: For commands with specific flags or arguments
- Default:
false(allows fuzzy matching)
- Type:
boolean - Description: Command is allowed to exit with non-zero status
- Example:
true - Usage: For commands that intentionally fail or return error codes
- Default:
false - Common Use Cases:
npm outdated,npm audit
- Type:
boolean - Description: Command opens a browser instead of producing terminal output
- Example:
true - Usage: Skips output validation for browser commands
- Default:
false - Common Use Cases:
npm docs,npm bugs,npm repo
- Type:
boolean - Description: Skip this task in automated test runs
- Example:
true - Usage: For tasks requiring user interaction or authentication
- Default:
false - Common Use Cases:
npm login,npm adduser,npm publish
- Type:
boolean - Description: Task requires interactive user input
- Example:
true - Usage: Displays warning in
gocommand; handled specially in tests - Default:
false - Note: Usually paired with
skipTest: true
- Type:
boolean - Description: Command is known to be broken in current npm version (all platforms)
- Example:
true - Usage: Task still shows in CLI (user can try it), but skipped in automated tests
- Default:
false - Common Use Cases: Deprecated or buggy npm commands (e.g.,
npm stars)
- Type:
boolean - Description: Command doesn't work on Windows but works on Linux/Mac
- Example:
true - Usage: Task shows normally in CLI on all platforms (user can try), but skipped in test suite on Windows only
- Default:
false - Common Use Cases: Unix-specific commands, Windows compatibility issues (e.g.,
npm edit) - Note: Paired with
nonZeroOkay: truesince command will fail on Windows
{
"description": "List installed packages.",
"expectedCommand": "npm ls",
"explanation": "Displays a tree of all installed packages."
}{
"description": "Install lodash package.",
"expectedCommand": "npm install lodash",
"checkCommand": "test -d node_modules/lodash",
"outputIncludes": "added",
"explanation": "Installs lodash and adds it to dependencies."
}{
"description": "Reinstall dependencies cleanly.",
"expectedCommand": "npm ci",
"beforeCommand": "rm -rf node_modules",
"preCheckCommand": "test -f package-lock.json",
"checkCommand": "test -d node_modules",
"afterCommand": "echo 'Cleanup complete'",
"explanation": "Clean install from lockfile."
}{
"description": "Link package globally.",
"expectedCommand": "npm link",
"requireSudo": true,
"checkCommand": "npm ls -g | grep -q 'my-package'",
"explanation": "Creates global symlink to your package."
}{
"description": "Diagnose npm environment.",
"expectedCommand": "npm doctor",
"beforeCommand": "npm install -g npm@11.6.1",
"beforeRequiresSudo": true,
"preCheckCommand": "npm -v | grep -q '^11\\.6\\.1$'",
"explanation": "Runs environment diagnostics."
}{
"description": "Initialize npm project.",
"expectedCommand": "npm init -y",
"checkCommand": "test -f package.json",
"windowsCheckCommand": "if exist package.json (exit 0) else (exit 1)",
"explanation": "Creates package.json with defaults."
}{
"description": "Log in to npm.",
"expectedCommand": "npm login",
"requiresUserInput": true,
"skipTest": true,
"outputIncludes": "Logged in",
"explanation": "Authenticates your npm account."
}{
"description": "View axios repository.",
"expectedCommand": "npm repo axios",
"strictCommandMatch": true,
"isBrowserCommand": true,
"explanation": "Opens the source code repository."
}When a task is executed, the following order is followed:
- beforeCommand (with sudo if
beforeRequiresSudo: trueon Linux) - preCheckCommand (validation - task skipped if fails)
- expectedCommand (with sudo if
requireSudo: trueon Linux) - outputIncludes (validation - checks command output)
- checkCommand or windowsCheckCommand (validation)
- afterCommand (cleanup - always runs)
- Uses
checkCommandfor validation - Prepends
sudowhenrequireSudo: true - Prepends
sudoto beforeCommand whenbeforeRequiresSudo: true - Some tasks may be skipped (e.g., sqlite3 due to SSL issues)
- Uses
checkCommandfor validation - No
sudoprepending (user typically has permissions) - All tasks should work natively
- Uses
windowsCheckCommandfor validation (falls back tocheckCommand) - No
sudosupport - May require admin privileges for global installs
- Path separators differ (backslash vs forward slash)
{
"description": "Install package globally.",
"expectedCommand": "npm install -g <package>",
"requireSudo": true,
"checkCommand": "command -v <package>",
"explanation": "Installs package globally for CLI usage."
}{
"description": "Switch to local registry.",
"expectedCommand": "npm set registry http://localhost:4873",
"checkCommand": "npm config get registry | grep -q 'localhost:4873'",
"explanation": "Points npm to local Verdaccio registry."
}{
"description": "Create temporary file.",
"expectedCommand": "npm pack",
"checkCommand": "ls *.tgz | grep -q '.tgz'",
"afterCommand": "rm *.tgz",
"explanation": "Creates tarball and cleans up after."
}✅ Good: Specific and reliable
"checkCommand": "npm list lodash | grep -q 'lodash@4.17.21'"❌ Bad: Too generic or fragile
"checkCommand": "ls node_modules"✅ Good: Unique substring
"outputIncludes": "added 1 package"❌ Bad: Common word that might appear elsewhere
"outputIncludes": "npm"If a task isn't working as expected, check:
- ✅ Is
requireSudoorbeforeRequiresSudoset correctly for Linux? - ✅ Does
checkCommandwork independently? - ✅ Is
windowsCheckCommandprovided for cross-platform tasks? - ✅ Does
outputIncludesmatch actual command output? - ✅ Are
beforeCommand/afterCommandidempotent (safe to run multiple times)? - ✅ Should the task be marked
skipTest: true?
When adding a new task to tasks.json:
- Start with minimal fields (
description,expectedCommand,explanation) - Add
checkCommandto verify completion - Add
windowsCheckCommandif task should work on Windows - Add
beforeCommandif setup is needed - Set
requireSudoorbeforeRequiresSudoif it needs elevated permissions on Linux - Set
skipTestif it requires authentication or user input - Test on all platforms if possible
- v1.0: Initial field definitions
- v1.1: Added
requireSudofor Linux global installs - v1.2: Added
beforeRequiresSudofor setup commands requiring sudo - v1.3: Added
windowsCheckCommandfor cross-platform support