Skip to content

Comments

Prevent generated imports of dart:_http#356

Merged
eernstg merged 11 commits intomasterfrom
improve_on_325_feb26
Feb 10, 2026
Merged

Prevent generated imports of dart:_http#356
eernstg merged 11 commits intomasterfrom
improve_on_325_feb26

Conversation

@eernstg
Copy link
Collaborator

@eernstg eernstg commented Feb 5, 2026

This PR improves on the situation which is reported in #325 (which is that reflectable can generate code that doesn't compile by importing an internal platform library) by special casing dart:_http. It is not obvious that there is a general solution, but dart:_http is only exported by dart:io which implies that we can always replace any import of dart:_http by an import of dart:io.

Also correct some URLs in the top-level README.md.

Also prepare reflectable/builder to be released as version 5.2.1/1.2.1.

Fixes #325

@eernstg eernstg requested a review from sigurdm February 5, 2026 14:52
@eernstg
Copy link
Collaborator Author

eernstg commented Feb 9, 2026

I've asked for an example in #325 which would allow the new code to be tested.

Copy link
Collaborator

@sigurdm sigurdm left a comment

Choose a reason for hiding this comment

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

Ideally we find the "canonical" library that exports a given element instead of special casing on imports after they have been generated.

Something like what we do in dartdoc: https://github.com/dart-lang/dartdoc/blob/cb8f442d36abb611d67c8d2fb3e702a641ea32dd/lib/src/model/model_element.dart#L503

Maybe it is ok to land this as a temporary fix though.

@eernstg
Copy link
Collaborator Author

eernstg commented Feb 10, 2026

OK! I actually changed the code generator in a slightly different way: It consistently treats 'dart:_http' as an importable library all the way to the end (which is needed in order to ensure that we will generate code for a Cookie class mirror and such). At the very end, the import of 'dart:_http' is changed (as before) to import 'dart:io' instead.

It may seem hacky to do this at the textual level, but I actually think it's a consistent approach.

If I change the construction of domains such that declarations in 'dart:_http' pretend to be declared in 'dart:io' then various other things are breaking.

PTAL!

@eernstg
Copy link
Collaborator Author

eernstg commented Feb 10, 2026

Thanks!

@eernstg eernstg merged commit a5aeb01 into master Feb 10, 2026
2 checks passed
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.

importing private libaries during build_runner build

2 participants