Skip to content

Commit d1cc3ce

Browse files
committed
[rush] Include RUSH_ABSOLUTE_SYMLINKS env variable option
1 parent 68a0988 commit d1cc3ce

3 files changed

Lines changed: 36 additions & 8 deletions

File tree

‎apps/rush-lib/src/api/EnvironmentConfiguration.ts‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ export const enum EnvironmentVariableNames {
2626
* and linking package dependencies. For more information, see this article:
2727
* https://rushjs.io/pages/advanced/installation_variants/
2828
*/
29-
RUSH_VARIANT = 'RUSH_VARIANT'
29+
RUSH_VARIANT = 'RUSH_VARIANT',
30+
31+
/**
32+
* If this variable is set to "true", Rush will create symlinks with absolute paths instead
33+
* of relative paths.
34+
*/
35+
RUSH_ABSOLUTE_SYMLINKS = 'RUSH_ABSOLUTE_SYMLINKS'
3036
}
3137

3238
/**
@@ -41,6 +47,8 @@ export class EnvironmentConfiguration {
4147

4248
private static _rushTempFolderOverride: string | undefined;
4349

50+
private static _absoluteSymlinks: boolean = false;
51+
4452
/**
4553
* An override for the common/temp folder path.
4654
*/
@@ -49,6 +57,11 @@ export class EnvironmentConfiguration {
4957
return EnvironmentConfiguration._rushTempFolderOverride;
5058
}
5159

60+
public static get absoluteSymlinks(): boolean {
61+
EnvironmentConfiguration._ensureInitialized();
62+
return EnvironmentConfiguration._absoluteSymlinks;
63+
}
64+
5265
/**
5366
* Reads and validates environment variables. If any are invalid, this function will throw.
5467
*/
@@ -62,9 +75,15 @@ export class EnvironmentConfiguration {
6275
// Environment variables are only case-insensitive on Windows
6376
const normalizedEnvVarName: string = os.platform() === 'win32' ? envVarName.toUpperCase() : envVarName;
6477
switch (normalizedEnvVarName) {
65-
case EnvironmentVariableNames.RUSH_TEMP_FOLDER:
78+
case EnvironmentVariableNames.RUSH_TEMP_FOLDER: {
6679
EnvironmentConfiguration._rushTempFolderOverride = value;
6780
break;
81+
}
82+
83+
case EnvironmentVariableNames.RUSH_ABSOLUTE_SYMLINKS: {
84+
EnvironmentConfiguration._absoluteSymlinks = value === 'true';
85+
break;
86+
}
6887

6988
case EnvironmentVariableNames.RUSH_PREVIEW_VERSION:
7089
case EnvironmentVariableNames.RUSH_VARIANT:

‎apps/rush-lib/src/logic/base/BaseLinkManager.ts‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { RushConfiguration } from '../../api/RushConfiguration';
1212
import { Utilities } from '../../utilities/Utilities';
1313
import { Stopwatch } from '../../utilities/Stopwatch';
1414
import { BasePackage } from './BasePackage';
15+
import { EnvironmentConfiguration } from '../../api/EnvironmentConfiguration';
1516

1617
export enum SymlinkKind {
1718
File,
@@ -29,15 +30,22 @@ export abstract class BaseLinkManager {
2930
const newLinkFolder: string = path.dirname(options.newLinkPath);
3031
FileSystem.ensureFolder(newLinkFolder);
3132

32-
// Link to the relative path, to avoid going outside containers such as a Docker image
33-
const targetRelativePath: string = path.relative(fs.realpathSync(newLinkFolder),
34-
options.linkTargetPath);
33+
let targetPath: string;
34+
if (EnvironmentConfiguration.absoluteSymlinks) {
35+
targetPath = options.linkTargetPath;
36+
} else {
37+
// Link to the relative path, to avoid going outside containers such as a Docker image
38+
targetPath = path.relative(
39+
fs.realpathSync(newLinkFolder),
40+
options.linkTargetPath
41+
);
42+
}
3543

3644
if (process.platform === 'win32') {
3745
if (options.symlinkKind === SymlinkKind.Directory) {
3846
// For directories, we use a Windows "junction". On Unix, this produces a regular symlink.
3947
FileSystem.createSymbolicLinkJunction({
40-
linkTargetPath: targetRelativePath,
48+
linkTargetPath: targetPath,
4149
newLinkPath: options.newLinkPath
4250
});
4351
} else {
@@ -55,12 +63,12 @@ export abstract class BaseLinkManager {
5563
// we use symbolic links for this case.
5664
if (options.symlinkKind === SymlinkKind.Directory) {
5765
FileSystem.createSymbolicLinkFolder({
58-
linkTargetPath: targetRelativePath,
66+
linkTargetPath: targetPath,
5967
newLinkPath: options.newLinkPath
6068
});
6169
} else {
6270
FileSystem.createSymbolicLinkFile({
63-
linkTargetPath: targetRelativePath,
71+
linkTargetPath: targetPath,
6472
newLinkPath: options.newLinkPath
6573
});
6674
}

‎common/reviews/api/rush-lib.api.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ enum DependencyType {
9393

9494
// @public
9595
enum EnvironmentVariableNames {
96+
RUSH_ABSOLUTE_SYMLINKS = "RUSH_ABSOLUTE_SYMLINKS",
9697
RUSH_PREVIEW_VERSION = "RUSH_PREVIEW_VERSION",
9798
RUSH_TEMP_FOLDER = "RUSH_TEMP_FOLDER",
9899
RUSH_VARIANT = "RUSH_VARIANT"

0 commit comments

Comments
 (0)