Skip to content

Commit fb0cbe0

Browse files
committed
dapp: remappings: allow non git folders in lib dir
1 parent c5c313e commit fb0cbe0

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/dapp/libexec/dapp/dapp-remappings

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,11 @@ console.log(buildRemappings(deduplicate(buildDependencyTree("."))).join("\n"))
1414
// deps: []
1515
// }
1616
function buildDependencyTree(prefix) {
17-
if (ls(prefix).includes(".git") != true) {
18-
console.error(`${PROGRAM_NAME}: error: ${prefix} is not a Git repository`)
19-
console.error(`${PROGRAM_NAME}: error: try "dapp update" to initialize submodules`)
20-
process.exit(1)
21-
}
22-
2317
const lib = `${prefix}/${process.env.DAPP_LIB}`
2418
return {
2519
name: prefix.split("/").pop(),
2620
path: normalize(`${prefix}/${process.env.DAPP_SRC}`),
27-
hash: run("git", ["-C", prefix, "rev-parse", "HEAD"]),
21+
hash: hash(prefix),
2822
deps: ls(lib).map(p => buildDependencyTree(`${lib}/${p}`))
2923
}
3024
}
@@ -58,6 +52,16 @@ function normalize(path) {
5852
return path.replace(/^\.\//, "").replace(/^\//, "")
5953
}
6054

55+
// computes the hash of the contents of a given directory, uses the git hash if
56+
// availalbe (because it's faster), or falls back to a sha256sum of the directory contents if needed
57+
function hash(dir) {
58+
if (ls(dir).includes(".git")) {
59+
return run("git", ["-C", dir, "rev-parse", "HEAD"])
60+
} else {
61+
return run("bash", ["-c", `rg --files ${dir} | sort | xargs sha256sum | sha256sum`])
62+
}
63+
}
64+
6165
function ls(dir) {
6266
try {
6367
return require("fs").readdirSync(dir).sort()

0 commit comments

Comments
 (0)