@@ -6,7 +6,7 @@ import * as fs from 'fs';
66import * as os from 'os' ;
77import * as path from 'path' ;
88
9- import { FileSystem } from '@microsoft/node-core-library' ;
9+ import { FileSystem , IFileSystemCreateLinkOptions } from '@microsoft/node-core-library' ;
1010
1111import { RushConfiguration } from '../../api/RushConfiguration' ;
1212import { Utilities } from '../../utilities/Utilities' ;
@@ -18,24 +18,37 @@ export enum SymlinkKind {
1818 Directory
1919}
2020
21+ export interface IBaseLinkManagerCreateSymlinkOptions extends IFileSystemCreateLinkOptions {
22+ symlinkKind : SymlinkKind ;
23+ }
24+
2125export abstract class BaseLinkManager {
2226 protected _rushConfiguration : RushConfiguration ;
2327
24- protected static _createSymlink ( linkTarget : string , linkSource : string , symlinkKind : SymlinkKind ) : void {
25- FileSystem . ensureFolder ( path . dirname ( linkSource ) ) ;
28+ protected static _createSymlink ( options : IBaseLinkManagerCreateSymlinkOptions ) : void {
29+ FileSystem . ensureFolder ( path . dirname ( options . newLinkPath ) ) ;
2630
27- if ( symlinkKind === SymlinkKind . Directory ) {
31+ if ( options . symlinkKind === SymlinkKind . Directory ) {
2832 // For directories, we use a Windows "junction". On Unix, this produces a regular symlink.
29- FileSystem . createSymbolicLinkJunction ( linkTarget , linkSource ) ;
33+ FileSystem . createSymbolicLinkJunction ( {
34+ linkTargetPath : options . linkTargetPath ,
35+ newLinkPath : options . newLinkPath
36+ } ) ;
3037 } else {
3138 if ( process . platform === 'win32' ) {
3239 // For files, we use a Windows "hard link", because creating a symbolic link requires
3340 // administrator permission.
34- FileSystem . createHardLink ( linkTarget , linkSource ) ;
41+ FileSystem . createHardLink ( {
42+ linkTargetPath : options . linkTargetPath ,
43+ newLinkPath : options . newLinkPath
44+ } ) ;
3545 } else {
3646 // However hard links seem to cause build failures on Mac, so for all other operating systems
3747 // we use symbolic links for this case.
38- FileSystem . createSymbolicLinkFile ( linkTarget , linkSource ) ;
48+ FileSystem . createSymbolicLinkFile ( {
49+ linkTargetPath : options . linkTargetPath ,
50+ newLinkPath : options . newLinkPath
51+ } ) ;
3952 }
4053 }
4154 }
@@ -91,10 +104,11 @@ export abstract class BaseLinkManager {
91104
92105 if ( localPackage . children . length === 0 ) {
93106 // If there are no children, then we can symlink the entire folder
94- BaseLinkManager . _createSymlink (
95- localPackage . symlinkTargetFolderPath ,
96- localPackage . folderPath ,
97- SymlinkKind . Directory ) ;
107+ BaseLinkManager . _createSymlink ( {
108+ linkTargetPath : localPackage . symlinkTargetFolderPath ,
109+ newLinkPath : localPackage . folderPath ,
110+ symlinkKind : SymlinkKind . Directory
111+ } ) ;
98112 } else {
99113 // If there are children, then we need to symlink each item in the folder individually
100114 Utilities . createFolderWithRetry ( localPackage . folderPath ) ;
@@ -126,7 +140,11 @@ export abstract class BaseLinkManager {
126140 symlinkKind = SymlinkKind . Directory ;
127141 }
128142
129- BaseLinkManager . _createSymlink ( linkTarget , linkSource , symlinkKind ) ;
143+ BaseLinkManager . _createSymlink ( {
144+ linkTargetPath : linkTarget ,
145+ newLinkPath : linkSource ,
146+ symlinkKind
147+ } ) ;
130148 }
131149 }
132150 }
0 commit comments