Skip to content

Commit

Permalink
Fix: Fix CJS/ESM build issues (#55)
Browse files Browse the repository at this point in the history
* fix: fix esm build, remove lodash dependency

* fix: fix esm build, remove lodash dependency
  • Loading branch information
jonluca authored Mar 30, 2023
1 parent 4ae492a commit fb59ce0
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 17 deletions.
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@
"author": "OpenAPI Contrib",
"license": "MIT",
"dependencies": {
"fast-deep-equal": "^3.1.3",
"lodash-es": "^4.17.21"
"fast-deep-equal": "^3.1.3"
},
"devDependencies": {
"@types/json-schema": "^7.0.11",
"@types/lodash-es": "^4.17.7",
"@typescript-eslint/eslint-plugin": "^5.57.0",
"@typescript-eslint/parser": "^5.57.0",
"c8": "^7.13.0",
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import deepEqual from "fast-deep-equal";
import { fromSchema, fromParameter } from "./lib/convert";
import type { Options, OptionsInternal, OpenAPI3 } from "./openapi-schema-types";
import { NOT_SUPPORTED, STRUCTS } from "./consts";
import { cloneDeep } from "lodash-es";
import type { JSONSchema4 } from "json-schema";
import type { ParameterObject, ResponseObject } from "openapi-typescript/src/types";
import { cloneDeep } from "./lib/utils/cloneDeep";
const patternPropertiesHandler = (schema) => {
let pattern;
const patternsObj = schema.patternProperties;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/converters/schema.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { isObject } from "../utils/isObject";
import InvalidTypeError from "../errors/invalid-type-error";
import type { OptionsInternal } from "../../openapi-schema-types";
import { cloneDeep } from "lodash-es";
import type { JSONSchema4, JSONSchema4TypeName } from "json-schema";
import { VALID_OPENAPI_FORMATS } from "../../consts";
import type { SchemaObject } from "openapi-typescript/src/types";
import type { PatternPropertiesHandler } from "../../openapi-schema-types";
import type { OpenAPI3 } from "openapi-typescript";
import type { ReferenceObject } from "openapi-typescript/src/types";
import { cloneDeep } from "../utils/cloneDeep";

// Convert from OpenAPI 3.0 `SchemaObject` to JSON schema v4
function convertFromSchema<T extends OpenAPI3 = OpenAPI3>(schema: T, options: OptionsInternal): JSONSchema4 {
Expand Down
47 changes: 47 additions & 0 deletions src/lib/utils/cloneDeep.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Fromhttps://dev.to/salyadav/deep-clone-of-js-objects-with-circular-dependency-4if7
const isArray = (val) => {
return Array.isArray(val);
};

const isObject = (val) => {
return {}.toString.call(val) === "[object Object]" && !isArray(val);
};

export const cloneDeep = (val, history = new Set()) => {
const stack = history || new Set();

if (stack.has(val)) {
return val;
}

stack.add(val);

const copyObject = (o) => {
const oo = Object.create({});
for (const k in o) {
oo[k] = cloneDeep(o[k], stack);
}
return oo;
};

const copyArray = (a) => {
return [...a].map((e) => {
if (isArray(e)) {
return copyArray(e);
} else if (isObject(e)) {
return copyObject(e);
}
return cloneDeep(e, stack);
});
};

if (isArray(val)) {
return copyArray(val);
}

if (isObject(val)) {
return copyObject(val);
}

return val;
};
12 changes: 0 additions & 12 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -650,18 +650,6 @@
resolved "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.11.tgz#d421b6c527a3037f7c84433fd2c4229e016863d3"
integrity sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==

"@types/lodash-es@^4.17.7":
version "4.17.7"
resolved "https://registry.npmjs.org/@types/lodash-es/-/lodash-es-4.17.7.tgz#22edcae9f44aff08546e71db8925f05b33c7cc40"
integrity sha512-z0ptr6UI10VlU6l5MYhGwS4mC8DZyYer2mCoyysZtSF7p26zOX8UpbrV0YpNYLGS8K4PUFIyEr62IMFFjveSiQ==
dependencies:
"@types/lodash" "*"

"@types/lodash@*":
version "4.14.192"
resolved "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.192.tgz#5790406361a2852d332d41635d927f1600811285"
integrity sha512-km+Vyn3BYm5ytMO13k9KTp27O75rbQ0NFw+U//g+PX7VZyjCioXaRFisqSIJRECljcTv73G3i6BpglNGHgUQ5A==

"@types/minimist@^1.2.0":
version "1.2.2"
resolved "https://registry.npmjs.org/@types/minimist/-/minimist-1.2.2.tgz#ee771e2ba4b3dc5b372935d549fd9617bf345b8c"
Expand Down

0 comments on commit fb59ce0

Please sign in to comment.