/*
 * Copyright 2021 Simon Edwards <simon@simonzone.com>
 *
 * This source code is licensed under the MIT license which is detailed in the LICENSE.txt file.
 */
import * as https from 'node:https';

const log = console.log.bind(console);

/**
 * @param {string} url
 * @return {Promise<Buffer>}
 */
async function fetchUrl(url) {
  log(`Downloading ${url}`);
  return new Promise( (resolve, reject) => {
    https.get(url, {}, (resp) => {
      // log(resp.headers);
      // log(`statusCode: ${resp.statusCode}`);

      if (resp.statusCode === 302) {
        fetchUrl(resp.headers.location).then(data => resolve(data));
        return;
      }

      const data = [];
      resp.on('data', (chunk) => {
        data.push(chunk);
      });

      resp.on('end', () => {
        resolve(Buffer.concat(data));
      });
    }).on("error", (err) => {
      log("Error: " + err.message);
      reject("Error: " + err.message);
    });
  });
}
exports.fetchUrl = fetchUrl;

@@ -292,16 +292,23 @@
 r%3E%7D%0A */%0A
+export 
 async fu
@@ -944,33 +944,4 @@
 ;%0A%7D%0A
-exports.fetchUrl = fetchUrl;%0A

Fix a ESM bug in build script