npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rollup-plugin-dts-path-alias

v0.0.3

Published

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

Downloads

7

Readme

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.