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

Fix recursive bugs #92

Merged
merged 9 commits into from
Feb 27, 2022
Merged

Conversation

Idered
Copy link
Contributor

@Idered Idered commented Oct 4, 2021

This PR fixes 5 bugs:

This issue can be closed too:

This PR completes my work on recursive feature

I'm also attaching a small migration guide bellow.

Can I get hacktoberfest-accepted label on this?


Breaking changes & examples

Recursive by default

  • parents option was removed
  • to get flat list of files use flat: true option

Example directory structure:

- .github/workflows/main.yml
- .github/funding.yml

Command: cpy('.github/**', 'dest')

Old output:

- dest/funding.yml
- dest/main.yml

New output:

- dest/workflows/main.yml
- dest/main.yml

Recreate old parents: true

Example directory structure:

- .github/workflows/main.yml
- .github/funding.yml

Old:
cpy('.github/**', 'dest', {parents: true})

New:
cpy('.github', 'dest')

Output:

- dest/.github/workglows/main.yml
- dest/.github/funding.yml

Recreate old parents: false

Example directory structure:

- .github/workflows/main.yml
- .github/funding.yml

Old:
cpy('.github/**', 'dest', {parents: false})

New:
cpy('.github', 'dest', {flat: true})

Output:

- dest/main.yml
- dest/funding.yml

Copy all package.json and preserve folder structure

Old:
cpy('node_modules/**/package.json', 'dest', {parents: true})

Old output:

New:
cpy('node_modules/**/package.json', 'dest')

New output:

Ignore colors, those are git changes

@Idered Idered marked this pull request as draft October 4, 2021 23:59
@Idered Idered marked this pull request as ready for review October 5, 2021 00:29
@sindresorhus
Copy link
Owner

Thanks for working on this. Would you be able to add some tests for the bugs being fixed?

@sindresorhus
Copy link
Owner

Can I get hacktoberfest-accepted label on this?

@Idered
Copy link
Contributor Author

Idered commented Oct 5, 2021

Thanks for working on this. Would you be able to add some tests for the bugs being fixed?

Sure

Comment on lines +66 to +72
let collection = [];
for (const pattern of patterns) {
collection = [...collection, ...micromatch.braces(pattern, {
expand: true,
nodupes: true,
})];
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be a good place to use Array#flatMap.

index.js Show resolved Hide resolved
return path.join(options.cwd, destination, path.basename(entry.pattern.originalPath), path.relative(entry.pattern.originalPath, entry.path));
}

if (!entry.pattern.isDirectory && entry.path === entry.relativePath) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to have a short code comment on both of these if's on what kind of case they handle.

@sindresorhus
Copy link
Owner

Bump :)

@iiLearner
Copy link

@Idered would you be able to have a follow up to this as its blocking #98 :)

@sindresorhus sindresorhus mentioned this pull request Jan 9, 2022
9 tasks
index.js Outdated Show resolved Hide resolved
@thetutlage
Copy link

thetutlage commented May 3, 2022

It seems this PR introduces a regression. Following is a snippet from the PR original content.

Recreate old parents: true

Example directory structure:

  • .github/workflows/main.yml
  • .github/funding.yml

Old:

cpy('.github/**', 'dest', {parents: true})

New:

cpy('.github', 'dest')

Output:

- dest/.github/workglows/main.yml
- dest/.github/funding.yml

How should I have the same output as previous parents: true while defining the file extensions as well.

Old:

cpy('.github/**/*.yml', 'dest', {parents: true})

Old Output:

- dest/.github/workglows/main.yml
- dest/.github/funding.yml

New:

cpy('.github/**/*.yaml', 'dest')

New Output:

- dest/workglows/main.yml
- dest/funding.yml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants