Skip to content

Commit

Permalink
fix: trim slashes from dest when flatten false; add support to ../
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoimbrizi committed May 30, 2023
1 parent 12e0847 commit 0041857
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
9 changes: 4 additions & 5 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,10 @@ export const collectCopyTargets = async (

// https://github.com/vladshcherbin/rollup-plugin-copy/blob/507bf5e99aa2c6d0d858821e627cb7617a1d9a6d/src/index.js#L32-L35
const { base, dir } = path.parse(matchedPath)
const destDir =
flatten || (!flatten && !dir)
? dest
: // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
dir.replace(dir.split('/')[0]!, dest)

const dirClean = dir.replace(/^(?:\.\.\/)+/, '')
const destClean = `${dest}/${dirClean}`.replace(/^\/+|\/+$/g, '')
const destDir = flatten || (!flatten && !dir) ? dest : destClean

copyTargets.push({
src: matchedPath,
Expand Down
2 changes: 1 addition & 1 deletion test/testcases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export const testcases: Record<string, Testcase[]> = {
{
name: 'glob with dir',
src: './dir/bar.txt',
dest: '/fixture2/bar.txt'
dest: '/fixture2/dir/bar.txt'
},
{
name: 'glob with parent dir',
Expand Down

0 comments on commit 0041857

Please sign in to comment.