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

RangeError: path should be a path.relative()d string, but got .... #113

Closed
anodynos opened this issue Nov 2, 2023 · 14 comments · Fixed by #124
Closed

RangeError: path should be a path.relative()d string, but got .... #113

anodynos opened this issue Nov 2, 2023 · 14 comments · Fixed by #124

Comments

@anodynos
Copy link

anodynos commented Nov 2, 2023

Hey and thanks for this great lib! It's the best copy out there! But I faced a daring bug:

(Also related to same error message #44)

My cmd is

╭─anodynos@Giga /mnt/projects/__fake/macos/newin
╰─$ cpx "/mnt/projects/devzen-tools/packages/newin/**" "./" --ignore "node_modules/,dist/,build/" --verbose --update  

so I want to copy from a deep path, into my CWD.

It fails with a a gazzillion of these - it enumerates all my files and node_modules (despite being ignored). For each file (mine & node_modules) it throws:

RangeError: path should be a `path.relative()`d string, but got "../../../devzen-tools/packages/newin/node_modules/expect/build/types.js"
    at throwError (/home/anodynos/.asdf/installs/nodejs/20.8.0/lib/node_modules/cpx2/node_modules/ignore/index.js:379:9)
    at checkPath (/home/anodynos/.asdf/installs/nodejs/20.8.0/lib/node_modules/cpx2/node_modules/ignore/index.js:398:12)
    at Ignore._test (/home/anodynos/.asdf/installs/nodejs/20.8.0/lib/node_modules/cpx2/node_modules/ignore/index.js:519:5)
    at Ignore.ignores (/home/anodynos/.asdf/installs/nodejs/20.8.0/lib/node_modules/cpx2/node_modules/ignore/index.js:564:17)
    at Object.ignored (/home/anodynos/.asdf/installs/nodejs/20.8.0/lib/node_modules/cpx2/lib/utils/apply-action.js:42:41)
    at #ignored (/home/anodynos/.asdf/installs/nodejs/20.8.0/lib/node_modules/cpx2/node_modules/glob/dist/commonjs/walker.js:54:64)
    at GlobWalker.matchFinish (/home/anodynos/.asdf/installs/nodejs/20.8.0/lib/node_modules/cpx2/node_modules/glob/dist/commonjs/walker.js:124:26)
    at GlobWalker.match (/home/anodynos/.asdf/installs/nodejs/20.8.0/lib/node_modules/cpx2/node_modules/glob/dist/commonjs/walker.js:148:18)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
RangeError: path should be a `path.relative()`d string, but got "../../../devzen-tools/packages/newin/node_modules/expect/build/toThrowMatchers.js"
    at throwError (/home/anodynos/.asdf/installs/nodejs/20.8.0/lib/node_modules/cpx2/node_modules/ignore/index.js:379:9)
    at checkPath (/home/anodynos/.asdf/installs/nodejs/20.8.0/lib/node_modules/cpx2/node_modules/ignore/index.js:398:12)
    at Ignore._test (/home/anodynos/.asdf/installs/nodejs/20.8.0/lib/node_modules/cpx2/node_modules/ignore/index.js:519:5)
    at Ignore.ignores (/home/anodynos/.asdf/installs/nodejs/20.8.0/lib/node_modules/cpx2/node_modules/ignore/index.js:564:17)
    at Object.ignored (/home/anodynos/.asdf/installs/nodejs/20.8.0/lib/node_modules/cpx2/lib/utils/apply-action.js:42:41)
    at #ignored (/home/anodynos/.asdf/installs/nodejs/20.8.0/lib/node_modules/cpx2/node_modules/glob/dist/commonjs/walker.js:54:64)
    at GlobWalker.matchFinish (/home/anodynos/.asdf/installs/nodejs/20.8.0/lib/node_modules/cpx2/node_modules/glob/dist/commonjs/walker.js:124:26)
    at GlobWalker.match (/home/anodynos/.asdf/installs/nodejs/20.8.0/lib/node_modules/cpx2/node_modules/glob/dist/commonjs/walker.js:148:18)
....
RangeError: path should be a `path.relative()`d string, but got "../../../../c/dev/newin/node_modules/lws-conditional-get"
...

Then it copies all the files I wanted, witch a glitch: ALWAYS, despite having --update.

Now the interesting thing is, if I reverse the paths, everything works fine:

╭─anodynos@Giga /mnt/projects/__fake/macos/newin
╰─$ cpx "./src/**/*" "/mnt/projects/devzen-tools/packages/newin/src" --ignore "node_modules/,dist/,build/" --verbose --update

Copy: ./src/**/* --> /mnt/projects/devzen-tools/packages/newin/src

Copied: src/tsconfig.json --> ../../../devzen-tools/packages/newin/src/tsconfig.json
Copied: src/tsconfig.deploy.json --> ../../../devzen-tools/packages/newin/src/tsconfig.deploy.json
Copied: src/package.json --> ../../../devzen-tools/packages/newin/src/package.json
Copied: src/package-lock.json --> ../../../devzen-tools/packages/newin/src/package-lock.json
Copied: src/nodemon.copy.json --> ../../../devzen-tools/packages/newin/src/nodemon.copy.json
....

Something's wrong with the globbing apparently, but after some digging I think it doesnt like absolute directories.

I converted to relative paths, and boom, all good.

$ cpx "./**/*" /mnt/projects/__fake/macos/newin --verbose

UPDATE:
It's not relative paths either, it crashes the same with them as well.

But when I add --watch the problem goes away!

Works:

╭─anodynos@Giga /mnt/projects/__fake/macos/newin
╰─$ cpx "../../../newin/**/*" . --verbose --ignore "node_modules" --watch  

Fails:

╭─anodynos@Giga /mnt/projects/__fake/macos/newin
╰─$ cpx "../../../newin/**/*" . --verbose --ignore "node_modules"

Great irony, I wanted to do it in a sleep loop "while sleep 5 ; cpx ...." cause watch dosnt work on Network drives apparently...

Any ideas?

Thanks again!

@bcomnes
Copy link
Owner

bcomnes commented Nov 2, 2023

Probably a bug introduced after I updated the glob library, which required a few changes to how ignore strings were handled. Thank you for the example, I will get it fixed. In the meantime, feel free to run the last latest version to avoid the issue.

@bcomnes
Copy link
Owner

bcomnes commented Nov 2, 2023

cause watch dosn't work on Network drives apparently...

Looks like this lib uses fs.watch, with has a fairly well known set of limitations: https://nodejs.org/api/fs.html#caveats

I would be open to swapping out to https://github.com/paulmillr/chokidar and exposing a --polling flag or something which WOULD work for network file systems, but I probably won't get around to it any time soon. Interested in looking into it?

@anodynos
Copy link
Author

anodynos commented Nov 4, 2023

Hey Bret, thanks for your response and concern.

I use chokidar as well, it's not without its caveats, but you can navigate around them. The network watch I think is tricky, and not so important. I just run cpx2 in a loop every couple of seconds, and done. Since --update works, I don't care about some extra reads in my ./src files!

I would absolutely love to work on it, your library in spec is the best out there, supporting --update & --watch & --ignore, I don't think any other does it... Unfortunately no time atm ;-(

I use the latest 6.0.1 already, do you mean the main branch directly?

Also, I noticed it doesn't copy hidden files (eg starting with .) and there's no option for it! This should be a trivial change, can you please add it?

Angelos ;-)

