Skip to content

Commit 261c641

Browse files
authored
fix: bin installation from git (FuelLabs#1667)
1 parent a29e08d commit 261c641

12 files changed

+39
-134
lines changed

.changeset/beige-actors-march.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@fuel-ts/forc": patch
3+
"@fuel-ts/fuel-core": patch
4+
---
5+
6+
Fixing installation from git branches

packages/forc/lib/bin.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { spawn } from 'child_process';
44

55
// eslint-disable-next-line import/extensions
6-
import binPath from './index.js';
6+
import { binPath } from './shared.js';
77

88
const args = process.argv.slice(2);
99
spawn(binPath, args, { stdio: 'inherit' }).on('exit', process.exit);

packages/forc/lib/index.js

-8
This file was deleted.

packages/forc/lib/install.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/usr/bin/env node
22

33
import { execSync } from 'child_process';
4+
import { error } from 'console';
45
import { existsSync, rmSync, writeFileSync } from 'fs';
56
import fetch from 'node-fetch';
67
import { join } from 'path';
7-
import tar from 'tar';
88

99
import {
1010
__dirname,
@@ -53,12 +53,9 @@ import {
5353
writeFileSync(pkgPath, buf);
5454

5555
// Extract
56-
await tar.x({
57-
file: pkgPath,
58-
C: binDir,
59-
});
56+
execSync(`tar xzf "${pkgPath}" -C "${binDir}"`);
6057

6158
// Cleanup
6259
rmSync(pkgPath);
6360
}
64-
})().catch((e) => console.error(e));
61+
})().catch((e) => error(e));

packages/forc/lib/shared.js

+13-16
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { execSync } from 'child_process';
2-
import { cpSync } from 'fs';
3-
import fs from 'fs/promises';
4-
import path, { join, dirname } from 'path';
2+
import { cpSync, mkdirSync, rmSync, readFileSync, writeFileSync } from 'fs';
3+
import { join, dirname } from 'path';
54
import { fileURLToPath } from 'url';
65

76
// eslint-disable-next-line @typescript-eslint/naming-convention
87
export const __dirname = dirname(fileURLToPath(import.meta.url));
98

9+
export const binPath = join(__dirname, '../forc-binaries/forc');
10+
1011
const platforms = {
1112
darwin: {
1213
arm64: 'darwin_arm64',
@@ -18,10 +19,6 @@ const platforms = {
1819
},
1920
};
2021

21-
const binPath = join(__dirname, '../forc-binaries/forc');
22-
23-
export default binPath;
24-
2522
export const getPkgPlatform = () => {
2623
if (process.platform !== 'darwin' && process.platform !== 'linux') {
2724
throw new Error(
@@ -36,28 +33,28 @@ export const getPkgPlatform = () => {
3633
return platforms[process.platform][process.arch];
3734
};
3835

39-
const versionFilePath = path.join(__dirname, '../VERSION');
36+
const versionFilePath = join(__dirname, '../VERSION');
4037

41-
export const getCurrentVersion = async () => {
42-
const versionContents = await fs.readFile(versionFilePath, 'utf8');
38+
export const getCurrentVersion = () => {
39+
const versionContents = readFileSync(versionFilePath, 'utf8');
4340
const forcVersion = versionContents.match(/^.+$/m)?.[0] || versionContents;
4441
return forcVersion;
4542
};
4643

47-
export const setCurrentVersion = async (version) => {
48-
await fs.writeFile(versionFilePath, version);
44+
export const setCurrentVersion = (version) => {
45+
writeFileSync(versionFilePath, version);
4946
};
5047

5148
export const isGitBranch = (versionFileContents) => versionFileContents.indexOf('git:') !== -1;
5249

5350
const swayRepoUrl = 'https://github.com/fuellabs/sway.git';
5451

5552
export const buildFromGitBranch = (branchName) => {
56-
fs.rmSync('sway-repo', { recursive: true, force: true });
57-
fs.rmSync('forc-binaries', { recursive: true, force: true });
53+
rmSync('sway-repo', { recursive: true, force: true });
54+
rmSync('forc-binaries', { recursive: true, force: true });
5855
execSync(`git clone --branch ${branchName} ${swayRepoUrl} sway-repo`);
5956
execSync(`cd sway-repo && cargo build`);
60-
fs.mkdirSync('forc-binaries');
57+
mkdirSync('forc-binaries');
6158
cpSync('sway-repo/target/debug/forc', 'forc-binaries');
6259
cpSync('sway-repo/target/debug/forc-deploy', 'forc-binaries');
6360
cpSync('sway-repo/target/debug/forc-doc', 'forc-binaries');
@@ -66,5 +63,5 @@ export const buildFromGitBranch = (branchName) => {
6663
cpSync('sway-repo/target/debug/forc-run', 'forc-binaries');
6764
cpSync('sway-repo/target/debug/forc-submit', 'forc-binaries');
6865
cpSync('sway-repo/target/debug/forc-tx', 'forc-binaries');
69-
fs.rmSync('sway-repo', { recursive: true, force: true });
66+
rmSync('sway-repo', { recursive: true, force: true });
7067
};

packages/forc/package.json

+1-5
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@
1717
},
1818
"license": "Apache-2.0",
1919
"dependencies": {
20-
"node-fetch": "^2.6.7",
21-
"tar": "^6.2.0"
22-
},
23-
"devDependencies": {
24-
"@types/tar": "^6.1.8"
20+
"node-fetch": "^2.6.7"
2521
}
2622
}

packages/fuel-core/lib/bin.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { spawn } from 'child_process';
44

55
// eslint-disable-next-line import/extensions
6-
import binPath from './index.js';
6+
import { binPath } from './shared.js';
77

88
const args = process.argv.slice(2);
99
spawn(binPath, args, { stdio: 'inherit' }).on('exit', process.exit);

packages/fuel-core/lib/index.js

-8
This file was deleted.

packages/fuel-core/lib/install.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/usr/bin/env node
22

33
import { execSync } from 'child_process';
4+
import { error } from 'console';
45
import { existsSync, rmSync, writeFileSync, mkdirSync, renameSync } from 'fs';
56
import fetch from 'node-fetch';
67
import { join } from 'path';
7-
import tar from 'tar';
88

99
import {
1010
__dirname,
@@ -66,12 +66,10 @@ import {
6666
writeFileSync(pkgPath, buf);
6767

6868
// Extract
69-
await tar.x({
70-
file: pkgPath,
71-
C: rootDir,
72-
});
69+
execSync(`tar xzf "${pkgPath}" -C "${rootDir}"`);
7370

74-
// Take the contents of the directory containing the extracted binaries and move them to the `fuel-core-binaries` directory
71+
// Take the contents of the directory containing the extracted
72+
// binaries and move them to the `fuel-core-binaries` directory
7573
renameSync(`${fileName}`, binDir);
7674

7775
// Cleanup
@@ -81,4 +79,4 @@ import {
8179
});
8280
rmSync(pkgPath);
8381
}
84-
})().catch((e) => console.error(e));
82+
})().catch((e) => error(e));

packages/fuel-core/lib/shared.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { execSync } from 'child_process';
2-
import { cpSync, rmSync } from 'fs';
3-
import fs from 'fs/promises';
2+
import { cpSync, mkdirSync, rmSync, readFileSync, writeFileSync } from 'fs';
43
import { join, dirname } from 'path';
54
import { fileURLToPath } from 'url';
65

76
// eslint-disable-next-line @typescript-eslint/naming-convention
87
export const __dirname = dirname(fileURLToPath(import.meta.url));
98

9+
export const binPath = join(__dirname, '../fuel-core-binaries/fuel-core');
10+
1011
const platforms = {
1112
darwin: {
1213
arm64: 'aarch64-apple-darwin',
@@ -34,13 +35,13 @@ export const getPkgPlatform = () => {
3435

3536
const versionFilePath = join(__dirname, '../VERSION');
3637

37-
export const getCurrentVersion = async () => {
38-
const fuelCoreVersion = await fs.readFile(versionFilePath, 'utf8');
38+
export const getCurrentVersion = () => {
39+
const fuelCoreVersion = readFileSync(versionFilePath, 'utf8');
3940
return fuelCoreVersion.trim();
4041
};
4142

42-
export const setCurrentVersion = async (version) => {
43-
await fs.writeFile(versionFilePath, version);
43+
export const setCurrentVersion = (version) => {
44+
writeFileSync(versionFilePath, version);
4445
};
4546

4647
export const isGitBranch = (versionFileContents) => versionFileContents.indexOf('git:') !== -1;
@@ -52,7 +53,7 @@ export const buildFromGitBranch = (branchName) => {
5253
rmSync('fuel-core-binaries', { recursive: true, force: true });
5354
execSync(`git clone --branch ${branchName} ${fuelCoreRepoUrl} fuel-core-repo`, { silent: true });
5455
execSync(`cd fuel-core-repo && cargo build`, { silent: true });
55-
fs.mkdirSync('fuel-core-binaries');
56+
mkdirSync('fuel-core-binaries');
5657
cpSync('fuel-core-repo/target/debug/fuel-core', 'fuel-core-binaries/fuel-core');
5758
rmSync('fuel-core-repo', { recursive: true, force: true });
5859
};

packages/fuel-core/package.json

+1-5
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@
1717
},
1818
"license": "Apache-2.0",
1919
"dependencies": {
20-
"node-fetch": "^2.7.0",
21-
"tar": "^6.2.0"
22-
},
23-
"devDependencies": {
24-
"@types/tar": "^6.1.8"
20+
"node-fetch": "^2.7.0"
2521
}
2622
}

pnpm-lock.yaml

-70
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)