Last active
December 10, 2023 22:44
-
-
Save piousdeer/83dedd5155cec9aadbed4e076e41be26 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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