github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/webapp/javascript/util/buildInfo.ts (about)

     1  // eslint-disable-next-line import/no-relative-packages
     2  import { Maybe } from 'true-myth';
     3  import { version as jsVersion } from '../../../package.json';
     4  
     5  export interface BuildInfo {
     6    goos: string;
     7    goarch: string;
     8    goVersion: string;
     9    version: string;
    10    time: string;
    11    gitSHA: string;
    12    gitDirty: string;
    13    useEmbeddedAssets: string;
    14    jsVersion: string;
    15  }
    16  
    17  export const buildInfo = function (): BuildInfo {
    18    // TODO: it may be possible that these fields are not populated
    19    // but as for now assume it is always present
    20    const win = window as unknown as { buildInfo: BuildInfo };
    21  
    22    return {
    23      jsVersion,
    24      goos: win.buildInfo?.goos,
    25      goarch: win.buildInfo?.goarch,
    26      goVersion: win.buildInfo?.goVersion,
    27      version: win.buildInfo?.version,
    28      time: win.buildInfo?.time,
    29      gitSHA: win.buildInfo?.gitSHA,
    30      gitDirty: win.buildInfo?.gitDirty,
    31      useEmbeddedAssets: win.buildInfo?.useEmbeddedAssets,
    32    };
    33  };
    34  
    35  interface LatestVersionInfo {
    36    latest_version: string;
    37  }
    38  
    39  // Make it explicit that this field may not be populated
    40  // for cases like standalone
    41  export const latestVersionInfo = function (): Maybe<LatestVersionInfo> {
    42    const win = window as unknown as { latestVersionInfo: LatestVersionInfo };
    43  
    44    if (!win.latestVersionInfo) {
    45      return Maybe.nothing();
    46    }
    47  
    48    return Maybe.of({
    49      latest_version: win.latestVersionInfo.latest_version,
    50    });
    51  };