From 88e7b2928201104fdc36a3e859ed0def75910599 Mon Sep 17 00:00:00 2001 From: febo Date: Mon, 2 Dec 2024 16:00:02 +0000 Subject: [PATCH 01/19] [wip]: scripts refactoring --- .../{ => helpers}/check-solana-version.mjs | 0 scripts/{ => helpers}/generate-clients.mjs | 0 scripts/{ => helpers}/link-solana-version.mjs | 0 scripts/{ => helpers}/start-validator.mjs | 0 scripts/{ => helpers}/stop-validator.mjs | 0 scripts/{ => helpers}/upgrade-template.mjs | 0 scripts/{ => helpers}/utils.mjs | 0 scripts/interface.mjs | 31 +++++++++++++++++++ .../{client/format-js.mjs => js/format.mjs} | 0 scripts/{client/lint-js.mjs => js/lint.mjs} | 0 .../{client/publish-js.mjs => js/publish.mjs} | 0 scripts/{client/test-js.mjs => js/test.mjs} | 0 scripts/program.mjs | 1 + scripts/rust-client.mjs | 0 scripts/{interface => rust}/format.mjs | 0 scripts/{interface => rust}/lint-clippy.mjs | 0 scripts/{interface => rust}/lint-docs.mjs | 0 scripts/{interface => rust}/lint-features.mjs | 0 scripts/{interface => rust}/lint.mjs | 0 scripts/{interface => rust}/test.mjs | 0 scripts/{interface => rust}/wasm.mjs | 0 21 files changed, 32 insertions(+) rename scripts/{ => helpers}/check-solana-version.mjs (100%) rename scripts/{ => helpers}/generate-clients.mjs (100%) rename scripts/{ => helpers}/link-solana-version.mjs (100%) rename scripts/{ => helpers}/start-validator.mjs (100%) rename scripts/{ => helpers}/stop-validator.mjs (100%) rename scripts/{ => helpers}/upgrade-template.mjs (100%) rename scripts/{ => helpers}/utils.mjs (100%) create mode 100644 scripts/interface.mjs rename scripts/{client/format-js.mjs => js/format.mjs} (100%) rename scripts/{client/lint-js.mjs => js/lint.mjs} (100%) rename scripts/{client/publish-js.mjs => js/publish.mjs} (100%) rename scripts/{client/test-js.mjs => js/test.mjs} (100%) create mode 100644 scripts/program.mjs create mode 100644 scripts/rust-client.mjs rename scripts/{interface => rust}/format.mjs (100%) rename scripts/{interface => rust}/lint-clippy.mjs (100%) rename scripts/{interface => rust}/lint-docs.mjs (100%) rename scripts/{interface => rust}/lint-features.mjs (100%) rename scripts/{interface => rust}/lint.mjs (100%) rename scripts/{interface => rust}/test.mjs (100%) rename scripts/{interface => rust}/wasm.mjs (100%) diff --git a/scripts/check-solana-version.mjs b/scripts/helpers/check-solana-version.mjs similarity index 100% rename from scripts/check-solana-version.mjs rename to scripts/helpers/check-solana-version.mjs diff --git a/scripts/generate-clients.mjs b/scripts/helpers/generate-clients.mjs similarity index 100% rename from scripts/generate-clients.mjs rename to scripts/helpers/generate-clients.mjs diff --git a/scripts/link-solana-version.mjs b/scripts/helpers/link-solana-version.mjs similarity index 100% rename from scripts/link-solana-version.mjs rename to scripts/helpers/link-solana-version.mjs diff --git a/scripts/start-validator.mjs b/scripts/helpers/start-validator.mjs similarity index 100% rename from scripts/start-validator.mjs rename to scripts/helpers/start-validator.mjs diff --git a/scripts/stop-validator.mjs b/scripts/helpers/stop-validator.mjs similarity index 100% rename from scripts/stop-validator.mjs rename to scripts/helpers/stop-validator.mjs diff --git a/scripts/upgrade-template.mjs b/scripts/helpers/upgrade-template.mjs similarity index 100% rename from scripts/upgrade-template.mjs rename to scripts/helpers/upgrade-template.mjs diff --git a/scripts/utils.mjs b/scripts/helpers/utils.mjs similarity index 100% rename from scripts/utils.mjs rename to scripts/helpers/utils.mjs diff --git a/scripts/interface.mjs b/scripts/interface.mjs new file mode 100644 index 0000000..b7a3119 --- /dev/null +++ b/scripts/interface.mjs @@ -0,0 +1,31 @@ +import { cliArguments, workingDirectory } from './helpers/utils.mjs'; + +export const manifestPath = path.join( + workingDirectory, + 'interface', + 'Cargo.toml' +); + +export function getLintClippyArguments() { + const args = ['--all-targets', '--all-features', ...cliArguments()]; + // Check whether a '--' was already used. + if (args.indexOf('--') === -1) { + args.push('--'); + } + // Add additional arguments. + args.push( + '--deny=warnings', + '--deny=clippy::default_trait_access', + '--deny=clippy::arithmetic_side_effects', + '--deny=clippy::manual_let_else', + '--deny=clippy::used_underscore_binding' + ); + return args; +} + +export function getLintDocsArguments() { + return cliArguments(); +} + +export function getLintFeaturesArguments() { +} diff --git a/scripts/client/format-js.mjs b/scripts/js/format.mjs similarity index 100% rename from scripts/client/format-js.mjs rename to scripts/js/format.mjs diff --git a/scripts/client/lint-js.mjs b/scripts/js/lint.mjs similarity index 100% rename from scripts/client/lint-js.mjs rename to scripts/js/lint.mjs diff --git a/scripts/client/publish-js.mjs b/scripts/js/publish.mjs similarity index 100% rename from scripts/client/publish-js.mjs rename to scripts/js/publish.mjs diff --git a/scripts/client/test-js.mjs b/scripts/js/test.mjs similarity index 100% rename from scripts/client/test-js.mjs rename to scripts/js/test.mjs diff --git a/scripts/program.mjs b/scripts/program.mjs new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/scripts/program.mjs @@ -0,0 +1 @@ + diff --git a/scripts/rust-client.mjs b/scripts/rust-client.mjs new file mode 100644 index 0000000..e69de29 diff --git a/scripts/interface/format.mjs b/scripts/rust/format.mjs similarity index 100% rename from scripts/interface/format.mjs rename to scripts/rust/format.mjs diff --git a/scripts/interface/lint-clippy.mjs b/scripts/rust/lint-clippy.mjs similarity index 100% rename from scripts/interface/lint-clippy.mjs rename to scripts/rust/lint-clippy.mjs diff --git a/scripts/interface/lint-docs.mjs b/scripts/rust/lint-docs.mjs similarity index 100% rename from scripts/interface/lint-docs.mjs rename to scripts/rust/lint-docs.mjs diff --git a/scripts/interface/lint-features.mjs b/scripts/rust/lint-features.mjs similarity index 100% rename from scripts/interface/lint-features.mjs rename to scripts/rust/lint-features.mjs diff --git a/scripts/interface/lint.mjs b/scripts/rust/lint.mjs similarity index 100% rename from scripts/interface/lint.mjs rename to scripts/rust/lint.mjs diff --git a/scripts/interface/test.mjs b/scripts/rust/test.mjs similarity index 100% rename from scripts/interface/test.mjs rename to scripts/rust/test.mjs diff --git a/scripts/interface/wasm.mjs b/scripts/rust/wasm.mjs similarity index 100% rename from scripts/interface/wasm.mjs rename to scripts/rust/wasm.mjs From df6e1989cce34a240a593e639fe960aab240e31d Mon Sep 17 00:00:00 2001 From: Loris Leiva Date: Mon, 2 Dec 2024 16:52:44 +0000 Subject: [PATCH 02/19] [wip]: use TypeScript in scripts --- .github/actions/setup/action.yml | 2 +- package.json | 33 +- pnpm-lock.yaml | 283 ++++++++++++++++++ scripts/ci/{set-env.mjs => set-env.mts} | 2 +- scripts/client/format-rust.mjs | 2 +- scripts/client/lint-rust-clippy.mjs | 2 +- scripts/client/lint-rust-docs.mjs | 6 +- scripts/client/lint-rust-features.mjs | 6 +- scripts/client/lint-rust.mjs | 2 +- scripts/client/publish-rust.mjs | 2 +- scripts/client/test-rust.mjs | 2 +- scripts/{ => crate}/interface.mjs | 5 +- scripts/{ => crate}/program.mjs | 0 scripts/{ => crate}/rust-client.mjs | 0 scripts/crate/shared.mts | 27 ++ scripts/dummy.mts | 4 + ...a-version.mjs => check-solana-version.mts} | 2 +- ...erate-clients.mjs => generate-clients.mts} | 16 +- ...na-version.mjs => link-solana-version.mts} | 2 +- ...tart-validator.mjs => start-validator.mts} | 10 +- ...{stop-validator.mjs => stop-validator.mts} | 0 ...rade-template.mjs => upgrade-template.mts} | 4 +- scripts/helpers/{utils.mjs => utils.mts} | 42 +-- scripts/js/{format.mjs => format.mts} | 2 +- scripts/js/{lint.mjs => lint.mts} | 2 +- scripts/js/{publish.mjs => publish.mts} | 2 +- scripts/js/{test.mjs => test.mts} | 2 +- scripts/rust/{format.mjs => format.mts} | 2 +- .../rust/{lint-clippy.mjs => lint-clippy.mts} | 2 +- scripts/rust/{lint-docs.mjs => lint-docs.mts} | 2 +- .../{lint-features.mjs => lint-features.mts} | 2 +- scripts/rust/{lint.mjs => lint.mts} | 2 +- scripts/rust/{test.mjs => test.mts} | 2 +- scripts/rust/{wasm.mjs => wasm.mts} | 5 +- 34 files changed, 393 insertions(+), 86 deletions(-) rename scripts/ci/{set-env.mjs => set-env.mts} (84%) rename scripts/{ => crate}/interface.mjs (84%) rename scripts/{ => crate}/program.mjs (100%) rename scripts/{ => crate}/rust-client.mjs (100%) create mode 100644 scripts/crate/shared.mts create mode 100644 scripts/dummy.mts rename scripts/helpers/{check-solana-version.mjs => check-solana-version.mts} (98%) rename scripts/helpers/{generate-clients.mjs => generate-clients.mts} (55%) rename scripts/helpers/{link-solana-version.mjs => link-solana-version.mts} (99%) rename scripts/helpers/{start-validator.mjs => start-validator.mts} (94%) rename scripts/helpers/{stop-validator.mjs => stop-validator.mts} (100%) rename scripts/helpers/{upgrade-template.mjs => upgrade-template.mts} (94%) rename scripts/helpers/{utils.mjs => utils.mts} (67%) rename scripts/js/{format.mjs => format.mts} (72%) rename scripts/js/{lint.mjs => lint.mts} (72%) rename scripts/js/{publish.mjs => publish.mts} (93%) rename scripts/js/{test.mjs => test.mts} (81%) rename scripts/rust/{format.mjs => format.mts} (96%) rename scripts/rust/{lint-clippy.mjs => lint-clippy.mts} (97%) rename scripts/rust/{lint-docs.mjs => lint-docs.mts} (92%) rename scripts/rust/{lint-features.mjs => lint-features.mts} (93%) rename scripts/rust/{lint.mjs => lint.mts} (88%) rename scripts/rust/{test.mjs => test.mts} (93%) rename scripts/rust/{wasm.mjs => wasm.mts} (82%) diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml index 08e967d..711cac8 100644 --- a/.github/actions/setup/action.yml +++ b/.github/actions/setup/action.yml @@ -35,7 +35,7 @@ runs: - name: Set Environment Variables shell: bash - run: pnpm zx ./scripts/ci/set-env.mjs + run: pnpm tsx ./scripts/ci/set-env.mts - name: Install Rust 'build' Toolchain if: ${{ contains(inputs.toolchain, 'build') }} diff --git a/package.json b/package.json index 2018050..12d9848 100644 --- a/package.json +++ b/package.json @@ -1,32 +1,29 @@ { "private": true, "scripts": { - "solana:check": "zx ./scripts/check-solana-version.mjs", - "solana:link": "zx ./scripts/link-solana-version.mjs", + "solana:check": "tsx ./scripts/helpers/check-solana-version.mts", + "solana:link": "tsx ./scripts/helpers/link-solana-version.mts", "generate": "pnpm generate:clients", - "generate:clients": "zx ./scripts/generate-clients.mjs", - "validator:start": "zx ./scripts/start-validator.mjs", + "generate:clients": "tsx ./scripts/helpers/generate-clients.mts", + "validator:start": "tsx ./scripts/helpers/start-validator.mts", "validator:restart": "pnpm validator:start --restart", - "validator:stop": "zx ./scripts/stop-validator.mjs", - "clients:js:format": "zx ./scripts/client/format-js.mjs", - "clients:js:lint": "zx ./scripts/client/lint-js.mjs", - "clients:js:publish": "zx ./scripts/client/publish-js.mjs", - "clients:js:test": "zx ./scripts/client/test-js.mjs", - "clients:rust:format": "zx ./scripts/client/format-rust.mjs", - "clients:rust:lint": "zx ./scripts/client/lint-rust.mjs", - "clients:rust:publish": "zx ./scripts/client/publish-rust.mjs", - "clients:rust:test": "zx ./scripts/client/test-rust.mjs", - "interface:format": "zx ./scripts/interface/format.mjs", - "interface:lint": "zx ./scripts/interface/lint.mjs", - "interface:test": "zx ./scripts/interface/test.mjs", - "interface:wasm": "zx ./scripts/interface/wasm.mjs", - "template:upgrade": "zx ./scripts/upgrade-template.mjs" + "validator:stop": "tsx ./scripts/helpers/stop-validator.mts", + "js:format": "tsx ./scripts/js/format.mts", + "js:lint": "tsx ./scripts/js/lint.mts", + "js:publish": "tsx ./scripts/js/publish.mts", + "js:test": "tsx ./scripts/js/test.mts", + "rust:format": "tsx ./scripts/client/format-rust.mts", + "rust:lint": "tsx ./scripts/client/lint-rust.mts", + "rust:publish": "tsx ./scripts/client/publish-rust.mts", + "rust:test": "tsx ./scripts/client/test-rust.mts", + "template:upgrade": "tsx ./scripts/helpers/upgrade-template.ts" }, "devDependencies": { "@codama/renderers-js": "^1.1.0", "@codama/renderers-rust": "^1.0.4", "@iarna/toml": "^2.2.5", "codama": "^1.1.0", + "tsx": "^4.19.2", "typescript": "^5.5.2", "zx": "^7.2.3" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 56041e9..5174a02 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -20,6 +20,9 @@ importers: codama: specifier: ^1.1.0 version: 1.1.0 + tsx: + specifier: ^4.19.2 + version: 4.19.2 typescript: specifier: ^5.5.2 version: 5.5.3 @@ -60,6 +63,150 @@ packages: '@codama/visitors@1.1.0': resolution: {integrity: sha512-QpAShuxemS8oplHDXNqnUnYwhJq58RZjfZ/KMIpdm88OCBnQRO4YfM/zQLEvXjA+tpwJpe4WnL6opTLLnSYThw==} + '@esbuild/aix-ppc64@0.23.1': + resolution: {integrity: sha512-6VhYk1diRqrhBAqpJEdjASR/+WVRtfjpqKuNw11cLiaWpAT/Uu+nokB+UJnevzy/P9C/ty6AOe0dwueMrGh/iQ==} + engines: {node: '>=18'} + cpu: [ppc64] + os: [aix] + + '@esbuild/android-arm64@0.23.1': + resolution: {integrity: sha512-xw50ipykXcLstLeWH7WRdQuysJqejuAGPd30vd1i5zSyKK3WE+ijzHmLKxdiCMtH1pHz78rOg0BKSYOSB/2Khw==} + engines: {node: '>=18'} + cpu: [arm64] + os: [android] + + '@esbuild/android-arm@0.23.1': + resolution: {integrity: sha512-uz6/tEy2IFm9RYOyvKl88zdzZfwEfKZmnX9Cj1BHjeSGNuGLuMD1kR8y5bteYmwqKm1tj8m4cb/aKEorr6fHWQ==} + engines: {node: '>=18'} + cpu: [arm] + os: [android] + + '@esbuild/android-x64@0.23.1': + resolution: {integrity: sha512-nlN9B69St9BwUoB+jkyU090bru8L0NA3yFvAd7k8dNsVH8bi9a8cUAUSEcEEgTp2z3dbEDGJGfP6VUnkQnlReg==} + engines: {node: '>=18'} + cpu: [x64] + os: [android] + + '@esbuild/darwin-arm64@0.23.1': + resolution: {integrity: sha512-YsS2e3Wtgnw7Wq53XXBLcV6JhRsEq8hkfg91ESVadIrzr9wO6jJDMZnCQbHm1Guc5t/CdDiFSSfWP58FNuvT3Q==} + engines: {node: '>=18'} + cpu: [arm64] + os: [darwin] + + '@esbuild/darwin-x64@0.23.1': + resolution: {integrity: sha512-aClqdgTDVPSEGgoCS8QDG37Gu8yc9lTHNAQlsztQ6ENetKEO//b8y31MMu2ZaPbn4kVsIABzVLXYLhCGekGDqw==} + engines: {node: '>=18'} + cpu: [x64] + os: [darwin] + + '@esbuild/freebsd-arm64@0.23.1': + resolution: {integrity: sha512-h1k6yS8/pN/NHlMl5+v4XPfikhJulk4G+tKGFIOwURBSFzE8bixw1ebjluLOjfwtLqY0kewfjLSrO6tN2MgIhA==} + engines: {node: '>=18'} + cpu: [arm64] + os: [freebsd] + + '@esbuild/freebsd-x64@0.23.1': + resolution: {integrity: sha512-lK1eJeyk1ZX8UklqFd/3A60UuZ/6UVfGT2LuGo3Wp4/z7eRTRYY+0xOu2kpClP+vMTi9wKOfXi2vjUpO1Ro76g==} + engines: {node: '>=18'} + cpu: [x64] + os: [freebsd] + + '@esbuild/linux-arm64@0.23.1': + resolution: {integrity: sha512-/93bf2yxencYDnItMYV/v116zff6UyTjo4EtEQjUBeGiVpMmffDNUyD9UN2zV+V3LRV3/on4xdZ26NKzn6754g==} + engines: {node: '>=18'} + cpu: [arm64] + os: [linux] + + '@esbuild/linux-arm@0.23.1': + resolution: {integrity: sha512-CXXkzgn+dXAPs3WBwE+Kvnrf4WECwBdfjfeYHpMeVxWE0EceB6vhWGShs6wi0IYEqMSIzdOF1XjQ/Mkm5d7ZdQ==} + engines: {node: '>=18'} + cpu: [arm] + os: [linux] + + '@esbuild/linux-ia32@0.23.1': + resolution: {integrity: sha512-VTN4EuOHwXEkXzX5nTvVY4s7E/Krz7COC8xkftbbKRYAl96vPiUssGkeMELQMOnLOJ8k3BY1+ZY52tttZnHcXQ==} + engines: {node: '>=18'} + cpu: [ia32] + os: [linux] + + '@esbuild/linux-loong64@0.23.1': + resolution: {integrity: sha512-Vx09LzEoBa5zDnieH8LSMRToj7ir/Jeq0Gu6qJ/1GcBq9GkfoEAoXvLiW1U9J1qE/Y/Oyaq33w5p2ZWrNNHNEw==} + engines: {node: '>=18'} + cpu: [loong64] + os: [linux] + + '@esbuild/linux-mips64el@0.23.1': + resolution: {integrity: sha512-nrFzzMQ7W4WRLNUOU5dlWAqa6yVeI0P78WKGUo7lg2HShq/yx+UYkeNSE0SSfSure0SqgnsxPvmAUu/vu0E+3Q==} + engines: {node: '>=18'} + cpu: [mips64el] + os: [linux] + + '@esbuild/linux-ppc64@0.23.1': + resolution: {integrity: sha512-dKN8fgVqd0vUIjxuJI6P/9SSSe/mB9rvA98CSH2sJnlZ/OCZWO1DJvxj8jvKTfYUdGfcq2dDxoKaC6bHuTlgcw==} + engines: {node: '>=18'} + cpu: [ppc64] + os: [linux] + + '@esbuild/linux-riscv64@0.23.1': + resolution: {integrity: sha512-5AV4Pzp80fhHL83JM6LoA6pTQVWgB1HovMBsLQ9OZWLDqVY8MVobBXNSmAJi//Csh6tcY7e7Lny2Hg1tElMjIA==} + engines: {node: '>=18'} + cpu: [riscv64] + os: [linux] + + '@esbuild/linux-s390x@0.23.1': + resolution: {integrity: sha512-9ygs73tuFCe6f6m/Tb+9LtYxWR4c9yg7zjt2cYkjDbDpV/xVn+68cQxMXCjUpYwEkze2RcU/rMnfIXNRFmSoDw==} + engines: {node: '>=18'} + cpu: [s390x] + os: [linux] + + '@esbuild/linux-x64@0.23.1': + resolution: {integrity: sha512-EV6+ovTsEXCPAp58g2dD68LxoP/wK5pRvgy0J/HxPGB009omFPv3Yet0HiaqvrIrgPTBuC6wCH1LTOY91EO5hQ==} + engines: {node: '>=18'} + cpu: [x64] + os: [linux] + + '@esbuild/netbsd-x64@0.23.1': + resolution: {integrity: sha512-aevEkCNu7KlPRpYLjwmdcuNz6bDFiE7Z8XC4CPqExjTvrHugh28QzUXVOZtiYghciKUacNktqxdpymplil1beA==} + engines: {node: '>=18'} + cpu: [x64] + os: [netbsd] + + '@esbuild/openbsd-arm64@0.23.1': + resolution: {integrity: sha512-3x37szhLexNA4bXhLrCC/LImN/YtWis6WXr1VESlfVtVeoFJBRINPJ3f0a/6LV8zpikqoUg4hyXw0sFBt5Cr+Q==} + engines: {node: '>=18'} + cpu: [arm64] + os: [openbsd] + + '@esbuild/openbsd-x64@0.23.1': + resolution: {integrity: sha512-aY2gMmKmPhxfU+0EdnN+XNtGbjfQgwZj43k8G3fyrDM/UdZww6xrWxmDkuz2eCZchqVeABjV5BpildOrUbBTqA==} + engines: {node: '>=18'} + cpu: [x64] + os: [openbsd] + + '@esbuild/sunos-x64@0.23.1': + resolution: {integrity: sha512-RBRT2gqEl0IKQABT4XTj78tpk9v7ehp+mazn2HbUeZl1YMdaGAQqhapjGTCe7uw7y0frDi4gS0uHzhvpFuI1sA==} + engines: {node: '>=18'} + cpu: [x64] + os: [sunos] + + '@esbuild/win32-arm64@0.23.1': + resolution: {integrity: sha512-4O+gPR5rEBe2FpKOVyiJ7wNDPA8nGzDuJ6gN4okSA1gEOYZ67N8JPk58tkWtdtPeLz7lBnY6I5L3jdsr3S+A6A==} + engines: {node: '>=18'} + cpu: [arm64] + os: [win32] + + '@esbuild/win32-ia32@0.23.1': + resolution: {integrity: sha512-BcaL0Vn6QwCwre3Y717nVHZbAa4UBEigzFm6VdsVdT/MbZ38xoj1X9HPkZhbmaBGUD1W8vxAfffbDe8bA6AKnQ==} + engines: {node: '>=18'} + cpu: [ia32] + os: [win32] + + '@esbuild/win32-x64@0.23.1': + resolution: {integrity: sha512-BHpFFeslkWrXWyUPnbKm+xYYVYruCinGcftSBaa8zoF9hZO4BcSCFUvHVTtzpIY6YzUnYtuEhZ+C9iEXjxnasg==} + engines: {node: '>=18'} + cpu: [x64] + os: [win32] + '@iarna/toml@2.2.5': resolution: {integrity: sha512-trnsAYxU3xnS1gPHPyU961coFyLkh4gAD/0zQ5mymY4yOZ+CYvsPqUbOFSw0aDM4y0tV7tiFxL/1XfXPNC6IPg==} @@ -175,6 +322,11 @@ packages: resolution: {integrity: sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==} engines: {node: '>= 0.4'} + esbuild@0.23.1: + resolution: {integrity: sha512-VVNz/9Sa0bs5SELtn3f7qhJCDPCF5oMEl5cO9/SSinpE9hbPVvxbd572HH5AKiP7WD8INO53GgfDDhRjkylHEg==} + engines: {node: '>=18'} + hasBin: true + event-stream@3.3.4: resolution: {integrity: sha512-QHpkERcGsR0T7Qm3HNJSyXKEEj8AHNxkY3PK8TS2KJvQ7NiSHe3DDpwVKKtoYprL/AreyzFBeIkBIWChAqn60g==} @@ -207,6 +359,11 @@ packages: resolution: {integrity: sha512-PmDi3uwK5nFuXh7XDTlVnS17xJS7vW36is2+w3xcv8SVxiB4NyATf4ctkVY5bkSjX0Y4nbvZCq1/EjtEyr9ktw==} engines: {node: '>=14.14'} + fsevents@2.3.3: + resolution: {integrity: sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==} + engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0} + os: [darwin] + function-bind@1.1.2: resolution: {integrity: sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==} @@ -218,6 +375,9 @@ packages: resolution: {integrity: sha512-5uYhsJH8VJBTv7oslg4BznJYhDoRI6waYCxMmCdnTrcCrHA/fCFKoTFz2JKKE0HdDFUF7/oQuhzumXJK7paBRQ==} engines: {node: '>= 0.4'} + get-tsconfig@4.8.1: + resolution: {integrity: sha512-k9PN+cFBmaLWtVz29SkUoqU5O0slLuHJXt/2P+tMVFT+phsSGXGkp9t3rQIqdz0e+06EHNGs3oM6ZX1s2zHxRg==} + glob-parent@5.1.2: resolution: {integrity: sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==} engines: {node: '>= 6'} @@ -339,6 +499,9 @@ packages: queue-microtask@1.2.3: resolution: {integrity: sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==} + resolve-pkg-maps@1.0.0: + resolution: {integrity: sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==} + reusify@1.0.4: resolution: {integrity: sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==} engines: {iojs: '>=1.0.0', node: '>=0.10.0'} @@ -367,6 +530,11 @@ packages: resolution: {integrity: sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==} engines: {node: '>=8.0'} + tsx@4.19.2: + resolution: {integrity: sha512-pOUl6Vo2LUq/bSa8S5q7b91cgNSjctn9ugq/+Mvow99qW6x/UZYwzxy/3NmqoT66eHYfCVvFvACC58UBPFf28g==} + engines: {node: '>=18.0.0'} + hasBin: true + typescript@5.5.3: resolution: {integrity: sha512-/hreyEujaB0w76zKo6717l3L0o/qEUtRgdvUBvlkhoWeOVMjMuHNHk0BRBzikzuGDqNmPQbg5ifMEqsHLiIUcQ==} engines: {node: '>=14.17'} @@ -476,6 +644,78 @@ snapshots: '@codama/nodes': 1.1.0 '@codama/visitors-core': 1.1.0 + '@esbuild/aix-ppc64@0.23.1': + optional: true + + '@esbuild/android-arm64@0.23.1': + optional: true + + '@esbuild/android-arm@0.23.1': + optional: true + + '@esbuild/android-x64@0.23.1': + optional: true + + '@esbuild/darwin-arm64@0.23.1': + optional: true + + '@esbuild/darwin-x64@0.23.1': + optional: true + + '@esbuild/freebsd-arm64@0.23.1': + optional: true + + '@esbuild/freebsd-x64@0.23.1': + optional: true + + '@esbuild/linux-arm64@0.23.1': + optional: true + + '@esbuild/linux-arm@0.23.1': + optional: true + + '@esbuild/linux-ia32@0.23.1': + optional: true + + '@esbuild/linux-loong64@0.23.1': + optional: true + + '@esbuild/linux-mips64el@0.23.1': + optional: true + + '@esbuild/linux-ppc64@0.23.1': + optional: true + + '@esbuild/linux-riscv64@0.23.1': + optional: true + + '@esbuild/linux-s390x@0.23.1': + optional: true + + '@esbuild/linux-x64@0.23.1': + optional: true + + '@esbuild/netbsd-x64@0.23.1': + optional: true + + '@esbuild/openbsd-arm64@0.23.1': + optional: true + + '@esbuild/openbsd-x64@0.23.1': + optional: true + + '@esbuild/sunos-x64@0.23.1': + optional: true + + '@esbuild/win32-arm64@0.23.1': + optional: true + + '@esbuild/win32-ia32@0.23.1': + optional: true + + '@esbuild/win32-x64@0.23.1': + optional: true + '@iarna/toml@2.2.5': {} '@noble/hashes@1.5.0': {} @@ -585,6 +825,33 @@ snapshots: es-errors@1.3.0: {} + esbuild@0.23.1: + optionalDependencies: + '@esbuild/aix-ppc64': 0.23.1 + '@esbuild/android-arm': 0.23.1 + '@esbuild/android-arm64': 0.23.1 + '@esbuild/android-x64': 0.23.1 + '@esbuild/darwin-arm64': 0.23.1 + '@esbuild/darwin-x64': 0.23.1 + '@esbuild/freebsd-arm64': 0.23.1 + '@esbuild/freebsd-x64': 0.23.1 + '@esbuild/linux-arm': 0.23.1 + '@esbuild/linux-arm64': 0.23.1 + '@esbuild/linux-ia32': 0.23.1 + '@esbuild/linux-loong64': 0.23.1 + '@esbuild/linux-mips64el': 0.23.1 + '@esbuild/linux-ppc64': 0.23.1 + '@esbuild/linux-riscv64': 0.23.1 + '@esbuild/linux-s390x': 0.23.1 + '@esbuild/linux-x64': 0.23.1 + '@esbuild/netbsd-x64': 0.23.1 + '@esbuild/openbsd-arm64': 0.23.1 + '@esbuild/openbsd-x64': 0.23.1 + '@esbuild/sunos-x64': 0.23.1 + '@esbuild/win32-arm64': 0.23.1 + '@esbuild/win32-ia32': 0.23.1 + '@esbuild/win32-x64': 0.23.1 + event-stream@3.3.4: dependencies: duplexer: 0.1.2 @@ -630,6 +897,9 @@ snapshots: jsonfile: 6.1.0 universalify: 2.0.1 + fsevents@2.3.3: + optional: true + function-bind@1.1.2: {} fx@31.0.0: {} @@ -642,6 +912,10 @@ snapshots: has-symbols: 1.0.3 hasown: 2.0.1 + get-tsconfig@4.8.1: + dependencies: + resolve-pkg-maps: 1.0.0 + glob-parent@5.1.2: dependencies: is-glob: 4.0.3 @@ -744,6 +1018,8 @@ snapshots: queue-microtask@1.2.3: {} + resolve-pkg-maps@1.0.0: {} + reusify@1.0.4: {} run-parallel@1.2.0: @@ -775,6 +1051,13 @@ snapshots: dependencies: is-number: 7.0.0 + tsx@4.19.2: + dependencies: + esbuild: 0.23.1 + get-tsconfig: 4.8.1 + optionalDependencies: + fsevents: 2.3.3 + typescript@5.5.3: {} undici-types@5.26.5: {} diff --git a/scripts/ci/set-env.mjs b/scripts/ci/set-env.mts similarity index 84% rename from scripts/ci/set-env.mjs rename to scripts/ci/set-env.mts index 76dd029..cc167ca 100644 --- a/scripts/ci/set-env.mjs +++ b/scripts/ci/set-env.mts @@ -1,5 +1,5 @@ #!/usr/bin/env zx -import { getSolanaVersion, getToolchain } from '../utils.mjs'; +import { getSolanaVersion, getToolchain } from '../helpers/utils.mts'; await $`echo "SOLANA_VERSION=${getSolanaVersion()}" >> $GITHUB_ENV`; await $`echo "TOOLCHAIN_BUILD=${getToolchain('build')}" >> $GITHUB_ENV`; diff --git a/scripts/client/format-rust.mjs b/scripts/client/format-rust.mjs index 038a832..71d3e12 100644 --- a/scripts/client/format-rust.mjs +++ b/scripts/client/format-rust.mjs @@ -6,7 +6,7 @@ import { partitionArguments, popArgument, workingDirectory, -} from '../utils.mjs'; +} from '../utils'; // Configure additional arguments here, e.g.: // ['--arg1', '--arg2', ...cliArguments()] diff --git a/scripts/client/lint-rust-clippy.mjs b/scripts/client/lint-rust-clippy.mjs index 309b089..b8cc390 100644 --- a/scripts/client/lint-rust-clippy.mjs +++ b/scripts/client/lint-rust-clippy.mjs @@ -5,7 +5,7 @@ import { getToolchainArgument, popArgument, workingDirectory, -} from '../utils.mjs'; +} from '../utils'; // Configure additional arguments here, e.g.: // ['--arg1', '--arg2', ...cliArguments()] diff --git a/scripts/client/lint-rust-docs.mjs b/scripts/client/lint-rust-docs.mjs index 75e7b41..4a6b3bb 100644 --- a/scripts/client/lint-rust-docs.mjs +++ b/scripts/client/lint-rust-docs.mjs @@ -1,10 +1,6 @@ #!/usr/bin/env zx import 'zx/globals'; -import { - cliArguments, - getToolchainArgument, - workingDirectory, -} from '../utils.mjs'; +import { cliArguments, getToolchainArgument, workingDirectory } from '../utils'; const args = cliArguments(); const toolchain = getToolchainArgument('lint'); diff --git a/scripts/client/lint-rust-features.mjs b/scripts/client/lint-rust-features.mjs index 4088c66..a760735 100644 --- a/scripts/client/lint-rust-features.mjs +++ b/scripts/client/lint-rust-features.mjs @@ -1,10 +1,6 @@ #!/usr/bin/env zx import 'zx/globals'; -import { - cliArguments, - getToolchainArgument, - workingDirectory, -} from '../utils.mjs'; +import { cliArguments, getToolchainArgument, workingDirectory } from '../utils'; const args = cliArguments(); const toolchain = getToolchainArgument('lint'); diff --git a/scripts/client/lint-rust.mjs b/scripts/client/lint-rust.mjs index 3f47eaf..3cbefe5 100644 --- a/scripts/client/lint-rust.mjs +++ b/scripts/client/lint-rust.mjs @@ -5,7 +5,7 @@ // - lint-rust-features.mjs // - lint-rust-docs.mjs -import { cliArguments, workingDirectory } from '../utils.mjs'; +import { cliArguments, workingDirectory } from '../utils'; const scripts = path.join(workingDirectory, 'scripts', 'client'); diff --git a/scripts/client/publish-rust.mjs b/scripts/client/publish-rust.mjs index b7a9fa6..f976821 100644 --- a/scripts/client/publish-rust.mjs +++ b/scripts/client/publish-rust.mjs @@ -1,6 +1,6 @@ #!/usr/bin/env zx import 'zx/globals'; -import { cliArguments, getCargo, workingDirectory } from '../utils.mjs'; +import { cliArguments, getCargo, workingDirectory } from '../utils'; const dryRun = argv['dry-run'] ?? false; const [level] = cliArguments(); diff --git a/scripts/client/test-rust.mjs b/scripts/client/test-rust.mjs index 699acb1..583776e 100644 --- a/scripts/client/test-rust.mjs +++ b/scripts/client/test-rust.mjs @@ -1,6 +1,6 @@ #!/usr/bin/env zx import 'zx/globals'; -import { cliArguments, workingDirectory } from '../utils.mjs'; +import { cliArguments, workingDirectory } from '../utils'; // Configure additional arguments here, e.g.: // ['--arg1', '--arg2', ...cliArguments()] diff --git a/scripts/interface.mjs b/scripts/crate/interface.mjs similarity index 84% rename from scripts/interface.mjs rename to scripts/crate/interface.mjs index b7a3119..cb79bbc 100644 --- a/scripts/interface.mjs +++ b/scripts/crate/interface.mjs @@ -1,4 +1,4 @@ -import { cliArguments, workingDirectory } from './helpers/utils.mjs'; +import { cliArguments, workingDirectory } from '../helpers/utils.mjs'; export const manifestPath = path.join( workingDirectory, @@ -27,5 +27,4 @@ export function getLintDocsArguments() { return cliArguments(); } -export function getLintFeaturesArguments() { -} +export function getLintFeaturesArguments() {} diff --git a/scripts/program.mjs b/scripts/crate/program.mjs similarity index 100% rename from scripts/program.mjs rename to scripts/crate/program.mjs diff --git a/scripts/rust-client.mjs b/scripts/crate/rust-client.mjs similarity index 100% rename from scripts/rust-client.mjs rename to scripts/crate/rust-client.mjs diff --git a/scripts/crate/shared.mts b/scripts/crate/shared.mts new file mode 100644 index 0000000..04c8032 --- /dev/null +++ b/scripts/crate/shared.mts @@ -0,0 +1,27 @@ +export type CrateEnvironment = { + getLintClippyArgs: () => string[]; + getLintDocsArgs: () => string[]; + // ... +}; + +// getCrateEnvironment("interface").getLintClippyArgs(); + +export function getCrateEnvironment(crate: string): CrateEnvironment { + switch (crate) { + case 'interface': + return getInterfaceCrateEnvironment(); + default: + throw new Error(`Unknown crate: ${crate}`); + } +} + +// interface.mjs +export function getInterfaceCrateEnvironment(): CrateEnvironment { + return { + getLintClippyArgs: () => ['--all-targets'], + getLintDocsArgs: () => ['--all-targets'], + // ... + }; +} + +// the others... diff --git a/scripts/dummy.mts b/scripts/dummy.mts new file mode 100644 index 0000000..8760454 --- /dev/null +++ b/scripts/dummy.mts @@ -0,0 +1,4 @@ +#!/usr/bin/env zx +import 'zx/globals'; + +echo(chalk.green('[ SUCCESS ]'), `Well done Loris!`); diff --git a/scripts/helpers/check-solana-version.mjs b/scripts/helpers/check-solana-version.mts similarity index 98% rename from scripts/helpers/check-solana-version.mjs rename to scripts/helpers/check-solana-version.mts index 28c1d19..1495e91 100644 --- a/scripts/helpers/check-solana-version.mjs +++ b/scripts/helpers/check-solana-version.mts @@ -1,6 +1,6 @@ #!/usr/bin/env zx import 'zx/globals'; -import { getInstalledSolanaVersion, getSolanaVersion } from './utils.mjs'; +import { getInstalledSolanaVersion, getSolanaVersion } from './utils.mts'; const expectedVersion = getSolanaVersion(); const installedVersion = await getInstalledSolanaVersion(); diff --git a/scripts/helpers/generate-clients.mjs b/scripts/helpers/generate-clients.mts similarity index 55% rename from scripts/helpers/generate-clients.mjs rename to scripts/helpers/generate-clients.mts index fe5956d..518012e 100644 --- a/scripts/helpers/generate-clients.mjs +++ b/scripts/helpers/generate-clients.mts @@ -3,23 +3,27 @@ import 'zx/globals'; import { createFromRoot } from 'codama'; import { renderVisitor as renderJavaScriptVisitor } from '@codama/renderers-js'; import { renderVisitor as renderRustVisitor } from '@codama/renderers-rust'; -import { workingDirectory } from './utils.mjs'; +import { workingDirectory } from './utils.mts'; // Instanciate Codama. -const codama = createFromRoot( - require(path.join(workingDirectory, 'program', 'idl.json')) +const idl = JSON.parse( + fs.readFileSync(path.join(workingDirectory, 'program', 'idl.json'), 'utf-8') ); +const codama = createFromRoot(idl); // Render JavaScript. -const jsClient = path.join(__dirname, '..', 'clients', 'js'); +const jsClient = path.join(__dirname, '..', '..', 'clients', 'js'); +const prettierOptions = JSON.parse( + fs.readFileSync(path.join(jsClient, '.prettierrc.json'), 'utf-8') +); codama.accept( renderJavaScriptVisitor(path.join(jsClient, 'src', 'generated'), { - prettier: require(path.join(jsClient, '.prettierrc.json')), + prettierOptions, }) ); // Render Rust. -const rustClient = path.join(__dirname, '..', 'clients', 'rust'); +const rustClient = path.join(__dirname, '..', '..', 'clients', 'rust'); codama.accept( renderRustVisitor(path.join(rustClient, 'src', 'generated'), { formatCode: true, diff --git a/scripts/helpers/link-solana-version.mjs b/scripts/helpers/link-solana-version.mts similarity index 99% rename from scripts/helpers/link-solana-version.mjs rename to scripts/helpers/link-solana-version.mts index f92ae45..9da37e1 100644 --- a/scripts/helpers/link-solana-version.mjs +++ b/scripts/helpers/link-solana-version.mts @@ -1,6 +1,6 @@ #!/usr/bin/env zx import 'zx/globals'; -import { getInstalledSolanaVersion, getSolanaVersion } from './utils.mjs'; +import { getInstalledSolanaVersion, getSolanaVersion } from './utils.mts'; const expectedVersion = getSolanaVersion(); const installedVersion = await getInstalledSolanaVersion(); diff --git a/scripts/helpers/start-validator.mjs b/scripts/helpers/start-validator.mts similarity index 94% rename from scripts/helpers/start-validator.mjs rename to scripts/helpers/start-validator.mts index 1adbcab..7d7bc31 100644 --- a/scripts/helpers/start-validator.mjs +++ b/scripts/helpers/start-validator.mts @@ -8,7 +8,7 @@ import { getExternalProgramAddresses, getExternalProgramOutputDir, getProgramFolders, -} from './utils.mjs'; +} from './utils.mts'; // Check Solana version. await $`pnpm solana:check`; @@ -60,7 +60,7 @@ accounts.forEach(({ account, deployPath }) => { // Start the validator in detached mode. const cliLogs = path.join(os.tmpdir(), 'validator-cli.log'); -fs.writeFileSync(cliLogs, '', () => {}); +fs.writeFileSync(cliLogs, ''); const out = fs.openSync(cliLogs, 'a'); const err = fs.openSync(cliLogs, 'a'); const validator = spawn('solana-test-validator', args, { @@ -79,7 +79,7 @@ const waitForValidator = spinner( if (validator.exitCode !== null) { reject(logs); } else if (logs.includes('Confirmed Slot: 1')) { - resolve(); + resolve(void 0); } }, 1000); }) @@ -100,9 +100,9 @@ function getPrograms() { const binaryDir = path.join(__dirname, '..', 'target', 'deploy'); return getProgramFolders().map((folder) => { const cargo = getCargo(folder); - const name = cargo.package.name.replace(/-/g, '_'); + const name = cargo.package['name'].replace(/-/g, '_'); return { - programId: cargo.package.metadata.solana['program-id'], + programId: cargo.package['metadata'].solana['program-id'], deployPath: path.join(binaryDir, `${name}.so`), }; }); diff --git a/scripts/helpers/stop-validator.mjs b/scripts/helpers/stop-validator.mts similarity index 100% rename from scripts/helpers/stop-validator.mjs rename to scripts/helpers/stop-validator.mts diff --git a/scripts/helpers/upgrade-template.mjs b/scripts/helpers/upgrade-template.mts similarity index 94% rename from scripts/helpers/upgrade-template.mjs rename to scripts/helpers/upgrade-template.mts index 946d3a9..2691e59 100644 --- a/scripts/helpers/upgrade-template.mjs +++ b/scripts/helpers/upgrade-template.mts @@ -1,6 +1,6 @@ #!/usr/bin/env zx import 'zx/globals'; -import { getCargo } from './utils.mjs'; +import { getCargo } from './utils.mts'; // Arguments to pass to the `create-solana-program` command. const rustClientCargo = getCargo(path.join('clients', 'rust')); @@ -14,7 +14,7 @@ const templateArgs = [ '--org', 'solana-program', '--rust-client-crate-name', - rustClientCargo.package.name, + rustClientCargo.package['name'], '--js-client-package-name', jsClientPkg.name, '--default', diff --git a/scripts/helpers/utils.mjs b/scripts/helpers/utils.mts similarity index 67% rename from scripts/helpers/utils.mjs rename to scripts/helpers/utils.mts index a6e2e44..62a75dc 100644 --- a/scripts/helpers/utils.mjs +++ b/scripts/helpers/utils.mts @@ -1,30 +1,31 @@ import 'zx/globals'; import { parse as parseToml } from '@iarna/toml'; -process.env.FORCE_COLOR = 3; +process.env.FORCE_COLOR = '3'; process.env.CARGO_TERM_COLOR = 'always'; +globalThis.__dirname = path.dirname(process.argv[1]); export const workingDirectory = (await $`pwd`.quiet()).toString().trim(); -export function getAllProgramIdls() { +export function getAllProgramIdls(): string[] { return getAllProgramFolders().map((folder) => path.join(workingDirectory, folder, 'idl.json') ); } -export function getExternalProgramOutputDir() { +export function getExternalProgramOutputDir(): string { const config = getCargoMetadata()?.solana?.['external-programs-output']; return path.join(workingDirectory, config ?? 'target/deploy'); } -export function getExternalProgramAddresses() { +export function getExternalProgramAddresses(): string[] { const addresses = getProgramFolders().flatMap( (folder) => getCargoMetadata(folder)?.solana?.['program-dependencies'] ?? [] ); return Array.from(new Set(addresses)); } -export function getExternalAccountAddresses() { +export function getExternalAccountAddresses(): string[] { const addresses = getProgramFolders().flatMap( (folder) => getCargoMetadata(folder)?.solana?.['account-dependencies'] ?? [] ); @@ -32,7 +33,7 @@ export function getExternalAccountAddresses() { } let didWarnAboutMissingPrograms = false; -export function getProgramFolders() { +export function getProgramFolders(): string[] { let programs; if (process.env.PROGRAMS) { @@ -64,13 +65,13 @@ export function getProgramFolders() { return filteredPrograms; } -export function getAllProgramFolders() { - return getCargo().workspace.members.filter((member) => - getCargo(member).package?.metadata?.solana?.['program-id'] +export function getAllProgramFolders(): string[] { + return getCargo().workspace['members'].filter( + (member) => getCargo(member).package['metadata']?.['solana']?.['program-id'] ); } -export function getCargo(folder) { +export function getCargo(folder?: string) { return parseToml( fs.readFileSync( path.join(workingDirectory, folder ? folder : '.', 'Cargo.toml'), @@ -79,29 +80,29 @@ export function getCargo(folder) { ); } -export function getCargoMetadata(folder) { +export function getCargoMetadata(folder?: string) { const cargo = getCargo(folder); - return folder ? cargo?.package?.metadata : cargo?.workspace?.metadata; + return folder ? cargo?.package?.['metadata'] : cargo?.workspace?.['metadata']; } -export function getSolanaVersion() { +export function getSolanaVersion(): string { return getCargoMetadata()?.cli?.solana; } -export function getToolchain(operation) { +export function getToolchain(operation): string { return getCargoMetadata()?.toolchains?.[operation]; } -export function getToolchainArgument(operation) { +export function getToolchainArgument(operation): string { const channel = getToolchain(operation); return channel ? `+${channel}` : ''; } -export function cliArguments() { +export function cliArguments(): string[] { return process.argv.slice(3); } -export function popArgument(args, arg) { +export function popArgument(args: string[], arg: string) { const index = args.indexOf(arg); if (index >= 0) { args.splice(index, 1); @@ -109,14 +110,17 @@ export function popArgument(args, arg) { return index >= 0; } -export function partitionArguments(args, delimiter) { +export function partitionArguments( + args: string[], + delimiter: string +): [string[], string[]] { const index = args.indexOf(delimiter); return index >= 0 ? [args.slice(0, index), args.slice(index + 1)] : [args, []]; } -export async function getInstalledSolanaVersion() { +export async function getInstalledSolanaVersion(): Promise { try { const { stdout } = await $`solana --version`.quiet(); return stdout.match(/(\d+\.\d+\.\d+)/)?.[1]; diff --git a/scripts/js/format.mjs b/scripts/js/format.mts similarity index 72% rename from scripts/js/format.mjs rename to scripts/js/format.mts index dcfc3d4..5557740 100644 --- a/scripts/js/format.mjs +++ b/scripts/js/format.mts @@ -1,6 +1,6 @@ #!/usr/bin/env zx import 'zx/globals'; -import { cliArguments, workingDirectory } from '../utils.mjs'; +import { cliArguments, workingDirectory } from '../helpers/utils.mts'; // Format the client using Prettier. cd(path.join(workingDirectory, 'clients', 'js')); diff --git a/scripts/js/lint.mjs b/scripts/js/lint.mts similarity index 72% rename from scripts/js/lint.mjs rename to scripts/js/lint.mts index f5583e2..9c2c09c 100644 --- a/scripts/js/lint.mjs +++ b/scripts/js/lint.mts @@ -1,6 +1,6 @@ #!/usr/bin/env zx import 'zx/globals'; -import { cliArguments, workingDirectory } from '../utils.mjs'; +import { cliArguments, workingDirectory } from '../helpers/utils.mts'; // Check the client using ESLint. cd(path.join(workingDirectory, 'clients', 'js')); diff --git a/scripts/js/publish.mjs b/scripts/js/publish.mts similarity index 93% rename from scripts/js/publish.mjs rename to scripts/js/publish.mts index 51df188..97bfecc 100644 --- a/scripts/js/publish.mjs +++ b/scripts/js/publish.mts @@ -1,6 +1,6 @@ #!/usr/bin/env zx import 'zx/globals'; -import { cliArguments, workingDirectory } from '../utils.mjs'; +import { cliArguments, workingDirectory } from '../helpers/utils.mts'; const [level, tag = 'latest'] = cliArguments(); if (!level) { diff --git a/scripts/js/test.mjs b/scripts/js/test.mts similarity index 81% rename from scripts/js/test.mjs rename to scripts/js/test.mts index 652df0e..c0ba4a5 100644 --- a/scripts/js/test.mjs +++ b/scripts/js/test.mts @@ -1,6 +1,6 @@ #!/usr/bin/env zx import 'zx/globals'; -import { cliArguments, workingDirectory } from '../utils.mjs'; +import { cliArguments, workingDirectory } from '../helpers/utils.mts'; // Start the local validator, or restart it if it is already running. await $`pnpm validator:restart`; diff --git a/scripts/rust/format.mjs b/scripts/rust/format.mts similarity index 96% rename from scripts/rust/format.mjs rename to scripts/rust/format.mts index aa94251..951be29 100644 --- a/scripts/rust/format.mjs +++ b/scripts/rust/format.mts @@ -6,7 +6,7 @@ import { partitionArguments, popArgument, workingDirectory, -} from '../utils.mjs'; +} from '../helpers/utils.mts'; // Configure additional arguments here, e.g.: // ['--arg1', '--arg2', ...cliArguments()] diff --git a/scripts/rust/lint-clippy.mjs b/scripts/rust/lint-clippy.mts similarity index 97% rename from scripts/rust/lint-clippy.mjs rename to scripts/rust/lint-clippy.mts index 68c0c59..658e712 100644 --- a/scripts/rust/lint-clippy.mjs +++ b/scripts/rust/lint-clippy.mts @@ -5,7 +5,7 @@ import { getToolchainArgument, popArgument, workingDirectory, -} from '../utils.mjs'; +} from '../helpers/utils.mts'; // Configure additional arguments here, e.g.: // ['--arg1', '--arg2', ...cliArguments()] diff --git a/scripts/rust/lint-docs.mjs b/scripts/rust/lint-docs.mts similarity index 92% rename from scripts/rust/lint-docs.mjs rename to scripts/rust/lint-docs.mts index d819e38..a576368 100644 --- a/scripts/rust/lint-docs.mjs +++ b/scripts/rust/lint-docs.mts @@ -4,7 +4,7 @@ import { cliArguments, getToolchainArgument, workingDirectory, -} from '../utils.mjs'; +} from '../helpers/utils.mts'; const args = cliArguments(); const toolchain = getToolchainArgument('lint'); diff --git a/scripts/rust/lint-features.mjs b/scripts/rust/lint-features.mts similarity index 93% rename from scripts/rust/lint-features.mjs rename to scripts/rust/lint-features.mts index 596528c..a99961a 100644 --- a/scripts/rust/lint-features.mjs +++ b/scripts/rust/lint-features.mts @@ -4,7 +4,7 @@ import { cliArguments, getToolchainArgument, workingDirectory, -} from '../utils.mjs'; +} from '../helpers/utils.mts'; const args = ['--exclude-features', 'frozen-abi', ...cliArguments()]; const toolchain = getToolchainArgument('lint'); diff --git a/scripts/rust/lint.mjs b/scripts/rust/lint.mts similarity index 88% rename from scripts/rust/lint.mjs rename to scripts/rust/lint.mts index be0e31c..e4c45b6 100644 --- a/scripts/rust/lint.mjs +++ b/scripts/rust/lint.mts @@ -5,7 +5,7 @@ // - lint-features.mjs // - lint-docs.mjs -import { workingDirectory } from '../utils.mjs'; +import { workingDirectory } from '../helpers/utils.mts'; const scripts = path.join(workingDirectory, 'scripts', 'interface'); diff --git a/scripts/rust/test.mjs b/scripts/rust/test.mts similarity index 93% rename from scripts/rust/test.mjs rename to scripts/rust/test.mts index 2938903..d3bcec9 100644 --- a/scripts/rust/test.mjs +++ b/scripts/rust/test.mts @@ -4,7 +4,7 @@ import { cliArguments, getToolchainArgument, workingDirectory, -} from '../utils.mjs'; +} from '../helpers/utils.mts'; // Configure additional arguments here, e.g.: // ['--arg1', '--arg2', ...cliArguments()] diff --git a/scripts/rust/wasm.mjs b/scripts/rust/wasm.mts similarity index 82% rename from scripts/rust/wasm.mjs rename to scripts/rust/wasm.mts index be4adc8..40039dc 100644 --- a/scripts/rust/wasm.mjs +++ b/scripts/rust/wasm.mts @@ -1,9 +1,6 @@ #!/usr/bin/env zx import 'zx/globals'; -import { - cliArguments, - workingDirectory, -} from '../utils.mjs'; +import { cliArguments, workingDirectory } from '../helpers/utils.mts'; // Configure additional arguments here, e.g.: // ['--arg1', '--arg2', ...cliArguments()] From 4efa8387e34a17c775478a69f5f79800a9c39159 Mon Sep 17 00:00:00 2001 From: Loris Leiva Date: Mon, 2 Dec 2024 17:16:02 +0000 Subject: [PATCH 03/19] [wip]: add and use CrateEnvironment --- scripts/crate/client.mts | 23 ++++++++++++++++++ scripts/crate/index.mts | 31 ++++++++++++++++++++++++ scripts/crate/interface.mjs | 30 ----------------------- scripts/crate/interface.mts | 36 ++++++++++++++++++++++++++++ scripts/crate/program.mjs | 1 - scripts/crate/program.mts | 23 ++++++++++++++++++ scripts/crate/rust-client.mjs | 0 scripts/crate/shared.mts | 27 --------------------- scripts/dummy.mts | 4 ---- scripts/helpers/generate-clients.mts | 4 ++-- scripts/helpers/start-validator.mts | 3 ++- scripts/helpers/upgrade-template.mts | 4 ++-- scripts/helpers/utils.mts | 1 - scripts/rust/lint-clippy.mts | 27 +++++++-------------- 14 files changed, 127 insertions(+), 87 deletions(-) create mode 100644 scripts/crate/client.mts create mode 100644 scripts/crate/index.mts delete mode 100644 scripts/crate/interface.mjs create mode 100644 scripts/crate/interface.mts delete mode 100644 scripts/crate/program.mjs create mode 100644 scripts/crate/program.mts delete mode 100644 scripts/crate/rust-client.mjs delete mode 100644 scripts/crate/shared.mts delete mode 100644 scripts/dummy.mts diff --git a/scripts/crate/client.mts b/scripts/crate/client.mts new file mode 100644 index 0000000..e90326b --- /dev/null +++ b/scripts/crate/client.mts @@ -0,0 +1,23 @@ +import { cliArguments, workingDirectory } from '../helpers/utils.mjs'; +import type { CrateEnvironment } from './index.mts'; + +export function getClientCrateEnvironment(): CrateEnvironment { + return { + manifestPath: path.join(workingDirectory, 'clients', 'rust', 'Cargo.toml'), + getLintClippyArguments, + getLintDocsArguments, + getLintFeaturesArguments, + }; +} + +function getLintClippyArguments(cliArguments: string[]): string[] { + return cliArguments; // TODO +} + +function getLintDocsArguments(cliArguments: string[]): string[] { + return cliArguments; // TODO +} + +function getLintFeaturesArguments(cliArguments: string[]): string[] { + return cliArguments; // TODO +} diff --git a/scripts/crate/index.mts b/scripts/crate/index.mts new file mode 100644 index 0000000..f4956b4 --- /dev/null +++ b/scripts/crate/index.mts @@ -0,0 +1,31 @@ +import { cliArguments } from '../helpers/utils.mts'; +import { getClientCrateEnvironment } from './client.mts'; +import { getInterfaceCrateEnvironment } from './interface.mts'; +import { getProgramCrateEnvironment } from './program.mts'; + +export type CrateEnvironment = { + getLintClippyArguments: (cliArguments: string[]) => string[]; + getLintDocsArguments: (cliArguments: string[]) => string[]; + getLintFeaturesArguments: (cliArguments: string[]) => string[]; + manifestPath: string; +}; + +type Crate = 'interface' | 'client' | 'program'; + +export function getCrateEnvironmentFromArgs(): [CrateEnvironment, string[]] { + const crate = process.argv[2] as Crate; + return [getCrateEnvironment(crate), cliArguments().slice(1)]; +} + +export function getCrateEnvironment(crate: Crate): CrateEnvironment { + switch (crate) { + case 'client': + return getClientCrateEnvironment(); + case 'interface': + return getInterfaceCrateEnvironment(); + case 'program': + return getProgramCrateEnvironment(); + default: + throw new Error(`Unknown crate: ${crate}`); + } +} diff --git a/scripts/crate/interface.mjs b/scripts/crate/interface.mjs deleted file mode 100644 index cb79bbc..0000000 --- a/scripts/crate/interface.mjs +++ /dev/null @@ -1,30 +0,0 @@ -import { cliArguments, workingDirectory } from '../helpers/utils.mjs'; - -export const manifestPath = path.join( - workingDirectory, - 'interface', - 'Cargo.toml' -); - -export function getLintClippyArguments() { - const args = ['--all-targets', '--all-features', ...cliArguments()]; - // Check whether a '--' was already used. - if (args.indexOf('--') === -1) { - args.push('--'); - } - // Add additional arguments. - args.push( - '--deny=warnings', - '--deny=clippy::default_trait_access', - '--deny=clippy::arithmetic_side_effects', - '--deny=clippy::manual_let_else', - '--deny=clippy::used_underscore_binding' - ); - return args; -} - -export function getLintDocsArguments() { - return cliArguments(); -} - -export function getLintFeaturesArguments() {} diff --git a/scripts/crate/interface.mts b/scripts/crate/interface.mts new file mode 100644 index 0000000..277c05f --- /dev/null +++ b/scripts/crate/interface.mts @@ -0,0 +1,36 @@ +import { cliArguments, workingDirectory } from '../helpers/utils.mjs'; +import type { CrateEnvironment } from './index.mts'; + +export function getInterfaceCrateEnvironment(): CrateEnvironment { + return { + manifestPath: path.join(workingDirectory, 'interface', 'Cargo.toml'), + getLintClippyArguments, + getLintDocsArguments, + getLintFeaturesArguments, + }; +} + +function getLintClippyArguments(cliArguments: string[]): string[] { + const args = ['--all-targets', '--all-features', ...cliArguments]; + // Check whether a '--' was already used. + if (args.indexOf('--') === -1) { + args.push('--'); + } + // Add additional arguments. + args.push( + '--deny=warnings', + '--deny=clippy::default_trait_access', + '--deny=clippy::arithmetic_side_effects', + '--deny=clippy::manual_let_else', + '--deny=clippy::used_underscore_binding' + ); + return args; +} + +function getLintDocsArguments(cliArguments: string[]): string[] { + return cliArguments; // TODO +} + +function getLintFeaturesArguments(cliArguments: string[]): string[] { + return cliArguments; // TODO +} diff --git a/scripts/crate/program.mjs b/scripts/crate/program.mjs deleted file mode 100644 index 8b13789..0000000 --- a/scripts/crate/program.mjs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/scripts/crate/program.mts b/scripts/crate/program.mts new file mode 100644 index 0000000..d1f1cfc --- /dev/null +++ b/scripts/crate/program.mts @@ -0,0 +1,23 @@ +import { cliArguments, workingDirectory } from '../helpers/utils.mjs'; +import type { CrateEnvironment } from './index.mts'; + +export function getProgramCrateEnvironment(): CrateEnvironment { + return { + manifestPath: path.join(workingDirectory, 'program', 'Cargo.toml'), + getLintClippyArguments, + getLintDocsArguments, + getLintFeaturesArguments, + }; +} + +function getLintClippyArguments(cliArguments: string[]): string[] { + return cliArguments; // TODO +} + +function getLintDocsArguments(cliArguments: string[]): string[] { + return cliArguments; // TODO +} + +function getLintFeaturesArguments(cliArguments: string[]): string[] { + return cliArguments; // TODO +} diff --git a/scripts/crate/rust-client.mjs b/scripts/crate/rust-client.mjs deleted file mode 100644 index e69de29..0000000 diff --git a/scripts/crate/shared.mts b/scripts/crate/shared.mts deleted file mode 100644 index 04c8032..0000000 --- a/scripts/crate/shared.mts +++ /dev/null @@ -1,27 +0,0 @@ -export type CrateEnvironment = { - getLintClippyArgs: () => string[]; - getLintDocsArgs: () => string[]; - // ... -}; - -// getCrateEnvironment("interface").getLintClippyArgs(); - -export function getCrateEnvironment(crate: string): CrateEnvironment { - switch (crate) { - case 'interface': - return getInterfaceCrateEnvironment(); - default: - throw new Error(`Unknown crate: ${crate}`); - } -} - -// interface.mjs -export function getInterfaceCrateEnvironment(): CrateEnvironment { - return { - getLintClippyArgs: () => ['--all-targets'], - getLintDocsArgs: () => ['--all-targets'], - // ... - }; -} - -// the others... diff --git a/scripts/dummy.mts b/scripts/dummy.mts deleted file mode 100644 index 8760454..0000000 --- a/scripts/dummy.mts +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env zx -import 'zx/globals'; - -echo(chalk.green('[ SUCCESS ]'), `Well done Loris!`); diff --git a/scripts/helpers/generate-clients.mts b/scripts/helpers/generate-clients.mts index 518012e..5c968da 100644 --- a/scripts/helpers/generate-clients.mts +++ b/scripts/helpers/generate-clients.mts @@ -12,7 +12,7 @@ const idl = JSON.parse( const codama = createFromRoot(idl); // Render JavaScript. -const jsClient = path.join(__dirname, '..', '..', 'clients', 'js'); +const jsClient = path.join(workingDirectory, 'clients', 'js'); const prettierOptions = JSON.parse( fs.readFileSync(path.join(jsClient, '.prettierrc.json'), 'utf-8') ); @@ -23,7 +23,7 @@ codama.accept( ); // Render Rust. -const rustClient = path.join(__dirname, '..', '..', 'clients', 'rust'); +const rustClient = path.join(workingDirectory, 'clients', 'rust'); codama.accept( renderRustVisitor(path.join(rustClient, 'src', 'generated'), { formatCode: true, diff --git a/scripts/helpers/start-validator.mts b/scripts/helpers/start-validator.mts index 7d7bc31..1b7e4ae 100644 --- a/scripts/helpers/start-validator.mts +++ b/scripts/helpers/start-validator.mts @@ -8,6 +8,7 @@ import { getExternalProgramAddresses, getExternalProgramOutputDir, getProgramFolders, + workingDirectory, } from './utils.mts'; // Check Solana version. @@ -97,7 +98,7 @@ try { } function getPrograms() { - const binaryDir = path.join(__dirname, '..', 'target', 'deploy'); + const binaryDir = path.join(workingDirectory, 'target', 'deploy'); return getProgramFolders().map((folder) => { const cargo = getCargo(folder); const name = cargo.package['name'].replace(/-/g, '_'); diff --git a/scripts/helpers/upgrade-template.mts b/scripts/helpers/upgrade-template.mts index 2691e59..17a6c45 100644 --- a/scripts/helpers/upgrade-template.mts +++ b/scripts/helpers/upgrade-template.mts @@ -1,11 +1,11 @@ #!/usr/bin/env zx import 'zx/globals'; -import { getCargo } from './utils.mts'; +import { getCargo, workingDirectory } from './utils.mts'; // Arguments to pass to the `create-solana-program` command. const rustClientCargo = getCargo(path.join('clients', 'rust')); const jsClientPkg = require( - path.join(__dirname, '..', 'clients', 'js', 'package.json') + path.join(workingDirectory, 'clients', 'js', 'package.json') ); const templateArgs = [ 'system', diff --git a/scripts/helpers/utils.mts b/scripts/helpers/utils.mts index 62a75dc..1d4e6a9 100644 --- a/scripts/helpers/utils.mts +++ b/scripts/helpers/utils.mts @@ -3,7 +3,6 @@ import { parse as parseToml } from '@iarna/toml'; process.env.FORCE_COLOR = '3'; process.env.CARGO_TERM_COLOR = 'always'; -globalThis.__dirname = path.dirname(process.argv[1]); export const workingDirectory = (await $`pwd`.quiet()).toString().trim(); diff --git a/scripts/rust/lint-clippy.mts b/scripts/rust/lint-clippy.mts index 658e712..3423c81 100644 --- a/scripts/rust/lint-clippy.mts +++ b/scripts/rust/lint-clippy.mts @@ -1,35 +1,24 @@ #!/usr/bin/env zx import 'zx/globals'; import { - cliArguments, getToolchainArgument, popArgument, workingDirectory, } from '../helpers/utils.mts'; +import { + getCrateEnvironment, + getCrateEnvironmentFromArgs, +} from '../crate/index.mts'; -// Configure additional arguments here, e.g.: -// ['--arg1', '--arg2', ...cliArguments()] -const lintArgs = ['--all-targets', '--all-features', ...cliArguments()]; -// Check whether a '--' was already used. -if (lintArgs.indexOf('--') === -1) { - lintArgs.push('--'); -} -// Add additional arguments. -lintArgs.push( - '--deny=warnings', - '--deny=clippy::default_trait_access', - '--deny=clippy::arithmetic_side_effects', - '--deny=clippy::manual_let_else', - '--deny=clippy::used_underscore_binding' -); - +const [env, cliArguments] = getCrateEnvironmentFromArgs(); +const lintArgs = env.getLintClippyArguments(cliArguments); const fix = popArgument(lintArgs, '--fix'); + // Note: need to use nightly clippy as frozen-abi proc-macro generates // a lot of code (frozen-abi is enabled only under nightly due to the // use of unstable rust feature). Likewise, frozen-abi(-macro) crates' // unit tests are only compiled under nightly. const toolchain = getToolchainArgument('lint'); -const manifestPath = path.join(workingDirectory, 'interface', 'Cargo.toml'); // Lint the interface. -await $`cargo ${toolchain} clippy --manifest-path ${manifestPath} ${fix ? '--fix' : ''} ${lintArgs}`; +await $`cargo ${toolchain} clippy --manifest-path ${env.manifestPath} ${fix ? '--fix' : ''} ${lintArgs}`; From 892ff8c8ecf5acb377acac3cc5ad3d1a560305c9 Mon Sep 17 00:00:00 2001 From: Loris Leiva Date: Mon, 2 Dec 2024 17:20:10 +0000 Subject: [PATCH 04/19] [wip]: add getDefaultCrateEnvironment --- scripts/crate/client.mts | 2 +- scripts/crate/index.mts | 4 ++++ scripts/crate/interface.mts | 5 +++-- scripts/crate/program.mts | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/scripts/crate/client.mts b/scripts/crate/client.mts index e90326b..c8598d4 100644 --- a/scripts/crate/client.mts +++ b/scripts/crate/client.mts @@ -1,4 +1,4 @@ -import { cliArguments, workingDirectory } from '../helpers/utils.mjs'; +import { workingDirectory } from '../helpers/utils.mjs'; import type { CrateEnvironment } from './index.mts'; export function getClientCrateEnvironment(): CrateEnvironment { diff --git a/scripts/crate/index.mts b/scripts/crate/index.mts index f4956b4..70c8c76 100644 --- a/scripts/crate/index.mts +++ b/scripts/crate/index.mts @@ -29,3 +29,7 @@ export function getCrateEnvironment(crate: Crate): CrateEnvironment { throw new Error(`Unknown crate: ${crate}`); } } + +export function getDefaultCrateEnvironment(): CrateEnvironment { + return {} as CrateEnvironment; // TODO +} diff --git a/scripts/crate/interface.mts b/scripts/crate/interface.mts index 277c05f..3e4c95c 100644 --- a/scripts/crate/interface.mts +++ b/scripts/crate/interface.mts @@ -1,8 +1,9 @@ -import { cliArguments, workingDirectory } from '../helpers/utils.mjs'; -import type { CrateEnvironment } from './index.mts'; +import { workingDirectory } from '../helpers/utils.mjs'; +import { getDefaultCrateEnvironment, type CrateEnvironment } from './index.mts'; export function getInterfaceCrateEnvironment(): CrateEnvironment { return { + ...getDefaultCrateEnvironment(), manifestPath: path.join(workingDirectory, 'interface', 'Cargo.toml'), getLintClippyArguments, getLintDocsArguments, diff --git a/scripts/crate/program.mts b/scripts/crate/program.mts index d1f1cfc..58e4132 100644 --- a/scripts/crate/program.mts +++ b/scripts/crate/program.mts @@ -1,4 +1,4 @@ -import { cliArguments, workingDirectory } from '../helpers/utils.mjs'; +import { workingDirectory } from '../helpers/utils.mjs'; import type { CrateEnvironment } from './index.mts'; export function getProgramCrateEnvironment(): CrateEnvironment { From ab253a89acde8b9b0b256c6e5727bbd0d0301281 Mon Sep 17 00:00:00 2001 From: febo Date: Fri, 6 Dec 2024 16:13:53 +0000 Subject: [PATCH 05/19] Moved to helpers --- scripts/js/format.mts | 8 -------- scripts/js/lint.mts | 8 -------- scripts/js/publish.mts | 35 ---------------------------------- scripts/js/test.mts | 12 ------------ scripts/rust/format.mts | 25 ------------------------ scripts/rust/lint-clippy.mts | 24 ----------------------- scripts/rust/lint-docs.mts | 13 ------------- scripts/rust/lint-features.mts | 14 -------------- scripts/rust/lint.mts | 17 ----------------- scripts/rust/test.mts | 16 ---------------- scripts/rust/wasm.mts | 11 ----------- 11 files changed, 183 deletions(-) delete mode 100644 scripts/js/format.mts delete mode 100644 scripts/js/lint.mts delete mode 100644 scripts/js/publish.mts delete mode 100644 scripts/js/test.mts delete mode 100644 scripts/rust/format.mts delete mode 100644 scripts/rust/lint-clippy.mts delete mode 100644 scripts/rust/lint-docs.mts delete mode 100644 scripts/rust/lint-features.mts delete mode 100644 scripts/rust/lint.mts delete mode 100644 scripts/rust/test.mts delete mode 100644 scripts/rust/wasm.mts diff --git a/scripts/js/format.mts b/scripts/js/format.mts deleted file mode 100644 index 5557740..0000000 --- a/scripts/js/format.mts +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env zx -import 'zx/globals'; -import { cliArguments, workingDirectory } from '../helpers/utils.mts'; - -// Format the client using Prettier. -cd(path.join(workingDirectory, 'clients', 'js')); -await $`pnpm install`; -await $`pnpm format ${cliArguments()}`; diff --git a/scripts/js/lint.mts b/scripts/js/lint.mts deleted file mode 100644 index 9c2c09c..0000000 --- a/scripts/js/lint.mts +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env zx -import 'zx/globals'; -import { cliArguments, workingDirectory } from '../helpers/utils.mts'; - -// Check the client using ESLint. -cd(path.join(workingDirectory, 'clients', 'js')); -await $`pnpm install`; -await $`pnpm lint ${cliArguments()}`; diff --git a/scripts/js/publish.mts b/scripts/js/publish.mts deleted file mode 100644 index 97bfecc..0000000 --- a/scripts/js/publish.mts +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env zx -import 'zx/globals'; -import { cliArguments, workingDirectory } from '../helpers/utils.mts'; - -const [level, tag = 'latest'] = cliArguments(); -if (!level) { - throw new Error('A version level — e.g. "path" — must be provided.'); -} - -// Go to the client directory and install the dependencies. -cd(path.join(workingDirectory, 'clients', 'js')); -await $`pnpm install`; - -// Update the version. -const versionArgs = [ - '--no-git-tag-version', - ...(level.startsWith('pre') ? [`--preid ${tag}`] : []), -]; -let { stdout } = await $`pnpm version ${level} ${versionArgs}`; -const newVersion = stdout.slice(1).trim(); - -// Expose the new version to CI if needed. -if (process.env.CI) { - await $`echo "new_version=${newVersion}" >> $GITHUB_OUTPUT`; -} - -// Publish the package. -// This will also build the package before publishing (see prepublishOnly script). -await $`pnpm publish --no-git-checks --tag ${tag}`; - -// Commit the new version. -await $`git commit -am "Publish JS client v${newVersion}"`; - -// Tag the new version. -await $`git tag -a js@v${newVersion} -m "JS client v${newVersion}"`; diff --git a/scripts/js/test.mts b/scripts/js/test.mts deleted file mode 100644 index c0ba4a5..0000000 --- a/scripts/js/test.mts +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env zx -import 'zx/globals'; -import { cliArguments, workingDirectory } from '../helpers/utils.mts'; - -// Start the local validator, or restart it if it is already running. -await $`pnpm validator:restart`; - -// Build the client and run the tests. -cd(path.join(workingDirectory, 'clients', 'js')); -await $`pnpm install`; -await $`pnpm build`; -await $`pnpm test ${cliArguments()}`; diff --git a/scripts/rust/format.mts b/scripts/rust/format.mts deleted file mode 100644 index 951be29..0000000 --- a/scripts/rust/format.mts +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env zx -import 'zx/globals'; -import { - cliArguments, - getToolchainArgument, - partitionArguments, - popArgument, - workingDirectory, -} from '../helpers/utils.mts'; - -// Configure additional arguments here, e.g.: -// ['--arg1', '--arg2', ...cliArguments()] -const formatArgs = cliArguments(); - -const fix = popArgument(formatArgs, '--fix'); -const [cargoArgs, fmtArgs] = partitionArguments(formatArgs, '--'); -const toolchain = getToolchainArgument('format'); -const manifestPath = path.join(workingDirectory, 'interface', 'Cargo.toml'); - -// Format the interface. -if (fix) { - await $`cargo ${toolchain} fmt --manifest-path ${manifestPath} ${cargoArgs} -- ${fmtArgs}`; -} else { - await $`cargo ${toolchain} fmt --manifest-path ${manifestPath} ${cargoArgs} -- --check ${fmtArgs}`; -} diff --git a/scripts/rust/lint-clippy.mts b/scripts/rust/lint-clippy.mts deleted file mode 100644 index 3423c81..0000000 --- a/scripts/rust/lint-clippy.mts +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env zx -import 'zx/globals'; -import { - getToolchainArgument, - popArgument, - workingDirectory, -} from '../helpers/utils.mts'; -import { - getCrateEnvironment, - getCrateEnvironmentFromArgs, -} from '../crate/index.mts'; - -const [env, cliArguments] = getCrateEnvironmentFromArgs(); -const lintArgs = env.getLintClippyArguments(cliArguments); -const fix = popArgument(lintArgs, '--fix'); - -// Note: need to use nightly clippy as frozen-abi proc-macro generates -// a lot of code (frozen-abi is enabled only under nightly due to the -// use of unstable rust feature). Likewise, frozen-abi(-macro) crates' -// unit tests are only compiled under nightly. -const toolchain = getToolchainArgument('lint'); - -// Lint the interface. -await $`cargo ${toolchain} clippy --manifest-path ${env.manifestPath} ${fix ? '--fix' : ''} ${lintArgs}`; diff --git a/scripts/rust/lint-docs.mts b/scripts/rust/lint-docs.mts deleted file mode 100644 index a576368..0000000 --- a/scripts/rust/lint-docs.mts +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env zx -import 'zx/globals'; -import { - cliArguments, - getToolchainArgument, - workingDirectory, -} from '../helpers/utils.mts'; - -const args = cliArguments(); -const toolchain = getToolchainArgument('lint'); -const manifestPath = path.join(workingDirectory, 'interface', 'Cargo.toml'); - -await $`RUSTDOCFLAGS="--cfg docsrs -D warnings" cargo ${toolchain} doc --manifest-path ${manifestPath} --all-features --no-deps ${args}`; diff --git a/scripts/rust/lint-features.mts b/scripts/rust/lint-features.mts deleted file mode 100644 index a99961a..0000000 --- a/scripts/rust/lint-features.mts +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env zx -import 'zx/globals'; -import { - cliArguments, - getToolchainArgument, - workingDirectory, -} from '../helpers/utils.mts'; - -const args = ['--exclude-features', 'frozen-abi', ...cliArguments()]; -const toolchain = getToolchainArgument('lint'); -const manifestPath = path.join(workingDirectory, 'interface', 'Cargo.toml'); - -// Check feature powerset. -await $`cargo ${toolchain} hack check --manifest-path ${manifestPath} --feature-powerset --all-targets ${args}`; diff --git a/scripts/rust/lint.mts b/scripts/rust/lint.mts deleted file mode 100644 index e4c45b6..0000000 --- a/scripts/rust/lint.mts +++ /dev/null @@ -1,17 +0,0 @@ -// Script to lint the interface crate. -// -// This script runs the following sub-scripts: -// - lint-clippy.mjs -// - lint-features.mjs -// - lint-docs.mjs - -import { workingDirectory } from '../helpers/utils.mts'; - -const scripts = path.join(workingDirectory, 'scripts', 'interface'); - -// clippy -await $`zx ${path.join(scripts, 'lint-clippy.mjs')}`; -// features -await $`zx ${path.join(scripts, 'lint-features.mjs')}`; -// rustdoc -await $`zx ${path.join(scripts, 'lint-docs.mjs')}`; diff --git a/scripts/rust/test.mts b/scripts/rust/test.mts deleted file mode 100644 index d3bcec9..0000000 --- a/scripts/rust/test.mts +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env zx -import 'zx/globals'; -import { - cliArguments, - getToolchainArgument, - workingDirectory, -} from '../helpers/utils.mts'; - -// Configure additional arguments here, e.g.: -// ['--arg1', '--arg2', ...cliArguments()] -const buildArgs = cliArguments(); -const toolchain = getToolchainArgument('test'); -const manifestPath = path.join(workingDirectory, 'interface', 'Cargo.toml'); - -// Test the interface. -await $`cargo ${toolchain} test --all-features --manifest-path ${manifestPath} ${buildArgs}`; diff --git a/scripts/rust/wasm.mts b/scripts/rust/wasm.mts deleted file mode 100644 index 40039dc..0000000 --- a/scripts/rust/wasm.mts +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env zx -import 'zx/globals'; -import { cliArguments, workingDirectory } from '../helpers/utils.mts'; - -// Configure additional arguments here, e.g.: -// ['--arg1', '--arg2', ...cliArguments()] -const buildArgs = cliArguments(); -const cratePath = path.join(workingDirectory, 'interface'); - -// Build the interface. -await $`wasm-pack build --target nodejs --dev ${cratePath} --features bincode ${buildArgs}`; From 07b0dda911c2cac143d11c26661037cb2f02bee3 Mon Sep 17 00:00:00 2001 From: febo Date: Fri, 6 Dec 2024 16:14:37 +0000 Subject: [PATCH 06/19] Remove unused --- scripts/client/format-rust.mjs | 30 -------------------- scripts/client/lint-rust-clippy.mjs | 24 ---------------- scripts/client/lint-rust-docs.mjs | 14 ---------- scripts/client/lint-rust-features.mjs | 15 ---------- scripts/client/lint-rust.mjs | 17 ------------ scripts/client/publish-rust.mjs | 40 --------------------------- scripts/client/test-rust.mjs | 18 ------------ 7 files changed, 158 deletions(-) delete mode 100644 scripts/client/format-rust.mjs delete mode 100644 scripts/client/lint-rust-clippy.mjs delete mode 100644 scripts/client/lint-rust-docs.mjs delete mode 100644 scripts/client/lint-rust-features.mjs delete mode 100644 scripts/client/lint-rust.mjs delete mode 100644 scripts/client/publish-rust.mjs delete mode 100644 scripts/client/test-rust.mjs diff --git a/scripts/client/format-rust.mjs b/scripts/client/format-rust.mjs deleted file mode 100644 index 71d3e12..0000000 --- a/scripts/client/format-rust.mjs +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env zx -import 'zx/globals'; -import { - cliArguments, - getToolchainArgument, - partitionArguments, - popArgument, - workingDirectory, -} from '../utils'; - -// Configure additional arguments here, e.g.: -// ['--arg1', '--arg2', ...cliArguments()] -const formatArgs = cliArguments(); - -const fix = popArgument(formatArgs, '--fix'); -const [cargoArgs, fmtArgs] = partitionArguments(formatArgs, '--'); -const toolchain = getToolchainArgument('format'); -const manifestPath = path.join( - workingDirectory, - 'clients', - 'rust', - 'Cargo.toml' -); - -// Format the client. -if (fix) { - await $`cargo ${toolchain} fmt --manifest-path ${manifestPath} ${cargoArgs} -- ${fmtArgs}`; -} else { - await $`cargo ${toolchain} fmt --manifest-path ${manifestPath} ${cargoArgs} -- --check ${fmtArgs}`; -} diff --git a/scripts/client/lint-rust-clippy.mjs b/scripts/client/lint-rust-clippy.mjs deleted file mode 100644 index b8cc390..0000000 --- a/scripts/client/lint-rust-clippy.mjs +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env zx -import 'zx/globals'; -import { - cliArguments, - getToolchainArgument, - popArgument, - workingDirectory, -} from '../utils'; - -// Configure additional arguments here, e.g.: -// ['--arg1', '--arg2', ...cliArguments()] -const lintArgs = cliArguments(); - -const fix = popArgument(lintArgs, '--fix'); -const toolchain = getToolchainArgument('lint'); -const manifestPath = path.join( - workingDirectory, - 'clients', - 'rust', - 'Cargo.toml' -); - -// Check the client using Clippy. -await $`cargo ${toolchain} clippy --manifest-path ${manifestPath} ${fix ? '--fix' : ''} ${lintArgs}`; diff --git a/scripts/client/lint-rust-docs.mjs b/scripts/client/lint-rust-docs.mjs deleted file mode 100644 index 4a6b3bb..0000000 --- a/scripts/client/lint-rust-docs.mjs +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env zx -import 'zx/globals'; -import { cliArguments, getToolchainArgument, workingDirectory } from '../utils'; - -const args = cliArguments(); -const toolchain = getToolchainArgument('lint'); -const manifestPath = path.join( - workingDirectory, - 'clients', - 'rust', - 'Cargo.toml' -); - -await $`RUSTDOCFLAGS="--cfg docsrs -D warnings" cargo ${toolchain} doc --manifest-path ${manifestPath} --all-features --no-deps ${args}`; diff --git a/scripts/client/lint-rust-features.mjs b/scripts/client/lint-rust-features.mjs deleted file mode 100644 index a760735..0000000 --- a/scripts/client/lint-rust-features.mjs +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env zx -import 'zx/globals'; -import { cliArguments, getToolchainArgument, workingDirectory } from '../utils'; - -const args = cliArguments(); -const toolchain = getToolchainArgument('lint'); -const manifestPath = path.join( - workingDirectory, - 'clients', - 'rust', - 'Cargo.toml' -); - -// Check feature powerset. -await $`cargo ${toolchain} hack check --manifest-path ${manifestPath} --feature-powerset --all-targets ${args}`; diff --git a/scripts/client/lint-rust.mjs b/scripts/client/lint-rust.mjs deleted file mode 100644 index 3cbefe5..0000000 --- a/scripts/client/lint-rust.mjs +++ /dev/null @@ -1,17 +0,0 @@ -// Script to lint the Rust client crate. -// -// This script runs the following sub-scripts: -// - lint-rust-clippy.mjs -// - lint-rust-features.mjs -// - lint-rust-docs.mjs - -import { cliArguments, workingDirectory } from '../utils'; - -const scripts = path.join(workingDirectory, 'scripts', 'client'); - -// clippy -await $`zx ${path.join(scripts, 'lint-rust-clippy.mjs')}`; -// features -await $`zx ${path.join(scripts, 'lint-rust-features.mjs')}`; -// rustdoc -await $`zx ${path.join(scripts, 'lint-rust-docs.mjs')}`; diff --git a/scripts/client/publish-rust.mjs b/scripts/client/publish-rust.mjs deleted file mode 100644 index f976821..0000000 --- a/scripts/client/publish-rust.mjs +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env zx -import 'zx/globals'; -import { cliArguments, getCargo, workingDirectory } from '../utils'; - -const dryRun = argv['dry-run'] ?? false; -const [level] = cliArguments(); -if (!level) { - throw new Error('A version level — e.g. "path" — must be provided.'); -} - -// Go to the client directory and install the dependencies. -cd(path.join(workingDirectory, 'clients', 'rust')); - -// Publish the new version. -const releaseArgs = dryRun - ? [] - : ['--no-push', '--no-tag', '--no-confirm', '--execute']; -await $`cargo release ${level} ${releaseArgs}`; - -// Stop here if this is a dry run. -if (dryRun) { - process.exit(0); -} - -// Get the new version. -const newVersion = getCargo(path.join('clients', 'rust')).package.version; - -// Expose the new version to CI if needed. -if (process.env.CI) { - await $`echo "new_version=${newVersion}" >> $GITHUB_OUTPUT`; -} - -// Soft reset the last commit so we can create our own commit and tag. -await $`git reset --soft HEAD~1`; - -// Commit the new version. -await $`git commit -am "Publish Rust client v${newVersion}"`; - -// Tag the new version. -await $`git tag -a rust@v${newVersion} -m "Rust client v${newVersion}"`; diff --git a/scripts/client/test-rust.mjs b/scripts/client/test-rust.mjs deleted file mode 100644 index 583776e..0000000 --- a/scripts/client/test-rust.mjs +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env zx -import 'zx/globals'; -import { cliArguments, workingDirectory } from '../utils'; - -// Configure additional arguments here, e.g.: -// ['--arg1', '--arg2', ...cliArguments()] -const testArgs = cliArguments(); - -const hasSolfmt = await which('solfmt', { nothrow: true }); -const sbfOutDir = path.join(workingDirectory, 'target', 'deploy'); - -// Run the tests. -cd(path.join(workingDirectory, 'clients', 'rust')); -if (hasSolfmt) { - await $`SBF_OUT_DIR=${sbfOutDir} cargo test --features "test-sbf" ${testArgs} 2>&1 | solfmt`; -} else { - await $`SBF_OUT_DIR=${sbfOutDir} cargo test --features "test-sbf" ${testArgs}`; -} From 9ade7b1c8bcced835d31ebad77f96e12b3a39397 Mon Sep 17 00:00:00 2001 From: febo Date: Fri, 6 Dec 2024 16:15:11 +0000 Subject: [PATCH 07/19] Complete CrateEnvironment type --- scripts/crate/client.mts | 4 +++- scripts/crate/index.mts | 21 ++++++++++++++++++++- scripts/crate/interface.mts | 3 ++- scripts/crate/program.mts | 4 +++- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/scripts/crate/client.mts b/scripts/crate/client.mts index c8598d4..33323ba 100644 --- a/scripts/crate/client.mts +++ b/scripts/crate/client.mts @@ -1,8 +1,10 @@ import { workingDirectory } from '../helpers/utils.mjs'; -import type { CrateEnvironment } from './index.mts'; +import { getDefaultCrateEnvironment, type CrateEnvironment } from './index.mts'; export function getClientCrateEnvironment(): CrateEnvironment { return { + ...getDefaultCrateEnvironment(), + cratePath: path.join(workingDirectory, 'clients', 'rust'), manifestPath: path.join(workingDirectory, 'clients', 'rust', 'Cargo.toml'), getLintClippyArguments, getLintDocsArguments, diff --git a/scripts/crate/index.mts b/scripts/crate/index.mts index 70c8c76..f88eed0 100644 --- a/scripts/crate/index.mts +++ b/scripts/crate/index.mts @@ -4,9 +4,14 @@ import { getInterfaceCrateEnvironment } from './interface.mts'; import { getProgramCrateEnvironment } from './program.mts'; export type CrateEnvironment = { + getFormatArguments: (cliArguments: string[]) => string[]; getLintClippyArguments: (cliArguments: string[]) => string[]; getLintDocsArguments: (cliArguments: string[]) => string[]; getLintFeaturesArguments: (cliArguments: string[]) => string[]; + getPublishArguments: (cliArguments: string[]) => string[]; + getTestArguments: (cliArguments: string[]) => string[]; + getWasmArguments: (cliArguments: string[]) => string[]; + cratePath: string; manifestPath: string; }; @@ -30,6 +35,20 @@ export function getCrateEnvironment(crate: Crate): CrateEnvironment { } } +const getCliArguments = (args: string[]): string[] => { + return args; +}; + export function getDefaultCrateEnvironment(): CrateEnvironment { - return {} as CrateEnvironment; // TODO + return { + getFormatArguments: getCliArguments, + getLintClippyArguments: getCliArguments, + getLintDocsArguments: getCliArguments, + getLintFeaturesArguments: getCliArguments, + getPublishArguments: getCliArguments, + getTestArguments: getCliArguments, + getWasmArguments: getCliArguments, + cratePath: '', + manifestPath: '', + } as CrateEnvironment; } diff --git a/scripts/crate/interface.mts b/scripts/crate/interface.mts index 3e4c95c..630a7c7 100644 --- a/scripts/crate/interface.mts +++ b/scripts/crate/interface.mts @@ -4,6 +4,7 @@ import { getDefaultCrateEnvironment, type CrateEnvironment } from './index.mts'; export function getInterfaceCrateEnvironment(): CrateEnvironment { return { ...getDefaultCrateEnvironment(), + cratePath: path.join(workingDirectory, 'interface'), manifestPath: path.join(workingDirectory, 'interface', 'Cargo.toml'), getLintClippyArguments, getLintDocsArguments, @@ -33,5 +34,5 @@ function getLintDocsArguments(cliArguments: string[]): string[] { } function getLintFeaturesArguments(cliArguments: string[]): string[] { - return cliArguments; // TODO + return ['--exclude-features', 'frozen-abi', ...cliArguments]; } diff --git a/scripts/crate/program.mts b/scripts/crate/program.mts index 58e4132..c2f5fc9 100644 --- a/scripts/crate/program.mts +++ b/scripts/crate/program.mts @@ -1,8 +1,10 @@ import { workingDirectory } from '../helpers/utils.mjs'; -import type { CrateEnvironment } from './index.mts'; +import { getDefaultCrateEnvironment, type CrateEnvironment } from './index.mts'; export function getProgramCrateEnvironment(): CrateEnvironment { return { + ...getDefaultCrateEnvironment(), + cratePath: path.join(workingDirectory, 'program'), manifestPath: path.join(workingDirectory, 'program', 'Cargo.toml'), getLintClippyArguments, getLintDocsArguments, From 1f9997b055cd7b3e813f1714b26b30e58aa3b98a Mon Sep 17 00:00:00 2001 From: febo Date: Fri, 6 Dec 2024 16:29:19 +0000 Subject: [PATCH 08/19] Update scripts path --- package.json | 16 +++++------ scripts/helpers/js/format.mts | 8 ++++++ scripts/helpers/js/lint.mts | 8 ++++++ scripts/helpers/js/publish.mts | 35 ++++++++++++++++++++++ scripts/helpers/js/test.mts | 12 ++++++++ scripts/helpers/rust/format.mts | 17 +++++++++++ scripts/helpers/rust/lint-clippy.mts | 16 +++++++++++ scripts/helpers/rust/lint-docs.mts | 10 +++++++ scripts/helpers/rust/lint-features.mts | 11 +++++++ scripts/helpers/rust/lint.mts | 17 +++++++++++ scripts/helpers/rust/publish.mts | 40 ++++++++++++++++++++++++++ scripts/helpers/rust/test.mts | 11 +++++++ scripts/helpers/rust/wasm.mts | 8 ++++++ 13 files changed, 201 insertions(+), 8 deletions(-) create mode 100644 scripts/helpers/js/format.mts create mode 100644 scripts/helpers/js/lint.mts create mode 100644 scripts/helpers/js/publish.mts create mode 100644 scripts/helpers/js/test.mts create mode 100644 scripts/helpers/rust/format.mts create mode 100644 scripts/helpers/rust/lint-clippy.mts create mode 100644 scripts/helpers/rust/lint-docs.mts create mode 100644 scripts/helpers/rust/lint-features.mts create mode 100644 scripts/helpers/rust/lint.mts create mode 100644 scripts/helpers/rust/publish.mts create mode 100644 scripts/helpers/rust/test.mts create mode 100644 scripts/helpers/rust/wasm.mts diff --git a/package.json b/package.json index 12d9848..4510633 100644 --- a/package.json +++ b/package.json @@ -8,14 +8,14 @@ "validator:start": "tsx ./scripts/helpers/start-validator.mts", "validator:restart": "pnpm validator:start --restart", "validator:stop": "tsx ./scripts/helpers/stop-validator.mts", - "js:format": "tsx ./scripts/js/format.mts", - "js:lint": "tsx ./scripts/js/lint.mts", - "js:publish": "tsx ./scripts/js/publish.mts", - "js:test": "tsx ./scripts/js/test.mts", - "rust:format": "tsx ./scripts/client/format-rust.mts", - "rust:lint": "tsx ./scripts/client/lint-rust.mts", - "rust:publish": "tsx ./scripts/client/publish-rust.mts", - "rust:test": "tsx ./scripts/client/test-rust.mts", + "js:format": "tsx ./scripts/helpers/js/format.mts", + "js:lint": "tsx ./scripts/helpers/js/lint.mts", + "js:publish": "tsx ./scripts/helpers/js/publish.mts", + "js:test": "tsx ./scripts/helpers/js/test.mts", + "rust:format": "tsx ./scripts/helpers/rust/format.mts", + "rust:lint": "tsx ./scripts/helpers/rust/lint.mts", + "rust:publish": "tsx ./scripts/helpers/rust/publish.mts", + "rust:test": "tsx ./scripts/helpers/rust/test.mts", "template:upgrade": "tsx ./scripts/helpers/upgrade-template.ts" }, "devDependencies": { diff --git a/scripts/helpers/js/format.mts b/scripts/helpers/js/format.mts new file mode 100644 index 0000000..a9056d2 --- /dev/null +++ b/scripts/helpers/js/format.mts @@ -0,0 +1,8 @@ +#!/usr/bin/env zx +import 'zx/globals'; +import { cliArguments, workingDirectory } from '../utils.mts'; + +// Format the client using Prettier. +cd(path.join(workingDirectory, 'clients', 'js')); +await $`pnpm install`; +await $`pnpm format ${cliArguments()}`; diff --git a/scripts/helpers/js/lint.mts b/scripts/helpers/js/lint.mts new file mode 100644 index 0000000..fb8f928 --- /dev/null +++ b/scripts/helpers/js/lint.mts @@ -0,0 +1,8 @@ +#!/usr/bin/env zx +import 'zx/globals'; +import { cliArguments, workingDirectory } from '../utils.mts'; + +// Check the client using ESLint. +cd(path.join(workingDirectory, 'clients', 'js')); +await $`pnpm install`; +await $`pnpm lint ${cliArguments()}`; diff --git a/scripts/helpers/js/publish.mts b/scripts/helpers/js/publish.mts new file mode 100644 index 0000000..262bc30 --- /dev/null +++ b/scripts/helpers/js/publish.mts @@ -0,0 +1,35 @@ +#!/usr/bin/env zx +import 'zx/globals'; +import { cliArguments, workingDirectory } from '../utils.mts'; + +const [level, tag = 'latest'] = cliArguments(); +if (!level) { + throw new Error('A version level — e.g. "path" — must be provided.'); +} + +// Go to the client directory and install the dependencies. +cd(path.join(workingDirectory, 'clients', 'js')); +await $`pnpm install`; + +// Update the version. +const versionArgs = [ + '--no-git-tag-version', + ...(level.startsWith('pre') ? [`--preid ${tag}`] : []), +]; +let { stdout } = await $`pnpm version ${level} ${versionArgs}`; +const newVersion = stdout.slice(1).trim(); + +// Expose the new version to CI if needed. +if (process.env.CI) { + await $`echo "new_version=${newVersion}" >> $GITHUB_OUTPUT`; +} + +// Publish the package. +// This will also build the package before publishing (see prepublishOnly script). +await $`pnpm publish --no-git-checks --tag ${tag}`; + +// Commit the new version. +await $`git commit -am "Publish JS client v${newVersion}"`; + +// Tag the new version. +await $`git tag -a js@v${newVersion} -m "JS client v${newVersion}"`; diff --git a/scripts/helpers/js/test.mts b/scripts/helpers/js/test.mts new file mode 100644 index 0000000..bb61419 --- /dev/null +++ b/scripts/helpers/js/test.mts @@ -0,0 +1,12 @@ +#!/usr/bin/env zx +import 'zx/globals'; +import { cliArguments, workingDirectory } from '../utils.mts'; + +// Start the local validator, or restart it if it is already running. +await $`pnpm validator:restart`; + +// Build the client and run the tests. +cd(path.join(workingDirectory, 'clients', 'js')); +await $`pnpm install`; +await $`pnpm build`; +await $`pnpm test ${cliArguments()}`; diff --git a/scripts/helpers/rust/format.mts b/scripts/helpers/rust/format.mts new file mode 100644 index 0000000..a9655ba --- /dev/null +++ b/scripts/helpers/rust/format.mts @@ -0,0 +1,17 @@ +#!/usr/bin/env zx +import 'zx/globals'; +import { getCrateEnvironmentFromArgs } from '../../crate/index.mts'; +import { + getToolchainArgument, + partitionArguments, + popArgument, +} from '../utils.mts'; + +const [env, cliArguments] = getCrateEnvironmentFromArgs(); +const args = env.getFormatArguments(cliArguments); + +const fix = popArgument(args, '--fix'); +const [cargoArgs, fmtArgs] = partitionArguments(args, '--'); +const toolchain = getToolchainArgument('format'); + +await $`cargo ${toolchain} fmt --manifest-path ${env.manifestPath} ${cargoArgs} -- ${fix ? '' : '--check'} ${fmtArgs}`; diff --git a/scripts/helpers/rust/lint-clippy.mts b/scripts/helpers/rust/lint-clippy.mts new file mode 100644 index 0000000..9c0448b --- /dev/null +++ b/scripts/helpers/rust/lint-clippy.mts @@ -0,0 +1,16 @@ +#!/usr/bin/env zx +import 'zx/globals'; +import { getCrateEnvironmentFromArgs } from '../../crate/index.mts'; +import { getToolchainArgument, popArgument } from '../utils.mts'; + +const [env, cliArguments] = getCrateEnvironmentFromArgs(); +const clippyArgs = env.getLintClippyArguments(cliArguments); +const fix = popArgument(clippyArgs, '--fix'); + +// Note: need to use nightly clippy as frozen-abi proc-macro generates +// a lot of code (frozen-abi is enabled only under nightly due to the +// use of unstable rust feature). Likewise, frozen-abi(-macro) crates' +// unit tests are only compiled under nightly. +const toolchain = getToolchainArgument('lint'); + +await $`cargo ${toolchain} clippy --manifest-path ${env.manifestPath} ${fix ? '--fix' : ''} ${clippyArgs}`; diff --git a/scripts/helpers/rust/lint-docs.mts b/scripts/helpers/rust/lint-docs.mts new file mode 100644 index 0000000..612acc5 --- /dev/null +++ b/scripts/helpers/rust/lint-docs.mts @@ -0,0 +1,10 @@ +#!/usr/bin/env zx +import 'zx/globals'; +import { getCrateEnvironmentFromArgs } from '../../crate/index.mts'; +import { getToolchainArgument } from '../utils.mts'; + +const [env, cliArguments] = getCrateEnvironmentFromArgs(); +const docArgs = env.getLintDocsArguments(cliArguments); +const toolchain = getToolchainArgument('lint'); + +await $`RUSTDOCFLAGS="--cfg docsrs -D warnings" cargo ${toolchain} doc --manifest-path ${env.manifestPath} --all-features --no-deps ${docArgs}`; diff --git a/scripts/helpers/rust/lint-features.mts b/scripts/helpers/rust/lint-features.mts new file mode 100644 index 0000000..69bdd79 --- /dev/null +++ b/scripts/helpers/rust/lint-features.mts @@ -0,0 +1,11 @@ +#!/usr/bin/env zx +import 'zx/globals'; +import { getCrateEnvironmentFromArgs } from '../../crate/index.mts'; +import { getToolchainArgument } from '../utils.mts'; + +const [env, cliArguments] = getCrateEnvironmentFromArgs(); +const featuresArgs = env.getLintDocsArguments(cliArguments); +const toolchain = getToolchainArgument('lint'); + +// Check feature powerset. +await $`cargo ${toolchain} hack check --manifest-path ${env.manifestPath} --feature-powerset --all-targets ${featuresArgs}`; diff --git a/scripts/helpers/rust/lint.mts b/scripts/helpers/rust/lint.mts new file mode 100644 index 0000000..f955173 --- /dev/null +++ b/scripts/helpers/rust/lint.mts @@ -0,0 +1,17 @@ +// Script to lint a crate. +// +// This script runs the following sub-scripts: +// - lint-clippy.mjs +// - lint-docs.mjs +// - lint-features.mjs + +import { workingDirectory } from '../utils.mts'; + +const scripts = path.join(workingDirectory, 'scripts', 'helpers', 'rust'); + +// clippy +await $`tsx ${path.join(scripts, 'lint-clippy.mjs')} ${process.argv.slice(2)}`; +// rustdoc +await $`tsx ${path.join(scripts, 'lint-docs.mjs')} ${process.argv.slice(2)}`; +// features +await $`tsx ${path.join(scripts, 'lint-features.mjs')} ${process.argv.slice(2)}`; diff --git a/scripts/helpers/rust/publish.mts b/scripts/helpers/rust/publish.mts new file mode 100644 index 0000000..f976821 --- /dev/null +++ b/scripts/helpers/rust/publish.mts @@ -0,0 +1,40 @@ +#!/usr/bin/env zx +import 'zx/globals'; +import { cliArguments, getCargo, workingDirectory } from '../utils'; + +const dryRun = argv['dry-run'] ?? false; +const [level] = cliArguments(); +if (!level) { + throw new Error('A version level — e.g. "path" — must be provided.'); +} + +// Go to the client directory and install the dependencies. +cd(path.join(workingDirectory, 'clients', 'rust')); + +// Publish the new version. +const releaseArgs = dryRun + ? [] + : ['--no-push', '--no-tag', '--no-confirm', '--execute']; +await $`cargo release ${level} ${releaseArgs}`; + +// Stop here if this is a dry run. +if (dryRun) { + process.exit(0); +} + +// Get the new version. +const newVersion = getCargo(path.join('clients', 'rust')).package.version; + +// Expose the new version to CI if needed. +if (process.env.CI) { + await $`echo "new_version=${newVersion}" >> $GITHUB_OUTPUT`; +} + +// Soft reset the last commit so we can create our own commit and tag. +await $`git reset --soft HEAD~1`; + +// Commit the new version. +await $`git commit -am "Publish Rust client v${newVersion}"`; + +// Tag the new version. +await $`git tag -a rust@v${newVersion} -m "Rust client v${newVersion}"`; diff --git a/scripts/helpers/rust/test.mts b/scripts/helpers/rust/test.mts new file mode 100644 index 0000000..7b81110 --- /dev/null +++ b/scripts/helpers/rust/test.mts @@ -0,0 +1,11 @@ +#!/usr/bin/env zx +import 'zx/globals'; +import { getCrateEnvironmentFromArgs } from '../../crate/index.mts'; +import { getToolchainArgument } from '../utils.mts'; + +const [env, cliArguments] = getCrateEnvironmentFromArgs(); +const testArgs = env.getTestArguments(cliArguments); +const toolchain = getToolchainArgument('test'); + +// Test the interface. +await $`cargo ${toolchain} test --all-features --manifest-path ${env.manifestPath} ${testArgs}`; diff --git a/scripts/helpers/rust/wasm.mts b/scripts/helpers/rust/wasm.mts new file mode 100644 index 0000000..ced20c3 --- /dev/null +++ b/scripts/helpers/rust/wasm.mts @@ -0,0 +1,8 @@ +#!/usr/bin/env zx +import 'zx/globals'; +import { getCrateEnvironmentFromArgs } from '../../crate/index.mts'; + +const [env, cliArguments] = getCrateEnvironmentFromArgs(); +const wasmArgs = env.getWasmArguments(cliArguments); + +await $`wasm-pack build --target nodejs --dev ${env.cratePath} --features bincode ${wasmArgs}`; From 0612c8da517371e4f8df38ef31b4c94732e3e5fc Mon Sep 17 00:00:00 2001 From: febo Date: Sun, 8 Dec 2024 01:39:19 +0000 Subject: [PATCH 09/19] Add rust test script --- scripts/helpers/rust/test.mts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/scripts/helpers/rust/test.mts b/scripts/helpers/rust/test.mts index 7b81110..453ab02 100644 --- a/scripts/helpers/rust/test.mts +++ b/scripts/helpers/rust/test.mts @@ -1,11 +1,18 @@ #!/usr/bin/env zx import 'zx/globals'; import { getCrateEnvironmentFromArgs } from '../../crate/index.mts'; -import { getToolchainArgument } from '../utils.mts'; +import { getToolchainArgument, workingDirectory } from '../utils.mts'; const [env, cliArguments] = getCrateEnvironmentFromArgs(); const testArgs = env.getTestArguments(cliArguments); const toolchain = getToolchainArgument('test'); -// Test the interface. -await $`cargo ${toolchain} test --all-features --manifest-path ${env.manifestPath} ${testArgs}`; +const hasSolfmt = await which('solfmt', { nothrow: true }); +const sbfOutDir = path.join(workingDirectory, 'target', 'deploy'); + +// Run the tests. +if (hasSolfmt) { + await $`SBF_OUT_DIR=${sbfOutDir} cargo ${toolchain} test --all-features --manifest-path ${env.manifestPath} ${testArgs} >&1 | solfmt`; +} else { + await $`SBF_OUT_DIR=${sbfOutDir} cargo ${toolchain} test --all-features --manifest-path ${env.manifestPath} ${testArgs}`; +} From 4a050cbbf1e91f9dd4bf45275ba3b2e48df0029a Mon Sep 17 00:00:00 2001 From: febo Date: Sun, 8 Dec 2024 02:06:23 +0000 Subject: [PATCH 10/19] Update crate type --- interface/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/Cargo.toml b/interface/Cargo.toml index 0ba75a1..f6968cb 100644 --- a/interface/Cargo.toml +++ b/interface/Cargo.toml @@ -56,4 +56,4 @@ frozen-abi = [ serde = ["dep:serde", "dep:serde_derive", "solana-pubkey/serde"] [lib] -crate-type = ["cdylib", "rlib"] +crate-type = ["rlib"] From 63e5131678de2a9faacb05f11dd75961fcce11bc Mon Sep 17 00:00:00 2001 From: febo Date: Sun, 8 Dec 2024 23:43:22 +0000 Subject: [PATCH 11/19] Fix workflow scripts --- .github/workflows/main.yml | 36 +++++++++++------------ .github/workflows/publish-js-client.yml | 14 ++++----- .github/workflows/publish-rust-client.yml | 12 ++++---- package.json | 1 + 4 files changed, 32 insertions(+), 31 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5d58b8a..7205e2d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -17,10 +17,10 @@ jobs: uses: ./.github/actions/setup - name: Format Client JS - run: pnpm clients:js:format + run: pnpm js:format - name: Lint Client JS - run: pnpm clients:js:lint + run: js:lint format_and_lint_client_rust: name: Format & Lint Client Rust @@ -35,16 +35,16 @@ jobs: toolchain: format, lint - name: Format - run: pnpm clients:rust:format + run: pnpm rust:format client - name: Lint / Clippy - run: pnpm zx ./scripts/client/lint-rust-clippy.mjs - - - name: Lint / Features - run: pnpm zx ./scripts/client/lint-rust-features.mjs + run: pnpm zx ./scripts/helpers/rust/lint-clippy.mjs client - name: Lint / Docs - run: pnpm zx ./scripts/client/lint-rust-docs.mjs + run: pnpm zx ./scripts/helpers/rust/lint-docs.mjs client + + - name: Lint / Features + run: pnpm zx ./scripts/helpers/rust/lint-features.mjs client format_and_lint_interface: name: Format & Lint Interface @@ -59,16 +59,16 @@ jobs: toolchain: format, lint - name: Format - run: pnpm interface:format + run: pnpm rust:format interface - name: Lint / Clippy - run: pnpm zx ./scripts/interface/lint-clippy.mjs - - - name: Lint / Features - run: pnpm zx ./scripts/interface/lint-features.mjs + run: pnpm zx ./scripts/helpers/rust/lint-clippy.mjs interface - name: Lint / Docs - run: pnpm zx ./scripts/interface/lint-docs.mjs + run: pnpm zx ./scripts/helpers/rust/lint-docs.mjs interface + + - name: Lint / Features + run: pnpm zx ./scripts/helpers/rust/lint-features.mjs interface wasm_interface: name: Build Interface in WASM @@ -90,7 +90,7 @@ jobs: tool: wasm-pack - name: Build Interface with wasm-pack - run: pnpm interface:wasm + run: pnpm rust:wasm interface test_interface: name: Test Interface @@ -108,7 +108,7 @@ jobs: solana: true - name: Test Interface - run: pnpm interface:test + run: pnpm rusr:test interface generate_clients: name: Check Client Generation @@ -144,7 +144,7 @@ jobs: solana: true - name: Test Client JS - run: pnpm clients:js:test + run: pnpm js:test test_client_rust: name: Test Client Rust @@ -161,4 +161,4 @@ jobs: solana: true - name: Test Client Rust - run: pnpm clients:rust:test + run: pnpm rust:test client diff --git a/.github/workflows/publish-js-client.yml b/.github/workflows/publish-js-client.yml index fcb29c0..67235da 100644 --- a/.github/workflows/publish-js-client.yml +++ b/.github/workflows/publish-js-client.yml @@ -40,14 +40,14 @@ jobs: with: solana: true - - name: Format JS Client - run: pnpm clients:js:format + - name: Format + run: pnpm js:format - - name: Lint JS Client - run: pnpm clients:js:lint + - name: Lint + run: pnpm js:lint - - name: Test JS Client - run: pnpm clients:js:test + - name: Test + run: pnpm js:test publish_js: name: Publish JS client @@ -83,7 +83,7 @@ jobs: - name: Publish JS Client id: publish - run: pnpm clients:js:publish ${{ inputs.level }} ${{ inputs.tag }} + run: pnpm js:publish ${{ inputs.level }} ${{ inputs.tag }} - name: Push Commit and Tag run: git push origin --follow-tags diff --git a/.github/workflows/publish-rust-client.yml b/.github/workflows/publish-rust-client.yml index ee3f09d..55cf743 100644 --- a/.github/workflows/publish-rust-client.yml +++ b/.github/workflows/publish-rust-client.yml @@ -48,14 +48,14 @@ jobs: rustfmt: true solana: true - - name: Format Rust Client - run: pnpm clients:rust:format + - name: Format + run: pnpm rust:format client - - name: Lint Rust Client - run: pnpm clients:rust:lint + - name: Lint + run: pnpm rust:lint client - - name: Test Rust Client - run: pnpm clients:rust:test + - name: Test + run: pnpm rust:test client publish_rust: name: Publish Rust Client diff --git a/package.json b/package.json index 4510633..3592c01 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "rust:lint": "tsx ./scripts/helpers/rust/lint.mts", "rust:publish": "tsx ./scripts/helpers/rust/publish.mts", "rust:test": "tsx ./scripts/helpers/rust/test.mts", + "rust:wasm": "tsx ./scripts/helpers/rust/wasm.mts", "template:upgrade": "tsx ./scripts/helpers/upgrade-template.ts" }, "devDependencies": { From 07ae95a07df950e968a91b4be1fcc69dc0afac49 Mon Sep 17 00:00:00 2001 From: febo Date: Sun, 8 Dec 2024 23:49:15 +0000 Subject: [PATCH 12/19] Use tsx --- .github/workflows/main.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7205e2d..4564cd1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -38,13 +38,13 @@ jobs: run: pnpm rust:format client - name: Lint / Clippy - run: pnpm zx ./scripts/helpers/rust/lint-clippy.mjs client + run: pnpm tsx ./scripts/helpers/rust/lint-clippy.mjs client - name: Lint / Docs - run: pnpm zx ./scripts/helpers/rust/lint-docs.mjs client + run: pnpm tsx ./scripts/helpers/rust/lint-docs.mjs client - name: Lint / Features - run: pnpm zx ./scripts/helpers/rust/lint-features.mjs client + run: pnpm tsx ./scripts/helpers/rust/lint-features.mjs client format_and_lint_interface: name: Format & Lint Interface @@ -62,13 +62,13 @@ jobs: run: pnpm rust:format interface - name: Lint / Clippy - run: pnpm zx ./scripts/helpers/rust/lint-clippy.mjs interface + run: pnpm tsx ./scripts/helpers/rust/lint-clippy.mjs interface - name: Lint / Docs - run: pnpm zx ./scripts/helpers/rust/lint-docs.mjs interface + run: pnpm tsx ./scripts/helpers/rust/lint-docs.mjs interface - name: Lint / Features - run: pnpm zx ./scripts/helpers/rust/lint-features.mjs interface + run: pnpm tsx ./scripts/helpers/rust/lint-features.mjs interface wasm_interface: name: Build Interface in WASM From 15b78e91e0d8441ca5b9072137fc19632acb3293 Mon Sep 17 00:00:00 2001 From: febo Date: Mon, 9 Dec 2024 00:05:35 +0000 Subject: [PATCH 13/19] Add missing toolchain --- .github/workflows/main.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4564cd1..258e56d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -20,7 +20,7 @@ jobs: run: pnpm js:format - name: Lint Client JS - run: js:lint + run: pnpm js:lint format_and_lint_client_rust: name: Format & Lint Client Rust @@ -158,6 +158,7 @@ jobs: uses: ./.github/actions/setup with: cargo-cache-key: cargo-rust-client + toolchain: test solana: true - name: Test Client Rust From a3e0947e311214fc355a4ba298feb14a378d0756 Mon Sep 17 00:00:00 2001 From: febo Date: Mon, 9 Dec 2024 00:10:41 +0000 Subject: [PATCH 14/19] Typo --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 258e56d..2d6b9ae 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -108,7 +108,7 @@ jobs: solana: true - name: Test Interface - run: pnpm rusr:test interface + run: pnpm rust:test interface generate_clients: name: Check Client Generation From 6de27e9ed2d7b8413b87f160afefba7e750efbe5 Mon Sep 17 00:00:00 2001 From: febo Date: Mon, 9 Dec 2024 00:11:22 +0000 Subject: [PATCH 15/19] Add missing crate type --- interface/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/Cargo.toml b/interface/Cargo.toml index f6968cb..0ba75a1 100644 --- a/interface/Cargo.toml +++ b/interface/Cargo.toml @@ -56,4 +56,4 @@ frozen-abi = [ serde = ["dep:serde", "dep:serde_derive", "solana-pubkey/serde"] [lib] -crate-type = ["rlib"] +crate-type = ["cdylib", "rlib"] From d240c5fcece95731e4953a909bc10cc6634883f4 Mon Sep 17 00:00:00 2001 From: febo Date: Tue, 17 Dec 2024 00:52:59 +0000 Subject: [PATCH 16/19] Simplify scripts --- .github/workflows/main.yml | 22 +++++++++--------- .github/workflows/publish-rust-client.yml | 8 +++---- package.json | 28 +++++++++++++++-------- scripts/helpers/rust/format.mts | 17 -------------- scripts/helpers/rust/lint-clippy.mts | 16 ------------- scripts/helpers/rust/lint-docs.mts | 10 -------- scripts/helpers/rust/lint-features.mts | 11 --------- scripts/helpers/rust/lint.mts | 17 -------------- scripts/helpers/rust/test.mts | 18 --------------- scripts/helpers/rust/wasm.mts | 8 ------- scripts/helpers/utils.mts | 23 ++++++++++++++++--- scripts/{helpers => }/js/format.mts | 0 scripts/{helpers => }/js/lint.mts | 0 scripts/{helpers => }/js/publish.mts | 0 scripts/{helpers => }/js/test.mts | 0 scripts/rust/format.mts | 20 ++++++++++++++++ scripts/rust/lint-clippy.mts | 22 ++++++++++++++++++ scripts/rust/lint-docs.mts | 12 ++++++++++ scripts/rust/lint-features.mts | 13 +++++++++++ scripts/rust/lint.mts | 17 ++++++++++++++ scripts/{helpers => }/rust/publish.mts | 16 +++++++++---- scripts/rust/test.mts | 25 ++++++++++++++++++++ scripts/rust/wasm.mts | 11 +++++++++ 23 files changed, 186 insertions(+), 128 deletions(-) delete mode 100644 scripts/helpers/rust/format.mts delete mode 100644 scripts/helpers/rust/lint-clippy.mts delete mode 100644 scripts/helpers/rust/lint-docs.mts delete mode 100644 scripts/helpers/rust/lint-features.mts delete mode 100644 scripts/helpers/rust/lint.mts delete mode 100644 scripts/helpers/rust/test.mts delete mode 100644 scripts/helpers/rust/wasm.mts rename scripts/{helpers => }/js/format.mts (100%) rename scripts/{helpers => }/js/lint.mts (100%) rename scripts/{helpers => }/js/publish.mts (100%) rename scripts/{helpers => }/js/test.mts (100%) create mode 100644 scripts/rust/format.mts create mode 100644 scripts/rust/lint-clippy.mts create mode 100644 scripts/rust/lint-docs.mts create mode 100644 scripts/rust/lint-features.mts create mode 100644 scripts/rust/lint.mts rename scripts/{helpers => }/rust/publish.mts (77%) create mode 100644 scripts/rust/test.mts create mode 100644 scripts/rust/wasm.mts diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2d6b9ae..5eba294 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -35,16 +35,16 @@ jobs: toolchain: format, lint - name: Format - run: pnpm rust:format client + run: pnpm rust:format - name: Lint / Clippy - run: pnpm tsx ./scripts/helpers/rust/lint-clippy.mjs client + run: pnpm rust:lint:clippy - name: Lint / Docs - run: pnpm tsx ./scripts/helpers/rust/lint-docs.mjs client + run: pnpm rust:lint:docs - name: Lint / Features - run: pnpm tsx ./scripts/helpers/rust/lint-features.mjs client + run: pnpm rust:lint:features format_and_lint_interface: name: Format & Lint Interface @@ -59,16 +59,16 @@ jobs: toolchain: format, lint - name: Format - run: pnpm rust:format interface + run: pnpm interface:format - name: Lint / Clippy - run: pnpm tsx ./scripts/helpers/rust/lint-clippy.mjs interface + run: pnpm interface:lint:clippy - name: Lint / Docs - run: pnpm tsx ./scripts/helpers/rust/lint-docs.mjs interface + run: pnpm interface:lint:docs - name: Lint / Features - run: pnpm tsx ./scripts/helpers/rust/lint-features.mjs interface + run: pnpm interface:lint:features wasm_interface: name: Build Interface in WASM @@ -90,7 +90,7 @@ jobs: tool: wasm-pack - name: Build Interface with wasm-pack - run: pnpm rust:wasm interface + run: pnpm interface:wasm test_interface: name: Test Interface @@ -108,7 +108,7 @@ jobs: solana: true - name: Test Interface - run: pnpm rust:test interface + run: pnpm interface:test generate_clients: name: Check Client Generation @@ -162,4 +162,4 @@ jobs: solana: true - name: Test Client Rust - run: pnpm rust:test client + run: pnpm rust:test diff --git a/.github/workflows/publish-rust-client.yml b/.github/workflows/publish-rust-client.yml index 55cf743..491a692 100644 --- a/.github/workflows/publish-rust-client.yml +++ b/.github/workflows/publish-rust-client.yml @@ -49,13 +49,13 @@ jobs: solana: true - name: Format - run: pnpm rust:format client + run: pnpm rust:format - name: Lint - run: pnpm rust:lint client + run: pnpm rust:lint - name: Test - run: pnpm rust:test client + run: pnpm rust:test publish_rust: name: Publish Rust Client @@ -109,7 +109,7 @@ jobs: OPTIONS="" fi - pnpm clients:rust:publish $LEVEL $OPTIONS + pnpm rust:publish $LEVEL $OPTIONS - name: Push Commit and Tag if: github.event.inputs.dry_run != 'true' diff --git a/package.json b/package.json index 3592c01..aa36e66 100644 --- a/package.json +++ b/package.json @@ -8,15 +8,25 @@ "validator:start": "tsx ./scripts/helpers/start-validator.mts", "validator:restart": "pnpm validator:start --restart", "validator:stop": "tsx ./scripts/helpers/stop-validator.mts", - "js:format": "tsx ./scripts/helpers/js/format.mts", - "js:lint": "tsx ./scripts/helpers/js/lint.mts", - "js:publish": "tsx ./scripts/helpers/js/publish.mts", - "js:test": "tsx ./scripts/helpers/js/test.mts", - "rust:format": "tsx ./scripts/helpers/rust/format.mts", - "rust:lint": "tsx ./scripts/helpers/rust/lint.mts", - "rust:publish": "tsx ./scripts/helpers/rust/publish.mts", - "rust:test": "tsx ./scripts/helpers/rust/test.mts", - "rust:wasm": "tsx ./scripts/helpers/rust/wasm.mts", + "js:format": "tsx ./scripts/js/format.mts", + "js:lint": "tsx ./scripts/js/lint.mts", + "js:publish": "tsx ./scripts/js/publish.mts", + "js:test": "tsx ./scripts/js/test.mts", + "rust:format": "tsx ./scripts/rust/format.mts clients/rust", + "rust:lint": "tsx ./scripts/rust/lint.mts clients/rust", + "rust:lint:clippy": "tsx ./scripts/rust/lint-clippy.mts clients/rust", + "rust:lint:docs": "tsx ./scripts/rust/lint-docs.mts clients/rust", + "rust:lint:features": "tsx ./scripts/rust/lint-features.mts clients/rust", + "rust:publish": "tsx ./scripts/rust/publish.mts clients/rust", + "rust:test": "tsx ./scripts/rust/test.mts clients/rust", + "interface:format": "tsx ./scripts/rust/format.mts interface", + "interface:lint": "tsx ./scripts/rust/lint.mts interface", + "interface:lint:clippy": "tsx ./scripts/rust/lint-clippy.mts interface", + "interface:lint:docs": "tsx ./scripts/rust/lint-docs.mts interface", + "interface:lint:features": "tsx ./scripts/rust/lint-features.mts interface", + "interface:publish": "tsx ./scripts/rust/publish.mts interface", + "interface:test": "tsx ./scripts/rust/test.mts interface", + "interface:wasm": "tsx ./scripts/rust/wasm.mts interface", "template:upgrade": "tsx ./scripts/helpers/upgrade-template.ts" }, "devDependencies": { diff --git a/scripts/helpers/rust/format.mts b/scripts/helpers/rust/format.mts deleted file mode 100644 index a9655ba..0000000 --- a/scripts/helpers/rust/format.mts +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env zx -import 'zx/globals'; -import { getCrateEnvironmentFromArgs } from '../../crate/index.mts'; -import { - getToolchainArgument, - partitionArguments, - popArgument, -} from '../utils.mts'; - -const [env, cliArguments] = getCrateEnvironmentFromArgs(); -const args = env.getFormatArguments(cliArguments); - -const fix = popArgument(args, '--fix'); -const [cargoArgs, fmtArgs] = partitionArguments(args, '--'); -const toolchain = getToolchainArgument('format'); - -await $`cargo ${toolchain} fmt --manifest-path ${env.manifestPath} ${cargoArgs} -- ${fix ? '' : '--check'} ${fmtArgs}`; diff --git a/scripts/helpers/rust/lint-clippy.mts b/scripts/helpers/rust/lint-clippy.mts deleted file mode 100644 index 9c0448b..0000000 --- a/scripts/helpers/rust/lint-clippy.mts +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env zx -import 'zx/globals'; -import { getCrateEnvironmentFromArgs } from '../../crate/index.mts'; -import { getToolchainArgument, popArgument } from '../utils.mts'; - -const [env, cliArguments] = getCrateEnvironmentFromArgs(); -const clippyArgs = env.getLintClippyArguments(cliArguments); -const fix = popArgument(clippyArgs, '--fix'); - -// Note: need to use nightly clippy as frozen-abi proc-macro generates -// a lot of code (frozen-abi is enabled only under nightly due to the -// use of unstable rust feature). Likewise, frozen-abi(-macro) crates' -// unit tests are only compiled under nightly. -const toolchain = getToolchainArgument('lint'); - -await $`cargo ${toolchain} clippy --manifest-path ${env.manifestPath} ${fix ? '--fix' : ''} ${clippyArgs}`; diff --git a/scripts/helpers/rust/lint-docs.mts b/scripts/helpers/rust/lint-docs.mts deleted file mode 100644 index 612acc5..0000000 --- a/scripts/helpers/rust/lint-docs.mts +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env zx -import 'zx/globals'; -import { getCrateEnvironmentFromArgs } from '../../crate/index.mts'; -import { getToolchainArgument } from '../utils.mts'; - -const [env, cliArguments] = getCrateEnvironmentFromArgs(); -const docArgs = env.getLintDocsArguments(cliArguments); -const toolchain = getToolchainArgument('lint'); - -await $`RUSTDOCFLAGS="--cfg docsrs -D warnings" cargo ${toolchain} doc --manifest-path ${env.manifestPath} --all-features --no-deps ${docArgs}`; diff --git a/scripts/helpers/rust/lint-features.mts b/scripts/helpers/rust/lint-features.mts deleted file mode 100644 index 69bdd79..0000000 --- a/scripts/helpers/rust/lint-features.mts +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env zx -import 'zx/globals'; -import { getCrateEnvironmentFromArgs } from '../../crate/index.mts'; -import { getToolchainArgument } from '../utils.mts'; - -const [env, cliArguments] = getCrateEnvironmentFromArgs(); -const featuresArgs = env.getLintDocsArguments(cliArguments); -const toolchain = getToolchainArgument('lint'); - -// Check feature powerset. -await $`cargo ${toolchain} hack check --manifest-path ${env.manifestPath} --feature-powerset --all-targets ${featuresArgs}`; diff --git a/scripts/helpers/rust/lint.mts b/scripts/helpers/rust/lint.mts deleted file mode 100644 index f955173..0000000 --- a/scripts/helpers/rust/lint.mts +++ /dev/null @@ -1,17 +0,0 @@ -// Script to lint a crate. -// -// This script runs the following sub-scripts: -// - lint-clippy.mjs -// - lint-docs.mjs -// - lint-features.mjs - -import { workingDirectory } from '../utils.mts'; - -const scripts = path.join(workingDirectory, 'scripts', 'helpers', 'rust'); - -// clippy -await $`tsx ${path.join(scripts, 'lint-clippy.mjs')} ${process.argv.slice(2)}`; -// rustdoc -await $`tsx ${path.join(scripts, 'lint-docs.mjs')} ${process.argv.slice(2)}`; -// features -await $`tsx ${path.join(scripts, 'lint-features.mjs')} ${process.argv.slice(2)}`; diff --git a/scripts/helpers/rust/test.mts b/scripts/helpers/rust/test.mts deleted file mode 100644 index 453ab02..0000000 --- a/scripts/helpers/rust/test.mts +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env zx -import 'zx/globals'; -import { getCrateEnvironmentFromArgs } from '../../crate/index.mts'; -import { getToolchainArgument, workingDirectory } from '../utils.mts'; - -const [env, cliArguments] = getCrateEnvironmentFromArgs(); -const testArgs = env.getTestArguments(cliArguments); -const toolchain = getToolchainArgument('test'); - -const hasSolfmt = await which('solfmt', { nothrow: true }); -const sbfOutDir = path.join(workingDirectory, 'target', 'deploy'); - -// Run the tests. -if (hasSolfmt) { - await $`SBF_OUT_DIR=${sbfOutDir} cargo ${toolchain} test --all-features --manifest-path ${env.manifestPath} ${testArgs} >&1 | solfmt`; -} else { - await $`SBF_OUT_DIR=${sbfOutDir} cargo ${toolchain} test --all-features --manifest-path ${env.manifestPath} ${testArgs}`; -} diff --git a/scripts/helpers/rust/wasm.mts b/scripts/helpers/rust/wasm.mts deleted file mode 100644 index ced20c3..0000000 --- a/scripts/helpers/rust/wasm.mts +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env zx -import 'zx/globals'; -import { getCrateEnvironmentFromArgs } from '../../crate/index.mts'; - -const [env, cliArguments] = getCrateEnvironmentFromArgs(); -const wasmArgs = env.getWasmArguments(cliArguments); - -await $`wasm-pack build --target nodejs --dev ${env.cratePath} --features bincode ${wasmArgs}`; diff --git a/scripts/helpers/utils.mts b/scripts/helpers/utils.mts index 1d4e6a9..5a9c132 100644 --- a/scripts/helpers/utils.mts +++ b/scripts/helpers/utils.mts @@ -1,5 +1,5 @@ import 'zx/globals'; -import { parse as parseToml } from '@iarna/toml'; +import { JsonMap, parse as parseToml } from '@iarna/toml'; process.env.FORCE_COLOR = '3'; process.env.CARGO_TERM_COLOR = 'always'; @@ -70,7 +70,7 @@ export function getAllProgramFolders(): string[] { ); } -export function getCargo(folder?: string) { +export function getCargo(folder?: string): JsonMap { return parseToml( fs.readFileSync( path.join(workingDirectory, folder ? folder : '.', 'Cargo.toml'), @@ -98,7 +98,7 @@ export function getToolchainArgument(operation): string { } export function cliArguments(): string[] { - return process.argv.slice(3); + return process.argv.slice(2); } export function popArgument(args: string[], arg: string) { @@ -127,3 +127,20 @@ export async function getInstalledSolanaVersion(): Promise { return ''; } } + +export function parseCliArguments(): { manifestPath: string; args: string[] } { + // Command-line arguments. + const args = cliArguments(); + // Extract the relative crate directory from the command-line arguments. This + // is the only required argument. + const relativePath = args.shift(); + + if (!relativePath) { + throw new Error('Missing relative manifest path'); + } + + return { + manifestPath: path.join(workingDirectory, relativePath, 'Cargo.toml'), + args, + }; +} diff --git a/scripts/helpers/js/format.mts b/scripts/js/format.mts similarity index 100% rename from scripts/helpers/js/format.mts rename to scripts/js/format.mts diff --git a/scripts/helpers/js/lint.mts b/scripts/js/lint.mts similarity index 100% rename from scripts/helpers/js/lint.mts rename to scripts/js/lint.mts diff --git a/scripts/helpers/js/publish.mts b/scripts/js/publish.mts similarity index 100% rename from scripts/helpers/js/publish.mts rename to scripts/js/publish.mts diff --git a/scripts/helpers/js/test.mts b/scripts/js/test.mts similarity index 100% rename from scripts/helpers/js/test.mts rename to scripts/js/test.mts diff --git a/scripts/rust/format.mts b/scripts/rust/format.mts new file mode 100644 index 0000000..4863d42 --- /dev/null +++ b/scripts/rust/format.mts @@ -0,0 +1,20 @@ +#!/usr/bin/env zx +import 'zx/globals'; +import { + getToolchainArgument, + parseCliArguments, + partitionArguments, + popArgument, +} from '../helpers/utils.mts'; + +// Extract the crate directory from the command-line arguments. +const { manifestPath, args } = parseCliArguments(); +// Configure additional arguments here, e.g.: +// ['--arg1', '--arg2', ...args] +const formatArgs = args; + +const fix = popArgument(args, '--fix'); +const [cargoArgs, fmtArgs] = partitionArguments(formatArgs, '--'); +const toolchain = getToolchainArgument('format'); + +await $`cargo ${toolchain} fmt --manifest-path ${manifestPath} ${cargoArgs} -- ${fix ? '' : '--check'} ${fmtArgs}`; diff --git a/scripts/rust/lint-clippy.mts b/scripts/rust/lint-clippy.mts new file mode 100644 index 0000000..377cb79 --- /dev/null +++ b/scripts/rust/lint-clippy.mts @@ -0,0 +1,22 @@ +#!/usr/bin/env zx +import 'zx/globals'; +import { + getToolchainArgument, + parseCliArguments, + popArgument, +} from '../helpers/utils.mts'; + +// Extract the crate directory from the command-line arguments. +const { manifestPath, args } = parseCliArguments(); +// Configure additional arguments here, e.g.: +// ['--arg1', '--arg2', ...args] +const clippyArgs = args; +// Note: need to use nightly clippy as frozen-abi proc-macro generates +// a lot of code (frozen-abi is enabled only under nightly due to the +// use of unstable rust feature). Likewise, frozen-abi(-macro) crates' +// unit tests are only compiled under nightly. +const toolchain = getToolchainArgument('lint'); +// Check if the `--fix` argument is present. +const fix = popArgument(clippyArgs, '--fix'); + +await $`cargo ${toolchain} clippy --manifest-path ${manifestPath} ${fix ? '--fix' : ''} ${clippyArgs}`; diff --git a/scripts/rust/lint-docs.mts b/scripts/rust/lint-docs.mts new file mode 100644 index 0000000..867e751 --- /dev/null +++ b/scripts/rust/lint-docs.mts @@ -0,0 +1,12 @@ +#!/usr/bin/env zx +import 'zx/globals'; +import { getToolchainArgument, parseCliArguments } from '../helpers/utils.mts'; + +// Extract the crate directory from the command-line arguments. +const { manifestPath, args } = parseCliArguments(); +// Configure additional arguments here, e.g.: +// ['--arg1', '--arg2', ...args] +const docArgs = args; +const toolchain = getToolchainArgument('lint'); + +await $`RUSTDOCFLAGS="--cfg docsrs -D warnings" cargo ${toolchain} doc --manifest-path ${manifestPath} --all-features --no-deps ${docArgs}`; diff --git a/scripts/rust/lint-features.mts b/scripts/rust/lint-features.mts new file mode 100644 index 0000000..9ebbe4d --- /dev/null +++ b/scripts/rust/lint-features.mts @@ -0,0 +1,13 @@ +#!/usr/bin/env zx +import 'zx/globals'; +import { getToolchainArgument, parseCliArguments } from '../helpers/utils.mts'; + +// Extract the crate directory from the command-line arguments. +const { manifestPath, args } = parseCliArguments(); +// Configure additional arguments here, e.g.: +// ['--arg1', '--arg2', ...args] +const featuresArgs = ['--exclude-features', 'frozen-abi', ...args]; +const toolchain = getToolchainArgument('lint'); + +// Check feature powerset. +await $`cargo ${toolchain} hack check --manifest-path ${manifestPath} --feature-powerset --all-targets ${featuresArgs}`; diff --git a/scripts/rust/lint.mts b/scripts/rust/lint.mts new file mode 100644 index 0000000..8bfe272 --- /dev/null +++ b/scripts/rust/lint.mts @@ -0,0 +1,17 @@ +// Script to lint a crate. +// +// This script runs the following sub-scripts: +// - lint-clippy.mjs +// - lint-docs.mjs +// - lint-features.mjs + +import { cliArguments, workingDirectory } from '../helpers/utils.mts'; + +const scripts = path.join(workingDirectory, 'scripts', 'rust'); + +// clippy +await $`tsx ${path.join(scripts, 'lint-clippy.mjs')} ${cliArguments()}`; +// rustdoc +await $`tsx ${path.join(scripts, 'lint-docs.mjs')} ${cliArguments()}`; +// features +await $`tsx ${path.join(scripts, 'lint-features.mjs')} ${cliArguments()}`; diff --git a/scripts/helpers/rust/publish.mts b/scripts/rust/publish.mts similarity index 77% rename from scripts/helpers/rust/publish.mts rename to scripts/rust/publish.mts index f976821..5bef639 100644 --- a/scripts/helpers/rust/publish.mts +++ b/scripts/rust/publish.mts @@ -1,15 +1,23 @@ #!/usr/bin/env zx import 'zx/globals'; -import { cliArguments, getCargo, workingDirectory } from '../utils'; +import { + cliArguments, + getCargo, + parseCliArguments, + workingDirectory, +} from '../helpers/utils.mts'; + +// Extract the crate directory from the command-line arguments. +const { manifestPath, args } = parseCliArguments(); const dryRun = argv['dry-run'] ?? false; -const [level] = cliArguments(); +const [level] = args; if (!level) { throw new Error('A version level — e.g. "path" — must be provided.'); } // Go to the client directory and install the dependencies. -cd(path.join(workingDirectory, 'clients', 'rust')); +cd(path.dirname(manifestPath)); // Publish the new version. const releaseArgs = dryRun @@ -23,7 +31,7 @@ if (dryRun) { } // Get the new version. -const newVersion = getCargo(path.join('clients', 'rust')).package.version; +const newVersion = getCargo(path.join('clients', 'rust')).package['version']; // Expose the new version to CI if needed. if (process.env.CI) { diff --git a/scripts/rust/test.mts b/scripts/rust/test.mts new file mode 100644 index 0000000..d3ad191 --- /dev/null +++ b/scripts/rust/test.mts @@ -0,0 +1,25 @@ +#!/usr/bin/env zx +import 'zx/globals'; +import { + getToolchainArgument, + parseCliArguments, + workingDirectory, +} from '../helpers/utils.mts'; + +// Extract the crate directory from the command-line arguments. +const { manifestPath, args } = parseCliArguments(); +// Configure additional arguments here, e.g.: +// ['--arg1', '--arg2', ...args] +const testArgs = args; + +const toolchain = getToolchainArgument('test'); + +const hasSolfmt = await which('solfmt', { nothrow: true }); +const sbfOutDir = path.join(workingDirectory, 'target', 'deploy'); + +// Run the tests. +if (hasSolfmt) { + await $`SBF_OUT_DIR=${sbfOutDir} cargo ${toolchain} test --all-features --manifest-path ${manifestPath} ${testArgs} >&1 | solfmt`; +} else { + await $`SBF_OUT_DIR=${sbfOutDir} cargo ${toolchain} test --all-features --manifest-path ${manifestPath} ${testArgs}`; +} diff --git a/scripts/rust/wasm.mts b/scripts/rust/wasm.mts new file mode 100644 index 0000000..6d48b9b --- /dev/null +++ b/scripts/rust/wasm.mts @@ -0,0 +1,11 @@ +#!/usr/bin/env zx +import 'zx/globals'; +import { parseCliArguments } from '../helpers/utils.mts'; + +// Extract the crate directory from the command-line arguments. +const { manifestPath, args } = parseCliArguments(); +// Configure additional arguments here, e.g.: +// ['--arg1', '--arg2', ...args] +const wasmArgs = args; + +await $`wasm-pack build --target nodejs --dev ${path.dirname(manifestPath)} --features bincode ${wasmArgs}`; From 8c91bb6cd0ca2fc503efd1a016354798106a52fc Mon Sep 17 00:00:00 2001 From: febo Date: Tue, 17 Dec 2024 00:56:17 +0000 Subject: [PATCH 17/19] Fix imports --- scripts/js/format.mts | 2 +- scripts/js/lint.mts | 2 +- scripts/js/publish.mts | 2 +- scripts/js/test.mts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/js/format.mts b/scripts/js/format.mts index a9056d2..5557740 100644 --- a/scripts/js/format.mts +++ b/scripts/js/format.mts @@ -1,6 +1,6 @@ #!/usr/bin/env zx import 'zx/globals'; -import { cliArguments, workingDirectory } from '../utils.mts'; +import { cliArguments, workingDirectory } from '../helpers/utils.mts'; // Format the client using Prettier. cd(path.join(workingDirectory, 'clients', 'js')); diff --git a/scripts/js/lint.mts b/scripts/js/lint.mts index fb8f928..9c2c09c 100644 --- a/scripts/js/lint.mts +++ b/scripts/js/lint.mts @@ -1,6 +1,6 @@ #!/usr/bin/env zx import 'zx/globals'; -import { cliArguments, workingDirectory } from '../utils.mts'; +import { cliArguments, workingDirectory } from '../helpers/utils.mts'; // Check the client using ESLint. cd(path.join(workingDirectory, 'clients', 'js')); diff --git a/scripts/js/publish.mts b/scripts/js/publish.mts index 262bc30..97bfecc 100644 --- a/scripts/js/publish.mts +++ b/scripts/js/publish.mts @@ -1,6 +1,6 @@ #!/usr/bin/env zx import 'zx/globals'; -import { cliArguments, workingDirectory } from '../utils.mts'; +import { cliArguments, workingDirectory } from '../helpers/utils.mts'; const [level, tag = 'latest'] = cliArguments(); if (!level) { diff --git a/scripts/js/test.mts b/scripts/js/test.mts index bb61419..c0ba4a5 100644 --- a/scripts/js/test.mts +++ b/scripts/js/test.mts @@ -1,6 +1,6 @@ #!/usr/bin/env zx import 'zx/globals'; -import { cliArguments, workingDirectory } from '../utils.mts'; +import { cliArguments, workingDirectory } from '../helpers/utils.mts'; // Start the local validator, or restart it if it is already running. await $`pnpm validator:restart`; From a8d43d235612dadef4af12d096742041b3951197 Mon Sep 17 00:00:00 2001 From: febo Date: Tue, 17 Dec 2024 02:01:32 +0000 Subject: [PATCH 18/19] Remove unused --- scripts/crate/client.mts | 25 ----------------- scripts/crate/index.mts | 54 ------------------------------------- scripts/crate/interface.mts | 38 -------------------------- scripts/crate/program.mts | 25 ----------------- 4 files changed, 142 deletions(-) delete mode 100644 scripts/crate/client.mts delete mode 100644 scripts/crate/index.mts delete mode 100644 scripts/crate/interface.mts delete mode 100644 scripts/crate/program.mts diff --git a/scripts/crate/client.mts b/scripts/crate/client.mts deleted file mode 100644 index 33323ba..0000000 --- a/scripts/crate/client.mts +++ /dev/null @@ -1,25 +0,0 @@ -import { workingDirectory } from '../helpers/utils.mjs'; -import { getDefaultCrateEnvironment, type CrateEnvironment } from './index.mts'; - -export function getClientCrateEnvironment(): CrateEnvironment { - return { - ...getDefaultCrateEnvironment(), - cratePath: path.join(workingDirectory, 'clients', 'rust'), - manifestPath: path.join(workingDirectory, 'clients', 'rust', 'Cargo.toml'), - getLintClippyArguments, - getLintDocsArguments, - getLintFeaturesArguments, - }; -} - -function getLintClippyArguments(cliArguments: string[]): string[] { - return cliArguments; // TODO -} - -function getLintDocsArguments(cliArguments: string[]): string[] { - return cliArguments; // TODO -} - -function getLintFeaturesArguments(cliArguments: string[]): string[] { - return cliArguments; // TODO -} diff --git a/scripts/crate/index.mts b/scripts/crate/index.mts deleted file mode 100644 index f88eed0..0000000 --- a/scripts/crate/index.mts +++ /dev/null @@ -1,54 +0,0 @@ -import { cliArguments } from '../helpers/utils.mts'; -import { getClientCrateEnvironment } from './client.mts'; -import { getInterfaceCrateEnvironment } from './interface.mts'; -import { getProgramCrateEnvironment } from './program.mts'; - -export type CrateEnvironment = { - getFormatArguments: (cliArguments: string[]) => string[]; - getLintClippyArguments: (cliArguments: string[]) => string[]; - getLintDocsArguments: (cliArguments: string[]) => string[]; - getLintFeaturesArguments: (cliArguments: string[]) => string[]; - getPublishArguments: (cliArguments: string[]) => string[]; - getTestArguments: (cliArguments: string[]) => string[]; - getWasmArguments: (cliArguments: string[]) => string[]; - cratePath: string; - manifestPath: string; -}; - -type Crate = 'interface' | 'client' | 'program'; - -export function getCrateEnvironmentFromArgs(): [CrateEnvironment, string[]] { - const crate = process.argv[2] as Crate; - return [getCrateEnvironment(crate), cliArguments().slice(1)]; -} - -export function getCrateEnvironment(crate: Crate): CrateEnvironment { - switch (crate) { - case 'client': - return getClientCrateEnvironment(); - case 'interface': - return getInterfaceCrateEnvironment(); - case 'program': - return getProgramCrateEnvironment(); - default: - throw new Error(`Unknown crate: ${crate}`); - } -} - -const getCliArguments = (args: string[]): string[] => { - return args; -}; - -export function getDefaultCrateEnvironment(): CrateEnvironment { - return { - getFormatArguments: getCliArguments, - getLintClippyArguments: getCliArguments, - getLintDocsArguments: getCliArguments, - getLintFeaturesArguments: getCliArguments, - getPublishArguments: getCliArguments, - getTestArguments: getCliArguments, - getWasmArguments: getCliArguments, - cratePath: '', - manifestPath: '', - } as CrateEnvironment; -} diff --git a/scripts/crate/interface.mts b/scripts/crate/interface.mts deleted file mode 100644 index 630a7c7..0000000 --- a/scripts/crate/interface.mts +++ /dev/null @@ -1,38 +0,0 @@ -import { workingDirectory } from '../helpers/utils.mjs'; -import { getDefaultCrateEnvironment, type CrateEnvironment } from './index.mts'; - -export function getInterfaceCrateEnvironment(): CrateEnvironment { - return { - ...getDefaultCrateEnvironment(), - cratePath: path.join(workingDirectory, 'interface'), - manifestPath: path.join(workingDirectory, 'interface', 'Cargo.toml'), - getLintClippyArguments, - getLintDocsArguments, - getLintFeaturesArguments, - }; -} - -function getLintClippyArguments(cliArguments: string[]): string[] { - const args = ['--all-targets', '--all-features', ...cliArguments]; - // Check whether a '--' was already used. - if (args.indexOf('--') === -1) { - args.push('--'); - } - // Add additional arguments. - args.push( - '--deny=warnings', - '--deny=clippy::default_trait_access', - '--deny=clippy::arithmetic_side_effects', - '--deny=clippy::manual_let_else', - '--deny=clippy::used_underscore_binding' - ); - return args; -} - -function getLintDocsArguments(cliArguments: string[]): string[] { - return cliArguments; // TODO -} - -function getLintFeaturesArguments(cliArguments: string[]): string[] { - return ['--exclude-features', 'frozen-abi', ...cliArguments]; -} diff --git a/scripts/crate/program.mts b/scripts/crate/program.mts deleted file mode 100644 index c2f5fc9..0000000 --- a/scripts/crate/program.mts +++ /dev/null @@ -1,25 +0,0 @@ -import { workingDirectory } from '../helpers/utils.mjs'; -import { getDefaultCrateEnvironment, type CrateEnvironment } from './index.mts'; - -export function getProgramCrateEnvironment(): CrateEnvironment { - return { - ...getDefaultCrateEnvironment(), - cratePath: path.join(workingDirectory, 'program'), - manifestPath: path.join(workingDirectory, 'program', 'Cargo.toml'), - getLintClippyArguments, - getLintDocsArguments, - getLintFeaturesArguments, - }; -} - -function getLintClippyArguments(cliArguments: string[]): string[] { - return cliArguments; // TODO -} - -function getLintDocsArguments(cliArguments: string[]): string[] { - return cliArguments; // TODO -} - -function getLintFeaturesArguments(cliArguments: string[]): string[] { - return cliArguments; // TODO -} From c72389533ed76be2ba14fc3ac936506d1110caaa Mon Sep 17 00:00:00 2001 From: febo Date: Tue, 17 Dec 2024 09:23:59 +0000 Subject: [PATCH 19/19] Fix crate name --- scripts/rust/publish.mts | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/scripts/rust/publish.mts b/scripts/rust/publish.mts index 5bef639..3f669bf 100644 --- a/scripts/rust/publish.mts +++ b/scripts/rust/publish.mts @@ -1,11 +1,6 @@ #!/usr/bin/env zx import 'zx/globals'; -import { - cliArguments, - getCargo, - parseCliArguments, - workingDirectory, -} from '../helpers/utils.mts'; +import { getCargo, parseCliArguments } from '../helpers/utils.mts'; // Extract the crate directory from the command-line arguments. const { manifestPath, args } = parseCliArguments(); @@ -30,8 +25,10 @@ if (dryRun) { process.exit(0); } -// Get the new version. -const newVersion = getCargo(path.join('clients', 'rust')).package['version']; +// Get the crate information. +const toml = getCargo(path.dirname(manifestPath)); +const crateName = toml.package['name']; +const newVersion = toml.package['version']; // Expose the new version to CI if needed. if (process.env.CI) { @@ -42,7 +39,7 @@ if (process.env.CI) { await $`git reset --soft HEAD~1`; // Commit the new version. -await $`git commit -am "Publish Rust client v${newVersion}"`; +await $`git commit -am "Publish ${crateName} v${newVersion}"`; // Tag the new version. -await $`git tag -a rust@v${newVersion} -m "Rust client v${newVersion}"`; +await $`git tag -a ${crateName}@v${newVersion} -m "${crateName} v${newVersion}"`;