feat(core): add staged self-updates and unify application version

This commit is contained in:
手瓜一十雪 committed 2026-10-18 12:50:11 +08:00
1 parent c54aeffc77
commit 5032cbb8c0
45 files changed
+1860 -165

No files matched your search

+19 -2
View File
@@ -132,5 +132,22 @@ function tryLoad(): NativeAddon {
}
}
const addon: NativeAddon = tryLoad();
export default addon;
let addon: NativeAddon | undefined;
function getAddon(): NativeAddon {
return (addon ??= tryLoad());
}
const native: NativeAddon = {
get Parser() {
return getAddon().Parser;
},
buildFrame(...args) {
return getAddon().buildFrame(...args);
},
computeAcceptKey(key) {
return getAddon().computeAcceptKey(key);
},
};
export default native;
+14 -1
View File
@@ -92,7 +92,9 @@ function restoreDevNoNative(): void {
}
async function loadNative(): Promise<NativeAddon> {
return (await import('../src/native')).default;
const addon = (await import('../src/native')).default;
void addon.Parser;
return addon;
}
function installFakeAddon(exports: NativeAddon): string[] {
@@ -403,6 +405,17 @@ describe('addon path resolution', () => {
afterEach(cleanupLoaderTest);
it('does not load a native library until first use, then caches it', async () => {
const opened = installFakeAddon(fakeAddon('lazy'));
existsSyncMock.mockReturnValue(true);
const addon = (await import('../src/native')).default;
expect(opened).toEqual([]);
expect(existsSyncMock).not.toHaveBeenCalled();
expect(addon.computeAcceptKey(RFC_KEY)).toBe('lazy');
expect(addon.computeAcceptKey(RFC_KEY)).toBe('lazy');
expect(opened).toHaveLength(1);
});
it('dlopens the first existing websocket-<platform>-<arch>.node candidate', async () => {
const opened = installFakeAddon(fakeAddon('from-first-hit'));
const winner = candidatePaths()[2]!;