From 063e450b446a45feb84d814596b87936dac9db35 Mon Sep 17 00:00:00 2001 From: wynterding Date: Mon, 7 Apr 2025 21:05:48 +0800 Subject: [PATCH 1/3] =?UTF-8?q?chore:=20=E5=90=8D=E6=9C=9B=20+1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b1c2e51..43a4848 100644 --- a/README.md +++ b/README.md @@ -63,11 +63,11 @@ $ ./bin/easy-i18n-cli.js -c ./google-translate.config.js ## Contributors -|[
xudafeng](https://github.com/xudafeng)
|[
snapre](https://github.com/snapre)
|[
ilimei](https://github.com/ilimei)
|[
yangkeni](https://github.com/yangkeni)
| -| :---: | :---: | :---: | :---: | +|[
xudafeng](https://github.com/xudafeng)
|[
snapre](https://github.com/snapre)
|[
yangkeni](https://github.com/yangkeni)
|[
WynterDing](https://github.com/WynterDing)
|[
ilimei](https://github.com/ilimei)
| +| :---: | :---: | :---: | :---: | :---: | -This project follows the git-contributor [spec](https://github.com/xudafeng/git-contributor), auto updated at `Tue Apr 01 2025 15:44:10 GMT+0800`. +This project follows the git-contributor [spec](https://github.com/xudafeng/git-contributor), auto updated at `Mon Apr 07 2025 21:05:31 GMT+0800`. From 87d58855ea2c3dc3b6314ef60de683e27cfc3da9 Mon Sep 17 00:00:00 2001 From: wynterding Date: Mon, 7 Apr 2025 21:19:16 +0800 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=20nocacheRequire?= =?UTF-8?q?=20=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/easy-i18n.js | 9 +++------ src/utils.js | 8 ++++++++ 2 files changed, 11 insertions(+), 6 deletions(-) create mode 100644 src/utils.js diff --git a/src/easy-i18n.js b/src/easy-i18n.js index 0fdf468..7324ad5 100644 --- a/src/easy-i18n.js +++ b/src/easy-i18n.js @@ -7,6 +7,7 @@ const globby = require('globby'); const { promises: fs } = require('fs'); const originFs = require('fs'); const { sync: mkdirp } = require('mkdirp'); +const Utils = require('./utils'); const defaultOptions = { distFileName: 'en-US.js', @@ -155,8 +156,7 @@ class EasyI18n { initData() { const { distFile } = this.options; try { - delete require.cache[distFile]; - const data = require(distFile); + const data = Utils.noCacheRequire(distFile); this.existedData = data.default || data; } catch (e) { console.error(e); @@ -188,7 +188,7 @@ class EasyI18n { async check() { const { distFile } = this.options; - const checkTarget = require(distFile); + const checkTarget = Utils.noCacheRequire(distFile); const lines = []; const lineOffset = await this._getLineOffset(); Object.keys(checkTarget).forEach((key, index) => { @@ -209,9 +209,6 @@ class EasyI18n { async runWithCheck(options = {}) { await this.run(options); - - const { distFile } = this.options; - delete require.cache[distFile]; await this.check(); } } diff --git a/src/utils.js b/src/utils.js new file mode 100644 index 0000000..1aa484c --- /dev/null +++ b/src/utils.js @@ -0,0 +1,8 @@ +const Utils = {}; + +Utils.noCacheRequire = function (resolvedPath) { + delete require.cache[resolvedPath]; + return require(resolvedPath); +}; + +module.exports = Utils; \ No newline at end of file From 955b8b5b79eb889a8622de38bea993b15c17c824 Mon Sep 17 00:00:00 2001 From: wynterding Date: Mon, 7 Apr 2025 21:20:14 +0800 Subject: [PATCH 3/3] feat: tab style --- src/utils.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils.js b/src/utils.js index 1aa484c..5157193 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,8 +1,8 @@ const Utils = {}; Utils.noCacheRequire = function (resolvedPath) { - delete require.cache[resolvedPath]; - return require(resolvedPath); + delete require.cache[resolvedPath]; + return require(resolvedPath); }; -module.exports = Utils; \ No newline at end of file +module.exports = Utils;