Skip to content

Commit b50bb86

Browse files
authored
Merge pull request microsoft#672 from Microsoft/pgonzal/rush-fixes
[rush] Fix some miscellaneous issues in preparation for Rush 5
2 parents f4e3e95 + 14075c4 commit b50bb86

13 files changed

Lines changed: 108 additions & 25 deletions

apps/rush-lib/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"node": ">=5.6.0"
1111
},
1212
"engineStrict": true,
13-
"homepage": "http://aka.ms/rush",
13+
"homepage": "https://rushjs.io",
1414
"main": "lib/index.js",
1515
"typings": "dist/rush-lib.d.ts",
1616
"tsdoc": {

apps/rush-lib/src/RushConstants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export namespace RushConstants {
116116
/**
117117
* The URL ("http://rushjs.io") for the Rush web site.
118118
*/
119-
export const rushWebSiteUrl: string = 'http://rushjs.io';
119+
export const rushWebSiteUrl: string = 'https://rushjs.io';
120120

121121
/**
122122
* The name of the NPM package for the Rush tool ("@microsoft/rush").

apps/rush-lib/src/cli/actions/BaseInstallAction.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { BaseRushAction } from './BaseRushAction';
1010
import { Event } from '../../data/EventHooks';
1111
import { InstallManager, IInstallManagerOptions } from '../logic/InstallManager';
1212
import { PurgeManager } from '../logic/PurgeManager';
13+
import { SetupChecks } from '../logic/SetupChecks';
1314
import { Stopwatch } from '../../utilities/Stopwatch';
1415

1516
/**
@@ -44,6 +45,8 @@ export abstract class BaseInstallAction extends BaseRushAction {
4445
protected run(): Promise<void> {
4546
const stopwatch: Stopwatch = Stopwatch.start();
4647

48+
SetupChecks.validate(this.rushConfiguration);
49+
4750
this.eventHooksManager.handle(Event.preRushInstall, this.parser.isDebug);
4851

4952
const purgeManager: PurgeManager = new PurgeManager(this.rushConfiguration);

apps/rush-lib/src/cli/actions/CommandLineMigrationAdvisor.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// See LICENSE in the project root for license information.
33

44
import * as colors from 'colors';
5-
import * as wordwrap from 'wordwrap';
65

76
import { RushConstants } from '../../RushConstants';
87
import { Utilities } from '../../utilities/Utilities';
@@ -24,16 +23,26 @@ export class CommandLineMigrationAdvisor {
2423
}
2524

2625
if (args[0] === 'install') {
27-
if (args.indexOf('-C') >= 0 || args.indexOf('--full-clean') >= 0) {
26+
if (args.indexOf('--full-clean') >= 0) {
2827
CommandLineMigrationAdvisor._reportDeprecated(
2928
'Instead of "rush install --full-clean", use "rush purge --unsafe".');
3029
return false;
3130
}
32-
if (args.indexOf('-c') >= 0 || args.indexOf('--clean') >= 0) {
31+
if (args.indexOf('-C') >= 0) {
32+
CommandLineMigrationAdvisor._reportDeprecated(
33+
'Instead of "rush install -C", use "rush purge --unsafe".');
34+
return false;
35+
}
36+
if (args.indexOf('--clean') >= 0) {
3337
CommandLineMigrationAdvisor._reportDeprecated(
3438
'Instead of "rush install --clean", use "rush install --purge".');
3539
return false;
3640
}
41+
if (args.indexOf('-c') >= 0) {
42+
CommandLineMigrationAdvisor._reportDeprecated(
43+
'Instead of "rush install -c", use "rush install --purge".');
44+
return false;
45+
}
3746
}
3847
}
3948

@@ -42,14 +51,12 @@ export class CommandLineMigrationAdvisor {
4251
}
4352

4453
private static _reportDeprecated(message: string): void {
45-
const wrap: (textToWrap: string) => string = wordwrap.soft(Utilities.getConsoleWidth());
46-
47-
console.error(colors.red(wrap(
54+
console.error(colors.red(Utilities.wrapWords(
4855
'ERROR: You specified an outdated command-line that is no longer supported by this version of Rush:'
4956
)));
50-
console.error(colors.yellow(wrap(message)));
57+
console.error(colors.yellow(Utilities.wrapWords(message)));
5158
console.error();
52-
console.error(wrap(`For command-line help, type "rush -h". For migration instructions,`
59+
console.error(Utilities.wrapWords(`For command-line help, type "rush -h". For migration instructions,`
5360
+ ` please visit ${RushConstants.rushWebSiteUrl}`));
5461
}
5562

apps/rush-lib/src/cli/actions/CustomRushAction.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424

2525
import { RushCommandLineParser } from './RushCommandLineParser';
2626
import { BaseRushAction } from './BaseRushAction';
27+
import { SetupChecks } from '../logic/SetupChecks';
2728
import { TaskSelector } from '../logic/TaskSelector';
2829
import { Stopwatch } from '../../utilities/Stopwatch';
2930
import { AlreadyReportedError } from '../../utilities/AlreadyReportedError';
@@ -224,6 +225,8 @@ export class CustomRushAction extends BaseRushAction {
224225
return;
225226
}
226227

228+
SetupChecks.validate(this.rushConfiguration);
229+
227230
this.eventHooksManager.handle(Event.preRushBuild, this.parser.isDebug);
228231
}
229232

apps/rush-lib/src/cli/actions/RushCommandLineParser.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import * as os from 'os';
55
import * as path from 'path';
66
import * as colors from 'colors';
7-
import * as wordwrap from 'wordwrap';
87
import { CommandLineParser, CommandLineFlagParameter } from '@microsoft/ts-command-line';
98

109
import { RushConstants } from '../../RushConstants';
@@ -126,8 +125,7 @@ export class RushCommandLineParser extends CommandLineParser {
126125
private _reportErrorAndSetExitCode(error: Error): void {
127126
if (!(error instanceof AlreadyReportedError)) {
128127
const prefix: string = 'ERROR: ';
129-
const wrap: (textToWrap: string) => string = wordwrap.soft(prefix.length, Utilities.getConsoleWidth());
130-
console.error(os.EOL + colors.red(prefix + wrap(error.message).trim()));
128+
console.error(os.EOL + colors.red(prefix + Utilities.wrapWords(error.message).trim()));
131129
}
132130

133131
if (this._debugParameter.value) {

apps/rush-lib/src/cli/logic/InstallManager.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import * as path from 'path';
1111
import * as fsx from 'fs-extra';
1212
import * as semver from 'semver';
1313
import * as tar from 'tar';
14-
import * as wordwrap from 'wordwrap';
1514
import globEscape = require('glob-escape');
1615
import {
1716
JsonFile,
@@ -41,8 +40,6 @@ import { AlreadyReportedError } from '../../utilities/AlreadyReportedError';
4140

4241
const MAX_INSTALL_ATTEMPTS: number = 5;
4342

44-
const wrap: (textToWrap: string) => string = wordwrap.soft(Utilities.getConsoleWidth());
45-
4643
/**
4744
* The "noMtime" flag is new in tar@4.4.1 and not available yet for \@types/tar.
4845
* As a temporary workaround, augment the type.
@@ -367,7 +364,7 @@ export class InstallManager {
367364
// Check any preferred dependencies first
368365
allPreferredVersions.forEach((version: string, dependency: string) => {
369366
if (!shrinkwrapFile.hasCompatibleTopLevelDependency(dependency, version)) {
370-
console.log(colors.yellow(wrap(
367+
console.log(colors.yellow(Utilities.wrapWords(
371368
`${os.EOL}The NPM shrinkwrap file does not provide "${dependency}"`
372369
+ ` (${version}) required by the preferred versions from ` + RushConstants.commonVersionsFilename)));
373370
shrinkwrapIsUpToDate = false;
@@ -501,7 +498,7 @@ export class InstallManager {
501498
if (!shrinkwrapFile.tryEnsureCompatibleDependency(pair.packageName, pair.packageVersion,
502499
rushProject.tempProjectName)) {
503500
console.log(colors.yellow(
504-
wrap(`${os.EOL}The NPM shrinkwrap file is missing "${pair.packageName}"`
501+
Utilities.wrapWords(`${os.EOL}The NPM shrinkwrap file is missing "${pair.packageName}"`
505502
+ ` (${pair.packageVersion}) required by "${rushProject.packageName}".`)));
506503
shrinkwrapIsUpToDate = false;
507504
}
@@ -1000,7 +997,7 @@ export class InstallManager {
1000997
}
1001998

1002999
if (anyChanges) {
1003-
console.log(os.EOL + colors.yellow(wrap(`Applied workaround for NPM 5 bug`)) + os.EOL);
1000+
console.log(os.EOL + colors.yellow(Utilities.wrapWords(`Applied workaround for NPM 5 bug`)) + os.EOL);
10041001
}
10051002
}
10061003

@@ -1015,7 +1012,7 @@ export class InstallManager {
10151012
// We can recognize temp projects because they are under the "@rush-temp" NPM scope.
10161013
for (const tempProjectName of shrinkwrapFile.getTempProjectNames()) {
10171014
if (!this._rushConfiguration.findProjectByTempName(tempProjectName)) {
1018-
console.log(os.EOL + colors.yellow(wrap(
1015+
console.log(os.EOL + colors.yellow(Utilities.wrapWords(
10191016
`Your NPM shrinkwrap file references a project "${tempProjectName}" which no longer exists.`))
10201017
+ os.EOL);
10211018
return true; // found one
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
2+
// See LICENSE in the project root for license information.
3+
4+
import * as colors from 'colors';
5+
import * as semver from 'semver';
6+
import { RushConfiguration } from '../../data/RushConfiguration';
7+
import { AlreadyReportedError } from '../../utilities/AlreadyReportedError';
8+
import { Utilities } from '../../utilities/Utilities';
9+
10+
// Refuses to run at all if the PNPM version is older than this, because there
11+
// are known bugs or missing features in earlier releases.
12+
const MINIMUM_SUPPORTED_NPM_VERSION: string = '4.5.0';
13+
14+
// Refuses to run at all if the PNPM version is older than this, because there
15+
// are known bugs or missing features in earlier releases.
16+
const MINIMUM_SUPPORTED_PNPM_VERSION: string = '2.1.0';
17+
18+
/**
19+
* Validate that the developer's setup is good.
20+
*/
21+
export class SetupChecks {
22+
public static validate(rushConfiguration: RushConfiguration): void {
23+
// NOTE: The Node.js version is also checked in rush/src/start.ts
24+
const errorMessage: string | undefined = SetupChecks._validate(rushConfiguration);
25+
26+
if (errorMessage) {
27+
console.error(colors.red(Utilities.wrapWords(errorMessage)));
28+
throw new AlreadyReportedError();
29+
}
30+
}
31+
32+
private static _validate(rushConfiguration: RushConfiguration): string | undefined {
33+
if (rushConfiguration.packageManager === 'pnpm') {
34+
if (semver.lt(rushConfiguration.packageManagerToolVersion, MINIMUM_SUPPORTED_PNPM_VERSION)) {
35+
return `The rush.json file requests PNPM version `
36+
+ rushConfiguration.packageManagerToolVersion
37+
+ `, but PNPM ${MINIMUM_SUPPORTED_PNPM_VERSION} is the minimum supported by Rush.`;
38+
}
39+
} else if (rushConfiguration.packageManager === 'npm') {
40+
if (semver.lt(rushConfiguration.packageManagerToolVersion, MINIMUM_SUPPORTED_NPM_VERSION)) {
41+
return `The rush.json file requests NPM version `
42+
+ rushConfiguration.packageManagerToolVersion
43+
+ `, but NPM ${MINIMUM_SUPPORTED_NPM_VERSION} is the minimum supported by Rush.`;
44+
}
45+
}
46+
}
47+
}

apps/rush-lib/src/utilities/Utilities.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as os from 'os';
77
import * as rimraf from 'rimraf';
88
import * as tty from 'tty';
99
import * as path from 'path';
10+
import * as wordwrap from 'wordwrap';
1011
import { JsonFile, IPackageJson } from '@microsoft/node-core-library';
1112

1213
export interface IEnvironment {
@@ -210,6 +211,22 @@ export class Utilities {
210211
return 80;
211212
}
212213

214+
/**
215+
* Applies word wrapping. If maxLineLength is unspecified, then it defaults to the console
216+
* width.
217+
*/
218+
public static wrapWords(text: string, maxLineLength?: number, indent?: number): string {
219+
if (!indent) {
220+
indent = 0;
221+
}
222+
if (!maxLineLength) {
223+
maxLineLength = Utilities.getConsoleWidth();
224+
}
225+
226+
const wrap: (textToWrap: string) => string = wordwrap.soft(indent, maxLineLength);
227+
return wrap(text);
228+
}
229+
213230
/**
214231
* Executes the command with the specified command-line parameters, and waits for it to complete.
215232
* The current directory will be set to the specified workingDirectory.

apps/rush/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
![rush](https://github.com/Microsoft/web-build-tools/blob/master/common/wiki-images/rush-logo.png?raw=true)
55
<br />
6-
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; https://aka.ms/rush
6+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; https://rushjs.io
77

88
<!-- -------------------------------------------------------------------------- -->
99
<!-- Text below this line should stay in sync with Rush.md from the GitHub wiki -->
@@ -19,7 +19,7 @@
1919

2020
- **Subset and incremental builds:** If you only plan to work with a few projects from your repo, `rush rebuild --to <project>` does a clean build of just your upstream dependencies. After you make changes, `rush rebuild --from <project>` does a clean build of only the affected downstream projects. And if your toolchain is [package-deps-hash](https://www.npmjs.com/package/@microsoft/package-deps-hash) enabled, `rush build` delivers a powerful cross-project incremental build (that also supports subset builds).
2121

22-
- **Cyclic dependencies:** If you have hammers that build hammer-factory-factories, Rush has you covered! When a package indirectly depends on an older version of itself, projects in the cycle use the last published version, whereas other projects still get the latest bits.
22+
- **Cyclic dependencies:** If you have hammers that build hammer-factory-factories, Rush has you covered! When a package indirectly depends on an older version of itself, projects in the cycle use the last published version, whereas other projects still get the latest bits.
2323

2424
- **Bulk publishing:** When it's time to do a release, Rush can detect which packages have changes, automatically bump all the appropriate version numbers, and run `npm publish` in each folder. If you like, configure your server to automatically run `rush publish` every hour.
2525

@@ -59,4 +59,4 @@ _(If you don't have a GitHub account set up, you can use `rush install --bypass-
5959

6060
# Getting Started
6161

62-
The GitHub wiki has complete, up-to-date documentation: https://aka.ms/rush
62+
The GitHub wiki has complete, up-to-date documentation: https://rushjs.io

0 commit comments

Comments
 (0)