From 89707ae675c9ffa65b108647781ab6c096c629ec Mon Sep 17 00:00:00 2001 From: DR497 <47689875+dr497@users.noreply.github.com> Date: Wed, 4 Sep 2024 09:52:48 +0800 Subject: [PATCH] js: resolve bundling issues --- js/package-lock.json | 34 ++++++++++++++++++++ js/package.json | 1 + js/rollup.config.mjs | 19 +++++++++-- js/src/record_v2/serializeRecordV2Content.ts | 2 +- 4 files changed, 53 insertions(+), 3 deletions(-) diff --git a/js/package-lock.json b/js/package-lock.json index 3aec8ad6..039aecdc 100644 --- a/js/package-lock.json +++ b/js/package-lock.json @@ -25,6 +25,7 @@ "@pythnetwork/client": "^2.19.0", "@rollup/plugin-babel": "^6.0.4", "@rollup/plugin-commonjs": "^25.0.7", + "@rollup/plugin-inject": "^5.0.5", "@rollup/plugin-json": "^6.0.1", "@rollup/plugin-node-resolve": "^15.2.3", "@rollup/plugin-replace": "^5.0.5", @@ -3093,6 +3094,28 @@ } } }, + "node_modules/@rollup/plugin-inject": { + "version": "5.0.5", + "resolved": "https://registry.npmjs.org/@rollup/plugin-inject/-/plugin-inject-5.0.5.tgz", + "integrity": "sha512-2+DEJbNBoPROPkgTDNe8/1YXWcqxbN5DTjASVIOx8HS+pITXushyNiBV56RB08zuptzz8gT3YfkqriTBVycepg==", + "dev": true, + "dependencies": { + "@rollup/pluginutils": "^5.0.1", + "estree-walker": "^2.0.2", + "magic-string": "^0.30.3" + }, + "engines": { + "node": ">=14.0.0" + }, + "peerDependencies": { + "rollup": "^1.20.0||^2.0.0||^3.0.0||^4.0.0" + }, + "peerDependenciesMeta": { + "rollup": { + "optional": true + } + } + }, "node_modules/@rollup/plugin-json": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/@rollup/plugin-json/-/plugin-json-6.0.1.tgz", @@ -14543,6 +14566,17 @@ "magic-string": "^0.30.3" } }, + "@rollup/plugin-inject": { + "version": "5.0.5", + "resolved": "https://registry.npmjs.org/@rollup/plugin-inject/-/plugin-inject-5.0.5.tgz", + "integrity": "sha512-2+DEJbNBoPROPkgTDNe8/1YXWcqxbN5DTjASVIOx8HS+pITXushyNiBV56RB08zuptzz8gT3YfkqriTBVycepg==", + "dev": true, + "requires": { + "@rollup/pluginutils": "^5.0.1", + "estree-walker": "^2.0.2", + "magic-string": "^0.30.3" + } + }, "@rollup/plugin-json": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/@rollup/plugin-json/-/plugin-json-6.0.1.tgz", diff --git a/js/package.json b/js/package.json index c0f52378..718e898e 100644 --- a/js/package.json +++ b/js/package.json @@ -38,6 +38,7 @@ "@pythnetwork/client": "^2.19.0", "@rollup/plugin-babel": "^6.0.4", "@rollup/plugin-commonjs": "^25.0.7", + "@rollup/plugin-inject": "^5.0.5", "@rollup/plugin-json": "^6.0.1", "@rollup/plugin-node-resolve": "^15.2.3", "@rollup/plugin-replace": "^5.0.5", diff --git a/js/rollup.config.mjs b/js/rollup.config.mjs index 11a04d71..c6199ec9 100644 --- a/js/rollup.config.mjs +++ b/js/rollup.config.mjs @@ -7,6 +7,7 @@ import replace from "@rollup/plugin-replace"; import babel from "@rollup/plugin-babel"; import { visualizer } from "rollup-plugin-visualizer"; import multiInput from "rollup-plugin-multi-input"; +import inject from "@rollup/plugin-inject"; /** * @type {import('rollup').RollupOptions} @@ -43,15 +44,29 @@ export default { preserveModulesRoot: "src", }, ], - external: ["@solana/web3.js"], + external: [ + "@solana/web3.js", + "@solana/buffer-layout-utils", + "@solana/buffer-layout", + ], plugins: [ multiInput.default(), nodeResolve({ browser: true, preferBuiltins: false, - dedupe: ["borsh", "@solana/spl-token", "bn.js", "buffer"], + dedupe: [ + "borsh", + "@solana/spl-token", + "bn.js", + "buffer", + "@solana/buffer-layout-utils", + "@solana/buffer-layout", + ], }), commonjs(), + inject({ + Buffer: ["buffer", "Buffer"], + }), typescript({ tsconfig: "./tsconfig.json", declaration: false, diff --git a/js/src/record_v2/serializeRecordV2Content.ts b/js/src/record_v2/serializeRecordV2Content.ts index 45f9eef8..c731819e 100644 --- a/js/src/record_v2/serializeRecordV2Content.ts +++ b/js/src/record_v2/serializeRecordV2Content.ts @@ -11,7 +11,7 @@ import { InvalidInjectiveAddressError, InvalidRecordInputError, } from "../error"; - +import { Buffer } from "buffer"; import { UTF8_ENCODED, EVM_RECORDS } from "./const"; /**