22
22
* the package directory (e.g. ../../something), then toAbsMid returns an
23
23
* irrational path. To work around this issue, we do the following:
24
24
*
25
- * 1. Replace the main path used by Dojo with 'main' , saving the real
25
+ * 1. Replace the main path used by Dojo with an empty string , saving the real
26
26
* main path in the 'realMain' property. The causes Dojo's toAbsMid to return
27
- * an absMid like 'packageName/main '.
27
+ * an absMid like 'packageName/'.
28
28
*
29
- * 2. In our patched implementation of toUrl, we call the Dojo implementation
29
+ * 2. In our patched implementation of toAbsMid, we remove the traling slash
30
+ * before returning the result to the user so that the absMid for a package
31
+ * is just the package name.
32
+ *
33
+ * 3. In our patched implementation of toUrl, we call the Dojo implementation
30
34
* and fixup the url using the path saved in the 'realMain' property.
31
35
*/
32
36
module . exports = function ( ) {
@@ -40,28 +44,38 @@ module.exports = function() {
40
44
&& typeof pkg . realMain === 'undefined' // hasn't already been adjusted
41
45
) {
42
46
pkg . realMain = pkg . main ;
43
- pkg . main = 'main ' ;
47
+ pkg . main = '' ;
44
48
}
45
49
} ) ;
50
+ function toAbsMid ( name , referenceModule ) {
51
+ var absMid = loaderScope . require . originalToAbsMid ( name , referenceModule ) ;
52
+ if ( absMid . indexOf ( '/' ) === absMid . length - 1 ) {
53
+ var pkgName = absMid . substring ( 0 , absMid . length - 1 ) ;
54
+ var pkg = loaderScope . require . packs [ pkgName ] ;
55
+ if ( pkg && pkg . realMain ) {
56
+ absMid = pkgName ;
57
+ }
58
+ }
59
+ return absMid ;
60
+ }
46
61
function toUrl ( name , referenceModule ) {
47
- var absMid = loaderScope . require . toAbsMid ( name , referenceModule ) ;
48
- var url = loaderScope . require . originalToUrl ( absMid , referenceModule ) ;
49
- var match = / ^ ( [ ^ / ] * ) \/ m a i n $ / . exec ( absMid ) ;
50
- var pkg = match && match [ 1 ] && loaderScope . require . packs [ match [ 1 ] ] ;
62
+ var url = loaderScope . require . originalToUrl ( name , referenceModule ) ;
63
+ var pkg = loaderScope . require . packs [ name ] ;
51
64
if ( pkg && pkg . realMain ) {
52
65
var parts = url . split ( '?' ) ;
53
66
if ( / ( ^ \/ ) | ( \: ) / . test ( pkg . realMain ) ) {
54
67
// absolute URL
55
68
parts [ 0 ] = pkg . realMain ;
56
69
} else {
57
70
// relative URL
58
- parts [ 0 ] = parts [ 0 ] . replace ( / m a i n $ / , '' ) + pkg . realMain ;
71
+ parts [ 0 ] = parts [ 0 ] + '/' + pkg . realMain ;
59
72
}
60
73
url = parts . join ( '?' ) ;
61
74
}
62
75
return url ;
63
76
}
64
77
loaderScope . require . originalToAbsMid = loaderScope . require . toAbsMid ;
65
78
loaderScope . require . originalToUrl = loaderScope . require . toUrl ;
79
+ loaderScope . require . toAbsMid = toAbsMid ;
66
80
loaderScope . require . toUrl = toUrl ;
67
81
} ;
0 commit comments