plugins icon indicating copy to clipboard operation
plugins copied to clipboard

fix(graphql): handle parentheses in fragment import file paths

Open grxy opened this issue 1 year ago • 0 comments

Rollup Plugin Name: graphql

This PR contains:

  • [x] bugfix
  • [ ] feature
  • [ ] refactor
  • [ ] documentation
  • [ ] other

Are tests included?

  • [x] yes (bugfixes and features will not be merged without tests)
  • [ ] no

Breaking Changes?

  • [ ] yes (breaking changes will not be merged unless absolutely necessary)
  • [x] no

If yes, then include "BREAKING CHANGES:" in the first commit message body, followed by a description of what is breaking.

List any relevant issue numbers:

N/A

Description

This PR fixes an issue in the GraphQL plugin where parentheses in file paths are not properly replaced with a fragment's variable, leading to a parsing error.

The fix works by updating the require statement replacement regex from /require\(([^)]+)\)/gi to /require\(["']([^"']+)["']\)/gi. The original regex considered a closing parenthesis as the terminator of a require statement, when in fact, we should be looking at a quote character before a parentheses as the terminator. In addition, by excluding the leading and trailing quote from the regex capture group, we can remove the additional replacePath variable.

grxy avatar Jul 03 '24 18:07 grxy