From aac954e0625a97a50ebab03416de8e61b5fde7a1 Mon Sep 17 00:00:00 2001 From: Mish <10400064+mishushakov@users.noreply.github.com> Date: Thu, 27 Nov 2025 17:10:19 +0100 Subject: [PATCH] fixes dot copy --- .changeset/humble-badgers-cross.md | 5 +++++ packages/js-sdk/src/template/utils.ts | 8 +++++++- .../template/utils/getAllFilesInPath.test.ts | 18 ++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 .changeset/humble-badgers-cross.md diff --git a/.changeset/humble-badgers-cross.md b/.changeset/humble-badgers-cross.md new file mode 100644 index 0000000000..a3b05d9456 --- /dev/null +++ b/.changeset/humble-badgers-cross.md @@ -0,0 +1,5 @@ +--- +'e2b': patch +--- + +fix copy bug when attempting to copy '.' as a source directory diff --git a/packages/js-sdk/src/template/utils.ts b/packages/js-sdk/src/template/utils.ts index 204991fded..f6377db14b 100644 --- a/packages/js-sdk/src/template/utils.ts +++ b/packages/js-sdk/src/template/utils.ts @@ -63,7 +63,13 @@ export async function getAllFilesInPath( if (includeDirectories) { files.set(file.fullpath(), file) } - const dirFiles = await glob(normalizePath(file.relative()) + '/**/*', { + const dirPattern = normalizePath( + // When the matched directory is '.', `file.relative()` can be an empty string. + // In that case, we want to match all files under the current directory instead of + // creating an absolute glob like '/**/*' which would traverse the entire filesystem. + path.join(file.relative() || '.', '**/*') + ) + const dirFiles = await glob(dirPattern, { ignore: ignorePatterns, withFileTypes: true, cwd: contextPath, diff --git a/packages/js-sdk/tests/template/utils/getAllFilesInPath.test.ts b/packages/js-sdk/tests/template/utils/getAllFilesInPath.test.ts index 89b4c6c33e..8d2d68b052 100644 --- a/packages/js-sdk/tests/template/utils/getAllFilesInPath.test.ts +++ b/packages/js-sdk/tests/template/utils/getAllFilesInPath.test.ts @@ -208,6 +208,24 @@ describe('getAllFilesInPath', () => { expect(files).toHaveLength(0) }) + test('should handle listing all files in current directory with dot pattern', async () => { + // Create a small directory tree inside the test directory + await writeFile(join(testDir, 'root.txt'), 'root') + await mkdir(join(testDir, 'subdir'), { recursive: true }) + await writeFile(join(testDir, 'subdir', 'nested.txt'), 'nested') + + const files = await getAllFilesInPath('.', testDir, []) + + // We should get at least the testDir itself (.) plus its children + expect(files.length).toBeGreaterThanOrEqual(3) + + // All returned paths must stay within the testDir - we must not traverse the whole filesystem + const allWithinTestDir = files.every((f) => + f.fullpath().startsWith(testDir) + ) + expect(allWithinTestDir).toBe(true) + }) + test('should handle complex ignore patterns with directories', async () => { // Create a complex structure await mkdir(join(testDir, 'src'), { recursive: true })