magnars / optimus

A Ring middleware for frontend performance optimization.
364 stars 23 forks source link

Make asset loading work cross-platform (Windows, *nix) #69

Closed augustl closed 4 years ago

augustl commented 4 years ago

Note: this pull request depends on https://github.com/magnars/optimus/pull/66. The tests are running fine on travis/unix, but not on Windows, as it stands now.

I'll rebase the pull request against the JSR223 PR once it's ready. For now, this PR exists for quiet contemplation and discussion :)

augustl commented 4 years ago

I just thought of an alternative approach.

The file iteration can convert all paths on the class path to URL-like relative paths, before sending it through the asset loader. So, it would convert /home/foo/myapp/resources/js/test.js AND C:\Users\Foo\myapp\resources\js\test.js to /js/test.js - and then send it to the matching process.

This means we can leave out the change to a vector representing a glob, and keep using regexps as the default.

Thoughts?

magnars commented 4 years ago

Wow, well done on this! 👏

The second approach seems better to me. Normalizing paths as close to the problem as possible might also stop other bugs from popping up.

We could still support globbing, tho. The regexen are kinda weird.

augustl commented 4 years ago

I agree - didn't think about that until I went to bed right after making this pull request. Should have used mytomatoes.com... :)

I'll make two new pull requests: one for adding support for globs based on java.nio paths, and another for converting file system paths into URLs at the earliest stage possible, requiring the smallest amount of changes.