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

Wrong Imports in Generated .d.ts on Windows #21

Closed
yfwz100 opened this issue Jun 3, 2019 · 8 comments
Closed

Wrong Imports in Generated .d.ts on Windows #21

yfwz100 opened this issue Jun 3, 2019 · 8 comments

Comments

@yfwz100
Copy link

yfwz100 commented Jun 3, 2019

As the picture shown, the generated file index.esm.d.ts contains OS-specific path imports:

image

More importantly, Suggestion interface is redefined...

@yfwz100
Copy link
Author

yfwz100 commented Jun 3, 2019

It works fine under OS X (without the duplicated imports). Seems like a problem related to path.

@yfwz100 yfwz100 changed the title Wrong Imports in Generated d.ts Wrong Imports in Generated .d.ts on Windows Jun 3, 2019
@wessberg
Copy link
Owner

wessberg commented Jun 3, 2019

Hi there, thanks for reporting this issue.
I think this issue and #19 are related.

Looking at the image, the import paths look wrong, so I'm certain that the issue is related to how relative paths are computed by the plugin.

I'll try to spin up a Windows VM and test it

@yfwz100
Copy link
Author

yfwz100 commented Jun 3, 2019

Is there any code determining whether a symbol is bundled or imported? As the picture shows, the Suggestion interface is declared twice.

@wessberg
Copy link
Owner

wessberg commented Jun 3, 2019

Yes there is, but grouped by emitted chunk, and since the import paths are broken, the logic for determining whether or not symbols are defined is broken on Windows

@yfwz100
Copy link
Author

yfwz100 commented Jun 3, 2019

Any help I can try? Not familiar with code but the plugin is awesome. It's better than the official one.

@Septh
Copy link

Septh commented Jun 4, 2019

I'm on a Windows 10 box and I'd like to offer my help, too, should you need some.

I just switched to rollup-plugin-ts to build my own plugin. For now, I'm using a separate build step to generate the declaration file and I'd rather have your plugin do all the dirty job 😁 in one step.

I've tried taking a look at your source code but it's dense and hard to follow when not used to. Just give some directions as to where to look in first.

edit: FWIW, using a bunch of console.log()s showed that when entering the deconflict() function in src\service\transformer\declaration-bundler\deconflict\deconflict.ts, sourceFile.fileName is normalized while options.localModuleNames is not. Hope this helps.

Capture

@wessberg
Copy link
Owner

wessberg commented Jun 4, 2019

I'm investigating the issue, and the issue is related to a couple of things:

  • When comparing two paths or filenames, rollup-plugin-ts always assume that they follow POSIX. For example, there are strict equality checks between generated filenames for Rollup chunks, which use the path convention of the OS, and Typescript sourcefile filenames, which are normalized to POSIX by Typescript itself. This means that some comparisons fail that wouldn't on MacOS where everything is POSIX.

  • The path module is used heavily to normalize file paths. However, they aren't normalized to POSIX when generating new ImportDeclarations and ExportDeclarations which means that stuff like import {foo} from "\\a\\b\\c" can happen where you would expect import {foo} from "./a/b/c" instead.

I'm working on fixing these things and I'm testing both on MacOS and Windows. I'll keep you posted.

wessberg added a commit that referenced this issue Jun 6, 2019
…on Windows. Fixes #19, #21. Fixes issue with transitive barrel exports. Fixes #10
@wessberg
Copy link
Owner

wessberg commented Jun 6, 2019

The issue has been fixed and released in v1.1.55. Thanks for reporting it!

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

No branches or pull requests

3 participants