diff --git a/packages/plugins/package.json b/packages/plugins/package.json index c5322911d..3e8c163a1 100644 --- a/packages/plugins/package.json +++ b/packages/plugins/package.json @@ -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", diff --git a/packages/plugins/src/$RefPlugin.ts b/packages/plugins/src/$RefPlugin.ts index ba4d1ecba..db226dafb 100644 --- a/packages/plugins/src/$RefPlugin.ts +++ b/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'; @@ -72,16 +72,17 @@ const $RefPlugin: PluginType = { ) { 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 @@ -96,10 +97,10 @@ const $RefPlugin: PluginType = { 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( @@ -130,16 +131,15 @@ const $RefPlugin: PluginType = { 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); diff --git a/yarn.lock b/yarn.lock index 22e935deb..2a51192bb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -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== @@ -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" @@ -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" @@ -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"