Skip to content

Commit c822522

Browse files
feat: enable fuels callbacks to be asynchronous (#3637)
* chore: updated callbacks * docs: added type hints to callback * chore: changeset * Update .changeset/three-taxis-do.md Co-authored-by: Nedim Salkić <[email protected]> --------- Co-authored-by: Nedim Salkić <[email protected]>
1 parent b3bb765 commit c822522

File tree

7 files changed

+16
-11
lines changed

7 files changed

+16
-11
lines changed

.changeset/three-taxis-do.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"fuels": patch
3+
---
4+
5+
feat: enable `fuels` callbacks to be asynchronous

apps/demo-fuels/fuels.config.full.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -85,31 +85,31 @@ export default createConfig({
8585
// #endregion deployConfig-fn
8686

8787
// #region onBuild
88-
onBuild: (config: FuelsConfig) => {
88+
onBuild: (config: FuelsConfig): void | Promise<void> => {
8989
console.log('fuels:onBuild', { config });
9090
},
9191
// #endregion onBuild
9292

9393
// #region onDeploy
94-
onDeploy: (config: FuelsConfig, data: DeployedData) => {
94+
onDeploy: (config: FuelsConfig, data: DeployedData): void | Promise<void> => {
9595
console.log('fuels:onDeploy', { config, data });
9696
},
9797
// #endregion onDeploy
9898

9999
// #region onDev
100-
onDev: (config: FuelsConfig) => {
100+
onDev: (config: FuelsConfig): void | Promise<void> => {
101101
console.log('fuels:onDev', { config });
102102
},
103103
// #endregion onDev
104104

105105
// #region onNode
106-
onNode: (config: FuelsConfig) => {
106+
onNode: (config: FuelsConfig): void | Promise<void> => {
107107
console.log('fuels:onNode', { config });
108108
},
109109
// #endregion onNode
110110

111111
// #region onFailure
112-
onFailure: (config: FuelsConfig, error: Error) => {
112+
onFailure: (config: FuelsConfig, error: Error): void | Promise<void> => {
113113
console.log('fuels:onFailure', { config, error });
114114
},
115115
// #endregion onFailure

packages/fuels/src/cli/commands/build/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export async function build(config: FuelsConfig, program?: Command) {
1313

1414
await buildSwayPrograms(config);
1515
await generateTypes(config);
16-
config.onBuild?.(config);
16+
await config.onBuild?.(config);
1717

1818
const options = program?.opts();
1919
if (options?.deploy) {

packages/fuels/src/cli/commands/deploy/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export async function deploy(config: FuelsConfig) {
2727
const predicates = await deployPredicates(config);
2828
savePredicateFiles(predicates, config);
2929

30-
config.onDeploy?.(config, {
30+
await config.onDeploy?.(config, {
3131
contracts,
3232
scripts,
3333
predicates,

packages/fuels/src/cli/commands/dev/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const closeAllFileHandlers = (handlers: FSWatcher[]) => {
1919
export const buildAndDeploy = async (config: FuelsConfig) => {
2020
await build(config);
2121
const deployedContracts = await deploy(config);
22-
config.onDev?.(config);
22+
await config.onDev?.(config);
2323

2424
return deployedContracts;
2525
};

packages/fuels/src/cli/commands/node/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export const configFileChanged = (state: NodeState) => async (_event: string, pa
3434
try {
3535
// eslint-disable-next-line @typescript-eslint/no-use-before-define
3636
await node(await loadConfig(state.config.basePath));
37-
state.config.onNode?.(state.config);
37+
await state.config.onNode?.(state.config);
3838
} catch (err: unknown) {
3939
await withConfigErrorHandler(<Error>err, state.config);
4040
}

packages/fuels/src/cli/types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export type OptionsFunction = (
7070
export type FuelsEventListener<CType extends Commands> = (
7171
config: FuelsConfig,
7272
data: Extract<CommandEvent, { type: CType }>['data']
73-
) => void;
73+
) => void | Promise<void>;
7474

7575
export type UserFuelsConfig = {
7676
/** Relative directory path to Forc workspace */
@@ -164,7 +164,7 @@ export type UserFuelsConfig = {
164164
* @param config - Configuration in use
165165
* @param error - Original error object
166166
*/
167-
onFailure?: (config: FuelsConfig, error: Error) => void;
167+
onFailure?: (config: FuelsConfig, error: Error) => void | Promise<void>;
168168
};
169169

170170
export type FuelsConfig = UserFuelsConfig &

0 commit comments

Comments
 (0)