From c04974914aa055cbac5977e358be6b926a5a91d7 Mon Sep 17 00:00:00 2001 From: Joey Perrott Date: Thu, 17 Jul 2025 18:18:01 +0000 Subject: [PATCH] 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. --- packages/angular_devkit/core/node/testing/index.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/angular_devkit/core/node/testing/index.ts b/packages/angular_devkit/core/node/testing/index.ts index fb520d9361f9..cecc0c08e3c6 100644 --- a/packages/angular_devkit/core/node/testing/index.ts +++ b/packages/angular_devkit/core/node/testing/index.ts @@ -6,6 +6,7 @@ * found in the LICENSE file at https://angular.dev/license */ +import * as crypto from 'node:crypto'; import * as fs from 'node:fs'; import * as os from 'node:os'; import * as path from 'node:path'; @@ -20,7 +21,9 @@ export class TempScopedNodeJsSyncHost extends virtualFs.ScopedHost { protected override _root: Path; constructor() { - const root = normalize(path.join(os.tmpdir(), `devkit-host-${+Date.now()}-${process.pid}`)); + const root = normalize( + path.join(os.tmpdir(), `devkit-host-${crypto.randomUUID()}-${process.pid}`), + ); fs.mkdirSync(getSystemPath(root)); super(new NodeJsSyncHost(), root);