diff --git a/src/utils.ts b/src/utils.ts index db1e260..3a8dc62 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -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, diff --git a/test/testcases.ts b/test/testcases.ts index 63a890d..21adae2 100644 --- a/test/testcases.ts +++ b/test/testcases.ts @@ -140,7 +140,7 @@ export const testcases: Record = { { name: 'glob with dir', src: './dir/bar.txt', - dest: '/fixture2/bar.txt' + dest: '/fixture2/dir/bar.txt' }, { name: 'glob with parent dir',