Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ module.exports = {
'/utility/**',
'rollup.config.mjs',
],
plugins: [
'require-extensions',
],
plugins: ['require-extensions'],
overrides: [
{
files: ['*.ts', '*.tsx', '*.d.ts'],
Expand Down
9 changes: 9 additions & 0 deletions .oxfmtrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "./node_modules/oxfmt/configuration_schema.json",
"printWidth": 120,
"proseWrap": "always",
"singleQuote": true,
"trailingComma": "all",
"experimentalSortPackageJson": false,
"ignorePatterns": []
}
6 changes: 0 additions & 6 deletions .prettierrc

This file was deleted.

2 changes: 1 addition & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": ["esbenp.prettier-vscode", "dbaeumer.vscode-eslint", "stkb.rewrap"]
"recommendations": ["oxc.oxc-vscode", "dbaeumer.vscode-eslint", "stkb.rewrap"]
}
11 changes: 1 addition & 10 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
{
"editor.formatOnType": true,
"editor.formatOnPaste": false,
"editor.formatOnSave": true,
"editor.rulers": [120],
"editor.tabSize": 2,
"files.autoSave": "onWindowChange",
"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true,
"typescript.tsdk": "./node_modules/typescript/lib",
"[json]": {
"editor.formatOnType": false,
"editor.formatOnPaste": false,
"editor.formatOnSave": false
}
"editor.defaultFormatter": "oxc.oxc-vscode",
}
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ To use this SDK, call `init(options)` as early as possible in the entry modules
renderer processes or further sub processes you spawn. This will initialize the SDK and hook the environment.

In the Electron main process:

```javascript
import { init } from '@sentry/electron/main';

Expand All @@ -39,6 +40,7 @@ init({
```

In all Electron renderer processes:

```javascript
// In the Electron renderer processes
import { init } from '@sentry/electron/renderer';
Expand All @@ -48,12 +50,17 @@ init();

If you are using a framework specific Sentry SDK, you can pass that `init` function as the second parameter in the
renderer and the two SDKs functionalities will be combined:

```javascript
import { init } from '@sentry/electron/renderer';
import { init as reactInit } from '@sentry/react';

init({ /* config */ }, reactInit);

