canjs / can-util

Essential utilities used by lots of CanJS's projects.
https://canjs.com/doc/can-util.html
MIT License
10 stars 8 forks source link

Incomplete AMD loader support in can-util/js/import/import #41

Open rjgotten opened 8 years ago

rjgotten commented 8 years ago

Expected behavior:

Actual current behavior:

Proposed solution: See the following gist: https://gist.github.com/rjgotten/7e1ecc8aa6e909add99f772e70d238cb

The AMD require function supports an error callback as its optional 3rd parameter, which can be used to implement the first bullet point.

The basic idea behind the implementation of the second and third, is that a loader plugin is woven inbetween and used to pull up a require function local to parentName, which in turn is used to resolve moduleName. This will support relative module name lookup. The query-string slug used in the gist should, iirc, be ignored by the module-local remapping feature, making it work as if this was the require local to the original parentName module. However, I am not 100% sure.

matthewp commented 8 years ago

Looks good to me! PR welcome here, I see no reason not to include this.