@@ -6,6 +6,8 @@ import { sync as rimraf } from 'rimraf';
66import { LogLevel } from './log' ;
77import { execSync } from 'child_process' ;
88
9+ const isWindows = process . platform === 'win32' ;
10+
911interface PackageInfo {
1012 name : string ;
1113 folderName : string ;
@@ -58,7 +60,16 @@ function linkBinCommands(
5860 rimraf ( symlinkBinPath ) ; // Remove existing symlink if it exists
5961 }
6062 mkdirp ( path . dirname ( symlinkBinPath ) ) ;
61- fs . symlinkSync ( targetBinPath , symlinkBinPath , 'file' ) ; // Create a symbolic link
63+ try {
64+ fs . symlinkSync ( targetBinPath , symlinkBinPath , isWindows ? 'junction' : 'file' ) ;
65+ } catch ( error : any ) {
66+ if ( isWindows && error . code === 'EPERM' ) {
67+ log ( `[${ chalk . magenta ( packageName ) } ]: Windows requires admin privileges for symlinks. Using junction instead.` , 'warn' ) ;
68+ fs . symlinkSync ( targetBinPath , symlinkBinPath , 'junction' ) ;
69+ } else {
70+ throw error ;
71+ }
72+ }
6273 log ( `[${ chalk . magenta ( packageName ) } ]: command ${ chalk . green ( binCommand ) } link ${ chalk . blue ( symlinkBinPath ) } ` , 'info' ) ;
6374 log ( `[${ chalk . magenta ( packageName ) } ]: command ${ chalk . green ( binCommand ) } target ${ chalk . green ( targetBinPath ) } ` , 'info' ) ;
6475 } ) ;
@@ -79,7 +90,16 @@ function linkModule(
7990 rimraf ( symlinkTarget ) ;
8091 }
8192 mkdirp ( path . dirname ( symlinkTarget ) ) ;
82- fs . symlinkSync ( depDistPath , symlinkTarget , 'junction' ) ;
93+ try {
94+ fs . symlinkSync ( depDistPath , symlinkTarget , isWindows ? 'junction' : 'dir' ) ;
95+ } catch ( error : any ) {
96+ if ( isWindows && error . code === 'EPERM' ) {
97+ log ( `[${ chalk . blue ( packageInfo . name ) } ]: Windows requires admin privileges for symlinks. Using junction.` , 'warn' ) ;
98+ fs . symlinkSync ( depDistPath , symlinkTarget , 'junction' ) ;
99+ } else {
100+ throw error ;
101+ }
102+ }
83103
84104
85105}
@@ -127,7 +147,16 @@ export function processPackages(
127147 const distPath = path . join ( packageInfo . path , 'dist' ) ;
128148 log ( chalk . yellow ( `Creating symlink in root for ${ packageName } ` ) , 'info' ) ;
129149 mkdirp ( path . dirname ( symlinkPath ) ) ;
130- fs . symlinkSync ( distPath , symlinkPath , 'junction' ) ;
150+ try {
151+ fs . symlinkSync ( distPath , symlinkPath , isWindows ? 'junction' : 'dir' ) ;
152+ } catch ( error : any ) {
153+ if ( isWindows && error . code === 'EPERM' ) {
154+ log ( chalk . yellow ( `Windows requires admin privileges for symlinks. Using junction for ${ packageName } .` ) , 'warn' ) ;
155+ fs . symlinkSync ( distPath , symlinkPath , 'junction' ) ;
156+ } else {
157+ throw error ;
158+ }
159+ }
131160 // END MODULE
132161 } ) ;
133162
0 commit comments