Add @snowluma/websocket TS package and integrate
Introduce an in-tree TypeScript WebSocket package (@snowluma/websocket): move JS websocket implementation into packages/websocket/src (client, server, websocket, extensions, native, index) and add package.json + tsconfig. Replace direct 'ws' dependency in core with the workspace package and update runtime manifest/description. Implement a native addon loader for platform-specific binaries, add typings/refinements across client/server/websocket (more strict types, handshake parsing, permessage-deflate plumbing, buffer/raw data handling), and wire WebSocketClient as the package default export while exposing internal types. Update vite config to bundle the new package and copy only platform-target native binaries into dist/native. Remove legacy JS entrypoints and native loader, and adjust imports/usages in core (ws-transport) to accept broader raw data types.
This commit is contained in:
1 parent
5fb969da7c
commit
252a65b833
15 files changed
+645
-436
No files matched your search
@@ -13,9 +13,9 @@ const nativeDir = path.resolve(runtimeDir, 'native');
|
||||
// vite-plugin-cp consumes globs through globby; on Windows we must use POSIX-style separators.
|
||||
const toPosix = (p: string) => p.replace(/\\/g, '/');
|
||||
|
||||
const external = [
|
||||
'ws'
|
||||
];
|
||||
// `@snowluma/websocket` is bundled (it's an in-tree TS workspace package), so
|
||||
// it must NOT be marked external. Only Node builtins stay external.
|
||||
const external: string[] = [];
|
||||
|
||||
const nodeModules = [...builtinModules, ...builtinModules.map((m) => `node:${m}`), 'node:sqlite'].flat();
|
||||
|
||||
@@ -26,6 +26,15 @@ const nativeSrc = toPosix(nativeDir);
|
||||
// (.gitignore and other dev artifacts must NOT be shipped.)
|
||||
const runtimeDistFiles = ['launcher.bat', 'package.json'];
|
||||
|
||||
// Only ship native binaries matching the current build host's platform/arch.
|
||||
// Override via SNOWLUMA_TARGET=<platform>-<arch> for cross-target packaging.
|
||||
const targetTriple = process.env.SNOWLUMA_TARGET ?? `${process.platform}-${process.arch}`;
|
||||
const nativeGlobs = [
|
||||
`snowluma-${targetTriple}.dll`,
|
||||
`snowluma-${targetTriple}.node`,
|
||||
`websocket-${targetTriple}.node`,
|
||||
];
|
||||
|
||||
const BaseConfigPlugin: PluginOption[] = [
|
||||
cp({
|
||||
targets: [
|
||||
@@ -34,7 +43,11 @@ const BaseConfigPlugin: PluginOption[] = [
|
||||
dest: distDir,
|
||||
flatten: true,
|
||||
})),
|
||||
{ src: `${nativeSrc}/*`, dest: path.join(distDir, 'native'), flatten: true },
|
||||
...nativeGlobs.map((g) => ({
|
||||
src: `${nativeSrc}/${g}`,
|
||||
dest: path.join(distDir, 'native'),
|
||||
flatten: true,
|
||||
})),
|
||||
]
|
||||
})
|
||||
];
|
||||
|
||||
Reference in new issue
Block a user