From 72836cbfe0be9996433406442dc7eff07c317b51 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 22 Oct 2015 17:46:26 -0400 Subject: [PATCH] bring back options.external but warn if missing rather than error --- src/Bundle.js | 20 ++++++++++++-------- src/utils/defaults.js | 7 +++++++ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/Bundle.js b/src/Bundle.js index a7ea612..037fe58 100644 --- a/src/Bundle.js +++ b/src/Bundle.js @@ -6,7 +6,7 @@ import Module from './Module'; import ExternalModule from './ExternalModule'; import finalisers from './finalisers/index'; import ensureArray from './utils/ensureArray'; -import { load, resolveId } from './utils/defaults'; +import { load, onwarn, resolveId } from './utils/defaults'; import getExportMode from './utils/getExportMode'; import getIndentString from './utils/getIndentString'; import { unixizePath } from './utils/normalizePlatform.js'; @@ -47,6 +47,9 @@ export default class Bundle { this.assumedGlobals = blank(); + this.external = options.external; + this.onwarn = options.onwarn || onwarn; + // TODO strictly speaking, this only applies with non-ES6, non-default-only bundles [ 'module', 'exports' ].forEach( global => this.assumedGlobals[ global ] = true ); } @@ -138,10 +141,10 @@ export default class Bundle { const promises = module.dependencies.map( source => { return Promise.resolve( this.resolveId( source, module.id ) ) .then( resolvedId => { - module.resolvedIds[ source ] = resolvedId || source; - - // external module if ( !resolvedId ) { + if ( !~this.external.indexOf( source ) ) this.onwarn( `Treating '${source}' as external dependency` ); + module.resolvedIds[ source ] = source; + if ( !this.moduleById[ source ] ) { const module = new ExternalModule( source ); this.externalModules.push( module ); @@ -149,11 +152,12 @@ export default class Bundle { } } - else if ( resolvedId === module.id ) { - throw new Error( `A module cannot import itself (${resolvedId})` ); - } - else { + if ( resolvedId === module.id ) { + throw new Error( `A module cannot import itself (${resolvedId})` ); + } + + module.resolvedIds[ source ] = resolvedId; return this.fetchModule( resolvedId ); } }); diff --git a/src/utils/defaults.js b/src/utils/defaults.js index 7d651fc..07bd31b 100644 --- a/src/utils/defaults.js +++ b/src/utils/defaults.js @@ -12,5 +12,12 @@ export function resolveId ( importee, importer ) { // if this is the entry point, resolve against cwd if ( importer === undefined ) return resolve( process.cwd(), importee ); + // external modules are skipped at this stage + if ( importee[0] !== '.' ) return null; + return resolve( dirname( importer ), importee ).replace( /\.js$/, '' ) + '.js'; } + +export function onwarn ( msg ) { + console.error( msg ); +}