Skip to content

Commit 6ec0dde

Browse files
authored
chore: 增加 nocacheRequire 导出 (#21)
* feat: 增加 nocacheRequire 导出 * feat: tab style
1 parent 655bc7a commit 6ec0dde

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ $ ./bin/easy-i18n-cli.js -c ./google-translate.config.js
6363

6464
## Contributors
6565

66-
|[<img src="https://avatars.githubusercontent.com/u/1011681?v=4" width="100px;"/><br/><sub><b>xudafeng</b></sub>](https://github.com/xudafeng)<br/>|[<img src="https://avatars.githubusercontent.com/u/52845048?v=4" width="100px;"/><br/><sub><b>snapre</b></sub>](https://github.com/snapre)<br/>|[<img src="https://avatars.githubusercontent.com/u/12947068?v=4" width="100px;"/><br/><sub><b>ilimei</b></sub>](https://github.com/ilimei)<br/>|[<img src="https://avatars.githubusercontent.com/u/61226209?v=4" width="100px;"/><br/><sub><b>yangkeni</b></sub>](https://github.com/yangkeni)<br/>|
67-
| :---: | :---: | :---: | :---: |
66+
|[<img src="https://avatars.githubusercontent.com/u/1011681?v=4" width="100px;"/><br/><sub><b>xudafeng</b></sub>](https://github.com/xudafeng)<br/>|[<img src="https://avatars.githubusercontent.com/u/52845048?v=4" width="100px;"/><br/><sub><b>snapre</b></sub>](https://github.com/snapre)<br/>|[<img src="https://avatars.githubusercontent.com/u/61226209?v=4" width="100px;"/><br/><sub><b>yangkeni</b></sub>](https://github.com/yangkeni)<br/>|[<img src="https://avatars.githubusercontent.com/u/11213298?v=4" width="100px;"/><br/><sub><b>WynterDing</b></sub>](https://github.com/WynterDing)<br/>|[<img src="https://avatars.githubusercontent.com/u/12947068?v=4" width="100px;"/><br/><sub><b>ilimei</b></sub>](https://github.com/ilimei)<br/>|
67+
| :---: | :---: | :---: | :---: | :---: |
6868

6969

70-
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`.
70+
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`.
7171

7272
<!-- GITCONTRIBUTOR_END -->
7373

src/easy-i18n.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const globby = require('globby');
77
const { promises: fs } = require('fs');
88
const originFs = require('fs');
99
const { sync: mkdirp } = require('mkdirp');
10+
const Utils = require('./utils');
1011

1112
const defaultOptions = {
1213
distFileName: 'en-US.js',
@@ -155,8 +156,7 @@ class EasyI18n {
155156
initData() {
156157
const { distFile } = this.options;
157158
try {
158-
delete require.cache[distFile];
159-
const data = require(distFile);
159+
const data = Utils.noCacheRequire(distFile);
160160
this.existedData = data.default || data;
161161
} catch (e) {
162162
console.error(e);
@@ -188,7 +188,7 @@ class EasyI18n {
188188

189189
async check() {
190190
const { distFile } = this.options;
191-
const checkTarget = require(distFile);
191+
const checkTarget = Utils.noCacheRequire(distFile);
192192
const lines = [];
193193
const lineOffset = await this._getLineOffset();
194194
Object.keys(checkTarget).forEach((key, index) => {
@@ -209,9 +209,6 @@ class EasyI18n {
209209

210210
async runWithCheck(options = {}) {
211211
await this.run(options);
212-
213-
const { distFile } = this.options;
214-
delete require.cache[distFile];
215212
await this.check();
216213
}
217214
}

src/utils.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const Utils = {};
2+
3+
Utils.noCacheRequire = function (resolvedPath) {
4+
delete require.cache[resolvedPath];
5+
return require(resolvedPath);
6+
};
7+
8+
module.exports = Utils;

0 commit comments

Comments
 (0)