Skip to content

Commit 2cf2e48

Browse files
authored
Merge pull request microsoft#1437 from nayanshah/intall-run-temp
[rush] install-run doesn't respect RUSH_TEMP_FOLDER environment variable
2 parents 9ca1900 + 88a2680 commit 2cf2e48

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

apps/rush-lib/src/scripts/install-run.ts

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import * as path from 'path';
1919
import { IPackageJson } from '@microsoft/node-core-library';
2020

2121
export const RUSH_JSON_FILENAME: string = 'rush.json';
22+
const RUSH_TEMP_FOLDER_ENV_VARIABLE_NAME: string = 'RUSH_TEMP_FOLDER';
2223
const INSTALLED_FLAG_FILENAME: string = 'installed.flag';
2324
const NODE_MODULES_FOLDER_NAME: string = 'node_modules';
2425
const PACKAGE_JSON_FILENAME: string = 'package.json';
@@ -64,7 +65,7 @@ function resolvePackageVersion(rushCommonFolder: string, { name, version }: IPac
6465
} else {
6566
// version resolves to
6667
try {
67-
const rushTempFolder: string = ensureAndJoinPath(rushCommonFolder, 'temp');
68+
const rushTempFolder: string = getRushTempFolder(rushCommonFolder);
6869
const sourceNpmrcFolder: string = path.join(rushCommonFolder, 'config', 'rush');
6970

7071
syncNpmrc(sourceNpmrcFolder, rushTempFolder);
@@ -276,7 +277,7 @@ function isPackageAlreadyInstalled(packageInstallFolder: string): boolean {
276277
* -
277278
* - node_modules
278279
*/
279-
function cleanInstallFolder(rushCommonFolder: string, packageInstallFolder: string): void {
280+
function cleanInstallFolder(rushTempFolder: string, packageInstallFolder: string): void {
280281
try {
281282
const flagFile: string = path.resolve(packageInstallFolder, INSTALLED_FLAG_FILENAME);
282283
if (fs.existsSync(flagFile)) {
@@ -291,8 +292,7 @@ function cleanInstallFolder(rushCommonFolder: string, packageInstallFolder: stri
291292
const nodeModulesFolder: string = path.resolve(packageInstallFolder, NODE_MODULES_FOLDER_NAME);
292293
if (fs.existsSync(nodeModulesFolder)) {
293294
const rushRecyclerFolder: string = ensureAndJoinPath(
294-
rushCommonFolder,
295-
'temp',
295+
rushTempFolder,
296296
'rush-recycler',
297297
`install-run-${Date.now().toString()}`
298298
);
@@ -371,6 +371,24 @@ function writeFlagFile(packageInstallFolder: string): void {
371371
}
372372
}
373373

374+
function getRushTempFolder(rushCommonFolder: string): string {
375+
const rushTempFolder: string | undefined = process.env[RUSH_TEMP_FOLDER_ENV_VARIABLE_NAME];
376+
if (rushTempFolder !== undefined) {
377+
ensureFolder(rushTempFolder);
378+
return rushTempFolder;
379+
} else {
380+
return ensureAndJoinPath(rushCommonFolder, 'temp');
381+
}
382+
}
383+
384+
function ensureFolder(folderPath: string): void {
385+
if (!fs.existsSync(folderPath)) {
386+
const parentDir: string = path.dirname(folderPath);
387+
ensureFolder(parentDir);
388+
fs.mkdirSync(folderPath);
389+
}
390+
}
391+
374392
export function installAndRun(
375393
packageName: string,
376394
packageVersion: string,
@@ -379,16 +397,16 @@ export function installAndRun(
379397
): number {
380398
const rushJsonFolder: string = findRushJsonFolder();
381399
const rushCommonFolder: string = path.join(rushJsonFolder, 'common');
400+
const rushTempFolder: string = getRushTempFolder(rushCommonFolder);
382401
const packageInstallFolder: string = ensureAndJoinPath(
383-
rushCommonFolder,
384-
'temp',
402+
rushTempFolder,
385403
'install-run',
386404
`${packageName}@${packageVersion}`
387405
);
388406

389407
if (!isPackageAlreadyInstalled(packageInstallFolder)) {
390408
// The package isn't already installed
391-
cleanInstallFolder(rushCommonFolder, packageInstallFolder);
409+
cleanInstallFolder(rushTempFolder, packageInstallFolder);
392410

393411
const sourceNpmrcFolder: string = path.join(rushCommonFolder, 'config', 'rush');
394412
syncNpmrc(sourceNpmrcFolder, packageInstallFolder);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"comment": "Add support for the RUSH_TEMP_FOLDER environment variable in the install-run-rush script.",
5+
"packageName": "@microsoft/rush",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@microsoft/rush",
10+
"email": "nayanshah@users.noreply.github.com"
11+
}

0 commit comments

Comments
 (0)