Pub: Creating resource only packages

Created on 24 Mar 2018  路  10Comments  路  Source: dart-lang/pub

_From @xster on March 23, 2018 22:4_

Hope it's not a dupe. Didn't find any similar issues.

We have a use case for having resource only packages like https://github.com/flutter/cupertino_icons. It generally works ok though when dependent projects bring them in, .packages' entry has the form

cupertino_icons:file:///Users/x/.pub-cache/hosted/pub.dartlang.org/cupertino_icons-0.1.1/lib/

which doesn't exist since there's no lib or dart files which can cause IDE warnings.

We can certainly make a blank directory. Though it would be good to have an officially recommended approach to this since it might be a generic repeatable problem.

_Copied from original issue: dart-lang/sdk#32662_

question

All 10 comments

If I understand this correctly, it sounds like the issue is that you're trying to create a local package of files for reuse, that you can import into any project as a package. I just finished the draft of a Medium article I'm working on to do exactly this with image files but it's appropriate for audio, video, dart files and whatever else you want to have in your local stash of reusable stuff.

Okay, so how do we do this?

Answer: We combine path packages in pubspec.yaml with a technique that allows us to load asset images from a package. Path packages allow us to keep the package on the local hard drive and with the ability to load images from packages, we can throw our entire image library into the package and fetch it from any project we want. We can also toss any often used dart files into the lib folder of this same package and have easy access to them too, which doesn鈥檛 hurt.

I'm cleaning it up and making an example before putting it on Medium but the first edition is already published here on GitHub. Since I know you don't want to wait days or a week for the details, go ahead and give it a read. Any feedback would be helpful too :)

https://github.com/ScottS2017/local_package/blob/master/lib/Image%20Library%20Article.docx

@matanlurey is there any chance we can get this moved into flutter instead of dart-lang? The ability to keep and access a local library of icons, images, audio and video files does seem much more appropriate to flutter than dart itself. Thanks!

@ScottS2017 I moved this here because @xster's original issue was about pub giving warnings/errors when a lib/ folder was missing. Package management isn't really part of the language (yet, at least), so at minimum the pub tool needs to have guidance or logic.

I also filed https://github.com/flutter/flutter/issues/15905 in Flutter.

/cc @mit-mit

It seems like the draft doc's solution is essentially putting all the assets inside the lib/ folder. It would solve it in the case I'm asking (which is a linter warning that the lib/ folder doesn't exist inside the resource package). Though it's structurally a bit inconsistent with how we organized standard code+resource packages where code goes into lib/ and resources goes into another root folder like assets/ etc.

Do we intend to make that distinction for resource packages? Or is the alternative of not specifically requiring a lib/ folder in all packages semantically simpler?

Assets should go in the lib/ directory鈥攊t's intended to contain everything that downstream packages might need to consume (with the sole exception of executables which go in bin). To be totally semantically accurate it would be called something like public/, but that would be more confusing in the common case where most or all of a package's public assets are code.

Hi @nex3 please don't close this. Flutter may be proposing changing this.

@matanlurey You tagged this as a question; I answered that question. Closing it doesn't stop future discussion, but it does help me track which issues continue to need active attention.

Though it's structurally a bit inconsistent with how we organized standard code+resource packages where code goes into lib/ and resources goes into another root folder like assets/ etc.

How do these normally get referenced in the code since we can't use a package: URI to find them?

It seems like referencing dependent package's resources (fonts in this case) via packages/<name of package>/<font family> does work.

cc @szakarias

@xster - is that with the font in <name of package>'s lib/ directory?

No, it's https://github.com/flutter/cupertino_icons in this case. It's just in /assets. Making it not work anymore is totally an ok solution too. I'm just trying to disambiguate so that either it doesn't work at all or that it works and doesn't output a linter warning.

Was this page helpful?
0 / 5 - 0 ratings