Typescript: Resolve project references from root

Created on 28 Jun 2019  路  1Comment  路  Source: microsoft/TypeScript

Search Terms

Project reference root resolve.

Suggestion

Resolve project reference paths from root directory of a mono repository.

Use Cases

We have a large mono-repository with 1000s of sub-packages we want to convert to TS projects. Currently the references between them must be defined as relative paths, leading to configuration like:

  "references": [
    {
      "path": "../../../base"
    },
    {
      "path": "../colors"
    },
    {
      "path": "../device_capabilities"
    }
  ],

Which is:

  • Hard to read and reason about
  • Creates noisy diffs when moving packages

Ideally project references could be resolved from the root of the mono-repo project, e.g. rootDir or baseUrl options.

E.g.:

  "references": [
    {
      "path": "base"
    },
    {
      "path": "ui/base/colors"
    },
    {
      "path": "ui/base/device_capabilities"
    }
  ],

Checklist

My suggestion meets these guidelines:

  • [x] This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • [x] This wouldn't change the runtime behavior of existing JavaScript code
  • [x] This could be implemented without emitting different JS based on the types of the expressions
  • [x] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • [x] This feature would agree with the rest of TypeScript's Design Goals.
Awaiting More Feedback Suggestion

Most helpful comment

To be consistent with current standards for relative to root, would it be better to prefix these references with "/"?:

...
 "references": [
    {
      "path": "/base"
    },
    {
      "path": "/ui/base/colors"
    },
    {
      "path": "/ui/base/device_capabilities"
    }
  ],
...

https://www.typescriptlang.org/docs/handbook/module-resolution.html

>All comments

To be consistent with current standards for relative to root, would it be better to prefix these references with "/"?:

...
 "references": [
    {
      "path": "/base"
    },
    {
      "path": "/ui/base/colors"
    },
    {
      "path": "/ui/base/device_capabilities"
    }
  ],
...

https://www.typescriptlang.org/docs/handbook/module-resolution.html

Was this page helpful?
0 / 5 - 0 ratings