Skip to content

Commit 28859f8

Browse files
committed
fixup!
1 parent a0dbd58 commit 28859f8

File tree

2 files changed

+10
-36
lines changed

2 files changed

+10
-36
lines changed

src/utils/configuration/__tests__/index.test.mjs

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ describe('config.mjs', () => {
137137
threads: 2,
138138
});
139139

140+
console.log(config);
141+
140142
assert.strictEqual(config.global.input, 'custom-src/');
141143
assert.strictEqual(config.global.output, 'custom-dist/');
142144
assert.strictEqual(config.threads, 2);
@@ -220,34 +222,6 @@ describe('config.mjs', () => {
220222
});
221223
});
222224

223-
describe('merge behavior', () => {
224-
it('should handle array concatenation', async () => {
225-
mockImportFromURL.mock.mockImplementationOnce(async () =>
226-
createMockConfig({ global: { ignore: ['node_modules/'] } })
227-
);
228-
229-
const config = await createRunConfiguration({
230-
configFile: 'config.mjs',
231-
ignore: ['dist/'],
232-
});
233-
234-
assert.ok(Array.isArray(config.global.ignore));
235-
});
236-
237-
it('should prefer earlier non-array values', async () => {
238-
mockImportFromURL.mock.mockImplementationOnce(async () =>
239-
createMockConfig({ global: { minify: false } })
240-
);
241-
242-
const config = await createRunConfiguration({
243-
configFile: 'config.mjs',
244-
minify: true,
245-
});
246-
247-
assert.strictEqual(config.global.minify, false);
248-
});
249-
});
250-
251225
describe('transformation optimization', () => {
252226
const testCases = [
253227
{

src/utils/misc.mjs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,20 @@ export const deepMerge = (...objects) => {
2929
const base = objects.pop();
3030

3131
return objects.reduce((result, source) => {
32-
// Skip null/undefined values
33-
if (!source) {
34-
return result;
35-
}
36-
3732
for (const key in source) {
3833
if (Object.prototype.hasOwnProperty.call(source, key)) {
3934
const sourceValue = source[key];
35+
const isSourcePlainObject = isPlainObject(sourceValue);
36+
4037
const targetValue = result[key];
38+
const baseValue = base[key];
4139

4240
result[key] =
43-
isPlainObject(targetValue) && isPlainObject(sourceValue)
44-
? deepMerge(targetValue, sourceValue, base[key])
45-
: sourceValue;
41+
isSourcePlainObject && isPlainObject(targetValue)
42+
? deepMerge(targetValue, sourceValue, baseValue ?? {})
43+
: isSourcePlainObject && isPlainObject(baseValue)
44+
? deepMerge(sourceValue, baseValue)
45+
: (sourceValue ?? baseValue);
4646
}
4747
}
4848

0 commit comments

Comments
 (0)