Skip to content

Commit

Permalink
fix: Sub-module imports in type definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
timfish committed Aug 14, 2024
1 parent 422f678 commit 87fa64a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"scripts": {
"prebuild": "yarn clean && node scripts/update-version.js",
"build": "rollup --config rollup.config.mjs",
"postbuild": "node scripts/check-exports.mjs",
"postbuild": "node scripts/check-exports.mjs && node scripts/check-types.mjs",
"clean": "rimraf --glob coverage common esm main preload renderer index.* sentry-electron*.tgz .eslintcache",
"prelint": "node scripts/update-version.js",
"lint": "run-s lint:prettier lint:eslint",
Expand Down
39 changes: 39 additions & 0 deletions scripts/check-types.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { promises as fs } from 'node:fs';
import * as path from 'node:path';

async function walk(dir, ty) {
let files = await fs.readdir(dir);
files = await Promise.all(
files.map(async (file) => {
const filePath = path.join(dir, file);
const stats = await fs.stat(filePath);
if (stats.isDirectory()) {
return filePath.endsWith('node_modules') ? [] : walk(filePath, ty);
} else if (stats.isFile() && file.endsWith(ty)) {
return filePath;
}
}),
);

return files.filter(Boolean).reduce((all, f) => all.concat(f), []);
}

// Find all the .d.ts files in the project
const typeDefs = await walk(process.cwd(), '.d.ts');

// Check for any sub-module imports in the type definitions
const regex = /import\("@sentry\/.+\//gi;
let failed = false;

for (const file of typeDefs) {
const content = await fs.readFile(file, 'utf-8');
const matches = content.match(regex);
if (matches) {
console.log(`Sub-module import in type def file '${file}':\n`, matches);
failed = true;
}
}

if (failed) {
process.exit(1);
}
5 changes: 4 additions & 1 deletion src/main/integrations/anr.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { defineIntegration } from '@sentry/core';
import { anrIntegration as nodeAnrIntegration } from '@sentry/node';
import { Integration } from '@sentry/types';
import { app, powerMonitor } from 'electron';

import { ELECTRON_MAJOR_VERSION } from '../electron-normalize';

type Options = Parameters<typeof nodeAnrIntegration>[0];

/**
* Starts a worker thread to detect App Not Responding (ANR) events
*/
export const anrIntegration = defineIntegration((options: Parameters<typeof nodeAnrIntegration>[0] = {}) => {
export const anrIntegration: (options: Options) => Integration = defineIntegration((options: Options = {}) => {
if (ELECTRON_MAJOR_VERSION < 22) {
throw new Error('Main process ANR detection requires Electron v22+');
}
Expand Down

0 comments on commit 87fa64a

Please sign in to comment.