From 85fbfae61e5dfd3e2c6481215482dfd8f20df379 Mon Sep 17 00:00:00 2001 From: Kiss Miklos Date: Mon, 18 Jul 2022 00:08:21 +0200 Subject: [PATCH 1/5] trim newlines when using Signed-off-by: Kiss Miklos --- .../config-loader/src/lib/transform/include.test.ts | 10 ++++++++++ packages/config-loader/src/lib/transform/include.ts | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/config-loader/src/lib/transform/include.test.ts b/packages/config-loader/src/lib/transform/include.test.ts index 0913b31f66..ad1a35102d 100644 --- a/packages/config-loader/src/lib/transform/include.test.ts +++ b/packages/config-loader/src/lib/transform/include.test.ts @@ -49,6 +49,8 @@ const readFile = jest.fn(async (path: string) => { const content = ( { [resolvePath(root, 'my-secret')]: 'secret', + [resolvePath(root, 'with-newline-at-the-end')]: + 'value without newline at the end\n', [resolvePath(root, 'my-data.json')]: '{"a":{"b":{"c":42}}}', [resolvePath(root, 'my-data.yaml')]: 'some:\n yaml:\n key: 7', [resolvePath(root, 'my-data.yml')]: 'different: { key: hello }', @@ -92,6 +94,14 @@ describe('includeTransform', () => { includeTransform({ $file: 'no-secret' }, root), ).rejects.toThrow('File not found!'); }); + it('should trim new lines from end of file', async () => { + await expect( + includeTransform({ $file: 'with-newline-at-the-end' }, root), + ).resolves.toEqual({ + applied: true, + value: 'value without new line at the end', + }); + }); it('should include env vars', async () => { await expect(includeTransform({ $env: 'SECRET' }, root)).resolves.toEqual({ diff --git a/packages/config-loader/src/lib/transform/include.ts b/packages/config-loader/src/lib/transform/include.ts index 569b61c82c..84e4a9294d 100644 --- a/packages/config-loader/src/lib/transform/include.ts +++ b/packages/config-loader/src/lib/transform/include.ts @@ -73,7 +73,7 @@ export function createIncludeTransform( case '$file': try { const value = await readFile(resolvePath(baseDir, includeValue)); - return { applied: true, value }; + return { applied: true, value: value.trimEnd() }; } catch (error) { throw new Error(`failed to read file ${includeValue}, ${error}`); } From bcada7cd9fb9251ca96eead1ad910e669b1dc7bf Mon Sep 17 00:00:00 2001 From: Kiss Miklos Date: Mon, 18 Jul 2022 00:11:52 +0200 Subject: [PATCH 2/5] add changeset Signed-off-by: Kiss Miklos --- .changeset/hip-pets-glow.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/hip-pets-glow.md diff --git a/.changeset/hip-pets-glow.md b/.changeset/hip-pets-glow.md new file mode 100644 index 0000000000..517fd9932e --- /dev/null +++ b/.changeset/hip-pets-glow.md @@ -0,0 +1,5 @@ +--- +'@backstage/config-loader': patch +--- + +From now on the \$file placeholder will trim the the whitespaces and newline characters from the end of the file it reads. From cf3afa1c2aeac920cbfcab17608d3ef25c80baf3 Mon Sep 17 00:00:00 2001 From: Kiss Miklos Date: Mon, 18 Jul 2022 00:13:38 +0200 Subject: [PATCH 3/5] fix test name Signed-off-by: Kiss Miklos --- packages/config-loader/src/lib/transform/include.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/config-loader/src/lib/transform/include.test.ts b/packages/config-loader/src/lib/transform/include.test.ts index ad1a35102d..c80efe6785 100644 --- a/packages/config-loader/src/lib/transform/include.test.ts +++ b/packages/config-loader/src/lib/transform/include.test.ts @@ -50,7 +50,7 @@ const readFile = jest.fn(async (path: string) => { { [resolvePath(root, 'my-secret')]: 'secret', [resolvePath(root, 'with-newline-at-the-end')]: - 'value without newline at the end\n', + 'value without newline at the end\n\n', [resolvePath(root, 'my-data.json')]: '{"a":{"b":{"c":42}}}', [resolvePath(root, 'my-data.yaml')]: 'some:\n yaml:\n key: 7', [resolvePath(root, 'my-data.yml')]: 'different: { key: hello }', @@ -94,12 +94,12 @@ describe('includeTransform', () => { includeTransform({ $file: 'no-secret' }, root), ).rejects.toThrow('File not found!'); }); - it('should trim new lines from end of file', async () => { + it('should trim newlines from end of file', async () => { await expect( includeTransform({ $file: 'with-newline-at-the-end' }, root), ).resolves.toEqual({ applied: true, - value: 'value without new line at the end', + value: 'value without newline at the end', }); }); From acf57f9aadb7b84da514858a4deffdab868c61c1 Mon Sep 17 00:00:00 2001 From: Kiss Miklos Date: Mon, 18 Jul 2022 09:47:59 +0200 Subject: [PATCH 4/5] remove duplicate 'the' Signed-off-by: Kiss Miklos --- .changeset/hip-pets-glow.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/hip-pets-glow.md b/.changeset/hip-pets-glow.md index 517fd9932e..8a074727f6 100644 --- a/.changeset/hip-pets-glow.md +++ b/.changeset/hip-pets-glow.md @@ -2,4 +2,4 @@ '@backstage/config-loader': patch --- -From now on the \$file placeholder will trim the the whitespaces and newline characters from the end of the file it reads. +From now on the \$file placeholder will trim the whitespaces and newline characters from the end of the file it reads. From 0c5cd6ce5f238f949a777c5c437760ae135856cb Mon Sep 17 00:00:00 2001 From: Kiss Miklos Date: Mon, 18 Jul 2022 11:30:33 +0200 Subject: [PATCH 5/5] fix changeset Signed-off-by: Kiss Miklos --- .changeset/hip-pets-glow.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/hip-pets-glow.md b/.changeset/hip-pets-glow.md index 8a074727f6..2b988c0d4c 100644 --- a/.changeset/hip-pets-glow.md +++ b/.changeset/hip-pets-glow.md @@ -2,4 +2,4 @@ '@backstage/config-loader': patch --- -From now on the \$file placeholder will trim the whitespaces and newline characters from the end of the file it reads. +From now on the `$file` placeholder will trim the whitespaces and newline characters from the end of the file it reads.