monorepopnpmpnpm-workspace

How to manage package version in pnpm workspace?


I'm using pnpm workspace, and I've added an typescript workspace and installed typescript 5.4.2 for example. I've also added this typescript workspace as a dependency in another workspace. How can I ensure that my typescript version remains the same as the one in the typescript workspace? When I add other dependencies, the eslint version seems changes, but I want to use just one version of typescript in whole monorepo. or Is this approach not worthy?

@storybook/react 8.3.1
└── typescript 5.6.2 peer
@storybook/react-vite 8.3.1
├─┬ @joshwooding/vite-plugin-react-docgen-typescript 0.3.1
│ ├─┬ react-docgen-typescript 2.2.2
│ │ └── typescript 5.6.2 peer
│ └── typescript 5.6.2 peer
├─┬ @storybook/builder-vite 8.3.1
│ └── typescript 5.6.2 peer
└─┬ @storybook/react 8.3.1
  └── typescript 5.6.2 peer
@storybook/test-runner 0.19.1
├─┬ jest 29.7.0
│ ├─┬ @jest/core 29.7.0
│ │ └─┬ jest-config 29.7.0
│ │   └─┬ ts-node 10.9.2 peer
│ │     └── typescript 5.6.2 peer
│ └─┬ jest-cli 29.7.0
│   ├─┬ @jest/core 29.7.0
│   │ └─┬ jest-config 29.7.0
│   │   └─┬ ts-node 10.9.2 peer
│   │     └── typescript 5.6.2 peer
│   ├─┬ create-jest 29.7.0
│   │ └─┬ jest-config 29.7.0
│   │   └─┬ ts-node 10.9.2 peer
│   │     └── typescript 5.6.2 peer
│   └─┬ jest-config 29.7.0
│     └─┬ ts-node 10.9.2 peer
│       └── typescript 5.6.2 peer
├─┬ jest-playwright-preset 4.0.0
│ └─┬ jest 29.7.0 peer
│   ├─┬ @jest/core 29.7.0
│   │ └─┬ jest-config 29.7.0
│   │   └─┬ ts-node 10.9.2 peer
│   │     └── typescript 5.6.2 peer
│   └─┬ jest-cli 29.7.0
│     ├─┬ @jest/core 29.7.0
│     │ └─┬ jest-config 29.7.0
│     │   └─┬

Solution

  • The best way to do it now is through catalogs.

    In pnpm-workspace.yaml:

    packages:
      - packages/*
    
    # Define a catalog of version ranges.
    catalog:
      typescript: ^5.4.2
    

    Then in example/package.json

    {
      "name": "example",
      "dependencies": {
        "typescript": "catalog:"
      }
    }