From 01e1051edf1a87db63205f3c72c2e4829244c1b4 Mon Sep 17 00:00:00 2001 From: Nick Cipollo Date: Mon, 25 Oct 2021 08:03:03 -0400 Subject: [PATCH] Fixes #136 Globber now also supports new line as separator. --- __tests__/ArtifactGlobber.test.ts | 17 ++++++++++++++++- lib/ArtifactGlobber.js | 4 +++- src/ArtifactGlobber.ts | 4 +++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/__tests__/ArtifactGlobber.test.ts b/__tests__/ArtifactGlobber.test.ts index b2b3080b..7fadb22b 100644 --- a/__tests__/ArtifactGlobber.test.ts +++ b/__tests__/ArtifactGlobber.test.ts @@ -54,7 +54,7 @@ describe("ArtifactGlobber", () => { expect(warnMock).not.toBeCalled() }) - it("splits multiple paths", () => { + it("splits multiple paths with comma separator", () => { const globber = createArtifactGlobber() const expectedArtifacts = @@ -69,6 +69,21 @@ describe("ArtifactGlobber", () => { expect(warnMock).not.toBeCalled() }) + it("splits multiple paths with new line separator and trims start", () => { + const globber = createArtifactGlobber() + + const expectedArtifacts = + globResults + .concat(globResults) + .map((path) => new Artifact(path, contentType)) + + expect(globber.globArtifactString('path1\n path2', 'raw', false)) + .toEqual(expectedArtifacts) + expect(globMock).toBeCalledWith('path1') + expect(globMock).toBeCalledWith('path2') + expect(warnMock).not.toBeCalled() + }) + it("warns when no glob results are produced and empty results shouldn't throw", () => { const globber = createArtifactGlobber([]) diff --git a/lib/ArtifactGlobber.js b/lib/ArtifactGlobber.js index 998d85b9..20847610 100644 --- a/lib/ArtifactGlobber.js +++ b/lib/ArtifactGlobber.js @@ -33,7 +33,9 @@ class FileArtifactGlobber { this.globber = globber; } globArtifactString(artifact, contentType, errorsFailBuild) { - return artifact.split(',') + const split = /[,\n]/; + return artifact.split(split) + .map(path => path.trimStart()) .map(path => FileArtifactGlobber.expandPath(path)) .map(pattern => this.globPattern(pattern, errorsFailBuild)) .map((globResult) => FileArtifactGlobber.validatePattern(errorsFailBuild, globResult[1], globResult[0])) diff --git a/src/ArtifactGlobber.ts b/src/ArtifactGlobber.ts index 824a3318..2f5887de 100644 --- a/src/ArtifactGlobber.ts +++ b/src/ArtifactGlobber.ts @@ -16,7 +16,9 @@ export class FileArtifactGlobber implements ArtifactGlobber { } globArtifactString(artifact: string, contentType: string, errorsFailBuild: boolean): Artifact[] { - return artifact.split(',') + const split = /[,\n]/ + return artifact.split(split) + .map(path => path.trimStart()) .map(path => FileArtifactGlobber.expandPath(path)) .map(pattern => this.globPattern(pattern, errorsFailBuild)) .map((globResult) => FileArtifactGlobber.validatePattern(errorsFailBuild, globResult[1], globResult[0]))