Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing input options to output #3223

Merged
merged 1 commit into from Nov 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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')
);
});
});