diff --git a/package.json b/package.json index b55f30a0..683ea561 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/scripts/check-types.mjs b/scripts/check-types.mjs new file mode 100644 index 00000000..7deccb40 --- /dev/null +++ b/scripts/check-types.mjs @@ -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); +} diff --git a/src/main/integrations/anr.ts b/src/main/integrations/anr.ts index f651d1ed..aad327c2 100644 --- a/src/main/integrations/anr.ts +++ b/src/main/integrations/anr.ts @@ -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[0]; + /** * Starts a worker thread to detect App Not Responding (ANR) events */ -export const anrIntegration = defineIntegration((options: Parameters[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+'); }