From 48e3cefe4fd08be379cf510e46792ca5ad451961 Mon Sep 17 00:00:00 2001 From: Release commit workflow Date: Tue, 11 Jun 2024 18:02:22 +0000 Subject: [PATCH 01/10] =?UTF-8?q?chore(release):=20v0.4.0-beta.0=20?= =?UTF-8?q?=E2=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 638b4e48a..31c8523d2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@grnsft/if", - "version": "0.3.4", + "version": "0.4.0-beta.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@grnsft/if", - "version": "0.3.4", + "version": "0.4.0-beta.0", "license": "MIT", "dependencies": { "@commitlint/cli": "^18.6.0", diff --git a/package.json b/package.json index 60e33dc0f..ef8a754a4 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@grnsft/if", "description": "Impact Framework", - "version": "0.3.4", + "version": "0.4.0-beta.0", "author": { "name": "Green Software Foundation", "email": "info@gsf.com" From 2fd2d62a667280672e20faeeb0b7d08a2524236b Mon Sep 17 00:00:00 2001 From: Narek Hovhannisyan Date: Wed, 12 Jun 2024 20:55:33 +0400 Subject: [PATCH 02/10] =?UTF-8?q?chore(release):=20v0.4.0-beta.1=20?= =?UTF-8?q?=E2=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 31c8523d2..736858023 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@grnsft/if", - "version": "0.4.0-beta.0", + "version": "0.4.0-beta.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@grnsft/if", - "version": "0.4.0-beta.0", + "version": "0.4.0-beta.1", "license": "MIT", "dependencies": { "@commitlint/cli": "^18.6.0", diff --git a/package.json b/package.json index ef8a754a4..718c4b4e4 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@grnsft/if", "description": "Impact Framework", - "version": "0.4.0-beta.0", + "version": "0.4.0-beta.1", "author": { "name": "Green Software Foundation", "email": "info@gsf.com" From 0c4de5921b8ac7c3bb584a75ddd27304d3fbd0f8 Mon Sep 17 00:00:00 2001 From: manushak Date: Thu, 13 Jun 2024 14:42:36 +0400 Subject: [PATCH 03/10] fix(src): call `overrideConsoleMethods(false)` to prevent show debug logs --- src/diff.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/diff.ts b/src/diff.ts index 7deb09e35..75a5450dd 100644 --- a/src/diff.ts +++ b/src/diff.ts @@ -9,6 +9,7 @@ import {validateManifest} from './util/validations'; import {CONFIG} from './config'; import {logger} from './util/logger'; +import {debugLogger} from './util/debug-logger'; const {IF_DIFF} = CONFIG; const {SUCCESS_MESSAGE, FAILURE_MESSAGE} = IF_DIFF; @@ -16,6 +17,9 @@ const {SUCCESS_MESSAGE, FAILURE_MESSAGE} = IF_DIFF; const IfDiff = async () => { const {sourcePath, targetPath} = parseIfDiffArgs(); + // Call this function with false parameter to prevent log debug messages. + debugLogger.overrideConsoleMethods(false); + const {rawSourceManifest, rawTargetManifest} = await loadIfDiffFiles({ targetPath, sourcePath, From 7e6772d4772af74cfb177de137acd9e46e36fe7f Mon Sep 17 00:00:00 2001 From: Narek Hovhannisyan Date: Thu, 13 Jun 2024 18:47:43 +0400 Subject: [PATCH 04/10] feat(src): read all piped data before checking params --- src/diff.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/diff.ts b/src/diff.ts index 7deb09e35..af61ae380 100644 --- a/src/diff.ts +++ b/src/diff.ts @@ -4,7 +4,7 @@ import {loadIfDiffFiles} from './lib/load'; import {compare} from './lib/compare'; import {parseIfDiffArgs} from './util/args'; -import {formatNotMatchingLog} from './util/helpers'; +import {formatNotMatchingLog, parseManifestFromStdin} from './util/helpers'; import {validateManifest} from './util/validations'; import {CONFIG} from './config'; @@ -14,11 +14,13 @@ const {IF_DIFF} = CONFIG; const {SUCCESS_MESSAGE, FAILURE_MESSAGE} = IF_DIFF; const IfDiff = async () => { + const pipedSourceManifest = await parseManifestFromStdin(); const {sourcePath, targetPath} = parseIfDiffArgs(); const {rawSourceManifest, rawTargetManifest} = await loadIfDiffFiles({ targetPath, sourcePath, + pipedSourceManifest, }); const [sourceManifest, targetManifest] = [ rawSourceManifest, From d4a492b6825ec881bd2be1dd87f34cae79b74e4a Mon Sep 17 00:00:00 2001 From: Narek Hovhannisyan Date: Thu, 13 Jun 2024 18:48:53 +0400 Subject: [PATCH 05/10] test(lib): fix load if diff cases --- src/__tests__/unit/lib/load.test.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/__tests__/unit/lib/load.test.ts b/src/__tests__/unit/lib/load.test.ts index f9ad3e73b..95ae6b26b 100644 --- a/src/__tests__/unit/lib/load.test.ts +++ b/src/__tests__/unit/lib/load.test.ts @@ -45,6 +45,8 @@ import {PARAMETERS} from '../../../config'; import {PluginParams} from '../../../types/interface'; import {STRINGS} from '../../../config'; +import {parseManifestFromStdin} from '../../../util/helpers'; +import {LoadDiffParams} from '../../../types/util/args'; const {INVALID_SOURCE} = STRINGS; @@ -109,8 +111,10 @@ describe('lib/load: ', () => { it('successfully loads target, and source from stdin.', async () => { process.env.readline = 'valid-source'; - const params = { + const piped = await parseManifestFromStdin(); + const params: LoadDiffParams = { targetPath: 'target-path.yml', + pipedSourceManifest: piped, }; const response = await loadIfDiffFiles(params); From 8cd4266b92901021e18f477ff07a6bcc15996e5c Mon Sep 17 00:00:00 2001 From: Narek Hovhannisyan Date: Thu, 13 Jun 2024 18:49:26 +0400 Subject: [PATCH 06/10] test(util): fix parseManifestFromStdin case --- src/__tests__/unit/util/helpers.test.ts | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/__tests__/unit/util/helpers.test.ts b/src/__tests__/unit/util/helpers.test.ts index d627790e4..58ed0525b 100644 --- a/src/__tests__/unit/util/helpers.test.ts +++ b/src/__tests__/unit/util/helpers.test.ts @@ -364,16 +364,11 @@ describe('util/helpers: ', () => { it('throws error if there is no manifest in stdin.', async () => { process.env.readline = 'no_manifest'; - const expectedMessage = 'Manifest not found in STDIN.'; expect.assertions(1); - try { - await parseManifestFromStdin(); - } catch (error) { - if (error instanceof Error) { - expect(error.message).toEqual(expectedMessage); - } - } + const response = await parseManifestFromStdin(); + + expect(response).toEqual(''); }); it('returns empty string if there is no data in stdin.', async () => { From 17948b6b5f2f401570607f399de6a6c103406149 Mon Sep 17 00:00:00 2001 From: Narek Hovhannisyan Date: Thu, 13 Jun 2024 18:50:10 +0400 Subject: [PATCH 07/10] fix(lib): move piped data reader --- src/lib/load.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/lib/load.ts b/src/lib/load.ts index 9b9508ded..2ed335b6f 100644 --- a/src/lib/load.ts +++ b/src/lib/load.ts @@ -3,7 +3,6 @@ import * as YAML from 'js-yaml'; import {ERRORS} from '../util/errors'; import {openYamlFileAsObject} from '../util/yaml'; import {readAndParseJson} from '../util/json'; -import {parseManifestFromStdin} from '../util/helpers'; import {PARAMETERS} from '../config'; import {STRINGS} from '../config'; @@ -41,8 +40,7 @@ export const load = async (inputPath: string, paramPath?: string) => { * Loads files to compare. As a source file checks if data is piped and then decides which one to take. */ export const loadIfDiffFiles = async (params: LoadDiffParams) => { - const {sourcePath, targetPath} = params; - const pipedSourceManifest = await parseManifestFromStdin(); + const {sourcePath, targetPath, pipedSourceManifest} = params; if (!sourcePath && !pipedSourceManifest) { throw new CliInputError(INVALID_SOURCE); From dd973179f7d78f9a29d57f94e7dc7e7d285fdbcc Mon Sep 17 00:00:00 2001 From: Narek Hovhannisyan Date: Thu, 13 Jun 2024 18:50:32 +0400 Subject: [PATCH 08/10] feat(types): add piped source manifest to load diff params --- src/types/util/args.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/types/util/args.ts b/src/types/util/args.ts index d9debf3cd..ae78fa4d0 100644 --- a/src/types/util/args.ts +++ b/src/types/util/args.ts @@ -1,4 +1,5 @@ export type LoadDiffParams = { sourcePath?: string; targetPath: string; + pipedSourceManifest?: string; }; From f14790bb2ef0484b005fa0feb03e66355063a7c0 Mon Sep 17 00:00:00 2001 From: Narek Hovhannisyan Date: Thu, 13 Jun 2024 18:51:09 +0400 Subject: [PATCH 09/10] fix(util): return empty string if no manifest found --- src/util/helpers.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util/helpers.ts b/src/util/helpers.ts index b15863cef..2b2dba87f 100644 --- a/src/util/helpers.ts +++ b/src/util/helpers.ts @@ -164,7 +164,7 @@ const collectPipedData = async () => { /** * Checks if there is piped data, tries to parse yaml from it. - * Throws error if there is piped info, but there is no valid manifest. + * Returns empty string if haven't found anything. */ export const parseManifestFromStdin = async () => { const pipedSourceManifest = await collectPipedData(); @@ -177,7 +177,7 @@ export const parseManifestFromStdin = async () => { const match = regex.exec(pipedSourceManifest); if (!match) { - throw new Error('Manifest not found in STDIN.'); + return ''; } return match![1]; From 640b0caf12fcee182592cf8d8e155b331dc62b00 Mon Sep 17 00:00:00 2001 From: Narek Hovhannisyan Date: Thu, 13 Jun 2024 18:51:41 +0400 Subject: [PATCH 10/10] fix(util): add newlines which improve readability --- src/util/validations.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/util/validations.ts b/src/util/validations.ts index 3cd1dd6b9..21695f3ee 100644 --- a/src/util/validations.ts +++ b/src/util/validations.ts @@ -9,6 +9,7 @@ import {STRINGS} from '../config/strings'; const {ManifestValidationError, InputValidationError} = ERRORS; const {VALIDATING_MANIFEST} = STRINGS; + /** * At least one property defined handler. */ @@ -148,5 +149,6 @@ const flattenPath = (path: (string | number)[]): string => { const flattenPath = path.map(part => typeof part === 'number' ? `[${part}]` : part ); + return flattenPath.join('.'); };