Skip to content

Commit e14866c

Browse files
jfinitymarionebl
authored andcommitted
fix: load and copy config module without mutation
1 parent 70e7991 commit e14866c

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

@commitlint/load/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export default async (seed = {}, options = {cwd: process.cwd()}) => {
2424
const base = loaded.filepath ? path.dirname(loaded.filepath) : options.cwd;
2525

2626
// Merge passed config with file based options
27-
const config = valid(merge(loaded.config, seed));
27+
const config = valid(merge({}, loaded.config, seed));
2828
const opts = merge(
2929
{extends: [], rules: {}, formatter: '@commitlint/format'},
3030
pick(config, 'extends', 'plugins', 'ignores', 'defaultIgnores')

@commitlint/load/src/index.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,3 +308,15 @@ test('returns formatter name when unable to resolve from config directory', asyn
308308
rules: {}
309309
});
310310
});
311+
312+
test('does not mutate config module reference', async t => {
313+
const file = 'config/commitlint.config.js';
314+
const cwd = await git.bootstrap('fixtures/specify-config-file');
315+
316+
const configPath = path.join(cwd, file);
317+
const before = JSON.stringify(require(configPath));
318+
await load({arbitraryField: true}, {cwd, file});
319+
const after = JSON.stringify(require(configPath));
320+
321+
t.is(before, after);
322+
});

0 commit comments

Comments
 (0)