@@ -18,6 +18,7 @@ import { spawnSync } from 'node:child_process';
1818import fs from 'node:fs' ;
1919import path from 'node:path' ;
2020import { performance } from 'node:perf_hooks' ;
21+ import { fileURLToPath } from 'node:url' ;
2122import { type FixtureOptions , type Layout , type Style , generateFixture } from './fixtures.mts' ;
2223
2324export interface LibraryBuilderBenchmarkOptions {
@@ -42,7 +43,7 @@ export interface BuildMeasurement {
4243 status : 'ok' | 'fail' ;
4344}
4445
45- const repoRoot = path . resolve ( import . meta . dirname , '../../..' ) ;
46+ const repoRoot = fileURLToPath ( new URL ( '../../../' , import . meta . url ) ) ;
4647const scratchRoot = path . join ( repoRoot , 'dist' , '.library-builder-benchmark-tmp' ) ;
4748const rootNodeModules = path . join ( repoRoot , 'node_modules' ) ;
4849const pnpmStore = path . join ( rootNodeModules , '.pnpm' ) ;
@@ -119,9 +120,21 @@ function ensureBuilderDepsLinkedAtRepoRoot(
119120
120121function linkIfMissing ( name : string , target : string ) : void {
121122 const linkPath = path . join ( rootNodeModules , name ) ;
122- if ( ! fs . existsSync ( linkPath ) ) {
123- fs . symlinkSync ( target , linkPath , 'dir' ) ;
123+ try {
124+ const stat = fs . lstatSync ( linkPath ) ;
125+ if ( stat . isSymbolicLink ( ) && ! fs . existsSync ( linkPath ) ) {
126+ // Remove broken symlink to avoid EEXIST error on recreation
127+ fs . unlinkSync ( linkPath ) ;
128+ } else {
129+ // Symlink already exists and is valid
130+ return ;
131+ }
132+ } catch ( e : any ) {
133+ if ( e . code !== 'ENOENT' ) {
134+ throw e ;
135+ }
124136 }
137+ fs . symlinkSync ( target , linkPath , 'dir' ) ;
125138}
126139
127140/** Resolves `dep` (e.g. "rxjs" or "@angular-devkit/core") to its pnpm store dir and symlinks it. */
0 commit comments