@@ -2,11 +2,7 @@ import { Origin } from 'aurelia-metadata';
22import { Loader , TemplateRegistryEntry } from 'aurelia-loader' ;
33import { PLATFORM , DOM } from 'aurelia-pal' ;
44import { getLogger , Logger } from 'aurelia-logging' ;
5- import { Container } from 'aurelia-dependency-injection' ;
6- import { Aurelia } from 'aurelia-framework' ;
7- import { FuseBoxAureliaHmrPlugin } from './fuse-box-aurelia-hmr-plugin' ;
85export type LoaderPlugin = { fetch : ( address : string ) => Promise < TemplateRegistryEntry > | TemplateRegistryEntry } ;
9-
106const log : Logger = getLogger ( 'fuse-box-aurelia-loader' ) ;
117
128
@@ -253,20 +249,38 @@ export class FuseBoxAureliaLoader extends Loader {
253249 const moduleId = addressParts . splice ( addressParts . length - 1 , 1 ) [ 0 ] ;
254250 const loaderPlugin = addressParts . length === 1 ? addressParts [ 0 ] : null ;
255251
256- if ( loaderPlugin ) {
257- const plugin = this . loaderPlugins [ loaderPlugin ] ;
258- if ( ! plugin ) {
259- throw new Error ( `Plugin ${ loaderPlugin } is not registered in the loader.` ) ;
252+ try {
253+ if ( loaderPlugin ) {
254+ const plugin = this . loaderPlugins [ loaderPlugin ] ;
255+ if ( ! plugin ) {
256+ throw new Error ( `Plugin ${ loaderPlugin } is not registered in the loader.` ) ;
257+ }
258+ return await plugin . fetch ( moduleId ) ;
260259 }
261- return await plugin . fetch ( moduleId ) ;
260+ } catch ( err ) {
261+ throw new Error ( `
262+ Fusebox-loader _import() telling this not registered in the loader:${ address } , module id was: ${ moduleId }
263+ Did you forget to add it to bundle?
264+
265+ ${ err }
266+ ` ) ;
262267 }
263268
264269 // not loader plugin....
265- let module = this . loadWithFusebox ( this . findFuseBoxPath ( moduleId ) ) ;
266- module = ensureOriginOnExports ( module , moduleId ) ;
267- this . moduleRegistry [ moduleId ] = module ;
268- return Promise . resolve ( module ) ;
269-
270+ let modulePath = this . findFuseBoxPath ( moduleId ) ;
271+ try {
272+ let module = this . loadWithFusebox ( modulePath ) ;
273+ module = ensureOriginOnExports ( module , moduleId ) ;
274+ this . moduleRegistry [ moduleId ] = module ;
275+ return Promise . resolve ( module ) ;
276+ } catch ( err ) {
277+ throw new Error ( `
278+ Fusebox-loader _import() telling this not registered in the loader:${ address } , module path returned: ${ modulePath }
279+ Did you forget to add it to bundle?
280+
281+ ${ err }
282+ ` ) ;
283+ }
270284
271285 }
272286
@@ -352,7 +366,12 @@ export class FuseBoxAureliaLoader extends Loader {
352366 }
353367
354368 if ( ! this . fuseBoxExist ( retunValue ) ) {
355- debugPrint ( 'error' , 'findFuseBoxPath() failed to find' , arguments ) ;
369+ debugPrint ( 'error' , 'findFuseBoxPath() failed to find' , path ) ;
370+ throw new Error ( `
371+ fusebox-loader - findFuseBoxPath() failed to find:${ path }
372+ Did you forget to add it to bundle??
373+
374+ ` ) ;
356375 }
357376
358377 }
@@ -369,8 +388,12 @@ export class FuseBoxAureliaLoader extends Loader {
369388 retunValue = '~/' + path ;
370389 break ;
371390 default :
372- debugPrint ( 'error' , 'findFuseBoxPath() failed to find' , arguments ) ;
391+ debugPrint ( 'error' , 'findFuseBoxPath() failed to find' , path ) ;
392+ throw new Error ( `
393+ fusebox-loader - findFuseBoxPath() failed to find:${ path }
394+ Did you forget to add it to bundle??
373395
396+ ` ) ;
374397 }
375398 }
376399
@@ -380,35 +403,4 @@ export class FuseBoxAureliaLoader extends Loader {
380403
381404}
382405
383-
384-
385406PLATFORM . Loader = FuseBoxAureliaLoader ;
386-
387-
388- // listen for aurleia started events
389- document . addEventListener ( 'aurelia-started' , ( ) => {
390-
391- // lets check for en
392- let env : any ;
393-
394- try {
395- env = FuseBox . import ( 'process' ) . env ;
396- } catch ( e ) {
397- env = { } ;
398- console . log ( e ) ;
399- }
400-
401- let hmr = env . FB_AU_HMR || ( < any > window ) . FUSEBOX_AURELIA_LOADER_HMR ;
402- let reload = env . FB_AU_RELOAD || ( < any > window ) . FUSEBOX_AURELIA_LOADER_RELOAD ;
403-
404- // if HMR or RELOAD activated
405- if ( hmr || reload ) {
406-
407- // get instance
408- let container = Container . instance ;
409- let aurelia = container . get ( Aurelia ) ;
410-
411- // create and push plugin
412- FuseBox . plugins . push ( new FuseBoxAureliaHmrPlugin ( aurelia . loader as any , reload ) ) ;
413- }
414- } ) ;
0 commit comments