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 1 commit
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
};
11 changes: 11 additions & 0 deletions test/cli/samples/config-promise/_expected.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(function (global, factory) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Including this file does not have an effect as it is only checked if you do NOT set execute: true in _config.js. You should remove it as it is rather confusing (and while you are at it, remove it from the cli/config test as well 😜)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You got it!

typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
global.myBundle = factory();
}(this, function () { 'use strict';

var main = 42;

return main;

}));
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 })
]
});