Skip to content

Commit

Permalink
Allow passing input options to output (#3223)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Nov 11, 2019
1 parent 6fed410 commit af8801b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/rollup/index.ts
Expand Up @@ -439,7 +439,11 @@ function normalizeOutputOptions(
}
const mergedOptions = mergeOptions({
config: {
output: { ...rawOutputOptions, ...(inputOptions.output as Object) }
output: {
...rawOutputOptions,
...(rawOutputOptions.output as Object),
...(inputOptions.output as Object)
}
}
});

Expand Down
30 changes: 25 additions & 5 deletions test/misc/misc.js
Expand Up @@ -3,7 +3,7 @@ const rollup = require('../../dist/rollup');
const { loader } = require('../utils.js');

describe('misc', () => {
it('throw modification of options or its property', () => {
it('avoids modification of options or their properties', () => {
const { freeze } = Object;
return rollup.rollup(
freeze({
Expand Down Expand Up @@ -118,12 +118,11 @@ describe('misc', () => {
});
});

it('ignores falsy plugins', () => {
return rollup.rollup({
it('ignores falsy plugins', () =>
rollup.rollup({
input: 'x',
plugins: [loader({ x: `console.log( 42 );` }), null, false, undefined]
});
});
}));

it('handles different import paths for different outputs', () => {
return rollup
Expand Down Expand Up @@ -156,4 +155,25 @@ describe('misc', () => {
])
);
});

it('allows passing the same object to `rollup` and `generate`', () => {
const options = {
input: 'input',
plugins: [
loader({
input: 'export default 42;'
})
],
output: {
format: 'esm'
}
};

return rollup
.rollup(options)
.then(bundle => bundle.generate(options))
.then(output =>
assert.strictEqual(output.output[0].code, 'var input = 42;\n\nexport default input;\n')
);
});
});

0 comments on commit af8801b

Please sign in to comment.