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: bin path for fuels-forc in fuels CLI, add support bun's structure #1481

Merged
merged 2 commits into from
Dec 6, 2023
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/mean-phones-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"fuels": patch
---

fix: bin path for `fuels-forc`, add support bun's structure
9 changes: 3 additions & 6 deletions packages/fuels/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { configureCliOptions as configureTypegenCliOptions } from '@fuel-ts/abi-
import { versions } from '@fuel-ts/versions';
import { runVersions } from '@fuel-ts/versions/cli';
import { Command, Option } from 'commander';
import { join } from 'path';

import { build } from './cli/commands/build';
import { deploy } from './cli/commands/deploy';
Expand All @@ -11,7 +10,7 @@ import { init } from './cli/commands/init';
import { withConfig } from './cli/commands/withConfig';
import { withProgram } from './cli/commands/withProgram';
import { Commands } from './cli/types';
import { findPackageRoot } from './cli/utils/findPackageRoot';
import { findBinPath } from './cli/utils/findBinPath';
import { configureLogging } from './cli/utils/logger';

export const onPreAction = (command: Command) => {
Expand Down Expand Up @@ -100,14 +99,12 @@ export const configureCli = () => {
* Binary wrappers
*/

const binDir = join(findPackageRoot(), 'node_modules', '.bin');

program.command('core', 'Wrapper around Fuel Core binary', {
executableFile: join(binDir, 'fuels-core'),
executableFile: findBinPath('fuels-core'),
});

program.command('forc', 'Wrapper around Forc binary', {
executableFile: join(binDir, 'fuels-forc'),
executableFile: findBinPath('fuels-forc'),
});

return program;
Expand Down
6 changes: 2 additions & 4 deletions packages/fuels/src/cli/commands/build/buildSwayPrograms.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { spawn } from 'child_process';
import { join } from 'path';

import type { FuelsConfig } from '../../types';
import { findPackageRoot } from '../../utils/findPackageRoot';
import { findBinPath } from '../../utils/findBinPath';
import { getBinarySource } from '../../utils/getBinarySource';
import { debug, error, log, loggingConfig } from '../../utils/logger';

Expand All @@ -28,8 +27,7 @@ export const buildSwayProgram = async (config: FuelsConfig, path: string) => {
debug('Building Sway program', path);

return new Promise<void>((resolve, reject) => {
const pkgRootDir = findPackageRoot();
const builtInForcPath = join(pkgRootDir, 'node_modules', '.bin', 'fuels-forc');
const builtInForcPath = findBinPath('fuels-forc');

const command = config.useBuiltinForc ? builtInForcPath : 'forc';
const forc = spawn(command, ['build', '-p', path], { stdio: 'pipe' });
Expand Down
7 changes: 2 additions & 5 deletions packages/fuels/src/cli/commands/dev/startFuelCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ import { getPortPromise } from 'portfinder';
import treeKill from 'tree-kill';

import type { FuelsConfig } from '../../types';
import { findBinPath } from '../../utils/findBinPath';
import { getBinarySource } from '../../utils/getBinarySource';
import { error, log, loggingConfig } from '../../utils/logger';

import { defaultChainConfig, defaultConsensusKey } from './defaultChainConfig';

// eslint-disable-next-line @typescript-eslint/no-var-requires
const npmWhich = require('npm-which')(__dirname);

export type FuelCoreNode = {
bindIp: string;
accessIp: string;
Expand Down Expand Up @@ -75,8 +73,7 @@ export const startFuelCore = async (config: FuelsConfig): Promise<FuelCoreNode>
].flat();

return new Promise((resolve, reject) => {
// This line finds the path to the built-in fuels-core binary
const builtInFuelsCorePath = npmWhich.sync('fuels-core');
const builtInFuelsCorePath = findBinPath('fuels-core');

const command = config.useBuiltinFuelCore ? builtInFuelsCorePath : 'fuel-core';
const core = spawn(command, flags, { stdio: 'pipe' });
Expand Down
16 changes: 16 additions & 0 deletions packages/fuels/src/cli/utils/findBinPath.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { existsSync } from 'fs';
import { join } from 'path';

// eslint-disable-next-line @typescript-eslint/no-var-requires
const npmWhich = require('npm-which')(__dirname);

export function findBinPath(binCommandName: string) {
let binPath = npmWhich.sync(binCommandName);

if (!existsSync(binPath)) {
// The user might be using bun, which has a different structure for binaries inside node_modules
binPath = join('node_modules', '.bin', binCommandName);
}

return binPath;
}
9 changes: 0 additions & 9 deletions packages/fuels/src/cli/utils/findPackageRoot.ts

This file was deleted.