docs
evals
scenario-1
scenario-10
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
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.
The tool should accept a workspace root directory path as a command-line argument. The workspace contains:
pnpm-workspace.yaml file defining workspace package locationspackage.json fileWorkspace Package Discovery: Read the pnpm-workspace.yaml file and scan the workspace to find all packages.
Dependency Analysis: For each package, check its dependencies and devDependencies to identify which ones reference other workspace packages.
Workspace Protocol Conversion: Update package.json files to replace version specifiers of workspace dependencies with workspace:*.
Report Generation: Output a summary showing:
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"]
}
}dependencies and devDependencies sectionsProvides package management and workspace protocol support for local dependencies.
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"]
}
}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"]
}
}package.json files in place.test.js or .test.ts extension