Browse Source

Merge pull request #328 from rollup/gh-321

treat missing relative imports as error not warning - fixes #321
gh-335
Rich Harris 9 years ago
parent
commit
6bc0ef45bf
  1. 2
      src/Bundle.js
  2. 5
      src/utils/path.js
  3. 8
      test/function/no-relative-external/_config.js
  4. 1
      test/function/no-relative-external/main.js

2
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;

5
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();
}

8
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 ) );
}
};

1
test/function/no-relative-external/main.js

@ -0,0 +1 @@
import missing from './missing.js';
Loading…
Cancel
Save