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

convertPathToPattern not converting some\\@directory\\ correctly #452

Open
AriPerkkio opened this issue Jul 29, 2024 · 1 comment
Open

Comments

@AriPerkkio
Copy link

AriPerkkio commented Jul 29, 2024

Environment

  • OS Version: Windows 11
  • Node.js Version: 20.15.0

Works fine on non-Windows, e.g. Mac. convertPathToPattern checks OS so reproduces only on Windows.

Actual behavior

const resolved = path.join(require.resolve("@vitest/coverage-v8"), "..");
const pattern = fg.convertPathToPattern(resolved) + "/**";
const files = fg.globSync(pattern);

//  resolved: 'C:\\Users\\Ari\\git\\fastglob\\node_modules\\@vitest\\coverage-v8\\dist',
//  pattern: 'C:/Users/Ari/git/fastglob/node_modules\\@vitest/coverage-v8/dist/**',
//                                                  ^^^
//  files: []

Expected behavior

//  resolved: 'C:\\Users\\Ari\\git\\fastglob\\node_modules\\@vitest\\coverage-v8\\dist',
//  pattern: 'C:/Users/Ari/git/fastglob/node_modules/@vitest/coverage-v8/dist/**',
//                                                  ^^
//  files: [
//    'C:/Users/Ari/git/fastglob/node_modules/@vitest/coverage-v8/dist/index.d.ts',
//    'C:/Users/Ari/git/fastglob/node_modules/@vitest/coverage-v8/dist/index.js',
//    'C:/Users/Ari/git/fastglob/node_modules/@vitest/coverage-v8/dist/provider.d.ts',
//    'C:/Users/Ari/git/fastglob/node_modules/@vitest/coverage-v8/dist/provider.js'
// ]

Steps to reproduce

  1. npm init
  2. npm i -D fast-glob @vitest/coverage-v8
  3. Save code sample to index.js
  4. node index.js

Code sample

const path = require("node:path");
const fg = require("fast-glob");

const resolved = path.join(require.resolve("@vitest/coverage-v8"), "..");
const pattern = fg.convertPathToPattern(resolved) + "/**";
const files = fg.globSync(pattern);

console.log({
  resolved,
  pattern,
  files,

  fixedPattern: pattern.replaceAll("\\@", "/@"),
  fixed: fg.globSync(pattern.replaceAll("\\@", "/@")),
});

image

@AriPerkkio
Copy link
Author

I see that https://github.com/mrmlnc/fast-glob?tab=readme-ov-file#convertpathtopatternpath does mention @ and backslash using as espace characters. In this case \\@ is not escape for @, right? In \@ it would be?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant