From 6752951d96b938d7274c86abf04312e63151e50e Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Fri, 27 Nov 2015 21:41:47 -0500 Subject: [PATCH] treat missing relative imports as error not warning - fixes #321 --- src/Bundle.js | 1 + test/function/no-relative-external/_config.js | 8 ++++++++ test/function/no-relative-external/main.js | 1 + 3 files changed, 10 insertions(+) create mode 100644 test/function/no-relative-external/_config.js create mode 100644 test/function/no-relative-external/main.js diff --git a/src/Bundle.js b/src/Bundle.js index 27f4a04..2f9189b 100644 --- a/src/Bundle.js +++ b/src/Bundle.js @@ -161,6 +161,7 @@ export default class Bundle { return Promise.resolve( this.resolveId( source, module.id ) ) .then( resolvedId => { if ( !resolvedId ) { + if ( source[0] === '.' ) 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/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';