Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ $ ./bin/easy-i18n-cli.js -c ./google-translate.config.js

## Contributors

|[<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/>|
| :---: | :---: | :---: | :---: |
|[<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/>|
| :---: | :---: | :---: | :---: | :---: |


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`.

<!-- GITCONTRIBUTOR_END -->

Expand Down
9 changes: 3 additions & 6 deletions src/easy-i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) => {
Expand All @@ -209,9 +209,6 @@ class EasyI18n {

async runWithCheck(options = {}) {
await this.run(options);

const { distFile } = this.options;
delete require.cache[distFile];
await this.check();
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const Utils = {};

Utils.noCacheRequire = function (resolvedPath) {
delete require.cache[resolvedPath];
return require(resolvedPath);
};

module.exports = Utils;