From a34e8048bf328c16c351a6e3e8bba48be4ddc156 Mon Sep 17 00:00:00 2001 From: Dhai Date: Thu, 26 Dec 2024 19:29:36 +0530 Subject: [PATCH 1/8] fix: `fuels dev` hangs after compilation errors --- .github/workflows/pr-release.yaml | 2 +- packages/contract/src/contract-factory.ts | 19 ++++++++++++ .../cli/commands/build/buildSwayProgram.ts | 13 ++++++-- .../src/cli/commands/build/forcHandlers.ts | 1 + .../src/cli/commands/build/generateTypes.ts | 6 ++-- .../cli/commands/deploy/deployContracts.ts | 7 +++-- packages/fuels/src/cli/commands/dev/index.ts | 30 ++++++++++++++++--- packages/fuels/src/cli/commands/node/index.ts | 2 +- 8 files changed, 68 insertions(+), 12 deletions(-) diff --git a/.github/workflows/pr-release.yaml b/.github/workflows/pr-release.yaml index 6eeca1f3f04..593d7fce145 100644 --- a/.github/workflows/pr-release.yaml +++ b/.github/workflows/pr-release.yaml @@ -8,7 +8,7 @@ jobs: name: "Release PR to npm" runs-on: ubuntu-latest # comment out if:false to enable release PR to npm - if: false + # if: false permissions: write-all steps: - name: Checkout diff --git a/packages/contract/src/contract-factory.ts b/packages/contract/src/contract-factory.ts index 3427651eb40..d05fcb3bf00 100644 --- a/packages/contract/src/contract-factory.ts +++ b/packages/contract/src/contract-factory.ts @@ -122,6 +122,8 @@ export default class ContractFactory { * @returns The CreateTransactionRequest object for deploying the contract. */ createTransactionRequest(deployOptions?: DeployContractOptions & { bytecode?: BytesLike }) { + console.log(`Creating transaction request ${deployOptions}`); + const storageSlots = (deployOptions?.storageSlots ?? []) .concat(this.storageSlots) .map(({ key, value }) => ({ @@ -147,6 +149,9 @@ export default class ContractFactory { const bytecode = deployOptions?.bytecode || this.bytecode; const stateRoot = options.stateRoot || getContractStorageRoot(options.storageSlots); const contractId = getContractId(bytecode, options.salt, stateRoot); + + console.log(`Contract ID: ${contractId}`); + const transactionRequest = new CreateTransactionRequest({ bytecodeWitnessIndex: 0, witnesses: [bytecode], @@ -189,6 +194,8 @@ export default class ContractFactory { await account.fund(request, txCost); + console.log(`Funded transaction request`); + return request; } @@ -230,10 +237,16 @@ export default class ContractFactory { ); } + console.log(`Preparing to deploy contract`); + const { contractId, transactionRequest } = await this.prepareDeploy(deployOptions); + console.log(`Sending transaction`); + const transactionResponse = await account.sendTransaction(transactionRequest); + console.log(`Waiting for transaction`); + const waitForResult = async () => { const transactionResult = await transactionResponse.waitForResult(); const contract = new Contract(contractId, this.interface, account) as T; @@ -434,10 +447,16 @@ export default class ContractFactory { this.setConfigurableConstants(configurableConstants); } + console.log(`Creating transaction request`); + const { contractId, transactionRequest } = this.createTransactionRequest(deployOptions); + console.log(`Funding transaction request`); + await this.fundTransactionRequest(transactionRequest, deployOptions); + console.log(`Transaction request funded`); + return { contractId, transactionRequest, diff --git a/packages/fuels/src/cli/commands/build/buildSwayProgram.ts b/packages/fuels/src/cli/commands/build/buildSwayProgram.ts index 58f989a8fdd..0689ea528c3 100644 --- a/packages/fuels/src/cli/commands/build/buildSwayProgram.ts +++ b/packages/fuels/src/cli/commands/build/buildSwayProgram.ts @@ -1,12 +1,12 @@ import { spawn } from 'child_process'; import type { FuelsConfig } from '../../types'; -import { debug, loggingConfig } from '../../utils/logger'; +import { debug, loggingConfig, log } from '../../utils/logger'; import { onForcExit, onForcError } from './forcHandlers'; export const buildSwayProgram = async (config: FuelsConfig, path: string) => { - debug('Building Sway program', path); + log('Building Sway program', path); return new Promise((resolve, reject) => { const args = ['build', '-p', path].concat(config.forcBuildFlags); @@ -14,6 +14,15 @@ export const buildSwayProgram = async (config: FuelsConfig, path: string) => { if (loggingConfig.isLoggingEnabled) { // eslint-disable-next-line no-console forc.stderr?.on('data', (chunk) => console.log(chunk.toString())); + + forc.stderr?.on('data', (chunk) => { + if (chunk.toString().includes('error')) { + console.log('onForcError'); + onForcError(reject); + } else { + console.log('onForcError NOPE'); + } + }); } if (loggingConfig.isDebugEnabled) { diff --git a/packages/fuels/src/cli/commands/build/forcHandlers.ts b/packages/fuels/src/cli/commands/build/forcHandlers.ts index 295005077a1..76f2efb6fa4 100644 --- a/packages/fuels/src/cli/commands/build/forcHandlers.ts +++ b/packages/fuels/src/cli/commands/build/forcHandlers.ts @@ -14,6 +14,7 @@ export const onForcExit = }; export const onForcError = (onError: OnErrorFn) => (err: Error) => { + console.log('onForcError'); error(err); onError(err); }; diff --git a/packages/fuels/src/cli/commands/build/generateTypes.ts b/packages/fuels/src/cli/commands/build/generateTypes.ts index dbcb17fe4bf..83eec0a4051 100644 --- a/packages/fuels/src/cli/commands/build/generateTypes.ts +++ b/packages/fuels/src/cli/commands/build/generateTypes.ts @@ -15,7 +15,7 @@ async function generateTypesForProgramType( paths: string[], programType: ProgramTypeEnum ) { - debug('Generating types..'); + log('Generating types..inside'); let filepaths = await getABIPaths(paths, config); const pluralizedDirName = `${String(programType).toLocaleLowerCase()}s`; @@ -33,6 +33,8 @@ async function generateTypesForProgramType( filepaths = filepaths.concat(loaderFiles); } + log('Generating types..outside'); + runTypegen({ programType, cwd: config.basePath, @@ -64,7 +66,7 @@ export async function generateTypes(config: FuelsConfig) { .map(({ programs, type }) => generateTypesForProgramType(config, programs, type)) ); - const indexFile = await renderIndexTemplate(pluralizedDirNames); + const indexFile = renderIndexTemplate(pluralizedDirNames); writeFileSync(join(config.output, 'index.ts'), indexFile); } diff --git a/packages/fuels/src/cli/commands/deploy/deployContracts.ts b/packages/fuels/src/cli/commands/deploy/deployContracts.ts index a7c6da13d2b..2f25b1c9e38 100644 --- a/packages/fuels/src/cli/commands/deploy/deployContracts.ts +++ b/packages/fuels/src/cli/commands/deploy/deployContracts.ts @@ -34,7 +34,7 @@ export async function deployContract( contractPath: string, tomlContents: ForcToml ) { - debug(`Deploying contract for ABI: ${abiPath}`); + log(`Deploying contract for ABI: ${abiPath}`); if (existsSync(storageSlotsPath)) { const storageSlots = JSON.parse(readFileSync(storageSlotsPath, 'utf-8')); @@ -60,8 +60,11 @@ export async function deployContract( if (!isProxyEnabled) { // a. Deploy the target contract const contractFactory = new ContractFactory(targetBytecode, targetAbi, wallet); + log(`Deploying ContractFactory: ${contractFactory}`); const { waitForResult } = await contractFactory.deploy(deployConfig); + log(`Waiting for ContractFactory to be deployed`); const { contract } = await waitForResult(); + log(`Contract deployed: ${contract.id.toB256()}`); return contract.id.toB256(); } @@ -167,7 +170,7 @@ export async function deployContracts(config: FuelsConfig) { tomlContents ); - debug(`Contract deployed: ${projectName} - ${contractId}`); + log(`Contract deployed: ${projectName} - ${contractId}`); contracts.push({ name: contractName, diff --git a/packages/fuels/src/cli/commands/dev/index.ts b/packages/fuels/src/cli/commands/dev/index.ts index bd62eaecbda..ecee6661097 100644 --- a/packages/fuels/src/cli/commands/dev/index.ts +++ b/packages/fuels/src/cli/commands/dev/index.ts @@ -36,15 +36,37 @@ export type DevState = { config: FuelsConfig; watchHandlers: FSWatcher[]; fuelCore?: FuelCoreNode; + workspaceFilesUnderProcessing: string[]; }; export const workspaceFileChanged = (state: DevState) => async (_event: string, path: string) => { - log(`\nFile changed: ${path}`); - await buildAndDeploy(state.config); + if (!state.workspaceFilesUnderProcessing.includes(path)) { + log(state.workspaceFilesUnderProcessing); + log({ + state, + }); + log('hii'); + log(`\nFile changed: ${path}`); + state.workspaceFilesUnderProcessing.push(path); + + try { + await buildAndDeploy(state.config); + } catch (err: unknown) { + log('Error building and deploying', err); + } finally { + const newState = { ...state }; + newState.workspaceFilesUnderProcessing = [...state.workspaceFilesUnderProcessing].filter( + (p) => p !== path + ); + Object.assign(state, newState); + } + } else { + log(`\nFile changed: ${path} (already processing)`); + } }; export const configFileChanged = (state: DevState) => async (_event: string, path: string) => { - log(`\nFile changed: ${path}`); + log(`\nFile changed config: ${path}`); closeAllFileHandlers(state.watchHandlers); state.fuelCore?.killChildProcess(); @@ -79,7 +101,7 @@ export const dev = async (config: FuelsConfig) => { const watchHandlers: FSWatcher[] = []; const options = { persistent: true, ignoreInitial: true, ignored: '**/out/**' }; - const state = { config, watchHandlers, fuelCore }; + const state: DevState = { config, watchHandlers, fuelCore, workspaceFilesUnderProcessing: [] }; // watch: fuels.config.ts and snapshotDir watchHandlers.push(watch(configFilePaths, options).on('all', configFileChanged(state))); diff --git a/packages/fuels/src/cli/commands/node/index.ts b/packages/fuels/src/cli/commands/node/index.ts index df762409f4c..7be09fa2e62 100644 --- a/packages/fuels/src/cli/commands/node/index.ts +++ b/packages/fuels/src/cli/commands/node/index.ts @@ -26,7 +26,7 @@ export const closeAllFileHandlers = (handlers: FSWatcher[]) => { }; export const configFileChanged = (state: NodeState) => async (_event: string, path: string) => { - log(`\nFile changed: ${path}`); + log(`\nFile changed config: ${path}`); closeAllFileHandlers(state.watchHandlers); state.fuelCore?.killChildProcess(); From e28162343ccc937dd796ed046cd80293f1c86a35 Mon Sep 17 00:00:00 2001 From: Dhai Date: Thu, 26 Dec 2024 19:48:40 +0530 Subject: [PATCH 2/8] revert debug changes --- packages/fuels/src/cli/commands/build/buildSwayProgram.ts | 8 +++----- packages/fuels/src/cli/commands/build/forcHandlers.ts | 1 - packages/fuels/src/cli/commands/build/generateTypes.ts | 4 ++-- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/packages/fuels/src/cli/commands/build/buildSwayProgram.ts b/packages/fuels/src/cli/commands/build/buildSwayProgram.ts index 0689ea528c3..b60d8e69b16 100644 --- a/packages/fuels/src/cli/commands/build/buildSwayProgram.ts +++ b/packages/fuels/src/cli/commands/build/buildSwayProgram.ts @@ -1,7 +1,7 @@ import { spawn } from 'child_process'; import type { FuelsConfig } from '../../types'; -import { debug, loggingConfig, log } from '../../utils/logger'; +import { loggingConfig, log } from '../../utils/logger'; import { onForcExit, onForcError } from './forcHandlers'; @@ -16,11 +16,9 @@ export const buildSwayProgram = async (config: FuelsConfig, path: string) => { forc.stderr?.on('data', (chunk) => console.log(chunk.toString())); forc.stderr?.on('data', (chunk) => { - if (chunk.toString().includes('error')) { - console.log('onForcError'); + if (chunk.toString().includes('Aborting')) { + // because forc logs out 'Aborting due to 2 compilation errors' etc. onForcError(reject); - } else { - console.log('onForcError NOPE'); } }); } diff --git a/packages/fuels/src/cli/commands/build/forcHandlers.ts b/packages/fuels/src/cli/commands/build/forcHandlers.ts index 76f2efb6fa4..295005077a1 100644 --- a/packages/fuels/src/cli/commands/build/forcHandlers.ts +++ b/packages/fuels/src/cli/commands/build/forcHandlers.ts @@ -14,7 +14,6 @@ export const onForcExit = }; export const onForcError = (onError: OnErrorFn) => (err: Error) => { - console.log('onForcError'); error(err); onError(err); }; diff --git a/packages/fuels/src/cli/commands/build/generateTypes.ts b/packages/fuels/src/cli/commands/build/generateTypes.ts index 83eec0a4051..09ecd9a232c 100644 --- a/packages/fuels/src/cli/commands/build/generateTypes.ts +++ b/packages/fuels/src/cli/commands/build/generateTypes.ts @@ -15,7 +15,7 @@ async function generateTypesForProgramType( paths: string[], programType: ProgramTypeEnum ) { - log('Generating types..inside'); + debug('Generating types..'); let filepaths = await getABIPaths(paths, config); const pluralizedDirName = `${String(programType).toLocaleLowerCase()}s`; @@ -33,7 +33,7 @@ async function generateTypesForProgramType( filepaths = filepaths.concat(loaderFiles); } - log('Generating types..outside'); + log('Generating types..'); runTypegen({ programType, From 40348992a070b022e8f45469c7254802190ba4ef Mon Sep 17 00:00:00 2001 From: Dhai Date: Thu, 26 Dec 2024 20:01:32 +0530 Subject: [PATCH 3/8] reset files --- packages/contract/src/contract-factory.ts | 18 ------------------ .../src/cli/commands/deploy/deployContracts.ts | 11 +++-------- packages/fuels/src/cli/commands/dev/index.ts | 14 +++----------- packages/fuels/src/cli/commands/node/index.ts | 2 +- 4 files changed, 7 insertions(+), 38 deletions(-) diff --git a/packages/contract/src/contract-factory.ts b/packages/contract/src/contract-factory.ts index d05fcb3bf00..a319b7b85c9 100644 --- a/packages/contract/src/contract-factory.ts +++ b/packages/contract/src/contract-factory.ts @@ -122,8 +122,6 @@ export default class ContractFactory { * @returns The CreateTransactionRequest object for deploying the contract. */ createTransactionRequest(deployOptions?: DeployContractOptions & { bytecode?: BytesLike }) { - console.log(`Creating transaction request ${deployOptions}`); - const storageSlots = (deployOptions?.storageSlots ?? []) .concat(this.storageSlots) .map(({ key, value }) => ({ @@ -150,8 +148,6 @@ export default class ContractFactory { const stateRoot = options.stateRoot || getContractStorageRoot(options.storageSlots); const contractId = getContractId(bytecode, options.salt, stateRoot); - console.log(`Contract ID: ${contractId}`); - const transactionRequest = new CreateTransactionRequest({ bytecodeWitnessIndex: 0, witnesses: [bytecode], @@ -194,8 +190,6 @@ export default class ContractFactory { await account.fund(request, txCost); - console.log(`Funded transaction request`); - return request; } @@ -237,16 +231,10 @@ export default class ContractFactory { ); } - console.log(`Preparing to deploy contract`); - const { contractId, transactionRequest } = await this.prepareDeploy(deployOptions); - console.log(`Sending transaction`); - const transactionResponse = await account.sendTransaction(transactionRequest); - console.log(`Waiting for transaction`); - const waitForResult = async () => { const transactionResult = await transactionResponse.waitForResult(); const contract = new Contract(contractId, this.interface, account) as T; @@ -447,16 +435,10 @@ export default class ContractFactory { this.setConfigurableConstants(configurableConstants); } - console.log(`Creating transaction request`); - const { contractId, transactionRequest } = this.createTransactionRequest(deployOptions); - console.log(`Funding transaction request`); - await this.fundTransactionRequest(transactionRequest, deployOptions); - console.log(`Transaction request funded`); - return { contractId, transactionRequest, diff --git a/packages/fuels/src/cli/commands/deploy/deployContracts.ts b/packages/fuels/src/cli/commands/deploy/deployContracts.ts index 2f25b1c9e38..d207e82151d 100644 --- a/packages/fuels/src/cli/commands/deploy/deployContracts.ts +++ b/packages/fuels/src/cli/commands/deploy/deployContracts.ts @@ -17,7 +17,7 @@ import { type ForcToml, } from '../../config/forcUtils'; import type { FuelsConfig, DeployedContract } from '../../types'; -import { debug, log } from '../../utils/logger'; +import { debug } from '../../utils/logger'; import { createWallet } from './createWallet'; import { getDeployConfig } from './getDeployConfig'; @@ -34,7 +34,7 @@ export async function deployContract( contractPath: string, tomlContents: ForcToml ) { - log(`Deploying contract for ABI: ${abiPath}`); + debug(`Deploying contract for ABI: ${abiPath}`); if (existsSync(storageSlotsPath)) { const storageSlots = JSON.parse(readFileSync(storageSlotsPath, 'utf-8')); @@ -60,11 +60,8 @@ export async function deployContract( if (!isProxyEnabled) { // a. Deploy the target contract const contractFactory = new ContractFactory(targetBytecode, targetAbi, wallet); - log(`Deploying ContractFactory: ${contractFactory}`); const { waitForResult } = await contractFactory.deploy(deployConfig); - log(`Waiting for ContractFactory to be deployed`); const { contract } = await waitForResult(); - log(`Contract deployed: ${contract.id.toB256()}`); return contract.id.toB256(); } @@ -141,8 +138,6 @@ export async function deployContracts(config: FuelsConfig) { const wallet = await createWallet(config.providerUrl, config.privateKey); - log(`Deploying contracts to: ${wallet.provider.url}`); - const contractsLen = config.contracts.length; for (let i = 0; i < contractsLen; i++) { @@ -170,7 +165,7 @@ export async function deployContracts(config: FuelsConfig) { tomlContents ); - log(`Contract deployed: ${projectName} - ${contractId}`); + debug(`Contract deployed: ${projectName} - ${contractId}`); contracts.push({ name: contractName, diff --git a/packages/fuels/src/cli/commands/dev/index.ts b/packages/fuels/src/cli/commands/dev/index.ts index ecee6661097..091e441bc4f 100644 --- a/packages/fuels/src/cli/commands/dev/index.ts +++ b/packages/fuels/src/cli/commands/dev/index.ts @@ -4,7 +4,7 @@ import { globSync } from 'glob'; import { loadConfig } from '../../config/loadConfig'; import { type FuelsConfig } from '../../types'; -import { error, log } from '../../utils/logger'; +import { debug, error, log } from '../../utils/logger'; import { build } from '../build'; import { deploy } from '../deploy'; import { withConfigErrorHandler } from '../withConfig'; @@ -41,18 +41,12 @@ export type DevState = { export const workspaceFileChanged = (state: DevState) => async (_event: string, path: string) => { if (!state.workspaceFilesUnderProcessing.includes(path)) { - log(state.workspaceFilesUnderProcessing); - log({ - state, - }); - log('hii'); log(`\nFile changed: ${path}`); - state.workspaceFilesUnderProcessing.push(path); - try { + state.workspaceFilesUnderProcessing.push(path); await buildAndDeploy(state.config); } catch (err: unknown) { - log('Error building and deploying', err); + debug('Error in buildAndDeploy', err); } finally { const newState = { ...state }; newState.workspaceFilesUnderProcessing = [...state.workspaceFilesUnderProcessing].filter( @@ -60,8 +54,6 @@ export const workspaceFileChanged = (state: DevState) => async (_event: string, ); Object.assign(state, newState); } - } else { - log(`\nFile changed: ${path} (already processing)`); } }; diff --git a/packages/fuels/src/cli/commands/node/index.ts b/packages/fuels/src/cli/commands/node/index.ts index 7be09fa2e62..df762409f4c 100644 --- a/packages/fuels/src/cli/commands/node/index.ts +++ b/packages/fuels/src/cli/commands/node/index.ts @@ -26,7 +26,7 @@ export const closeAllFileHandlers = (handlers: FSWatcher[]) => { }; export const configFileChanged = (state: NodeState) => async (_event: string, path: string) => { - log(`\nFile changed config: ${path}`); + log(`\nFile changed: ${path}`); closeAllFileHandlers(state.watchHandlers); state.fuelCore?.killChildProcess(); From 3851e851467299458a42445efb957f34c26018ab Mon Sep 17 00:00:00 2001 From: Dhai Date: Thu, 26 Dec 2024 20:03:14 +0530 Subject: [PATCH 4/8] reset --- packages/fuels/src/cli/commands/build/generateTypes.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/fuels/src/cli/commands/build/generateTypes.ts b/packages/fuels/src/cli/commands/build/generateTypes.ts index 09ecd9a232c..6ec2344e384 100644 --- a/packages/fuels/src/cli/commands/build/generateTypes.ts +++ b/packages/fuels/src/cli/commands/build/generateTypes.ts @@ -33,8 +33,6 @@ async function generateTypesForProgramType( filepaths = filepaths.concat(loaderFiles); } - log('Generating types..'); - runTypegen({ programType, cwd: config.basePath, From a1dac4b5bfc285fa53a1c1dbf739531390a46f6c Mon Sep 17 00:00:00 2001 From: Dhai Date: Thu, 26 Dec 2024 21:52:31 +0530 Subject: [PATCH 5/8] rename var --- packages/fuels/src/cli/commands/dev/index.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/fuels/src/cli/commands/dev/index.ts b/packages/fuels/src/cli/commands/dev/index.ts index 091e441bc4f..06ec10b5453 100644 --- a/packages/fuels/src/cli/commands/dev/index.ts +++ b/packages/fuels/src/cli/commands/dev/index.ts @@ -36,22 +36,20 @@ export type DevState = { config: FuelsConfig; watchHandlers: FSWatcher[]; fuelCore?: FuelCoreNode; - workspaceFilesUnderProcessing: string[]; + filesBeingProcsesed: string[]; }; export const workspaceFileChanged = (state: DevState) => async (_event: string, path: string) => { - if (!state.workspaceFilesUnderProcessing.includes(path)) { + if (!state.filesBeingProcsesed.includes(path)) { log(`\nFile changed: ${path}`); try { - state.workspaceFilesUnderProcessing.push(path); + state.filesBeingProcsesed.push(path); await buildAndDeploy(state.config); } catch (err: unknown) { debug('Error in buildAndDeploy', err); } finally { const newState = { ...state }; - newState.workspaceFilesUnderProcessing = [...state.workspaceFilesUnderProcessing].filter( - (p) => p !== path - ); + newState.filesBeingProcsesed = [...state.filesBeingProcsesed].filter((p) => p !== path); Object.assign(state, newState); } } @@ -93,7 +91,7 @@ export const dev = async (config: FuelsConfig) => { const watchHandlers: FSWatcher[] = []; const options = { persistent: true, ignoreInitial: true, ignored: '**/out/**' }; - const state: DevState = { config, watchHandlers, fuelCore, workspaceFilesUnderProcessing: [] }; + const state: DevState = { config, watchHandlers, fuelCore, filesBeingProcsesed: [] }; // watch: fuels.config.ts and snapshotDir watchHandlers.push(watch(configFilePaths, options).on('all', configFileChanged(state))); From 4ce66e6c224dfb44e56b68c47a9e2decedb14dc8 Mon Sep 17 00:00:00 2001 From: Dhai Date: Thu, 26 Dec 2024 21:53:40 +0530 Subject: [PATCH 6/8] fix test --- packages/fuels/src/cli/commands/dev/index.test.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/fuels/src/cli/commands/dev/index.test.ts b/packages/fuels/src/cli/commands/dev/index.test.ts index f950daff5b4..a2f173fa81f 100644 --- a/packages/fuels/src/cli/commands/dev/index.test.ts +++ b/packages/fuels/src/cli/commands/dev/index.test.ts @@ -65,7 +65,10 @@ describe('dev', () => { const { log } = mockLogger(); const { build, deploy } = mockAll(); - await workspaceFileChanged({ config: fuelsConfig, watchHandlers: [] })('event', 'some/path'); + await workspaceFileChanged({ config: fuelsConfig, watchHandlers: [], filesBeingProcsesed: [] })( + 'event', + 'some/path' + ); expect(log).toHaveBeenCalledTimes(1); expect(build).toHaveBeenCalledTimes(1); @@ -127,7 +130,10 @@ describe('dev', () => { const close = vi.fn(); const watchHandlers = [{ close }, { close }] as unknown as FSWatcher[]; - await configFileChanged({ config, fuelCore, watchHandlers })('event', 'some/path'); + await configFileChanged({ config, fuelCore, watchHandlers, filesBeingProcsesed: [] })( + 'event', + 'some/path' + ); // configFileChanged() internals expect(log).toHaveBeenCalledTimes(1); @@ -163,7 +169,10 @@ describe('dev', () => { const close = vi.fn(); const watchHandlers = [{ close }, { close }] as unknown as FSWatcher[]; - await configFileChanged({ config, fuelCore, watchHandlers })('event', 'some/path'); + await configFileChanged({ config, fuelCore, watchHandlers, filesBeingProcsesed: [] })( + 'event', + 'some/path' + ); // configFileChanged() internals expect(log).toHaveBeenCalledTimes(1); From c5c693f34e1eb3efe7ef15b5c8fb6aa7066561f6 Mon Sep 17 00:00:00 2001 From: Dhai Date: Thu, 26 Dec 2024 22:40:24 +0530 Subject: [PATCH 7/8] add changeset --- .changeset/silly-pianos-fry.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/silly-pianos-fry.md diff --git a/.changeset/silly-pianos-fry.md b/.changeset/silly-pianos-fry.md new file mode 100644 index 00000000000..4ccee6af8da --- /dev/null +++ b/.changeset/silly-pianos-fry.md @@ -0,0 +1,6 @@ +--- +"@fuel-ts/contract": patch +"fuels": patch +--- + +fix: `fuels dev` hangs after compilation errors From 4319dd1367b5ef724b8b62860f4acd2342d2acc3 Mon Sep 17 00:00:00 2001 From: Dhai Date: Fri, 27 Dec 2024 21:10:18 +0530 Subject: [PATCH 8/8] fix typo --- packages/fuels/src/cli/commands/dev/index.test.ts | 6 +++--- packages/fuels/src/cli/commands/dev/index.ts | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/fuels/src/cli/commands/dev/index.test.ts b/packages/fuels/src/cli/commands/dev/index.test.ts index a2f173fa81f..dd3982a5718 100644 --- a/packages/fuels/src/cli/commands/dev/index.test.ts +++ b/packages/fuels/src/cli/commands/dev/index.test.ts @@ -65,7 +65,7 @@ describe('dev', () => { const { log } = mockLogger(); const { build, deploy } = mockAll(); - await workspaceFileChanged({ config: fuelsConfig, watchHandlers: [], filesBeingProcsesed: [] })( + await workspaceFileChanged({ config: fuelsConfig, watchHandlers: [], filesBeingProcessed: [] })( 'event', 'some/path' ); @@ -130,7 +130,7 @@ describe('dev', () => { const close = vi.fn(); const watchHandlers = [{ close }, { close }] as unknown as FSWatcher[]; - await configFileChanged({ config, fuelCore, watchHandlers, filesBeingProcsesed: [] })( + await configFileChanged({ config, fuelCore, watchHandlers, filesBeingProcessed: [] })( 'event', 'some/path' ); @@ -169,7 +169,7 @@ describe('dev', () => { const close = vi.fn(); const watchHandlers = [{ close }, { close }] as unknown as FSWatcher[]; - await configFileChanged({ config, fuelCore, watchHandlers, filesBeingProcsesed: [] })( + await configFileChanged({ config, fuelCore, watchHandlers, filesBeingProcessed: [] })( 'event', 'some/path' ); diff --git a/packages/fuels/src/cli/commands/dev/index.ts b/packages/fuels/src/cli/commands/dev/index.ts index 06ec10b5453..afda9ec5904 100644 --- a/packages/fuels/src/cli/commands/dev/index.ts +++ b/packages/fuels/src/cli/commands/dev/index.ts @@ -36,20 +36,20 @@ export type DevState = { config: FuelsConfig; watchHandlers: FSWatcher[]; fuelCore?: FuelCoreNode; - filesBeingProcsesed: string[]; + filesBeingProcessed: string[]; }; export const workspaceFileChanged = (state: DevState) => async (_event: string, path: string) => { - if (!state.filesBeingProcsesed.includes(path)) { + if (!state.filesBeingProcessed.includes(path)) { log(`\nFile changed: ${path}`); try { - state.filesBeingProcsesed.push(path); + state.filesBeingProcessed.push(path); await buildAndDeploy(state.config); } catch (err: unknown) { debug('Error in buildAndDeploy', err); } finally { const newState = { ...state }; - newState.filesBeingProcsesed = [...state.filesBeingProcsesed].filter((p) => p !== path); + newState.filesBeingProcessed = [...state.filesBeingProcessed].filter((p) => p !== path); Object.assign(state, newState); } } @@ -91,7 +91,7 @@ export const dev = async (config: FuelsConfig) => { const watchHandlers: FSWatcher[] = []; const options = { persistent: true, ignoreInitial: true, ignored: '**/out/**' }; - const state: DevState = { config, watchHandlers, fuelCore, filesBeingProcsesed: [] }; + const state: DevState = { config, watchHandlers, fuelCore, filesBeingProcessed: [] }; // watch: fuels.config.ts and snapshotDir watchHandlers.push(watch(configFilePaths, options).on('all', configFileChanged(state)));