File tree Expand file tree Collapse file tree 3 files changed +9
-2
lines changed
Expand file tree Collapse file tree 3 files changed +9
-2
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " path-temp " : patch
3+ ---
4+
5+ The location created by fastPathTemp should be unique across worker threads.
Original file line number Diff line number Diff line change 11'use strict'
22const path = require ( 'path' )
33const uniqueString = require ( 'unique-string' )
4+ const workerThreads = require ( 'node:worker_threads' )
45
56module . exports = function pathTemp ( folder ) {
67 return path . join ( folder , `_tmp_${ process . pid } _${ uniqueString ( ) } ` )
78}
89
910module . 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}
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ test('pathTemp', t => {
99} )
1010
1111test ( '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} )
You can’t perform that action at this time.
0 commit comments