Skip to content

Commit

Permalink
dapp: remappings: allow non git folders in lib dir
Browse files Browse the repository at this point in the history
  • Loading branch information
d-xo committed Aug 4, 2021
1 parent c5c313e commit fb0cbe0
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/dapp/libexec/dapp/dapp-remappings
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,11 @@ console.log(buildRemappings(deduplicate(buildDependencyTree("."))).join("\n"))
// deps: []
// }
function buildDependencyTree(prefix) {
if (ls(prefix).includes(".git") != true) {
console.error(`${PROGRAM_NAME}: error: ${prefix} is not a Git repository`)
console.error(`${PROGRAM_NAME}: error: try "dapp update" to initialize submodules`)
process.exit(1)
}

const lib = `${prefix}/${process.env.DAPP_LIB}`
return {
name: prefix.split("/").pop(),
path: normalize(`${prefix}/${process.env.DAPP_SRC}`),
hash: run("git", ["-C", prefix, "rev-parse", "HEAD"]),
hash: hash(prefix),
deps: ls(lib).map(p => buildDependencyTree(`${lib}/${p}`))
}
}
Expand Down Expand Up @@ -58,6 +52,16 @@ function normalize(path) {
return path.replace(/^\.\//, "").replace(/^\//, "")
}

// computes the hash of the contents of a given directory, uses the git hash if
// availalbe (because it's faster), or falls back to a sha256sum of the directory contents if needed
function hash(dir) {
if (ls(dir).includes(".git")) {
return run("git", ["-C", dir, "rev-parse", "HEAD"])
} else {
return run("bash", ["-c", `rg --files ${dir} | sort | xargs sha256sum | sha256sum`])
}
}

function ls(dir) {
try {
return require("fs").readdirSync(dir).sort()
Expand Down

0 comments on commit fb0cbe0

Please sign in to comment.