From 686358c2da35a2def6b447bbdaf8d3ed260d83f0 Mon Sep 17 00:00:00 2001 From: Sebastien Guillemot Date: Tue, 3 Oct 2023 02:03:39 +0900 Subject: [PATCH] Add cjs support to build-utils --- README.md | 2 +- package.json | 2 +- .../paima-sdk/paima-build-utils/README.md | 4 +- .../paima-sdk/paima-build-utils/package.json | 9 ++- .../src/middleware-esbuildconfig.template.mts | 2 + .../src/standalone-esbuildconfig.template.mts | 2 + .../paima-build-utils/tsconfig.base.json | 8 ++ .../paima-build-utils/tsconfig.cjs.json | 8 ++ .../paima-build-utils/tsconfig.esm.json | 6 ++ packages/paima-sdk/paima-concise/package.json | 4 +- packages/paima-sdk/paima-crypto/package.json | 4 +- packages/paima-sdk/paima-db/package.json | 4 +- .../paima-sdk/paima-executors/package.json | 4 +- packages/paima-sdk/paima-mw-core/package.json | 10 +-- .../paima-sdk/paima-mw-core/src/errors.ts | 74 +++++++++---------- packages/paima-sdk/paima-prando/package.json | 2 +- .../paima-sdk/paima-providers/package.json | 6 +- packages/paima-sdk/paima-sdk/package.json | 21 +++--- packages/paima-sdk/paima-sdk/tsconfig.json | 1 - .../paima-utils-backend/package.json | 6 +- packages/paima-sdk/paima-utils/package.json | 2 +- 21 files changed, 103 insertions(+), 78 deletions(-) create mode 100644 packages/paima-sdk/paima-build-utils/src/middleware-esbuildconfig.template.mts create mode 100644 packages/paima-sdk/paima-build-utils/src/standalone-esbuildconfig.template.mts create mode 100644 packages/paima-sdk/paima-build-utils/tsconfig.base.json create mode 100644 packages/paima-sdk/paima-build-utils/tsconfig.cjs.json create mode 100644 packages/paima-sdk/paima-build-utils/tsconfig.esm.json diff --git a/README.md b/README.md index bdfc803f0..46f475b86 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ While `Paima Engine SDK` refers to these modules: - `Paima Middleware Core` (The library which aids connecting frontends to Paima logic) - `Paima Utils` (The Library which holds auxillary functions between the other modules) - `Paima Utils Backend` (Utils which are purely for backend (and may not work in a browser environment)) -- `Paima Build Utils` (Helps build the Paima components used user projects) +- `Paima Build Utils` (Helps build the Paima components used user projects - not included as part of the `@paima/sdk` package) - `Paima Prando` (Custom fork of a deterministic pseudo-RNG generator library) - `Paima Concise` (The library which enables building and parsing concise encoding) - `Paima Crypto` (Has utility functions for all cryptography and blockchains Paima supports) diff --git a/package.json b/package.json index 3dacfde48..404924521 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "prebuild": "npx nx run-many --parallel=${PARALLEL:-3} -t prebuild", "build": "npm run lint:configs && npx nx run-many --parallel=${PARALLEL:-3} -t build", "test": "npm run lint:configs && npx nx run-many --parallel=${PARALLEL:-3} -t test", - "release:lib": "./wipe.sh && npm run build && npm run lint && npm run test && sh ./tools/scripts/bump-version.sh && read -p 'Enter OTP: ' otp && export NPM_CONFIG_OTP=$otp && npx nx release publish -g paima-sdk", + "release:lib": "./wipe.sh && sh ./tools/scripts/bump-version.sh && npm run build && npm run lint && npm run test && read -p 'Enter OTP: ' otp && export NPM_CONFIG_OTP=$otp && npx nx release publish -g paima-sdk", "release:bin": "./wipe.sh && npm run lint:configs && npx nx run-many --parallel=${PARALLEL:-3} -t release && cp -r ./packages/engine/paima-standalone/packaged/@standalone/* ./bin" }, "devDependencies": { diff --git a/packages/paima-sdk/paima-build-utils/README.md b/packages/paima-sdk/paima-build-utils/README.md index cdade34c3..5e9ab05eb 100644 --- a/packages/paima-sdk/paima-build-utils/README.md +++ b/packages/paima-sdk/paima-build-utils/README.md @@ -4,5 +4,7 @@ A common place to store utility scripts to help build Paima projects on various These are provided as part of Paima itself to avoid the need for projects depending on Paima to update their build scripts for every internal change in Paima engine +**Note**: This module comes with both ESM and CommonJS files, but only the ESM files are exposed through `paima-sdk`. Use this module directly if you need CommonJS. + You can find the full docs for Paima [here](https://docs.paimastudios.com/). \ -**Note**: We generally recommend using [@paima/sdk](https://www.npmjs.com/package/@paima/sdk) instead of this SDK to get all Paima features as a single package. +**Note**: This is not part of the [@paima/sdk](https://www.npmjs.com/package/@paima/sdk) package as typically you will want this in your `devDependencies` unlike `@paima/sdk`, and unlike `@paima/sdk` this package is not purely ESM modules. diff --git a/packages/paima-sdk/paima-build-utils/package.json b/packages/paima-sdk/paima-build-utils/package.json index c85d18e2d..598caf8d9 100644 --- a/packages/paima-sdk/paima-build-utils/package.json +++ b/packages/paima-sdk/paima-build-utils/package.json @@ -1,12 +1,15 @@ { "name": "@paima/build-utils", - "version": "1.1.2", + "version": "1.1.3", "publishConfig": { "access": "public" }, "description": "Util functions to build Paima projects for various platforms", "exports": { - "./*": "./build/*.cjs" + "./*": { + "import": "./build/esm/*.mjs", + "require": "./build/cjs/*.cjs" + } }, "files": [ "/build", @@ -21,7 +24,7 @@ "homepage": "https://docs.paimastudios.com", "scripts": { "lint:eslint": "eslint .", - "build": "tsc" + "build": "tsc --project tsconfig.cjs.json && tsc --project tsconfig.esm.json" }, "bin": { "paima-build-middleware": "./scripts/esbuild.sh" diff --git a/packages/paima-sdk/paima-build-utils/src/middleware-esbuildconfig.template.mts b/packages/paima-sdk/paima-build-utils/src/middleware-esbuildconfig.template.mts new file mode 100644 index 000000000..3f21a16e8 --- /dev/null +++ b/packages/paima-sdk/paima-build-utils/src/middleware-esbuildconfig.template.mts @@ -0,0 +1,2 @@ +import * as buildScript from './middleware-esbuildconfig.template.cjs'; +export default buildScript; diff --git a/packages/paima-sdk/paima-build-utils/src/standalone-esbuildconfig.template.mts b/packages/paima-sdk/paima-build-utils/src/standalone-esbuildconfig.template.mts new file mode 100644 index 000000000..83c93f934 --- /dev/null +++ b/packages/paima-sdk/paima-build-utils/src/standalone-esbuildconfig.template.mts @@ -0,0 +1,2 @@ +import * as buildScript from './standalone-esbuildconfig.template.cjs'; +export default buildScript; diff --git a/packages/paima-sdk/paima-build-utils/tsconfig.base.json b/packages/paima-sdk/paima-build-utils/tsconfig.base.json new file mode 100644 index 000000000..a723692a4 --- /dev/null +++ b/packages/paima-sdk/paima-build-utils/tsconfig.base.json @@ -0,0 +1,8 @@ +{ + "extends": "../tsconfig.json", + "compilerOptions": { + "rootDir": "src", + }, + "include": ["src/**/*"], + "references": [] +} diff --git a/packages/paima-sdk/paima-build-utils/tsconfig.cjs.json b/packages/paima-sdk/paima-build-utils/tsconfig.cjs.json new file mode 100644 index 000000000..403a3f7bb --- /dev/null +++ b/packages/paima-sdk/paima-build-utils/tsconfig.cjs.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.base.json", + "compilerOptions": { + "outDir": "build/cjs", + "module": "commonjs", + }, + "include": ["src/**/*.cts"] +} diff --git a/packages/paima-sdk/paima-build-utils/tsconfig.esm.json b/packages/paima-sdk/paima-build-utils/tsconfig.esm.json new file mode 100644 index 000000000..b7efdbb7c --- /dev/null +++ b/packages/paima-sdk/paima-build-utils/tsconfig.esm.json @@ -0,0 +1,6 @@ +{ + "extends": "./tsconfig.base.json", + "compilerOptions": { + "outDir": "build/esm" + } +} diff --git a/packages/paima-sdk/paima-concise/package.json b/packages/paima-sdk/paima-concise/package.json index 61d154ae3..32b23b76c 100644 --- a/packages/paima-sdk/paima-concise/package.json +++ b/packages/paima-sdk/paima-concise/package.json @@ -1,6 +1,6 @@ { "name": "@paima/concise", - "version": "1.1.2", + "version": "1.1.3", "publishConfig": { "access": "public" }, @@ -29,6 +29,6 @@ }, "devDependencies": { "@types/node": "^18.17.1", - "@paima/utils": "1.1.2" + "@paima/utils": "1.1.3" } } diff --git a/packages/paima-sdk/paima-crypto/package.json b/packages/paima-sdk/paima-crypto/package.json index d37318aeb..95c573e28 100644 --- a/packages/paima-sdk/paima-crypto/package.json +++ b/packages/paima-sdk/paima-crypto/package.json @@ -1,6 +1,6 @@ { "name": "@paima/crypto", - "version": "1.1.2", + "version": "1.1.3", "publishConfig": { "access": "public" }, @@ -33,6 +33,6 @@ "@polkadot/util": "^10.4.2", "@polkadot/util-crypto": "^10.4.2", "bech32": "^2.0.0", - "@paima/utils": "1.1.2" + "@paima/utils": "1.1.3" } } diff --git a/packages/paima-sdk/paima-db/package.json b/packages/paima-sdk/paima-db/package.json index 44154f4fa..7b1751860 100644 --- a/packages/paima-sdk/paima-db/package.json +++ b/packages/paima-sdk/paima-db/package.json @@ -1,6 +1,6 @@ { "name": "@paima/db", - "version": "1.1.2", + "version": "1.1.3", "publishConfig": { "access": "public" }, @@ -31,6 +31,6 @@ "pg": "^8.7.3", "pg-tx": "^1.0.1", "@pgtyped/runtime": "2.1.0", - "@paima/utils": "1.1.2" + "@paima/utils": "1.1.3" } } diff --git a/packages/paima-sdk/paima-executors/package.json b/packages/paima-sdk/paima-executors/package.json index 03a0f4cba..b3c68be24 100644 --- a/packages/paima-sdk/paima-executors/package.json +++ b/packages/paima-sdk/paima-executors/package.json @@ -1,6 +1,6 @@ { "name": "@paima/executors", - "version": "1.1.2", + "version": "1.1.3", "publishConfig": { "access": "public" }, @@ -26,6 +26,6 @@ "typescript": "^5.2.2" }, "dependencies": { - "@paima/prando": "1.1.2" + "@paima/prando": "1.1.3" } } diff --git a/packages/paima-sdk/paima-mw-core/package.json b/packages/paima-sdk/paima-mw-core/package.json index 180a2280c..8a7e16460 100644 --- a/packages/paima-sdk/paima-mw-core/package.json +++ b/packages/paima-sdk/paima-mw-core/package.json @@ -1,6 +1,6 @@ { "name": "@paima/mw-core", - "version": "1.1.2", + "version": "1.1.3", "publishConfig": { "access": "public" }, @@ -37,9 +37,9 @@ "@truffle/hdwallet-provider": "^2.1.15", "algosdk": "^2.3.0", "bech32": "^2.0.0", - "@paima/utils": "1.1.2", - "@paima/providers": "1.1.2", - "@paima/concise": "1.1.2", - "@paima/prando": "1.1.2" + "@paima/utils": "1.1.3", + "@paima/providers": "1.1.3", + "@paima/concise": "1.1.3", + "@paima/prando": "1.1.3" } } diff --git a/packages/paima-sdk/paima-mw-core/src/errors.ts b/packages/paima-sdk/paima-mw-core/src/errors.ts index 2e51224ea..70faf4b59 100644 --- a/packages/paima-sdk/paima-mw-core/src/errors.ts +++ b/packages/paima-sdk/paima-mw-core/src/errors.ts @@ -21,50 +21,46 @@ export const FE_ERR_SPECIFIC_WALLET_NOT_INSTALLED = 3; export const FE_ERR_BATCHER_REJECTED_INPUT = 4; export const FE_ERR_BATCHER_LIMIT_REACHED = 5; -// We don't use enum here as we need these to be constants (an enums (even `const enum`) are not constants when exported with `preserveConstEnums` from a library -export const PaimaMiddlewareErrorCode = { - OK: 0, - UNKNOWN: 1, +export const enum PaimaMiddlewareErrorCode { + OK = 0, + UNKNOWN, // Account related: - EVM_WALLET_NOT_INSTALLED: 1_000, - EVM_LOGIN: 1_001, - EVM_WRONG_CHAIN: 1_002, - EVM_CHAIN_SWITCH: 1_003, - EVM_CHAIN_VERIFICATION: 1_004, - NO_ADDRESS_SELECTED: 1_005, - BACKEND_VERSION_INCOMPATIBLE: 1_006, - ERROR_UPDATING_FEE: 1_007, - WALLET_NOT_CONNECTED: 1_008, - ERROR_SWITCHING_TO_CHAIN: 1_009, - ERROR_ADDING_CHAIN: 1_010, - WALLET_NOT_SUPPORTED: 1_011, - CARDANO_WALLET_NOT_INSTALLED: 1_012, - CARDANO_LOGIN: 1_013, - POLKADOT_WALLET_NOT_INSTALLED: 1_014, - POLKADOT_LOGIN: 1_015, - ALGORAND_LOGIN: 1_016, - TRUFFLE_LOGIN: 1_017, + EVM_WALLET_NOT_INSTALLED = 1_000, + EVM_LOGIN, + EVM_WRONG_CHAIN, + EVM_CHAIN_SWITCH, + EVM_CHAIN_VERIFICATION, + NO_ADDRESS_SELECTED, + BACKEND_VERSION_INCOMPATIBLE, + ERROR_UPDATING_FEE, + WALLET_NOT_CONNECTED, + ERROR_SWITCHING_TO_CHAIN, + ERROR_ADDING_CHAIN, + WALLET_NOT_SUPPORTED, + CARDANO_WALLET_NOT_INSTALLED, + CARDANO_LOGIN, + POLKADOT_WALLET_NOT_INSTALLED, + POLKADOT_LOGIN, + ALGORAND_LOGIN, + TRUFFLE_LOGIN, // Input posting related: - ERROR_POSTING_TO_CHAIN: 2_000, - ERROR_POSTING_TO_BATCHER: 2_001, - BATCHER_REJECTED_INPUT: 2_002, - INVALID_RESPONSE_FROM_BATCHER: 2_003, - FAILURE_VERIFYING_BATCHER_ACCEPTANCE: 2_004, + ERROR_POSTING_TO_CHAIN = 2_000, + ERROR_POSTING_TO_BATCHER, + BATCHER_REJECTED_INPUT, + INVALID_RESPONSE_FROM_BATCHER, + FAILURE_VERIFYING_BATCHER_ACCEPTANCE, // Query endpoint related: - ERROR_QUERYING_BACKEND_ENDPOINT: 3_000, - ERROR_QUERYING_BATCHER_ENDPOINT: 3_001, - INVALID_RESPONSE_FROM_BACKEND: 3_002, + ERROR_QUERYING_BACKEND_ENDPOINT = 3_000, + ERROR_QUERYING_BATCHER_ENDPOINT, + INVALID_RESPONSE_FROM_BACKEND, // Internal, should never occur: - INTERNAL_INVALID_DEPLOYMENT: 4_000, - INTERNAL_INVALID_POSTING_MODE: 4_000, - // only to be used as a starting point for user-defined error codes - FINAL_PAIMA_GENERIC_ERROR: 1_000_000, -} as const; + INTERNAL_INVALID_DEPLOYMENT = 4_000, + INTERNAL_INVALID_POSTING_MODE, + // only to be used as a counter + FINAL_PAIMA_GENERIC_ERROR = 1_000_000, +} -export const PAIMA_MIDDLEWARE_ERROR_MESSAGES: Record< - (typeof PaimaMiddlewareErrorCode)[keyof typeof PaimaMiddlewareErrorCode], - string -> = { +export const PAIMA_MIDDLEWARE_ERROR_MESSAGES: Record = { [PaimaMiddlewareErrorCode.OK]: '', [PaimaMiddlewareErrorCode.UNKNOWN]: 'Unknown error', [PaimaMiddlewareErrorCode.EVM_WALLET_NOT_INSTALLED]: 'Selected EVM wallet not installed', diff --git a/packages/paima-sdk/paima-prando/package.json b/packages/paima-sdk/paima-prando/package.json index 605adea66..10ffcf6ba 100644 --- a/packages/paima-sdk/paima-prando/package.json +++ b/packages/paima-sdk/paima-prando/package.json @@ -1,6 +1,6 @@ { "name": "@paima/prando", - "version": "1.1.2", + "version": "1.1.3", "publishConfig": { "access": "public" }, diff --git a/packages/paima-sdk/paima-providers/package.json b/packages/paima-sdk/paima-providers/package.json index 37472b33f..5be9895c7 100644 --- a/packages/paima-sdk/paima-providers/package.json +++ b/packages/paima-sdk/paima-providers/package.json @@ -1,6 +1,6 @@ { "name": "@paima/providers", - "version": "1.1.2", + "version": "1.1.3", "publishConfig": { "access": "public" }, @@ -32,7 +32,7 @@ "bech32": "^2.0.0", "web3": "1.10.0", "web3-utils": "1.10.0", - "@paima/crypto": "1.1.2", - "@paima/utils": "1.1.2" + "@paima/crypto": "1.1.3", + "@paima/utils": "1.1.3" } } diff --git a/packages/paima-sdk/paima-sdk/package.json b/packages/paima-sdk/paima-sdk/package.json index 76e71c3b8..daf675bca 100644 --- a/packages/paima-sdk/paima-sdk/package.json +++ b/packages/paima-sdk/paima-sdk/package.json @@ -1,6 +1,6 @@ { "name": "@paima/sdk", - "version": "1.1.2", + "version": "1.1.3", "publishConfig": { "access": "public" }, @@ -26,15 +26,14 @@ }, "devDependencies": {}, "dependencies": { - "@paima/build-utils": "1.1.2", - "@paima/concise": "1.1.2", - "@paima/crypto": "1.1.2", - "@paima/db": "1.1.2", - "@paima/executors": "1.1.2", - "@paima/mw-core": "1.1.2", - "@paima/prando": "1.1.2", - "@paima/providers": "1.1.2", - "@paima/utils-backend": "1.1.2", - "@paima/utils": "1.1.2" + "@paima/concise": "1.1.3", + "@paima/crypto": "1.1.3", + "@paima/db": "1.1.3", + "@paima/executors": "1.1.3", + "@paima/mw-core": "1.1.3", + "@paima/prando": "1.1.3", + "@paima/providers": "1.1.3", + "@paima/utils-backend": "1.1.3", + "@paima/utils": "1.1.3" } } diff --git a/packages/paima-sdk/paima-sdk/tsconfig.json b/packages/paima-sdk/paima-sdk/tsconfig.json index 22bf3d3f6..aecf926f0 100644 --- a/packages/paima-sdk/paima-sdk/tsconfig.json +++ b/packages/paima-sdk/paima-sdk/tsconfig.json @@ -20,6 +20,5 @@ { "path": "../paima-concise/tsconfig.build.json" }, { "path": "../paima-executors" }, { "path": "../paima-mw-core" }, - { "path": "../paima-build-utils" } ] } diff --git a/packages/paima-sdk/paima-utils-backend/package.json b/packages/paima-sdk/paima-utils-backend/package.json index c25d46878..b213613cf 100644 --- a/packages/paima-sdk/paima-utils-backend/package.json +++ b/packages/paima-sdk/paima-utils-backend/package.json @@ -1,6 +1,6 @@ { "name": "@paima/utils-backend", - "version": "1.1.2", + "version": "1.1.3", "publishConfig": { "access": "public" }, @@ -27,7 +27,7 @@ }, "dependencies": { "yaml": "^2.3.1", - "@paima/db": "1.1.2", - "@paima/utils": "1.1.2" + "@paima/db": "1.1.3", + "@paima/utils": "1.1.3" } } diff --git a/packages/paima-sdk/paima-utils/package.json b/packages/paima-sdk/paima-utils/package.json index 6220da4e7..9d157b198 100644 --- a/packages/paima-sdk/paima-utils/package.json +++ b/packages/paima-sdk/paima-utils/package.json @@ -1,6 +1,6 @@ { "name": "@paima/utils", - "version": "1.1.2", + "version": "1.1.3", "publishConfig": { "access": "public" },