File tree Expand file tree Collapse file tree 4 files changed +23
-14
lines changed Expand file tree Collapse file tree 4 files changed +23
-14
lines changed Original file line number Diff line number Diff line change @@ -8,23 +8,26 @@ export default function alias(options = {}) {
8
8
}
9
9
10
10
const aliasKeys = Object . keys ( options ) ;
11
- const aliasIndex = aliasKeys . indexOf ( importee ) ;
11
+ // TODO: We shouldn't have a case of double aliases. But may need to handle that better
12
+ const filteredAlias = aliasKeys . filter ( value => importee . indexOf ( value ) === 0 ) [ 0 ] ;
12
13
13
- if ( aliasIndex >= 0 ) {
14
- const entry = options [ aliasKeys [ aliasIndex ] ] ;
14
+ if ( ! filteredAlias ) {
15
+ return null ;
16
+ }
17
+
18
+ const entry = options [ filteredAlias ] ;
15
19
16
- if ( entry . indexOf ( './' ) === 0 ) {
17
- const basename = path . basename ( importer ) ;
18
- const directory = importer . split ( basename ) [ 0 ] ;
20
+ const updatedId = importee . replace ( filteredAlias , entry ) ;
19
21
20
- // TODO: Is there a way not to have the extension being defined explicitly?
21
- return path . resolve ( directory , entry ) + '.js' ;
22
- }
22
+ if ( updatedId . indexOf ( './' ) === 0 ) {
23
+ const basename = path . basename ( importer ) ;
24
+ const directory = importer . split ( basename ) [ 0 ] ;
23
25
24
- return entry ;
26
+ // TODO: Is there a way not to have the extension being defined explicitly?
27
+ return path . resolve ( directory , updatedId ) + '.js' ;
25
28
}
26
29
27
- return null ;
30
+ return updatedId ;
28
31
} ,
29
32
} ;
30
33
}
Original file line number Diff line number Diff line change
1
+ export default 33 ;
Original file line number Diff line number Diff line change 1
1
import nonAliased from './nonAliased' ;
2
2
import fancyNumber from 'fancyNumber' ;
3
3
import anotherFancyNumber from './anotherFancyNumber' ;
4
+ import anotherNumber from './numberFolder/anotherNumber' ;
5
+ import moreNumbers from 'numberFolder/anotherNumber' ;
4
6
5
- export default fancyNumber + anotherFancyNumber + nonAliased ;
7
+ export default fancyNumber + anotherFancyNumber + nonAliased + anotherNumber + moreNumbers ;
Original file line number Diff line number Diff line change @@ -11,12 +11,15 @@ test(t =>
11
11
plugins : [ alias ( {
12
12
fancyNumber : './aliasMe' ,
13
13
'./anotherFancyNumber' : './localAliasMe' ,
14
+ numberFolder : './folder' ,
15
+ './numberFolder' : './folder' ,
14
16
} ) ] ,
15
17
} ) . then ( stats => {
16
18
t . is ( path . basename ( stats . modules [ 0 ] . id ) , 'nonAliased.js' ) ;
17
19
t . is ( path . basename ( stats . modules [ 1 ] . id ) , 'aliasMe.js' ) ;
18
20
t . is ( path . basename ( stats . modules [ 2 ] . id ) , 'localAliasMe.js' ) ;
19
- t . is ( path . basename ( stats . modules [ 3 ] . id ) , 'index.js' ) ;
20
- t . is ( stats . modules . length , 4 ) ;
21
+ t . is ( path . basename ( stats . modules [ 3 ] . id ) , 'anotherNumber.js' ) ;
22
+ t . is ( path . basename ( stats . modules [ 4 ] . id ) , 'index.js' ) ;
23
+ t . is ( stats . modules . length , 5 ) ;
21
24
} )
22
25
) ;
You can’t perform that action at this time.
0 commit comments