Skip to content

Commit

Permalink
Merge ddc081a into 6feb698
Browse files Browse the repository at this point in the history
  • Loading branch information
HazAT authored Aug 5, 2020
2 parents 6feb698 + ddc081a commit d011131
Show file tree
Hide file tree
Showing 18 changed files with 466 additions and 281 deletions.
19 changes: 11 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
- release/**
pull_request:

env:
ELECTRON_CACHE_DIR: ${{ github.workspace }}

jobs:
job_1:
name: Build
Expand All @@ -16,9 +19,9 @@ jobs:
- uses: actions/cache@v2
with:
path: |
~/.cache/**
.cache/**
**/node_modules
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}
- name: Install
run: yarn install
- name: Build
Expand All @@ -33,9 +36,9 @@ jobs:
- uses: actions/cache@v2
with:
path: |
~/.cache/**
.cache/**
**/node_modules
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}
- run: yarn install
- name: Run Linter
run: yarn lint
Expand All @@ -55,9 +58,9 @@ jobs:
- uses: actions/cache@v2
with:
path: |
~/.cache/**
.cache/**
**/node_modules
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}
- run: yarn install
- name: Run Unit Tests
run: yarn test
Expand All @@ -77,9 +80,9 @@ jobs:
- uses: actions/cache@v2
with:
path: |
~/.cache/**
.cache/**
**/node_modules
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}
- run: yarn install
- name: Run E2E Tests
run: yarn e2e
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## Unreleased

