Skip to content

Commit

Permalink
Merge pull request #1731 from ankeetmaini/promiseable-config
Browse files Browse the repository at this point in the history
Adds support for Promises returned in config, fixes #1503
  • Loading branch information
lukastaegert committed Nov 22, 2017
2 parents 3bf44e8 + 8c5bdd4 commit a11c5a2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 21 deletions.
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.

0 comments on commit a11c5a2

Please sign in to comment.