Sdk: Recognize file entry-points that should be accessed as package URIs

Created on 8 May 2018  路  17Comments  路  Source: dart-lang/sdk

Users provide entry points to our tools as command line arguments. In some cases those entry points are inside a the lib directory of the package the user is working on, but are specified as file paths.
This can cause the same library file to be imported both using a file URI and a package URI, causing it to be interpreted as two different libraries.

To help users, we should vet the entry point path against its package configuration, and if the entry point could be referenced using a package URI, use that package URI as the URI of the entry-point instead.

area-front-end front-end-fasta type-enhancement

Most helpful comment

What does this have to do with the CFE

My understanding of the proposal is that the CFE would automatically treat lib/some_file.dart as package:the_package/some_file.dart. This isn't a warning to the user - it's accepting the pattern and attempting to do what the user expects.

All 17 comments

What does "entry point" mean in this context? Is it "Dart library with a main() method?"

It means a reference to something you can run the tool on. It doesn't need to have a main method, and it doesn't need to be a library. For example, you can run both dartfmt and the analyzer on part files.

Yes, any user supplied file name, as long as there is also a way to resolve package URIs.

For application entry points (library containing the main method), we search for a .packages file relative to that library.

Purely single-file or source based tools, like the formatter, usually don't care what URI the library is identified by, so there is no reason to exempt them.

For application entry points (library containing the main method), we search for a .packages file relative to that library.

Actually, we would search for a .packages file for any entry point.

This would be amazing! I've had a lot of issues filed on my projects related to this very problem. A few examples:

flutter_redux:
https://github.com/brianegan/flutter_redux/issues/35
https://github.com/brianegan/flutter_redux/issues/36

scoped_model:
https://github.com/brianegan/scoped_model/issues/15

This is just the tip of the iceberg :)

This is now the main issue for tracking this problem.

What does this have to do with the CFE, though? Wouldn't this be handled by the analyzer?

What does this have to do with the CFE

My understanding of the proposal is that the CFE would automatically treat lib/some_file.dart as package:the_package/some_file.dart. This isn't a warning to the user - it's accepting the pattern and attempting to do what the user expects.

Oh, love it!

Until this is solved, can we add a TL;DR for users that followed the various bug threads to here for what the bug is and what is the temporary workaround?

@xster I was thinking if it were a good idea to add a comment to lib/main.dart generated by flutter create to not use relative imports in this file and to not import this file from anywhere.

Face the same problem.
This problem is easily overlooked during development, please fix it.

@peter-ahe-google are you still looking at this?

It's next on my todo list.

Is it possible that the fix will be included in the Dart 2.1 release?

@vanesyan it's looking good, but I can't promise anything.

Was this page helpful?
0 / 5 - 0 ratings