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`. 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..5157193 --- /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;