Skip to content

Commit

Permalink
feat: auto install fuse-t
Browse files Browse the repository at this point in the history
  • Loading branch information
killagu committed Oct 25, 2023
1 parent 918c6e2 commit 6d38c78
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
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.
40 changes: 40 additions & 0 deletions packages/cli/lib/fuse_t.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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() {
const answers = await inquirer.prompt([{
type: 'confirm',
name: 'installFuseT',
message: 'Do you want install fuse-t?',
default: true,
}]);
return answers.installFuseT === true;
};
18 changes: 17 additions & 1 deletion 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 All @@ -23,6 +24,7 @@ const {
nydusdBootstrapFile,
nydusdMnt,
} = require('./constants');
let confirmed = false;

// node_modules/a -> a
// node_mdoules/@scope/b -> @scope/b
Expand Down Expand Up @@ -103,9 +105,23 @@ async function shouldFuseSupport() {
}

if (os.type() === 'Darwin') {
const fuseTInstalled = await fuse_t.checkFuseT();
if (fuseTInstalled) {
return;
}
if (confirmed) {
throw new NotSupportedError('install fuse-t first.');
}
const confirmInstallFuseT = await fuse_t.confirmInstallFuseT();
confirmed = true;
if (!confirmInstallFuseT) {
throw new NotSupportedError('install fuse-t first.');
}
try {
await fs.stat('/usr/local/bin/go-nfsv4');
await fuse_t.installFuseT();
} catch (error) {
error.message = '[rapid] install fuse-t failed: ' + error.message;
console.warn(error);
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 6d38c78

Please sign in to comment.