@@ -258,18 +258,22 @@ DependecyGraph.prototype.resolveDependency = function(
258258 }
259259
260260 // JS modules can be required without extensios.
261- if ( this . _assetExts . indexOf ( extname ( modulePath ) ) === - 1 ) {
261+ if ( ! this . _isFileAsset ( modulePath ) ) {
262262 modulePath = withExtJs ( modulePath ) ;
263263 }
264264
265265 dep = this . _graph [ modulePath ] ;
266266
267267 // Maybe the dependency is a directory and there is an index.js inside it.
268268 if ( dep == null ) {
269- modulePath = path . join ( dir , depModuleId , 'index.js' ) ;
269+ dep = this . _graph [ path . join ( dir , depModuleId , 'index.js' ) ] ;
270270 }
271271
272- dep = this . _graph [ modulePath ] ;
272+ // Maybe it's an asset with @n.nx resolution and the path doesn't map
273+ // to the id
274+ if ( dep == null && this . _isFileAsset ( modulePath ) ) {
275+ dep = this . _moduleById [ this . _lookupName ( modulePath ) ] ;
276+ }
273277
274278 if ( dep == null ) {
275279 debug (
@@ -417,11 +421,14 @@ DependecyGraph.prototype._processModule = function(modulePath) {
417421 var module ;
418422
419423 if ( this . _assetExts . indexOf ( extname ( modulePath ) ) > - 1 ) {
420- moduleData . id = this . _lookupName ( modulePath ) ;
424+ var assetData = extractResolutionPostfix ( this . _lookupName ( modulePath ) ) ;
425+ moduleData . id = assetData . assetName ;
426+ moduleData . resolution = assetData . resolution ;
421427 moduleData . isAsset = true ;
422428 moduleData . dependencies = [ ] ;
423- module = Promise . resolve ( new ModuleDescriptor ( moduleData ) ) ;
429+ module = new ModuleDescriptor ( moduleData ) ;
424430 this . _updateGraphWithModule ( module ) ;
431+ return Promise . resolve ( module ) ;
425432 }
426433
427434 var self = this ;
@@ -652,6 +659,10 @@ DependecyGraph.prototype._processAssetChange_DEPRECATED = function(eventType, fi
652659 }
653660} ;
654661
662+ DependecyGraph . prototype . _isFileAsset = function ( file ) {
663+ return this . _assetExts . indexOf ( extname ( file ) ) !== - 1 ;
664+ } ;
665+
655666/**
656667 * Extract all required modules from a `code` string.
657668 */
@@ -761,6 +772,27 @@ function extname(name) {
761772 return path . extname ( name ) . replace ( / ^ \. / , '' ) ;
762773}
763774
775+ function extractResolutionPostfix ( filename ) {
776+ var ext = extname ( filename ) ;
777+ var re = new RegExp ( '@([\\d\\.]+)x\\.' + ext + '$' ) ;
778+
779+ var match = filename . match ( re ) ;
780+ var resolution ;
781+
782+ if ( ! ( match && match [ 1 ] ) ) {
783+ resolution = 1 ;
784+ } else {
785+ resolution = parseFloat ( match [ 1 ] , 10 ) ;
786+ if ( isNaN ( resolution ) ) {
787+ resolution = 1 ;
788+ }
789+ }
790+
791+ return {
792+ resolution : resolution ,
793+ assetName : match ? filename . replace ( re , '.' + ext ) : filename ,
794+ } ;
795+ }
764796
765797function NotFoundError ( ) {
766798 Error . call ( this ) ;
0 commit comments