scripts/build/build.mjs/run
async function run(params) {
  params.files = params.file ? new Set([params.file].flat()) : params.file;
  delete params.file;

  params.saveAs = params["save-as"];
  delete params["save-as"];

  params.printSize = params["print-size"];
  delete params["print-size"];

  params.compareSize = params["compare-size"];
  delete params["compare-size"];

  if (params.report === "") {
    params.report = ["html"];
  }
  params.reports = params.report ? [params.report].flat() : params.report;
  delete params.report;

  if (params.saveAs && !(params.files && params.files.size === 1)) {
    throw new Error("'--save-as' can only use together with one '--file' flag");
  }

  if (
    params.saveAs &&
    !path.join(DIST_DIR, params.saveAs).startsWith(DIST_DIR)
  ) {
    throw new Error("'--save-as' can only relative path");
  }

  if (params.clean) {
    let stat;
    try {
      stat = await fs.stat(DIST_DIR);
    } catch {
      // No op
    }

    if (stat) {
      if (stat.isDirectory()) {
        await fs.rm(DIST_DIR, { recursive: true, force: true });
      } else {
        throw new Error(`"${DIST_DIR}" is not a directory`);
      }
    }
  }

  if (params.compareSize) {
    if (params.minify === false) {
      throw new Error(
        "'--compare-size' can not use together with '--no-minify' flag"
      );
    }

    if (params.saveAs) {
      throw new Error(
        "'--compare-size' can not use together with '--save-as' flag"
      );
    }
  }

  const shouldPreparePackage =
    !params.playground && !params.files && params.minify === null;
  const shouldSaveBundledPackagesLicenses = shouldPreparePackage;

  const licenses = [];
  if (shouldSaveBundledPackagesLicenses) {
    params.onLicenseFound = (dependencies) => licenses.push(...dependencies);
  }

  console.log(chalk.inverse(" Building packages "));

  for (const bundleConfig of bundleConfigs) {
    await createBundle(bundleConfig, params);
  }

  if (shouldPreparePackage) {
    await preparePackage();
  }

  if (shouldSaveBundledPackagesLicenses) {
    const vendorMeta = await readJson(
      new URL("../vendors/vendor-meta.json", import.meta.url)
    );
    licenses.push(...vendorMeta.licenses);

    await saveLicenses(licenses.filter(({ name }) => name !== "prettier"));
  } else {
    console.warn(
      chalk.red("Bundled packages licenses not included in `dist/LICENSE`.")
    );
  }
}