Skip to content

Commit 877f4f0

Browse files
author
cod1k
committed
Refactor path handling in copyToTemp filter logic
Replaced manual path manipulation with `path.relative` for cleaner and more reliable relative path creation. This improves code readability and reduces the risk of potential errors.
1 parent 0f11c25 commit 877f4f0

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

dev-packages/e2e-tests/lib/copyToTemp.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { existsSync, readFileSync, writeFileSync } from 'fs';
33
import { cp } from 'fs/promises';
44
import ignore from 'ignore';
5-
import { dirname, join } from 'path';
5+
import { dirname, join, relative } from 'path';
66

77
export async function copyToTemp(originalPath: string, tmpDirPath: string): Promise<void> {
88
// copy files to tmp dir
@@ -22,9 +22,9 @@ export async function copyToTemp(originalPath: string, tmpDirPath: string): Prom
2222
await cp(originalPath, tmpDirPath, {
2323
recursive: true,
2424
filter: src => {
25-
const relative = src.replace(originalPath, '').replace(/^\//, '');
26-
if(!relative) return true;
27-
return !ig.ignores(relative);
25+
const relPath = relative(originalPath, src);
26+
if (!relPath) return true;
27+
return !ig.ignores(relPath);
2828
},
2929
});
3030

0 commit comments

Comments
 (0)