From ac46671ea99f9dadff71d642cd534e0aa3e0039f Mon Sep 17 00:00:00 2001 From: Chad Ostrowski <221614+chadoh@users.noreply.github.com> Date: Mon, 20 May 2024 16:00:39 -0400 Subject: [PATCH] fix(ts-bindings): package.json needs type: module Since we started using `module: nodenext` in tsconfig.json, we need to tell libraries that import these ones that the exported code is an ES Module. This fixes github.com/stellar/soroban-astro-template to work with libraries generated with `soroban contract bindings typescript` --- .../fixtures/test_custom_types/dist/index.js | 54 +++++-------------- .../test_custom_types/package-lock.json | 6 +-- .../fixtures/test_custom_types/package.json | 13 ++--- .../src/project_template/package.json | 13 ++--- 4 files changed, 29 insertions(+), 57 deletions(-) diff --git a/cmd/crates/soroban-spec-typescript/fixtures/test_custom_types/dist/index.js b/cmd/crates/soroban-spec-typescript/fixtures/test_custom_types/dist/index.js index b4d1675cc..5b9e067c9 100644 --- a/cmd/crates/soroban-spec-typescript/fixtures/test_custom_types/dist/index.js +++ b/cmd/crates/soroban-spec-typescript/fixtures/test_custom_types/dist/index.js @@ -1,60 +1,31 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); -}; -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.Client = exports.Errors = exports.RoyalCard = exports.networks = exports.rpc = exports.contract = void 0; -const buffer_1 = require("buffer"); -const contract_1 = require("@stellar/stellar-sdk/contract"); -__exportStar(require("@stellar/stellar-sdk"), exports); -exports.contract = __importStar(require("@stellar/stellar-sdk/contract")); -exports.rpc = __importStar(require("@stellar/stellar-sdk/rpc")); +import { Buffer } from "buffer"; +import { Client as ContractClient, Spec as ContractSpec, } from '@stellar/stellar-sdk/contract'; +export * from '@stellar/stellar-sdk'; +export * as contract from '@stellar/stellar-sdk/contract'; +export * as rpc from '@stellar/stellar-sdk/rpc'; if (typeof window !== 'undefined') { //@ts-ignore Buffer exists - window.Buffer = window.Buffer || buffer_1.Buffer; + window.Buffer = window.Buffer || Buffer; } -exports.networks = { +export const networks = { futurenet: { networkPassphrase: "Test SDF Future Network ; October 2022", contractId: "CBYMYMSDF6FBDNCFJCRC7KMO4REYFPOH2U4N7FXI3GJO6YXNCQ43CDSK", } }; -var RoyalCard; +export var RoyalCard; (function (RoyalCard) { RoyalCard[RoyalCard["Jack"] = 11] = "Jack"; RoyalCard[RoyalCard["Queen"] = 12] = "Queen"; RoyalCard[RoyalCard["King"] = 13] = "King"; -})(RoyalCard || (exports.RoyalCard = RoyalCard = {})); -exports.Errors = { +})(RoyalCard || (RoyalCard = {})); +export const Errors = { 1: { message: "Please provide an odd number" } }; -class Client extends contract_1.Client { +export class Client extends ContractClient { options; constructor(options) { - super(new contract_1.Spec(["AAAAAQAAAC9UaGlzIGlzIGZyb20gdGhlIHJ1c3QgZG9jIGFib3ZlIHRoZSBzdHJ1Y3QgVGVzdAAAAAAAAAAABFRlc3QAAAADAAAAAAAAAAFhAAAAAAAABAAAAAAAAAABYgAAAAAAAAEAAAAAAAAAAWMAAAAAAAAR", + super(new ContractSpec(["AAAAAQAAAC9UaGlzIGlzIGZyb20gdGhlIHJ1c3QgZG9jIGFib3ZlIHRoZSBzdHJ1Y3QgVGVzdAAAAAAAAAAABFRlc3QAAAADAAAAAAAAAAFhAAAAAAAABAAAAAAAAAABYgAAAAAAAAEAAAAAAAAAAWMAAAAAAAAR", "AAAAAgAAAAAAAAAAAAAAClNpbXBsZUVudW0AAAAAAAMAAAAAAAAAAAAAAAVGaXJzdAAAAAAAAAAAAAAAAAAABlNlY29uZAAAAAAAAAAAAAAAAAAFVGhpcmQAAAA=", "AAAAAwAAAAAAAAAAAAAACVJveWFsQ2FyZAAAAAAAAAMAAAAAAAAABEphY2sAAAALAAAAAAAAAAVRdWVlbgAAAAAAAAwAAAAAAAAABEtpbmcAAAAN", "AAAAAQAAAAAAAAAAAAAAC1R1cGxlU3RydWN0AAAAAAIAAAAAAAAAATAAAAAAAAfQAAAABFRlc3QAAAAAAAAAATEAAAAAAAfQAAAAClNpbXBsZUVudW0AAA==", @@ -121,4 +92,3 @@ class Client extends contract_1.Client { tuple_strukt: (this.txFromJSON) }; } -exports.Client = Client; diff --git a/cmd/crates/soroban-spec-typescript/fixtures/test_custom_types/package-lock.json b/cmd/crates/soroban-spec-typescript/fixtures/test_custom_types/package-lock.json index 130804467..6703264cf 100644 --- a/cmd/crates/soroban-spec-typescript/fixtures/test_custom_types/package-lock.json +++ b/cmd/crates/soroban-spec-typescript/fixtures/test_custom_types/package-lock.json @@ -62,9 +62,9 @@ "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" }, "node_modules/axios": { - "version": "1.6.8", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.8.tgz", - "integrity": "sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ==", + "version": "1.7.1", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.1.tgz", + "integrity": "sha512-+LV37nQcd1EpFalkXksWNBiA17NZ5m5/WspmHGmZmdx1qBOg/VNq/c4eRJiA9VQQHBOs+N0ZhhdU10h2TyNK7Q==", "dependencies": { "follow-redirects": "^1.15.6", "form-data": "^4.0.0", diff --git a/cmd/crates/soroban-spec-typescript/fixtures/test_custom_types/package.json b/cmd/crates/soroban-spec-typescript/fixtures/test_custom_types/package.json index ddd8718d5..4fa87a8ac 100644 --- a/cmd/crates/soroban-spec-typescript/fixtures/test_custom_types/package.json +++ b/cmd/crates/soroban-spec-typescript/fixtures/test_custom_types/package.json @@ -1,17 +1,18 @@ { "version": "0.0.0", "name": "test_custom_types", + "type": "module", + "exports": "./dist/index.js", + "typings": "dist/index.d.ts", + "scripts": { + "build": "tsc" + }, "dependencies": { "@stellar/freighter-api": "2.0.0", "buffer": "6.0.3", "@stellar/stellar-sdk": "12.0.0-rc.3" }, - "scripts": { - "build": "tsc" - }, - "exports": "./dist/index.js", - "typings": "dist/index.d.ts", "devDependencies": { "typescript": "5.3.3" } -} \ No newline at end of file +} diff --git a/cmd/crates/soroban-spec-typescript/src/project_template/package.json b/cmd/crates/soroban-spec-typescript/src/project_template/package.json index dd3f40c7a..383bf7d19 100644 --- a/cmd/crates/soroban-spec-typescript/src/project_template/package.json +++ b/cmd/crates/soroban-spec-typescript/src/project_template/package.json @@ -1,17 +1,18 @@ { "version": "0.0.0", "name": "INSERT_CONTRACT_NAME_HERE", + "type": "module", + "exports": "./dist/index.js", + "typings": "dist/index.d.ts", + "scripts": { + "build": "tsc" + }, "dependencies": { "@stellar/freighter-api": "2.0.0", "buffer": "6.0.3", "@stellar/stellar-sdk": "12.0.0-rc.3" }, - "scripts": { - "build": "tsc" - }, - "exports": "./dist/index.js", - "typings": "dist/index.d.ts", "devDependencies": { "typescript": "5.3.3" } -} \ No newline at end of file +}