async hashXpiCrcs()

in src/util/submit-addon.js [385:402]


  async hashXpiCrcs(filePath, asyncFsReadFile = defaultAsyncFsReadFile) {
    const zip = await JSZip.loadAsync(
      asyncFsReadFile(filePath, { createFolders: true }),
    );
    const hash = createHash('sha256');
    const entries = [];
    zip.forEach((relativePath, entry) => {
      let path = relativePath.replace(/\/+$/, '');
      if (entry.dir) {
        path += '/';
      }
      // if the file is 0 bytes or a dir `_data` is missing so assume crc is 0
      entries.push({ path, crc32: entry._data?.crc32 || 0 });
    });
    entries.sort((a, b) => (a.path === b.path ? 0 : a.path > b.path ? 1 : -1));
    hash.update(JSON.stringify(entries));
    return hash.digest('hex');
  }