Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: No sub-module imports in type definitions #958

Merged
merged 1 commit into from
Aug 16, 2024
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
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
Loading