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

Merged
merged 8 commits into from
Feb 11, 2025
Merged

feat: support DTS redirect #742

merged 8 commits into from
Feb 11, 2025

Conversation

Timeless0911
Copy link
Contributor

@Timeless0911 Timeless0911 commented Feb 7, 2025

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 6aef338
🔍 Latest deploy log https://app.netlify.com/sites/rslib/deploys/67aaf3c7e7495b0008f3a579
😎 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.

@Timeless0911 Timeless0911 enabled auto-merge (squash) February 11, 2025 07:56
@Timeless0911 Timeless0911 merged commit d16af1d into main Feb 11, 2025
17 of 19 checks passed
@Timeless0911 Timeless0911 deleted the feat/dts-redirect branch February 11, 2025 10:01
@chenjiahan chenjiahan restored the feat/dts-redirect branch February 12, 2025 03:26
@chenjiahan chenjiahan deleted the feat/dts-redirect branch February 12, 2025 03:26
@Timeless0911 Timeless0911 mentioned this pull request Feb 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants