From 030059198a58f997425f6ff480b225adbfeff978 Mon Sep 17 00:00:00 2001 From: Luke Steyn Date: Tue, 10 Dec 2024 14:53:54 +1000 Subject: [PATCH 1/4] Fix isomorphic build --- sdk/scripts/postbuild.js | 27 +++++++++++++++++---------- sdk/src/isomorphic/grpc.ts | 26 +++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 11 deletions(-) diff --git a/sdk/scripts/postbuild.js b/sdk/scripts/postbuild.js index c632f74a7..7a6c9e29e 100644 --- a/sdk/scripts/postbuild.js +++ b/sdk/scripts/postbuild.js @@ -55,17 +55,24 @@ environments.forEach((environment) => { return; } - const otherTargetPath = path.join( - __dirname, - '..', - 'lib', - environment, - 'isomorphic', - `${package}.${otherEnvironment}.js` - ); + const otherTargetFiles = [ + `${package}.${otherEnvironment}.js`, + `${package}.${otherEnvironment}.d.ts`, + ]; + + for (const otherTargetFile of otherTargetFiles) { + const otherTargetPath = path.join( + __dirname, + '..', + 'lib', + environment, + 'isomorphic', + otherTargetFile + ); - if (fs.existsSync(otherTargetPath)) { - fs.unlinkSync(otherTargetPath); + if (fs.existsSync(otherTargetPath)) { + fs.unlinkSync(otherTargetPath); + } } }); }); diff --git a/sdk/src/isomorphic/grpc.ts b/sdk/src/isomorphic/grpc.ts index b1ccf629a..a4fb2b7a5 100644 --- a/sdk/src/isomorphic/grpc.ts +++ b/sdk/src/isomorphic/grpc.ts @@ -1 +1,25 @@ -export * from './grpc.node'; +/** + * DO NOT DO A STRAIGHT EXPORT FROM grpc.node.ts + * + * You will break the isomorphic build if you import anything from the bad packages except for the types (using "import type"). + */ + +import type Client from '@triton-one/yellowstone-grpc'; +import type { + SubscribeRequest, + SubscribeUpdate, + CommitmentLevel, +} from '@triton-one/yellowstone-grpc'; +import type { ClientDuplexStream, ChannelOptions } from '@grpc/grpc-js'; + +export { + ClientDuplexStream, + ChannelOptions, + SubscribeRequest, + SubscribeUpdate, + CommitmentLevel, + Client, +}; + +// Declare the function type without implementation +export declare function createClient(...args: ConstructorParameters): Client; \ No newline at end of file From 7f822ef35ec45283431b0e5c841e77ceb13937b7 Mon Sep 17 00:00:00 2001 From: Luke Steyn Date: Tue, 10 Dec 2024 14:58:45 +1000 Subject: [PATCH 2/4] Prettify --- sdk/src/isomorphic/grpc.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sdk/src/isomorphic/grpc.ts b/sdk/src/isomorphic/grpc.ts index a4fb2b7a5..b9cc69c02 100644 --- a/sdk/src/isomorphic/grpc.ts +++ b/sdk/src/isomorphic/grpc.ts @@ -22,4 +22,6 @@ export { }; // Declare the function type without implementation -export declare function createClient(...args: ConstructorParameters): Client; \ No newline at end of file +export declare function createClient( + ...args: ConstructorParameters +): Client; From 9891936a8f01f4cb19bc84b47ff8461799f3414e Mon Sep 17 00:00:00 2001 From: Luke Steyn Date: Tue, 10 Dec 2024 15:16:41 +1000 Subject: [PATCH 3/4] Bump --- sdk/scripts/postbuild.js | 52 +++++++++++++++++++++++++------------- sdk/src/isomorphic/grpc.ts | 28 +------------------- 2 files changed, 35 insertions(+), 45 deletions(-) diff --git a/sdk/scripts/postbuild.js b/sdk/scripts/postbuild.js index 7a6c9e29e..0e2314dd5 100644 --- a/sdk/scripts/postbuild.js +++ b/sdk/scripts/postbuild.js @@ -20,38 +20,54 @@ environments.forEach((environment) => { console.log(``); isomorphicPackages.forEach((package) => { - const isomorphPath = path.join( + + // We want to overwrite the base isomorphic files (the "target" files) with the concrete implementation code and definition files (the "source" files). + + const isomorphicFolderPath = path.join( __dirname, '..', 'lib', environment, - 'isomorphic', - package + '.js' + 'isomorphic' ); const targetEnv = forceEnv ? forceEnv : environment; - const targetPath = path.join( - __dirname, - '..', - 'lib', - environment, - 'isomorphic', - `${package}.${targetEnv}.js` - ); + const filesToSwap = [ + { + source: `${package}.${targetEnv}.js`, + target: `${package}.js`, + }, + { + source: `${package}.${targetEnv}.d.ts`, + target: `${package}.d.ts`, + }, + ]; + + for (const file of filesToSwap) { + const sourcePath = path.join( + isomorphicFolderPath, + file.source + ); - try { - const content = fs.readFileSync(targetPath, 'utf8'); - fs.writeFileSync(isomorphPath, content); - } catch (error) { - console.error( - `Error processing isomophic package : ${package} :: ${error.message}` + const targetPath = path.join( + isomorphicFolderPath, + file.target ); + + try { + const sourceContent = fs.readFileSync(sourcePath, 'utf8'); + fs.writeFileSync(targetPath, sourceContent); + } catch (error) { + console.error( + `Error processing isomophic package : ${package} :: ${error.message}` + ); + } } // Delete other environment files for safety environments.forEach((otherEnvironment) => { - if (otherEnvironment === environment) { + if (otherEnvironment === targetEnv) { return; } diff --git a/sdk/src/isomorphic/grpc.ts b/sdk/src/isomorphic/grpc.ts index b9cc69c02..94c532a7f 100644 --- a/sdk/src/isomorphic/grpc.ts +++ b/sdk/src/isomorphic/grpc.ts @@ -1,27 +1 @@ -/** - * DO NOT DO A STRAIGHT EXPORT FROM grpc.node.ts - * - * You will break the isomorphic build if you import anything from the bad packages except for the types (using "import type"). - */ - -import type Client from '@triton-one/yellowstone-grpc'; -import type { - SubscribeRequest, - SubscribeUpdate, - CommitmentLevel, -} from '@triton-one/yellowstone-grpc'; -import type { ClientDuplexStream, ChannelOptions } from '@grpc/grpc-js'; - -export { - ClientDuplexStream, - ChannelOptions, - SubscribeRequest, - SubscribeUpdate, - CommitmentLevel, - Client, -}; - -// Declare the function type without implementation -export declare function createClient( - ...args: ConstructorParameters -): Client; +export * from './grpc.node'; \ No newline at end of file From 9eaed3a11325bdc264379acaf9ab8b6b35b21a27 Mon Sep 17 00:00:00 2001 From: Luke Steyn Date: Tue, 10 Dec 2024 15:21:08 +1000 Subject: [PATCH 4/4] Prettify --- sdk/src/isomorphic/grpc.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/src/isomorphic/grpc.ts b/sdk/src/isomorphic/grpc.ts index 94c532a7f..b1ccf629a 100644 --- a/sdk/src/isomorphic/grpc.ts +++ b/sdk/src/isomorphic/grpc.ts @@ -1 +1 @@ -export * from './grpc.node'; \ No newline at end of file +export * from './grpc.node';