Repository: paularmstrong/build-tracker
Pull request #152 (2020-02-27 18:17:54)

Ignore directions when running glob
<!--
Thank you so much for contributing to open source and the Build Tracker project!
-->

# Problem

We tried to use the glob `**/*` to include all artifacts, regardless of file extension, however we were getting an exception:

```
    EISDIR: illegal operation on a directory, read
```

# Solution

<!--
When trying to solve more solutions with Build Tracker, please keep in mind some of the following goals of the project:
* Be lightweight: small package sizes (single-digit KiBs, gzipped)
* Be easy: too many options in an API can become confusing
* Be clear: the intended purpose of every method should be as obvious as possible
* Is it easy to do this in "userland"? Would it be better off done there?
-->

Explain your approach. Sometimes it helps to justify your approach against some others that you didn't choose to explain why yours is better.

# TODO

- [x] 🤓 Add & update tests (always try to _increase_ test coverage)
- [x] 🔬 Ensure CI is passing (`yarn lint:ci`, `yarn test`, `yarn tsc:ci`)
- [x] 📖 Update relevant documentation


paularmstrong: The test file is tripping me up. Can you add some content like `this file intentionally left blank` and rename it to something like `test-no-extension`
OliverJAsh: Sure, done!

Patch:
diff --git a/src/cli/src/commands/stat-artifacts.ts b/src/cli/src/commands/stat-artifacts.ts
index f7730fe..65fb966 100644
--- a/src/cli/src/commands/stat-artifacts.ts
+++ b/src/cli/src/commands/stat-artifacts.ts
@@ -51,7 +51,7 @@ export const handler = async (args: Args): Promise<{ artifacts: Map<string, Stat
 
   const artifacts = new Map();
   artifactGlobs.forEach(fileGlob => {
-    glob.sync(path.resolve(cwd, fileGlob)).forEach(filePath => {
+    glob.sync(path.resolve(cwd, fileGlob), { nodir: true }).forEach(filePath => {
       const sizes = readfile(filePath, getFilenameHash);
       artifacts.set(nameMapper(path.relative(baseDir, filePath).replace(`.${sizes.hash}`, '')), sizes);
     });
diff --git a/src/fixtures/cli-configs/rc/.build-trackerrc.js b/src/fixtures/cli-configs/rc/.build-trackerrc.js
index f7a25ae..63b7a16 100644
--- a/src/fixtures/cli-configs/rc/.build-trackerrc.js
+++ b/src/fixtures/cli-configs/rc/.build-trackerrc.js
@@ -2,7 +2,7 @@ const path = require('path');
 
 module.exports = {
   applicationUrl: 'https://build-tracker.local',
-  artifacts: ['../fakedist/*.js'],
+  artifacts: ['../fakedist/**/*'],
   baseDir: path.resolve(__dirname, 'fakedist'),
   cwd: __dirname,
   onCompare: data => Promise.resolve()


Test patch:
diff --git a/src/cli/src/commands/__tests__/create-build.test.ts b/src/cli/src/commands/__tests__/create-build.test.ts
index d20cc63..3823fd7 100644
--- a/src/cli/src/commands/__tests__/create-build.test.ts
+++ b/src/cli/src/commands/__tests__/create-build.test.ts
@@ -124,6 +124,15 @@ describe('create-build', () => {
               stat: 64
             }
           },
+          {
+            hash: '415dec15fc798bb79f499aeff00258fb',
+            name: '../../fakedist/test-folder/test-no-extension',
+            sizes: {
+              brotli: 49,
+              gzip: 54,
+              stat: 34
+            }
+          },
           {
             hash: 'fc4bcd175441f89862f9d81e37599416',
             name: '../../fakedist/vendor.js',
diff --git a/src/cli/src/commands/__tests__/stat-artifacts.test.ts b/src/cli/src/commands/__tests__/stat-artifacts.test.ts
index cd06de5..b15921e 100644
--- a/src/cli/src/commands/__tests__/stat-artifacts.test.ts
+++ b/src/cli/src/commands/__tests__/stat-artifacts.test.ts
@@ -36,6 +36,12 @@ describe('stat-artifacts command', () => {
               hash: '631a500f31d7602a386b4f858338dd6f'
               // NOTE: if brotli is availalbe, it will appear here
             }),
+            '../../fakedist/test-folder/test-no-extension': expect.objectContaining({
+              brotli: 29,
+              gzip: 54,
+              hash: '415dec15fc798bb79f499aeff00258fb',
+              stat: 34
+            }),
             '../../fakedist/vendor.js': expect.objectContaining({
               stat: 82,
               gzip: 82,
diff --git a/src/fixtures/cli-configs/fakedist/test-folder/test-no-extension b/src/fixtures/cli-configs/fakedist/test-folder/test-no-extension
new file mode 100644
index 0000000..c67d6be
--- /dev/null
+++ b/src/fixtures/cli-configs/fakedist/test-folder/test-no-extension
@@ -0,0 +1,1 @@
+this file intentionally left blank
\ No newline at end of file