
Product
Introducing Socket Firewall Enterprise: Flexible, Configurable Protection for Modern Package Ecosystems
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.
@ovos-media/ts-transform-paths
Advanced tools
Heavily tested and most complete import/require path rewriter for typescript.
tsconfig baseUrl + paths alias rewriting in bundles and declaration files. You can use absolute paths in libraries. All them will be rewritted to relative in transpiled js and in d.ts files.
Works everywhere, no more tspath, rollup-plugin-alias or webpack resolve alias and other workarounds.
Why? Problem described here: d.ts files not working, if absolute paths used in npm-packaged library.
ts-transform-import-path-rewrite does't support compilerOptions.paths config, doesn't support require function, weak tested.
ts-transformer-imports doesn't support dynamic import and require function. It doesn't support d.ts: "transform": "ts-transformer-imports", "afterDeclarations" true, "before": "true"} rewrites paths only in d.ts, "transform": "ts-transformer-imports", "afterDeclarations" true, "after": "true"} rewrites paths only in js.
Since 1.7.4 plugin rewrites paths only in internal project files, not for packages in node_modules.
// tsconfig.json
{
"compilerOptions": {
"baseUrl": "src"
"plugins": [{ "transform": "@zerollup/ts-transform-paths" }],
"paths": { "*": ["*"] },
}
}
// main.ts
import { app } from "electron"; // a module in node_modules
import { setMenu } from "main/menu"; // a module in the current dir
// main.js
const electron_1 = require("electron");
const menu_1 = require("./main/menu");
ttypescript is a wrapper around typescript with transformer plugin support in tsconfig.json.
my-lib/tsconfig.json:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"my-lib/*": ["src/*"]
},
"plugins": [
{
"transform": "@zerollup/ts-transform-paths",
"exclude": ["*"]
}
]
}
}
my-lib/src/index.ts
export * from 'my-lib/some'
my-lib/src/some.ts
export const some = '123'
Transpiled my-lib/dist/index.js
export * from './some'
Typings my-lib/dist/index.d.ts
export * from './some';
For more examples see zerollup demo lib.
install:
$ npm i -D @zerollup/ts-transform-paths ttypescript
add to configure file rollup.config.js
import ttypescript from 'ttypescript'
import tsPlugin from 'rollup-plugin-typescript2'
export default {
input: 'src/lib.ts',
output: [{ file : 'dist/lib.js', name : 'mylib', format : 'iife', sourcemap : true }],
plugins: [
tsPlugin({
typescript: ttypescript
})
]
}
And setup tsconfig.json
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"my-lib/*": ["src/*"]
},
"plugins": [
{
"transform": "@zerollup/ts-transform-paths",
"exclude": ["*"]
}
]
}
}
const tsTransformPaths = require('@zerollup/ts-transform-paths');
module.exports = {
module: {
rules: [
{
test: /\.(ts|tsx)$/,
loader: 'ts-loader',
options: {
getCustomTransformers: (program) => {
const transformer = tsTransformPaths(program);
return {
before: [transformer.before], // for updating paths in generated code
afterDeclarations: [transformer.afterDeclarations] // for updating paths in declaration files
};
}
}
}
]
}
};
interface Config {
/**
Disable plugin path resolving for given paths keys
*/
exclude?: string[] | void
}
FAQs
Ts transform paths
We found that @ovos-media/ts-transform-paths demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 12 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
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.

Security News
Open source dashboard CNAPulse tracks CVE Numbering Authorities’ publishing activity, highlighting trends and transparency across the CVE ecosystem.

Product
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socket’s new workflow scanning support.