Back to Nx

Remove Redundant Ts Project References

packages/js/src/migrations/update-22-1-0/remove-redundant-ts-project-references.md

22.7.12.6 KB
Original Source

Removes Redundant TypeScript Project References from tsconfig.json Files

Removes redundant TypeScript project references from tsconfig.json files when runtime tsconfig files (e.g., tsconfig.lib.json, tsconfig.app.json) exist. Previously, external project references were duplicated in both the project's tsconfig.json and runtime tsconfig files. This migration syncs the TypeScript project references to match the project graph, ensuring that external references only appear in runtime tsconfig files when they exist.

Examples

When a project has runtime tsconfig files like tsconfig.lib.json, the migration will remove external project references from the project's tsconfig.json file:

Before
jsonc
// libs/my-lib/tsconfig.json
{
  "compilerOptions": {
    "composite": true,
  },
  "references": [
    {
      "path": "../other-lib",
    },
  ],
}
After
jsonc
// libs/my-lib/tsconfig.json
{
  "compilerOptions": {
    "composite": true,
  },
  "references": [],
}

The external references remain in the runtime tsconfig file where they belong:

Before
jsonc
// libs/my-lib/tsconfig.lib.json
{
  "compilerOptions": {
    "composite": true,
  },
  "references": [
    {
      "path": "../other-lib/tsconfig.lib.json",
    },
  ],
}
After
jsonc
// libs/my-lib/tsconfig.lib.json
{
  "compilerOptions": {
    "composite": true,
  },
  "references": [
    {
      "path": "../other-lib/tsconfig.lib.json",
    },
  ],
}

For projects without runtime tsconfig files, the project's tsconfig.json file will continue to contain external project references:

Before
jsonc
// libs/legacy-lib/tsconfig.json
{
  "compilerOptions": {
    "composite": true,
  },
  "references": [
    {
      "path": "../other-lib",
    },
  ],
}
After
jsonc
// libs/legacy-lib/tsconfig.json
{
  "compilerOptions": {
    "composite": true,
  },
  "references": [
    {
      "path": "../other-lib",
    },
  ],
}

Internal project references (references within the same project directory) are preserved in the project's tsconfig.json:

Before
jsonc
// libs/my-lib/tsconfig.json
{
  "compilerOptions": {
    "composite": true,
  },
  "references": [
    {
      "path": "./tsconfig.lib.json",
    },
    {
      "path": "./tsconfig.spec.json",
    },
  ],
}
After
jsonc
// libs/my-lib/tsconfig.json
{
  "compilerOptions": {
    "composite": true,
  },
  "references": [
    {
      "path": "./tsconfig.lib.json",
    },
    {
      "path": "./tsconfig.spec.json",
    },
  ],
}