or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-7/

Workspace Dependency Converter

Overview

Build a command-line tool that converts local package dependencies in a monorepo to use the workspace protocol. The tool should scan a workspace, identify packages that depend on other workspace packages, and update their package.json files to use the workspace protocol syntax.

Requirements

Input

The tool should accept a workspace root directory path as a command-line argument. The workspace contains:

  • A pnpm-workspace.yaml file defining workspace package locations
  • Multiple packages, each with its own package.json file

Core Functionality

  1. Workspace Package Discovery: Read the pnpm-workspace.yaml file and scan the workspace to find all packages.

  2. Dependency Analysis: For each package, check its dependencies and devDependencies to identify which ones reference other workspace packages.

  3. Workspace Protocol Conversion: Update package.json files to replace version specifiers of workspace dependencies with workspace:*.

  4. Report Generation: Output a summary showing:

    • Total packages found
    • Total workspace dependencies converted
    • Mapping of packages to their workspace dependencies

Output Format

The tool should print a JSON report to stdout with the following structure:

{
  "totalPackages": 5,
  "convertedDependencies": 8,
  "workspaceReferences": {
    "package-a": ["package-b", "package-c"],
    "package-b": ["package-c"]
  }
}

Edge Cases

  • Skip packages that don't have any dependencies
  • Handle both dependencies and devDependencies sections
  • Ignore external (non-workspace) packages

Dependencies { .dependencies }

pnpm { .dependency }

Provides package management and workspace protocol support for local dependencies.

Test Cases

Test 1: Basic Workspace Protocol Update { .test-case @test }

Setup: Create a workspace with three packages:

  • packages/utils/package.json:
    {
      "name": "utils",
      "version": "1.0.0"
    }
  • packages/core/package.json:
    {
      "name": "core",
      "version": "1.0.0",
      "dependencies": {
        "utils": "1.0.0"
      }
    }
  • pnpm-workspace.yaml:
    packages:
      - 'packages/*'

Expected Behavior: After running the tool, packages/core/package.json should be updated to:

{
  "name": "core",
  "version": "1.0.0",
  "dependencies": {
    "utils": "workspace:*"
  }
}

The tool should output:

{
  "totalPackages": 2,
  "convertedDependencies": 1,
  "workspaceReferences": {
    "core": ["utils"]
  }
}

Test 2: Multiple Dependencies with External Packages { .test-case @test }

Setup: Create a workspace with packages that have both workspace and external dependencies:

  • packages/utils/package.json:
    {
      "name": "utils",
      "version": "1.0.0"
    }
  • packages/helpers/package.json:
    {
      "name": "helpers",
      "version": "2.0.0"
    }
  • packages/app/package.json:
    {
      "name": "app",
      "version": "1.0.0",
      "dependencies": {
        "utils": "^1.0.0",
        "lodash": "^4.17.21"
      },
      "devDependencies": {
        "helpers": "2.0.0"
      }
    }
  • pnpm-workspace.yaml:
    packages:
      - 'packages/*'

Expected Behavior: After running the tool, packages/app/package.json should be updated to:

{
  "name": "app",
  "version": "1.0.0",
  "dependencies": {
    "utils": "workspace:*",
    "lodash": "^4.17.21"
  },
  "devDependencies": {
    "helpers": "workspace:*"
  }
}

The tool should output:

{
  "totalPackages": 3,
  "convertedDependencies": 2,
  "workspaceReferences": {
    "app": ["utils", "helpers"]
  }
}

Implementation Notes

  • The tool should be implemented in JavaScript or TypeScript
  • Use Node.js file system APIs or appropriate libraries for file operations
  • The tool should modify package.json files in place
  • Test files should be named with .test.js or .test.ts extension