{"name":"typescript-transform-paths","version":"3.4.10-1723086173.5a2b0c9","keywords":["typescript","transform","transformer","plugin","path","paths","virtual directory","import","require"],"author":{"url":"https://twitter.com/Ron","name":"Ron S."},"license":"MIT","_id":"typescript-transform-paths@3.4.10-1723086173.5a2b0c9","contributors":["Daniel Perez Alvarez <danielpza@protonmail.com>"],"homepage":"https://github.com/LeDDGroup/typescript-transform-paths#readme","bugs":{"url":"https://github.com/LeDDGroup/typescript-transform-paths/issues"},"dist":{"shasum":"2f988e617e1abd2f038b25988b60ef620b7f97f4","tarball":"http://registry-npm.ywwl.com/typescript-transform-paths/download/typescript-transform-paths-3.4.10-1723086173.5a2b0c9.tgz","fileCount":68,"integrity":"sha512-Kl4moQtvjPpjODsFRHGggITbWi6Ba0bn33o05+l1kFBEwuvQU8zo0Ch+G7ac9CUhaoNmYs0dq67pEXTRUeTjOg==","signatures":[{"sig":"MEUCID8Cem2YAsYv8J83MrXXylyoQY1qWBwTTyIMBs33EXYeAiEAkp2ePsxMD9O0dM9kDo6Fa7WbkVl1K+MkkFoWSBjxbO8=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":140828,"size":34540,"noattachment":false,"key":"/typescript-transform-paths/-/typescript-transform-paths-3.4.10-1723086173.5a2b0c9.tgz"},"main":"dist/index.js","types":"types/index.d.ts","gitHead":"e4fb9c3be8aad5288b04c0a6c5feb6321cb927a9","scripts":{"test":"yarn test/ install && yarn test/ add-package && yarn test/ test","build":"rm -rf dist && yarn run clean && yarn run compile","clean":"rm -rf dist \"**/*.tsbuildinfo\" ./test/projects/nx/dist","reset":"yarn run clean:all && yarn install && yarn build","format":"prettier --write .","compile":"tsc","prepack":"yarn build","release":"changelogen --release --push","clean:all":"yarn run clean && rm -rf node_modules \"**/node_modules\" \"**/yarn.lock\" yarn.lock","--------------":"","-------------- ":""},"_npmUser":{"name":"danielpanpm","email":"danielpza@protonmail.com"},"repository":{"url":"git+https://github.com/LeDDGroup/typescript-transform-paths.git","type":"git"},"description":"Transforms module resolution paths using TypeScript path mapping and/or custom paths","directories":{},"dependencies":{"minimatch":"^3.1.2"},"_hasShrinkwrap":false,"packageManager":"yarn@4.4.0+sha512.91d93b445d9284e7ed52931369bc89a663414e5582d00eea45c67ddc459a2582919eece27c412d6ffd1bd0793ff35399381cb229326b961798ce4f4cc60ddfdb","devDependencies":{"prettier":"^3.3.3","ts-patch":"^3.2.1","typescript":"^5.5.4","@types/node":"^18.19.43","changelogen":"^0.5.5","@types/ts-node":"npm:ts-node@^10.9.2","@tsconfig/node18":"^18.2.4","@types/minimatch":"^5.1.2","@types/ts-expose-internals":"npm:ts-expose-internals@4.9.5"},"peerDependencies":{"typescript":">=3.6.5"},"_npmOperationalInternal":{"tmp":"tmp/typescript-transform-paths_3.4.10-1723086173.5a2b0c9_1723086418314_0.056194367888115826","host":"s3://npm-registry-packages"},"readme":"# typescript-transform-paths\n\n[![npm version](https://img.shields.io/npm/v/typescript-transform-paths.svg)](https://www.npmjs.com/package/typescript-transform-paths)\n[![Build Status](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2FLeDDGroup%2Ftypescript-transform-paths%2Fbadge%3Fref%3Dmaster&style=flat)](https://actions-badge.atrox.dev/LeDDGroup/typescript-transform-paths/goto?ref=master)\n[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)\n[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)\n\nTransform compiled source module resolution paths using TypeScript's `paths` config, and/or custom resolution paths.\n\n## Setup Steps\n\n### 1. Install\n\n```sh\n<yarn|npm|pnpm> add -D typescript-transform-paths\n```\n\n### 2. Configure\n\nAdd it to _plugins_ in your _tsconfig.json_\n\n#### Example Config\n\n```jsonc\n{\n  \"compilerOptions\": {\n    \"baseUrl\": \"./\",\n    // Configure your path mapping here\n    \"paths\": {\n      \"@utils/*\": [\"utils/*\"],\n    },\n    // Note: To transform paths for both the output .js and .d.ts files, you need both of the below entries\n    \"plugins\": [\n      // Transform paths in output .js files\n      { \"transform\": \"typescript-transform-paths\" },\n\n      // Transform paths in output .d.ts files (Include this line if you output declarations files)\n      { \"transform\": \"typescript-transform-paths\", \"afterDeclarations\": true },\n    ],\n  },\n}\n```\n\n#### Example result\n\n`core/index.ts`\n\n```tsx\n// The following transforms path to '../utils/sum'\nimport { sum } from \"@utils/sum\";\n```\n\n### 3. Usage\n\n- **Compile with `tsc`** — Use [ts-patch](https://github.com/nonara/ts-patch)\n\n- **Use with ts-node** — Add `typescript-transform-paths/register` to `require` config.\n\n  `tsconfig.json`\n\n  ```jsonc\n  {\n    \"ts-node\": {\n      \"transpileOnly\": true,\n      \"require\": [ \"typescript-transform-paths/register\" ],\n    },\n    \"compilerOptions\" { /* ... */ }\n  }\n  ```\n\n- **Use with node** — Use the register script: `node -r typescript-transform-paths/register src/index.ts`\n\n- **Use with NX** — Add the `typescript-transform-paths/nx-transformer` to project config\n\n  `project.json`\n\n  ```jsonc\n  {\n    /* ... */\n    \"targets\": {\n      \"build\": {\n        /* ... */\n        \"options\": {\n          /* ... */\n          \"transformers\": [\n            {\n              \"name\": \"typescript-transform-paths/nx-transformer\",\n              \"options\": { \"afterDeclarations\": true },\n            },\n          ],\n        },\n      },\n    },\n  }\n  ```\n\n## Virtual Directories\n\nTS allows defining\n[virtual directories](https://www.typescriptlang.org/docs/handbook/module-resolution.html#virtual-directories-with-rootdirs)\nvia the `rootDirs` compiler option.\nTo enable virtual directory mapping, use the `useRootDirs` plugin option.\n\n```jsonc\n{\n  \"compilerOptions\": {\n    \"rootDirs\": [\"src\", \"generated\"],\n    \"baseUrl\": \".\",\n    \"paths\": {\n      \"#root/*\": [\"./src/*\", \"./generated/*\"],\n    },\n    \"plugins\": [\n      { \"transform\": \"typescript-transform-paths\", \"useRootDirs\": true },\n      { \"transform\": \"typescript-transform-paths\", \"useRootDirs\": true, \"afterDeclarations\": true },\n    ],\n  },\n}\n```\n\n#### Example\n\n```\n- src/\n    - subdir/\n      - sub-file.ts\n    - file1.ts\n- generated/\n    - file2.ts\n```\n\n`src/file1.ts`\n\n```ts\nimport \"#root/file2.ts\"; // resolves to './file2'\n```\n\n`src/subdir/sub-file.ts`\n\n```ts\nimport \"#root/file2.ts\"; // resolves to '../file2'\nimport \"#root/file1.ts\"; // resolves to '../file1'\n```\n\n## Custom Control\n\n### Exclusion patterns\n\nYou can disable transformation for paths based on the resolved file path. The `exclude` option allows specifying glob\npatterns to match against resolved file path.\n\nFor an example context in which this would be useful, see [Issue #83](https://github.com/LeDDGroup/typescript-transform-paths/issues/83)\n\nExample:\n\n```jsonc\n{\n  \"compilerOptions\": {\n    \"paths\": {\n      \"sub-module1/*\": [\"../../node_modules/sub-module1/*\"],\n      \"sub-module2/*\": [\"../../node_modules/sub-module2/*\"],\n    },\n    \"plugins\": [\n      {\n        \"transform\": \"typescript-transform-paths\",\n        \"exclude\": [\"**/node_modules/**\"],\n      },\n    ],\n  },\n}\n```\n\n```ts\n// This path will not be transformed\nimport * as sm1 from \"sub-module1/index\";\n```\n\n### @transform-path tag\n\nUse the `@transform-path` tag to explicitly specify the output path for a single statement.\n\n```ts\n// @transform-path https://cdnjs.cloudflare.com/ajax/libs/react/17.0.1/umd/react.production.min.js\nimport react from \"react\"; // Output path will be the url above\n```\n\n### @no-transform-path\n\nUse the `@no-transform-path` tag to explicitly disable transformation for a single statement.\n\n```ts\n// @no-transform-path\nimport \"normally-transformed\"; // This will remain 'normally-transformed', even though it has a different value in paths config\n```\n\n## Project Guidelines for Contributors\n\n- Package Manager: `yarn` (`yarn install`)\n- Format and lint the code before commit: `prettier` (`yarn format && yarn lint`)\n- Commit messages: [Conventional Commit Specs](https://www.conventionalcommits.org/en/v1.0.0/)\n- Releases: `changelogen` (`yarn release`)\n\n```shell\nGH_TOKEN=$(gh auth token) yarn release\n```\n\n## Alternatives\n\n- [NodeJS subpath imports](https://nodejs.org/api/packages.html#subpath-imports)\n- [Yarn link: protocol](https://yarnpkg.com/protocol/link)\n\n## Maintainers\n\n<!-- prettier-ignore-start -->\n<!-- markdownlint-disable -->\n<table>\n  <tr>\n    <td align=\"center\"><a href=\"https://github.com/nonara\"><img src=\"https://avatars0.githubusercontent.com/u/1427565?v=4\" width=\"100px;\" alt=\"\"/><br /><sub><b>Ron S.</b></sub></a></td>\n    <td align=\"center\"><a href=\"https://github.com/danielpza\"><img src=\"https://avatars2.githubusercontent.com/u/17787042?v=4\" width=\"100px;\" alt=\"\"/><br /><sub><b>Daniel Perez Alvarez</b></sub></a></td>\n  </tr>\n</table>\n","publish_time":1723086418602,"maintainers":[{"name":"danielpza","email":"danielpza+npm@protonmail.com"}],"_cnpm_publish_time":1723086418602,"dist-tags":{"alpha":"3.4.0-alpha","beta":"4.0.0-beta.2","beta1":"2.1.0-beta1","beta2":"2.1.0-beta2","latest":"4.0.0","test":"3.5.3-20241222-065611-bce1be7","testing":"3.4.10-1723087060.2b01c26"}}