Skip to content

Commit 7595e1f

Browse files
josephperrottjkrems
authored andcommitted
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 3cd73d3 commit 7595e1f

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy