Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ignore libraries in fuels CLI #2302

Merged
merged 3 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/loud-fans-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"fuels": patch
---

fix: ignore libraries in `fuels` CLI
24 changes: 24 additions & 0 deletions packages/fuels/src/cli/config/loadConfig.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { safeExec } from '@fuel-ts/errors/test-utils';
import { readFileSync } from 'fs';
import { resolve } from 'path';

import {
runInit,
Expand All @@ -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';

/**
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions packages/fuels/src/cli/config/loadConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<FuelsConfig> {
Expand Down Expand Up @@ -95,10 +95,10 @@ export async function loadConfig(cwd: string): Promise<FuelsConfig> {

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;
}
Expand Down
1 change: 1 addition & 0 deletions packages/fuels/test/fixtures/workspace/Forc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ members = [
"./contracts/foo",
"./scripts/script",
"./predicates/predicate",
"./libraries/library",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[project]
authors = ["Fuel Labs <contact@fuel.sh>"]
entry = "lib.sw"
license = "Apache-2.0"
name = "library"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
library;

pub enum FooType {
Foo: (),
Bar: (),
}

pub enum BarType {
Bar: (),
Foo: (),
}
Loading