Skip to content

Commit

Permalink
Use posix paths with patterns passed to globby.
Browse files Browse the repository at this point in the history
globby uses the fast-glob package, which states this in its README (RE:
patterns):

> ⚠️ Always use forward-slashes in glob expressions (patterns and ignore
> option). Use backslashes for escaping characters.

Previously, we were using `path.join` which will use the OS specific
separator and therefore fail to match files when invoked with a
directory path directly.

---

This also corrects for a bug in globby (to be reported/fixed separately)
where the `cwd` option is defaulted to `process.cwd()` _without_ posix
correction, and then subsequently an assertion is made that a given path
"starts with" the cwd.
  • Loading branch information
rwjblue committed Oct 16, 2019
1 parent 389a1d9 commit d1ce04c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -34,6 +34,7 @@
"commander": "^3.0.0",
"globby": "^10.0.1",
"ora": "^4.0.2",
"slash": "^3.0.0",
"tmp": "^0.1.0",
"workerpool": "^5.0.1"
},
Expand Down
13 changes: 11 additions & 2 deletions src/runner.js
@@ -1,8 +1,10 @@
const http = require('http');
const https = require('https');
const { writeFileSync } = require('fs');
const { resolve, extname, join } = require('path');
const { join } = require('path').posix;
const { resolve, extname } = require('path');
const colors = require('colors/safe');
const slash = require('slash');
const globby = require('globby');
const ora = require('ora');
const queue = require('async-promise-queue');
Expand Down Expand Up @@ -182,7 +184,14 @@ async function getAllFiles(paths) {
return path;
});

const files = await globby(patterns, { absolute: true, gitignore: true });
const files = await globby(patterns, {
// must specify a properly escaped `cwd` because globby infers from
// process.cwd() directly and without correcting back to posix paths
// asserts if the individual file path isn't "in" the cwd
cwd: slash(process.cwd()),
absolute: true,
gitignore: true,
});
if (files.length < 1) {
throw new NoFilesError();
}
Expand Down

0 comments on commit d1ce04c

Please sign in to comment.