Skip to content

Commit 6a1ed34

Browse files
authored
fix: path-temp across worker threads (#222)
1 parent 4575e4d commit 6a1ed34

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

.changeset/metal-games-melt.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"path-temp": patch
3+
---
4+
5+
The location created by fastPathTemp should be unique across worker threads.

path-temp/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
'use strict'
22
const path = require('path')
33
const uniqueString = require('unique-string')
4+
const workerThreads = require('node:worker_threads')
45

56
module.exports = function pathTemp (folder) {
67
return path.join(folder, `_tmp_${process.pid}_${uniqueString()}`)
78
}
89

910
module.exports.fastPathTemp = function pathTempFast (file) {
10-
return path.join(path.dirname(file), `${path.basename(file)}_tmp_${process.pid}`)
11+
return path.join(path.dirname(file), `${path.basename(file)}_tmp_${process.pid}_${workerThreads.threadId}`)
1112
}

path-temp/test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ test('pathTemp', t => {
99
})
1010

1111
test('fastPathTemp', t => {
12-
t.equal(pathTemp.fastPathTemp(path.resolve('foo.txt')), path.resolve(`foo.txt_tmp_${process.pid}`))
12+
const workerThreads = require('node:worker_threads')
13+
t.equal(pathTemp.fastPathTemp(path.resolve('foo.txt')), path.resolve(`foo.txt_tmp_${process.pid}_${workerThreads.threadId}`))
1314
t.end()
1415
})

0 commit comments

Comments
 (0)