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

fix: include .d.ts extension in multiple outputs #161

Closed
wants to merge 1 commit into from

Conversation

KubaJastrz
Copy link
Contributor

Fix for this comment #136 (comment)
Perhaps it also fixes this issue #144

Problem

With multiple entries, name equals the name of the input, which doesn't include any file extension. Therefore, the tsRe regex doesn't work.

Fix

Add .d.ts extension manually to these entries

@joerobot
Copy link

To fix #144 I think we just need the same change at this point:

const path = resolve(outputDir, name.replace(tsRE, '.d.ts'))

I was testing this locally and seemed to resolve that error for me.

@hidde-jan
Copy link

Can confirm this happens with multiple entry files. A workaround currently is to use the beforeWriteFile hook:

dts({
  insertTypesEntry: true,
  beforeWriteFile(filePath) {
    return { filePath: filePath.endsWith('.d.ts') ? filePath : `${filePath}.d.ts` }
  },
}),

@@ -438,7 +438,7 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin {
const typesPath = types ? resolve(root, types) : resolve(outputDir, indexName)

for (const name of entryNames) {
let filePath = multiple ? resolve(outputDir, name.replace(tsRE, '.d.ts')) : typesPath
let filePath = multiple ? resolve(outputDir, `${name}.d.ts`) : typesPath
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should judge whether the extension is included here, because it will fail when extension exists (xxx.ts -> xxx.ts.d.ts).

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And we should apply the same change to line 491.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense 👍

Also, I'm no longer using your library and don't have time to contribute anymore. Feel free to pick up this PR where I left off.

Copy link
Owner

@qmhc qmhc Jan 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All right, thanks for your contributions, I will fix it directly.

@qmhc qmhc closed this Jan 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error: The "mainEntryPointFilePath" value is not a declaration file Support multiple entries for lib mode
4 participants