Browse Source

more error stuff

gh-1187
Rich-Harris 8 years ago
parent
commit
dd9a93f094
  1. 7
      src/Bundle.js
  2. 16
      src/Module.js
  3. 6
      src/finalisers/iife.js
  4. 6
      src/finalisers/umd.js
  5. 14
      src/rollup.js
  6. 5
      src/utils/collapseSourcemaps.js
  7. 9
      src/utils/defaults.js

7
src/Bundle.js

@ -474,7 +474,12 @@ export default class Bundle {
const indentString = getIndentString( magicString, options ); const indentString = getIndentString( magicString, options );
const finalise = finalisers[ options.format ]; const finalise = finalisers[ options.format ];
if ( !finalise ) throw new Error( `You must specify an output type - valid options are ${keys( finalisers ).join( ', ' )}` ); if ( !finalise ) {
error({
code: 'INVALID_OPTION',
message: `You must specify an output type - valid options are ${keys( finalisers ).join( ', ' )}`
});
}
timeStart( 'render format' ); timeStart( 'render format' );

16
src/Module.js

@ -121,7 +121,10 @@ export default class Module {
const name = specifier.exported.name; const name = specifier.exported.name;
if ( this.exports[ name ] || this.reexports[ name ] ) { if ( this.exports[ name ] || this.reexports[ name ] ) {
throw new Error( `A module cannot have multiple exports with the same name ('${name}')` ); this.error({
code: 'DUPLICATE_EXPORT',
message: `A module cannot have multiple exports with the same name ('${name}')`
}, specifier.start );
} }
this.reexports[ name ] = { this.reexports[ name ] = {
@ -141,8 +144,10 @@ export default class Module {
const identifier = ( node.declaration.id && node.declaration.id.name ) || node.declaration.name; const identifier = ( node.declaration.id && node.declaration.id.name ) || node.declaration.name;
if ( this.exports.default ) { if ( this.exports.default ) {
// TODO indicate location this.error({
throw new Error( 'A module can only have one default export' ); code: 'DUPLICATE_EXPORT',
message: `A module can only have one default export`
}, node.start );
} }
this.exports.default = { this.exports.default = {
@ -182,7 +187,10 @@ export default class Module {
const exportedName = specifier.exported.name; const exportedName = specifier.exported.name;
if ( this.exports[ exportedName ] || this.reexports[ exportedName ] ) { if ( this.exports[ exportedName ] || this.reexports[ exportedName ] ) {
throw new Error( `A module cannot have multiple exports with the same name ('${exportedName}')` ); this.error({
code: 'DUPLICATE_EXPORT',
message: `A module cannot have multiple exports with the same name ('${exportedName}')`
}, specifier.start );
} }
this.exports[ exportedName ] = { localName }; this.exports[ exportedName ] = { localName };

6
src/finalisers/iife.js

@ -1,5 +1,6 @@
import { blank } from '../utils/object.js'; import { blank } from '../utils/object.js';
import { getName } from '../utils/map-helpers.js'; import { getName } from '../utils/map-helpers.js';
import error from '../utils/error.js';
import getInteropBlock from './shared/getInteropBlock.js'; import getInteropBlock from './shared/getInteropBlock.js';
import getExportBlock from './shared/getExportBlock.js'; import getExportBlock from './shared/getExportBlock.js';
import getGlobalNameMaker from './shared/getGlobalNameMaker.js'; import getGlobalNameMaker from './shared/getGlobalNameMaker.js';
@ -36,7 +37,10 @@ export default function iife ( bundle, magicString, { exportMode, indentString,
const args = bundle.externalModules.map( getName ); const args = bundle.externalModules.map( getName );
if ( exportMode !== 'none' && !name ) { if ( exportMode !== 'none' && !name ) {
throw new Error( 'You must supply options.moduleName for IIFE bundles' ); error({
code: 'INVALID_OPTION',
message: `You must supply options.moduleName for IIFE bundles`
});
} }
if ( exportMode === 'named' ) { if ( exportMode === 'named' ) {

6
src/finalisers/umd.js

@ -1,5 +1,6 @@
import { blank } from '../utils/object.js'; import { blank } from '../utils/object.js';
import { getName, quotePath, req } from '../utils/map-helpers.js'; import { getName, quotePath, req } from '../utils/map-helpers.js';
import error from '../utils/error.js';
import getInteropBlock from './shared/getInteropBlock.js'; import getInteropBlock from './shared/getInteropBlock.js';
import getExportBlock from './shared/getExportBlock.js'; import getExportBlock from './shared/getExportBlock.js';
import getGlobalNameMaker from './shared/getGlobalNameMaker.js'; import getGlobalNameMaker from './shared/getGlobalNameMaker.js';
@ -28,7 +29,10 @@ const wrapperOutro = '\n\n})));';
export default function umd ( bundle, magicString, { exportMode, indentString, intro, outro }, options ) { export default function umd ( bundle, magicString, { exportMode, indentString, intro, outro }, options ) {
if ( exportMode !== 'none' && !options.moduleName ) { if ( exportMode !== 'none' && !options.moduleName ) {
throw new Error( 'You must supply options.moduleName for UMD bundles' ); error({
code: 'INVALID_OPTION',
message: 'You must supply options.moduleName for UMD bundles'
});
} }
warnOnBuiltins( bundle ); warnOnBuiltins( bundle );

14
src/rollup.js

@ -4,6 +4,7 @@ import { writeFile } from './utils/fs.js';
import { assign, keys } from './utils/object.js'; import { assign, keys } from './utils/object.js';
import { mapSequence } from './utils/promise.js'; import { mapSequence } from './utils/promise.js';
import validateKeys from './utils/validateKeys.js'; import validateKeys from './utils/validateKeys.js';
import error from './utils/error.js';
import { SOURCEMAPPING_URL } from './utils/sourceMappingURL.js'; import { SOURCEMAPPING_URL } from './utils/sourceMappingURL.js';
import Bundle from './Bundle.js'; import Bundle from './Bundle.js';
@ -50,15 +51,15 @@ function checkOptions ( options ) {
return new Error( 'The `transform`, `load`, `resolveId` and `resolveExternal` options are deprecated in favour of a unified plugin API. See https://github.com/rollup/rollup/wiki/Plugins for details' ); return new Error( 'The `transform`, `load`, `resolveId` and `resolveExternal` options are deprecated in favour of a unified plugin API. See https://github.com/rollup/rollup/wiki/Plugins for details' );
} }
const error = validateKeys( keys(options), ALLOWED_KEYS ); const err = validateKeys( keys(options), ALLOWED_KEYS );
if ( error ) return error; if ( err ) return err;
return null; return null;
} }
export function rollup ( options ) { export function rollup ( options ) {
const error = checkOptions ( options ); const err = checkOptions ( options );
if ( error ) return Promise.reject( error ); if ( err ) return Promise.reject( err );
const bundle = new Bundle( options ); const bundle = new Bundle( options );
@ -105,7 +106,10 @@ export function rollup ( options ) {
generate, generate,
write: options => { write: options => {
if ( !options || !options.dest ) { if ( !options || !options.dest ) {
throw new Error( 'You must supply options.dest to bundle.write' ); error({
code: 'MISSING_OPTION',
message: 'You must supply options.dest to bundle.write'
});
} }
const dest = options.dest; const dest = options.dest;

5
src/utils/collapseSourcemaps.js

@ -1,4 +1,5 @@
import { encode } from 'sourcemap-codec'; import { encode } from 'sourcemap-codec';
import error from './error.js';
import { dirname, relative, resolve } from './path.js'; import { dirname, relative, resolve } from './path.js';
class Source { class Source {
@ -51,7 +52,9 @@ class Link {
} else if ( sourcesContent[ sourceIndex ] == null ) { } else if ( sourcesContent[ sourceIndex ] == null ) {
sourcesContent[ sourceIndex ] = traced.source.content; sourcesContent[ sourceIndex ] = traced.source.content;
} else if ( traced.source.content != null && sourcesContent[ sourceIndex ] !== traced.source.content ) { } else if ( traced.source.content != null && sourcesContent[ sourceIndex ] !== traced.source.content ) {
throw new Error( `Multiple conflicting contents for sourcemap source ${source.filename}` ); error({
message: `Multiple conflicting contents for sourcemap source ${source.filename}`
});
} }
segment[1] = sourceIndex; segment[1] = sourceIndex;

9
src/utils/defaults.js

@ -1,6 +1,7 @@
import { lstatSync, readdirSync, readFileSync, realpathSync } from './fs.js'; // eslint-disable-line import { lstatSync, readdirSync, readFileSync, realpathSync } from './fs.js'; // eslint-disable-line
import { basename, dirname, isAbsolute, resolve } from './path.js'; import { basename, dirname, isAbsolute, resolve } from './path.js';
import { blank } from './object.js'; import { blank } from './object.js';
import error from './error.js';
export function load ( id ) { export function load ( id ) {
return readFileSync( id, 'utf-8' ); return readFileSync( id, 'utf-8' );
@ -27,7 +28,13 @@ function addJsExtensionIfNecessary ( file ) {
} }
export function resolveId ( importee, importer ) { export function resolveId ( importee, importer ) {
if ( typeof process === 'undefined' ) throw new Error( `It looks like you're using Rollup in a non-Node.js environment. This means you must supply a plugin with custom resolveId and load functions. See https://github.com/rollup/rollup/wiki/Plugins for more information` ); if ( typeof process === 'undefined' ) {
error({
code: 'MISSING_PROCESS',
message: `It looks like you're using Rollup in a non-Node.js environment. This means you must supply a plugin with custom resolveId and load functions`,
url: 'https://github.com/rollup/rollup/wiki/Plugins'
});
}
// absolute paths are left untouched // absolute paths are left untouched
if ( isAbsolute( importee ) ) return addJsExtensionIfNecessary( resolve( importee ) ); if ( isAbsolute( importee ) ) return addJsExtensionIfNecessary( resolve( importee ) );

Loading…
Cancel
Save