Browse Source

Merge pull request #1192 from rollup/gh-1051

more informative warning for implicit external dependencies
gh-786
Rich Harris 8 years ago
committed by GitHub
parent
commit
bda138ccc6
  1. 3
      bin/src/runRollup.js
  2. 3
      src/Bundle.js
  3. 6
      src/utils/relativeId.js
  4. 2
      test/function/custom-path-resolver-async/_config.js
  5. 2
      test/function/custom-path-resolver-sync/_config.js
  6. 8
      test/function/does-not-hang-on-missing-module/_config.js
  7. 2
      test/function/unused-import/_config.js

3
bin/src/runRollup.js

@ -60,7 +60,8 @@ export default function runRollup ( command ) {
rollup.rollup({
entry: config,
onwarn: message => {
if ( /Treating .+ as external dependency/.test( message ) ) return;
// TODO use warning codes instead of this hackery
if ( /treating it as an external dependency/.test( message ) ) return;
stderr( message );
}
}).then( bundle => {

3
src/Bundle.js

@ -16,6 +16,7 @@ import transform from './utils/transform.js';
import transformBundle from './utils/transformBundle.js';
import collapseSourcemaps from './utils/collapseSourcemaps.js';
import callIfFunction from './utils/callIfFunction.js';
import relativeId from './utils/relativeId.js';
import { dirname, isRelative, isAbsolute, normalize, relative, resolve } from './utils/path.js';
import BundleScope from './ast/scopes/BundleScope.js';
@ -332,7 +333,7 @@ export default class Bundle {
if ( !resolvedId && !isExternal ) {
if ( isRelative( source ) ) throw new Error( `Could not resolve '${source}' from ${module.id}` );
this.onwarn( `Treating '${source}' as external dependency` );
this.onwarn( `'${source}' is imported by ${relativeId( module.id )}, but could not be resolved – treating it as an external dependency. For help see https://github.com/rollup/rollup/wiki/Troubleshooting#treating-module-as-external-dependency` );
isExternal = true;
}

6
src/utils/relativeId.js

@ -1,4 +1,6 @@
import { isAbsolute, relative } from './path.js';
export default function relativeId ( id ) {
if ( typeof process === 'undefined' ) return id;
return id.replace( process.cwd(), '' ).replace( /^[\/\\]/, '' );
if ( typeof process === 'undefined' || !isAbsolute( id ) ) return id;
return relative( process.cwd(), id );
}

2
test/function/custom-path-resolver-async/_config.js

@ -23,7 +23,7 @@ module.exports = {
},
warnings: function ( warnings ) {
assert.deepEqual( warnings, [
"Treating 'path' as external dependency"
`'path' is imported by main.js, but could not be resolved – treating it as an external dependency. For help see https://github.com/rollup/rollup/wiki/Troubleshooting#treating-module-as-external-dependency`
]);
},
exports: function ( exports ) {

2
test/function/custom-path-resolver-sync/_config.js

@ -15,7 +15,7 @@ module.exports = {
},
warnings: function ( warnings ) {
assert.deepEqual( warnings, [
"Treating 'path' as external dependency"
`'path' is imported by main.js, but could not be resolved – treating it as an external dependency. For help see https://github.com/rollup/rollup/wiki/Troubleshooting#treating-module-as-external-dependency`
]);
},
exports: function ( exports ) {

8
test/function/does-not-hang-on-missing-module/_config.js

@ -2,10 +2,10 @@ var assert = require( 'assert' );
module.exports = {
description: 'does not hang on missing module (#53)',
options: {
onwarn: function ( msg ) {
assert.equal( "Treating 'unlessYouCreatedThisFileForSomeReason' as external dependency", msg );
}
warnings: warnings => {
assert.deepEqual( warnings, [
`'unlessYouCreatedThisFileForSomeReason' is imported by main.js, but could not be resolved – treating it as an external dependency. For help see https://github.com/rollup/rollup/wiki/Troubleshooting#treating-module-as-external-dependency`
]);
},
runtimeError: function ( error ) {
assert.equal( "Cannot find module 'unlessYouCreatedThisFileForSomeReason'", error.message );

2
test/function/unused-import/_config.js

@ -4,7 +4,7 @@ module.exports = {
description: 'warns on unused imports ([#595])',
warnings: warnings => {
assert.deepEqual( warnings, [
`Treating 'external' as external dependency`,
`'external' is imported by main.js, but could not be resolved – treating it as an external dependency. For help see https://github.com/rollup/rollup/wiki/Troubleshooting#treating-module-as-external-dependency`,
`'unused', 'notused' and 'neverused' are imported from external module 'external' but never used`,
`Generated an empty bundle`
]);

Loading…
Cancel
Save