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

The fixtures/{first,}/* pattern returns incorrect results #394

Closed
mrmlnc opened this issue May 13, 2023 · 2 comments
Closed

The fixtures/{first,}/* pattern returns incorrect results #394

mrmlnc opened this issue May 13, 2023 · 2 comments
Milestone

Comments

@mrmlnc
Copy link
Owner

mrmlnc commented May 13, 2023

Environment

  • OS Version: macOS 13.1
  • Node.js Version: v16.16.0

Actual behavior

{
  entries: [
    'fixtures/first/file.md',
    'fixtures/first/nested'
  ]
}

Expected behavior

The fixtures/{first,}/* can be considered as two patterns:

  • fixtures/first/*
  • fixtures/*
{
  entries: [
    'fixtures/third',
    'fixtures/second',
    'fixtures/file.md',
    'fixtures/first',
    'fixtures/first/nested',
    'fixtures/first/file.md'
  ]
}

Code sample

const incorrect = fg.sync(['fixtures/{first,}/*'], {
	onlyFiles: false,
});

const correct = fg.sync(['fixtures/first/*', 'fixtures/*'], {
	onlyFiles: false,
});

console.dir({ incorrect, correct }, { colors: true, compact: false, depth: null });
@mrmlnc
Copy link
Owner Author

mrmlnc commented May 13, 2023

The micromatch package generates the following regexp: ^(?:fixtures\/(first|)\/(?!\.)(?=.)[^/]*?\/?)$.This expression does not match the fixtures/file.md path.

// After expand brace expressions
[
  'fixtures/first/*',
  'fixtures//*' // incorrect
]
[
  /^(?:fixtures\/first\/(?!\.)(?=.)[^/]*?\/?)$/,
  /^(?:fixtures\/\/(?!\.)(?=.)[^/]*?\/?)$/
]

// fixtures/* (correct)
^(?:fixtures\/(?!\.)(?=.)[^/]*?\/?)$

Hm. From my point of view, micromatch generates a knowingly incorrect pattern. However, he did what he had to do - it expands the pattern without any additional processing.

@mrmlnc
Copy link
Owner Author

mrmlnc commented May 14, 2023

Already fixed in the master by #395 in this package. Will be shipped with 3.3.0.

@mrmlnc mrmlnc closed this as completed May 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant