From 68a047fd019234ddf7ce329dbb97018b1e1088d4 Mon Sep 17 00:00:00 2001 From: Brian DeHamer Date: Tue, 9 Jul 2024 07:55:19 -0700 Subject: [PATCH] bugfix for glob exclude patterns (#100) Signed-off-by: Brian DeHamer --- __tests__/subject.test.ts | 23 +++++++++++++++++++++++ dist/index.js | 9 +++------ src/subject.ts | 9 +++------ 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/__tests__/subject.test.ts b/__tests__/subject.test.ts index 9014b39..fd35b56 100644 --- a/__tests__/subject.test.ts +++ b/__tests__/subject.test.ts @@ -296,6 +296,29 @@ describe('subjectFromInputs', () => { }) }) + describe('when an excluding glob is supplied', () => { + it('returns the multiple subjects', async () => { + const inputs: SubjectInputs = { + ...blankInputs, + subjectPath: `${path.join(dir, 'subject-*')},!${path.join(dir, 'subject-1')}` + } + + const subjects = await subjectFromInputs(inputs) + + expect(subjects).toBeDefined() + expect(subjects).toHaveLength(2) + + expect(subjects).toContainEqual({ + name: 'subject-0', + digest: { sha256: expectedDigest } + }) + expect(subjects).toContainEqual({ + name: 'subject-2', + digest: { sha256: expectedDigest } + }) + }) + }) + describe('when a multi-line glob list is supplied', () => { it('returns the multiple subjects', async () => { const inputs: SubjectInputs = { diff --git a/dist/index.js b/dist/index.js index 0e8df52..8c21938 100644 --- a/dist/index.js +++ b/dist/index.js @@ -80356,14 +80356,11 @@ exports.subjectFromInputs = subjectFromInputs; // calculated and returned along with the subject's name. const getSubjectFromPath = async (subjectPath, subjectName) => { const digestedSubjects = []; - const files = []; // Parse the list of subject paths - const subjectPaths = parseList(subjectPath); + const subjectPaths = parseList(subjectPath).join('\n'); // Expand the globbed paths to a list of files - for (const subPath of subjectPaths) { - /* eslint-disable-next-line github/no-then */ - files.push(...(await glob.create(subPath).then(async (g) => g.glob()))); - } + /* eslint-disable-next-line github/no-then */ + const files = await glob.create(subjectPaths).then(async (g) => g.glob()); if (files.length > MAX_SUBJECT_COUNT) { throw new Error(`Too many subjects specified. The maximum number of subjects is ${MAX_SUBJECT_COUNT}.`); } diff --git a/src/subject.ts b/src/subject.ts index 947fdca..5157907 100644 --- a/src/subject.ts +++ b/src/subject.ts @@ -56,16 +56,13 @@ const getSubjectFromPath = async ( subjectName?: string ): Promise => { const digestedSubjects: Subject[] = [] - const files: string[] = [] // Parse the list of subject paths - const subjectPaths = parseList(subjectPath) + const subjectPaths = parseList(subjectPath).join('\n') // Expand the globbed paths to a list of files - for (const subPath of subjectPaths) { - /* eslint-disable-next-line github/no-then */ - files.push(...(await glob.create(subPath).then(async g => g.glob()))) - } + /* eslint-disable-next-line github/no-then */ + const files = await glob.create(subjectPaths).then(async g => g.glob()) if (files.length > MAX_SUBJECT_COUNT) { throw new Error(