Skip to content

Commit

Permalink
fix: remove use of lodash merge from $RefPlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
DavieReid committed Jul 11, 2023
1 parent 1974ea6 commit 6511d7c
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 37 deletions.
2 changes: 1 addition & 1 deletion packages/plugins/package.json
Expand Up @@ -32,7 +32,7 @@
"@types/fs-extra": "^9.0.13"
},
"dependencies": {
"@apidevtools/json-schema-ref-parser": "^9.0.9",
"@apidevtools/json-schema-ref-parser": "^10.1.0",
"@jpmorganchase/mosaic-schemas": "^0.1.0-beta.38",
"@jpmorganchase/mosaic-serialisers": "^0.1.0-beta.38",
"@jpmorganchase/mosaic-source-git-repo": "^0.1.0-beta.38",
Expand Down
48 changes: 24 additions & 24 deletions packages/plugins/src/$RefPlugin.ts
@@ -1,6 +1,6 @@
import path from 'path';
import { reduce, omit, merge, escapeRegExp } from 'lodash-es';
import $RefParser from '@apidevtools/json-schema-ref-parser';
import { reduce, omit, escapeRegExp } from 'lodash-es';
import { $RefParser } from '@apidevtools/json-schema-ref-parser';
import type { Plugin as PluginType } from '@jpmorganchase/mosaic-types';

import normaliseRefs from './utils/normaliseRefs.js';
Expand Down Expand Up @@ -72,16 +72,17 @@ const $RefPlugin: PluginType<RefsPluginPage, unknown, RefsPluginConfigData> = {
) {
mutableFilesystem.__internal_do_not_use_addReadFileHook(async (pagePath: string, fileData) => {
if (globalConfig.data.globalRefs[pagePath]) {
const normalisedRef = merge(
await serialiser.deserialise(pagePath, fileData),
await normaliseRefs(
String(pagePath),
globalConfig.data.globalRefs[pagePath],
globalFilesystem,
pageExtensions,
ignorePages
)
const expandedRefs = await normaliseRefs(
String(pagePath),
globalConfig.data.globalRefs[pagePath],
globalFilesystem,
pageExtensions,
ignorePages
);

const page = await serialiser.deserialise(pagePath, fileData);
const normalisedRef = { ...page, ...expandedRefs };

const resolve = createRefResolver(
{
[pagePath]: normalisedRef
Expand All @@ -96,10 +97,10 @@ const $RefPlugin: PluginType<RefsPluginPage, unknown, RefsPluginConfigData> = {
resolve,
dereference: { circular: false }
});
const serialisedPage = await serialiser.serialise(
pagePath,
merge(normalisedRef, resolved)
);
const serialisedPage = await serialiser.serialise(pagePath, {
...normalisedRef,
...resolved
});
return serialisedPage;
} catch (e) {
console.warn(
Expand Down Expand Up @@ -130,16 +131,15 @@ const $RefPlugin: PluginType<RefsPluginPage, unknown, RefsPluginConfigData> = {
fullPath,
await mutableFilesystem.promises.readFile(fullPath)
);
normalisedRefs[fullPath] = merge(
page,
await normaliseRefs(
String(fullPath),
config.data.refs[fullPath],
mutableFilesystem,
pageExtensions,
ignorePages
)

const expandedRefs = await normaliseRefs(
String(fullPath),
config.data.refs[fullPath],
mutableFilesystem,
pageExtensions,
ignorePages
);
normalisedRefs[fullPath] = { ...page, ...expandedRefs };
}

const resolve = createRefResolver(normalisedRefs, serialiser, mutableFilesystem);
Expand Down
37 changes: 25 additions & 12 deletions yarn.lock
Expand Up @@ -15,15 +15,16 @@
"@jridgewell/gen-mapping" "^0.1.0"
"@jridgewell/trace-mapping" "^0.3.9"

"@apidevtools/json-schema-ref-parser@^9.0.9":
version "9.0.9"
resolved "https://registry.yarnpkg.com/@apidevtools/json-schema-ref-parser/-/json-schema-ref-parser-9.0.9.tgz#d720f9256e3609621280584f2b47ae165359268b"
integrity sha1-1yD5JW42CWISgFhPK0euFlNZJos=
"@apidevtools/json-schema-ref-parser@^10.1.0":
version "10.1.0"
resolved "https://registry.yarnpkg.com/@apidevtools/json-schema-ref-parser/-/json-schema-ref-parser-10.1.0.tgz#bf54494039a56fa7f77fed17dc6f01dfde50f64c"
integrity sha512-3e+viyMuXdrcK8v5pvP+SDoAQ77FH6OyRmuK48SZKmdHJRFm87RsSs8qm6kP39a/pOPURByJw+OXzQIqcfmKtA==
dependencies:
"@jsdevtools/ono" "^7.1.3"
"@types/json-schema" "^7.0.6"
call-me-maybe "^1.0.1"
"@types/json-schema" "^7.0.11"
"@types/lodash.clonedeep" "^4.5.7"
js-yaml "^4.1.0"
lodash.clonedeep "^4.5.0"

"@aws-crypto/crc32@3.0.0":
version "3.0.0"
Expand Down Expand Up @@ -3449,7 +3450,12 @@
"@types/tough-cookie" "*"
parse5 "^7.0.0"

"@types/json-schema@^7.0.6", "@types/json-schema@^7.0.9":
"@types/json-schema@^7.0.11":
version "7.0.12"
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.12.tgz#d70faba7039d5fca54c83c7dbab41051d2b6f6cb"
integrity sha512-Hr5Jfhc9eYOQNPYO5WLDq/n4jqijdHNlDXjuAQkkt+mWdQR+XJToOHrsD4cPaMXpn6KO7y2+wM8AZEs8VpBLVA==

"@types/json-schema@^7.0.9":
version "7.0.11"
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.11.tgz#d421b6c527a3037f7c84433fd2c4229e016863d3"
integrity sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==
Expand All @@ -3466,6 +3472,13 @@
dependencies:
"@types/lodash" "*"

"@types/lodash.clonedeep@^4.5.7":
version "4.5.7"
resolved "https://registry.yarnpkg.com/@types/lodash.clonedeep/-/lodash.clonedeep-4.5.7.tgz#0e119f582ed6f9e6b373c04a644651763214f197"
integrity sha512-ccNqkPptFIXrpVqUECi60/DFxjNKsfoQxSQsgcBJCX/fuX1wgyQieojkcWH/KpE3xzLoWN/2k+ZeGqIN3paSvw==
dependencies:
"@types/lodash" "*"

"@types/lodash@*":
version "4.14.189"
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.189.tgz#975ff8c38da5ae58b751127b19ad5e44b5b7f6d2"
Expand Down Expand Up @@ -4556,11 +4569,6 @@ call-bind@^1.0.0, call-bind@^1.0.2:
function-bind "^1.1.1"
get-intrinsic "^1.0.2"

call-me-maybe@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/call-me-maybe/-/call-me-maybe-1.0.1.tgz#26d208ea89e37b5cbde60250a15f031c16a4d66b"
integrity sha1-JtII6onje1y95gJQoV8DHBak1ms=

callsites@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/callsites/-/callsites-3.1.0.tgz#b3630abd8943432f54b3f0519238e33cd7df2f73"
Expand Down Expand Up @@ -8724,6 +8732,11 @@ lodash-es@^4.17.15, lodash-es@^4.17.21:
resolved "https://registry.yarnpkg.com/lodash-es/-/lodash-es-4.17.21.tgz#43e626c46e6591b7750beb2b50117390c609e3ee"
integrity sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==

lodash.clonedeep@^4.5.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz#e23f3f9c4f8fbdde872529c1071857a086e5ccef"
integrity sha512-H5ZhCF25riFd9uB5UCkVKo61m3S/xZk1x4wA6yp/L3RFP6Z/eHH1ymQcGLo7J3GMPfm0V/7m1tryHuGVxpqEBQ==

lodash.debounce@^4:
version "4.0.8"
resolved "https://registry.yarnpkg.com/lodash.debounce/-/lodash.debounce-4.0.8.tgz#82d79bff30a67c4005ffd5e2515300ad9ca4d7af"
Expand Down

0 comments on commit 6511d7c

Please sign in to comment.