@less-is-more/less-js 1.5.0-10 → 1.5.0-11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/nas.js +6 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@less-is-more/less-js",
3
- "version": "1.5.0-10",
3
+ "version": "1.5.0-11",
4
4
  "description": "Fast develop kit for nodejs",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/nas.js CHANGED
@@ -140,7 +140,9 @@ class Nas {
140
140
 
141
141
  try {
142
142
  // 创建临时文件名,避免写入过程中的并发问题
143
- const tempFilePath = filePath + ".tmp";
143
+ const timestamp = Date.now();
144
+ const randomSuffix = Math.random().toFixed(4) * 10000;
145
+ const tempFilePath = `${filePath}.tmp.${timestamp}.${randomSuffix}`;
144
146
  // 写入过期时间戳和值,用换行符分隔
145
147
  const fileContent = `${expireTime}\n${content}`;
146
148
  fs.writeFileSync(tempFilePath, fileContent, "utf8");
@@ -150,7 +152,9 @@ class Nas {
150
152
  console.error("保存缓存文件失败:", filePath, e);
151
153
  // 如果临时文件创建失败,清理临时文件
152
154
  try {
153
- fs.unlinkSync(filePath + ".tmp");
155
+ if (fs.existsSync(tempFilePath)) {
156
+ fs.unlinkSync(tempFilePath);
157
+ }
154
158
  } catch (cleanupError) {
155
159
  // 忽略清理错误
156
160
  }