Skip to content

Understand conditional imports #2763

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

Closed
simc opened this issue Sep 12, 2019 · 7 comments
Closed

Understand conditional imports #2763

simc opened this issue Sep 12, 2019 · 7 comments

Comments

@simc
Copy link

simc commented Sep 12, 2019

My package has a conditional import which either imports a file which uses dart:io (for vm) or another file which uses dart:indexed_db (for web).

The analysis tab on pub.dev says:

Detected platforms: Flutter, other

Primary library: package:hive/hive.dart with components: io.

It should also detect "web". I think there is a problem with detecting the supported platform when conditional imports are used.

@jonasfj
Copy link
Member

jonasfj commented Sep 12, 2019

It should also detect "web". I think there is a problem with detecting the supported platform when conditional imports are used.

Correct, there is a bug here.

We are looking into refactoring the platform detection in pana soon, but I'm not sure this will get fixed. For now there is few packages that uses conditional imports, and they have special handling in pana 🙈

https://github.com/dart-lang/pana/blob/aaa9afa7000a2064678e2339f1d0a3cb4d79b7f3/lib/src/package_analyzer.dart#L264-L269

@simc
Copy link
Author

simc commented Sep 12, 2019

Should I open an issue for pana too?

@isoos
Copy link
Collaborator

isoos commented Sep 12, 2019

@leisim: in which of your libraries are you using the conditional import? Could you please link to it? Is it reachable from package:hive/hive.dart?

@simc
Copy link
Author

simc commented Sep 12, 2019

@isoos
The library is hive and here is the file with the conditional import. This file is not part of the hive library but it is imported.

@isoos
Copy link
Collaborator

isoos commented Sep 12, 2019

This file is not part of the hive library but it is imported.

As the storage_backend.dart is imported in the main library, I think we should probably adjust the component detection in pana (to also detect these in conditional exports), but with the current logic after that, it will classify them as conflicting components, and the package will be marked as "platform conflict". I think we should keep this issue open, and we'll deal with it as we go ahead with the rewrite/refactoring of the platform classification.

@yjbanov
Copy link

yjbanov commented Sep 13, 2019

See also: flutter/flutter#35588

@jonasfj
Copy link
Member

jonasfj commented Aug 4, 2020

I think this is fixed now, please reopen if not.

@jonasfj jonasfj closed this as completed Aug 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants