Skip to content

Merging configs should be by prioritize. #864

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

Merged
merged 1 commit into from
Aug 4, 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
31 changes: 26 additions & 5 deletions __tests__/lib/merge_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,30 @@ test('bad config', async function() {
}
});

test('nc(mergeConfig)', function(done) {
test('right merging package configuration', async function() {
// Omit configuration from output, for simplicity
var nc = _.curryRight(_.omit, 2)([
'config',
'no-package',
'parseExtension',
'project-homepage',
'project-version'
]);
return mergeConfig({
config: path.join(__dirname, '../config_fixture/config.json'),
'no-package': true,
'project-name': 'cool Documentation'
})
.then(nc)
.then(res => {
expect(res).toEqual({
'project-name': 'cool Documentation',
foo: 'bar'
});
});
});

test('nc(mergeConfig)', async function() {
// Omit configuration from output, for simplicity
var nc = _.curryRight(_.omit, 2)([
'config',
Expand All @@ -21,7 +44,7 @@ test('nc(mergeConfig)', function(done) {
'project-version'
]);

Promise.all(
return Promise.all(
[
[
{ config: path.join(__dirname, '../config_fixture/config.json') },
Expand Down Expand Up @@ -74,7 +97,5 @@ test('nc(mergeConfig)', function(done) {
expect(res).toEqual(pair[1]);
})
)
).then(res => {
done();
});
);
});
19 changes: 7 additions & 12 deletions src/merge_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
var yaml = require('js-yaml'),
fs = require('fs'),
pify = require('pify'),
_ = require('lodash'),
readPkgUp = require('read-pkg-up'),
path = require('path'),
stripComments = require('strip-json-comments');
Expand All @@ -29,7 +28,7 @@ function processToc(config: DocumentationConfig, absFilePath: string) {
* values of `name` and `version` config.
*
* @param {Object} config the user-provided config, usually via argv
* @returns {Object} configuration with inferred parameters
* @returns {Promise<Object>} configuration with inferred parameters
* @throws {Error} if the file cannot be read.
*/
function mergePackage(config: Object): Promise<Object> {
Expand All @@ -38,16 +37,12 @@ function mergePackage(config: Object): Promise<Object> {
}
return (
readPkgUp()
.then(pkg =>
_.defaults(
{},
_.mapKeys(
_.pick(pkg.pkg, ['name', 'homepage', 'version']),
(val, key) => `project-${key}`
),
config
)
)
.then(pkg => {
['name', 'homepage', 'version'].forEach(key => {
config[`project-${key}`] = config[`project-${key}`] || pkg.pkg[key];
});
return config;
})
// Allow this to fail: this inference is not required.
.catch(() => config)
);
Expand Down