Skip to content

Commit

Permalink
[Fix] bin/tape: ignore options on windows
Browse files Browse the repository at this point in the history
The current version of `glob` returns paths always with forward slashes, even on windows. This causes the `dotignore` `Matcher` to never match the paths on windows, because it expects backslashes on windows. This means that the `--ignore` and `--ignore-pattern` options do not work properly on windows.

This is fixed in a newer version of glob (not sure which specific version). However, we can not upgrade because it drops support for older node versions that we still want to support in tape. So instead, a workaround is to correct the slashes ourselves.

This issue is already covered by existing test cases (test/ignore-pattern.js), that are currently failing when they are ran on windows. For example: `.\node_modules\.bin\tap test/*.js`. However, an additional fix is needed to make these tests pass (see next commit).
  • Loading branch information
Joris-van-der-Wel authored and ljharb committed Jan 7, 2024
1 parent 9cbae8a commit a2b74f9
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions bin/tape
Expand Up @@ -2,6 +2,7 @@

'use strict';

var path = require('path');
var parseOpts = require('minimist');
var objectKeys = require('object-keys');

Expand Down Expand Up @@ -68,6 +69,19 @@ var files = opts._.reduce(function (result, arg) {
throw new TypeError('unknown error: glob.sync("' + arg + '") did not return an array or throw. Please report this.');
}

// Workaround for glob v7 always replacing backslashes with forward slashes on windows
// This causes dotignore to not match the paths properly.
// This is fixed in newer version of glob, however we can not upgrade because it drops
// support for older node versions that we still want to support in tape.
// If glob is updated in the future this workaround can be removed, however note that
// the output of glob must then be sorted here because glob no longer does that.
// (also, backslashes and forward slashes should be ordered the same)
if (path.sep === '\\') {
globFiles = globFiles.map(function (globFile) {
return globFile.replace(/\//g, '\\');
});
}

return result.concat(globFiles);
}
return result.concat(arg);
Expand Down

0 comments on commit a2b74f9

Please sign in to comment.