diff --git a/lib/config/definitions.js b/lib/config/definitions.js index 99ef31037746573a0a9183f26d685ed7db144214..c518f6a5877b9105359d4ccc163098d41040634c 100644 --- a/lib/config/definitions.js +++ b/lib/config/definitions.js @@ -154,6 +154,7 @@ const options = [ description: 'String copy of npmrc file. Use \\n instead of line breaks', stage: 'branch', type: 'string', + mergeable: 'true', }, { name: 'yarnrc', diff --git a/lib/config/index.js b/lib/config/index.js index 97c850a381c6df6e88057f5b23d716bd1a049005..60ca1a110c1e9ceb1271291990dd3dccebf2a4de 100644 --- a/lib/config/index.js +++ b/lib/config/index.js @@ -126,6 +126,8 @@ function mergeChildConfig(parentConfig, childConfig) { config[option.name] = (parentConfig[option.name] || []).concat( config[option.name] || [] ); + } else if (option.type === 'string') { + config[option.name] = parentConfig[option.name] + config[option.name]; } else { config[option.name] = { ...parentConfig[option.name], diff --git a/test/config/__snapshots__/index.spec.js.snap b/test/config/__snapshots__/index.spec.js.snap index 73df5d60dca5903b72ce29704bc547a9a64c6cc9..56c31694d8c4b02c2a60b8953f2c7438bd966b87 100644 --- a/test/config/__snapshots__/index.spec.js.snap +++ b/test/config/__snapshots__/index.spec.js.snap @@ -1,5 +1,12 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`config/index mergeChildConfig(parentConfig, childConfig) handles mergeable strings 1`] = ` +"_auth=abcd-abcd-abcd-abcd +always-auth=true +registry=some-registry +" +`; + exports[`config/index mergeChildConfig(parentConfig, childConfig) merges 1`] = ` Object { "branchName": "{{branchPrefix}}lock-file-maintenance", diff --git a/test/config/index.spec.js b/test/config/index.spec.js index 582a3cddd9fa06f0ae02a854ac704a5acfcf08b3..87ddd5924f58f073b35b984553eb33f7ccc3dbbb 100644 --- a/test/config/index.spec.js +++ b/test/config/index.spec.js @@ -235,5 +235,15 @@ describe('config/index', () => { const config = configParser.mergeChildConfig(parentConfig, undefined); expect(config).toMatchObject(parentConfig); }); + it('handles mergeable strings', () => { + const parentConfig = { ...defaultConfig }; + parentConfig.npmrc = '_auth=abcd-abcd-abcd-abcd\n'; + const childConfig = { + npmrc: 'always-auth=true\nregistry=some-registry\n', + }; + const configParser = require('../../lib/config/index.js'); + const config = configParser.mergeChildConfig(parentConfig, childConfig); + expect(config.npmrc).toMatchSnapshot(); + }); }); });