You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While making use of the --replacement-js flag and trying to use a matched group for the replacement string on multiples files it ends up giving an undefined error, even if the file contents do not match the given pattern.
For example running the following command with 2 existing files inside a "test" folder:
test1.txt with content: "test:1"
test2.txt with content: "noMatch:2"
root@fdde7fe2dc62:/workspaces# npx rexreplace 'test:(.*)' 'dirpath + €1' -A -j --debug 'test/*'
"2 files found "
"Open sync: test/test1.txt "
"Work on content from: test/test1.txt"
"Write new content to: test/test1.txt"
test/test1.txt
"Open sync: test/test2.txt "
"Work on content from: test/test2.txt"
undefined:1
dirpath + $1
^
ReferenceError: $1 is not defined
at eval (eval at <anonymous> (eval at dynamicReplacement (/root/.npm/_npx/eb65943d65d3ffaf/node_modules/rexreplace/bin/rexreplace.cli.js:328:257)), <anonymous>:1:11)
at eval (eval at dynamicReplacement (/root/.npm/_npx/eb65943d65d3ffaf/node_modules/rexreplace/bin/rexreplace.cli.js:328:257), <anonymous>:3:258)
at dynamicReplacement (/root/.npm/_npx/eb65943d65d3ffaf/node_modules/rexreplace/bin/rexreplace.cli.js:359:17)
at doReplacement (/root/.npm/_npx/eb65943d65d3ffaf/node_modules/rexreplace/bin/rexreplace.cli.js:118:35)
at openFile (/root/.npm/_npx/eb65943d65d3ffaf/node_modules/rexreplace/bin/rexreplace.cli.js:102:17)
at /root/.npm/_npx/eb65943d65d3ffaf/node_modules/rexreplace/bin/rexreplace.cli.js:96:27
at Array.forEach (<anonymous>)
at engine (/root/.npm/_npx/eb65943d65d3ffaf/node_modules/rexreplace/bin/rexreplace.cli.js:96:7)
at /root/.npm/_npx/eb65943d65d3ffaf/node_modules/rexreplace/bin/rexreplace.cli.js:555:10
at /root/.npm/_npx/eb65943d65d3ffaf/node_modules/rexreplace/bin/rexreplace.cli.js:578:4
Node.js v20.17.0
This error occurs with the -o flag as well and with or without the -A flag.
However, with the -m flag it seems to find the matches correctly.
root@fdde7fe2dc62:/workspaces# npx rexreplace 'test:(.*)' 'dirpath + €1' -A -j -m --debug 'test/*'
"2 files found "
"Open sync: test/test1.txt "
"Work on content from: test/test1.txt"
1
"Open sync: test/test2.txt "
"Work on content from: test/test2.txt"
When not using a glob to find files and providing the exact file path it functions as expected:
root@fdde7fe2dc62:/workspaces# npx rexreplace 'test:(.*)' 'dirpath + €1' -A -j --debug 'test/test1.txt'
"1 files found "
"Open sync: test/test1.txt "
"Work on content from: test/test1.txt"
"Write new content to: test/test1.txt"
test/test1.txt
root@fdde7fe2dc62:/workspaces# npx rexreplace 'test:(.*)' 'dirpath + €1' -A -j --debug 'test/test2.txt'
"1 files found "
"Open sync: test/test2.txt "
"Work on content from: test/test2.txt"
"Nothing changed in: test/test2.txt "
The text was updated successfully, but these errors were encountered:
Rockdell
changed the title
Issue using --replacement-js flag when referencing matched groups while matching multiple files with glob notation
Using --replacement-js flag when referencing matched groups while matching multiple files with glob notation
Sep 9, 2024
After a bit of analyzing it seems the issue was that the replacement string was being lost after the parsing the first file. I made a PR #513 fixing this issue. Not sure which branch to merge it to so I just used the default main branch.
I would very much appreciate your review 😄
While making use of the --replacement-js flag and trying to use a matched group for the replacement string on multiples files it ends up giving an undefined error, even if the file contents do not match the given pattern.
For example running the following command with 2 existing files inside a "test" folder:
This error occurs with the -o flag as well and with or without the -A flag.
However, with the -m flag it seems to find the matches correctly.
When not using a glob to find files and providing the exact file path it functions as expected:
The text was updated successfully, but these errors were encountered: