Shazwazza / ClientDependency

DEPRECATED. A library for managing CSS & JavaScript dependencies and optimization in ASP.Net
139 stars 65 forks source link

Loading relative dependencies with HTTP requests broken on 1.9.7 #152

Open allyen opened 6 years ago

allyen commented 6 years ago

With the 1.9.7 upgrade it stopped to be possible to load local relative URIs over HTTP requests. We use this for generating JS code via razor (something like this) -- sometimes useful, although the generated JS must be immutable to make it's caching meaningful :). We could resolve it by putting absolute URIs into the RequiresJs calls but this doesn't feel quite right since with static assets it works.

As for the origin of this issue -- at https://github.com/Shazwazza/ClientDependency/blob/master/ClientDependency.Core/CompositeFiles/Providers/BaseCompositeFileProcessingProvider.cs#L217 there's a call to uri.PathAndQuery which throws for relative URIs. Would it make sense to elaborate on the uri.PathAndQuery part (make it a variable and add some if's) to enable passing local paths? If yes, I can come up with a pull request.

allyen commented 6 years ago

It seems that other code parts called in this place are ok with relative paths -- the IsLocalUri extension method is prepared for local URIs...

Shazwazza commented 6 years ago

There's another discussion about a similar thing here: https://github.com/Shazwazza/ClientDependency/issues/147#issuecomment-423111708

By the time it reaches that line of code that you mention, the path must be an absolute URI. For relative paths, the CanProcessLocally method should return a boolean. What is an example of the path that isn't passing the CanProcessLocally check that isn't an absolute URL?

allyen commented 6 years ago

I see. The problem is that the extension of our custom generated JS files is included in config in @fileDependencyExtensions but it doesn't have an IVirtualFileWriter registered. Instead, these files are processed by a surface controller which requires the WritePathToStream method to call an URL which it now won't do for a relative path. So the correct approach would by to write a custom IVirtualFileWriter?

Shazwazza commented 6 years ago

That will be one way to make it work for sure. If you want to create a PR to allow for non-absolute paths for that specific line i can run some tests to see if it can be allowed.