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

Error using replace-x 1.7.2 in package.json node 10.16.0 #4

Open
ghwrivas opened this issue Oct 9, 2019 · 2 comments
Open

Error using replace-x 1.7.2 in package.json node 10.16.0 #4

ghwrivas opened this issue Oct 9, 2019 · 2 comments

Comments

@ghwrivas
Copy link

ghwrivas commented Oct 9, 2019

in package json build command:

"ng-build": ng build --configuration=qa --project="app-web" --base-href=./ && replace-x 'ABC' 'XYZ' dist/app/index.html",

Error
fs.js:114
throw err;
^

Error: ENOENT: no such file or directory, lstat 'XYZ'
at Object.lstatSync (fs.js:845:3)
at replaceFileSync (/home/develop/repos/node_modules/replace-x/dist/replace-x.js:217:31)
at Array.forEach ()
at replace (/home/develop/repos/node_modules/replace-x/dist/replace-x.js:266:14)
at Object. (/home/develop/repos/node_modules/replace-x/bin/replace-x.js:42:1)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)

@Xotic750
Copy link
Owner

I'm afraid that I'm unable to reproduce this problem. Are you able to give me something more definitive that I can reproduce it with?

@marcosins
Copy link

I'm able to reproduce this. It looks like the script is taking the replacement string as one of the paths to look for files:

$ npm i replace-x
$ npx replace-x --version
1.7.2
$ echo 'this file has text'  > test.txt
$ cat test.txt 
this file has text
$ npx replace-x 'text' 'TEXT BUT UPPERCASE' test.txt
ENOENT: no such file or directory, lstat 'TEXT BUT UPPERCASE'

I was able to fix it by adding the replacement property to shared-options:

replacement: {
      position: 1, // Second argument
      string: true,
      describe: 'Replacement string for matches',
      demandOption: true,
}

At the same time, the paths property has a wrong index of 1 when it should be 2 (third argument):

position: 1,

It also looks like positionalArgs being an object is a problem for the parser that is looking for an array:

const $addlPosArgs = Array.isArray(addlPosArgs) ? addlPosArgs : [];

After those fixes, I was able to run the script successfully:

$ echo 'some random TEXT' > test.txt 
$ cat test.txt 
some random TEXT
$ npx replace-x 'TEXT' 'text, but lowercase' test.txt
test.txt
 1: some random text, but lowercase
$ cat test.txt 
some random text, but lowercase

I hope this helps you to publish a fix.

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

3 participants