Skip to content

Commit b52679c

Browse files
committed
Some cleanup of the install-run*.js scripts.
1 parent de983f4 commit b52679c

File tree

3 files changed

+53
-37
lines changed

3 files changed

+53
-37
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
const PACKAGE_NAME: string = '@microsoft/rush';
2626
const RUSH_PREVIEW_VERSION: string = 'RUSH_PREVIEW_VERSION';
2727

28-
function getRushVersion(): string {
28+
function _getRushVersion(): string {
2929
const rushPreviewVersion: string | undefined = process.env[RUSH_PREVIEW_VERSION];
3030
if (rushPreviewVersion !== undefined) {
3131
console.log(`Using Rush version from environment variable ${RUSH_PREVIEW_VERSION}=${rushPreviewVersion}`);
@@ -49,7 +49,7 @@ function getRushVersion(): string {
4949
}
5050
}
5151

52-
function run(): void {
52+
function _run(): void {
5353
const [
5454
nodePath, /* Ex: /bin/node */
5555
scriptPath, /* /repo/common/scripts/install-run-rush.js */
@@ -75,11 +75,11 @@ function run(): void {
7575
}
7676

7777
runWithErrorAndStatusCode(() => {
78-
const version: string = getRushVersion();
78+
const version: string = _getRushVersion();
7979
console.log(`The rush.json configuration requests Rush version ${version}`);
8080

8181
return installAndRun(PACKAGE_NAME, version, bin, packageBinArgs);
8282
});
8383
}
8484

85-
run();
85+
_run();
Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,17 @@
1-
import './install-run-rush';
1+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
2+
// See the @microsoft/rush package's LICENSE file for license information.
3+
4+
// THIS FILE WAS GENERATED BY A TOOL. ANY MANUAL MODIFICATIONS WILL GET OVERWRITTEN WHENEVER RUSH IS UPGRADED.
5+
//
6+
// This script is intended for usage in an automated build environment where the Rush command may not have
7+
// been preinstalled, or may have an unpredictable version. This script will automatically install the version of Rush
8+
// specified in the rush.json configuration file (if not already installed), and then pass a command-line to the
9+
// rushx command.
10+
//
11+
// An example usage would be:
12+
//
13+
// node common/scripts/install-run-rushx.js custom-command
14+
//
15+
// For more information, see: https://rushjs.io/pages/maintainer/setup_new_repo/
16+
17+
import './install-run-rush';

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

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const PACKAGE_JSON_FILENAME: string = 'package.json';
2727
/**
2828
* Parse a package specifier (in the form of name\@version) into name and version parts.
2929
*/
30-
function parsePackageSpecifier(rawPackageSpecifier: string): IPackageSpecifier {
30+
function _parsePackageSpecifier(rawPackageSpecifier: string): IPackageSpecifier {
3131
rawPackageSpecifier = (rawPackageSpecifier || '').trim();
3232
const separatorIndex: number = rawPackageSpecifier.lastIndexOf('@');
3333

@@ -53,7 +53,7 @@ function parsePackageSpecifier(rawPackageSpecifier: string): IPackageSpecifier {
5353
/**
5454
* Resolve a package specifier to a static version
5555
*/
56-
function resolvePackageVersion(rushCommonFolder: string, { name, version }: IPackageSpecifier): string {
56+
function _resolvePackageVersion(rushCommonFolder: string, { name, version }: IPackageSpecifier): string {
5757
if (!version) {
5858
version = '*'; // If no version is specified, use the latest version
5959
}
@@ -65,10 +65,10 @@ function resolvePackageVersion(rushCommonFolder: string, { name, version }: IPac
6565
} else {
6666
// version resolves to
6767
try {
68-
const rushTempFolder: string = getRushTempFolder(rushCommonFolder);
68+
const rushTempFolder: string = _getRushTempFolder(rushCommonFolder);
6969
const sourceNpmrcFolder: string = path.join(rushCommonFolder, 'config', 'rush');
7070

71-
syncNpmrc(sourceNpmrcFolder, rushTempFolder);
71+
_syncNpmrc(sourceNpmrcFolder, rushTempFolder);
7272

7373
const npmPath: string = getNpmPath();
7474

@@ -179,7 +179,7 @@ export function findRushJsonFolder(): string {
179179
* Does not support "." or ".." path segments.
180180
* Assumes the baseFolder exists.
181181
*/
182-
function ensureAndJoinPath(baseFolder: string, ...pathSegments: string[]): string {
182+
function _ensureAndJoinPath(baseFolder: string, ...pathSegments: string[]): string {
183183
let joinedPath: string = baseFolder;
184184
try {
185185
for (let pathSegment of pathSegments) {
@@ -210,7 +210,7 @@ function ensureAndJoinPath(baseFolder: string, ...pathSegments: string[]): strin
210210
*
211211
* IMPORTANT: THIS CODE SHOULD BE KEPT UP TO DATE WITH Utilities._syncNpmrc()
212212
*/
213-
function syncNpmrc(sourceNpmrcFolder: string, targetNpmrcFolder: string): void {
213+
function _syncNpmrc(sourceNpmrcFolder: string, targetNpmrcFolder: string): void {
214214
const sourceNpmrcPath: string = path.join(sourceNpmrcFolder, '.npmrc');
215215
const targetNpmrcPath: string = path.join(targetNpmrcFolder, '.npmrc');
216216
try {
@@ -257,7 +257,7 @@ function syncNpmrc(sourceNpmrcFolder: string, targetNpmrcFolder: string): void {
257257
/**
258258
* Detects if the package in the specified directory is installed
259259
*/
260-
function isPackageAlreadyInstalled(packageInstallFolder: string): boolean {
260+
function _isPackageAlreadyInstalled(packageInstallFolder: string): boolean {
261261
try {
262262
const flagFilePath: string = path.join(packageInstallFolder, INSTALLED_FLAG_FILENAME);
263263
if (!fs.existsSync(flagFilePath)) {
@@ -277,7 +277,7 @@ function isPackageAlreadyInstalled(packageInstallFolder: string): boolean {
277277
* -
278278
* - node_modules
279279
*/
280-
function cleanInstallFolder(rushTempFolder: string, packageInstallFolder: string): void {
280+
function _cleanInstallFolder(rushTempFolder: string, packageInstallFolder: string): void {
281281
try {
282282
const flagFile: string = path.resolve(packageInstallFolder, INSTALLED_FLAG_FILENAME);
283283
if (fs.existsSync(flagFile)) {
@@ -291,7 +291,7 @@ function cleanInstallFolder(rushTempFolder: string, packageInstallFolder: string
291291

292292
const nodeModulesFolder: string = path.resolve(packageInstallFolder, NODE_MODULES_FOLDER_NAME);
293293
if (fs.existsSync(nodeModulesFolder)) {
294-
const rushRecyclerFolder: string = ensureAndJoinPath(
294+
const rushRecyclerFolder: string = _ensureAndJoinPath(
295295
rushTempFolder,
296296
'rush-recycler',
297297
`install-run-${Date.now().toString()}`
@@ -303,7 +303,7 @@ function cleanInstallFolder(rushTempFolder: string, packageInstallFolder: string
303303
}
304304
}
305305

306-
function createPackageJson(packageInstallFolder: string, name: string, version: string): void {
306+
function _createPackageJson(packageInstallFolder: string, name: string, version: string): void {
307307
try {
308308
const packageJsonContents: IPackageJson = {
309309
'name': 'ci-rush',
@@ -326,7 +326,7 @@ function createPackageJson(packageInstallFolder: string, name: string, version:
326326
/**
327327
* Run "npm install" in the package install folder.
328328
*/
329-
function installPackage(packageInstallFolder: string, name: string, version: string): void {
329+
function _installPackage(packageInstallFolder: string, name: string, version: string): void {
330330
try {
331331
console.log(`Installing ${name}...`);
332332
const npmPath: string = getNpmPath();
@@ -353,7 +353,7 @@ function installPackage(packageInstallFolder: string, name: string, version: str
353353
/**
354354
* Get the ".bin" path for the package.
355355
*/
356-
function getBinPath(packageInstallFolder: string, binName: string): string {
356+
function _getBinPath(packageInstallFolder: string, binName: string): string {
357357
const binFolderPath: string = path.resolve(packageInstallFolder, NODE_MODULES_FOLDER_NAME, '.bin');
358358
const resolvedBinName: string = (os.platform() === 'win32') ? `${binName}.cmd` : binName;
359359
return path.resolve(binFolderPath, resolvedBinName);
@@ -362,7 +362,7 @@ function getBinPath(packageInstallFolder: string, binName: string): string {
362362
/**
363363
* Write a flag file to the package's install directory, signifying that the install was successful.
364364
*/
365-
function writeFlagFile(packageInstallFolder: string): void {
365+
function _writeFlagFile(packageInstallFolder: string): void {
366366
try {
367367
const flagFilePath: string = path.join(packageInstallFolder, INSTALLED_FLAG_FILENAME);
368368
fs.writeFileSync(flagFilePath, process.version);
@@ -371,20 +371,20 @@ function writeFlagFile(packageInstallFolder: string): void {
371371
}
372372
}
373373

374-
function getRushTempFolder(rushCommonFolder: string): string {
374+
function _getRushTempFolder(rushCommonFolder: string): string {
375375
const rushTempFolder: string | undefined = process.env[RUSH_TEMP_FOLDER_ENV_VARIABLE_NAME];
376376
if (rushTempFolder !== undefined) {
377-
ensureFolder(rushTempFolder);
377+
_ensureFolder(rushTempFolder);
378378
return rushTempFolder;
379379
} else {
380-
return ensureAndJoinPath(rushCommonFolder, 'temp');
380+
return _ensureAndJoinPath(rushCommonFolder, 'temp');
381381
}
382382
}
383383

384-
function ensureFolder(folderPath: string): void {
384+
function _ensureFolder(folderPath: string): void {
385385
if (!fs.existsSync(folderPath)) {
386386
const parentDir: string = path.dirname(folderPath);
387-
ensureFolder(parentDir);
387+
_ensureFolder(parentDir);
388388
fs.mkdirSync(folderPath);
389389
}
390390
}
@@ -397,30 +397,30 @@ export function installAndRun(
397397
): number {
398398
const rushJsonFolder: string = findRushJsonFolder();
399399
const rushCommonFolder: string = path.join(rushJsonFolder, 'common');
400-
const rushTempFolder: string = getRushTempFolder(rushCommonFolder);
401-
const packageInstallFolder: string = ensureAndJoinPath(
400+
const rushTempFolder: string = _getRushTempFolder(rushCommonFolder);
401+
const packageInstallFolder: string = _ensureAndJoinPath(
402402
rushTempFolder,
403403
'install-run',
404404
`${packageName}@${packageVersion}`
405405
);
406406

407-
if (!isPackageAlreadyInstalled(packageInstallFolder)) {
407+
if (!_isPackageAlreadyInstalled(packageInstallFolder)) {
408408
// The package isn't already installed
409-
cleanInstallFolder(rushTempFolder, packageInstallFolder);
409+
_cleanInstallFolder(rushTempFolder, packageInstallFolder);
410410

411411
const sourceNpmrcFolder: string = path.join(rushCommonFolder, 'config', 'rush');
412-
syncNpmrc(sourceNpmrcFolder, packageInstallFolder);
412+
_syncNpmrc(sourceNpmrcFolder, packageInstallFolder);
413413

414-
createPackageJson(packageInstallFolder, packageName, packageVersion);
415-
installPackage(packageInstallFolder, packageName, packageVersion);
416-
writeFlagFile(packageInstallFolder);
414+
_createPackageJson(packageInstallFolder, packageName, packageVersion);
415+
_installPackage(packageInstallFolder, packageName, packageVersion);
416+
_writeFlagFile(packageInstallFolder);
417417
}
418418

419419
const statusMessage: string = `Invoking "${packageBinName} ${packageBinArgs.join(' ')}"`;
420420
const statusMessageLine: string = new Array(statusMessage.length + 1).join('-');
421421
console.log(os.EOL + statusMessage + os.EOL + statusMessageLine + os.EOL);
422422

423-
const binPath: string = getBinPath(packageInstallFolder, packageBinName);
423+
const binPath: string = _getBinPath(packageInstallFolder, packageBinName);
424424
const result: childProcess.SpawnSyncReturns<Buffer> = childProcess.spawnSync(
425425
binPath,
426426
packageBinArgs,
@@ -445,7 +445,7 @@ export function runWithErrorAndStatusCode(fn: () => number): void {
445445
}
446446
}
447447

448-
function run(): void {
448+
function _run(): void {
449449
const [
450450
nodePath, /* Ex: /bin/node */
451451
scriptPath, /* /repo/common/scripts/install-run-rush.js */
@@ -473,11 +473,11 @@ function run(): void {
473473

474474
runWithErrorAndStatusCode(() => {
475475
const rushJsonFolder: string = findRushJsonFolder();
476-
const rushCommonFolder: string = ensureAndJoinPath(rushJsonFolder, 'common');
476+
const rushCommonFolder: string = _ensureAndJoinPath(rushJsonFolder, 'common');
477477

478-
const packageSpecifier: IPackageSpecifier = parsePackageSpecifier(rawPackageSpecifier);
478+
const packageSpecifier: IPackageSpecifier = _parsePackageSpecifier(rawPackageSpecifier);
479479
const name: string = packageSpecifier.name;
480-
const version: string = resolvePackageVersion(rushCommonFolder, packageSpecifier);
480+
const version: string = _resolvePackageVersion(rushCommonFolder, packageSpecifier);
481481

482482
if (packageSpecifier.version !== version) {
483483
console.log(`Resolved to ${name}@${version}`);
@@ -487,4 +487,4 @@ function run(): void {
487487
});
488488
}
489489

490-
run();
490+
_run();

0 commit comments

Comments
 (0)