From 15386dd348e6a0676891d3bc88014e2a24f80f43 Mon Sep 17 00:00:00 2001
From: fengmk2 <suqian.yf@antgroup.com>
Date: Sun, 26 Nov 2023 21:51:16 +0800
Subject: [PATCH] fix: remove updater

---
 .eslintrc           |  7 +----
 README.md           |  3 ---
 README.zh-CN.md     |  6 ++---
 lib/init_command.js | 63 +++++++++++++++++++--------------------------
 package.json        |  1 -
 5 files changed, 29 insertions(+), 51 deletions(-)

diff --git a/.eslintrc b/.eslintrc
index 78c98eb..c799fe5 100644
--- a/.eslintrc
+++ b/.eslintrc
@@ -1,8 +1,3 @@
 {
-  "extends": "eslint-config-egg",
-  "rules": {
-    "no-console": "off",
-    "no-else-return": "off",
-    "linebreak-style": "off"
-  }
+  "extends": "eslint-config-egg"
 }
diff --git a/README.md b/README.md
index 5171f27..3e0fea8 100644
--- a/README.md
+++ b/README.md
@@ -3,15 +3,12 @@
 [![NPM version][npm-image]][npm-url]
 [![Node.js CI](https://github.com/eggjs/egg-init/actions/workflows/nodejs.yml/badge.svg)](https://github.com/eggjs/egg-init/actions/workflows/nodejs.yml)
 [![Test coverage][codecov-image]][codecov-url]
-[![Known Vulnerabilities][snyk-image]][snyk-url]
 [![npm download][download-image]][download-url]
 
 [npm-image]: https://img.shields.io/npm/v/egg-init.svg?style=flat-square
 [npm-url]: https://npmjs.org/package/egg-init
 [codecov-image]: https://codecov.io/gh/eggjs/egg-init/branch/master/graph/badge.svg
 [codecov-url]: https://codecov.io/gh/eggjs/egg-init
-[snyk-image]: https://snyk.io/test/npm/egg-init/badge.svg?style=flat-square
-[snyk-url]: https://snyk.io/test/npm/egg-init
 [download-image]: https://img.shields.io/npm/dm/egg-init.svg?style=flat-square
 [download-url]: https://npmjs.org/package/egg-init
 
diff --git a/README.zh-CN.md b/README.zh-CN.md
index 48ab9d0..272c671 100644
--- a/README.zh-CN.md
+++ b/README.zh-CN.md
@@ -3,15 +3,12 @@
 [![NPM version][npm-image]][npm-url]
 [![Node.js CI](https://github.com/eggjs/egg-init/actions/workflows/nodejs.yml/badge.svg)](https://github.com/eggjs/egg-init/actions/workflows/nodejs.yml)
 [![Test coverage][codecov-image]][codecov-url]
-[![Known Vulnerabilities][snyk-image]][snyk-url]
 [![npm download][download-image]][download-url]
 
 [npm-image]: https://img.shields.io/npm/v/egg-init.svg?style=flat-square
 [npm-url]: https://npmjs.org/package/egg-init
 [codecov-image]: https://codecov.io/gh/eggjs/egg-init/branch/master/graph/badge.svg
 [codecov-url]: https://codecov.io/gh/eggjs/egg-init
-[snyk-image]: https://snyk.io/test/npm/egg-init/badge.svg?style=flat-square
-[snyk-url]: https://snyk.io/test/npm/egg-init
 [download-image]: https://img.shields.io/npm/dm/egg-init.svg?style=flat-square
 [download-url]: https://npmjs.org/package/egg-init
 
@@ -85,6 +82,7 @@ module.exports = {
 ## License
 
 [MIT](LICENSE)
+
 <!-- GITCONTRIBUTOR_START -->
 
 ## Contributors
@@ -96,4 +94,4 @@ module.exports = {
 
 This project follows the git-contributor [spec](https://github.com/xudafeng/git-contributor), auto updated at `Sat Nov 25 2023 23:06:04 GMT+0800`.
 
-<!-- GITCONTRIBUTOR_END -->
\ No newline at end of file
+<!-- GITCONTRIBUTOR_END -->
diff --git a/lib/init_command.js b/lib/init_command.js
index 6da17d1..8ee368e 100644
--- a/lib/init_command.js
+++ b/lib/init_command.js
@@ -3,7 +3,6 @@ const assert = require('node:assert');
 const fs = require('node:fs');
 const path = require('node:path');
 const urllib = require('urllib');
-const updater = require('npm-updater');
 const mkdirp = require('mkdirp');
 const inquirer = require('inquirer');
 const yargs = require('yargs');
@@ -21,7 +20,6 @@ module.exports = class Command {
     this.name = options.name || 'egg-init';
     this.configName = options.configName || 'egg-init-config';
     this.pkgInfo = options.pkgInfo || require('../package.json');
-    this.needUpdate = options.needUpdate !== false;
     this.httpClient = urllib;
 
     this.inquirer = inquirer;
@@ -44,15 +42,6 @@ module.exports = class Command {
     this.registryUrl = this.getRegistryByType(argv.registry);
     this.log(`use registry: ${this.registryUrl}`);
 
-    if (this.needUpdate) {
-      // check update
-      await updater({
-        package: this.pkgInfo,
-        registry: this.registryUrl,
-        level: 'major',
-      });
-    }
-
     // ask for target dir
     this.targetDir = await this.getTargetDirectory();
 
@@ -182,10 +171,10 @@ module.exports = class Command {
 
     if (shouldInstall) {
       return boilerplateInfo;
-    } else {
-      console.log(`Exit due to: ${boilerplateInfo.deprecate}`);
-      return;
     }
+    console.log(`Exit due to: ${boilerplateInfo.deprecate}`);
+    return;
+
   }
 
   /**
@@ -232,19 +221,19 @@ module.exports = class Command {
       }, {});
       this.log('use default due to --silent, %j', result);
       return result;
-    } else {
-      return await inquirer.prompt(keys.map(key => {
-        const question = questions[key];
-        return {
-          type: question.type || 'input',
-          name: key,
-          message: question.description || question.desc,
-          default: question.default,
-          filter: question.filter,
-          choices: question.choices,
-        };
-      }));
     }
+    return await inquirer.prompt(keys.map(key => {
+      const question = questions[key];
+      return {
+        type: question.type || 'input',
+        name: key,
+        message: question.description || question.desc,
+        default: question.default,
+        filter: question.filter,
+        choices: question.choices,
+      };
+    }));
+
   }
 
   /**
@@ -357,16 +346,16 @@ module.exports = class Command {
       default: {
         if (/^https?:/.test(key)) {
           return key.replace(/\/$/, '');
-        } else {
-          // support .npmrc
-          const home = homedir();
-          let url = process.env.npm_registry || process.env.npm_config_registry || 'https://registry.npmjs.org';
-          if (fs.existsSync(path.join(home, '.cnpmrc')) || fs.existsSync(path.join(home, '.tnpmrc'))) {
-            url = 'https://registry.npmmirror.com';
-          }
-          url = url.replace(/\/$/, '');
-          return url;
         }
+        // support .npmrc
+        const home = homedir();
+        let url = process.env.npm_registry || process.env.npm_config_registry || 'https://registry.npmjs.org';
+        if (fs.existsSync(path.join(home, '.cnpmrc')) || fs.existsSync(path.join(home, '.tnpmrc'))) {
+          url = 'https://registry.npmmirror.com';
+        }
+        url = url.replace(/\/$/, '');
+        return url;
+
       }
     }
   }
@@ -539,9 +528,9 @@ module.exports = class Command {
       if (withFallback) {
         this.log(`use fallback from ${pkgName}`);
         return require(`${pkgName}/package.json`);
-      } else {
-        throw err;
       }
+      throw err;
+
     }
   }
 
diff --git a/package.json b/package.json
index 85bcb00..c692669 100644
--- a/package.json
+++ b/package.json
@@ -29,7 +29,6 @@
     "mkdirp": "^0.5.1",
     "mz-modules": "^2.1.0",
     "node-homedir": "^2.0.0",
-    "npm-updater": "^3.0.3",
     "urllib": "^3.19.3",
     "yargs": "^11.1.0"
   },