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

refactor: uninstall npm on ipfs #1947

Merged
merged 4 commits into from
Jan 21, 2022
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
13 changes: 0 additions & 13 deletions assets/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -205,19 +205,6 @@
"title": "Enable download shortcut",
"message": "By enabling this, the shortcut \"{ accelerator }\" will be available to download files as long as IPFS Desktop is running."
},
"installNpmOnIpfsWarning": {
"title": "Install npm on IPFS",
"message": "This experimental feature installs the \"ipfs-npm\" package on your system. It requires Node.js to be installed.",
"action": "Install"
},
"unableToInstallNpmOnIpfs": {
"title": "Error",
"message": "It was not possible to install \"ipfs-npm\" package on your system. Please check the logs for more information or try installing it manually by running \"npm install -g ipfs-npm\" on your command line."
},
"unableToUninstallNpmOnIpfs": {
"title": "Error",
"message": "It was not possible to uninstall \"ipfs-npm\" package on your system. Please check the logs for more information or try uninstalling it manually by running \"npm uninstall -g ipfs-npm\" on your command line."
},
"settings": {
"settings": "Settings",
"preferences": "Preferences",
Expand Down
73 changes: 25 additions & 48 deletions src/npm-on-ipfs/index.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
const which = require('which')
const util = require('util')
const i18n = require('i18next')
const pkg = require('./package')
const logger = require('../common/logger')
const store = require('../common/store')
const { showDialog } = require('../dialogs')
const createToggler = require('../utils/create-toggler')
const { IS_WIN } = require('../common/consts')
const childProcess = require('child_process')

const execFile = util.promisify(childProcess.execFile)
const npmBin = IS_WIN ? 'npm.cmd' : 'npm'

const CONFIG_KEY = 'experiments.npmOnIpfs'

// Deprecated in February 2021. Remove soon.
module.exports = function (ctx) {
// Every 12 hours, check if `ipfs-npm` is installed and, if it is,
// tries to update it to the latest version.
setInterval(existsAndUpdate, 43200000)

// Configure toggler
createToggler(CONFIG_KEY, toggle)

// When running for the first time, update the config to know if `ipfs-npm`
// is installed or not.
if (store.get(CONFIG_KEY, null) === null) {
const exists = isPkgInstalled()
logger.info(`[npm on ipfs] 1st time running and package is ${exists ? 'installed' : 'not installed'}`)
store.set(CONFIG_KEY, exists)
if (store.get(CONFIG_KEY, null) === true) {
logger.info('[npm on ipfs] deprecated, removing')
store.delete(CONFIG_KEY)
uninstall()

showDialog({
title: 'NPM on IPFS Uninstalled',
message: 'NPM on IPFS via IPFS Desktop has been deprecated since February 2021. It was now fully removed. As an alternative, you can use https://github.com/foragepm/forage.',
buttons: [i18n.t('close')]
})
}
}

Expand All @@ -31,41 +33,16 @@ function isPkgInstalled () {
return !!which.sync('ipfs-npm', { nothrow: true })
}

function existsAndUpdate () {
if (isPkgInstalled()) {
pkg.update()
} else {
store.set(CONFIG_KEY, false)
async function uninstall () {
if (isPkgInstalled() === false) {
return
}
}

async function toggle ({ newValue, oldValue }) {
if (newValue === oldValue || oldValue === null) {
try {
await execFile(npmBin, ['uninstall', '-g', 'ipfs-npm'])
logger.info('[npm on ipfs] ipfs-npm: uninstalled globally')
return true
} catch (err) {
logger.error(`[npm on ipfs] ipfs-npm failed to uninstall: ${err.toString()}`, err)
}

// If the user is telling to (un)install even though they have (un)installed
// ipfs-npm package manually.
const manual = isPkgInstalled() === newValue

if (!newValue) {
return manual || pkg.uninstall()
}

const opt = showDialog({
type: 'warning',
title: i18n.t('installNpmOnIpfsWarning.title'),
message: i18n.t('installNpmOnIpfsWarning.message'),
buttons: [
i18n.t('installNpmOnIpfsWarning.action'),
i18n.t('cancel')
]
})

if (opt !== 0) {
// User canceled
return
}

return manual || pkg.install()
}
65 changes: 0 additions & 65 deletions src/npm-on-ipfs/package.js

This file was deleted.

8 changes: 2 additions & 6 deletions src/tray.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@ const { CONFIG_KEY: PUBSUB_KEY } = require('./enable-pubsub')
const { CONFIG_KEY: NAMESYS_PUBSUB_KEY } = require('./enable-namesys-pubsub')
const { CONFIG_KEY: AUTO_GC_KEY } = require('./automatic-gc')
const { CONFIG_KEY: IPFS_PATH_KEY } = require('./ipfs-on-path')
const { CONFIG_KEY: NPM_IPFS_KEY } = require('./npm-on-ipfs')
const { CONFIG_KEY: AUTO_LAUNCH_WEBUI_KEY } = require('./webui')

const CONFIG_KEYS = [
AUTO_LAUNCH_KEY,
AUTO_LAUNCH_WEBUI_KEY,
AUTO_GC_KEY,
IPFS_PATH_KEY,
NPM_IPFS_KEY,
SCREENSHOT_KEY,
DOWNLOAD_KEY,
PUBSUB_KEY,
Expand All @@ -34,8 +32,7 @@ const CONFIG_KEYS = [

// We show them if user enabled them before, but hide when off
const DEPRECATED_KEYS = new Set([
IPFS_PATH_KEY, // brittle, buggy, way better if user does this by hand for now
NPM_IPFS_KEY // superseded by https://github.com/forestpm/forest
IPFS_PATH_KEY // brittle, buggy, way better if user does this by hand for now
])

function buildCheckbox (key, label) {
Expand Down Expand Up @@ -146,8 +143,7 @@ function buildMenu (ctx) {
enabled: false
},
buildCheckbox(PUBSUB_KEY, 'settings.pubsub'),
buildCheckbox(NAMESYS_PUBSUB_KEY, 'settings.namesysPubsub'),
buildCheckbox(NPM_IPFS_KEY, 'settings.npmOnIpfs')
buildCheckbox(NAMESYS_PUBSUB_KEY, 'settings.namesysPubsub')
]
},
{
Expand Down