-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Requesting a new getter for a fully resolved URIs for the resource API #23990
Comments
cc @lrhn The docs for the
Since the @nex3 can you let us know how this is blocking something you need? This issue is marked High, so I presume that means this breaks something that exists now, or blocks something we need to launch. Thanks! |
@sethladd I think my original issue title was correct. It's my understanding that the intent of the |
The The absence of a way to resolve package URIs to non-package URIs is deliberate. We don't want to break the For example, we don't require a deployed program to even have a location for a resource - the deployment step is allowed to bundle up resources in any way it wants to, as long as the Resource class can load them. They can be inlined in generated code, they can be stored in a database (maybe a browser preloading them) or they can use some other platform specific storage method that we haven't even heard of yet. If you need to have a file accessible outside of Dart, that's not a problem intended to be resolved by resources - and we decided on not doing that after some thought. For example, you can't directly use a resource as a CSS file for a web page you generate, because that requires the resource to have a web-accessible location, which we can't guarantee anyway. |
@nex3 I re-read your original description in this issue, and it wasn't clear what use case you're trying to solve. What do you think about starting a DEP or (maybe easier) sending around a description for what you're trying to workaround/accomplish ? |
Without the ability to find the resolved URL of a resource, the Resource API is only suitable for the simplest of use cases. It certainly doesn't cover any of the instances I've seen in practice where users have asked for access to their resources. As I mentioned before, it doesn't allow linking to resources, which is a serious problem for web apps, since you can't use it to add things like images or stylesheets to the application. It's not useful for serving assets, since it doesn't support accessing the file's modification time to produce effective caching. Users can't list available resources, they can't start Dart scripts or isolates using their resources, and in general they just can't use their resources with any API that's filesystem- or URL-based. |
That is all correct and deliberate. We did not want to introduce a full resource management system for web applications - that's a far more complex problem that web applications were already solving in different ways (and that's without going into CDNs and image spriting, which web resource systems can also be using). You can't list available resources because if the resources come from a web server, there may not be any way to list them. This Resource object is intended solely for having non-Dart data that can be used by the program at runtime and be replaced without recompiling the program. It replaces embedding the data as String literals or other similar hacks. |
Put another way: the new Resource [1] class solves a problem that user-space could not work around: loading a There are many other valid use cases that the core SDK does not provide an out-of-the-box solution for, and we should continue to look for solutions to common and gnarly use cases our developers are running into.
Hm, they should be able to take advantage of URL-based APIs... the Resource class will take any URL that the embedder knows how to load. Might I suggest we start a new effort to identify more use cases that simply cannot be solved by third-party or external packages, and thus require a capability from the core SDK? [1] perhaps Resource wasn't the best name. |
Re-opening this based on our conversation this morning. |
Since there's no way to load resources without using the packages/ directory, this flag will introduce a lot of confusing unfixable breakage. We should un-hide it once there's sufficient SDK support for locating/loading resources (dart-lang/sdk#23990). [email protected] Review URL: https://codereview.chromium.org//1292933003 .
Good question for @sigmundch . If yall decide you need to do something here, please do open a new issue for us to track, specifically for dart2js. |
I also had a different view somewhere in between. However, I do not see Resource.uri as a way to resolve where packages are located, I rather see Resource as an abstraction so you can decouple the URI in the source-tree from the URI in the deployed application. For dart2js, my thinking was that we would translate const-Resource instances removing the Because you may need to expose in your app the URI to the deployed asset, I agree with @nex3 that this needs to be exposed. However, I don't have a strong preference between repurposing |
@sigmundch would you mind opening an issue stating the problem we need to look into? I don't want to repurpose this one. Thanks! (this sounds like it could even be a feature of dart2js?) |
Currently, the
Resource.uri
property in the VM's implementation of theResource
API returns the original URI passed tonew Resource()
. This isn't useful in the common case of passing in apackage:
URI; the point of having auri
property at all is to use the VM's logic to return the concrete path of the resource on disk (or potentially over HTTP), so that it could be referred to in a way that's comprehensible outside the Dart ecosystem (e.g.file:///path/to/pub-cache/hosted/pub.dartlang.org/package-1.2.3/lib/src/resource.txt
).The text was updated successfully, but these errors were encountered: