@@ -26,8 +26,6 @@ const skipDirectories = [
2626 '_windows_amd64/bin/nodejs/node_modules' ,
2727] ;
2828
29- const workspaceRootPaths = [ / .* \. r u n f i l e s \/ _ m a i n \/ / , / ^ .* - f a s t b u i l d \/ b i n \/ / ] ;
30-
3129// Copying can be parallelized and doesn't cause any WSL flakiness (no exe is invoked).
3230const parallelCopyTasks = [ ] ;
3331
@@ -51,58 +49,40 @@ async function transformDir(p) {
5149 // Allow for parallel processing of directory entries.
5250 tasks . push (
5351 ( async ( ) => {
54- let target = '' ;
52+ let realTarget = '' ;
53+ let linkTarget = '' ;
54+
5555 try {
56- target = await fs . realpath ( subPath ) ;
56+ realTarget = await fs . realpath ( subPath ) ;
57+ linkTarget = await fs . readlink ( subPath ) ;
5758 } catch ( e ) {
5859 if ( debug ) {
59- console . error ( 'Skipping' , subPath ) ;
60+ console . error ( 'Skipping; cannot dereference & read link ' , subPath ) ;
6061 }
6162 return ;
6263 }
6364
6465 await fs . rm ( subPath ) ;
6566
66- const subPathId = relativizeForSimilarWorkspacePaths ( subPath ) ;
67- const targetPathId = relativizeForSimilarWorkspacePaths ( target ) ;
68- const isSelfLink = subPathId === targetPathId ;
69-
70- // This is an actual file that needs to be copied. Copy contents.
71- // - the target path is equivalent to the link. This is a self-link from `.runfiles` to `bin/`.
72- // - the target path is outside any of our workspace roots.
73- if ( isSelfLink || targetPathId . startsWith ( '..' ) ) {
74- parallelCopyTasks . push ( exec ( `cp -Rf ${ target } ${ subPath } ` ) ) ;
67+ // Transform relative links but preserve them.
68+ // This is needed for pnpm.
69+ if ( ! path . isAbsolute ( linkTarget ) ) {
70+ const wslSubPath = path . relative ( rootDir , subPath ) . replace ( / \/ / g, '\\' ) ;
71+ const linkTargetWindowsPath = linkTarget . replace ( / \/ / g, '\\' ) ;
72+
73+ if ( ( await fs . stat ( realTarget ) ) . isDirectory ( ) ) {
74+ // This is a symlink to a directory, create a dir junction.
75+ // Re-create this symlink on the Windows FS using the Windows mklink command.
76+ await exec ( `${ cmdPath } /c mklink /d "${ wslSubPath } " "${ linkTargetWindowsPath } "` ) ;
77+ } else {
78+ // This is a symlink to a file, create a file junction.
79+ // Re-create this symlink on the Windows FS using the Windows mklink command.
80+ await exec ( `${ cmdPath } /c mklink "${ wslSubPath } " "${ linkTargetWindowsPath } "` ) ;
81+ }
7582 return ;
7683 }
7784
78- const relativeSubPath = relativizeToRoot ( subPath ) ;
79- const targetAtDestination = path . relative ( path . dirname ( subPathId ) , targetPathId ) ;
80- const targetAtDestinationWindowsPath = targetAtDestination . replace ( / \/ / g, '\\' ) ;
81-
82- const wslSubPath = relativeSubPath . replace ( / \/ / g, '\\' ) ;
83-
84- if ( debug ) {
85- console . log ( {
86- targetAtDestination,
87- subPath,
88- relativeSubPath,
89- target,
90- targetPathId,
91- subPathId,
92- } ) ;
93- }
94-
95- if ( ( await fs . stat ( target ) ) . isDirectory ( ) ) {
96- // This is a symlink to a directory, create a dir junction.
97- // Re-create this symlink on the Windows FS using the Windows mklink command.
98- await exec (
99- `${ cmdPath } /c mklink /d "${ wslSubPath } " "${ targetAtDestinationWindowsPath } "` ,
100- ) ;
101- } else {
102- // This is a symlink to a file, create a file junction.
103- // Re-create this symlink on the Windows FS using the Windows mklink command.
104- await exec ( `${ cmdPath } /c mklink "${ wslSubPath } " "${ targetAtDestinationWindowsPath } "` ) ;
105- }
85+ parallelCopyTasks . push ( exec ( `cp -Rf ${ realTarget } ${ subPath } ` ) ) ;
10686 } ) ( ) ,
10787 ) ;
10888 } else if ( file . isDirectory ( ) ) {
@@ -143,24 +123,6 @@ function exec(cmd, maxRetries = 2) {
143123 } ) ;
144124}
145125
146- function relativizeForSimilarWorkspacePaths ( p ) {
147- const workspaceRootMatch = workspaceRootPaths . find ( ( r ) => r . test ( p ) ) ;
148- if ( workspaceRootMatch !== undefined ) {
149- return p . replace ( workspaceRootMatch , '' ) ;
150- }
151-
152- return path . relative ( rootDir , p ) ;
153- }
154-
155- function relativizeToRoot ( p ) {
156- const res = path . relative ( rootDir , p ) ;
157- if ( ! res . startsWith ( '..' ) ) {
158- return res ;
159- }
160-
161- throw new Error ( 'Could not relativize to root: ' + p ) ;
162- }
163-
164126try {
165127 await transformDir ( rootDir ) ;
166128 await Promise . all ( parallelCopyTasks ) ;
0 commit comments