Skip to content

Commit

Permalink
Merge pull request #1477 from rollup/gh-1264
Browse files Browse the repository at this point in the history
less cryptic error if entry module is external
  • Loading branch information
Rich-Harris committed Jul 9, 2017
2 parents dee8f85 + 85b01a9 commit 22a2cd9
Show file tree
Hide file tree
Showing 8 changed files with 369 additions and 181 deletions.
458 changes: 306 additions & 152 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions package.json
Expand Up @@ -23,7 +23,7 @@
"watch": "rollup -c -w",
"watch:browser": "rollup -c rollup.config.browser.js -w",
"watch:cli": "rollup -c rollup.config.cli.js -w",
"prepublish": "npm run lint && npm test && npm run build:browser",
"prepublish": "npm run lint && npm test && npm run test:leak && npm run build:browser",
"lint": "eslint src browser test/test.js test/utils test/**/_config.js"
},
"repository": "rollup/rollup",
Expand All @@ -45,7 +45,7 @@
},
"homepage": "https://github.com/rollup/rollup",
"devDependencies": {
"acorn": "^5.0.3",
"acorn": "^5.1.1",
"buble": "^0.15.1",
"chalk": "^1.1.3",
"codecov.io": "^0.1.6",
Expand All @@ -70,8 +70,7 @@
"sander": "^0.6.0",
"source-map": "^0.5.6",
"sourcemap-codec": "^1.3.0",
"uglify-js": "^3.0.19",
"weak": "^1.0.1"
"uglify-js": "^3.0.19"
},
"dependencies": {
"source-map-support": "^0.4.0"
Expand All @@ -80,5 +79,8 @@
"dist",
"bin/rollup",
"README.md"
]
],
"optionalDependencies": {
"weak": "^1.0.1"
}
}
7 changes: 7 additions & 0 deletions src/Bundle.js
Expand Up @@ -124,6 +124,13 @@ export default class Bundle {
// of the entry module's dependencies
return this.resolveId( this.entry, undefined )
.then( id => {
if ( id === false ) {
error({
code: 'UNRESOLVED_ENTRY',
message: `Entry module cannot be external`
});
}

if ( id == null ) {
error({
code: 'UNRESOLVED_ENTRY',
Expand Down
2 changes: 1 addition & 1 deletion src/Module.js
@@ -1,4 +1,4 @@
import { parse } from 'acorn/src/index.js';
import { parse } from 'acorn';
import MagicString from 'magic-string';
import { locate } from 'locate-character';
import { timeStart, timeEnd } from './utils/flushTime.js';
Expand Down
10 changes: 10 additions & 0 deletions test/function/external-function-always-true/_config.js
@@ -0,0 +1,10 @@
module.exports = {
description: 'prints useful error if external returns true for entry (#1264)',
options: {
external: id => true
},
error: {
code: 'UNRESOLVED_ENTRY',
message: 'Entry module cannot be external'
}
};
2 changes: 2 additions & 0 deletions test/function/external-function-always-true/main.js
@@ -0,0 +1,2 @@
import ext from 'external';
assert.equal( ext, 42 );
58 changes: 36 additions & 22 deletions test/leak/test.js
@@ -1,27 +1,41 @@
const path = require('path')
const weak = require('weak')
const rollup = require('../..')
var path = require('path')
var rollup = require('../..')

let shouldCollect = false;
let isCollected = false;
try {
var weak = require('weak')

const onCollect = () => isCollected = true;
var shouldCollect = false;
var isCollected = false;

let cache;
const run = () => rollup.rollup({
entry: path.resolve(__dirname, 'index.js'),
cache
}).then(bundle => {
weak(bundle, onCollect);
cache = bundle;
global.gc();
if (shouldCollect && !isCollected) {
throw new Error('Memory leak detected')
function onCollect () {
isCollected = true;
}
shouldCollect = true;
})

run().then(run).then(() => console.log('Success')).catch((err) => {
console.error(err.message);
process.exit(1);
});
var cache;
function run () {
return rollup.rollup({
entry: path.resolve(__dirname, 'index.js'),
cache
}).then(function (bundle) {
weak(bundle, onCollect);
cache = bundle;
global.gc();
if (shouldCollect && !isCollected) {
throw new Error('Memory leak detected')
}
shouldCollect = true;
});
};

run()
.then(run)
.then(function () {
console.log('Success');
}).
catch(function (err) {
console.error(err.message);
process.exit(1);
});
} catch (err) {
console.log(`skipping memory leak test`);
}
1 change: 0 additions & 1 deletion test/test.js
Expand Up @@ -7,7 +7,6 @@ const assert = require( 'assert' );
const { exec } = require( 'child_process' );
const buble = require( 'buble' );
const acorn = require( 'acorn' );
const weak = require( 'weak' );
const rollup = require( '../dist/rollup' );

const FUNCTION = path.resolve( __dirname, 'function' );
Expand Down

0 comments on commit 22a2cd9

Please sign in to comment.