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

Resolver can't resolve library not transitively imported from primary input #493

Open
dam0vm3nt opened this issue Oct 8, 2017 · 6 comments
Labels
P1 A high priority bug; for example, a single project is unusable or has many test failures package:build_runner type-enhancement A request for a change that isn't a bug

Comments

@dam0vm3nt
Copy link

I've created a Builder that accept an HTML file as its primary input but needs to analyze some dart files to accomplish its task.

Trying to use buildStep.resolver.isLibrary(assetId) / getLibrary(assetId) with a valid dart library assetId always returns false or throws (the latter). It behaves like if the resolver didn't actually knows anything about the asset. This doesn't change even if a previously call canRead or readAsString on the same assets.

If I make the builder accept the dart file as primary input (only to investigate the problem) then the resolver works.

@natebosch
Copy link
Member

Are you running wrapped as a Transformer with pub? I think the BarbackResolvers can only resolve libraries that are in the transitive imports of one of the primary inputs.

What is the use case for resolving a library which is not imported? Supporting resolution will be tough since the analyzer code expects files to be available synchronously while builds can only read assets asynchronously.

@dam0vm3nt
Copy link
Author

dam0vm3nt commented Oct 9, 2017

No it's a bare Builder. I'd like to generate a new .html file from an existing one. The original one references some dart scripts in script like tag (e.g. : <script type='application/dart' src='scriptName'></script>). I need to use those scripts as entry-point to look for some kind of annotation in order to inject other html fragments. It's something very similar to the web-components transformer (html import inliner). But I want to do this in a Builder.

The strange thing is that I was expecting that calling resolver.getLibrary(assetId) would trigger the analysis even if that asset was not analyzed until that point and also introduce a dependency of the buildStep - but that seams not the case.

@dam0vm3nt
Copy link
Author

... and the file I'm going to analyze is part of the current project, it doesn't resides in another - not imported - package.

@jakemac53
Copy link
Contributor

Ya, this is a known issue that was a side effect of some of the simplification around the resolver apis.

Today you can only resolve dart code that is reachable from your primary input, primarily for performance reasons. When we move away from the barback_resolvers package we should be able to fix this.

@natebosch
Copy link
Member

Yeah I think we stand a much better chance at resolving this in build_runner than when running with pub, I'm not sure of the approach but we'll definitely keep this in mind while we work on #348

@natebosch natebosch changed the title resolvers doesn't resolve ? Resolver can't resolve library not transitively imported from primary input Oct 9, 2017
@dam0vm3nt
Copy link
Author

Ok. In the meanwhile I have resorted on using my own AnalysisContext. I'll revert using the BuildStep resolver once this is "fixed".

@matanlurey matanlurey added package:build_runner type-enhancement A request for a change that isn't a bug labels Oct 16, 2017
@jakemac53 jakemac53 added the P1 A high priority bug; for example, a single project is unusable or has many test failures label Jan 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 A high priority bug; for example, a single project is unusable or has many test failures package:build_runner type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

4 participants