diff --git a/src/Bundle.js b/src/Bundle.js index 27f4a04..dabbde2 100644 --- a/src/Bundle.js +++ b/src/Bundle.js @@ -13,6 +13,7 @@ import { unixizePath } from './utils/normalizePlatform.js'; import transform from './utils/transform.js'; import collapseSourcemaps from './utils/collapseSourcemaps.js'; import callIfFunction from './utils/callIfFunction.js'; +import { isRelative } from './utils/path.js'; export default class Bundle { constructor ( options ) { @@ -161,6 +162,7 @@ export default class Bundle { return Promise.resolve( this.resolveId( source, module.id ) ) .then( resolvedId => { if ( !resolvedId ) { + if ( isRelative( source ) ) throw new Error( `Could not resolve ${source} from ${module.id}` ); if ( !~this.external.indexOf( source ) ) this.onwarn( `Treating '${source}' as external dependency` ); module.resolvedIds[ source ] = source; diff --git a/src/utils/path.js b/src/utils/path.js index 5ef7f49..ec749a4 100644 --- a/src/utils/path.js +++ b/src/utils/path.js @@ -1,11 +1,16 @@ // TODO does this all work on windows? export const absolutePath = /^(?:\/|(?:[A-Za-z]:)?[\\|\/])/; +export const relativePath = /^\.?\.\//; export function isAbsolute ( path ) { return absolutePath.test( path ); } +export function isRelative ( path ) { + return relativePath.test( path ); +} + export function basename ( path ) { return path.split( /(\/|\\)/ ).pop(); } diff --git a/test/function/no-relative-external/_config.js b/test/function/no-relative-external/_config.js new file mode 100644 index 0000000..37f86df --- /dev/null +++ b/test/function/no-relative-external/_config.js @@ -0,0 +1,8 @@ +var assert = require( 'assert' ); + +module.exports = { + description: 'missing relative imports are an error, not a warning', + error: function ( err ) { + assert.ok( /Could not resolve \.\/missing\.js from/.test( err.message ) ); + } +}; diff --git a/test/function/no-relative-external/main.js b/test/function/no-relative-external/main.js new file mode 100644 index 0000000..d0de2af --- /dev/null +++ b/test/function/no-relative-external/main.js @@ -0,0 +1 @@ +import missing from './missing.js';