sindresorhus / cpy-cli

Copy files
MIT License
345 stars 33 forks source link

`--cwd` flag does not work #35

Open ZebraFlesh opened 2 years ago

ZebraFlesh commented 2 years ago

Previously I was executing the following command with 3.1.x

cpy **/*.scss !**/*.stories.scss ../lib --parents --cwd=src

with a result similar to:

% ls lib/**/*.scss 
lib/Button/Button.scss
lib/ButtonLink/ButtonLink.scss
lib/Checkbox/Checkbox.scss

However, the 4.0 release doesn't find any files to copy. This seems like a globbing problem.

sindresorhus commented 2 years ago

Does it work if you remove !**/*.stories.scss?

sindresorhus commented 2 years ago

// @andy2mrqz

ZebraFlesh commented 2 years ago

Does it work if you remove !**/*.stories.scss?

Strangely no: it encounters an error trying to copy a file from the node_modules directory, which is a sibling to src. So it seems like the --cwd=src flag is not being honored. (If the flag was honored, cpy-cli wouldn't even traverse into the node_modules directory.)

farfromrefug commented 2 years ago

I face the same issue. 4.x is not working for me anymore. Had to rollback to 3.x

andy2mrqz commented 2 years ago

@sindresorhus thanks for tagging, I totally missed the notifications and didn't see this until now.

I inspected #34 to see if that could have introduced a regression. The areas that my PR touched were:

I think the regression may have been introduced in cpy v9, which this package proxies to, in sindresorhus/cpy#92. The most recent comment as of writing mentions an issue very similar to this one.

I also was able to recreate this issue by creating a simple repo with cpy and the file structure that ZebraFresh mentioned in his description. This seems to indicate that cpy-cli is not the failure point.

Sometime in the coming days/weeks I'll spend some time and see if I can resolve the issue in cpy - but the main blockers there are time and my lack of familiarity with cpy internals. Anyone else interested should feel free to jump in and contribute as well, if able.

jurijzahn8019 commented 2 years ago

Hi there,

The current behavior i see is, that glob patterns must start with a posix path segment:

**/* will not work.

Possible fix could be

farfromrefug commented 1 year ago

Just managed to fix this in my setup and i saw actually 1 issue and 1 breaking change:

RiZKiT commented 1 year ago

Not sure if it is related or if I should open another ticket, but with 5.0.0 --cwd isn't working for us anymore the way it does in 4.x, so we had to switch back to 4.x.

stweet commented 9 months ago

with 5.0.0 don't work '--cwd'

farfromrefug commented 9 months ago

@sindresorhus would be nice to have some feedback on this. I have been stuck on 3.x because of this. Hope you can look at it

ankjevel commented 1 month ago

As I can see, the cwd-argument is handled twice. First to create the relative path for each item that should be copied, then processed once again by copyFile.

If removed from options when passed to copyFile it works (at least for me).

The example with --cwd should have been:

# with this project tree:
# .
# └── src
#     ├── a.file
#     └── subdirectory
#         └── another.file

cpy . '../../dist' --cwd=src

# should produce:
# .
# ├── dist
# │   ├── a.file
# │   └── subdirectory
# │       └── another.file
# └── src
#     ├── a.file
#     └── subdirectory
#         └── another.file

Let's say you want to copy the contents from src/subdirectory to dist, the relative path to the destination-directory needs to be referenced twice.

# this would be the expected destination path, if the initial example was correct
cpy . '../../dist' --cwd=src/subdirectory

# ... but, in order to get it to work, you need to add the relative path _TWICE_.
cpy . '../../../../dist' --cwd=src/subdirectory