Skip to content

Commit

Permalink
various minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Aug 20, 2017
1 parent 313873b commit 30cd1ca
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 26 deletions.
6 changes: 6 additions & 0 deletions bin/src/index.js
Expand Up @@ -35,5 +35,11 @@ else if ( command.version ) {
}

else {
try {
require('source-map-support').install();
} catch (err) {
// do nothing
}

run( command );
}
10 changes: 6 additions & 4 deletions bin/src/run/watch.js
Expand Up @@ -15,16 +15,18 @@ export default function watch(configFile, configs, command, silent) {

configs = configs.map(options => {
const merged = mergeOptions(options, command);
const onwarn = merged.input.onwarn;
const onwarn = merged.inputOptions.onwarn;
if ( onwarn ) {
merged.input.onwarn = warning => {
merged.inputOptions.onwarn = warning => {
onwarn( warning, warnings.add );
};
} else {
merged.input.onwarn = warnings.add;
merged.inputOptions.onwarn = warnings.add;
}

return merged;
return Object.assign({}, merged.inputOptions, {
output: merged.outputOptions
});
});

let watcher;
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions src/rollup/index.js
Expand Up @@ -16,6 +16,7 @@ const ALLOWED_KEYS = [
'banner',
'cache',
'context',
'entry',
'exports',
'extend',
'external',
Expand Down Expand Up @@ -86,7 +87,7 @@ const deprecated = {
useStrict: 'strict'
};

function checkOutputOptions ( options, onwarn ) {
function checkOutputOptions ( options, warn ) {
if ( options.format === 'es6' ) {
error({
message: 'The `es6` output format is deprecated – use `es` instead',
Expand All @@ -107,7 +108,7 @@ function checkOutputOptions ( options, onwarn ) {
options.amd = { id: options.moduleId };
delete options.moduleId;

onwarn({
warn({
message: `options.moduleId is deprecated in favour of options.amd = { id: moduleId }`
});
}
Expand All @@ -123,7 +124,7 @@ function checkOutputOptions ( options, onwarn ) {

if ( deprecations.length ) {
const message = `The following options have been renamed — please update your config: ${deprecations.map(option => `${option.old} -> ${option.new}`).join(', ')}`;
onwarn({
warn({
code: 'DEPRECATED_OPTIONS',
message,
deprecations
Expand Down Expand Up @@ -157,7 +158,7 @@ export default function rollup ( options ) {
if ( !options ) {
throw new Error( 'You must supply an options object' );
}
checkOutputOptions( options );
checkOutputOptions( options, warn );
checkAmd( options );

timeStart( '--GENERATE--' );
Expand Down
41 changes: 41 additions & 0 deletions src/utils/deprecateOptions.js
@@ -1,10 +1,51 @@
export default function deprecateOptions(options) {
const deprecations = [];

if ( options.entry ) {
deprecations.push({ old: 'options.entry', new: 'options.input' });
options.input = options.entry; // don't delete, as plugins sometimes depend on this...
}

if ( options.moduleName ) {
deprecations.push({ old: 'options.moduleName', new: 'options.name' });
options.name = options.moduleName;
delete options.moduleName;
}

if ( options.sourceMap ) {
deprecations.push({ old: 'options.sourceMap', new: 'options.sourcemap' });
options.sourcemap = options.sourceMap;
delete options.sourceMap;
}

if ( options.sourceMapFile ) {
deprecations.push({ old: 'options.sourceMapFile', new: 'options.sourcemapFile' });
options.sourcemapFile = options.sourceMapFile;
delete options.sourceMapFile;
}

if ( options.useStrict ) {
deprecations.push({ old: 'options.useStrict', new: 'options.strict' });
options.strict = options.useStrict;
delete options.useStrict;
}

if ( options.targets ) {
deprecations.push({ old: 'options.targets', new: 'options.output' });
options.output = options.targets;
delete options.targets;

let deprecatedDest = false;
options.output.forEach(output => {
if (output.dest) {
if (!deprecatedDest) {
deprecations.push({ old: 'output.dest', new: 'output.file' });
deprecatedDest = true;
}
output.file = output.dest;
delete output.dest;
}
});
} else if ( options.dest ) {
deprecations.push({ old: 'options.dest', new: 'options.output.file' });
options.output = {
Expand Down
16 changes: 1 addition & 15 deletions test/incremental/index.js
@@ -1,23 +1,9 @@
const assert = require('assert');
const acorn = require('acorn');
const { executeBundle } = require('../utils.js');
const rollup = require('../../dist/rollup');

describe('incremental', () => {
function executeBundle(bundle) {
return bundle
.generate({
format: 'cjs'
})
.then(cjs => {
const m = new Function('module', 'exports', cjs.code);

const module = { exports: {} };
m(module, module.exports);

return module.exports;
});
}

let resolveIdCalls;
let transformCalls;
let modules;
Expand Down
1 change: 1 addition & 0 deletions test/leak/index.js
Expand Up @@ -42,6 +42,7 @@ try {
require.resolve('weak');
test();
} catch (err) {
console.error(err);
console.log('installing weak');
require('child_process').exec('npm i --no-save --silent weak@1.0.1', (err, stdout, stderr) => {
if (err) {
Expand Down
22 changes: 20 additions & 2 deletions test/misc/index.js
@@ -1,6 +1,6 @@
const assert = require('assert');
const rollup = require('../../dist/rollup');
const { loader } = require('../utils.js');
const { executeBundle, loader } = require('../utils.js');

describe('sanity checks', () => {
it('exists', () => {
Expand Down Expand Up @@ -44,7 +44,7 @@ describe('sanity checks', () => {
err => {
assert.equal(
err.message,
"Unexpected key 'plUgins' found, expected one of: acorn, amd, banner, cache, context, exports, extend, external, file, footer, format, globals, indent, input, interop, intro, legacy, moduleContext, name, noConflict, onwarn, output, outro, paths, plugins, preferConst, pureExternalModules, sourcemap, sourcemapFile, strict, targets, treeshake, watch"
"Unexpected key 'plUgins' found, expected one of: acorn, amd, banner, cache, context, entry, exports, extend, external, file, footer, format, globals, indent, input, interop, intro, legacy, moduleContext, name, noConflict, onwarn, output, outro, paths, plugins, preferConst, pureExternalModules, sourcemap, sourcemapFile, strict, targets, treeshake, watch"
);
}
);
Expand Down Expand Up @@ -107,6 +107,24 @@ describe('sanity checks', () => {
});

describe('deprecations', () => {
it('warns on options.entry, but handles', () => {
const warnings = [];
return rollup.rollup({
entry: 'x',
plugins: [loader({ x: `export default 42` })],
onwarn: warning => {
warnings.push(warning);
}
}).then(executeBundle).then(result => {
assert.equal(result, 42);
assert.deepEqual(warnings, [
{
message: `options.entry is deprecated, use options.input`
}
]);
});
});

it('throws a useful error on accessing code/map properties of bundle.generate promise', () => {
return rollup
.rollup({
Expand Down
16 changes: 16 additions & 0 deletions test/utils.js
Expand Up @@ -3,6 +3,7 @@ const assert = require('assert');
exports.compareError = compareError;
exports.compareWarnings = compareWarnings;
exports.deindent = deindent;
exports.executeBundle = executeBundle;
exports.extend = extend;
exports.loadConfig = loadConfig;
exports.loader = loader;
Expand Down Expand Up @@ -50,6 +51,21 @@ function deindent(str) {
return str.slice(1).replace(/^\t+/gm, '').replace(/\s+$/gm, '').trim();
}

function executeBundle(bundle) {
return bundle
.generate({
format: 'cjs'
})
.then(cjs => {
const m = new Function('module', 'exports', cjs.code);

const module = { exports: {} };
m(module, module.exports);

return module.exports;
});
}

function extend(target) {
[].slice.call(arguments, 1).forEach(source => {
source &&
Expand Down

0 comments on commit 30cd1ca

Please sign in to comment.