@@ -12,34 +12,57 @@ module.exports = function(dep, filename, directory) {
1212 if ( ! filename ) { throw new Error ( 'filename not given' ) ; }
1313 if ( ! directory ) { throw new Error ( 'directory not given' ) ; }
1414
15- var depExt = path . extname ( dep ) ;
16- var fileExt = path . extname ( filename ) ;
17- var filepath ;
15+ var filepath = getDependencyPath ( dep , filename , directory ) ;
16+ var ext = getDependencyExtension ( dep , filename ) ;
17+
18+ return filepath + ext ;
19+ }
1820
21+ /**
22+ * @param {String } dep
23+ * @return {Boolean }
24+ */
25+ function isRelative ( dep ) {
26+ return dep . indexOf ( '..' ) === 0 || dep . indexOf ( '.' ) === 0 ;
27+ }
28+
29+ /**
30+ * @param {String } dep
31+ * @param {String } filename
32+ * @param {String } directory
33+ * @return {String } Absolute path for the dependency
34+ */
35+ function getDependencyPath ( dep , filename , directory ) {
1936 if ( isRelative ( dep ) ) {
20- filepath = path . resolve ( path . dirname ( filename ) , dep ) ;
21- } else {
22- filepath = path . resolve ( directory , dep ) ;
37+ return path . resolve ( path . dirname ( filename ) , dep ) ;
2338 }
2439
40+ return path . resolve ( directory , dep ) ;
41+ }
42+
43+ /**
44+ * @param {String } dep
45+ * @param {String } filename
46+ * @return {String } The determined extension for the dependency (or empty if already supplied)
47+ */
48+ function getDependencyExtension ( dep , filename ) {
49+ var depExt = path . extname ( dep ) ;
50+ var fileExt = path . extname ( filename ) ;
51+
2552 if ( ! depExt ) {
26- filepath += fileExt ;
27- } else {
28- // If a dependency starts with a period AND it doesn't already end
29- // in .js AND doesn't use a custom plugin, add .js back to path.
30- if ( fileExt === '.js' && depExt !== '.js' && dep . indexOf ( '!' ) < 0 ) {
31- filepath += fileExt ;
32- } else {
33- // If using a SystemJS style plugin
34- if ( depExt . indexOf ( '!' ) > - 1 ) {
35- filepath += depExt . substring ( 0 , depExt . indexOf ( '!' ) ) ;
36- }
37- }
53+ return fileExt ;
3854 }
3955
40- return filepath ;
41- }
56+ // If a dependency starts with a period AND it doesn't already end
57+ // in .js AND doesn't use a custom plugin, add .js back to path
58+ if ( fileExt === '.js' && depExt !== '.js' && dep . indexOf ( '!' ) < 0 ) {
59+ return fileExt ;
60+ }
4261
43- function isRelative ( dep ) {
44- return dep . indexOf ( '..' ) === 0 || dep . indexOf ( '.' ) === 0 ;
62+ // If using a SystemJS style plugin
63+ if ( depExt . indexOf ( '!' ) > - 1 ) {
64+ return depExt . substring ( 0 , depExt . indexOf ( '!' ) ) ;
65+ }
66+
67+ return '' ;
4568}
0 commit comments