File tree 5 files changed +116
-8
lines changed
5 files changed +116
-8
lines changed Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
import ModuleShim = DojoLoader . ModuleShim ;
3
3
import Module = DojoLoader . Module ;
4
+ import Package = DojoLoader . Package ;
4
5
5
6
declare const load : ( module : string ) => any ;
6
7
declare const Packages : { } | undefined ;
@@ -544,16 +545,16 @@ declare const Packages: {} | undefined;
544
545
}
545
546
546
547
function getModuleInformation ( moduleId : string , referenceModule ?: DojoLoader . Module ) : DojoLoader . Module {
547
- let match = moduleId . match ( / ^ ( [ ^ \/ ] + ) ( \/ ( .+ ) ) ? $ / ) ;
548
- let packageId = match ? match [ 1 ] : '' ;
549
- let pack = config && config . pkgs ? config . pkgs [ packageId ] : { } ;
548
+ let packageId = '' ;
549
+ let pack : Package = { } ;
550
550
let moduleIdInPackage = '' ;
551
551
552
- if ( pack ) {
553
- moduleId = packageId + '/' + ( moduleIdInPackage = ( ( match && match [ 3 ] ) || pack . main || 'main' ) ) ;
554
- }
555
- else {
556
- packageId = '' ;
552
+ const matches = Object . keys ( ( config && config . pkgs || { } ) ) . filter ( pkg => ( moduleId + '/' ) . indexOf ( pkg + '/' ) === 0 ) . sort ( ( a , b ) => a . length > b . length ? - 1 : 1 ) ;
553
+
554
+ if ( matches . length ) {
555
+ packageId = matches . shift ( ) as string ;
556
+ pack = config . pkgs ! [ packageId ] ;
557
+ moduleId = packageId + '/' + ( moduleIdInPackage = ( moduleId . substr ( packageId . length + 1 ) || pack . main || 'main' ) ) ;
557
558
}
558
559
559
560
let module = modules [ moduleId ] ;
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html >
3
+ < head lang ="en ">
4
+ < meta charset ="UTF-8 ">
5
+ < title > require.config Test</ title >
6
+ </ head >
7
+
8
+ < body >
9
+ < script src ="../../../../src/loader.js "> </ script >
10
+ < script >
11
+ require . config ( {
12
+ packages : [
13
+ {
14
+ name : '@test/common' ,
15
+ location : '../../../common'
16
+ }
17
+ ]
18
+ } ) ;
19
+
20
+ require ( [
21
+ '@test/common/app'
22
+ ] , function ( app ) {
23
+ window . loaderTestResults = app ;
24
+ } ) ;
25
+ </ script >
26
+ </ body >
27
+ </ html >
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html >
3
+ < head lang ="en ">
4
+ < meta charset ="UTF-8 ">
5
+ < title > require.config Test</ title >
6
+ </ head >
7
+
8
+ < body >
9
+ < script src ="../../../../src/loader.js "> </ script >
10
+ < script >
11
+ require . config ( {
12
+ packages : [
13
+ { name : '@common' , location : '../../../common' } ,
14
+ { name : '@common/a' , location : '../../../common/a' , main : 'app' }
15
+ ]
16
+ } ) ;
17
+
18
+ require ( [
19
+ '@common/app' ,
20
+ '@common/a'
21
+ ] , function ( app ) {
22
+ window . loaderTestResults = app ;
23
+ } ) ;
24
+ </ script >
25
+ </ body >
26
+ </ html >
Original file line number Diff line number Diff line change @@ -97,6 +97,18 @@ registerSuite({
97
97
return executeTest ( this , './config/packages2.html' , function ( results : any ) {
98
98
assert . strictEqual ( results , appMessage , '"app" module should load' ) ;
99
99
} ) ;
100
+ } ,
101
+
102
+ 'package name with slashes' ( this : any ) {
103
+ return executeTest ( this , './config/packages3.html' , function ( results : any ) {
104
+ assert . strictEqual ( results , appMessage , '"app" module should load' ) ;
105
+ } ) ;
106
+ } ,
107
+
108
+ 'nested packages' ( this : any ) {
109
+ return executeTest ( this , './config/packages4.html' , function ( results : any ) {
110
+ assert . strictEqual ( results , appMessage , '"app" module should load' ) ;
111
+ } ) ;
100
112
}
101
113
} ,
102
114
Original file line number Diff line number Diff line change @@ -505,6 +505,48 @@ registerSuite({
505
505
] , dfd . callback ( function ( app : any ) {
506
506
assert . strictEqual ( app , 'app' , '"app" module should load' ) ;
507
507
} ) ) ;
508
+ } ,
509
+ 'slashes in package name' ( this : any ) {
510
+ let dfd = this . async ( DEFAULT_TIMEOUT ) ;
511
+
512
+ setErrorHandler ( dfd ) ;
513
+
514
+ global . require . config ( {
515
+ packages : [
516
+ {
517
+ name : '@test/common' ,
518
+ location : './_build/tests/common' ,
519
+ main : 'app'
520
+ }
521
+ ]
522
+ } ) ;
523
+
524
+ global . require ( [
525
+ '@test/common'
526
+ ] , dfd . callback ( function ( app : any ) {
527
+ assert . strictEqual ( app , 'app' , '"app" module should load' ) ;
528
+ } ) ) ;
529
+ } ,
530
+ 'single @ package' ( this : any ) {
531
+ let dfd = this . async ( DEFAULT_TIMEOUT ) ;
532
+
533
+ setErrorHandler ( dfd ) ;
534
+
535
+ global . require . config ( {
536
+ packages : [
537
+ {
538
+ name : '@test' ,
539
+ location : './_build/tests' ,
540
+ main : 'app'
541
+ }
542
+ ]
543
+ } ) ;
544
+
545
+ global . require ( [
546
+ '@test/common/app'
547
+ ] , dfd . callback ( function ( app : any ) {
548
+ assert . strictEqual ( app , 'app' , '"app" module should load' ) ;
549
+ } ) ) ;
508
550
}
509
551
} ,
510
552
You can’t perform that action at this time.
0 commit comments