MCPcopy Index your code
hub / github.com/LeDDGroup/typescript-transform-paths

github.com/LeDDGroup/typescript-transform-paths @v4.0.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v4.0.0 ↗ · + Follow
76 symbols 196 edges 59 files 6 documented · 8% 14 cross-repo links updated 51d agov4.0.0 · 2026-05-17★ 4946 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

typescript-transform-paths

Transform compiled source module resolution paths using TypeScript's paths config, and/or custom resolution paths

npm version Build Status Conventional Commits Code Style: Prettier

[!TIP]
Upgrading from v3 to v4? See the migration documentation.

[!IMPORTANT]
We are looking for maintainers.
Explore alternatives.

Setup Steps

1. Install

<yarn|npm|pnpm> add -D typescript-transform-paths

2. Configure

Add it to plugins in your tsconfig.json file.

Example Configuration

{
  "compilerOptions": {
    "baseUrl": "./",
    // Configure your path mapping here
    "paths": {
      "@utils/*": ["utils/*"],
    },
    // Note: to transform paths for both the output .js and .d.ts files,
    //       you need both of the below entries
    "plugins": [
      // Transform paths in output .js files
      { "transform": "typescript-transform-paths" },

      // Transform paths in output .d.ts files (include this line if you output declarations files)
      { "transform": "typescript-transform-paths", "afterDeclarations": true },
    ],
  },
}

Example Result

core/index.ts

// The following import path is transformed to '../utils/sum'
import { sum } from "@utils/sum";

3. Use

  • Compile with tsc — Use ts-patch.
  • Run with ts-node — See the Wiki.
  • Integrate with Nx — Add the typescript-transform-paths/plugins/nx transformer to the project configuration.

project.json

jsonc { /* ... */ "targets": { "build": { /* ... */ "options": { /* ... */ "transformers": [ { "name": "typescript-transform-paths/plugins/nx", "options": { "afterDeclarations": true }, }, ], }, }, }, }

Virtual Directories

TypeScript allows defining Virtual Directories via the rootDirs compiler option.
To enable Virtual Directory mapping, use the useRootDirs plugin option.

tsconfig.json

{
  "compilerOptions": {
    "rootDirs": ["src", "generated"],
    "baseUrl": ".",
    "paths": {
      "#root/*": ["./src/*", "./generated/*"],
    },
    "plugins": [
      { "transform": "typescript-transform-paths", "useRootDirs": true },
      { "transform": "typescript-transform-paths", "useRootDirs": true, "afterDeclarations": true },
    ],
  },
}

Example

├src/
├─ subdir/
│  └─ sub-file.ts
├─ file1.ts
├generated/
├─ file2.ts

src/file1.ts

import "#root/file2.ts"; // Resolves to './file2'

src/subdir/sub-file.ts

import "#root/file2.ts"; // Resolves to '../file2'
import "#root/file1.ts"; // Resolves to '../file1'

Custom Control

Exclusion Patterns

You can disable transformation for paths based on the resolved file path.
The exclude option allows specifying Glob patterns to match against those resolved file paths.

For an example context in which this would be useful, see issue #83.

tsconfig.json

{
  "compilerOptions": {
    "paths": {
      "sub-module1/*": ["../../node_modules/sub-module1/*"],
      "sub-module2/*": ["../../node_modules/sub-module2/*"],
    },
    "plugins": [
      {
        "transform": "typescript-transform-paths",
        "exclude": ["**/node_modules/**"],
      },
    ],
  },
}
// This path will NOT be transformed
import * as sm1 from "sub-module1/index";

@transform-path

Use the @transform-path tag to explicitly specify the output path for a single statement.

// @transform-path https://cdnjs.cloudflare.com/ajax/libs/react/17.0.1/umd/react.production.min.js
import react from "react"; // Output path will be the URL defined above

@no-transform-path

Use the @no-transform-path tag to explicitly disable transformation for a single statement.

// @no-transform-path
import "normally-transformed"; // This will remain 'normally-transformed' even though
//                                it has a different value in paths config

Version Compatibility

typescript-transform-paths TypeScript Node.js
^4.0.0 >=5.x >=22
^3.5.2 >=3.6.5, >=4.x, >=5.x >=18

Project Guidelines for Contributors

  • Package Manager: yarn (yarn install)
  • Format and lint the code before commit: prettier (yarn format && yarn lint)
  • Commit messages: Conventional Commit Specs
  • Releases: changelogen (yarn release)
GH_TOKEN=$(gh auth token) yarn release

Alternatives

Maintainers

Ron S. Daniel Perez

Extension points exported contracts — how you extend this code

CreateTsProgramOptions (Interface)
(no doc)
test/utils/helpers.ts
Expandable (Interface)
(no doc)
test/projects/specific/src/module-augment.ts
TsTransformPathsConfig (Interface)
(no doc)
src/types.ts
ResolvedModule (Interface)
(no doc)
src/utils/resolve-module-name.ts
TsTransformPathsConfig (Interface)
(no doc)
src/plugins/nx.ts
CreateTsSolutionBuilderOptions (Interface)
(no doc)
test/utils/helpers.ts
Expandable (Interface)
(no doc)
test/projects/specific/src/general.ts
TsTransformPathsContext (Interface)
(no doc)
src/types.ts

Core symbols most depended-on inside this repo

log
called by 6
test/projects/general/dynamic/logger.ts
resolvePathAndUpdateNode
called by 6
src/utils/resolve-path-update-node.ts
createTsProgram
called by 4
test/utils/helpers.ts
getEmitResultFromProgram
called by 4
test/utils/helpers.ts
getMatchPortion
called by 4
src/utils/get-relative-path.ts
before
called by 4
src/plugins/nx.ts
getVisitor
called by 3
src/types.ts
shouldEmitAliasDeclaration
called by 3
src/utils/elide-import-export.ts

Shape

Function 50
Class 10
Interface 10
Method 6

Languages

TypeScript100%

Modules by API surface

test/utils/helpers.ts9 symbols
src/utils/elide-import-export.ts9 symbols
src/plugins/nx.ts5 symbols
src/utils/resolve-module-name.ts4 symbols
src/utils/get-relative-path.ts4 symbols
src/types.ts4 symbols
test/utils/module-not-found-error.ts3 symbols
test/projects/general/dynamic/tester.ts3 symbols
test/projects/general/dynamic/logger.ts3 symbols
test/projects/general/circular/b.ts3 symbols
test/projects/general/circular/a.ts3 symbols
src/visitor.ts3 symbols

For agents

$ claude mcp add typescript-transform-paths \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact