Skip to content

Commit fb59ce0

Browse files
authored
Fix: Fix CJS/ESM build issues (#55)
* fix: fix esm build, remove lodash dependency * fix: fix esm build, remove lodash dependency
1 parent 4ae492a commit fb59ce0

File tree

5 files changed

+50
-17
lines changed

5 files changed

+50
-17
lines changed

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,10 @@
2626
"author": "OpenAPI Contrib",
2727
"license": "MIT",
2828
"dependencies": {
29-
"fast-deep-equal": "^3.1.3",
30-
"lodash-es": "^4.17.21"
29+
"fast-deep-equal": "^3.1.3"
3130
},
3231
"devDependencies": {
3332
"@types/json-schema": "^7.0.11",
34-
"@types/lodash-es": "^4.17.7",
3533
"@typescript-eslint/eslint-plugin": "^5.57.0",
3634
"@typescript-eslint/parser": "^5.57.0",
3735
"c8": "^7.13.0",

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import deepEqual from "fast-deep-equal";
22
import { fromSchema, fromParameter } from "./lib/convert";
33
import type { Options, OptionsInternal, OpenAPI3 } from "./openapi-schema-types";
44
import { NOT_SUPPORTED, STRUCTS } from "./consts";
5-
import { cloneDeep } from "lodash-es";
65
import type { JSONSchema4 } from "json-schema";
76
import type { ParameterObject, ResponseObject } from "openapi-typescript/src/types";
7+
import { cloneDeep } from "./lib/utils/cloneDeep";
88
const patternPropertiesHandler = (schema) => {
99
let pattern;
1010
const patternsObj = schema.patternProperties;

src/lib/converters/schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { isObject } from "../utils/isObject";
22
import InvalidTypeError from "../errors/invalid-type-error";
33
import type { OptionsInternal } from "../../openapi-schema-types";
4-
import { cloneDeep } from "lodash-es";
54
import type { JSONSchema4, JSONSchema4TypeName } from "json-schema";
65
import { VALID_OPENAPI_FORMATS } from "../../consts";
76
import type { SchemaObject } from "openapi-typescript/src/types";
87
import type { PatternPropertiesHandler } from "../../openapi-schema-types";
98
import type { OpenAPI3 } from "openapi-typescript";
109
import type { ReferenceObject } from "openapi-typescript/src/types";
10+
import { cloneDeep } from "../utils/cloneDeep";
1111

1212
// Convert from OpenAPI 3.0 `SchemaObject` to JSON schema v4
1313
function convertFromSchema<T extends OpenAPI3 = OpenAPI3>(schema: T, options: OptionsInternal): JSONSchema4 {

src/lib/utils/cloneDeep.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Fromhttps://dev.to/salyadav/deep-clone-of-js-objects-with-circular-dependency-4if7
2+
const isArray = (val) => {
3+
return Array.isArray(val);
4+
};
5+
6+
const isObject = (val) => {
7+
return {}.toString.call(val) === "[object Object]" && !isArray(val);
8+
};
9+
10+
export const cloneDeep = (val, history = new Set()) => {
11+
const stack = history || new Set();
12+
13+
if (stack.has(val)) {
14+
return val;
15+
}
16+
17+
stack.add(val);
18+
19+
const copyObject = (o) => {
20+
const oo = Object.create({});
21+
for (const k in o) {
22+
oo[k] = cloneDeep(o[k], stack);
23+
}
24+
return oo;
25+
};
26+
27+
const copyArray = (a) => {
28+
return [...a].map((e) => {
29+
if (isArray(e)) {
30+
return copyArray(e);
31+
} else if (isObject(e)) {
32+
return copyObject(e);
33+
}
34+
return cloneDeep(e, stack);
35+
});
36+
};
37+
38+
if (isArray(val)) {
39+
return copyArray(val);
40+
}
41+
42+
if (isObject(val)) {
43+
return copyObject(val);
44+
}
45+
46+
return val;
47+
};

yarn.lock

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -650,18 +650,6 @@
650650
resolved "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.11.tgz#d421b6c527a3037f7c84433fd2c4229e016863d3"
651651
integrity sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==
652652

653-
"@types/lodash-es@^4.17.7":
654-
version "4.17.7"
655-
resolved "https://registry.npmjs.org/@types/lodash-es/-/lodash-es-4.17.7.tgz#22edcae9f44aff08546e71db8925f05b33c7cc40"
656-
integrity sha512-z0ptr6UI10VlU6l5MYhGwS4mC8DZyYer2mCoyysZtSF7p26zOX8UpbrV0YpNYLGS8K4PUFIyEr62IMFFjveSiQ==
657-
dependencies:
658-
"@types/lodash" "*"
659-
660-
"@types/lodash@*":
661-
version "4.14.192"
662-
resolved "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.192.tgz#5790406361a2852d332d41635d927f1600811285"
663-
integrity sha512-km+Vyn3BYm5ytMO13k9KTp27O75rbQ0NFw+U//g+PX7VZyjCioXaRFisqSIJRECljcTv73G3i6BpglNGHgUQ5A==
664-
665653
"@types/minimist@^1.2.0":
666654
version "1.2.2"
667655
resolved "https://registry.npmjs.org/@types/minimist/-/minimist-1.2.2.tgz#ee771e2ba4b3dc5b372935d549fd9617bf345b8c"

0 commit comments

Comments
 (0)