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 installation from git #1667

Merged
merged 6 commits into from
Jan 22, 2024
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
6 changes: 6 additions & 0 deletions .changeset/beige-actors-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@fuel-ts/forc": patch
"@fuel-ts/fuel-core": patch
---

Fixing installation from git branches
2 changes: 1 addition & 1 deletion packages/forc/lib/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { spawn } from 'child_process';

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

const args = process.argv.slice(2);
spawn(binPath, args, { stdio: 'inherit' }).on('exit', process.exit);
8 changes: 0 additions & 8 deletions packages/forc/lib/index.js

This file was deleted.

9 changes: 3 additions & 6 deletions packages/forc/lib/install.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env node

import { execSync } from 'child_process';
import { error } from 'console';
import { existsSync, rmSync, writeFileSync } from 'fs';
import fetch from 'node-fetch';
import { join } from 'path';
import tar from 'tar';

import {
__dirname,
Expand Down Expand Up @@ -53,12 +53,9 @@ import {
writeFileSync(pkgPath, buf);

// Extract
await tar.x({
file: pkgPath,
C: binDir,
});
execSync(`tar xzf "${pkgPath}" -C "${binDir}"`);

// Cleanup
rmSync(pkgPath);
}
})().catch((e) => console.error(e));
})().catch((e) => error(e));
29 changes: 13 additions & 16 deletions packages/forc/lib/shared.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { execSync } from 'child_process';
import { cpSync } from 'fs';
import fs from 'fs/promises';
import path, { join, dirname } from 'path';
import { cpSync, mkdirSync, rmSync, readFileSync, writeFileSync } from 'fs';
import { join, dirname } from 'path';
import { fileURLToPath } from 'url';

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

export const binPath = join(__dirname, '../forc-binaries/forc');

const platforms = {
darwin: {
arm64: 'darwin_arm64',
Expand All @@ -18,10 +19,6 @@ const platforms = {
},
};

const binPath = join(__dirname, '../forc-binaries/forc');

export default binPath;

export const getPkgPlatform = () => {
if (process.platform !== 'darwin' && process.platform !== 'linux') {
throw new Error(
Expand All @@ -36,28 +33,28 @@ export const getPkgPlatform = () => {
return platforms[process.platform][process.arch];
};

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

export const getCurrentVersion = async () => {
const versionContents = await fs.readFile(versionFilePath, 'utf8');
export const getCurrentVersion = () => {
const versionContents = readFileSync(versionFilePath, 'utf8');
const forcVersion = versionContents.match(/^.+$/m)?.[0] || versionContents;
return forcVersion;
};

export const setCurrentVersion = async (version) => {
await fs.writeFile(versionFilePath, version);
export const setCurrentVersion = (version) => {
writeFileSync(versionFilePath, version);
};

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

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

export const buildFromGitBranch = (branchName) => {
fs.rmSync('sway-repo', { recursive: true, force: true });
fs.rmSync('forc-binaries', { recursive: true, force: true });
rmSync('sway-repo', { recursive: true, force: true });
rmSync('forc-binaries', { recursive: true, force: true });
execSync(`git clone --branch ${branchName} ${swayRepoUrl} sway-repo`);
execSync(`cd sway-repo && cargo build`);
fs.mkdirSync('forc-binaries');
mkdirSync('forc-binaries');
cpSync('sway-repo/target/debug/forc', 'forc-binaries');
cpSync('sway-repo/target/debug/forc-deploy', 'forc-binaries');
cpSync('sway-repo/target/debug/forc-doc', 'forc-binaries');
Expand All @@ -66,5 +63,5 @@ export const buildFromGitBranch = (branchName) => {
cpSync('sway-repo/target/debug/forc-run', 'forc-binaries');
cpSync('sway-repo/target/debug/forc-submit', 'forc-binaries');
cpSync('sway-repo/target/debug/forc-tx', 'forc-binaries');
fs.rmSync('sway-repo', { recursive: true, force: true });
rmSync('sway-repo', { recursive: true, force: true });
};
6 changes: 1 addition & 5 deletions packages/forc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
},
"license": "Apache-2.0",
"dependencies": {
"node-fetch": "^2.6.7",
"tar": "^6.2.0"
},
"devDependencies": {
"@types/tar": "^6.1.8"
"node-fetch": "^2.6.7"
}
}
2 changes: 1 addition & 1 deletion packages/fuel-core/lib/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { spawn } from 'child_process';

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

const args = process.argv.slice(2);
spawn(binPath, args, { stdio: 'inherit' }).on('exit', process.exit);
8 changes: 0 additions & 8 deletions packages/fuel-core/lib/index.js

This file was deleted.

12 changes: 5 additions & 7 deletions packages/fuel-core/lib/install.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env node

import { execSync } from 'child_process';
import { error } from 'console';
import { existsSync, rmSync, writeFileSync, mkdirSync, renameSync } from 'fs';
import fetch from 'node-fetch';
import { join } from 'path';
import tar from 'tar';

import {
__dirname,
Expand Down Expand Up @@ -66,12 +66,10 @@ import {
writeFileSync(pkgPath, buf);

// Extract
await tar.x({
file: pkgPath,
C: rootDir,
});
execSync(`tar xzf "${pkgPath}" -C "${rootDir}"`);

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

// Cleanup
Expand All @@ -81,4 +79,4 @@ import {
});
rmSync(pkgPath);
}
})().catch((e) => console.error(e));
})().catch((e) => error(e));
15 changes: 8 additions & 7 deletions packages/fuel-core/lib/shared.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { execSync } from 'child_process';
import { cpSync, rmSync } from 'fs';
import fs from 'fs/promises';
import { cpSync, mkdirSync, rmSync, readFileSync, writeFileSync } from 'fs';
import { join, dirname } from 'path';
import { fileURLToPath } from 'url';

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

export const binPath = join(__dirname, '../fuel-core-binaries/fuel-core');

const platforms = {
darwin: {
arm64: 'aarch64-apple-darwin',
Expand Down Expand Up @@ -34,13 +35,13 @@ export const getPkgPlatform = () => {

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

export const getCurrentVersion = async () => {
const fuelCoreVersion = await fs.readFile(versionFilePath, 'utf8');
export const getCurrentVersion = () => {
const fuelCoreVersion = readFileSync(versionFilePath, 'utf8');
return fuelCoreVersion.trim();
};

export const setCurrentVersion = async (version) => {
await fs.writeFile(versionFilePath, version);
export const setCurrentVersion = (version) => {
writeFileSync(versionFilePath, version);
};

export const isGitBranch = (versionFileContents) => versionFileContents.indexOf('git:') !== -1;
Expand All @@ -52,7 +53,7 @@ export const buildFromGitBranch = (branchName) => {
rmSync('fuel-core-binaries', { recursive: true, force: true });
execSync(`git clone --branch ${branchName} ${fuelCoreRepoUrl} fuel-core-repo`, { silent: true });
execSync(`cd fuel-core-repo && cargo build`, { silent: true });
fs.mkdirSync('fuel-core-binaries');
mkdirSync('fuel-core-binaries');
cpSync('fuel-core-repo/target/debug/fuel-core', 'fuel-core-binaries/fuel-core');
rmSync('fuel-core-repo', { recursive: true, force: true });
};
6 changes: 1 addition & 5 deletions packages/fuel-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
},
"license": "Apache-2.0",
"dependencies": {
"node-fetch": "^2.7.0",
"tar": "^6.2.0"
},
"devDependencies": {
"@types/tar": "^6.1.8"
"node-fetch": "^2.7.0"
}
}
70 changes: 0 additions & 70 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading