diff --git a/openless-all/app/android/frontend/components/AndroidPermissionsPanel.tsx b/openless-all/app/android/frontend/components/AndroidPermissionsPanel.tsx index 959a5565..ff667399 100644 --- a/openless-all/app/android/frontend/components/AndroidPermissionsPanel.tsx +++ b/openless-all/app/android/frontend/components/AndroidPermissionsPanel.tsx @@ -1,7 +1,7 @@ import { useEffect, useRef, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { Icon } from '../../../src/components/Icon'; -import { getSettings, setSettings } from '../../../src/lib/ipc'; +import { getSettings, setSettings } from '../../../src/lib/ipc/settings'; import type { UserPreferences } from '../../../src/lib/types'; import { Btn, Pill } from '../../../src/pages/_atoms'; import { SettingRow } from '../../../src/pages/settings/shared'; diff --git a/openless-all/app/package.json b/openless-all/app/package.json index 65be9c15..c0d5a89b 100644 --- a/openless-all/app/package.json +++ b/openless-all/app/package.json @@ -5,6 +5,7 @@ "type": "module", "scripts": { "dev": "vite", + "prebuild": "node scripts/android-ipc-import-boundary.test.mjs", "build": "tsc && vite build", "preview": "vite preview", "tauri": "tauri", diff --git a/openless-all/app/scripts/android-ipc-import-boundary.test.mjs b/openless-all/app/scripts/android-ipc-import-boundary.test.mjs new file mode 100644 index 00000000..32b8a49d --- /dev/null +++ b/openless-all/app/scripts/android-ipc-import-boundary.test.mjs @@ -0,0 +1,29 @@ +import { readFile } from 'node:fs/promises'; + +const panelUrl = new URL( + '../android/frontend/components/AndroidPermissionsPanel.tsx', + import.meta.url, +); +const source = await readFile(panelUrl, 'utf8'); +const imports = [...source.matchAll(/import\s+([\s\S]*?)\s+from\s+['"]([^'"]+)['"];?/g)]; + +function moduleFor(name) { + return imports + .filter(([, bindings]) => new RegExp(`\\b${name}\\b`).test(bindings)) + .map(([, , moduleName]) => moduleName); +} + +for (const name of ['getSettings', 'setSettings']) { + const modules = moduleFor(name); + if (modules.length !== 1 || modules[0] !== '../../../src/lib/ipc/settings') { + throw new Error( + `${name} must be imported directly from ../../../src/lib/ipc/settings; found ${JSON.stringify(modules)}`, + ); + } +} + +if (/from\s+['"]\.\.\/\.\.\/\.\.\/src\/lib\/ipc['"]/.test(source)) { + throw new Error('AndroidPermissionsPanel must not import through the IPC barrel'); +} + +console.log('android-ipc-import-boundary.test.mjs passed');