PS: nice stuff you got on https://bret.io/, but I think cpx2 deserves a mention too!

@bcomnes
Copy link
Owner

bcomnes commented Nov 4, 2023

I’m planning on fixing the relative path error asap. Chokidar would be nice but it might be a bit longer till I get to it. I don’t work with nfs very often.

I think the dotfile thing is a glob option that's just a matter of exposing so it should be easy.

Mostly credit goes to mysticatea who did the bulk of the work originally!

@bcomnes
Copy link
Owner

bcomnes commented Nov 21, 2023

Still planning on working on this.

@bcomnes
Copy link
Owner

bcomnes commented Dec 29, 2023

Bumping to remind myself to look at this issue soon. Please use an older version or a workaround (working out of a parent of the src directory) in the meantime.

@thorsent
Copy link

thorsent commented Feb 1, 2024

Oh no, I just hit this and now my release is bust. I'm gonna go back to prior version but +1 on this being the best copy library out there.

@bcomnes
Copy link
Owner

bcomnes commented Feb 1, 2024

Sorry about that, I may have some time to fix here soon.

@artsiommiksiuk
Copy link

@bcomnes I've hit this as well.

@mcollina
Copy link

mcollina commented Oct 4, 2024

@bcomnes got hurt by this as well :(

@bcomnes
Copy link
Owner

bcomnes commented Oct 4, 2024

Arg sorry folks. I'll get a hot fix out. I can just bypass the ignore glob error for the outer relative path case.

@bcomnes
Copy link
Owner

bcomnes commented Oct 4, 2024

Taking a stab at this right now. Sorry for taking so long.

@bcomnes
Copy link
Owner

bcomnes commented Oct 4, 2024

If you are still with me, give cpx2@7.0.2 or v8.0.0 (updated deps) a try.

@mcollina
Copy link

works here

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

Successfully merging a pull request may close this issue.

5 participants