11import trace from './trace' ;
22import { cleanPath , parse , mapId } from 'dumber-module-loader/dist/id-utils' ;
3- import alias from './transformers/alias' ;
43import defaultPackageFileReader from './package-file-reader/default' ;
54import PackageReader from './package-reader' ;
65import Package from './package' ;
@@ -9,7 +8,6 @@ import {info, error, warn} from './log';
98import { generateHash , stripJsExtension , resolvePackagePath , contentOrFile } from './shared' ;
109import * as cache from './cache/default' ;
1110import path from 'path' ;
12- import mergeTransformed from './transformers/merge' ;
1311import ModulesDone from './modules-done' ;
1412import ModulesTodo from './modules-todo' ;
1513
@@ -167,7 +165,9 @@ export default class Bundler {
167165 }
168166
169167 _capture ( tracedUnit ) {
170- this . _unitsMap [ tracedUnit . path ] = tracedUnit ;
168+ let key = tracedUnit . path ;
169+ if ( tracedUnit . packageName ) key = tracedUnit . packageName + ':' + key ;
170+ this . _unitsMap [ key ] = tracedUnit ;
171171
172172 // mark as done.
173173 this . _modules_done . addUnit ( tracedUnit ) ;
@@ -194,10 +194,7 @@ export default class Bundler {
194194 p = p . then ( ( ) => this . packageReaderFor ( pkg ) ) . then ( reader => {
195195 if ( ! pkg . lazyMain ) {
196196 return reader . readMain ( )
197- . then ( unit => this . capture ( unit ) )
198- . then ( tracedUnit => {
199- this . _ensureNpmAlias ( tracedUnit , pkg . name ) ;
200- } ) ;
197+ . then ( unit => this . capture ( unit ) ) ;
201198 }
202199 } ) ;
203200 } ) ;
@@ -222,31 +219,6 @@ export default class Bundler {
222219 } )
223220 }
224221
225- // this ensures alias to package main, and alias to direct require
226- // to some browser replacement.
227- // e.g. readable-stream/readable -> readable-stream/readable-browser
228- _ensureNpmAlias ( tracedUnit , id ) {
229- const defined = tracedUnit . defined ;
230- let toId ;
231- if ( Array . isArray ( defined ) ) {
232- const ds = defined . map ( d => parse ( d ) . bareId ) ;
233- if ( ds . indexOf ( id ) !== - 1 ) return ;
234- toId = ds [ 0 ] ;
235- } else if ( typeof defined === 'string' ) {
236- toId = parse ( defined ) . bareId ;
237- }
238-
239- // alias to main is also created here
240- if ( ! toId ) warn ( 'no defined module found in ' + tracedUnit . path ) ;
241-
242- // only create alias when defined id is not same as package name
243- if ( toId !== id && toId !== tracedUnit . packageName ) {
244- const aliasResult = alias ( id , toId ) ;
245- mergeTransformed ( tracedUnit , aliasResult ) ;
246- this . _modules_done . addUnit ( tracedUnit ) ;
247- }
248- }
249-
250222 _supportInjectCssIfNeeded ( ) {
251223 if ( ! this . _modules_todo . needCssInjection || ! this . _injectCss || this . _isInjectCssTurnedOn ) {
252224 return Promise . resolve ( ) ;
@@ -280,11 +252,16 @@ export default class Bundler {
280252 const requiredBy = opts . requiredBy ;
281253 const parsedId = parse ( mapId ( id , this . _paths ) ) ;
282254
255+ if ( this . _modules_done . has ( parsedId . bareId , checkUserSpace , checkPackageSpace ) ) {
256+ return Promise . resolve ( ) ;
257+ }
258+
283259 // TODO add a callback point to fillup missing local dep.
284260 // This is needed by dumberify.
285261 if ( checkUserSpace && ! checkPackageSpace ) {
286262 // detected missing local dep
287263 warn ( `local dependency ${ parsedId . bareId } (requiredBy ${ requiredBy . join ( ', ' ) } ) is missing` ) ;
264+ return Promise . resolve ( ) ;
288265 }
289266
290267 return new Promise ( resolve => {
@@ -344,9 +321,6 @@ export default class Bundler {
344321 return this . packageReaderFor ( stub || { name : packageName } )
345322 . then ( reader => resource ? reader . readResource ( resource ) : reader . readMain ( ) )
346323 . then ( unit => this . capture ( unit ) )
347- . then ( tracedUnit => {
348- this . _ensureNpmAlias ( tracedUnit , bareId ) ;
349- } )
350324 . catch ( err => {
351325 error ( 'Resolving failed for module ' + bareId ) ;
352326 error ( err ) ;
@@ -357,8 +331,8 @@ export default class Bundler {
357331 _unitsForBundle ( bundle ) {
358332 let units = [ ] ;
359333
360- Object . keys ( this . _unitsMap ) . forEach ( filePath => {
361- const unit = this . _unitsMap [ filePath ] ;
334+ Object . keys ( this . _unitsMap ) . forEach ( key => {
335+ const unit = this . _unitsMap [ key ] ;
362336 if ( unit . bundle === bundle ) units . push ( unit ) ;
363337 } ) ;
364338
0 commit comments