init(
{
/* config */
},
reactInit,
);
```

To set context information or send manual events, use the exported functions of `@sentry/electron`. Note that these
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@
"postbuild": "node scripts/check-exports.mjs && node scripts/check-types.mjs && node scripts/check-loading.mjs && yarn pack",
"clean": "rimraf --glob coverage common esm main preload renderer index.* sentry-electron*.tgz .eslintcache",
"prelint": "yarn set-version",
"lint": "run-s lint:prettier lint:eslint",
"lint:prettier": "prettier --check \"{src,test,examples}/**/*.{ts,js}\"",
"lint": "run-s lint:oxfmt lint:eslint",
"lint:oxfmt": "oxfmt --check \"{scripts,src,test,examples}/**/*.{ts,js}\"",
"lint:eslint": "eslint . --cache --format stylish",
"fix": "run-s fix:prettier fix:eslint",
"fix:prettier": "prettier --write \"{src,test,examples}/**/*.{ts,js}\"",
"fix": "run-s fix:oxfmt fix:eslint",
"fix:oxfmt": "oxfmt --write \"{scripts,src,test,examples}/**/*.{ts,js}\"",
"fix:eslint": "eslint . --format stylish --fix",
"update-electron-versions": "node ./scripts/update-electron-versions.mjs",
"update-sdk-versions": "node ./scripts/update-sdk-versions.mjs",
Expand All @@ -119,9 +119,9 @@
},
"devDependencies": {
"@rollup/plugin-typescript": "^12.1.3",
"@sentry/node-native": "10.38.0",
"@sentry-internal/eslint-config-sdk": "10.38.0",
"@sentry-internal/typescript": "10.38.0",
"@sentry/node-native": "10.38.0",
"@types/busboy": "^1.5.4",
"@types/koa": "^2.0.52",
"@types/koa-bodyparser": "^4.3.0",
Expand All @@ -135,10 +135,10 @@
"koa-bodyparser": "^4.3.0",
"koa-tree-router": "^0.12.1",
"npm-run-all2": "^8.0.4",
"prettier": "^2.8.4",
"oxfmt": "^0.32.0",
"rimraf": "^6.0.1",
"tmp": "^0.2.1",
"rollup": "^4.44.1",
"tmp": "^0.2.1",
"typescript": "~5.0.0",
"vitest": "^3.2.4",
"xvfb-maybe": "^0.2.1",
Expand Down
32 changes: 16 additions & 16 deletions scripts/update-version.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
const { join } = require('path');
const { readFileSync, writeFileSync } = require('fs');
const packageJson = require('../package.json');
// SDK_VERSION to 'src/main/version.ts'
const versionPath = join(__dirname, '../src/main/version.ts');
writeFileSync(versionPath, `export const SDK_VERSION = '${packageJson.version}';\n`);
// Write @sentry/core version into options variable name so TypeScript error includes useful hint
const coreVersion = packageJson.dependencies['@sentry/core'];
const coreVersionVar = coreVersion.replace(/\./g, '_');
const rendererSdkPath = join(__dirname, '../src/renderer/sdk.ts');
let rendererSdk = readFileSync(rendererSdkPath, { encoding: 'utf8' });
rendererSdk = rendererSdk.replace(/version_v\d+_\d+_\d+[a-z_0-9]*/, `version_v${coreVersionVar.replace(/-/, '_')}`);
writeFileSync(rendererSdkPath, rendererSdk);
const { join } = require('path');
const { readFileSync, writeFileSync } = require('fs');

const packageJson = require('../package.json');

// SDK_VERSION to 'src/main/version.ts'
const versionPath = join(__dirname, '../src/main/version.ts');
writeFileSync(versionPath, `export const SDK_VERSION = '${packageJson.version}';\n`);

// Write @sentry/core version into options variable name so TypeScript error includes useful hint
const coreVersion = packageJson.dependencies['@sentry/core'];
const coreVersionVar = coreVersion.replace(/\./g, '_');
const rendererSdkPath = join(__dirname, '../src/renderer/sdk.ts');
let rendererSdk = readFileSync(rendererSdkPath, { encoding: 'utf8' });
rendererSdk = rendererSdk.replace(/version_v\d+_\d+_\d+[a-z_0-9]*/, `version_v${coreVersionVar.replace(/-/, '_')}`);
writeFileSync(rendererSdkPath, rendererSdk);
27 changes: 15 additions & 12 deletions src/main/integrations/electron-breadcrumbs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,23 @@ const DEFAULT_OPTIONS: ElectronBreadcrumbsOptions<EventFunction> = {
export function normalizeOptions(
options: Partial<ElectronBreadcrumbsOptions<EventTypes>>,
): Partial<ElectronBreadcrumbsOptions<EventFunction | false>> {
return (Object.keys(options) as (keyof ElectronBreadcrumbsOptions<EventTypes>)[]).reduce((obj, k) => {
if (k === 'captureWindowTitles') {
obj[k] = !!options[k];
} else {
const val: EventTypes = options[k];
if (Array.isArray(val)) {
obj[k] = (name) => val.includes(name);
} else if (typeof val === 'function' || val === false) {
obj[k] = val;
return (Object.keys(options) as (keyof ElectronBreadcrumbsOptions<EventTypes>)[]).reduce(
(obj, k) => {
if (k === 'captureWindowTitles') {
obj[k] = !!options[k];
} else {
const val: EventTypes = options[k];
if (Array.isArray(val)) {
obj[k] = (name) => val.includes(name);
} else if (typeof val === 'function' || val === false) {
obj[k] = val;
}
}
}

return obj;
}, {} as Partial<ElectronBreadcrumbsOptions<EventFunction | false>>);
return obj;
},
{} as Partial<ElectronBreadcrumbsOptions<EventFunction | false>>,
);
}

/**
Expand Down
11 changes: 7 additions & 4 deletions src/main/integrations/electron-minidump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,13 @@ function getNativeUploaderExtraParams(event: Event): { [key: string]: string } {
buf = buf.subarray(i + 1);
}

return chunks.reduce((acc, cur, i) => {
acc[`sentry__${i + 1}`] = cur;
return acc;
}, {} as { [key: string]: string });
return chunks.reduce(
(acc, cur, i) => {
acc[`sentry__${i + 1}`] = cur;
return acc;
},
{} as { [key: string]: string },
);
}

/**
Expand Down
13 changes: 8 additions & 5 deletions src/main/integrations/startup-tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,14 @@ export const startupTracingIntegration = defineIntegration((options: StartupTrac
return {
name: 'StartupTracing',
setup() {
const fallbackTimeout = setTimeout(() => {
const transaction = rootTransaction();
transaction.setStatus({ code: 2, message: 'Timeout exceeded' });
transaction.end();
}, (options.timeoutSeconds || 10) * 1000);
const fallbackTimeout = setTimeout(
() => {
const transaction = rootTransaction();
transaction.setStatus({ code: 2, message: 'Timeout exceeded' });
transaction.end();
},
(options.timeoutSeconds || 10) * 1000,
);

app.once('will-finish-launching', () => {
zeroLengthSpan({
Expand Down
7 changes: 4 additions & 3 deletions src/main/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ export function getDefaultIntegrations(options: ElectronMainOptions): Integratio
}

export interface ElectronMainOptionsInternal
extends Options<ElectronOfflineTransportOptions>,
Omit<NodeOptions, 'transport' | 'transportOptions'> {
extends Options<ElectronOfflineTransportOptions>, Omit<NodeOptions, 'transport' | 'transportOptions'> {
/**
* Inter-process communication mode to receive event and scope from renderers
*
Expand Down Expand Up @@ -232,7 +231,9 @@ const INTEGRATION_OVERRIDES = [
/** Sets the default integrations and ensures that multiple minidump or session integrations are not enabled */
function removeRedundantIntegrations(
// At this point we know that the integrations are an array
options: { integrations: Integration[] },
options: {
integrations: Integration[];
},
): void {
for (const { userAdded, toRemove } of INTEGRATION_OVERRIDES) {
if (options.integrations.some((i) => i.name === userAdded)) {
Expand Down
7 changes: 6 additions & 1 deletion src/main/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,12 @@ export class BufferedWriteStore<T> extends Store<T> {
* @param initial An initial value to initialize data with.
* @param throttleTime The minimum time between writes
*/
public constructor(path: string, id: string, initial: T, private readonly _throttleTime: number = 500) {
public constructor(
path: string,
id: string,
initial: T,
private readonly _throttleTime: number = 500,
) {
super(path, id, initial);
}

Expand Down
13 changes: 8 additions & 5 deletions test/e2e/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ const SENTRY_KEY = '37f8a2ee37c0409d8970bc7559c7c7e4';
function getFiles(rootDir: string): Record<string, string> {
return Array.from(walkSync(rootDir))
.filter((path) => !path.endsWith('test.ts'))
.reduce((acc, absPath) => {
const relPath = absPath.replace(rootDir + sep, '');
acc[relPath] = readFileSync(absPath, { encoding: 'utf-8' });
return acc;
}, {} as Record<string, string>);
.reduce(
(acc, absPath) => {
const relPath = absPath.replace(rootDir + sep, '');
acc[relPath] = readFileSync(absPath, { encoding: 'utf-8' });
return acc;
},
{} as Record<string, string>,
);
}

function insertAfterLastImport(content: string, insert: string): string {
Expand Down
11 changes: 7 additions & 4 deletions test/e2e/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ export interface MinidumpResult {
function sentryNamespacedFormFields(form: MultipartResult): Record<string, any> {
return Object.entries(form.fields)
.filter(([key, _]) => key.startsWith('sentry___'))
.reduce((acc, [key, value]) => {
acc[key.replace('sentry___', '')] = JSON.parse(value);
return acc;
}, {} as Record<string, any>);
.reduce(
(acc, [key, value]) => {
acc[key.replace('sentry___', '')] = JSON.parse(value);
return acc;
},
{} as Record<string, any>,
);
}

export function sentryEventFromFormFields(logger: TestLogger, form: MultipartResult): [Event, Record<string, any>] {
Expand Down
Loading
Loading