Skip to content

Commit

Permalink
Merge branch 'master' into st/chore/[email protected]
Browse files Browse the repository at this point in the history
  • Loading branch information
Torres-ssf authored Jan 29, 2025
2 parents b8b4192 + 9edc438 commit 49070fb
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 11 deletions.
4 changes: 4 additions & 0 deletions .changeset/hungry-rivers-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
---

chore: added validation for toolchain versions
5 changes: 5 additions & 0 deletions .changeset/three-taxis-do.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"fuels": patch
---

feat: enable `fuels` callbacks to be asynchronous
10 changes: 5 additions & 5 deletions apps/demo-fuels/fuels.config.full.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,31 +85,31 @@ export default createConfig({
// #endregion deployConfig-fn

// #region onBuild
onBuild: (config: FuelsConfig) => {
onBuild: (config: FuelsConfig): void | Promise<void> => {
console.log('fuels:onBuild', { config });
},
// #endregion onBuild

// #region onDeploy
onDeploy: (config: FuelsConfig, data: DeployedData) => {
onDeploy: (config: FuelsConfig, data: DeployedData): void | Promise<void> => {
console.log('fuels:onDeploy', { config, data });
},
// #endregion onDeploy

// #region onDev
onDev: (config: FuelsConfig) => {
onDev: (config: FuelsConfig): void | Promise<void> => {
console.log('fuels:onDev', { config });
},
// #endregion onDev

// #region onNode
onNode: (config: FuelsConfig) => {
onNode: (config: FuelsConfig): void | Promise<void> => {
console.log('fuels:onNode', { config });
},
// #endregion onNode

// #region onFailure
onFailure: (config: FuelsConfig, error: Error) => {
onFailure: (config: FuelsConfig, error: Error): void | Promise<void> => {
console.log('fuels:onFailure', { config, error });
},
// #endregion onFailure
Expand Down
51 changes: 51 additions & 0 deletions packages/create-fuels/test/toolchain-versions.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { versions } from '@fuel-ts/versions';
import toml from '@iarna/toml';
import { readFileSync } from 'fs';
import { join } from 'path';

const projectRoot = join(__dirname, '..', '..', '..');
const templateDir = join(projectRoot, 'templates');
const counterGuideDir = join(projectRoot, 'apps', 'create-fuels-counter-guide');

const toolchainPaths = [
join(templateDir, 'vite', 'fuel-toolchain.toml'),
join(templateDir, 'nextjs', 'fuel-toolchain.toml'),
join(counterGuideDir, 'fuel-toolchain.toml'),
];

interface ToolchainComponents extends toml.JsonMap {
forc: string;
'fuel-core': string;
}

/**
* @group node
*/
describe('versions', () => {
it('should have versions compatible with fuel-core', () => {
const expectedVersions = {
FORC: versions.FORC,
FUEL_CORE: versions.FUEL_CORE,
};
const expectedToolchains = toolchainPaths.map((path) => ({
path,
versions: expectedVersions,
}));

const toolchains = toolchainPaths.map((toolchainPath) => {
const toolchainContents = readFileSync(toolchainPath, 'utf-8');
const parsedToolchain = toml.parse(toolchainContents);
const components = parsedToolchain.components as ToolchainComponents;

return {
path: toolchainPath,
versions: {
FORC: components.forc,
FUEL_CORE: components['fuel-core'],
},
};
});

expect(toolchains).toStrictEqual(expectedToolchains);
});
});
2 changes: 1 addition & 1 deletion packages/fuels/src/cli/commands/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export async function build(config: FuelsConfig, program?: Command) {

await buildSwayPrograms(config);
await generateTypes(config);
config.onBuild?.(config);
await config.onBuild?.(config);

const options = program?.opts();
if (options?.deploy) {
Expand Down
2 changes: 1 addition & 1 deletion packages/fuels/src/cli/commands/deploy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export async function deploy(config: FuelsConfig) {
const predicates = await deployPredicates(config);
savePredicateFiles(predicates, config);

config.onDeploy?.(config, {
await config.onDeploy?.(config, {
contracts,
scripts,
predicates,
Expand Down
2 changes: 1 addition & 1 deletion packages/fuels/src/cli/commands/dev/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const closeAllFileHandlers = (handlers: FSWatcher[]) => {
export const buildAndDeploy = async (config: FuelsConfig) => {
await build(config);
const deployedContracts = await deploy(config);
config.onDev?.(config);
await config.onDev?.(config);

return deployedContracts;
};
Expand Down
2 changes: 1 addition & 1 deletion packages/fuels/src/cli/commands/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const configFileChanged = (state: NodeState) => async (_event: string, pa
try {
// eslint-disable-next-line @typescript-eslint/no-use-before-define
await node(await loadConfig(state.config.basePath));
state.config.onNode?.(state.config);
await state.config.onNode?.(state.config);
} catch (err: unknown) {
await withConfigErrorHandler(<Error>err, state.config);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/fuels/src/cli/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export type OptionsFunction = (
export type FuelsEventListener<CType extends Commands> = (
config: FuelsConfig,
data: Extract<CommandEvent, { type: CType }>['data']
) => void;
) => void | Promise<void>;

export type UserFuelsConfig = {
/** Relative directory path to Forc workspace */
Expand Down Expand Up @@ -164,7 +164,7 @@ export type UserFuelsConfig = {
* @param config - Configuration in use
* @param error - Original error object
*/
onFailure?: (config: FuelsConfig, error: Error) => void;
onFailure?: (config: FuelsConfig, error: Error) => void | Promise<void>;
};

export type FuelsConfig = UserFuelsConfig &
Expand Down

0 comments on commit 49070fb

Please sign in to comment.