From b3bb30eea5485fac6af5b3dfa499114742b9e456 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Tue, 4 Jan 2022 08:38:52 +0000 Subject: [PATCH 1/4] chore: uninstall npm on ipfs License: MIT Signed-off-by: Henrique Dias --- src/npm-on-ipfs/index.js | 72 +++++++++++++------------------------- src/npm-on-ipfs/package.js | 65 ---------------------------------- src/tray.js | 8 ++--- 3 files changed, 26 insertions(+), 119 deletions(-) delete mode 100644 src/npm-on-ipfs/package.js diff --git a/src/npm-on-ipfs/index.js b/src/npm-on-ipfs/index.js index 0c8a0cffb..a485ecffd 100644 --- a/src/npm-on-ipfs/index.js +++ b/src/npm-on-ipfs/index.js @@ -1,27 +1,28 @@ 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' 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 Deprecated', + 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/forestpm/forest.', + buttons: [i18n.t('close')] + }) } } @@ -31,41 +32,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] ${err.toString()}`) } - - // 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() } diff --git a/src/npm-on-ipfs/package.js b/src/npm-on-ipfs/package.js deleted file mode 100644 index 11ff37eb5..000000000 --- a/src/npm-on-ipfs/package.js +++ /dev/null @@ -1,65 +0,0 @@ -const util = require('util') -const i18n = require('i18next') -const logger = require('../common/logger') -const { IS_WIN } = require('../common/consts') -const { recoverableErrorDialog } = require('../dialogs') -const childProcess = require('child_process') - -const execFile = util.promisify(childProcess.execFile) -const npmBin = IS_WIN ? 'npm.cmd' : 'npm' - -async function update () { - try { - logger.info('[npm on ipfs] ipfs-npm: checking if outdated') - - // NOTE: might fail on older NPM (< 6.9.1) versions - // https://github.com/npm/cli/pull/173 - const { stdout } = await execFile(npmBin, ['outdated', '-g']) - - if (stdout.indexOf('ipfs-npm') === -1) { - logger.info('[npm on ipfs] ipfs-npm: is up to date') - return - } - } catch (e) { - logger.error(`[npm on ipfs] ipfs-npm: could not check if up to date ${e.toString()}`) - } - - logger.info('[npm on ipfs] ipfs-npm: is out to date, will update') - install() -} - -async function install () { - try { - await execFile(npmBin, ['install', '-g', 'ipfs-npm']) - logger.info('[npm on ipfs] ipfs-npm: installed globally') - return true - } catch (err) { - logger.error(`[npm on ipfs] ${err.toString()}`) - recoverableErrorDialog(err, { - title: i18n.t('unableToInstallNpmOnIpfs.title'), - message: i18n.t('unableToInstallNpmOnIpfs.message') - }) - return false - } -} - -async function uninstall () { - 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] ${err.toString()}`) - recoverableErrorDialog(err, { - title: i18n.t('unableToUninstallNpmOnIpfs.title'), - message: i18n.t('unableToUninstallNpmOnIpfs.message') - }) - return false - } -} - -module.exports = Object.freeze({ - update, - install, - uninstall -}) diff --git a/src/tray.js b/src/tray.js index ea1c71e5f..d7ec3a7cd 100644 --- a/src/tray.js +++ b/src/tray.js @@ -17,7 +17,6 @@ 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 = [ @@ -25,7 +24,6 @@ const CONFIG_KEYS = [ AUTO_LAUNCH_WEBUI_KEY, AUTO_GC_KEY, IPFS_PATH_KEY, - NPM_IPFS_KEY, SCREENSHOT_KEY, DOWNLOAD_KEY, PUBSUB_KEY, @@ -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) { @@ -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') ] }, { From 2ab310dcf1b0cd11b75d8239d1fba4bec00b7548 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Tue, 4 Jan 2022 08:42:38 +0000 Subject: [PATCH 2/4] add comment License: MIT Signed-off-by: Henrique Dias --- src/npm-on-ipfs/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/npm-on-ipfs/index.js b/src/npm-on-ipfs/index.js index a485ecffd..19e1d56cd 100644 --- a/src/npm-on-ipfs/index.js +++ b/src/npm-on-ipfs/index.js @@ -12,6 +12,7 @@ const npmBin = IS_WIN ? 'npm.cmd' : 'npm' const CONFIG_KEY = 'experiments.npmOnIpfs' +// Deprecated in February 2021. Remove soon. module.exports = function (ctx) { if (store.get(CONFIG_KEY, null) === true) { logger.info('[npm on ipfs] deprecated, removing') @@ -19,7 +20,7 @@ module.exports = function (ctx) { uninstall() showDialog({ - title: 'NPM on IPFS Deprecated', + 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/forestpm/forest.', buttons: [i18n.t('close')] }) From 95bc3df7c2968147a49c52da37af7973bd3aa30e Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Tue, 4 Jan 2022 09:25:59 +0000 Subject: [PATCH 3/4] refactor: remove npm on ipfs --- assets/locales/en.json | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/assets/locales/en.json b/assets/locales/en.json index ea0788e94..f60c72c90 100644 --- a/assets/locales/en.json +++ b/assets/locales/en.json @@ -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", From 8102ae71dc77eabb6f2527d99324fb8c12217f5e Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Fri, 21 Jan 2022 00:49:56 +0100 Subject: [PATCH 4/4] =?UTF-8?q?chore:=20forestpm=20=E2=86=92=20foragepm?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/npm-on-ipfs/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/npm-on-ipfs/index.js b/src/npm-on-ipfs/index.js index 19e1d56cd..b154e2a07 100644 --- a/src/npm-on-ipfs/index.js +++ b/src/npm-on-ipfs/index.js @@ -21,7 +21,7 @@ module.exports = function (ctx) { 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/forestpm/forest.', + 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')] }) } @@ -43,6 +43,6 @@ async function uninstall () { logger.info('[npm on ipfs] ipfs-npm: uninstalled globally') return true } catch (err) { - logger.error(`[npm on ipfs] ${err.toString()}`) + logger.error(`[npm on ipfs] ipfs-npm failed to uninstall: ${err.toString()}`, err) } }