Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rollup-plugin-dts-path-alias

Package Overview
Dependencies
Maintainers
0
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rollup-plugin-dts-path-alias

A Rollup plugin that converts TypeScript path aliases in .d.ts files to relative paths, ensuring correct type resolution in projects.

  • 0.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
0
Weekly downloads
 
Created
Source

rollup-plugin-dts-path-alias

A Rollup plugin that resolves TypeScript path aliases and baseUrl configurations in .d.ts files by converting them into relative paths. This is particularly useful when building individual .ts files into corresponding .js and .d.ts files without bundling them into a single .d.ts file.

Features

  • Automatically resolves path aliases and baseUrl settings from your tsconfig.json to relative paths in .d.ts files.
  • Supports monorepo environments.
  • Designed to work with individual .ts file builds rather than a single bundled .d.ts file.

Installation

Install the plugin via npm or yarn:

npm install rollup-plugin-dts-path-alias --save-dev

or

yarn add rollup-plugin-dts-path-alias --dev

Usage

Add rollup-plugin-dts-path-alias to your Rollup configuration alongside a TypeScript plugin like @rollup/plugin-typescript:

import typescript from '@rollup/plugin-typescript';
import dtsPathAlias from 'rollup-plugin-dts-path-alias';

export default {
  input: 'src/index.ts',
  output: {
    dir: 'dist',
    format: 'es',
  },
  plugins: [
    dtsPathAlias(),  // Apply the path alias plugin before generating .d.ts files
    typescript(),    // Compile TypeScript files to .js and .d.ts
  ],
};

Important Note

This plugin is not designed to be used with rollup-plugin-dts, which bundles all TypeScript declaration files into a single .d.ts file. Instead, rollup-plugin-dts-path-alias works best when TypeScript files are compiled individually into .js and .d.ts files using plugins like @rollup/plugin-typescript.

Options

cwd (optional)

  • Type: string
  • Default: process.cwd()

The cwd option allows you to specify the current working directory from which the plugin will start searching for the tsconfig.json file. If not provided, the plugin defaults to the current working directory.

Example:

dtsPathAlias({
  cwd: '/path/to/project',
})

How It Works

This plugin automatically locates your tsconfig.json by starting from the provided cwd (or the current working directory if not specified) and moving up the directory tree. Once it finds tsconfig.json, it reads the baseUrl and paths configuration and rewrites import/export paths in .d.ts files to relative paths.

Example

Given the following tsconfig.json:

{
  "compilerOptions": {
    "baseUrl": "./src",
    "paths": {
      "@utils/*": ["utils/*"]
    }
  }
}

If your .d.ts file contains:

import { someFunction } from '@utils/someFunction';

After applying the plugin, it will be converted to:

import { someFunction } from '../utils/someFunction';

This ensures that your .d.ts files are portable and can be correctly resolved in different environments.

Contributing

Contributions are welcome! Feel free to open an issue or submit a pull request with improvements or bug fixes.

License

This project is licensed under the MIT License.

FAQs

Package last updated on 13 Aug 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc