Skip to content

Instantly share code, notes, and snippets.

@piousdeer
Last active December 10, 2023 22:44
Show Gist options
  • Save piousdeer/83dedd5155cec9aadbed4e076e41be26 to your computer and use it in GitHub Desktop.
Save piousdeer/83dedd5155cec9aadbed4e076e41be26 to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
import esbuild from "esbuild";
import fs from "fs/promises";
import { resolve as resolvePath } from "path";
const [root] = process.argv.slice(2);
console.log(JSON.stringify(await getGnomeExtensionGiDependencies(root)));
async function getGnomeExtensionGiDependencies(root) {
const entryPoints = [resolvePath(root, "extension.js")];
const prefsPath = resolvePath(root, "prefs.js");
try {
await fs.access(prefsPath);
entryPoints.push(prefsPath);
} catch {}
const { metafile } = await esbuild.build({
entryPoints,
outdir: "/tmp/gnome-extension-analyzer",
bundle: true,
format: "esm",
external: ["gi", "system", "cairo", "gettext", "gi://*", "resource://*"],
metafile: true,
logLevel: "silent",
});
return Object.fromEntries(
Object.entries(metafile.outputs).map(([path, file]) => [
path.split("/").at(-1),
dedupe(
file.imports
.map((module) => module.path)
.filter((path) => path.startsWith("gi://"))
),
])
);
}
function dedupe(arr) {
return Array.from(new Set(arr));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment