Skip to content

Commit

Permalink
Merge branch 'master' into db/feat/deprecate-v0
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbate authored May 14, 2024
2 parents ff92730 + 8866c09 commit ae97dac
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 5 deletions.
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: (),
}

0 comments on commit ae97dac

Please sign in to comment.