Skip to content

Commit c9d0711

Browse files
committed
pkg
1 parent 3de88bf commit c9d0711

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"name": "symlink-workspace",
3-
"version": "1.9.0",
3+
"version": "1.11.0",
44
"description": "create symlinks in lerna/yarn workspaces for publish setups requiring both esm and cjs builds",
55
"author": "Dan Lynch <pyramation@gmail.com>",
6-
"homepage": "https://github.com/cosmology-tech/symlink-workspace#readme",
6+
"homepage": "https://github.com/hyperweb-io/symlink-workspace#readme",
77
"license": "SEE LICENSE IN LICENSE",
88
"main": "main/index.js",
99
"directories": {
@@ -45,11 +45,11 @@
4545
},
4646
"repository": {
4747
"type": "git",
48-
"url": "https://github.com/cosmology-tech/symlink-workspace"
48+
"url": "https://github.com/hyperweb-io/symlink-workspace"
4949
},
5050
"keywords": [],
5151
"bugs": {
52-
"url": "https://github.com/cosmology-tech/symlink-workspace/issues"
52+
"url": "https://github.com/hyperweb-io/symlink-workspace/issues"
5353
},
5454
"devDependencies": {
5555
"@types/jest": "^29.5.12",

src/create-symlinks.ts

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { sync as rimraf } from 'rimraf';
66
import { LogLevel } from './log';
77
import { execSync } from 'child_process';
88

9+
const isWindows = process.platform === 'win32';
10+
911
interface 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

Comments
 (0)