From ee3b9c33109a5a1e04c079bbcf7ea9220ae90c91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Mon, 25 Jul 2022 11:35:48 +0200 Subject: [PATCH] Improve dead code detection (#22829) --- scripts/analyse_unused_exports.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/scripts/analyse_unused_exports.js b/scripts/analyse_unused_exports.js index bb4b29a173..36014b1dc8 100755 --- a/scripts/analyse_unused_exports.js +++ b/scripts/analyse_unused_exports.js @@ -4,15 +4,21 @@ const fs = require("fs"); const { exec } = require("node:child_process"); +const includeJSSDK = process.argv.includes("--include-js-sdk"); const ignore = []; ignore.push(...Object.values(JSON.parse(fs.readFileSync(`${__dirname}/../components.json`)))); ignore.push("/index.ts"); +// We ignore js-sdk by default as it may export for other non element-web projects +if (!includeJSSDK) ignore.push("matrix-js-sdk"); const command = `yarn ts-prune --ignore "${ignore.join("|")}" | grep -v "(used in module)"`; -exec(command, (error, stdout) => { +exec(command, (error, stdout, stderr) => { if (error) throw error; + // We have to do this as piping the output of ts-prune causes the return + // code to be 0 + if (stderr) throw Error(stderr); let lines = stdout.split("\n"); // Remove the first line as that is the command that was being run and we