<commit_before>/**
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 * @format
 */

import os from 'os';
import {isTest} from './isProduction';

export type Info = {
  arch: string;
  platform: string;
  unixname: string;
  versions: {
    [key: string]: string | undefined;
  };
};

/**
 * This method builds up some metadata about the users environment that we send
 * on bug reports, analytic events, errors etc.
 */
export function getInfo(): Info {
  return {
    arch: process.arch,
    platform: process.platform,
    unixname: os.userInfo().username,
    versions: {
      electron: process.versions.electron,
      node: process.versions.node,
      platform: os.release(),
    },
  };
}

let APP_VERSION: string | undefined;
export function getAppVersion(): string {
  return (APP_VERSION =
    APP_VERSION ??
    process.env.FLIPPER_FORCE_VERSION ??
    (isTest() ? '0.0.0' : require('../../package.json').version ?? '0.0.0'));
}

export function stringifyInfo(info: Info): string {<commit_msg>Fix retrieving versions for release builds<commit_after>/**
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 * @format
 */

import os from 'os';
import isProduction, {isTest} from './isProduction';
import fs from 'fs-extra';
import path from 'path';
import {getStaticPath} from './pathUtils';

export type Info = {
  arch: string;
  platform: string;
  unixname: string;
  versions: {
    [key: string]: string | undefined;
  };
};

/**
 * This method builds up some metadata about the users environment that we send
 * on bug reports, analytic events, errors etc.
 */
export function getInfo(): Info {
  return {
    arch: process.arch,
    platform: process.platform,
    unixname: os.userInfo().username,
    versions: {
      electron: process.versions.electron,
      node: process.versions.node,
      platform: os.release(),
    },
  };
}

let APP_VERSION: string | undefined;
export function getAppVersion(): string {
  return (APP_VERSION =
    APP_VERSION ??
    process.env.FLIPPER_FORCE_VERSION ??
    (isTest()
      ? '0.0.0'
      : (isProduction()
          ? fs.readJsonSync(path.join(getStaticPath(), 'package.json'), {
              throws: false,
            })?.version
          : require('../../package.json').version) ?? '0.0.0'));
}

export function stringifyInfo(info: Info): string {
{'fraction_non_alphanumeric': 0.13070378963650425, 'fraction_numerical': 0.004640371229698376, 'mean_word_length': 3.1928687196110213, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '642212', 'n_tokens_mistral': 770, 'n_tokens_neox': 756, 'n_words': 248}