From a2b74f97fe6ea14898b636f560291647bb747753 Mon Sep 17 00:00:00 2001 From: Joris van der Wel Date: Sun, 7 Jan 2024 19:53:10 +0100 Subject: [PATCH] [Fix] `bin/tape`: ignore options on windows 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). --- bin/tape | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/bin/tape b/bin/tape index 3b41be76..aa8cea32 100755 --- a/bin/tape +++ b/bin/tape @@ -2,6 +2,7 @@ 'use strict'; +var path = require('path'); var parseOpts = require('minimist'); var objectKeys = require('object-keys'); @@ -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);