Skip to content

Commit

Permalink
fix: validation and documentation for unsupported Windows platform (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhaiwat10 authored Jan 11, 2024
1 parent 08a85b4 commit 0e7697d
Show file tree
Hide file tree
Showing 12 changed files with 118 additions and 68 deletions.
7 changes: 7 additions & 0 deletions .changeset/sharp-cycles-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"create-fuels": patch
"@fuel-ts/forc": patch
"@fuel-ts/fuel-core": patch
---

fix: use functions from `fs` instead of plain UNIX commands in install scripts to ensure Windows support
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ The [documentation](https://fuellabs.github.io/fuels-ts) site is your main stop
npm install fuels --save
```

> If you are a Windows user, you will need to be running Windows Subsystem for Linux (WSL) to install and use the Fuel toolchain, including the TypeScript SDK. We don't support Windows natively at this time.
# Import

Simple example usages.
Expand Down
3 changes: 2 additions & 1 deletion apps/docs/spell-check-custom-words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -287,4 +287,5 @@ Keystore
cryptographically
Config
config
configs
configs
WSL
2 changes: 2 additions & 0 deletions apps/docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ npm install fuels --save

:::

> If you are a Windows user, you will need to be running Windows Subsystem for Linux (WSL) to install and use the Fuel toolchain, including the TypeScript SDK. We don't support Windows natively at this time.
## Import

<!-- TODO: stop using hard-coded snippets -->
Expand Down
6 changes: 2 additions & 4 deletions packages/create-fuels/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@
"chalk": "4",
"commander": "^9.4.1",
"fuels": "workspace:*",
"prompts": "^2.4.2",
"tar": "^6.2.0"
"prompts": "^2.4.2"
},
"devDependencies": {
"@fuel-ts/versions": "workspace:*",
"@types/prompts": "^2.4.8",
"@types/tar": "^6.1.8"
"@types/prompts": "^2.4.8"
}
}
8 changes: 6 additions & 2 deletions packages/forc/lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { execSync } from 'child_process';
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 @@ -52,9 +53,12 @@ import {
writeFileSync(pkgPath, buf);

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

// Cleanup
rmSync(pkgPath);
}
})().catch(process.stderr.write);
})().catch((e) => console.error(e));
31 changes: 18 additions & 13 deletions packages/forc/lib/shared.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { execSync } from 'child_process';
import { cpSync } from 'fs';
import fs from 'fs/promises';
import path, { join, dirname } from 'path';
import { fileURLToPath } from 'url';
Expand All @@ -23,7 +24,11 @@ export default binPath;

export const getPkgPlatform = () => {
if (process.platform !== 'darwin' && process.platform !== 'linux') {
throw new Error(`Unsupported platform ${process.platform}`);
throw new Error(
`Unsupported platform ${process.platform}.${
process.platform === 'win32' ? ' If you are on Windows, please use WSL.' : ''
}}`
);
}
if (process.arch !== 'arm64' && process.arch !== 'x64') {
throw new Error(`Unsupported arch ${process.arch}`);
Expand All @@ -48,18 +53,18 @@ export const isGitBranch = (versionFileContents) => versionFileContents.indexOf(
const swayRepoUrl = 'https://github.com/fuellabs/sway.git';

export const buildFromGitBranch = (branchName) => {
execSync('rm -rf sway-repo');
execSync('rm -rf forc-binaries');
fs.rmSync('sway-repo', { recursive: true, force: true });
fs.rmSync('forc-binaries', { recursive: true, force: true });
execSync(`git clone --branch ${branchName} ${swayRepoUrl} sway-repo`);
execSync(`cd sway-repo && cargo build`);
execSync('mkdir forc-binaries');
execSync('cp sway-repo/target/debug/forc forc-binaries/');
execSync('cp sway-repo/target/debug/forc-deploy forc-binaries/');
execSync('cp sway-repo/target/debug/forc-doc forc-binaries/');
execSync('cp sway-repo/target/debug/forc-fmt forc-binaries/');
execSync('cp sway-repo/target/debug/forc-lsp forc-binaries/');
execSync('cp sway-repo/target/debug/forc-run forc-binaries/');
execSync('cp sway-repo/target/debug/forc-submit forc-binaries/');
execSync('cp sway-repo/target/debug/forc-tx forc-binaries/');
execSync(`rm -rf sway-repo`);
fs.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');
cpSync('sway-repo/target/debug/forc-fmt', 'forc-binaries');
cpSync('sway-repo/target/debug/forc-lsp', 'forc-binaries');
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 });
};
6 changes: 5 additions & 1 deletion packages/forc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
},
"license": "Apache-2.0",
"dependencies": {
"node-fetch": "^2.6.7"
"node-fetch": "^2.6.7",
"tar": "^6.2.0"
},
"devDependencies": {
"@types/tar": "^6.1.8"
}
}
18 changes: 14 additions & 4 deletions packages/fuel-core/lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { execSync } from 'child_process';
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 @@ -51,7 +52,10 @@ import {
} else {
// Empty the `fuel-core-binaries` directory if it exists
if (existsSync(binDir)) {
execSync(`rm -rf ${binDir}/*`);
rmSync(`${binDir}/*`, {
recursive: true,
force: true,
});
} else {
// Create the `fuel-core-binaries` directory if it doesn't exist
mkdirSync(binDir);
Expand All @@ -62,13 +66,19 @@ import {
writeFileSync(pkgPath, buf);

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

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

// Cleanup
execSync(`rm -rf ${fileName}`);
rmSync(fileName, {
recursive: true,
force: true,
});
rmSync(pkgPath);
}
})().catch(process.stderr.write);
})().catch((e) => console.error(e));
17 changes: 11 additions & 6 deletions packages/fuel-core/lib/shared.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { execSync } from 'child_process';
import { cpSync, rmSync } from 'fs';
import fs from 'fs/promises';
import { join, dirname } from 'path';
import { fileURLToPath } from 'url';
Expand All @@ -19,7 +20,11 @@ const platforms = {

export const getPkgPlatform = () => {
if (process.platform !== 'darwin' && process.platform !== 'linux') {
throw new Error(`Unsupported platform ${process.platform}`);
throw new Error(
`Unsupported platform ${process.platform}.${
process.platform === 'win32' ? ' If you are on Windows, please use WSL.' : ''
}`
);
}
if (process.arch !== 'arm64' && process.arch !== 'x64') {
throw new Error(`Unsupported arch ${process.arch}`);
Expand All @@ -43,11 +48,11 @@ export const isGitBranch = (versionFileContents) => versionFileContents.indexOf(
const fuelCoreRepoUrl = 'https://github.com/fuellabs/fuel-core.git';

export const buildFromGitBranch = (branchName) => {
execSync('rm -rf fuel-core-repo');
execSync('rm -rf fuel-core-binaries');
rmSync('fuel-core-repo', { recursive: true, force: true });
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 });
execSync('mkdir fuel-core-binaries');
execSync('cp fuel-core-repo/target/debug/fuel-core fuel-core-binaries/fuel-core');
execSync(`rm -rf fuel-core-repo`);
fs.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: 5 additions & 1 deletion packages/fuel-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
},
"license": "Apache-2.0",
"dependencies": {
"node-fetch": "^2.7.0"
"node-fetch": "^2.7.0",
"tar": "^6.2.0"
},
"devDependencies": {
"@types/tar": "^6.1.8"
}
}
Loading

0 comments on commit 0e7697d

Please sign in to comment.