Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite paths for globby to use forward slash #5386

Merged
merged 6 commits into from Jul 14, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 normal backslash in glob pattern', async () => {
tbowmo marked this conversation as resolved.
Show resolved Hide resolved
const cssGlob = path.win32.join(fixturesPath, 'globs', '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));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only works when path is absolute, if applying a pattern like "**/*.scss" that is not absolute, it still fails.
I tried to run with
entry = entry.replace(/\(?![[]()])/g, '/');

it works, I have not read all comments what was the reason to remove it.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

entry = normalizePath(entry) needs to be before if (fs.existsSync(absolutePath)) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@VikasAgarwal1984 this is an old (merged) pr, so if you think something needs changes, you should create a new pr for the changes.

}

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