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

Adds support for Promises returned in config, fixes #1503 #1731

Merged
merged 2 commits into from
Nov 22, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions bin/src/run/loadConfigFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,18 @@ export default function loadConfigFile (configFile, silent) {
};

delete require.cache[configFile];
const configs = require( configFile );
if ( Object.keys( configs ).length === 0 ) {
handleError({
code: 'MISSING_CONFIG',
message: 'Config file must export an options object, or an array of options objects',
url: 'https://github.com/rollup/rollup/wiki/Command-Line-Interface#using-a-config-file'
});
}
return Promise.resolve(require( configFile )).then(configs => {
if ( Object.keys( configs ).length === 0 ) {
handleError({
code: 'MISSING_CONFIG',
message: 'Config file must export an options object, or an array of options objects',
url: 'https://github.com/rollup/rollup/wiki/Command-Line-Interface#using-a-config-file'
});
}

require.extensions[ '.js' ] = defaultLoader;
require.extensions[ '.js' ] = defaultLoader;

return Array.isArray( configs ) ? configs : [configs];
return Array.isArray( configs ) ? configs : [configs];
});
});
}
5 changes: 5 additions & 0 deletions test/cli/samples/config-promise/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
description: 'uses config file which returns a Promise',
command: 'rollup --config rollup.config.js',
execute: true
};
1 change: 1 addition & 0 deletions test/cli/samples/config-promise/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
assert.equal( ANSWER, 42 );
9 changes: 9 additions & 0 deletions test/cli/samples/config-promise/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var replace = require( 'rollup-plugin-replace' );

module.exports = Promise.resolve({
input: 'main.js',
format: 'cjs',
plugins: [
replace({ 'ANSWER': 42 })
]
});
11 changes: 0 additions & 11 deletions test/cli/samples/config/_expected.js

This file was deleted.