Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support DTS redirect #742

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

feat: support DTS redirect #742

wants to merge 3 commits into from

Conversation

Timeless0911
Copy link
Contributor

Summary

This PR introduces a new redirect feature about DTS files.

redirect.dts

Controls the redirect of the import paths of output Typescript declaration files.

redirect.dts.path

Whether to automatically redirect the import paths of Typescript declaration output files.

  • Type: boolean
  • Default: true

When set to true, the compilerOptions.paths configured in the tsconfig.json file will take effect, and the import path of the DTS output file will be redirected to the corresponding relative path.

When set to false, the original import path will remain unchanged.

  • Example:

When compilerOptions.paths is set to { "@/*": ["src/*"] } in tsconfig.json, the DTS output file will be redirected to the correct relative path:

import { foo } from '@/foo'; // source code of './src/bar.ts' ↓
import { foo } from './foo'; // expected output of './dist/bar.d.ts'

import { foo } from '@/foo'; // source code of './src/utils/index.ts' ↓
import { foo } from '../foo'; // expected output './dist/utils/index.d.ts'

redirect.dts.extension

Whether to automatically redirect the file extension to import paths based on the Typescript declaration output files.

  • Type: boolean
  • Default: false

When set to true, the import paths in DTS files will be redirected to the corresponding JavaScript extension which can be resolved to corresponding DTS file.

When set to false, the file extension will remain unchanged from the original import path in the rewritten import path of the output file (regardless of whether it is specified or specified as any value).

:::note
The extension of the TypeScript declaration file is related to the dts.autoExtension configuration.
:::

  • Example:

For the .d.mts file, in some scenarios, the full extension of the module import path is needed to load correctly.

import { foo } from './foo'; // source code of './src/bar.ts' ↓
import { foo } from './foo.mjs'; // expected output of './dist/bar.d.mts'

import { foo } from './foo.ts'; // source code of './src/utils/index.ts' ↓
import { foo } from './foo.mjs'; // expected output './dist/utils/index.d.mts'

Related Links

close: #263
close: #140
close: #409

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copy link

netlify bot commented Feb 7, 2025

Deploy Preview for rslib ready!

Name Link
🔨 Latest commit a811c95
🔍 Latest deploy log https://app.netlify.com/sites/rslib/deploys/67a5f6abf7eb6c0008aeacfa
😎 Deploy Preview https://deploy-preview-742--rslib.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant