From 25c7c1a49637b503c9154a0f27119e9d6fbdb8fd Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 25 Oct 2021 16:53:35 -0400 Subject: [PATCH] Bump @types/js-yaml from 4.0.2 to 4.0.4 (#4124) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Sebastian Malton --- package.json | 2 +- src/common/k8s/resource-stack.ts | 28 +++++++++++++++------------- yarn.lock | 8 ++++---- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index a4f1b3521d..e88ce851f2 100644 --- a/package.json +++ b/package.json @@ -276,7 +276,7 @@ "@types/html-webpack-plugin": "^3.2.6", "@types/http-proxy": "^1.17.7", "@types/jest": "^26.0.24", - "@types/js-yaml": "^4.0.2", + "@types/js-yaml": "^4.0.4", "@types/jsdom": "^16.2.13", "@types/jsonpath": "^0.2.0", "@types/lodash": "^4.14.155", diff --git a/src/common/k8s/resource-stack.ts b/src/common/k8s/resource-stack.ts index 650650ff92..483dbeeb9b 100644 --- a/src/common/k8s/resource-stack.ts +++ b/src/common/k8s/resource-stack.ts @@ -121,30 +121,32 @@ export class ResourceStack { for(const filename of files) { const file = path.join(folderPath, filename); const raw = await fse.readFile(file); - let resourceData: string; + const data = ( + filename.endsWith(".hb") + ? hb.compile(raw.toString())(templateContext) + : raw.toString() + ).trim(); - if (filename.endsWith(".hb")) { - const template = hb.compile(raw.toString()); - - resourceData = template(templateContext); - } else { - resourceData = raw.toString(); + if (!data) { + continue; } - if (!resourceData.trim()) continue; + for (const entry of yaml.loadAll(data)) { + if (typeof entry !== "object" || !entry) { + continue; + } - const resourceArray = yaml.loadAll(resourceData.toString()); + const resource = entry as Record; - resourceArray.forEach((resource) => { - if (resource?.metadata) { - resource.metadata.labels ||= {}; + if (typeof resource.metadata === "object") { + resource.metadata.labels ??= {}; resource.metadata.labels["app.kubernetes.io/name"] = this.name; resource.metadata.labels["app.kubernetes.io/managed-by"] = productName; resource.metadata.labels["app.kubernetes.io/created-by"] = "resource-stack"; } resources.push(yaml.dump(resource)); - }); + } } return resources; diff --git a/yarn.lock b/yarn.lock index c87d34502a..003364f77c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1596,10 +1596,10 @@ jest-diff "^26.0.0" pretty-format "^26.0.0" -"@types/js-yaml@^4.0.1", "@types/js-yaml@^4.0.2": - version "4.0.2" - resolved "https://registry.yarnpkg.com/@types/js-yaml/-/js-yaml-4.0.2.tgz#4117a7a378593a218e9d6f0ef44ce6d5d9edf7fa" - integrity sha512-KbeHS/Y4R+k+5sWXEYzAZKuB1yQlZtEghuhRxrVRLaqhtoG5+26JwQsa4HyS3AWX8v1Uwukma5HheduUDskasA== +"@types/js-yaml@^4.0.1", "@types/js-yaml@^4.0.4": + version "4.0.4" + resolved "https://registry.yarnpkg.com/@types/js-yaml/-/js-yaml-4.0.4.tgz#cc38781257612581a1a0eb25f1709d2b06812fce" + integrity sha512-AuHubXUmg0AzkXH0Mx6sIxeY/1C110mm/EkE/gB1sTRz3h2dao2W/63q42SlVST+lICxz5Oki2hzYA6+KnnieQ== "@types/jsdom@^16.2.13": version "16.2.13"