azu / monorepo-utils

A collection of utilities for monorepo/lerna. Tools for TypeScript project references etc..
164 stars 10 forks source link

Don't write project reference if the dependency's version does not match #34

Closed noisyscanner closed 3 years ago

noisyscanner commented 3 years ago

Example

@scope/package-a@1.0.0 depends on @scope/package-b@1.0.0, but the latest version of package-b in the monorepo is 2.0.0.

packages/
  package-a/
    package.json # "version": "1.0.0"
    node_modules/
      @scope/
        package-b/
          package.json # "version": "1.0.0"
  package-b/
    package.json # "version": "2.0.0"

Expected behaviour

The project reference for package-b is omitted from package-a as the version does not match.

Actual behaviour

The project reference for project-b is written into project-a regardless. When using Yarn Workspaces (and probably others), even though TS will have built the project reference, importing it actually uses the older version from node_modules/, so building is pointless.

Suggestion

When filtering the project references of project-a, check the package.json for both projects and ensure the version of project-b matches what is in project-a's package.json

I am working on a PR for this now