@flighthq/host-tauri 0.5.1-next.920.da8f530 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/contract.d.ts +12 -15
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +12 -15
- package/dist/contract.js.map +1 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -1
- package/dist/index.js.map +1 -1
- package/dist/tauriApp.d.ts +10 -3
- package/dist/tauriApp.d.ts.map +1 -1
- package/dist/tauriApp.js +51 -34
- package/dist/tauriApp.js.map +1 -1
- package/dist/tauriClipboard.d.ts +4 -3
- package/dist/tauriClipboard.d.ts.map +1 -1
- package/dist/tauriClipboard.js +11 -11
- package/dist/tauriClipboard.js.map +1 -1
- package/dist/tauriDialog.d.ts +8 -9
- package/dist/tauriDialog.d.ts.map +1 -1
- package/dist/tauriDialog.js +32 -25
- package/dist/tauriDialog.js.map +1 -1
- package/dist/tauriHost.d.ts +4 -0
- package/dist/tauriHost.d.ts.map +1 -0
- package/dist/tauriHost.js +70 -0
- package/dist/tauriHost.js.map +1 -0
- package/dist/tauriHostGroups.d.ts +85 -0
- package/dist/tauriHostGroups.d.ts.map +1 -0
- package/dist/tauriHostGroups.js +2 -0
- package/dist/tauriHostGroups.js.map +1 -0
- package/dist/tauriMenu.d.ts +6 -3
- package/dist/tauriMenu.d.ts.map +1 -1
- package/dist/tauriMenu.js +42 -26
- package/dist/tauriMenu.js.map +1 -1
- package/dist/tauriNotification.d.ts +6 -3
- package/dist/tauriNotification.d.ts.map +1 -1
- package/dist/tauriNotification.js +35 -20
- package/dist/tauriNotification.js.map +1 -1
- package/dist/tauriPlatform.d.ts +4 -3
- package/dist/tauriPlatform.d.ts.map +1 -1
- package/dist/tauriPlatform.js +6 -10
- package/dist/tauriPlatform.js.map +1 -1
- package/dist/tauriShell.d.ts +6 -5
- package/dist/tauriShell.d.ts.map +1 -1
- package/dist/tauriShell.js +24 -24
- package/dist/tauriShell.js.map +1 -1
- package/dist/tauriShortcut.d.ts +5 -5
- package/dist/tauriShortcut.d.ts.map +1 -1
- package/dist/tauriShortcut.js +20 -19
- package/dist/tauriShortcut.js.map +1 -1
- package/dist/tauriTray.d.ts +11 -3
- package/dist/tauriTray.d.ts.map +1 -1
- package/dist/tauriTray.js +260 -227
- package/dist/tauriTray.js.map +1 -1
- package/dist/tauriUnsupportedHostGroups.d.ts +70 -0
- package/dist/tauriUnsupportedHostGroups.d.ts.map +1 -0
- package/dist/tauriUnsupportedHostGroups.js +127 -0
- package/dist/tauriUnsupportedHostGroups.js.map +1 -0
- package/dist/tauriWindow.d.ts +5 -3
- package/dist/tauriWindow.d.ts.map +1 -1
- package/dist/tauriWindow.js +209 -132
- package/dist/tauriWindow.js.map +1 -1
- package/dist/types.d.ts +251 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +40 -16
- package/src/tauriApp.test.ts +55 -12
- package/src/tauriClipboard.test.ts +13 -14
- package/src/tauriDialog.test.ts +37 -57
- package/src/tauriHost.test.ts +312 -0
- package/src/tauriMenu.test.ts +41 -26
- package/src/tauriNotification.test.ts +31 -13
- package/src/tauriPackage.test.ts +295 -0
- package/src/tauriPlatform.test.ts +16 -11
- package/src/tauriShell.test.ts +31 -34
- package/src/tauriShortcut.test.ts +15 -29
- package/src/tauriTray.test.ts +108 -49
- package/src/tauriUnsupportedHostGroups.test.ts +125 -0
- package/src/tauriWindow.test.ts +98 -85
- package/dist/tauriRegister.d.ts +0 -4
- package/dist/tauriRegister.d.ts.map +0 -1
- package/dist/tauriRegister.js +0 -69
- package/dist/tauriRegister.js.map +0 -1
- package/src/tauriRegister.test.ts +0 -91
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import { EntityRuntimeKey } from '@flighthq/
|
|
2
|
-
import type { TauriApi, TauriNotificationOptions, TauriNotificationPermission } from '@flighthq/types/contract';
|
|
1
|
+
import { EntityRuntimeKey } from '@flighthq/entity/contract';
|
|
3
2
|
|
|
4
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
tauriHostNotification,
|
|
5
|
+
tauriHostNotificationDelivery,
|
|
6
|
+
tauriHostNotificationLifecycle,
|
|
7
|
+
tauriHostNotificationPermission,
|
|
8
|
+
} from './tauriNotification.ts';
|
|
9
|
+
import type { TauriApi, TauriNotificationOptions, TauriNotificationPermission } from './types.ts';
|
|
5
10
|
|
|
6
11
|
function fakeTauri(granted = true, permission: TauriNotificationPermission = 'granted') {
|
|
7
12
|
const sent: TauriNotificationOptions[] = [];
|
|
@@ -19,16 +24,16 @@ function fakeTauri(granted = true, permission: TauriNotificationPermission = 'gr
|
|
|
19
24
|
return { notification, sent, tauri: { notification } as unknown as TauriApi };
|
|
20
25
|
}
|
|
21
26
|
|
|
22
|
-
describe('
|
|
27
|
+
describe('tauriHostNotification', () => {
|
|
23
28
|
it('constructs exactly permission, delivery, and lifecycle', () => {
|
|
24
|
-
const capabilities =
|
|
25
|
-
expect(EntityRuntimeKey in capabilities).toBe(
|
|
29
|
+
const capabilities = tauriHostNotification(fakeTauri().tauri);
|
|
30
|
+
expect(EntityRuntimeKey in capabilities).toBe(false);
|
|
26
31
|
expect(Object.keys(capabilities).sort()).toEqual(['delivery', 'lifecycle', 'permission']);
|
|
27
32
|
});
|
|
28
33
|
|
|
29
34
|
it('reports provider acceptance without claiming display success', async () => {
|
|
30
35
|
const { sent, tauri } = fakeTauri();
|
|
31
|
-
const capabilities =
|
|
36
|
+
const capabilities = tauriHostNotification(tauri);
|
|
32
37
|
const outcome = await capabilities.delivery.notify({
|
|
33
38
|
body: 'there',
|
|
34
39
|
id: 'n1',
|
|
@@ -42,7 +47,7 @@ describe('createTauriNotificationCapabilities', () => {
|
|
|
42
47
|
});
|
|
43
48
|
|
|
44
49
|
it('reports permission denial and operation failure distinctly', async () => {
|
|
45
|
-
const denied =
|
|
50
|
+
const denied = tauriHostNotification(fakeTauri(false).tauri);
|
|
46
51
|
await expect(denied.delivery.notify({ title: 'No' })).resolves.toEqual({
|
|
47
52
|
reason: 'permission-denied',
|
|
48
53
|
});
|
|
@@ -50,7 +55,7 @@ describe('createTauriNotificationCapabilities', () => {
|
|
|
50
55
|
fixture.notification.isPermissionGranted = async () => {
|
|
51
56
|
throw new Error('native failed');
|
|
52
57
|
};
|
|
53
|
-
const failed =
|
|
58
|
+
const failed = tauriHostNotification(fixture.tauri);
|
|
54
59
|
await expect(failed.permission.getPermission()).resolves.toEqual({
|
|
55
60
|
reason: 'operation-failed',
|
|
56
61
|
});
|
|
@@ -60,15 +65,28 @@ describe('createTauriNotificationCapabilities', () => {
|
|
|
60
65
|
});
|
|
61
66
|
|
|
62
67
|
it('rejects fields the built Tauri profile cannot carry', async () => {
|
|
63
|
-
const capabilities =
|
|
68
|
+
const capabilities = tauriHostNotification(fakeTauri().tauri);
|
|
64
69
|
await expect(capabilities.delivery.notify({ silent: true, title: 'No' })).resolves.toEqual({
|
|
65
70
|
fields: ['silent'],
|
|
66
71
|
reason: 'invalid-request',
|
|
67
72
|
});
|
|
68
73
|
});
|
|
69
74
|
});
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
75
|
+
|
|
76
|
+
describe('tauriHostNotificationDelivery', () => {
|
|
77
|
+
it('constructs the delivery provider independently', () => {
|
|
78
|
+
expect(tauriHostNotificationDelivery(fakeTauri().tauri).notify).toBeTypeOf('function');
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
describe('tauriHostNotificationLifecycle', () => {
|
|
83
|
+
it('constructs the lifecycle provider independently', () => {
|
|
84
|
+
expect(tauriHostNotificationLifecycle(fakeTauri().tauri).destroy).toBeTypeOf('function');
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
describe('tauriHostNotificationPermission', () => {
|
|
89
|
+
it('constructs the permission provider independently', () => {
|
|
90
|
+
expect(tauriHostNotificationPermission(fakeTauri().tauri).getPermission).toBeTypeOf('function');
|
|
73
91
|
});
|
|
74
92
|
});
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import { mkdtempSync, readFileSync, readdirSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { join, resolve } from 'node:path';
|
|
5
|
+
|
|
6
|
+
import { rollup } from 'rollup';
|
|
7
|
+
import type { OutputChunk } from 'rollup';
|
|
8
|
+
import ts from 'typescript5';
|
|
9
|
+
import { beforeAll, describe, expect, it } from 'vitest';
|
|
10
|
+
|
|
11
|
+
import * as publicApi from './index.ts';
|
|
12
|
+
|
|
13
|
+
const ROOT = resolve(__dirname, '../../..');
|
|
14
|
+
const PACKAGE_ROOT = resolve(__dirname, '..');
|
|
15
|
+
const DIST_ROOT = resolve(PACKAGE_ROOT, 'dist');
|
|
16
|
+
const PACK_TIMEOUT_MS = 120_000;
|
|
17
|
+
// Cannot find module, and a module that resolves but lacks the imported name: either one reads as `any`.
|
|
18
|
+
const UNRESOLVED_DIAGNOSTIC_CODES: ReadonlySet<number> = new Set([2305, 2307, 2614, 2724]);
|
|
19
|
+
|
|
20
|
+
const ENTITY_CONSTRUCTORS = ['tauriHost'] as const;
|
|
21
|
+
|
|
22
|
+
const LEAF_MODULE_BY_EXPORT = {
|
|
23
|
+
tauriHostAppHide: 'tauriApp.js',
|
|
24
|
+
tauriHostAppLocale: 'tauriApp.js',
|
|
25
|
+
tauriHostAppName: 'tauriApp.js',
|
|
26
|
+
tauriHostAppQuit: 'tauriApp.js',
|
|
27
|
+
tauriHostAppRelaunch: 'tauriApp.js',
|
|
28
|
+
tauriHostAppShow: 'tauriApp.js',
|
|
29
|
+
tauriHostAppVersion: 'tauriApp.js',
|
|
30
|
+
tauriHostClipboardText: 'tauriClipboard.js',
|
|
31
|
+
tauriHostDirectoryOpenDialog: 'tauriDialog.js',
|
|
32
|
+
tauriHostFileOpenDialog: 'tauriDialog.js',
|
|
33
|
+
tauriHostFileSaveDialog: 'tauriDialog.js',
|
|
34
|
+
tauriHostAppMenu: 'tauriMenu.js',
|
|
35
|
+
tauriHostMenuPopup: 'tauriMenu.js',
|
|
36
|
+
tauriHostMenuSelect: 'tauriMenu.js',
|
|
37
|
+
tauriHostMessageDialog: 'tauriDialog.js',
|
|
38
|
+
tauriHostNotificationDelivery: 'tauriNotification.js',
|
|
39
|
+
tauriHostNotificationLifecycle: 'tauriNotification.js',
|
|
40
|
+
tauriHostNotificationPermission: 'tauriNotification.js',
|
|
41
|
+
tauriHostPlatform: 'tauriPlatform.js',
|
|
42
|
+
tauriHostShellExternal: 'tauriShell.js',
|
|
43
|
+
tauriHostShellPathOpen: 'tauriShell.js',
|
|
44
|
+
tauriHostShellPathReveal: 'tauriShell.js',
|
|
45
|
+
tauriHostShortcutQuery: 'tauriShortcut.js',
|
|
46
|
+
tauriHostShortcutTrigger: 'tauriShortcut.js',
|
|
47
|
+
tauriHostTrayImage: 'tauriTray.js',
|
|
48
|
+
tauriHostTrayInteractionEvents: 'tauriTray.js',
|
|
49
|
+
tauriHostTrayLifecycle: 'tauriTray.js',
|
|
50
|
+
tauriHostTrayMenu: 'tauriTray.js',
|
|
51
|
+
tauriHostTrayMenuSelectionEvents: 'tauriTray.js',
|
|
52
|
+
tauriHostTrayTemplateImage: 'tauriTray.js',
|
|
53
|
+
tauriHostTrayTitle: 'tauriTray.js',
|
|
54
|
+
tauriHostTrayTooltip: 'tauriTray.js',
|
|
55
|
+
tauriHostWindow: 'tauriWindow.js',
|
|
56
|
+
} as const;
|
|
57
|
+
|
|
58
|
+
interface PackedFile {
|
|
59
|
+
path: string;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
interface PackResult {
|
|
63
|
+
files: PackedFile[];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
let packedFiles: string[];
|
|
67
|
+
|
|
68
|
+
// `npm pack` would run this package's `prepack`, whose `tsc -b --clean` walks every project reference and
|
|
69
|
+
// deletes then rebuilds thousands of files across the referenced packages on every test run, while other
|
|
70
|
+
// workers read them. Cleaning only this package's outputs and letting
|
|
71
|
+
// `tsc -b` rebuild incrementally still packs a fresh, clean build of the surface under test.
|
|
72
|
+
beforeAll(() => {
|
|
73
|
+
execFileSync('npm', ['run', 'clean:dist'], { cwd: PACKAGE_ROOT, stdio: 'ignore' });
|
|
74
|
+
execFileSync(process.execPath, [resolve(ROOT, 'node_modules/typescript/bin/tsc'), '-b'], {
|
|
75
|
+
cwd: PACKAGE_ROOT,
|
|
76
|
+
stdio: 'ignore',
|
|
77
|
+
});
|
|
78
|
+
const output = execFileSync('npm', ['pack', '--dry-run', '--json', '--ignore-scripts'], {
|
|
79
|
+
cwd: PACKAGE_ROOT,
|
|
80
|
+
encoding: 'utf8',
|
|
81
|
+
});
|
|
82
|
+
const packed = JSON.parse(output) as PackResult[];
|
|
83
|
+
packedFiles = packed[0]!.files.map((file) => file.path).sort();
|
|
84
|
+
}, PACK_TIMEOUT_MS);
|
|
85
|
+
|
|
86
|
+
// These build TypeScript programs over the emitted declarations: a few hundred milliseconds alone, but they
|
|
87
|
+
// share the CPU with every other worker in the aggregate run. The budget is contention headroom, not a deadline.
|
|
88
|
+
describe('packed Tauri host surface', { timeout: 30_000 }, () => {
|
|
89
|
+
it('ships exactly one clean build of every production source module', () => {
|
|
90
|
+
const sourceModules = readdirSync(resolve(PACKAGE_ROOT, 'src'))
|
|
91
|
+
.filter((name) => name.endsWith('.ts') && !name.endsWith('.test.ts'))
|
|
92
|
+
.map((name) => name.slice(0, -'.ts'.length));
|
|
93
|
+
const expected = sourceModules
|
|
94
|
+
.flatMap((module) => ['d.ts', 'd.ts.map', 'js', 'js.map'].map((extension) => `dist/${module}.${extension}`))
|
|
95
|
+
.sort();
|
|
96
|
+
const emitted = packedFiles.filter((path) => path.startsWith('dist/'));
|
|
97
|
+
|
|
98
|
+
expect(emitted).toEqual(expected);
|
|
99
|
+
expect(emitted.some((path) => path.includes('.test.'))).toBe(false);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('contains no retired Tauri constructors, backends, initializer, registrar, or module', () => {
|
|
103
|
+
const retiredModule = ['tauri', 'Register'].join('');
|
|
104
|
+
const backendSuffix = ['Back', 'end'].join('');
|
|
105
|
+
const backendName = new RegExp(String.raw`\b[A-Za-z][A-Za-z0-9]*${backendSuffix}s?\b`, 'u');
|
|
106
|
+
const packedText = packedFiles
|
|
107
|
+
.filter((path) => /\.(?:[cm]?[jt]s|json|map)$/u.test(path))
|
|
108
|
+
.map((path) => readFileSync(resolve(PACKAGE_ROOT, path), 'utf8'))
|
|
109
|
+
.join('\n');
|
|
110
|
+
|
|
111
|
+
expect(packedFiles.filter((path) => path.includes(retiredModule))).toEqual([]);
|
|
112
|
+
expect(packedText).not.toMatch(/\b(?:create|initialize|register|make)Tauri[A-Z][A-Za-z0-9]*\b/u);
|
|
113
|
+
expect(packedText).not.toMatch(backendName);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('keeps emitted public and contract declarations exactly aligned', () => {
|
|
117
|
+
const { checker, contractSource, publicSource } = declarationProgram();
|
|
118
|
+
const runtimeNames = Object.keys(publicApi).sort();
|
|
119
|
+
|
|
120
|
+
expect(moduleExportNames(checker, publicSource)).toEqual(runtimeNames);
|
|
121
|
+
expect(moduleExportNames(checker, contractSource)).toEqual(runtimeNames);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('emits Entity return types for exactly the constructors that allocate entities', () => {
|
|
125
|
+
const { checker, entitySource, publicSource } = declarationProgram();
|
|
126
|
+
const entitySymbol = moduleExports(checker, entitySource).find((symbol) => symbol.name === 'Entity');
|
|
127
|
+
expect(entitySymbol).toBeDefined();
|
|
128
|
+
const entityType = checker.getDeclaredTypeOfSymbol(entitySymbol!);
|
|
129
|
+
const entityConstructors = moduleExports(checker, publicSource)
|
|
130
|
+
.filter((symbol) => {
|
|
131
|
+
const declaration = resolvedSymbol(checker, symbol).declarations?.[0];
|
|
132
|
+
if (declaration === undefined) return false;
|
|
133
|
+
const signature = checker.getSignaturesOfType(
|
|
134
|
+
checker.getTypeOfSymbolAtLocation(resolvedSymbol(checker, symbol), declaration),
|
|
135
|
+
ts.SignatureKind.Call,
|
|
136
|
+
)[0];
|
|
137
|
+
return (
|
|
138
|
+
signature !== undefined && checker.isTypeAssignableTo(checker.getReturnTypeOfSignature(signature), entityType)
|
|
139
|
+
);
|
|
140
|
+
})
|
|
141
|
+
.map((symbol) => symbol.name)
|
|
142
|
+
.sort();
|
|
143
|
+
|
|
144
|
+
expect(entityConstructors).toEqual([...ENTITY_CONSTRUCTORS].sort());
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// Each leaf is a real rollup bundle of the emitted package, every supported leaf at once: CPU-bound work that
|
|
149
|
+
// shares the machine with every other worker in the aggregate run. The budget is contention headroom.
|
|
150
|
+
describe('packed Tauri leaf isolation', { timeout: 30_000 }, () => {
|
|
151
|
+
const isolatedLeaves = [
|
|
152
|
+
{
|
|
153
|
+
exportName: 'tauriHostAppMenu',
|
|
154
|
+
module: 'tauriMenu.js',
|
|
155
|
+
siblingTokens: ['LogicalPosition', '.popup(', '.subscribe('],
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
exportName: 'tauriHostNotificationDelivery',
|
|
159
|
+
module: 'tauriNotification.js',
|
|
160
|
+
siblingTokens: ['already-destroyed', 'requestPermission'],
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
exportName: 'tauriHostTrayTooltip',
|
|
164
|
+
module: 'tauriTray.js',
|
|
165
|
+
siblingTokens: ['TrayIcon.new', '.setIcon(', '.setMenu(', '.setTitle(', '.setIconAsTemplate('],
|
|
166
|
+
},
|
|
167
|
+
] as const;
|
|
168
|
+
|
|
169
|
+
it('retains exactly one Tauri implementation module for every supported leaf', async () => {
|
|
170
|
+
const actual = Object.fromEntries(
|
|
171
|
+
await Promise.all(
|
|
172
|
+
Object.entries(LEAF_MODULE_BY_EXPORT).map(async ([exportName]) => {
|
|
173
|
+
const modules = implementationModuleNames(await bundleLeaf(exportName));
|
|
174
|
+
expect(modules, exportName).toHaveLength(1);
|
|
175
|
+
return [exportName, modules[0]];
|
|
176
|
+
}),
|
|
177
|
+
),
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
expect(actual).toEqual(LEAF_MODULE_BY_EXPORT);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
for (const leaf of isolatedLeaves) {
|
|
184
|
+
it(`${leaf.exportName} retains only its leaf implementation`, async () => {
|
|
185
|
+
const chunk = await bundleLeaf(leaf.exportName);
|
|
186
|
+
|
|
187
|
+
expect(implementationModuleNames(chunk)).toEqual([leaf.module]);
|
|
188
|
+
for (const siblingToken of leaf.siblingTokens) expect(chunk.code).not.toContain(siblingToken);
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
function declarationProgram(): {
|
|
194
|
+
checker: ts.TypeChecker;
|
|
195
|
+
contractSource: ts.SourceFile;
|
|
196
|
+
entitySource: ts.SourceFile;
|
|
197
|
+
publicSource: ts.SourceFile;
|
|
198
|
+
} {
|
|
199
|
+
const publicPath = resolve(DIST_ROOT, 'index.d.ts');
|
|
200
|
+
const contractPath = resolve(DIST_ROOT, 'contract.d.ts');
|
|
201
|
+
// The Entity base, stated from @flighthq/entity's emitted vocabulary: a raw record carrying the runtime slot.
|
|
202
|
+
const entityPath = join(mkdtempSync(join(tmpdir(), 'flight-tauri-entity-')), 'Entity.d.ts');
|
|
203
|
+
const entityTypes = resolve(ROOT, 'packages/entity/dist/types.js');
|
|
204
|
+
writeFileSync(
|
|
205
|
+
entityPath,
|
|
206
|
+
`import type { EntityRaw, EntityRuntime, EntityRuntimeKey } from '${entityTypes}';\n` +
|
|
207
|
+
'export interface Entity extends EntityRaw {\n [EntityRuntimeKey]: EntityRuntime | undefined;\n}\n',
|
|
208
|
+
);
|
|
209
|
+
// The package builds against several contract-types projects (tsconfig `moduleSuffixes`), each of which emits
|
|
210
|
+
// only `contract.<pkg>-types.d.ts`, so resolve every such `@flighthq/<pkg>/contract` to that declaration as the
|
|
211
|
+
// build does. A full `dist/contract.d.ts` left over from an earlier build may lack the names, and a missing name
|
|
212
|
+
// reads as `any`, which is assignable to `Entity`.
|
|
213
|
+
const program = ts.createProgram([publicPath, contractPath, entityPath], {
|
|
214
|
+
module: ts.ModuleKind.ESNext,
|
|
215
|
+
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
216
|
+
paths: contractTypesPaths(),
|
|
217
|
+
skipLibCheck: true,
|
|
218
|
+
target: ts.ScriptTarget.ESNext,
|
|
219
|
+
});
|
|
220
|
+
const unresolved = ts
|
|
221
|
+
.getPreEmitDiagnostics(program)
|
|
222
|
+
.filter((diagnostic) => UNRESOLVED_DIAGNOSTIC_CODES.has(diagnostic.code))
|
|
223
|
+
.map((diagnostic) => ts.flattenDiagnosticMessageText(diagnostic.messageText, ' '));
|
|
224
|
+
expect(unresolved).toEqual([]);
|
|
225
|
+
return {
|
|
226
|
+
checker: program.getTypeChecker(),
|
|
227
|
+
contractSource: program.getSourceFile(contractPath)!,
|
|
228
|
+
entitySource: program.getSourceFile(entityPath)!,
|
|
229
|
+
publicSource: program.getSourceFile(publicPath)!,
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function contractTypesPaths(): Record<string, string[]> {
|
|
234
|
+
const tsconfig = JSON.parse(readFileSync(resolve(PACKAGE_ROOT, 'tsconfig.json'), 'utf8')) as {
|
|
235
|
+
compilerOptions: { moduleSuffixes: string[] };
|
|
236
|
+
};
|
|
237
|
+
const paths: Record<string, string[]> = {};
|
|
238
|
+
for (const suffix of tsconfig.compilerOptions.moduleSuffixes) {
|
|
239
|
+
const match = /^\.(.+)-types$/u.exec(suffix);
|
|
240
|
+
if (match === null) continue;
|
|
241
|
+
const name = match[1]!;
|
|
242
|
+
paths[`@flighthq/${name}/contract`] = [resolve(ROOT, `packages/${name}/dist/contract.${name}-types.d.ts`)];
|
|
243
|
+
}
|
|
244
|
+
return paths;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function moduleExports(checker: ts.TypeChecker, source: ts.SourceFile): ts.Symbol[] {
|
|
248
|
+
const symbol = checker.getSymbolAtLocation(source);
|
|
249
|
+
expect(symbol).toBeDefined();
|
|
250
|
+
return checker.getExportsOfModule(symbol!);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function moduleExportNames(checker: ts.TypeChecker, source: ts.SourceFile): string[] {
|
|
254
|
+
return moduleExports(checker, source)
|
|
255
|
+
.map((symbol) => symbol.name)
|
|
256
|
+
.sort();
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function resolvedSymbol(checker: ts.TypeChecker, symbol: ts.Symbol): ts.Symbol {
|
|
260
|
+
return symbol.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function implementationModuleNames(chunk: OutputChunk): string[] {
|
|
264
|
+
return Object.keys(chunk.modules)
|
|
265
|
+
.filter((id) => id.startsWith(DIST_ROOT) && !id.endsWith('/index.js'))
|
|
266
|
+
.map((id) => id.slice(DIST_ROOT.length + 1));
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
async function bundleLeaf(exportName: string): Promise<OutputChunk> {
|
|
270
|
+
const entry = `virtual:${exportName}`;
|
|
271
|
+
const bundle = await rollup({
|
|
272
|
+
input: entry,
|
|
273
|
+
external: (id) => id.startsWith('@flighthq/'),
|
|
274
|
+
plugins: [
|
|
275
|
+
{
|
|
276
|
+
name: 'tauri-leaf-entry',
|
|
277
|
+
load(id) {
|
|
278
|
+
return id === entry
|
|
279
|
+
? `export { ${exportName} } from ${JSON.stringify(resolve(DIST_ROOT, 'index.js'))};`
|
|
280
|
+
: null;
|
|
281
|
+
},
|
|
282
|
+
resolveId(id) {
|
|
283
|
+
return id === entry ? id : null;
|
|
284
|
+
},
|
|
285
|
+
},
|
|
286
|
+
],
|
|
287
|
+
treeshake: { moduleSideEffects: false },
|
|
288
|
+
});
|
|
289
|
+
try {
|
|
290
|
+
const { output } = await bundle.generate({ format: 'es' });
|
|
291
|
+
return output.find((entry): entry is OutputChunk => entry.type === 'chunk')!;
|
|
292
|
+
} finally {
|
|
293
|
+
await bundle.close();
|
|
294
|
+
}
|
|
295
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { PlatformInfo
|
|
1
|
+
import type { PlatformInfo } from '@flighthq/platform/contract';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { tauriHostPlatform, tauriHostPlatformGroup } from './tauriPlatform.ts';
|
|
4
|
+
import type { TauriApi } from './types.ts';
|
|
4
5
|
|
|
5
6
|
function fakeTauri(platform: string): TauriApi {
|
|
6
7
|
return {
|
|
@@ -13,13 +14,12 @@ function fakeTauri(platform: string): TauriApi {
|
|
|
13
14
|
} as unknown as TauriApi;
|
|
14
15
|
}
|
|
15
16
|
|
|
16
|
-
describe('
|
|
17
|
+
describe('tauriHostPlatform', () => {
|
|
17
18
|
it('fills platform info from the os plugin', async () => {
|
|
18
|
-
const backend =
|
|
19
|
+
const backend = tauriHostPlatform(fakeTauri('macos'));
|
|
19
20
|
await Promise.resolve();
|
|
20
21
|
const out = {} as PlatformInfo;
|
|
21
|
-
|
|
22
|
-
expect(result).toBe(out);
|
|
22
|
+
backend.getInfo(out);
|
|
23
23
|
expect(out.name).toBe('macos');
|
|
24
24
|
expect(out.kind).toBe('desktop');
|
|
25
25
|
expect(out.version).toBe('14.2.1');
|
|
@@ -40,7 +40,7 @@ describe('createTauriPlatformBackend', () => {
|
|
|
40
40
|
};
|
|
41
41
|
for (const [tauriName, expected] of Object.entries(cases)) {
|
|
42
42
|
const out = {} as PlatformInfo;
|
|
43
|
-
|
|
43
|
+
tauriHostPlatform(fakeTauri(tauriName)).getInfo(out);
|
|
44
44
|
expect(out.name).toBe(expected);
|
|
45
45
|
}
|
|
46
46
|
});
|
|
@@ -50,12 +50,17 @@ describe('createTauriPlatformBackend', () => {
|
|
|
50
50
|
os: { arch: () => '', locale: async () => null, platform: () => 'linux', version: () => '' },
|
|
51
51
|
} as unknown as TauriApi;
|
|
52
52
|
const out = {} as PlatformInfo;
|
|
53
|
-
|
|
53
|
+
tauriHostPlatform(tauri).getInfo(out);
|
|
54
54
|
expect(out.locale).toBe('');
|
|
55
55
|
});
|
|
56
56
|
});
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
|
|
58
|
+
describe('tauriHostPlatformGroup', () => {
|
|
59
|
+
it('constructs exactly the platform info slot', () => {
|
|
60
|
+
const group = tauriHostPlatformGroup(fakeTauri('linux'));
|
|
61
|
+
expect(Object.keys(group)).toEqual(['info']);
|
|
62
|
+
const out = {} as PlatformInfo;
|
|
63
|
+
group.info.getInfo(out);
|
|
64
|
+
expect(out.name).toBe('linux');
|
|
60
65
|
});
|
|
61
66
|
});
|
package/src/tauriShell.test.ts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import type { TauriApi } from '@flighthq/types/contract';
|
|
2
|
-
import { EntityRuntimeKey } from '@flighthq/types/contract';
|
|
3
|
-
|
|
4
1
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} from './tauriShell';
|
|
2
|
+
tauriHostShell,
|
|
3
|
+
tauriHostShellExternal,
|
|
4
|
+
tauriHostShellPathOpen,
|
|
5
|
+
tauriHostShellPathReveal,
|
|
6
|
+
} from './tauriShell.ts';
|
|
7
|
+
import type { TauriApi } from './types.ts';
|
|
10
8
|
|
|
11
9
|
function fakeTauri(rejection: unknown = NO_REJECTION) {
|
|
12
10
|
const calls: { openUrl: string[]; openPath: string[]; reveal: string[] } = {
|
|
@@ -36,35 +34,16 @@ function fakeTauri(rejection: unknown = NO_REJECTION) {
|
|
|
36
34
|
return { tauri, calls };
|
|
37
35
|
}
|
|
38
36
|
|
|
39
|
-
describe('initializeTauriShellExternalBackend', () => {
|
|
40
|
-
it('is the construction initializer of createTauriShellExternalBackend', () => {
|
|
41
|
-
expect(typeof initializeTauriShellExternalBackend).toBe('function');
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
|
|
45
37
|
const NO_REJECTION = Symbol('no rejection');
|
|
46
|
-
describe('
|
|
47
|
-
it('
|
|
48
|
-
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
describe('initializeTauriShellPathRevealBackend', () => {
|
|
53
|
-
it('is the construction initializer of createTauriShellPathRevealBackend', () => {
|
|
54
|
-
expect(typeof initializeTauriShellPathRevealBackend).toBe('function');
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
describe('makeTauriShellCapabilities', () => {
|
|
59
|
-
it('constructs exactly three Entity providers', () => {
|
|
60
|
-
const capabilities = makeTauriShellCapabilities(fakeTauri().tauri);
|
|
38
|
+
describe('tauriHostShell', () => {
|
|
39
|
+
it('constructs exactly three providers', () => {
|
|
40
|
+
const capabilities = tauriHostShell(fakeTauri().tauri);
|
|
61
41
|
expect(Object.keys(capabilities).sort()).toEqual(['external', 'pathOpen', 'pathReveal']);
|
|
62
|
-
for (const provider of Object.values(capabilities)) expect(EntityRuntimeKey in provider).toBe(true);
|
|
63
42
|
});
|
|
64
43
|
|
|
65
44
|
it('opens URLs and paths and reveals through the opener plugin', async () => {
|
|
66
45
|
const { tauri, calls } = fakeTauri();
|
|
67
|
-
const capabilities =
|
|
46
|
+
const capabilities = tauriHostShell(tauri);
|
|
68
47
|
await expect(capabilities.external?.open('https://x.test')).resolves.toEqual({ reason: 'ok' });
|
|
69
48
|
await expect(capabilities.pathOpen?.open('/tmp/a')).resolves.toEqual({ reason: 'ok' });
|
|
70
49
|
await expect(capabilities.pathReveal?.reveal('/tmp/a')).resolves.toEqual({ reason: 'ok' });
|
|
@@ -74,7 +53,7 @@ describe('makeTauriShellCapabilities', () => {
|
|
|
74
53
|
});
|
|
75
54
|
|
|
76
55
|
it('preserves the path rejection message', async () => {
|
|
77
|
-
const capabilities =
|
|
56
|
+
const capabilities = tauriHostShell(fakeTauri(new Error('boom')).tauri);
|
|
78
57
|
await expect(capabilities.pathOpen?.open('/tmp/a')).resolves.toEqual({
|
|
79
58
|
message: 'boom',
|
|
80
59
|
reason: 'operation-failed',
|
|
@@ -82,12 +61,12 @@ describe('makeTauriShellCapabilities', () => {
|
|
|
82
61
|
});
|
|
83
62
|
|
|
84
63
|
it('does not turn an empty rejected path open into success', async () => {
|
|
85
|
-
const capabilities =
|
|
64
|
+
const capabilities = tauriHostShell(fakeTauri('').tauri);
|
|
86
65
|
await expect(capabilities.pathOpen?.open('/tmp/a')).resolves.toEqual({ message: '', reason: 'operation-failed' });
|
|
87
66
|
});
|
|
88
67
|
|
|
89
68
|
it('maps external and reveal rejection without inventing unsupported slots', async () => {
|
|
90
|
-
const capabilities =
|
|
69
|
+
const capabilities = tauriHostShell(fakeTauri(new Error('boom')).tauri);
|
|
91
70
|
await expect(capabilities.external?.open('https://x.test')).resolves.toEqual({ reason: 'operation-failed' });
|
|
92
71
|
await expect(capabilities.pathReveal?.reveal('/tmp/a')).resolves.toEqual({ reason: 'operation-failed' });
|
|
93
72
|
expect(capabilities.beep).toBeUndefined();
|
|
@@ -95,3 +74,21 @@ describe('makeTauriShellCapabilities', () => {
|
|
|
95
74
|
expect(capabilities.trash).toBeUndefined();
|
|
96
75
|
});
|
|
97
76
|
});
|
|
77
|
+
|
|
78
|
+
describe('tauriHostShellExternal', () => {
|
|
79
|
+
it('constructs the external provider', () => {
|
|
80
|
+
expect(tauriHostShellExternal(fakeTauri().tauri)).toBeDefined();
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
describe('tauriHostShellPathOpen', () => {
|
|
85
|
+
it('constructs the path open provider', () => {
|
|
86
|
+
expect(tauriHostShellPathOpen(fakeTauri().tauri)).toBeDefined();
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
describe('tauriHostShellPathReveal', () => {
|
|
91
|
+
it('constructs the path reveal provider', () => {
|
|
92
|
+
expect(tauriHostShellPathReveal(fakeTauri().tauri)).toBeDefined();
|
|
93
|
+
});
|
|
94
|
+
});
|
|
@@ -1,12 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
createTauriShortcutQueryBackend,
|
|
6
|
-
createTauriShortcutTriggerBackend,
|
|
7
|
-
initializeTauriShortcutQueryBackend,
|
|
8
|
-
initializeTauriShortcutTriggerBackend,
|
|
9
|
-
} from './tauriShortcut';
|
|
1
|
+
import { tauriHostShortcut, tauriHostShortcutQuery, tauriHostShortcutTrigger } from './tauriShortcut.ts';
|
|
2
|
+
import type { TauriApi, TauriShortcutEvent } from './types.ts';
|
|
10
3
|
|
|
11
4
|
interface Deferred {
|
|
12
5
|
readonly promise: Promise<void>;
|
|
@@ -42,27 +35,31 @@ function fakeTauri() {
|
|
|
42
35
|
return { handlers, tauri, unregisterCalls, unregisterFailures };
|
|
43
36
|
}
|
|
44
37
|
|
|
45
|
-
describe('
|
|
38
|
+
describe('tauriHostShortcut', () => {
|
|
39
|
+
it('constructs exactly the query and trigger group', () => {
|
|
40
|
+
const group = tauriHostShortcut(fakeTauri().tauri);
|
|
41
|
+
expect(Object.keys(group).sort()).toEqual(['query', 'trigger']);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe('tauriHostShortcutQuery', () => {
|
|
46
46
|
it('returns an Entity and awaits the plugin query', async () => {
|
|
47
47
|
const fake = fakeTauri();
|
|
48
48
|
fake.handlers.set('Control+K', () => {});
|
|
49
|
-
const provider =
|
|
50
|
-
expect(EntityRuntimeKey in provider).toBe(true);
|
|
49
|
+
const provider = tauriHostShortcutQuery(fake.tauri);
|
|
51
50
|
await expect(provider.isRegistered('Control+K')).resolves.toBe(true);
|
|
52
51
|
await expect(provider.isRegistered('Control+J')).resolves.toBe(false);
|
|
53
52
|
});
|
|
54
53
|
});
|
|
55
54
|
|
|
56
|
-
describe('
|
|
55
|
+
describe('tauriHostShortcutTrigger', () => {
|
|
57
56
|
it('returns an Entity, awaits acquisition, filters release events, and tears down by exact token', async () => {
|
|
58
57
|
const fake = fakeTauri();
|
|
59
|
-
const provider =
|
|
58
|
+
const provider = tauriHostShortcutTrigger(fake.tauri);
|
|
60
59
|
const trigger = vi.fn();
|
|
61
|
-
expect(EntityRuntimeKey in provider).toBe(true);
|
|
62
60
|
const outcome = await provider.subscribe('Control+K', trigger);
|
|
63
61
|
expect(outcome.reason).toBe('subscribed');
|
|
64
62
|
if (outcome.reason !== 'subscribed') return;
|
|
65
|
-
expect(EntityRuntimeKey in outcome.subscription).toBe(true);
|
|
66
63
|
fake.handlers.get('Control+K')?.({ shortcut: 'Control+K', state: 'Released' });
|
|
67
64
|
fake.handlers.get('Control+K')?.({ shortcut: 'Control+K', state: 'Pressed' });
|
|
68
65
|
expect(trigger).toHaveBeenCalledTimes(1);
|
|
@@ -75,7 +72,7 @@ describe('createTauriShortcutTriggerBackend', () => {
|
|
|
75
72
|
fake.tauri.globalShortcut.register = async () => {
|
|
76
73
|
throw new Error('registration failed');
|
|
77
74
|
};
|
|
78
|
-
const provider =
|
|
75
|
+
const provider = tauriHostShortcutTrigger(fake.tauri);
|
|
79
76
|
await expect(provider.subscribe('Control+K', () => {})).rejects.toThrow('registration failed');
|
|
80
77
|
await expect(provider.destroy()).resolves.toBeUndefined();
|
|
81
78
|
});
|
|
@@ -87,7 +84,7 @@ describe('createTauriShortcutTriggerBackend', () => {
|
|
|
87
84
|
if (accelerator === 'Control+A') await registration.promise;
|
|
88
85
|
fake.handlers.set(accelerator, handler);
|
|
89
86
|
};
|
|
90
|
-
const provider =
|
|
87
|
+
const provider = tauriHostShortcutTrigger(fake.tauri);
|
|
91
88
|
const pending = provider.subscribe('Control+A', () => {});
|
|
92
89
|
await provider.subscribe('Control+B', () => {});
|
|
93
90
|
fake.unregisterFailures.add('Control+A');
|
|
@@ -106,14 +103,3 @@ describe('createTauriShortcutTriggerBackend', () => {
|
|
|
106
103
|
expect(fake.unregisterCalls.filter((accelerator) => accelerator === 'Control+B')).toHaveLength(1);
|
|
107
104
|
});
|
|
108
105
|
});
|
|
109
|
-
describe('initializeTauriShortcutQueryBackend', () => {
|
|
110
|
-
it('is the construction initializer of createTauriShortcutQueryBackend', () => {
|
|
111
|
-
expect(typeof initializeTauriShortcutQueryBackend).toBe('function');
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
describe('initializeTauriShortcutTriggerBackend', () => {
|
|
116
|
-
it('is the construction initializer of createTauriShortcutTriggerBackend', () => {
|
|
117
|
-
expect(typeof initializeTauriShortcutTriggerBackend).toBe('function');
|
|
118
|
-
});
|
|
119
|
-
});
|