diff --git a/.changeset/friendly-deers-glow.md b/.changeset/friendly-deers-glow.md new file mode 100644 index 00000000000..da9fcc9d217 --- /dev/null +++ b/.changeset/friendly-deers-glow.md @@ -0,0 +1,9 @@ +--- +"@fuel-ts/account": patch +"create-fuels": patch +"fuels": minor +"@fuel-ts/utils": minor +"@fuel-ts/versions": patch +--- + +chore!: remove built-in binaries for `forc` and `fuel-core` \ No newline at end of file diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index c811e7b2d31..d8a91401583 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -39,8 +39,8 @@ jobs: run: | pnpm changeset version echo "RELEASE_VERSION=v$(sed -nE 's/^\s*"version": "(.*?)",$/\1/p' packages/fuels/package.json)" >> $GITHUB_ENV - echo "FUEL_CORE_VERSION=$(cat ./packages/fuel-core/VERSION)" >> $GITHUB_ENV - echo "FORC_VERSION=$(cat ./packages/forc/VERSION)" >> $GITHUB_ENV + echo "FUEL_CORE_VERSION=$(cat ./internal/fuel-core/VERSION)" >> $GITHUB_ENV + echo "FORC_VERSION=$(cat ./internal/forc/VERSION)" >> $GITHUB_ENV git reset --hard env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.knip.json b/.knip.json index 9e0ca4f5953..4aa56873de3 100644 --- a/.knip.json +++ b/.knip.json @@ -8,6 +8,8 @@ ], "ignoreDependencies": [ "@fuel-ts/*", + "@internal/fuel-core", + "@internal/forc", "@types/jest", "@types/rimraf", "@graphql-codegen*", diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b2caa274843..47906608a05 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -224,7 +224,7 @@ After this you should run tests and fix any incompatibilities. # Updating Fuel Core version -Manually edit the `packages/fuel-core/VERSION` file, add the right version, and then: +Manually edit the `internal/fuel-core/VERSION` file, add the right version, and then: ```sh pnpm install # will download new binaries diff --git a/README.md b/README.md index 8d04b7fcce5..f32381757d6 100644 --- a/README.md +++ b/README.md @@ -71,8 +71,6 @@ Commands: deploy [options] Deploy contracts to the Fuel network typegen [options] Generate Typescript from Sway ABI JSON files versions Check for version incompatibilities - core Wrapper around Fuel Core binary - forc Wrapper around Forc binary help [command] Display help for command ``` diff --git a/apps/create-fuels-counter-guide/package.json b/apps/create-fuels-counter-guide/package.json index e9257e04c5e..01a1240798e 100644 --- a/apps/create-fuels-counter-guide/package.json +++ b/apps/create-fuels-counter-guide/package.json @@ -33,9 +33,5 @@ "postcss": "^8", "tailwindcss": "^3.3.0", "typescript": "^5" - }, - "trustedDependencies": [ - "@fuel-ts/fuel-core", - "@fuel-ts/forc" - ] + } } diff --git a/apps/demo-fuels/fuels.config.explicit-built-in.ts b/apps/demo-fuels/fuels.config.explicit-built-in.ts deleted file mode 100644 index 8c0cc48b73e..00000000000 --- a/apps/demo-fuels/fuels.config.explicit-built-in.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { createConfig } from 'fuels'; - -// #region config-built-in -export default createConfig({ - workspace: './sway-programs', - output: './src/sway-programs-api', - useBuiltinForc: true, - useBuiltinFuelCore: true, -}); -// #endregion config-built-in diff --git a/apps/demo-fuels/fuels.config.explicit-system.ts b/apps/demo-fuels/fuels.config.explicit-system.ts deleted file mode 100644 index 12294eeadf5..00000000000 --- a/apps/demo-fuels/fuels.config.explicit-system.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { createConfig } from 'fuels'; - -// #region config-system -export default createConfig({ - workspace: './sway-programs', - output: './src/sway-programs-api', - useBuiltinForc: false, - useBuiltinFuelCore: false, -}); -// #endregion config-system diff --git a/apps/demo-fuels/fuels.config.full.ts b/apps/demo-fuels/fuels.config.full.ts index 8b9dddd3d73..9dadb0fcef8 100644 --- a/apps/demo-fuels/fuels.config.full.ts +++ b/apps/demo-fuels/fuels.config.full.ts @@ -1,6 +1,6 @@ /* eslint-disable no-console */ import { createConfig } from 'fuels'; -import type { CommandEvent, ContractDeployOptions, FuelsConfig } from 'fuels/src/cli/types'; +import type { CommandEvent, ContractDeployOptions, FuelsConfig } from 'fuels'; const MY_FIRST_DEPLOYED_CONTRACT_NAME = ''; @@ -96,15 +96,15 @@ export default createConfig({ }, // #endregion onFailure - // #region useBuiltInForc - // Default: undefined - useBuiltinForc: false, - // #endregion useBuiltInForc + // #region forcPath + // Default: 'forc', + forcPath: '~/.fuelup/bin/forc', + // #endregion forcPath - // #region useBuiltInFuelCore - // Default: undefined - useBuiltinFuelCore: false, - // #endregion useBuiltInFuelCore + // #region fuelCorePath + // Default: 'fuel-core' + fuelCorePath: '~/.fuelup/bin/fuel-core', + // #endregion fuelCorePath }); export const simpleDeployConfig = createConfig({ diff --git a/apps/demo-fuels/fuels.config.minimal.ts b/apps/demo-fuels/fuels.config.minimal.ts new file mode 100644 index 00000000000..7d8d6a04635 --- /dev/null +++ b/apps/demo-fuels/fuels.config.minimal.ts @@ -0,0 +1,13 @@ +// #region config +import { createConfig } from 'fuels'; + +export default createConfig({ + workspace: './sway-programs', // forc workspace + output: './src/sway-programs-api', +}); +// #endregion config + +/** + * Check the docs: + * https://docs.fuel.network/docs/fuels-ts/fuels-cli/config-file/ + */ diff --git a/apps/demo-fuels/fuels.config.ts b/apps/demo-fuels/fuels.config.ts index 8b17236adde..81f8a998759 100644 --- a/apps/demo-fuels/fuels.config.ts +++ b/apps/demo-fuels/fuels.config.ts @@ -1,13 +1,13 @@ -// #region config import { createConfig } from 'fuels'; export default createConfig({ workspace: './sway-programs', // forc workspace output: './src/sway-programs-api', + forcPath: 'fuels-forc', + fuelCorePath: 'fuels-core', }); -// #endregion config /** * Check the docs: - * https://fuellabs.github.io/fuels-ts/guide/fuels/config-file + * https://docs.fuel.network/docs/fuels-ts/fuels-cli/config-file/ */ diff --git a/apps/demo-typegen/package.json b/apps/demo-typegen/package.json index 489629f5a07..0869ed7dc9a 100644 --- a/apps/demo-typegen/package.json +++ b/apps/demo-typegen/package.json @@ -21,7 +21,7 @@ "devDependencies": { "@fuel-ts/account": "workspace:*", "@fuel-ts/errors": "workspace:*", - "@fuel-ts/forc": "workspace:*" + "@internal/forc": "workspace:*" }, "version": null } diff --git a/apps/docs-snippets/fuels.config.ts b/apps/docs-snippets/fuels.config.ts index fcc0abef737..016d6327b74 100644 --- a/apps/docs-snippets/fuels.config.ts +++ b/apps/docs-snippets/fuels.config.ts @@ -4,4 +4,6 @@ export default createConfig({ workspace: './test/fixtures/forc-projects', output: './test/typegen', forcBuildFlags: ['--release'], + forcPath: 'fuels-forc', + fuelCorePath: 'fuels-core', }); diff --git a/apps/docs/.vitepress/config.ts b/apps/docs/.vitepress/config.ts index 5378ac6baf7..f5103710a36 100644 --- a/apps/docs/.vitepress/config.ts +++ b/apps/docs/.vitepress/config.ts @@ -98,10 +98,6 @@ export default defineConfig({ text: 'Commands', link: '/guide/fuels-cli/commands', }, - { - text: 'Binaries', - link: '/guide/fuels-cli/binaries', - }, { text: 'ABI Typegen', link: '/guide/fuels-cli/abi-typegen', diff --git a/apps/docs/src/guide/fuels-cli/binaries.md b/apps/docs/src/guide/fuels-cli/binaries.md deleted file mode 100644 index e70d1d798e5..00000000000 --- a/apps/docs/src/guide/fuels-cli/binaries.md +++ /dev/null @@ -1,61 +0,0 @@ - - -# Built-In Binaries - -`fuels` conveniently ships with `built-in` binaries for [`forc`](https://docs.fuel.network/docs/forc/commands/) and [`fuel-core`](https://docs.fuel.network/guides/running-a-node/running-a-local-node/). - -In case you haven't installed [The Fuel Toolchain](#the-fuel-toolchain) _yet_, these will be used. - -Here's how to configure this explicitly: - -- [`useBuiltinForc`](./config-file.md#usebuiltinforc): `true` -- [`useBuiltinFuelCore`](./config-file.md#usebuiltinfuelcore): `true` - -<<< @../../../demo-fuels/fuels.config.explicit-built-in.ts#config-built-in{ts:line-numbers} - -You can also call the `built-in` binaries directly: - -```console-vue -npx fuels@{{fuels}} help forc -npx fuels@{{fuels}} forc --version -npx fuels@{{fuels}} forc test -h -``` - -```console-vue -npx fuels@{{fuels}} help core -npx fuels@{{fuels}} core --version -npx fuels@{{fuels}} core run -h -``` - -Check the docs for `forc` and `fuel-core`: - -- [Forc Commands](https://docs.fuel.network/docs/forc/commands/) -- [Running a local Node using `fuel-core`](https://docs.fuel.network/guides/running-a-node/running-a-local-node/) - -## The Fuel Toolchain - -The Fuel Toolchain consists of several [components](https://docs.fuel.network/docs/sway/introduction/fuel_toolchain/). - -You can use [`fuel-up`](https://docs.fuel.network/docs/fuelup/installation/) to get it up and running. - -Check if it's working correctly with: - -```console -forc --version -``` - -```console -fuel-core --version -``` - -The `forc` and `fuel-core` binaries will be available in your `system` and `fuels` automatically prioritize them instead of the `built-in` ones. - -Here's how to configure this explicitly: - -- [`useBuiltinForc`](./config-file.md#usebuiltinforc): `false` -- [`useBuiltinFuelCore`](./config-file.md#usebuiltinfuelcore): `false` - -<<< @../../../demo-fuels/fuels.config.explicit-system.ts#config-system{ts:line-numbers} diff --git a/apps/docs/src/guide/fuels-cli/commands.md b/apps/docs/src/guide/fuels-cli/commands.md index a41e43df253..71dd906709e 100644 --- a/apps/docs/src/guide/fuels-cli/commands.md +++ b/apps/docs/src/guide/fuels-cli/commands.md @@ -1,11 +1,11 @@ # Commands -The `fuels` CLI consists of a couple commands. +The `fuels` CLI consists of a couple of commands. ## `fuels init` @@ -36,7 +36,7 @@ npx fuels@{{fuels}} init --workspace ./sway-programs --output ./src/sway-program This will give you a minimal configuration: -<<< @../../../demo-fuels/fuels.config.ts#config{ts:line-numbers} +<<< @../../../demo-fuels/fuels.config.minimal.ts#config{ts:line-numbers} In a nutshell: @@ -127,7 +127,7 @@ The `fuels dev` command does three things: 1. Auto-start a short-lived `fuel-core` node ([docs](./config-file.md#autostartfuelcore)) 1. Runs `build` and `deploy` once at the start -1. Watches your Forc workspace and repeats previous step on every change +1. Watches your Forc workspace and repeats the previous step on every change > _In `dev` mode, every time you update a contract on your Forc `workspace`, we re-generate type definitions and factory classes for it, following your pre-configured [`output`](./config-file.md#output) directory. If it's part of another build system running in dev mode (i.e. `next dev`), you can expect it to re-build / auto-reload as well._ @@ -161,31 +161,14 @@ Check for version incompatibilities between your [Fuel Toolchain](https://docs.f npx fuels@{{fuels}} versions ``` -``` +```console-vue +┌───────────┬───────────┬────────────────┬─────────────┐ +│ │ Supported │ Yours / System │ System Path │ +├───────────┼───────────┼────────────────┼─────────────┤ +│ Forc │ {{forc}} │ {{forc}} │ forc │ +├───────────┼───────────┼────────────────┼─────────────┤ +│ Fuel-Core │ {{fuelCore}} │ {{fuelCore}} │ fuel-core │ +└───────────┴───────────┴────────────────┴─────────────┘ + You have all the right versions! ⚡ -┌───────────┬───────────┬─────────────────┐ -│ │ Supported │ Yours / System │ -├───────────┼───────────┼─────────────────┤ -│ Forc │ 0.30.0 │ 0.30.0 │ -├───────────┼───────────┼─────────────────┤ -│ Fuel-Core │ 0.14.0 │ 0.14.0 │ -└───────────┴───────────┴─────────────────┘ ``` - -## `fuels forc` - -Simple [wrapper](./binaries.md) around the `forc` binary. - -Check also: - -- [Built-in Binaries](./binaries.md) -- [`forc` documentation](https://docs.fuel.network/docs/forc/commands/) - -## `fuels core` - -Simple [wrapper](./binaries.md) around the `fuel-core` binary. - -Check also: - -- [Built-in Binaries](./binaries.md) -- [`fuel-core` documentation](https://docs.fuel.network/guides/running-a-node/running-a-local-node/) diff --git a/apps/docs/src/guide/fuels-cli/config-file.md b/apps/docs/src/guide/fuels-cli/config-file.md index 8a64d3248d5..3b9beec829e 100644 --- a/apps/docs/src/guide/fuels-cli/config-file.md +++ b/apps/docs/src/guide/fuels-cli/config-file.md @@ -143,33 +143,21 @@ Parameters: <<< @../../../demo-fuels/fuels.config.full.ts#onFailure{ts:line-numbers} -## `useBuiltinForc` +## `forcPath` -Opt-in or out from using [built-in](./binaries.md) `forc` binaries. +Path to the `forc` binary. -When not supplied, will default to using the `system` binaries. +When not supplied, will default to using the `system` binaries (`forc`). -If `system` binaries are absent, print a warning and use `built-in` ones instead. +<<< @../../../demo-fuels/fuels.config.full.ts#forcPath{ts:line-numbers} -<<< @../../../demo-fuels/fuels.config.full.ts#useBuiltInForc{ts:line-numbers} +## `fuelCorePath` -Check also: - -- [Built-in Binaries](./binaries.md) - -## `useBuiltinFuelCore` - -Opt-in or out from using [built-in](./binaries.md) `fuel-core` binaries. +Path to the `fuel-core` binary. -When not supplied, will default to using the `system` binaries. - -If `system` binaries are absent, print a warning and use `built-in` ones instead. - -<<< @../../../demo-fuels/fuels.config.full.ts#useBuiltInFuelCore{ts:line-numbers} - -Check also: +When not supplied, will default to using the `system` binaries (`fuel-core`). -- [Built-in Binaries](./binaries.md) +<<< @../../../demo-fuels/fuels.config.full.ts#fuelCorePath{ts:line-numbers} ## Loading environment variables diff --git a/apps/docs/src/guide/fuels-cli/index.md b/apps/docs/src/guide/fuels-cli/index.md index d33d90c0dc2..edd0bb5f19d 100644 --- a/apps/docs/src/guide/fuels-cli/index.md +++ b/apps/docs/src/guide/fuels-cli/index.md @@ -31,6 +31,15 @@ my-fuel-dapp # NextJS app or similar └── package.json ``` +## Prerequisites + +The [Fuel Toolchain](https://docs.fuel.network/docs/sway/introduction/fuel_toolchain/#the-fuel-toolchain) and its components (namely `forc` and `fuel-core`) are pre-requisite for several operations with the Fuels CLI. For example: + +- Building out contracts using [`fuels build`](./commands.md#fuels-build) requires `forc`. +- Deploying contracts locally using [`fuels deploy`](./commands.md#fuels-deploy) requires `fuel-core`. + +Follow the [installation guide](https://docs.fuel.network/guides/installation/) if you don't have them installed already. + ## Installation Add it to your `my-fuel-dapp` project: diff --git a/apps/docs/src/guide/getting-started/connecting-to-a-local-node.md b/apps/docs/src/guide/getting-started/connecting-to-a-local-node.md index f6b2d99f696..705592612b2 100644 --- a/apps/docs/src/guide/getting-started/connecting-to-a-local-node.md +++ b/apps/docs/src/guide/getting-started/connecting-to-a-local-node.md @@ -3,7 +3,7 @@ Firstly, you will need a local node running on your machine. We recommend one of the following methods: - [Testing utilities](../testing/index.md#wallet-test-utilities) can assist in programmatically launching a short-lived node. -- Running [fuel-core](https://docs.fuel.network/guides/running-a-node/running-a-local-node/) directly, or via the CLI [fuels](../fuels-cli/commands.md#fuels-core). +- Running [fuel-core](https://docs.fuel.network/guides/running-a-node/running-a-local-node/) locally. In the following example, we create a provider to connect to the local node and sign a message. diff --git a/packages/forc/.gitignore b/internal/forc/.gitignore similarity index 100% rename from packages/forc/.gitignore rename to internal/forc/.gitignore diff --git a/packages/forc/CHANGELOG.md b/internal/forc/CHANGELOG.md similarity index 100% rename from packages/forc/CHANGELOG.md rename to internal/forc/CHANGELOG.md diff --git a/packages/forc/LICENSE b/internal/forc/LICENSE similarity index 100% rename from packages/forc/LICENSE rename to internal/forc/LICENSE diff --git a/packages/forc/README.md b/internal/forc/README.md similarity index 76% rename from packages/forc/README.md rename to internal/forc/README.md index 96518e3e7fc..494db35ed65 100644 --- a/packages/forc/README.md +++ b/internal/forc/README.md @@ -1,3 +1,3 @@ -# `@fuel-ts/forc` +# `@internal/forc` Binary wrapper for [Forc](https://github.com/FuelLabs/sway) diff --git a/packages/forc/VERSION b/internal/forc/VERSION similarity index 100% rename from packages/forc/VERSION rename to internal/forc/VERSION diff --git a/packages/forc/lib/bin.js b/internal/forc/lib/bin.js similarity index 100% rename from packages/forc/lib/bin.js rename to internal/forc/lib/bin.js diff --git a/packages/forc/lib/install.js b/internal/forc/lib/install.js similarity index 100% rename from packages/forc/lib/install.js rename to internal/forc/lib/install.js diff --git a/packages/forc/lib/shared.js b/internal/forc/lib/shared.js similarity index 100% rename from packages/forc/lib/shared.js rename to internal/forc/lib/shared.js diff --git a/packages/forc/lib/update.js b/internal/forc/lib/update.js similarity index 100% rename from packages/forc/lib/update.js rename to internal/forc/lib/update.js diff --git a/packages/forc/package.json b/internal/forc/package.json similarity index 90% rename from packages/forc/package.json rename to internal/forc/package.json index 6d0652d820e..62a9763b1c3 100644 --- a/packages/forc/package.json +++ b/internal/forc/package.json @@ -1,5 +1,6 @@ { - "name": "@fuel-ts/forc", + "private": true, + "name": "@internal/forc", "version": "0.88.1", "description": "NPM bin wrapper around Fuel `forc`", "author": "Fuel Labs (https://fuel.network/)", diff --git a/packages/fuel-core/.gitignore b/internal/fuel-core/.gitignore similarity index 100% rename from packages/fuel-core/.gitignore rename to internal/fuel-core/.gitignore diff --git a/packages/fuel-core/CHANGELOG.md b/internal/fuel-core/CHANGELOG.md similarity index 99% rename from packages/fuel-core/CHANGELOG.md rename to internal/fuel-core/CHANGELOG.md index c3a35c22a82..2c2b0cb8af8 100644 --- a/packages/fuel-core/CHANGELOG.md +++ b/internal/fuel-core/CHANGELOG.md @@ -1,4 +1,6 @@ -# @fuel-ts/fuel-core +# @internal/fuel-core + +## 0.86.0 ## 0.88.1 diff --git a/packages/fuel-core/LICENSE b/internal/fuel-core/LICENSE similarity index 100% rename from packages/fuel-core/LICENSE rename to internal/fuel-core/LICENSE diff --git a/packages/fuel-core/README.md b/internal/fuel-core/README.md similarity index 100% rename from packages/fuel-core/README.md rename to internal/fuel-core/README.md diff --git a/packages/fuel-core/VERSION b/internal/fuel-core/VERSION similarity index 100% rename from packages/fuel-core/VERSION rename to internal/fuel-core/VERSION diff --git a/packages/fuel-core/lib/bin.js b/internal/fuel-core/lib/bin.js similarity index 100% rename from packages/fuel-core/lib/bin.js rename to internal/fuel-core/lib/bin.js diff --git a/packages/fuel-core/lib/install.js b/internal/fuel-core/lib/install.js similarity index 100% rename from packages/fuel-core/lib/install.js rename to internal/fuel-core/lib/install.js diff --git a/packages/fuel-core/lib/shared.js b/internal/fuel-core/lib/shared.js similarity index 100% rename from packages/fuel-core/lib/shared.js rename to internal/fuel-core/lib/shared.js diff --git a/packages/fuel-core/lib/update.js b/internal/fuel-core/lib/update.js similarity index 100% rename from packages/fuel-core/lib/update.js rename to internal/fuel-core/lib/update.js diff --git a/packages/fuel-core/package.json b/internal/fuel-core/package.json similarity index 89% rename from packages/fuel-core/package.json rename to internal/fuel-core/package.json index bfbbcb0a89c..a273c8db08e 100644 --- a/packages/fuel-core/package.json +++ b/internal/fuel-core/package.json @@ -1,5 +1,6 @@ { - "name": "@fuel-ts/fuel-core", + "private": true, + "name": "@internal/fuel-core", "version": "0.88.1", "description": "NPM bin wrapper around `fuel-core`", "author": "Fuel Labs (https://fuel.network/)", diff --git a/package.json b/package.json index 0f38c5cd44d..bba36a2413a 100644 --- a/package.json +++ b/package.json @@ -63,11 +63,10 @@ "@changesets/get-github-info": "^0.5.2", "@changesets/read": "^0.6.0", "@changesets/types": "^6.0.0", + "@internal/forc": "workspace:*", + "@internal/fuel-core": "workspace:*", "@elasticpath/textlint-rule-no-dead-relative-link": "^1.1.1", - "@fuel-ts/forc": "workspace:*", - "@fuel-ts/fuel-core": "workspace:*", "@fuel-ts/utils": "workspace:*", - "@fuel-ts/versions": "workspace:^", "@internal/tsup": "workspace:*", "@istanbuljs/nyc-config-typescript": "^1.0.2", "@types/node": "18.15.3", diff --git a/packages/abi-typegen/package.json b/packages/abi-typegen/package.json index cc5f59b22d5..49af05d8974 100644 --- a/packages/abi-typegen/package.json +++ b/packages/abi-typegen/package.json @@ -62,7 +62,7 @@ "rimraf": "^3.0.2" }, "devDependencies": { - "@fuel-ts/forc": "workspace:*", + "@internal/forc": "workspace:*", "@types/mkdirp": "^1.0.2", "@types/ramda": "^0.29.3", "@types/rimraf": "^3.0.2" diff --git a/packages/account/src/test-utils/launchNode.test.ts b/packages/account/src/test-utils/launchNode.test.ts index f49d0913499..cf88c28d7d4 100644 --- a/packages/account/src/test-utils/launchNode.test.ts +++ b/packages/account/src/test-utils/launchNode.test.ts @@ -63,29 +63,43 @@ const defaultLaunchNodeConfig: Partial = { * @group node */ describe('launchNode', () => { - test('should start `fuel-core` node using built-in binary', async () => { + test('should start `fuel-core` node using system binary', async () => { mockSpawn(); + const { cleanup, ip, port } = await launchNode(defaultLaunchNodeConfig); + + expect(ip).toBe('0.0.0.0'); + expect(port).toBe('4000'); + + cleanup(); + }); + + test('should start `fuel-core` node with custom binary', async () => { + const { spawn } = mockSpawn(); + const { cleanup, ip, port } = await launchNode({ ...defaultLaunchNodeConfig, - useSystemFuelCore: false, + fuelCorePath: 'fuels-core', }); expect(ip).toBe('0.0.0.0'); expect(port).toBe('4000'); + expect(spawn).toBeCalledWith('fuels-core', expect.any(Array), expect.any(Object)); + cleanup(); }); - test('should start `fuel-core` node using system binary', async () => { - mockSpawn(); + test('should start `fuel-core` node with custom binaries', async () => { + const { spawn } = mockSpawn(); const { cleanup, ip, port } = await launchNode({ ...defaultLaunchNodeConfig, - useSystemFuelCore: true, + fuelCorePath: 'custom-fuels-core', }); expect(ip).toBe('0.0.0.0'); expect(port).toBe('4000'); + expect(spawn).toBeCalledWith('custom-fuels-core', expect.any(Array), expect.any(Object)); cleanup(); }); diff --git a/packages/account/src/test-utils/launchNode.ts b/packages/account/src/test-utils/launchNode.ts index 41a2ecc1f24..9684067171c 100644 --- a/packages/account/src/test-utils/launchNode.ts +++ b/packages/account/src/test-utils/launchNode.ts @@ -1,7 +1,6 @@ import { UTXO_ID_LEN } from '@fuel-ts/abi-coder'; import { randomBytes } from '@fuel-ts/crypto'; import { defaultSnapshotConfigs, defaultConsensusKey, hexlify } from '@fuel-ts/utils'; -import { findBinPath } from '@fuel-ts/utils/cli-utils'; import type { ChildProcessWithoutNullStreams } from 'child_process'; import { spawn } from 'child_process'; import { randomUUID } from 'crypto'; @@ -40,7 +39,7 @@ export type LaunchNodeOptions = { ip?: string; port?: string; args?: string[]; - useSystemFuelCore?: boolean; + fuelCorePath?: string; loggingEnabled?: boolean; debugEnabled?: boolean; basePath?: string; @@ -87,7 +86,7 @@ export const killNode = (params: KillNodeParams) => { * @param ip - the ip to bind to. (optional, defaults to 0.0.0.0) * @param port - the port to bind to. (optional, defaults to 4000 or the next available port) * @param args - additional arguments to pass to fuel-core. - * @param useSystemFuelCore - whether to use the system fuel-core binary or the one provided by the \@fuel-ts/fuel-core package. + * @param fuelCorePath - the path to the fuel-core binary. (optional, defaults to 'fuel-core') * @param loggingEnabled - whether the node should output logs. (optional, defaults to true) * @param debugEnabled - whether the node should log debug messages. (optional, defaults to false) * @param basePath - the base path to use for the temporary folder. (optional, defaults to os.tmpdir()) @@ -97,7 +96,7 @@ export const launchNode = async ({ ip, port, args = [], - useSystemFuelCore = false, + fuelCorePath = process.env.FUEL_CORE_PATH ?? undefined, loggingEnabled = true, debugEnabled = false, basePath, @@ -124,9 +123,7 @@ export const launchNode = async ({ // This string is logged by the client when the node has successfully started. We use it to know when to resolve. const graphQLStartSubstring = 'Binding GraphQL provider to'; - const binPath = findBinPath('fuels-core', __dirname); - - const command = useSystemFuelCore ? 'fuel-core' : binPath; + const command = fuelCorePath ?? 'fuel-core'; const ipToUse = ip || '0.0.0.0'; diff --git a/packages/create-fuels/package.json b/packages/create-fuels/package.json index 679b7cb915f..c995e8baac9 100644 --- a/packages/create-fuels/package.json +++ b/packages/create-fuels/package.json @@ -16,7 +16,7 @@ "license": "Apache-2.0", "scripts": { "build": "tsup", - "prepublishOnly": "cp -r ../../templates . && tsx ./scripts/rewriteTemplatePackageJson.ts" + "prepublishOnly": "cp -r ../../templates . && tsx ./scripts/rewriteTemplateFiles.ts" }, "dependencies": { "@iarna/toml": "^2.2.5", diff --git a/packages/create-fuels/scripts/rewriteTemplateFiles.ts b/packages/create-fuels/scripts/rewriteTemplateFiles.ts new file mode 100644 index 00000000000..5767c0b5259 --- /dev/null +++ b/packages/create-fuels/scripts/rewriteTemplateFiles.ts @@ -0,0 +1,19 @@ +import { versions } from '@fuel-ts/versions'; +import { readFileSync, writeFileSync } from 'fs'; +import { join } from 'path'; + +const templateDir = join(__dirname, '../templates/nextjs'); +const packageJsonFilePath = join(templateDir, 'package.json'); +const fuelsConfigFilePath = join(templateDir, 'fuels.config.ts'); + +// package.json +let contents = readFileSync(packageJsonFilePath, 'utf-8'); +contents = contents.replace(/xprebuild/g, 'prebuild'); +contents = contents.replace(/"fuels": "workspace:\*"/, `"fuels": "${versions.FUELS}"`); +writeFileSync(packageJsonFilePath, contents); + +// fuels.config.ts +contents = readFileSync(fuelsConfigFilePath, 'utf-8'); +contents = contents.replace(/\n\W+forcPath: 'fuels-forc',/g, ''); +contents = contents.replace(/\n\W+fuelCorePath: 'fuels-core',/g, ''); +writeFileSync(fuelsConfigFilePath, contents); diff --git a/packages/create-fuels/scripts/rewriteTemplatePackageJson.ts b/packages/create-fuels/scripts/rewriteTemplatePackageJson.ts deleted file mode 100644 index 907be434c6f..00000000000 --- a/packages/create-fuels/scripts/rewriteTemplatePackageJson.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { versions } from '@fuel-ts/versions'; -import { readFileSync, writeFileSync } from 'fs'; -import { join } from 'path'; - -const filepath = join(__dirname, '../templates/nextjs/package.json'); - -let contents = readFileSync(filepath, 'utf-8'); - -contents = contents.replace(/xprebuild/g, 'prebuild'); -contents = contents.replace(/"fuels": "workspace:\*"/, `"fuels": "${versions.FUELS}"`); - -writeFileSync(filepath, contents); diff --git a/packages/fuel-gauge/fuels.config.ts b/packages/fuel-gauge/fuels.config.ts index fcc0abef737..016d6327b74 100644 --- a/packages/fuel-gauge/fuels.config.ts +++ b/packages/fuel-gauge/fuels.config.ts @@ -4,4 +4,6 @@ export default createConfig({ workspace: './test/fixtures/forc-projects', output: './test/typegen', forcBuildFlags: ['--release'], + forcPath: 'fuels-forc', + fuelCorePath: 'fuels-core', }); diff --git a/packages/fuel-gauge/package.json b/packages/fuel-gauge/package.json index 3f8a30e5cb9..409d2a215d2 100644 --- a/packages/fuel-gauge/package.json +++ b/packages/fuel-gauge/package.json @@ -15,7 +15,7 @@ }, "devDependencies": { "@fuel-ts/account": "workspace:*", - "@fuel-ts/forc": "workspace:*", + "@internal/forc": "workspace:*", "@fuel-ts/utils": "workspace:*", "@fuel-ts/errors": "workspace:*" } diff --git a/packages/fuels/package.json b/packages/fuels/package.json index f707a90b2d8..a65179a2ae2 100644 --- a/packages/fuels/package.json +++ b/packages/fuels/package.json @@ -48,8 +48,6 @@ "@fuel-ts/contract": "workspace:*", "@fuel-ts/crypto": "workspace:*", "@fuel-ts/errors": "workspace:*", - "@fuel-ts/forc": "workspace:*", - "@fuel-ts/fuel-core": "workspace:*", "@fuel-ts/hasher": "workspace:*", "@fuel-ts/interfaces": "workspace:*", "@fuel-ts/math": "workspace:*", diff --git a/packages/fuels/src/cli.test.ts b/packages/fuels/src/cli.test.ts index 37bf5bc22dd..02c5a2e6feb 100644 --- a/packages/fuels/src/cli.test.ts +++ b/packages/fuels/src/cli.test.ts @@ -36,15 +36,11 @@ describe('cli.js', () => { const dev = cmd(Commands.dev); const build = cmd(Commands.build); const deploy = cmd(Commands.deploy); - const forc = cmd('forc'); - const core = cmd('core'); expect(init).toBeTruthy(); expect(dev).toBeTruthy(); expect(build).toBeTruthy(); expect(deploy).toBeTruthy(); - expect(forc).toBeTruthy(); - expect(core).toBeTruthy(); // checking default options const path = process.cwd(); @@ -53,8 +49,6 @@ describe('cli.js', () => { expect(dev?.opts()).toEqual({ path }); expect(build?.opts()).toEqual({ path }); expect(deploy?.opts()).toEqual({ path }); - expect(forc?.opts()).toEqual({}); - expect(core?.opts()).toEqual({}); }); it('preAction should configure logging', () => { diff --git a/packages/fuels/src/cli.ts b/packages/fuels/src/cli.ts index 427fbac360f..b32842805f4 100644 --- a/packages/fuels/src/cli.ts +++ b/packages/fuels/src/cli.ts @@ -1,5 +1,4 @@ import { configureCliOptions as configureTypegenCliOptions } from '@fuel-ts/abi-typegen/cli'; -import { findBinPath } from '@fuel-ts/utils/cli-utils'; import { versions } from '@fuel-ts/versions'; import { runVersions } from '@fuel-ts/versions/cli'; import { Command, Option } from 'commander'; @@ -8,6 +7,7 @@ import { build } from './cli/commands/build'; import { deploy } from './cli/commands/deploy'; import { dev } from './cli/commands/dev'; import { init } from './cli/commands/init'; +import { withBinaryPaths } from './cli/commands/withBinaryPaths'; import { withConfig } from './cli/commands/withConfig'; import { withProgram } from './cli/commands/withProgram'; import { Commands } from './cli/types'; @@ -56,8 +56,8 @@ export const configureCli = () => { .addOption(new Option(`-s, --scripts ${arg}`, `${desc} Scripts`).conflicts('workspace')) .addOption(new Option(`-p, --predicates ${arg}`, `${desc} Predicates`).conflicts('workspace')) .requiredOption('-o, --output ', 'Relative dir path for Typescript generation output') - .option('--use-builtin-forc', 'Use buit-in `forc` to build Sway programs') - .option('--use-builtin-fuel-core', 'Use buit-in `fuel-core` when starting a Fuel node') + .option('--forc-path ', 'Path to the `forc` binary') + .option('--fuel-core-path ', 'Path to the `fuel-core` binary') .option('--auto-start-fuel-core', 'Auto-starts a `fuel-core` node during `dev` command') .action(withProgram(command, Commands.init, init)); @@ -90,22 +90,10 @@ export const configureCli = () => { ); // Versions - program - .command('versions') + (command = program.command('versions')) .description('Check for version incompatibilities') - .action(runVersions); - - /** - * Binary wrappers - */ - - program.command('core', 'Wrapper around Fuel Core binary', { - executableFile: findBinPath('fuels-core', __dirname), - }); - - program.command('forc', 'Wrapper around Forc binary', { - executableFile: findBinPath('fuels-forc', __dirname), - }); + .addOption(pathOption) + .action(withBinaryPaths(command, Commands.versions, runVersions)); return program; }; diff --git a/packages/fuels/src/cli/commands/build/buildSwayProgram.test.ts b/packages/fuels/src/cli/commands/build/buildSwayProgram.test.ts index 24cf1be223b..94e32731fe1 100644 --- a/packages/fuels/src/cli/commands/build/buildSwayProgram.test.ts +++ b/packages/fuels/src/cli/commands/build/buildSwayProgram.test.ts @@ -1,4 +1,3 @@ -import * as findBinPathMod from '@fuel-ts/utils/cli-utils'; import * as childProcessMod from 'child_process'; import { fuelsConfig } from '../../../../test/fixtures/fuels.config'; @@ -24,8 +23,6 @@ describe('buildSwayPrograms', () => { }); function mockAll(params: { shouldError: boolean } = { shouldError: false }) { - const findBinPath = vi.spyOn(findBinPathMod, 'findBinPath').mockReturnValue(''); - const spawnMocks = { // eslint-disable-next-line @typescript-eslint/no-explicit-any on: vi.fn((eventName: string, fn: (..._: any) => void) => { @@ -48,7 +45,6 @@ describe('buildSwayPrograms', () => { return { spawn, spawnMocks, - findBinPath, }; } diff --git a/packages/fuels/src/cli/commands/build/buildSwayProgram.ts b/packages/fuels/src/cli/commands/build/buildSwayProgram.ts index b3370b1195f..89b29e15f81 100644 --- a/packages/fuels/src/cli/commands/build/buildSwayProgram.ts +++ b/packages/fuels/src/cli/commands/build/buildSwayProgram.ts @@ -1,4 +1,3 @@ -import { findBinPath } from '@fuel-ts/utils/cli-utils'; import { spawn } from 'child_process'; import type { FuelsConfig } from '../../types'; @@ -10,11 +9,8 @@ export const buildSwayProgram = async (config: FuelsConfig, path: string) => { debug('Building Sway program', path); return new Promise((resolve, reject) => { - const builtInForcPath = findBinPath('fuels-forc', __dirname); - - const command = config.useBuiltinForc ? builtInForcPath : 'forc'; const args = ['build', '-p', path].concat(config.forcBuildFlags); - const forc = spawn(command, args, { stdio: 'pipe' }); + const forc = spawn(config.forcPath, args, { stdio: 'pipe' }); if (loggingConfig.isLoggingEnabled) { forc.stderr?.pipe(process.stderr); diff --git a/packages/fuels/src/cli/commands/build/buildSwayPrograms.ts b/packages/fuels/src/cli/commands/build/buildSwayPrograms.ts index 57cf9957dd5..936d4d99fd8 100644 --- a/packages/fuels/src/cli/commands/build/buildSwayPrograms.ts +++ b/packages/fuels/src/cli/commands/build/buildSwayPrograms.ts @@ -1,11 +1,10 @@ import type { FuelsConfig } from '../../types'; -import { getBinarySource } from '../../utils/getBinarySource'; import { log } from '../../utils/logger'; import { buildSwayProgram } from './buildSwayProgram'; export async function buildSwayPrograms(config: FuelsConfig) { - log(`Building Sway programs using ${getBinarySource(config.useBuiltinFuelCore)} 'forc' binary`); + log(`Building Sway programs using: '${config.forcPath}'`); const paths = config.workspace ? [config.workspace] diff --git a/packages/fuels/src/cli/commands/dev/autoStartFuelCore.test.ts b/packages/fuels/src/cli/commands/dev/autoStartFuelCore.test.ts index 59392249a12..40dafed638e 100644 --- a/packages/fuels/src/cli/commands/dev/autoStartFuelCore.test.ts +++ b/packages/fuels/src/cli/commands/dev/autoStartFuelCore.test.ts @@ -60,11 +60,11 @@ describe('autoStartFuelCore', () => { expect(launchNode).toHaveBeenCalledTimes(0); }); - test('should start `fuel-core` node using built-in binary', async () => { + test('should start `fuel-core` node using custom binary', async () => { const { launchNode } = mockLaunchNode(); const copyConfig: FuelsConfig = structuredClone(fuelsConfig); - copyConfig.useBuiltinFuelCore = true; + copyConfig.fuelCorePath = 'fuels-core'; // this will cause it to autofind a free port copyConfig.fuelCorePort = undefined; @@ -79,6 +79,11 @@ describe('autoStartFuelCore', () => { expect(core.port).toBeGreaterThanOrEqual(4000); expect(core.providerUrl).toMatch(/http:\/\/127\.0\.0\.1:([0-9]+)\/v1\/graphql/); expect(core.killChildProcess).toBeTruthy(); + expect(launchNode).toBeCalledWith( + expect.objectContaining({ + fuelCorePath: 'fuels-core', + }) + ); core.killChildProcess(); }); @@ -86,10 +91,8 @@ describe('autoStartFuelCore', () => { test('should start `fuel-core` node using system binary', async () => { const { launchNode } = mockLaunchNode(); - const core = (await autoStartFuelCore({ - ...structuredClone(fuelsConfig), - useBuiltinFuelCore: false, - })) as FuelCoreNode; + const config = structuredClone(fuelsConfig); + const core = (await autoStartFuelCore(config)) as FuelCoreNode; expect(launchNode).toHaveBeenCalledTimes(1); diff --git a/packages/fuels/src/cli/commands/dev/autoStartFuelCore.ts b/packages/fuels/src/cli/commands/dev/autoStartFuelCore.ts index 126d36c6e2d..dd538e200a1 100644 --- a/packages/fuels/src/cli/commands/dev/autoStartFuelCore.ts +++ b/packages/fuels/src/cli/commands/dev/autoStartFuelCore.ts @@ -4,7 +4,6 @@ import type { ChildProcessWithoutNullStreams } from 'child_process'; import { getPortPromise } from 'portfinder'; import type { FuelsConfig } from '../../types'; -import { getBinarySource } from '../../utils/getBinarySource'; import { log, loggingConfig } from '../../utils/logger'; export type FuelCoreNode = { @@ -28,7 +27,7 @@ export const autoStartFuelCore = async (config: FuelsConfig) => { let fuelCore: FuelCoreNode | undefined; if (config.autoStartFuelCore) { - log(`Starting ${getBinarySource(config.useBuiltinFuelCore)} 'fuel-core' node..`); + log(`Starting node using: '${config.fuelCorePath}'`); const bindIp = '0.0.0.0'; const accessIp = '127.0.0.1'; @@ -47,7 +46,7 @@ export const autoStartFuelCore = async (config: FuelsConfig) => { loggingEnabled: loggingConfig.isLoggingEnabled, debugEnabled: loggingConfig.isDebugEnabled, basePath: config.basePath, - useSystemFuelCore: !config.useBuiltinFuelCore, + fuelCorePath: config.fuelCorePath, }); fuelCore = { diff --git a/packages/fuels/src/cli/commands/init/index.ts b/packages/fuels/src/cli/commands/init/index.ts index 934f4c1391a..433d6b5fc07 100644 --- a/packages/fuels/src/cli/commands/init/index.ts +++ b/packages/fuels/src/cli/commands/init/index.ts @@ -9,7 +9,7 @@ import { log } from '../../utils/logger'; export function init(program: Command) { const options = program.opts(); - const { path, autoStartFuelCore, useBuiltinForc, useBuiltinFuelCore } = options; + const { path, autoStartFuelCore, forcPath, fuelCorePath } = options; let workspace: string | undefined; let absoluteWorkspace: string | undefined; @@ -53,8 +53,8 @@ export function init(program: Command) { scripts, predicates, output, - useBuiltinForc, - useBuiltinFuelCore, + forcPath, + fuelCorePath, autoStartFuelCore, }); diff --git a/packages/fuels/src/cli/commands/init/shouldUseBuiltinForc.test.ts b/packages/fuels/src/cli/commands/init/shouldUseBuiltinForc.test.ts deleted file mode 100644 index 6324b16246a..00000000000 --- a/packages/fuels/src/cli/commands/init/shouldUseBuiltinForc.test.ts +++ /dev/null @@ -1,59 +0,0 @@ -import * as getSystemFuelCoreMod from '@fuel-ts/versions/cli'; - -import { mockLogger } from '../../../../test/utils/mockLogger'; - -import { shouldUseBuiltinFuelCore } from './shouldUseBuiltinFuelCore'; - -vi.mock('prompts', async () => { - const mod = await vi.importActual('prompts'); - return { - __esModule: true, - ...mod, - }; -}); - -/** - * @group node - */ -describe('shouldUseBuiltinFuelCore', () => { - afterEach(() => { - vi.restoreAllMocks(); - }); - - function mockAll(returns: { getSystemFuelCore: string | null }) { - const getSystemFuelCore = vi - .spyOn(getSystemFuelCoreMod, 'getSystemFuelCore') - .mockReturnValue({ error: null, systemFuelCoreVersion: returns.getSystemFuelCore }); - - const { error } = mockLogger(); - - return { - getSystemFuelCore, - error, - }; - } - - it('should select [built-in] fuel-core', () => { - const { getSystemFuelCore, error } = mockAll({ getSystemFuelCore: null }); - - const useBuiltinFuelCore = shouldUseBuiltinFuelCore(); - - expect(useBuiltinFuelCore).toEqual(true); - expect(getSystemFuelCore).toHaveBeenCalledTimes(1); - - expect(error).toHaveBeenCalledTimes(0); - }); - - it('should select [system] fuel-core', () => { - const { getSystemFuelCore, error } = mockAll({ - getSystemFuelCore: '1.0.0', - }); - - const useBuiltinFuelCore = shouldUseBuiltinFuelCore(); - - expect(useBuiltinFuelCore).toEqual(false); - expect(getSystemFuelCore).toHaveBeenCalledTimes(1); - - expect(error).toHaveBeenCalledTimes(0); - }); -}); diff --git a/packages/fuels/src/cli/commands/init/shouldUseBuiltinForc.ts b/packages/fuels/src/cli/commands/init/shouldUseBuiltinForc.ts deleted file mode 100644 index aa4975cc298..00000000000 --- a/packages/fuels/src/cli/commands/init/shouldUseBuiltinForc.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { getSystemForc } from '@fuel-ts/versions/cli'; - -export const shouldUseBuiltinForc = () => { - // first, tries to use system binary - const { systemForcVersion } = getSystemForc(); - if (systemForcVersion !== null) { - return false; - } - - // if its not found, will default to the built-in binary - return true; -}; diff --git a/packages/fuels/src/cli/commands/init/shouldUseBuiltinFuelCore.test.ts b/packages/fuels/src/cli/commands/init/shouldUseBuiltinFuelCore.test.ts deleted file mode 100644 index 3f02b09f773..00000000000 --- a/packages/fuels/src/cli/commands/init/shouldUseBuiltinFuelCore.test.ts +++ /dev/null @@ -1,49 +0,0 @@ -import * as getSystemForcMod from '@fuel-ts/versions/cli'; - -import { mockLogger } from '../../../../test/utils/mockLogger'; - -import { shouldUseBuiltinForc } from './shouldUseBuiltinForc'; - -/** - * @group node - */ -describe('shouldUseBuiltinForc', () => { - beforeEach(() => { - vi.restoreAllMocks(); - }); - - function mockAll(returns: { getSystemForc: string | null }) { - const getSystemForc = vi - .spyOn(getSystemForcMod, 'getSystemForc') - .mockReturnValue({ error: null, systemForcVersion: returns.getSystemForc }); - - const { error } = mockLogger(); - - return { - getSystemForc, - error, - }; - } - - it('should select [built-in] forc', () => { - const { getSystemForc, error } = mockAll({ getSystemForc: null }); - - const useBuiltinForc = shouldUseBuiltinForc(); - - expect(useBuiltinForc).toEqual(true); - expect(getSystemForc).toHaveBeenCalledTimes(1); - - expect(error).toHaveBeenCalledTimes(0); - }); - - it('should select [system] forc', () => { - const { getSystemForc, error } = mockAll({ getSystemForc: '1.0.0' }); - - const useBuiltinForc = shouldUseBuiltinForc(); - - expect(useBuiltinForc).toEqual(false); - expect(getSystemForc).toHaveBeenCalledTimes(1); - - expect(error).toHaveBeenCalledTimes(0); - }); -}); diff --git a/packages/fuels/src/cli/commands/init/shouldUseBuiltinFuelCore.ts b/packages/fuels/src/cli/commands/init/shouldUseBuiltinFuelCore.ts deleted file mode 100644 index 7cb7f7ef9fc..00000000000 --- a/packages/fuels/src/cli/commands/init/shouldUseBuiltinFuelCore.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { getSystemFuelCore } from '@fuel-ts/versions/cli'; - -export const shouldUseBuiltinFuelCore = () => { - // first, tries use system binary - const { systemFuelCoreVersion } = getSystemFuelCore(); - if (systemFuelCoreVersion !== null) { - return false; - } - - // if its not found, will default to the built-in binary - return true; -}; diff --git a/packages/fuels/src/cli/commands/withBinaryPaths.test.ts b/packages/fuels/src/cli/commands/withBinaryPaths.test.ts new file mode 100644 index 00000000000..b2d09bfa6b8 --- /dev/null +++ b/packages/fuels/src/cli/commands/withBinaryPaths.test.ts @@ -0,0 +1,95 @@ +import { program } from 'commander'; + +import { fuelsConfig } from '../../../test/fixtures/fuels.config'; +import { mockLogger } from '../../../test/utils/mockLogger'; +import * as loadConfigMod from '../config/loadConfig'; +import { Commands } from '../types'; + +import { withBinaryPaths } from './withBinaryPaths'; + +const mockAllDeps = ( + params: { configPath?: string; forcPath?: string; fuelCorePath?: string } = {} +) => { + const { forcPath, fuelCorePath, configPath } = params; + + const command = program + .command(Commands.versions) + .option('-p, --path ', 'Path to project root', configPath); + + const runVersions = vi.fn(); + + const loadUserConfig = vi.spyOn(loadConfigMod, 'loadUserConfig').mockResolvedValue({ + configPath: '/path/to/config', + userConfig: { + ...structuredClone(fuelsConfig), + forcPath, + fuelCorePath, + }, + }); + + return { + command, + runVersions, + loadUserConfig, + }; +}; + +/** + * @group node + */ +describe('withBinaryPaths', () => { + beforeEach(() => { + mockLogger(); + }); + + beforeEach(() => { + vi.restoreAllMocks(); + }); + + it('should load the user config from the path', async () => { + const configPath = '/path/to/config'; + const { command, runVersions, loadUserConfig } = mockAllDeps({ configPath }); + + await withBinaryPaths(command, Commands.versions, runVersions)(); + + expect(loadUserConfig).toHaveBeenCalledWith(configPath); + }); + + it('should fallback to default binary paths (undefined)', async () => { + const expectedPaths = { forcPath: undefined, fuelCorePath: undefined }; + const { command, runVersions } = mockAllDeps(); + + await withBinaryPaths(command, Commands.versions, runVersions)(); + + expect(runVersions).toHaveBeenCalledWith(expectedPaths); + }); + + it('should use resolved user config paths', async () => { + const expectedPaths = { forcPath: 'forc', fuelCorePath: 'fuel-core' }; + const { command, runVersions } = mockAllDeps({ ...expectedPaths }); + + await withBinaryPaths(command, Commands.versions, runVersions)(); + + expect(runVersions).toHaveBeenCalledWith(expectedPaths); + }); + + it(`should debug any errors that occur while loading the user config`, async () => { + const { debug } = mockLogger(); + const { command, runVersions, loadUserConfig } = mockAllDeps(); + loadUserConfig.mockRejectedValue(new Error('Something happened')); + + await withBinaryPaths(command, Commands.versions, runVersions)(); + + expect(debug).toHaveBeenCalledWith('Something happened'); + }); + + it(`should error any errors that occur while running the command`, async () => { + const { error } = mockLogger(); + const { command, runVersions } = mockAllDeps(); + runVersions.mockRejectedValue(new Error('Something happened')); + + await withBinaryPaths(command, Commands.versions, runVersions)(); + + expect(error).toHaveBeenCalledWith(new Error('Something happened')); + }); +}); diff --git a/packages/fuels/src/cli/commands/withBinaryPaths.ts b/packages/fuels/src/cli/commands/withBinaryPaths.ts new file mode 100644 index 00000000000..4df77474ae6 --- /dev/null +++ b/packages/fuels/src/cli/commands/withBinaryPaths.ts @@ -0,0 +1,33 @@ +import type { Command } from 'commander'; + +import { loadUserConfig } from '../config/loadConfig'; +import type { Commands, UserFuelsConfig } from '../types'; +import { debug, error } from '../utils/logger'; + +type BinaryPaths = Pick; + +export function withBinaryPaths( + program: Command, + _command: CType, + fn: (paths: BinaryPaths) => void +) { + return async () => { + const options = program.opts(); + + const paths: BinaryPaths = {}; + + try { + const { userConfig } = await loadUserConfig(options.path); + paths.forcPath = userConfig.forcPath; + paths.fuelCorePath = userConfig.fuelCorePath; + } catch (err) { + debug((err).message); + } + + try { + await fn(paths); + } catch (err) { + error(err); + } + }; +} diff --git a/packages/fuels/src/cli/commands/withConfig.ts b/packages/fuels/src/cli/commands/withConfig.ts index bc1870e1c4e..7dbd9883d74 100644 --- a/packages/fuels/src/cli/commands/withConfig.ts +++ b/packages/fuels/src/cli/commands/withConfig.ts @@ -6,7 +6,7 @@ import type { Commands, FuelsConfig, CommandEvent } from '../types'; import { error, log } from '../utils/logger'; export const withConfigErrorHandler = async (err: Error, config?: FuelsConfig) => { - error(err); + error(err.message); if (config) { await config.onFailure?.(err, config); } diff --git a/packages/fuels/src/cli/config/loadConfig.test.ts b/packages/fuels/src/cli/config/loadConfig.test.ts index 705119848c2..c696215dc89 100644 --- a/packages/fuels/src/cli/config/loadConfig.test.ts +++ b/packages/fuels/src/cli/config/loadConfig.test.ts @@ -8,8 +8,6 @@ import { resetConfigAndMocks, resetDiskAndMocks, } from '../../../test/utils/runCommands'; -import * as shouldUseBuiltinForcMod from '../commands/init/shouldUseBuiltinForc'; -import * as shouldUseBuiltinFuelCoreMod from '../commands/init/shouldUseBuiltinFuelCore'; import type { FuelsConfig } from '../types'; import { readForcToml, readSwayType } from './forcUtils'; @@ -42,7 +40,8 @@ describe('loadConfig', () => { root: paths.root, workspace: paths.workspaceDir, output: paths.outputDir, - useBuiltinBinaries: true, + forcPath: paths.forcPath, + fuelCorePath: paths.fuelCorePath, autoStartFuelCore: true, }); @@ -66,6 +65,8 @@ describe('loadConfig', () => { root: paths.root, workspace: paths.workspaceDir, output: paths.outputDir, + forcPath: paths.forcPath, + fuelCorePath: paths.fuelCorePath, }); const config = await loadConfig(paths.root); @@ -79,6 +80,8 @@ describe('loadConfig', () => { await runInit({ root: paths.root, output: paths.outputDir, + forcPath: paths.forcPath, + fuelCorePath: paths.fuelCorePath, contracts: 'workspace/contracts/*', scripts: 'workspace/scripts/*', predicates: 'workspace/predicates/*', @@ -95,6 +98,8 @@ describe('loadConfig', () => { await runInit({ root: paths.root, output: paths.outputDir, + forcPath: paths.forcPath, + fuelCorePath: paths.fuelCorePath, contracts: 'workspace/contracts/*', }); @@ -109,6 +114,8 @@ describe('loadConfig', () => { await runInit({ root: paths.root, output: paths.outputDir, + forcPath: paths.forcPath, + fuelCorePath: paths.fuelCorePath, scripts: 'workspace/scripts/*', }); @@ -123,6 +130,8 @@ describe('loadConfig', () => { await runInit({ root: paths.root, output: paths.outputDir, + forcPath: paths.forcPath, + fuelCorePath: paths.fuelCorePath, predicates: 'workspace/predicates/*', }); @@ -137,6 +146,8 @@ describe('loadConfig', () => { await runInit({ root: paths.root, output: paths.outputDir, + forcPath: paths.forcPath, + fuelCorePath: paths.fuelCorePath, // passing contract path in workspace config option workspace: 'workspace/contracts/bar', }); @@ -148,27 +159,40 @@ describe('loadConfig', () => { expect(error?.message).toMatch(/try using 'contracts'/i); }); - test(`should smart-set built-in flags`, async () => { + test(`should load custom binary paths`, async () => { await runInit({ root: paths.root, workspace: paths.workspaceDir, output: paths.outputDir, + forcPath: 'fuels-forc', + fuelCorePath: 'fuels-core', }); - const shouldUseBuiltinForc = vi - .spyOn(shouldUseBuiltinForcMod, 'shouldUseBuiltinForc') - .mockReturnValue(false); + const config = await loadConfig(paths.root); - const shouldUseBuiltinFuelCore = vi - .spyOn(shouldUseBuiltinFuelCoreMod, 'shouldUseBuiltinFuelCore') - .mockReturnValue(true); + expect(config.forcPath).toEqual('fuels-forc'); + expect(config.fuelCorePath).toEqual('fuels-core'); + }); - const config = await loadConfig(paths.root); + test('should throw if system binary paths are not found', async () => { + const forcPath = '/non/existent/forc'; + const fuelCorePath = '/non/existent/fuel-core'; + await runInit({ + root: paths.root, + workspace: paths.workspaceDir, + output: paths.outputDir, + forcPath, + fuelCorePath, + }); - expect(config.useBuiltinForc).toEqual(false); - expect(config.useBuiltinFuelCore).toEqual(true); + const { error, result } = await safeExec(() => loadConfig(paths.root)); - expect(shouldUseBuiltinForc).toHaveBeenCalledTimes(1); - expect(shouldUseBuiltinFuelCore).toHaveBeenCalledTimes(1); + expect(result).toBeFalsy(); + expect(error?.message).toContain(`Unable to find the following binaries on the filesystem`); + expect(error?.message).toContain(`'forc' at path '${forcPath}'`); + expect(error?.message).toContain(`'fuel-core' at path '${fuelCorePath}'`); + expect(error?.message).toContain( + 'Visit https://docs.fuel.network/guides/installation/ for an installation guide.' + ); }); }); diff --git a/packages/fuels/src/cli/config/loadConfig.ts b/packages/fuels/src/cli/config/loadConfig.ts index b98ea82bed8..a3a27e25a93 100644 --- a/packages/fuels/src/cli/config/loadConfig.ts +++ b/packages/fuels/src/cli/config/loadConfig.ts @@ -1,18 +1,19 @@ import { FUEL_NETWORK_URL } from '@fuel-ts/account/configs'; import { defaultConsensusKey } from '@fuel-ts/utils'; +import { tryFindBinaries } from '@fuel-ts/utils/cli-utils'; import { bundleRequire } from 'bundle-require'; import type { BuildOptions } from 'esbuild'; import JoyCon from 'joycon'; import { resolve, parse } from 'path'; -import { shouldUseBuiltinForc } from '../commands/init/shouldUseBuiltinForc'; -import { shouldUseBuiltinFuelCore } from '../commands/init/shouldUseBuiltinFuelCore'; import type { FuelsConfig, UserFuelsConfig } from '../types'; import { SwayType, readForcToml, readSwayType } from './forcUtils'; import { validateConfig } from './validateConfig'; -export async function loadConfig(cwd: string): Promise { +export async function loadUserConfig( + cwd: string +): Promise<{ userConfig: UserFuelsConfig; configPath: string }> { const configJoycon = new JoyCon(); const configPath = await configJoycon.resolve({ @@ -38,16 +39,22 @@ export async function loadConfig(cwd: string): Promise { }); const userConfig: UserFuelsConfig = result.mod.default; + return { configPath, userConfig }; +} +export async function loadConfig(cwd: string): Promise { + const { configPath, userConfig } = await loadUserConfig(cwd); await validateConfig(userConfig); - const useBuiltinForc = userConfig.useBuiltinForc ?? shouldUseBuiltinForc(); - const useBuiltinFuelCore = userConfig.useBuiltinFuelCore ?? shouldUseBuiltinFuelCore(); - const { forcBuildFlags = [] } = userConfig; const releaseFlag = forcBuildFlags.find((f) => f === '--release'); const buildMode = releaseFlag ? 'release' : 'debug'; + const { forcPath, fuelCorePath } = tryFindBinaries({ + forcPath: userConfig.forcPath, + fuelCorePath: userConfig.fuelCorePath, + }); + // Start clone-object while initializing optional props const config: FuelsConfig = { contracts: [], @@ -60,8 +67,8 @@ export async function loadConfig(cwd: string): Promise { privateKey: defaultConsensusKey, ...userConfig, basePath: cwd, - useBuiltinForc, - useBuiltinFuelCore, + forcPath, + fuelCorePath, configPath, forcBuildFlags, buildMode, diff --git a/packages/fuels/src/cli/templates/fuels.config.hbs b/packages/fuels/src/cli/templates/fuels.config.hbs index 7971ad4f8ef..dc351121c38 100644 --- a/packages/fuels/src/cli/templates/fuels.config.hbs +++ b/packages/fuels/src/cli/templates/fuels.config.hbs @@ -27,11 +27,11 @@ export default createConfig({ {{/if}} {{/if}} output: '{{output}}', - {{#if (isDefined useBuiltinForc)}} - useBuiltinForc: {{useBuiltinForc}}, + {{#if (isDefined forcPath)}} + forcPath: '{{forcPath}}', {{/if}} - {{#if (isDefined useBuiltinFuelCore)}} - useBuiltinFuelCore: {{useBuiltinFuelCore}}, + {{#if (isDefined fuelCorePath)}} + fuelCorePath: '{{fuelCorePath}}', {{/if}} {{#if (isDefined autoStartFuelCore)}} autoStartFuelCore: {{autoStartFuelCore}}, @@ -40,5 +40,5 @@ export default createConfig({ /** * Check the docs: - * https://fuellabs.github.io/fuels-ts/tooling/cli/fuels/config-file + * https://docs.fuel.network/docs/fuels-ts/fuels-cli/config-file/ */ diff --git a/packages/fuels/src/cli/templates/fuels.config.ts b/packages/fuels/src/cli/templates/fuels.config.ts index 1e6951d8584..71930e975a9 100644 --- a/packages/fuels/src/cli/templates/fuels.config.ts +++ b/packages/fuels/src/cli/templates/fuels.config.ts @@ -13,8 +13,8 @@ export function renderFuelsConfigTemplate(props: { scripts?: string[]; predicates?: string[]; output: string; - useBuiltinForc?: boolean; - useBuiltinFuelCore?: boolean; + forcPath?: string; + fuelCorePath?: string; autoStartFuelCore?: boolean; }) { const renderTemplate = Handlebars.compile(fuelsConfigTemplate, { diff --git a/packages/fuels/src/cli/types.ts b/packages/fuels/src/cli/types.ts index 9527b69bfef..b4c8d007c91 100644 --- a/packages/fuels/src/cli/types.ts +++ b/packages/fuels/src/cli/types.ts @@ -5,6 +5,7 @@ export enum Commands { deploy = 'deploy', dev = 'dev', init = 'init', + versions = 'versions', } export type CommandEvent = @@ -23,6 +24,10 @@ export type CommandEvent = | { type: Commands.init; data: unknown; + } + | { + type: Commands.versions; + data: unknown; }; export type DeployedContract = { @@ -75,15 +80,15 @@ export type UserFuelsConfig = { /** Static of dyanmic deploy configs to be used when deploying contracts */ deployConfig?: DeployContractOptions | OptionsFunction; - /** Opt-in or out from using builtin Forc binaries */ - useBuiltinForc?: boolean; - - /** Opt-in or out from using builtin Fuel Core binaries */ - useBuiltinFuelCore?: boolean; - /** If set to false, you will need to spin up a Fuel core node by yourself */ autoStartFuelCore?: boolean; + /** If set, will use absolute path to forc binary */ + forcPath?: string; + + /** If set, will use absolute path to forc binary */ + fuelCorePath?: string; + /** * Port to use when starting a `fuel-core` node * Default: first free port, starting from 4000 @@ -121,9 +126,9 @@ export type FuelsConfig = UserFuelsConfig & | 'predicates' | 'scripts' | 'deployConfig' - | 'useBuiltinForc' - | 'useBuiltinFuelCore' | 'autoStartFuelCore' + | 'forcPath' + | 'fuelCorePath' | 'providerUrl' | 'forcBuildFlags' > diff --git a/packages/fuels/src/cli/utils/getBinarySource.ts b/packages/fuels/src/cli/utils/getBinarySource.ts deleted file mode 100644 index 6323d447807..00000000000 --- a/packages/fuels/src/cli/utils/getBinarySource.ts +++ /dev/null @@ -1,7 +0,0 @@ -import chalk from 'chalk'; - -export const getBinarySource = (useBuiltIn: boolean) => - ({ - true: chalk.cyan('built-in'), - false: chalk.green('source'), - })[`${useBuiltIn}`]; diff --git a/packages/fuels/test/features/build.test.ts b/packages/fuels/test/features/build.test.ts index ebc7c8049b6..ff473a2f7f2 100644 --- a/packages/fuels/test/features/build.test.ts +++ b/packages/fuels/test/features/build.test.ts @@ -41,6 +41,8 @@ describe( root: paths.root, workspace: paths.workspaceDir, output: paths.outputDir, + forcPath: paths.forcPath, + fuelCorePath: paths.fuelCorePath, }); await runBuild({ root: paths.root }); @@ -76,6 +78,8 @@ describe( root: paths.root, contracts: paths.contractsDir, output: paths.outputDir, + forcPath: paths.forcPath, + fuelCorePath: paths.fuelCorePath, }); await runBuild({ root: paths.root }); @@ -102,6 +106,8 @@ describe( root: paths.root, workspace: paths.workspaceDir, output: paths.outputDir, + forcPath: paths.forcPath, + fuelCorePath: paths.fuelCorePath, }); await runBuild({ root: paths.root, deploy: true }); @@ -118,6 +124,8 @@ describe( root: paths.root, workspace: paths.workspaceDir, output: paths.outputDir, + forcPath: paths.forcPath, + fuelCorePath: paths.fuelCorePath, }); // inject `forcBuildFlags: ['--release']` in config file diff --git a/packages/fuels/test/features/deploy.test.ts b/packages/fuels/test/features/deploy.test.ts index 444c46b0214..f3f75f89f9a 100644 --- a/packages/fuels/test/features/deploy.test.ts +++ b/packages/fuels/test/features/deploy.test.ts @@ -30,6 +30,8 @@ describe( root: paths.root, workspace: paths.workspaceDir, output: paths.outputDir, + forcPath: paths.forcPath, + fuelCorePath: paths.fuelCorePath, }); await runBuild({ root: paths.root }); diff --git a/packages/fuels/test/features/dev.test.ts b/packages/fuels/test/features/dev.test.ts index bb4daaa47a9..832e7917432 100644 --- a/packages/fuels/test/features/dev.test.ts +++ b/packages/fuels/test/features/dev.test.ts @@ -52,6 +52,8 @@ describe('dev', () => { root: paths.root, workspace: paths.workspaceDir, output: paths.outputDir, + forcPath: paths.forcPath, + fuelCorePath: paths.fuelCorePath, }); await runDev({ root: paths.root }); diff --git a/packages/fuels/test/features/init.test.ts b/packages/fuels/test/features/init.test.ts index 3f111cd75d5..39e494390ed 100644 --- a/packages/fuels/test/features/init.test.ts +++ b/packages/fuels/test/features/init.test.ts @@ -40,24 +40,25 @@ describe('init', () => { const fuelsContents = readFileSync(paths.fuelsConfigPath, 'utf-8'); expect(fuelsContents).toMatch(`workspace: './workspace',`); expect(fuelsContents).toMatch(`output: './output',`); - expect(fuelsContents).not.toMatch(`useBuiltinForc: true,`); - expect(fuelsContents).not.toMatch(`useBuiltinFuelCore: true,`); + expect(fuelsContents).not.toMatch(`forcPath: 'fuels-forc',`); + expect(fuelsContents).not.toMatch(`fuelCorePath: 'fuels-core',`); }); - it('should run `init` command using built-in flags', async () => { + it('should run `init` command using custom binaries', async () => { await runInit({ root: paths.root, workspace: paths.workspaceDir, output: paths.outputDir, - useBuiltinBinaries: true, + forcPath: paths.forcPath, + fuelCorePath: paths.fuelCorePath, }); expect(existsSync(paths.fuelsConfigPath)).toBeTruthy(); const fuelsContents = readFileSync(paths.fuelsConfigPath, 'utf-8'); expect(fuelsContents).toMatch(`workspace: './workspace',`); expect(fuelsContents).toMatch(`output: './output',`); - expect(fuelsContents).toMatch(`useBuiltinForc: true,`); - expect(fuelsContents).toMatch(`useBuiltinFuelCore: true,`); + expect(fuelsContents).toMatch(`forcPath: 'fuels-forc',`); + expect(fuelsContents).toMatch(`fuelCorePath: 'fuels-core',`); }); it('should run `init` command and throw for existent config file', async () => { diff --git a/packages/fuels/test/fixtures/fuels.config.ts b/packages/fuels/test/fixtures/fuels.config.ts index 2e201acff51..ce52f7fe227 100644 --- a/packages/fuels/test/fixtures/fuels.config.ts +++ b/packages/fuels/test/fixtures/fuels.config.ts @@ -16,9 +16,9 @@ export const fuelsConfig: FuelsConfig = { scripts: [join(scriptsDir, 'script')], predicates: [join(predicatesDir, 'predicate')], output: '/output', + forcPath: 'fuels-forc', + fuelCorePath: 'fuels-core', deployConfig: {}, - useBuiltinForc: false, - useBuiltinFuelCore: false, autoStartFuelCore: true, fuelCorePort: 4000, providerUrl: FUEL_NETWORK_URL, diff --git a/packages/fuels/test/utils/runCommands.ts b/packages/fuels/test/utils/runCommands.ts index 37b3337bd56..57d47e8c829 100644 --- a/packages/fuels/test/utils/runCommands.ts +++ b/packages/fuels/test/utils/runCommands.ts @@ -48,6 +48,9 @@ export function bootstrapProject(testFilepath: string) { const contractsJsonPath = join(outputDir, 'contract-ids.json'); const fooContractFactoryPath = join(outputDir, 'contracts', 'factories', 'FooBarAbi__factory.ts'); + const forcPath = 'fuels-forc'; + const fuelCorePath = 'fuels-core'; + return { root, workspaceDir, @@ -60,6 +63,8 @@ export function bootstrapProject(testFilepath: string) { outputDir, contractsJsonPath, fooContractFactoryPath, + forcPath, + fuelCorePath, }; } @@ -82,7 +87,8 @@ export type InitParams = BaseParams & { scripts?: string; predicates?: string; output: string; - useBuiltinBinaries?: boolean; + forcPath?: string; + fuelCorePath?: string; autoStartFuelCore?: boolean; build?: boolean; }; @@ -99,7 +105,8 @@ export async function runInit(params: InitParams) { predicates, root, scripts, - useBuiltinBinaries, + forcPath, + fuelCorePath, workspace, } = params; @@ -113,7 +120,8 @@ export async function runInit(params: InitParams) { flag(['--contracts', contracts], contracts), flag(['--scripts', scripts], scripts), flag(['--predicates', predicates], predicates), - flag(['--use-builtin-forc', '--use-builtin-fuel-core'], useBuiltinBinaries), + flag(['--forc-path', forcPath], forcPath), + flag(['--fuel-core-path', fuelCorePath], fuelCorePath), flag(['--auto-start-fuel-core'], autoStartFuelCore), ].flat(); diff --git a/packages/script/package.json b/packages/script/package.json index adf095d3783..12cf02bd2b0 100644 --- a/packages/script/package.json +++ b/packages/script/package.json @@ -38,6 +38,6 @@ "@fuel-ts/utils": "workspace:*" }, "devDependencies": { - "@fuel-ts/forc": "workspace:*" + "@internal/forc": "workspace:*" } } diff --git a/packages/utils/package.json b/packages/utils/package.json index 561113cf958..e86c6ffaa8e 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -49,6 +49,7 @@ "dependencies": { "@fuel-ts/errors": "workspace:*", "@fuel-ts/interfaces": "workspace:*", - "@fuel-ts/math": "workspace:*" + "@fuel-ts/math": "workspace:*", + "@fuel-ts/versions": "workspace:*" } } diff --git a/packages/utils/src/cli-utils.ts b/packages/utils/src/cli-utils.ts index eaac016729a..01bf43b5e2a 100644 --- a/packages/utils/src/cli-utils.ts +++ b/packages/utils/src/cli-utils.ts @@ -1 +1 @@ -export * from './cli-utils/findBinPath'; +export * from './cli-utils/tryFindBinaries'; diff --git a/packages/utils/src/cli-utils/findBinPath.test.ts b/packages/utils/src/cli-utils/findBinPath.test.ts deleted file mode 100644 index 48c1247299a..00000000000 --- a/packages/utils/src/cli-utils/findBinPath.test.ts +++ /dev/null @@ -1,63 +0,0 @@ -import { safeExec } from '@fuel-ts/errors/test-utils'; -import { mkdirSync, rmSync, writeFileSync } from 'fs'; -import { join } from 'path'; - -import { findBinPath } from './findBinPath'; - -/** - * @group node - */ -describe('findBinPath', () => { - const bootstrap = (dir: string) => { - const cmdName = 'my-cmd'; - const mods = join(dir, 'node_modules'); - const bin = join(mods, '.bin'); - const cmdPath = join(bin, cmdName); - - const resetDisk = (params?: { cmdOnly: boolean }) => { - if (params?.cmdOnly) { - rmSync(cmdPath); - } else { - rmSync(mods, { recursive: true }); - } - }; - - mkdirSync(bin, { recursive: true }); - writeFileSync(cmdPath, ''); - - return { resetDisk, mods, cmdName, cmdPath }; - }; - - it('should find bin path in current dir', () => { - const base = __dirname; // current dir - const { cmdName, cmdPath, resetDisk } = bootstrap(base); - const binPath = findBinPath(cmdName, base); - - resetDisk(); - expect(binPath).toEqual(cmdPath); - }); - - it('should find bin path one dir up', () => { - const base = join(__dirname, '..'); // one dir up - const { cmdName, cmdPath, resetDisk } = bootstrap(base); - const binPath = findBinPath(cmdName, base); - - resetDisk(); - expect(binPath).toEqual(cmdPath); - }); - - it('should find bin path two dir up', () => { - const base = join(__dirname, '..', '..'); // two dirs up - const { cmdName, cmdPath, resetDisk } = bootstrap(base); - const binPath = findBinPath(cmdName, base); - - resetDisk({ cmdOnly: true }); - expect(binPath).toEqual(cmdPath); - }); - - it('should throw for bin path not found', async () => { - const cmdName = 'non-existent'; - const { error } = await safeExec(() => findBinPath(cmdName, __dirname)); - expect(error?.message).toEqual(`Command not found: ${cmdName}`); - }); -}); diff --git a/packages/utils/src/cli-utils/findBinPath.ts b/packages/utils/src/cli-utils/findBinPath.ts deleted file mode 100644 index 7f255e01bd1..00000000000 --- a/packages/utils/src/cli-utils/findBinPath.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { existsSync } from 'fs'; -import { join } from 'path'; - -export const findBinPath = (binCommandName: string, startingDir: string): string => { - const cmdPath = join(startingDir, 'node_modules', '.bin', binCommandName); - const parentDir = join(startingDir, '..'); - - if (existsSync(cmdPath)) { - return cmdPath; - } - - if (parentDir === startingDir) { - throw new Error(`Command not found: ${binCommandName}`); - } - - return findBinPath(binCommandName, parentDir); -}; diff --git a/packages/utils/src/cli-utils/tryFindBinaries.test.ts b/packages/utils/src/cli-utils/tryFindBinaries.test.ts new file mode 100644 index 00000000000..9dfb07b36fd --- /dev/null +++ b/packages/utils/src/cli-utils/tryFindBinaries.test.ts @@ -0,0 +1,144 @@ +import { safeExec } from '@fuel-ts/errors/test-utils'; +import * as versionsCliMod from '@fuel-ts/versions/cli'; +import * as childProcessMod from 'child_process'; + +import { tryFindBinaries } from './tryFindBinaries'; + +vi.mock('child_process', async () => { + const mod = await vi.importActual('child_process'); + return { + __esModule: true, + ...mod, + }; +}); + +const mockAllDeps = ( + params: { + compatibleVersion?: string; + forcError?: boolean; + forcVersion?: string; + fuelCoreError?: boolean; + fuelCoreVersion?: string; + } = {} +) => { + const { forcError, forcVersion, fuelCoreError, fuelCoreVersion } = params; + + const compatibleVersion = params.compatibleVersion ?? '1.0.0'; + + const execSyncError = vi.fn(() => { + throw new Error(); + }); + + const getSystemForc = vi.spyOn(versionsCliMod, 'getSystemForc'); + vi.spyOn(childProcessMod, 'execSync').mockImplementationOnce( + forcError ? execSyncError : vi.fn().mockReturnValue(forcVersion ?? compatibleVersion) + ); + + const getSystemFuelCore = vi.spyOn(versionsCliMod, 'getSystemFuelCore'); + vi.spyOn(childProcessMod, 'execSync').mockImplementationOnce( + fuelCoreError ? execSyncError : vi.fn().mockReturnValue(fuelCoreVersion ?? compatibleVersion) + ); + + const getBuiltinVersions = vi.spyOn(versionsCliMod, 'getBuiltinVersions').mockReturnValue({ + FORC: compatibleVersion, + FUEL_CORE: compatibleVersion, + FUELS: compatibleVersion, + }); + + const warn = vi.spyOn(console, 'warn').mockImplementation(() => {}); + + return { + warn, + getSystemForc, + getSystemFuelCore, + getBuiltinVersions, + }; +}; + +/** + * @group node + */ +describe('tryFindBinaries', () => { + it(`should use default binaries when not paths supplied`, () => { + const { getSystemForc, getSystemFuelCore } = mockAllDeps(); + + const binaries = tryFindBinaries(); + + expect(getSystemForc).toHaveBeenCalledTimes(1); + expect(getSystemForc).toBeCalledWith(undefined); + expect(getSystemFuelCore).toHaveBeenCalledTimes(1); + expect(getSystemFuelCore).toBeCalledWith(undefined); + expect(binaries.forcPath).toEqual('forc'); + expect(binaries.fuelCorePath).toEqual('fuel-core'); + }); + + it(`should use custom binaries when paths supplied`, () => { + const { getSystemForc, getSystemFuelCore } = mockAllDeps(); + + const forcPath = '/some/path/to/forc'; + const fuelCorePath = '/some/path/to/fuel-core'; + + const binaries = tryFindBinaries({ forcPath, fuelCorePath }); + + expect(getSystemForc).toHaveBeenCalledTimes(1); + expect(getSystemForc).toBeCalledWith(forcPath); + expect(getSystemFuelCore).toHaveBeenCalledTimes(1); + expect(getSystemFuelCore).toBeCalledWith(fuelCorePath); + expect(binaries.forcPath).toEqual(forcPath); + expect(binaries.fuelCorePath).toEqual(fuelCorePath); + }); + + it('should handle undefined paths', () => { + const { getSystemForc, getSystemFuelCore } = mockAllDeps(); + + const binaries = tryFindBinaries({ forcPath: undefined, fuelCorePath: undefined }); + + expect(getSystemForc).toHaveBeenCalledTimes(1); + expect(getSystemForc).toBeCalledWith(undefined); + expect(getSystemFuelCore).toHaveBeenCalledTimes(1); + expect(getSystemFuelCore).toBeCalledWith(undefined); + expect(binaries.forcPath).toEqual('forc'); + expect(binaries.fuelCorePath).toEqual('fuel-core'); + }); + + it(`should throw when binaries are not found`, async () => { + const forcPath = '/non/existent/path/to/forc'; + const fuelCorePath = '/non/existent/path/to/fuel-core'; + const { getSystemForc, getSystemFuelCore } = mockAllDeps({ + forcError: true, + fuelCoreError: true, + }); + + const { error } = await safeExec(() => tryFindBinaries({ forcPath, fuelCorePath })); + + expect(getSystemForc).toHaveBeenCalledTimes(1); + expect(getSystemFuelCore).toHaveBeenCalledTimes(1); + expect(error?.message).toContain(`Unable to find the following binaries on the filesystem`); + expect(error?.message).toContain(`'forc' at path '${forcPath}'`); + expect(error?.message).toContain(`'fuel-core' at path '${fuelCorePath}'`); + expect(error?.message).toContain( + 'Visit https://docs.fuel.network/guides/installation/ for an installation guide.' + ); + }); + + it(`should warn the user when binaries are outdated`, () => { + const compatibleVersion = '1.0.0'; + const currentVersion = '0.0.1'; + const expectedMessage = [ + `The following binaries on the filesystem are outdated:`, + ` -> 'forc' is currently 'v${currentVersion}', but the current 'fuels' version requires 'v${compatibleVersion}'.`, + ` -> 'fuel-core' is currently 'v${currentVersion}', but the current 'fuels' version requires 'v${compatibleVersion}'.`, + ].join('\n'); + const { warn, getSystemForc, getSystemFuelCore } = mockAllDeps({ + compatibleVersion, + forcVersion: currentVersion, + fuelCoreVersion: currentVersion, + }); + + tryFindBinaries(); + + expect(getSystemForc).toHaveBeenCalledTimes(1); + expect(getSystemFuelCore).toHaveBeenCalledTimes(1); + expect(warn).toBeCalledWith(expectedMessage); + }); +}); diff --git a/packages/utils/src/cli-utils/tryFindBinaries.ts b/packages/utils/src/cli-utils/tryFindBinaries.ts new file mode 100644 index 00000000000..c7901371919 --- /dev/null +++ b/packages/utils/src/cli-utils/tryFindBinaries.ts @@ -0,0 +1,68 @@ +import { FuelError } from '@fuel-ts/errors'; +import { + compareSystemVersions, + eitherOr, + getSystemForc, + getSystemFuelCore, + getBuiltinVersions, +} from '@fuel-ts/versions/cli'; + +/** + * Tries to find compatible binaries on the filesystem, otherwise throws an error. + * + * @param paths - paths to the binaries (optional) + * @returns - paths to the resolved binaries + */ +export const tryFindBinaries = (paths: { forcPath?: string; fuelCorePath?: string } = {}) => { + // Ensure we can get the binary versions + const { error: forcError, systemForcPath, systemForcVersion } = getSystemForc(paths.forcPath); + + const { + error: fuelCoreError, + systemFuelCorePath, + systemFuelCoreVersion, + } = getSystemFuelCore(paths.fuelCorePath); + + if (forcError || fuelCoreError) { + const errors = [ + 'Unable to find the following binaries on the filesystem:', + forcError ? ` -> 'forc' at path '${systemForcPath}'` : undefined, + fuelCoreError ? ` -> 'fuel-core' at path '${systemFuelCorePath}'` : undefined, + `\nVisit https://docs.fuel.network/guides/installation/ for an installation guide.`, + ]; + + throw new FuelError( + FuelError.CODES.BIN_FILE_NOT_FOUND, + `${errors.filter(Boolean).join('\n')}`, + { ...paths } + ); + } + + const { systemForcIsLt, systemFuelCoreIsLt } = compareSystemVersions({ + systemForcVersion: eitherOr(systemForcVersion, '0'), + systemFuelCoreVersion: eitherOr(systemFuelCoreVersion, '0'), + }); + + if (systemForcIsLt || systemFuelCoreIsLt) { + const { FORC: compatibleForcVersion, FUEL_CORE: compatibleFuelCoreVersion } = + getBuiltinVersions(); + + const errors = [ + 'The following binaries on the filesystem are outdated:', + systemForcIsLt + ? ` -> '${systemForcPath}' is currently 'v${systemForcVersion}', but the current 'fuels' version requires 'v${compatibleForcVersion}'.` + : undefined, + systemFuelCoreIsLt + ? ` -> '${systemFuelCorePath}' is currently 'v${systemFuelCoreVersion}', but the current 'fuels' version requires 'v${compatibleFuelCoreVersion}'.` + : undefined, + ]; + + // eslint-disable-next-line no-console + console.warn(`${errors.filter(Boolean).join('\n')}`); + } + + return { + forcPath: systemForcPath, + fuelCorePath: systemFuelCorePath, + }; +}; diff --git a/packages/versions/README.md b/packages/versions/README.md index 717348e25c6..708f47bb4cd 100644 --- a/packages/versions/README.md +++ b/packages/versions/README.md @@ -5,8 +5,8 @@ It automatically assembles all supported versions of the Fuel toolchain, including: - `FUELS` — comes from `/packages/fuels/package.json` -- `FUEL_CORE` — comes from `/packages/fuel-core/VERSION` -- `FORC` — comes from `/packages/forc/VERSION` +- `FUEL_CORE` — comes from `/internal/fuel-core/VERSION` +- `FORC` — comes from `/internal/forc/VERSION` There is a `prebuild` script to ensure that the `src/index.ts` file never goes outdated. diff --git a/packages/versions/scripts/rewriteVersions.ts b/packages/versions/scripts/rewriteVersions.ts index 4c3997668e2..36ba9394f5f 100644 --- a/packages/versions/scripts/rewriteVersions.ts +++ b/packages/versions/scripts/rewriteVersions.ts @@ -3,16 +3,17 @@ import { join } from 'path'; export const readVersionsFromFiles = () => { const rootDir = join(__dirname, '../../..'); + const internalDir = join(rootDir, 'internal'); const packagesDir = join(rootDir, 'packages'); const firstLineReg = /^.+$/m; // forc - const forcPath = join(packagesDir, 'forc', 'VERSION'); + const forcPath = join(internalDir, 'forc', 'VERSION'); const forcVersion = readFileSync(forcPath, 'utf8').match(firstLineReg)?.[0]; // fuel-core - const fuelCorePath = join(packagesDir, 'fuel-core', 'VERSION'); + const fuelCorePath = join(internalDir, 'fuel-core', 'VERSION'); const fuelCoreVersion = readFileSync(fuelCorePath, 'utf8').match(firstLineReg)?.[0]; // fuels diff --git a/packages/versions/src/cli.test.ts b/packages/versions/src/cli.test.ts index 7b3e36145d6..64a905f40a1 100644 --- a/packages/versions/src/cli.test.ts +++ b/packages/versions/src/cli.test.ts @@ -58,6 +58,8 @@ describe('cli.js', () => { error: systemVersionsError, systemForcVersion, systemFuelCoreVersion, + systemForcPath: 'forc', + systemFuelCorePath: 'fuel-core', })); vi.spyOn(getBuiltinVersionsMod, 'getBuiltinVersions').mockImplementation(() => ({ diff --git a/packages/versions/src/cli.ts b/packages/versions/src/cli.ts index 09cf858b3f5..f15697b1bb5 100644 --- a/packages/versions/src/cli.ts +++ b/packages/versions/src/cli.ts @@ -10,19 +10,26 @@ import { getSystemVersions } from './lib/getSystemVersions'; export * from './lib/compareSystemVersions'; export * from './lib/fuelUpLink'; export * from './lib/getSystemVersions'; +export * from './lib/getBuiltinVersions'; export const eitherOr = (val1: string | null, val2: string) => val1 ?? val2; -export function runVersions() { +export function runVersions(params: { forcPath?: string; fuelCorePath?: string } = {}) { const { error, info } = console; const supportedVersions = getBuiltinVersions(); const cliTable = new CliTable({ - head: ['', chalk.bold('Supported'), chalk.bold(`Yours / System`)], + head: ['', chalk.bold('Supported'), chalk.bold(`Yours / System`), chalk.bold('System Path')], }); - const { error: systemError, systemForcVersion, systemFuelCoreVersion } = getSystemVersions(); + const { + error: systemError, + systemForcVersion, + systemFuelCoreVersion, + systemForcPath, + systemFuelCorePath, + } = getSystemVersions(params); const comparisons = compareSystemVersions({ systemForcVersion: eitherOr(systemForcVersion, '0'), @@ -41,8 +48,13 @@ export function runVersions() { isOk: comparisons.systemFuelCoreIsEq, }); - cliTable.push(['Forc', supportedVersions.FORC, userForcColorized]); - cliTable.push(['Fuel-Core', supportedVersions.FUEL_CORE, userFuelCoreColorized]); + cliTable.push(['Forc', supportedVersions.FORC, userForcColorized, systemForcPath]); + cliTable.push([ + 'Fuel-Core', + supportedVersions.FUEL_CORE, + userFuelCoreColorized, + systemFuelCorePath, + ]); const someIsGt = comparisons.systemForcIsGt || comparisons.systemFuelCoreIsGt; const bothAreExact = comparisons.systemForcIsEq && comparisons.systemFuelCoreIsEq; diff --git a/packages/versions/src/index.ts b/packages/versions/src/index.ts index 1936481f6e6..4c14514fe13 100644 --- a/packages/versions/src/index.ts +++ b/packages/versions/src/index.ts @@ -2,8 +2,8 @@ 1) Variables ------------ `FUELS` — comes from `/packages/fuels/package.json` - `FUEL_CORE` — comes from `/packages/fuel-core/VERSION` - `FORC` — comes from `/packages/forc/VERSION` + `FUEL_CORE` — comes from `/internal/fuel-core/VERSION` + `FORC` — comes from `/internal/forc/VERSION` 3) Pre Build ------------ diff --git a/packages/versions/src/lib/compareSystemVersions.test.ts b/packages/versions/src/lib/compareSystemVersions.test.ts index e4003a7b5d2..6863d24157b 100644 --- a/packages/versions/src/lib/compareSystemVersions.test.ts +++ b/packages/versions/src/lib/compareSystemVersions.test.ts @@ -29,9 +29,11 @@ describe('compareSystemVersions.js', () => { expect(comparisons.systemForcIsGt).toEqual(true); expect(comparisons.systemForcIsEq).toEqual(false); + expect(comparisons.systemForcIsLt).toEqual(false); expect(comparisons.systemFuelCoreIsGt).toEqual(true); expect(comparisons.systemFuelCoreIsEq).toEqual(false); + expect(comparisons.systemFuelCoreIsLt).toEqual(false); }); test('should compare against: exact versions', () => { @@ -42,9 +44,11 @@ describe('compareSystemVersions.js', () => { expect(comparisons.systemForcIsGt).toEqual(false); expect(comparisons.systemForcIsEq).toEqual(true); + expect(comparisons.systemForcIsLt).toEqual(false); expect(comparisons.systemFuelCoreIsGt).toEqual(false); expect(comparisons.systemFuelCoreIsEq).toEqual(true); + expect(comparisons.systemFuelCoreIsLt).toEqual(false); }); test('should compare against: older versions', () => { @@ -55,8 +59,10 @@ describe('compareSystemVersions.js', () => { expect(comparisons.systemForcIsGt).toEqual(false); expect(comparisons.systemForcIsEq).toEqual(false); + expect(comparisons.systemForcIsLt).toEqual(true); expect(comparisons.systemFuelCoreIsGt).toEqual(false); expect(comparisons.systemFuelCoreIsEq).toEqual(false); + expect(comparisons.systemFuelCoreIsLt).toEqual(true); }); }); diff --git a/packages/versions/src/lib/compareSystemVersions.ts b/packages/versions/src/lib/compareSystemVersions.ts index 12f47794091..690deabdd46 100644 --- a/packages/versions/src/lib/compareSystemVersions.ts +++ b/packages/versions/src/lib/compareSystemVersions.ts @@ -19,10 +19,16 @@ export function compareSystemVersions(params: ICompareVersionsParams) { const systemForcIsEq = eq(systemForcVersion, versions.FORC); const systemFuelCoreIsEq = eq(systemFuelCoreVersion, versions.FUEL_CORE); + // are user's versions LESS than the ones supported by the SDK? + const systemForcIsLt = !systemForcIsGt && !systemForcIsEq; + const systemFuelCoreIsLt = !systemFuelCoreIsGt && !systemFuelCoreIsEq; + return { systemForcIsGt, systemFuelCoreIsGt, systemForcIsEq, systemFuelCoreIsEq, + systemForcIsLt, + systemFuelCoreIsLt, }; } diff --git a/packages/versions/src/lib/getSystemVersions.test.ts b/packages/versions/src/lib/getSystemVersions.test.ts index 85d09234ccb..6771be7729f 100644 --- a/packages/versions/src/lib/getSystemVersions.test.ts +++ b/packages/versions/src/lib/getSystemVersions.test.ts @@ -10,43 +10,40 @@ vi.mock('child_process', async () => { }; }); -/** - * @group node - */ -describe('getSystemVersions.js', () => { - /* - Test (mocking) utility - */ - function mockAllDeps(params: { - systemForcVersion: string; - systemFuelCoreVersion: string; - shouldThrow?: boolean; - }) { - const { systemForcVersion, systemFuelCoreVersion, shouldThrow } = params; - - const error = vi.spyOn(console, 'error').mockImplementation(() => []); - - const mockedExecOk = vi.fn(); - mockedExecOk.mockReturnValueOnce(systemForcVersion); // first call (forc) - mockedExecOk.mockReturnValueOnce(systemFuelCoreVersion); // second call (fuel-core) - - const execSyncThrow = vi.fn(() => { - throw new Error(); - }); +/* + Test (mocking) utility +*/ +function mockAllDeps(params: { + systemForcVersion: string; + systemFuelCoreVersion: string; + shouldThrow?: boolean; +}) { + const { systemForcVersion, systemFuelCoreVersion, shouldThrow } = params; + + const error = vi.spyOn(console, 'error').mockImplementation(() => []); + + const mockedExecOk = vi.fn(); + mockedExecOk.mockReturnValueOnce(systemForcVersion); // first call (forc) + mockedExecOk.mockReturnValueOnce(systemFuelCoreVersion); // second call (fuel-core) + + const execSyncThrow = vi.fn(() => { + throw new Error(); + }); - const execSync = vi - .spyOn(childProcessMod, 'execSync') - .mockImplementation(shouldThrow ? execSyncThrow : mockedExecOk); + const execSync = vi + .spyOn(childProcessMod, 'execSync') + .mockImplementation(shouldThrow ? execSyncThrow : mockedExecOk); - return { - error, - execSync, - }; - } + return { + error, + execSync, + }; +} - /* - Tests - */ +/** + * @group node + */ +describe('getSystemVersions', () => { test('should get user versions just fine', () => { // mocking const systemForcVersion = '1.0.0'; @@ -61,16 +58,19 @@ describe('getSystemVersions.js', () => { // validating expect(execSync).toHaveBeenCalledTimes(2); + expect(execSync).toBeCalledWith(`forc --version`, expect.any(Object)); + expect(execSync).toBeCalledWith(`fuel-core --version`, expect.any(Object)); expect(versions.systemForcVersion).toEqual(systemForcVersion); expect(versions.systemFuelCoreVersion).toEqual(systemFuelCoreVersion); + expect(versions.systemForcPath).toEqual('forc'); + expect(versions.systemFuelCorePath).toEqual('fuel-core'); }); test('should return error if Forc or Fuel-Core is not installed', () => { // mocking const systemForcVersion = '1.0.0'; const systemFuelCoreVersion = '2.0.0'; - - mockAllDeps({ + const { execSync } = mockAllDeps({ systemForcVersion, systemFuelCoreVersion, shouldThrow: true, @@ -80,6 +80,9 @@ describe('getSystemVersions.js', () => { const { error: systemError } = getSystemVersions(); // validating + expect(execSync).toHaveBeenCalledTimes(2); + expect(execSync).toBeCalledWith(`forc --version`, expect.any(Object)); + expect(execSync).toBeCalledWith(`fuel-core --version`, expect.any(Object)); expect(systemError).toBeTruthy(); }); @@ -97,8 +100,35 @@ describe('getSystemVersions.js', () => { // validating expect(execSync).toHaveBeenCalledTimes(2); + expect(execSync).toBeCalledWith(`forc --version`, expect.any(Object)); + expect(execSync).toBeCalledWith(`fuel-core --version`, expect.any(Object)); expect(versions.error?.toString()).toEqual(`Error: ${systemForcVersion}`); expect(versions.systemForcVersion).toEqual(null); expect(versions.systemFuelCoreVersion).toEqual(null); }); + + it('should be able to use custom binary paths', () => { + // mocking + const systemForcVersion = '1.0.0'; + const systemFuelCoreVersion = '2.0.0'; + const { execSync } = mockAllDeps({ + systemForcVersion, + systemFuelCoreVersion, + }); + + // executing + const versions = getSystemVersions({ + forcPath: '/path/to/custom/forc', + fuelCorePath: '/path/to/custom/fuel-core', + }); + + // validating + expect(execSync).toHaveBeenCalledTimes(2); + expect(execSync).toBeCalledWith(`/path/to/custom/forc --version`, expect.any(Object)); + expect(execSync).toBeCalledWith(`/path/to/custom/fuel-core --version`, expect.any(Object)); + expect(versions.systemForcVersion).toEqual(systemForcVersion); + expect(versions.systemFuelCoreVersion).toEqual(systemFuelCoreVersion); + expect(versions.systemForcPath).toEqual('/path/to/custom/forc'); + expect(versions.systemFuelCorePath).toEqual('/path/to/custom/fuel-core'); + }); }); diff --git a/packages/versions/src/lib/getSystemVersions.ts b/packages/versions/src/lib/getSystemVersions.ts index 86ea4a2b63c..ee9a883b2da 100644 --- a/packages/versions/src/lib/getSystemVersions.ts +++ b/packages/versions/src/lib/getSystemVersions.ts @@ -1,13 +1,18 @@ import { execSync } from 'child_process'; const versionReg = /[0-9]+\.[0-9]+\.[0-9]/; +const defaultForcCommand = 'forc'; +const defaultFuelCoreCommand = 'fuel-core'; export const getSystemVersion = (command: string) => { let version: string | null = null; let error: Error | null = null; try { - const contents = execSync(command).toString(); + const contents = execSync(command, { + stdio: ['pipe', 'pipe', 'ignore'], + encoding: 'utf8', + }).toString(); if (versionReg.test(contents)) { version = contents.match(versionReg)?.[0] as string; } else { @@ -23,25 +28,32 @@ export const getSystemVersion = (command: string) => { }; }; -export function getSystemForc() { - const { error, version: v } = getSystemVersion('forc --version'); - return { error, systemForcVersion: v }; +export function getSystemForc(forcPath: string = defaultForcCommand) { + const { error, version: v } = getSystemVersion(`${forcPath} --version`); + return { error, systemForcVersion: v, systemForcPath: forcPath }; } -export function getSystemFuelCore() { - const { error, version: v } = getSystemVersion('fuel-core --version'); - return { error, systemFuelCoreVersion: v }; +export function getSystemFuelCore(fuelCorePath: string = defaultFuelCoreCommand) { + const { error, version: v } = getSystemVersion(`${fuelCorePath} --version`); + return { error, systemFuelCoreVersion: v, systemFuelCorePath: fuelCorePath }; } -export function getSystemVersions() { - const { error: errorForc, systemForcVersion } = getSystemForc(); - const { error: errorCore, systemFuelCoreVersion } = getSystemFuelCore(); +export function getSystemVersions(params: { forcPath?: string; fuelCorePath?: string } = {}) { + const { forcPath, fuelCorePath } = params; + const { error: errorForc, systemForcVersion, systemForcPath } = getSystemForc(forcPath); + const { + error: errorCore, + systemFuelCoreVersion, + systemFuelCorePath, + } = getSystemFuelCore(fuelCorePath); const error = errorForc ?? errorCore; return { error, systemForcVersion, + systemForcPath, systemFuelCoreVersion, + systemFuelCorePath, }; } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6b5cf8a41d0..05c8783c175 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -31,18 +31,15 @@ importers: '@elasticpath/textlint-rule-no-dead-relative-link': specifier: ^1.1.1 version: 1.1.1 - '@fuel-ts/forc': - specifier: workspace:* - version: link:packages/forc - '@fuel-ts/fuel-core': - specifier: workspace:* - version: link:packages/fuel-core '@fuel-ts/utils': specifier: workspace:* version: link:packages/utils - '@fuel-ts/versions': - specifier: workspace:^ - version: link:packages/versions + '@internal/forc': + specifier: workspace:* + version: link:internal/forc + '@internal/fuel-core': + specifier: workspace:* + version: link:internal/fuel-core '@internal/tsup': specifier: workspace:* version: link:internal/tsup @@ -386,9 +383,9 @@ importers: '@fuel-ts/errors': specifier: workspace:* version: link:../../packages/errors - '@fuel-ts/forc': + '@internal/forc': specifier: workspace:* - version: link:../../packages/forc + version: link:../../internal/forc apps/demo-wallet-sdk-react: dependencies: @@ -562,6 +559,18 @@ importers: internal/check-tests: {} + internal/forc: + dependencies: + node-fetch: + specifier: ^2.6.7 + version: 2.7.0 + + internal/fuel-core: + dependencies: + node-fetch: + specifier: ^2.7.0 + version: 2.7.0 + internal/tsup: {} packages/abi-coder: @@ -621,9 +630,9 @@ importers: specifier: ^3.0.2 version: 3.0.2 devDependencies: - '@fuel-ts/forc': + '@internal/forc': specifier: workspace:* - version: link:../forc + version: link:../../internal/forc '@types/mkdirp': specifier: ^1.0.2 version: 1.0.2 @@ -828,18 +837,6 @@ importers: specifier: workspace:* version: link:../versions - packages/forc: - dependencies: - node-fetch: - specifier: ^2.6.7 - version: 2.6.7 - - packages/fuel-core: - dependencies: - node-fetch: - specifier: ^2.7.0 - version: 2.7.0 - packages/fuel-gauge: dependencies: fuels: @@ -852,12 +849,12 @@ importers: '@fuel-ts/errors': specifier: workspace:* version: link:../errors - '@fuel-ts/forc': - specifier: workspace:* - version: link:../forc '@fuel-ts/utils': specifier: workspace:* version: link:../utils + '@internal/forc': + specifier: workspace:* + version: link:../../internal/forc packages/fuels: dependencies: @@ -882,12 +879,6 @@ importers: '@fuel-ts/errors': specifier: workspace:* version: link:../errors - '@fuel-ts/forc': - specifier: workspace:* - version: link:../forc - '@fuel-ts/fuel-core': - specifier: workspace:* - version: link:../fuel-core '@fuel-ts/hasher': specifier: workspace:* version: link:../hasher @@ -1070,9 +1061,9 @@ importers: specifier: workspace:* version: link:../utils devDependencies: - '@fuel-ts/forc': + '@internal/forc': specifier: workspace:* - version: link:../forc + version: link:../../internal/forc packages/transactions: dependencies: @@ -1109,6 +1100,9 @@ importers: '@fuel-ts/math': specifier: workspace:* version: link:../math + '@fuel-ts/versions': + specifier: workspace:* + version: link:../versions packages/versions: dependencies: @@ -8883,15 +8877,6 @@ packages: resolution: {integrity: sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==} engines: {node: '>=10.5.0'} - node-fetch@2.6.7: - resolution: {integrity: sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==} - engines: {node: 4.x || >=6.0.0} - peerDependencies: - encoding: ^0.1.0 - peerDependenciesMeta: - encoding: - optional: true - node-fetch@2.7.0: resolution: {integrity: sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==} engines: {node: 4.x || >=6.0.0} @@ -22209,10 +22194,6 @@ snapshots: node-domexception@1.0.0: {} - node-fetch@2.6.7: - dependencies: - whatwg-url: 5.0.0 - node-fetch@2.7.0: dependencies: whatwg-url: 5.0.0 diff --git a/scripts/forc-check.sh b/scripts/forc-check.sh index 0f10025e1f4..e8c412b9b8c 100755 --- a/scripts/forc-check.sh +++ b/scripts/forc-check.sh @@ -2,7 +2,7 @@ main_dir=$(pwd) forc_tomls=$(find . -type f -name "Forc.toml") -forc_fmt=$(realpath ./packages/forc/forc-binaries/forc-fmt) +forc_fmt=$(realpath ./internal/forc/forc-binaries/forc-fmt) expected_authors="authors = [\"Fuel Labs \"]" ERRORED=0 diff --git a/scripts/forc-format.sh b/scripts/forc-format.sh index 8c151534ff5..20f95316610 100755 --- a/scripts/forc-format.sh +++ b/scripts/forc-format.sh @@ -2,7 +2,7 @@ main_dir=$(pwd) forc_tomls=$(find . -type f -name "Forc.toml") -forc_fmt=$(realpath ./packages/forc/forc-binaries/forc-fmt) +forc_fmt=$(realpath ./internal/forc/forc-binaries/forc-fmt) expected_authors="authors = [\"Fuel Labs \"]" for forc_toml in $forc_tomls; do diff --git a/scripts/forc-update.ts b/scripts/forc-update.ts index 7122fd7ad56..e65c593516e 100644 --- a/scripts/forc-update.ts +++ b/scripts/forc-update.ts @@ -4,7 +4,7 @@ import { execSync } from 'child_process'; (() => { // Update - execSync(`pnpm --filter @fuel-ts/forc run update`); + execSync(`pnpm --filter @internal/forc run update`); // Remove lockfiles so latest stdlib can be used execSync(`rm packages/**/Forc.lock`); diff --git a/scripts/verify-forc-version.ts b/scripts/verify-forc-version.ts index 1fa67ce4bcb..9d6a0e764b1 100644 --- a/scripts/verify-forc-version.ts +++ b/scripts/verify-forc-version.ts @@ -2,7 +2,7 @@ import fs from 'fs/promises'; import path from 'path'; (async () => { - const pathToForcVersionFile = path.join(__dirname, '..', 'packages', 'forc', 'VERSION'); + const pathToForcVersionFile = path.join(__dirname, '..', 'internal', 'forc', 'VERSION'); const forcVersion = await fs.readFile(pathToForcVersionFile, 'utf-8'); if (forcVersion.indexOf('git:') !== -1) { throw new Error('Cannot publish from a git branch. Please use a release directly.'); diff --git a/templates/nextjs/fuels.config.ts b/templates/nextjs/fuels.config.ts index 38682bc5c9f..d14d32f6dd1 100644 --- a/templates/nextjs/fuels.config.ts +++ b/templates/nextjs/fuels.config.ts @@ -13,4 +13,6 @@ export default createConfig({ output: './src/sway-api', fuelCorePort, providerUrl: NODE_URL, + forcPath: 'fuels-forc', + fuelCorePath: 'fuels-core', }); diff --git a/templates/nextjs/package.json b/templates/nextjs/package.json index cec10c2d32b..e69f12b227a 100644 --- a/templates/nextjs/package.json +++ b/templates/nextjs/package.json @@ -32,9 +32,5 @@ "postcss": "^8", "tailwindcss": "^3.3.0", "typescript": "^5" - }, - "trustedDependencies": [ - "@fuel-ts/fuel-core", - "@fuel-ts/forc" - ] + } } diff --git a/vitest.env.ts b/vitest.env.ts index 689c8aa5304..5d994aa1248 100644 --- a/vitest.env.ts +++ b/vitest.env.ts @@ -32,5 +32,7 @@ const getPrivateKeyForCurrentWorker = () => { return privateKey; }; +process.env.FUEL_CORE_PATH = 'fuels-core'; + process.env.GENESIS_SECRET = process.env.FUEL_NETWORK_GENESIS_KEY || getPrivateKeyForCurrentWorker();