Skip to content

Commit 2bdbb41

Browse files
mishushakovclaude
andcommitted
Revert JS getAllFilesInPath to original implementation
The glob library has a bug where array patterns cause broken symlinks to have isSymbolicLink() return false, while single patterns work correctly. Reverting to the original nested-call approach to maintain correct symlink detection. The Python SDK simplification is retained since wcmatch may handle this differently. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 8c4cc3a commit 2bdbb41

1 file changed

Lines changed: 23 additions & 11 deletions

File tree

packages/js-sdk/src/template/utils.ts

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,25 +86,37 @@ export async function getAllFilesInPath(
8686
includeDirectories: boolean = true
8787
) {
8888
const { glob } = await dynamicImport<typeof import('glob')>('glob')
89+
const files = new Map<string, Path>()
8990

90-
// Match both the pattern and its recursive contents in one call
91-
// This handles directories (src -> src + src/**/*) and file patterns (*.txt -> just files)
92-
const normalizedSrc = normalizePath(src)
93-
const patterns = [normalizedSrc, `${normalizedSrc}/**/*`]
94-
95-
const globFiles = await glob(patterns, {
91+
const globFiles = await glob(src, {
9692
ignore: ignorePatterns,
9793
withFileTypes: true,
94+
// this is required so that the ignore pattern is relative to the file path
9895
cwd: contextPath,
9996
})
10097

101-
// Deduplicate by full path
102-
const files = new Map<string, Path>()
10398
for (const file of globFiles) {
104-
if (!includeDirectories && file.isDirectory()) {
105-
continue
99+
if (file.isDirectory()) {
100+
// For directories, add the directory itself and all files inside it
101+
if (includeDirectories) {
102+
files.set(file.fullpath(), file)
103+
}
104+
const dirPattern = normalizePath(
105+
// When the matched directory is '.', `file.relative()` can be an empty string.
106+
// In that case, we want to match all files under the current directory instead of
107+
// creating an absolute glob like '/**/*' which would traverse the entire filesystem.
108+
path.join(file.relative() || '.', '**/*')
109+
)
110+
const dirFiles = await glob(dirPattern, {
111+
ignore: ignorePatterns,
112+
withFileTypes: true,
113+
cwd: contextPath,
114+
})
115+
dirFiles.forEach((f) => files.set(f.fullpath(), f))
116+
} else {
117+
// For files, just add the file
118+
files.set(file.fullpath(), file)
106119
}
107-
files.set(file.fullpath(), file)
108120
}
109121

110122
return Array.from(files.values()).sort()

0 commit comments

Comments
 (0)