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

Directory structure not maintained during copy #113

Open
thetutlage opened this issue Jul 4, 2023 · 6 comments
Open

Directory structure not maintained during copy #113

thetutlage opened this issue Jul 4, 2023 · 6 comments

Comments

@thetutlage
Copy link

You can find source code for reproduction here. https://github.com/thetutlage/cpy-issue-reproduction

I expect cpy to maintain the folder structure of the source when copying files to destination.

Source directory structure

resources
└── views
    ├── app.edge
    └── nested
        └── baz.edge

Code to copy the files

await copyFiles(['resources/views/**/*.edge'], join(BASE_PATH, './build'), {
	cwd: BASE_PATH,
})

Expected output

build
└── resources
	└── views
    	├── app.edge
    	└── nested
        	└── baz.edge

Actual output

build
├── app.edge
└── nested
    └── baz.edge
@thetutlage
Copy link
Author

Okay, it seems my issue is similar to this. #105

@editedredx
Copy link

Seems I've just ran into the same issue and I managed to solve it by using a relative path for the destination. Hope it'll work for your case as well.

@thetutlage
Copy link
Author

@editedredx Can you share an example of the code that works for you?

@editedredx
Copy link

editedredx commented Jul 6, 2023

Sure, my failing code looked like this:

cpy(
  [
    appPath
  ],
  path.resolve('dist')
);

The change is just a relative destination path:

cpy(
  [
    appPath
  ],
  'dist'
);

EDIT: Removed the no longer needed options.

I checked where it went wrong in the installed cpy and it seems to be in the preprocessDestinationPath function where it just appends the file name to the destination. https://github.com/sindresorhus/cpy/blob/main/index.js#L96

if (path.isAbsolute(destination)) {
  return path.join(destination, entry.name);
}

@danielweck
Copy link

FYI, I think I found a breaking change in how CWD is handled (default process.cwd() vs. options.cwd) from cp-file/cpy v9 -> v10, which affects cpy-cli v4 -> v5:

#107 (comment)

@Trainmaster
Copy link

I can confirm this issue after upgrading from 8.1.2 to 9.0.1.

Before:
await cpy(['./src/**/*.js'], './dist', { parents: true });

dist
└── src
    └── foo.js
    └── bar
        └── baz.js

After:
await cpy(['./src/**/*.js'], './dist');

dist
└── foo.js
└── bar
    └── baz.js

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

4 participants