{
var TopTree = {};
var urls = [];
async function getChildren(url, tree, path) {
if (path.includes(url)) {
tree.circular = true;
console.log(path, url);
console.log("circular dependency detected, sad");
return tree;
} else if (urls.includes(url)) {
tree.requested = true;
return tree;
} else {
urls.push(url);
}
path.push(url);
let sauce = await fetch(url).then(async (_) => [
getUrlDirectory(_.url),
await _.text()
]);
Object.assign(
tree,
Object.fromEntries(
[...sauce[1].matchAll(/require\(["'](.+?)["']\)/g)]
.map((a) => a[1])
.map((a) => [
a,
{
url:
a[0] == "."
? unpkg + simplifyUrl(unpkg + sauce[0] + "/" + a).substr(1)
: unpkg + a,
tree: {}
}
])
)
);
for (const [key, value] of Object.entries(tree)) {
await getChildren(value.url, value.tree, path.slice());
console.log("fetching " + value.url);
}
}
getChildren("https://unpkg.com/@babel/traverse", TopTree, []);
return TopTree;
}