Browse Source

support more plugin stuff, remove support for transform, resolveId, load, external, resolveExternal

better-aggressive
Rich Harris 9 years ago
parent
commit
5b711ec005
  1. 28
      src/Bundle.js

28
src/Bundle.js

@ -6,8 +6,7 @@ import Module from './Module';
import ExternalModule from './ExternalModule'; import ExternalModule from './ExternalModule';
import finalisers from './finalisers/index'; import finalisers from './finalisers/index';
import ensureArray from './utils/ensureArray'; import ensureArray from './utils/ensureArray';
import { defaultResolver, defaultExternalResolver } from './utils/resolveId'; import { load, resolveId } from './utils/defaults';
import { defaultLoader } from './utils/load';
import getExportMode from './utils/getExportMode'; import getExportMode from './utils/getExportMode';
import getIndentString from './utils/getIndentString'; import getIndentString from './utils/getIndentString';
import { unixizePath } from './utils/normalizePlatform.js'; import { unixizePath } from './utils/normalizePlatform.js';
@ -21,15 +20,20 @@ export default class Bundle {
this.plugins = ensureArray( options.plugins ); this.plugins = ensureArray( options.plugins );
this.resolveId = first( ensureArray( options.resolveId ).concat( defaultResolver ) ); this.resolveId = first(
this.load = first( ensureArray( options.load ).concat( defaultLoader ) ); this.plugins
.map( plugin => plugin.resolveId )
.filter( Boolean )
.concat( resolveId )
);
this.resolveOptions = { this.load = first(
external: ensureArray( options.external ), this.plugins
resolveExternal: first( ensureArray( options.resolveExternal ).concat( defaultExternalResolver ) ) .map( plugin => plugin.load )
}; .filter( Boolean )
.concat( load )
);
this.loadOptions = {};
this.transformers = ensureArray( options.transform ).concat( this.transformers = ensureArray( options.transform ).concat(
this.plugins.map( plugin => plugin.transform ).filter( Boolean ) this.plugins.map( plugin => plugin.transform ).filter( Boolean )
); );
@ -48,7 +52,7 @@ export default class Bundle {
} }
build () { build () {
return Promise.resolve( this.resolveId( this.entry, undefined, this.resolveOptions ) ) return Promise.resolve( this.resolveId( this.entry, undefined ) )
.then( id => this.fetchModule( id ) ) .then( id => this.fetchModule( id ) )
.then( entryModule => { .then( entryModule => {
this.entryModule = entryModule; this.entryModule = entryModule;
@ -116,7 +120,7 @@ export default class Bundle {
if ( this.pending[ id ] ) return null; if ( this.pending[ id ] ) return null;
this.pending[ id ] = true; this.pending[ id ] = true;
return Promise.resolve( this.load( id, this.loadOptions ) ) return Promise.resolve( this.load( id ) )
.then( source => transform( source, id, this.transformers ) ) .then( source => transform( source, id, this.transformers ) )
.then( source => { .then( source => {
const { code, originalCode, ast, sourceMapChain } = source; const { code, originalCode, ast, sourceMapChain } = source;
@ -132,7 +136,7 @@ export default class Bundle {
fetchAllDependencies ( module ) { fetchAllDependencies ( module ) {
const promises = module.dependencies.map( source => { const promises = module.dependencies.map( source => {
return Promise.resolve( this.resolveId( source, module.id, this.resolveOptions ) ) return Promise.resolve( this.resolveId( source, module.id ) )
.then( resolvedId => { .then( resolvedId => {
module.resolvedIds[ source ] = resolvedId || source; module.resolvedIds[ source ] = resolvedId || source;

Loading…
Cancel
Save