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

fix: merge objects with Module type #121

Merged
merged 7 commits into from
Jan 5, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/_utils.ts
Expand Up @@ -14,9 +14,13 @@ export function isPlainObject(value: unknown): boolean {
return false;
}

if (Symbol.toStringTag in value || Symbol.iterator in value) {
if (Symbol.iterator in value) {
return false;
}

if (Symbol.toStringTag in value) {
return Object.prototype.toString.call(value) === "[object Module]";
}

return true;
}
18 changes: 18 additions & 0 deletions test/defu.test.ts
@@ -1,6 +1,7 @@
import { expectTypeOf } from "expect-type";
import { it, describe, expect } from "vitest";
import { defu, createDefu, defuFn, defuArrayFn } from "../src/defu";
import * as asteriskImport from "./fixtures/";

// Part of tests brought from jonschlinkert/defaults-deep (MIT)
const nonObject = [null, undefined, [], false, true, 123];
Expand Down Expand Up @@ -232,4 +233,21 @@ describe("defu", () => {
foo: { bar: { modules: "foo.bar:X,Y" } },
});
});

it("works with asterisk-import", () => {
expect(
defu(asteriskImport, {
a: 2,
exp: {
anotherNested: 2,
},
}),
).toStrictEqual({
a: 2,
exp: {
anotherNested: 2,
nested: 1,
},
});
});
});
1 change: 1 addition & 0 deletions test/fixtures/index.ts
@@ -0,0 +1 @@
export { default as exp } from "./nested.js";
3 changes: 3 additions & 0 deletions test/fixtures/nested.ts
@@ -0,0 +1,3 @@
export default {
nested: 1,
};