**Breaking Change**: This version uses the [envelope endpoint](https://develop.sentry.dev/sdk/envelopes/). If you are
using an on-premise installation it requires Sentry version `>= v20.6.0` to work. If you are using
[sentry.io](https://sentry.io) nothing will change and no action is needed.

- ref: Decrease bundle size by removing dependencies (#252)
- ref: Use envelope endpoint (#252)
- feat: Export NetTransport (#252)
- feat: Export `flush` & `close` (#252)

## v1.5.2

- fix: Cirular refs (#253)
Expand Down
21 changes: 9 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@sentry/electron",
"description": "Offical Sentry SDK for Electron",
"version": "1.5.2",
"version": "2.0.0-beta.1",
"main": "./dist/index.js",
"module": "./esm/main/index.js",
"browser": "./esm/renderer/index.js",
Expand Down Expand Up @@ -37,19 +37,16 @@
"e2e": "cross-env TS_NODE_PROJECT=tsconfig.json xvfb-maybe mocha --require ts-node/register/transpile-only --timeout 30000 --retries 5 ./test/e2e/**/*.ts"
},
"dependencies": {
"@sentry/browser": "~5.20.0",
"@sentry/core": "~5.20.0",
"@sentry/minimal": "~5.20.0",
"@sentry/node": "~5.20.0",
"@sentry/types": "~5.20.0",
"@sentry/utils": "~5.20.0",
"electron-fetch": "^1.4.0",
"form-data": "2.5.1",
"util.promisify": "1.0.1",
"@sentry/browser": "~5.20.1",
"@sentry/core": "~5.20.1",
"@sentry/minimal": "~5.20.1",
"@sentry/node": "~5.20.1",
"@sentry/types": "~5.20.1",
"@sentry/utils": "~5.20.1",
"tslib": "^1.9.3"
},
"devDependencies": {
"@sentry/typescript": "^5.20.0",
"@sentry/typescript": "^5.20.1",
"@types/body-parser": "^1.17.0",
"@types/chai": "^4.2.10",
"@types/chai-as-promised": "^7.1.0",
Expand All @@ -72,7 +69,6 @@
"finalhandler": "^1.1.1",
"http-router": "^0.5.0",
"mocha": "^6.2.2",
"multiparty": "^4.2.1",
"npm-run-all": "^4.1.5",
"prettier": "^1.19.1",
"prettier-check": "^2.0.0",
Expand All @@ -84,6 +80,7 @@
"tslint-eslint-rules": "^5.4.0",
"typescript": "^3.7.4",
"typescript-tslint-plugin": "^0.5.5",
"util.promisify": "1.0.1",
"xvfb-maybe": "^0.2.1"
},
"sideEffects": false
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ export {

export { CommonBackend, ElectronOptions } from './common';
export { ElectronClient, getIntegrations } from './dispatch';
export { captureMinidump, init, showReportDialog } from './sdk';
export { captureMinidump, init, showReportDialog, flush, close } from './sdk';
2 changes: 1 addition & 1 deletion src/main/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export class MainBackend extends BaseBackend<ElectronOptions> implements CommonB
// on the crash library being used (Crashpad or Breakpad).
const crashesDirectory = crashReporter.getCrashesDirectory();

this._uploader = new MinidumpUploader(dsn, crashesDirectory, getCachePath());
this._uploader = new MinidumpUploader(dsn, crashesDirectory, getCachePath(), this.getTransport());

// Flush already cached minidumps from the queue.
forget(this._uploader.flushQueue());
Expand Down
21 changes: 13 additions & 8 deletions src/main/context.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import { Event } from '@sentry/types';
import * as child from 'child_process';
import { app } from 'electron';
import * as fs from 'fs';
import { platform, release } from 'os';
import { join } from 'path';
import { promisify } from 'util';

import { getNameFallback } from '../common';

const execFile = promisify(child.execFile);
const readdir = promisify(fs.readdir);
const readFile = promisify(fs.readFile);
import { readDirAsync, readFileAsync } from './fs';

/** Operating system context information. */
interface OsContext {
Expand Down Expand Up @@ -114,7 +110,16 @@ async function getDarwinInfo(): Promise<OsContext> {
// We try to load the actual macOS version by executing the `sw_vers` tool.
// This tool should be available on every standard macOS installation. In
// case this fails, we stick with the values computed above.
const output = (await execFile('/usr/bin/sw_vers')).stdout;

const output = await new Promise<string>((resolve, reject) => {
child.execFile('/usr/bin/sw_vers', (error: Error | null, stdout: string) => {
if (error) {
reject(error);
return;
}
resolve(stdout);
});
});
darwinInfo.name = matchFirst(/^ProductName:\s+(.*)$/m, output);
darwinInfo.version = matchFirst(/^ProductVersion:\s+(.*)$/m, output);
darwinInfo.build = matchFirst(/^BuildVersion:\s+(.*)$/m, output);
Expand Down Expand Up @@ -147,7 +152,7 @@ async function getLinuxInfo(): Promise<OsContext> {
// for exactly one known file defined in `LINUX_DISTROS` and exit if none
// are found. In case there are more than one file, we just stick with the
// first one.
const etcFiles = await readdir('/etc');
const etcFiles = await readDirAsync('/etc');
const distroFile = LINUX_DISTROS.find(file => etcFiles.includes(file.name));
if (!distroFile) {
return linuxInfo;
Expand All @@ -158,7 +163,7 @@ async function getLinuxInfo(): Promise<OsContext> {
// usually quite small, this should not allocate too much memory and we only
// hold on to it for a very short amount of time.
const distroPath = join('/etc', distroFile.name);
const contents = (await readFile(distroPath, 'utf-8')).toLowerCase();
const contents = ((await readFileAsync(distroPath, { encoding: 'utf-8' })) as string).toLowerCase();

// Some Linux distributions store their release information in the same file
// (e.g. RHEL and Centos). In those cases, we scan the file for an
Expand Down
71 changes: 67 additions & 4 deletions src/main/fs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mkdir, mkdirSync, readFile, statSync } from 'fs';
import { mkdir, mkdirSync, readdir, readFile, rename, stat, Stats, statSync, unlink } from 'fs';
import { dirname, resolve } from 'path';

const _0777 = parseInt('0777', 8);
Expand All @@ -9,11 +9,14 @@ const _0777 = parseInt('0777', 8);
* @param path A relative or absolute path to the file
* @returns A Promise that resolves when the file has been read.
*/
export async function readFileAsync(path: string): Promise<string> {
export async function readFileAsync(
path: string,
options?: { encoding?: string; flag?: string },
): Promise<string | Buffer> {
// We cannot use util.promisify here because that was only introduced in Node
// 8 and we need to support older Node versions.
return new Promise<string>((res, reject) => {
readFile(path, 'utf8', (err, data) => {
return new Promise<string | Buffer>((res, reject) => {
readFile(path, options, (err, data) => {
if (err) {
reject(err);
} else {
Expand Down Expand Up @@ -102,3 +105,63 @@ export function mkdirpSync(path: string): void {
}
}
}

/**
* Read stats async
*/
export function statAsync(path: string): Promise<Stats> {
return new Promise<Stats>((res, reject) => {
stat(path, (err, stats) => {
if (err) {
reject(err);
return;
}
res(stats);
});
});
}

/**
* unlink async
*/
export function unlinkAsync(path: string): Promise<void> {
return new Promise<void>((res, reject) => {
unlink(path, err => {
if (err) {
reject(err);
return;
}
res();
});
});
}

/**
* readdir async
*/
export function readDirAsync(path: string): Promise<string[]> {
return new Promise<string[]>((res, reject) => {
readdir(path, (err, files) => {
if (err) {
reject(err);
return;
}
res(files);
});
});
}

/**
* rename async
*/
export function renameAsync(oldPath: string, newPath: string): Promise<void> {
return new Promise<void>((res, reject) => {
rename(oldPath, newPath, err => {
if (err) {
reject(err);
return;
}
res();
});
});
}
33 changes: 30 additions & 3 deletions src/main/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// tslint:disable-next-line
require('util.promisify/shim')();
export {
Breadcrumb,
Request,
Expand Down Expand Up @@ -35,7 +33,7 @@ export {
withScope,
} from '@sentry/core';

import { initAndBind } from '@sentry/core';
import { getCurrentHub, initAndBind } from '@sentry/core';
import { _callOnClient } from '@sentry/minimal';
import { defaultIntegrations } from '@sentry/node';
import { Event } from '@sentry/types';
Expand All @@ -47,6 +45,7 @@ import { Electron, OnUncaughtException } from './integrations';
import { NetTransport } from './transports/net';
export { MainClient } from './client';
export { MainBackend } from './backend';
export { NetTransport } from './transports/net';
export { Integrations as NodeIntegrations } from '@sentry/node';

// tslint:disable-next-line:variable-name
Expand Down Expand Up @@ -88,3 +87,31 @@ export function showReportDialog(): void {
export function captureMinidump(path: string, event: Event = {}): void {
_callOnClient('captureMinidump', path, event);
}

/**
* A promise that resolves when all current events have been sent.
* If you provide a timeout and the queue takes longer to drain the promise returns false.
*
* @param timeout Maximum time in ms the client should wait.
*/
export async function flush(timeout?: number): Promise<boolean> {
const client = getCurrentHub().getClient<MainClient>();
if (client) {
return client.flush(timeout);
}
return Promise.reject(false);
}

/**
* A promise that resolves when all current events have been sent.
* If you provide a timeout and the queue takes longer to drain the promise returns false.
*
* @param timeout Maximum time in ms the client should wait.
*/
export async function close(timeout?: number): Promise<boolean> {
const client = getCurrentHub().getClient<MainClient>();
if (client) {
return client.close(timeout);
}
return Promise.reject(false);
}
Loading

0 comments on commit d011131

Please sign in to comment.