Skip to content

Commit

Permalink
refactor: ♻️ don't use Object.fromEntries
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Mar 5, 2020
1 parent 785a389 commit a829863
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
9 changes: 4 additions & 5 deletions __tests__/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import path from "path"
const workspaceRoot = path.resolve(__dirname, "workspace")

function f(files: Record<string, unknown>) {
return files
? Object.fromEntries(
Object.entries(files).map(([k, v]) => [k.replace(/\\/gu, "/"), v])
)
: files
if (!files) return files
const ret: Record<string, unknown> = {}
Object.entries(files).forEach(([k, v]) => (ret[k.replace(/\\/gu, "/")] = v))
return ret
}

test("parseGitFiles", () => {
Expand Down
34 changes: 18 additions & 16 deletions src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,25 @@ class FilesCache {
this.cache.set(root, await getGitFiles(root))
}
const files = this.cache.get(root) || {}
return Object.fromEntries(
Object.entries(files)
.filter(([file]) => {
const filePath = path.resolve(root, file)
return (
filePath == directory || filePath.startsWith(directory + path.sep)
)
})
.map(([file, hash]) => [
path.relative(directory, path.resolve(root, file)),
hash,
])
.filter(
([file]) =>
file.length && !exclude.includes(file) && !file.endsWith(HASH_FILE)
const ret: GitFiles = {}

Object.entries(files)
.filter(([file]) => {
const filePath = path.resolve(root, file)
return (
filePath == directory || filePath.startsWith(directory + path.sep)
)
)
})
.map(([file, hash]) => [
path.relative(directory, path.resolve(root, file)),
hash,
])
.filter(
([file]) =>
file.length && !exclude.includes(file) && !file.endsWith(HASH_FILE)
)
.forEach(([file, hash]) => (ret[file] = hash))
return ret
}
}

Expand Down

0 comments on commit a829863

Please sign in to comment.