async extractMetadata()

in src/linter.js [454:518]


  async extractMetadata({
    _Crx = Crx,
    _Directory = Directory,
    _Xpi = Xpi,
    _console = console,
  } = {}) {
    await checkMinNodeVersion();

    const stats = await this.checkFileExists(this.packagePath);

    // Simple logging adapter for addons-scanner-utils IO.
    const stderr = {
      debug: (message) => log.debug(message),
      error: (message) => log.error(message),
      info: (message) => log.info(message),
    };

    if (stats.isFile()) {
      if (this.packagePath.endsWith('.crx')) {
        log.info('Package is a file ending in .crx; parsing as a CRX');
        this.io = new _Crx({ filePath: this.packagePath, stderr });
      } else {
        log.info('Package is a file. Attempting to parse as an .xpi/.zip');

        // We should set `autoClose` to `false` when we want to disable this
        // feature. By default, the auto-close feature is enabled.
        const autoClose = this.config.disableXpiAutoclose !== true;

        if (!autoClose) {
          log.info('Disabling the auto-close feature');
        }

        this.io = new _Xpi({ autoClose, filePath: this.packagePath, stderr });
      }
    } else {
      // If not a file then it's a directory.
      log.info('Package path is a directory. Parsing as a directory');
      this.io = new _Directory({ filePath: this.packagePath, stderr });
    }

    this.io.setScanFileCallback(this.shouldScanFile);

    let addonMetadata = await this.getAddonMetadata();
    addonMetadata = await this.markSpecialFiles(addonMetadata);

    log.info('Metadata option is set to %s', this.config.metadata);
    if (this.config.metadata === true) {
      const metadataObject = {
        // Reflects if errors were encountered in extraction
        // of metadata.
        hasErrors: this.output.errors.length !== 0,
        metadata: addonMetadata,
      };

      // If errors exist the data is available via the
      // errors list.
      if (metadataObject.hasErrors) {
        metadataObject.errors = this.output.errors;
      }

      _console.log(this.toJSON({ input: metadataObject }));
    }

    return addonMetadata;
  }