Skip to content

Commit

Permalink
Fix "No files matching the pattern" when using backslash paths on Win…
Browse files Browse the repository at this point in the history
…dows (#5386)

* Rewrite paths for globby to use forward slash

* Remove stray comment

* Extend tests to verify 'windows paths'

* Use normalize-path for path normalization instead of regex

* Amend tests as suggested in PR comments

* Updated test description

Co-authored-by: Thomas Bowman Mørch <thomas.git@bowmo.dk>
  • Loading branch information
tbowmo and Thomas Bowman Mørch committed Jul 14, 2021
1 parent 92c3fea commit 336cf15
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 5 deletions.
29 changes: 29 additions & 0 deletions lib/__tests__/standalone-globs.test.js
Expand Up @@ -112,6 +112,35 @@ describe('standalone globbing', () => {
);
});

describe('windows path style with backslash', () => {
// The tests fail on non-windows environments.
if (process.platform !== 'win32') {
return;
}

it('should handle a backslash-separated file path', async () => {
const cssGlob = path.win32.join(fixturesPath, 'with spaces', 'styles.css');

const { results } = await standalone({
files: cssGlob,
config: {
rules: {
'block-no-empty': true,
},
},
});

expect(results).toHaveLength(1);
expect(results[0].errored).toEqual(true);
expect(results[0].warnings[0]).toEqual(
expect.objectContaining({
rule: 'block-no-empty',
severity: 'error',
}),
);
});
});

describe('mixed globs and paths with special chars', () => {
it('manual escaping', async () => {
const cssGlob = `${fixturesPath}/got\\[braces\\] and \\(spaces\\)/*.+(s|c)ss`;
Expand Down
3 changes: 2 additions & 1 deletion lib/standalone.js
Expand Up @@ -12,6 +12,7 @@ const getFormatterOptionsText = require('./utils/getFormatterOptionsText');
const globby = require('globby');
const hash = require('./utils/hash');
const NoFilesFoundError = require('./utils/noFilesFoundError');
const normalizePath = require('normalize-path');
const path = require('path');
const pkg = require('../package.json');
const prepareReturnValue = require('./prepareReturnValue');
Expand Down Expand Up @@ -176,7 +177,7 @@ module.exports = function (options) {

if (fs.existsSync(absolutePath)) {
// This path points to a file. Return an escaped path to avoid globbing
return fastGlob.escapePath(entry);
return fastGlob.escapePath(normalizePath(entry));
}

return entry;
Expand Down
23 changes: 19 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -130,6 +130,7 @@
"mathml-tag-names": "^2.1.3",
"meow": "^9.0.0",
"micromatch": "^4.0.4",
"normalize-path": "^3.0.0",
"normalize-selector": "^0.2.0",
"postcss": "^8.3.0",
"postcss-media-query-parser": "^0.2.3",
Expand Down Expand Up @@ -158,6 +159,7 @@
"@types/globjoin": "^0.1.0",
"@types/imurmurhash": "^0.1.1",
"@types/micromatch": "^4.0.1",
"@types/normalize-path": "^3.0.0",
"@types/postcss-less": "^4.0.0",
"@types/postcss-safe-parser": "^5.0.0",
"@types/style-search": "^0.1.1",
Expand Down

0 comments on commit 336cf15

Please sign in to comment.