Repository: codecov/uploader
Pull request #400 (2021-09-30 14:52:19)

Create release
- #390
- Dependencies


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9e5d3d4..667104a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,14 @@
 
 All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
 
+### [0.1.3](https://github.com/codecov/uploader/compare/v0.1.2...v0.1.3) (2021-09-30)
+
+### Bug Fixes
+
+- **deps:** update dependency glob to v7.2.0 ([f19bd71](https://github.com/codecov/uploader/commit/f19bd71777a88fcdea07e7594ee505152e926124))
+- **deps:** update dependency yargs to v17.2.0 ([9c70e07](https://github.com/codecov/uploader/commit/9c70e07ddcdabdde545748e0395511b927f25681))
+- **deps:** update dependency yargs to v17.2.1 ([670257e](https://github.com/codecov/uploader/commit/670257e883f501c1813d45f1b4ab75e59053c85b))
+
 ### [0.1.2](https://github.com/codecov/uploader/compare/v0.1.1...v0.1.2) (2021-09-22)
 
 ### Features
diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json
index 0e27313..e8b825b 100644
--- a/npm-shrinkwrap.json
+++ b/npm-shrinkwrap.json
@@ -1,12 +1,12 @@
 {
   "name": "codecov",
-  "version": "0.1.2",
+  "version": "0.1.3",
   "lockfileVersion": 2,
   "requires": true,
   "packages": {
     "": {
       "name": "codecov",
-      "version": "0.1.2",
+      "version": "0.1.3",
       "license": "ISC",
       "dependencies": {
         "fast-glob": "3.2.7",
@@ -2559,9 +2559,7 @@
       "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-2.0.0.tgz",
       "integrity": "sha512-MWufYdFw53ccGjCA+Ol7XJYpAlW6/prSMzuPOTRnJGcGzuhLn4Scrz7qf6o8bROZ514ltazcIFJZevcfbo0x7A==",
       "dev": true,
-      "engines": [
-        "node >= 6.0"
-      ],
+      "engines": ["node >= 6.0"],
       "dependencies": {
         "buffer-from": "^1.0.0",
         "inherits": "^2.0.3",
@@ -4101,9 +4099,7 @@
       "dev": true,
       "hasInstallScript": true,
       "optional": true,
-      "os": [
-        "darwin"
-      ],
+      "os": ["darwin"],
       "engines": {
         "node": "^8.16.0 || ^10.6.0 || >=11.0.0"
       }
@@ -5794,9 +5790,7 @@
       "resolved": "https://registry.npmjs.org/jsonparse/-/jsonparse-1.3.1.tgz",
       "integrity": "sha1-P02uSpH6wxX3EGL4UhzCOfE2YoA=",
       "dev": true,
-      "engines": [
-        "node >= 0.2.0"
-      ]
+      "engines": ["node >= 0.2.0"]
     },
     "node_modules/JSONStream": {
       "version": "1.3.5",
diff --git a/package.json b/package.json
index 34628d2..d66cb76 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "codecov",
-  "version": "0.1.2",
+  "version": "0.1.3",
   "description": "Codecov Report Uploader",
   "private": true,
   "bin": "dist/bin/codecov.js",
diff --git a/src/helpers/files.ts b/src/helpers/files.ts
index 16ab397..54058f0 100644
--- a/src/helpers/files.ts
+++ b/src/helpers/files.ts
@@ -170,6 +170,10 @@ export function coverageFilePatterns(): string[] {
   ]
 }
 
+const EMPTY_STRING = '' as const
+
+const isNegated = (path: string) => path.startsWith('!')
+
 /**
  *
  * @param {string} projectRoot
@@ -180,7 +184,20 @@ export async function getCoverageFiles(
   projectRoot: string,
   coverageFilePatterns: string[],
 ): Promise<string[]> {
-  return glob(coverageFilePatterns.map(globstar), {
+  const globstar = (pattern: string) => `**/${pattern}`
+
+  return glob(coverageFilePatterns.map((pattern: string) => {
+    const parts = []
+
+    if (isNegated(pattern)) {
+      parts.push('!')
+      parts.push(globstar(pattern.substr(1)))
+    } else {
+      parts.push(globstar(pattern))
+    }
+    
+    return parts.join(EMPTY_STRING)
+  }), {
     cwd: projectRoot,
     ignore: [...manualBlacklist(), ...globBlacklist()],
   })
diff --git a/src/index.ts b/src/index.ts
index 025284a..f5b9f3f 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -149,9 +149,18 @@ export async function main(
       coverageFilePaths = args.file
     }
   }
+  const isNegated = (path: string) => path.startsWith('!')
   coverageFilePaths = coverageFilePaths.concat(await getCoverageFiles(
     args.dir || projectRoot,
-    coverageFilePaths.length > 0 ? coverageFilePaths : coverageFilePatterns(),
+    (() => {
+      const numOfNegatedPaths = coverageFilePaths.filter(isNegated).length
+      
+      if (coverageFilePaths.length > numOfNegatedPaths) {
+        return coverageFilePaths
+      } else {
+        return coverageFilePaths.concat(coverageFilePatterns())
+      }
+    })(),
   ))
 
   // Remove invalid and duplicate file paths


Test patch:
diff --git a/test/helpers/files.test.ts b/test/helpers/files.test.ts
index c5737b6..0a214ee 100644
--- a/test/helpers/files.test.ts
+++ b/test/helpers/files.test.ts
@@ -116,6 +116,11 @@ describe('File Helpers', () => {
         await fileHelpers.getCoverageFiles('.', ['index.test.ts']),
       ).toStrictEqual(['test/index.test.ts', 'test/providers/index.test.ts'])
     })
+    it('can return a list of coverage files with a negated pattern', async () => {
+      expect(
+        await fileHelpers.getCoverageFiles('.', ['index.test.ts', '!test/providers']),
+      ).toStrictEqual(['test/index.test.ts'])
+    })
     describe('coverage file patterns', () => {
       it('contains `jacoco*.xml`', () => {
         expect(fileHelpers.coverageFilePatterns()).toContain('jacoco*.xml')
diff --git a/test/index.test.ts b/test/index.test.ts
index e5f600f..3753790 100644
--- a/test/index.test.ts
+++ b/test/index.test.ts
@@ -227,6 +227,7 @@ describe('Uploader Core', () => {
       dryRun: 'true',
       file: [
         'cover*.txt',
+        '!fixtures/other'
       ],
       name: 'customname',
       token: 'abcdefg',
@@ -236,7 +237,7 @@ describe('Uploader Core', () => {
     expect(log).toHaveBeenCalledWith(
       expect.stringMatching(/Processing.*test\/fixtures\/coverage\.txt\.\.\./),
     )
-    expect(log).toHaveBeenCalledWith(
+    expect(log).not.toHaveBeenCalledWith(
       expect.stringMatching(/Processing.*test\/fixtures\/other\/coverage\.txt\.\.\./),
     )
     expect(log).not.toHaveBeenCalledWith(