
Product
Introducing Socket Fix for Safe, Automated Dependency Upgrades
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
typescript-transform-paths
Advanced tools
Transforms module resolution paths using TypeScript path mapping
Transform module resolution paths in compiled output source to conform with TypeScript
internal resolution via tsconfig.json
settings (paths
, rootDirs
, baseUrl
)
# NPM
npm i -D typescript-transform-paths
# Yarn
yarn add -D typescript-transform-paths
Add it to plugins in your tsconfig.json
{
"compilerOptions": {
"baseUrl": "./",
"paths": {
"@utils/*": ["utils/*"]
},
"plugins": [
// Tranform paths in output .js files
{ "transform": "typescript-transform-paths" },
// Tranform paths in output .d.ts files
{ "transform": "typescript-transform-paths", "afterDeclarations": true }
]
}
}
core/index.ts
import { sum } from "@utils/sum";
sum(2, 3);
core/index.js
(compiled output)
// core/index.js
var sum_1 = require("../utils/sum");
sum_1.sum(2, 3);
TS allows defining
virtual directories
via the rootDirs
compiler option.
To enable virtual directory mapping, use the useRootDirs
plugin option.
{
"compilerOptions": {
"rootDirs": [ "src", "generated" ],
"baseUrl": ".",
"paths": {
"#root/*": [ "./src/*", "./generated/*" ]
},
"plugins": [
{ "transform": "typescript-transform-paths", "useRootDirs": true },
{ "transform": "typescript-transform-paths", "useRootDirs": true, "afterDeclarations": true }
]
}
}
- 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'
yarn
(yarn install
)prettier
(yarn run format
)standard-version
(yarn run release
)Ron S. | Daniel Perez Alvarez |
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!
FAQs
Transforms module resolution paths using TypeScript path mapping and/or custom paths
The npm package typescript-transform-paths receives a total of 258,236 weekly downloads. As such, typescript-transform-paths popularity was classified as popular.
We found that typescript-transform-paths demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
Security News
CISA denies CVE funding issues amid backlash over a new CVE foundation formed by board members, raising concerns about transparency and program governance.
Product
We’re excited to announce a powerful new capability in Socket: historical data and enhanced analytics.