Skip to content

Commit 0cce7f4

Browse files
committed
fix(@angular-devkit/core): use crypto.randomUUID instead of Date.now for unique string in tmp file names
Use crypto.randomUUID instead of Date.now for unique string in the tmpdir path name for a TempScopedNodeJsSyncHost to prevent naming conflicts. When performaning tests on a fast enough machine which rely on this class, two instances can be instantiated within one second and can cause failures because the path already exists that is attempted to be used. Using crypto.randomUUID should not run into this issue.
1 parent 51272f7 commit 0cce7f4

File tree

1 file changed

+4
-1
lines changed
  • packages/angular_devkit/core/node/testing

1 file changed

+4
-1
lines changed

packages/angular_devkit/core/node/testing/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9+
import * as crypto from 'node:crypto';
910
import * as fs from 'node:fs';
1011
import * as os from 'node:os';
1112
import * as path from 'node:path';
@@ -20,7 +21,9 @@ export class TempScopedNodeJsSyncHost extends virtualFs.ScopedHost<fs.Stats> {
2021
protected override _root: Path;
2122

2223
constructor() {
23-
const root = normalize(path.join(os.tmpdir(), `devkit-host-${+Date.now()}-${process.pid}`));
24+
const root = normalize(
25+
path.join(os.tmpdir(), `devkit-host-${crypto.randomUUID()}-${process.pid}`),
26+
);
2427
fs.mkdirSync(getSystemPath(root));
2528

2629
super(new NodeJsSyncHost(), root);

0 commit comments

Comments
 (0)