Skip to content

Commit

Permalink
feat: auto install fuse-t (#40)
Browse files Browse the repository at this point in the history
* feat: auto install fuse-t

* feat: add INSTALL_FUSE_T env
  • Loading branch information
killagu authored Oct 25, 2023
1 parent 918c6e2 commit b8e453e
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 10 deletions.
7 changes: 1 addition & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,6 @@ jobs:
- name: Change directory ownership
run: chown -R $(id -un):$(id -gn) .

- name: Install macfuse
run: |
wget https://github.com/macos-fuse-t/fuse-t/releases/download/1.0.24/fuse-t-macos-installer-1.0.24.pkg
sudo installer -pkg fuse-t-macos-installer-1.0.24.pkg -target /
- name: Rust Cache
uses: actions/cache@v3
with:
Expand All @@ -205,6 +200,6 @@ jobs:
CARGO_BUILD_TARGET=x86_64-apple-darwin BUILD_OS=macos BUILD_ARCH=amd64 npm run init:ci
- name: Run CI
run: npm run test:integration
run: INSTALL_FUSE_T=true npm run test:integration
env:
NODE_OPTIONS: --max_old_space_size=6144
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ The fastest way to install npm packages.
const rapid = require('@cnpmjs/rapid');
await rapid({});
```

# 🎁 Acknowledgements
- [fuse-t](https://github.com/macos-fuse-t/fuse-t) Thanks fuse-t for kext-less implementation of FUSE.
6 changes: 6 additions & 0 deletions packages/cli/bin/rapid.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const yargs = require('yargs');
const { NpmFsMode, NYDUS_TYPE } = require('../lib/constants.js');
const util = require('../lib/util');
const path = require('node:path');
const fuse_t = require('../lib/fuse_t');

yargs
.command({
Expand All @@ -31,6 +32,11 @@ yargs
const cwd = process.cwd();
const pkgRes = await util.readPkgJSON();
const pkg = pkgRes?.pkg || {};
if (!(await fuse_t.checkFuseT())) {
if (await fuse_t.confirmInstallFuseT()) {
await fuse_t.installFuseT();
}
}

await util.shouldFuseSupport();
await install({
Expand Down
42 changes: 42 additions & 0 deletions packages/cli/lib/fuse_t.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const fs = require('node:fs/promises');
const fsSync = require('node:fs');
const crypto = require('node:crypto');
const path = require('node:path');
const urllib = require('urllib');
const execa = require('execa');
const inquirer = require('inquirer');

const FUSE_T_INSTALL_PATH = '/usr/local/bin/go-nfsv4';
const FUSE_T_VERSION = '1.0.28';
const FUSE_T_DOWNLOAD_URL = `https://registry.npmmirror.com/-/binary/fuse-t/${FUSE_T_VERSION}/fuse-t-macos-installer-${FUSE_T_VERSION}.pkg`;

exports.checkFuseT = async function checkFuseT() {
try {
await fs.stat(FUSE_T_INSTALL_PATH);
return true;
} catch {
return false;
}
};

exports.installFuseT = async function installFuseT() {
const tmpPath = path.join('/tmp', `${crypto.randomUUID()}.pkg`);
await urllib.request(FUSE_T_DOWNLOAD_URL, {
method: 'GET',
writeStream: fsSync.createWriteStream(tmpPath),
followRedirect: true,
});
await execa.command(`sudo installer -pkg ${tmpPath} -target /`);
};

exports.confirmInstallFuseT = async function confirmInstallFuseT() {
if (process.env.INSTALL_FUSE_T === 'true') return true;
if (!process.stdout.isTTY) return false;
const answers = await inquirer.prompt([{
type: 'confirm',
name: 'installFuseT',
message: 'Do you want install fuse-t?',
default: true,
}]);
return answers.installFuseT === true;
};
6 changes: 3 additions & 3 deletions packages/cli/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const os = require('node:os');
const url = require('node:url');
const crypto = require('node:crypto');
const mapWorkspaces = require('@npmcli/map-workspaces');
const fuse_t = require('./fuse_t');

const parser = require('yargs-parser');
const { NpmFsMode } = require('./constants');
Expand Down Expand Up @@ -103,9 +104,8 @@ async function shouldFuseSupport() {
}

if (os.type() === 'Darwin') {
try {
await fs.stat('/usr/local/bin/go-nfsv4');
} catch (error) {
const fuseTInstalled = await fuse_t.checkFuseT();
if (!fuseTInstalled) {
throw new NotSupportedError('install fuse-t first.');
}
}
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"semver": "^7.3.8",
"urllib": "^3.16.1",
"yargs": "^17.7.2",
"yargs-parser": "^9.0.2"
"yargs-parser": "^9.0.2",
"inquirer": "^8.2.6"
},
"homepage": "https://github.com/cnpm/rapid",
"repository": {
Expand Down

0 comments on commit b8e453e

Please sign in to comment.