From 8866c0976fa60f7805447dc1758f45b440a97c78 Mon Sep 17 00:00:00 2001 From: Daniel Bate Date: Tue, 14 May 2024 20:22:54 +0100 Subject: [PATCH] fix: ignore libraries in `fuels` CLI (#2302) * fix: ignore libraries in `fuels` CLI * chore: changeset --- .changeset/loud-fans-hunt.md | 5 ++++ .../fuels/src/cli/config/loadConfig.test.ts | 24 +++++++++++++++++++ packages/fuels/src/cli/config/loadConfig.ts | 10 ++++---- .../fuels/test/fixtures/workspace/Forc.toml | 1 + .../workspace/libraries/library/Forc.toml | 7 ++++++ .../workspace/libraries/library/src/lib.sw | 11 +++++++++ 6 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 .changeset/loud-fans-hunt.md create mode 100644 packages/fuels/test/fixtures/workspace/libraries/library/Forc.toml create mode 100644 packages/fuels/test/fixtures/workspace/libraries/library/src/lib.sw diff --git a/.changeset/loud-fans-hunt.md b/.changeset/loud-fans-hunt.md new file mode 100644 index 00000000000..8979105eba8 --- /dev/null +++ b/.changeset/loud-fans-hunt.md @@ -0,0 +1,5 @@ +--- +"fuels": patch +--- + +fix: ignore libraries in `fuels` CLI diff --git a/packages/fuels/src/cli/config/loadConfig.test.ts b/packages/fuels/src/cli/config/loadConfig.test.ts index 6fbc5dc3e7b..705119848c2 100644 --- a/packages/fuels/src/cli/config/loadConfig.test.ts +++ b/packages/fuels/src/cli/config/loadConfig.test.ts @@ -1,5 +1,6 @@ import { safeExec } from '@fuel-ts/errors/test-utils'; import { readFileSync } from 'fs'; +import { resolve } from 'path'; import { runInit, @@ -11,6 +12,7 @@ import * as shouldUseBuiltinForcMod from '../commands/init/shouldUseBuiltinForc' import * as shouldUseBuiltinFuelCoreMod from '../commands/init/shouldUseBuiltinFuelCore'; import type { FuelsConfig } from '../types'; +import { readForcToml, readSwayType } from './forcUtils'; import { loadConfig } from './loadConfig'; /** @@ -51,6 +53,28 @@ describe('loadConfig', () => { expect(config.autoStartFuelCore).toEqual(true); }); + test('should resolve a workspace path that includes a library', async () => { + const libraries = readForcToml(paths.workspaceDir) + .workspace.members.map((member) => resolve(paths.workspaceDir, member)) + .map((member) => readSwayType(member)) + // @ts-expect-error should be SwayType enum which doesn't include library + .filter((type) => type === 'library'); + + expect(libraries.length).toEqual(1); + + await runInit({ + root: paths.root, + workspace: paths.workspaceDir, + output: paths.outputDir, + }); + + const config = await loadConfig(paths.root); + + expect(config.contracts.length).toEqual(2); + expect(config.scripts.length).toEqual(1); + expect(config.predicates.length).toEqual(1); + }); + test(`should resolve individual paths when not using workspaces`, async () => { await runInit({ root: paths.root, diff --git a/packages/fuels/src/cli/config/loadConfig.ts b/packages/fuels/src/cli/config/loadConfig.ts index 7e80d34d4e9..b98ea82bed8 100644 --- a/packages/fuels/src/cli/config/loadConfig.ts +++ b/packages/fuels/src/cli/config/loadConfig.ts @@ -9,7 +9,7 @@ import { shouldUseBuiltinForc } from '../commands/init/shouldUseBuiltinForc'; import { shouldUseBuiltinFuelCore } from '../commands/init/shouldUseBuiltinFuelCore'; import type { FuelsConfig, UserFuelsConfig } from '../types'; -import { readForcToml, readSwayType } from './forcUtils'; +import { SwayType, readForcToml, readSwayType } from './forcUtils'; import { validateConfig } from './validateConfig'; export async function loadConfig(cwd: string): Promise { @@ -95,10 +95,10 @@ export async function loadConfig(cwd: string): Promise { const swayMembers = forcToml.workspace.members.map((member) => resolve(workspace, member)); - swayMembers.forEach((path) => { - const type = readSwayType(path); - config[`${type}s`].push(path); - }); + swayMembers + .map((path) => ({ path, type: readSwayType(path) })) + .filter(({ type }) => Object.values(SwayType).includes(type)) + .forEach(({ path, type }) => config[`${type}s`].push(path)); config.workspace = workspace; } diff --git a/packages/fuels/test/fixtures/workspace/Forc.toml b/packages/fuels/test/fixtures/workspace/Forc.toml index bc31a96f43f..e3b08e4f2f6 100644 --- a/packages/fuels/test/fixtures/workspace/Forc.toml +++ b/packages/fuels/test/fixtures/workspace/Forc.toml @@ -4,4 +4,5 @@ members = [ "./contracts/foo", "./scripts/script", "./predicates/predicate", + "./libraries/library", ] diff --git a/packages/fuels/test/fixtures/workspace/libraries/library/Forc.toml b/packages/fuels/test/fixtures/workspace/libraries/library/Forc.toml new file mode 100644 index 00000000000..b7b8e8e99b3 --- /dev/null +++ b/packages/fuels/test/fixtures/workspace/libraries/library/Forc.toml @@ -0,0 +1,7 @@ +[project] +authors = ["Fuel Labs "] +entry = "lib.sw" +license = "Apache-2.0" +name = "library" + +[dependencies] diff --git a/packages/fuels/test/fixtures/workspace/libraries/library/src/lib.sw b/packages/fuels/test/fixtures/workspace/libraries/library/src/lib.sw new file mode 100644 index 00000000000..5f0aa529299 --- /dev/null +++ b/packages/fuels/test/fixtures/workspace/libraries/library/src/lib.sw @@ -0,0 +1,11 @@ +library; + +pub enum FooType { + Foo: (), + Bar: (), +} + +pub enum BarType { + Bar: (), + Foo: (), +}