From cf07cc21c9adf3d80a2862c4fb12ba5ac6b3ab4a Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Mon, 27 Jul 2020 15:34:46 -0700 Subject: [PATCH 01/97] Initial commit --- apps/rush-lib/src/api/Rush.ts | 4 +- .../rush-lib/src/cli/RushCommandLineParser.ts | 4 +- .../src/cli/actions/BaseRushAction.ts | 4 +- .../src/cli/actions/TabCompleteAction.ts | 57 +++++++++++++++++++ .../CommandLineHelp.test.ts.snap | 13 +++++ apps/rush/src/MinimalRushConfiguration.ts | 2 +- 6 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 apps/rush-lib/src/cli/actions/TabCompleteAction.ts diff --git a/apps/rush-lib/src/api/Rush.ts b/apps/rush-lib/src/api/Rush.ts index fa4e8eeffdf..325411815c7 100644 --- a/apps/rush-lib/src/api/Rush.ts +++ b/apps/rush-lib/src/api/Rush.ts @@ -53,7 +53,9 @@ export class Rush { public static launch(launcherVersion: string, arg: ILaunchOptions): void { const options: ILaunchOptions = Rush._normalizeLaunchOptions(arg); - Rush._printStartupBanner(options.isManaged); + if (!(process.argv.length > 2 && process.argv[2] === 'tab-complete')) { + Rush._printStartupBanner(options.isManaged); + } if (!CommandLineMigrationAdvisor.checkArgv(process.argv)) { // The migration advisor recognized an obsolete command-line diff --git a/apps/rush-lib/src/cli/RushCommandLineParser.ts b/apps/rush-lib/src/cli/RushCommandLineParser.ts index 80b7ee0a37f..d7fe7761d7d 100644 --- a/apps/rush-lib/src/cli/RushCommandLineParser.ts +++ b/apps/rush-lib/src/cli/RushCommandLineParser.ts @@ -28,6 +28,7 @@ import { ListAction } from './actions/ListAction'; import { PublishAction } from './actions/PublishAction'; import { PurgeAction } from './actions/PurgeAction'; import { ScanAction } from './actions/ScanAction'; +import { TabCompleteAction } from './actions/TabCompleteAction'; import { UnlinkAction } from './actions/UnlinkAction'; import { UpdateAction } from './actions/UpdateAction'; import { UpdateAutoinstallerAction } from './actions/UpdateAutoinstallerAction'; @@ -76,7 +77,7 @@ export class RushCommandLineParser extends CommandLineParser { try { const rushJsonFilename: string | undefined = RushConfiguration.tryFindRushJsonLocation({ startingFolder: this._rushOptions.cwd, - showVerbose: true + showVerbose: process.argv.length > 2 && process.argv[2] !== 'tab-complete' }); if (rushJsonFilename) { this.rushConfiguration = RushConfiguration.loadFromConfigurationFile(rushJsonFilename); @@ -174,6 +175,7 @@ export class RushCommandLineParser extends CommandLineParser { this.addAction(new PurgeAction(this)); this.addAction(new ScanAction(this)); this.addAction(new UnlinkAction(this)); + this.addAction(new TabCompleteAction(this)); this.addAction(new UpdateAction(this)); this.addAction(new UpdateAutoinstallerAction(this)); this.addAction(new VersionAction(this)); diff --git a/apps/rush-lib/src/cli/actions/BaseRushAction.ts b/apps/rush-lib/src/cli/actions/BaseRushAction.ts index b9c8749bb0f..70adca54c00 100644 --- a/apps/rush-lib/src/cli/actions/BaseRushAction.ts +++ b/apps/rush-lib/src/cli/actions/BaseRushAction.ts @@ -75,7 +75,9 @@ export abstract class BaseConfiglessRushAction extends CommandLineAction { } } - console.log(`Starting "rush ${this.actionName}"${os.EOL}`); + if (!(process.argv.length > 2 && process.argv[2] === 'tab-complete')) { + console.log(`Starting "rush ${this.actionName}"${os.EOL}`); + } return this.run(); } diff --git a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts new file mode 100644 index 00000000000..89bae3489fc --- /dev/null +++ b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts @@ -0,0 +1,57 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. +// See LICENSE in the project root for license information. + +import { BaseRushAction } from './BaseRushAction'; +import { RushCommandLineParser } from '../RushCommandLineParser'; +import { CommandLineStringParameter, CommandLineIntegerParameter } from '@rushstack/ts-command-line'; + +export class TabCompleteAction extends BaseRushAction { + private _wordToCompleteParameter: CommandLineStringParameter; + private _positionParameter: CommandLineIntegerParameter; + + public constructor(parser: RushCommandLineParser) { + super({ + actionName: 'tab-complete', + summary: 'Provides tab completion.', + documentation: 'Provides tab completion', + parser + }); + } + + protected async run(): Promise { + this.parser.actions.forEach((element) => { + console.log(element.actionName); + element.parameters.forEach((elem) => { + console.log(elem.longName); + if (elem.shortName) { + console.log(elem.shortName); + } + }); + }); + + // console.log(this.parameters.join()); + // console.log(this.parser.actions.join()); + + if (!this._wordToCompleteParameter.value) { + return; + } + + if (!this._positionParameter.value) { + return; + } + } + + protected onDefineParameters(): void { + this._wordToCompleteParameter = this.defineStringParameter({ + parameterLongName: '--word', + argumentName: 'WORD', + description: `The word to complete.` + }); + + this._positionParameter = this.defineIntegerParameter({ + parameterLongName: '--position', + argumentName: 'INDEX', + description: `The position in the word to be completed.` + }); + } +} diff --git a/apps/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap b/apps/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap index 9f914ab4e7c..cda613a5457 100644 --- a/apps/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap +++ b/apps/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap @@ -42,6 +42,7 @@ Positional arguments: of imported packages. unlink Delete node_modules symlinks for all projects in the repo + tab-complete Provides tab completion. update Install package dependencies for all projects in the repo, and create or update the shrinkwrap file as needed @@ -657,6 +658,18 @@ Optional arguments: " `; +exports[`CommandLineHelp prints the help for each action: tab-complete 1`] = ` +"usage: rush tab-complete [-h] [--word WORD] [--position INDEX] + +Provides tab completion + +Optional arguments: + -h, --help Show this help message and exit. + --word WORD The word to complete. + --position INDEX The position in the word to be completed. +" +`; + exports[`CommandLineHelp prints the help for each action: unlink 1`] = ` "usage: rush unlink [-h] diff --git a/apps/rush/src/MinimalRushConfiguration.ts b/apps/rush/src/MinimalRushConfiguration.ts index ea8b66f9212..2b27b673a0a 100644 --- a/apps/rush/src/MinimalRushConfiguration.ts +++ b/apps/rush/src/MinimalRushConfiguration.ts @@ -33,7 +33,7 @@ export class MinimalRushConfiguration { public static loadFromDefaultLocation(): MinimalRushConfiguration | undefined { const rushJsonLocation: string | undefined = RushConfiguration.tryFindRushJsonLocation({ - showVerbose: true + showVerbose: process.argv.length > 2 && process.argv[2] !== 'tab-complete' }); if (rushJsonLocation) { return MinimalRushConfiguration._loadFromConfigurationFile(rushJsonLocation); From 68a18cbb93fb78edc96e89e76ef450874a012077 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Mon, 27 Jul 2020 17:03:11 -0700 Subject: [PATCH 02/97] WIP --- .../src/cli/actions/TabCompleteAction.ts | 26 +++++++++---------- apps/rush-lib/src/start.ts | 4 +++ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts index 89bae3489fc..a0943fc4eb2 100644 --- a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts +++ b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts @@ -14,30 +14,30 @@ export class TabCompleteAction extends BaseRushAction { actionName: 'tab-complete', summary: 'Provides tab completion.', documentation: 'Provides tab completion', - parser + parser, + safeForSimultaneousRushProcesses: true }); } protected async run(): Promise { this.parser.actions.forEach((element) => { console.log(element.actionName); - element.parameters.forEach((elem) => { - console.log(elem.longName); - if (elem.shortName) { - console.log(elem.shortName); - } - }); + // element.parameters.forEach((elem) => { + // console.log(elem.longName); + // if (elem.shortName) { + // console.log(elem.shortName); + // } + // }); }); - // console.log(this.parameters.join()); - // console.log(this.parser.actions.join()); + console.log(); - if (!this._wordToCompleteParameter.value) { - return; + if (this._wordToCompleteParameter.value) { + console.log(this._wordToCompleteParameter.value); } - if (!this._positionParameter.value) { - return; + if (this._positionParameter.value) { + console.log(this._positionParameter.value); } } diff --git a/apps/rush-lib/src/start.ts b/apps/rush-lib/src/start.ts index b4da75c1edc..044b4a6b59f 100644 --- a/apps/rush-lib/src/start.ts +++ b/apps/rush-lib/src/start.ts @@ -3,4 +3,8 @@ import { Rush } from './api/Rush'; +console.log('1'); + Rush.launch(Rush.version, { isManaged: false }); + +console.log('100'); From adb2a59eef6730ad90b77043453449d2e7c1471a Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Tue, 28 Jul 2020 12:48:12 -0700 Subject: [PATCH 03/97] WIP --- .../src/cli/actions/TabCompleteAction.ts | 36 +++++++++++++------ apps/rush-lib/src/start.ts | 4 --- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts index a0943fc4eb2..485e68d318e 100644 --- a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts +++ b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts @@ -9,6 +9,8 @@ export class TabCompleteAction extends BaseRushAction { private _wordToCompleteParameter: CommandLineStringParameter; private _positionParameter: CommandLineIntegerParameter; + private static _actions: string[] = []; + public constructor(parser: RushCommandLineParser) { super({ actionName: 'tab-complete', @@ -17,20 +19,34 @@ export class TabCompleteAction extends BaseRushAction { parser, safeForSimultaneousRushProcesses: true }); - } - protected async run(): Promise { this.parser.actions.forEach((element) => { - console.log(element.actionName); - // element.parameters.forEach((elem) => { - // console.log(elem.longName); - // if (elem.shortName) { - // console.log(elem.shortName); - // } - // }); + TabCompleteAction._actions.push(element.actionName); }); + TabCompleteAction._actions.push('-d'); + TabCompleteAction._actions.push('-debug'); + TabCompleteAction._actions.push('-h'); + TabCompleteAction._actions.push('-help'); + } - console.log(); + protected async run(): Promise { + console.log('arg count: ' + process.argv.length); + + for (let i: number = 0; i < process.argv.length; i++) { + console.log(i + ': ' + process.argv[i]); + } + + if (process.argv.length < 4) { + TabCompleteAction._actions.forEach((element) => { + console.log(element); + }); + } else { + for (let i: number = 0; i < TabCompleteAction._actions.length; i++) { + if (TabCompleteAction._actions[i].indexOf(process.argv[4]) === 0) { + console.log(TabCompleteAction._actions[i]); + } + } + } if (this._wordToCompleteParameter.value) { console.log(this._wordToCompleteParameter.value); diff --git a/apps/rush-lib/src/start.ts b/apps/rush-lib/src/start.ts index 044b4a6b59f..b4da75c1edc 100644 --- a/apps/rush-lib/src/start.ts +++ b/apps/rush-lib/src/start.ts @@ -3,8 +3,4 @@ import { Rush } from './api/Rush'; -console.log('1'); - Rush.launch(Rush.version, { isManaged: false }); - -console.log('100'); From 64df804873c205807e99305b14ff9e339ff756a6 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Tue, 28 Jul 2020 14:05:37 -0700 Subject: [PATCH 04/97] WIP --- .../src/cli/actions/TabCompleteAction.ts | 45 ++++++++++++++----- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts index 485e68d318e..c80ba35aa75 100644 --- a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts +++ b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts @@ -30,33 +30,56 @@ export class TabCompleteAction extends BaseRushAction { } protected async run(): Promise { - console.log('arg count: ' + process.argv.length); + // console.log('arg count: ' + process.argv.length); - for (let i: number = 0; i < process.argv.length; i++) { - console.log(i + ': ' + process.argv[i]); + // for (let i: number = 0; i < process.argv.length; i++) { + // console.log(i + ': ' + process.argv[i] + ' [' + process.argv[i].length + ']'); + // } + + if (!this._wordToCompleteParameter.value || !this._positionParameter.value) { + this._printAllActions(); + return; } - if (process.argv.length < 4) { - TabCompleteAction._actions.forEach((element) => { - console.log(element); - }); - } else { + const commandLine: string = this._wordToCompleteParameter.value; + const caretPosition: number = this._positionParameter.value; + const commands: string[] = commandLine.split(' '); + + if (commands.length < 2) { + this._printAllActions(); + return; + } + + // console.log('commands.length: ' + commands.length); + // console.log('caretPosition: ' + caretPosition); + // console.log('commandLine.length: ' + commandLine.length); + + if (commands.length === 2 && caretPosition === commandLine.length) { for (let i: number = 0; i < TabCompleteAction._actions.length; i++) { - if (TabCompleteAction._actions[i].indexOf(process.argv[4]) === 0) { + // console.log('TabCompleteAction._actions[' + i + ']: ' + TabCompleteAction._actions[i] + ', commands[1]: ' + commands[1]); + if (TabCompleteAction._actions[i].indexOf(commands[1]) === 0) { console.log(TabCompleteAction._actions[i]); } } + + return; } if (this._wordToCompleteParameter.value) { - console.log(this._wordToCompleteParameter.value); + console.log('wordToComplete: ' + this._wordToCompleteParameter.value); } if (this._positionParameter.value) { - console.log(this._positionParameter.value); + console.log('position: ' + this._positionParameter.value); } } + private _printAllActions(): void { + TabCompleteAction._actions.forEach((element) => { + console.log(element); + }); + } + protected onDefineParameters(): void { this._wordToCompleteParameter = this.defineStringParameter({ parameterLongName: '--word', From 59c60b50ba00a9541ec48ee10df2c3c3dadd8715 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Tue, 28 Jul 2020 15:47:06 -0700 Subject: [PATCH 05/97] WIP --- .../src/cli/actions/TabCompleteAction.ts | 91 ++++++++++++------- 1 file changed, 60 insertions(+), 31 deletions(-) diff --git a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts index c80ba35aa75..4a37e9e0112 100644 --- a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts +++ b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts @@ -9,7 +9,7 @@ export class TabCompleteAction extends BaseRushAction { private _wordToCompleteParameter: CommandLineStringParameter; private _positionParameter: CommandLineIntegerParameter; - private static _actions: string[] = []; + private static _actions: { [actionName: string]: string[] } = {}; public constructor(parser: RushCommandLineParser) { super({ @@ -21,12 +21,20 @@ export class TabCompleteAction extends BaseRushAction { }); this.parser.actions.forEach((element) => { - TabCompleteAction._actions.push(element.actionName); + const actionParameters: string[] = []; + element.parameters.forEach((elem) => { + actionParameters.push(elem.longName); + if (elem.shortName) { + actionParameters.push(elem.shortName); + } + }); + TabCompleteAction._actions[element.actionName] = actionParameters; }); - TabCompleteAction._actions.push('-d'); - TabCompleteAction._actions.push('-debug'); - TabCompleteAction._actions.push('-h'); - TabCompleteAction._actions.push('-help'); + + TabCompleteAction._actions['-d'] = []; + TabCompleteAction._actions['-debug'] = []; + TabCompleteAction._actions['-h'] = []; + TabCompleteAction._actions['-help'] = []; } protected async run(): Promise { @@ -45,39 +53,60 @@ export class TabCompleteAction extends BaseRushAction { const caretPosition: number = this._positionParameter.value; const commands: string[] = commandLine.split(' '); + console.log('commandLine: ' + commandLine); + console.log('commandLine.length: ' + commandLine.length); + console.log('caretPosition: ' + caretPosition); + console.log('commands.length: ' + commands.length); + if (commands.length < 2) { this._printAllActions(); - return; - } - - // console.log('commands.length: ' + commands.length); - // console.log('caretPosition: ' + caretPosition); - // console.log('commandLine.length: ' + commandLine.length); - - if (commands.length === 2 && caretPosition === commandLine.length) { - for (let i: number = 0; i < TabCompleteAction._actions.length; i++) { - // console.log('TabCompleteAction._actions[' + i + ']: ' + TabCompleteAction._actions[i] + ', commands[1]: ' + commands[1]); - if (TabCompleteAction._actions[i].indexOf(commands[1]) === 0) { - console.log(TabCompleteAction._actions[i]); + } else { + if (commands.length === 2) { + if (caretPosition === commandLine.length) { + for (const actionName of Object.keys(TabCompleteAction._actions)) { + // console.log('TabCompleteAction._actions[' + i + ']: ' + TabCompleteAction._actions[i] + ', commands[1]: ' + commands[1]); + if (actionName.indexOf(commands[1]) === 0) { + console.log(actionName); + } + } + } else { + for (const actionName of Object.keys(TabCompleteAction._actions)) { + // console.log('TabCompleteAction._actions[' + i + ']: ' + TabCompleteAction._actions[i] + ', commands[1]: ' + commands[1]); + if (actionName === commands[1]) { + for (let i: number = 0; i < TabCompleteAction._actions[actionName].length; i++) { + console.log(TabCompleteAction._actions[actionName][i]); + } + } + } + } + } else if (caretPosition === commandLine.length + 1) { + for (const actionName of Object.keys(TabCompleteAction._actions)) { + // console.log('TabCompleteAction._actions[' + i + ']: ' + TabCompleteAction._actions[i] + ', commands[1]: ' + commands[1]); + if (actionName === commands[1]) { + for (let i: number = 0; i < TabCompleteAction._actions[actionName].length; i++) { + console.log(TabCompleteAction._actions[actionName][i]); + } + } + } + } else { + for (const actionName of Object.keys(TabCompleteAction._actions)) { + // console.log('TabCompleteAction._actions[' + i + ']: ' + TabCompleteAction._actions[i] + ', commands[1]: ' + commands[1]); + if (actionName === commands[1]) { + for (let i: number = 0; i < TabCompleteAction._actions[actionName].length; i++) { + if (TabCompleteAction._actions[actionName][i].indexOf(commands[commands.length - 1]) === 0) { + console.log(TabCompleteAction._actions[actionName][i]); + } + } + } } } - - return; - } - - if (this._wordToCompleteParameter.value) { - console.log('wordToComplete: ' + this._wordToCompleteParameter.value); - } - - if (this._positionParameter.value) { - console.log('position: ' + this._positionParameter.value); } } private _printAllActions(): void { - TabCompleteAction._actions.forEach((element) => { - console.log(element); - }); + for (const actionName of Object.keys(TabCompleteAction._actions)) { + console.log(actionName); + } } protected onDefineParameters(): void { From d45da592836d698c50ef6e2a503340a0b3b9878b Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Tue, 28 Jul 2020 15:59:58 -0700 Subject: [PATCH 06/97] WIP --- .../src/cli/actions/TabCompleteAction.ts | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts index 4a37e9e0112..cf7d910d081 100644 --- a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts +++ b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts @@ -61,8 +61,8 @@ export class TabCompleteAction extends BaseRushAction { if (commands.length < 2) { this._printAllActions(); } else { - if (commands.length === 2) { - if (caretPosition === commandLine.length) { + if (caretPosition === commandLine.length) { + if (commands.length === 2) { for (const actionName of Object.keys(TabCompleteAction._actions)) { // console.log('TabCompleteAction._actions[' + i + ']: ' + TabCompleteAction._actions[i] + ', commands[1]: ' + commands[1]); if (actionName.indexOf(commands[1]) === 0) { @@ -74,28 +74,19 @@ export class TabCompleteAction extends BaseRushAction { // console.log('TabCompleteAction._actions[' + i + ']: ' + TabCompleteAction._actions[i] + ', commands[1]: ' + commands[1]); if (actionName === commands[1]) { for (let i: number = 0; i < TabCompleteAction._actions[actionName].length; i++) { - console.log(TabCompleteAction._actions[actionName][i]); + if (TabCompleteAction._actions[actionName][i].indexOf(commands[commands.length - 1]) === 0) { + console.log(TabCompleteAction._actions[actionName][i]); + } } } } } - } else if (caretPosition === commandLine.length + 1) { - for (const actionName of Object.keys(TabCompleteAction._actions)) { - // console.log('TabCompleteAction._actions[' + i + ']: ' + TabCompleteAction._actions[i] + ', commands[1]: ' + commands[1]); - if (actionName === commands[1]) { - for (let i: number = 0; i < TabCompleteAction._actions[actionName].length; i++) { - console.log(TabCompleteAction._actions[actionName][i]); - } - } - } } else { for (const actionName of Object.keys(TabCompleteAction._actions)) { // console.log('TabCompleteAction._actions[' + i + ']: ' + TabCompleteAction._actions[i] + ', commands[1]: ' + commands[1]); if (actionName === commands[1]) { for (let i: number = 0; i < TabCompleteAction._actions[actionName].length; i++) { - if (TabCompleteAction._actions[actionName][i].indexOf(commands[commands.length - 1]) === 0) { - console.log(TabCompleteAction._actions[actionName][i]); - } + console.log(TabCompleteAction._actions[actionName][i]); } } } From 5e8d0f2230bd43ee7336f6bb0d9fd04a86b77774 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Tue, 28 Jul 2020 16:26:27 -0700 Subject: [PATCH 07/97] WIP --- .../src/cli/actions/TabCompleteAction.ts | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts index cf7d910d081..3818a042704 100644 --- a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts +++ b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts @@ -3,13 +3,22 @@ import { BaseRushAction } from './BaseRushAction'; import { RushCommandLineParser } from '../RushCommandLineParser'; -import { CommandLineStringParameter, CommandLineIntegerParameter } from '@rushstack/ts-command-line'; +import { + CommandLineStringParameter, + CommandLineIntegerParameter, + CommandLineParameterKind +} from '@rushstack/ts-command-line'; + +interface IParameter { + name: string; + kind: CommandLineParameterKind; +} export class TabCompleteAction extends BaseRushAction { private _wordToCompleteParameter: CommandLineStringParameter; private _positionParameter: CommandLineIntegerParameter; - private static _actions: { [actionName: string]: string[] } = {}; + private static _actions: { [actionName: string]: IParameter[] } = {}; public constructor(parser: RushCommandLineParser) { super({ @@ -21,11 +30,11 @@ export class TabCompleteAction extends BaseRushAction { }); this.parser.actions.forEach((element) => { - const actionParameters: string[] = []; + const actionParameters: IParameter[] = []; element.parameters.forEach((elem) => { - actionParameters.push(elem.longName); + actionParameters.push({ name: elem.longName, kind: elem.kind }); if (elem.shortName) { - actionParameters.push(elem.shortName); + actionParameters.push({ name: elem.shortName, kind: elem.kind }); } }); TabCompleteAction._actions[element.actionName] = actionParameters; @@ -74,7 +83,9 @@ export class TabCompleteAction extends BaseRushAction { // console.log('TabCompleteAction._actions[' + i + ']: ' + TabCompleteAction._actions[i] + ', commands[1]: ' + commands[1]); if (actionName === commands[1]) { for (let i: number = 0; i < TabCompleteAction._actions[actionName].length; i++) { - if (TabCompleteAction._actions[actionName][i].indexOf(commands[commands.length - 1]) === 0) { + if ( + TabCompleteAction._actions[actionName][i].name.indexOf(commands[commands.length - 1]) === 0 + ) { console.log(TabCompleteAction._actions[actionName][i]); } } @@ -86,7 +97,16 @@ export class TabCompleteAction extends BaseRushAction { // console.log('TabCompleteAction._actions[' + i + ']: ' + TabCompleteAction._actions[i] + ', commands[1]: ' + commands[1]); if (actionName === commands[1]) { for (let i: number = 0; i < TabCompleteAction._actions[actionName].length; i++) { - console.log(TabCompleteAction._actions[actionName][i]); + if ( + commands[commands.length - 1] === TabCompleteAction._actions[actionName][i].name && + TabCompleteAction._actions[actionName][i].kind !== CommandLineParameterKind.Flag + ) { + return; + } + } + + for (let i: number = 0; i < TabCompleteAction._actions[actionName].length; i++) { + console.log(TabCompleteAction._actions[actionName][i].name); } } } From d6ad7cb1b67981080115b4a4e3156e1fa0e46274 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Tue, 28 Jul 2020 17:15:26 -0700 Subject: [PATCH 08/97] Add autocomplete for common parameter values --- .../src/cli/actions/TabCompleteAction.ts | 40 +++++++++++++++++-- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts index 3818a042704..b3366f89020 100644 --- a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts +++ b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts @@ -70,6 +70,8 @@ export class TabCompleteAction extends BaseRushAction { if (commands.length < 2) { this._printAllActions(); } else { + const lastCommand: string = commands[commands.length - 1]; + // const secondLastCommand: string = commands[commands.length - 2]; if (caretPosition === commandLine.length) { if (commands.length === 2) { for (const actionName of Object.keys(TabCompleteAction._actions)) { @@ -83,9 +85,7 @@ export class TabCompleteAction extends BaseRushAction { // console.log('TabCompleteAction._actions[' + i + ']: ' + TabCompleteAction._actions[i] + ', commands[1]: ' + commands[1]); if (actionName === commands[1]) { for (let i: number = 0; i < TabCompleteAction._actions[actionName].length; i++) { - if ( - TabCompleteAction._actions[actionName][i].name.indexOf(commands[commands.length - 1]) === 0 - ) { + if (TabCompleteAction._actions[actionName][i].name.indexOf(lastCommand) === 0) { console.log(TabCompleteAction._actions[actionName][i]); } } @@ -96,9 +96,41 @@ export class TabCompleteAction extends BaseRushAction { for (const actionName of Object.keys(TabCompleteAction._actions)) { // console.log('TabCompleteAction._actions[' + i + ']: ' + TabCompleteAction._actions[i] + ', commands[1]: ' + commands[1]); if (actionName === commands[1]) { + // TODO: Add support for -d/--debug switches + if (actionName === 'build' || actionName === 'rebuild') { + const projectCommands: string[] = ['-f', '--from', '-t', '--to']; + if (projectCommands.indexOf(lastCommand) !== -1) { + for (let i: number = 0; i < this.rushConfiguration.projects.length; i++) { + console.log(this.rushConfiguration.projects[i].packageName); + } + + return; + } + + // TODO: Add support for version policy, variant + } else if (actionName === 'change') { + if (lastCommand === '--bump-type') { + const bumpTypes: string[] = ['major', 'minor', 'patch', 'none']; + for (let i: number = 0; i < bumpTypes.length; i++) { + console.log(bumpTypes[i]); + } + + return; + } + } else if (actionName === 'publish') { + if (lastCommand === '--set-access-level') { + const accessLevels: string[] = ['public', 'restricted']; + for (let i: number = 0; i < accessLevels.length; i++) { + console.log(accessLevels[i]); + } + + return; + } + } + for (let i: number = 0; i < TabCompleteAction._actions[actionName].length; i++) { if ( - commands[commands.length - 1] === TabCompleteAction._actions[actionName][i].name && + lastCommand === TabCompleteAction._actions[actionName][i].name && TabCompleteAction._actions[actionName][i].kind !== CommandLineParameterKind.Flag ) { return; From 1d0fe7d494d4abb7e3db80e0702877aef5e66a79 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Tue, 28 Jul 2020 18:13:30 -0700 Subject: [PATCH 09/97] Move action table population to run() method so that custom commands and parameters can also be populated. --- apps/rush-lib/src/cli/actions/TabCompleteAction.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts index b3366f89020..075188f7f17 100644 --- a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts +++ b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts @@ -3,6 +3,8 @@ import { BaseRushAction } from './BaseRushAction'; import { RushCommandLineParser } from '../RushCommandLineParser'; +import { FileSystem } from '@rushstack/node-core-library'; + import { CommandLineStringParameter, CommandLineIntegerParameter, @@ -28,7 +30,9 @@ export class TabCompleteAction extends BaseRushAction { parser, safeForSimultaneousRushProcesses: true }); + } + protected async run(): Promise { this.parser.actions.forEach((element) => { const actionParameters: IParameter[] = []; element.parameters.forEach((elem) => { @@ -44,9 +48,9 @@ export class TabCompleteAction extends BaseRushAction { TabCompleteAction._actions['-debug'] = []; TabCompleteAction._actions['-h'] = []; TabCompleteAction._actions['-help'] = []; - } - protected async run(): Promise { + // FileSystem.writeFile('D:/a.txt', JSON.stringify(TabCompleteAction._actions)); + // console.log('arg count: ' + process.argv.length); // for (let i: number = 0; i < process.argv.length; i++) { @@ -99,6 +103,7 @@ export class TabCompleteAction extends BaseRushAction { // TODO: Add support for -d/--debug switches if (actionName === 'build' || actionName === 'rebuild') { const projectCommands: string[] = ['-f', '--from', '-t', '--to']; + console.log('lastCommandIndex: ' + projectCommands.indexOf(lastCommand)); if (projectCommands.indexOf(lastCommand) !== -1) { for (let i: number = 0; i < this.rushConfiguration.projects.length; i++) { console.log(this.rushConfiguration.projects[i].packageName); From 97d73036bd0e2f32f270ebbc34303958bb7a76e1 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Tue, 28 Jul 2020 18:30:42 -0700 Subject: [PATCH 10/97] Add support for -d/--debug switch --- .../src/cli/actions/TabCompleteAction.ts | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts index 075188f7f17..4deb225d430 100644 --- a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts +++ b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts @@ -3,7 +3,6 @@ import { BaseRushAction } from './BaseRushAction'; import { RushCommandLineParser } from '../RushCommandLineParser'; -import { FileSystem } from '@rushstack/node-core-library'; import { CommandLineStringParameter, @@ -49,8 +48,6 @@ export class TabCompleteAction extends BaseRushAction { TabCompleteAction._actions['-h'] = []; TabCompleteAction._actions['-help'] = []; - // FileSystem.writeFile('D:/a.txt', JSON.stringify(TabCompleteAction._actions)); - // console.log('arg count: ' + process.argv.length); // for (let i: number = 0; i < process.argv.length; i++) { @@ -71,23 +68,24 @@ export class TabCompleteAction extends BaseRushAction { console.log('caretPosition: ' + caretPosition); console.log('commands.length: ' + commands.length); - if (commands.length < 2) { + const debugParameterUsed: boolean = + commands.length > 1 && (commands[1] === '-d' || commands[1] === '--debug'); + const debugParameterOffset: number = debugParameterUsed ? 1 : 0; // if debug switch is used, then offset everything by 1. + + if (commands.length < 2 + debugParameterOffset) { this._printAllActions(); } else { const lastCommand: string = commands[commands.length - 1]; - // const secondLastCommand: string = commands[commands.length - 2]; if (caretPosition === commandLine.length) { - if (commands.length === 2) { + if (commands.length === 2 + debugParameterOffset) { for (const actionName of Object.keys(TabCompleteAction._actions)) { - // console.log('TabCompleteAction._actions[' + i + ']: ' + TabCompleteAction._actions[i] + ', commands[1]: ' + commands[1]); - if (actionName.indexOf(commands[1]) === 0) { + if (actionName.indexOf(commands[1 + debugParameterOffset]) === 0) { console.log(actionName); } } } else { for (const actionName of Object.keys(TabCompleteAction._actions)) { - // console.log('TabCompleteAction._actions[' + i + ']: ' + TabCompleteAction._actions[i] + ', commands[1]: ' + commands[1]); - if (actionName === commands[1]) { + if (actionName === commands[1 + debugParameterOffset]) { for (let i: number = 0; i < TabCompleteAction._actions[actionName].length; i++) { if (TabCompleteAction._actions[actionName][i].name.indexOf(lastCommand) === 0) { console.log(TabCompleteAction._actions[actionName][i]); @@ -98,8 +96,7 @@ export class TabCompleteAction extends BaseRushAction { } } else { for (const actionName of Object.keys(TabCompleteAction._actions)) { - // console.log('TabCompleteAction._actions[' + i + ']: ' + TabCompleteAction._actions[i] + ', commands[1]: ' + commands[1]); - if (actionName === commands[1]) { + if (actionName === commands[1 + debugParameterOffset]) { // TODO: Add support for -d/--debug switches if (actionName === 'build' || actionName === 'rebuild') { const projectCommands: string[] = ['-f', '--from', '-t', '--to']; From 35115e57ff2435353905e6ff8bf2ad0399e1406b Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Wed, 29 Jul 2020 00:10:21 -0700 Subject: [PATCH 11/97] Refactor --- apps/rush-lib/src/cli/actions/TabCompleteAction.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts index 4deb225d430..e05aa1efddb 100644 --- a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts +++ b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts @@ -97,7 +97,6 @@ export class TabCompleteAction extends BaseRushAction { } else { for (const actionName of Object.keys(TabCompleteAction._actions)) { if (actionName === commands[1 + debugParameterOffset]) { - // TODO: Add support for -d/--debug switches if (actionName === 'build' || actionName === 'rebuild') { const projectCommands: string[] = ['-f', '--from', '-t', '--to']; console.log('lastCommandIndex: ' + projectCommands.indexOf(lastCommand)); From 7fdce2fa7c1d185b420aa5ad459e4b97e7bb08c8 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Wed, 29 Jul 2020 01:05:59 -0700 Subject: [PATCH 12/97] Autocomplete for partially completed package names --- .../src/cli/actions/TabCompleteAction.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts index e05aa1efddb..fc7d40efe9f 100644 --- a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts +++ b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts @@ -76,6 +76,9 @@ export class TabCompleteAction extends BaseRushAction { this._printAllActions(); } else { const lastCommand: string = commands[commands.length - 1]; + const secondLastCommand: string = commands[commands.length - 2]; + console.log('lastCommand: ' + lastCommand); + console.log('secondLastCommand: ' + secondLastCommand); if (caretPosition === commandLine.length) { if (commands.length === 2 + debugParameterOffset) { for (const actionName of Object.keys(TabCompleteAction._actions)) { @@ -86,6 +89,18 @@ export class TabCompleteAction extends BaseRushAction { } else { for (const actionName of Object.keys(TabCompleteAction._actions)) { if (actionName === commands[1 + debugParameterOffset]) { + if (actionName === 'build' || actionName === 'rebuild') { + const projectCommands: string[] = ['-f', '--from', '-t', '--to']; + if (projectCommands.indexOf(secondLastCommand) !== -1) { + for (let i: number = 0; i < this.rushConfiguration.projects.length; i++) { + if (this.rushConfiguration.projects[i].packageName.indexOf(lastCommand) === 0) { + console.log(this.rushConfiguration.projects[i].packageName); + } + } + + return; + } + } for (let i: number = 0; i < TabCompleteAction._actions[actionName].length; i++) { if (TabCompleteAction._actions[actionName][i].name.indexOf(lastCommand) === 0) { console.log(TabCompleteAction._actions[actionName][i]); @@ -99,7 +114,6 @@ export class TabCompleteAction extends BaseRushAction { if (actionName === commands[1 + debugParameterOffset]) { if (actionName === 'build' || actionName === 'rebuild') { const projectCommands: string[] = ['-f', '--from', '-t', '--to']; - console.log('lastCommandIndex: ' + projectCommands.indexOf(lastCommand)); if (projectCommands.indexOf(lastCommand) !== -1) { for (let i: number = 0; i < this.rushConfiguration.projects.length; i++) { console.log(this.rushConfiguration.projects[i].packageName); From abb42e5722d27310d111452b2c7c7a73c51be9c5 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Wed, 29 Jul 2020 02:30:49 -0700 Subject: [PATCH 13/97] Refactor to remove some duplicate code --- .../src/cli/actions/TabCompleteAction.ts | 123 +++++++++++------- 1 file changed, 73 insertions(+), 50 deletions(-) diff --git a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts index fc7d40efe9f..d0c28a3c796 100644 --- a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts +++ b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts @@ -79,18 +79,21 @@ export class TabCompleteAction extends BaseRushAction { const secondLastCommand: string = commands[commands.length - 2]; console.log('lastCommand: ' + lastCommand); console.log('secondLastCommand: ' + secondLastCommand); - if (caretPosition === commandLine.length) { - if (commands.length === 2 + debugParameterOffset) { - for (const actionName of Object.keys(TabCompleteAction._actions)) { - if (actionName.indexOf(commands[1 + debugParameterOffset]) === 0) { - console.log(actionName); - } + + const completePartialWord: boolean = caretPosition === commandLine.length; + + if (completePartialWord && commands.length === 2 + debugParameterOffset) { + for (const actionName of Object.keys(TabCompleteAction._actions)) { + if (actionName.indexOf(commands[1 + debugParameterOffset]) === 0) { + console.log(actionName); } - } else { - for (const actionName of Object.keys(TabCompleteAction._actions)) { - if (actionName === commands[1 + debugParameterOffset]) { - if (actionName === 'build' || actionName === 'rebuild') { - const projectCommands: string[] = ['-f', '--from', '-t', '--to']; + } + } else { + for (const actionName of Object.keys(TabCompleteAction._actions)) { + if (actionName === commands[1 + debugParameterOffset]) { + if (actionName === 'build' || actionName === 'rebuild') { + const projectCommands: string[] = ['-f', '--from', '-t', '--to']; + if (completePartialWord) { if (projectCommands.indexOf(secondLastCommand) !== -1) { for (let i: number = 0; i < this.rushConfiguration.projects.length; i++) { if (this.rushConfiguration.projects[i].packageName.indexOf(lastCommand) === 0) { @@ -100,60 +103,80 @@ export class TabCompleteAction extends BaseRushAction { return; } - } - for (let i: number = 0; i < TabCompleteAction._actions[actionName].length; i++) { - if (TabCompleteAction._actions[actionName][i].name.indexOf(lastCommand) === 0) { - console.log(TabCompleteAction._actions[actionName][i]); - } - } - } - } - } - } else { - for (const actionName of Object.keys(TabCompleteAction._actions)) { - if (actionName === commands[1 + debugParameterOffset]) { - if (actionName === 'build' || actionName === 'rebuild') { - const projectCommands: string[] = ['-f', '--from', '-t', '--to']; - if (projectCommands.indexOf(lastCommand) !== -1) { - for (let i: number = 0; i < this.rushConfiguration.projects.length; i++) { - console.log(this.rushConfiguration.projects[i].packageName); - } + } else { + if (projectCommands.indexOf(lastCommand) !== -1) { + for (let i: number = 0; i < this.rushConfiguration.projects.length; i++) { + console.log(this.rushConfiguration.projects[i].packageName); + } - return; + return; + } } - // TODO: Add support for version policy, variant } else if (actionName === 'change') { - if (lastCommand === '--bump-type') { - const bumpTypes: string[] = ['major', 'minor', 'patch', 'none']; - for (let i: number = 0; i < bumpTypes.length; i++) { - console.log(bumpTypes[i]); + const bumpTypes: string[] = ['major', 'minor', 'patch', 'none']; + if (completePartialWord) { + if (secondLastCommand === '--bump-type') { + for (let i: number = 0; i < bumpTypes.length; i++) { + if (bumpTypes[i].indexOf(lastCommand) === 0) { + console.log(bumpTypes[i]); + } + } + + return; } + } else { + if (lastCommand === '--bump-type') { + for (let i: number = 0; i < bumpTypes.length; i++) { + console.log(bumpTypes[i]); + } - return; + return; + } } } else if (actionName === 'publish') { - if (lastCommand === '--set-access-level') { - const accessLevels: string[] = ['public', 'restricted']; - for (let i: number = 0; i < accessLevels.length; i++) { - console.log(accessLevels[i]); + const accessLevels: string[] = ['public', 'restricted']; + if (completePartialWord) { + if (secondLastCommand === '--set-access-level') { + for (let i: number = 0; i < accessLevels.length; i++) { + if (accessLevels[i].indexOf(lastCommand) === 0) { + console.log(accessLevels[i]); + } + } + + return; } + } else { + if (lastCommand === '--set-access-level') { + for (let i: number = 0; i < accessLevels.length; i++) { + console.log(accessLevels[i]); + } - return; + return; + } } } - for (let i: number = 0; i < TabCompleteAction._actions[actionName].length; i++) { - if ( - lastCommand === TabCompleteAction._actions[actionName][i].name && - TabCompleteAction._actions[actionName][i].kind !== CommandLineParameterKind.Flag - ) { - return; + if (completePartialWord) { + for (let i: number = 0; i < TabCompleteAction._actions[actionName].length; i++) { + if (TabCompleteAction._actions[actionName][i].name.indexOf(lastCommand) === 0) { + console.log(TabCompleteAction._actions[actionName][i]); + } + } + } else { + for (let i: number = 0; i < TabCompleteAction._actions[actionName].length; i++) { + if ( + lastCommand === TabCompleteAction._actions[actionName][i].name && + TabCompleteAction._actions[actionName][i].kind !== CommandLineParameterKind.Flag + ) { + // The parameter is expecting a value, so don't suggest parameter names again + return; + } } - } - for (let i: number = 0; i < TabCompleteAction._actions[actionName].length; i++) { - console.log(TabCompleteAction._actions[actionName][i].name); + for (let i: number = 0; i < TabCompleteAction._actions[actionName].length; i++) { + console.log(TabCompleteAction._actions[actionName][i].name); + } } } } From f885dbf4809af98f835df599cee9bfd8c964ec3f Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Wed, 29 Jul 2020 02:36:08 -0700 Subject: [PATCH 14/97] Comment out logs --- apps/rush-lib/src/cli/actions/TabCompleteAction.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts index d0c28a3c796..55f71b92fa9 100644 --- a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts +++ b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts @@ -63,10 +63,10 @@ export class TabCompleteAction extends BaseRushAction { const caretPosition: number = this._positionParameter.value; const commands: string[] = commandLine.split(' '); - console.log('commandLine: ' + commandLine); - console.log('commandLine.length: ' + commandLine.length); - console.log('caretPosition: ' + caretPosition); - console.log('commands.length: ' + commands.length); + // console.log('commandLine: ' + commandLine); + // console.log('commandLine.length: ' + commandLine.length); + // console.log('caretPosition: ' + caretPosition); + // console.log('commands.length: ' + commands.length); const debugParameterUsed: boolean = commands.length > 1 && (commands[1] === '-d' || commands[1] === '--debug'); @@ -77,8 +77,8 @@ export class TabCompleteAction extends BaseRushAction { } else { const lastCommand: string = commands[commands.length - 1]; const secondLastCommand: string = commands[commands.length - 2]; - console.log('lastCommand: ' + lastCommand); - console.log('secondLastCommand: ' + secondLastCommand); + // console.log('lastCommand: ' + lastCommand); + // console.log('secondLastCommand: ' + secondLastCommand); const completePartialWord: boolean = caretPosition === commandLine.length; From 9b7542f3bb0c0458a513d62ebde4e6bdeafdbcb7 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Wed, 29 Jul 2020 02:44:35 -0700 Subject: [PATCH 15/97] Refactor --- apps/rush-lib/src/cli/actions/TabCompleteAction.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts index 55f71b92fa9..a2aedc57178 100644 --- a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts +++ b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts @@ -32,6 +32,10 @@ export class TabCompleteAction extends BaseRushAction { } protected async run(): Promise { + this.getCompletions(); + } + + private getCompletions(): void { this.parser.actions.forEach((element) => { const actionParameters: IParameter[] = []; element.parameters.forEach((elem) => { From 86666c33da7c8ba20029edfe6402c211536d4393 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Wed, 29 Jul 2020 02:48:50 -0700 Subject: [PATCH 16/97] Fix minor bug --- apps/rush-lib/src/cli/actions/TabCompleteAction.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts index a2aedc57178..51736fba75a 100644 --- a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts +++ b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts @@ -32,10 +32,10 @@ export class TabCompleteAction extends BaseRushAction { } protected async run(): Promise { - this.getCompletions(); + this._getCompletions(); } - private getCompletions(): void { + private _getCompletions(): void { this.parser.actions.forEach((element) => { const actionParameters: IParameter[] = []; element.parameters.forEach((elem) => { @@ -164,7 +164,7 @@ export class TabCompleteAction extends BaseRushAction { if (completePartialWord) { for (let i: number = 0; i < TabCompleteAction._actions[actionName].length; i++) { if (TabCompleteAction._actions[actionName][i].name.indexOf(lastCommand) === 0) { - console.log(TabCompleteAction._actions[actionName][i]); + console.log(TabCompleteAction._actions[actionName][i].name); } } } else { From 6c7e2135ebad86e9adcaebd9e9388d270cf2da62 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Wed, 29 Jul 2020 04:28:01 -0700 Subject: [PATCH 17/97] Add tests --- .../src/cli/actions/TabCompleteAction.ts | 224 +++++++++--------- .../actions/test/TabCompleteAction.test.ts | 144 +++++++++++ .../actions/test/tabComplete/a/package.json | 5 + .../actions/test/tabComplete/b/package.json | 5 + .../cli/actions/test/tabComplete/rush.json | 17 ++ 5 files changed, 285 insertions(+), 110 deletions(-) create mode 100644 apps/rush-lib/src/cli/actions/test/TabCompleteAction.test.ts create mode 100644 apps/rush-lib/src/cli/actions/test/tabComplete/a/package.json create mode 100644 apps/rush-lib/src/cli/actions/test/tabComplete/b/package.json create mode 100644 apps/rush-lib/src/cli/actions/test/tabComplete/rush.json diff --git a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts index 51736fba75a..942f68efcd3 100644 --- a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts +++ b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts @@ -31,11 +31,30 @@ export class TabCompleteAction extends BaseRushAction { }); } + protected onDefineParameters(): void { + this._wordToCompleteParameter = this.defineStringParameter({ + parameterLongName: '--word', + argumentName: 'WORD', + description: `The word to complete.` + }); + + this._positionParameter = this.defineIntegerParameter({ + parameterLongName: '--position', + argumentName: 'INDEX', + description: `The position in the word to be completed.` + }); + } + protected async run(): Promise { - this._getCompletions(); + const commandLine: string = this._wordToCompleteParameter.value || ''; + const caretPosition: number = this._positionParameter.value || 0; + + for (const value of this._getCompletions(commandLine, caretPosition)) { + console.log(value); + } } - private _getCompletions(): void { + public *_getCompletions(commandLine: string, caretPosition: number): IterableIterator { this.parser.actions.forEach((element) => { const actionParameters: IParameter[] = []; element.parameters.forEach((elem) => { @@ -48,163 +67,148 @@ export class TabCompleteAction extends BaseRushAction { }); TabCompleteAction._actions['-d'] = []; - TabCompleteAction._actions['-debug'] = []; + TabCompleteAction._actions['--debug'] = []; TabCompleteAction._actions['-h'] = []; - TabCompleteAction._actions['-help'] = []; + TabCompleteAction._actions['--help'] = []; - // console.log('arg count: ' + process.argv.length); + // yield ('arg count: ' + process.argv.length); // for (let i: number = 0; i < process.argv.length; i++) { - // console.log(i + ': ' + process.argv[i] + ' [' + process.argv[i].length + ']'); + // yield (i + ': ' + process.argv[i] + ' [' + process.argv[i].length + ']'); // } - if (!this._wordToCompleteParameter.value || !this._positionParameter.value) { - this._printAllActions(); + if (!commandLine || !caretPosition) { + yield* this._getAllActions(); return; } - const commandLine: string = this._wordToCompleteParameter.value; - const caretPosition: number = this._positionParameter.value; const commands: string[] = commandLine.split(' '); - // console.log('commandLine: ' + commandLine); - // console.log('commandLine.length: ' + commandLine.length); - // console.log('caretPosition: ' + caretPosition); - // console.log('commands.length: ' + commands.length); + // yield ('commandLine: ' + commandLine); + // yield ('commandLine.length: ' + commandLine.length); + // yield ('caretPosition: ' + caretPosition); + // yield ('commands.length: ' + commands.length); const debugParameterUsed: boolean = commands.length > 1 && (commands[1] === '-d' || commands[1] === '--debug'); const debugParameterOffset: number = debugParameterUsed ? 1 : 0; // if debug switch is used, then offset everything by 1. if (commands.length < 2 + debugParameterOffset) { - this._printAllActions(); - } else { - const lastCommand: string = commands[commands.length - 1]; - const secondLastCommand: string = commands[commands.length - 2]; - // console.log('lastCommand: ' + lastCommand); - // console.log('secondLastCommand: ' + secondLastCommand); + yield* this._getAllActions(); + return; + } - const completePartialWord: boolean = caretPosition === commandLine.length; + const lastCommand: string = commands[commands.length - 1]; + const secondLastCommand: string = commands[commands.length - 2]; + // yield ('lastCommand: ' + lastCommand); + // yield ('secondLastCommand: ' + secondLastCommand); - if (completePartialWord && commands.length === 2 + debugParameterOffset) { - for (const actionName of Object.keys(TabCompleteAction._actions)) { - if (actionName.indexOf(commands[1 + debugParameterOffset]) === 0) { - console.log(actionName); - } + const completePartialWord: boolean = caretPosition === commandLine.length; + + if (completePartialWord && commands.length === 2 + debugParameterOffset) { + for (const actionName of Object.keys(TabCompleteAction._actions)) { + if (actionName.indexOf(commands[1 + debugParameterOffset]) === 0) { + yield actionName; } - } else { - for (const actionName of Object.keys(TabCompleteAction._actions)) { - if (actionName === commands[1 + debugParameterOffset]) { - if (actionName === 'build' || actionName === 'rebuild') { - const projectCommands: string[] = ['-f', '--from', '-t', '--to']; - if (completePartialWord) { - if (projectCommands.indexOf(secondLastCommand) !== -1) { - for (let i: number = 0; i < this.rushConfiguration.projects.length; i++) { - if (this.rushConfiguration.projects[i].packageName.indexOf(lastCommand) === 0) { - console.log(this.rushConfiguration.projects[i].packageName); - } + } + } else { + for (const actionName of Object.keys(TabCompleteAction._actions)) { + if (actionName === commands[1 + debugParameterOffset]) { + if (actionName === 'build' || actionName === 'rebuild') { + const projectCommands: string[] = ['-f', '--from', '-t', '--to']; + if (completePartialWord) { + if (projectCommands.indexOf(secondLastCommand) !== -1) { + for (let i: number = 0; i < this.rushConfiguration.projects.length; i++) { + if (this.rushConfiguration.projects[i].packageName.indexOf(lastCommand) === 0) { + yield this.rushConfiguration.projects[i].packageName; } - - return; } - } else { - if (projectCommands.indexOf(lastCommand) !== -1) { - for (let i: number = 0; i < this.rushConfiguration.projects.length; i++) { - console.log(this.rushConfiguration.projects[i].packageName); - } - return; - } + return; } - // TODO: Add support for version policy, variant - } else if (actionName === 'change') { - const bumpTypes: string[] = ['major', 'minor', 'patch', 'none']; - if (completePartialWord) { - if (secondLastCommand === '--bump-type') { - for (let i: number = 0; i < bumpTypes.length; i++) { - if (bumpTypes[i].indexOf(lastCommand) === 0) { - console.log(bumpTypes[i]); - } - } - - return; + } else { + if (projectCommands.indexOf(lastCommand) !== -1) { + for (let i: number = 0; i < this.rushConfiguration.projects.length; i++) { + yield this.rushConfiguration.projects[i].packageName; } - } else { - if (lastCommand === '--bump-type') { - for (let i: number = 0; i < bumpTypes.length; i++) { - console.log(bumpTypes[i]); - } - return; - } + return; } - } else if (actionName === 'publish') { - const accessLevels: string[] = ['public', 'restricted']; - if (completePartialWord) { - if (secondLastCommand === '--set-access-level') { - for (let i: number = 0; i < accessLevels.length; i++) { - if (accessLevels[i].indexOf(lastCommand) === 0) { - console.log(accessLevels[i]); - } + } + // TODO: Add support for version policy, variant + } else if (actionName === 'change') { + const bumpTypes: string[] = ['major', 'minor', 'patch', 'none']; + if (completePartialWord) { + if (secondLastCommand === '--bump-type') { + for (let i: number = 0; i < bumpTypes.length; i++) { + if (bumpTypes[i].indexOf(lastCommand) === 0) { + yield bumpTypes[i]; } - - return; } - } else { - if (lastCommand === '--set-access-level') { - for (let i: number = 0; i < accessLevels.length; i++) { - console.log(accessLevels[i]); - } - return; + return; + } + } else { + if (lastCommand === '--bump-type') { + for (let i: number = 0; i < bumpTypes.length; i++) { + yield bumpTypes[i]; } + + return; } } - + } else if (actionName === 'publish') { + const accessLevels: string[] = ['public', 'restricted']; if (completePartialWord) { - for (let i: number = 0; i < TabCompleteAction._actions[actionName].length; i++) { - if (TabCompleteAction._actions[actionName][i].name.indexOf(lastCommand) === 0) { - console.log(TabCompleteAction._actions[actionName][i].name); + if (secondLastCommand === '--set-access-level') { + for (let i: number = 0; i < accessLevels.length; i++) { + if (accessLevels[i].indexOf(lastCommand) === 0) { + yield accessLevels[i]; + } } + + return; } } else { - for (let i: number = 0; i < TabCompleteAction._actions[actionName].length; i++) { - if ( - lastCommand === TabCompleteAction._actions[actionName][i].name && - TabCompleteAction._actions[actionName][i].kind !== CommandLineParameterKind.Flag - ) { - // The parameter is expecting a value, so don't suggest parameter names again - return; + if (lastCommand === '--set-access-level') { + for (let i: number = 0; i < accessLevels.length; i++) { + yield accessLevels[i]; } + + return; } + } + } - for (let i: number = 0; i < TabCompleteAction._actions[actionName].length; i++) { - console.log(TabCompleteAction._actions[actionName][i].name); + if (completePartialWord) { + for (let i: number = 0; i < TabCompleteAction._actions[actionName].length; i++) { + if (TabCompleteAction._actions[actionName][i].name.indexOf(lastCommand) === 0) { + yield TabCompleteAction._actions[actionName][i].name; + } + } + } else { + for (let i: number = 0; i < TabCompleteAction._actions[actionName].length; i++) { + if ( + lastCommand === TabCompleteAction._actions[actionName][i].name && + TabCompleteAction._actions[actionName][i].kind !== CommandLineParameterKind.Flag + ) { + // The parameter is expecting a value, so don't suggest parameter names again + return; } } + + for (let i: number = 0; i < TabCompleteAction._actions[actionName].length; i++) { + yield TabCompleteAction._actions[actionName][i].name; + } } } } } } - private _printAllActions(): void { + private *_getAllActions(): IterableIterator { for (const actionName of Object.keys(TabCompleteAction._actions)) { - console.log(actionName); + yield actionName; } } - - protected onDefineParameters(): void { - this._wordToCompleteParameter = this.defineStringParameter({ - parameterLongName: '--word', - argumentName: 'WORD', - description: `The word to complete.` - }); - - this._positionParameter = this.defineIntegerParameter({ - parameterLongName: '--position', - argumentName: 'INDEX', - description: `The position in the word to be completed.` - }); - } } diff --git a/apps/rush-lib/src/cli/actions/test/TabCompleteAction.test.ts b/apps/rush-lib/src/cli/actions/test/TabCompleteAction.test.ts new file mode 100644 index 00000000000..c7ca391bb50 --- /dev/null +++ b/apps/rush-lib/src/cli/actions/test/TabCompleteAction.test.ts @@ -0,0 +1,144 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. +// See LICENSE in the project root for license information. + +import '../../test/mockRushCommandLineParser'; + +import * as path from 'path'; + +import { TabCompleteAction } from '../TabCompleteAction'; +import { RushCommandLineParser } from '../../RushCommandLineParser'; + +function arrayEqual(actual: string[], expected: string[]): boolean { + return ( + actual.length === expected.length && + actual.sort().every((v: string, i: number) => { + return v === expected.sort()[i]; + }) + ); +} + +describe('TabCompleteAction', () => { + let oldExitCode: number | undefined; + let oldArgs: string[]; + + beforeEach(() => { + jest.spyOn(process, 'exit').mockImplementation(); + oldExitCode = process.exitCode; + oldArgs = process.argv; + }); + + afterEach(() => { + jest.clearAllMocks(); + process.exitCode = oldExitCode; + process.argv = oldArgs; + }); + + describe(`Get TabCompletions`, () => { + it(`gets completion(s) for rush `, () => { + const startPath: string = path.resolve(__dirname, 'tabComplete'); + // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit + // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test + // repo will fail due to contention over the same lock which is kept until the test runner process + // ends. + jest.spyOn(process, 'cwd').mockReturnValue(startPath); + const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); + const tc: TabCompleteAction = new TabCompleteAction(parser); + + const actual: string[] = Array.from(tc._getCompletions('rush', 5)); + + expect(actual.indexOf('add') !== -1).toBe(true); + expect(actual.indexOf('check') !== -1).toBe(true); + expect(actual.indexOf('build') !== -1).toBe(true); + expect(actual.indexOf('rebuild') !== -1).toBe(true); + expect(actual.indexOf('-d') !== -1).toBe(true); + expect(actual.indexOf('--debug') !== -1).toBe(true); + expect(actual.indexOf('--help') !== -1).toBe(true); + }); + + it(`gets completion(s) for rush a`, () => { + const startPath: string = path.resolve(__dirname, 'tabComplete'); + // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit + // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test + // repo will fail due to contention over the same lock which is kept until the test runner process + // ends. + jest.spyOn(process, 'cwd').mockReturnValue(startPath); + const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); + const tc: TabCompleteAction = new TabCompleteAction(parser); + + const actual: string[] = Array.from(tc._getCompletions('rush a', 6)); + + const expected: string[] = ['add']; + + expect(arrayEqual(actual, expected)).toBe(true); + }); + + it(`gets completion(s) for rush build `, () => { + const startPath: string = path.resolve(__dirname, 'tabComplete'); + // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit + // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test + // repo will fail due to contention over the same lock which is kept until the test runner process + // ends. + jest.spyOn(process, 'cwd').mockReturnValue(startPath); + const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); + const tc: TabCompleteAction = new TabCompleteAction(parser); + + const actual: string[] = Array.from(tc._getCompletions('rush build', 11)); + + expect(actual.indexOf('-t') !== -1).toBe(true); + expect(actual.indexOf('--to') !== -1).toBe(true); + expect(actual.indexOf('-f') !== -1).toBe(true); + expect(actual.indexOf('--from') !== -1).toBe(true); + }); + + it(`gets completion(s) for rush build --`, () => { + const startPath: string = path.resolve(__dirname, 'tabComplete'); + // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit + // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test + // repo will fail due to contention over the same lock which is kept until the test runner process + // ends. + jest.spyOn(process, 'cwd').mockReturnValue(startPath); + const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); + const tc: TabCompleteAction = new TabCompleteAction(parser); + + const actual: string[] = Array.from(tc._getCompletions('rush build -', 13)); + + expect(actual.indexOf('-t') !== -1).toBe(true); + expect(actual.indexOf('--to') !== -1).toBe(true); + expect(actual.indexOf('-f') !== -1).toBe(true); + expect(actual.indexOf('--from') !== -1).toBe(true); + }); + + it(`gets completion(s) for rush build -t `, () => { + const startPath: string = path.resolve(__dirname, 'tabComplete'); + // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit + // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test + // repo will fail due to contention over the same lock which is kept until the test runner process + // ends. + jest.spyOn(process, 'cwd').mockReturnValue(startPath); + const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); + const tc: TabCompleteAction = new TabCompleteAction(parser); + + const actual: string[] = Array.from(tc._getCompletions('rush build -t', 14)); + + const expected: string[] = ['a', 'b']; + + expect(arrayEqual(actual, expected)).toBe(true); + }); + + it(`gets completion(s) for rush change --bump-type `, () => { + const startPath: string = path.resolve(__dirname, 'tabComplete'); + // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit + // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test + // repo will fail due to contention over the same lock which is kept until the test runner process + // ends. + jest.spyOn(process, 'cwd').mockReturnValue(startPath); + const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); + const tc: TabCompleteAction = new TabCompleteAction(parser); + + const actual: string[] = Array.from(tc._getCompletions('rush change --bump-type', 24)); + const expected: string[] = ['major', 'minor', 'patch', 'none']; + + expect(arrayEqual(actual, expected)).toBe(true); + }); + }); +}); diff --git a/apps/rush-lib/src/cli/actions/test/tabComplete/a/package.json b/apps/rush-lib/src/cli/actions/test/tabComplete/a/package.json new file mode 100644 index 00000000000..e57f46f8473 --- /dev/null +++ b/apps/rush-lib/src/cli/actions/test/tabComplete/a/package.json @@ -0,0 +1,5 @@ +{ + "name": "a", + "version": "1.0.0", + "description": "Test package a" +} diff --git a/apps/rush-lib/src/cli/actions/test/tabComplete/b/package.json b/apps/rush-lib/src/cli/actions/test/tabComplete/b/package.json new file mode 100644 index 00000000000..c76b152c4ee --- /dev/null +++ b/apps/rush-lib/src/cli/actions/test/tabComplete/b/package.json @@ -0,0 +1,5 @@ +{ + "name": "b", + "version": "1.0.0", + "description": "Test package b" +} diff --git a/apps/rush-lib/src/cli/actions/test/tabComplete/rush.json b/apps/rush-lib/src/cli/actions/test/tabComplete/rush.json new file mode 100644 index 00000000000..f39da1606c4 --- /dev/null +++ b/apps/rush-lib/src/cli/actions/test/tabComplete/rush.json @@ -0,0 +1,17 @@ +{ + "npmVersion": "6.4.1", + "rushVersion": "5.5.2", + "projectFolderMinDepth": 1, + "projectFolderMaxDepth": 99, + + "projects": [ + { + "packageName": "a", + "projectFolder": "a" + }, + { + "packageName": "b", + "projectFolder": "b" + } + ] +} From a2cd8fa37bfdee1f1e347bec6bf93a73b9369e05 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Wed, 29 Jul 2020 04:32:58 -0700 Subject: [PATCH 18/97] Rush change --- ...seph-rush-shell-tab-complete_2020-07-29-11-32.json | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 common/changes/@microsoft/rush/sachinjoseph-rush-shell-tab-complete_2020-07-29-11-32.json diff --git a/common/changes/@microsoft/rush/sachinjoseph-rush-shell-tab-complete_2020-07-29-11-32.json b/common/changes/@microsoft/rush/sachinjoseph-rush-shell-tab-complete_2020-07-29-11-32.json new file mode 100644 index 00000000000..2725b623510 --- /dev/null +++ b/common/changes/@microsoft/rush/sachinjoseph-rush-shell-tab-complete_2020-07-29-11-32.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "packageName": "@microsoft/rush", + "comment": "Add support for shell tab completion.", + "type": "none" + } + ], + "packageName": "@microsoft/rush", + "email": "sachinjoseph@users.noreply.github.com" +} \ No newline at end of file From 4bacae49681045af74a740b9fc313292b5553b11 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Wed, 29 Jul 2020 14:54:02 -0700 Subject: [PATCH 19/97] Add more tests --- .../actions/test/TabCompleteAction.test.ts | 61 ++++++++++++++++--- .../actions/test/tabComplete/a/package.json | 5 -- .../actions/test/tabComplete/abc/package.json | 5 ++ .../actions/test/tabComplete/b/package.json | 5 -- .../actions/test/tabComplete/def/package.json | 5 ++ .../cli/actions/test/tabComplete/rush.json | 8 +-- 6 files changed, 67 insertions(+), 22 deletions(-) delete mode 100644 apps/rush-lib/src/cli/actions/test/tabComplete/a/package.json create mode 100644 apps/rush-lib/src/cli/actions/test/tabComplete/abc/package.json delete mode 100644 apps/rush-lib/src/cli/actions/test/tabComplete/b/package.json create mode 100644 apps/rush-lib/src/cli/actions/test/tabComplete/def/package.json diff --git a/apps/rush-lib/src/cli/actions/test/TabCompleteAction.test.ts b/apps/rush-lib/src/cli/actions/test/TabCompleteAction.test.ts index c7ca391bb50..8ae37dbea65 100644 --- a/apps/rush-lib/src/cli/actions/test/TabCompleteAction.test.ts +++ b/apps/rush-lib/src/cli/actions/test/TabCompleteAction.test.ts @@ -44,7 +44,8 @@ describe('TabCompleteAction', () => { const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); const tc: TabCompleteAction = new TabCompleteAction(parser); - const actual: string[] = Array.from(tc._getCompletions('rush', 5)); + const commandLine: string = 'rush'; + const actual: string[] = Array.from(tc._getCompletions(commandLine.trim(), commandLine.length)); expect(actual.indexOf('add') !== -1).toBe(true); expect(actual.indexOf('check') !== -1).toBe(true); @@ -65,7 +66,8 @@ describe('TabCompleteAction', () => { const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); const tc: TabCompleteAction = new TabCompleteAction(parser); - const actual: string[] = Array.from(tc._getCompletions('rush a', 6)); + const commandLine: string = 'rush a'; + const actual: string[] = Array.from(tc._getCompletions(commandLine.trim(), commandLine.length)); const expected: string[] = ['add']; @@ -82,7 +84,8 @@ describe('TabCompleteAction', () => { const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); const tc: TabCompleteAction = new TabCompleteAction(parser); - const actual: string[] = Array.from(tc._getCompletions('rush build', 11)); + const commandLine: string = 'rush build '; + const actual: string[] = Array.from(tc._getCompletions(commandLine.trim(), commandLine.length)); expect(actual.indexOf('-t') !== -1).toBe(true); expect(actual.indexOf('--to') !== -1).toBe(true); @@ -90,7 +93,7 @@ describe('TabCompleteAction', () => { expect(actual.indexOf('--from') !== -1).toBe(true); }); - it(`gets completion(s) for rush build --`, () => { + it(`gets completion(s) for rush build -`, () => { const startPath: string = path.resolve(__dirname, 'tabComplete'); // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test @@ -100,7 +103,8 @@ describe('TabCompleteAction', () => { const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); const tc: TabCompleteAction = new TabCompleteAction(parser); - const actual: string[] = Array.from(tc._getCompletions('rush build -', 13)); + const commandLine: string = 'rush build -'; + const actual: string[] = Array.from(tc._getCompletions(commandLine.trim(), commandLine.length)); expect(actual.indexOf('-t') !== -1).toBe(true); expect(actual.indexOf('--to') !== -1).toBe(true); @@ -118,9 +122,30 @@ describe('TabCompleteAction', () => { const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); const tc: TabCompleteAction = new TabCompleteAction(parser); - const actual: string[] = Array.from(tc._getCompletions('rush build -t', 14)); + const commandLine: string = 'rush build -t '; + const actual: string[] = Array.from(tc._getCompletions(commandLine.trim(), commandLine.length)); - const expected: string[] = ['a', 'b']; + const expected: string[] = ['abc', 'def']; + + expect(arrayEqual(actual, expected)).toBe(true); + }); + + it(`gets completion(s) for rush build -t a`, () => { + const startPath: string = path.resolve(__dirname, 'tabComplete'); + // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit + // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test + // repo will fail due to contention over the same lock which is kept until the test runner process + // ends. + jest.spyOn(process, 'cwd').mockReturnValue(startPath); + const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); + const tc: TabCompleteAction = new TabCompleteAction(parser); + + const commandLine: string = 'rush build -t a'; + const actual: string[] = Array.from(tc._getCompletions(commandLine.trim(), commandLine.length)); + + console.log('Actual: ' + actual); + + const expected: string[] = ['abc']; expect(arrayEqual(actual, expected)).toBe(true); }); @@ -135,10 +160,30 @@ describe('TabCompleteAction', () => { const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); const tc: TabCompleteAction = new TabCompleteAction(parser); - const actual: string[] = Array.from(tc._getCompletions('rush change --bump-type', 24)); + const commandLine: string = 'rush change --bump-type '; + const actual: string[] = Array.from(tc._getCompletions(commandLine.trim(), commandLine.length)); const expected: string[] = ['major', 'minor', 'patch', 'none']; expect(arrayEqual(actual, expected)).toBe(true); }); + + it(`gets completion(s) for rush change --bump-type m`, () => { + const startPath: string = path.resolve(__dirname, 'tabComplete'); + // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit + // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test + // repo will fail due to contention over the same lock which is kept until the test runner process + // ends. + jest.spyOn(process, 'cwd').mockReturnValue(startPath); + const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); + const tc: TabCompleteAction = new TabCompleteAction(parser); + + const commandLine: string = 'rush change --bump-type m'; + const actual: string[] = Array.from(tc._getCompletions(commandLine.trim(), commandLine.length)); + console.log('Actual: ' + actual); + + const expected: string[] = ['major', 'minor']; + + expect(arrayEqual(actual, expected)).toBe(true); + }); }); }); diff --git a/apps/rush-lib/src/cli/actions/test/tabComplete/a/package.json b/apps/rush-lib/src/cli/actions/test/tabComplete/a/package.json deleted file mode 100644 index e57f46f8473..00000000000 --- a/apps/rush-lib/src/cli/actions/test/tabComplete/a/package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "a", - "version": "1.0.0", - "description": "Test package a" -} diff --git a/apps/rush-lib/src/cli/actions/test/tabComplete/abc/package.json b/apps/rush-lib/src/cli/actions/test/tabComplete/abc/package.json new file mode 100644 index 00000000000..f90b1417a7a --- /dev/null +++ b/apps/rush-lib/src/cli/actions/test/tabComplete/abc/package.json @@ -0,0 +1,5 @@ +{ + "name": "abc", + "version": "1.0.0", + "description": "Test package abc" +} diff --git a/apps/rush-lib/src/cli/actions/test/tabComplete/b/package.json b/apps/rush-lib/src/cli/actions/test/tabComplete/b/package.json deleted file mode 100644 index c76b152c4ee..00000000000 --- a/apps/rush-lib/src/cli/actions/test/tabComplete/b/package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "b", - "version": "1.0.0", - "description": "Test package b" -} diff --git a/apps/rush-lib/src/cli/actions/test/tabComplete/def/package.json b/apps/rush-lib/src/cli/actions/test/tabComplete/def/package.json new file mode 100644 index 00000000000..99a1aec27cc --- /dev/null +++ b/apps/rush-lib/src/cli/actions/test/tabComplete/def/package.json @@ -0,0 +1,5 @@ +{ + "name": "def", + "version": "1.0.0", + "description": "Test package def" +} diff --git a/apps/rush-lib/src/cli/actions/test/tabComplete/rush.json b/apps/rush-lib/src/cli/actions/test/tabComplete/rush.json index f39da1606c4..a136d8a8ea8 100644 --- a/apps/rush-lib/src/cli/actions/test/tabComplete/rush.json +++ b/apps/rush-lib/src/cli/actions/test/tabComplete/rush.json @@ -6,12 +6,12 @@ "projects": [ { - "packageName": "a", - "projectFolder": "a" + "packageName": "abc", + "projectFolder": "abc" }, { - "packageName": "b", - "projectFolder": "b" + "packageName": "def", + "projectFolder": "def" } ] } From 1b6bb1496a301892642b44a7946e47fc5ea72185 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Wed, 29 Jul 2020 15:03:29 -0700 Subject: [PATCH 20/97] Use constants --- apps/rush-lib/src/cli/actions/TabCompleteAction.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts index 942f68efcd3..c66c4f1cd22 100644 --- a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts +++ b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts @@ -15,6 +15,8 @@ interface IParameter { kind: CommandLineParameterKind; } +const DEFAULT_WORD_TO_AUTOCOMPLETE = ''; +const DEFAULT_POSITION = 0; export class TabCompleteAction extends BaseRushAction { private _wordToCompleteParameter: CommandLineStringParameter; private _positionParameter: CommandLineIntegerParameter; @@ -35,13 +37,15 @@ export class TabCompleteAction extends BaseRushAction { this._wordToCompleteParameter = this.defineStringParameter({ parameterLongName: '--word', argumentName: 'WORD', - description: `The word to complete.` + description: `The word to complete.`, + defaultValue: DEFAULT_WORD_TO_AUTOCOMPLETE }); this._positionParameter = this.defineIntegerParameter({ parameterLongName: '--position', argumentName: 'INDEX', - description: `The position in the word to be completed.` + description: `The position in the word to be completed.`, + defaultValue: DEFAULT_POSITION }); } From 8f4e67770c54ed3b26a1deb6e9d590582154409c Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Wed, 29 Jul 2020 18:13:08 -0700 Subject: [PATCH 21/97] Set default values for args --- apps/rush-lib/src/cli/actions/TabCompleteAction.ts | 4 ++-- .../src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts index c66c4f1cd22..7cfdb1fb2e2 100644 --- a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts +++ b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts @@ -15,8 +15,8 @@ interface IParameter { kind: CommandLineParameterKind; } -const DEFAULT_WORD_TO_AUTOCOMPLETE = ''; -const DEFAULT_POSITION = 0; +const DEFAULT_WORD_TO_AUTOCOMPLETE: string = ''; +const DEFAULT_POSITION: number = 0; export class TabCompleteAction extends BaseRushAction { private _wordToCompleteParameter: CommandLineStringParameter; private _positionParameter: CommandLineIntegerParameter; diff --git a/apps/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap b/apps/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap index cda613a5457..b0f55e85f09 100644 --- a/apps/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap +++ b/apps/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap @@ -665,8 +665,9 @@ Provides tab completion Optional arguments: -h, --help Show this help message and exit. - --word WORD The word to complete. - --position INDEX The position in the word to be completed. + --word WORD The word to complete. The default value is \\"\\". + --position INDEX The position in the word to be completed. The default + value is 0. " `; From fe00b9fa60574b7ebfcf1e00ec74016723d4bd33 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Thu, 30 Jul 2020 13:41:15 -0700 Subject: [PATCH 22/97] Refactor some code. Address comments. --- apps/rush-lib/src/api/Rush.ts | 3 +- .../rush-lib/src/cli/RushCommandLineParser.ts | 2 +- .../src/cli/actions/BaseRushAction.ts | 2 +- .../src/cli/actions/TabCompleteAction.ts | 115 +++++++++--------- .../CommandLineHelp.test.ts.snap | 2 +- apps/rush-lib/src/utilities/Utilities.ts | 4 + apps/rush/src/MinimalRushConfiguration.ts | 3 +- 7 files changed, 66 insertions(+), 65 deletions(-) diff --git a/apps/rush-lib/src/api/Rush.ts b/apps/rush-lib/src/api/Rush.ts index 325411815c7..66f1da977b4 100644 --- a/apps/rush-lib/src/api/Rush.ts +++ b/apps/rush-lib/src/api/Rush.ts @@ -10,6 +10,7 @@ import { RushConstants } from '../logic/RushConstants'; import { RushXCommandLine } from '../cli/RushXCommandLine'; import { CommandLineMigrationAdvisor } from '../cli/CommandLineMigrationAdvisor'; import { NodeJsCompatibility } from '../logic/NodeJsCompatibility'; +import { Utilities } from '../utilities/Utilities'; /** * Options to pass to the rush "launch" functions. @@ -53,7 +54,7 @@ export class Rush { public static launch(launcherVersion: string, arg: ILaunchOptions): void { const options: ILaunchOptions = Rush._normalizeLaunchOptions(arg); - if (!(process.argv.length > 2 && process.argv[2] === 'tab-complete')) { + if (!Utilities.isNonDebugTabCompletionRequest()) { Rush._printStartupBanner(options.isManaged); } diff --git a/apps/rush-lib/src/cli/RushCommandLineParser.ts b/apps/rush-lib/src/cli/RushCommandLineParser.ts index d7fe7761d7d..12a5b703fc0 100644 --- a/apps/rush-lib/src/cli/RushCommandLineParser.ts +++ b/apps/rush-lib/src/cli/RushCommandLineParser.ts @@ -77,7 +77,7 @@ export class RushCommandLineParser extends CommandLineParser { try { const rushJsonFilename: string | undefined = RushConfiguration.tryFindRushJsonLocation({ startingFolder: this._rushOptions.cwd, - showVerbose: process.argv.length > 2 && process.argv[2] !== 'tab-complete' + showVerbose: !Utilities.isNonDebugTabCompletionRequest() }); if (rushJsonFilename) { this.rushConfiguration = RushConfiguration.loadFromConfigurationFile(rushJsonFilename); diff --git a/apps/rush-lib/src/cli/actions/BaseRushAction.ts b/apps/rush-lib/src/cli/actions/BaseRushAction.ts index 70adca54c00..d260bb73875 100644 --- a/apps/rush-lib/src/cli/actions/BaseRushAction.ts +++ b/apps/rush-lib/src/cli/actions/BaseRushAction.ts @@ -75,7 +75,7 @@ export abstract class BaseConfiglessRushAction extends CommandLineAction { } } - if (!(process.argv.length > 2 && process.argv[2] === 'tab-complete')) { + if (!Utilities.isNonDebugTabCompletionRequest()) { console.log(`Starting "rush ${this.actionName}"${os.EOL}`); } return this.run(); diff --git a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts index 7cfdb1fb2e2..926a507fa93 100644 --- a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts +++ b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts @@ -27,7 +27,7 @@ export class TabCompleteAction extends BaseRushAction { super({ actionName: 'tab-complete', summary: 'Provides tab completion.', - documentation: 'Provides tab completion', + documentation: 'Provides tab completion.', parser, safeForSimultaneousRushProcesses: true }); @@ -119,69 +119,40 @@ export class TabCompleteAction extends BaseRushAction { for (const actionName of Object.keys(TabCompleteAction._actions)) { if (actionName === commands[1 + debugParameterOffset]) { if (actionName === 'build' || actionName === 'rebuild') { - const projectCommands: string[] = ['-f', '--from', '-t', '--to']; - if (completePartialWord) { - if (projectCommands.indexOf(secondLastCommand) !== -1) { - for (let i: number = 0; i < this.rushConfiguration.projects.length; i++) { - if (this.rushConfiguration.projects[i].packageName.indexOf(lastCommand) === 0) { - yield this.rushConfiguration.projects[i].packageName; - } - } - - return; - } - } else { - if (projectCommands.indexOf(lastCommand) !== -1) { - for (let i: number = 0; i < this.rushConfiguration.projects.length; i++) { - yield this.rushConfiguration.projects[i].packageName; - } - - return; - } + const choiceParameter: string[] = ['-f', '--from', '-t', '--to']; + const choiceParameterValues: string[] = []; + for (let i: number = 0; i < this.rushConfiguration.projects.length; i++) { + choiceParameterValues.push(this.rushConfiguration.projects[i].packageName); } + yield* this._getChoiceParameterValues( + choiceParameter, + choiceParameterValues, + lastCommand, + secondLastCommand, + completePartialWord + ); + // TODO: Add support for version policy, variant } else if (actionName === 'change') { - const bumpTypes: string[] = ['major', 'minor', 'patch', 'none']; - if (completePartialWord) { - if (secondLastCommand === '--bump-type') { - for (let i: number = 0; i < bumpTypes.length; i++) { - if (bumpTypes[i].indexOf(lastCommand) === 0) { - yield bumpTypes[i]; - } - } - - return; - } - } else { - if (lastCommand === '--bump-type') { - for (let i: number = 0; i < bumpTypes.length; i++) { - yield bumpTypes[i]; - } - - return; - } - } + const choiceParameter: string[] = ['--bump-type']; + const choiceParameterValues: string[] = ['major', 'minor', 'patch', 'none']; + yield* this._getChoiceParameterValues( + choiceParameter, + choiceParameterValues, + lastCommand, + secondLastCommand, + completePartialWord + ); } else if (actionName === 'publish') { - const accessLevels: string[] = ['public', 'restricted']; - if (completePartialWord) { - if (secondLastCommand === '--set-access-level') { - for (let i: number = 0; i < accessLevels.length; i++) { - if (accessLevels[i].indexOf(lastCommand) === 0) { - yield accessLevels[i]; - } - } - - return; - } - } else { - if (lastCommand === '--set-access-level') { - for (let i: number = 0; i < accessLevels.length; i++) { - yield accessLevels[i]; - } - - return; - } - } + const choiceParameter: string[] = ['--set-access-level']; + const choiceParameterValues: string[] = ['public', 'restricted']; + yield* this._getChoiceParameterValues( + choiceParameter, + choiceParameterValues, + lastCommand, + secondLastCommand, + completePartialWord + ); } if (completePartialWord) { @@ -210,6 +181,30 @@ export class TabCompleteAction extends BaseRushAction { } } + private *_getChoiceParameterValues( + choiceParameter: string[], + choiceParamaterValues: string[], + lastCommand: string, + secondLastCommand: string, + completePartialWord: boolean + ): IterableIterator { + if (completePartialWord) { + if (choiceParameter.indexOf(secondLastCommand) !== -1) { + for (let i: number = 0; i < choiceParamaterValues.length; i++) { + if (choiceParamaterValues[i].indexOf(lastCommand) === 0) { + yield choiceParamaterValues[i]; + } + } + } + } else { + if (choiceParameter.indexOf(lastCommand) !== -1) { + for (let i: number = 0; i < choiceParamaterValues.length; i++) { + yield choiceParamaterValues[i]; + } + } + } + } + private *_getAllActions(): IterableIterator { for (const actionName of Object.keys(TabCompleteAction._actions)) { yield actionName; diff --git a/apps/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap b/apps/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap index b0f55e85f09..2d281e396e9 100644 --- a/apps/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap +++ b/apps/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap @@ -661,7 +661,7 @@ Optional arguments: exports[`CommandLineHelp prints the help for each action: tab-complete 1`] = ` "usage: rush tab-complete [-h] [--word WORD] [--position INDEX] -Provides tab completion +Provides tab completion. Optional arguments: -h, --help Show this help message and exit. diff --git a/apps/rush-lib/src/utilities/Utilities.ts b/apps/rush-lib/src/utilities/Utilities.ts index 4cec356fc3d..4b7e344c8ef 100644 --- a/apps/rush-lib/src/utilities/Utilities.ts +++ b/apps/rush-lib/src/utilities/Utilities.ts @@ -442,6 +442,10 @@ export class Utilities { return Utilities._executeLifecycleCommandInternal(command, child_process.spawn, options); } + public static isNonDebugTabCompletionRequest(): boolean { + return process.argv.length > 2 && process.argv[2] === 'tab-complete'; + } + /** * For strings passed to a shell command, this adds appropriate escaping * to avoid misinterpretation of spaces or special characters. diff --git a/apps/rush/src/MinimalRushConfiguration.ts b/apps/rush/src/MinimalRushConfiguration.ts index 2b27b673a0a..9e7953de13e 100644 --- a/apps/rush/src/MinimalRushConfiguration.ts +++ b/apps/rush/src/MinimalRushConfiguration.ts @@ -6,6 +6,7 @@ import * as path from 'path'; import { JsonFile } from '@rushstack/node-core-library'; import { RushConfiguration } from '@microsoft/rush-lib'; import { RushConstants } from '@microsoft/rush-lib/lib/logic/RushConstants'; +import { Utilities } from '@microsoft/rush-lib/lib/utilities/Utilities'; interface IMinimalRushConfigurationJson { rushMinimumVersion: string; @@ -33,7 +34,7 @@ export class MinimalRushConfiguration { public static loadFromDefaultLocation(): MinimalRushConfiguration | undefined { const rushJsonLocation: string | undefined = RushConfiguration.tryFindRushJsonLocation({ - showVerbose: process.argv.length > 2 && process.argv[2] !== 'tab-complete' + showVerbose: !Utilities.isNonDebugTabCompletionRequest() }); if (rushJsonLocation) { return MinimalRushConfiguration._loadFromConfigurationFile(rushJsonLocation); From 518c8bf9215efcc37021cdfdad948363e1a2a460 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Fri, 31 Jul 2020 09:27:52 -0700 Subject: [PATCH 23/97] Change run() to runAsync() --- apps/rush-lib/src/cli/actions/AddAction.ts | 2 +- apps/rush-lib/src/cli/actions/BaseInstallAction.ts | 2 +- apps/rush-lib/src/cli/actions/BaseRushAction.ts | 4 ++-- apps/rush-lib/src/cli/actions/ChangeAction.ts | 2 +- apps/rush-lib/src/cli/actions/CheckAction.ts | 2 +- apps/rush-lib/src/cli/actions/DeployAction.ts | 2 +- apps/rush-lib/src/cli/actions/InitAction.ts | 2 +- apps/rush-lib/src/cli/actions/InitAutoinstallerAction.ts | 2 +- apps/rush-lib/src/cli/actions/InitDeployAction.ts | 2 +- apps/rush-lib/src/cli/actions/LinkAction.ts | 2 +- apps/rush-lib/src/cli/actions/ListAction.ts | 2 +- apps/rush-lib/src/cli/actions/PublishAction.ts | 2 +- apps/rush-lib/src/cli/actions/PurgeAction.ts | 2 +- apps/rush-lib/src/cli/actions/ScanAction.ts | 2 +- apps/rush-lib/src/cli/actions/TabCompleteAction.ts | 2 +- apps/rush-lib/src/cli/actions/UnlinkAction.ts | 2 +- apps/rush-lib/src/cli/actions/UpdateAutoinstallerAction.ts | 2 +- apps/rush-lib/src/cli/actions/VersionAction.ts | 2 +- apps/rush-lib/src/cli/scriptActions/BulkScriptAction.ts | 2 +- apps/rush-lib/src/cli/scriptActions/GlobalScriptAction.ts | 2 +- 20 files changed, 21 insertions(+), 21 deletions(-) diff --git a/apps/rush-lib/src/cli/actions/AddAction.ts b/apps/rush-lib/src/cli/actions/AddAction.ts index 8ff51a78b54..308d886867a 100644 --- a/apps/rush-lib/src/cli/actions/AddAction.ts +++ b/apps/rush-lib/src/cli/actions/AddAction.ts @@ -87,7 +87,7 @@ export class AddAction extends BaseRushAction { }); } - public async run(): Promise { + public async runAsync(): Promise { let projects: RushConfigurationProject[]; if (this._allFlag.value) { projects = this.rushConfiguration.projects; diff --git a/apps/rush-lib/src/cli/actions/BaseInstallAction.ts b/apps/rush-lib/src/cli/actions/BaseInstallAction.ts index 1cafd9517af..3ed4c7c06fc 100644 --- a/apps/rush-lib/src/cli/actions/BaseInstallAction.ts +++ b/apps/rush-lib/src/cli/actions/BaseInstallAction.ts @@ -77,7 +77,7 @@ export abstract class BaseInstallAction extends BaseRushAction { protected abstract buildInstallOptions(): IInstallManagerOptions; - protected run(): Promise { + protected runAsync(): Promise { VersionMismatchFinder.ensureConsistentVersions(this.rushConfiguration, { variant: this._variant.value }); diff --git a/apps/rush-lib/src/cli/actions/BaseRushAction.ts b/apps/rush-lib/src/cli/actions/BaseRushAction.ts index d260bb73875..51b5cbd9f60 100644 --- a/apps/rush-lib/src/cli/actions/BaseRushAction.ts +++ b/apps/rush-lib/src/cli/actions/BaseRushAction.ts @@ -78,14 +78,14 @@ export abstract class BaseConfiglessRushAction extends CommandLineAction { if (!Utilities.isNonDebugTabCompletionRequest()) { console.log(`Starting "rush ${this.actionName}"${os.EOL}`); } - return this.run(); + return this.runAsync(); } /** * All Rush actions need to implement this method. This method runs after * environment has been set up by the base class. */ - protected abstract run(): Promise; + protected abstract runAsync(): Promise; private _ensureEnvironment(): void { if (this.rushConfiguration) { diff --git a/apps/rush-lib/src/cli/actions/ChangeAction.ts b/apps/rush-lib/src/cli/actions/ChangeAction.ts index a85a744cdd0..171be820585 100644 --- a/apps/rush-lib/src/cli/actions/ChangeAction.ts +++ b/apps/rush-lib/src/cli/actions/ChangeAction.ts @@ -142,7 +142,7 @@ export class ChangeAction extends BaseRushAction { }); } - public async run(): Promise { + public async runAsync(): Promise { console.log(`The target branch is ${this._targetBranch}`); this._projectHostMap = this._generateHostMap(); diff --git a/apps/rush-lib/src/cli/actions/CheckAction.ts b/apps/rush-lib/src/cli/actions/CheckAction.ts index 0fc07c96746..79597504a8d 100644 --- a/apps/rush-lib/src/cli/actions/CheckAction.ts +++ b/apps/rush-lib/src/cli/actions/CheckAction.ts @@ -35,7 +35,7 @@ export class CheckAction extends BaseRushAction { }); } - protected run(): Promise { + protected runAsync(): Promise { const variant: string | undefined = this.rushConfiguration.currentInstalledVariant; if (!this._variant.value && variant) { diff --git a/apps/rush-lib/src/cli/actions/DeployAction.ts b/apps/rush-lib/src/cli/actions/DeployAction.ts index d40e4795efd..a3aa8fa3725 100644 --- a/apps/rush-lib/src/cli/actions/DeployAction.ts +++ b/apps/rush-lib/src/cli/actions/DeployAction.ts @@ -77,7 +77,7 @@ export class DeployAction extends BaseRushAction { }); } - protected async run(): Promise { + protected async runAsync(): Promise { const deployManager: DeployManager = new DeployManager(this.rushConfiguration); await deployManager.deployAsync( this._project.value, diff --git a/apps/rush-lib/src/cli/actions/InitAction.ts b/apps/rush-lib/src/cli/actions/InitAction.ts index 23d2e6cdb0b..0566f793a7e 100644 --- a/apps/rush-lib/src/cli/actions/InitAction.ts +++ b/apps/rush-lib/src/cli/actions/InitAction.ts @@ -80,7 +80,7 @@ export class InitAction extends BaseConfiglessRushAction { }); } - protected run(): Promise { + protected runAsync(): Promise { const initFolder: string = process.cwd(); if (!this._overwriteParameter.value) { diff --git a/apps/rush-lib/src/cli/actions/InitAutoinstallerAction.ts b/apps/rush-lib/src/cli/actions/InitAutoinstallerAction.ts index 97d981318e0..1a06642df1e 100644 --- a/apps/rush-lib/src/cli/actions/InitAutoinstallerAction.ts +++ b/apps/rush-lib/src/cli/actions/InitAutoinstallerAction.ts @@ -35,7 +35,7 @@ export class InitAutoinstallerAction extends BaseRushAction { }); } - protected async run(): Promise { + protected async runAsync(): Promise { const autoinstallerName: string = this._name.value!; const autoinstaller: Autoinstaller = new Autoinstaller(autoinstallerName, this.rushConfiguration); diff --git a/apps/rush-lib/src/cli/actions/InitDeployAction.ts b/apps/rush-lib/src/cli/actions/InitDeployAction.ts index c01470124b8..416d2f3b0de 100644 --- a/apps/rush-lib/src/cli/actions/InitDeployAction.ts +++ b/apps/rush-lib/src/cli/actions/InitDeployAction.ts @@ -52,7 +52,7 @@ export class InitDeployAction extends BaseRushAction { }); } - protected async run(): Promise { + protected async runAsync(): Promise { const scenarioFilePath: string = DeployScenarioConfiguration.getConfigFilePath( this._scenario.value, this.rushConfiguration diff --git a/apps/rush-lib/src/cli/actions/LinkAction.ts b/apps/rush-lib/src/cli/actions/LinkAction.ts index 4f6d6aab686..773b68de894 100644 --- a/apps/rush-lib/src/cli/actions/LinkAction.ts +++ b/apps/rush-lib/src/cli/actions/LinkAction.ts @@ -34,7 +34,7 @@ export class LinkAction extends BaseRushAction { }); } - protected async run(): Promise { + protected async runAsync(): Promise { const linkManager: BaseLinkManager = LinkManagerFactory.getLinkManager(this.rushConfiguration); await linkManager.createSymlinksForProjects(this._force.value); } diff --git a/apps/rush-lib/src/cli/actions/ListAction.ts b/apps/rush-lib/src/cli/actions/ListAction.ts index 43f5c8bbef7..28860560a65 100644 --- a/apps/rush-lib/src/cli/actions/ListAction.ts +++ b/apps/rush-lib/src/cli/actions/ListAction.ts @@ -67,7 +67,7 @@ export class ListAction extends BaseRushAction { }); } - protected async run(): Promise { + protected async runAsync(): Promise { const allPackages: Map = this.rushConfiguration.projectsByName; if (this._jsonFlag.value) { this._printJson(allPackages); diff --git a/apps/rush-lib/src/cli/actions/PublishAction.ts b/apps/rush-lib/src/cli/actions/PublishAction.ts index 144eec68923..79dde857640 100644 --- a/apps/rush-lib/src/cli/actions/PublishAction.ts +++ b/apps/rush-lib/src/cli/actions/PublishAction.ts @@ -207,7 +207,7 @@ export class PublishAction extends BaseRushAction { /** * Executes the publish action, which will read change request files, apply changes to package.jsons, */ - protected run(): Promise { + protected runAsync(): Promise { return Promise.resolve().then(() => { PolicyValidator.validatePolicy(this.rushConfiguration, { bypassPolicy: false }); diff --git a/apps/rush-lib/src/cli/actions/PurgeAction.ts b/apps/rush-lib/src/cli/actions/PurgeAction.ts index 917cf427666..20dc563c542 100644 --- a/apps/rush-lib/src/cli/actions/PurgeAction.ts +++ b/apps/rush-lib/src/cli/actions/PurgeAction.ts @@ -37,7 +37,7 @@ export class PurgeAction extends BaseRushAction { }); } - protected run(): Promise { + protected runAsync(): Promise { return Promise.resolve().then(() => { const stopwatch: Stopwatch = Stopwatch.start(); diff --git a/apps/rush-lib/src/cli/actions/ScanAction.ts b/apps/rush-lib/src/cli/actions/ScanAction.ts index c16db44b44e..c243c09e734 100644 --- a/apps/rush-lib/src/cli/actions/ScanAction.ts +++ b/apps/rush-lib/src/cli/actions/ScanAction.ts @@ -33,7 +33,7 @@ export class ScanAction extends BaseConfiglessRushAction { // abstract } - protected run(): Promise { + protected runAsync(): Promise { const packageJsonFilename: string = path.resolve('./package.json'); if (!FileSystem.exists(packageJsonFilename)) { diff --git a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts index 926a507fa93..6d513275492 100644 --- a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts +++ b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts @@ -49,7 +49,7 @@ export class TabCompleteAction extends BaseRushAction { }); } - protected async run(): Promise { + protected async runAsync(): Promise { const commandLine: string = this._wordToCompleteParameter.value || ''; const caretPosition: number = this._positionParameter.value || 0; diff --git a/apps/rush-lib/src/cli/actions/UnlinkAction.ts b/apps/rush-lib/src/cli/actions/UnlinkAction.ts index 99b2d32b9f5..5111027628b 100644 --- a/apps/rush-lib/src/cli/actions/UnlinkAction.ts +++ b/apps/rush-lib/src/cli/actions/UnlinkAction.ts @@ -24,7 +24,7 @@ export class UnlinkAction extends BaseRushAction { // No parameters } - protected run(): Promise { + protected runAsync(): Promise { return Promise.resolve().then(() => { const unlinkManager: UnlinkManager = new UnlinkManager(this.rushConfiguration); diff --git a/apps/rush-lib/src/cli/actions/UpdateAutoinstallerAction.ts b/apps/rush-lib/src/cli/actions/UpdateAutoinstallerAction.ts index 5e8b1f41be9..252c71cc3d2 100644 --- a/apps/rush-lib/src/cli/actions/UpdateAutoinstallerAction.ts +++ b/apps/rush-lib/src/cli/actions/UpdateAutoinstallerAction.ts @@ -29,7 +29,7 @@ export class UpdateAutoinstallerAction extends BaseRushAction { }); } - protected async run(): Promise { + protected async runAsync(): Promise { const autoinstallerName: string = this._name.value!; const autoinstaller: Autoinstaller = new Autoinstaller(autoinstallerName, this.rushConfiguration); diff --git a/apps/rush-lib/src/cli/actions/VersionAction.ts b/apps/rush-lib/src/cli/actions/VersionAction.ts index 4761e514c5d..a5f121c91ea 100644 --- a/apps/rush-lib/src/cli/actions/VersionAction.ts +++ b/apps/rush-lib/src/cli/actions/VersionAction.ts @@ -92,7 +92,7 @@ export class VersionAction extends BaseRushAction { }); } - protected run(): Promise { + protected runAsync(): Promise { return Promise.resolve().then(() => { PolicyValidator.validatePolicy(this.rushConfiguration, { bypassPolicy: this._bypassPolicy.value }); const userEmail: string = Git.getGitEmail(this.rushConfiguration); diff --git a/apps/rush-lib/src/cli/scriptActions/BulkScriptAction.ts b/apps/rush-lib/src/cli/scriptActions/BulkScriptAction.ts index e2e23ae1d0b..8100e90ee84 100644 --- a/apps/rush-lib/src/cli/scriptActions/BulkScriptAction.ts +++ b/apps/rush-lib/src/cli/scriptActions/BulkScriptAction.ts @@ -75,7 +75,7 @@ export class BulkScriptAction extends BaseScriptAction { this._allowWarningsInSuccessfulBuild = options.allowWarningsInSuccessfulBuild; } - public run(): Promise { + public runAsync(): Promise { // TODO: Replace with last-install.flag when "rush link" and "rush unlink" are deprecated const lastLinkFlag: LastLinkFlag = LastLinkFlagFactory.getCommonTempFlag(this.rushConfiguration); if (!lastLinkFlag.isValid()) { diff --git a/apps/rush-lib/src/cli/scriptActions/GlobalScriptAction.ts b/apps/rush-lib/src/cli/scriptActions/GlobalScriptAction.ts index 948153c9606..1ec816468c9 100644 --- a/apps/rush-lib/src/cli/scriptActions/GlobalScriptAction.ts +++ b/apps/rush-lib/src/cli/scriptActions/GlobalScriptAction.ts @@ -149,7 +149,7 @@ export class GlobalScriptAction extends BaseScriptAction { lock.release(); } - public async run(): Promise { + public async runAsync(): Promise { const additionalPathFolders: string[] = []; if (this._autoinstallerName) { From 12ce2f1c63a2d5eb1d35103ae707aa8baf4daeed Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Fri, 31 Jul 2020 09:45:30 -0700 Subject: [PATCH 24/97] Address David's comments --- .../src/cli/actions/TabCompleteAction.ts | 52 +++++++++---------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts index 6d513275492..d55c700e3c4 100644 --- a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts +++ b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts @@ -17,12 +17,15 @@ interface IParameter { const DEFAULT_WORD_TO_AUTOCOMPLETE: string = ''; const DEFAULT_POSITION: number = 0; + +interface IActionMap { + [actionName: string]: IParameter[]; +} + export class TabCompleteAction extends BaseRushAction { private _wordToCompleteParameter: CommandLineStringParameter; private _positionParameter: CommandLineIntegerParameter; - private static _actions: { [actionName: string]: IParameter[] } = {}; - public constructor(parser: RushCommandLineParser) { super({ actionName: 'tab-complete', @@ -59,6 +62,7 @@ export class TabCompleteAction extends BaseRushAction { } public *_getCompletions(commandLine: string, caretPosition: number): IterableIterator { + const actions: IActionMap = {}; this.parser.actions.forEach((element) => { const actionParameters: IParameter[] = []; element.parameters.forEach((elem) => { @@ -67,13 +71,13 @@ export class TabCompleteAction extends BaseRushAction { actionParameters.push({ name: elem.shortName, kind: elem.kind }); } }); - TabCompleteAction._actions[element.actionName] = actionParameters; + actions[element.actionName] = actionParameters; }); - TabCompleteAction._actions['-d'] = []; - TabCompleteAction._actions['--debug'] = []; - TabCompleteAction._actions['-h'] = []; - TabCompleteAction._actions['--help'] = []; + actions['-d'] = []; + actions['--debug'] = []; + actions['-h'] = []; + actions['--help'] = []; // yield ('arg count: ' + process.argv.length); @@ -82,7 +86,7 @@ export class TabCompleteAction extends BaseRushAction { // } if (!commandLine || !caretPosition) { - yield* this._getAllActions(); + yield* Object.keys(actions); // return all actions return; } @@ -98,7 +102,7 @@ export class TabCompleteAction extends BaseRushAction { const debugParameterOffset: number = debugParameterUsed ? 1 : 0; // if debug switch is used, then offset everything by 1. if (commands.length < 2 + debugParameterOffset) { - yield* this._getAllActions(); + yield* Object.keys(actions); // return all actions return; } @@ -110,13 +114,13 @@ export class TabCompleteAction extends BaseRushAction { const completePartialWord: boolean = caretPosition === commandLine.length; if (completePartialWord && commands.length === 2 + debugParameterOffset) { - for (const actionName of Object.keys(TabCompleteAction._actions)) { + for (const actionName of Object.keys(actions)) { if (actionName.indexOf(commands[1 + debugParameterOffset]) === 0) { yield actionName; } } } else { - for (const actionName of Object.keys(TabCompleteAction._actions)) { + for (const actionName of Object.keys(actions)) { if (actionName === commands[1 + debugParameterOffset]) { if (actionName === 'build' || actionName === 'rebuild') { const choiceParameter: string[] = ['-f', '--from', '-t', '--to']; @@ -156,24 +160,24 @@ export class TabCompleteAction extends BaseRushAction { } if (completePartialWord) { - for (let i: number = 0; i < TabCompleteAction._actions[actionName].length; i++) { - if (TabCompleteAction._actions[actionName][i].name.indexOf(lastCommand) === 0) { - yield TabCompleteAction._actions[actionName][i].name; + for (let i: number = 0; i < actions[actionName].length; i++) { + if (actions[actionName][i].name.indexOf(lastCommand) === 0) { + yield actions[actionName][i].name; } } } else { - for (let i: number = 0; i < TabCompleteAction._actions[actionName].length; i++) { + for (let i: number = 0; i < actions[actionName].length; i++) { if ( - lastCommand === TabCompleteAction._actions[actionName][i].name && - TabCompleteAction._actions[actionName][i].kind !== CommandLineParameterKind.Flag + lastCommand === actions[actionName][i].name && + actions[actionName][i].kind !== CommandLineParameterKind.Flag ) { // The parameter is expecting a value, so don't suggest parameter names again return; } } - for (let i: number = 0; i < TabCompleteAction._actions[actionName].length; i++) { - yield TabCompleteAction._actions[actionName][i].name; + for (let i: number = 0; i < actions[actionName].length; i++) { + yield actions[actionName][i].name; } } } @@ -198,16 +202,8 @@ export class TabCompleteAction extends BaseRushAction { } } else { if (choiceParameter.indexOf(lastCommand) !== -1) { - for (let i: number = 0; i < choiceParamaterValues.length; i++) { - yield choiceParamaterValues[i]; - } + yield* choiceParamaterValues; } } } - - private *_getAllActions(): IterableIterator { - for (const actionName of Object.keys(TabCompleteAction._actions)) { - yield actionName; - } - } } From 98f91049aa98dbb404256eb984e7b16fb0d2e561 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Fri, 31 Jul 2020 10:35:55 -0700 Subject: [PATCH 25/97] Address David's comments. Add a new unit test --- .../src/cli/actions/TabCompleteAction.ts | 35 +++++++++---------- .../actions/test/TabCompleteAction.test.ts | 22 +++++++++--- 2 files changed, 35 insertions(+), 22 deletions(-) diff --git a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts index d55c700e3c4..0df554ba52a 100644 --- a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts +++ b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts @@ -18,10 +18,6 @@ interface IParameter { const DEFAULT_WORD_TO_AUTOCOMPLETE: string = ''; const DEFAULT_POSITION: number = 0; -interface IActionMap { - [actionName: string]: IParameter[]; -} - export class TabCompleteAction extends BaseRushAction { private _wordToCompleteParameter: CommandLineStringParameter; private _positionParameter: CommandLineIntegerParameter; @@ -62,7 +58,7 @@ export class TabCompleteAction extends BaseRushAction { } public *_getCompletions(commandLine: string, caretPosition: number): IterableIterator { - const actions: IActionMap = {}; + const actions: Map = new Map(); this.parser.actions.forEach((element) => { const actionParameters: IParameter[] = []; element.parameters.forEach((elem) => { @@ -159,12 +155,10 @@ export class TabCompleteAction extends BaseRushAction { ); } + const parameterNames: string[] = Array.from(actions[actionName], (x: IParameter) => x.name); + if (completePartialWord) { - for (let i: number = 0; i < actions[actionName].length; i++) { - if (actions[actionName][i].name.indexOf(lastCommand) === 0) { - yield actions[actionName][i].name; - } - } + yield* this._completeChoiceParameterValues(parameterNames, lastCommand); } else { for (let i: number = 0; i < actions[actionName].length; i++) { if ( @@ -176,9 +170,7 @@ export class TabCompleteAction extends BaseRushAction { } } - for (let i: number = 0; i < actions[actionName].length; i++) { - yield actions[actionName][i].name; - } + yield* parameterNames; } } } @@ -194,11 +186,7 @@ export class TabCompleteAction extends BaseRushAction { ): IterableIterator { if (completePartialWord) { if (choiceParameter.indexOf(secondLastCommand) !== -1) { - for (let i: number = 0; i < choiceParamaterValues.length; i++) { - if (choiceParamaterValues[i].indexOf(lastCommand) === 0) { - yield choiceParamaterValues[i]; - } - } + yield* this._completeChoiceParameterValues(choiceParamaterValues, lastCommand); } } else { if (choiceParameter.indexOf(lastCommand) !== -1) { @@ -206,4 +194,15 @@ export class TabCompleteAction extends BaseRushAction { } } } + + private *_completeChoiceParameterValues( + choiceParamaterValues: string[], + lastCommand: string + ): IterableIterator { + for (let i: number = 0; i < choiceParamaterValues.length; i++) { + if (choiceParamaterValues[i].indexOf(lastCommand) === 0) { + yield choiceParamaterValues[i]; + } + } + } } diff --git a/apps/rush-lib/src/cli/actions/test/TabCompleteAction.test.ts b/apps/rush-lib/src/cli/actions/test/TabCompleteAction.test.ts index 8ae37dbea65..963aedf4ca0 100644 --- a/apps/rush-lib/src/cli/actions/test/TabCompleteAction.test.ts +++ b/apps/rush-lib/src/cli/actions/test/TabCompleteAction.test.ts @@ -143,8 +143,6 @@ describe('TabCompleteAction', () => { const commandLine: string = 'rush build -t a'; const actual: string[] = Array.from(tc._getCompletions(commandLine.trim(), commandLine.length)); - console.log('Actual: ' + actual); - const expected: string[] = ['abc']; expect(arrayEqual(actual, expected)).toBe(true); @@ -179,11 +177,27 @@ describe('TabCompleteAction', () => { const commandLine: string = 'rush change --bump-type m'; const actual: string[] = Array.from(tc._getCompletions(commandLine.trim(), commandLine.length)); - console.log('Actual: ' + actual); - const expected: string[] = ['major', 'minor']; expect(arrayEqual(actual, expected)).toBe(true); }); + + it(`gets completion(s) for rush change --message `, () => { + const startPath: string = path.resolve(__dirname, 'tabComplete'); + // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit + // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test + // repo will fail due to contention over the same lock which is kept until the test runner process + // ends. + jest.spyOn(process, 'cwd').mockReturnValue(startPath); + const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); + const tc: TabCompleteAction = new TabCompleteAction(parser); + + const commandLine: string = 'rush change --message '; + const actual: string[] = Array.from(tc._getCompletions(commandLine.trim(), commandLine.length)); + + const expected: string[] = []; + + expect(arrayEqual(actual, expected)).toBe(true); + }); }); }); From fffb507971b1076675988327b2acc58a6dbfa3c6 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Fri, 31 Jul 2020 11:31:58 -0700 Subject: [PATCH 26/97] Some refactoring --- .../src/cli/actions/TabCompleteAction.ts | 78 ++++++++++--------- 1 file changed, 40 insertions(+), 38 deletions(-) diff --git a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts index 0df554ba52a..d6a671c305d 100644 --- a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts +++ b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts @@ -86,49 +86,50 @@ export class TabCompleteAction extends BaseRushAction { return; } - const commands: string[] = commandLine.split(' '); + const tokens: string[] = this._tokenizeCommandLine(commandLine); // yield ('commandLine: ' + commandLine); // yield ('commandLine.length: ' + commandLine.length); // yield ('caretPosition: ' + caretPosition); - // yield ('commands.length: ' + commands.length); + // yield ('tokens.length: ' + tokens.length); - const debugParameterUsed: boolean = - commands.length > 1 && (commands[1] === '-d' || commands[1] === '--debug'); + const debugParameterUsed: boolean = tokens.length > 1 && (tokens[1] === '-d' || tokens[1] === '--debug'); const debugParameterOffset: number = debugParameterUsed ? 1 : 0; // if debug switch is used, then offset everything by 1. - if (commands.length < 2 + debugParameterOffset) { + if (tokens.length < 2 + debugParameterOffset) { yield* Object.keys(actions); // return all actions return; } - const lastCommand: string = commands[commands.length - 1]; - const secondLastCommand: string = commands[commands.length - 2]; - // yield ('lastCommand: ' + lastCommand); - // yield ('secondLastCommand: ' + secondLastCommand); + const lastToken: string = tokens[tokens.length - 1]; + const secondLastToken: string = tokens[tokens.length - 2]; + // yield ('lastToken: ' + lastToken); + // yield ('secondLastToken: ' + secondLastToken); const completePartialWord: boolean = caretPosition === commandLine.length; - if (completePartialWord && commands.length === 2 + debugParameterOffset) { + if (completePartialWord && tokens.length === 2 + debugParameterOffset) { for (const actionName of Object.keys(actions)) { - if (actionName.indexOf(commands[1 + debugParameterOffset]) === 0) { + if (actionName.indexOf(tokens[1 + debugParameterOffset]) === 0) { yield actionName; } } } else { for (const actionName of Object.keys(actions)) { - if (actionName === commands[1 + debugParameterOffset]) { + if (actionName === tokens[1 + debugParameterOffset]) { if (actionName === 'build' || actionName === 'rebuild') { const choiceParameter: string[] = ['-f', '--from', '-t', '--to']; const choiceParameterValues: string[] = []; - for (let i: number = 0; i < this.rushConfiguration.projects.length; i++) { - choiceParameterValues.push(this.rushConfiguration.projects[i].packageName); + + for (const project of this.rushConfiguration.projects) { + choiceParameterValues.push(project.packageName); } + yield* this._getChoiceParameterValues( choiceParameter, choiceParameterValues, - lastCommand, - secondLastCommand, + lastToken, + secondLastToken, completePartialWord ); @@ -139,8 +140,8 @@ export class TabCompleteAction extends BaseRushAction { yield* this._getChoiceParameterValues( choiceParameter, choiceParameterValues, - lastCommand, - secondLastCommand, + lastToken, + secondLastToken, completePartialWord ); } else if (actionName === 'publish') { @@ -149,8 +150,8 @@ export class TabCompleteAction extends BaseRushAction { yield* this._getChoiceParameterValues( choiceParameter, choiceParameterValues, - lastCommand, - secondLastCommand, + lastToken, + secondLastToken, completePartialWord ); } @@ -158,13 +159,10 @@ export class TabCompleteAction extends BaseRushAction { const parameterNames: string[] = Array.from(actions[actionName], (x: IParameter) => x.name); if (completePartialWord) { - yield* this._completeChoiceParameterValues(parameterNames, lastCommand); + yield* this._completeChoiceParameterValues(parameterNames, lastToken); } else { - for (let i: number = 0; i < actions[actionName].length; i++) { - if ( - lastCommand === actions[actionName][i].name && - actions[actionName][i].kind !== CommandLineParameterKind.Flag - ) { + for (const parameter of actions[actionName]) { + if (parameter.name === lastToken && parameter.kind !== CommandLineParameterKind.Flag) { // The parameter is expecting a value, so don't suggest parameter names again return; } @@ -177,31 +175,35 @@ export class TabCompleteAction extends BaseRushAction { } } + private _tokenizeCommandLine(commandLine: string): string[] { + return commandLine.split(' '); + } + private *_getChoiceParameterValues( choiceParameter: string[], - choiceParamaterValues: string[], - lastCommand: string, - secondLastCommand: string, + choiceParameterValues: string[], + lastToken: string, + secondLastToken: string, completePartialWord: boolean ): IterableIterator { if (completePartialWord) { - if (choiceParameter.indexOf(secondLastCommand) !== -1) { - yield* this._completeChoiceParameterValues(choiceParamaterValues, lastCommand); + if (choiceParameter.indexOf(secondLastToken) !== -1) { + yield* this._completeChoiceParameterValues(choiceParameterValues, lastToken); } } else { - if (choiceParameter.indexOf(lastCommand) !== -1) { - yield* choiceParamaterValues; + if (choiceParameter.indexOf(lastToken) !== -1) { + yield* choiceParameterValues; } } } private *_completeChoiceParameterValues( - choiceParamaterValues: string[], - lastCommand: string + choiceParameterValues: string[], + lastToken: string ): IterableIterator { - for (let i: number = 0; i < choiceParamaterValues.length; i++) { - if (choiceParamaterValues[i].indexOf(lastCommand) === 0) { - yield choiceParamaterValues[i]; + for (const choiceParameterValue of choiceParameterValues) { + if (choiceParameterValue.indexOf(lastToken) === 0) { + yield choiceParameterValue; } } } From cde89aa02cc7cce6eb92b45e56f4481457753090 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Fri, 31 Jul 2020 17:42:34 -0700 Subject: [PATCH 27/97] Use importLazy to improve spin up times --- apps/rush-lib/package.json | 1 + .../src/api/ApprovedPackagesConfiguration.ts | 35 +++-- .../src/api/ApprovedPackagesPolicy.ts | 5 + .../src/api/CommonVersionsConfiguration.ts | 6 + apps/rush-lib/src/api/PackageJsonEditor.ts | 29 ++-- apps/rush-lib/src/api/PackageNameParsers.ts | 13 +- apps/rush-lib/src/api/Rush.ts | 22 ++- apps/rush-lib/src/api/RushConfiguration.ts | 133 ++++++++++++++++-- .../src/api/RushConfigurationProject.ts | 52 ++++--- .../src/api/VersionPolicyConfiguration.ts | 26 +++- .../rush-lib/src/cli/RushCommandLineParser.ts | 54 ++++++- apps/rush-lib/src/cli/actions/AddAction.ts | 9 ++ apps/rush-lib/src/cli/actions/ChangeAction.ts | 55 ++++++-- apps/rush-lib/src/cli/actions/DeployAction.ts | 5 + .../src/cli/actions/TabCompleteAction.ts | 4 + .../rush-lib/src/logic/DependencySpecifier.ts | 13 +- .../src/logic/InstallManagerFactory.ts | 10 ++ apps/rush-lib/src/logic/LinkManagerFactory.ts | 5 + apps/rush-lib/src/logic/PackageJsonUpdater.ts | 18 ++- apps/rush-lib/src/logic/RepoStateFile.ts | 27 ++-- apps/rush-lib/src/logic/VersionManager.ts | 2 +- .../src/logic/deploy/DeployArchiver.ts | 24 +++- .../src/logic/deploy/DeployManager.ts | 131 ++++++++++------- .../installManager/RushInstallManager.ts | 56 ++++++-- apps/rush-lib/src/logic/npm/NpmLinkManager.ts | 40 +++++- .../src/logic/pnpm/PnpmLinkManager.ts | 24 +++- apps/rush-lib/src/start.ts | 4 + apps/rush-lib/src/utilities/Utilities.ts | 54 ++++--- common/config/rush/pnpm-lock.yaml | 5 + common/config/rush/repo-state.json | 2 +- common/reviews/api/rush-lib.api.md | 7 +- common/reviews/api/ts-command-line.api.md | 4 +- libraries/node-core-library/package.json | 1 + libraries/node-core-library/src/JsonSchema.ts | 20 ++- libraries/ts-command-line/src/index.ts | 14 ++ .../src/providers/CommandLineAction.ts | 5 +- .../providers/CommandLineParameterProvider.ts | 10 ++ 37 files changed, 723 insertions(+), 202 deletions(-) diff --git a/apps/rush-lib/package.json b/apps/rush-lib/package.json index 01f950aff72..45212bf9957 100644 --- a/apps/rush-lib/package.json +++ b/apps/rush-lib/package.json @@ -32,6 +32,7 @@ "glob": "~7.0.5", "https-proxy-agent": "~2.2.1", "ignore": "~5.1.6", + "import-lazy": "~4.0.0", "inquirer": "~6.2.0", "js-yaml": "~3.13.1", "lodash": "~4.17.15", diff --git a/apps/rush-lib/src/api/ApprovedPackagesConfiguration.ts b/apps/rush-lib/src/api/ApprovedPackagesConfiguration.ts index c3c3b23e0ba..9b09cb57612 100644 --- a/apps/rush-lib/src/api/ApprovedPackagesConfiguration.ts +++ b/apps/rush-lib/src/api/ApprovedPackagesConfiguration.ts @@ -1,12 +1,23 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +// eslint-disable-next-line +const importLazy = require('import-lazy')(require); + +console.log('ApprovedPackagesConfiguration.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as path from 'path'; +console.log('ApprovedPackagesConfiguration.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as os from 'os'; -import { JsonFile, JsonSchema, FileSystem, NewlineKind, InternalError } from '@rushstack/node-core-library'; +console.log('ApprovedPackagesConfiguration.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); +// import { JsonFile, JsonSchema, FileSystem, NewlineKind, InternalError } from '@rushstack/node-core-library'; +// eslint-disable-next-line +const nodeCoreLibrary = importLazy('@rushstack/node-core-library'); +console.log('ApprovedPackagesConfiguration.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { Utilities } from '../utilities/Utilities'; +console.log('ApprovedPackagesConfiguration.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import { JsonSchemaUrls } from '../logic/JsonSchemaUrls'; +console.log('ApprovedPackagesConfiguration.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); /** * Part of IApprovedPackagesJson. @@ -47,9 +58,12 @@ export class ApprovedPackagesItem { * @public */ export class ApprovedPackagesConfiguration { - private static _jsonSchema: JsonSchema = JsonSchema.fromFile( - path.join(__dirname, '../schemas/approved-packages.schema.json') - ); + // eslint-disable-next-line + private static get _jsonSchema() { + return nodeCoreLibrary.JsonSchema.fromFile( + path.join(__dirname, '../schemas/approved-packages.schema.json') + ); + } public items: ApprovedPackagesItem[] = []; @@ -102,7 +116,8 @@ export class ApprovedPackagesConfiguration { * If the file exists, calls loadFromFile(). */ public tryLoadFromFile(approvedPackagesPolicyEnabled: boolean): boolean { - if (!FileSystem.exists(this._jsonFilename)) { + // eslint-disable-next-line + if (!nodeCoreLibrary.FileSystem.exists(this._jsonFilename)) { return false; } @@ -122,7 +137,7 @@ export class ApprovedPackagesConfiguration { * Loads the configuration data from the filename that was passed to the constructor. */ public loadFromFile(): void { - const approvedPackagesJson: IApprovedPackagesJson = JsonFile.loadAndValidate( + const approvedPackagesJson: IApprovedPackagesJson = nodeCoreLibrary.JsonFile.loadAndValidate( this._jsonFilename, ApprovedPackagesConfiguration._jsonSchema ); @@ -164,7 +179,7 @@ export class ApprovedPackagesConfiguration { } // Save the file - let body: string = JsonFile.stringify(this._loadedJson); + let body: string = nodeCoreLibrary.JsonFile.stringify(this._loadedJson); // Unindent the allowedCategories array to improve readability body = body.replace(/("allowedCategories": +\[)([^\]]+)/g, (substring: string, ...args: string[]) => { @@ -174,8 +189,8 @@ export class ApprovedPackagesConfiguration { // Add a header body = '// DO NOT ADD COMMENTS IN THIS FILE. They will be lost when the Rush tool resaves it.\n' + body; - FileSystem.writeFile(this._jsonFilename, body, { - convertLineEndings: NewlineKind.CrLf + nodeCoreLibrary.FileSystem.writeFile(this._jsonFilename, body, { + convertLineEndings: nodeCoreLibrary.NewlineKind.CrLf }); } @@ -207,7 +222,7 @@ export class ApprovedPackagesConfiguration { */ private _addItem(item: ApprovedPackagesItem): void { if (this._itemsByName.has(item.packageName)) { - throw new InternalError('Duplicate key'); + throw new nodeCoreLibrary.InternalError('Duplicate key'); } this.items.push(item); this._itemsByName.set(item.packageName, item); diff --git a/apps/rush-lib/src/api/ApprovedPackagesPolicy.ts b/apps/rush-lib/src/api/ApprovedPackagesPolicy.ts index 852bc315247..a0bcc2e4e3b 100644 --- a/apps/rush-lib/src/api/ApprovedPackagesPolicy.ts +++ b/apps/rush-lib/src/api/ApprovedPackagesPolicy.ts @@ -1,11 +1,16 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +console.log('ApprovedPackagesPolicy.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as path from 'path'; +console.log('ApprovedPackagesPolicy.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import { ApprovedPackagesConfiguration } from './ApprovedPackagesConfiguration'; +console.log('ApprovedPackagesPolicy.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConstants } from '../logic/RushConstants'; +console.log('ApprovedPackagesPolicy.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfiguration, IRushConfigurationJson, IApprovedPackagesPolicyJson } from './RushConfiguration'; +console.log('ApprovedPackagesPolicy.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); /** * This is a helper object for RushConfiguration. diff --git a/apps/rush-lib/src/api/CommonVersionsConfiguration.ts b/apps/rush-lib/src/api/CommonVersionsConfiguration.ts index 90514feacec..48b7c618a95 100644 --- a/apps/rush-lib/src/api/CommonVersionsConfiguration.ts +++ b/apps/rush-lib/src/api/CommonVersionsConfiguration.ts @@ -1,8 +1,11 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +console.log('CommonVersionsConfiguration.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as crypto from 'crypto'; +console.log('CommonVersionsConfiguration.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as path from 'path'; +console.log('CommonVersionsConfiguration.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import { JsonFile, JsonSchema, @@ -11,8 +14,11 @@ import { FileSystem, Sort } from '@rushstack/node-core-library'; +console.log('CommonVersionsConfiguration.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { PackageNameParsers } from './PackageNameParsers'; +console.log('CommonVersionsConfiguration.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import { JsonSchemaUrls } from '../logic/JsonSchemaUrls'; +console.log('CommonVersionsConfiguration.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); /** * Part of the ICommonVersionsJson structure. diff --git a/apps/rush-lib/src/api/PackageJsonEditor.ts b/apps/rush-lib/src/api/PackageJsonEditor.ts index a6a5c82e5fc..3a626fc9f78 100644 --- a/apps/rush-lib/src/api/PackageJsonEditor.ts +++ b/apps/rush-lib/src/api/PackageJsonEditor.ts @@ -1,9 +1,17 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +// eslint-disable-next-line +const importLazy = require('import-lazy')(require); + +console.log('PackageJsonEditor.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as semver from 'semver'; +console.log('PackageJsonEditor.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); -import { IPackageJson, JsonFile, Sort } from '@rushstack/node-core-library'; +// import { IPackageJson, JsonFile, Sort } from '@rushstack/node-core-library'; +// eslint-disable-next-line +const nodeCoreLibrary = importLazy('@rushstack/node-core-library'); +console.log('PackageJsonEditor.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); /** * @beta @@ -57,7 +65,7 @@ export class PackageJsonDependency { */ export class PackageJsonEditor { private readonly _filePath: string; - private readonly _data: IPackageJson; + private readonly _data; private readonly _dependencies: Map; // NOTE: The "devDependencies" section is tracked separately because sometimes people @@ -67,7 +75,8 @@ export class PackageJsonEditor { private readonly _devDependencies: Map; private _modified: boolean; - private constructor(filepath: string, data: IPackageJson) { + // eslint-disable-next-line + private constructor(filepath: string, data /* IPackageJson */) { this._filePath = filepath; this._data = data; this._modified = false; @@ -140,18 +149,19 @@ export class PackageJsonEditor { ); }); - Sort.sortMapKeys(this._dependencies); - Sort.sortMapKeys(this._devDependencies); + nodeCoreLibrary.Sort.sortMapKeys(this._dependencies); + nodeCoreLibrary.Sort.sortMapKeys(this._devDependencies); } catch (e) { throw new Error(`Error loading "${filepath}": ${e.message}`); } } public static load(filePath: string): PackageJsonEditor { - return new PackageJsonEditor(filePath, JsonFile.load(filePath)); + return new PackageJsonEditor(filePath, nodeCoreLibrary.JsonFile.load(filePath)); } - public static fromObject(object: IPackageJson, filename: string): PackageJsonEditor { + // eslint-disable-next-line + public static fromObject(object /* IPackageJson */, filename: string): PackageJsonEditor { return new PackageJsonEditor(filename, object); } @@ -217,7 +227,7 @@ export class PackageJsonEditor { public saveIfModified(): boolean { if (this._modified) { - JsonFile.save(this._normalize(), this._filePath, { updateExistingFile: true }); + nodeCoreLibrary.JsonFile.save(this._normalize(), this._filePath, { updateExistingFile: true }); this._modified = false; return true; } @@ -228,7 +238,8 @@ export class PackageJsonEditor { this._modified = true; } - private _normalize(): IPackageJson { + // eslint-disable-next-line + private _normalize() /* IPackageJson */ { delete this._data.dependencies; delete this._data.optionalDependencies; delete this._data.peerDependencies; diff --git a/apps/rush-lib/src/api/PackageNameParsers.ts b/apps/rush-lib/src/api/PackageNameParsers.ts index a248c0f4882..8409fc4d485 100644 --- a/apps/rush-lib/src/api/PackageNameParsers.ts +++ b/apps/rush-lib/src/api/PackageNameParsers.ts @@ -1,19 +1,24 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import { PackageNameParser } from '@rushstack/node-core-library'; +// eslint-disable-next-line +const importLazy = require('import-lazy')(require); + +// import { PackageNameParser } from '@rushstack/node-core-library'; +// eslint-disable-next-line +const nodeCoreLibrary = importLazy('@rushstack/node-core-library/lib/PackageName'); export class PackageNameParsers { /** * This is the default for `RushConfiguration.packageNameParser`. */ - public static rushDefault: PackageNameParser = new PackageNameParser({}); + public static rushDefault /*: PackageNameParser*/ = new nodeCoreLibrary.PackageNameParser({}); /** * This is the `RushConfiguration.packageNameParser` used when `allowMostlyStandardPackageNames = true` * in rush.json. */ - public static mostlyStandard: PackageNameParser = new PackageNameParser({ + public static mostlyStandard /*: PackageNameParser*/ = new nodeCoreLibrary.PackageNameParser({ allowUpperCase: true }); @@ -21,5 +26,5 @@ export class PackageNameParsers { * Use this in contexts where we don't have easy access to `RushConfiguration.packageNameParser` * AND the package name was already validated at some earlier stage. */ - public static permissive: PackageNameParser = PackageNameParsers.mostlyStandard; + public static permissive /*: PackageNameParser*/ = PackageNameParsers.mostlyStandard; } diff --git a/apps/rush-lib/src/api/Rush.ts b/apps/rush-lib/src/api/Rush.ts index 66f1da977b4..d15a8ff4a8f 100644 --- a/apps/rush-lib/src/api/Rush.ts +++ b/apps/rush-lib/src/api/Rush.ts @@ -1,16 +1,31 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +// eslint-disable-next-line +const importLazy = require('import-lazy')(require); + +console.log('Rush.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import { EOL } from 'os'; +console.log('Rush.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as colors from 'colors'; -import { PackageJsonLookup } from '@rushstack/node-core-library'; +console.log('Rush.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); +// import { PackageJsonLookup } from '@rushstack/node-core-library'; +// eslint-disable-next-line +const nodeCoreLibrary = importLazy('@rushstack/node-core-library'); +console.log('Rush.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { RushCommandLineParser } from '../cli/RushCommandLineParser'; +console.log('Rush.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConstants } from '../logic/RushConstants'; +console.log('Rush.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); import { RushXCommandLine } from '../cli/RushXCommandLine'; +console.log('Rush.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); import { CommandLineMigrationAdvisor } from '../cli/CommandLineMigrationAdvisor'; +console.log('Rush.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); import { NodeJsCompatibility } from '../logic/NodeJsCompatibility'; +console.log('Rush.ts : 9: ' + (new Date().getTime() % 20000) / 1000.0); import { Utilities } from '../utilities/Utilities'; +console.log('Rush.ts : 10: ' + (new Date().getTime() % 20000) / 1000.0); /** * Options to pass to the rush "launch" functions. @@ -52,6 +67,7 @@ export class Rush { * Even though this API isn't documented, it is still supported for legacy compatibility. */ public static launch(launcherVersion: string, arg: ILaunchOptions): void { + console.log('Rush.launch : 1: ' + (new Date().getTime() % 20000) / 1000.0); const options: ILaunchOptions = Rush._normalizeLaunchOptions(arg); if (!Utilities.isNonDebugTabCompletionRequest()) { @@ -67,7 +83,9 @@ export class Rush { const parser: RushCommandLineParser = new RushCommandLineParser({ alreadyReportedNodeTooNewError: options.alreadyReportedNodeTooNewError }); + console.log('Rush.launch : 2: ' + (new Date().getTime() % 20000) / 1000.0); parser.execute().catch(console.error); // CommandLineParser.execute() should never reject the promise + console.log('Rush.launch : 3: ' + (new Date().getTime() % 20000) / 1000.0); } /** @@ -90,7 +108,7 @@ export class Rush { * This is the same as the Rush tool version for that release. */ public static get version(): string { - return PackageJsonLookup.loadOwnPackageJson(__dirname).version; + return nodeCoreLibrary.PackageJsonLookup.loadOwnPackageJson(__dirname).version; } /** diff --git a/apps/rush-lib/src/api/RushConfiguration.ts b/apps/rush-lib/src/api/RushConfiguration.ts index 7bba6081c31..57a8d085811 100644 --- a/apps/rush-lib/src/api/RushConfiguration.ts +++ b/apps/rush-lib/src/api/RushConfiguration.ts @@ -3,28 +3,57 @@ /* eslint max-lines: off */ +// eslint-disable-next-line +const importLazy = require('import-lazy')(require); + +console.log('RushConfiguration.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as path from 'path'; +console.log('RushConfiguration.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as fs from 'fs'; -import * as semver from 'semver'; -import { JsonFile, JsonSchema, Path, FileSystem, PackageNameParser } from '@rushstack/node-core-library'; +console.log('RushConfiguration.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); +// eslint-disable-next-line +const semver = importLazy('semver'); +console.log('RushConfiguration.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); +// import { JsonFile, JsonSchema, Path, FileSystem, PackageNameParser } from '@rushstack/node-core-library'; +// eslint-disable-next-line +const nodeCoreLibrary = importLazy('@rushstack/node-core-library'); + +console.log('RushConfiguration.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import { trueCasePathSync } from 'true-case-path'; +console.log('RushConfiguration.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); import { Rush } from '../api/Rush'; +console.log('RushConfiguration.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfigurationProject, IRushConfigurationProjectJson } from './RushConfigurationProject'; +console.log('RushConfiguration.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConstants } from '../logic/RushConstants'; +console.log('RushConfiguration.ts : 9: ' + (new Date().getTime() % 20000) / 1000.0); import { ApprovedPackagesPolicy } from './ApprovedPackagesPolicy'; +console.log('RushConfiguration.ts : 10: ' + (new Date().getTime() % 20000) / 1000.0); import { EventHooks } from './EventHooks'; +console.log('RushConfiguration.ts : 11: ' + (new Date().getTime() % 20000) / 1000.0); import { VersionPolicyConfiguration } from './VersionPolicyConfiguration'; +console.log('RushConfiguration.ts : 12: ' + (new Date().getTime() % 20000) / 1000.0); import { EnvironmentConfiguration } from './EnvironmentConfiguration'; +console.log('RushConfiguration.ts : 13: ' + (new Date().getTime() % 20000) / 1000.0); import { CommonVersionsConfiguration } from './CommonVersionsConfiguration'; +console.log('RushConfiguration.ts : 14: ' + (new Date().getTime() % 20000) / 1000.0); import { Utilities } from '../utilities/Utilities'; +console.log('RushConfiguration.ts : 15: ' + (new Date().getTime() % 20000) / 1000.0); import { PackageManagerName, PackageManager } from './packageManager/PackageManager'; +console.log('RushConfiguration.ts : 16: ' + (new Date().getTime() % 20000) / 1000.0); import { NpmPackageManager } from './packageManager/NpmPackageManager'; +console.log('RushConfiguration.ts : 17: ' + (new Date().getTime() % 20000) / 1000.0); import { YarnPackageManager } from './packageManager/YarnPackageManager'; +console.log('RushConfiguration.ts : 18: ' + (new Date().getTime() % 20000) / 1000.0); import { PnpmPackageManager } from './packageManager/PnpmPackageManager'; +console.log('RushConfiguration.ts : 19: ' + (new Date().getTime() % 20000) / 1000.0); import { ExperimentsConfiguration } from './ExperimentsConfiguration'; +console.log('RushConfiguration.ts : 20: ' + (new Date().getTime() % 20000) / 1000.0); import { PackageNameParsers } from './PackageNameParsers'; +console.log('RushConfiguration.ts : 21: ' + (new Date().getTime() % 20000) / 1000.0); import { RepoStateFile } from '../logic/RepoStateFile'; +console.log('RushConfiguration.ts : 22: ' + (new Date().getTime() % 20000) / 1000.0); const MINIMUM_SUPPORTED_RUSH_JSON_VERSION: string = '0.0.0'; const DEFAULT_BRANCH: string = 'master'; @@ -423,7 +452,8 @@ export type ResolutionStrategy = 'fewer-dependencies' | 'fast'; * @public */ export class RushConfiguration { - private static _jsonSchema: JsonSchema = JsonSchema.fromFile( + // eslint-disable-next-line + private static _jsonSchema = nodeCoreLibrary.JsonSchema.fromFile( path.join(__dirname, '../schemas/rush.schema.json') ); @@ -478,7 +508,7 @@ export class RushConfiguration { // Rush hooks private _eventHooks: EventHooks; - private readonly _packageNameParser: PackageNameParser; + private readonly _packageNameParser: any; private _telemetryEnabled: boolean; @@ -493,21 +523,29 @@ export class RushConfiguration { * instead. */ private constructor(rushConfigurationJson: IRushConfigurationJson, rushJsonFilename: string) { + console.log('RushConfiguration.constructor() : 1: ' + (new Date().getTime() % 20000) / 1000.0); EnvironmentConfiguration.initialize(); + console.log('RushConfiguration.constructor() : 2: ' + (new Date().getTime() % 20000) / 1000.0); if (rushConfigurationJson.nodeSupportedVersionRange) { + console.log('RushConfiguration.constructor() : 3: ' + (new Date().getTime() % 20000) / 1000.0); if (!semver.validRange(rushConfigurationJson.nodeSupportedVersionRange)) { + console.log('RushConfiguration.constructor() : 4: ' + (new Date().getTime() % 20000) / 1000.0); throw new Error( 'Error parsing the node-semver expression in the "nodeSupportedVersionRange"' + ` field from rush.json: "${rushConfigurationJson.nodeSupportedVersionRange}"` ); } + console.log('RushConfiguration.constructor() : 5: ' + (new Date().getTime() % 20000) / 1000.0); if (!semver.satisfies(process.version, rushConfigurationJson.nodeSupportedVersionRange)) { + console.log('RushConfiguration.constructor() : 6: ' + (new Date().getTime() % 20000) / 1000.0); const message: string = `Your dev environment is running Node.js version ${process.version} which does` + ` not meet the requirements for building this repository. (The rush.json configuration` + ` requires nodeSupportedVersionRange="${rushConfigurationJson.nodeSupportedVersionRange}")`; + console.log('RushConfiguration.constructor() : 7: ' + (new Date().getTime() % 20000) / 1000.0); if (EnvironmentConfiguration.allowUnsupportedNodeVersion) { + console.log('RushConfiguration.constructor() : 8: ' + (new Date().getTime() % 20000) / 1000.0); console.warn(message); } else { throw new Error(message); @@ -515,43 +553,62 @@ export class RushConfiguration { } } + console.log('RushConfiguration.constructor() : 9: ' + (new Date().getTime() % 20000) / 1000.0); this._rushJsonFile = rushJsonFilename; + console.log('RushConfiguration.constructor() : 10: ' + (new Date().getTime() % 20000) / 1000.0); this._rushJsonFolder = path.dirname(rushJsonFilename); + console.log('RushConfiguration.constructor() : 11: ' + (new Date().getTime() % 20000) / 1000.0); this._commonFolder = path.resolve(path.join(this._rushJsonFolder, RushConstants.commonFolderName)); + console.log('RushConfiguration.constructor() : 12: ' + (new Date().getTime() % 20000) / 1000.0); this._commonRushConfigFolder = path.join(this._commonFolder, 'config', 'rush'); + console.log('RushConfiguration.constructor() : 13: ' + (new Date().getTime() % 20000) / 1000.0); this._commonTempFolder = EnvironmentConfiguration.rushTempFolderOverride || path.join(this._commonFolder, RushConstants.rushTempFolderName); + console.log('RushConfiguration.constructor() : 14: ' + (new Date().getTime() % 20000) / 1000.0); this._commonScriptsFolder = path.join(this._commonFolder, 'scripts'); + console.log('RushConfiguration.constructor() : 15: ' + (new Date().getTime() % 20000) / 1000.0); this._npmCacheFolder = path.resolve(path.join(this._commonTempFolder, 'npm-cache')); + console.log('RushConfiguration.constructor() : 16: ' + (new Date().getTime() % 20000) / 1000.0); this._npmTmpFolder = path.resolve(path.join(this._commonTempFolder, 'npm-tmp')); + console.log('RushConfiguration.constructor() : 17: ' + (new Date().getTime() % 20000) / 1000.0); this._yarnCacheFolder = path.resolve(path.join(this._commonTempFolder, 'yarn-cache')); + console.log('RushConfiguration.constructor() : 18: ' + (new Date().getTime() % 20000) / 1000.0); this._changesFolder = path.join(this._commonFolder, RushConstants.changeFilesFolderName); + console.log('RushConfiguration.constructor() : 19: ' + (new Date().getTime() % 20000) / 1000.0); this._currentVariantJsonFilename = path.join(this._commonTempFolder, 'current-variant.json'); + console.log('RushConfiguration.constructor() : 20: ' + (new Date().getTime() % 20000) / 1000.0); this._suppressNodeLtsWarning = !!rushConfigurationJson.suppressNodeLtsWarning; + console.log('RushConfiguration.constructor() : 21: ' + (new Date().getTime() % 20000) / 1000.0); this._ensureConsistentVersions = !!rushConfigurationJson.ensureConsistentVersions; + console.log('RushConfiguration.constructor() : 22: ' + (new Date().getTime() % 20000) / 1000.0); const experimentsConfigFile: string = path.join( this._commonRushConfigFolder, RushConstants.experimentsFilename ); + console.log('RushConfiguration.constructor() : 23: ' + (new Date().getTime() % 20000) / 1000.0); this._experimentsConfiguration = new ExperimentsConfiguration(experimentsConfigFile); + console.log('RushConfiguration.constructor() : 24: ' + (new Date().getTime() % 20000) / 1000.0); this._npmOptions = new NpmOptionsConfiguration(rushConfigurationJson.npmOptions || {}); + console.log('RushConfiguration.constructor() : 25: ' + (new Date().getTime() % 20000) / 1000.0); this._pnpmOptions = new PnpmOptionsConfiguration( rushConfigurationJson.pnpmOptions || {}, this._commonTempFolder ); + console.log('RushConfiguration.constructor() : 26: ' + (new Date().getTime() % 20000) / 1000.0); this._yarnOptions = new YarnOptionsConfiguration(rushConfigurationJson.yarnOptions || {}); + console.log('RushConfiguration.constructor() : 27: ' + (new Date().getTime() % 20000) / 1000.0); // TODO: Add an actual "packageManager" field in rush.json const packageManagerFields: string[] = []; @@ -590,7 +647,9 @@ export class RushConfiguration { this._packageManagerWrapper = new NpmPackageManager(this._packageManagerToolVersion); } else if (this._packageManager === 'pnpm') { this._packageManagerToolVersion = rushConfigurationJson.pnpmVersion!; + console.log('RushConfiguration.constructor() : 28: ' + (new Date().getTime() % 20000) / 1000.0); this._packageManagerWrapper = new PnpmPackageManager(this._packageManagerToolVersion); + console.log('RushConfiguration.constructor() : 29: ' + (new Date().getTime() % 20000) / 1000.0); } else { this._packageManagerToolVersion = rushConfigurationJson.yarnVersion!; this._packageManagerWrapper = new YarnPackageManager(this._packageManagerToolVersion); @@ -616,11 +675,13 @@ export class RushConfiguration { parsedPath.name + '-preinstall' + parsedPath.ext ); + console.log('RushConfiguration.constructor() : 30: ' + (new Date().getTime() % 20000) / 1000.0); RushConfiguration._validateCommonRushConfigFolder( this._commonRushConfigFolder, this.packageManager, this._shrinkwrapFilename ); + console.log('RushConfiguration.constructor() : 31: ' + (new Date().getTime() % 20000) / 1000.0); this._projectFolderMinDepth = rushConfigurationJson.projectFolderMinDepth !== undefined @@ -643,7 +704,9 @@ export class RushConfiguration { ? PackageNameParsers.mostlyStandard : PackageNameParsers.rushDefault; + console.log('RushConfiguration.constructor() : 32: ' + (new Date().getTime() % 20000) / 1000.0); this._approvedPackagesPolicy = new ApprovedPackagesPolicy(this, rushConfigurationJson); + console.log('RushConfiguration.constructor() : 33: ' + (new Date().getTime() % 20000) / 1000.0); this._gitAllowedEmailRegExps = []; this._gitSampleEmail = ''; @@ -766,13 +829,31 @@ export class RushConfiguration { * an RushConfiguration object. */ public static loadFromConfigurationFile(rushJsonFilename: string): RushConfiguration { + console.log( + 'RushConfiguration.loadFromConfigurationFile() : 1: ' + (new Date().getTime() % 20000) / 1000.0 + ); let resolvedRushJsonFilename: string = path.resolve(rushJsonFilename); + // Load the rush.json before we fix the casing. If the case is wrong on a case-sensitive filesystem, // the next line show throw. - const rushConfigurationJson: IRushConfigurationJson = JsonFile.load(resolvedRushJsonFilename); + console.log( + 'RushConfiguration.loadFromConfigurationFile() : 2: ' + (new Date().getTime() % 20000) / 1000.0 + ); + const rushConfigurationJson: IRushConfigurationJson = nodeCoreLibrary.JsonFile.load( + resolvedRushJsonFilename + ); + console.log( + 'RushConfiguration.loadFromConfigurationFile() : 3: ' + (new Date().getTime() % 20000) / 1000.0 + ); try { + console.log( + 'RushConfiguration.loadFromConfigurationFile() : 4: ' + (new Date().getTime() % 20000) / 1000.0 + ); resolvedRushJsonFilename = trueCasePathSync(resolvedRushJsonFilename); + console.log( + 'RushConfiguration.loadFromConfigurationFile() : 5: ' + (new Date().getTime() % 20000) / 1000.0 + ); } catch (error) { /* ignore errors from true-case-path */ } @@ -782,11 +863,17 @@ export class RushConfiguration { // but we'll validate anyway. const expectedRushVersion: string = rushConfigurationJson.rushVersion; + console.log( + 'RushConfiguration.loadFromConfigurationFile() : 6: ' + (new Date().getTime() % 20000) / 1000.0 + ); const rushJsonBaseName: string = path.basename(resolvedRushJsonFilename); // If the version is missing or malformed, fall through and let the schema handle it. if (expectedRushVersion && semver.valid(expectedRushVersion)) { // Make sure the requested version isn't too old + console.log( + 'RushConfiguration.loadFromConfigurationFile() : 7: ' + (new Date().getTime() % 20000) / 1000.0 + ); if (semver.lt(expectedRushVersion, MINIMUM_SUPPORTED_RUSH_JSON_VERSION)) { throw new Error( `${rushJsonBaseName} is version ${expectedRushVersion}, which is too old for this tool. ` + @@ -801,11 +888,17 @@ export class RushConfiguration { // // IMPORTANT: Whenever a breaking change is introduced for one of the config files, we must // increment the minor version number for Rush. + console.log( + 'RushConfiguration.loadFromConfigurationFile() : 8: ' + (new Date().getTime() % 20000) / 1000.0 + ); if ( semver.major(Rush.version) !== semver.major(expectedRushVersion) || semver.minor(Rush.version) !== semver.minor(expectedRushVersion) ) { // If the major/minor are different, then make sure it's an older version. + console.log( + 'RushConfiguration.loadFromConfigurationFile() : 9: ' + (new Date().getTime() % 20000) / 1000.0 + ); if (semver.lt(Rush.version, expectedRushVersion)) { throw new Error( `Unable to load ${rushJsonBaseName} because its RushVersion is` + @@ -816,8 +909,14 @@ export class RushConfiguration { } } + console.log( + 'RushConfiguration.loadFromConfigurationFile() : 10: ' + (new Date().getTime() % 20000) / 1000.0 + ); RushConfiguration._jsonSchema.validateObject(rushConfigurationJson, resolvedRushJsonFilename); + console.log( + 'RushConfiguration.loadFromConfigurationFile() : 11: ' + (new Date().getTime() % 20000) / 1000.0 + ); return new RushConfiguration(rushConfigurationJson, resolvedRushJsonFilename); } @@ -843,7 +942,7 @@ export class RushConfiguration { for (let i: number = 0; i < 10; ++i) { const rushJsonFilename: string = path.join(currentFolder, 'rush.json'); - if (FileSystem.exists(rushJsonFilename)) { + if (nodeCoreLibrary.FileSystem.exists(rushJsonFilename)) { if (i > 0 && verbose) { console.log('Found configuration in ' + rushJsonFilename); } @@ -912,15 +1011,17 @@ export class RushConfiguration { packageManager: PackageManagerName, shrinkwrapFilename: string ): void { - if (!FileSystem.exists(commonRushConfigFolder)) { + if (!nodeCoreLibrary.FileSystem.exists(commonRushConfigFolder)) { console.log(`Creating folder: ${commonRushConfigFolder}`); - FileSystem.ensureFolder(commonRushConfigFolder); + nodeCoreLibrary.FileSystem.ensureFolder(commonRushConfigFolder); return; } - for (const filename of FileSystem.readFolder(commonRushConfigFolder)) { + for (const filename of nodeCoreLibrary.FileSystem.readFolder(commonRushConfigFolder)) { // Ignore things that aren't actual files - const stat: fs.Stats = FileSystem.getLinkStatistics(path.join(commonRushConfigFolder, filename)); + const stat: fs.Stats = nodeCoreLibrary.FileSystem.getLinkStatistics( + path.join(commonRushConfigFolder, filename) + ); if (!stat.isFile() && !stat.isSymbolicLink()) { continue; } @@ -959,7 +1060,7 @@ export class RushConfiguration { commonRushConfigFolder, RushConstants.pinnedVersionsFilename ); - if (FileSystem.exists(pinnedVersionsFilename)) { + if (nodeCoreLibrary.FileSystem.exists(pinnedVersionsFilename)) { throw new Error( 'The "pinned-versions.json" config file is no longer supported;' + ' please move your settings to the "preferredVersions" field of a "common-versions.json" config file.' + @@ -1397,8 +1498,10 @@ export class RushConfiguration { public get currentInstalledVariant(): string | undefined { let variant: string | undefined; - if (FileSystem.exists(this._currentVariantJsonFilename)) { - const currentVariantJson: ICurrentVariantJson = JsonFile.load(this._currentVariantJsonFilename); + if (nodeCoreLibrary.FileSystem.exists(this._currentVariantJsonFilename)) { + const currentVariantJson: ICurrentVariantJson = nodeCoreLibrary.JsonFile.load( + this._currentVariantJsonFilename + ); variant = currentVariantJson.variant || undefined; } @@ -1417,7 +1520,7 @@ export class RushConfiguration { /** * The rush hooks. It allows customized scripts to run at the specified point. */ - public get packageNameParser(): PackageNameParser { + public get packageNameParser(): any { return this._packageNameParser; } @@ -1572,7 +1675,7 @@ export class RushConfiguration { public tryGetProjectForPath(currentFolderPath: string): RushConfigurationProject | undefined { const resolvedPath: string = path.resolve(currentFolderPath); for (const project of this.projects) { - if (Path.isUnderOrEqual(resolvedPath, project.projectFolder)) { + if (nodeCoreLibrary.Path.isUnderOrEqual(resolvedPath, project.projectFolder)) { return project; } } diff --git a/apps/rush-lib/src/api/RushConfigurationProject.ts b/apps/rush-lib/src/api/RushConfigurationProject.ts index 898d1cc2cd5..d04933a9714 100644 --- a/apps/rush-lib/src/api/RushConfigurationProject.ts +++ b/apps/rush-lib/src/api/RushConfigurationProject.ts @@ -1,22 +1,40 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +// eslint-disable-next-line +const importLazy = require('import-lazy')(require); + +console.log('RushConfigurationProject.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as path from 'path'; +console.log('RushConfigurationProject.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as semver from 'semver'; -import { - JsonFile, - IPackageJson, - FileSystem, - FileConstants, - IPackageJsonDependencyTable -} from '@rushstack/node-core-library'; +console.log('RushConfigurationProject.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); + +// import { +// JsonFile, +// IPackageJson, +// FileSystem, +// FileConstants, +// IPackageJsonDependencyTable +// } from '@rushstack/node-core-library'; +// eslint-disable-next-line +const nodeCoreLibrary = importLazy('@rushstack/node-core-library'); +console.log('RushConfigurationProject.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfiguration } from '../api/RushConfiguration'; +console.log('RushConfigurationProject.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import { VersionPolicy, LockStepVersionPolicy } from './VersionPolicy'; +console.log('RushConfigurationProject.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); import { PackageJsonEditor } from './PackageJsonEditor'; +console.log('RushConfigurationProject.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConstants } from '../logic/RushConstants'; +console.log('RushConfigurationProject.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); import { PackageNameParsers } from './PackageNameParsers'; +console.log('RushConfigurationProject.ts : 9: ' + (new Date().getTime() % 20000) / 1000.0); import { DependencySpecifier, DependencySpecifierType } from '../logic/DependencySpecifier'; +// eslint-disable-next-line +// const depSpecifier = importLazy('../logic/DependencySpecifier'); +console.log('RushConfigurationProject.ts : 10: ' + (new Date().getTime() % 20000) / 1000.0); /** * This represents the JSON data object for a project entry in the rush.json configuration file. @@ -42,7 +60,7 @@ export class RushConfigurationProject { private _projectRelativeFolder: string; private _projectRushTempFolder: string; private _reviewCategory: string; - private _packageJson: IPackageJson; + private _packageJson: any; private _packageJsonEditor: PackageJsonEditor; private _tempProjectName: string; private _unscopedTempProjectName: string; @@ -84,7 +102,7 @@ export class RushConfigurationProject { this._projectFolder = path.join(rushConfiguration.rushJsonFolder, projectJson.projectFolder); - if (!FileSystem.exists(this._projectFolder)) { + if (!nodeCoreLibrary.FileSystem.exists(this._projectFolder)) { throw new Error(`Project folder not found: ${projectJson.projectFolder}`); } @@ -113,8 +131,8 @@ export class RushConfigurationProject { this._reviewCategory = projectJson.reviewCategory; } - const packageJsonFilename: string = path.join(this._projectFolder, FileConstants.PackageJson); - this._packageJson = JsonFile.load(packageJsonFilename); + const packageJsonFilename: string = path.join(this._projectFolder, 'package.json'); + this._packageJson = nodeCoreLibrary.JsonFile.load(packageJsonFilename); if (this._packageJson.name !== this._packageName) { throw new Error( @@ -232,7 +250,7 @@ export class RushConfigurationProject { * The parsed NPM "package.json" file from projectFolder. * @deprecated Use packageJsonEditor instead */ - public get packageJson(): IPackageJson { + public get packageJson(): any { return this._packageJson; } @@ -327,9 +345,7 @@ export class RushConfigurationProject { return isMain; } - private _getLocalDependencyProjects( - dependencies: IPackageJsonDependencyTable = {} - ): RushConfigurationProject[] { + private _getLocalDependencyProjects(dependencies: any = {}): RushConfigurationProject[] { const localDependencyProjects: RushConfigurationProject[] = []; for (const dependency of Object.keys(dependencies)) { // Skip if we can't find the local project or it's a cyclic dependency @@ -338,10 +354,8 @@ export class RushConfigurationProject { ); if (localProject && !this._cyclicDependencyProjects.has(dependency)) { // Set the value if it's a workspace project, or if we have a local project and the semver is satisfied - const dependencySpecifier: DependencySpecifier = new DependencySpecifier( - dependency, - dependencies[dependency] - ); + // eslint-disable-next-line + const dependencySpecifier = new DependencySpecifier(dependency, dependencies[dependency]); switch (dependencySpecifier.specifierType) { case DependencySpecifierType.Version: case DependencySpecifierType.Range: diff --git a/apps/rush-lib/src/api/VersionPolicyConfiguration.ts b/apps/rush-lib/src/api/VersionPolicyConfiguration.ts index ba9554728bc..04782eabde6 100644 --- a/apps/rush-lib/src/api/VersionPolicyConfiguration.ts +++ b/apps/rush-lib/src/api/VersionPolicyConfiguration.ts @@ -1,11 +1,21 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +// eslint-disable-next-line +const importLazy = require('import-lazy')(require); + +console.log('VersionPolicyConfiguration.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as path from 'path'; -import { JsonFile, JsonSchema, FileSystem } from '@rushstack/node-core-library'; +console.log('VersionPolicyConfiguration.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); +// import { JsonFile, JsonSchema, FileSystem } from '@rushstack/node-core-library'; +// eslint-disable-next-line +const nodeCoreLibrary = importLazy('@rushstack/node-core-library'); +console.log('VersionPolicyConfiguration.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import { VersionPolicy, BumpType, LockStepVersionPolicy } from './VersionPolicy'; +console.log('VersionPolicyConfiguration.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfigurationProject } from './RushConfigurationProject'; +console.log('VersionPolicyConfiguration.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); /** * @beta @@ -64,9 +74,11 @@ export interface IVersionPolicyDependencyJson { * @beta */ export class VersionPolicyConfiguration { - private static _jsonSchema: JsonSchema = JsonSchema.fromFile( - path.join(__dirname, '../schemas/version-policies.schema.json') - ); + private static get _jsonSchema() /* NodeCoreLibrary.JsonSchema */ { + return nodeCoreLibrary.JsonSchema.fromFile( + path.join(__dirname, '../schemas/version-policies.schema.json') + ); + } private _versionPolicies: Map; private _jsonFileName: string; @@ -164,10 +176,10 @@ export class VersionPolicyConfiguration { } private _loadFile(): void { - if (!FileSystem.exists(this._jsonFileName)) { + if (!nodeCoreLibrary.FileSystem.exists(this._jsonFileName)) { return; } - const versionPolicyJson: IVersionPolicyJson[] = JsonFile.loadAndValidate( + const versionPolicyJson: IVersionPolicyJson[] = nodeCoreLibrary.JsonFile.loadAndValidate( this._jsonFileName, VersionPolicyConfiguration._jsonSchema ); @@ -186,7 +198,7 @@ export class VersionPolicyConfiguration { versionPolicyJson.push(versionPolicy._json); }); if (shouldCommit) { - JsonFile.save(versionPolicyJson, this._jsonFileName, { updateExistingFile: true }); + nodeCoreLibrary.JsonFile.save(versionPolicyJson, this._jsonFileName, { updateExistingFile: true }); } } } diff --git a/apps/rush-lib/src/cli/RushCommandLineParser.ts b/apps/rush-lib/src/cli/RushCommandLineParser.ts index 12a5b703fc0..826cf29a9b4 100644 --- a/apps/rush-lib/src/cli/RushCommandLineParser.ts +++ b/apps/rush-lib/src/cli/RushCommandLineParser.ts @@ -1,46 +1,88 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +// eslint-disable-next-line +const importLazy = require('import-lazy')(require); + +console.log('RushCommandLineParser.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as colors from 'colors'; +console.log('RushCommandLineParser.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as os from 'os'; +console.log('RushCommandLineParser.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import * as path from 'path'; +console.log('RushCommandLineParser.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { CommandLineParser, CommandLineFlagParameter, CommandLineAction } from '@rushstack/ts-command-line'; -import { InternalError } from '@rushstack/node-core-library'; +console.log('RushCommandLineParser.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); +// import { InternalError } from '@rushstack/node-core-library'; +// eslint-disable-next-line +const nodeCoreLibrary = importLazy('@rushstack/node-core-library'); + +console.log('RushCommandLineParser.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfiguration } from '../api/RushConfiguration'; +console.log('RushCommandLineParser.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConstants } from '../logic/RushConstants'; +console.log('RushCommandLineParser.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); import { CommandLineConfiguration } from '../api/CommandLineConfiguration'; +console.log('RushCommandLineParser.ts : 9: ' + (new Date().getTime() % 20000) / 1000.0); import { CommandJson } from '../api/CommandLineJson'; +console.log('RushCommandLineParser.ts : 10: ' + (new Date().getTime() % 20000) / 1000.0); import { Utilities } from '../utilities/Utilities'; +console.log('RushCommandLineParser.ts : 11: ' + (new Date().getTime() % 20000) / 1000.0); import { BaseScriptAction } from '../cli/scriptActions/BaseScriptAction'; +console.log('RushCommandLineParser.ts : 12: ' + (new Date().getTime() % 20000) / 1000.0); import { AddAction } from './actions/AddAction'; +console.log('RushCommandLineParser.ts : 13: ' + (new Date().getTime() % 20000) / 1000.0); import { ChangeAction } from './actions/ChangeAction'; +console.log('RushCommandLineParser.ts : 14: ' + (new Date().getTime() % 20000) / 1000.0); import { CheckAction } from './actions/CheckAction'; +console.log('RushCommandLineParser.ts : 15: ' + (new Date().getTime() % 20000) / 1000.0); import { DeployAction } from './actions/DeployAction'; +console.log('RushCommandLineParser.ts : 16: ' + (new Date().getTime() % 20000) / 1000.0); import { InitAction } from './actions/InitAction'; +console.log('RushCommandLineParser.ts : 17: ' + (new Date().getTime() % 20000) / 1000.0); import { InitAutoinstallerAction } from './actions/InitAutoinstallerAction'; +console.log('RushCommandLineParser.ts : 18: ' + (new Date().getTime() % 20000) / 1000.0); import { InitDeployAction } from './actions/InitDeployAction'; +console.log('RushCommandLineParser.ts : 19: ' + (new Date().getTime() % 20000) / 1000.0); import { InstallAction } from './actions/InstallAction'; +console.log('RushCommandLineParser.ts : 20: ' + (new Date().getTime() % 20000) / 1000.0); import { LinkAction } from './actions/LinkAction'; +console.log('RushCommandLineParser.ts : 21: ' + (new Date().getTime() % 20000) / 1000.0); import { ListAction } from './actions/ListAction'; +console.log('RushCommandLineParser.ts : 22: ' + (new Date().getTime() % 20000) / 1000.0); import { PublishAction } from './actions/PublishAction'; +console.log('RushCommandLineParser.ts : 23: ' + (new Date().getTime() % 20000) / 1000.0); import { PurgeAction } from './actions/PurgeAction'; +console.log('RushCommandLineParser.ts : 24: ' + (new Date().getTime() % 20000) / 1000.0); import { ScanAction } from './actions/ScanAction'; +console.log('RushCommandLineParser.ts : 25: ' + (new Date().getTime() % 20000) / 1000.0); import { TabCompleteAction } from './actions/TabCompleteAction'; +console.log('RushCommandLineParser.ts : 26: ' + (new Date().getTime() % 20000) / 1000.0); import { UnlinkAction } from './actions/UnlinkAction'; +console.log('RushCommandLineParser.ts : 27: ' + (new Date().getTime() % 20000) / 1000.0); import { UpdateAction } from './actions/UpdateAction'; +console.log('RushCommandLineParser.ts : 28: ' + (new Date().getTime() % 20000) / 1000.0); import { UpdateAutoinstallerAction } from './actions/UpdateAutoinstallerAction'; +console.log('RushCommandLineParser.ts : 29: ' + (new Date().getTime() % 20000) / 1000.0); import { VersionAction } from './actions/VersionAction'; +console.log('RushCommandLineParser.ts : 30: ' + (new Date().getTime() % 20000) / 1000.0); import { BulkScriptAction } from './scriptActions/BulkScriptAction'; +console.log('RushCommandLineParser.ts : 31: ' + (new Date().getTime() % 20000) / 1000.0); import { GlobalScriptAction } from './scriptActions/GlobalScriptAction'; +console.log('RushCommandLineParser.ts : 32: ' + (new Date().getTime() % 20000) / 1000.0); import { Telemetry } from '../logic/Telemetry'; +console.log('RushCommandLineParser.ts : 33: ' + (new Date().getTime() % 20000) / 1000.0); import { AlreadyReportedError } from '../utilities/AlreadyReportedError'; +console.log('RushCommandLineParser.ts : 34: ' + (new Date().getTime() % 20000) / 1000.0); import { RushGlobalFolder } from '../api/RushGlobalFolder'; +console.log('RushCommandLineParser.ts : 35: ' + (new Date().getTime() % 20000) / 1000.0); import { NodeJsCompatibility } from '../logic/NodeJsCompatibility'; +console.log('RushCommandLineParser.ts : 36: ' + (new Date().getTime() % 20000) / 1000.0); /** * Options for `RushCommandLineParser`. @@ -59,6 +101,7 @@ export class RushCommandLineParser extends CommandLineParser { private _rushOptions: IRushCommandLineParserOptions; public constructor(options?: Partial) { + console.log('RushCommandLineParser.constructor : 1: ' + (new Date().getTime() % 20000) / 1000.0); super({ toolFilename: 'rush', toolDescription: @@ -71,28 +114,35 @@ export class RushCommandLineParser extends CommandLineParser { ' automation tools. If you are looking for a proven turnkey solution for monorepo management,' + ' Rush is for you.' }); + console.log('RushCommandLineParser.constructor : 2: ' + (new Date().getTime() % 20000) / 1000.0); this._rushOptions = this._normalizeOptions(options || {}); + console.log('RushCommandLineParser.constructor : 3: ' + (new Date().getTime() % 20000) / 1000.0); try { const rushJsonFilename: string | undefined = RushConfiguration.tryFindRushJsonLocation({ startingFolder: this._rushOptions.cwd, showVerbose: !Utilities.isNonDebugTabCompletionRequest() }); + console.log('RushCommandLineParser.constructor : 4: ' + (new Date().getTime() % 20000) / 1000.0); if (rushJsonFilename) { this.rushConfiguration = RushConfiguration.loadFromConfigurationFile(rushJsonFilename); } + console.log('RushCommandLineParser.constructor : 5: ' + (new Date().getTime() % 20000) / 1000.0); } catch (error) { this._reportErrorAndSetExitCode(error); } + console.log('RushCommandLineParser.constructor : 6: ' + (new Date().getTime() % 20000) / 1000.0); NodeJsCompatibility.warnAboutCompatibilityIssues({ isRushLib: true, alreadyReportedNodeTooNewError: this._rushOptions.alreadyReportedNodeTooNewError, rushConfiguration: this.rushConfiguration }); + console.log('RushCommandLineParser.constructor : 7: ' + (new Date().getTime() % 20000) / 1000.0); this._populateActions(); + console.log('RushCommandLineParser.constructor : 8: ' + (new Date().getTime() % 20000) / 1000.0); } public get isDebug(): boolean { @@ -122,7 +172,7 @@ export class RushCommandLineParser extends CommandLineParser { process.exitCode = 1; if (this._debugParameter.value) { - InternalError.breakInDebugger = true; + nodeCoreLibrary.InternalError.breakInDebugger = true; } return this._wrapOnExecute() diff --git a/apps/rush-lib/src/cli/actions/AddAction.ts b/apps/rush-lib/src/cli/actions/AddAction.ts index 308d886867a..16280ace892 100644 --- a/apps/rush-lib/src/cli/actions/AddAction.ts +++ b/apps/rush-lib/src/cli/actions/AddAction.ts @@ -1,16 +1,25 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +console.log('AddAction.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as os from 'os'; +console.log('AddAction.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as semver from 'semver'; +console.log('AddAction.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import { CommandLineFlagParameter, CommandLineStringParameter } from '@rushstack/ts-command-line'; +console.log('AddAction.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfigurationProject } from '../../api/RushConfigurationProject'; +console.log('AddAction.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import { BaseRushAction } from './BaseRushAction'; +console.log('AddAction.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); import { RushCommandLineParser } from '../RushCommandLineParser'; +console.log('AddAction.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); import { PackageJsonUpdater, SemVerStyle } from '../../logic/PackageJsonUpdater'; +console.log('AddAction.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); import { DependencySpecifier } from '../../logic/DependencySpecifier'; +console.log('AddAction.ts : 9: ' + (new Date().getTime() % 20000) / 1000.0); export class AddAction extends BaseRushAction { private _allFlag: CommandLineFlagParameter; diff --git a/apps/rush-lib/src/cli/actions/ChangeAction.ts b/apps/rush-lib/src/cli/actions/ChangeAction.ts index 171be820585..56b2d80617b 100644 --- a/apps/rush-lib/src/cli/actions/ChangeAction.ts +++ b/apps/rush-lib/src/cli/actions/ChangeAction.ts @@ -1,33 +1,56 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +// eslint-disable-next-line +const importLazy = require('import-lazy')(require); + +console.log('ChangeAction.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as os from 'os'; +console.log('ChangeAction.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as path from 'path'; +console.log('ChangeAction.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import * as child_process from 'child_process'; +console.log('ChangeAction.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import * as colors from 'colors'; -import * as inquirer from 'inquirer'; +console.log('ChangeAction.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); +// import * as inquirer from 'inquirer'; +// eslint-disable-next-line +const inquirer = importLazy('inquirer'); + +console.log('ChangeAction.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); import { CommandLineFlagParameter, CommandLineStringParameter, CommandLineChoiceParameter } from '@rushstack/ts-command-line'; +console.log('ChangeAction.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); import { FileSystem, Path } from '@rushstack/node-core-library'; +console.log('ChangeAction.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfigurationProject } from '../../api/RushConfigurationProject'; +console.log('ChangeAction.ts : 9: ' + (new Date().getTime() % 20000) / 1000.0); import { IChangeFile, IChangeInfo, ChangeType } from '../../api/ChangeManagement'; +console.log('ChangeAction.ts : 10: ' + (new Date().getTime() % 20000) / 1000.0); import { VersionControl } from '../../utilities/VersionControl'; +console.log('ChangeAction.ts : 11: ' + (new Date().getTime() % 20000) / 1000.0); import { ChangeFile } from '../../api/ChangeFile'; +console.log('ChangeAction.ts : 12: ' + (new Date().getTime() % 20000) / 1000.0); import { BaseRushAction } from './BaseRushAction'; +console.log('ChangeAction.ts : 13: ' + (new Date().getTime() % 20000) / 1000.0); import { RushCommandLineParser } from '../RushCommandLineParser'; +console.log('ChangeAction.ts : 14: ' + (new Date().getTime() % 20000) / 1000.0); import { ChangeFiles } from '../../logic/ChangeFiles'; +console.log('ChangeAction.ts : 15: ' + (new Date().getTime() % 20000) / 1000.0); import { VersionPolicy, IndividualVersionPolicy, LockStepVersionPolicy, VersionPolicyDefinitionName } from '../../api/VersionPolicy'; +console.log('ChangeAction.ts : 16: ' + (new Date().getTime() % 20000) / 1000.0); import { AlreadyReportedError } from '../../utilities/AlreadyReportedError'; +console.log('ChangeAction.ts : 17: ' + (new Date().getTime() % 20000) / 1000.0); export class ChangeAction extends BaseRushAction { private _verifyParameter: CommandLineFlagParameter; @@ -178,7 +201,8 @@ export class ChangeAction extends BaseRushAction { this._warnUncommittedChanges(); - const promptModule: inquirer.PromptModule = inquirer.createPromptModule(); + // eslint-disable-next-line + const promptModule = inquirer.createPromptModule(); let changeFileData: Map = new Map(); let interactiveMode: boolean = false; if (this._bulkChangeParameter.value) { @@ -366,7 +390,8 @@ export class ChangeAction extends BaseRushAction { * The main loop which prompts the user for information on changed projects. */ private async _promptForChangeFileData( - promptModule: inquirer.PromptModule, + // eslint-disable-next-line + promptModule, sortedProjectList: string[], existingChangeComments: Map ): Promise> { @@ -401,7 +426,8 @@ export class ChangeAction extends BaseRushAction { * Asks all questions which are needed to generate changelist for a project. */ private async _askQuestions( - promptModule: inquirer.PromptModule, + // eslint-disable-next-line + promptModule, packageName: string, existingChangeComments: Map ): Promise { @@ -440,7 +466,8 @@ export class ChangeAction extends BaseRushAction { } private async _promptForComments( - promptModule: inquirer.PromptModule, + // eslint-disable-next-line + promptModule, packageName: string ): Promise { const bumpOptions: { [type: string]: string } = this._getBumpOptions(packageName); @@ -519,7 +546,8 @@ export class ChangeAction extends BaseRushAction { * Will determine a user's email by first detecting it from their Git config, * or will ask for it if it is not found or the Git config is wrong. */ - private async _detectOrAskForEmail(promptModule: inquirer.PromptModule): Promise { + // eslint-disable-next-line + private async _detectOrAskForEmail(promptModule): Promise { return (await this._detectAndConfirmEmail(promptModule)) || (await this._promptForEmail(promptModule)); } @@ -539,7 +567,8 @@ export class ChangeAction extends BaseRushAction { * Detects the user's email address from their Git configuration, prompts the user to approve the * detected email. It returns undefined if it cannot be detected. */ - private async _detectAndConfirmEmail(promptModule: inquirer.PromptModule): Promise { + // eslint-disable-next-line + private async _detectAndConfirmEmail(promptModule): Promise { const email: string | undefined = this._detectEmail(); if (email) { @@ -560,7 +589,8 @@ export class ChangeAction extends BaseRushAction { /** * Asks the user for their email address */ - private async _promptForEmail(promptModule: inquirer.PromptModule): Promise { + // eslint-disable-next-line + private async _promptForEmail(promptModule): Promise { const { email }: { email: string } = await promptModule([ { type: 'input', @@ -594,7 +624,8 @@ export class ChangeAction extends BaseRushAction { * Writes change files to the common/changes folder. Will prompt for overwrite if file already exists. */ private async _writeChangeFiles( - promptModule: inquirer.PromptModule, + // eslint-disable-next-line + promptModule, changeFileData: Map, overwrite: boolean, interactiveMode: boolean @@ -605,7 +636,8 @@ export class ChangeAction extends BaseRushAction { } private async _writeChangeFile( - promptModule: inquirer.PromptModule, + // eslint-disable-next-line + promptModule, changeFileData: IChangeFile, overwrite: boolean, interactiveMode: boolean @@ -629,7 +661,8 @@ export class ChangeAction extends BaseRushAction { } } - private async _promptForOverwrite(promptModule: inquirer.PromptModule, filePath: string): Promise { + // eslint-disable-next-line + private async _promptForOverwrite(promptModule, filePath: string): Promise { const overwrite: boolean = await promptModule([ { name: 'overwrite', diff --git a/apps/rush-lib/src/cli/actions/DeployAction.ts b/apps/rush-lib/src/cli/actions/DeployAction.ts index a3aa8fa3725..b89b56c262a 100644 --- a/apps/rush-lib/src/cli/actions/DeployAction.ts +++ b/apps/rush-lib/src/cli/actions/DeployAction.ts @@ -1,10 +1,15 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +console.log('DeployAction.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import { BaseRushAction } from './BaseRushAction'; +console.log('DeployAction.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import { RushCommandLineParser } from '../RushCommandLineParser'; +console.log('DeployAction.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import { CommandLineFlagParameter, CommandLineStringParameter } from '@rushstack/ts-command-line'; +console.log('DeployAction.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { DeployManager } from '../../logic/deploy/DeployManager'; +console.log('DeployAction.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); export class DeployAction extends BaseRushAction { private _scenario: CommandLineStringParameter; diff --git a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts index d6a671c305d..1ffd3f8c9ad 100644 --- a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts +++ b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts @@ -23,6 +23,7 @@ export class TabCompleteAction extends BaseRushAction { private _positionParameter: CommandLineIntegerParameter; public constructor(parser: RushCommandLineParser) { + console.log('TabCompleteAction.constructor : 1: ' + (new Date().getTime() % 20000) / 1000.0); super({ actionName: 'tab-complete', summary: 'Provides tab completion.', @@ -30,6 +31,7 @@ export class TabCompleteAction extends BaseRushAction { parser, safeForSimultaneousRushProcesses: true }); + console.log('TabCompleteAction.constructor : 2: ' + (new Date().getTime() % 20000) / 1000.0); } protected onDefineParameters(): void { @@ -49,12 +51,14 @@ export class TabCompleteAction extends BaseRushAction { } protected async runAsync(): Promise { + console.log('TabCompleteAction.runAsync : 1: ' + (new Date().getTime() % 20000) / 1000.0); const commandLine: string = this._wordToCompleteParameter.value || ''; const caretPosition: number = this._positionParameter.value || 0; for (const value of this._getCompletions(commandLine, caretPosition)) { console.log(value); } + console.log('TabCompleteAction.runAsync : 2: ' + (new Date().getTime() % 20000) / 1000.0); } public *_getCompletions(commandLine: string, caretPosition: number): IterableIterator { diff --git a/apps/rush-lib/src/logic/DependencySpecifier.ts b/apps/rush-lib/src/logic/DependencySpecifier.ts index bdcf3d8a31f..2dbdf659e1d 100644 --- a/apps/rush-lib/src/logic/DependencySpecifier.ts +++ b/apps/rush-lib/src/logic/DependencySpecifier.ts @@ -1,8 +1,15 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +// eslint-disable-next-line +const importLazy = require('import-lazy')(require); + +console.log('DependencySpecifier.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import npmPackageArg = require('npm-package-arg'); -import { InternalError } from '@rushstack/node-core-library'; +console.log('DependencySpecifier.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); +// import { InternalError } from '@rushstack/node-core-library'; +const nodeCoreLibrary = importLazy('@rushstack/node-core-library/lib/InternalError'); +console.log('DependencySpecifier.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); /** * The parsed format of a provided version specifier. @@ -102,7 +109,7 @@ export class DependencySpecifier { if (this.specifierType === DependencySpecifierType.Alias) { const aliasResult: npmPackageArg.AliasResult = result as npmPackageArg.AliasResult; if (!aliasResult.subSpec || !aliasResult.subSpec.name) { - throw new InternalError('Unexpected result from npm-package-arg'); + throw new nodeCoreLibrary.InternalError('Unexpected result from npm-package-arg'); } this.aliasTarget = new DependencySpecifier(aliasResult.subSpec.name, aliasResult.subSpec.rawSpec); } else { @@ -129,7 +136,7 @@ export class DependencySpecifier { case 'alias': return DependencySpecifierType.Alias; default: - throw new InternalError(`Unexpected npm-package-arg result type "${specifierType}"`); + throw new nodeCoreLibrary.InternalError(`Unexpected npm-package-arg result type "${specifierType}"`); } } } diff --git a/apps/rush-lib/src/logic/InstallManagerFactory.ts b/apps/rush-lib/src/logic/InstallManagerFactory.ts index fb27a19b0da..5bbc63505c9 100644 --- a/apps/rush-lib/src/logic/InstallManagerFactory.ts +++ b/apps/rush-lib/src/logic/InstallManagerFactory.ts @@ -1,16 +1,26 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +console.log('InstallManagerFactory.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as colors from 'colors'; +console.log('InstallManagerFactory.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as semver from 'semver'; +console.log('InstallManagerFactory.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import { BaseInstallManager, IInstallManagerOptions } from './base/BaseInstallManager'; +console.log('InstallManagerFactory.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { RushInstallManager } from './installManager/RushInstallManager'; +console.log('InstallManagerFactory.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import { WorkspaceInstallManager } from './installManager/WorkspaceInstallManager'; +console.log('InstallManagerFactory.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); import { AlreadyReportedError } from '../utilities/AlreadyReportedError'; +console.log('InstallManagerFactory.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); import { PurgeManager } from './PurgeManager'; +console.log('InstallManagerFactory.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfiguration } from '../api/RushConfiguration'; +console.log('InstallManagerFactory.ts : 9: ' + (new Date().getTime() % 20000) / 1000.0); import { RushGlobalFolder } from '../api/RushGlobalFolder'; +console.log('InstallManagerFactory.ts : 10: ' + (new Date().getTime() % 20000) / 1000.0); export class InstallManagerFactory { public static getInstallManager( diff --git a/apps/rush-lib/src/logic/LinkManagerFactory.ts b/apps/rush-lib/src/logic/LinkManagerFactory.ts index c6f36989a94..e1c030b317c 100644 --- a/apps/rush-lib/src/logic/LinkManagerFactory.ts +++ b/apps/rush-lib/src/logic/LinkManagerFactory.ts @@ -1,10 +1,15 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +console.log('LinkManagerFactory.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfiguration } from '../api/RushConfiguration'; +console.log('LinkManagerFactory.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import { BaseLinkManager } from './base/BaseLinkManager'; +console.log('LinkManagerFactory.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import { NpmLinkManager } from './npm/NpmLinkManager'; +console.log('LinkManagerFactory.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { PnpmLinkManager } from './pnpm/PnpmLinkManager'; +console.log('LinkManagerFactory.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); export class LinkManagerFactory { public static getLinkManager(rushConfiguration: RushConfiguration): BaseLinkManager { diff --git a/apps/rush-lib/src/logic/PackageJsonUpdater.ts b/apps/rush-lib/src/logic/PackageJsonUpdater.ts index df86ce05297..6dcf5b35f05 100644 --- a/apps/rush-lib/src/logic/PackageJsonUpdater.ts +++ b/apps/rush-lib/src/logic/PackageJsonUpdater.ts @@ -1,22 +1,38 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +console.log('PackageJsonUpdater.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as colors from 'colors'; +console.log('PackageJsonUpdater.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as semver from 'semver'; +console.log('PackageJsonUpdater.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfiguration } from '../api/RushConfiguration'; +console.log('PackageJsonUpdater.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { BaseInstallManager, IInstallManagerOptions } from './base/BaseInstallManager'; +console.log('PackageJsonUpdater.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import { InstallManagerFactory } from './InstallManagerFactory'; +console.log('PackageJsonUpdater.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); import { VersionMismatchFinder } from './versionMismatch/VersionMismatchFinder'; +console.log('PackageJsonUpdater.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); import { PurgeManager } from './PurgeManager'; +console.log('PackageJsonUpdater.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); import { Utilities } from '../utilities/Utilities'; +console.log('PackageJsonUpdater.ts : 9: ' + (new Date().getTime() % 20000) / 1000.0); import { DependencyType, PackageJsonDependency } from '../api/PackageJsonEditor'; +console.log('PackageJsonUpdater.ts : 10: ' + (new Date().getTime() % 20000) / 1000.0); import { RushGlobalFolder } from '../api/RushGlobalFolder'; +console.log('PackageJsonUpdater.ts : 11: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfigurationProject } from '../api/RushConfigurationProject'; +console.log('PackageJsonUpdater.ts : 12: ' + (new Date().getTime() % 20000) / 1000.0); import { VersionMismatchFinderEntity } from './versionMismatch/VersionMismatchFinderEntity'; +console.log('PackageJsonUpdater.ts : 13: ' + (new Date().getTime() % 20000) / 1000.0); import { VersionMismatchFinderProject } from './versionMismatch/VersionMismatchFinderProject'; +console.log('PackageJsonUpdater.ts : 14: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConstants } from './RushConstants'; +console.log('PackageJsonUpdater.ts : 15: ' + (new Date().getTime() % 20000) / 1000.0); import { InstallHelpers } from './installManager/InstallHelpers'; +console.log('PackageJsonUpdater.ts : 16: ' + (new Date().getTime() % 20000) / 1000.0); /** * The type of SemVer range specifier that is prepended to the version @@ -445,7 +461,7 @@ export class PackageJsonUpdater { console.log(); - console.log(`Found latest version: ${colors.cyan(selectedVersion)}`); + console.log(`Found latest version: ${colors.cyan(selectedVersion!)}`); } console.log(); diff --git a/apps/rush-lib/src/logic/RepoStateFile.ts b/apps/rush-lib/src/logic/RepoStateFile.ts index 23bffc9f36a..0eec013e871 100644 --- a/apps/rush-lib/src/logic/RepoStateFile.ts +++ b/apps/rush-lib/src/logic/RepoStateFile.ts @@ -1,8 +1,13 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +// eslint-disable-next-line +const importLazy = require('import-lazy')(require); + import * as path from 'path'; -import { FileSystem, JsonFile, JsonSchema, NewlineKind } from '@rushstack/node-core-library'; +// import { FileSystem, JsonFile, JsonSchema, NewlineKind } from '@rushstack/node-core-library'; +// eslint-disable-next-line +const nodeCoreLibrary = importLazy('@rushstack/node-core-library'); import { RushConfiguration } from '../api/RushConfiguration'; import { PnpmShrinkwrapFile } from './pnpm/PnpmShrinkwrapFile'; @@ -34,9 +39,11 @@ interface IRepoStateJson { * @public */ export class RepoStateFile { - private static _jsonSchema: JsonSchema = JsonSchema.fromFile( - path.join(__dirname, '../schemas/repo-state.schema.json') - ); + // eslint-disable-next-line + private static get _jsonSchema() /* NodeCoreLibrary.JsonSchema */ { + return nodeCoreLibrary.JsonSchema.fromFile(path.join(__dirname, '../schemas/repo-state.schema.json')); + } + private _repoStateFilePath: string; private _variant: string | undefined; private _pnpmShrinkwrapHash: string | undefined; @@ -88,9 +95,9 @@ export class RepoStateFile { public static loadFromFile(jsonFilename: string, variant: string | undefined): RepoStateFile { let repoStateJson: IRepoStateJson | undefined = undefined; try { - repoStateJson = JsonFile.loadAndValidate(jsonFilename, RepoStateFile._jsonSchema); + repoStateJson = nodeCoreLibrary.JsonFile.loadAndValidate(jsonFilename, RepoStateFile._jsonSchema); } catch (error) { - if (!FileSystem.isNotExistError(error)) { + if (!nodeCoreLibrary.FileSystem.isNotExistError(error)) { throw error; } } @@ -154,8 +161,8 @@ export class RepoStateFile { if (this._modified) { const content: string = '// DO NOT MODIFY THIS FILE. It is generated and used by Rush.' + - `${NewlineKind.Lf}${this._serialize()}`; - FileSystem.writeFile(this._repoStateFilePath, content); + `${nodeCoreLibrary.NewlineKind.Lf}${this._serialize()}`; + nodeCoreLibrary.FileSystem.writeFile(this._repoStateFilePath, content); this._modified = false; return true; } @@ -173,6 +180,8 @@ export class RepoStateFile { repoStateJson.preferredVersionsHash = this._preferredVersionsHash; } - return JsonFile.stringify(repoStateJson, { newlineConversion: NewlineKind.Lf }); + return nodeCoreLibrary.JsonFile.stringify(repoStateJson, { + newlineConversion: nodeCoreLibrary.NewlineKind.Lf + }); } } diff --git a/apps/rush-lib/src/logic/VersionManager.ts b/apps/rush-lib/src/logic/VersionManager.ts index 80b32cb5b30..3a0237ae493 100644 --- a/apps/rush-lib/src/logic/VersionManager.ts +++ b/apps/rush-lib/src/logic/VersionManager.ts @@ -188,7 +188,7 @@ export class VersionManager { clonedProject = cloneDeep(rushProject.packageJson); projectVersionChanged = false; } - this._updateProjectAllDependencies(rushProject, clonedProject, projectVersionChanged); + this._updateProjectAllDependencies(rushProject, clonedProject!, projectVersionChanged); }); } diff --git a/apps/rush-lib/src/logic/deploy/DeployArchiver.ts b/apps/rush-lib/src/logic/deploy/DeployArchiver.ts index 86d6ff38159..95a9934a995 100644 --- a/apps/rush-lib/src/logic/deploy/DeployArchiver.ts +++ b/apps/rush-lib/src/logic/deploy/DeployArchiver.ts @@ -1,8 +1,21 @@ -import * as JSZip from 'jszip'; +// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. +// See LICENSE in the project root for license information. + +// eslint-disable-next-line +const importLazy = require('import-lazy')(require); + +console.log('DeployArchiver.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); +// import * as JSZip from 'jszip'; +// eslint-disable-next-line +const JSZip = importLazy('jszip'); +console.log('DeployArchiver.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as path from 'path'; +console.log('DeployArchiver.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import { FileSystem, FileSystemStats } from '@rushstack/node-core-library'; +console.log('DeployArchiver.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { IDeployState } from './DeployManager'; +console.log('DeployArchiver.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); // JSZip is dependant on Blob being declared. declare global { @@ -13,7 +26,8 @@ export class DeployArchiver { public static async createArchiveAsync(deployState: IDeployState): Promise { if (deployState.createArchiveFilePath !== undefined) { console.log('Creating archive...'); - const zip: JSZip = this._getZipOfFolder(deployState.targetRootFolder); + // eslint-disable-next-line + const zip = this._getZipOfFolder(deployState.targetRootFolder); const zipContent: Buffer = await zip.generateAsync({ type: 'nodebuffer', platform: 'UNIX' @@ -50,7 +64,8 @@ export class DeployArchiver { return results; } - private static _getZipOfFolder(dir: string): JSZip { + // eslint-disable-next-line + private static _getZipOfFolder(dir: string) { // returns a JSZip instance filled with contents of dir. const allPaths: string[] = this._getFilePathsRecursively(dir); @@ -59,7 +74,8 @@ export class DeployArchiver { // See: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/uapi/linux/stat.h#n10 const permissionsValue: number = 0o120755; - const zip: JSZip = new JSZip(); + // eslint-disable-next-line + const zip = new JSZip(); for (const filePath of allPaths) { const addPath: string = path.relative(dir, filePath); const stat: FileSystemStats = FileSystem.getLinkStatistics(filePath); diff --git a/apps/rush-lib/src/logic/deploy/DeployManager.ts b/apps/rush-lib/src/logic/deploy/DeployManager.ts index 5adb84c64cf..7d9136bb48b 100644 --- a/apps/rush-lib/src/logic/deploy/DeployManager.ts +++ b/apps/rush-lib/src/logic/deploy/DeployManager.ts @@ -1,36 +1,60 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +// eslint-disable-next-line +const importLazy = require('import-lazy')(require); + +console.log('DeployManager.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as colors from 'colors'; +console.log('DeployManager.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as path from 'path'; +console.log('DeployManager.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import * as resolve from 'resolve'; +console.log('DeployManager.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import * as npmPacklist from 'npm-packlist'; -import pnpmLinkBins from '@pnpm/link-bins'; +console.log('DeployManager.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); +// eslint-disable-next-line +const pnpmLinkBins = importLazy('@pnpm/link-bins'); +console.log('DeployManager.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); // (Used only by the legacy code fragment in the resolve.sync() hook below) import * as fsForResolve from 'fs'; +console.log('DeployManager.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); import ignore, { Ignore } from 'ignore'; -import { - Path, - FileSystem, - PackageJsonLookup, - FileSystemStats, - Sort, - JsonFile, - IPackageJson, - AlreadyExistsBehavior, - InternalError, - NewlineKind, - Text -} from '@rushstack/node-core-library'; +console.log('DeployManager.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); +// import { +// Path, +// FileSystem, +// PackageJsonLookup, +// FileSystemStats, +// Sort, +// JsonFile, +// IPackageJson, +// AlreadyExistsBehavior, +// InternalError, +// NewlineKind, +// Text +// } from '@rushstack/node-core-library'; + +// eslint-disable-next-line +const nodeCoreLibrary = importLazy('@rushstack/node-core-library'); +console.log('DeployManager.ts : 9: ' + (new Date().getTime() % 20000) / 1000.0); + import { DeployArchiver } from './DeployArchiver'; +console.log('DeployManager.ts : 10: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfiguration } from '../../api/RushConfiguration'; +console.log('DeployManager.ts : 11: ' + (new Date().getTime() % 20000) / 1000.0); import { SymlinkAnalyzer, ILinkInfo } from './SymlinkAnalyzer'; +console.log('DeployManager.ts : 12: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfigurationProject } from '../../api/RushConfigurationProject'; +console.log('DeployManager.ts : 13: ' + (new Date().getTime() % 20000) / 1000.0); import { DeployScenarioConfiguration, IDeployScenarioProjectJson } from './DeployScenarioConfiguration'; +console.log('DeployManager.ts : 14: ' + (new Date().getTime() % 20000) / 1000.0); import { PnpmfileConfiguration } from './PnpmfileConfiguration'; +console.log('DeployManager.ts : 15: ' + (new Date().getTime() % 20000) / 1000.0); import { matchesWithStar } from './Utils'; +console.log('DeployManager.ts : 16: ' + (new Date().getTime() % 20000) / 1000.0); // (@types/npm-packlist is missing this API) declare module 'npm-packlist' { @@ -129,18 +153,19 @@ export interface IDeployState { */ export class DeployManager { private readonly _rushConfiguration: RushConfiguration; - private readonly _packageJsonLookup: PackageJsonLookup; + private readonly _packageJsonLookup; public constructor(rushConfiguration: RushConfiguration) { this._rushConfiguration = rushConfiguration; - this._packageJsonLookup = new PackageJsonLookup(); + // eslint-disable-next-line + this._packageJsonLookup = new nodeCoreLibrary.PackageJsonLookup(); } /** * Recursively crawl the node_modules dependencies and collect the result in IDeployState.foldersToCopy. */ private _collectFoldersRecursive(packageJsonFolderPath: string, deployState: IDeployState): void { - const packageJsonRealFolderPath: string = FileSystem.getRealPath(packageJsonFolderPath); + const packageJsonRealFolderPath: string = nodeCoreLibrary.FileSystem.getRealPath(packageJsonFolderPath); if (deployState.foldersToCopy.has(packageJsonRealFolderPath)) { // we've already seen this folder @@ -149,16 +174,17 @@ export class DeployManager { deployState.foldersToCopy.add(packageJsonRealFolderPath); - const originalPackageJson: IPackageJson = JsonFile.load( + const originalPackageJson = nodeCoreLibrary.JsonFile.load( path.join(packageJsonRealFolderPath, 'package.json') ); const sourceFolderInfo: IFolderInfo | undefined = deployState.folderInfosByPath.get( - FileSystem.getRealPath(packageJsonFolderPath) + // eslint-disable-next-line + nodeCoreLibrary.FileSystem.getRealPath(packageJsonFolderPath) ); // Transform packageJson using pnpmfile.js - const packageJson: IPackageJson = deployState.pnpmfileConfiguration.transform(originalPackageJson); + const packageJson = deployState.pnpmfileConfiguration.transform(originalPackageJson); // Union of keys from regular dependencies, peerDependencies, optionalDependencies // (and possibly devDependencies if includeDevDependencies=true) @@ -214,7 +240,7 @@ export class DeployManager { // Replicate the PNPM workaround links. // Only apply this logic for packages that were actually installed under the common/temp folder. - if (Path.isUnder(packageJsonFolderPath, this._rushConfiguration.commonTempFolder)) { + if (nodeCoreLibrary.Path.isUnder(packageJsonFolderPath, this._rushConfiguration.commonTempFolder)) { try { // The PNPM workaround links are created in this folder. We will resolve the current package // from that location and collect any additional links encountered along the way. @@ -317,7 +343,7 @@ export class DeployManager { if (!resolvedDependency) { // This should not happen, since the resolve.sync() docs say it will throw an exception instead - throw new InternalError(`Error resolving ${packageName} from ${startingFolder}`); + throw new nodeCoreLibrary.InternalError(`Error resolving ${packageName} from ${startingFolder}`); } const dependencyPackageFolderPath: string | undefined = this._packageJsonLookup.tryGetPackageFolderFor( @@ -338,7 +364,7 @@ export class DeployManager { * Example output: "C:\MyRepo\common\deploy\libraries\my-lib" */ private _remapPathForDeployFolder(absolutePathInSourceFolder: string, deployState: IDeployState): string { - if (!Path.isUnderOrEqual(absolutePathInSourceFolder, deployState.sourceRootFolder)) { + if (!nodeCoreLibrary.Path.isUnderOrEqual(absolutePathInSourceFolder, deployState.sourceRootFolder)) { throw new Error( `Source path is not under ${deployState.sourceRootFolder}\n${absolutePathInSourceFolder}` ); @@ -355,13 +381,13 @@ export class DeployManager { * Example output: "libraries/my-lib" */ private _remapPathForDeployMetadata(absolutePathInSourceFolder: string, deployState: IDeployState): string { - if (!Path.isUnderOrEqual(absolutePathInSourceFolder, deployState.sourceRootFolder)) { + if (!nodeCoreLibrary.Path.isUnderOrEqual(absolutePathInSourceFolder, deployState.sourceRootFolder)) { throw new Error( `Source path is not under ${deployState.sourceRootFolder}\n${absolutePathInSourceFolder}` ); } const relativePath: string = path.relative(deployState.sourceRootFolder, absolutePathInSourceFolder); - return Text.replaceAll(relativePath, '\\', '/'); + return nodeCoreLibrary.Text.replaceAll(relativePath, '\\', '/'); } /** @@ -372,7 +398,7 @@ export class DeployManager { if (!deployState.scenarioConfiguration.json.includeNpmIgnoreFiles) { const sourceFolderInfo: IFolderInfo | undefined = deployState.folderInfosByPath.get( - FileSystem.getRealPath(sourceFolderPath) + nodeCoreLibrary.FileSystem.getRealPath(sourceFolderPath) ); if (sourceFolderInfo) { if (sourceFolderInfo.isRushProject) { @@ -397,12 +423,12 @@ export class DeployManager { const copyDestinationPath: string = path.join(targetFolderPath, npmPackFile); if (deployState.symlinkAnalyzer.analyzePath(copySourcePath).kind !== 'link') { - FileSystem.ensureFolder(path.dirname(copyDestinationPath)); + nodeCoreLibrary.FileSystem.ensureFolder(path.dirname(copyDestinationPath)); - FileSystem.copyFile({ + nodeCoreLibrary.FileSystem.copyFile({ sourcePath: copySourcePath, destinationPath: copyDestinationPath, - alreadyExistsBehavior: AlreadyExistsBehavior.Error + alreadyExistsBehavior: nodeCoreLibrary.AlreadyExistsBehavior.Error }); } } @@ -419,10 +445,10 @@ export class DeployManager { '**/.DS_Store' ]); - FileSystem.copyFiles({ + nodeCoreLibrary.FileSystem.copyFiles({ sourcePath: sourceFolderPath, destinationPath: targetFolderPath, - alreadyExistsBehavior: AlreadyExistsBehavior.Error, + alreadyExistsBehavior: nodeCoreLibrary.AlreadyExistsBehavior.Error, filter: (src: string, dest: string) => { const relativeSrc: string = path.relative(sourceFolderPath, src); if (!relativeSrc) { @@ -433,7 +459,8 @@ export class DeployManager { return false; } - const stats: FileSystemStats = FileSystem.getLinkStatistics(src); + // eslint-disable-next-line + const stats = nodeCoreLibrary.FileSystem.getLinkStatistics(src); if (stats.isSymbolicLink()) { deployState.symlinkAnalyzer.analyzePath(src); return false; @@ -456,12 +483,12 @@ export class DeployManager { }; // Has the link target been created yet? If not, we should try again later - if (!FileSystem.exists(linkInfo.targetPath)) { + if (!nodeCoreLibrary.FileSystem.exists(linkInfo.targetPath)) { return false; } const newLinkFolder: string = path.dirname(linkInfo.linkPath); - FileSystem.ensureFolder(newLinkFolder); + nodeCoreLibrary.FileSystem.ensureFolder(newLinkFolder); // Link to the relative path for symlinks const relativeTargetPath: string = path.relative(newLinkFolder, linkInfo.targetPath); @@ -470,7 +497,7 @@ export class DeployManager { if (process.platform === 'win32') { if (linkInfo.kind === 'folderLink') { // For directories, we use a Windows "junction". On Unix, this produces a regular symlink. - FileSystem.createSymbolicLinkJunction({ + nodeCoreLibrary.FileSystem.createSymbolicLinkJunction({ linkTargetPath: relativeTargetPath, newLinkPath: linkInfo.linkPath }); @@ -479,7 +506,7 @@ export class DeployManager { // administrator permission. // NOTE: We cannot use the relative path for hard links - FileSystem.createHardLink({ + nodeCoreLibrary.FileSystem.createHardLink({ linkTargetPath: relativeTargetPath, newLinkPath: linkInfo.linkPath }); @@ -488,12 +515,12 @@ export class DeployManager { // However hard links seem to cause build failures on Mac, so for all other operating systems // we use symbolic links for this case. if (linkInfo.kind === 'folderLink') { - FileSystem.createSymbolicLinkFolder({ + nodeCoreLibrary.FileSystem.createSymbolicLinkFolder({ linkTargetPath: relativeTargetPath, newLinkPath: linkInfo.linkPath }); } else { - FileSystem.createSymbolicLinkFile({ + nodeCoreLibrary.FileSystem.createSymbolicLinkFile({ linkTargetPath: relativeTargetPath, newLinkPath: linkInfo.linkPath }); @@ -569,8 +596,8 @@ export class DeployManager { deployMetadataJson.links.push(relativeInfo); } - JsonFile.save(deployMetadataJson, deployMetadataFilePath, { - newlineConversion: NewlineKind.OsDefault + nodeCoreLibrary.JsonFile.save(deployMetadataJson, deployMetadataFilePath, { + newlineConversion: nodeCoreLibrary.NewlineKind.OsDefault }); } @@ -605,7 +632,7 @@ export class DeployManager { ); for (const rushProject of this._rushConfiguration.projects) { - const projectFolder: string = FileSystem.getRealPath(rushProject.projectFolder); + const projectFolder: string = nodeCoreLibrary.FileSystem.getRealPath(rushProject.projectFolder); const projectSettings: | IDeployScenarioProjectJson | undefined = deployState.scenarioConfiguration.projectJsonsByName.get(rushProject.packageName); @@ -632,7 +659,7 @@ export class DeployManager { console.log(); } - Sort.sortSet(deployState.foldersToCopy); + nodeCoreLibrary.Sort.sortSet(deployState.foldersToCopy); console.log('Copying folders...'); for (const folderToCopy of deployState.foldersToCopy) { @@ -644,10 +671,10 @@ export class DeployManager { if (deployState.scenarioConfiguration.json.linkCreation === 'script') { console.log('Copying create-links.js'); - FileSystem.copyFile({ + nodeCoreLibrary.FileSystem.copyFile({ sourcePath: path.join(__dirname, '../../scripts/create-links.js'), destinationPath: path.join(deployState.targetRootFolder, 'create-links.js'), - alreadyExistsBehavior: AlreadyExistsBehavior.Error + alreadyExistsBehavior: nodeCoreLibrary.AlreadyExistsBehavior.Error }); } @@ -660,7 +687,9 @@ export class DeployManager { // TODO: If a symbolic link points to another symbolic link, then we should order the operations // so that the intermediary target is created first. This case was procrastinated because it does // not seem to occur in practice. If you encounter this, please report it. - throw new InternalError('Target does not exist: ' + JSON.stringify(linkToCopy, undefined, 2)); + throw new nodeCoreLibrary.InternalError( + 'Target does not exist: ' + JSON.stringify(linkToCopy, undefined, 2) + ); } } @@ -671,10 +700,10 @@ export class DeployManager { this._rushConfiguration.rushJsonFolder, deployState.scenarioConfiguration.json.folderToCopy ); - FileSystem.copyFiles({ + nodeCoreLibrary.FileSystem.copyFiles({ sourcePath: sourceFolderPath, destinationPath: deployState.targetRootFolder, - alreadyExistsBehavior: AlreadyExistsBehavior.Error + alreadyExistsBehavior: nodeCoreLibrary.AlreadyExistsBehavior.Error }); } await DeployArchiver.createArchiveAsync(deployState); @@ -721,7 +750,7 @@ export class DeployManager { let targetRootFolder: string; if (targetFolderParameter) { targetRootFolder = path.resolve(targetFolderParameter); - if (!FileSystem.exists(targetRootFolder)) { + if (!nodeCoreLibrary.FileSystem.exists(targetRootFolder)) { throw new Error( 'The specified target folder does not exist: ' + JSON.stringify(targetFolderParameter) ); @@ -734,13 +763,13 @@ export class DeployManager { console.log(colors.cyan('Deploying to target folder: ') + targetRootFolder); console.log(colors.cyan('Main project for deployment: ') + mainProjectName + '\n'); - FileSystem.ensureFolder(targetRootFolder); + nodeCoreLibrary.FileSystem.ensureFolder(targetRootFolder); // Is the target folder empty? - if (FileSystem.readFolder(targetRootFolder).length > 0) { + if (nodeCoreLibrary.FileSystem.readFolder(targetRootFolder).length > 0) { if (overwriteExisting) { console.log('Deleting target folder contents because "--overwrite" was specified...'); - FileSystem.ensureEmptyFolder(targetRootFolder); + nodeCoreLibrary.FileSystem.ensureEmptyFolder(targetRootFolder); console.log(); } else { throw new Error( diff --git a/apps/rush-lib/src/logic/installManager/RushInstallManager.ts b/apps/rush-lib/src/logic/installManager/RushInstallManager.ts index ad685ee5d2f..2dba537f88c 100644 --- a/apps/rush-lib/src/logic/installManager/RushInstallManager.ts +++ b/apps/rush-lib/src/logic/installManager/RushInstallManager.ts @@ -1,13 +1,25 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +// eslint-disable-next-line +const importLazy = require('import-lazy')(require); + +console.log('RushInstallManager.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as glob from 'glob'; +console.log('RushInstallManager.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as colors from 'colors'; +console.log('RushInstallManager.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import * as os from 'os'; +console.log('RushInstallManager.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import * as path from 'path'; +console.log('RushInstallManager.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import * as semver from 'semver'; -import * as tar from 'tar'; +console.log('RushInstallManager.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); +// eslint-disable-next-line +const tar = importLazy('tar'); +console.log('RushInstallManager.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); import * as globEscape from 'glob-escape'; +console.log('RushInstallManager.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); import { JsonFile, Text, @@ -17,35 +29,49 @@ import { PosixModeBits, InternalError } from '@rushstack/node-core-library'; +console.log('RushInstallManager.ts : 9: ' + (new Date().getTime() % 20000) / 1000.0); import { BaseInstallManager } from '../base/BaseInstallManager'; +console.log('RushInstallManager.ts : 10: ' + (new Date().getTime() % 20000) / 1000.0); import { BaseShrinkwrapFile } from '../../logic/base/BaseShrinkwrapFile'; +console.log('RushInstallManager.ts : 11: ' + (new Date().getTime() % 20000) / 1000.0); import { IRushTempPackageJson } from '../../logic/base/BasePackage'; +console.log('RushInstallManager.ts : 12: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfigurationProject } from '../../api/RushConfigurationProject'; +console.log('RushInstallManager.ts : 13: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConstants } from '../../logic/RushConstants'; +console.log('RushInstallManager.ts : 14: ' + (new Date().getTime() % 20000) / 1000.0); import { Stopwatch } from '../../utilities/Stopwatch'; +console.log('RushInstallManager.ts : 15: ' + (new Date().getTime() % 20000) / 1000.0); import { Utilities } from '../../utilities/Utilities'; +console.log('RushInstallManager.ts : 16: ' + (new Date().getTime() % 20000) / 1000.0); import { PackageJsonEditor, DependencyType, PackageJsonDependency } from '../../api/PackageJsonEditor'; +console.log('RushInstallManager.ts : 17: ' + (new Date().getTime() % 20000) / 1000.0); import { DependencySpecifier, DependencySpecifierType } from '../DependencySpecifier'; +console.log('RushInstallManager.ts : 18: ' + (new Date().getTime() % 20000) / 1000.0); import { InstallHelpers } from './InstallHelpers'; +console.log('RushInstallManager.ts : 19: ' + (new Date().getTime() % 20000) / 1000.0); import { AlreadyReportedError } from '../../utilities/AlreadyReportedError'; +console.log('RushInstallManager.ts : 20: ' + (new Date().getTime() % 20000) / 1000.0); import { LinkManagerFactory } from '../LinkManagerFactory'; +console.log('RushInstallManager.ts : 21: ' + (new Date().getTime() % 20000) / 1000.0); import { BaseLinkManager } from '../base/BaseLinkManager'; +console.log('RushInstallManager.ts : 22: ' + (new Date().getTime() % 20000) / 1000.0); /** * The "noMtime" flag is new in tar@4.4.1 and not available yet for \@types/tar. * As a temporary workaround, augment the type. */ -declare module 'tar' { - // eslint-disable-next-line @typescript-eslint/naming-convention - export interface CreateOptions { - /** - * "Set to true to omit writing mtime values for entries. Note that this prevents using other - * mtime-based features like tar.update or the keepNewer option with the resulting tar archive." - */ - noMtime?: boolean; - } -} +// declare module 'tar' { +// // eslint-disable-next-line @typescript-eslint/naming-convention +// export interface CreateOptions { +// /** +// * "Set to true to omit writing mtime values for entries. Note that this prevents using other +// * mtime-based features like tar.update or the keepNewer option with the resulting tar archive." +// */ +// noMtime?: boolean; +// } +// } /** * This class implements common logic between "rush install" and "rush update". @@ -350,7 +376,8 @@ export class RushInstallManager extends BaseInstallManager { // NPM expects the root of the tarball to have a directory called 'package' const npmPackageFolder: string = 'package'; - const tarOptions: tar.CreateOptions = { + // eslint-disable-next-line + const tarOptions = { gzip: true, file: tarballFile, cwd: tempProjectFolder, @@ -359,7 +386,8 @@ export class RushInstallManager extends BaseInstallManager { noPax: true, sync: true, prefix: npmPackageFolder, - filter: (path: string, stat: tar.FileStat): boolean => { + // eslint-disable-next-line + filter: (path: string, stat): boolean => { if ( !this.rushConfiguration.experimentsConfiguration.configuration.noChmodFieldInTarHeaderNormalization ) { @@ -369,7 +397,7 @@ export class RushInstallManager extends BaseInstallManager { } return true; } - } as tar.CreateOptions; + }; // create the new tarball tar.create(tarOptions, [FileConstants.PackageJson]); } diff --git a/apps/rush-lib/src/logic/npm/NpmLinkManager.ts b/apps/rush-lib/src/logic/npm/NpmLinkManager.ts index dc46fffb73e..82041bf2f36 100644 --- a/apps/rush-lib/src/logic/npm/NpmLinkManager.ts +++ b/apps/rush-lib/src/logic/npm/NpmLinkManager.ts @@ -1,20 +1,41 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +// eslint-disable-next-line +const importLazy = require('import-lazy')(require); + +console.log('NpmLinkManager.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as colors from 'colors'; +console.log('NpmLinkManager.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as os from 'os'; +console.log('NpmLinkManager.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import * as path from 'path'; +console.log('NpmLinkManager.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import * as semver from 'semver'; -import * as tar from 'tar'; -import readPackageTree = require('read-package-tree'); +console.log('NpmLinkManager.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); +// import * as tar from 'tar'; +// eslint-disable-next-line +const tar = importLazy('tar'); +console.log('NpmLinkManager.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); +// import readPackageTree = require('read-package-tree'); +// eslint-disable-next-line +const readPackageTree = importLazy('read-package-tree'); +console.log('NpmLinkManager.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); import { FileSystem, FileConstants, LegacyAdapters } from '@rushstack/node-core-library'; +console.log('NpmLinkManager.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConstants } from '../../logic/RushConstants'; +console.log('NpmLinkManager.ts : 9: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfigurationProject } from '../../api/RushConfigurationProject'; +console.log('NpmLinkManager.ts : 10: ' + (new Date().getTime() % 20000) / 1000.0); import { Utilities } from '../../utilities/Utilities'; +console.log('NpmLinkManager.ts : 11: ' + (new Date().getTime() % 20000) / 1000.0); import { NpmPackage, IResolveOrCreateResult, PackageDependencyKind } from './NpmPackage'; +console.log('NpmLinkManager.ts : 12: ' + (new Date().getTime() % 20000) / 1000.0); import { PackageLookup } from '../PackageLookup'; +console.log('NpmLinkManager.ts : 13: ' + (new Date().getTime() % 20000) / 1000.0); import { BaseLinkManager, SymlinkKind } from '../base/BaseLinkManager'; +console.log('NpmLinkManager.ts : 14: ' + (new Date().getTime() % 20000) / 1000.0); interface IQueueItem { // A project from somewhere under "common/temp/node_modules" @@ -28,10 +49,21 @@ interface IQueueItem { cyclicSubtreeRoot: NpmPackage | undefined; } +interface readPackageTreeNode { + id: number; + package: any; + children: readPackageTreeNode[]; + parent: readPackageTreeNode | null; + path: string; + realpath: string; + error: Error | null; + isLink: boolean; +} + export class NpmLinkManager extends BaseLinkManager { protected async _linkProjects(): Promise { - const npmPackage: readPackageTree.Node = await LegacyAdapters.convertCallbackToPromise< - readPackageTree.Node, + const npmPackage: readPackageTreeNode = await LegacyAdapters.convertCallbackToPromise< + readPackageTreeNode, Error, string >(readPackageTree, this._rushConfiguration.commonTempFolder); diff --git a/apps/rush-lib/src/logic/pnpm/PnpmLinkManager.ts b/apps/rush-lib/src/logic/pnpm/PnpmLinkManager.ts index b3953512acc..1706ead0c67 100644 --- a/apps/rush-lib/src/logic/pnpm/PnpmLinkManager.ts +++ b/apps/rush-lib/src/logic/pnpm/PnpmLinkManager.ts @@ -1,22 +1,44 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +// eslint-disable-next-line +const importLazy = require('import-lazy')(require); + +console.log('PnpmLinkManager.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as os from 'os'; +console.log('PnpmLinkManager.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as path from 'path'; +console.log('PnpmLinkManager.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import uriEncode = require('strict-uri-encode'); -import pnpmLinkBins from '@pnpm/link-bins'; +console.log('PnpmLinkManager.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); + +// import pnpmLinkBins from '@pnpm/link-bins'; +// eslint-disable-next-line +const pnpmLinkBins = importLazy('@pnpm/link-bins'); + +console.log('PnpmLinkManager.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import * as semver from 'semver'; +console.log('PnpmLinkManager.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); import * as colors from 'colors'; +console.log('PnpmLinkManager.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); import { Text, FileSystem, FileConstants, InternalError } from '@rushstack/node-core-library'; +console.log('PnpmLinkManager.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); import { BaseLinkManager } from '../base/BaseLinkManager'; +console.log('PnpmLinkManager.ts : 9: ' + (new Date().getTime() % 20000) / 1000.0); import { BasePackage } from '../base/BasePackage'; +console.log('PnpmLinkManager.ts : 10: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConstants } from '../../logic/RushConstants'; +console.log('PnpmLinkManager.ts : 11: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfigurationProject } from '../../api/RushConfigurationProject'; +console.log('PnpmLinkManager.ts : 12: ' + (new Date().getTime() % 20000) / 1000.0); import { PnpmShrinkwrapFile, IPnpmShrinkwrapDependencyYaml } from './PnpmShrinkwrapFile'; +console.log('PnpmLinkManager.ts : 13: ' + (new Date().getTime() % 20000) / 1000.0); import { PnpmProjectDependencyManifest } from './PnpmProjectDependencyManifest'; +console.log('PnpmLinkManager.ts : 14: ' + (new Date().getTime() % 20000) / 1000.0); import { AlreadyReportedError } from '../../utilities/AlreadyReportedError'; +console.log('PnpmLinkManager.ts : 15: ' + (new Date().getTime() % 20000) / 1000.0); // special flag for debugging, will print extra diagnostic information, // but comes with performance cost diff --git a/apps/rush-lib/src/start.ts b/apps/rush-lib/src/start.ts index b4da75c1edc..334fa2a4e1f 100644 --- a/apps/rush-lib/src/start.ts +++ b/apps/rush-lib/src/start.ts @@ -1,6 +1,10 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +console.log('start.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); + import { Rush } from './api/Rush'; +console.log('start.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); Rush.launch(Rush.version, { isManaged: false }); +console.log('start.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); diff --git a/apps/rush-lib/src/utilities/Utilities.ts b/apps/rush-lib/src/utilities/Utilities.ts index 4b7e344c8ef..c05e96ee3b0 100644 --- a/apps/rush-lib/src/utilities/Utilities.ts +++ b/apps/rush-lib/src/utilities/Utilities.ts @@ -1,13 +1,18 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +// eslint-disable-next-line +const importLazy = require('import-lazy')(require); + import * as child_process from 'child_process'; import * as fs from 'fs'; import * as os from 'os'; import * as tty from 'tty'; import * as path from 'path'; import * as wordwrap from 'wordwrap'; -import { JsonFile, IPackageJson, FileSystem, FileConstants } from '@rushstack/node-core-library'; +// import { JsonFile, IPackageJson, FileSystem, FileConstants } from '@rushstack/node-core-library'; +// eslint-disable-next-line +const nodeCoreLibrary = importLazy('@rushstack/node-core-library'); import { RushConfiguration } from '../api/RushConfiguration'; import { Stream } from 'stream'; @@ -124,7 +129,7 @@ export class Utilities { throw new Error(dirError); } const homeFolder: string = path.resolve(unresolvedUserFolder); - if (!FileSystem.exists(homeFolder)) { + if (!nodeCoreLibrary.FileSystem.exists(homeFolder)) { throw new Error(dirError); } @@ -190,7 +195,7 @@ export class Utilities { } /** - * Creates the specified folder by calling FileSystem.ensureFolder(), but using a + * Creates the specified folder by calling nodeCoreLibrary.FileSystem.ensureFolder(), but using a * retry loop to recover from temporary locks that may be held by other processes. * If the folder already exists, no error occurs. */ @@ -209,7 +214,7 @@ export class Utilities { const maxWaitTimeMs: number = 7 * 1000; return Utilities.retryUntilTimeout( - () => FileSystem.ensureFolder(folderName), + () => nodeCoreLibrary.FileSystem.ensureFolder(folderName), maxWaitTimeMs, (e) => new Error( @@ -228,7 +233,7 @@ export class Utilities { let exists: boolean = false; try { - const lstat: fs.Stats = FileSystem.getLinkStatistics(filePath); + const lstat: fs.Stats = nodeCoreLibrary.FileSystem.getLinkStatistics(filePath); exists = lstat.isFile(); } catch (e) { /* no-op */ @@ -244,7 +249,7 @@ export class Utilities { let exists: boolean = false; try { - const lstat: fs.Stats = FileSystem.getLinkStatistics(directoryPath); + const lstat: fs.Stats = nodeCoreLibrary.FileSystem.getLinkStatistics(directoryPath); exists = lstat.isDirectory(); } catch (e) { /* no-op */ @@ -260,7 +265,7 @@ export class Utilities { */ public static dangerouslyDeletePath(folderPath: string): void { try { - FileSystem.deleteFolder(folderPath); + nodeCoreLibrary.FileSystem.deleteFolder(folderPath); } catch (e) { throw new Error( `${e.message}${os.EOL}Often this is caused by a file lock from a process ` + @@ -275,7 +280,7 @@ export class Utilities { public static deleteFile(filePath: string): void { if (Utilities.fileExists(filePath)) { console.log(`Deleting: ${filePath}`); - FileSystem.deleteFile(filePath); + nodeCoreLibrary.FileSystem.deleteFile(filePath); } } @@ -288,11 +293,11 @@ export class Utilities { */ public static isFileTimestampCurrent(dateToCompare: Date, inputFilenames: string[]): boolean { for (const inputFilename of inputFilenames) { - if (!FileSystem.exists(inputFilename)) { + if (!nodeCoreLibrary.FileSystem.exists(inputFilename)) { return false; } - const inputStats: fs.Stats = FileSystem.getStatistics(inputFilename); + const inputStats: fs.Stats = nodeCoreLibrary.FileSystem.getStatistics(inputFilename); if (dateToCompare < inputStats.mtime) { return false; } @@ -461,13 +466,13 @@ export class Utilities { */ public static installPackageInDirectory(options: IInstallPackageInDirectoryOptions): void { const directory: string = path.resolve(options.directory); - if (FileSystem.exists(directory)) { + if (nodeCoreLibrary.FileSystem.exists(directory)) { console.log('Deleting old files from ' + directory); } - FileSystem.ensureEmptyFolder(directory); + nodeCoreLibrary.FileSystem.ensureEmptyFolder(directory); - const npmPackageJson: IPackageJson = { + const npmPackageJson /*: IPackageJson*/ = { dependencies: { [options.packageName]: options.version }, @@ -476,7 +481,10 @@ export class Utilities { private: true, version: '0.0.0' }; - JsonFile.save(npmPackageJson, path.join(directory, FileConstants.PackageJson)); + nodeCoreLibrary.JsonFile.save( + npmPackageJson, + path.join(directory, nodeCoreLibrary.FileConstants.PackageJson) + ); if (options.commonRushConfigFolder) { Utilities.syncNpmrc(options.commonRushConfigFolder, directory); @@ -532,7 +540,7 @@ export class Utilities { */ public static copyAndTrimNpmrcFile(sourceNpmrcPath: string, targetNpmrcPath: string): void { console.log(`Copying ${sourceNpmrcPath} --> ${targetNpmrcPath}`); // Verbose - let npmrcFileLines: string[] = FileSystem.readFile(sourceNpmrcPath).split('\n'); + let npmrcFileLines: string[] = nodeCoreLibrary.FileSystem.readFile(sourceNpmrcPath).split('\n'); npmrcFileLines = npmrcFileLines.map((line) => (line || '').trim()); const resultLines: string[] = []; @@ -573,7 +581,7 @@ export class Utilities { } } - FileSystem.writeFile(targetNpmrcPath, resultLines.join(os.EOL)); + nodeCoreLibrary.FileSystem.writeFile(targetNpmrcPath, resultLines.join(os.EOL)); } /** @@ -581,14 +589,14 @@ export class Utilities { * If the source file does not exist, then the target file is deleted. */ public static syncFile(sourcePath: string, destinationPath: string): void { - if (FileSystem.exists(sourcePath)) { + if (nodeCoreLibrary.FileSystem.exists(sourcePath)) { console.log(`Updating ${destinationPath}`); - FileSystem.copyFile({ sourcePath, destinationPath }); + nodeCoreLibrary.FileSystem.copyFile({ sourcePath, destinationPath }); } else { - if (FileSystem.exists(destinationPath)) { + if (nodeCoreLibrary.FileSystem.exists(destinationPath)) { // If the source file doesn't exist and there is one in the target, delete the one in the target console.log(`Deleting ${destinationPath}`); - FileSystem.deleteFile(destinationPath); + nodeCoreLibrary.FileSystem.deleteFile(destinationPath); } } } @@ -610,12 +618,12 @@ export class Utilities { ); const targetNpmrcPath: string = path.join(targetNpmrcFolder, '.npmrc'); try { - if (FileSystem.exists(sourceNpmrcPath)) { + if (nodeCoreLibrary.FileSystem.exists(sourceNpmrcPath)) { Utilities.copyAndTrimNpmrcFile(sourceNpmrcPath, targetNpmrcPath); - } else if (FileSystem.exists(targetNpmrcPath)) { + } else if (nodeCoreLibrary.FileSystem.exists(targetNpmrcPath)) { // If the source .npmrc doesn't exist and there is one in the target, delete the one in the target console.log(`Deleting ${targetNpmrcPath}`); // Verbose - FileSystem.deleteFile(targetNpmrcPath); + nodeCoreLibrary.FileSystem.deleteFile(targetNpmrcPath); } } catch (e) { throw new Error(`Error syncing .npmrc file: ${e}`); diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index 405619f61e5..9a6f5ecd70f 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -225,6 +225,7 @@ importers: glob-escape: 0.0.2 https-proxy-agent: 2.2.4 ignore: 5.1.8 + import-lazy: 4.0.0 inquirer: 6.2.2 js-yaml: 3.13.1 jszip: 3.5.0 @@ -300,6 +301,7 @@ importers: gulp: ~4.0.2 https-proxy-agent: ~2.2.1 ignore: ~5.1.6 + import-lazy: ~4.0.0 inquirer: ~6.2.0 jest: ~25.4.0 js-yaml: ~3.13.1 @@ -1236,6 +1238,7 @@ importers: '@types/node': 10.17.13 colors: 1.2.5 fs-extra: 7.0.1 + import-lazy: 4.0.0 jju: 1.4.0 semver: 7.3.2 timsort: 0.3.0 @@ -1265,6 +1268,7 @@ importers: colors: ~1.2.1 fs-extra: ~7.0.1 gulp: ~4.0.2 + import-lazy: ~4.0.0 jju: ~1.4.0 semver: ~7.3.0 timsort: ~0.3.0 @@ -14096,3 +14100,4 @@ packages: commander: 2.20.3 resolution: integrity: sha512-DUOKC/IhbkdLKKiV89gw9DUauTV8U/8yJl1sjf6MtDmzevLKOF2duNJ495S3MFVjqZarr+qNGCPbkg4mu4PpLw== +registry: '' diff --git a/common/config/rush/repo-state.json b/common/config/rush/repo-state.json index cddf09f8d6c..c3ee4a3d9a3 100644 --- a/common/config/rush/repo-state.json +++ b/common/config/rush/repo-state.json @@ -1,5 +1,5 @@ // DO NOT MODIFY THIS FILE. It is generated and used by Rush. { - "pnpmShrinkwrapHash": "83a05a11e0d701d4be08ee3106d6ee25f86127b3", + "pnpmShrinkwrapHash": "8c870f5a94af8b340beb7dcdd3861915ca4544bc", "preferredVersionsHash": "334ea62b6a2798dcf80917b79555983377e7435e" } diff --git a/common/reviews/api/rush-lib.api.md b/common/reviews/api/rush-lib.api.md index 33c1044665d..c75cce47e5c 100644 --- a/common/reviews/api/rush-lib.api.md +++ b/common/reviews/api/rush-lib.api.md @@ -6,7 +6,6 @@ import { IPackageJson } from '@rushstack/node-core-library'; import { JsonObject } from '@rushstack/node-core-library'; -import { PackageNameParser } from '@rushstack/node-core-library'; // @public export class ApprovedPackagesConfiguration { @@ -247,7 +246,7 @@ export class PackageJsonEditor { // (undocumented) readonly filePath: string; // (undocumented) - static fromObject(object: IPackageJson, filename: string): PackageJsonEditor; + static fromObject(object: any, filename: string): PackageJsonEditor; // (undocumented) static load(filePath: string): PackageJsonEditor; // (undocumented) @@ -363,7 +362,7 @@ export class RushConfiguration { readonly packageManagerToolVersion: string; // @beta readonly packageManagerWrapper: PackageManager; - readonly packageNameParser: PackageNameParser; + readonly packageNameParser: any; readonly pnpmOptions: PnpmOptionsConfiguration; readonly projectFolderMaxDepth: number; readonly projectFolderMinDepth: number; @@ -406,7 +405,7 @@ export class RushConfigurationProject { readonly isMainProject: boolean; readonly localDependencyProjects: ReadonlyArray; // @deprecated - readonly packageJson: IPackageJson; + readonly packageJson: any; // @beta readonly packageJsonEditor: PackageJsonEditor; readonly packageName: string; diff --git a/common/reviews/api/ts-command-line.api.md b/common/reviews/api/ts-command-line.api.md index d07d9de07a7..85a482fd1fc 100644 --- a/common/reviews/api/ts-command-line.api.md +++ b/common/reviews/api/ts-command-line.api.md @@ -145,7 +145,7 @@ export abstract class CommandLineParser extends CommandLineParameterProvider { readonly toolDescription: string; readonly toolFilename: string; tryGetAction(actionName: string): CommandLineAction | undefined; -} + } // @public export class CommandLineRemainder { @@ -265,4 +265,6 @@ export interface ICommandLineStringListDefinition extends IBaseCommandLineDefini } +// (No @packageDocumentation comment for this package) + ``` diff --git a/libraries/node-core-library/package.json b/libraries/node-core-library/package.json index ab5f8e467c6..1cbc6b0ccfb 100644 --- a/libraries/node-core-library/package.json +++ b/libraries/node-core-library/package.json @@ -16,6 +16,7 @@ "colors": "~1.2.1", "fs-extra": "~7.0.1", "jju": "~1.4.0", + "import-lazy": "~4.0.0", "semver": "~7.3.0", "timsort": "~0.3.0", "z-schema": "~3.18.3" diff --git a/libraries/node-core-library/src/JsonSchema.ts b/libraries/node-core-library/src/JsonSchema.ts index 3a2214f9705..49d2e58c024 100644 --- a/libraries/node-core-library/src/JsonSchema.ts +++ b/libraries/node-core-library/src/JsonSchema.ts @@ -1,9 +1,13 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +// eslint-disable-next-line +const importLazy = require('import-lazy')(require); + import * as os from 'os'; import * as path from 'path'; -import Validator = require('z-schema'); +// eslint-disable-next-line +const Validator = importLazy('z-schema'); import { JsonFile, JsonObject } from './JsonFile'; import { FileSystem } from './FileSystem'; @@ -71,7 +75,8 @@ export interface IJsonSchemaFromFileOptions { export class JsonSchema { private _dependentSchemas: JsonSchema[] = []; private _filename: string = ''; - private _validator: Validator | undefined = undefined; + // eslint-disable-next-line + private _validator; private _schemaObject: JsonObject | undefined = undefined; private constructor() {} @@ -153,15 +158,18 @@ export class JsonSchema { /** * Used to nicely format the ZSchema error tree. */ - private static _formatErrorDetails(errorDetails: Validator.SchemaErrorDetail[]): string { + // eslint-disable-next-line + private static _formatErrorDetails(errorDetails /*: Validator.SchemaErrorDetail[]*/): string { return JsonSchema._formatErrorDetailsHelper(errorDetails, '', ''); } /** * Used by _formatErrorDetails. */ + // eslint-disable-next-line private static _formatErrorDetailsHelper( - errorDetails: Validator.SchemaErrorDetail[], + // eslint-disable-next-line + errorDetails /*: Validator.SchemaErrorDetail[]*/, indent: string, buffer: string ): string { @@ -218,7 +226,8 @@ export class JsonSchema { if (!this._validator) { // Don't assign this to _validator until we're sure everything was successful - const newValidator: Validator = new Validator({ + // eslint-disable-next-line + const newValidator = new Validator({ breakOnFirstError: false, noTypeless: true, noExtraKeywords: true @@ -285,6 +294,7 @@ export class JsonSchema { this.ensureCompiled(); if (!this._validator!.validate(jsonObject, this._schemaObject)) { + // eslint-disable-next-line const errorDetails: string = JsonSchema._formatErrorDetails(this._validator!.getLastErrors()); const args: IJsonSchemaErrorInfo = { diff --git a/libraries/ts-command-line/src/index.ts b/libraries/ts-command-line/src/index.ts index 169bc69e105..abbab30e94a 100644 --- a/libraries/ts-command-line/src/index.ts +++ b/libraries/ts-command-line/src/index.ts @@ -7,7 +7,9 @@ * @packageDocumentation */ +console.log('ts-command-line.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); export { CommandLineAction, ICommandLineActionOptions } from './providers/CommandLineAction'; +console.log('ts-command-line.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); export { IBaseCommandLineDefinition, @@ -20,26 +22,38 @@ export { ICommandLineRemainderDefinition } from './parameters/CommandLineDefinition'; +console.log('ts-command-line.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); export { CommandLineParameterKind, CommandLineParameter, CommandLineParameterWithArgument } from './parameters/BaseClasses'; +console.log('ts-command-line.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); export { CommandLineFlagParameter } from './parameters/CommandLineFlagParameter'; +console.log('ts-command-line.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); export { CommandLineStringParameter } from './parameters/CommandLineStringParameter'; +console.log('ts-command-line.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); export { CommandLineStringListParameter } from './parameters/CommandLineStringListParameter'; +console.log('ts-command-line.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); export { CommandLineIntegerParameter } from './parameters/CommandLineIntegerParameter'; +console.log('ts-command-line.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); export { CommandLineChoiceParameter } from './parameters/CommandLineChoiceParameter'; +console.log('ts-command-line.ts : 9: ' + (new Date().getTime() % 20000) / 1000.0); export { CommandLineRemainder } from './parameters/CommandLineRemainder'; +console.log('ts-command-line.ts : 10: ' + (new Date().getTime() % 20000) / 1000.0); export { CommandLineParameterProvider, ICommandLineParserData as _ICommandLineParserData } from './providers/CommandLineParameterProvider'; +console.log('ts-command-line.ts : 11: ' + (new Date().getTime() % 20000) / 1000.0); export { ICommandLineParserOptions, CommandLineParser } from './providers/CommandLineParser'; +console.log('ts-command-line.ts : 12: ' + (new Date().getTime() % 20000) / 1000.0); export { DynamicCommandLineAction } from './providers/DynamicCommandLineAction'; +console.log('ts-command-line.ts : 13: ' + (new Date().getTime() % 20000) / 1000.0); export { DynamicCommandLineParser } from './providers/DynamicCommandLineParser'; +console.log('ts-command-line.ts : 14: ' + (new Date().getTime() % 20000) / 1000.0); diff --git a/libraries/ts-command-line/src/providers/CommandLineAction.ts b/libraries/ts-command-line/src/providers/CommandLineAction.ts index a0bd8deb4d9..ef3842a9228 100644 --- a/libraries/ts-command-line/src/providers/CommandLineAction.ts +++ b/libraries/ts-command-line/src/providers/CommandLineAction.ts @@ -1,8 +1,11 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import * as argparse from 'argparse'; +console.log('CommandLineAction.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import { CommandLineParameterProvider, ICommandLineParserData } from './CommandLineParameterProvider'; +console.log('CommandLineAction.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); +import * as argparse from 'argparse'; +console.log('CommandLineAction.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); /** * Options for the CommandLineAction constructor. diff --git a/libraries/ts-command-line/src/providers/CommandLineParameterProvider.ts b/libraries/ts-command-line/src/providers/CommandLineParameterProvider.ts index 61378abc8ea..d306b7c7c99 100644 --- a/libraries/ts-command-line/src/providers/CommandLineParameterProvider.ts +++ b/libraries/ts-command-line/src/providers/CommandLineParameterProvider.ts @@ -1,7 +1,9 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +console.log('CommandLineParameterProvider.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as argparse from 'argparse'; +console.log('CommandLineParameterProvider.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import { ICommandLineFlagDefinition, ICommandLineStringDefinition, @@ -10,17 +12,25 @@ import { ICommandLineChoiceDefinition, ICommandLineRemainderDefinition } from '../parameters/CommandLineDefinition'; +console.log('CommandLineParameterProvider.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import { CommandLineParameter, CommandLineParameterWithArgument, CommandLineParameterKind } from '../parameters/BaseClasses'; +console.log('CommandLineParameterProvider.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { CommandLineFlagParameter } from '../parameters/CommandLineFlagParameter'; +console.log('CommandLineParameterProvider.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import { CommandLineStringParameter } from '../parameters/CommandLineStringParameter'; +console.log('CommandLineParameterProvider.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); import { CommandLineStringListParameter } from '../parameters/CommandLineStringListParameter'; +console.log('CommandLineParameterProvider.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); import { CommandLineIntegerParameter } from '../parameters/CommandLineIntegerParameter'; +console.log('CommandLineParameterProvider.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); import { CommandLineChoiceParameter } from '../parameters/CommandLineChoiceParameter'; +console.log('CommandLineParameterProvider.ts : 9: ' + (new Date().getTime() % 20000) / 1000.0); import { CommandLineRemainder } from '../parameters/CommandLineRemainder'; +console.log('CommandLineParameterProvider.ts : 10: ' + (new Date().getTime() % 20000) / 1000.0); /** * This is the argparse result data object From 1296b78bc63fa1eab5a7a330069d6677f6e28424 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Fri, 31 Jul 2020 18:22:20 -0700 Subject: [PATCH 28/97] Change _jsonSchema to a static getter --- .../src/api/ApprovedPackagesConfiguration.ts | 33 ++--- .../src/api/CommandLineConfiguration.ts | 6 +- .../src/api/CommonVersionsConfiguration.ts | 6 +- .../src/api/ExperimentsConfiguration.ts | 6 +- apps/rush-lib/src/api/PackageJsonEditor.ts | 29 ++-- apps/rush-lib/src/api/Rush.ts | 24 ++- apps/rush-lib/src/api/RushConfiguration.ts | 137 +++--------------- .../src/api/RushConfigurationProject.ts | 52 +++---- .../src/api/VersionPolicyConfiguration.ts | 24 +-- .../rush-lib/src/cli/RushCommandLineParser.ts | 63 ++------ apps/rush-lib/src/logic/RepoStateFile.ts | 25 +--- .../src/logic/deploy/DeployManager.ts | 125 +++++++--------- .../deploy/DeployScenarioConfiguration.ts | 6 +- apps/rush-lib/src/utilities/Utilities.ts | 54 +++---- common/reviews/api/rush-lib.api.md | 7 +- 15 files changed, 179 insertions(+), 418 deletions(-) diff --git a/apps/rush-lib/src/api/ApprovedPackagesConfiguration.ts b/apps/rush-lib/src/api/ApprovedPackagesConfiguration.ts index 9b09cb57612..8c0380b2e3a 100644 --- a/apps/rush-lib/src/api/ApprovedPackagesConfiguration.ts +++ b/apps/rush-lib/src/api/ApprovedPackagesConfiguration.ts @@ -1,23 +1,12 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line -const importLazy = require('import-lazy')(require); - -console.log('ApprovedPackagesConfiguration.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as path from 'path'; -console.log('ApprovedPackagesConfiguration.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as os from 'os'; -console.log('ApprovedPackagesConfiguration.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); -// import { JsonFile, JsonSchema, FileSystem, NewlineKind, InternalError } from '@rushstack/node-core-library'; -// eslint-disable-next-line -const nodeCoreLibrary = importLazy('@rushstack/node-core-library'); -console.log('ApprovedPackagesConfiguration.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); +import { JsonFile, JsonSchema, FileSystem, NewlineKind, InternalError } from '@rushstack/node-core-library'; import { Utilities } from '../utilities/Utilities'; -console.log('ApprovedPackagesConfiguration.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import { JsonSchemaUrls } from '../logic/JsonSchemaUrls'; -console.log('ApprovedPackagesConfiguration.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); /** * Part of IApprovedPackagesJson. @@ -58,11 +47,8 @@ export class ApprovedPackagesItem { * @public */ export class ApprovedPackagesConfiguration { - // eslint-disable-next-line - private static get _jsonSchema() { - return nodeCoreLibrary.JsonSchema.fromFile( - path.join(__dirname, '../schemas/approved-packages.schema.json') - ); + private static get _jsonSchema(): JsonSchema { + return JsonSchema.fromFile(path.join(__dirname, '../schemas/approved-packages.schema.json')); } public items: ApprovedPackagesItem[] = []; @@ -116,8 +102,7 @@ export class ApprovedPackagesConfiguration { * If the file exists, calls loadFromFile(). */ public tryLoadFromFile(approvedPackagesPolicyEnabled: boolean): boolean { - // eslint-disable-next-line - if (!nodeCoreLibrary.FileSystem.exists(this._jsonFilename)) { + if (!FileSystem.exists(this._jsonFilename)) { return false; } @@ -137,7 +122,7 @@ export class ApprovedPackagesConfiguration { * Loads the configuration data from the filename that was passed to the constructor. */ public loadFromFile(): void { - const approvedPackagesJson: IApprovedPackagesJson = nodeCoreLibrary.JsonFile.loadAndValidate( + const approvedPackagesJson: IApprovedPackagesJson = JsonFile.loadAndValidate( this._jsonFilename, ApprovedPackagesConfiguration._jsonSchema ); @@ -179,7 +164,7 @@ export class ApprovedPackagesConfiguration { } // Save the file - let body: string = nodeCoreLibrary.JsonFile.stringify(this._loadedJson); + let body: string = JsonFile.stringify(this._loadedJson); // Unindent the allowedCategories array to improve readability body = body.replace(/("allowedCategories": +\[)([^\]]+)/g, (substring: string, ...args: string[]) => { @@ -189,8 +174,8 @@ export class ApprovedPackagesConfiguration { // Add a header body = '// DO NOT ADD COMMENTS IN THIS FILE. They will be lost when the Rush tool resaves it.\n' + body; - nodeCoreLibrary.FileSystem.writeFile(this._jsonFilename, body, { - convertLineEndings: nodeCoreLibrary.NewlineKind.CrLf + FileSystem.writeFile(this._jsonFilename, body, { + convertLineEndings: NewlineKind.CrLf }); } @@ -222,7 +207,7 @@ export class ApprovedPackagesConfiguration { */ private _addItem(item: ApprovedPackagesItem): void { if (this._itemsByName.has(item.packageName)) { - throw new nodeCoreLibrary.InternalError('Duplicate key'); + throw new InternalError('Duplicate key'); } this.items.push(item); this._itemsByName.set(item.packageName, item); diff --git a/apps/rush-lib/src/api/CommandLineConfiguration.ts b/apps/rush-lib/src/api/CommandLineConfiguration.ts index 262656fbe10..6ebc9cdfa5f 100644 --- a/apps/rush-lib/src/api/CommandLineConfiguration.ts +++ b/apps/rush-lib/src/api/CommandLineConfiguration.ts @@ -13,9 +13,9 @@ import { CommandJson, ICommandLineJson, ParameterJson } from './CommandLineJson' * Custom Commands and Options for the Rush Command Line */ export class CommandLineConfiguration { - private static _jsonSchema: JsonSchema = JsonSchema.fromFile( - path.join(__dirname, '../schemas/command-line.schema.json') - ); + private static get _jsonSchema(): JsonSchema { + return JsonSchema.fromFile(path.join(__dirname, '../schemas/command-line.schema.json')); + } public readonly commands: CommandJson[] = []; public readonly parameters: ParameterJson[] = []; diff --git a/apps/rush-lib/src/api/CommonVersionsConfiguration.ts b/apps/rush-lib/src/api/CommonVersionsConfiguration.ts index 48b7c618a95..c659f24cac5 100644 --- a/apps/rush-lib/src/api/CommonVersionsConfiguration.ts +++ b/apps/rush-lib/src/api/CommonVersionsConfiguration.ts @@ -63,9 +63,9 @@ interface ICommonVersionsJson { * @public */ export class CommonVersionsConfiguration { - private static _jsonSchema: JsonSchema = JsonSchema.fromFile( - path.join(__dirname, '../schemas/common-versions.schema.json') - ); + private static get _jsonSchema(): JsonSchema { + return JsonSchema.fromFile(path.join(__dirname, '../schemas/common-versions.schema.json')); + } private _filePath: string; private _preferredVersions: ProtectableMap; diff --git a/apps/rush-lib/src/api/ExperimentsConfiguration.ts b/apps/rush-lib/src/api/ExperimentsConfiguration.ts index 1560a677e76..e5bee18035f 100644 --- a/apps/rush-lib/src/api/ExperimentsConfiguration.ts +++ b/apps/rush-lib/src/api/ExperimentsConfiguration.ts @@ -35,9 +35,9 @@ export interface IExperimentsJson { * @beta */ export class ExperimentsConfiguration { - private static _jsonSchema: JsonSchema = JsonSchema.fromFile( - path.resolve(__dirname, '..', 'schemas', 'experiments.schema.json') - ); + private static get _jsonSchema(): JsonSchema { + return JsonSchema.fromFile(path.resolve(__dirname, '..', 'schemas', 'experiments.schema.json')); + } private _experimentConfiguration: IExperimentsJson; private _jsonFileName: string; diff --git a/apps/rush-lib/src/api/PackageJsonEditor.ts b/apps/rush-lib/src/api/PackageJsonEditor.ts index 3a626fc9f78..a6a5c82e5fc 100644 --- a/apps/rush-lib/src/api/PackageJsonEditor.ts +++ b/apps/rush-lib/src/api/PackageJsonEditor.ts @@ -1,17 +1,9 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line -const importLazy = require('import-lazy')(require); - -console.log('PackageJsonEditor.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as semver from 'semver'; -console.log('PackageJsonEditor.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); -// import { IPackageJson, JsonFile, Sort } from '@rushstack/node-core-library'; -// eslint-disable-next-line -const nodeCoreLibrary = importLazy('@rushstack/node-core-library'); -console.log('PackageJsonEditor.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); +import { IPackageJson, JsonFile, Sort } from '@rushstack/node-core-library'; /** * @beta @@ -65,7 +57,7 @@ export class PackageJsonDependency { */ export class PackageJsonEditor { private readonly _filePath: string; - private readonly _data; + private readonly _data: IPackageJson; private readonly _dependencies: Map; // NOTE: The "devDependencies" section is tracked separately because sometimes people @@ -75,8 +67,7 @@ export class PackageJsonEditor { private readonly _devDependencies: Map; private _modified: boolean; - // eslint-disable-next-line - private constructor(filepath: string, data /* IPackageJson */) { + private constructor(filepath: string, data: IPackageJson) { this._filePath = filepath; this._data = data; this._modified = false; @@ -149,19 +140,18 @@ export class PackageJsonEditor { ); }); - nodeCoreLibrary.Sort.sortMapKeys(this._dependencies); - nodeCoreLibrary.Sort.sortMapKeys(this._devDependencies); + Sort.sortMapKeys(this._dependencies); + Sort.sortMapKeys(this._devDependencies); } catch (e) { throw new Error(`Error loading "${filepath}": ${e.message}`); } } public static load(filePath: string): PackageJsonEditor { - return new PackageJsonEditor(filePath, nodeCoreLibrary.JsonFile.load(filePath)); + return new PackageJsonEditor(filePath, JsonFile.load(filePath)); } - // eslint-disable-next-line - public static fromObject(object /* IPackageJson */, filename: string): PackageJsonEditor { + public static fromObject(object: IPackageJson, filename: string): PackageJsonEditor { return new PackageJsonEditor(filename, object); } @@ -227,7 +217,7 @@ export class PackageJsonEditor { public saveIfModified(): boolean { if (this._modified) { - nodeCoreLibrary.JsonFile.save(this._normalize(), this._filePath, { updateExistingFile: true }); + JsonFile.save(this._normalize(), this._filePath, { updateExistingFile: true }); this._modified = false; return true; } @@ -238,8 +228,7 @@ export class PackageJsonEditor { this._modified = true; } - // eslint-disable-next-line - private _normalize() /* IPackageJson */ { + private _normalize(): IPackageJson { delete this._data.dependencies; delete this._data.optionalDependencies; delete this._data.peerDependencies; diff --git a/apps/rush-lib/src/api/Rush.ts b/apps/rush-lib/src/api/Rush.ts index d15a8ff4a8f..49f20ef0dab 100644 --- a/apps/rush-lib/src/api/Rush.ts +++ b/apps/rush-lib/src/api/Rush.ts @@ -1,19 +1,14 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line -const importLazy = require('import-lazy')(require); - console.log('Rush.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import { EOL } from 'os'; console.log('Rush.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as colors from 'colors'; console.log('Rush.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); -// import { PackageJsonLookup } from '@rushstack/node-core-library'; -// eslint-disable-next-line -const nodeCoreLibrary = importLazy('@rushstack/node-core-library'); - +import { PackageJsonLookup } from '@rushstack/node-core-library'; console.log('Rush.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); + import { RushCommandLineParser } from '../cli/RushCommandLineParser'; console.log('Rush.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConstants } from '../logic/RushConstants'; @@ -23,9 +18,9 @@ console.log('Rush.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); import { CommandLineMigrationAdvisor } from '../cli/CommandLineMigrationAdvisor'; console.log('Rush.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); import { NodeJsCompatibility } from '../logic/NodeJsCompatibility'; -console.log('Rush.ts : 9: ' + (new Date().getTime() % 20000) / 1000.0); +console.log('Rush.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); import { Utilities } from '../utilities/Utilities'; -console.log('Rush.ts : 10: ' + (new Date().getTime() % 20000) / 1000.0); +console.log('Rush.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); /** * Options to pass to the rush "launch" functions. @@ -67,25 +62,28 @@ export class Rush { * Even though this API isn't documented, it is still supported for legacy compatibility. */ public static launch(launcherVersion: string, arg: ILaunchOptions): void { - console.log('Rush.launch : 1: ' + (new Date().getTime() % 20000) / 1000.0); + console.log('Rush.launch() : 1: ' + (new Date().getTime() % 20000) / 1000.0); const options: ILaunchOptions = Rush._normalizeLaunchOptions(arg); + console.log('Rush.launch() : 2: ' + (new Date().getTime() % 20000) / 1000.0); if (!Utilities.isNonDebugTabCompletionRequest()) { Rush._printStartupBanner(options.isManaged); } + console.log('Rush.launch() : 3: ' + (new Date().getTime() % 20000) / 1000.0); if (!CommandLineMigrationAdvisor.checkArgv(process.argv)) { // The migration advisor recognized an obsolete command-line process.exitCode = 1; return; } + console.log('Rush.launch() : 4: ' + (new Date().getTime() % 20000) / 1000.0); const parser: RushCommandLineParser = new RushCommandLineParser({ alreadyReportedNodeTooNewError: options.alreadyReportedNodeTooNewError }); - console.log('Rush.launch : 2: ' + (new Date().getTime() % 20000) / 1000.0); + console.log('Rush.launch() : 5: ' + (new Date().getTime() % 20000) / 1000.0); parser.execute().catch(console.error); // CommandLineParser.execute() should never reject the promise - console.log('Rush.launch : 3: ' + (new Date().getTime() % 20000) / 1000.0); + console.log('Rush.launch() : 6: ' + (new Date().getTime() % 20000) / 1000.0); } /** @@ -108,7 +106,7 @@ export class Rush { * This is the same as the Rush tool version for that release. */ public static get version(): string { - return nodeCoreLibrary.PackageJsonLookup.loadOwnPackageJson(__dirname).version; + return PackageJsonLookup.loadOwnPackageJson(__dirname).version; } /** diff --git a/apps/rush-lib/src/api/RushConfiguration.ts b/apps/rush-lib/src/api/RushConfiguration.ts index 57a8d085811..64ece23f18c 100644 --- a/apps/rush-lib/src/api/RushConfiguration.ts +++ b/apps/rush-lib/src/api/RushConfiguration.ts @@ -3,57 +3,28 @@ /* eslint max-lines: off */ -// eslint-disable-next-line -const importLazy = require('import-lazy')(require); - -console.log('RushConfiguration.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as path from 'path'; -console.log('RushConfiguration.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as fs from 'fs'; -console.log('RushConfiguration.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); -// eslint-disable-next-line -const semver = importLazy('semver'); -console.log('RushConfiguration.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); -// import { JsonFile, JsonSchema, Path, FileSystem, PackageNameParser } from '@rushstack/node-core-library'; -// eslint-disable-next-line -const nodeCoreLibrary = importLazy('@rushstack/node-core-library'); - -console.log('RushConfiguration.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); +import * as semver from 'semver'; +import { JsonFile, JsonSchema, Path, FileSystem, PackageNameParser } from '@rushstack/node-core-library'; import { trueCasePathSync } from 'true-case-path'; -console.log('RushConfiguration.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); import { Rush } from '../api/Rush'; -console.log('RushConfiguration.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfigurationProject, IRushConfigurationProjectJson } from './RushConfigurationProject'; -console.log('RushConfiguration.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConstants } from '../logic/RushConstants'; -console.log('RushConfiguration.ts : 9: ' + (new Date().getTime() % 20000) / 1000.0); import { ApprovedPackagesPolicy } from './ApprovedPackagesPolicy'; -console.log('RushConfiguration.ts : 10: ' + (new Date().getTime() % 20000) / 1000.0); import { EventHooks } from './EventHooks'; -console.log('RushConfiguration.ts : 11: ' + (new Date().getTime() % 20000) / 1000.0); import { VersionPolicyConfiguration } from './VersionPolicyConfiguration'; -console.log('RushConfiguration.ts : 12: ' + (new Date().getTime() % 20000) / 1000.0); import { EnvironmentConfiguration } from './EnvironmentConfiguration'; -console.log('RushConfiguration.ts : 13: ' + (new Date().getTime() % 20000) / 1000.0); import { CommonVersionsConfiguration } from './CommonVersionsConfiguration'; -console.log('RushConfiguration.ts : 14: ' + (new Date().getTime() % 20000) / 1000.0); import { Utilities } from '../utilities/Utilities'; -console.log('RushConfiguration.ts : 15: ' + (new Date().getTime() % 20000) / 1000.0); import { PackageManagerName, PackageManager } from './packageManager/PackageManager'; -console.log('RushConfiguration.ts : 16: ' + (new Date().getTime() % 20000) / 1000.0); import { NpmPackageManager } from './packageManager/NpmPackageManager'; -console.log('RushConfiguration.ts : 17: ' + (new Date().getTime() % 20000) / 1000.0); import { YarnPackageManager } from './packageManager/YarnPackageManager'; -console.log('RushConfiguration.ts : 18: ' + (new Date().getTime() % 20000) / 1000.0); import { PnpmPackageManager } from './packageManager/PnpmPackageManager'; -console.log('RushConfiguration.ts : 19: ' + (new Date().getTime() % 20000) / 1000.0); import { ExperimentsConfiguration } from './ExperimentsConfiguration'; -console.log('RushConfiguration.ts : 20: ' + (new Date().getTime() % 20000) / 1000.0); import { PackageNameParsers } from './PackageNameParsers'; -console.log('RushConfiguration.ts : 21: ' + (new Date().getTime() % 20000) / 1000.0); import { RepoStateFile } from '../logic/RepoStateFile'; -console.log('RushConfiguration.ts : 22: ' + (new Date().getTime() % 20000) / 1000.0); const MINIMUM_SUPPORTED_RUSH_JSON_VERSION: string = '0.0.0'; const DEFAULT_BRANCH: string = 'master'; @@ -452,10 +423,9 @@ export type ResolutionStrategy = 'fewer-dependencies' | 'fast'; * @public */ export class RushConfiguration { - // eslint-disable-next-line - private static _jsonSchema = nodeCoreLibrary.JsonSchema.fromFile( - path.join(__dirname, '../schemas/rush.schema.json') - ); + private static get _jsonSchema(): JsonSchema { + return JsonSchema.fromFile(path.join(__dirname, '../schemas/rush.schema.json')); + } private _rushJsonFile: string; private _rushJsonFolder: string; @@ -508,7 +478,7 @@ export class RushConfiguration { // Rush hooks private _eventHooks: EventHooks; - private readonly _packageNameParser: any; + private readonly _packageNameParser: PackageNameParser; private _telemetryEnabled: boolean; @@ -523,29 +493,21 @@ export class RushConfiguration { * instead. */ private constructor(rushConfigurationJson: IRushConfigurationJson, rushJsonFilename: string) { - console.log('RushConfiguration.constructor() : 1: ' + (new Date().getTime() % 20000) / 1000.0); EnvironmentConfiguration.initialize(); - console.log('RushConfiguration.constructor() : 2: ' + (new Date().getTime() % 20000) / 1000.0); if (rushConfigurationJson.nodeSupportedVersionRange) { - console.log('RushConfiguration.constructor() : 3: ' + (new Date().getTime() % 20000) / 1000.0); if (!semver.validRange(rushConfigurationJson.nodeSupportedVersionRange)) { - console.log('RushConfiguration.constructor() : 4: ' + (new Date().getTime() % 20000) / 1000.0); throw new Error( 'Error parsing the node-semver expression in the "nodeSupportedVersionRange"' + ` field from rush.json: "${rushConfigurationJson.nodeSupportedVersionRange}"` ); } - console.log('RushConfiguration.constructor() : 5: ' + (new Date().getTime() % 20000) / 1000.0); if (!semver.satisfies(process.version, rushConfigurationJson.nodeSupportedVersionRange)) { - console.log('RushConfiguration.constructor() : 6: ' + (new Date().getTime() % 20000) / 1000.0); const message: string = `Your dev environment is running Node.js version ${process.version} which does` + ` not meet the requirements for building this repository. (The rush.json configuration` + ` requires nodeSupportedVersionRange="${rushConfigurationJson.nodeSupportedVersionRange}")`; - console.log('RushConfiguration.constructor() : 7: ' + (new Date().getTime() % 20000) / 1000.0); if (EnvironmentConfiguration.allowUnsupportedNodeVersion) { - console.log('RushConfiguration.constructor() : 8: ' + (new Date().getTime() % 20000) / 1000.0); console.warn(message); } else { throw new Error(message); @@ -553,62 +515,43 @@ export class RushConfiguration { } } - console.log('RushConfiguration.constructor() : 9: ' + (new Date().getTime() % 20000) / 1000.0); this._rushJsonFile = rushJsonFilename; - console.log('RushConfiguration.constructor() : 10: ' + (new Date().getTime() % 20000) / 1000.0); this._rushJsonFolder = path.dirname(rushJsonFilename); - console.log('RushConfiguration.constructor() : 11: ' + (new Date().getTime() % 20000) / 1000.0); this._commonFolder = path.resolve(path.join(this._rushJsonFolder, RushConstants.commonFolderName)); - console.log('RushConfiguration.constructor() : 12: ' + (new Date().getTime() % 20000) / 1000.0); this._commonRushConfigFolder = path.join(this._commonFolder, 'config', 'rush'); - console.log('RushConfiguration.constructor() : 13: ' + (new Date().getTime() % 20000) / 1000.0); this._commonTempFolder = EnvironmentConfiguration.rushTempFolderOverride || path.join(this._commonFolder, RushConstants.rushTempFolderName); - console.log('RushConfiguration.constructor() : 14: ' + (new Date().getTime() % 20000) / 1000.0); this._commonScriptsFolder = path.join(this._commonFolder, 'scripts'); - console.log('RushConfiguration.constructor() : 15: ' + (new Date().getTime() % 20000) / 1000.0); this._npmCacheFolder = path.resolve(path.join(this._commonTempFolder, 'npm-cache')); - console.log('RushConfiguration.constructor() : 16: ' + (new Date().getTime() % 20000) / 1000.0); this._npmTmpFolder = path.resolve(path.join(this._commonTempFolder, 'npm-tmp')); - console.log('RushConfiguration.constructor() : 17: ' + (new Date().getTime() % 20000) / 1000.0); this._yarnCacheFolder = path.resolve(path.join(this._commonTempFolder, 'yarn-cache')); - console.log('RushConfiguration.constructor() : 18: ' + (new Date().getTime() % 20000) / 1000.0); this._changesFolder = path.join(this._commonFolder, RushConstants.changeFilesFolderName); - console.log('RushConfiguration.constructor() : 19: ' + (new Date().getTime() % 20000) / 1000.0); this._currentVariantJsonFilename = path.join(this._commonTempFolder, 'current-variant.json'); - console.log('RushConfiguration.constructor() : 20: ' + (new Date().getTime() % 20000) / 1000.0); this._suppressNodeLtsWarning = !!rushConfigurationJson.suppressNodeLtsWarning; - console.log('RushConfiguration.constructor() : 21: ' + (new Date().getTime() % 20000) / 1000.0); this._ensureConsistentVersions = !!rushConfigurationJson.ensureConsistentVersions; - console.log('RushConfiguration.constructor() : 22: ' + (new Date().getTime() % 20000) / 1000.0); const experimentsConfigFile: string = path.join( this._commonRushConfigFolder, RushConstants.experimentsFilename ); - console.log('RushConfiguration.constructor() : 23: ' + (new Date().getTime() % 20000) / 1000.0); this._experimentsConfiguration = new ExperimentsConfiguration(experimentsConfigFile); - console.log('RushConfiguration.constructor() : 24: ' + (new Date().getTime() % 20000) / 1000.0); this._npmOptions = new NpmOptionsConfiguration(rushConfigurationJson.npmOptions || {}); - console.log('RushConfiguration.constructor() : 25: ' + (new Date().getTime() % 20000) / 1000.0); this._pnpmOptions = new PnpmOptionsConfiguration( rushConfigurationJson.pnpmOptions || {}, this._commonTempFolder ); - console.log('RushConfiguration.constructor() : 26: ' + (new Date().getTime() % 20000) / 1000.0); this._yarnOptions = new YarnOptionsConfiguration(rushConfigurationJson.yarnOptions || {}); - console.log('RushConfiguration.constructor() : 27: ' + (new Date().getTime() % 20000) / 1000.0); // TODO: Add an actual "packageManager" field in rush.json const packageManagerFields: string[] = []; @@ -647,9 +590,7 @@ export class RushConfiguration { this._packageManagerWrapper = new NpmPackageManager(this._packageManagerToolVersion); } else if (this._packageManager === 'pnpm') { this._packageManagerToolVersion = rushConfigurationJson.pnpmVersion!; - console.log('RushConfiguration.constructor() : 28: ' + (new Date().getTime() % 20000) / 1000.0); this._packageManagerWrapper = new PnpmPackageManager(this._packageManagerToolVersion); - console.log('RushConfiguration.constructor() : 29: ' + (new Date().getTime() % 20000) / 1000.0); } else { this._packageManagerToolVersion = rushConfigurationJson.yarnVersion!; this._packageManagerWrapper = new YarnPackageManager(this._packageManagerToolVersion); @@ -675,13 +616,11 @@ export class RushConfiguration { parsedPath.name + '-preinstall' + parsedPath.ext ); - console.log('RushConfiguration.constructor() : 30: ' + (new Date().getTime() % 20000) / 1000.0); RushConfiguration._validateCommonRushConfigFolder( this._commonRushConfigFolder, this.packageManager, this._shrinkwrapFilename ); - console.log('RushConfiguration.constructor() : 31: ' + (new Date().getTime() % 20000) / 1000.0); this._projectFolderMinDepth = rushConfigurationJson.projectFolderMinDepth !== undefined @@ -704,9 +643,7 @@ export class RushConfiguration { ? PackageNameParsers.mostlyStandard : PackageNameParsers.rushDefault; - console.log('RushConfiguration.constructor() : 32: ' + (new Date().getTime() % 20000) / 1000.0); this._approvedPackagesPolicy = new ApprovedPackagesPolicy(this, rushConfigurationJson); - console.log('RushConfiguration.constructor() : 33: ' + (new Date().getTime() % 20000) / 1000.0); this._gitAllowedEmailRegExps = []; this._gitSampleEmail = ''; @@ -829,31 +766,13 @@ export class RushConfiguration { * an RushConfiguration object. */ public static loadFromConfigurationFile(rushJsonFilename: string): RushConfiguration { - console.log( - 'RushConfiguration.loadFromConfigurationFile() : 1: ' + (new Date().getTime() % 20000) / 1000.0 - ); let resolvedRushJsonFilename: string = path.resolve(rushJsonFilename); - // Load the rush.json before we fix the casing. If the case is wrong on a case-sensitive filesystem, // the next line show throw. - console.log( - 'RushConfiguration.loadFromConfigurationFile() : 2: ' + (new Date().getTime() % 20000) / 1000.0 - ); - const rushConfigurationJson: IRushConfigurationJson = nodeCoreLibrary.JsonFile.load( - resolvedRushJsonFilename - ); - console.log( - 'RushConfiguration.loadFromConfigurationFile() : 3: ' + (new Date().getTime() % 20000) / 1000.0 - ); + const rushConfigurationJson: IRushConfigurationJson = JsonFile.load(resolvedRushJsonFilename); try { - console.log( - 'RushConfiguration.loadFromConfigurationFile() : 4: ' + (new Date().getTime() % 20000) / 1000.0 - ); resolvedRushJsonFilename = trueCasePathSync(resolvedRushJsonFilename); - console.log( - 'RushConfiguration.loadFromConfigurationFile() : 5: ' + (new Date().getTime() % 20000) / 1000.0 - ); } catch (error) { /* ignore errors from true-case-path */ } @@ -863,17 +782,11 @@ export class RushConfiguration { // but we'll validate anyway. const expectedRushVersion: string = rushConfigurationJson.rushVersion; - console.log( - 'RushConfiguration.loadFromConfigurationFile() : 6: ' + (new Date().getTime() % 20000) / 1000.0 - ); const rushJsonBaseName: string = path.basename(resolvedRushJsonFilename); // If the version is missing or malformed, fall through and let the schema handle it. if (expectedRushVersion && semver.valid(expectedRushVersion)) { // Make sure the requested version isn't too old - console.log( - 'RushConfiguration.loadFromConfigurationFile() : 7: ' + (new Date().getTime() % 20000) / 1000.0 - ); if (semver.lt(expectedRushVersion, MINIMUM_SUPPORTED_RUSH_JSON_VERSION)) { throw new Error( `${rushJsonBaseName} is version ${expectedRushVersion}, which is too old for this tool. ` + @@ -888,17 +801,11 @@ export class RushConfiguration { // // IMPORTANT: Whenever a breaking change is introduced for one of the config files, we must // increment the minor version number for Rush. - console.log( - 'RushConfiguration.loadFromConfigurationFile() : 8: ' + (new Date().getTime() % 20000) / 1000.0 - ); if ( semver.major(Rush.version) !== semver.major(expectedRushVersion) || semver.minor(Rush.version) !== semver.minor(expectedRushVersion) ) { // If the major/minor are different, then make sure it's an older version. - console.log( - 'RushConfiguration.loadFromConfigurationFile() : 9: ' + (new Date().getTime() % 20000) / 1000.0 - ); if (semver.lt(Rush.version, expectedRushVersion)) { throw new Error( `Unable to load ${rushJsonBaseName} because its RushVersion is` + @@ -909,14 +816,8 @@ export class RushConfiguration { } } - console.log( - 'RushConfiguration.loadFromConfigurationFile() : 10: ' + (new Date().getTime() % 20000) / 1000.0 - ); RushConfiguration._jsonSchema.validateObject(rushConfigurationJson, resolvedRushJsonFilename); - console.log( - 'RushConfiguration.loadFromConfigurationFile() : 11: ' + (new Date().getTime() % 20000) / 1000.0 - ); return new RushConfiguration(rushConfigurationJson, resolvedRushJsonFilename); } @@ -942,7 +843,7 @@ export class RushConfiguration { for (let i: number = 0; i < 10; ++i) { const rushJsonFilename: string = path.join(currentFolder, 'rush.json'); - if (nodeCoreLibrary.FileSystem.exists(rushJsonFilename)) { + if (FileSystem.exists(rushJsonFilename)) { if (i > 0 && verbose) { console.log('Found configuration in ' + rushJsonFilename); } @@ -1011,17 +912,15 @@ export class RushConfiguration { packageManager: PackageManagerName, shrinkwrapFilename: string ): void { - if (!nodeCoreLibrary.FileSystem.exists(commonRushConfigFolder)) { + if (!FileSystem.exists(commonRushConfigFolder)) { console.log(`Creating folder: ${commonRushConfigFolder}`); - nodeCoreLibrary.FileSystem.ensureFolder(commonRushConfigFolder); + FileSystem.ensureFolder(commonRushConfigFolder); return; } - for (const filename of nodeCoreLibrary.FileSystem.readFolder(commonRushConfigFolder)) { + for (const filename of FileSystem.readFolder(commonRushConfigFolder)) { // Ignore things that aren't actual files - const stat: fs.Stats = nodeCoreLibrary.FileSystem.getLinkStatistics( - path.join(commonRushConfigFolder, filename) - ); + const stat: fs.Stats = FileSystem.getLinkStatistics(path.join(commonRushConfigFolder, filename)); if (!stat.isFile() && !stat.isSymbolicLink()) { continue; } @@ -1060,7 +959,7 @@ export class RushConfiguration { commonRushConfigFolder, RushConstants.pinnedVersionsFilename ); - if (nodeCoreLibrary.FileSystem.exists(pinnedVersionsFilename)) { + if (FileSystem.exists(pinnedVersionsFilename)) { throw new Error( 'The "pinned-versions.json" config file is no longer supported;' + ' please move your settings to the "preferredVersions" field of a "common-versions.json" config file.' + @@ -1498,10 +1397,8 @@ export class RushConfiguration { public get currentInstalledVariant(): string | undefined { let variant: string | undefined; - if (nodeCoreLibrary.FileSystem.exists(this._currentVariantJsonFilename)) { - const currentVariantJson: ICurrentVariantJson = nodeCoreLibrary.JsonFile.load( - this._currentVariantJsonFilename - ); + if (FileSystem.exists(this._currentVariantJsonFilename)) { + const currentVariantJson: ICurrentVariantJson = JsonFile.load(this._currentVariantJsonFilename); variant = currentVariantJson.variant || undefined; } @@ -1520,7 +1417,7 @@ export class RushConfiguration { /** * The rush hooks. It allows customized scripts to run at the specified point. */ - public get packageNameParser(): any { + public get packageNameParser(): PackageNameParser { return this._packageNameParser; } @@ -1675,7 +1572,7 @@ export class RushConfiguration { public tryGetProjectForPath(currentFolderPath: string): RushConfigurationProject | undefined { const resolvedPath: string = path.resolve(currentFolderPath); for (const project of this.projects) { - if (nodeCoreLibrary.Path.isUnderOrEqual(resolvedPath, project.projectFolder)) { + if (Path.isUnderOrEqual(resolvedPath, project.projectFolder)) { return project; } } diff --git a/apps/rush-lib/src/api/RushConfigurationProject.ts b/apps/rush-lib/src/api/RushConfigurationProject.ts index d04933a9714..898d1cc2cd5 100644 --- a/apps/rush-lib/src/api/RushConfigurationProject.ts +++ b/apps/rush-lib/src/api/RushConfigurationProject.ts @@ -1,40 +1,22 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line -const importLazy = require('import-lazy')(require); - -console.log('RushConfigurationProject.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as path from 'path'; -console.log('RushConfigurationProject.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as semver from 'semver'; -console.log('RushConfigurationProject.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); - -// import { -// JsonFile, -// IPackageJson, -// FileSystem, -// FileConstants, -// IPackageJsonDependencyTable -// } from '@rushstack/node-core-library'; -// eslint-disable-next-line -const nodeCoreLibrary = importLazy('@rushstack/node-core-library'); -console.log('RushConfigurationProject.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); +import { + JsonFile, + IPackageJson, + FileSystem, + FileConstants, + IPackageJsonDependencyTable +} from '@rushstack/node-core-library'; import { RushConfiguration } from '../api/RushConfiguration'; -console.log('RushConfigurationProject.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import { VersionPolicy, LockStepVersionPolicy } from './VersionPolicy'; -console.log('RushConfigurationProject.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); import { PackageJsonEditor } from './PackageJsonEditor'; -console.log('RushConfigurationProject.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConstants } from '../logic/RushConstants'; -console.log('RushConfigurationProject.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); import { PackageNameParsers } from './PackageNameParsers'; -console.log('RushConfigurationProject.ts : 9: ' + (new Date().getTime() % 20000) / 1000.0); import { DependencySpecifier, DependencySpecifierType } from '../logic/DependencySpecifier'; -// eslint-disable-next-line -// const depSpecifier = importLazy('../logic/DependencySpecifier'); -console.log('RushConfigurationProject.ts : 10: ' + (new Date().getTime() % 20000) / 1000.0); /** * This represents the JSON data object for a project entry in the rush.json configuration file. @@ -60,7 +42,7 @@ export class RushConfigurationProject { private _projectRelativeFolder: string; private _projectRushTempFolder: string; private _reviewCategory: string; - private _packageJson: any; + private _packageJson: IPackageJson; private _packageJsonEditor: PackageJsonEditor; private _tempProjectName: string; private _unscopedTempProjectName: string; @@ -102,7 +84,7 @@ export class RushConfigurationProject { this._projectFolder = path.join(rushConfiguration.rushJsonFolder, projectJson.projectFolder); - if (!nodeCoreLibrary.FileSystem.exists(this._projectFolder)) { + if (!FileSystem.exists(this._projectFolder)) { throw new Error(`Project folder not found: ${projectJson.projectFolder}`); } @@ -131,8 +113,8 @@ export class RushConfigurationProject { this._reviewCategory = projectJson.reviewCategory; } - const packageJsonFilename: string = path.join(this._projectFolder, 'package.json'); - this._packageJson = nodeCoreLibrary.JsonFile.load(packageJsonFilename); + const packageJsonFilename: string = path.join(this._projectFolder, FileConstants.PackageJson); + this._packageJson = JsonFile.load(packageJsonFilename); if (this._packageJson.name !== this._packageName) { throw new Error( @@ -250,7 +232,7 @@ export class RushConfigurationProject { * The parsed NPM "package.json" file from projectFolder. * @deprecated Use packageJsonEditor instead */ - public get packageJson(): any { + public get packageJson(): IPackageJson { return this._packageJson; } @@ -345,7 +327,9 @@ export class RushConfigurationProject { return isMain; } - private _getLocalDependencyProjects(dependencies: any = {}): RushConfigurationProject[] { + private _getLocalDependencyProjects( + dependencies: IPackageJsonDependencyTable = {} + ): RushConfigurationProject[] { const localDependencyProjects: RushConfigurationProject[] = []; for (const dependency of Object.keys(dependencies)) { // Skip if we can't find the local project or it's a cyclic dependency @@ -354,8 +338,10 @@ export class RushConfigurationProject { ); if (localProject && !this._cyclicDependencyProjects.has(dependency)) { // Set the value if it's a workspace project, or if we have a local project and the semver is satisfied - // eslint-disable-next-line - const dependencySpecifier = new DependencySpecifier(dependency, dependencies[dependency]); + const dependencySpecifier: DependencySpecifier = new DependencySpecifier( + dependency, + dependencies[dependency] + ); switch (dependencySpecifier.specifierType) { case DependencySpecifierType.Version: case DependencySpecifierType.Range: diff --git a/apps/rush-lib/src/api/VersionPolicyConfiguration.ts b/apps/rush-lib/src/api/VersionPolicyConfiguration.ts index 04782eabde6..8dbca789495 100644 --- a/apps/rush-lib/src/api/VersionPolicyConfiguration.ts +++ b/apps/rush-lib/src/api/VersionPolicyConfiguration.ts @@ -1,21 +1,11 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line -const importLazy = require('import-lazy')(require); - -console.log('VersionPolicyConfiguration.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as path from 'path'; -console.log('VersionPolicyConfiguration.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); -// import { JsonFile, JsonSchema, FileSystem } from '@rushstack/node-core-library'; -// eslint-disable-next-line -const nodeCoreLibrary = importLazy('@rushstack/node-core-library'); -console.log('VersionPolicyConfiguration.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); +import { JsonFile, JsonSchema, FileSystem } from '@rushstack/node-core-library'; import { VersionPolicy, BumpType, LockStepVersionPolicy } from './VersionPolicy'; -console.log('VersionPolicyConfiguration.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfigurationProject } from './RushConfigurationProject'; -console.log('VersionPolicyConfiguration.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); /** * @beta @@ -74,10 +64,8 @@ export interface IVersionPolicyDependencyJson { * @beta */ export class VersionPolicyConfiguration { - private static get _jsonSchema() /* NodeCoreLibrary.JsonSchema */ { - return nodeCoreLibrary.JsonSchema.fromFile( - path.join(__dirname, '../schemas/version-policies.schema.json') - ); + private static get _jsonSchema(): JsonSchema { + return JsonSchema.fromFile(path.join(__dirname, '../schemas/version-policies.schema.json')); } private _versionPolicies: Map; @@ -176,10 +164,10 @@ export class VersionPolicyConfiguration { } private _loadFile(): void { - if (!nodeCoreLibrary.FileSystem.exists(this._jsonFileName)) { + if (!FileSystem.exists(this._jsonFileName)) { return; } - const versionPolicyJson: IVersionPolicyJson[] = nodeCoreLibrary.JsonFile.loadAndValidate( + const versionPolicyJson: IVersionPolicyJson[] = JsonFile.loadAndValidate( this._jsonFileName, VersionPolicyConfiguration._jsonSchema ); @@ -198,7 +186,7 @@ export class VersionPolicyConfiguration { versionPolicyJson.push(versionPolicy._json); }); if (shouldCommit) { - nodeCoreLibrary.JsonFile.save(versionPolicyJson, this._jsonFileName, { updateExistingFile: true }); + JsonFile.save(versionPolicyJson, this._jsonFileName, { updateExistingFile: true }); } } } diff --git a/apps/rush-lib/src/cli/RushCommandLineParser.ts b/apps/rush-lib/src/cli/RushCommandLineParser.ts index 826cf29a9b4..1938c42649f 100644 --- a/apps/rush-lib/src/cli/RushCommandLineParser.ts +++ b/apps/rush-lib/src/cli/RushCommandLineParser.ts @@ -1,88 +1,46 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line -const importLazy = require('import-lazy')(require); - -console.log('RushCommandLineParser.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as colors from 'colors'; -console.log('RushCommandLineParser.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as os from 'os'; -console.log('RushCommandLineParser.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import * as path from 'path'; -console.log('RushCommandLineParser.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { CommandLineParser, CommandLineFlagParameter, CommandLineAction } from '@rushstack/ts-command-line'; -console.log('RushCommandLineParser.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); -// import { InternalError } from '@rushstack/node-core-library'; -// eslint-disable-next-line -const nodeCoreLibrary = importLazy('@rushstack/node-core-library'); - -console.log('RushCommandLineParser.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); +import { InternalError } from '@rushstack/node-core-library'; import { RushConfiguration } from '../api/RushConfiguration'; -console.log('RushCommandLineParser.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConstants } from '../logic/RushConstants'; -console.log('RushCommandLineParser.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); import { CommandLineConfiguration } from '../api/CommandLineConfiguration'; -console.log('RushCommandLineParser.ts : 9: ' + (new Date().getTime() % 20000) / 1000.0); import { CommandJson } from '../api/CommandLineJson'; -console.log('RushCommandLineParser.ts : 10: ' + (new Date().getTime() % 20000) / 1000.0); import { Utilities } from '../utilities/Utilities'; -console.log('RushCommandLineParser.ts : 11: ' + (new Date().getTime() % 20000) / 1000.0); import { BaseScriptAction } from '../cli/scriptActions/BaseScriptAction'; -console.log('RushCommandLineParser.ts : 12: ' + (new Date().getTime() % 20000) / 1000.0); import { AddAction } from './actions/AddAction'; -console.log('RushCommandLineParser.ts : 13: ' + (new Date().getTime() % 20000) / 1000.0); import { ChangeAction } from './actions/ChangeAction'; -console.log('RushCommandLineParser.ts : 14: ' + (new Date().getTime() % 20000) / 1000.0); import { CheckAction } from './actions/CheckAction'; -console.log('RushCommandLineParser.ts : 15: ' + (new Date().getTime() % 20000) / 1000.0); import { DeployAction } from './actions/DeployAction'; -console.log('RushCommandLineParser.ts : 16: ' + (new Date().getTime() % 20000) / 1000.0); import { InitAction } from './actions/InitAction'; -console.log('RushCommandLineParser.ts : 17: ' + (new Date().getTime() % 20000) / 1000.0); import { InitAutoinstallerAction } from './actions/InitAutoinstallerAction'; -console.log('RushCommandLineParser.ts : 18: ' + (new Date().getTime() % 20000) / 1000.0); import { InitDeployAction } from './actions/InitDeployAction'; -console.log('RushCommandLineParser.ts : 19: ' + (new Date().getTime() % 20000) / 1000.0); import { InstallAction } from './actions/InstallAction'; -console.log('RushCommandLineParser.ts : 20: ' + (new Date().getTime() % 20000) / 1000.0); import { LinkAction } from './actions/LinkAction'; -console.log('RushCommandLineParser.ts : 21: ' + (new Date().getTime() % 20000) / 1000.0); import { ListAction } from './actions/ListAction'; -console.log('RushCommandLineParser.ts : 22: ' + (new Date().getTime() % 20000) / 1000.0); import { PublishAction } from './actions/PublishAction'; -console.log('RushCommandLineParser.ts : 23: ' + (new Date().getTime() % 20000) / 1000.0); import { PurgeAction } from './actions/PurgeAction'; -console.log('RushCommandLineParser.ts : 24: ' + (new Date().getTime() % 20000) / 1000.0); import { ScanAction } from './actions/ScanAction'; -console.log('RushCommandLineParser.ts : 25: ' + (new Date().getTime() % 20000) / 1000.0); import { TabCompleteAction } from './actions/TabCompleteAction'; -console.log('RushCommandLineParser.ts : 26: ' + (new Date().getTime() % 20000) / 1000.0); import { UnlinkAction } from './actions/UnlinkAction'; -console.log('RushCommandLineParser.ts : 27: ' + (new Date().getTime() % 20000) / 1000.0); import { UpdateAction } from './actions/UpdateAction'; -console.log('RushCommandLineParser.ts : 28: ' + (new Date().getTime() % 20000) / 1000.0); import { UpdateAutoinstallerAction } from './actions/UpdateAutoinstallerAction'; -console.log('RushCommandLineParser.ts : 29: ' + (new Date().getTime() % 20000) / 1000.0); import { VersionAction } from './actions/VersionAction'; -console.log('RushCommandLineParser.ts : 30: ' + (new Date().getTime() % 20000) / 1000.0); import { BulkScriptAction } from './scriptActions/BulkScriptAction'; -console.log('RushCommandLineParser.ts : 31: ' + (new Date().getTime() % 20000) / 1000.0); import { GlobalScriptAction } from './scriptActions/GlobalScriptAction'; -console.log('RushCommandLineParser.ts : 32: ' + (new Date().getTime() % 20000) / 1000.0); import { Telemetry } from '../logic/Telemetry'; -console.log('RushCommandLineParser.ts : 33: ' + (new Date().getTime() % 20000) / 1000.0); import { AlreadyReportedError } from '../utilities/AlreadyReportedError'; -console.log('RushCommandLineParser.ts : 34: ' + (new Date().getTime() % 20000) / 1000.0); import { RushGlobalFolder } from '../api/RushGlobalFolder'; -console.log('RushCommandLineParser.ts : 35: ' + (new Date().getTime() % 20000) / 1000.0); import { NodeJsCompatibility } from '../logic/NodeJsCompatibility'; -console.log('RushCommandLineParser.ts : 36: ' + (new Date().getTime() % 20000) / 1000.0); /** * Options for `RushCommandLineParser`. @@ -101,7 +59,7 @@ export class RushCommandLineParser extends CommandLineParser { private _rushOptions: IRushCommandLineParserOptions; public constructor(options?: Partial) { - console.log('RushCommandLineParser.constructor : 1: ' + (new Date().getTime() % 20000) / 1000.0); + console.log('RushCommandLineParser.constructor() : 1: ' + (new Date().getTime() % 20000) / 1000.0); super({ toolFilename: 'rush', toolDescription: @@ -114,35 +72,36 @@ export class RushCommandLineParser extends CommandLineParser { ' automation tools. If you are looking for a proven turnkey solution for monorepo management,' + ' Rush is for you.' }); - console.log('RushCommandLineParser.constructor : 2: ' + (new Date().getTime() % 20000) / 1000.0); + console.log('RushCommandLineParser.constructor() : 2: ' + (new Date().getTime() % 20000) / 1000.0); this._rushOptions = this._normalizeOptions(options || {}); - console.log('RushCommandLineParser.constructor : 3: ' + (new Date().getTime() % 20000) / 1000.0); + console.log('RushCommandLineParser.constructor() : 3: ' + (new Date().getTime() % 20000) / 1000.0); try { + console.log('RushCommandLineParser.constructor() : 4: ' + (new Date().getTime() % 20000) / 1000.0); const rushJsonFilename: string | undefined = RushConfiguration.tryFindRushJsonLocation({ startingFolder: this._rushOptions.cwd, showVerbose: !Utilities.isNonDebugTabCompletionRequest() }); - console.log('RushCommandLineParser.constructor : 4: ' + (new Date().getTime() % 20000) / 1000.0); + console.log('RushCommandLineParser.constructor() : 5: ' + (new Date().getTime() % 20000) / 1000.0); if (rushJsonFilename) { this.rushConfiguration = RushConfiguration.loadFromConfigurationFile(rushJsonFilename); } - console.log('RushCommandLineParser.constructor : 5: ' + (new Date().getTime() % 20000) / 1000.0); + console.log('RushCommandLineParser.constructor() : 6: ' + (new Date().getTime() % 20000) / 1000.0); } catch (error) { this._reportErrorAndSetExitCode(error); } - console.log('RushCommandLineParser.constructor : 6: ' + (new Date().getTime() % 20000) / 1000.0); + console.log('RushCommandLineParser.constructor() : 7: ' + (new Date().getTime() % 20000) / 1000.0); NodeJsCompatibility.warnAboutCompatibilityIssues({ isRushLib: true, alreadyReportedNodeTooNewError: this._rushOptions.alreadyReportedNodeTooNewError, rushConfiguration: this.rushConfiguration }); - console.log('RushCommandLineParser.constructor : 7: ' + (new Date().getTime() % 20000) / 1000.0); + console.log('RushCommandLineParser.constructor() : 8: ' + (new Date().getTime() % 20000) / 1000.0); this._populateActions(); - console.log('RushCommandLineParser.constructor : 8: ' + (new Date().getTime() % 20000) / 1000.0); + console.log('RushCommandLineParser.constructor() : 9: ' + (new Date().getTime() % 20000) / 1000.0); } public get isDebug(): boolean { @@ -172,7 +131,7 @@ export class RushCommandLineParser extends CommandLineParser { process.exitCode = 1; if (this._debugParameter.value) { - nodeCoreLibrary.InternalError.breakInDebugger = true; + InternalError.breakInDebugger = true; } return this._wrapOnExecute() diff --git a/apps/rush-lib/src/logic/RepoStateFile.ts b/apps/rush-lib/src/logic/RepoStateFile.ts index 0eec013e871..f8e83d23127 100644 --- a/apps/rush-lib/src/logic/RepoStateFile.ts +++ b/apps/rush-lib/src/logic/RepoStateFile.ts @@ -1,13 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line -const importLazy = require('import-lazy')(require); - import * as path from 'path'; -// import { FileSystem, JsonFile, JsonSchema, NewlineKind } from '@rushstack/node-core-library'; -// eslint-disable-next-line -const nodeCoreLibrary = importLazy('@rushstack/node-core-library'); +import { FileSystem, JsonFile, JsonSchema, NewlineKind } from '@rushstack/node-core-library'; import { RushConfiguration } from '../api/RushConfiguration'; import { PnpmShrinkwrapFile } from './pnpm/PnpmShrinkwrapFile'; @@ -39,11 +34,9 @@ interface IRepoStateJson { * @public */ export class RepoStateFile { - // eslint-disable-next-line - private static get _jsonSchema() /* NodeCoreLibrary.JsonSchema */ { - return nodeCoreLibrary.JsonSchema.fromFile(path.join(__dirname, '../schemas/repo-state.schema.json')); + private static get _jsonSchema(): JsonSchema { + return JsonSchema.fromFile(path.join(__dirname, '../schemas/repo-state.schema.json')); } - private _repoStateFilePath: string; private _variant: string | undefined; private _pnpmShrinkwrapHash: string | undefined; @@ -95,9 +88,9 @@ export class RepoStateFile { public static loadFromFile(jsonFilename: string, variant: string | undefined): RepoStateFile { let repoStateJson: IRepoStateJson | undefined = undefined; try { - repoStateJson = nodeCoreLibrary.JsonFile.loadAndValidate(jsonFilename, RepoStateFile._jsonSchema); + repoStateJson = JsonFile.loadAndValidate(jsonFilename, RepoStateFile._jsonSchema); } catch (error) { - if (!nodeCoreLibrary.FileSystem.isNotExistError(error)) { + if (!FileSystem.isNotExistError(error)) { throw error; } } @@ -161,8 +154,8 @@ export class RepoStateFile { if (this._modified) { const content: string = '// DO NOT MODIFY THIS FILE. It is generated and used by Rush.' + - `${nodeCoreLibrary.NewlineKind.Lf}${this._serialize()}`; - nodeCoreLibrary.FileSystem.writeFile(this._repoStateFilePath, content); + `${NewlineKind.Lf}${this._serialize()}`; + FileSystem.writeFile(this._repoStateFilePath, content); this._modified = false; return true; } @@ -180,8 +173,6 @@ export class RepoStateFile { repoStateJson.preferredVersionsHash = this._preferredVersionsHash; } - return nodeCoreLibrary.JsonFile.stringify(repoStateJson, { - newlineConversion: nodeCoreLibrary.NewlineKind.Lf - }); + return JsonFile.stringify(repoStateJson, { newlineConversion: NewlineKind.Lf }); } } diff --git a/apps/rush-lib/src/logic/deploy/DeployManager.ts b/apps/rush-lib/src/logic/deploy/DeployManager.ts index 7d9136bb48b..f5205781e7c 100644 --- a/apps/rush-lib/src/logic/deploy/DeployManager.ts +++ b/apps/rush-lib/src/logic/deploy/DeployManager.ts @@ -4,57 +4,37 @@ // eslint-disable-next-line const importLazy = require('import-lazy')(require); -console.log('DeployManager.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as colors from 'colors'; -console.log('DeployManager.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as path from 'path'; -console.log('DeployManager.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import * as resolve from 'resolve'; -console.log('DeployManager.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import * as npmPacklist from 'npm-packlist'; -console.log('DeployManager.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); // eslint-disable-next-line const pnpmLinkBins = importLazy('@pnpm/link-bins'); -console.log('DeployManager.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); // (Used only by the legacy code fragment in the resolve.sync() hook below) import * as fsForResolve from 'fs'; -console.log('DeployManager.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); import ignore, { Ignore } from 'ignore'; -console.log('DeployManager.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); -// import { -// Path, -// FileSystem, -// PackageJsonLookup, -// FileSystemStats, -// Sort, -// JsonFile, -// IPackageJson, -// AlreadyExistsBehavior, -// InternalError, -// NewlineKind, -// Text -// } from '@rushstack/node-core-library'; - -// eslint-disable-next-line -const nodeCoreLibrary = importLazy('@rushstack/node-core-library'); -console.log('DeployManager.ts : 9: ' + (new Date().getTime() % 20000) / 1000.0); - +import { + Path, + FileSystem, + PackageJsonLookup, + FileSystemStats, + Sort, + JsonFile, + IPackageJson, + AlreadyExistsBehavior, + InternalError, + NewlineKind, + Text +} from '@rushstack/node-core-library'; import { DeployArchiver } from './DeployArchiver'; -console.log('DeployManager.ts : 10: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfiguration } from '../../api/RushConfiguration'; -console.log('DeployManager.ts : 11: ' + (new Date().getTime() % 20000) / 1000.0); import { SymlinkAnalyzer, ILinkInfo } from './SymlinkAnalyzer'; -console.log('DeployManager.ts : 12: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfigurationProject } from '../../api/RushConfigurationProject'; -console.log('DeployManager.ts : 13: ' + (new Date().getTime() % 20000) / 1000.0); import { DeployScenarioConfiguration, IDeployScenarioProjectJson } from './DeployScenarioConfiguration'; -console.log('DeployManager.ts : 14: ' + (new Date().getTime() % 20000) / 1000.0); import { PnpmfileConfiguration } from './PnpmfileConfiguration'; -console.log('DeployManager.ts : 15: ' + (new Date().getTime() % 20000) / 1000.0); import { matchesWithStar } from './Utils'; -console.log('DeployManager.ts : 16: ' + (new Date().getTime() % 20000) / 1000.0); // (@types/npm-packlist is missing this API) declare module 'npm-packlist' { @@ -153,19 +133,18 @@ export interface IDeployState { */ export class DeployManager { private readonly _rushConfiguration: RushConfiguration; - private readonly _packageJsonLookup; + private readonly _packageJsonLookup: PackageJsonLookup; public constructor(rushConfiguration: RushConfiguration) { this._rushConfiguration = rushConfiguration; - // eslint-disable-next-line - this._packageJsonLookup = new nodeCoreLibrary.PackageJsonLookup(); + this._packageJsonLookup = new PackageJsonLookup(); } /** * Recursively crawl the node_modules dependencies and collect the result in IDeployState.foldersToCopy. */ private _collectFoldersRecursive(packageJsonFolderPath: string, deployState: IDeployState): void { - const packageJsonRealFolderPath: string = nodeCoreLibrary.FileSystem.getRealPath(packageJsonFolderPath); + const packageJsonRealFolderPath: string = FileSystem.getRealPath(packageJsonFolderPath); if (deployState.foldersToCopy.has(packageJsonRealFolderPath)) { // we've already seen this folder @@ -174,17 +153,16 @@ export class DeployManager { deployState.foldersToCopy.add(packageJsonRealFolderPath); - const originalPackageJson = nodeCoreLibrary.JsonFile.load( + const originalPackageJson: IPackageJson = JsonFile.load( path.join(packageJsonRealFolderPath, 'package.json') ); const sourceFolderInfo: IFolderInfo | undefined = deployState.folderInfosByPath.get( - // eslint-disable-next-line - nodeCoreLibrary.FileSystem.getRealPath(packageJsonFolderPath) + FileSystem.getRealPath(packageJsonFolderPath) ); // Transform packageJson using pnpmfile.js - const packageJson = deployState.pnpmfileConfiguration.transform(originalPackageJson); + const packageJson: IPackageJson = deployState.pnpmfileConfiguration.transform(originalPackageJson); // Union of keys from regular dependencies, peerDependencies, optionalDependencies // (and possibly devDependencies if includeDevDependencies=true) @@ -240,7 +218,7 @@ export class DeployManager { // Replicate the PNPM workaround links. // Only apply this logic for packages that were actually installed under the common/temp folder. - if (nodeCoreLibrary.Path.isUnder(packageJsonFolderPath, this._rushConfiguration.commonTempFolder)) { + if (Path.isUnder(packageJsonFolderPath, this._rushConfiguration.commonTempFolder)) { try { // The PNPM workaround links are created in this folder. We will resolve the current package // from that location and collect any additional links encountered along the way. @@ -343,7 +321,7 @@ export class DeployManager { if (!resolvedDependency) { // This should not happen, since the resolve.sync() docs say it will throw an exception instead - throw new nodeCoreLibrary.InternalError(`Error resolving ${packageName} from ${startingFolder}`); + throw new InternalError(`Error resolving ${packageName} from ${startingFolder}`); } const dependencyPackageFolderPath: string | undefined = this._packageJsonLookup.tryGetPackageFolderFor( @@ -364,7 +342,7 @@ export class DeployManager { * Example output: "C:\MyRepo\common\deploy\libraries\my-lib" */ private _remapPathForDeployFolder(absolutePathInSourceFolder: string, deployState: IDeployState): string { - if (!nodeCoreLibrary.Path.isUnderOrEqual(absolutePathInSourceFolder, deployState.sourceRootFolder)) { + if (!Path.isUnderOrEqual(absolutePathInSourceFolder, deployState.sourceRootFolder)) { throw new Error( `Source path is not under ${deployState.sourceRootFolder}\n${absolutePathInSourceFolder}` ); @@ -381,13 +359,13 @@ export class DeployManager { * Example output: "libraries/my-lib" */ private _remapPathForDeployMetadata(absolutePathInSourceFolder: string, deployState: IDeployState): string { - if (!nodeCoreLibrary.Path.isUnderOrEqual(absolutePathInSourceFolder, deployState.sourceRootFolder)) { + if (!Path.isUnderOrEqual(absolutePathInSourceFolder, deployState.sourceRootFolder)) { throw new Error( `Source path is not under ${deployState.sourceRootFolder}\n${absolutePathInSourceFolder}` ); } const relativePath: string = path.relative(deployState.sourceRootFolder, absolutePathInSourceFolder); - return nodeCoreLibrary.Text.replaceAll(relativePath, '\\', '/'); + return Text.replaceAll(relativePath, '\\', '/'); } /** @@ -398,7 +376,7 @@ export class DeployManager { if (!deployState.scenarioConfiguration.json.includeNpmIgnoreFiles) { const sourceFolderInfo: IFolderInfo | undefined = deployState.folderInfosByPath.get( - nodeCoreLibrary.FileSystem.getRealPath(sourceFolderPath) + FileSystem.getRealPath(sourceFolderPath) ); if (sourceFolderInfo) { if (sourceFolderInfo.isRushProject) { @@ -423,12 +401,12 @@ export class DeployManager { const copyDestinationPath: string = path.join(targetFolderPath, npmPackFile); if (deployState.symlinkAnalyzer.analyzePath(copySourcePath).kind !== 'link') { - nodeCoreLibrary.FileSystem.ensureFolder(path.dirname(copyDestinationPath)); + FileSystem.ensureFolder(path.dirname(copyDestinationPath)); - nodeCoreLibrary.FileSystem.copyFile({ + FileSystem.copyFile({ sourcePath: copySourcePath, destinationPath: copyDestinationPath, - alreadyExistsBehavior: nodeCoreLibrary.AlreadyExistsBehavior.Error + alreadyExistsBehavior: AlreadyExistsBehavior.Error }); } } @@ -445,10 +423,10 @@ export class DeployManager { '**/.DS_Store' ]); - nodeCoreLibrary.FileSystem.copyFiles({ + FileSystem.copyFiles({ sourcePath: sourceFolderPath, destinationPath: targetFolderPath, - alreadyExistsBehavior: nodeCoreLibrary.AlreadyExistsBehavior.Error, + alreadyExistsBehavior: AlreadyExistsBehavior.Error, filter: (src: string, dest: string) => { const relativeSrc: string = path.relative(sourceFolderPath, src); if (!relativeSrc) { @@ -459,8 +437,7 @@ export class DeployManager { return false; } - // eslint-disable-next-line - const stats = nodeCoreLibrary.FileSystem.getLinkStatistics(src); + const stats: FileSystemStats = FileSystem.getLinkStatistics(src); if (stats.isSymbolicLink()) { deployState.symlinkAnalyzer.analyzePath(src); return false; @@ -483,12 +460,12 @@ export class DeployManager { }; // Has the link target been created yet? If not, we should try again later - if (!nodeCoreLibrary.FileSystem.exists(linkInfo.targetPath)) { + if (!FileSystem.exists(linkInfo.targetPath)) { return false; } const newLinkFolder: string = path.dirname(linkInfo.linkPath); - nodeCoreLibrary.FileSystem.ensureFolder(newLinkFolder); + FileSystem.ensureFolder(newLinkFolder); // Link to the relative path for symlinks const relativeTargetPath: string = path.relative(newLinkFolder, linkInfo.targetPath); @@ -497,7 +474,7 @@ export class DeployManager { if (process.platform === 'win32') { if (linkInfo.kind === 'folderLink') { // For directories, we use a Windows "junction". On Unix, this produces a regular symlink. - nodeCoreLibrary.FileSystem.createSymbolicLinkJunction({ + FileSystem.createSymbolicLinkJunction({ linkTargetPath: relativeTargetPath, newLinkPath: linkInfo.linkPath }); @@ -506,7 +483,7 @@ export class DeployManager { // administrator permission. // NOTE: We cannot use the relative path for hard links - nodeCoreLibrary.FileSystem.createHardLink({ + FileSystem.createHardLink({ linkTargetPath: relativeTargetPath, newLinkPath: linkInfo.linkPath }); @@ -515,12 +492,12 @@ export class DeployManager { // However hard links seem to cause build failures on Mac, so for all other operating systems // we use symbolic links for this case. if (linkInfo.kind === 'folderLink') { - nodeCoreLibrary.FileSystem.createSymbolicLinkFolder({ + FileSystem.createSymbolicLinkFolder({ linkTargetPath: relativeTargetPath, newLinkPath: linkInfo.linkPath }); } else { - nodeCoreLibrary.FileSystem.createSymbolicLinkFile({ + FileSystem.createSymbolicLinkFile({ linkTargetPath: relativeTargetPath, newLinkPath: linkInfo.linkPath }); @@ -596,8 +573,8 @@ export class DeployManager { deployMetadataJson.links.push(relativeInfo); } - nodeCoreLibrary.JsonFile.save(deployMetadataJson, deployMetadataFilePath, { - newlineConversion: nodeCoreLibrary.NewlineKind.OsDefault + JsonFile.save(deployMetadataJson, deployMetadataFilePath, { + newlineConversion: NewlineKind.OsDefault }); } @@ -632,7 +609,7 @@ export class DeployManager { ); for (const rushProject of this._rushConfiguration.projects) { - const projectFolder: string = nodeCoreLibrary.FileSystem.getRealPath(rushProject.projectFolder); + const projectFolder: string = FileSystem.getRealPath(rushProject.projectFolder); const projectSettings: | IDeployScenarioProjectJson | undefined = deployState.scenarioConfiguration.projectJsonsByName.get(rushProject.packageName); @@ -659,7 +636,7 @@ export class DeployManager { console.log(); } - nodeCoreLibrary.Sort.sortSet(deployState.foldersToCopy); + Sort.sortSet(deployState.foldersToCopy); console.log('Copying folders...'); for (const folderToCopy of deployState.foldersToCopy) { @@ -671,10 +648,10 @@ export class DeployManager { if (deployState.scenarioConfiguration.json.linkCreation === 'script') { console.log('Copying create-links.js'); - nodeCoreLibrary.FileSystem.copyFile({ + FileSystem.copyFile({ sourcePath: path.join(__dirname, '../../scripts/create-links.js'), destinationPath: path.join(deployState.targetRootFolder, 'create-links.js'), - alreadyExistsBehavior: nodeCoreLibrary.AlreadyExistsBehavior.Error + alreadyExistsBehavior: AlreadyExistsBehavior.Error }); } @@ -687,9 +664,7 @@ export class DeployManager { // TODO: If a symbolic link points to another symbolic link, then we should order the operations // so that the intermediary target is created first. This case was procrastinated because it does // not seem to occur in practice. If you encounter this, please report it. - throw new nodeCoreLibrary.InternalError( - 'Target does not exist: ' + JSON.stringify(linkToCopy, undefined, 2) - ); + throw new InternalError('Target does not exist: ' + JSON.stringify(linkToCopy, undefined, 2)); } } @@ -700,10 +675,10 @@ export class DeployManager { this._rushConfiguration.rushJsonFolder, deployState.scenarioConfiguration.json.folderToCopy ); - nodeCoreLibrary.FileSystem.copyFiles({ + FileSystem.copyFiles({ sourcePath: sourceFolderPath, destinationPath: deployState.targetRootFolder, - alreadyExistsBehavior: nodeCoreLibrary.AlreadyExistsBehavior.Error + alreadyExistsBehavior: AlreadyExistsBehavior.Error }); } await DeployArchiver.createArchiveAsync(deployState); @@ -750,7 +725,7 @@ export class DeployManager { let targetRootFolder: string; if (targetFolderParameter) { targetRootFolder = path.resolve(targetFolderParameter); - if (!nodeCoreLibrary.FileSystem.exists(targetRootFolder)) { + if (!FileSystem.exists(targetRootFolder)) { throw new Error( 'The specified target folder does not exist: ' + JSON.stringify(targetFolderParameter) ); @@ -763,13 +738,13 @@ export class DeployManager { console.log(colors.cyan('Deploying to target folder: ') + targetRootFolder); console.log(colors.cyan('Main project for deployment: ') + mainProjectName + '\n'); - nodeCoreLibrary.FileSystem.ensureFolder(targetRootFolder); + FileSystem.ensureFolder(targetRootFolder); // Is the target folder empty? - if (nodeCoreLibrary.FileSystem.readFolder(targetRootFolder).length > 0) { + if (FileSystem.readFolder(targetRootFolder).length > 0) { if (overwriteExisting) { console.log('Deleting target folder contents because "--overwrite" was specified...'); - nodeCoreLibrary.FileSystem.ensureEmptyFolder(targetRootFolder); + FileSystem.ensureEmptyFolder(targetRootFolder); console.log(); } else { throw new Error( diff --git a/apps/rush-lib/src/logic/deploy/DeployScenarioConfiguration.ts b/apps/rush-lib/src/logic/deploy/DeployScenarioConfiguration.ts index 98011f78ff7..cb9653e7fd3 100644 --- a/apps/rush-lib/src/logic/deploy/DeployScenarioConfiguration.ts +++ b/apps/rush-lib/src/logic/deploy/DeployScenarioConfiguration.ts @@ -31,9 +31,9 @@ export class DeployScenarioConfiguration { // Example: "deploy-the-thing123" private static _scenarioNameRegExp: RegExp = /^[a-z0-9]+(-[a-z0-9]+)*$/; - private static _jsonSchema: JsonSchema = JsonSchema.fromFile( - path.join(__dirname, '../../schemas/deploy-scenario.schema.json') - ); + private static get _jsonSchema(): JsonSchema { + return JsonSchema.fromFile(path.join(__dirname, '../../schemas/deploy-scenario.schema.json')); + } public readonly json: IDeployScenarioJson; diff --git a/apps/rush-lib/src/utilities/Utilities.ts b/apps/rush-lib/src/utilities/Utilities.ts index c05e96ee3b0..4b7e344c8ef 100644 --- a/apps/rush-lib/src/utilities/Utilities.ts +++ b/apps/rush-lib/src/utilities/Utilities.ts @@ -1,18 +1,13 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line -const importLazy = require('import-lazy')(require); - import * as child_process from 'child_process'; import * as fs from 'fs'; import * as os from 'os'; import * as tty from 'tty'; import * as path from 'path'; import * as wordwrap from 'wordwrap'; -// import { JsonFile, IPackageJson, FileSystem, FileConstants } from '@rushstack/node-core-library'; -// eslint-disable-next-line -const nodeCoreLibrary = importLazy('@rushstack/node-core-library'); +import { JsonFile, IPackageJson, FileSystem, FileConstants } from '@rushstack/node-core-library'; import { RushConfiguration } from '../api/RushConfiguration'; import { Stream } from 'stream'; @@ -129,7 +124,7 @@ export class Utilities { throw new Error(dirError); } const homeFolder: string = path.resolve(unresolvedUserFolder); - if (!nodeCoreLibrary.FileSystem.exists(homeFolder)) { + if (!FileSystem.exists(homeFolder)) { throw new Error(dirError); } @@ -195,7 +190,7 @@ export class Utilities { } /** - * Creates the specified folder by calling nodeCoreLibrary.FileSystem.ensureFolder(), but using a + * Creates the specified folder by calling FileSystem.ensureFolder(), but using a * retry loop to recover from temporary locks that may be held by other processes. * If the folder already exists, no error occurs. */ @@ -214,7 +209,7 @@ export class Utilities { const maxWaitTimeMs: number = 7 * 1000; return Utilities.retryUntilTimeout( - () => nodeCoreLibrary.FileSystem.ensureFolder(folderName), + () => FileSystem.ensureFolder(folderName), maxWaitTimeMs, (e) => new Error( @@ -233,7 +228,7 @@ export class Utilities { let exists: boolean = false; try { - const lstat: fs.Stats = nodeCoreLibrary.FileSystem.getLinkStatistics(filePath); + const lstat: fs.Stats = FileSystem.getLinkStatistics(filePath); exists = lstat.isFile(); } catch (e) { /* no-op */ @@ -249,7 +244,7 @@ export class Utilities { let exists: boolean = false; try { - const lstat: fs.Stats = nodeCoreLibrary.FileSystem.getLinkStatistics(directoryPath); + const lstat: fs.Stats = FileSystem.getLinkStatistics(directoryPath); exists = lstat.isDirectory(); } catch (e) { /* no-op */ @@ -265,7 +260,7 @@ export class Utilities { */ public static dangerouslyDeletePath(folderPath: string): void { try { - nodeCoreLibrary.FileSystem.deleteFolder(folderPath); + FileSystem.deleteFolder(folderPath); } catch (e) { throw new Error( `${e.message}${os.EOL}Often this is caused by a file lock from a process ` + @@ -280,7 +275,7 @@ export class Utilities { public static deleteFile(filePath: string): void { if (Utilities.fileExists(filePath)) { console.log(`Deleting: ${filePath}`); - nodeCoreLibrary.FileSystem.deleteFile(filePath); + FileSystem.deleteFile(filePath); } } @@ -293,11 +288,11 @@ export class Utilities { */ public static isFileTimestampCurrent(dateToCompare: Date, inputFilenames: string[]): boolean { for (const inputFilename of inputFilenames) { - if (!nodeCoreLibrary.FileSystem.exists(inputFilename)) { + if (!FileSystem.exists(inputFilename)) { return false; } - const inputStats: fs.Stats = nodeCoreLibrary.FileSystem.getStatistics(inputFilename); + const inputStats: fs.Stats = FileSystem.getStatistics(inputFilename); if (dateToCompare < inputStats.mtime) { return false; } @@ -466,13 +461,13 @@ export class Utilities { */ public static installPackageInDirectory(options: IInstallPackageInDirectoryOptions): void { const directory: string = path.resolve(options.directory); - if (nodeCoreLibrary.FileSystem.exists(directory)) { + if (FileSystem.exists(directory)) { console.log('Deleting old files from ' + directory); } - nodeCoreLibrary.FileSystem.ensureEmptyFolder(directory); + FileSystem.ensureEmptyFolder(directory); - const npmPackageJson /*: IPackageJson*/ = { + const npmPackageJson: IPackageJson = { dependencies: { [options.packageName]: options.version }, @@ -481,10 +476,7 @@ export class Utilities { private: true, version: '0.0.0' }; - nodeCoreLibrary.JsonFile.save( - npmPackageJson, - path.join(directory, nodeCoreLibrary.FileConstants.PackageJson) - ); + JsonFile.save(npmPackageJson, path.join(directory, FileConstants.PackageJson)); if (options.commonRushConfigFolder) { Utilities.syncNpmrc(options.commonRushConfigFolder, directory); @@ -540,7 +532,7 @@ export class Utilities { */ public static copyAndTrimNpmrcFile(sourceNpmrcPath: string, targetNpmrcPath: string): void { console.log(`Copying ${sourceNpmrcPath} --> ${targetNpmrcPath}`); // Verbose - let npmrcFileLines: string[] = nodeCoreLibrary.FileSystem.readFile(sourceNpmrcPath).split('\n'); + let npmrcFileLines: string[] = FileSystem.readFile(sourceNpmrcPath).split('\n'); npmrcFileLines = npmrcFileLines.map((line) => (line || '').trim()); const resultLines: string[] = []; @@ -581,7 +573,7 @@ export class Utilities { } } - nodeCoreLibrary.FileSystem.writeFile(targetNpmrcPath, resultLines.join(os.EOL)); + FileSystem.writeFile(targetNpmrcPath, resultLines.join(os.EOL)); } /** @@ -589,14 +581,14 @@ export class Utilities { * If the source file does not exist, then the target file is deleted. */ public static syncFile(sourcePath: string, destinationPath: string): void { - if (nodeCoreLibrary.FileSystem.exists(sourcePath)) { + if (FileSystem.exists(sourcePath)) { console.log(`Updating ${destinationPath}`); - nodeCoreLibrary.FileSystem.copyFile({ sourcePath, destinationPath }); + FileSystem.copyFile({ sourcePath, destinationPath }); } else { - if (nodeCoreLibrary.FileSystem.exists(destinationPath)) { + if (FileSystem.exists(destinationPath)) { // If the source file doesn't exist and there is one in the target, delete the one in the target console.log(`Deleting ${destinationPath}`); - nodeCoreLibrary.FileSystem.deleteFile(destinationPath); + FileSystem.deleteFile(destinationPath); } } } @@ -618,12 +610,12 @@ export class Utilities { ); const targetNpmrcPath: string = path.join(targetNpmrcFolder, '.npmrc'); try { - if (nodeCoreLibrary.FileSystem.exists(sourceNpmrcPath)) { + if (FileSystem.exists(sourceNpmrcPath)) { Utilities.copyAndTrimNpmrcFile(sourceNpmrcPath, targetNpmrcPath); - } else if (nodeCoreLibrary.FileSystem.exists(targetNpmrcPath)) { + } else if (FileSystem.exists(targetNpmrcPath)) { // If the source .npmrc doesn't exist and there is one in the target, delete the one in the target console.log(`Deleting ${targetNpmrcPath}`); // Verbose - nodeCoreLibrary.FileSystem.deleteFile(targetNpmrcPath); + FileSystem.deleteFile(targetNpmrcPath); } } catch (e) { throw new Error(`Error syncing .npmrc file: ${e}`); diff --git a/common/reviews/api/rush-lib.api.md b/common/reviews/api/rush-lib.api.md index c75cce47e5c..33c1044665d 100644 --- a/common/reviews/api/rush-lib.api.md +++ b/common/reviews/api/rush-lib.api.md @@ -6,6 +6,7 @@ import { IPackageJson } from '@rushstack/node-core-library'; import { JsonObject } from '@rushstack/node-core-library'; +import { PackageNameParser } from '@rushstack/node-core-library'; // @public export class ApprovedPackagesConfiguration { @@ -246,7 +247,7 @@ export class PackageJsonEditor { // (undocumented) readonly filePath: string; // (undocumented) - static fromObject(object: any, filename: string): PackageJsonEditor; + static fromObject(object: IPackageJson, filename: string): PackageJsonEditor; // (undocumented) static load(filePath: string): PackageJsonEditor; // (undocumented) @@ -362,7 +363,7 @@ export class RushConfiguration { readonly packageManagerToolVersion: string; // @beta readonly packageManagerWrapper: PackageManager; - readonly packageNameParser: any; + readonly packageNameParser: PackageNameParser; readonly pnpmOptions: PnpmOptionsConfiguration; readonly projectFolderMaxDepth: number; readonly projectFolderMinDepth: number; @@ -405,7 +406,7 @@ export class RushConfigurationProject { readonly isMainProject: boolean; readonly localDependencyProjects: ReadonlyArray; // @deprecated - readonly packageJson: any; + readonly packageJson: IPackageJson; // @beta readonly packageJsonEditor: PackageJsonEditor; readonly packageName: string; From a91fc88e3ef128d4fe1ee325ab2538770223fb62 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Fri, 31 Jul 2020 21:09:06 -0700 Subject: [PATCH 29/97] Profiling in progress --- apps/rush-lib/src/api/RushConfiguration.ts | 28 +++++++++++++++ apps/rush-lib/src/api/VersionPolicy.ts | 8 +++++ .../src/api/VersionPolicyConfiguration.ts | 5 +++ .../rush-lib/src/cli/RushCommandLineParser.ts | 36 +++++++++++++++++++ apps/rush-lib/src/cli/RushXCommandLine.ts | 9 +++++ apps/rush-lib/src/cli/actions/ListAction.ts | 15 ++++++-- apps/rush-lib/src/cli/actions/ScanAction.ts | 6 +++- .../src/cli/scriptActions/BulkScriptAction.ts | 16 +++++++++ apps/rush-lib/src/logic/ChangeFiles.ts | 6 +++- apps/rush-lib/src/logic/RepoStateFile.ts | 6 ++++ .../src/logic/base/BaseInstallManager.ts | 35 +++++++++++++++++- .../src/logic/deploy/DeployManager.ts | 34 ++++++++++++------ .../installManager/RushInstallManager.ts | 3 +- .../installManager/WorkspaceInstallManager.ts | 23 ++++++++++++ .../src/logic/pnpm/PnpmShrinkwrapFile.ts | 31 ++++++++++------ .../src/logic/pnpm/PnpmWorkspaceFile.ts | 18 ++++------ .../rush-lib/src/logic/pnpm/PnpmYamlCommon.ts | 15 ++++++++ apps/rush-lib/src/start.ts | 4 ++- common/reviews/api/node-core-library.api.md | 2 ++ libraries/node-core-library/src/Executable.ts | 6 ++++ libraries/node-core-library/src/FileSystem.ts | 13 ++++++- libraries/node-core-library/src/FileWriter.ts | 7 +++- libraries/node-core-library/src/JsonSchema.ts | 20 +++-------- .../node-core-library/src/LegacyAdapters.ts | 3 ++ .../src/PackageJsonLookup.ts | 6 ++++ libraries/node-core-library/src/index.ts | 25 +++++++++++++ 26 files changed, 324 insertions(+), 56 deletions(-) create mode 100644 apps/rush-lib/src/logic/pnpm/PnpmYamlCommon.ts diff --git a/apps/rush-lib/src/api/RushConfiguration.ts b/apps/rush-lib/src/api/RushConfiguration.ts index 64ece23f18c..0812cb3198e 100644 --- a/apps/rush-lib/src/api/RushConfiguration.ts +++ b/apps/rush-lib/src/api/RushConfiguration.ts @@ -3,28 +3,50 @@ /* eslint max-lines: off */ +console.log('RushConfiguration.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as path from 'path'; +console.log('RushConfiguration.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as fs from 'fs'; +console.log('RushConfiguration.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import * as semver from 'semver'; +console.log('RushConfiguration.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { JsonFile, JsonSchema, Path, FileSystem, PackageNameParser } from '@rushstack/node-core-library'; +console.log('RushConfiguration.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import { trueCasePathSync } from 'true-case-path'; +console.log('RushConfiguration.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); import { Rush } from '../api/Rush'; +console.log('RushConfiguration.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfigurationProject, IRushConfigurationProjectJson } from './RushConfigurationProject'; +console.log('RushConfiguration.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConstants } from '../logic/RushConstants'; +console.log('RushConfiguration.ts : 9: ' + (new Date().getTime() % 20000) / 1000.0); import { ApprovedPackagesPolicy } from './ApprovedPackagesPolicy'; +console.log('RushConfiguration.ts : 10: ' + (new Date().getTime() % 20000) / 1000.0); import { EventHooks } from './EventHooks'; +console.log('RushConfiguration.ts : 11: ' + (new Date().getTime() % 20000) / 1000.0); import { VersionPolicyConfiguration } from './VersionPolicyConfiguration'; +console.log('RushConfiguration.ts : 12: ' + (new Date().getTime() % 20000) / 1000.0); import { EnvironmentConfiguration } from './EnvironmentConfiguration'; +console.log('RushConfiguration.ts : 13: ' + (new Date().getTime() % 20000) / 1000.0); import { CommonVersionsConfiguration } from './CommonVersionsConfiguration'; +console.log('RushConfiguration.ts : 14: ' + (new Date().getTime() % 20000) / 1000.0); import { Utilities } from '../utilities/Utilities'; +console.log('RushConfiguration.ts : 15: ' + (new Date().getTime() % 20000) / 1000.0); import { PackageManagerName, PackageManager } from './packageManager/PackageManager'; +console.log('RushConfiguration.ts : 16: ' + (new Date().getTime() % 20000) / 1000.0); import { NpmPackageManager } from './packageManager/NpmPackageManager'; +console.log('RushConfiguration.ts : 17: ' + (new Date().getTime() % 20000) / 1000.0); import { YarnPackageManager } from './packageManager/YarnPackageManager'; +console.log('RushConfiguration.ts : 18: ' + (new Date().getTime() % 20000) / 1000.0); import { PnpmPackageManager } from './packageManager/PnpmPackageManager'; +console.log('RushConfiguration.ts : 19: ' + (new Date().getTime() % 20000) / 1000.0); import { ExperimentsConfiguration } from './ExperimentsConfiguration'; +console.log('RushConfiguration.ts : 20: ' + (new Date().getTime() % 20000) / 1000.0); import { PackageNameParsers } from './PackageNameParsers'; +console.log('RushConfiguration.ts : 21: ' + (new Date().getTime() % 20000) / 1000.0); import { RepoStateFile } from '../logic/RepoStateFile'; +console.log('RushConfiguration.ts : 22: ' + (new Date().getTime() % 20000) / 1000.0); const MINIMUM_SUPPORTED_RUSH_JSON_VERSION: string = '0.0.0'; const DEFAULT_BRANCH: string = 'master'; @@ -816,7 +838,13 @@ export class RushConfiguration { } } + console.log( + 'RushConfiguration.loadFromConfigurationFile() : 5: ' + (new Date().getTime() % 20000) / 1000.0 + ); RushConfiguration._jsonSchema.validateObject(rushConfigurationJson, resolvedRushJsonFilename); + console.log( + 'RushConfiguration.loadFromConfigurationFile() : 6: ' + (new Date().getTime() % 20000) / 1000.0 + ); return new RushConfiguration(rushConfigurationJson, resolvedRushJsonFilename); } diff --git a/apps/rush-lib/src/api/VersionPolicy.ts b/apps/rush-lib/src/api/VersionPolicy.ts index 90612dba5a7..9ee80139e6d 100644 --- a/apps/rush-lib/src/api/VersionPolicy.ts +++ b/apps/rush-lib/src/api/VersionPolicy.ts @@ -1,9 +1,13 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +console.log('VersionPolicy.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import { cloneDeep } from 'lodash'; +console.log('VersionPolicy.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as semver from 'semver'; +console.log('VersionPolicy.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import { IPackageJson } from '@rushstack/node-core-library'; +console.log('VersionPolicy.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { IVersionPolicyJson, @@ -13,9 +17,13 @@ import { VersionFormatForPublish, IVersionPolicyDependencyJson } from './VersionPolicyConfiguration'; +console.log('VersionPolicy.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import { PackageJsonEditor } from './PackageJsonEditor'; +console.log('VersionPolicy.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfiguration } from './RushConfiguration'; +console.log('VersionPolicy.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfigurationProject } from './RushConfigurationProject'; +console.log('VersionPolicy.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); /** * Type of version bumps diff --git a/apps/rush-lib/src/api/VersionPolicyConfiguration.ts b/apps/rush-lib/src/api/VersionPolicyConfiguration.ts index 8dbca789495..fcc59a712df 100644 --- a/apps/rush-lib/src/api/VersionPolicyConfiguration.ts +++ b/apps/rush-lib/src/api/VersionPolicyConfiguration.ts @@ -1,11 +1,16 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +console.log('VersionPolicyConfiguration.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as path from 'path'; +console.log('VersionPolicyConfiguration.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import { JsonFile, JsonSchema, FileSystem } from '@rushstack/node-core-library'; +console.log('VersionPolicyConfiguration.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import { VersionPolicy, BumpType, LockStepVersionPolicy } from './VersionPolicy'; +console.log('VersionPolicyConfiguration.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfigurationProject } from './RushConfigurationProject'; +console.log('VersionPolicyConfiguration.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); /** * @beta diff --git a/apps/rush-lib/src/cli/RushCommandLineParser.ts b/apps/rush-lib/src/cli/RushCommandLineParser.ts index 1938c42649f..357a9387939 100644 --- a/apps/rush-lib/src/cli/RushCommandLineParser.ts +++ b/apps/rush-lib/src/cli/RushCommandLineParser.ts @@ -1,46 +1,82 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +console.log('RushCommandLineParser.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as colors from 'colors'; +console.log('RushCommandLineParser.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as os from 'os'; +console.log('RushCommandLineParser.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import * as path from 'path'; +console.log('RushCommandLineParser.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { CommandLineParser, CommandLineFlagParameter, CommandLineAction } from '@rushstack/ts-command-line'; +console.log('RushCommandLineParser.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import { InternalError } from '@rushstack/node-core-library'; +console.log('RushCommandLineParser.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfiguration } from '../api/RushConfiguration'; +console.log('RushCommandLineParser.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConstants } from '../logic/RushConstants'; +console.log('RushCommandLineParser.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); import { CommandLineConfiguration } from '../api/CommandLineConfiguration'; +console.log('RushCommandLineParser.ts : 9: ' + (new Date().getTime() % 20000) / 1000.0); import { CommandJson } from '../api/CommandLineJson'; +console.log('RushCommandLineParser.ts : 10: ' + (new Date().getTime() % 20000) / 1000.0); import { Utilities } from '../utilities/Utilities'; +console.log('RushCommandLineParser.ts : 11: ' + (new Date().getTime() % 20000) / 1000.0); import { BaseScriptAction } from '../cli/scriptActions/BaseScriptAction'; +console.log('RushCommandLineParser.ts : 12: ' + (new Date().getTime() % 20000) / 1000.0); import { AddAction } from './actions/AddAction'; +console.log('RushCommandLineParser.ts : 13: ' + (new Date().getTime() % 20000) / 1000.0); import { ChangeAction } from './actions/ChangeAction'; +console.log('RushCommandLineParser.ts : 14: ' + (new Date().getTime() % 20000) / 1000.0); import { CheckAction } from './actions/CheckAction'; +console.log('RushCommandLineParser.ts : 15: ' + (new Date().getTime() % 20000) / 1000.0); import { DeployAction } from './actions/DeployAction'; +console.log('RushCommandLineParser.ts : 16: ' + (new Date().getTime() % 20000) / 1000.0); import { InitAction } from './actions/InitAction'; +console.log('RushCommandLineParser.ts : 17: ' + (new Date().getTime() % 20000) / 1000.0); import { InitAutoinstallerAction } from './actions/InitAutoinstallerAction'; +console.log('RushCommandLineParser.ts : 18: ' + (new Date().getTime() % 20000) / 1000.0); import { InitDeployAction } from './actions/InitDeployAction'; +console.log('RushCommandLineParser.ts : 19: ' + (new Date().getTime() % 20000) / 1000.0); import { InstallAction } from './actions/InstallAction'; +console.log('RushCommandLineParser.ts : 20: ' + (new Date().getTime() % 20000) / 1000.0); import { LinkAction } from './actions/LinkAction'; +console.log('RushCommandLineParser.ts : 21: ' + (new Date().getTime() % 20000) / 1000.0); import { ListAction } from './actions/ListAction'; +console.log('RushCommandLineParser.ts : 22: ' + (new Date().getTime() % 20000) / 1000.0); import { PublishAction } from './actions/PublishAction'; +console.log('RushCommandLineParser.ts : 23: ' + (new Date().getTime() % 20000) / 1000.0); import { PurgeAction } from './actions/PurgeAction'; +console.log('RushCommandLineParser.ts : 24: ' + (new Date().getTime() % 20000) / 1000.0); import { ScanAction } from './actions/ScanAction'; +console.log('RushCommandLineParser.ts : 25: ' + (new Date().getTime() % 20000) / 1000.0); import { TabCompleteAction } from './actions/TabCompleteAction'; +console.log('RushCommandLineParser.ts : 26: ' + (new Date().getTime() % 20000) / 1000.0); import { UnlinkAction } from './actions/UnlinkAction'; +console.log('RushCommandLineParser.ts : 27: ' + (new Date().getTime() % 20000) / 1000.0); import { UpdateAction } from './actions/UpdateAction'; +console.log('RushCommandLineParser.ts : 28: ' + (new Date().getTime() % 20000) / 1000.0); import { UpdateAutoinstallerAction } from './actions/UpdateAutoinstallerAction'; +console.log('RushCommandLineParser.ts : 29: ' + (new Date().getTime() % 20000) / 1000.0); import { VersionAction } from './actions/VersionAction'; +console.log('RushCommandLineParser.ts : 30: ' + (new Date().getTime() % 20000) / 1000.0); import { BulkScriptAction } from './scriptActions/BulkScriptAction'; +console.log('RushCommandLineParser.ts : 31: ' + (new Date().getTime() % 20000) / 1000.0); import { GlobalScriptAction } from './scriptActions/GlobalScriptAction'; +console.log('RushCommandLineParser.ts : 32: ' + (new Date().getTime() % 20000) / 1000.0); import { Telemetry } from '../logic/Telemetry'; +console.log('RushCommandLineParser.ts : 33: ' + (new Date().getTime() % 20000) / 1000.0); import { AlreadyReportedError } from '../utilities/AlreadyReportedError'; +console.log('RushCommandLineParser.ts : 34: ' + (new Date().getTime() % 20000) / 1000.0); import { RushGlobalFolder } from '../api/RushGlobalFolder'; +console.log('RushCommandLineParser.ts : 35: ' + (new Date().getTime() % 20000) / 1000.0); import { NodeJsCompatibility } from '../logic/NodeJsCompatibility'; +console.log('RushCommandLineParser.ts : 36: ' + (new Date().getTime() % 20000) / 1000.0); /** * Options for `RushCommandLineParser`. diff --git a/apps/rush-lib/src/cli/RushXCommandLine.ts b/apps/rush-lib/src/cli/RushXCommandLine.ts index 9b1b2502a44..952b52e3699 100644 --- a/apps/rush-lib/src/cli/RushXCommandLine.ts +++ b/apps/rush-lib/src/cli/RushXCommandLine.ts @@ -1,15 +1,24 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +console.log('RushXCommandLine.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as colors from 'colors'; +console.log('RushXCommandLine.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as os from 'os'; +console.log('RushXCommandLine.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import * as path from 'path'; +console.log('RushXCommandLine.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { PackageJsonLookup, IPackageJson, Text } from '@rushstack/node-core-library'; +console.log('RushXCommandLine.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import { Utilities } from '../utilities/Utilities'; +console.log('RushXCommandLine.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); import { ProjectCommandSet } from '../logic/ProjectCommandSet'; +console.log('RushXCommandLine.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfiguration } from '../api/RushConfiguration'; +console.log('RushXCommandLine.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); import { NodeJsCompatibility } from '../logic/NodeJsCompatibility'; +console.log('RushXCommandLine.ts : 9: ' + (new Date().getTime() % 20000) / 1000.0); /** * @internal diff --git a/apps/rush-lib/src/cli/actions/ListAction.ts b/apps/rush-lib/src/cli/actions/ListAction.ts index 28860560a65..72441632ce1 100644 --- a/apps/rush-lib/src/cli/actions/ListAction.ts +++ b/apps/rush-lib/src/cli/actions/ListAction.ts @@ -1,11 +1,20 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +// eslint-disable-next-line +const importLazy = require('import-lazy')(require); + +console.log('ListAction.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import { BaseRushAction } from './BaseRushAction'; +console.log('ListAction.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import { RushCommandLineParser } from '../RushCommandLineParser'; +console.log('ListAction.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import { CommandLineFlagParameter } from '@rushstack/ts-command-line'; +console.log('ListAction.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfigurationProject } from '../../api/RushConfigurationProject'; -import * as Table from 'cli-table'; +console.log('ListAction.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); +const Table = importLazy('cli-table'); +console.log('ListAction.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); export interface IJsonEntry { name: string; @@ -113,7 +122,9 @@ export class ListAction extends BaseRushAction { if (this._fullPath.value) { tableHeader.push('Full Path'); } - const table: Table = new Table({ + + // eslint-disable-next-line + const table = new Table({ head: tableHeader }); diff --git a/apps/rush-lib/src/cli/actions/ScanAction.ts b/apps/rush-lib/src/cli/actions/ScanAction.ts index c243c09e734..c5f8893d496 100644 --- a/apps/rush-lib/src/cli/actions/ScanAction.ts +++ b/apps/rush-lib/src/cli/actions/ScanAction.ts @@ -1,8 +1,12 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +// eslint-disable-next-line +const importLazy = require('import-lazy')(require); + import * as colors from 'colors'; -import * as glob from 'glob'; +// import * as glob from 'glob'; +const glob = importLazy('glob'); import * as path from 'path'; import * as builtinPackageNames from 'builtin-modules'; import { FileSystem } from '@rushstack/node-core-library'; diff --git a/apps/rush-lib/src/cli/scriptActions/BulkScriptAction.ts b/apps/rush-lib/src/cli/scriptActions/BulkScriptAction.ts index 8100e90ee84..fd63bff0e5a 100644 --- a/apps/rush-lib/src/cli/scriptActions/BulkScriptAction.ts +++ b/apps/rush-lib/src/cli/scriptActions/BulkScriptAction.ts @@ -1,8 +1,11 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +console.log('BulkScriptAction.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as os from 'os'; +console.log('BulkScriptAction.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as colors from 'colors'; +console.log('BulkScriptAction.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import { CommandLineFlagParameter, @@ -11,18 +14,31 @@ import { CommandLineParameterKind } from '@rushstack/ts-command-line'; +console.log('BulkScriptAction.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { Event } from '../../index'; +console.log('BulkScriptAction.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import { SetupChecks } from '../../logic/SetupChecks'; +console.log('BulkScriptAction.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); import { TaskSelector } from '../../logic/TaskSelector'; +console.log('BulkScriptAction.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); import { Stopwatch } from '../../utilities/Stopwatch'; +console.log('BulkScriptAction.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); import { AlreadyReportedError } from '../../utilities/AlreadyReportedError'; +console.log('BulkScriptAction.ts : 9: ' + (new Date().getTime() % 20000) / 1000.0); import { BaseScriptAction, IBaseScriptActionOptions } from './BaseScriptAction'; +console.log('BulkScriptAction.ts : 10: ' + (new Date().getTime() % 20000) / 1000.0); import { TaskRunner } from '../../logic/taskRunner/TaskRunner'; +console.log('BulkScriptAction.ts : 11: ' + (new Date().getTime() % 20000) / 1000.0); import { TaskCollection } from '../../logic/taskRunner/TaskCollection'; +console.log('BulkScriptAction.ts : 12: ' + (new Date().getTime() % 20000) / 1000.0); import { Utilities } from '../../utilities/Utilities'; +console.log('BulkScriptAction.ts : 13: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConstants } from '../../logic/RushConstants'; +console.log('BulkScriptAction.ts : 14: ' + (new Date().getTime() % 20000) / 1000.0); import { EnvironmentVariableNames } from '../../api/EnvironmentConfiguration'; +console.log('BulkScriptAction.ts : 15: ' + (new Date().getTime() % 20000) / 1000.0); import { LastLinkFlag, LastLinkFlagFactory } from '../../api/LastLinkFlag'; +console.log('BulkScriptAction.ts : 16: ' + (new Date().getTime() % 20000) / 1000.0); /** * Constructor parameters for BulkScriptAction. diff --git a/apps/rush-lib/src/logic/ChangeFiles.ts b/apps/rush-lib/src/logic/ChangeFiles.ts index bcbf49f17b5..d1746422abb 100644 --- a/apps/rush-lib/src/logic/ChangeFiles.ts +++ b/apps/rush-lib/src/logic/ChangeFiles.ts @@ -1,8 +1,12 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +// eslint-disable-next-line +const importLazy = require('import-lazy')(require); + import { EOL } from 'os'; -import * as glob from 'glob'; +// import * as glob from 'glob'; +const glob = importLazy('glob'); import { Utilities } from '../utilities/Utilities'; import { IChangeInfo } from '../api/ChangeManagement'; diff --git a/apps/rush-lib/src/logic/RepoStateFile.ts b/apps/rush-lib/src/logic/RepoStateFile.ts index f8e83d23127..31929d2401e 100644 --- a/apps/rush-lib/src/logic/RepoStateFile.ts +++ b/apps/rush-lib/src/logic/RepoStateFile.ts @@ -1,12 +1,18 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +console.log('RepoStateFile.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as path from 'path'; +console.log('RepoStateFile.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import { FileSystem, JsonFile, JsonSchema, NewlineKind } from '@rushstack/node-core-library'; +console.log('RepoStateFile.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfiguration } from '../api/RushConfiguration'; +console.log('RepoStateFile.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { PnpmShrinkwrapFile } from './pnpm/PnpmShrinkwrapFile'; +console.log('RepoStateFile.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import { CommonVersionsConfiguration } from '../api/CommonVersionsConfiguration'; +console.log('RepoStateFile.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); /** * This interface represents the raw repo-state.json file diff --git a/apps/rush-lib/src/logic/base/BaseInstallManager.ts b/apps/rush-lib/src/logic/base/BaseInstallManager.ts index 0aab21daa41..6ec9c065058 100644 --- a/apps/rush-lib/src/logic/base/BaseInstallManager.ts +++ b/apps/rush-lib/src/logic/base/BaseInstallManager.ts @@ -1,35 +1,68 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +// eslint-disable-next-line +const importLazy = require('import-lazy')(require); + +console.log('BaseInstallManager.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as colors from 'colors'; +console.log('BaseInstallManager.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as fetch from 'node-fetch'; +console.log('BaseInstallManager.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import * as fs from 'fs'; +console.log('BaseInstallManager.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import * as http from 'http'; -import HttpsProxyAgent = require('https-proxy-agent'); +console.log('BaseInstallManager.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); +// import HttpsProxyAgent = require('https-proxy-agent'); +// eslint-disable-next-line +const HttpsProxyAgent = importLazy('https-proxy-agent'); +console.log('BaseInstallManager.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); import * as os from 'os'; +console.log('BaseInstallManager.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); import * as path from 'path'; +console.log('BaseInstallManager.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); import * as semver from 'semver'; +console.log('BaseInstallManager.ts : 9: ' + (new Date().getTime() % 20000) / 1000.0); import { FileSystem, JsonFile, PosixModeBits, NewlineKind } from '@rushstack/node-core-library'; +console.log('BaseInstallManager.ts : 10: ' + (new Date().getTime() % 20000) / 1000.0); import { AlreadyReportedError } from '../../utilities/AlreadyReportedError'; +console.log('BaseInstallManager.ts : 11: ' + (new Date().getTime() % 20000) / 1000.0); import { ApprovedPackagesChecker } from '../ApprovedPackagesChecker'; +console.log('BaseInstallManager.ts : 12: ' + (new Date().getTime() % 20000) / 1000.0); import { AsyncRecycler } from '../../utilities/AsyncRecycler'; +console.log('BaseInstallManager.ts : 13: ' + (new Date().getTime() % 20000) / 1000.0); import { BaseShrinkwrapFile } from '../base/BaseShrinkwrapFile'; +console.log('BaseInstallManager.ts : 14: ' + (new Date().getTime() % 20000) / 1000.0); import { EnvironmentConfiguration } from '../../api/EnvironmentConfiguration'; +console.log('BaseInstallManager.ts : 15: ' + (new Date().getTime() % 20000) / 1000.0); import { Git } from '../Git'; +console.log('BaseInstallManager.ts : 16: ' + (new Date().getTime() % 20000) / 1000.0); import { LastInstallFlag, LastInstallFlagFactory } from '../../api/LastInstallFlag'; +console.log('BaseInstallManager.ts : 17: ' + (new Date().getTime() % 20000) / 1000.0); import { LastLinkFlag, LastLinkFlagFactory } from '../../api/LastLinkFlag'; import { PnpmPackageManager } from '../../api/packageManager/PnpmPackageManager'; +console.log('BaseInstallManager.ts : 18: ' + (new Date().getTime() % 20000) / 1000.0); import { PurgeManager } from '../PurgeManager'; +console.log('BaseInstallManager.ts : 19: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfiguration, ICurrentVariantJson } from '../../api/RushConfiguration'; +console.log('BaseInstallManager.ts : 20: ' + (new Date().getTime() % 20000) / 1000.0); import { Rush } from '../../api/Rush'; +console.log('BaseInstallManager.ts : 21: ' + (new Date().getTime() % 20000) / 1000.0); import { RushGlobalFolder } from '../../api/RushGlobalFolder'; +console.log('BaseInstallManager.ts : 22: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConstants } from '../RushConstants'; +console.log('BaseInstallManager.ts : 23: ' + (new Date().getTime() % 20000) / 1000.0); import { ShrinkwrapFileFactory } from '../ShrinkwrapFileFactory'; +console.log('BaseInstallManager.ts : 24: ' + (new Date().getTime() % 20000) / 1000.0); import { Utilities } from '../../utilities/Utilities'; +console.log('BaseInstallManager.ts : 25: ' + (new Date().getTime() % 20000) / 1000.0); import { InstallHelpers } from '../installManager/InstallHelpers'; +console.log('BaseInstallManager.ts : 26: ' + (new Date().getTime() % 20000) / 1000.0); import { PolicyValidator } from '../policy/PolicyValidator'; +console.log('BaseInstallManager.ts : 27: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfigurationProject } from '../../api/RushConfigurationProject'; +console.log('BaseInstallManager.ts : 28: ' + (new Date().getTime() % 20000) / 1000.0); export interface IInstallManagerOptions { /** diff --git a/apps/rush-lib/src/logic/deploy/DeployManager.ts b/apps/rush-lib/src/logic/deploy/DeployManager.ts index f5205781e7c..d48e34c8350 100644 --- a/apps/rush-lib/src/logic/deploy/DeployManager.ts +++ b/apps/rush-lib/src/logic/deploy/DeployManager.ts @@ -4,17 +4,26 @@ // eslint-disable-next-line const importLazy = require('import-lazy')(require); +console.log('DeployManager.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as colors from 'colors'; +console.log('DeployManager.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as path from 'path'; -import * as resolve from 'resolve'; -import * as npmPacklist from 'npm-packlist'; +console.log('DeployManager.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); +const resolve = importLazy('resolve'); +console.log('DeployManager.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); +// eslint-disable-next-line +const npmPacklist = importLazy('npm-packlist'); +console.log('DeployManager.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); // eslint-disable-next-line const pnpmLinkBins = importLazy('@pnpm/link-bins'); +console.log('DeployManager.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); // (Used only by the legacy code fragment in the resolve.sync() hook below) import * as fsForResolve from 'fs'; +console.log('DeployManager.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); import ignore, { Ignore } from 'ignore'; +console.log('DeployManager.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); import { Path, FileSystem, @@ -28,21 +37,26 @@ import { NewlineKind, Text } from '@rushstack/node-core-library'; +console.log('DeployManager.ts : 9: ' + (new Date().getTime() % 20000) / 1000.0); import { DeployArchiver } from './DeployArchiver'; +console.log('DeployManager.ts : 10: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfiguration } from '../../api/RushConfiguration'; +console.log('DeployManager.ts : 11: ' + (new Date().getTime() % 20000) / 1000.0); import { SymlinkAnalyzer, ILinkInfo } from './SymlinkAnalyzer'; +console.log('DeployManager.ts : 12: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfigurationProject } from '../../api/RushConfigurationProject'; +console.log('DeployManager.ts : 13: ' + (new Date().getTime() % 20000) / 1000.0); import { DeployScenarioConfiguration, IDeployScenarioProjectJson } from './DeployScenarioConfiguration'; +console.log('DeployManager.ts : 14: ' + (new Date().getTime() % 20000) / 1000.0); import { PnpmfileConfiguration } from './PnpmfileConfiguration'; +console.log('DeployManager.ts : 15: ' + (new Date().getTime() % 20000) / 1000.0); import { matchesWithStar } from './Utils'; +console.log('DeployManager.ts : 16: ' + (new Date().getTime() % 20000) / 1000.0); -// (@types/npm-packlist is missing this API) -declare module 'npm-packlist' { - export class WalkerSync { - public readonly result: string[]; - public constructor(opts: { path: string }); - public start(): void; - } +interface INpmPackListWalkerSync { + readonly result: string[]; + constructor(opts: { path: string }); + start(): void; } /** @@ -390,7 +404,7 @@ export class DeployManager { if (useNpmIgnoreFilter) { // Use npm-packlist to filter the files. Using the WalkerSync class (instead of the sync() API) ensures // that "bundledDependencies" are not included. - const walker: npmPacklist.WalkerSync = new npmPacklist.WalkerSync({ + const walker: INpmPackListWalkerSync = new npmPacklist.WalkerSync({ path: sourceFolderPath }); walker.start(); diff --git a/apps/rush-lib/src/logic/installManager/RushInstallManager.ts b/apps/rush-lib/src/logic/installManager/RushInstallManager.ts index 2dba537f88c..f39577973b4 100644 --- a/apps/rush-lib/src/logic/installManager/RushInstallManager.ts +++ b/apps/rush-lib/src/logic/installManager/RushInstallManager.ts @@ -5,7 +5,8 @@ const importLazy = require('import-lazy')(require); console.log('RushInstallManager.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); -import * as glob from 'glob'; +// import * as glob from 'glob'; +const glob = importLazy('glob'); console.log('RushInstallManager.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as colors from 'colors'; console.log('RushInstallManager.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); diff --git a/apps/rush-lib/src/logic/installManager/WorkspaceInstallManager.ts b/apps/rush-lib/src/logic/installManager/WorkspaceInstallManager.ts index 6ed029d3ae2..76650f6e287 100644 --- a/apps/rush-lib/src/logic/installManager/WorkspaceInstallManager.ts +++ b/apps/rush-lib/src/logic/installManager/WorkspaceInstallManager.ts @@ -1,10 +1,15 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +console.log('WorkspaceInstallManager.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as colors from 'colors'; +console.log('WorkspaceInstallManager.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as os from 'os'; +console.log('WorkspaceInstallManager.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import * as path from 'path'; +console.log('WorkspaceInstallManager.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import * as semver from 'semver'; +console.log('WorkspaceInstallManager.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import { FileSystem, InternalError, @@ -12,24 +17,42 @@ import { JsonFile, FileConstants } from '@rushstack/node-core-library'; +console.log('WorkspaceInstallManager.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); import { AlreadyReportedError } from '../../utilities/AlreadyReportedError'; +console.log('WorkspaceInstallManager.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); import { BaseInstallManager, IInstallManagerOptions } from '../base/BaseInstallManager'; +console.log('WorkspaceInstallManager.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); import { BaseShrinkwrapFile } from '../../logic/base/BaseShrinkwrapFile'; +console.log('WorkspaceInstallManager.ts : 9: ' + (new Date().getTime() % 20000) / 1000.0); import { DependencySpecifier, DependencySpecifierType } from '../DependencySpecifier'; +console.log('WorkspaceInstallManager.ts : 10: ' + (new Date().getTime() % 20000) / 1000.0); import { PackageJsonEditor, DependencyType, PackageJsonDependency } from '../../api/PackageJsonEditor'; +console.log('WorkspaceInstallManager.ts : 11: ' + (new Date().getTime() % 20000) / 1000.0); import { PnpmWorkspaceFile } from '../pnpm/PnpmWorkspaceFile'; +console.log('WorkspaceInstallManager.ts : 12: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfigurationProject } from '../../api/RushConfigurationProject'; +console.log('WorkspaceInstallManager.ts : 13: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConstants } from '../../logic/RushConstants'; +console.log('WorkspaceInstallManager.ts : 14: ' + (new Date().getTime() % 20000) / 1000.0); import { Stopwatch } from '../../utilities/Stopwatch'; +console.log('WorkspaceInstallManager.ts : 15: ' + (new Date().getTime() % 20000) / 1000.0); import { Utilities } from '../../utilities/Utilities'; +console.log('WorkspaceInstallManager.ts : 16: ' + (new Date().getTime() % 20000) / 1000.0); import { InstallHelpers } from './InstallHelpers'; +console.log('WorkspaceInstallManager.ts : 17: ' + (new Date().getTime() % 20000) / 1000.0); import { CommonVersionsConfiguration } from '../../api/CommonVersionsConfiguration'; +console.log('WorkspaceInstallManager.ts : 18: ' + (new Date().getTime() % 20000) / 1000.0); import { RepoStateFile } from '../RepoStateFile'; +console.log('WorkspaceInstallManager.ts : 19: ' + (new Date().getTime() % 20000) / 1000.0); import { IPnpmfileShimSettings } from '../pnpm/IPnpmfileShimSettings'; +console.log('WorkspaceInstallManager.ts : 20: ' + (new Date().getTime() % 20000) / 1000.0); import { PnpmProjectDependencyManifest } from '../pnpm/PnpmProjectDependencyManifest'; +console.log('WorkspaceInstallManager.ts : 21: ' + (new Date().getTime() % 20000) / 1000.0); import { PnpmShrinkwrapFile, IPnpmShrinkwrapImporterYaml } from '../pnpm/PnpmShrinkwrapFile'; +console.log('WorkspaceInstallManager.ts : 22: ' + (new Date().getTime() % 20000) / 1000.0); import { LastLinkFlagFactory } from '../../api/LastLinkFlag'; +console.log('WorkspaceInstallManager.ts : 22: ' + (new Date().getTime() % 20000) / 1000.0); /** * This class implements common logic between "rush install" and "rush update". diff --git a/apps/rush-lib/src/logic/pnpm/PnpmShrinkwrapFile.ts b/apps/rush-lib/src/logic/pnpm/PnpmShrinkwrapFile.ts index 58d9124bedb..d154b7a2ad0 100644 --- a/apps/rush-lib/src/logic/pnpm/PnpmShrinkwrapFile.ts +++ b/apps/rush-lib/src/logic/pnpm/PnpmShrinkwrapFile.ts @@ -1,31 +1,40 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import * as yaml from 'js-yaml'; +// eslint-disable-next-line +const importLazy = require('import-lazy')(require); + +console.log('PnpmShrinkwrapFile.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); +// eslint-disable-next-line +const yaml = importLazy('js-yaml'); +console.log('PnpmShrinkwrapFile.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as os from 'os'; +console.log('PnpmShrinkwrapFile.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import * as path from 'path'; +console.log('PnpmShrinkwrapFile.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import * as semver from 'semver'; +console.log('PnpmShrinkwrapFile.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import * as crypto from 'crypto'; +console.log('PnpmShrinkwrapFile.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); import * as colors from 'colors'; +console.log('PnpmShrinkwrapFile.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); import { FileSystem } from '@rushstack/node-core-library'; +console.log('PnpmShrinkwrapFile.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); import { BaseShrinkwrapFile } from '../base/BaseShrinkwrapFile'; +console.log('PnpmShrinkwrapFile.ts : 9: ' + (new Date().getTime() % 20000) / 1000.0); import { DependencySpecifier } from '../DependencySpecifier'; +console.log('PnpmShrinkwrapFile.ts : 10: ' + (new Date().getTime() % 20000) / 1000.0); import { PackageManagerOptionsConfigurationBase, PnpmOptionsConfiguration } from '../../api/RushConfiguration'; +console.log('PnpmShrinkwrapFile.ts : 11: ' + (new Date().getTime() % 20000) / 1000.0); import { IShrinkwrapFilePolicyValidatorOptions } from '../policy/ShrinkwrapFilePolicy'; +console.log('PnpmShrinkwrapFile.ts : 12: ' + (new Date().getTime() % 20000) / 1000.0); import { AlreadyReportedError } from '../../utilities/AlreadyReportedError'; - -// This is based on PNPM's own configuration: -// https://github.com/pnpm/pnpm-shrinkwrap/blob/master/src/write.ts -const SHRINKWRAP_YAML_FORMAT: yaml.DumpOptions = { - lineWidth: 1000, - noCompatMode: true, - noRefs: true, - sortKeys: true -}; +import { PNPM_SHRINKWRAP_YAML_FORMAT } from './PnpmYamlCommon'; +console.log('PnpmShrinkwrapFile.ts : 13: ' + (new Date().getTime() % 20000) / 1000.0); export interface IPeerDependenciesMetaYaml { optional?: boolean; @@ -437,7 +446,7 @@ export class PnpmShrinkwrapFile extends BaseShrinkwrapFile { } } - return yaml.safeDump(shrinkwrapToSerialize, SHRINKWRAP_YAML_FORMAT); + return yaml.safeDump(shrinkwrapToSerialize, PNPM_SHRINKWRAP_YAML_FORMAT); } /** diff --git a/apps/rush-lib/src/logic/pnpm/PnpmWorkspaceFile.ts b/apps/rush-lib/src/logic/pnpm/PnpmWorkspaceFile.ts index dd3618a549c..dc42eeded83 100644 --- a/apps/rush-lib/src/logic/pnpm/PnpmWorkspaceFile.ts +++ b/apps/rush-lib/src/logic/pnpm/PnpmWorkspaceFile.ts @@ -1,22 +1,18 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +// eslint-disable-next-line +const importLazy = require('import-lazy')(require); + import * as globEscape from 'glob-escape'; import * as os from 'os'; import * as path from 'path'; -import * as yaml from 'js-yaml'; +// eslint-disable-next-line +const yaml = importLazy('js-yaml'); import { FileSystem, Sort, Text } from '@rushstack/node-core-library'; import { BaseWorkspaceFile } from '../base/BaseWorkspaceFile'; - -// This is based on PNPM's own configuration: -// https://github.com/pnpm/pnpm-shrinkwrap/blob/master/src/write.ts -const WORKSPACE_YAML_FORMAT: yaml.DumpOptions = { - lineWidth: 1000, - noCompatMode: true, - noRefs: true, - sortKeys: true -}; +import { PNPM_SHRINKWRAP_YAML_FORMAT as PNPM_YAML_DUMP_OPTIONS } from './PnpmYamlCommon'; /** * This interface represents the raw pnpm-workspace.YAML file @@ -81,6 +77,6 @@ export class PnpmWorkspaceFile extends BaseWorkspaceFile { const workspaceYaml: IPnpmWorkspaceYaml = { packages: Array.from(this._workspacePackages) }; - return yaml.safeDump(workspaceYaml, WORKSPACE_YAML_FORMAT); + return yaml.safeDump(workspaceYaml, PNPM_YAML_DUMP_OPTIONS); } } diff --git a/apps/rush-lib/src/logic/pnpm/PnpmYamlCommon.ts b/apps/rush-lib/src/logic/pnpm/PnpmYamlCommon.ts new file mode 100644 index 00000000000..b94be3e3563 --- /dev/null +++ b/apps/rush-lib/src/logic/pnpm/PnpmYamlCommon.ts @@ -0,0 +1,15 @@ +export interface IYamlDumpOptions { + lineWidth: number; + noCompatMode: boolean; + noRefs: boolean; + sortKeys: boolean; +} + +// This is based on PNPM's own configuration: +// https://github.com/pnpm/pnpm-shrinkwrap/blob/master/src/write.ts +export const PNPM_SHRINKWRAP_YAML_FORMAT: IYamlDumpOptions = { + lineWidth: 1000, + noCompatMode: true, + noRefs: true, + sortKeys: true +}; diff --git a/apps/rush-lib/src/start.ts b/apps/rush-lib/src/start.ts index 334fa2a4e1f..2f73cdd6d10 100644 --- a/apps/rush-lib/src/start.ts +++ b/apps/rush-lib/src/start.ts @@ -6,5 +6,7 @@ console.log('start.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import { Rush } from './api/Rush'; console.log('start.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); -Rush.launch(Rush.version, { isManaged: false }); +const rushVersion: string = Rush.version; console.log('start.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); +Rush.launch(rushVersion, { isManaged: false }); +console.log('start.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); diff --git a/common/reviews/api/node-core-library.api.md b/common/reviews/api/node-core-library.api.md index 002a514eefa..84b28b7994d 100644 --- a/common/reviews/api/node-core-library.api.md +++ b/common/reviews/api/node-core-library.api.md @@ -650,4 +650,6 @@ export enum TextAttribute { } +// (No @packageDocumentation comment for this package) + ``` diff --git a/libraries/node-core-library/src/Executable.ts b/libraries/node-core-library/src/Executable.ts index d36e2691d38..e29a71902ec 100644 --- a/libraries/node-core-library/src/Executable.ts +++ b/libraries/node-core-library/src/Executable.ts @@ -1,12 +1,18 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +console.log('NCL.Executable.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as child_process from 'child_process'; +console.log('NCL.Executable.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as os from 'os'; +console.log('NCL.Executable.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import * as path from 'path'; +console.log('NCL.Executable.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { FileSystem } from './FileSystem'; +console.log('NCL.Executable.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import { PosixModeBits } from './PosixModeBits'; +console.log('NCL.Executable.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); /** * Typings for one of the streams inside IExecutableSpawnSyncOptions.stdio. diff --git a/libraries/node-core-library/src/FileSystem.ts b/libraries/node-core-library/src/FileSystem.ts index aef1592c933..b5a423d21de 100644 --- a/libraries/node-core-library/src/FileSystem.ts +++ b/libraries/node-core-library/src/FileSystem.ts @@ -1,12 +1,23 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +// eslint-disable-next-line +const importLazy = require('import-lazy')(require); + +console.log('NCL.FileSystem.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as nodeJsPath from 'path'; +console.log('NCL.FileSystem.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as fs from 'fs'; -import * as fsx from 'fs-extra'; +console.log('NCL.FileSystem.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); +// import * as fsx from 'fs-extra'; +// eslint-disable-next-line +const fsx = importLazy('fs-extra'); +console.log('NCL.FileSystem.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { Text, NewlineKind, Encoding } from './Text'; +console.log('NCL.FileSystem.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import { PosixModeBits } from './PosixModeBits'; +console.log('NCL.FileSystem.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); /** * An alias for the Node.js `fs.Stats` object. diff --git a/libraries/node-core-library/src/FileWriter.ts b/libraries/node-core-library/src/FileWriter.ts index 906c1a8e6a8..d1147d5969c 100644 --- a/libraries/node-core-library/src/FileWriter.ts +++ b/libraries/node-core-library/src/FileWriter.ts @@ -1,7 +1,12 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import * as fsx from 'fs-extra'; +// eslint-disable-next-line +const importLazy = require('import-lazy')(require); + +// import * as fsx from 'fs-extra'; +// eslint-disable-next-line +const fsx = importLazy('fs-extra'); /** * Available file handle opening flags. diff --git a/libraries/node-core-library/src/JsonSchema.ts b/libraries/node-core-library/src/JsonSchema.ts index 49d2e58c024..3a2214f9705 100644 --- a/libraries/node-core-library/src/JsonSchema.ts +++ b/libraries/node-core-library/src/JsonSchema.ts @@ -1,13 +1,9 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line -const importLazy = require('import-lazy')(require); - import * as os from 'os'; import * as path from 'path'; -// eslint-disable-next-line -const Validator = importLazy('z-schema'); +import Validator = require('z-schema'); import { JsonFile, JsonObject } from './JsonFile'; import { FileSystem } from './FileSystem'; @@ -75,8 +71,7 @@ export interface IJsonSchemaFromFileOptions { export class JsonSchema { private _dependentSchemas: JsonSchema[] = []; private _filename: string = ''; - // eslint-disable-next-line - private _validator; + private _validator: Validator | undefined = undefined; private _schemaObject: JsonObject | undefined = undefined; private constructor() {} @@ -158,18 +153,15 @@ export class JsonSchema { /** * Used to nicely format the ZSchema error tree. */ - // eslint-disable-next-line - private static _formatErrorDetails(errorDetails /*: Validator.SchemaErrorDetail[]*/): string { + private static _formatErrorDetails(errorDetails: Validator.SchemaErrorDetail[]): string { return JsonSchema._formatErrorDetailsHelper(errorDetails, '', ''); } /** * Used by _formatErrorDetails. */ - // eslint-disable-next-line private static _formatErrorDetailsHelper( - // eslint-disable-next-line - errorDetails /*: Validator.SchemaErrorDetail[]*/, + errorDetails: Validator.SchemaErrorDetail[], indent: string, buffer: string ): string { @@ -226,8 +218,7 @@ export class JsonSchema { if (!this._validator) { // Don't assign this to _validator until we're sure everything was successful - // eslint-disable-next-line - const newValidator = new Validator({ + const newValidator: Validator = new Validator({ breakOnFirstError: false, noTypeless: true, noExtraKeywords: true @@ -294,7 +285,6 @@ export class JsonSchema { this.ensureCompiled(); if (!this._validator!.validate(jsonObject, this._schemaObject)) { - // eslint-disable-next-line const errorDetails: string = JsonSchema._formatErrorDetails(this._validator!.getLastErrors()); const args: IJsonSchemaErrorInfo = { diff --git a/libraries/node-core-library/src/LegacyAdapters.ts b/libraries/node-core-library/src/LegacyAdapters.ts index 759cca26142..03ca0f3d09a 100644 --- a/libraries/node-core-library/src/LegacyAdapters.ts +++ b/libraries/node-core-library/src/LegacyAdapters.ts @@ -1,8 +1,11 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +console.log('LegacyAdapters.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import { sort as timsort } from 'timsort'; +console.log('LegacyAdapters.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as semver from 'semver'; +console.log('LegacyAdapters.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); /** * Callback used by {@link LegacyAdapters}. diff --git a/libraries/node-core-library/src/PackageJsonLookup.ts b/libraries/node-core-library/src/PackageJsonLookup.ts index 6152e073d49..4e5705df611 100644 --- a/libraries/node-core-library/src/PackageJsonLookup.ts +++ b/libraries/node-core-library/src/PackageJsonLookup.ts @@ -1,11 +1,17 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +console.log('PackageJsonLookup.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as path from 'path'; +console.log('PackageJsonLookup.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import { JsonFile } from './JsonFile'; +console.log('PackageJsonLookup.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import { IPackageJson, INodePackageJson } from './IPackageJson'; +console.log('PackageJsonLookup.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { FileConstants } from './Constants'; +console.log('PackageJsonLookup.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import { FileSystem } from './FileSystem'; +console.log('PackageJsonLookup.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); /** * Constructor parameters for {@link PackageJsonLookup} diff --git a/libraries/node-core-library/src/index.ts b/libraries/node-core-library/src/index.ts index 7e23cfa79ca..6dc657853d8 100644 --- a/libraries/node-core-library/src/index.ts +++ b/libraries/node-core-library/src/index.ts @@ -7,7 +7,9 @@ * @packageDocumentation */ +console.log('NCL.index.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); export { FileConstants, FolderConstants } from './Constants'; +console.log('NCL.index.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); export { ExecutableStdioStreamMapping, ExecutableStdioMapping, @@ -15,25 +17,35 @@ export { IExecutableSpawnSyncOptions, Executable } from './Executable'; +console.log('NCL.index.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); export { INodePackageJson, IPackageJson, IPackageJsonDependencyTable, IPackageJsonScriptTable } from './IPackageJson'; +console.log('NCL.index.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); export { InternalError } from './InternalError'; +console.log('NCL.index.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); export { JsonObject, JsonFile, IJsonFileSaveOptions, IJsonFileStringifyOptions } from './JsonFile'; +console.log('NCL.index.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); export { JsonSchema, IJsonSchemaErrorInfo, IJsonSchemaValidateOptions, IJsonSchemaFromFileOptions } from './JsonSchema'; +console.log('NCL.index.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); export { LockFile } from './LockFile'; +console.log('NCL.index.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); export { MapExtensions } from './MapExtensions'; +console.log('NCL.index.ts : 9: ' + (new Date().getTime() % 20000) / 1000.0); export { PosixModeBits } from './PosixModeBits'; +console.log('NCL.index.ts : 10: ' + (new Date().getTime() % 20000) / 1000.0); export { ProtectableMap, IProtectableMapParameters } from './ProtectableMap'; +console.log('NCL.index.ts : 11: ' + (new Date().getTime() % 20000) / 1000.0); export { IPackageJsonLookupParameters, PackageJsonLookup } from './PackageJsonLookup'; +console.log('NCL.index.ts : 12: ' + (new Date().getTime() % 20000) / 1000.0); export { PackageName, PackageNameParser, @@ -41,9 +53,13 @@ export { IParsedPackageName, IParsedPackageNameOrError } from './PackageName'; +console.log('NCL.index.ts : 13: ' + (new Date().getTime() % 20000) / 1000.0); export { Path } from './Path'; +console.log('NCL.index.ts : 14: ' + (new Date().getTime() % 20000) / 1000.0); export { Encoding, Text, NewlineKind } from './Text'; +console.log('NCL.index.ts : 15: ' + (new Date().getTime() % 20000) / 1000.0); export { Sort } from './Sort'; +console.log('NCL.index.ts : 16: ' + (new Date().getTime() % 20000) / 1000.0); export { AlreadyExistsBehavior, FileSystem, @@ -61,11 +77,20 @@ export { FileSystemCopyFilesAsyncFilter, FileSystemCopyFilesFilter } from './FileSystem'; +console.log('NCL.index.ts : 17: ' + (new Date().getTime() % 20000) / 1000.0); export { FileWriter, IFileWriterFlags } from './FileWriter'; +console.log('NCL.index.ts : 18: ' + (new Date().getTime() % 20000) / 1000.0); export { LegacyAdapters, LegacyCallback } from './LegacyAdapters'; +console.log('NCL.index.ts : 19: ' + (new Date().getTime() % 20000) / 1000.0); export { StringBuilder, IStringBuilder } from './StringBuilder'; +console.log('NCL.index.ts : 20: ' + (new Date().getTime() % 20000) / 1000.0); export { Terminal } from './Terminal/Terminal'; +console.log('NCL.index.ts : 21: ' + (new Date().getTime() % 20000) / 1000.0); export { Colors, IColorableSequence, ColorValue, TextAttribute } from './Terminal/Colors'; +console.log('NCL.index.ts : 22: ' + (new Date().getTime() % 20000) / 1000.0); export { ITerminalProvider, TerminalProviderSeverity } from './Terminal/ITerminalProvider'; +console.log('NCL.index.ts : 23: ' + (new Date().getTime() % 20000) / 1000.0); export { ConsoleTerminalProvider, IConsoleTerminalProviderOptions } from './Terminal/ConsoleTerminalProvider'; +console.log('NCL.index.ts : 24: ' + (new Date().getTime() % 20000) / 1000.0); export { StringBufferTerminalProvider } from './Terminal/StringBufferTerminalProvider'; +console.log('NCL.index.ts : 25: ' + (new Date().getTime() % 20000) / 1000.0); From 9cf5d08296ebe3373668d99f2084b51dad3a59a4 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Fri, 31 Jul 2020 23:36:03 -0700 Subject: [PATCH 30/97] Further optimization --- apps/rush-lib/src/api/LastInstallFlag.ts | 5 ++++- apps/rush-lib/src/api/Rush.ts | 2 +- apps/rush-lib/src/api/VersionPolicy.ts | 9 +++++--- .../src/logic/ShrinkwrapFileFactory.ts | 7 +++++++ apps/rush-lib/src/logic/Telemetry.ts | 7 +++++-- apps/rush-lib/src/logic/VersionManager.ts | 7 +++++-- .../src/logic/npm/NpmShrinkwrapFile.ts | 4 ++++ .../src/logic/yarn/YarnShrinkwrapFile.ts | 21 +++++++++++++++++-- common/reviews/api/node-core-library.api.md | 2 ++ libraries/node-core-library/src/JsonFile.ts | 6 ++++++ libraries/node-core-library/src/JsonSchema.ts | 8 ++++++- .../src/PackageJsonLookup.ts | 17 +++++++++++++++ 12 files changed, 83 insertions(+), 12 deletions(-) diff --git a/apps/rush-lib/src/api/LastInstallFlag.ts b/apps/rush-lib/src/api/LastInstallFlag.ts index b52d194991a..cb9a9f8b980 100644 --- a/apps/rush-lib/src/api/LastInstallFlag.ts +++ b/apps/rush-lib/src/api/LastInstallFlag.ts @@ -1,8 +1,11 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +// eslint-disable-next-line +const importLazy = require('import-lazy')(require); + import * as path from 'path'; -import * as _ from 'lodash'; +const _ = importLazy('lodash'); import { FileSystem, JsonFile, JsonObject } from '@rushstack/node-core-library'; import { PackageManagerName } from './packageManager/PackageManager'; diff --git a/apps/rush-lib/src/api/Rush.ts b/apps/rush-lib/src/api/Rush.ts index 49f20ef0dab..3e71aa70278 100644 --- a/apps/rush-lib/src/api/Rush.ts +++ b/apps/rush-lib/src/api/Rush.ts @@ -106,7 +106,7 @@ export class Rush { * This is the same as the Rush tool version for that release. */ public static get version(): string { - return PackageJsonLookup.loadOwnPackageJson(__dirname).version; + return PackageJsonLookup.getOwnPackageJsonVersion(__dirname); } /** diff --git a/apps/rush-lib/src/api/VersionPolicy.ts b/apps/rush-lib/src/api/VersionPolicy.ts index 9ee80139e6d..fbd8e855774 100644 --- a/apps/rush-lib/src/api/VersionPolicy.ts +++ b/apps/rush-lib/src/api/VersionPolicy.ts @@ -1,8 +1,11 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +// eslint-disable-next-line +const importLazy = require('import-lazy')(require); + console.log('VersionPolicy.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); -import { cloneDeep } from 'lodash'; +const _ = importLazy('lodash'); console.log('VersionPolicy.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as semver from 'semver'; console.log('VersionPolicy.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); @@ -328,7 +331,7 @@ export class LockStepVersionPolicy extends VersionPolicy { } private _updatePackageVersion(project: IPackageJson, newVersion: semver.SemVer): IPackageJson { - const updatedProject: IPackageJson = cloneDeep(project); + const updatedProject: IPackageJson = _.cloneDeep(project); updatedProject.version = newVersion.format(); return updatedProject; } @@ -387,7 +390,7 @@ export class IndividualVersionPolicy extends VersionPolicy { if (this.lockedMajor) { const version: semver.SemVer = new semver.SemVer(project.version); if (version.major < this.lockedMajor) { - const updatedProject: IPackageJson = cloneDeep(project); + const updatedProject: IPackageJson = _.cloneDeep(project); updatedProject.version = `${this._lockedMajor}.0.0`; return updatedProject; } else if (version.major > this.lockedMajor) { diff --git a/apps/rush-lib/src/logic/ShrinkwrapFileFactory.ts b/apps/rush-lib/src/logic/ShrinkwrapFileFactory.ts index 8df0af0837c..e178972d357 100644 --- a/apps/rush-lib/src/logic/ShrinkwrapFileFactory.ts +++ b/apps/rush-lib/src/logic/ShrinkwrapFileFactory.ts @@ -1,12 +1,19 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +console.log('ShrinkwrapFileFactory.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import { PackageManagerName } from '../api/packageManager/PackageManager'; +console.log('ShrinkwrapFileFactory.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import { BaseShrinkwrapFile } from './base/BaseShrinkwrapFile'; +console.log('ShrinkwrapFileFactory.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import { NpmShrinkwrapFile } from './npm/NpmShrinkwrapFile'; +console.log('ShrinkwrapFileFactory.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { PnpmShrinkwrapFile } from './pnpm/PnpmShrinkwrapFile'; +console.log('ShrinkwrapFileFactory.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import { YarnShrinkwrapFile } from './yarn/YarnShrinkwrapFile'; +console.log('ShrinkwrapFileFactory.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); import { PackageManagerOptionsConfigurationBase, PnpmOptionsConfiguration } from '../api/RushConfiguration'; +console.log('ShrinkwrapFileFactory.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); export class ShrinkwrapFileFactory { public static getShrinkwrapFile( diff --git a/apps/rush-lib/src/logic/Telemetry.ts b/apps/rush-lib/src/logic/Telemetry.ts index acad82c639c..7a681063012 100644 --- a/apps/rush-lib/src/logic/Telemetry.ts +++ b/apps/rush-lib/src/logic/Telemetry.ts @@ -1,9 +1,12 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +// eslint-disable-next-line +const importLazy = require('import-lazy')(require); + import * as fs from 'fs'; import * as path from 'path'; -import { cloneDeep } from 'lodash'; +const _ = importLazy('lodash'); import { RushConfiguration } from '../api/RushConfiguration'; import { Rush } from '../api/Rush'; @@ -40,7 +43,7 @@ export class Telemetry { if (!this._enabled) { return; } - const data: ITelemetryData = cloneDeep(telemetryData); + const data: ITelemetryData = _.cloneDeep(telemetryData); data.timestamp = data.timestamp || new Date().getTime(); data.platform = data.platform || process.platform; data.rushVersion = data.rushVersion || Rush.version; diff --git a/apps/rush-lib/src/logic/VersionManager.ts b/apps/rush-lib/src/logic/VersionManager.ts index 3a0237ae493..10b57e218ac 100644 --- a/apps/rush-lib/src/logic/VersionManager.ts +++ b/apps/rush-lib/src/logic/VersionManager.ts @@ -1,9 +1,12 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +// eslint-disable-next-line +const importLazy = require('import-lazy')(require); + import * as path from 'path'; import * as semver from 'semver'; -import { cloneDeep } from 'lodash'; +const _ = importLazy('lodash'); import { IPackageJson, JsonFile, FileConstants } from '@rushstack/node-core-library'; import { VersionPolicy, BumpType, LockStepVersionPolicy } from '../api/VersionPolicy'; @@ -185,7 +188,7 @@ export class VersionManager { let clonedProject: IPackageJson | undefined = this._updatedProjects.get(rushProject.packageName); let projectVersionChanged: boolean = true; if (!clonedProject) { - clonedProject = cloneDeep(rushProject.packageJson); + clonedProject = _.cloneDeep(rushProject.packageJson); projectVersionChanged = false; } this._updateProjectAllDependencies(rushProject, clonedProject!, projectVersionChanged); diff --git a/apps/rush-lib/src/logic/npm/NpmShrinkwrapFile.ts b/apps/rush-lib/src/logic/npm/NpmShrinkwrapFile.ts index 6fb91b74331..3c829d678cf 100644 --- a/apps/rush-lib/src/logic/npm/NpmShrinkwrapFile.ts +++ b/apps/rush-lib/src/logic/npm/NpmShrinkwrapFile.ts @@ -3,10 +3,14 @@ import * as os from 'os'; +console.log('NpmShrinkwrapFile.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import { JsonFile, FileSystem, InternalError } from '@rushstack/node-core-library'; +console.log('NpmShrinkwrapFile.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import { BaseShrinkwrapFile } from '../base/BaseShrinkwrapFile'; +console.log('NpmShrinkwrapFile.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import { DependencySpecifier } from '../DependencySpecifier'; +console.log('NpmShrinkwrapFile.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); interface INpmShrinkwrapDependencyJson { version: string; diff --git a/apps/rush-lib/src/logic/yarn/YarnShrinkwrapFile.ts b/apps/rush-lib/src/logic/yarn/YarnShrinkwrapFile.ts index 8a7b79d9db0..906f1413f26 100644 --- a/apps/rush-lib/src/logic/yarn/YarnShrinkwrapFile.ts +++ b/apps/rush-lib/src/logic/yarn/YarnShrinkwrapFile.ts @@ -1,13 +1,30 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +// eslint-disable-next-line +const importLazy = require('import-lazy')(require); + +console.log('YarnShrinkwrapFile.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as os from 'os'; -import * as lockfile from '@yarnpkg/lockfile'; +console.log('YarnShrinkwrapFile.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); +// eslint-disable-next-line +const lockfile = importLazy('@yarnpkg/lockfile'); +console.log('YarnShrinkwrapFile.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import { BaseShrinkwrapFile } from '../base/BaseShrinkwrapFile'; +console.log('YarnShrinkwrapFile.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { FileSystem, IParsedPackageNameOrError, InternalError } from '@rushstack/node-core-library'; +console.log('YarnShrinkwrapFile.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConstants } from '../RushConstants'; +console.log('YarnShrinkwrapFile.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); import { DependencySpecifier } from '../DependencySpecifier'; +console.log('YarnShrinkwrapFile.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); import { PackageNameParsers } from '../../api/PackageNameParsers'; +console.log('YarnShrinkwrapFile.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); + +interface IYarnLockfileParseResult { + // eslint-disable-next-line + object: any; +} /** * Used with YarnShrinkwrapFile._encodePackageNameAndSemVer() and _decodePackageNameAndSemVer(). @@ -146,7 +163,7 @@ export class YarnShrinkwrapFile extends BaseShrinkwrapFile { public static loadFromFile(shrinkwrapFilename: string): YarnShrinkwrapFile | undefined { let shrinkwrapString: string; - let shrinkwrapJson: lockfile.ParseResult; + let shrinkwrapJson: IYarnLockfileParseResult; try { if (!FileSystem.exists(shrinkwrapFilename)) { return undefined; // file does not exist diff --git a/common/reviews/api/node-core-library.api.md b/common/reviews/api/node-core-library.api.md index 84b28b7994d..9fbc8190a9d 100644 --- a/common/reviews/api/node-core-library.api.md +++ b/common/reviews/api/node-core-library.api.md @@ -496,6 +496,8 @@ export const enum NewlineKind { export class PackageJsonLookup { constructor(parameters?: IPackageJsonLookupParameters); clearCache(): void; + // (undocumented) + static getOwnPackageJsonVersion(dirnameOfCaller: string): string; loadNodePackageJson(jsonFilename: string): INodePackageJson; static loadOwnPackageJson(dirnameOfCaller: string): IPackageJson; loadPackageJson(jsonFilename: string): IPackageJson; diff --git a/libraries/node-core-library/src/JsonFile.ts b/libraries/node-core-library/src/JsonFile.ts index d4ca40c9314..ed62808b591 100644 --- a/libraries/node-core-library/src/JsonFile.ts +++ b/libraries/node-core-library/src/JsonFile.ts @@ -1,12 +1,18 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +console.log('JsonFile.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as os from 'os'; +console.log('JsonFile.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as jju from 'jju'; +console.log('JsonFile.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import { JsonSchema, IJsonSchemaErrorInfo, IJsonSchemaValidateOptions } from './JsonSchema'; +console.log('JsonFile.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { Text, NewlineKind } from './Text'; +console.log('JsonFile.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import { FileSystem } from './FileSystem'; +console.log('JsonFile.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); /** * Represents a JSON-serializable object whose type has not been determined yet. diff --git a/libraries/node-core-library/src/JsonSchema.ts b/libraries/node-core-library/src/JsonSchema.ts index 3a2214f9705..119630175c8 100644 --- a/libraries/node-core-library/src/JsonSchema.ts +++ b/libraries/node-core-library/src/JsonSchema.ts @@ -1,12 +1,18 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +console.log('JsonSchema.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as os from 'os'; +console.log('JsonSchema.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as path from 'path'; -import Validator = require('z-schema'); +console.log('JsonSchema.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); +import Validator = require('z-schema/dist/ZSchema-browser-min'); +console.log('JsonSchema.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { JsonFile, JsonObject } from './JsonFile'; +console.log('JsonSchema.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import { FileSystem } from './FileSystem'; +console.log('JsonSchema.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); interface ISchemaWithId { id: string | undefined; diff --git a/libraries/node-core-library/src/PackageJsonLookup.ts b/libraries/node-core-library/src/PackageJsonLookup.ts index 4e5705df611..72198e6b9b6 100644 --- a/libraries/node-core-library/src/PackageJsonLookup.ts +++ b/libraries/node-core-library/src/PackageJsonLookup.ts @@ -82,10 +82,12 @@ export class PackageJsonLookup { * loading, an exception will be thrown instead. */ public static loadOwnPackageJson(dirnameOfCaller: string): IPackageJson { + console.log('PackageJsonLookup.loadOwnPackageJson() : 1: ' + (new Date().getTime() % 20000) / 1000.0); const packageJson: | IPackageJson | undefined = PackageJsonLookup._loadOwnPackageJsonLookup.tryLoadPackageJsonFor(dirnameOfCaller); + console.log('PackageJsonLookup.loadOwnPackageJson() : 2: ' + (new Date().getTime() % 20000) / 1000.0); if (packageJson === undefined) { throw new Error( `PackageJsonLookup.loadOwnPackageJson() failed to find the caller's package.json.` + @@ -93,10 +95,12 @@ export class PackageJsonLookup { ); } + console.log('PackageJsonLookup.loadOwnPackageJson() : 3: ' + (new Date().getTime() % 20000) / 1000.0); if (packageJson.version !== undefined) { return packageJson as IPackageJson; } + console.log('PackageJsonLookup.loadOwnPackageJson() : 4: ' + (new Date().getTime() % 20000) / 1000.0); const errorPath: string = PackageJsonLookup._loadOwnPackageJsonLookup.tryGetPackageJsonFilePathFor(dirnameOfCaller) || 'package.json'; @@ -106,6 +110,19 @@ export class PackageJsonLookup { ); } + public static getOwnPackageJsonVersion(dirnameOfCaller: string): string { + let parent: string = path.dirname(dirnameOfCaller); + do { + try { + return require(path.resolve(dirnameOfCaller, 'package.json')).version; + } catch { + dirnameOfCaller = parent; + parent = path.dirname(dirnameOfCaller); + } + } while (parent !== dirnameOfCaller); + throw new Error("Couldn't get path"); + } + /** * Clears the internal file cache. * @remarks From e6a76ad7dc1b80ba99622184b638117353d94b1a Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Sat, 1 Aug 2020 00:46:09 -0700 Subject: [PATCH 31/97] Remove node-core-library lazyImport --- apps/rush-lib/src/api/PackageNameParsers.ts | 13 ++++--------- apps/rush-lib/src/logic/DependencySpecifier.ts | 13 +++---------- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/apps/rush-lib/src/api/PackageNameParsers.ts b/apps/rush-lib/src/api/PackageNameParsers.ts index 8409fc4d485..a248c0f4882 100644 --- a/apps/rush-lib/src/api/PackageNameParsers.ts +++ b/apps/rush-lib/src/api/PackageNameParsers.ts @@ -1,24 +1,19 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line -const importLazy = require('import-lazy')(require); - -// import { PackageNameParser } from '@rushstack/node-core-library'; -// eslint-disable-next-line -const nodeCoreLibrary = importLazy('@rushstack/node-core-library/lib/PackageName'); +import { PackageNameParser } from '@rushstack/node-core-library'; export class PackageNameParsers { /** * This is the default for `RushConfiguration.packageNameParser`. */ - public static rushDefault /*: PackageNameParser*/ = new nodeCoreLibrary.PackageNameParser({}); + public static rushDefault: PackageNameParser = new PackageNameParser({}); /** * This is the `RushConfiguration.packageNameParser` used when `allowMostlyStandardPackageNames = true` * in rush.json. */ - public static mostlyStandard /*: PackageNameParser*/ = new nodeCoreLibrary.PackageNameParser({ + public static mostlyStandard: PackageNameParser = new PackageNameParser({ allowUpperCase: true }); @@ -26,5 +21,5 @@ export class PackageNameParsers { * Use this in contexts where we don't have easy access to `RushConfiguration.packageNameParser` * AND the package name was already validated at some earlier stage. */ - public static permissive /*: PackageNameParser*/ = PackageNameParsers.mostlyStandard; + public static permissive: PackageNameParser = PackageNameParsers.mostlyStandard; } diff --git a/apps/rush-lib/src/logic/DependencySpecifier.ts b/apps/rush-lib/src/logic/DependencySpecifier.ts index 2dbdf659e1d..bdcf3d8a31f 100644 --- a/apps/rush-lib/src/logic/DependencySpecifier.ts +++ b/apps/rush-lib/src/logic/DependencySpecifier.ts @@ -1,15 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line -const importLazy = require('import-lazy')(require); - -console.log('DependencySpecifier.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import npmPackageArg = require('npm-package-arg'); -console.log('DependencySpecifier.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); -// import { InternalError } from '@rushstack/node-core-library'; -const nodeCoreLibrary = importLazy('@rushstack/node-core-library/lib/InternalError'); -console.log('DependencySpecifier.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); +import { InternalError } from '@rushstack/node-core-library'; /** * The parsed format of a provided version specifier. @@ -109,7 +102,7 @@ export class DependencySpecifier { if (this.specifierType === DependencySpecifierType.Alias) { const aliasResult: npmPackageArg.AliasResult = result as npmPackageArg.AliasResult; if (!aliasResult.subSpec || !aliasResult.subSpec.name) { - throw new nodeCoreLibrary.InternalError('Unexpected result from npm-package-arg'); + throw new InternalError('Unexpected result from npm-package-arg'); } this.aliasTarget = new DependencySpecifier(aliasResult.subSpec.name, aliasResult.subSpec.rawSpec); } else { @@ -136,7 +129,7 @@ export class DependencySpecifier { case 'alias': return DependencySpecifierType.Alias; default: - throw new nodeCoreLibrary.InternalError(`Unexpected npm-package-arg result type "${specifierType}"`); + throw new InternalError(`Unexpected npm-package-arg result type "${specifierType}"`); } } } From 2efcac0fbedd29d7063546072cad864f57ac1821 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Sat, 1 Aug 2020 00:54:06 -0700 Subject: [PATCH 32/97] Remove trace logs --- .../src/api/ApprovedPackagesPolicy.ts | 5 --- .../src/api/CommonVersionsConfiguration.ts | 6 ---- apps/rush-lib/src/api/LastInstallFlag.ts | 1 + apps/rush-lib/src/api/Rush.ts | 10 ------ apps/rush-lib/src/api/RushConfiguration.ts | 22 ------------ apps/rush-lib/src/api/VersionPolicy.ts | 9 +---- .../src/api/VersionPolicyConfiguration.ts | 5 --- .../rush-lib/src/cli/RushCommandLineParser.ts | 36 ------------------- apps/rush-lib/src/cli/RushXCommandLine.ts | 9 ----- apps/rush-lib/src/cli/actions/AddAction.ts | 9 ----- apps/rush-lib/src/cli/actions/ChangeAction.ts | 18 ---------- apps/rush-lib/src/cli/actions/DeployAction.ts | 5 --- apps/rush-lib/src/cli/actions/ListAction.ts | 6 ---- .../src/cli/scriptActions/BulkScriptAction.ts | 16 --------- .../src/logic/InstallManagerFactory.ts | 10 ------ apps/rush-lib/src/logic/LinkManagerFactory.ts | 5 --- apps/rush-lib/src/logic/PackageJsonUpdater.ts | 16 --------- apps/rush-lib/src/logic/RepoStateFile.ts | 6 ---- .../src/logic/ShrinkwrapFileFactory.ts | 7 ---- apps/rush-lib/src/logic/Telemetry.ts | 3 +- apps/rush-lib/src/logic/VersionManager.ts | 1 + .../src/logic/base/BaseInstallManager.ts | 28 --------------- .../src/logic/deploy/DeployArchiver.ts | 5 --- .../src/logic/deploy/DeployManager.ts | 16 --------- .../installManager/RushInstallManager.ts | 22 ------------ .../installManager/WorkspaceInstallManager.ts | 23 ------------ apps/rush-lib/src/logic/npm/NpmLinkManager.ts | 14 -------- .../src/logic/npm/NpmShrinkwrapFile.ts | 4 --- .../src/logic/pnpm/PnpmLinkManager.ts | 15 -------- .../src/logic/pnpm/PnpmShrinkwrapFile.ts | 13 ------- .../src/logic/yarn/YarnShrinkwrapFile.ts | 8 ----- apps/rush-lib/src/start.ts | 5 --- libraries/node-core-library/src/Executable.ts | 6 ---- libraries/node-core-library/src/FileSystem.ts | 6 ---- libraries/node-core-library/src/JsonFile.ts | 6 ---- libraries/node-core-library/src/JsonSchema.ts | 6 ---- .../node-core-library/src/LegacyAdapters.ts | 3 -- .../src/PackageJsonLookup.ts | 6 ---- libraries/node-core-library/src/index.ts | 25 ------------- libraries/ts-command-line/src/index.ts | 14 -------- .../src/providers/CommandLineAction.ts | 3 -- .../providers/CommandLineParameterProvider.ts | 10 ------ 42 files changed, 5 insertions(+), 438 deletions(-) diff --git a/apps/rush-lib/src/api/ApprovedPackagesPolicy.ts b/apps/rush-lib/src/api/ApprovedPackagesPolicy.ts index a0bcc2e4e3b..852bc315247 100644 --- a/apps/rush-lib/src/api/ApprovedPackagesPolicy.ts +++ b/apps/rush-lib/src/api/ApprovedPackagesPolicy.ts @@ -1,16 +1,11 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -console.log('ApprovedPackagesPolicy.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as path from 'path'; -console.log('ApprovedPackagesPolicy.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import { ApprovedPackagesConfiguration } from './ApprovedPackagesConfiguration'; -console.log('ApprovedPackagesPolicy.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConstants } from '../logic/RushConstants'; -console.log('ApprovedPackagesPolicy.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfiguration, IRushConfigurationJson, IApprovedPackagesPolicyJson } from './RushConfiguration'; -console.log('ApprovedPackagesPolicy.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); /** * This is a helper object for RushConfiguration. diff --git a/apps/rush-lib/src/api/CommonVersionsConfiguration.ts b/apps/rush-lib/src/api/CommonVersionsConfiguration.ts index c659f24cac5..b4f5c997fb1 100644 --- a/apps/rush-lib/src/api/CommonVersionsConfiguration.ts +++ b/apps/rush-lib/src/api/CommonVersionsConfiguration.ts @@ -1,11 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -console.log('CommonVersionsConfiguration.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as crypto from 'crypto'; -console.log('CommonVersionsConfiguration.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as path from 'path'; -console.log('CommonVersionsConfiguration.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import { JsonFile, JsonSchema, @@ -14,11 +11,8 @@ import { FileSystem, Sort } from '@rushstack/node-core-library'; -console.log('CommonVersionsConfiguration.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { PackageNameParsers } from './PackageNameParsers'; -console.log('CommonVersionsConfiguration.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import { JsonSchemaUrls } from '../logic/JsonSchemaUrls'; -console.log('CommonVersionsConfiguration.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); /** * Part of the ICommonVersionsJson structure. diff --git a/apps/rush-lib/src/api/LastInstallFlag.ts b/apps/rush-lib/src/api/LastInstallFlag.ts index cb9a9f8b980..52387957e3b 100644 --- a/apps/rush-lib/src/api/LastInstallFlag.ts +++ b/apps/rush-lib/src/api/LastInstallFlag.ts @@ -5,6 +5,7 @@ const importLazy = require('import-lazy')(require); import * as path from 'path'; +// eslint-disable-next-line const _ = importLazy('lodash'); import { FileSystem, JsonFile, JsonObject } from '@rushstack/node-core-library'; diff --git a/apps/rush-lib/src/api/Rush.ts b/apps/rush-lib/src/api/Rush.ts index 3e71aa70278..e8e263c635d 100644 --- a/apps/rush-lib/src/api/Rush.ts +++ b/apps/rush-lib/src/api/Rush.ts @@ -1,26 +1,16 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -console.log('Rush.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import { EOL } from 'os'; -console.log('Rush.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as colors from 'colors'; -console.log('Rush.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import { PackageJsonLookup } from '@rushstack/node-core-library'; -console.log('Rush.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { RushCommandLineParser } from '../cli/RushCommandLineParser'; -console.log('Rush.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConstants } from '../logic/RushConstants'; -console.log('Rush.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); import { RushXCommandLine } from '../cli/RushXCommandLine'; -console.log('Rush.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); import { CommandLineMigrationAdvisor } from '../cli/CommandLineMigrationAdvisor'; -console.log('Rush.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); import { NodeJsCompatibility } from '../logic/NodeJsCompatibility'; -console.log('Rush.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); import { Utilities } from '../utilities/Utilities'; -console.log('Rush.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); /** * Options to pass to the rush "launch" functions. diff --git a/apps/rush-lib/src/api/RushConfiguration.ts b/apps/rush-lib/src/api/RushConfiguration.ts index 0812cb3198e..05c4825c213 100644 --- a/apps/rush-lib/src/api/RushConfiguration.ts +++ b/apps/rush-lib/src/api/RushConfiguration.ts @@ -3,50 +3,28 @@ /* eslint max-lines: off */ -console.log('RushConfiguration.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as path from 'path'; -console.log('RushConfiguration.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as fs from 'fs'; -console.log('RushConfiguration.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import * as semver from 'semver'; -console.log('RushConfiguration.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { JsonFile, JsonSchema, Path, FileSystem, PackageNameParser } from '@rushstack/node-core-library'; -console.log('RushConfiguration.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import { trueCasePathSync } from 'true-case-path'; -console.log('RushConfiguration.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); import { Rush } from '../api/Rush'; -console.log('RushConfiguration.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfigurationProject, IRushConfigurationProjectJson } from './RushConfigurationProject'; -console.log('RushConfiguration.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConstants } from '../logic/RushConstants'; -console.log('RushConfiguration.ts : 9: ' + (new Date().getTime() % 20000) / 1000.0); import { ApprovedPackagesPolicy } from './ApprovedPackagesPolicy'; -console.log('RushConfiguration.ts : 10: ' + (new Date().getTime() % 20000) / 1000.0); import { EventHooks } from './EventHooks'; -console.log('RushConfiguration.ts : 11: ' + (new Date().getTime() % 20000) / 1000.0); import { VersionPolicyConfiguration } from './VersionPolicyConfiguration'; -console.log('RushConfiguration.ts : 12: ' + (new Date().getTime() % 20000) / 1000.0); import { EnvironmentConfiguration } from './EnvironmentConfiguration'; -console.log('RushConfiguration.ts : 13: ' + (new Date().getTime() % 20000) / 1000.0); import { CommonVersionsConfiguration } from './CommonVersionsConfiguration'; -console.log('RushConfiguration.ts : 14: ' + (new Date().getTime() % 20000) / 1000.0); import { Utilities } from '../utilities/Utilities'; -console.log('RushConfiguration.ts : 15: ' + (new Date().getTime() % 20000) / 1000.0); import { PackageManagerName, PackageManager } from './packageManager/PackageManager'; -console.log('RushConfiguration.ts : 16: ' + (new Date().getTime() % 20000) / 1000.0); import { NpmPackageManager } from './packageManager/NpmPackageManager'; -console.log('RushConfiguration.ts : 17: ' + (new Date().getTime() % 20000) / 1000.0); import { YarnPackageManager } from './packageManager/YarnPackageManager'; -console.log('RushConfiguration.ts : 18: ' + (new Date().getTime() % 20000) / 1000.0); import { PnpmPackageManager } from './packageManager/PnpmPackageManager'; -console.log('RushConfiguration.ts : 19: ' + (new Date().getTime() % 20000) / 1000.0); import { ExperimentsConfiguration } from './ExperimentsConfiguration'; -console.log('RushConfiguration.ts : 20: ' + (new Date().getTime() % 20000) / 1000.0); import { PackageNameParsers } from './PackageNameParsers'; -console.log('RushConfiguration.ts : 21: ' + (new Date().getTime() % 20000) / 1000.0); import { RepoStateFile } from '../logic/RepoStateFile'; -console.log('RushConfiguration.ts : 22: ' + (new Date().getTime() % 20000) / 1000.0); const MINIMUM_SUPPORTED_RUSH_JSON_VERSION: string = '0.0.0'; const DEFAULT_BRANCH: string = 'master'; diff --git a/apps/rush-lib/src/api/VersionPolicy.ts b/apps/rush-lib/src/api/VersionPolicy.ts index fbd8e855774..a9ebdbeca3c 100644 --- a/apps/rush-lib/src/api/VersionPolicy.ts +++ b/apps/rush-lib/src/api/VersionPolicy.ts @@ -4,13 +4,10 @@ // eslint-disable-next-line const importLazy = require('import-lazy')(require); -console.log('VersionPolicy.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); +// eslint-disable-next-line const _ = importLazy('lodash'); -console.log('VersionPolicy.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as semver from 'semver'; -console.log('VersionPolicy.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import { IPackageJson } from '@rushstack/node-core-library'; -console.log('VersionPolicy.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { IVersionPolicyJson, @@ -20,13 +17,9 @@ import { VersionFormatForPublish, IVersionPolicyDependencyJson } from './VersionPolicyConfiguration'; -console.log('VersionPolicy.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import { PackageJsonEditor } from './PackageJsonEditor'; -console.log('VersionPolicy.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfiguration } from './RushConfiguration'; -console.log('VersionPolicy.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfigurationProject } from './RushConfigurationProject'; -console.log('VersionPolicy.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); /** * Type of version bumps diff --git a/apps/rush-lib/src/api/VersionPolicyConfiguration.ts b/apps/rush-lib/src/api/VersionPolicyConfiguration.ts index fcc59a712df..8dbca789495 100644 --- a/apps/rush-lib/src/api/VersionPolicyConfiguration.ts +++ b/apps/rush-lib/src/api/VersionPolicyConfiguration.ts @@ -1,16 +1,11 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -console.log('VersionPolicyConfiguration.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as path from 'path'; -console.log('VersionPolicyConfiguration.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import { JsonFile, JsonSchema, FileSystem } from '@rushstack/node-core-library'; -console.log('VersionPolicyConfiguration.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import { VersionPolicy, BumpType, LockStepVersionPolicy } from './VersionPolicy'; -console.log('VersionPolicyConfiguration.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfigurationProject } from './RushConfigurationProject'; -console.log('VersionPolicyConfiguration.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); /** * @beta diff --git a/apps/rush-lib/src/cli/RushCommandLineParser.ts b/apps/rush-lib/src/cli/RushCommandLineParser.ts index 357a9387939..1938c42649f 100644 --- a/apps/rush-lib/src/cli/RushCommandLineParser.ts +++ b/apps/rush-lib/src/cli/RushCommandLineParser.ts @@ -1,82 +1,46 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -console.log('RushCommandLineParser.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as colors from 'colors'; -console.log('RushCommandLineParser.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as os from 'os'; -console.log('RushCommandLineParser.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import * as path from 'path'; -console.log('RushCommandLineParser.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { CommandLineParser, CommandLineFlagParameter, CommandLineAction } from '@rushstack/ts-command-line'; -console.log('RushCommandLineParser.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import { InternalError } from '@rushstack/node-core-library'; -console.log('RushCommandLineParser.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfiguration } from '../api/RushConfiguration'; -console.log('RushCommandLineParser.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConstants } from '../logic/RushConstants'; -console.log('RushCommandLineParser.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); import { CommandLineConfiguration } from '../api/CommandLineConfiguration'; -console.log('RushCommandLineParser.ts : 9: ' + (new Date().getTime() % 20000) / 1000.0); import { CommandJson } from '../api/CommandLineJson'; -console.log('RushCommandLineParser.ts : 10: ' + (new Date().getTime() % 20000) / 1000.0); import { Utilities } from '../utilities/Utilities'; -console.log('RushCommandLineParser.ts : 11: ' + (new Date().getTime() % 20000) / 1000.0); import { BaseScriptAction } from '../cli/scriptActions/BaseScriptAction'; -console.log('RushCommandLineParser.ts : 12: ' + (new Date().getTime() % 20000) / 1000.0); import { AddAction } from './actions/AddAction'; -console.log('RushCommandLineParser.ts : 13: ' + (new Date().getTime() % 20000) / 1000.0); import { ChangeAction } from './actions/ChangeAction'; -console.log('RushCommandLineParser.ts : 14: ' + (new Date().getTime() % 20000) / 1000.0); import { CheckAction } from './actions/CheckAction'; -console.log('RushCommandLineParser.ts : 15: ' + (new Date().getTime() % 20000) / 1000.0); import { DeployAction } from './actions/DeployAction'; -console.log('RushCommandLineParser.ts : 16: ' + (new Date().getTime() % 20000) / 1000.0); import { InitAction } from './actions/InitAction'; -console.log('RushCommandLineParser.ts : 17: ' + (new Date().getTime() % 20000) / 1000.0); import { InitAutoinstallerAction } from './actions/InitAutoinstallerAction'; -console.log('RushCommandLineParser.ts : 18: ' + (new Date().getTime() % 20000) / 1000.0); import { InitDeployAction } from './actions/InitDeployAction'; -console.log('RushCommandLineParser.ts : 19: ' + (new Date().getTime() % 20000) / 1000.0); import { InstallAction } from './actions/InstallAction'; -console.log('RushCommandLineParser.ts : 20: ' + (new Date().getTime() % 20000) / 1000.0); import { LinkAction } from './actions/LinkAction'; -console.log('RushCommandLineParser.ts : 21: ' + (new Date().getTime() % 20000) / 1000.0); import { ListAction } from './actions/ListAction'; -console.log('RushCommandLineParser.ts : 22: ' + (new Date().getTime() % 20000) / 1000.0); import { PublishAction } from './actions/PublishAction'; -console.log('RushCommandLineParser.ts : 23: ' + (new Date().getTime() % 20000) / 1000.0); import { PurgeAction } from './actions/PurgeAction'; -console.log('RushCommandLineParser.ts : 24: ' + (new Date().getTime() % 20000) / 1000.0); import { ScanAction } from './actions/ScanAction'; -console.log('RushCommandLineParser.ts : 25: ' + (new Date().getTime() % 20000) / 1000.0); import { TabCompleteAction } from './actions/TabCompleteAction'; -console.log('RushCommandLineParser.ts : 26: ' + (new Date().getTime() % 20000) / 1000.0); import { UnlinkAction } from './actions/UnlinkAction'; -console.log('RushCommandLineParser.ts : 27: ' + (new Date().getTime() % 20000) / 1000.0); import { UpdateAction } from './actions/UpdateAction'; -console.log('RushCommandLineParser.ts : 28: ' + (new Date().getTime() % 20000) / 1000.0); import { UpdateAutoinstallerAction } from './actions/UpdateAutoinstallerAction'; -console.log('RushCommandLineParser.ts : 29: ' + (new Date().getTime() % 20000) / 1000.0); import { VersionAction } from './actions/VersionAction'; -console.log('RushCommandLineParser.ts : 30: ' + (new Date().getTime() % 20000) / 1000.0); import { BulkScriptAction } from './scriptActions/BulkScriptAction'; -console.log('RushCommandLineParser.ts : 31: ' + (new Date().getTime() % 20000) / 1000.0); import { GlobalScriptAction } from './scriptActions/GlobalScriptAction'; -console.log('RushCommandLineParser.ts : 32: ' + (new Date().getTime() % 20000) / 1000.0); import { Telemetry } from '../logic/Telemetry'; -console.log('RushCommandLineParser.ts : 33: ' + (new Date().getTime() % 20000) / 1000.0); import { AlreadyReportedError } from '../utilities/AlreadyReportedError'; -console.log('RushCommandLineParser.ts : 34: ' + (new Date().getTime() % 20000) / 1000.0); import { RushGlobalFolder } from '../api/RushGlobalFolder'; -console.log('RushCommandLineParser.ts : 35: ' + (new Date().getTime() % 20000) / 1000.0); import { NodeJsCompatibility } from '../logic/NodeJsCompatibility'; -console.log('RushCommandLineParser.ts : 36: ' + (new Date().getTime() % 20000) / 1000.0); /** * Options for `RushCommandLineParser`. diff --git a/apps/rush-lib/src/cli/RushXCommandLine.ts b/apps/rush-lib/src/cli/RushXCommandLine.ts index 952b52e3699..9b1b2502a44 100644 --- a/apps/rush-lib/src/cli/RushXCommandLine.ts +++ b/apps/rush-lib/src/cli/RushXCommandLine.ts @@ -1,24 +1,15 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -console.log('RushXCommandLine.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as colors from 'colors'; -console.log('RushXCommandLine.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as os from 'os'; -console.log('RushXCommandLine.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import * as path from 'path'; -console.log('RushXCommandLine.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { PackageJsonLookup, IPackageJson, Text } from '@rushstack/node-core-library'; -console.log('RushXCommandLine.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import { Utilities } from '../utilities/Utilities'; -console.log('RushXCommandLine.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); import { ProjectCommandSet } from '../logic/ProjectCommandSet'; -console.log('RushXCommandLine.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfiguration } from '../api/RushConfiguration'; -console.log('RushXCommandLine.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); import { NodeJsCompatibility } from '../logic/NodeJsCompatibility'; -console.log('RushXCommandLine.ts : 9: ' + (new Date().getTime() % 20000) / 1000.0); /** * @internal diff --git a/apps/rush-lib/src/cli/actions/AddAction.ts b/apps/rush-lib/src/cli/actions/AddAction.ts index 16280ace892..308d886867a 100644 --- a/apps/rush-lib/src/cli/actions/AddAction.ts +++ b/apps/rush-lib/src/cli/actions/AddAction.ts @@ -1,25 +1,16 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -console.log('AddAction.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as os from 'os'; -console.log('AddAction.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as semver from 'semver'; -console.log('AddAction.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import { CommandLineFlagParameter, CommandLineStringParameter } from '@rushstack/ts-command-line'; -console.log('AddAction.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfigurationProject } from '../../api/RushConfigurationProject'; -console.log('AddAction.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import { BaseRushAction } from './BaseRushAction'; -console.log('AddAction.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); import { RushCommandLineParser } from '../RushCommandLineParser'; -console.log('AddAction.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); import { PackageJsonUpdater, SemVerStyle } from '../../logic/PackageJsonUpdater'; -console.log('AddAction.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); import { DependencySpecifier } from '../../logic/DependencySpecifier'; -console.log('AddAction.ts : 9: ' + (new Date().getTime() % 20000) / 1000.0); export class AddAction extends BaseRushAction { private _allFlag: CommandLineFlagParameter; diff --git a/apps/rush-lib/src/cli/actions/ChangeAction.ts b/apps/rush-lib/src/cli/actions/ChangeAction.ts index 56b2d80617b..22e8211f2d6 100644 --- a/apps/rush-lib/src/cli/actions/ChangeAction.ts +++ b/apps/rush-lib/src/cli/actions/ChangeAction.ts @@ -4,53 +4,35 @@ // eslint-disable-next-line const importLazy = require('import-lazy')(require); -console.log('ChangeAction.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as os from 'os'; -console.log('ChangeAction.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as path from 'path'; -console.log('ChangeAction.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import * as child_process from 'child_process'; -console.log('ChangeAction.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import * as colors from 'colors'; -console.log('ChangeAction.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); // import * as inquirer from 'inquirer'; // eslint-disable-next-line const inquirer = importLazy('inquirer'); -console.log('ChangeAction.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); - import { CommandLineFlagParameter, CommandLineStringParameter, CommandLineChoiceParameter } from '@rushstack/ts-command-line'; -console.log('ChangeAction.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); import { FileSystem, Path } from '@rushstack/node-core-library'; -console.log('ChangeAction.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfigurationProject } from '../../api/RushConfigurationProject'; -console.log('ChangeAction.ts : 9: ' + (new Date().getTime() % 20000) / 1000.0); import { IChangeFile, IChangeInfo, ChangeType } from '../../api/ChangeManagement'; -console.log('ChangeAction.ts : 10: ' + (new Date().getTime() % 20000) / 1000.0); import { VersionControl } from '../../utilities/VersionControl'; -console.log('ChangeAction.ts : 11: ' + (new Date().getTime() % 20000) / 1000.0); import { ChangeFile } from '../../api/ChangeFile'; -console.log('ChangeAction.ts : 12: ' + (new Date().getTime() % 20000) / 1000.0); import { BaseRushAction } from './BaseRushAction'; -console.log('ChangeAction.ts : 13: ' + (new Date().getTime() % 20000) / 1000.0); import { RushCommandLineParser } from '../RushCommandLineParser'; -console.log('ChangeAction.ts : 14: ' + (new Date().getTime() % 20000) / 1000.0); import { ChangeFiles } from '../../logic/ChangeFiles'; -console.log('ChangeAction.ts : 15: ' + (new Date().getTime() % 20000) / 1000.0); import { VersionPolicy, IndividualVersionPolicy, LockStepVersionPolicy, VersionPolicyDefinitionName } from '../../api/VersionPolicy'; -console.log('ChangeAction.ts : 16: ' + (new Date().getTime() % 20000) / 1000.0); import { AlreadyReportedError } from '../../utilities/AlreadyReportedError'; -console.log('ChangeAction.ts : 17: ' + (new Date().getTime() % 20000) / 1000.0); export class ChangeAction extends BaseRushAction { private _verifyParameter: CommandLineFlagParameter; diff --git a/apps/rush-lib/src/cli/actions/DeployAction.ts b/apps/rush-lib/src/cli/actions/DeployAction.ts index b89b56c262a..a3aa8fa3725 100644 --- a/apps/rush-lib/src/cli/actions/DeployAction.ts +++ b/apps/rush-lib/src/cli/actions/DeployAction.ts @@ -1,15 +1,10 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -console.log('DeployAction.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import { BaseRushAction } from './BaseRushAction'; -console.log('DeployAction.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import { RushCommandLineParser } from '../RushCommandLineParser'; -console.log('DeployAction.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import { CommandLineFlagParameter, CommandLineStringParameter } from '@rushstack/ts-command-line'; -console.log('DeployAction.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { DeployManager } from '../../logic/deploy/DeployManager'; -console.log('DeployAction.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); export class DeployAction extends BaseRushAction { private _scenario: CommandLineStringParameter; diff --git a/apps/rush-lib/src/cli/actions/ListAction.ts b/apps/rush-lib/src/cli/actions/ListAction.ts index 72441632ce1..cf05edd55df 100644 --- a/apps/rush-lib/src/cli/actions/ListAction.ts +++ b/apps/rush-lib/src/cli/actions/ListAction.ts @@ -4,17 +4,11 @@ // eslint-disable-next-line const importLazy = require('import-lazy')(require); -console.log('ListAction.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import { BaseRushAction } from './BaseRushAction'; -console.log('ListAction.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import { RushCommandLineParser } from '../RushCommandLineParser'; -console.log('ListAction.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import { CommandLineFlagParameter } from '@rushstack/ts-command-line'; -console.log('ListAction.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfigurationProject } from '../../api/RushConfigurationProject'; -console.log('ListAction.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); const Table = importLazy('cli-table'); -console.log('ListAction.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); export interface IJsonEntry { name: string; diff --git a/apps/rush-lib/src/cli/scriptActions/BulkScriptAction.ts b/apps/rush-lib/src/cli/scriptActions/BulkScriptAction.ts index fd63bff0e5a..8100e90ee84 100644 --- a/apps/rush-lib/src/cli/scriptActions/BulkScriptAction.ts +++ b/apps/rush-lib/src/cli/scriptActions/BulkScriptAction.ts @@ -1,11 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -console.log('BulkScriptAction.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as os from 'os'; -console.log('BulkScriptAction.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as colors from 'colors'; -console.log('BulkScriptAction.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import { CommandLineFlagParameter, @@ -14,31 +11,18 @@ import { CommandLineParameterKind } from '@rushstack/ts-command-line'; -console.log('BulkScriptAction.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { Event } from '../../index'; -console.log('BulkScriptAction.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import { SetupChecks } from '../../logic/SetupChecks'; -console.log('BulkScriptAction.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); import { TaskSelector } from '../../logic/TaskSelector'; -console.log('BulkScriptAction.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); import { Stopwatch } from '../../utilities/Stopwatch'; -console.log('BulkScriptAction.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); import { AlreadyReportedError } from '../../utilities/AlreadyReportedError'; -console.log('BulkScriptAction.ts : 9: ' + (new Date().getTime() % 20000) / 1000.0); import { BaseScriptAction, IBaseScriptActionOptions } from './BaseScriptAction'; -console.log('BulkScriptAction.ts : 10: ' + (new Date().getTime() % 20000) / 1000.0); import { TaskRunner } from '../../logic/taskRunner/TaskRunner'; -console.log('BulkScriptAction.ts : 11: ' + (new Date().getTime() % 20000) / 1000.0); import { TaskCollection } from '../../logic/taskRunner/TaskCollection'; -console.log('BulkScriptAction.ts : 12: ' + (new Date().getTime() % 20000) / 1000.0); import { Utilities } from '../../utilities/Utilities'; -console.log('BulkScriptAction.ts : 13: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConstants } from '../../logic/RushConstants'; -console.log('BulkScriptAction.ts : 14: ' + (new Date().getTime() % 20000) / 1000.0); import { EnvironmentVariableNames } from '../../api/EnvironmentConfiguration'; -console.log('BulkScriptAction.ts : 15: ' + (new Date().getTime() % 20000) / 1000.0); import { LastLinkFlag, LastLinkFlagFactory } from '../../api/LastLinkFlag'; -console.log('BulkScriptAction.ts : 16: ' + (new Date().getTime() % 20000) / 1000.0); /** * Constructor parameters for BulkScriptAction. diff --git a/apps/rush-lib/src/logic/InstallManagerFactory.ts b/apps/rush-lib/src/logic/InstallManagerFactory.ts index 5bbc63505c9..fb27a19b0da 100644 --- a/apps/rush-lib/src/logic/InstallManagerFactory.ts +++ b/apps/rush-lib/src/logic/InstallManagerFactory.ts @@ -1,26 +1,16 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -console.log('InstallManagerFactory.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as colors from 'colors'; -console.log('InstallManagerFactory.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as semver from 'semver'; -console.log('InstallManagerFactory.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import { BaseInstallManager, IInstallManagerOptions } from './base/BaseInstallManager'; -console.log('InstallManagerFactory.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { RushInstallManager } from './installManager/RushInstallManager'; -console.log('InstallManagerFactory.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import { WorkspaceInstallManager } from './installManager/WorkspaceInstallManager'; -console.log('InstallManagerFactory.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); import { AlreadyReportedError } from '../utilities/AlreadyReportedError'; -console.log('InstallManagerFactory.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); import { PurgeManager } from './PurgeManager'; -console.log('InstallManagerFactory.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfiguration } from '../api/RushConfiguration'; -console.log('InstallManagerFactory.ts : 9: ' + (new Date().getTime() % 20000) / 1000.0); import { RushGlobalFolder } from '../api/RushGlobalFolder'; -console.log('InstallManagerFactory.ts : 10: ' + (new Date().getTime() % 20000) / 1000.0); export class InstallManagerFactory { public static getInstallManager( diff --git a/apps/rush-lib/src/logic/LinkManagerFactory.ts b/apps/rush-lib/src/logic/LinkManagerFactory.ts index e1c030b317c..c6f36989a94 100644 --- a/apps/rush-lib/src/logic/LinkManagerFactory.ts +++ b/apps/rush-lib/src/logic/LinkManagerFactory.ts @@ -1,15 +1,10 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -console.log('LinkManagerFactory.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfiguration } from '../api/RushConfiguration'; -console.log('LinkManagerFactory.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import { BaseLinkManager } from './base/BaseLinkManager'; -console.log('LinkManagerFactory.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import { NpmLinkManager } from './npm/NpmLinkManager'; -console.log('LinkManagerFactory.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { PnpmLinkManager } from './pnpm/PnpmLinkManager'; -console.log('LinkManagerFactory.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); export class LinkManagerFactory { public static getLinkManager(rushConfiguration: RushConfiguration): BaseLinkManager { diff --git a/apps/rush-lib/src/logic/PackageJsonUpdater.ts b/apps/rush-lib/src/logic/PackageJsonUpdater.ts index 6dcf5b35f05..02d649879a9 100644 --- a/apps/rush-lib/src/logic/PackageJsonUpdater.ts +++ b/apps/rush-lib/src/logic/PackageJsonUpdater.ts @@ -1,38 +1,22 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -console.log('PackageJsonUpdater.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as colors from 'colors'; -console.log('PackageJsonUpdater.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as semver from 'semver'; -console.log('PackageJsonUpdater.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfiguration } from '../api/RushConfiguration'; -console.log('PackageJsonUpdater.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { BaseInstallManager, IInstallManagerOptions } from './base/BaseInstallManager'; -console.log('PackageJsonUpdater.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import { InstallManagerFactory } from './InstallManagerFactory'; -console.log('PackageJsonUpdater.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); import { VersionMismatchFinder } from './versionMismatch/VersionMismatchFinder'; -console.log('PackageJsonUpdater.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); import { PurgeManager } from './PurgeManager'; -console.log('PackageJsonUpdater.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); import { Utilities } from '../utilities/Utilities'; -console.log('PackageJsonUpdater.ts : 9: ' + (new Date().getTime() % 20000) / 1000.0); import { DependencyType, PackageJsonDependency } from '../api/PackageJsonEditor'; -console.log('PackageJsonUpdater.ts : 10: ' + (new Date().getTime() % 20000) / 1000.0); import { RushGlobalFolder } from '../api/RushGlobalFolder'; -console.log('PackageJsonUpdater.ts : 11: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfigurationProject } from '../api/RushConfigurationProject'; -console.log('PackageJsonUpdater.ts : 12: ' + (new Date().getTime() % 20000) / 1000.0); import { VersionMismatchFinderEntity } from './versionMismatch/VersionMismatchFinderEntity'; -console.log('PackageJsonUpdater.ts : 13: ' + (new Date().getTime() % 20000) / 1000.0); import { VersionMismatchFinderProject } from './versionMismatch/VersionMismatchFinderProject'; -console.log('PackageJsonUpdater.ts : 14: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConstants } from './RushConstants'; -console.log('PackageJsonUpdater.ts : 15: ' + (new Date().getTime() % 20000) / 1000.0); import { InstallHelpers } from './installManager/InstallHelpers'; -console.log('PackageJsonUpdater.ts : 16: ' + (new Date().getTime() % 20000) / 1000.0); /** * The type of SemVer range specifier that is prepended to the version diff --git a/apps/rush-lib/src/logic/RepoStateFile.ts b/apps/rush-lib/src/logic/RepoStateFile.ts index 31929d2401e..f8e83d23127 100644 --- a/apps/rush-lib/src/logic/RepoStateFile.ts +++ b/apps/rush-lib/src/logic/RepoStateFile.ts @@ -1,18 +1,12 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -console.log('RepoStateFile.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as path from 'path'; -console.log('RepoStateFile.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import { FileSystem, JsonFile, JsonSchema, NewlineKind } from '@rushstack/node-core-library'; -console.log('RepoStateFile.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfiguration } from '../api/RushConfiguration'; -console.log('RepoStateFile.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { PnpmShrinkwrapFile } from './pnpm/PnpmShrinkwrapFile'; -console.log('RepoStateFile.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import { CommonVersionsConfiguration } from '../api/CommonVersionsConfiguration'; -console.log('RepoStateFile.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); /** * This interface represents the raw repo-state.json file diff --git a/apps/rush-lib/src/logic/ShrinkwrapFileFactory.ts b/apps/rush-lib/src/logic/ShrinkwrapFileFactory.ts index e178972d357..8df0af0837c 100644 --- a/apps/rush-lib/src/logic/ShrinkwrapFileFactory.ts +++ b/apps/rush-lib/src/logic/ShrinkwrapFileFactory.ts @@ -1,19 +1,12 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -console.log('ShrinkwrapFileFactory.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import { PackageManagerName } from '../api/packageManager/PackageManager'; -console.log('ShrinkwrapFileFactory.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import { BaseShrinkwrapFile } from './base/BaseShrinkwrapFile'; -console.log('ShrinkwrapFileFactory.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import { NpmShrinkwrapFile } from './npm/NpmShrinkwrapFile'; -console.log('ShrinkwrapFileFactory.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { PnpmShrinkwrapFile } from './pnpm/PnpmShrinkwrapFile'; -console.log('ShrinkwrapFileFactory.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import { YarnShrinkwrapFile } from './yarn/YarnShrinkwrapFile'; -console.log('ShrinkwrapFileFactory.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); import { PackageManagerOptionsConfigurationBase, PnpmOptionsConfiguration } from '../api/RushConfiguration'; -console.log('ShrinkwrapFileFactory.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); export class ShrinkwrapFileFactory { public static getShrinkwrapFile( diff --git a/apps/rush-lib/src/logic/Telemetry.ts b/apps/rush-lib/src/logic/Telemetry.ts index 7a681063012..db9f5dc61ec 100644 --- a/apps/rush-lib/src/logic/Telemetry.ts +++ b/apps/rush-lib/src/logic/Telemetry.ts @@ -6,11 +6,12 @@ const importLazy = require('import-lazy')(require); import * as fs from 'fs'; import * as path from 'path'; +// eslint-disable-next-line const _ = importLazy('lodash'); +import { FileSystem } from '@rushstack/node-core-library'; import { RushConfiguration } from '../api/RushConfiguration'; import { Rush } from '../api/Rush'; -import { FileSystem } from '@rushstack/node-core-library'; export interface ITelemetryData { name: string; diff --git a/apps/rush-lib/src/logic/VersionManager.ts b/apps/rush-lib/src/logic/VersionManager.ts index 10b57e218ac..1b467baadb0 100644 --- a/apps/rush-lib/src/logic/VersionManager.ts +++ b/apps/rush-lib/src/logic/VersionManager.ts @@ -6,6 +6,7 @@ const importLazy = require('import-lazy')(require); import * as path from 'path'; import * as semver from 'semver'; +// eslint-disable-next-line const _ = importLazy('lodash'); import { IPackageJson, JsonFile, FileConstants } from '@rushstack/node-core-library'; diff --git a/apps/rush-lib/src/logic/base/BaseInstallManager.ts b/apps/rush-lib/src/logic/base/BaseInstallManager.ts index 6ec9c065058..1f4ae2e4bd9 100644 --- a/apps/rush-lib/src/logic/base/BaseInstallManager.ts +++ b/apps/rush-lib/src/logic/base/BaseInstallManager.ts @@ -4,65 +4,37 @@ // eslint-disable-next-line const importLazy = require('import-lazy')(require); -console.log('BaseInstallManager.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as colors from 'colors'; -console.log('BaseInstallManager.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as fetch from 'node-fetch'; -console.log('BaseInstallManager.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import * as fs from 'fs'; -console.log('BaseInstallManager.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import * as http from 'http'; -console.log('BaseInstallManager.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); // import HttpsProxyAgent = require('https-proxy-agent'); // eslint-disable-next-line const HttpsProxyAgent = importLazy('https-proxy-agent'); -console.log('BaseInstallManager.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); import * as os from 'os'; -console.log('BaseInstallManager.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); import * as path from 'path'; -console.log('BaseInstallManager.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); import * as semver from 'semver'; -console.log('BaseInstallManager.ts : 9: ' + (new Date().getTime() % 20000) / 1000.0); import { FileSystem, JsonFile, PosixModeBits, NewlineKind } from '@rushstack/node-core-library'; -console.log('BaseInstallManager.ts : 10: ' + (new Date().getTime() % 20000) / 1000.0); import { AlreadyReportedError } from '../../utilities/AlreadyReportedError'; -console.log('BaseInstallManager.ts : 11: ' + (new Date().getTime() % 20000) / 1000.0); import { ApprovedPackagesChecker } from '../ApprovedPackagesChecker'; -console.log('BaseInstallManager.ts : 12: ' + (new Date().getTime() % 20000) / 1000.0); import { AsyncRecycler } from '../../utilities/AsyncRecycler'; -console.log('BaseInstallManager.ts : 13: ' + (new Date().getTime() % 20000) / 1000.0); import { BaseShrinkwrapFile } from '../base/BaseShrinkwrapFile'; -console.log('BaseInstallManager.ts : 14: ' + (new Date().getTime() % 20000) / 1000.0); import { EnvironmentConfiguration } from '../../api/EnvironmentConfiguration'; -console.log('BaseInstallManager.ts : 15: ' + (new Date().getTime() % 20000) / 1000.0); import { Git } from '../Git'; -console.log('BaseInstallManager.ts : 16: ' + (new Date().getTime() % 20000) / 1000.0); import { LastInstallFlag, LastInstallFlagFactory } from '../../api/LastInstallFlag'; -console.log('BaseInstallManager.ts : 17: ' + (new Date().getTime() % 20000) / 1000.0); import { LastLinkFlag, LastLinkFlagFactory } from '../../api/LastLinkFlag'; import { PnpmPackageManager } from '../../api/packageManager/PnpmPackageManager'; -console.log('BaseInstallManager.ts : 18: ' + (new Date().getTime() % 20000) / 1000.0); import { PurgeManager } from '../PurgeManager'; -console.log('BaseInstallManager.ts : 19: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfiguration, ICurrentVariantJson } from '../../api/RushConfiguration'; -console.log('BaseInstallManager.ts : 20: ' + (new Date().getTime() % 20000) / 1000.0); import { Rush } from '../../api/Rush'; -console.log('BaseInstallManager.ts : 21: ' + (new Date().getTime() % 20000) / 1000.0); import { RushGlobalFolder } from '../../api/RushGlobalFolder'; -console.log('BaseInstallManager.ts : 22: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConstants } from '../RushConstants'; -console.log('BaseInstallManager.ts : 23: ' + (new Date().getTime() % 20000) / 1000.0); import { ShrinkwrapFileFactory } from '../ShrinkwrapFileFactory'; -console.log('BaseInstallManager.ts : 24: ' + (new Date().getTime() % 20000) / 1000.0); import { Utilities } from '../../utilities/Utilities'; -console.log('BaseInstallManager.ts : 25: ' + (new Date().getTime() % 20000) / 1000.0); import { InstallHelpers } from '../installManager/InstallHelpers'; -console.log('BaseInstallManager.ts : 26: ' + (new Date().getTime() % 20000) / 1000.0); import { PolicyValidator } from '../policy/PolicyValidator'; -console.log('BaseInstallManager.ts : 27: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfigurationProject } from '../../api/RushConfigurationProject'; -console.log('BaseInstallManager.ts : 28: ' + (new Date().getTime() % 20000) / 1000.0); export interface IInstallManagerOptions { /** diff --git a/apps/rush-lib/src/logic/deploy/DeployArchiver.ts b/apps/rush-lib/src/logic/deploy/DeployArchiver.ts index 95a9934a995..ba4f3c01201 100644 --- a/apps/rush-lib/src/logic/deploy/DeployArchiver.ts +++ b/apps/rush-lib/src/logic/deploy/DeployArchiver.ts @@ -4,18 +4,13 @@ // eslint-disable-next-line const importLazy = require('import-lazy')(require); -console.log('DeployArchiver.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); // import * as JSZip from 'jszip'; // eslint-disable-next-line const JSZip = importLazy('jszip'); -console.log('DeployArchiver.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as path from 'path'; -console.log('DeployArchiver.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import { FileSystem, FileSystemStats } from '@rushstack/node-core-library'; -console.log('DeployArchiver.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { IDeployState } from './DeployManager'; -console.log('DeployArchiver.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); // JSZip is dependant on Blob being declared. declare global { diff --git a/apps/rush-lib/src/logic/deploy/DeployManager.ts b/apps/rush-lib/src/logic/deploy/DeployManager.ts index d48e34c8350..4d57d09f191 100644 --- a/apps/rush-lib/src/logic/deploy/DeployManager.ts +++ b/apps/rush-lib/src/logic/deploy/DeployManager.ts @@ -4,26 +4,18 @@ // eslint-disable-next-line const importLazy = require('import-lazy')(require); -console.log('DeployManager.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as colors from 'colors'; -console.log('DeployManager.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as path from 'path'; -console.log('DeployManager.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); const resolve = importLazy('resolve'); -console.log('DeployManager.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); // eslint-disable-next-line const npmPacklist = importLazy('npm-packlist'); -console.log('DeployManager.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); // eslint-disable-next-line const pnpmLinkBins = importLazy('@pnpm/link-bins'); -console.log('DeployManager.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); // (Used only by the legacy code fragment in the resolve.sync() hook below) import * as fsForResolve from 'fs'; -console.log('DeployManager.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); import ignore, { Ignore } from 'ignore'; -console.log('DeployManager.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); import { Path, FileSystem, @@ -37,21 +29,13 @@ import { NewlineKind, Text } from '@rushstack/node-core-library'; -console.log('DeployManager.ts : 9: ' + (new Date().getTime() % 20000) / 1000.0); import { DeployArchiver } from './DeployArchiver'; -console.log('DeployManager.ts : 10: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfiguration } from '../../api/RushConfiguration'; -console.log('DeployManager.ts : 11: ' + (new Date().getTime() % 20000) / 1000.0); import { SymlinkAnalyzer, ILinkInfo } from './SymlinkAnalyzer'; -console.log('DeployManager.ts : 12: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfigurationProject } from '../../api/RushConfigurationProject'; -console.log('DeployManager.ts : 13: ' + (new Date().getTime() % 20000) / 1000.0); import { DeployScenarioConfiguration, IDeployScenarioProjectJson } from './DeployScenarioConfiguration'; -console.log('DeployManager.ts : 14: ' + (new Date().getTime() % 20000) / 1000.0); import { PnpmfileConfiguration } from './PnpmfileConfiguration'; -console.log('DeployManager.ts : 15: ' + (new Date().getTime() % 20000) / 1000.0); import { matchesWithStar } from './Utils'; -console.log('DeployManager.ts : 16: ' + (new Date().getTime() % 20000) / 1000.0); interface INpmPackListWalkerSync { readonly result: string[]; diff --git a/apps/rush-lib/src/logic/installManager/RushInstallManager.ts b/apps/rush-lib/src/logic/installManager/RushInstallManager.ts index f39577973b4..397c962dfbe 100644 --- a/apps/rush-lib/src/logic/installManager/RushInstallManager.ts +++ b/apps/rush-lib/src/logic/installManager/RushInstallManager.ts @@ -4,23 +4,15 @@ // eslint-disable-next-line const importLazy = require('import-lazy')(require); -console.log('RushInstallManager.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); // import * as glob from 'glob'; const glob = importLazy('glob'); -console.log('RushInstallManager.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as colors from 'colors'; -console.log('RushInstallManager.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import * as os from 'os'; -console.log('RushInstallManager.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import * as path from 'path'; -console.log('RushInstallManager.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import * as semver from 'semver'; -console.log('RushInstallManager.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); // eslint-disable-next-line const tar = importLazy('tar'); -console.log('RushInstallManager.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); import * as globEscape from 'glob-escape'; -console.log('RushInstallManager.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); import { JsonFile, Text, @@ -30,34 +22,20 @@ import { PosixModeBits, InternalError } from '@rushstack/node-core-library'; -console.log('RushInstallManager.ts : 9: ' + (new Date().getTime() % 20000) / 1000.0); import { BaseInstallManager } from '../base/BaseInstallManager'; -console.log('RushInstallManager.ts : 10: ' + (new Date().getTime() % 20000) / 1000.0); import { BaseShrinkwrapFile } from '../../logic/base/BaseShrinkwrapFile'; -console.log('RushInstallManager.ts : 11: ' + (new Date().getTime() % 20000) / 1000.0); import { IRushTempPackageJson } from '../../logic/base/BasePackage'; -console.log('RushInstallManager.ts : 12: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfigurationProject } from '../../api/RushConfigurationProject'; -console.log('RushInstallManager.ts : 13: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConstants } from '../../logic/RushConstants'; -console.log('RushInstallManager.ts : 14: ' + (new Date().getTime() % 20000) / 1000.0); import { Stopwatch } from '../../utilities/Stopwatch'; -console.log('RushInstallManager.ts : 15: ' + (new Date().getTime() % 20000) / 1000.0); import { Utilities } from '../../utilities/Utilities'; -console.log('RushInstallManager.ts : 16: ' + (new Date().getTime() % 20000) / 1000.0); import { PackageJsonEditor, DependencyType, PackageJsonDependency } from '../../api/PackageJsonEditor'; -console.log('RushInstallManager.ts : 17: ' + (new Date().getTime() % 20000) / 1000.0); import { DependencySpecifier, DependencySpecifierType } from '../DependencySpecifier'; -console.log('RushInstallManager.ts : 18: ' + (new Date().getTime() % 20000) / 1000.0); import { InstallHelpers } from './InstallHelpers'; -console.log('RushInstallManager.ts : 19: ' + (new Date().getTime() % 20000) / 1000.0); import { AlreadyReportedError } from '../../utilities/AlreadyReportedError'; -console.log('RushInstallManager.ts : 20: ' + (new Date().getTime() % 20000) / 1000.0); import { LinkManagerFactory } from '../LinkManagerFactory'; -console.log('RushInstallManager.ts : 21: ' + (new Date().getTime() % 20000) / 1000.0); import { BaseLinkManager } from '../base/BaseLinkManager'; -console.log('RushInstallManager.ts : 22: ' + (new Date().getTime() % 20000) / 1000.0); /** * The "noMtime" flag is new in tar@4.4.1 and not available yet for \@types/tar. diff --git a/apps/rush-lib/src/logic/installManager/WorkspaceInstallManager.ts b/apps/rush-lib/src/logic/installManager/WorkspaceInstallManager.ts index 76650f6e287..6ed029d3ae2 100644 --- a/apps/rush-lib/src/logic/installManager/WorkspaceInstallManager.ts +++ b/apps/rush-lib/src/logic/installManager/WorkspaceInstallManager.ts @@ -1,15 +1,10 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -console.log('WorkspaceInstallManager.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as colors from 'colors'; -console.log('WorkspaceInstallManager.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as os from 'os'; -console.log('WorkspaceInstallManager.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import * as path from 'path'; -console.log('WorkspaceInstallManager.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import * as semver from 'semver'; -console.log('WorkspaceInstallManager.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import { FileSystem, InternalError, @@ -17,42 +12,24 @@ import { JsonFile, FileConstants } from '@rushstack/node-core-library'; -console.log('WorkspaceInstallManager.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); import { AlreadyReportedError } from '../../utilities/AlreadyReportedError'; -console.log('WorkspaceInstallManager.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); import { BaseInstallManager, IInstallManagerOptions } from '../base/BaseInstallManager'; -console.log('WorkspaceInstallManager.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); import { BaseShrinkwrapFile } from '../../logic/base/BaseShrinkwrapFile'; -console.log('WorkspaceInstallManager.ts : 9: ' + (new Date().getTime() % 20000) / 1000.0); import { DependencySpecifier, DependencySpecifierType } from '../DependencySpecifier'; -console.log('WorkspaceInstallManager.ts : 10: ' + (new Date().getTime() % 20000) / 1000.0); import { PackageJsonEditor, DependencyType, PackageJsonDependency } from '../../api/PackageJsonEditor'; -console.log('WorkspaceInstallManager.ts : 11: ' + (new Date().getTime() % 20000) / 1000.0); import { PnpmWorkspaceFile } from '../pnpm/PnpmWorkspaceFile'; -console.log('WorkspaceInstallManager.ts : 12: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfigurationProject } from '../../api/RushConfigurationProject'; -console.log('WorkspaceInstallManager.ts : 13: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConstants } from '../../logic/RushConstants'; -console.log('WorkspaceInstallManager.ts : 14: ' + (new Date().getTime() % 20000) / 1000.0); import { Stopwatch } from '../../utilities/Stopwatch'; -console.log('WorkspaceInstallManager.ts : 15: ' + (new Date().getTime() % 20000) / 1000.0); import { Utilities } from '../../utilities/Utilities'; -console.log('WorkspaceInstallManager.ts : 16: ' + (new Date().getTime() % 20000) / 1000.0); import { InstallHelpers } from './InstallHelpers'; -console.log('WorkspaceInstallManager.ts : 17: ' + (new Date().getTime() % 20000) / 1000.0); import { CommonVersionsConfiguration } from '../../api/CommonVersionsConfiguration'; -console.log('WorkspaceInstallManager.ts : 18: ' + (new Date().getTime() % 20000) / 1000.0); import { RepoStateFile } from '../RepoStateFile'; -console.log('WorkspaceInstallManager.ts : 19: ' + (new Date().getTime() % 20000) / 1000.0); import { IPnpmfileShimSettings } from '../pnpm/IPnpmfileShimSettings'; -console.log('WorkspaceInstallManager.ts : 20: ' + (new Date().getTime() % 20000) / 1000.0); import { PnpmProjectDependencyManifest } from '../pnpm/PnpmProjectDependencyManifest'; -console.log('WorkspaceInstallManager.ts : 21: ' + (new Date().getTime() % 20000) / 1000.0); import { PnpmShrinkwrapFile, IPnpmShrinkwrapImporterYaml } from '../pnpm/PnpmShrinkwrapFile'; -console.log('WorkspaceInstallManager.ts : 22: ' + (new Date().getTime() % 20000) / 1000.0); import { LastLinkFlagFactory } from '../../api/LastLinkFlag'; -console.log('WorkspaceInstallManager.ts : 22: ' + (new Date().getTime() % 20000) / 1000.0); /** * This class implements common logic between "rush install" and "rush update". diff --git a/apps/rush-lib/src/logic/npm/NpmLinkManager.ts b/apps/rush-lib/src/logic/npm/NpmLinkManager.ts index 82041bf2f36..49b3785acfe 100644 --- a/apps/rush-lib/src/logic/npm/NpmLinkManager.ts +++ b/apps/rush-lib/src/logic/npm/NpmLinkManager.ts @@ -4,38 +4,24 @@ // eslint-disable-next-line const importLazy = require('import-lazy')(require); -console.log('NpmLinkManager.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as colors from 'colors'; -console.log('NpmLinkManager.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as os from 'os'; -console.log('NpmLinkManager.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import * as path from 'path'; -console.log('NpmLinkManager.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import * as semver from 'semver'; -console.log('NpmLinkManager.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); // import * as tar from 'tar'; // eslint-disable-next-line const tar = importLazy('tar'); -console.log('NpmLinkManager.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); // import readPackageTree = require('read-package-tree'); // eslint-disable-next-line const readPackageTree = importLazy('read-package-tree'); -console.log('NpmLinkManager.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); import { FileSystem, FileConstants, LegacyAdapters } from '@rushstack/node-core-library'; -console.log('NpmLinkManager.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConstants } from '../../logic/RushConstants'; -console.log('NpmLinkManager.ts : 9: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfigurationProject } from '../../api/RushConfigurationProject'; -console.log('NpmLinkManager.ts : 10: ' + (new Date().getTime() % 20000) / 1000.0); import { Utilities } from '../../utilities/Utilities'; -console.log('NpmLinkManager.ts : 11: ' + (new Date().getTime() % 20000) / 1000.0); import { NpmPackage, IResolveOrCreateResult, PackageDependencyKind } from './NpmPackage'; -console.log('NpmLinkManager.ts : 12: ' + (new Date().getTime() % 20000) / 1000.0); import { PackageLookup } from '../PackageLookup'; -console.log('NpmLinkManager.ts : 13: ' + (new Date().getTime() % 20000) / 1000.0); import { BaseLinkManager, SymlinkKind } from '../base/BaseLinkManager'; -console.log('NpmLinkManager.ts : 14: ' + (new Date().getTime() % 20000) / 1000.0); interface IQueueItem { // A project from somewhere under "common/temp/node_modules" diff --git a/apps/rush-lib/src/logic/npm/NpmShrinkwrapFile.ts b/apps/rush-lib/src/logic/npm/NpmShrinkwrapFile.ts index 3c829d678cf..6fb91b74331 100644 --- a/apps/rush-lib/src/logic/npm/NpmShrinkwrapFile.ts +++ b/apps/rush-lib/src/logic/npm/NpmShrinkwrapFile.ts @@ -3,14 +3,10 @@ import * as os from 'os'; -console.log('NpmShrinkwrapFile.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import { JsonFile, FileSystem, InternalError } from '@rushstack/node-core-library'; -console.log('NpmShrinkwrapFile.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import { BaseShrinkwrapFile } from '../base/BaseShrinkwrapFile'; -console.log('NpmShrinkwrapFile.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import { DependencySpecifier } from '../DependencySpecifier'; -console.log('NpmShrinkwrapFile.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); interface INpmShrinkwrapDependencyJson { version: string; diff --git a/apps/rush-lib/src/logic/pnpm/PnpmLinkManager.ts b/apps/rush-lib/src/logic/pnpm/PnpmLinkManager.ts index 1706ead0c67..a19075eca61 100644 --- a/apps/rush-lib/src/logic/pnpm/PnpmLinkManager.ts +++ b/apps/rush-lib/src/logic/pnpm/PnpmLinkManager.ts @@ -4,41 +4,26 @@ // eslint-disable-next-line const importLazy = require('import-lazy')(require); -console.log('PnpmLinkManager.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as os from 'os'; -console.log('PnpmLinkManager.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as path from 'path'; -console.log('PnpmLinkManager.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import uriEncode = require('strict-uri-encode'); -console.log('PnpmLinkManager.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); // import pnpmLinkBins from '@pnpm/link-bins'; // eslint-disable-next-line const pnpmLinkBins = importLazy('@pnpm/link-bins'); -console.log('PnpmLinkManager.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import * as semver from 'semver'; -console.log('PnpmLinkManager.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); import * as colors from 'colors'; -console.log('PnpmLinkManager.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); import { Text, FileSystem, FileConstants, InternalError } from '@rushstack/node-core-library'; -console.log('PnpmLinkManager.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); import { BaseLinkManager } from '../base/BaseLinkManager'; -console.log('PnpmLinkManager.ts : 9: ' + (new Date().getTime() % 20000) / 1000.0); import { BasePackage } from '../base/BasePackage'; -console.log('PnpmLinkManager.ts : 10: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConstants } from '../../logic/RushConstants'; -console.log('PnpmLinkManager.ts : 11: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConfigurationProject } from '../../api/RushConfigurationProject'; -console.log('PnpmLinkManager.ts : 12: ' + (new Date().getTime() % 20000) / 1000.0); import { PnpmShrinkwrapFile, IPnpmShrinkwrapDependencyYaml } from './PnpmShrinkwrapFile'; -console.log('PnpmLinkManager.ts : 13: ' + (new Date().getTime() % 20000) / 1000.0); import { PnpmProjectDependencyManifest } from './PnpmProjectDependencyManifest'; -console.log('PnpmLinkManager.ts : 14: ' + (new Date().getTime() % 20000) / 1000.0); import { AlreadyReportedError } from '../../utilities/AlreadyReportedError'; -console.log('PnpmLinkManager.ts : 15: ' + (new Date().getTime() % 20000) / 1000.0); // special flag for debugging, will print extra diagnostic information, // but comes with performance cost diff --git a/apps/rush-lib/src/logic/pnpm/PnpmShrinkwrapFile.ts b/apps/rush-lib/src/logic/pnpm/PnpmShrinkwrapFile.ts index d154b7a2ad0..500eb46c430 100644 --- a/apps/rush-lib/src/logic/pnpm/PnpmShrinkwrapFile.ts +++ b/apps/rush-lib/src/logic/pnpm/PnpmShrinkwrapFile.ts @@ -4,37 +4,24 @@ // eslint-disable-next-line const importLazy = require('import-lazy')(require); -console.log('PnpmShrinkwrapFile.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); // eslint-disable-next-line const yaml = importLazy('js-yaml'); -console.log('PnpmShrinkwrapFile.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as os from 'os'; -console.log('PnpmShrinkwrapFile.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import * as path from 'path'; -console.log('PnpmShrinkwrapFile.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import * as semver from 'semver'; -console.log('PnpmShrinkwrapFile.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import * as crypto from 'crypto'; -console.log('PnpmShrinkwrapFile.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); import * as colors from 'colors'; -console.log('PnpmShrinkwrapFile.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); import { FileSystem } from '@rushstack/node-core-library'; -console.log('PnpmShrinkwrapFile.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); import { BaseShrinkwrapFile } from '../base/BaseShrinkwrapFile'; -console.log('PnpmShrinkwrapFile.ts : 9: ' + (new Date().getTime() % 20000) / 1000.0); import { DependencySpecifier } from '../DependencySpecifier'; -console.log('PnpmShrinkwrapFile.ts : 10: ' + (new Date().getTime() % 20000) / 1000.0); import { PackageManagerOptionsConfigurationBase, PnpmOptionsConfiguration } from '../../api/RushConfiguration'; -console.log('PnpmShrinkwrapFile.ts : 11: ' + (new Date().getTime() % 20000) / 1000.0); import { IShrinkwrapFilePolicyValidatorOptions } from '../policy/ShrinkwrapFilePolicy'; -console.log('PnpmShrinkwrapFile.ts : 12: ' + (new Date().getTime() % 20000) / 1000.0); import { AlreadyReportedError } from '../../utilities/AlreadyReportedError'; import { PNPM_SHRINKWRAP_YAML_FORMAT } from './PnpmYamlCommon'; -console.log('PnpmShrinkwrapFile.ts : 13: ' + (new Date().getTime() % 20000) / 1000.0); export interface IPeerDependenciesMetaYaml { optional?: boolean; diff --git a/apps/rush-lib/src/logic/yarn/YarnShrinkwrapFile.ts b/apps/rush-lib/src/logic/yarn/YarnShrinkwrapFile.ts index 906f1413f26..d6ff0268382 100644 --- a/apps/rush-lib/src/logic/yarn/YarnShrinkwrapFile.ts +++ b/apps/rush-lib/src/logic/yarn/YarnShrinkwrapFile.ts @@ -4,22 +4,14 @@ // eslint-disable-next-line const importLazy = require('import-lazy')(require); -console.log('YarnShrinkwrapFile.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as os from 'os'; -console.log('YarnShrinkwrapFile.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); // eslint-disable-next-line const lockfile = importLazy('@yarnpkg/lockfile'); -console.log('YarnShrinkwrapFile.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import { BaseShrinkwrapFile } from '../base/BaseShrinkwrapFile'; -console.log('YarnShrinkwrapFile.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { FileSystem, IParsedPackageNameOrError, InternalError } from '@rushstack/node-core-library'; -console.log('YarnShrinkwrapFile.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import { RushConstants } from '../RushConstants'; -console.log('YarnShrinkwrapFile.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); import { DependencySpecifier } from '../DependencySpecifier'; -console.log('YarnShrinkwrapFile.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); import { PackageNameParsers } from '../../api/PackageNameParsers'; -console.log('YarnShrinkwrapFile.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); interface IYarnLockfileParseResult { // eslint-disable-next-line diff --git a/apps/rush-lib/src/start.ts b/apps/rush-lib/src/start.ts index 2f73cdd6d10..2824680ce9a 100644 --- a/apps/rush-lib/src/start.ts +++ b/apps/rush-lib/src/start.ts @@ -1,12 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -console.log('start.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); - import { Rush } from './api/Rush'; -console.log('start.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); const rushVersion: string = Rush.version; -console.log('start.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); Rush.launch(rushVersion, { isManaged: false }); -console.log('start.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); diff --git a/libraries/node-core-library/src/Executable.ts b/libraries/node-core-library/src/Executable.ts index e29a71902ec..d36e2691d38 100644 --- a/libraries/node-core-library/src/Executable.ts +++ b/libraries/node-core-library/src/Executable.ts @@ -1,18 +1,12 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -console.log('NCL.Executable.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as child_process from 'child_process'; -console.log('NCL.Executable.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as os from 'os'; -console.log('NCL.Executable.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import * as path from 'path'; -console.log('NCL.Executable.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { FileSystem } from './FileSystem'; -console.log('NCL.Executable.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import { PosixModeBits } from './PosixModeBits'; -console.log('NCL.Executable.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); /** * Typings for one of the streams inside IExecutableSpawnSyncOptions.stdio. diff --git a/libraries/node-core-library/src/FileSystem.ts b/libraries/node-core-library/src/FileSystem.ts index b5a423d21de..0821ddd4c30 100644 --- a/libraries/node-core-library/src/FileSystem.ts +++ b/libraries/node-core-library/src/FileSystem.ts @@ -4,20 +4,14 @@ // eslint-disable-next-line const importLazy = require('import-lazy')(require); -console.log('NCL.FileSystem.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as nodeJsPath from 'path'; -console.log('NCL.FileSystem.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as fs from 'fs'; -console.log('NCL.FileSystem.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); // import * as fsx from 'fs-extra'; // eslint-disable-next-line const fsx = importLazy('fs-extra'); -console.log('NCL.FileSystem.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { Text, NewlineKind, Encoding } from './Text'; -console.log('NCL.FileSystem.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import { PosixModeBits } from './PosixModeBits'; -console.log('NCL.FileSystem.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); /** * An alias for the Node.js `fs.Stats` object. diff --git a/libraries/node-core-library/src/JsonFile.ts b/libraries/node-core-library/src/JsonFile.ts index ed62808b591..d4ca40c9314 100644 --- a/libraries/node-core-library/src/JsonFile.ts +++ b/libraries/node-core-library/src/JsonFile.ts @@ -1,18 +1,12 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -console.log('JsonFile.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as os from 'os'; -console.log('JsonFile.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as jju from 'jju'; -console.log('JsonFile.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import { JsonSchema, IJsonSchemaErrorInfo, IJsonSchemaValidateOptions } from './JsonSchema'; -console.log('JsonFile.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { Text, NewlineKind } from './Text'; -console.log('JsonFile.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import { FileSystem } from './FileSystem'; -console.log('JsonFile.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); /** * Represents a JSON-serializable object whose type has not been determined yet. diff --git a/libraries/node-core-library/src/JsonSchema.ts b/libraries/node-core-library/src/JsonSchema.ts index 119630175c8..673ef8cc0d4 100644 --- a/libraries/node-core-library/src/JsonSchema.ts +++ b/libraries/node-core-library/src/JsonSchema.ts @@ -1,18 +1,12 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -console.log('JsonSchema.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as os from 'os'; -console.log('JsonSchema.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as path from 'path'; -console.log('JsonSchema.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import Validator = require('z-schema/dist/ZSchema-browser-min'); -console.log('JsonSchema.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { JsonFile, JsonObject } from './JsonFile'; -console.log('JsonSchema.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import { FileSystem } from './FileSystem'; -console.log('JsonSchema.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); interface ISchemaWithId { id: string | undefined; diff --git a/libraries/node-core-library/src/LegacyAdapters.ts b/libraries/node-core-library/src/LegacyAdapters.ts index 03ca0f3d09a..759cca26142 100644 --- a/libraries/node-core-library/src/LegacyAdapters.ts +++ b/libraries/node-core-library/src/LegacyAdapters.ts @@ -1,11 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -console.log('LegacyAdapters.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import { sort as timsort } from 'timsort'; -console.log('LegacyAdapters.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as semver from 'semver'; -console.log('LegacyAdapters.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); /** * Callback used by {@link LegacyAdapters}. diff --git a/libraries/node-core-library/src/PackageJsonLookup.ts b/libraries/node-core-library/src/PackageJsonLookup.ts index 72198e6b9b6..e5f9a625b85 100644 --- a/libraries/node-core-library/src/PackageJsonLookup.ts +++ b/libraries/node-core-library/src/PackageJsonLookup.ts @@ -1,17 +1,11 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -console.log('PackageJsonLookup.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as path from 'path'; -console.log('PackageJsonLookup.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import { JsonFile } from './JsonFile'; -console.log('PackageJsonLookup.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import { IPackageJson, INodePackageJson } from './IPackageJson'; -console.log('PackageJsonLookup.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { FileConstants } from './Constants'; -console.log('PackageJsonLookup.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import { FileSystem } from './FileSystem'; -console.log('PackageJsonLookup.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); /** * Constructor parameters for {@link PackageJsonLookup} diff --git a/libraries/node-core-library/src/index.ts b/libraries/node-core-library/src/index.ts index 6dc657853d8..7e23cfa79ca 100644 --- a/libraries/node-core-library/src/index.ts +++ b/libraries/node-core-library/src/index.ts @@ -7,9 +7,7 @@ * @packageDocumentation */ -console.log('NCL.index.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); export { FileConstants, FolderConstants } from './Constants'; -console.log('NCL.index.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); export { ExecutableStdioStreamMapping, ExecutableStdioMapping, @@ -17,35 +15,25 @@ export { IExecutableSpawnSyncOptions, Executable } from './Executable'; -console.log('NCL.index.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); export { INodePackageJson, IPackageJson, IPackageJsonDependencyTable, IPackageJsonScriptTable } from './IPackageJson'; -console.log('NCL.index.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); export { InternalError } from './InternalError'; -console.log('NCL.index.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); export { JsonObject, JsonFile, IJsonFileSaveOptions, IJsonFileStringifyOptions } from './JsonFile'; -console.log('NCL.index.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); export { JsonSchema, IJsonSchemaErrorInfo, IJsonSchemaValidateOptions, IJsonSchemaFromFileOptions } from './JsonSchema'; -console.log('NCL.index.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); export { LockFile } from './LockFile'; -console.log('NCL.index.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); export { MapExtensions } from './MapExtensions'; -console.log('NCL.index.ts : 9: ' + (new Date().getTime() % 20000) / 1000.0); export { PosixModeBits } from './PosixModeBits'; -console.log('NCL.index.ts : 10: ' + (new Date().getTime() % 20000) / 1000.0); export { ProtectableMap, IProtectableMapParameters } from './ProtectableMap'; -console.log('NCL.index.ts : 11: ' + (new Date().getTime() % 20000) / 1000.0); export { IPackageJsonLookupParameters, PackageJsonLookup } from './PackageJsonLookup'; -console.log('NCL.index.ts : 12: ' + (new Date().getTime() % 20000) / 1000.0); export { PackageName, PackageNameParser, @@ -53,13 +41,9 @@ export { IParsedPackageName, IParsedPackageNameOrError } from './PackageName'; -console.log('NCL.index.ts : 13: ' + (new Date().getTime() % 20000) / 1000.0); export { Path } from './Path'; -console.log('NCL.index.ts : 14: ' + (new Date().getTime() % 20000) / 1000.0); export { Encoding, Text, NewlineKind } from './Text'; -console.log('NCL.index.ts : 15: ' + (new Date().getTime() % 20000) / 1000.0); export { Sort } from './Sort'; -console.log('NCL.index.ts : 16: ' + (new Date().getTime() % 20000) / 1000.0); export { AlreadyExistsBehavior, FileSystem, @@ -77,20 +61,11 @@ export { FileSystemCopyFilesAsyncFilter, FileSystemCopyFilesFilter } from './FileSystem'; -console.log('NCL.index.ts : 17: ' + (new Date().getTime() % 20000) / 1000.0); export { FileWriter, IFileWriterFlags } from './FileWriter'; -console.log('NCL.index.ts : 18: ' + (new Date().getTime() % 20000) / 1000.0); export { LegacyAdapters, LegacyCallback } from './LegacyAdapters'; -console.log('NCL.index.ts : 19: ' + (new Date().getTime() % 20000) / 1000.0); export { StringBuilder, IStringBuilder } from './StringBuilder'; -console.log('NCL.index.ts : 20: ' + (new Date().getTime() % 20000) / 1000.0); export { Terminal } from './Terminal/Terminal'; -console.log('NCL.index.ts : 21: ' + (new Date().getTime() % 20000) / 1000.0); export { Colors, IColorableSequence, ColorValue, TextAttribute } from './Terminal/Colors'; -console.log('NCL.index.ts : 22: ' + (new Date().getTime() % 20000) / 1000.0); export { ITerminalProvider, TerminalProviderSeverity } from './Terminal/ITerminalProvider'; -console.log('NCL.index.ts : 23: ' + (new Date().getTime() % 20000) / 1000.0); export { ConsoleTerminalProvider, IConsoleTerminalProviderOptions } from './Terminal/ConsoleTerminalProvider'; -console.log('NCL.index.ts : 24: ' + (new Date().getTime() % 20000) / 1000.0); export { StringBufferTerminalProvider } from './Terminal/StringBufferTerminalProvider'; -console.log('NCL.index.ts : 25: ' + (new Date().getTime() % 20000) / 1000.0); diff --git a/libraries/ts-command-line/src/index.ts b/libraries/ts-command-line/src/index.ts index abbab30e94a..169bc69e105 100644 --- a/libraries/ts-command-line/src/index.ts +++ b/libraries/ts-command-line/src/index.ts @@ -7,9 +7,7 @@ * @packageDocumentation */ -console.log('ts-command-line.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); export { CommandLineAction, ICommandLineActionOptions } from './providers/CommandLineAction'; -console.log('ts-command-line.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); export { IBaseCommandLineDefinition, @@ -22,38 +20,26 @@ export { ICommandLineRemainderDefinition } from './parameters/CommandLineDefinition'; -console.log('ts-command-line.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); export { CommandLineParameterKind, CommandLineParameter, CommandLineParameterWithArgument } from './parameters/BaseClasses'; -console.log('ts-command-line.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); export { CommandLineFlagParameter } from './parameters/CommandLineFlagParameter'; -console.log('ts-command-line.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); export { CommandLineStringParameter } from './parameters/CommandLineStringParameter'; -console.log('ts-command-line.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); export { CommandLineStringListParameter } from './parameters/CommandLineStringListParameter'; -console.log('ts-command-line.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); export { CommandLineIntegerParameter } from './parameters/CommandLineIntegerParameter'; -console.log('ts-command-line.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); export { CommandLineChoiceParameter } from './parameters/CommandLineChoiceParameter'; -console.log('ts-command-line.ts : 9: ' + (new Date().getTime() % 20000) / 1000.0); export { CommandLineRemainder } from './parameters/CommandLineRemainder'; -console.log('ts-command-line.ts : 10: ' + (new Date().getTime() % 20000) / 1000.0); export { CommandLineParameterProvider, ICommandLineParserData as _ICommandLineParserData } from './providers/CommandLineParameterProvider'; -console.log('ts-command-line.ts : 11: ' + (new Date().getTime() % 20000) / 1000.0); export { ICommandLineParserOptions, CommandLineParser } from './providers/CommandLineParser'; -console.log('ts-command-line.ts : 12: ' + (new Date().getTime() % 20000) / 1000.0); export { DynamicCommandLineAction } from './providers/DynamicCommandLineAction'; -console.log('ts-command-line.ts : 13: ' + (new Date().getTime() % 20000) / 1000.0); export { DynamicCommandLineParser } from './providers/DynamicCommandLineParser'; -console.log('ts-command-line.ts : 14: ' + (new Date().getTime() % 20000) / 1000.0); diff --git a/libraries/ts-command-line/src/providers/CommandLineAction.ts b/libraries/ts-command-line/src/providers/CommandLineAction.ts index ef3842a9228..0fa094c7f64 100644 --- a/libraries/ts-command-line/src/providers/CommandLineAction.ts +++ b/libraries/ts-command-line/src/providers/CommandLineAction.ts @@ -1,11 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -console.log('CommandLineAction.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import { CommandLineParameterProvider, ICommandLineParserData } from './CommandLineParameterProvider'; -console.log('CommandLineAction.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import * as argparse from 'argparse'; -console.log('CommandLineAction.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); /** * Options for the CommandLineAction constructor. diff --git a/libraries/ts-command-line/src/providers/CommandLineParameterProvider.ts b/libraries/ts-command-line/src/providers/CommandLineParameterProvider.ts index d306b7c7c99..61378abc8ea 100644 --- a/libraries/ts-command-line/src/providers/CommandLineParameterProvider.ts +++ b/libraries/ts-command-line/src/providers/CommandLineParameterProvider.ts @@ -1,9 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -console.log('CommandLineParameterProvider.ts : 1: ' + (new Date().getTime() % 20000) / 1000.0); import * as argparse from 'argparse'; -console.log('CommandLineParameterProvider.ts : 2: ' + (new Date().getTime() % 20000) / 1000.0); import { ICommandLineFlagDefinition, ICommandLineStringDefinition, @@ -12,25 +10,17 @@ import { ICommandLineChoiceDefinition, ICommandLineRemainderDefinition } from '../parameters/CommandLineDefinition'; -console.log('CommandLineParameterProvider.ts : 3: ' + (new Date().getTime() % 20000) / 1000.0); import { CommandLineParameter, CommandLineParameterWithArgument, CommandLineParameterKind } from '../parameters/BaseClasses'; -console.log('CommandLineParameterProvider.ts : 4: ' + (new Date().getTime() % 20000) / 1000.0); import { CommandLineFlagParameter } from '../parameters/CommandLineFlagParameter'; -console.log('CommandLineParameterProvider.ts : 5: ' + (new Date().getTime() % 20000) / 1000.0); import { CommandLineStringParameter } from '../parameters/CommandLineStringParameter'; -console.log('CommandLineParameterProvider.ts : 6: ' + (new Date().getTime() % 20000) / 1000.0); import { CommandLineStringListParameter } from '../parameters/CommandLineStringListParameter'; -console.log('CommandLineParameterProvider.ts : 7: ' + (new Date().getTime() % 20000) / 1000.0); import { CommandLineIntegerParameter } from '../parameters/CommandLineIntegerParameter'; -console.log('CommandLineParameterProvider.ts : 8: ' + (new Date().getTime() % 20000) / 1000.0); import { CommandLineChoiceParameter } from '../parameters/CommandLineChoiceParameter'; -console.log('CommandLineParameterProvider.ts : 9: ' + (new Date().getTime() % 20000) / 1000.0); import { CommandLineRemainder } from '../parameters/CommandLineRemainder'; -console.log('CommandLineParameterProvider.ts : 10: ' + (new Date().getTime() % 20000) / 1000.0); /** * This is the argparse result data object From b663e6a7cef5fadd88cb0734fcee477b8d42d400 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Sat, 1 Aug 2020 00:55:01 -0700 Subject: [PATCH 33/97] Remove trace logs --- apps/rush-lib/src/api/Rush.ts | 6 ------ apps/rush-lib/src/cli/RushCommandLineParser.ts | 9 --------- apps/rush-lib/src/cli/actions/TabCompleteAction.ts | 4 ---- libraries/node-core-library/src/PackageJsonLookup.ts | 4 ---- 4 files changed, 23 deletions(-) diff --git a/apps/rush-lib/src/api/Rush.ts b/apps/rush-lib/src/api/Rush.ts index e8e263c635d..273e898e39e 100644 --- a/apps/rush-lib/src/api/Rush.ts +++ b/apps/rush-lib/src/api/Rush.ts @@ -52,28 +52,22 @@ export class Rush { * Even though this API isn't documented, it is still supported for legacy compatibility. */ public static launch(launcherVersion: string, arg: ILaunchOptions): void { - console.log('Rush.launch() : 1: ' + (new Date().getTime() % 20000) / 1000.0); const options: ILaunchOptions = Rush._normalizeLaunchOptions(arg); - console.log('Rush.launch() : 2: ' + (new Date().getTime() % 20000) / 1000.0); if (!Utilities.isNonDebugTabCompletionRequest()) { Rush._printStartupBanner(options.isManaged); } - console.log('Rush.launch() : 3: ' + (new Date().getTime() % 20000) / 1000.0); if (!CommandLineMigrationAdvisor.checkArgv(process.argv)) { // The migration advisor recognized an obsolete command-line process.exitCode = 1; return; } - console.log('Rush.launch() : 4: ' + (new Date().getTime() % 20000) / 1000.0); const parser: RushCommandLineParser = new RushCommandLineParser({ alreadyReportedNodeTooNewError: options.alreadyReportedNodeTooNewError }); - console.log('Rush.launch() : 5: ' + (new Date().getTime() % 20000) / 1000.0); parser.execute().catch(console.error); // CommandLineParser.execute() should never reject the promise - console.log('Rush.launch() : 6: ' + (new Date().getTime() % 20000) / 1000.0); } /** diff --git a/apps/rush-lib/src/cli/RushCommandLineParser.ts b/apps/rush-lib/src/cli/RushCommandLineParser.ts index 1938c42649f..12a5b703fc0 100644 --- a/apps/rush-lib/src/cli/RushCommandLineParser.ts +++ b/apps/rush-lib/src/cli/RushCommandLineParser.ts @@ -59,7 +59,6 @@ export class RushCommandLineParser extends CommandLineParser { private _rushOptions: IRushCommandLineParserOptions; public constructor(options?: Partial) { - console.log('RushCommandLineParser.constructor() : 1: ' + (new Date().getTime() % 20000) / 1000.0); super({ toolFilename: 'rush', toolDescription: @@ -73,35 +72,27 @@ export class RushCommandLineParser extends CommandLineParser { ' Rush is for you.' }); - console.log('RushCommandLineParser.constructor() : 2: ' + (new Date().getTime() % 20000) / 1000.0); this._rushOptions = this._normalizeOptions(options || {}); - console.log('RushCommandLineParser.constructor() : 3: ' + (new Date().getTime() % 20000) / 1000.0); try { - console.log('RushCommandLineParser.constructor() : 4: ' + (new Date().getTime() % 20000) / 1000.0); const rushJsonFilename: string | undefined = RushConfiguration.tryFindRushJsonLocation({ startingFolder: this._rushOptions.cwd, showVerbose: !Utilities.isNonDebugTabCompletionRequest() }); - console.log('RushCommandLineParser.constructor() : 5: ' + (new Date().getTime() % 20000) / 1000.0); if (rushJsonFilename) { this.rushConfiguration = RushConfiguration.loadFromConfigurationFile(rushJsonFilename); } - console.log('RushCommandLineParser.constructor() : 6: ' + (new Date().getTime() % 20000) / 1000.0); } catch (error) { this._reportErrorAndSetExitCode(error); } - console.log('RushCommandLineParser.constructor() : 7: ' + (new Date().getTime() % 20000) / 1000.0); NodeJsCompatibility.warnAboutCompatibilityIssues({ isRushLib: true, alreadyReportedNodeTooNewError: this._rushOptions.alreadyReportedNodeTooNewError, rushConfiguration: this.rushConfiguration }); - console.log('RushCommandLineParser.constructor() : 8: ' + (new Date().getTime() % 20000) / 1000.0); this._populateActions(); - console.log('RushCommandLineParser.constructor() : 9: ' + (new Date().getTime() % 20000) / 1000.0); } public get isDebug(): boolean { diff --git a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts index 1ffd3f8c9ad..d6a671c305d 100644 --- a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts +++ b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts @@ -23,7 +23,6 @@ export class TabCompleteAction extends BaseRushAction { private _positionParameter: CommandLineIntegerParameter; public constructor(parser: RushCommandLineParser) { - console.log('TabCompleteAction.constructor : 1: ' + (new Date().getTime() % 20000) / 1000.0); super({ actionName: 'tab-complete', summary: 'Provides tab completion.', @@ -31,7 +30,6 @@ export class TabCompleteAction extends BaseRushAction { parser, safeForSimultaneousRushProcesses: true }); - console.log('TabCompleteAction.constructor : 2: ' + (new Date().getTime() % 20000) / 1000.0); } protected onDefineParameters(): void { @@ -51,14 +49,12 @@ export class TabCompleteAction extends BaseRushAction { } protected async runAsync(): Promise { - console.log('TabCompleteAction.runAsync : 1: ' + (new Date().getTime() % 20000) / 1000.0); const commandLine: string = this._wordToCompleteParameter.value || ''; const caretPosition: number = this._positionParameter.value || 0; for (const value of this._getCompletions(commandLine, caretPosition)) { console.log(value); } - console.log('TabCompleteAction.runAsync : 2: ' + (new Date().getTime() % 20000) / 1000.0); } public *_getCompletions(commandLine: string, caretPosition: number): IterableIterator { diff --git a/libraries/node-core-library/src/PackageJsonLookup.ts b/libraries/node-core-library/src/PackageJsonLookup.ts index e5f9a625b85..7f24ee31ad2 100644 --- a/libraries/node-core-library/src/PackageJsonLookup.ts +++ b/libraries/node-core-library/src/PackageJsonLookup.ts @@ -76,12 +76,10 @@ export class PackageJsonLookup { * loading, an exception will be thrown instead. */ public static loadOwnPackageJson(dirnameOfCaller: string): IPackageJson { - console.log('PackageJsonLookup.loadOwnPackageJson() : 1: ' + (new Date().getTime() % 20000) / 1000.0); const packageJson: | IPackageJson | undefined = PackageJsonLookup._loadOwnPackageJsonLookup.tryLoadPackageJsonFor(dirnameOfCaller); - console.log('PackageJsonLookup.loadOwnPackageJson() : 2: ' + (new Date().getTime() % 20000) / 1000.0); if (packageJson === undefined) { throw new Error( `PackageJsonLookup.loadOwnPackageJson() failed to find the caller's package.json.` + @@ -89,12 +87,10 @@ export class PackageJsonLookup { ); } - console.log('PackageJsonLookup.loadOwnPackageJson() : 3: ' + (new Date().getTime() % 20000) / 1000.0); if (packageJson.version !== undefined) { return packageJson as IPackageJson; } - console.log('PackageJsonLookup.loadOwnPackageJson() : 4: ' + (new Date().getTime() % 20000) / 1000.0); const errorPath: string = PackageJsonLookup._loadOwnPackageJsonLookup.tryGetPackageJsonFilePathFor(dirnameOfCaller) || 'package.json'; From ea20cfad52d83726bbd4da647255ff2b5e6c4472 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Sat, 1 Aug 2020 01:12:06 -0700 Subject: [PATCH 34/97] Suppress some linter warnings --- apps/rush-lib/src/api/RushConfiguration.ts | 6 ------ apps/rush-lib/src/cli/actions/ListAction.ts | 1 + apps/rush-lib/src/cli/actions/ScanAction.ts | 2 +- apps/rush-lib/src/logic/ChangeFiles.ts | 4 ++-- .../src/logic/deploy/DeployManager.ts | 2 +- .../installManager/RushInstallManager.ts | 2 +- apps/rush-lib/src/logic/npm/NpmLinkManager.ts | 19 +++---------------- common/reviews/api/node-core-library.api.md | 2 -- common/reviews/api/ts-command-line.api.md | 2 -- 9 files changed, 9 insertions(+), 31 deletions(-) diff --git a/apps/rush-lib/src/api/RushConfiguration.ts b/apps/rush-lib/src/api/RushConfiguration.ts index 05c4825c213..64ece23f18c 100644 --- a/apps/rush-lib/src/api/RushConfiguration.ts +++ b/apps/rush-lib/src/api/RushConfiguration.ts @@ -816,13 +816,7 @@ export class RushConfiguration { } } - console.log( - 'RushConfiguration.loadFromConfigurationFile() : 5: ' + (new Date().getTime() % 20000) / 1000.0 - ); RushConfiguration._jsonSchema.validateObject(rushConfigurationJson, resolvedRushJsonFilename); - console.log( - 'RushConfiguration.loadFromConfigurationFile() : 6: ' + (new Date().getTime() % 20000) / 1000.0 - ); return new RushConfiguration(rushConfigurationJson, resolvedRushJsonFilename); } diff --git a/apps/rush-lib/src/cli/actions/ListAction.ts b/apps/rush-lib/src/cli/actions/ListAction.ts index cf05edd55df..f310d42073b 100644 --- a/apps/rush-lib/src/cli/actions/ListAction.ts +++ b/apps/rush-lib/src/cli/actions/ListAction.ts @@ -8,6 +8,7 @@ import { BaseRushAction } from './BaseRushAction'; import { RushCommandLineParser } from '../RushCommandLineParser'; import { CommandLineFlagParameter } from '@rushstack/ts-command-line'; import { RushConfigurationProject } from '../../api/RushConfigurationProject'; +// eslint-disable-next-line const Table = importLazy('cli-table'); export interface IJsonEntry { diff --git a/apps/rush-lib/src/cli/actions/ScanAction.ts b/apps/rush-lib/src/cli/actions/ScanAction.ts index c5f8893d496..052072811ac 100644 --- a/apps/rush-lib/src/cli/actions/ScanAction.ts +++ b/apps/rush-lib/src/cli/actions/ScanAction.ts @@ -5,7 +5,7 @@ const importLazy = require('import-lazy')(require); import * as colors from 'colors'; -// import * as glob from 'glob'; +// eslint-disable-next-line const glob = importLazy('glob'); import * as path from 'path'; import * as builtinPackageNames from 'builtin-modules'; diff --git a/apps/rush-lib/src/logic/ChangeFiles.ts b/apps/rush-lib/src/logic/ChangeFiles.ts index d1746422abb..703e6c9d114 100644 --- a/apps/rush-lib/src/logic/ChangeFiles.ts +++ b/apps/rush-lib/src/logic/ChangeFiles.ts @@ -5,13 +5,13 @@ const importLazy = require('import-lazy')(require); import { EOL } from 'os'; -// import * as glob from 'glob'; +// eslint-disable-next-line const glob = importLazy('glob'); +import { JsonFile } from '@rushstack/node-core-library'; import { Utilities } from '../utilities/Utilities'; import { IChangeInfo } from '../api/ChangeManagement'; import { IChangelog } from '../api/Changelog'; -import { JsonFile } from '@rushstack/node-core-library'; import { RushConfiguration } from '../api/RushConfiguration'; /** diff --git a/apps/rush-lib/src/logic/deploy/DeployManager.ts b/apps/rush-lib/src/logic/deploy/DeployManager.ts index 4d57d09f191..7b99d3b910c 100644 --- a/apps/rush-lib/src/logic/deploy/DeployManager.ts +++ b/apps/rush-lib/src/logic/deploy/DeployManager.ts @@ -6,6 +6,7 @@ const importLazy = require('import-lazy')(require); import * as colors from 'colors'; import * as path from 'path'; +// eslint-disable-next-line const resolve = importLazy('resolve'); // eslint-disable-next-line const npmPacklist = importLazy('npm-packlist'); @@ -39,7 +40,6 @@ import { matchesWithStar } from './Utils'; interface INpmPackListWalkerSync { readonly result: string[]; - constructor(opts: { path: string }); start(): void; } diff --git a/apps/rush-lib/src/logic/installManager/RushInstallManager.ts b/apps/rush-lib/src/logic/installManager/RushInstallManager.ts index 397c962dfbe..99b80897c84 100644 --- a/apps/rush-lib/src/logic/installManager/RushInstallManager.ts +++ b/apps/rush-lib/src/logic/installManager/RushInstallManager.ts @@ -4,7 +4,7 @@ // eslint-disable-next-line const importLazy = require('import-lazy')(require); -// import * as glob from 'glob'; +// eslint-disable-next-line const glob = importLazy('glob'); import * as colors from 'colors'; import * as os from 'os'; diff --git a/apps/rush-lib/src/logic/npm/NpmLinkManager.ts b/apps/rush-lib/src/logic/npm/NpmLinkManager.ts index 49b3785acfe..a8634e6a20a 100644 --- a/apps/rush-lib/src/logic/npm/NpmLinkManager.ts +++ b/apps/rush-lib/src/logic/npm/NpmLinkManager.ts @@ -8,12 +8,10 @@ import * as colors from 'colors'; import * as os from 'os'; import * as path from 'path'; import * as semver from 'semver'; -// import * as tar from 'tar'; // eslint-disable-next-line const tar = importLazy('tar'); -// import readPackageTree = require('read-package-tree'); // eslint-disable-next-line -const readPackageTree = importLazy('read-package-tree'); +import readPackageTree = require('read-package-tree'); import { FileSystem, FileConstants, LegacyAdapters } from '@rushstack/node-core-library'; import { RushConstants } from '../../logic/RushConstants'; @@ -35,21 +33,10 @@ interface IQueueItem { cyclicSubtreeRoot: NpmPackage | undefined; } -interface readPackageTreeNode { - id: number; - package: any; - children: readPackageTreeNode[]; - parent: readPackageTreeNode | null; - path: string; - realpath: string; - error: Error | null; - isLink: boolean; -} - export class NpmLinkManager extends BaseLinkManager { protected async _linkProjects(): Promise { - const npmPackage: readPackageTreeNode = await LegacyAdapters.convertCallbackToPromise< - readPackageTreeNode, + const npmPackage: readPackageTree.Node = await LegacyAdapters.convertCallbackToPromise< + readPackageTree.Node, Error, string >(readPackageTree, this._rushConfiguration.commonTempFolder); diff --git a/common/reviews/api/node-core-library.api.md b/common/reviews/api/node-core-library.api.md index 9fbc8190a9d..f7357cc3ee0 100644 --- a/common/reviews/api/node-core-library.api.md +++ b/common/reviews/api/node-core-library.api.md @@ -652,6 +652,4 @@ export enum TextAttribute { } -// (No @packageDocumentation comment for this package) - ``` diff --git a/common/reviews/api/ts-command-line.api.md b/common/reviews/api/ts-command-line.api.md index 85a482fd1fc..d6a4f4684aa 100644 --- a/common/reviews/api/ts-command-line.api.md +++ b/common/reviews/api/ts-command-line.api.md @@ -265,6 +265,4 @@ export interface ICommandLineStringListDefinition extends IBaseCommandLineDefini } -// (No @packageDocumentation comment for this package) - ``` From b17f84fe7258dadf373de20cf39ec5bbd076d71a Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Sat, 1 Aug 2020 01:32:09 -0700 Subject: [PATCH 35/97] Remove comments --- apps/rush-lib/src/cli/actions/ChangeAction.ts | 1 - apps/rush-lib/src/cli/scriptActions/BulkScriptAction.ts | 2 +- apps/rush-lib/src/logic/base/BaseInstallManager.ts | 1 - apps/rush-lib/src/logic/deploy/DeployArchiver.ts | 1 - apps/rush-lib/src/logic/pnpm/PnpmLinkManager.ts | 1 - libraries/node-core-library/src/FileSystem.ts | 2 +- libraries/node-core-library/src/FileWriter.ts | 1 - 7 files changed, 2 insertions(+), 7 deletions(-) diff --git a/apps/rush-lib/src/cli/actions/ChangeAction.ts b/apps/rush-lib/src/cli/actions/ChangeAction.ts index 22e8211f2d6..9d6314223d2 100644 --- a/apps/rush-lib/src/cli/actions/ChangeAction.ts +++ b/apps/rush-lib/src/cli/actions/ChangeAction.ts @@ -8,7 +8,6 @@ import * as os from 'os'; import * as path from 'path'; import * as child_process from 'child_process'; import * as colors from 'colors'; -// import * as inquirer from 'inquirer'; // eslint-disable-next-line const inquirer = importLazy('inquirer'); diff --git a/apps/rush-lib/src/cli/scriptActions/BulkScriptAction.ts b/apps/rush-lib/src/cli/scriptActions/BulkScriptAction.ts index 8100e90ee84..9b6975fccfa 100644 --- a/apps/rush-lib/src/cli/scriptActions/BulkScriptAction.ts +++ b/apps/rush-lib/src/cli/scriptActions/BulkScriptAction.ts @@ -75,7 +75,7 @@ export class BulkScriptAction extends BaseScriptAction { this._allowWarningsInSuccessfulBuild = options.allowWarningsInSuccessfulBuild; } - public runAsync(): Promise { + public async runAsync(): Promise { // TODO: Replace with last-install.flag when "rush link" and "rush unlink" are deprecated const lastLinkFlag: LastLinkFlag = LastLinkFlagFactory.getCommonTempFlag(this.rushConfiguration); if (!lastLinkFlag.isValid()) { diff --git a/apps/rush-lib/src/logic/base/BaseInstallManager.ts b/apps/rush-lib/src/logic/base/BaseInstallManager.ts index 1f4ae2e4bd9..c68dfc64ac2 100644 --- a/apps/rush-lib/src/logic/base/BaseInstallManager.ts +++ b/apps/rush-lib/src/logic/base/BaseInstallManager.ts @@ -8,7 +8,6 @@ import * as colors from 'colors'; import * as fetch from 'node-fetch'; import * as fs from 'fs'; import * as http from 'http'; -// import HttpsProxyAgent = require('https-proxy-agent'); // eslint-disable-next-line const HttpsProxyAgent = importLazy('https-proxy-agent'); import * as os from 'os'; diff --git a/apps/rush-lib/src/logic/deploy/DeployArchiver.ts b/apps/rush-lib/src/logic/deploy/DeployArchiver.ts index ba4f3c01201..9f511436493 100644 --- a/apps/rush-lib/src/logic/deploy/DeployArchiver.ts +++ b/apps/rush-lib/src/logic/deploy/DeployArchiver.ts @@ -4,7 +4,6 @@ // eslint-disable-next-line const importLazy = require('import-lazy')(require); -// import * as JSZip from 'jszip'; // eslint-disable-next-line const JSZip = importLazy('jszip'); import * as path from 'path'; diff --git a/apps/rush-lib/src/logic/pnpm/PnpmLinkManager.ts b/apps/rush-lib/src/logic/pnpm/PnpmLinkManager.ts index a19075eca61..86edcbf4ee0 100644 --- a/apps/rush-lib/src/logic/pnpm/PnpmLinkManager.ts +++ b/apps/rush-lib/src/logic/pnpm/PnpmLinkManager.ts @@ -8,7 +8,6 @@ import * as os from 'os'; import * as path from 'path'; import uriEncode = require('strict-uri-encode'); -// import pnpmLinkBins from '@pnpm/link-bins'; // eslint-disable-next-line const pnpmLinkBins = importLazy('@pnpm/link-bins'); diff --git a/libraries/node-core-library/src/FileSystem.ts b/libraries/node-core-library/src/FileSystem.ts index 0821ddd4c30..99ec39fb717 100644 --- a/libraries/node-core-library/src/FileSystem.ts +++ b/libraries/node-core-library/src/FileSystem.ts @@ -6,7 +6,7 @@ const importLazy = require('import-lazy')(require); import * as nodeJsPath from 'path'; import * as fs from 'fs'; -// import * as fsx from 'fs-extra'; + // eslint-disable-next-line const fsx = importLazy('fs-extra'); diff --git a/libraries/node-core-library/src/FileWriter.ts b/libraries/node-core-library/src/FileWriter.ts index d1147d5969c..fd3d64141a4 100644 --- a/libraries/node-core-library/src/FileWriter.ts +++ b/libraries/node-core-library/src/FileWriter.ts @@ -4,7 +4,6 @@ // eslint-disable-next-line const importLazy = require('import-lazy')(require); -// import * as fsx from 'fs-extra'; // eslint-disable-next-line const fsx = importLazy('fs-extra'); From e3d6b4beb6296bc2c14757517ad660f814a8bf78 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Sat, 1 Aug 2020 01:36:19 -0700 Subject: [PATCH 36/97] Rename import --- apps/rush-lib/src/logic/pnpm/PnpmWorkspaceFile.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/rush-lib/src/logic/pnpm/PnpmWorkspaceFile.ts b/apps/rush-lib/src/logic/pnpm/PnpmWorkspaceFile.ts index dc42eeded83..d9b7e245fc5 100644 --- a/apps/rush-lib/src/logic/pnpm/PnpmWorkspaceFile.ts +++ b/apps/rush-lib/src/logic/pnpm/PnpmWorkspaceFile.ts @@ -12,7 +12,7 @@ const yaml = importLazy('js-yaml'); import { FileSystem, Sort, Text } from '@rushstack/node-core-library'; import { BaseWorkspaceFile } from '../base/BaseWorkspaceFile'; -import { PNPM_SHRINKWRAP_YAML_FORMAT as PNPM_YAML_DUMP_OPTIONS } from './PnpmYamlCommon'; +import { PNPM_SHRINKWRAP_YAML_FORMAT } from './PnpmYamlCommon'; /** * This interface represents the raw pnpm-workspace.YAML file @@ -77,6 +77,6 @@ export class PnpmWorkspaceFile extends BaseWorkspaceFile { const workspaceYaml: IPnpmWorkspaceYaml = { packages: Array.from(this._workspacePackages) }; - return yaml.safeDump(workspaceYaml, PNPM_YAML_DUMP_OPTIONS); + return yaml.safeDump(workspaceYaml, PNPM_SHRINKWRAP_YAML_FORMAT); } } From 6db96247c4a189d118766f720bde17ac18eb8b13 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Sat, 1 Aug 2020 01:55:08 -0700 Subject: [PATCH 37/97] Address comments --- apps/rush-lib/src/api/Rush.ts | 2 +- apps/rush-lib/src/utilities/Utilities.ts | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/rush-lib/src/api/Rush.ts b/apps/rush-lib/src/api/Rush.ts index 273e898e39e..f71ca88e03f 100644 --- a/apps/rush-lib/src/api/Rush.ts +++ b/apps/rush-lib/src/api/Rush.ts @@ -54,7 +54,7 @@ export class Rush { public static launch(launcherVersion: string, arg: ILaunchOptions): void { const options: ILaunchOptions = Rush._normalizeLaunchOptions(arg); - if (!Utilities.isNonDebugTabCompletionRequest()) { + if (!Utilities.shouldPrintBanner()) { Rush._printStartupBanner(options.isManaged); } diff --git a/apps/rush-lib/src/utilities/Utilities.ts b/apps/rush-lib/src/utilities/Utilities.ts index 4b7e344c8ef..adcb33d9724 100644 --- a/apps/rush-lib/src/utilities/Utilities.ts +++ b/apps/rush-lib/src/utilities/Utilities.ts @@ -446,6 +446,10 @@ export class Utilities { return process.argv.length > 2 && process.argv[2] === 'tab-complete'; } + public static shouldPrintBanner(): boolean { + return !Utilities.isNonDebugTabCompletionRequest() && process.argv.indexOf('--json') === -1; + } + /** * For strings passed to a shell command, this adds appropriate escaping * to avoid misinterpretation of spaces or special characters. From 38bf225c2805f90e604cf7f32c7d3955fe339faf Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Sat, 1 Aug 2020 11:28:29 -0700 Subject: [PATCH 38/97] Fix some bugs. Use a lib for parsing command line sentences. --- apps/rush-lib/package.json | 1 + apps/rush-lib/src/api/Rush.ts | 2 +- .../src/cli/actions/TabCompleteAction.ts | 27 ++---- .../actions/test/TabCompleteAction.test.ts | 93 +++++++++++++++++-- apps/rush-lib/src/start.ts | 6 +- .../rush/browser-approved-packages.json | 11 ++- .../rush/nonbrowser-approved-packages.json | 1 - common/config/rush/pnpm-lock.yaml | 8 ++ common/config/rush/repo-state.json | 2 +- 9 files changed, 117 insertions(+), 34 deletions(-) diff --git a/apps/rush-lib/package.json b/apps/rush-lib/package.json index 45212bf9957..aee4341b879 100644 --- a/apps/rush-lib/package.json +++ b/apps/rush-lib/package.json @@ -44,6 +44,7 @@ "resolve": "~1.17.0", "semver": "~7.3.0", "strict-uri-encode": "~2.0.0", + "string-argv": "^0.3.1", "tar": "~5.0.5", "true-case-path": "~2.2.1", "wordwrap": "~1.0.0", diff --git a/apps/rush-lib/src/api/Rush.ts b/apps/rush-lib/src/api/Rush.ts index f71ca88e03f..96fac4bc939 100644 --- a/apps/rush-lib/src/api/Rush.ts +++ b/apps/rush-lib/src/api/Rush.ts @@ -54,7 +54,7 @@ export class Rush { public static launch(launcherVersion: string, arg: ILaunchOptions): void { const options: ILaunchOptions = Rush._normalizeLaunchOptions(arg); - if (!Utilities.shouldPrintBanner()) { + if (Utilities.shouldPrintBanner()) { Rush._printStartupBanner(options.isManaged); } diff --git a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts index d6a671c305d..63a92c9b0fc 100644 --- a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts +++ b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts @@ -3,6 +3,7 @@ import { BaseRushAction } from './BaseRushAction'; import { RushCommandLineParser } from '../RushCommandLineParser'; +import stringArgv from 'string-argv'; import { CommandLineStringParameter, @@ -52,12 +53,12 @@ export class TabCompleteAction extends BaseRushAction { const commandLine: string = this._wordToCompleteParameter.value || ''; const caretPosition: number = this._positionParameter.value || 0; - for (const value of this._getCompletions(commandLine, caretPosition)) { + for (const value of this.getCompletions(commandLine, caretPosition)) { console.log(value); } } - public *_getCompletions(commandLine: string, caretPosition: number): IterableIterator { + public *getCompletions(commandLine: string, caretPosition: number): IterableIterator { const actions: Map = new Map(); this.parser.actions.forEach((element) => { const actionParameters: IParameter[] = []; @@ -75,23 +76,12 @@ export class TabCompleteAction extends BaseRushAction { actions['-h'] = []; actions['--help'] = []; - // yield ('arg count: ' + process.argv.length); - - // for (let i: number = 0; i < process.argv.length; i++) { - // yield (i + ': ' + process.argv[i] + ' [' + process.argv[i].length + ']'); - // } - if (!commandLine || !caretPosition) { yield* Object.keys(actions); // return all actions return; } - const tokens: string[] = this._tokenizeCommandLine(commandLine); - - // yield ('commandLine: ' + commandLine); - // yield ('commandLine.length: ' + commandLine.length); - // yield ('caretPosition: ' + caretPosition); - // yield ('tokens.length: ' + tokens.length); + const tokens: string[] = Array.from(this.tokenizeCommandLine(commandLine)); const debugParameterUsed: boolean = tokens.length > 1 && (tokens[1] === '-d' || tokens[1] === '--debug'); const debugParameterOffset: number = debugParameterUsed ? 1 : 0; // if debug switch is used, then offset everything by 1. @@ -103,8 +93,6 @@ export class TabCompleteAction extends BaseRushAction { const lastToken: string = tokens[tokens.length - 1]; const secondLastToken: string = tokens[tokens.length - 2]; - // yield ('lastToken: ' + lastToken); - // yield ('secondLastToken: ' + secondLastToken); const completePartialWord: boolean = caretPosition === commandLine.length; @@ -175,8 +163,8 @@ export class TabCompleteAction extends BaseRushAction { } } - private _tokenizeCommandLine(commandLine: string): string[] { - return commandLine.split(' '); + public tokenizeCommandLine(commandLine: string): string[] { + return stringArgv(commandLine); } private *_getChoiceParameterValues( @@ -208,3 +196,6 @@ export class TabCompleteAction extends BaseRushAction { } } } +// function isWhiteSpaceStrict(ch: string | undefined) { +// return ch && ch.length > 0 && ch.trim() === ''; +// } diff --git a/apps/rush-lib/src/cli/actions/test/TabCompleteAction.test.ts b/apps/rush-lib/src/cli/actions/test/TabCompleteAction.test.ts index 963aedf4ca0..a19f3693aae 100644 --- a/apps/rush-lib/src/cli/actions/test/TabCompleteAction.test.ts +++ b/apps/rush-lib/src/cli/actions/test/TabCompleteAction.test.ts @@ -45,7 +45,7 @@ describe('TabCompleteAction', () => { const tc: TabCompleteAction = new TabCompleteAction(parser); const commandLine: string = 'rush'; - const actual: string[] = Array.from(tc._getCompletions(commandLine.trim(), commandLine.length)); + const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); expect(actual.indexOf('add') !== -1).toBe(true); expect(actual.indexOf('check') !== -1).toBe(true); @@ -67,7 +67,7 @@ describe('TabCompleteAction', () => { const tc: TabCompleteAction = new TabCompleteAction(parser); const commandLine: string = 'rush a'; - const actual: string[] = Array.from(tc._getCompletions(commandLine.trim(), commandLine.length)); + const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); const expected: string[] = ['add']; @@ -85,7 +85,7 @@ describe('TabCompleteAction', () => { const tc: TabCompleteAction = new TabCompleteAction(parser); const commandLine: string = 'rush build '; - const actual: string[] = Array.from(tc._getCompletions(commandLine.trim(), commandLine.length)); + const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); expect(actual.indexOf('-t') !== -1).toBe(true); expect(actual.indexOf('--to') !== -1).toBe(true); @@ -104,7 +104,7 @@ describe('TabCompleteAction', () => { const tc: TabCompleteAction = new TabCompleteAction(parser); const commandLine: string = 'rush build -'; - const actual: string[] = Array.from(tc._getCompletions(commandLine.trim(), commandLine.length)); + const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); expect(actual.indexOf('-t') !== -1).toBe(true); expect(actual.indexOf('--to') !== -1).toBe(true); @@ -123,7 +123,7 @@ describe('TabCompleteAction', () => { const tc: TabCompleteAction = new TabCompleteAction(parser); const commandLine: string = 'rush build -t '; - const actual: string[] = Array.from(tc._getCompletions(commandLine.trim(), commandLine.length)); + const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); const expected: string[] = ['abc', 'def']; @@ -141,7 +141,7 @@ describe('TabCompleteAction', () => { const tc: TabCompleteAction = new TabCompleteAction(parser); const commandLine: string = 'rush build -t a'; - const actual: string[] = Array.from(tc._getCompletions(commandLine.trim(), commandLine.length)); + const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); const expected: string[] = ['abc']; @@ -159,7 +159,7 @@ describe('TabCompleteAction', () => { const tc: TabCompleteAction = new TabCompleteAction(parser); const commandLine: string = 'rush change --bump-type '; - const actual: string[] = Array.from(tc._getCompletions(commandLine.trim(), commandLine.length)); + const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); const expected: string[] = ['major', 'minor', 'patch', 'none']; expect(arrayEqual(actual, expected)).toBe(true); @@ -176,7 +176,7 @@ describe('TabCompleteAction', () => { const tc: TabCompleteAction = new TabCompleteAction(parser); const commandLine: string = 'rush change --bump-type m'; - const actual: string[] = Array.from(tc._getCompletions(commandLine.trim(), commandLine.length)); + const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); const expected: string[] = ['major', 'minor']; expect(arrayEqual(actual, expected)).toBe(true); @@ -193,11 +193,86 @@ describe('TabCompleteAction', () => { const tc: TabCompleteAction = new TabCompleteAction(parser); const commandLine: string = 'rush change --message '; - const actual: string[] = Array.from(tc._getCompletions(commandLine.trim(), commandLine.length)); + const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); const expected: string[] = []; expect(arrayEqual(actual, expected)).toBe(true); }); + + it(`gets completion(s) for rush change --message "my change log message" --bump-type `, () => { + const startPath: string = path.resolve(__dirname, 'tabComplete'); + // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit + // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test + // repo will fail due to contention over the same lock which is kept until the test runner process + // ends. + jest.spyOn(process, 'cwd').mockReturnValue(startPath); + const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); + const tc: TabCompleteAction = new TabCompleteAction(parser); + + const commandLine: string = 'rush change --message "my change log message" --bump-type '; + const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); + + const expected: string[] = ['major', 'minor', 'patch', 'none']; + + expect(arrayEqual(actual, expected)).toBe(true); + }); + + it(`gets completion(s) for rush change --message "my change log message" --bump-type m`, () => { + const startPath: string = path.resolve(__dirname, 'tabComplete'); + // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit + // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test + // repo will fail due to contention over the same lock which is kept until the test runner process + // ends. + jest.spyOn(process, 'cwd').mockReturnValue(startPath); + const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); + const tc: TabCompleteAction = new TabCompleteAction(parser); + + const commandLine: string = 'rush change --message "my change log message" --bump-type m'; + const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); + + const expected: string[] = ['major', 'minor']; + + expect(arrayEqual(actual, expected)).toBe(true); + }); + }); + + describe(`Tokenize command line`, () => { + it(`tokenizes "rush change -"`, () => { + const startPath: string = path.resolve(__dirname, 'tabComplete'); + // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit + // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test + // repo will fail due to contention over the same lock which is kept until the test runner process + // ends. + jest.spyOn(process, 'cwd').mockReturnValue(startPath); + const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); + const tc: TabCompleteAction = new TabCompleteAction(parser); + + const commandLine: string = 'rush change -'; + const actual: string[] = Array.from(tc.tokenizeCommandLine(commandLine.trim())); + console.log(actual); + + const expected: string[] = ['rush', 'change', '-']; + + expect(arrayEqual(actual, expected)).toBe(true); + }); + it(`tokenizes 'rush change -m "my change log"'`, () => { + const startPath: string = path.resolve(__dirname, 'tabComplete'); + // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit + // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test + // repo will fail due to contention over the same lock which is kept until the test runner process + // ends. + jest.spyOn(process, 'cwd').mockReturnValue(startPath); + const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); + const tc: TabCompleteAction = new TabCompleteAction(parser); + + const commandLine: string = 'rush change -m "my change log"'; + const actual: string[] = Array.from(tc.tokenizeCommandLine(commandLine.trim())); + console.log(actual); + + const expected: string[] = ['rush', 'change', '-m', 'my change log']; + + expect(arrayEqual(actual, expected)).toBe(true); + }); }); }); diff --git a/apps/rush-lib/src/start.ts b/apps/rush-lib/src/start.ts index 2824680ce9a..ad8526ee613 100644 --- a/apps/rush-lib/src/start.ts +++ b/apps/rush-lib/src/start.ts @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. - +console.log('start.ts: 1: ' + (new Date().getTime() % 20000) / 1000.0); import { Rush } from './api/Rush'; -const rushVersion: string = Rush.version; -Rush.launch(rushVersion, { isManaged: false }); +Rush.launch(Rush.version, { isManaged: false }); +console.log('start.ts: 2: ' + (new Date().getTime() % 20000) / 1000.0); diff --git a/common/config/rush/browser-approved-packages.json b/common/config/rush/browser-approved-packages.json index 34c3a91cc03..1ac66e34b6d 100644 --- a/common/config/rush/browser-approved-packages.json +++ b/common/config/rush/browser-approved-packages.json @@ -1,5 +1,14 @@ // DO NOT ADD COMMENTS IN THIS FILE. They will be lost when the Rush tool resaves it. { "$schema": "https://developer.microsoft.com/json-schemas/rush/v5/approved-packages.schema.json", - "packages": [] + "packages": [ + { + "name": "minimist-string", + "allowedCategories": [ "libraries" ] + }, + { + "name": "string-argv", + "allowedCategories": [ "libraries" ] + } + ] } diff --git a/common/config/rush/nonbrowser-approved-packages.json b/common/config/rush/nonbrowser-approved-packages.json index 043bab8e791..d163920d46d 100644 --- a/common/config/rush/nonbrowser-approved-packages.json +++ b/common/config/rush/nonbrowser-approved-packages.json @@ -26,7 +26,6 @@ "name": "@microsoft/api-extractor-model", "allowedCategories": [ "libraries" ] }, - { "name": "@microsoft/gulp-core-build", "allowedCategories": [ "libraries" ] diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index 9a6f5ecd70f..03d633d56b9 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -238,6 +238,7 @@ importers: resolve: 1.17.0 semver: 7.3.2 strict-uri-encode: 2.0.0 + string-argv: 0.3.1 tar: 5.0.5 true-case-path: 2.2.1 wordwrap: 1.0.0 @@ -315,6 +316,7 @@ importers: resolve: ~1.17.0 semver: ~7.3.0 strict-uri-encode: ~2.0.0 + string-argv: ^0.3.1 tar: ~5.0.5 true-case-path: ~2.2.1 wordwrap: ~1.0.0 @@ -11741,6 +11743,12 @@ packages: node: '>=4' resolution: integrity: sha1-ucczDHBChi9rFC3CdLvMWGbONUY= + /string-argv/0.3.1: + dev: false + engines: + node: '>=0.6.19' + resolution: + integrity: sha512-a1uQGz7IyVy9YwhqjZIZu1c8JO8dNIe20xBmSS6qu9kv++k3JGzCVmprbNN5Kn+BgzD5E7YYwg1CcjuJMRNsvg== /string-hash/1.1.3: dev: false resolution: diff --git a/common/config/rush/repo-state.json b/common/config/rush/repo-state.json index c3ee4a3d9a3..2ffa8773ef5 100644 --- a/common/config/rush/repo-state.json +++ b/common/config/rush/repo-state.json @@ -1,5 +1,5 @@ // DO NOT MODIFY THIS FILE. It is generated and used by Rush. { - "pnpmShrinkwrapHash": "8c870f5a94af8b340beb7dcdd3861915ca4544bc", + "pnpmShrinkwrapHash": "6957acc74d6d88a0dbe114947f15059ef12bda4d", "preferredVersionsHash": "334ea62b6a2798dcf80917b79555983377e7435e" } From 180c363601a3b310f6c4d9d17fe32504a6dceb27 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Sat, 1 Aug 2020 11:29:46 -0700 Subject: [PATCH 39/97] Change the dependency specifier to ~ --- apps/rush-lib/package.json | 2 +- common/config/rush/pnpm-lock.yaml | 2 +- common/config/rush/repo-state.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/rush-lib/package.json b/apps/rush-lib/package.json index aee4341b879..3850cc292b7 100644 --- a/apps/rush-lib/package.json +++ b/apps/rush-lib/package.json @@ -44,7 +44,7 @@ "resolve": "~1.17.0", "semver": "~7.3.0", "strict-uri-encode": "~2.0.0", - "string-argv": "^0.3.1", + "string-argv": "~0.3.1", "tar": "~5.0.5", "true-case-path": "~2.2.1", "wordwrap": "~1.0.0", diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index 03d633d56b9..e75785ed537 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -316,7 +316,7 @@ importers: resolve: ~1.17.0 semver: ~7.3.0 strict-uri-encode: ~2.0.0 - string-argv: ^0.3.1 + string-argv: ~0.3.1 tar: ~5.0.5 true-case-path: ~2.2.1 wordwrap: ~1.0.0 diff --git a/common/config/rush/repo-state.json b/common/config/rush/repo-state.json index 2ffa8773ef5..9645b1e1f5d 100644 --- a/common/config/rush/repo-state.json +++ b/common/config/rush/repo-state.json @@ -1,5 +1,5 @@ // DO NOT MODIFY THIS FILE. It is generated and used by Rush. { - "pnpmShrinkwrapHash": "6957acc74d6d88a0dbe114947f15059ef12bda4d", + "pnpmShrinkwrapHash": "932a5731d43fd1b56baa34be6f4ced6a2fb99114", "preferredVersionsHash": "334ea62b6a2798dcf80917b79555983377e7435e" } From 819189fac589a61ffece4ce56ba7f5047e4e1cd7 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Sat, 1 Aug 2020 15:06:30 -0700 Subject: [PATCH 40/97] Rush change --- ...seph-rush-shell-tab-complete_2020-08-01-22-06.json | 11 +++++++++++ ...seph-rush-shell-tab-complete_2020-08-01-22-06.json | 11 +++++++++++ ...seph-rush-shell-tab-complete_2020-08-01-22-06.json | 11 +++++++++++ .../src/providers/CommandLineAction.ts | 2 +- 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 common/changes/@microsoft/rush/sachinjoseph-rush-shell-tab-complete_2020-08-01-22-06.json create mode 100644 common/changes/@rushstack/node-core-library/sachinjoseph-rush-shell-tab-complete_2020-08-01-22-06.json create mode 100644 common/changes/@rushstack/ts-command-line/sachinjoseph-rush-shell-tab-complete_2020-08-01-22-06.json diff --git a/common/changes/@microsoft/rush/sachinjoseph-rush-shell-tab-complete_2020-08-01-22-06.json b/common/changes/@microsoft/rush/sachinjoseph-rush-shell-tab-complete_2020-08-01-22-06.json new file mode 100644 index 00000000000..7ff8cf80349 --- /dev/null +++ b/common/changes/@microsoft/rush/sachinjoseph-rush-shell-tab-complete_2020-08-01-22-06.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "packageName": "@microsoft/rush", + "comment": "", + "type": "none" + } + ], + "packageName": "@microsoft/rush", + "email": "sachinjoseph@users.noreply.github.com" +} \ No newline at end of file diff --git a/common/changes/@rushstack/node-core-library/sachinjoseph-rush-shell-tab-complete_2020-08-01-22-06.json b/common/changes/@rushstack/node-core-library/sachinjoseph-rush-shell-tab-complete_2020-08-01-22-06.json new file mode 100644 index 00000000000..162425000f8 --- /dev/null +++ b/common/changes/@rushstack/node-core-library/sachinjoseph-rush-shell-tab-complete_2020-08-01-22-06.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "packageName": "@rushstack/node-core-library", + "comment": "Lazy-import some packages to improve spin up times.", + "type": "patch" + } + ], + "packageName": "@rushstack/node-core-library", + "email": "sachinjoseph@users.noreply.github.com" +} \ No newline at end of file diff --git a/common/changes/@rushstack/ts-command-line/sachinjoseph-rush-shell-tab-complete_2020-08-01-22-06.json b/common/changes/@rushstack/ts-command-line/sachinjoseph-rush-shell-tab-complete_2020-08-01-22-06.json new file mode 100644 index 00000000000..48aafc0a599 --- /dev/null +++ b/common/changes/@rushstack/ts-command-line/sachinjoseph-rush-shell-tab-complete_2020-08-01-22-06.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "packageName": "@rushstack/ts-command-line", + "comment": "Create a lighter weight function to get own package version.", + "type": "minor" + } + ], + "packageName": "@rushstack/ts-command-line", + "email": "sachinjoseph@users.noreply.github.com" +} \ No newline at end of file diff --git a/libraries/ts-command-line/src/providers/CommandLineAction.ts b/libraries/ts-command-line/src/providers/CommandLineAction.ts index 0fa094c7f64..a0bd8deb4d9 100644 --- a/libraries/ts-command-line/src/providers/CommandLineAction.ts +++ b/libraries/ts-command-line/src/providers/CommandLineAction.ts @@ -1,8 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import { CommandLineParameterProvider, ICommandLineParserData } from './CommandLineParameterProvider'; import * as argparse from 'argparse'; +import { CommandLineParameterProvider, ICommandLineParserData } from './CommandLineParameterProvider'; /** * Options for the CommandLineAction constructor. From 7d050936f9ddff89e8fd90f5001006a6af4a6a8f Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Sat, 1 Aug 2020 15:09:07 -0700 Subject: [PATCH 41/97] Remove trace logs --- apps/rush-lib/src/start.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/apps/rush-lib/src/start.ts b/apps/rush-lib/src/start.ts index ad8526ee613..1abfb211ea0 100644 --- a/apps/rush-lib/src/start.ts +++ b/apps/rush-lib/src/start.ts @@ -1,7 +1,5 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -console.log('start.ts: 1: ' + (new Date().getTime() % 20000) / 1000.0); import { Rush } from './api/Rush'; Rush.launch(Rush.version, { isManaged: false }); -console.log('start.ts: 2: ' + (new Date().getTime() % 20000) / 1000.0); From f6415c91fe4f7505aed2fdfe501d3c14745f3606 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Sat, 1 Aug 2020 21:03:01 -0700 Subject: [PATCH 42/97] Remove commented-out code. --- apps/rush-lib/src/cli/actions/TabCompleteAction.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts index 63a92c9b0fc..cdbb224db0f 100644 --- a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts +++ b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts @@ -196,6 +196,3 @@ export class TabCompleteAction extends BaseRushAction { } } } -// function isWhiteSpaceStrict(ch: string | undefined) { -// return ch && ch.length > 0 && ch.trim() === ''; -// } From 5422f4df7fb41a5bb0432fdcebdf24ae59772eb9 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Sun, 2 Aug 2020 01:29:50 -0700 Subject: [PATCH 43/97] Get choice values from CommandLineChoiceParameter object. --- .../src/cli/actions/TabCompleteAction.ts | 96 +++++++++++-------- .../actions/test/TabCompleteAction.test.ts | 49 +++++++++- 2 files changed, 103 insertions(+), 42 deletions(-) diff --git a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts index cdbb224db0f..eb7c030de0f 100644 --- a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts +++ b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts @@ -8,14 +8,11 @@ import stringArgv from 'string-argv'; import { CommandLineStringParameter, CommandLineIntegerParameter, - CommandLineParameterKind + CommandLineChoiceParameter, + CommandLineParameterKind, + CommandLineParameter } from '@rushstack/ts-command-line'; -interface IParameter { - name: string; - kind: CommandLineParameterKind; -} - const DEFAULT_WORD_TO_AUTOCOMPLETE: string = ''; const DEFAULT_POSITION: number = 0; @@ -59,16 +56,23 @@ export class TabCompleteAction extends BaseRushAction { } public *getCompletions(commandLine: string, caretPosition: number): IterableIterator { - const actions: Map = new Map(); + const actions: Map> = new Map< + string, + Map + >(); + this.parser.actions.forEach((element) => { - const actionParameters: IParameter[] = []; + const parameterNameToParameterInfoMap: Map = new Map< + string, + CommandLineParameter + >(); element.parameters.forEach((elem) => { - actionParameters.push({ name: elem.longName, kind: elem.kind }); + parameterNameToParameterInfoMap[elem.longName] = elem; if (elem.shortName) { - actionParameters.push({ name: elem.shortName, kind: elem.kind }); + parameterNameToParameterInfoMap[elem.shortName] = elem; } }); - actions[element.actionName] = actionParameters; + actions[element.actionName] = parameterNameToParameterInfoMap; }); actions['-d'] = []; @@ -113,44 +117,54 @@ export class TabCompleteAction extends BaseRushAction { choiceParameterValues.push(project.packageName); } - yield* this._getChoiceParameterValues( - choiceParameter, - choiceParameterValues, - lastToken, - secondLastToken, - completePartialWord + const projectNamesToReturn: string[] = Array.from( + this._getChoiceParameterValues( + choiceParameter, + choiceParameterValues, + lastToken, + secondLastToken, + completePartialWord + ) ); + if (projectNamesToReturn.length > 0) { + yield* projectNamesToReturn; + return; + } + // TODO: Add support for version policy, variant - } else if (actionName === 'change') { - const choiceParameter: string[] = ['--bump-type']; - const choiceParameterValues: string[] = ['major', 'minor', 'patch', 'none']; - yield* this._getChoiceParameterValues( - choiceParameter, - choiceParameterValues, - lastToken, - secondLastToken, - completePartialWord - ); - } else if (actionName === 'publish') { - const choiceParameter: string[] = ['--set-access-level']; - const choiceParameterValues: string[] = ['public', 'restricted']; - yield* this._getChoiceParameterValues( - choiceParameter, - choiceParameterValues, - lastToken, - secondLastToken, - completePartialWord - ); } - - const parameterNames: string[] = Array.from(actions[actionName], (x: IParameter) => x.name); + const parameterNameMap: Map = actions[actionName]; + + const parameterNames: string[] = Array.from(Object.keys(actions[actionName]), (x: string) => x); + + for (const parameter of parameterNames) { + if (parameterNameMap[parameter].kind === CommandLineParameterKind.Choice) { + const choiceParameterValues: string[] = (parameterNameMap[ + parameter + ] as CommandLineChoiceParameter).alternatives as string[]; + if (completePartialWord) { + if (parameter === secondLastToken) { + yield* this._completeChoiceParameterValues(choiceParameterValues, lastToken); + return; + } + } else { + if (parameter === lastToken) { + yield* choiceParameterValues; + return; + } + } + } + } if (completePartialWord) { yield* this._completeChoiceParameterValues(parameterNames, lastToken); } else { - for (const parameter of actions[actionName]) { - if (parameter.name === lastToken && parameter.kind !== CommandLineParameterKind.Flag) { + for (const parameter of parameterNames) { + if ( + parameter === lastToken && + parameterNameMap[parameter].kind !== CommandLineParameterKind.Flag + ) { // The parameter is expecting a value, so don't suggest parameter names again return; } diff --git a/apps/rush-lib/src/cli/actions/test/TabCompleteAction.test.ts b/apps/rush-lib/src/cli/actions/test/TabCompleteAction.test.ts index a19f3693aae..fdc2e172aab 100644 --- a/apps/rush-lib/src/cli/actions/test/TabCompleteAction.test.ts +++ b/apps/rush-lib/src/cli/actions/test/TabCompleteAction.test.ts @@ -46,6 +46,8 @@ describe('TabCompleteAction', () => { const commandLine: string = 'rush'; const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); + console.log('tab-complete --word "' + commandLine.trim() + '" --position ' + commandLine.length); + console.log(actual); expect(actual.indexOf('add') !== -1).toBe(true); expect(actual.indexOf('check') !== -1).toBe(true); @@ -68,6 +70,8 @@ describe('TabCompleteAction', () => { const commandLine: string = 'rush a'; const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); + console.log('tab-complete --word "' + commandLine.trim() + '" --position ' + commandLine.length); + console.log(actual); const expected: string[] = ['add']; @@ -86,6 +90,8 @@ describe('TabCompleteAction', () => { const commandLine: string = 'rush build '; const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); + console.log('tab-complete --word "' + commandLine.trim() + '" --position ' + commandLine.length); + console.log(actual); expect(actual.indexOf('-t') !== -1).toBe(true); expect(actual.indexOf('--to') !== -1).toBe(true); @@ -105,6 +111,8 @@ describe('TabCompleteAction', () => { const commandLine: string = 'rush build -'; const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); + console.log('tab-complete --word "' + commandLine.trim() + '" --position ' + commandLine.length); + console.log(actual); expect(actual.indexOf('-t') !== -1).toBe(true); expect(actual.indexOf('--to') !== -1).toBe(true); @@ -124,13 +132,15 @@ describe('TabCompleteAction', () => { const commandLine: string = 'rush build -t '; const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); + console.log('tab-complete --word "' + commandLine.trim() + '" --position ' + commandLine.length); + console.log(actual); const expected: string[] = ['abc', 'def']; expect(arrayEqual(actual, expected)).toBe(true); }); - it(`gets completion(s) for rush build -t a`, () => { + it(`gets completion(s) for rush build -t a`, () => { const startPath: string = path.resolve(__dirname, 'tabComplete'); // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test @@ -142,6 +152,8 @@ describe('TabCompleteAction', () => { const commandLine: string = 'rush build -t a'; const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); + console.log('tab-complete --word "' + commandLine.trim() + '" --position ' + commandLine.length); + console.log(actual); const expected: string[] = ['abc']; @@ -160,11 +172,35 @@ describe('TabCompleteAction', () => { const commandLine: string = 'rush change --bump-type '; const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); + console.log('tab-complete --word "' + commandLine.trim() + '" --position ' + commandLine.length); + console.log(actual); + const expected: string[] = ['major', 'minor', 'patch', 'none']; expect(arrayEqual(actual, expected)).toBe(true); }); + it(`gets completion(s) for rush change --bulk `, () => { + const startPath: string = path.resolve(__dirname, 'tabComplete'); + // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit + // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test + // repo will fail due to contention over the same lock which is kept until the test runner process + // ends. + jest.spyOn(process, 'cwd').mockReturnValue(startPath); + const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); + const tc: TabCompleteAction = new TabCompleteAction(parser); + + const commandLine: string = 'rush change --bulk '; + const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); + console.log('tab-complete --word "' + commandLine.trim() + '" --position ' + commandLine.length); + console.log(actual); + + expect(actual.indexOf('--bulk') !== -1).toBe(true); + expect(actual.indexOf('--message') !== -1).toBe(true); + expect(actual.indexOf('--bump-type') !== -1).toBe(true); + expect(actual.indexOf('--verify') !== -1).toBe(true); + }); + it(`gets completion(s) for rush change --bump-type m`, () => { const startPath: string = path.resolve(__dirname, 'tabComplete'); // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit @@ -177,6 +213,9 @@ describe('TabCompleteAction', () => { const commandLine: string = 'rush change --bump-type m'; const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); + console.log('tab-complete --word "' + commandLine.trim() + '" --position ' + commandLine.length); + console.log(actual); + const expected: string[] = ['major', 'minor']; expect(arrayEqual(actual, expected)).toBe(true); @@ -194,6 +233,8 @@ describe('TabCompleteAction', () => { const commandLine: string = 'rush change --message '; const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); + console.log('tab-complete --word "' + commandLine.trim() + '" --position ' + commandLine.length); + console.log(actual); const expected: string[] = []; @@ -212,6 +253,8 @@ describe('TabCompleteAction', () => { const commandLine: string = 'rush change --message "my change log message" --bump-type '; const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); + console.log('tab-complete --word "' + commandLine.trim() + '" --position ' + commandLine.length); + console.log(actual); const expected: string[] = ['major', 'minor', 'patch', 'none']; @@ -230,6 +273,8 @@ describe('TabCompleteAction', () => { const commandLine: string = 'rush change --message "my change log message" --bump-type m'; const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); + console.log('tab-complete --word "' + commandLine.trim() + '" --position ' + commandLine.length); + console.log(actual); const expected: string[] = ['major', 'minor']; @@ -250,6 +295,7 @@ describe('TabCompleteAction', () => { const commandLine: string = 'rush change -'; const actual: string[] = Array.from(tc.tokenizeCommandLine(commandLine.trim())); + console.log('tab-complete --word "' + commandLine.trim() + '" --position ' + commandLine.length); console.log(actual); const expected: string[] = ['rush', 'change', '-']; @@ -268,6 +314,7 @@ describe('TabCompleteAction', () => { const commandLine: string = 'rush change -m "my change log"'; const actual: string[] = Array.from(tc.tokenizeCommandLine(commandLine.trim())); + console.log('tab-complete --word "' + commandLine.trim() + '" --position ' + commandLine.length); console.log(actual); const expected: string[] = ['rush', 'change', '-m', 'my change log']; From b15d4e98b402d929225e3aa1e05ef82c701a7b04 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Sun, 2 Aug 2020 01:31:46 -0700 Subject: [PATCH 44/97] Remove test logs --- .../actions/test/TabCompleteAction.test.ts | 28 ------------------- 1 file changed, 28 deletions(-) diff --git a/apps/rush-lib/src/cli/actions/test/TabCompleteAction.test.ts b/apps/rush-lib/src/cli/actions/test/TabCompleteAction.test.ts index fdc2e172aab..f253faec30c 100644 --- a/apps/rush-lib/src/cli/actions/test/TabCompleteAction.test.ts +++ b/apps/rush-lib/src/cli/actions/test/TabCompleteAction.test.ts @@ -46,8 +46,6 @@ describe('TabCompleteAction', () => { const commandLine: string = 'rush'; const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); - console.log('tab-complete --word "' + commandLine.trim() + '" --position ' + commandLine.length); - console.log(actual); expect(actual.indexOf('add') !== -1).toBe(true); expect(actual.indexOf('check') !== -1).toBe(true); @@ -70,8 +68,6 @@ describe('TabCompleteAction', () => { const commandLine: string = 'rush a'; const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); - console.log('tab-complete --word "' + commandLine.trim() + '" --position ' + commandLine.length); - console.log(actual); const expected: string[] = ['add']; @@ -90,8 +86,6 @@ describe('TabCompleteAction', () => { const commandLine: string = 'rush build '; const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); - console.log('tab-complete --word "' + commandLine.trim() + '" --position ' + commandLine.length); - console.log(actual); expect(actual.indexOf('-t') !== -1).toBe(true); expect(actual.indexOf('--to') !== -1).toBe(true); @@ -111,8 +105,6 @@ describe('TabCompleteAction', () => { const commandLine: string = 'rush build -'; const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); - console.log('tab-complete --word "' + commandLine.trim() + '" --position ' + commandLine.length); - console.log(actual); expect(actual.indexOf('-t') !== -1).toBe(true); expect(actual.indexOf('--to') !== -1).toBe(true); @@ -132,8 +124,6 @@ describe('TabCompleteAction', () => { const commandLine: string = 'rush build -t '; const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); - console.log('tab-complete --word "' + commandLine.trim() + '" --position ' + commandLine.length); - console.log(actual); const expected: string[] = ['abc', 'def']; @@ -152,8 +142,6 @@ describe('TabCompleteAction', () => { const commandLine: string = 'rush build -t a'; const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); - console.log('tab-complete --word "' + commandLine.trim() + '" --position ' + commandLine.length); - console.log(actual); const expected: string[] = ['abc']; @@ -172,8 +160,6 @@ describe('TabCompleteAction', () => { const commandLine: string = 'rush change --bump-type '; const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); - console.log('tab-complete --word "' + commandLine.trim() + '" --position ' + commandLine.length); - console.log(actual); const expected: string[] = ['major', 'minor', 'patch', 'none']; @@ -192,8 +178,6 @@ describe('TabCompleteAction', () => { const commandLine: string = 'rush change --bulk '; const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); - console.log('tab-complete --word "' + commandLine.trim() + '" --position ' + commandLine.length); - console.log(actual); expect(actual.indexOf('--bulk') !== -1).toBe(true); expect(actual.indexOf('--message') !== -1).toBe(true); @@ -213,8 +197,6 @@ describe('TabCompleteAction', () => { const commandLine: string = 'rush change --bump-type m'; const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); - console.log('tab-complete --word "' + commandLine.trim() + '" --position ' + commandLine.length); - console.log(actual); const expected: string[] = ['major', 'minor']; @@ -233,8 +215,6 @@ describe('TabCompleteAction', () => { const commandLine: string = 'rush change --message '; const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); - console.log('tab-complete --word "' + commandLine.trim() + '" --position ' + commandLine.length); - console.log(actual); const expected: string[] = []; @@ -253,8 +233,6 @@ describe('TabCompleteAction', () => { const commandLine: string = 'rush change --message "my change log message" --bump-type '; const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); - console.log('tab-complete --word "' + commandLine.trim() + '" --position ' + commandLine.length); - console.log(actual); const expected: string[] = ['major', 'minor', 'patch', 'none']; @@ -273,8 +251,6 @@ describe('TabCompleteAction', () => { const commandLine: string = 'rush change --message "my change log message" --bump-type m'; const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); - console.log('tab-complete --word "' + commandLine.trim() + '" --position ' + commandLine.length); - console.log(actual); const expected: string[] = ['major', 'minor']; @@ -295,8 +271,6 @@ describe('TabCompleteAction', () => { const commandLine: string = 'rush change -'; const actual: string[] = Array.from(tc.tokenizeCommandLine(commandLine.trim())); - console.log('tab-complete --word "' + commandLine.trim() + '" --position ' + commandLine.length); - console.log(actual); const expected: string[] = ['rush', 'change', '-']; @@ -314,8 +288,6 @@ describe('TabCompleteAction', () => { const commandLine: string = 'rush change -m "my change log"'; const actual: string[] = Array.from(tc.tokenizeCommandLine(commandLine.trim())); - console.log('tab-complete --word "' + commandLine.trim() + '" --position ' + commandLine.length); - console.log(actual); const expected: string[] = ['rush', 'change', '-m', 'my change log']; From c09564f8d1b65f3eb0ee1949f4eca05c31238ac3 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Sun, 2 Aug 2020 01:39:48 -0700 Subject: [PATCH 45/97] Initial commit: Move tab-completion to ts-command-line --- .../rush-lib/src/cli/RushCommandLineParser.ts | 3 +- common/config/rush/pnpm-lock.yaml | 2 + common/config/rush/repo-state.json | 2 +- common/reviews/api/ts-command-line.api.md | 3 +- libraries/ts-command-line/package.json | 3 +- .../src/providers/CommandLineParser.ts | 15 +- .../src/providers/TabCompletionAction.ts | 210 ++++++++++++++++++ 7 files changed, 227 insertions(+), 11 deletions(-) create mode 100644 libraries/ts-command-line/src/providers/TabCompletionAction.ts diff --git a/apps/rush-lib/src/cli/RushCommandLineParser.ts b/apps/rush-lib/src/cli/RushCommandLineParser.ts index 12a5b703fc0..783b8f365db 100644 --- a/apps/rush-lib/src/cli/RushCommandLineParser.ts +++ b/apps/rush-lib/src/cli/RushCommandLineParser.ts @@ -69,7 +69,8 @@ export class RushCommandLineParser extends CommandLineParser { ' and automates package publishing. It can manage decoupled subsets of projects with different' + ' release and versioning strategies. A full API is included to facilitate integration with other' + ' automation tools. If you are looking for a proven turnkey solution for monorepo management,' + - ' Rush is for you.' + ' Rush is for you.', + enableTabCompletionAction: true }); this._rushOptions = this._normalizeOptions(options || {}); diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index e75785ed537..be71d335d0f 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -1338,6 +1338,7 @@ importers: '@types/argparse': 1.0.38 argparse: 1.0.10 colors: 1.2.5 + string-argv: 0.3.1 devDependencies: '@microsoft/node-library-build': 6.4.31 '@microsoft/rush-stack-compiler-3.5': 0.8.0 @@ -1355,6 +1356,7 @@ importers: argparse: ~1.0.9 colors: ~1.2.1 gulp: ~4.0.2 + string-argv: ~0.3.1 ../../libraries/typings-generator: dependencies: '@rushstack/node-core-library': 'link:../node-core-library' diff --git a/common/config/rush/repo-state.json b/common/config/rush/repo-state.json index 9645b1e1f5d..92d87600a26 100644 --- a/common/config/rush/repo-state.json +++ b/common/config/rush/repo-state.json @@ -1,5 +1,5 @@ // DO NOT MODIFY THIS FILE. It is generated and used by Rush. { - "pnpmShrinkwrapHash": "932a5731d43fd1b56baa34be6f4ced6a2fb99114", + "pnpmShrinkwrapHash": "24bd6ece2a2ef9f037e9364b856cf0bf1af6d3d8", "preferredVersionsHash": "334ea62b6a2798dcf80917b79555983377e7435e" } diff --git a/common/reviews/api/ts-command-line.api.md b/common/reviews/api/ts-command-line.api.md index d6a4f4684aa..3164b2a331b 100644 --- a/common/reviews/api/ts-command-line.api.md +++ b/common/reviews/api/ts-command-line.api.md @@ -142,8 +142,6 @@ export abstract class CommandLineParser extends CommandLineParameterProvider { protected _getArgumentParser(): argparse.ArgumentParser; protected onExecute(): Promise; selectedAction: CommandLineAction | undefined; - readonly toolDescription: string; - readonly toolFilename: string; tryGetAction(actionName: string): CommandLineAction | undefined; } @@ -246,6 +244,7 @@ export interface _ICommandLineParserData { // @public export interface ICommandLineParserOptions { + enableTabCompletionAction?: boolean; toolDescription: string; toolFilename: string; } diff --git a/libraries/ts-command-line/package.json b/libraries/ts-command-line/package.json index f14b2f3b142..d95d7091f3c 100644 --- a/libraries/ts-command-line/package.json +++ b/libraries/ts-command-line/package.json @@ -15,7 +15,8 @@ "dependencies": { "@types/argparse": "1.0.38", "argparse": "~1.0.9", - "colors": "~1.2.1" + "colors": "~1.2.1", + "string-argv": "~0.3.1" }, "devDependencies": { "@types/jest": "25.2.1", diff --git a/libraries/ts-command-line/src/providers/CommandLineParser.ts b/libraries/ts-command-line/src/providers/CommandLineParser.ts index bc388efbef4..5a730cc83e4 100644 --- a/libraries/ts-command-line/src/providers/CommandLineParser.ts +++ b/libraries/ts-command-line/src/providers/CommandLineParser.ts @@ -7,6 +7,7 @@ import * as colors from 'colors'; import { CommandLineAction } from './CommandLineAction'; import { CommandLineParameterProvider, ICommandLineParserData } from './CommandLineParameterProvider'; import { CommandLineParserExitError, CustomArgumentParser } from './CommandLineParserExitError'; +import { TabCompleteAction } from './TabCompletionAction'; /** * Options for the {@link CommandLineParser} constructor. @@ -22,6 +23,11 @@ export interface ICommandLineParserOptions { * General documentation that is included in the "--help" main page */ toolDescription: string; + + /** + * Set to true to auto-define a tab completion action. False by default. + */ + enableTabCompletionAction?: boolean; } /** @@ -35,12 +41,6 @@ export interface ICommandLineParserOptions { * @public */ export abstract class CommandLineParser extends CommandLineParameterProvider { - /** {@inheritDoc ICommandLineParserOptions.toolFilename} */ - public readonly toolFilename: string; - - /** {@inheritDoc ICommandLineParserOptions.toolDescription} */ - public readonly toolDescription: string; - /** * Reports which CommandLineAction was specified on the command line. * @remarks @@ -135,6 +135,9 @@ export abstract class CommandLineParser extends CommandLineParameterProvider { * the process.argv will be used */ public execute(args?: string[]): Promise { + if (this._options.enableTabCompletionAction) { + this.addAction(new TabCompleteAction(this._actionsByName)); + } return this.executeWithoutErrorHandling(args) .then(() => { return true; diff --git a/libraries/ts-command-line/src/providers/TabCompletionAction.ts b/libraries/ts-command-line/src/providers/TabCompletionAction.ts new file mode 100644 index 00000000000..966c8fea55a --- /dev/null +++ b/libraries/ts-command-line/src/providers/TabCompletionAction.ts @@ -0,0 +1,210 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. +// See LICENSE in the project root for license information. + +// import { BaseRushAction } from './BaseRushAction'; +// import { CommandLineParser } from './CommandLineParser'; +import stringArgv from 'string-argv'; + +import { CommandLineIntegerParameter } from '../parameters/CommandLineIntegerParameter'; +import { CommandLineStringParameter } from '../parameters/CommandLineStringParameter'; +import { CommandLineParameterKind, CommandLineParameter } from '../parameters/BaseClasses'; +import { CommandLineAction } from './CommandLineAction'; + +interface IParameter { + name: string; + parameterInfo: CommandLineParameter; +} + +const DEFAULT_WORD_TO_AUTOCOMPLETE: string = ''; +const DEFAULT_POSITION: number = 0; + +export class TabCompleteAction extends CommandLineAction { + private _wordToCompleteParameter: CommandLineStringParameter; + private _positionParameter: CommandLineIntegerParameter; + private _actionsByName: Map; + + public constructor(actionsByName: Map) { + super({ + actionName: 'tab-complete2', + summary: 'Provides tab completion.', + documentation: 'Provides tab completion.' + }); + + this._actionsByName = actionsByName; + } + + protected onDefineParameters(): void { + this._wordToCompleteParameter = this.defineStringParameter({ + parameterLongName: '--word', + argumentName: 'WORD', + description: `The word to complete.`, + defaultValue: DEFAULT_WORD_TO_AUTOCOMPLETE + }); + + this._positionParameter = this.defineIntegerParameter({ + parameterLongName: '--position', + argumentName: 'INDEX', + description: `The position in the word to be completed.`, + defaultValue: DEFAULT_POSITION + }); + } + + protected async onExecute(): Promise { + await this.runAsync(); + } + + protected async runAsync(): Promise { + const commandLine: string = this._wordToCompleteParameter.value || ''; + const caretPosition: number = this._positionParameter.value || 0; + + for (const value of this.getCompletions(commandLine, caretPosition)) { + console.log(value); + } + } + + public *getCompletions(commandLine: string, caretPosition: number): IterableIterator { + const actions: Map> = new Map< + string, + Map + >(); + for (const [key, value] of this._actionsByName.entries()) { + const parameterNameToParameterInfoMap: IParameter[] = []; + value.parameters.forEach((elem) => { + parameterNameToParameterInfoMap[elem.longName] = elem; + if (elem.shortName) { + parameterNameToParameterInfoMap[elem.shortName] = elem; + } + }); + actions[key] = parameterNameToParameterInfoMap; + } + + actions['-d'] = []; + actions['--debug'] = []; + actions['-h'] = []; + actions['--help'] = []; + + if (!commandLine || !caretPosition) { + yield* Object.keys(actions); // return all actions + return; + } + + const tokens: string[] = Array.from(this.tokenizeCommandLine(commandLine)); + + const debugParameterUsed: boolean = tokens.length > 1 && (tokens[1] === '-d' || tokens[1] === '--debug'); + const debugParameterOffset: number = debugParameterUsed ? 1 : 0; // if debug switch is used, then offset everything by 1. + + if (tokens.length < 2 + debugParameterOffset) { + yield* Object.keys(actions); // return all actions + return; + } + + const lastToken: string = tokens[tokens.length - 1]; + const secondLastToken: string = tokens[tokens.length - 2]; + + const completePartialWord: boolean = caretPosition === commandLine.length; + + if (completePartialWord && tokens.length === 2 + debugParameterOffset) { + for (const actionName of Object.keys(actions)) { + if (actionName.indexOf(tokens[1 + debugParameterOffset]) === 0) { + yield actionName; + } + } + } else { + for (const actionName of Object.keys(actions)) { + if (actionName === tokens[1 + debugParameterOffset]) { + if (actionName === 'build' || actionName === 'rebuild') { + const choiceParameter: string[] = ['-f', '--from', '-t', '--to']; + const choiceParameterValues: string[] = []; + + // TODO: Provide a way to supply custom parameter values + // for (const project of this.rushConfiguration.projects) { + // choiceParameterValues.push(project.packageName); + // } + + choiceParameterValues.push('abc'); + choiceParameterValues.push('def'); + choiceParameterValues.push('hij'); + + yield* this._getChoiceParameterValues( + choiceParameter, + choiceParameterValues, + lastToken, + secondLastToken, + completePartialWord + ); + + // TODO: Add support for version policy, variant + } else if (actionName === 'change') { + const choiceParameter: string[] = ['--bump-type']; + const choiceParameterValues: string[] = ['major', 'minor', 'patch', 'none']; + yield* this._getChoiceParameterValues( + choiceParameter, + choiceParameterValues, + lastToken, + secondLastToken, + completePartialWord + ); + } else if (actionName === 'publish') { + const choiceParameter: string[] = ['--set-access-level']; + const choiceParameterValues: string[] = ['public', 'restricted']; + yield* this._getChoiceParameterValues( + choiceParameter, + choiceParameterValues, + lastToken, + secondLastToken, + completePartialWord + ); + } + + const parameterNames: string[] = Array.from(actions[actionName], (x: IParameter) => x.name); + + if (completePartialWord) { + yield* this._completeChoiceParameterValues(parameterNames, lastToken); + } else { + for (const parameter of actions[actionName]) { + if (parameter.name === lastToken && parameter.kind !== CommandLineParameterKind.Flag) { + // The parameter is expecting a value, so don't suggest parameter names again + return; + } + } + + yield* parameterNames; + } + } + } + } + } + + public tokenizeCommandLine(commandLine: string): string[] { + return stringArgv(commandLine); + } + + private *_getChoiceParameterValues( + choiceParameter: string[], + choiceParameterValues: string[], + lastToken: string, + secondLastToken: string, + completePartialWord: boolean + ): IterableIterator { + if (completePartialWord) { + if (choiceParameter.indexOf(secondLastToken) !== -1) { + yield* this._completeChoiceParameterValues(choiceParameterValues, lastToken); + } + } else { + if (choiceParameter.indexOf(lastToken) !== -1) { + yield* choiceParameterValues; + } + } + } + + private *_completeChoiceParameterValues( + choiceParameterValues: string[], + lastToken: string + ): IterableIterator { + for (const choiceParameterValue of choiceParameterValues) { + if (choiceParameterValue.indexOf(lastToken) === 0) { + yield choiceParameterValue; + } + } + } +} From 13c04fb4e61ac2a4ec4a1233af6ab8a40b1db9bf Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Sun, 2 Aug 2020 16:20:45 -0700 Subject: [PATCH 46/97] Move code entirely to ts-commandline. Implement a way to provide custom tab completion entries. Add more tests. --- .../rush-lib/src/cli/RushCommandLineParser.ts | 2 - .../src/cli/actions/TabCompleteAction.ts | 212 -------- .../actions/test/TabCompleteAction.test.ts | 297 ----------- .../src/cli/scriptActions/BulkScriptAction.ts | 11 +- .../CommandLineHelp.test.ts.snap | 14 - apps/rush-lib/src/utilities/Utilities.ts | 5 +- common/reviews/api/ts-command-line.api.md | 4 + .../src/parameters/BaseClasses.ts | 4 + .../src/parameters/CommandLineDefinition.ts | 5 + .../src/providers/CommandLineParser.ts | 2 +- .../src/providers/TabCompletionAction.ts | 156 +++--- .../src/test/TabCompleteAction.test.ts | 483 ++++++++++++++++++ 12 files changed, 583 insertions(+), 612 deletions(-) delete mode 100644 apps/rush-lib/src/cli/actions/TabCompleteAction.ts delete mode 100644 apps/rush-lib/src/cli/actions/test/TabCompleteAction.test.ts create mode 100644 libraries/ts-command-line/src/test/TabCompleteAction.test.ts diff --git a/apps/rush-lib/src/cli/RushCommandLineParser.ts b/apps/rush-lib/src/cli/RushCommandLineParser.ts index 783b8f365db..333799ebbc0 100644 --- a/apps/rush-lib/src/cli/RushCommandLineParser.ts +++ b/apps/rush-lib/src/cli/RushCommandLineParser.ts @@ -28,7 +28,6 @@ import { ListAction } from './actions/ListAction'; import { PublishAction } from './actions/PublishAction'; import { PurgeAction } from './actions/PurgeAction'; import { ScanAction } from './actions/ScanAction'; -import { TabCompleteAction } from './actions/TabCompleteAction'; import { UnlinkAction } from './actions/UnlinkAction'; import { UpdateAction } from './actions/UpdateAction'; import { UpdateAutoinstallerAction } from './actions/UpdateAutoinstallerAction'; @@ -176,7 +175,6 @@ export class RushCommandLineParser extends CommandLineParser { this.addAction(new PurgeAction(this)); this.addAction(new ScanAction(this)); this.addAction(new UnlinkAction(this)); - this.addAction(new TabCompleteAction(this)); this.addAction(new UpdateAction(this)); this.addAction(new UpdateAutoinstallerAction(this)); this.addAction(new VersionAction(this)); diff --git a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts b/apps/rush-lib/src/cli/actions/TabCompleteAction.ts deleted file mode 100644 index eb7c030de0f..00000000000 --- a/apps/rush-lib/src/cli/actions/TabCompleteAction.ts +++ /dev/null @@ -1,212 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. -// See LICENSE in the project root for license information. - -import { BaseRushAction } from './BaseRushAction'; -import { RushCommandLineParser } from '../RushCommandLineParser'; -import stringArgv from 'string-argv'; - -import { - CommandLineStringParameter, - CommandLineIntegerParameter, - CommandLineChoiceParameter, - CommandLineParameterKind, - CommandLineParameter -} from '@rushstack/ts-command-line'; - -const DEFAULT_WORD_TO_AUTOCOMPLETE: string = ''; -const DEFAULT_POSITION: number = 0; - -export class TabCompleteAction extends BaseRushAction { - private _wordToCompleteParameter: CommandLineStringParameter; - private _positionParameter: CommandLineIntegerParameter; - - public constructor(parser: RushCommandLineParser) { - super({ - actionName: 'tab-complete', - summary: 'Provides tab completion.', - documentation: 'Provides tab completion.', - parser, - safeForSimultaneousRushProcesses: true - }); - } - - protected onDefineParameters(): void { - this._wordToCompleteParameter = this.defineStringParameter({ - parameterLongName: '--word', - argumentName: 'WORD', - description: `The word to complete.`, - defaultValue: DEFAULT_WORD_TO_AUTOCOMPLETE - }); - - this._positionParameter = this.defineIntegerParameter({ - parameterLongName: '--position', - argumentName: 'INDEX', - description: `The position in the word to be completed.`, - defaultValue: DEFAULT_POSITION - }); - } - - protected async runAsync(): Promise { - const commandLine: string = this._wordToCompleteParameter.value || ''; - const caretPosition: number = this._positionParameter.value || 0; - - for (const value of this.getCompletions(commandLine, caretPosition)) { - console.log(value); - } - } - - public *getCompletions(commandLine: string, caretPosition: number): IterableIterator { - const actions: Map> = new Map< - string, - Map - >(); - - this.parser.actions.forEach((element) => { - const parameterNameToParameterInfoMap: Map = new Map< - string, - CommandLineParameter - >(); - element.parameters.forEach((elem) => { - parameterNameToParameterInfoMap[elem.longName] = elem; - if (elem.shortName) { - parameterNameToParameterInfoMap[elem.shortName] = elem; - } - }); - actions[element.actionName] = parameterNameToParameterInfoMap; - }); - - actions['-d'] = []; - actions['--debug'] = []; - actions['-h'] = []; - actions['--help'] = []; - - if (!commandLine || !caretPosition) { - yield* Object.keys(actions); // return all actions - return; - } - - const tokens: string[] = Array.from(this.tokenizeCommandLine(commandLine)); - - const debugParameterUsed: boolean = tokens.length > 1 && (tokens[1] === '-d' || tokens[1] === '--debug'); - const debugParameterOffset: number = debugParameterUsed ? 1 : 0; // if debug switch is used, then offset everything by 1. - - if (tokens.length < 2 + debugParameterOffset) { - yield* Object.keys(actions); // return all actions - return; - } - - const lastToken: string = tokens[tokens.length - 1]; - const secondLastToken: string = tokens[tokens.length - 2]; - - const completePartialWord: boolean = caretPosition === commandLine.length; - - if (completePartialWord && tokens.length === 2 + debugParameterOffset) { - for (const actionName of Object.keys(actions)) { - if (actionName.indexOf(tokens[1 + debugParameterOffset]) === 0) { - yield actionName; - } - } - } else { - for (const actionName of Object.keys(actions)) { - if (actionName === tokens[1 + debugParameterOffset]) { - if (actionName === 'build' || actionName === 'rebuild') { - const choiceParameter: string[] = ['-f', '--from', '-t', '--to']; - const choiceParameterValues: string[] = []; - - for (const project of this.rushConfiguration.projects) { - choiceParameterValues.push(project.packageName); - } - - const projectNamesToReturn: string[] = Array.from( - this._getChoiceParameterValues( - choiceParameter, - choiceParameterValues, - lastToken, - secondLastToken, - completePartialWord - ) - ); - - if (projectNamesToReturn.length > 0) { - yield* projectNamesToReturn; - return; - } - - // TODO: Add support for version policy, variant - } - const parameterNameMap: Map = actions[actionName]; - - const parameterNames: string[] = Array.from(Object.keys(actions[actionName]), (x: string) => x); - - for (const parameter of parameterNames) { - if (parameterNameMap[parameter].kind === CommandLineParameterKind.Choice) { - const choiceParameterValues: string[] = (parameterNameMap[ - parameter - ] as CommandLineChoiceParameter).alternatives as string[]; - if (completePartialWord) { - if (parameter === secondLastToken) { - yield* this._completeChoiceParameterValues(choiceParameterValues, lastToken); - return; - } - } else { - if (parameter === lastToken) { - yield* choiceParameterValues; - return; - } - } - } - } - - if (completePartialWord) { - yield* this._completeChoiceParameterValues(parameterNames, lastToken); - } else { - for (const parameter of parameterNames) { - if ( - parameter === lastToken && - parameterNameMap[parameter].kind !== CommandLineParameterKind.Flag - ) { - // The parameter is expecting a value, so don't suggest parameter names again - return; - } - } - - yield* parameterNames; - } - } - } - } - } - - public tokenizeCommandLine(commandLine: string): string[] { - return stringArgv(commandLine); - } - - private *_getChoiceParameterValues( - choiceParameter: string[], - choiceParameterValues: string[], - lastToken: string, - secondLastToken: string, - completePartialWord: boolean - ): IterableIterator { - if (completePartialWord) { - if (choiceParameter.indexOf(secondLastToken) !== -1) { - yield* this._completeChoiceParameterValues(choiceParameterValues, lastToken); - } - } else { - if (choiceParameter.indexOf(lastToken) !== -1) { - yield* choiceParameterValues; - } - } - } - - private *_completeChoiceParameterValues( - choiceParameterValues: string[], - lastToken: string - ): IterableIterator { - for (const choiceParameterValue of choiceParameterValues) { - if (choiceParameterValue.indexOf(lastToken) === 0) { - yield choiceParameterValue; - } - } - } -} diff --git a/apps/rush-lib/src/cli/actions/test/TabCompleteAction.test.ts b/apps/rush-lib/src/cli/actions/test/TabCompleteAction.test.ts deleted file mode 100644 index f253faec30c..00000000000 --- a/apps/rush-lib/src/cli/actions/test/TabCompleteAction.test.ts +++ /dev/null @@ -1,297 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. -// See LICENSE in the project root for license information. - -import '../../test/mockRushCommandLineParser'; - -import * as path from 'path'; - -import { TabCompleteAction } from '../TabCompleteAction'; -import { RushCommandLineParser } from '../../RushCommandLineParser'; - -function arrayEqual(actual: string[], expected: string[]): boolean { - return ( - actual.length === expected.length && - actual.sort().every((v: string, i: number) => { - return v === expected.sort()[i]; - }) - ); -} - -describe('TabCompleteAction', () => { - let oldExitCode: number | undefined; - let oldArgs: string[]; - - beforeEach(() => { - jest.spyOn(process, 'exit').mockImplementation(); - oldExitCode = process.exitCode; - oldArgs = process.argv; - }); - - afterEach(() => { - jest.clearAllMocks(); - process.exitCode = oldExitCode; - process.argv = oldArgs; - }); - - describe(`Get TabCompletions`, () => { - it(`gets completion(s) for rush `, () => { - const startPath: string = path.resolve(__dirname, 'tabComplete'); - // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit - // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test - // repo will fail due to contention over the same lock which is kept until the test runner process - // ends. - jest.spyOn(process, 'cwd').mockReturnValue(startPath); - const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); - const tc: TabCompleteAction = new TabCompleteAction(parser); - - const commandLine: string = 'rush'; - const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); - - expect(actual.indexOf('add') !== -1).toBe(true); - expect(actual.indexOf('check') !== -1).toBe(true); - expect(actual.indexOf('build') !== -1).toBe(true); - expect(actual.indexOf('rebuild') !== -1).toBe(true); - expect(actual.indexOf('-d') !== -1).toBe(true); - expect(actual.indexOf('--debug') !== -1).toBe(true); - expect(actual.indexOf('--help') !== -1).toBe(true); - }); - - it(`gets completion(s) for rush a`, () => { - const startPath: string = path.resolve(__dirname, 'tabComplete'); - // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit - // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test - // repo will fail due to contention over the same lock which is kept until the test runner process - // ends. - jest.spyOn(process, 'cwd').mockReturnValue(startPath); - const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); - const tc: TabCompleteAction = new TabCompleteAction(parser); - - const commandLine: string = 'rush a'; - const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); - - const expected: string[] = ['add']; - - expect(arrayEqual(actual, expected)).toBe(true); - }); - - it(`gets completion(s) for rush build `, () => { - const startPath: string = path.resolve(__dirname, 'tabComplete'); - // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit - // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test - // repo will fail due to contention over the same lock which is kept until the test runner process - // ends. - jest.spyOn(process, 'cwd').mockReturnValue(startPath); - const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); - const tc: TabCompleteAction = new TabCompleteAction(parser); - - const commandLine: string = 'rush build '; - const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); - - expect(actual.indexOf('-t') !== -1).toBe(true); - expect(actual.indexOf('--to') !== -1).toBe(true); - expect(actual.indexOf('-f') !== -1).toBe(true); - expect(actual.indexOf('--from') !== -1).toBe(true); - }); - - it(`gets completion(s) for rush build -`, () => { - const startPath: string = path.resolve(__dirname, 'tabComplete'); - // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit - // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test - // repo will fail due to contention over the same lock which is kept until the test runner process - // ends. - jest.spyOn(process, 'cwd').mockReturnValue(startPath); - const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); - const tc: TabCompleteAction = new TabCompleteAction(parser); - - const commandLine: string = 'rush build -'; - const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); - - expect(actual.indexOf('-t') !== -1).toBe(true); - expect(actual.indexOf('--to') !== -1).toBe(true); - expect(actual.indexOf('-f') !== -1).toBe(true); - expect(actual.indexOf('--from') !== -1).toBe(true); - }); - - it(`gets completion(s) for rush build -t `, () => { - const startPath: string = path.resolve(__dirname, 'tabComplete'); - // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit - // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test - // repo will fail due to contention over the same lock which is kept until the test runner process - // ends. - jest.spyOn(process, 'cwd').mockReturnValue(startPath); - const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); - const tc: TabCompleteAction = new TabCompleteAction(parser); - - const commandLine: string = 'rush build -t '; - const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); - - const expected: string[] = ['abc', 'def']; - - expect(arrayEqual(actual, expected)).toBe(true); - }); - - it(`gets completion(s) for rush build -t a`, () => { - const startPath: string = path.resolve(__dirname, 'tabComplete'); - // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit - // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test - // repo will fail due to contention over the same lock which is kept until the test runner process - // ends. - jest.spyOn(process, 'cwd').mockReturnValue(startPath); - const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); - const tc: TabCompleteAction = new TabCompleteAction(parser); - - const commandLine: string = 'rush build -t a'; - const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); - - const expected: string[] = ['abc']; - - expect(arrayEqual(actual, expected)).toBe(true); - }); - - it(`gets completion(s) for rush change --bump-type `, () => { - const startPath: string = path.resolve(__dirname, 'tabComplete'); - // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit - // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test - // repo will fail due to contention over the same lock which is kept until the test runner process - // ends. - jest.spyOn(process, 'cwd').mockReturnValue(startPath); - const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); - const tc: TabCompleteAction = new TabCompleteAction(parser); - - const commandLine: string = 'rush change --bump-type '; - const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); - - const expected: string[] = ['major', 'minor', 'patch', 'none']; - - expect(arrayEqual(actual, expected)).toBe(true); - }); - - it(`gets completion(s) for rush change --bulk `, () => { - const startPath: string = path.resolve(__dirname, 'tabComplete'); - // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit - // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test - // repo will fail due to contention over the same lock which is kept until the test runner process - // ends. - jest.spyOn(process, 'cwd').mockReturnValue(startPath); - const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); - const tc: TabCompleteAction = new TabCompleteAction(parser); - - const commandLine: string = 'rush change --bulk '; - const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); - - expect(actual.indexOf('--bulk') !== -1).toBe(true); - expect(actual.indexOf('--message') !== -1).toBe(true); - expect(actual.indexOf('--bump-type') !== -1).toBe(true); - expect(actual.indexOf('--verify') !== -1).toBe(true); - }); - - it(`gets completion(s) for rush change --bump-type m`, () => { - const startPath: string = path.resolve(__dirname, 'tabComplete'); - // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit - // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test - // repo will fail due to contention over the same lock which is kept until the test runner process - // ends. - jest.spyOn(process, 'cwd').mockReturnValue(startPath); - const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); - const tc: TabCompleteAction = new TabCompleteAction(parser); - - const commandLine: string = 'rush change --bump-type m'; - const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); - - const expected: string[] = ['major', 'minor']; - - expect(arrayEqual(actual, expected)).toBe(true); - }); - - it(`gets completion(s) for rush change --message `, () => { - const startPath: string = path.resolve(__dirname, 'tabComplete'); - // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit - // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test - // repo will fail due to contention over the same lock which is kept until the test runner process - // ends. - jest.spyOn(process, 'cwd').mockReturnValue(startPath); - const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); - const tc: TabCompleteAction = new TabCompleteAction(parser); - - const commandLine: string = 'rush change --message '; - const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); - - const expected: string[] = []; - - expect(arrayEqual(actual, expected)).toBe(true); - }); - - it(`gets completion(s) for rush change --message "my change log message" --bump-type `, () => { - const startPath: string = path.resolve(__dirname, 'tabComplete'); - // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit - // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test - // repo will fail due to contention over the same lock which is kept until the test runner process - // ends. - jest.spyOn(process, 'cwd').mockReturnValue(startPath); - const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); - const tc: TabCompleteAction = new TabCompleteAction(parser); - - const commandLine: string = 'rush change --message "my change log message" --bump-type '; - const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); - - const expected: string[] = ['major', 'minor', 'patch', 'none']; - - expect(arrayEqual(actual, expected)).toBe(true); - }); - - it(`gets completion(s) for rush change --message "my change log message" --bump-type m`, () => { - const startPath: string = path.resolve(__dirname, 'tabComplete'); - // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit - // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test - // repo will fail due to contention over the same lock which is kept until the test runner process - // ends. - jest.spyOn(process, 'cwd').mockReturnValue(startPath); - const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); - const tc: TabCompleteAction = new TabCompleteAction(parser); - - const commandLine: string = 'rush change --message "my change log message" --bump-type m'; - const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); - - const expected: string[] = ['major', 'minor']; - - expect(arrayEqual(actual, expected)).toBe(true); - }); - }); - - describe(`Tokenize command line`, () => { - it(`tokenizes "rush change -"`, () => { - const startPath: string = path.resolve(__dirname, 'tabComplete'); - // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit - // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test - // repo will fail due to contention over the same lock which is kept until the test runner process - // ends. - jest.spyOn(process, 'cwd').mockReturnValue(startPath); - const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); - const tc: TabCompleteAction = new TabCompleteAction(parser); - - const commandLine: string = 'rush change -'; - const actual: string[] = Array.from(tc.tokenizeCommandLine(commandLine.trim())); - - const expected: string[] = ['rush', 'change', '-']; - - expect(arrayEqual(actual, expected)).toBe(true); - }); - it(`tokenizes 'rush change -m "my change log"'`, () => { - const startPath: string = path.resolve(__dirname, 'tabComplete'); - // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit - // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test - // repo will fail due to contention over the same lock which is kept until the test runner process - // ends. - jest.spyOn(process, 'cwd').mockReturnValue(startPath); - const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); - const tc: TabCompleteAction = new TabCompleteAction(parser); - - const commandLine: string = 'rush change -m "my change log"'; - const actual: string[] = Array.from(tc.tokenizeCommandLine(commandLine.trim())); - - const expected: string[] = ['rush', 'change', '-m', 'my change log']; - - expect(arrayEqual(actual, expected)).toBe(true); - }); - }); -}); diff --git a/apps/rush-lib/src/cli/scriptActions/BulkScriptAction.ts b/apps/rush-lib/src/cli/scriptActions/BulkScriptAction.ts index 9b6975fccfa..4b25b7d5376 100644 --- a/apps/rush-lib/src/cli/scriptActions/BulkScriptAction.ts +++ b/apps/rush-lib/src/cli/scriptActions/BulkScriptAction.ts @@ -173,7 +173,8 @@ export class BulkScriptAction extends BaseScriptAction { argumentName: 'PROJECT1', description: 'Run command in the specified project and all of its dependencies. "." can be used as shorthand ' + - 'to specify the project in the current working directory.' + 'to specify the project in the current working directory.', + completions: this._getProjectNames.bind(this) }); this._fromVersionPolicy = this.defineStringListParameter({ parameterLongName: '--from-version-policy', @@ -214,6 +215,14 @@ export class BulkScriptAction extends BaseScriptAction { this.defineScriptParameters(); } + private async _getProjectNames(): Promise { + const ret: string[] = []; + for (const project of this.rushConfiguration.projects) { + ret.push(project.packageName); + } + return ret; + } + private _doBeforeTask(): void { if ( this.actionName !== RushConstants.buildCommandName && diff --git a/apps/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap b/apps/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap index 2d281e396e9..9f914ab4e7c 100644 --- a/apps/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap +++ b/apps/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap @@ -42,7 +42,6 @@ Positional arguments: of imported packages. unlink Delete node_modules symlinks for all projects in the repo - tab-complete Provides tab completion. update Install package dependencies for all projects in the repo, and create or update the shrinkwrap file as needed @@ -658,19 +657,6 @@ Optional arguments: " `; -exports[`CommandLineHelp prints the help for each action: tab-complete 1`] = ` -"usage: rush tab-complete [-h] [--word WORD] [--position INDEX] - -Provides tab completion. - -Optional arguments: - -h, --help Show this help message and exit. - --word WORD The word to complete. The default value is \\"\\". - --position INDEX The position in the word to be completed. The default - value is 0. -" -`; - exports[`CommandLineHelp prints the help for each action: unlink 1`] = ` "usage: rush unlink [-h] diff --git a/apps/rush-lib/src/utilities/Utilities.ts b/apps/rush-lib/src/utilities/Utilities.ts index adcb33d9724..dbc6bad1f4c 100644 --- a/apps/rush-lib/src/utilities/Utilities.ts +++ b/apps/rush-lib/src/utilities/Utilities.ts @@ -443,7 +443,10 @@ export class Utilities { } public static isNonDebugTabCompletionRequest(): boolean { - return process.argv.length > 2 && process.argv[2] === 'tab-complete'; + return ( + (process.argv.length > 2 && process.argv[2] === 'tab-complete') || + (process.argv.length > 2 && process.argv[2] === 'tab-complete2') + ); } public static shouldPrintBanner(): boolean { diff --git a/common/reviews/api/ts-command-line.api.md b/common/reviews/api/ts-command-line.api.md index 3164b2a331b..efba0b1771f 100644 --- a/common/reviews/api/ts-command-line.api.md +++ b/common/reviews/api/ts-command-line.api.md @@ -72,6 +72,8 @@ export abstract class CommandLineParameter { // @internal constructor(definition: IBaseCommandLineDefinition); abstract appendToArgList(argList: string[]): void; + // (undocumented) + readonly completions: (() => Promise) | undefined; readonly description: string; readonly environmentVariable: string | undefined; // @internal @@ -200,6 +202,8 @@ export class DynamicCommandLineParser extends CommandLineParser { // @public export interface IBaseCommandLineDefinition { + // (undocumented) + completions?: () => Promise; description: string; environmentVariable?: string; parameterLongName: string; diff --git a/libraries/ts-command-line/src/parameters/BaseClasses.ts b/libraries/ts-command-line/src/parameters/BaseClasses.ts index e7142342718..8ccf08ecbb4 100644 --- a/libraries/ts-command-line/src/parameters/BaseClasses.ts +++ b/libraries/ts-command-line/src/parameters/BaseClasses.ts @@ -58,6 +58,9 @@ export abstract class CommandLineParameter { /** {@inheritDoc IBaseCommandLineDefinition.environmentVariable} */ public readonly environmentVariable: string | undefined; + /** {@inheritDoc IBaseCommandLineDefinition.completions} */ + public readonly completions: (() => Promise) | undefined; + /** @internal */ public constructor(definition: IBaseCommandLineDefinition) { this.longName = definition.parameterLongName; @@ -65,6 +68,7 @@ export abstract class CommandLineParameter { this.description = definition.description; this.required = !!definition.required; this.environmentVariable = definition.environmentVariable; + this.completions = definition.completions; if (!CommandLineParameter._longNameRegExp.test(this.longName)) { throw new Error( diff --git a/libraries/ts-command-line/src/parameters/CommandLineDefinition.ts b/libraries/ts-command-line/src/parameters/CommandLineDefinition.ts index 012a342cb01..b4a566e34b8 100644 --- a/libraries/ts-command-line/src/parameters/CommandLineDefinition.ts +++ b/libraries/ts-command-line/src/parameters/CommandLineDefinition.ts @@ -62,6 +62,11 @@ export interface IBaseCommandLineDefinition { * ordinary String Parameter: Any value is accepted, including an empty string. */ environmentVariable?: string; + + /** + * + */ + completions?: () => Promise; } /** diff --git a/libraries/ts-command-line/src/providers/CommandLineParser.ts b/libraries/ts-command-line/src/providers/CommandLineParser.ts index 5a730cc83e4..e18a6513c02 100644 --- a/libraries/ts-command-line/src/providers/CommandLineParser.ts +++ b/libraries/ts-command-line/src/providers/CommandLineParser.ts @@ -136,7 +136,7 @@ export abstract class CommandLineParser extends CommandLineParameterProvider { */ public execute(args?: string[]): Promise { if (this._options.enableTabCompletionAction) { - this.addAction(new TabCompleteAction(this._actionsByName)); + this.addAction(new TabCompleteAction(this.actions, this.parameters)); } return this.executeWithoutErrorHandling(args) .then(() => { diff --git a/libraries/ts-command-line/src/providers/TabCompletionAction.ts b/libraries/ts-command-line/src/providers/TabCompletionAction.ts index 966c8fea55a..28c80eed5cf 100644 --- a/libraries/ts-command-line/src/providers/TabCompletionAction.ts +++ b/libraries/ts-command-line/src/providers/TabCompletionAction.ts @@ -1,14 +1,13 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// import { BaseRushAction } from './BaseRushAction'; -// import { CommandLineParser } from './CommandLineParser'; import stringArgv from 'string-argv'; import { CommandLineIntegerParameter } from '../parameters/CommandLineIntegerParameter'; import { CommandLineStringParameter } from '../parameters/CommandLineStringParameter'; import { CommandLineParameterKind, CommandLineParameter } from '../parameters/BaseClasses'; import { CommandLineAction } from './CommandLineAction'; +import { CommandLineChoiceParameter } from '..'; interface IParameter { name: string; @@ -21,16 +20,21 @@ const DEFAULT_POSITION: number = 0; export class TabCompleteAction extends CommandLineAction { private _wordToCompleteParameter: CommandLineStringParameter; private _positionParameter: CommandLineIntegerParameter; - private _actionsByName: Map; + private _actions: ReadonlyArray; + private _globalParameters: ReadonlyArray; - public constructor(actionsByName: Map) { + public constructor( + actions: ReadonlyArray, + globalParameters: ReadonlyArray + ) { super({ - actionName: 'tab-complete2', + actionName: 'tab-complete', summary: 'Provides tab completion.', documentation: 'Provides tab completion.' }); - this._actionsByName = actionsByName; + this._actions = actions; + this._globalParameters = globalParameters; } protected onDefineParameters(): void { @@ -57,31 +61,33 @@ export class TabCompleteAction extends CommandLineAction { const commandLine: string = this._wordToCompleteParameter.value || ''; const caretPosition: number = this._positionParameter.value || 0; - for (const value of this.getCompletions(commandLine, caretPosition)) { + for await (const value of this.getCompletions(commandLine, caretPosition)) { console.log(value); } } - public *getCompletions(commandLine: string, caretPosition: number): IterableIterator { + public async *getCompletions(commandLine: string, caretPosition: number): AsyncIterable { const actions: Map> = new Map< string, Map >(); - for (const [key, value] of this._actionsByName.entries()) { + for (const action of this._actions) { const parameterNameToParameterInfoMap: IParameter[] = []; - value.parameters.forEach((elem) => { - parameterNameToParameterInfoMap[elem.longName] = elem; - if (elem.shortName) { - parameterNameToParameterInfoMap[elem.shortName] = elem; + action.parameters.forEach((parameter) => { + parameterNameToParameterInfoMap[parameter.longName] = parameter; + if (parameter.shortName) { + parameterNameToParameterInfoMap[parameter.shortName] = parameter; } }); - actions[key] = parameterNameToParameterInfoMap; + actions[action.actionName] = parameterNameToParameterInfoMap; } - actions['-d'] = []; - actions['--debug'] = []; - actions['-h'] = []; - actions['--help'] = []; + for (const parameter of this._globalParameters) { + actions[parameter.longName] = parameter; + if (parameter.shortName) { + actions[parameter.shortName] = parameter; + } + } if (!commandLine || !caretPosition) { yield* Object.keys(actions); // return all actions @@ -90,10 +96,10 @@ export class TabCompleteAction extends CommandLineAction { const tokens: string[] = Array.from(this.tokenizeCommandLine(commandLine)); - const debugParameterUsed: boolean = tokens.length > 1 && (tokens[1] === '-d' || tokens[1] === '--debug'); - const debugParameterOffset: number = debugParameterUsed ? 1 : 0; // if debug switch is used, then offset everything by 1. + // offset arguments by the number of global params in the input + const globalParameterOffset: number = this._getGlobalParameterOffset(tokens); - if (tokens.length < 2 + debugParameterOffset) { + if (tokens.length < 2 + globalParameterOffset) { yield* Object.keys(actions); // return all actions return; } @@ -103,66 +109,50 @@ export class TabCompleteAction extends CommandLineAction { const completePartialWord: boolean = caretPosition === commandLine.length; - if (completePartialWord && tokens.length === 2 + debugParameterOffset) { + if (completePartialWord && tokens.length === 2 + globalParameterOffset) { for (const actionName of Object.keys(actions)) { - if (actionName.indexOf(tokens[1 + debugParameterOffset]) === 0) { + if (actionName.indexOf(tokens[1 + globalParameterOffset]) === 0) { yield actionName; } } } else { for (const actionName of Object.keys(actions)) { - if (actionName === tokens[1 + debugParameterOffset]) { - if (actionName === 'build' || actionName === 'rebuild') { - const choiceParameter: string[] = ['-f', '--from', '-t', '--to']; - const choiceParameterValues: string[] = []; - - // TODO: Provide a way to supply custom parameter values - // for (const project of this.rushConfiguration.projects) { - // choiceParameterValues.push(project.packageName); - // } - - choiceParameterValues.push('abc'); - choiceParameterValues.push('def'); - choiceParameterValues.push('hij'); - - yield* this._getChoiceParameterValues( - choiceParameter, - choiceParameterValues, - lastToken, - secondLastToken, - completePartialWord - ); - - // TODO: Add support for version policy, variant - } else if (actionName === 'change') { - const choiceParameter: string[] = ['--bump-type']; - const choiceParameterValues: string[] = ['major', 'minor', 'patch', 'none']; - yield* this._getChoiceParameterValues( - choiceParameter, - choiceParameterValues, - lastToken, - secondLastToken, - completePartialWord - ); - } else if (actionName === 'publish') { - const choiceParameter: string[] = ['--set-access-level']; - const choiceParameterValues: string[] = ['public', 'restricted']; - yield* this._getChoiceParameterValues( - choiceParameter, - choiceParameterValues, - lastToken, - secondLastToken, - completePartialWord - ); + if (actionName === tokens[1 + globalParameterOffset]) { + const parameterNameMap: Map = actions[actionName]; + + const parameterNames: string[] = Array.from(Object.keys(actions[actionName]), (x: string) => x); + + for (const parameter of parameterNames) { + let choiceParameterValues: string[] = []; + if (parameterNameMap[parameter].kind === CommandLineParameterKind.Choice) { + choiceParameterValues = (parameterNameMap[parameter] as CommandLineChoiceParameter) + .alternatives as string[]; + } else if (parameterNameMap[parameter].completions) { + choiceParameterValues = await parameterNameMap[parameter].completions(); + } + if (choiceParameterValues.length > 0) { + if (completePartialWord) { + if (parameter === secondLastToken) { + yield* this._completeChoiceParameterValues(choiceParameterValues, lastToken); + return; + } + } else { + if (parameter === lastToken) { + yield* choiceParameterValues; + return; + } + } + } } - const parameterNames: string[] = Array.from(actions[actionName], (x: IParameter) => x.name); - if (completePartialWord) { yield* this._completeChoiceParameterValues(parameterNames, lastToken); } else { - for (const parameter of actions[actionName]) { - if (parameter.name === lastToken && parameter.kind !== CommandLineParameterKind.Flag) { + for (const parameter of parameterNames) { + if ( + parameter === lastToken && + parameterNameMap[parameter].kind !== CommandLineParameterKind.Flag + ) { // The parameter is expecting a value, so don't suggest parameter names again return; } @@ -170,6 +160,8 @@ export class TabCompleteAction extends CommandLineAction { yield* parameterNames; } + + break; } } } @@ -179,22 +171,18 @@ export class TabCompleteAction extends CommandLineAction { return stringArgv(commandLine); } - private *_getChoiceParameterValues( - choiceParameter: string[], - choiceParameterValues: string[], - lastToken: string, - secondLastToken: string, - completePartialWord: boolean - ): IterableIterator { - if (completePartialWord) { - if (choiceParameter.indexOf(secondLastToken) !== -1) { - yield* this._completeChoiceParameterValues(choiceParameterValues, lastToken); - } - } else { - if (choiceParameter.indexOf(lastToken) !== -1) { - yield* choiceParameterValues; + private _getGlobalParameterOffset(tokens: string[]): number { + let count: number = 0; + for (let i: number = 1; i < tokens.length; i++) { + for (const globalParameter of this._globalParameters) { + if (tokens[i] !== globalParameter.longName && tokens[i] !== globalParameter.shortName) { + break; + } + count++; } } + + return count; } private *_completeChoiceParameterValues( diff --git a/libraries/ts-command-line/src/test/TabCompleteAction.test.ts b/libraries/ts-command-line/src/test/TabCompleteAction.test.ts new file mode 100644 index 00000000000..e41980fe1fb --- /dev/null +++ b/libraries/ts-command-line/src/test/TabCompleteAction.test.ts @@ -0,0 +1,483 @@ +import { DynamicCommandLineParser, DynamicCommandLineAction } from '..'; +import { TabCompleteAction } from '../providers/TabCompletionAction'; +import { ICommandLineStringDefinition } from '../parameters/CommandLineDefinition'; + +/** + * Provides the parameter configuration for '--variant'. + */ +const VARIANT_PARAMETER: ICommandLineStringDefinition = { + parameterLongName: '--variant', + argumentName: 'VARIANT', + description: 'Run command using a variant installation configuration', + environmentVariable: 'RUSH_VARIANT' +}; + +async function arrayFromAsyncIteractorAsync(iterator: AsyncIterable): Promise { + const ret: string[] = []; + + for await (const val of iterator) { + ret.push(val); + } + + return ret; +} + +function getCommandLineParser(): DynamicCommandLineParser { + const commandLineParser: DynamicCommandLineParser = new DynamicCommandLineParser({ + toolFilename: 'rush', + toolDescription: 'Rush: a scalable monorepo manager for the web', + enableTabCompletionAction: true + }); + + const addAction: DynamicCommandLineAction = new DynamicCommandLineAction({ + actionName: 'add', + summary: 'Adds a dependency to the package.json and runs rush upgrade.', + documentation: 'Adds a dependency to the package.json and runs rush upgrade.' + }); + commandLineParser.addAction(addAction); + addAction.defineStringParameter({ + parameterLongName: '--package', + parameterShortName: '-p', + required: true, + argumentName: 'PACKAGE', + description: + '(Required) The name of the package which should be added as a dependency.' + + ' A SemVer version specifier can be appended after an "@" sign. WARNING: Symbol characters' + + " are usually interpreted by your shell, so it's recommended to use quotes." + + ' For example, write "rush add --package "example@^1.2.3"" instead of "rush add --package example@^1.2.3".' + }); + addAction.defineFlagParameter({ + parameterLongName: '--exact', + description: + 'If specified, the SemVer specifier added to the' + + ' package.json will be an exact version (e.g. without tilde or caret).' + }); + addAction.defineFlagParameter({ + parameterLongName: '--caret', + description: + 'If specified, the SemVer specifier added to the' + + ' package.json will be a prepended with a "caret" specifier ("^").' + }); + addAction.defineFlagParameter({ + parameterLongName: '--dev', + description: + 'If specified, the package will be added to the "devDependencies" section of the package.json' + }); + addAction.defineFlagParameter({ + parameterLongName: '--make-consistent', + parameterShortName: '-m', + description: + 'If specified, other packages with this dependency will have their package.json' + + ' files updated to use the same version of the dependency.' + }); + addAction.defineFlagParameter({ + parameterLongName: '--skip-update', + parameterShortName: '-s', + description: + 'If specified, the "rush update" command will not be run after updating the package.json files.' + }); + addAction.defineFlagParameter({ + parameterLongName: '--all', + description: 'If specified, the dependency will be added to all projects.' + }); + + const buildAction: DynamicCommandLineAction = new DynamicCommandLineAction({ + actionName: 'build', + summary: "Build all projects that haven't been built.", + documentation: "Build all projects that haven't been built." + }); + commandLineParser.addAction(buildAction); + buildAction.defineStringParameter({ + parameterLongName: '--parallelism', + parameterShortName: '-p', + argumentName: 'COUNT', + description: 'Specifies the maximum number of concurrent processes to launch during a build.' + }); + buildAction.defineStringListParameter({ + parameterLongName: '--to', + parameterShortName: '-t', + argumentName: 'PROJECT1', + description: 'Run command in the specified project and all of its dependencies.', + completions: async (): Promise => { + return ['abc', 'def', 'hij']; + } + }); + buildAction.defineStringListParameter({ + parameterLongName: '--from', + parameterShortName: '-f', + argumentName: 'PROJECT2', + description: + 'Run command in the specified project and all projects that directly or indirectly depend on the ' + + 'specified project.' + }); + + const changeAction: DynamicCommandLineAction = new DynamicCommandLineAction({ + actionName: 'change', + summary: + 'Records changes made to projects, indicating how the package version number should be bumped ' + + 'for the next publish.', + documentation: 'Asks a series of questions and then generates a -.json file.' + }); + commandLineParser.addAction(changeAction); + changeAction.defineFlagParameter({ + parameterLongName: '--verify', + parameterShortName: '-v', + description: 'Verify the change file has been generated and that it is a valid JSON file' + }); + changeAction.defineFlagParameter({ + parameterLongName: '--no-fetch', + description: 'Skips fetching the baseline branch before running "git diff" to detect changes.' + }); + changeAction.defineStringParameter({ + parameterLongName: '--target-branch', + parameterShortName: '-b', + argumentName: 'BRANCH', + description: 'If this parameter is specified, compare the checked out branch with the specified branch.' + }); + changeAction.defineFlagParameter({ + parameterLongName: '--overwrite', + description: `If a changefile already exists, overwrite without prompting.` + }); + changeAction.defineStringParameter({ + parameterLongName: '--email', + argumentName: 'EMAIL', + description: + 'The email address to use in changefiles. If this parameter is not provided, the email address ' + + 'will be detected or prompted for in interactive mode.' + }); + changeAction.defineFlagParameter({ + parameterLongName: '--bulk', + description: + 'If this flag is specified, apply the same change message and bump type to all changed projects. ' + }); + changeAction.defineStringParameter({ + parameterLongName: '--message', + argumentName: 'MESSAGE', + description: `The message to apply to all changed projects.` + }); + changeAction.defineChoiceParameter({ + parameterLongName: '--bump-type', + alternatives: ['major', 'minor', 'patch', 'none'], + description: `The bump type to apply to all changed projects.` + }); + + const installAction: DynamicCommandLineAction = new DynamicCommandLineAction({ + actionName: 'install', + summary: 'Install package dependencies for all projects in the repo according to the shrinkwrap file.', + documentation: + 'Longer description: Install package dependencies for all projects in the repo according ' + + 'to the shrinkwrap file.' + }); + commandLineParser.addAction(installAction); + installAction.defineFlagParameter({ + parameterLongName: '--purge', + parameterShortName: '-p', + description: 'Perform "rush purge" before starting the installation' + }); + installAction.defineFlagParameter({ + parameterLongName: '--bypass-policy', + description: 'Overrides enforcement of the "gitPolicy" rules from rush.json (use honorably!)' + }); + installAction.defineFlagParameter({ + parameterLongName: '--no-link', + description: 'If "--no-link" is specified, then project symlinks will NOT be created' + }); + installAction.defineIntegerParameter({ + parameterLongName: '--network-concurrency', + argumentName: 'COUNT', + description: 'If specified, limits the maximum number of concurrent network requests.' + }); + installAction.defineFlagParameter({ + parameterLongName: '--debug-package-manager', + description: 'Activates verbose logging for the package manager.' + }); + installAction.defineIntegerParameter({ + parameterLongName: '--max-install-attempts', + argumentName: 'NUMBER', + description: `Overrides the default maximum number of install attempts.`, + defaultValue: 3 + }); + installAction.defineStringParameter(VARIANT_PARAMETER); + + commandLineParser.defineFlagParameter({ + parameterLongName: '--debug', + parameterShortName: '-d', + description: 'Show the full call stack if an error occurs while executing the tool' + }); + + return commandLineParser; +} + +describe('Gets TabCompletion(s)', () => { + it(`gets completion(s) for rush `, async () => { + const commandLineParser: DynamicCommandLineParser = getCommandLineParser(); + const tc: TabCompleteAction = new TabCompleteAction( + commandLineParser.actions, + commandLineParser.parameters + ); + + const commandLine: string = 'rush '; + const actual: string[] = await arrayFromAsyncIteractorAsync( + tc.getCompletions(commandLine.trim(), commandLine.length) + ); + + const expected: string[] = ['add', 'build', 'change', 'install', '--debug', '-d']; + + expect(actual.sort()).toEqual(expected.sort()); + }); + + it(`gets completion(s) for rush a`, async () => { + const commandLineParser: DynamicCommandLineParser = getCommandLineParser(); + const tc: TabCompleteAction = new TabCompleteAction( + commandLineParser.actions, + commandLineParser.parameters + ); + + const commandLine: string = 'rush a'; + const actual: string[] = await arrayFromAsyncIteractorAsync( + tc.getCompletions(commandLine.trim(), commandLine.length) + ); + + const expected: string[] = ['add']; + + expect(actual.sort()).toEqual(expected.sort()); + }); + + it(`gets completion(s) for rush -d a`, async () => { + const commandLineParser: DynamicCommandLineParser = getCommandLineParser(); + const tc: TabCompleteAction = new TabCompleteAction( + commandLineParser.actions, + commandLineParser.parameters + ); + + const commandLine: string = 'rush -d a'; + const actual: string[] = await arrayFromAsyncIteractorAsync( + tc.getCompletions(commandLine.trim(), commandLine.length) + ); + + const expected: string[] = ['add']; + + expect(actual.sort()).toEqual(expected.sort()); + }); + + it(`gets completion(s) for rush build `, async () => { + const commandLineParser: DynamicCommandLineParser = getCommandLineParser(); + const tc: TabCompleteAction = new TabCompleteAction( + commandLineParser.actions, + commandLineParser.parameters + ); + + const commandLine: string = 'rush build '; + const actual: string[] = await arrayFromAsyncIteractorAsync( + tc.getCompletions(commandLine.trim(), commandLine.length) + ); + + expect(actual.indexOf('-t') !== -1).toBe(true); + expect(actual.indexOf('--to') !== -1).toBe(true); + expect(actual.indexOf('-f') !== -1).toBe(true); + expect(actual.indexOf('--from') !== -1).toBe(true); + }); + + it(`gets completion(s) for rush build -`, async () => { + const commandLineParser: DynamicCommandLineParser = getCommandLineParser(); + const tc: TabCompleteAction = new TabCompleteAction( + commandLineParser.actions, + commandLineParser.parameters + ); + + const commandLine: string = 'rush build -'; + const actual: string[] = await arrayFromAsyncIteractorAsync( + tc.getCompletions(commandLine.trim(), commandLine.length) + ); + + expect(actual.indexOf('-t') !== -1).toBe(true); + expect(actual.indexOf('--to') !== -1).toBe(true); + expect(actual.indexOf('-f') !== -1).toBe(true); + expect(actual.indexOf('--from') !== -1).toBe(true); + }); + + it(`gets completion(s) for rush build -t `, async () => { + const commandLineParser: DynamicCommandLineParser = getCommandLineParser(); + const tc: TabCompleteAction = new TabCompleteAction( + commandLineParser.actions, + commandLineParser.parameters + ); + + const commandLine: string = 'rush build -t '; + const actual: string[] = await arrayFromAsyncIteractorAsync( + tc.getCompletions(commandLine.trim(), commandLine.length) + ); + + const expected: string[] = ['abc', 'def', 'hij']; + + expect(actual.sort()).toEqual(expected.sort()); + }); + + it(`gets completion(s) for rush build -t a`, async () => { + const commandLineParser: DynamicCommandLineParser = getCommandLineParser(); + const tc: TabCompleteAction = new TabCompleteAction( + commandLineParser.actions, + commandLineParser.parameters + ); + + const commandLine: string = 'rush build -t a'; + const actual: string[] = await arrayFromAsyncIteractorAsync( + tc.getCompletions(commandLine.trim(), commandLine.length) + ); + + const expected: string[] = ['abc']; + + expect(actual.sort()).toEqual(expected.sort()); + }); + + it(`gets completion(s) for rush --debug build -t a`, async () => { + const commandLineParser: DynamicCommandLineParser = getCommandLineParser(); + const tc: TabCompleteAction = new TabCompleteAction( + commandLineParser.actions, + commandLineParser.parameters + ); + + const commandLine: string = 'rush --debug build -t a'; + const actual: string[] = await arrayFromAsyncIteractorAsync( + tc.getCompletions(commandLine.trim(), commandLine.length) + ); + + const expected: string[] = ['abc']; + + expect(actual.sort()).toEqual(expected.sort()); + }); + + it(`gets completion(s) for rush change --bump-type `, async () => { + const commandLineParser: DynamicCommandLineParser = getCommandLineParser(); + const tc: TabCompleteAction = new TabCompleteAction( + commandLineParser.actions, + commandLineParser.parameters + ); + + const commandLine: string = 'rush change --bump-type '; + const actual: string[] = await arrayFromAsyncIteractorAsync( + tc.getCompletions(commandLine.trim(), commandLine.length) + ); + + const expected: string[] = ['major', 'minor', 'patch', 'none']; + + expect(actual.sort()).toEqual(expected.sort()); + }); + + it(`gets completion(s) for rush change --bulk `, async () => { + const commandLineParser: DynamicCommandLineParser = getCommandLineParser(); + const tc: TabCompleteAction = new TabCompleteAction( + commandLineParser.actions, + commandLineParser.parameters + ); + + const commandLine: string = 'rush change --bulk '; + const actual: string[] = await arrayFromAsyncIteractorAsync( + tc.getCompletions(commandLine.trim(), commandLine.length) + ); + + expect(actual.indexOf('--bulk') !== -1).toBe(true); + expect(actual.indexOf('--message') !== -1).toBe(true); + expect(actual.indexOf('--bump-type') !== -1).toBe(true); + expect(actual.indexOf('--verify') !== -1).toBe(true); + }); + + it(`gets completion(s) for rush change --bump-type m`, async () => { + const commandLineParser: DynamicCommandLineParser = getCommandLineParser(); + const tc: TabCompleteAction = new TabCompleteAction( + commandLineParser.actions, + commandLineParser.parameters + ); + + const commandLine: string = 'rush change --bump-type m'; + const actual: string[] = await arrayFromAsyncIteractorAsync( + tc.getCompletions(commandLine.trim(), commandLine.length) + ); + + const expected: string[] = ['major', 'minor']; + + expect(actual.sort()).toEqual(expected.sort()); + }); + + it(`gets completion(s) for rush change --message `, async () => { + const commandLineParser: DynamicCommandLineParser = getCommandLineParser(); + const tc: TabCompleteAction = new TabCompleteAction( + commandLineParser.actions, + commandLineParser.parameters + ); + + const commandLine: string = 'rush change --message '; + const actual: string[] = await arrayFromAsyncIteractorAsync( + tc.getCompletions(commandLine.trim(), commandLine.length) + ); + + const expected: string[] = []; + + expect(actual.sort()).toEqual(expected.sort()); + }); + + it(`gets completion(s) for rush change --message "my change log message" --bump-type `, async () => { + const commandLineParser: DynamicCommandLineParser = getCommandLineParser(); + const tc: TabCompleteAction = new TabCompleteAction( + commandLineParser.actions, + commandLineParser.parameters + ); + + const commandLine: string = 'rush change --message "my change log message" --bump-type '; + const actual: string[] = await arrayFromAsyncIteractorAsync( + tc.getCompletions(commandLine.trim(), commandLine.length) + ); + + const expected: string[] = ['major', 'minor', 'patch', 'none']; + + expect(actual.sort()).toEqual(expected.sort()); + }); + + it(`gets completion(s) for rush change --message "my change log message" --bump-type m`, async () => { + const commandLineParser: DynamicCommandLineParser = getCommandLineParser(); + const tc: TabCompleteAction = new TabCompleteAction( + commandLineParser.actions, + commandLineParser.parameters + ); + + const commandLine: string = 'rush change --message "my change log message" --bump-type m'; + const actual: string[] = await arrayFromAsyncIteractorAsync( + tc.getCompletions(commandLine.trim(), commandLine.length) + ); + + const expected: string[] = ['major', 'minor']; + + expect(actual.sort()).toEqual(expected.sort()); + }); +}); + +describe(`Tokenize command line`, () => { + it(`tokenizes "rush change -"`, () => { + const commandLineParser: DynamicCommandLineParser = getCommandLineParser(); + const tc: TabCompleteAction = new TabCompleteAction( + commandLineParser.actions, + commandLineParser.parameters + ); + + const commandLine: string = 'rush change -'; + const actual: string[] = tc.tokenizeCommandLine(commandLine.trim()); + + const expected: string[] = ['rush', 'change', '-']; + + expect(actual.sort()).toEqual(expected.sort()); + }); + it(`tokenizes 'rush change -m "my change log"'`, () => { + const commandLineParser: DynamicCommandLineParser = getCommandLineParser(); + const tc: TabCompleteAction = new TabCompleteAction( + commandLineParser.actions, + commandLineParser.parameters + ); + + const commandLine: string = 'rush change -m "my change log"'; + const actual: string[] = tc.tokenizeCommandLine(commandLine.trim()); + + const expected: string[] = ['rush', 'change', '-m', 'my change log']; + + expect(actual.sort()).toEqual(expected.sort()); + }); +}); From 114ef50b9a814d8d0b73d96e51241f729d036cd7 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Sun, 2 Aug 2020 16:32:53 -0700 Subject: [PATCH 47/97] Commit tests --- .../actions/test/TabCompleteAction.test.ts | 297 ++++++++++++++++++ 1 file changed, 297 insertions(+) create mode 100644 apps/rush-lib/src/cli/actions/test/TabCompleteAction.test.ts diff --git a/apps/rush-lib/src/cli/actions/test/TabCompleteAction.test.ts b/apps/rush-lib/src/cli/actions/test/TabCompleteAction.test.ts new file mode 100644 index 00000000000..7a60938ff0b --- /dev/null +++ b/apps/rush-lib/src/cli/actions/test/TabCompleteAction.test.ts @@ -0,0 +1,297 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. +// See LICENSE in the project root for license information. + +import '../../test/mockRushCommandLineParser'; + +import * as path from 'path'; + +import { TabCompleteAction } from '../TabCompleteAction'; +import { RushCommandLineParser } from '../../RushCommandLineParser'; + +function arrayEqual(actual: string[], expected: string[]): boolean { + return ( + actual.length === expected.length && + actual.sort().every((v: string, i: number) => { + return v === expected.sort()[i]; + }) + ); +} + +describe('TabCompleteAction', () => { + let oldExitCode: number | undefined; + let oldArgs: string[]; + + beforeEach(() => { + jest.spyOn(process, 'exit').mockImplementation(); + oldExitCode = process.exitCode; + oldArgs = process.argv; + }); + + afterEach(() => { + jest.clearAllMocks(); + process.exitCode = oldExitCode; + process.argv = oldArgs; + }); + + describe(`Gets TabCompletions`, () => { + it(`gets completion(s) for rush `, () => { + const startPath: string = path.resolve(__dirname, 'tabComplete'); + // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit + // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test + // repo will fail due to contention over the same lock which is kept until the test runner process + // ends. + jest.spyOn(process, 'cwd').mockReturnValue(startPath); + const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); + const tc: TabCompleteAction = new TabCompleteAction(parser); + + const commandLine: string = 'rush'; + const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); + + expect(actual.indexOf('add') !== -1).toBe(true); + expect(actual.indexOf('check') !== -1).toBe(true); + expect(actual.indexOf('build') !== -1).toBe(true); + expect(actual.indexOf('rebuild') !== -1).toBe(true); + expect(actual.indexOf('-d') !== -1).toBe(true); + expect(actual.indexOf('--debug') !== -1).toBe(true); + expect(actual.indexOf('--help') !== -1).toBe(true); + }); + + it(`gets completion(s) for rush a`, () => { + const startPath: string = path.resolve(__dirname, 'tabComplete'); + // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit + // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test + // repo will fail due to contention over the same lock which is kept until the test runner process + // ends. + jest.spyOn(process, 'cwd').mockReturnValue(startPath); + const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); + const tc: TabCompleteAction = new TabCompleteAction(parser); + + const commandLine: string = 'rush a'; + const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); + + const expected: string[] = ['add']; + + expect(arrayEqual(actual, expected)).toBe(true); + }); + + it(`gets completion(s) for rush build `, () => { + const startPath: string = path.resolve(__dirname, 'tabComplete'); + // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit + // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test + // repo will fail due to contention over the same lock which is kept until the test runner process + // ends. + jest.spyOn(process, 'cwd').mockReturnValue(startPath); + const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); + const tc: TabCompleteAction = new TabCompleteAction(parser); + + const commandLine: string = 'rush build '; + const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); + + expect(actual.indexOf('-t') !== -1).toBe(true); + expect(actual.indexOf('--to') !== -1).toBe(true); + expect(actual.indexOf('-f') !== -1).toBe(true); + expect(actual.indexOf('--from') !== -1).toBe(true); + }); + + it(`gets completion(s) for rush build -`, () => { + const startPath: string = path.resolve(__dirname, 'tabComplete'); + // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit + // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test + // repo will fail due to contention over the same lock which is kept until the test runner process + // ends. + jest.spyOn(process, 'cwd').mockReturnValue(startPath); + const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); + const tc: TabCompleteAction = new TabCompleteAction(parser); + + const commandLine: string = 'rush build -'; + const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); + + expect(actual.indexOf('-t') !== -1).toBe(true); + expect(actual.indexOf('--to') !== -1).toBe(true); + expect(actual.indexOf('-f') !== -1).toBe(true); + expect(actual.indexOf('--from') !== -1).toBe(true); + }); + + it(`gets completion(s) for rush build -t `, () => { + const startPath: string = path.resolve(__dirname, 'tabComplete'); + // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit + // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test + // repo will fail due to contention over the same lock which is kept until the test runner process + // ends. + jest.spyOn(process, 'cwd').mockReturnValue(startPath); + const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); + const tc: TabCompleteAction = new TabCompleteAction(parser); + + const commandLine: string = 'rush build -t '; + const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); + + const expected: string[] = ['abc', 'def']; + + expect(arrayEqual(actual, expected)).toBe(true); + }); + + it(`gets completion(s) for rush build -t a`, () => { + const startPath: string = path.resolve(__dirname, 'tabComplete'); + // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit + // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test + // repo will fail due to contention over the same lock which is kept until the test runner process + // ends. + jest.spyOn(process, 'cwd').mockReturnValue(startPath); + const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); + const tc: TabCompleteAction = new TabCompleteAction(parser); + + const commandLine: string = 'rush build -t a'; + const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); + + const expected: string[] = ['abc']; + + expect(arrayEqual(actual, expected)).toBe(true); + }); + + it(`gets completion(s) for rush change --bump-type `, () => { + const startPath: string = path.resolve(__dirname, 'tabComplete'); + // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit + // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test + // repo will fail due to contention over the same lock which is kept until the test runner process + // ends. + jest.spyOn(process, 'cwd').mockReturnValue(startPath); + const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); + const tc: TabCompleteAction = new TabCompleteAction(parser); + + const commandLine: string = 'rush change --bump-type '; + const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); + + const expected: string[] = ['major', 'minor', 'patch', 'none']; + + expect(arrayEqual(actual, expected)).toBe(true); + }); + + it(`gets completion(s) for rush change --bulk `, () => { + const startPath: string = path.resolve(__dirname, 'tabComplete'); + // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit + // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test + // repo will fail due to contention over the same lock which is kept until the test runner process + // ends. + jest.spyOn(process, 'cwd').mockReturnValue(startPath); + const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); + const tc: TabCompleteAction = new TabCompleteAction(parser); + + const commandLine: string = 'rush change --bulk '; + const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); + + expect(actual.indexOf('--bulk') !== -1).toBe(true); + expect(actual.indexOf('--message') !== -1).toBe(true); + expect(actual.indexOf('--bump-type') !== -1).toBe(true); + expect(actual.indexOf('--verify') !== -1).toBe(true); + }); + + it(`gets completion(s) for rush change --bump-type m`, () => { + const startPath: string = path.resolve(__dirname, 'tabComplete'); + // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit + // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test + // repo will fail due to contention over the same lock which is kept until the test runner process + // ends. + jest.spyOn(process, 'cwd').mockReturnValue(startPath); + const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); + const tc: TabCompleteAction = new TabCompleteAction(parser); + + const commandLine: string = 'rush change --bump-type m'; + const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); + + const expected: string[] = ['major', 'minor']; + + expect(arrayEqual(actual, expected)).toBe(true); + }); + + it(`gets completion(s) for rush change --message `, () => { + const startPath: string = path.resolve(__dirname, 'tabComplete'); + // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit + // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test + // repo will fail due to contention over the same lock which is kept until the test runner process + // ends. + jest.spyOn(process, 'cwd').mockReturnValue(startPath); + const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); + const tc: TabCompleteAction = new TabCompleteAction(parser); + + const commandLine: string = 'rush change --message '; + const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); + + const expected: string[] = []; + + expect(arrayEqual(actual, expected)).toBe(true); + }); + + it(`gets completion(s) for rush change --message "my change log message" --bump-type `, () => { + const startPath: string = path.resolve(__dirname, 'tabComplete'); + // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit + // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test + // repo will fail due to contention over the same lock which is kept until the test runner process + // ends. + jest.spyOn(process, 'cwd').mockReturnValue(startPath); + const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); + const tc: TabCompleteAction = new TabCompleteAction(parser); + + const commandLine: string = 'rush change --message "my change log message" --bump-type '; + const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); + + const expected: string[] = ['major', 'minor', 'patch', 'none']; + + expect(arrayEqual(actual, expected)).toBe(true); + }); + + it(`gets completion(s) for rush change --message "my change log message" --bump-type m`, () => { + const startPath: string = path.resolve(__dirname, 'tabComplete'); + // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit + // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test + // repo will fail due to contention over the same lock which is kept until the test runner process + // ends. + jest.spyOn(process, 'cwd').mockReturnValue(startPath); + const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); + const tc: TabCompleteAction = new TabCompleteAction(parser); + + const commandLine: string = 'rush change --message "my change log message" --bump-type m'; + const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); + + const expected: string[] = ['major', 'minor']; + + expect(arrayEqual(actual, expected)).toBe(true); + }); + }); + + describe(`Tokenize command line`, () => { + it(`tokenizes "rush change -"`, () => { + const startPath: string = path.resolve(__dirname, 'tabComplete'); + // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit + // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test + // repo will fail due to contention over the same lock which is kept until the test runner process + // ends. + jest.spyOn(process, 'cwd').mockReturnValue(startPath); + const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); + const tc: TabCompleteAction = new TabCompleteAction(parser); + + const commandLine: string = 'rush change -'; + const actual: string[] = Array.from(tc.tokenizeCommandLine(commandLine.trim())); + + const expected: string[] = ['rush', 'change', '-']; + + expect(arrayEqual(actual, expected)).toBe(true); + }); + it(`tokenizes 'rush change -m "my change log"'`, () => { + const startPath: string = path.resolve(__dirname, 'tabComplete'); + // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit + // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test + // repo will fail due to contention over the same lock which is kept until the test runner process + // ends. + jest.spyOn(process, 'cwd').mockReturnValue(startPath); + const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); + const tc: TabCompleteAction = new TabCompleteAction(parser); + + const commandLine: string = 'rush change -m "my change log"'; + const actual: string[] = Array.from(tc.tokenizeCommandLine(commandLine.trim())); + + const expected: string[] = ['rush', 'change', '-m', 'my change log']; + + expect(arrayEqual(actual, expected)).toBe(true); + }); + }); +}); From d0a38c0916f42cda66899185cd8ad5fcd460c265 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Sun, 2 Aug 2020 16:33:02 -0700 Subject: [PATCH 48/97] Rush change --- ...seph-rush-shell-tab-complete_2020-07-29-11-32.json | 11 ----------- ...seph-rush-shell-tab-complete_2020-08-01-22-06.json | 4 ++-- ...seph-rush-shell-tab-complete_2020-08-01-22-06.json | 4 ++-- ...seph-rush-shell-tab-complete_2020-08-01-22-06.json | 2 +- 4 files changed, 5 insertions(+), 16 deletions(-) delete mode 100644 common/changes/@microsoft/rush/sachinjoseph-rush-shell-tab-complete_2020-07-29-11-32.json diff --git a/common/changes/@microsoft/rush/sachinjoseph-rush-shell-tab-complete_2020-07-29-11-32.json b/common/changes/@microsoft/rush/sachinjoseph-rush-shell-tab-complete_2020-07-29-11-32.json deleted file mode 100644 index 2725b623510..00000000000 --- a/common/changes/@microsoft/rush/sachinjoseph-rush-shell-tab-complete_2020-07-29-11-32.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "changes": [ - { - "packageName": "@microsoft/rush", - "comment": "Add support for shell tab completion.", - "type": "none" - } - ], - "packageName": "@microsoft/rush", - "email": "sachinjoseph@users.noreply.github.com" -} \ No newline at end of file diff --git a/common/changes/@microsoft/rush/sachinjoseph-rush-shell-tab-complete_2020-08-01-22-06.json b/common/changes/@microsoft/rush/sachinjoseph-rush-shell-tab-complete_2020-08-01-22-06.json index 7ff8cf80349..e546771c8ce 100644 --- a/common/changes/@microsoft/rush/sachinjoseph-rush-shell-tab-complete_2020-08-01-22-06.json +++ b/common/changes/@microsoft/rush/sachinjoseph-rush-shell-tab-complete_2020-08-01-22-06.json @@ -2,8 +2,8 @@ "changes": [ { "packageName": "@microsoft/rush", - "comment": "", - "type": "none" + "comment": "Add support for shell tab completion.", + "type": "minor" } ], "packageName": "@microsoft/rush", diff --git a/common/changes/@rushstack/node-core-library/sachinjoseph-rush-shell-tab-complete_2020-08-01-22-06.json b/common/changes/@rushstack/node-core-library/sachinjoseph-rush-shell-tab-complete_2020-08-01-22-06.json index 162425000f8..3763d0a2457 100644 --- a/common/changes/@rushstack/node-core-library/sachinjoseph-rush-shell-tab-complete_2020-08-01-22-06.json +++ b/common/changes/@rushstack/node-core-library/sachinjoseph-rush-shell-tab-complete_2020-08-01-22-06.json @@ -2,8 +2,8 @@ "changes": [ { "packageName": "@rushstack/node-core-library", - "comment": "Lazy-import some packages to improve spin up times.", - "type": "patch" + "comment": "Create a lighter weight function to get own package version. Lazy-import some packages to improve spin up times.", + "type": "minor" } ], "packageName": "@rushstack/node-core-library", diff --git a/common/changes/@rushstack/ts-command-line/sachinjoseph-rush-shell-tab-complete_2020-08-01-22-06.json b/common/changes/@rushstack/ts-command-line/sachinjoseph-rush-shell-tab-complete_2020-08-01-22-06.json index 48aafc0a599..2b27472b38f 100644 --- a/common/changes/@rushstack/ts-command-line/sachinjoseph-rush-shell-tab-complete_2020-08-01-22-06.json +++ b/common/changes/@rushstack/ts-command-line/sachinjoseph-rush-shell-tab-complete_2020-08-01-22-06.json @@ -2,7 +2,7 @@ "changes": [ { "packageName": "@rushstack/ts-command-line", - "comment": "Create a lighter weight function to get own package version.", + "comment": "Add support for shell tab completion.", "type": "minor" } ], From e81bc620c1e16f634894d9e69df8427a59382c8f Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Sun, 2 Aug 2020 16:49:29 -0700 Subject: [PATCH 49/97] Move 'tab-complete' to a constant --- .../actions/test/TabCompleteAction.test.ts | 297 ------------------ apps/rush-lib/src/utilities/Utilities.ts | 6 +- common/reviews/api/ts-command-line.api.md | 5 + libraries/ts-command-line/src/Constants.ts | 14 + libraries/ts-command-line/src/index.ts | 2 + 5 files changed, 23 insertions(+), 301 deletions(-) delete mode 100644 apps/rush-lib/src/cli/actions/test/TabCompleteAction.test.ts create mode 100644 libraries/ts-command-line/src/Constants.ts diff --git a/apps/rush-lib/src/cli/actions/test/TabCompleteAction.test.ts b/apps/rush-lib/src/cli/actions/test/TabCompleteAction.test.ts deleted file mode 100644 index 7a60938ff0b..00000000000 --- a/apps/rush-lib/src/cli/actions/test/TabCompleteAction.test.ts +++ /dev/null @@ -1,297 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. -// See LICENSE in the project root for license information. - -import '../../test/mockRushCommandLineParser'; - -import * as path from 'path'; - -import { TabCompleteAction } from '../TabCompleteAction'; -import { RushCommandLineParser } from '../../RushCommandLineParser'; - -function arrayEqual(actual: string[], expected: string[]): boolean { - return ( - actual.length === expected.length && - actual.sort().every((v: string, i: number) => { - return v === expected.sort()[i]; - }) - ); -} - -describe('TabCompleteAction', () => { - let oldExitCode: number | undefined; - let oldArgs: string[]; - - beforeEach(() => { - jest.spyOn(process, 'exit').mockImplementation(); - oldExitCode = process.exitCode; - oldArgs = process.argv; - }); - - afterEach(() => { - jest.clearAllMocks(); - process.exitCode = oldExitCode; - process.argv = oldArgs; - }); - - describe(`Gets TabCompletions`, () => { - it(`gets completion(s) for rush `, () => { - const startPath: string = path.resolve(__dirname, 'tabComplete'); - // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit - // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test - // repo will fail due to contention over the same lock which is kept until the test runner process - // ends. - jest.spyOn(process, 'cwd').mockReturnValue(startPath); - const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); - const tc: TabCompleteAction = new TabCompleteAction(parser); - - const commandLine: string = 'rush'; - const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); - - expect(actual.indexOf('add') !== -1).toBe(true); - expect(actual.indexOf('check') !== -1).toBe(true); - expect(actual.indexOf('build') !== -1).toBe(true); - expect(actual.indexOf('rebuild') !== -1).toBe(true); - expect(actual.indexOf('-d') !== -1).toBe(true); - expect(actual.indexOf('--debug') !== -1).toBe(true); - expect(actual.indexOf('--help') !== -1).toBe(true); - }); - - it(`gets completion(s) for rush a`, () => { - const startPath: string = path.resolve(__dirname, 'tabComplete'); - // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit - // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test - // repo will fail due to contention over the same lock which is kept until the test runner process - // ends. - jest.spyOn(process, 'cwd').mockReturnValue(startPath); - const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); - const tc: TabCompleteAction = new TabCompleteAction(parser); - - const commandLine: string = 'rush a'; - const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); - - const expected: string[] = ['add']; - - expect(arrayEqual(actual, expected)).toBe(true); - }); - - it(`gets completion(s) for rush build `, () => { - const startPath: string = path.resolve(__dirname, 'tabComplete'); - // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit - // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test - // repo will fail due to contention over the same lock which is kept until the test runner process - // ends. - jest.spyOn(process, 'cwd').mockReturnValue(startPath); - const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); - const tc: TabCompleteAction = new TabCompleteAction(parser); - - const commandLine: string = 'rush build '; - const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); - - expect(actual.indexOf('-t') !== -1).toBe(true); - expect(actual.indexOf('--to') !== -1).toBe(true); - expect(actual.indexOf('-f') !== -1).toBe(true); - expect(actual.indexOf('--from') !== -1).toBe(true); - }); - - it(`gets completion(s) for rush build -`, () => { - const startPath: string = path.resolve(__dirname, 'tabComplete'); - // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit - // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test - // repo will fail due to contention over the same lock which is kept until the test runner process - // ends. - jest.spyOn(process, 'cwd').mockReturnValue(startPath); - const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); - const tc: TabCompleteAction = new TabCompleteAction(parser); - - const commandLine: string = 'rush build -'; - const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); - - expect(actual.indexOf('-t') !== -1).toBe(true); - expect(actual.indexOf('--to') !== -1).toBe(true); - expect(actual.indexOf('-f') !== -1).toBe(true); - expect(actual.indexOf('--from') !== -1).toBe(true); - }); - - it(`gets completion(s) for rush build -t `, () => { - const startPath: string = path.resolve(__dirname, 'tabComplete'); - // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit - // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test - // repo will fail due to contention over the same lock which is kept until the test runner process - // ends. - jest.spyOn(process, 'cwd').mockReturnValue(startPath); - const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); - const tc: TabCompleteAction = new TabCompleteAction(parser); - - const commandLine: string = 'rush build -t '; - const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); - - const expected: string[] = ['abc', 'def']; - - expect(arrayEqual(actual, expected)).toBe(true); - }); - - it(`gets completion(s) for rush build -t a`, () => { - const startPath: string = path.resolve(__dirname, 'tabComplete'); - // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit - // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test - // repo will fail due to contention over the same lock which is kept until the test runner process - // ends. - jest.spyOn(process, 'cwd').mockReturnValue(startPath); - const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); - const tc: TabCompleteAction = new TabCompleteAction(parser); - - const commandLine: string = 'rush build -t a'; - const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); - - const expected: string[] = ['abc']; - - expect(arrayEqual(actual, expected)).toBe(true); - }); - - it(`gets completion(s) for rush change --bump-type `, () => { - const startPath: string = path.resolve(__dirname, 'tabComplete'); - // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit - // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test - // repo will fail due to contention over the same lock which is kept until the test runner process - // ends. - jest.spyOn(process, 'cwd').mockReturnValue(startPath); - const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); - const tc: TabCompleteAction = new TabCompleteAction(parser); - - const commandLine: string = 'rush change --bump-type '; - const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); - - const expected: string[] = ['major', 'minor', 'patch', 'none']; - - expect(arrayEqual(actual, expected)).toBe(true); - }); - - it(`gets completion(s) for rush change --bulk `, () => { - const startPath: string = path.resolve(__dirname, 'tabComplete'); - // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit - // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test - // repo will fail due to contention over the same lock which is kept until the test runner process - // ends. - jest.spyOn(process, 'cwd').mockReturnValue(startPath); - const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); - const tc: TabCompleteAction = new TabCompleteAction(parser); - - const commandLine: string = 'rush change --bulk '; - const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); - - expect(actual.indexOf('--bulk') !== -1).toBe(true); - expect(actual.indexOf('--message') !== -1).toBe(true); - expect(actual.indexOf('--bump-type') !== -1).toBe(true); - expect(actual.indexOf('--verify') !== -1).toBe(true); - }); - - it(`gets completion(s) for rush change --bump-type m`, () => { - const startPath: string = path.resolve(__dirname, 'tabComplete'); - // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit - // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test - // repo will fail due to contention over the same lock which is kept until the test runner process - // ends. - jest.spyOn(process, 'cwd').mockReturnValue(startPath); - const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); - const tc: TabCompleteAction = new TabCompleteAction(parser); - - const commandLine: string = 'rush change --bump-type m'; - const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); - - const expected: string[] = ['major', 'minor']; - - expect(arrayEqual(actual, expected)).toBe(true); - }); - - it(`gets completion(s) for rush change --message `, () => { - const startPath: string = path.resolve(__dirname, 'tabComplete'); - // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit - // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test - // repo will fail due to contention over the same lock which is kept until the test runner process - // ends. - jest.spyOn(process, 'cwd').mockReturnValue(startPath); - const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); - const tc: TabCompleteAction = new TabCompleteAction(parser); - - const commandLine: string = 'rush change --message '; - const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); - - const expected: string[] = []; - - expect(arrayEqual(actual, expected)).toBe(true); - }); - - it(`gets completion(s) for rush change --message "my change log message" --bump-type `, () => { - const startPath: string = path.resolve(__dirname, 'tabComplete'); - // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit - // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test - // repo will fail due to contention over the same lock which is kept until the test runner process - // ends. - jest.spyOn(process, 'cwd').mockReturnValue(startPath); - const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); - const tc: TabCompleteAction = new TabCompleteAction(parser); - - const commandLine: string = 'rush change --message "my change log message" --bump-type '; - const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); - - const expected: string[] = ['major', 'minor', 'patch', 'none']; - - expect(arrayEqual(actual, expected)).toBe(true); - }); - - it(`gets completion(s) for rush change --message "my change log message" --bump-type m`, () => { - const startPath: string = path.resolve(__dirname, 'tabComplete'); - // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit - // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test - // repo will fail due to contention over the same lock which is kept until the test runner process - // ends. - jest.spyOn(process, 'cwd').mockReturnValue(startPath); - const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); - const tc: TabCompleteAction = new TabCompleteAction(parser); - - const commandLine: string = 'rush change --message "my change log message" --bump-type m'; - const actual: string[] = Array.from(tc.getCompletions(commandLine.trim(), commandLine.length)); - - const expected: string[] = ['major', 'minor']; - - expect(arrayEqual(actual, expected)).toBe(true); - }); - }); - - describe(`Tokenize command line`, () => { - it(`tokenizes "rush change -"`, () => { - const startPath: string = path.resolve(__dirname, 'tabComplete'); - // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit - // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test - // repo will fail due to contention over the same lock which is kept until the test runner process - // ends. - jest.spyOn(process, 'cwd').mockReturnValue(startPath); - const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); - const tc: TabCompleteAction = new TabCompleteAction(parser); - - const commandLine: string = 'rush change -'; - const actual: string[] = Array.from(tc.tokenizeCommandLine(commandLine.trim())); - - const expected: string[] = ['rush', 'change', '-']; - - expect(arrayEqual(actual, expected)).toBe(true); - }); - it(`tokenizes 'rush change -m "my change log"'`, () => { - const startPath: string = path.resolve(__dirname, 'tabComplete'); - // Create a Rush CLI instance. This instance is heavy-weight and relies on setting process.exit - // to exit and clear the Rush file lock. So running multiple `it` or `describe` test blocks over the same test - // repo will fail due to contention over the same lock which is kept until the test runner process - // ends. - jest.spyOn(process, 'cwd').mockReturnValue(startPath); - const parser: RushCommandLineParser = new RushCommandLineParser({ cwd: startPath }); - const tc: TabCompleteAction = new TabCompleteAction(parser); - - const commandLine: string = 'rush change -m "my change log"'; - const actual: string[] = Array.from(tc.tokenizeCommandLine(commandLine.trim())); - - const expected: string[] = ['rush', 'change', '-m', 'my change log']; - - expect(arrayEqual(actual, expected)).toBe(true); - }); - }); -}); diff --git a/apps/rush-lib/src/utilities/Utilities.ts b/apps/rush-lib/src/utilities/Utilities.ts index dbc6bad1f4c..46ba3fbe49e 100644 --- a/apps/rush-lib/src/utilities/Utilities.ts +++ b/apps/rush-lib/src/utilities/Utilities.ts @@ -10,6 +10,7 @@ import * as wordwrap from 'wordwrap'; import { JsonFile, IPackageJson, FileSystem, FileConstants } from '@rushstack/node-core-library'; import { RushConfiguration } from '../api/RushConfiguration'; import { Stream } from 'stream'; +import { CommandLineConstants } from '@rushstack/ts-command-line'; export interface IEnvironment { // NOTE: the process.env doesn't actually support "undefined" as a value. @@ -443,10 +444,7 @@ export class Utilities { } public static isNonDebugTabCompletionRequest(): boolean { - return ( - (process.argv.length > 2 && process.argv[2] === 'tab-complete') || - (process.argv.length > 2 && process.argv[2] === 'tab-complete2') - ); + return process.argv.length > 2 && process.argv[2] === CommandLineConstants.TabCompletionParameterName; } public static shouldPrintBanner(): boolean { diff --git a/common/reviews/api/ts-command-line.api.md b/common/reviews/api/ts-command-line.api.md index efba0b1771f..a77cc858d2e 100644 --- a/common/reviews/api/ts-command-line.api.md +++ b/common/reviews/api/ts-command-line.api.md @@ -40,6 +40,11 @@ export class CommandLineChoiceParameter extends CommandLineParameter { readonly value: string | undefined; } +// @public +export const enum CommandLineConstants { + TabCompletionParameterName = "tab-complete" +} + // @public export class CommandLineFlagParameter extends CommandLineParameter { // @internal diff --git a/libraries/ts-command-line/src/Constants.ts b/libraries/ts-command-line/src/Constants.ts new file mode 100644 index 00000000000..9cf6f1d0e7e --- /dev/null +++ b/libraries/ts-command-line/src/Constants.ts @@ -0,0 +1,14 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. +// See LICENSE in the project root for license information. + +/** + * String constants for parts of filenames. + * + * @public + */ +export const enum CommandLineConstants { + /** + * "package.json" - the configuration file that defines an NPM package + */ + TabCompletionParameterName = 'tab-complete' +} diff --git a/libraries/ts-command-line/src/index.ts b/libraries/ts-command-line/src/index.ts index 169bc69e105..60cd18423d5 100644 --- a/libraries/ts-command-line/src/index.ts +++ b/libraries/ts-command-line/src/index.ts @@ -43,3 +43,5 @@ export { ICommandLineParserOptions, CommandLineParser } from './providers/Comman export { DynamicCommandLineAction } from './providers/DynamicCommandLineAction'; export { DynamicCommandLineParser } from './providers/DynamicCommandLineParser'; + +export { CommandLineConstants } from './Constants'; From 0b9bc4414fa8d83ff1ed71d9555ac9f59ed24db4 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Sun, 2 Aug 2020 17:02:54 -0700 Subject: [PATCH 50/97] Cache the test object --- common/reviews/api/ts-command-line.api.md | 2 - .../src/parameters/CommandLineDefinition.ts | 2 +- .../src/test/TabCompleteAction.test.ts | 99 +------------------ 3 files changed, 4 insertions(+), 99 deletions(-) diff --git a/common/reviews/api/ts-command-line.api.md b/common/reviews/api/ts-command-line.api.md index a77cc858d2e..b06c4f0e1e0 100644 --- a/common/reviews/api/ts-command-line.api.md +++ b/common/reviews/api/ts-command-line.api.md @@ -77,7 +77,6 @@ export abstract class CommandLineParameter { // @internal constructor(definition: IBaseCommandLineDefinition); abstract appendToArgList(argList: string[]): void; - // (undocumented) readonly completions: (() => Promise) | undefined; readonly description: string; readonly environmentVariable: string | undefined; @@ -207,7 +206,6 @@ export class DynamicCommandLineParser extends CommandLineParser { // @public export interface IBaseCommandLineDefinition { - // (undocumented) completions?: () => Promise; description: string; environmentVariable?: string; diff --git a/libraries/ts-command-line/src/parameters/CommandLineDefinition.ts b/libraries/ts-command-line/src/parameters/CommandLineDefinition.ts index b4a566e34b8..aaf8ad7f40a 100644 --- a/libraries/ts-command-line/src/parameters/CommandLineDefinition.ts +++ b/libraries/ts-command-line/src/parameters/CommandLineDefinition.ts @@ -64,7 +64,7 @@ export interface IBaseCommandLineDefinition { environmentVariable?: string; /** - * + * Custom tab completions for the parameter values. */ completions?: () => Promise; } diff --git a/libraries/ts-command-line/src/test/TabCompleteAction.test.ts b/libraries/ts-command-line/src/test/TabCompleteAction.test.ts index e41980fe1fb..18fd7f1ca88 100644 --- a/libraries/ts-command-line/src/test/TabCompleteAction.test.ts +++ b/libraries/ts-command-line/src/test/TabCompleteAction.test.ts @@ -208,14 +208,11 @@ function getCommandLineParser(): DynamicCommandLineParser { return commandLineParser; } +const commandLineParser: DynamicCommandLineParser = getCommandLineParser(); +const tc: TabCompleteAction = new TabCompleteAction(commandLineParser.actions, commandLineParser.parameters); + describe('Gets TabCompletion(s)', () => { it(`gets completion(s) for rush `, async () => { - const commandLineParser: DynamicCommandLineParser = getCommandLineParser(); - const tc: TabCompleteAction = new TabCompleteAction( - commandLineParser.actions, - commandLineParser.parameters - ); - const commandLine: string = 'rush '; const actual: string[] = await arrayFromAsyncIteractorAsync( tc.getCompletions(commandLine.trim(), commandLine.length) @@ -227,12 +224,6 @@ describe('Gets TabCompletion(s)', () => { }); it(`gets completion(s) for rush a`, async () => { - const commandLineParser: DynamicCommandLineParser = getCommandLineParser(); - const tc: TabCompleteAction = new TabCompleteAction( - commandLineParser.actions, - commandLineParser.parameters - ); - const commandLine: string = 'rush a'; const actual: string[] = await arrayFromAsyncIteractorAsync( tc.getCompletions(commandLine.trim(), commandLine.length) @@ -244,12 +235,6 @@ describe('Gets TabCompletion(s)', () => { }); it(`gets completion(s) for rush -d a`, async () => { - const commandLineParser: DynamicCommandLineParser = getCommandLineParser(); - const tc: TabCompleteAction = new TabCompleteAction( - commandLineParser.actions, - commandLineParser.parameters - ); - const commandLine: string = 'rush -d a'; const actual: string[] = await arrayFromAsyncIteractorAsync( tc.getCompletions(commandLine.trim(), commandLine.length) @@ -261,12 +246,6 @@ describe('Gets TabCompletion(s)', () => { }); it(`gets completion(s) for rush build `, async () => { - const commandLineParser: DynamicCommandLineParser = getCommandLineParser(); - const tc: TabCompleteAction = new TabCompleteAction( - commandLineParser.actions, - commandLineParser.parameters - ); - const commandLine: string = 'rush build '; const actual: string[] = await arrayFromAsyncIteractorAsync( tc.getCompletions(commandLine.trim(), commandLine.length) @@ -279,12 +258,6 @@ describe('Gets TabCompletion(s)', () => { }); it(`gets completion(s) for rush build -`, async () => { - const commandLineParser: DynamicCommandLineParser = getCommandLineParser(); - const tc: TabCompleteAction = new TabCompleteAction( - commandLineParser.actions, - commandLineParser.parameters - ); - const commandLine: string = 'rush build -'; const actual: string[] = await arrayFromAsyncIteractorAsync( tc.getCompletions(commandLine.trim(), commandLine.length) @@ -297,12 +270,6 @@ describe('Gets TabCompletion(s)', () => { }); it(`gets completion(s) for rush build -t `, async () => { - const commandLineParser: DynamicCommandLineParser = getCommandLineParser(); - const tc: TabCompleteAction = new TabCompleteAction( - commandLineParser.actions, - commandLineParser.parameters - ); - const commandLine: string = 'rush build -t '; const actual: string[] = await arrayFromAsyncIteractorAsync( tc.getCompletions(commandLine.trim(), commandLine.length) @@ -314,12 +281,6 @@ describe('Gets TabCompletion(s)', () => { }); it(`gets completion(s) for rush build -t a`, async () => { - const commandLineParser: DynamicCommandLineParser = getCommandLineParser(); - const tc: TabCompleteAction = new TabCompleteAction( - commandLineParser.actions, - commandLineParser.parameters - ); - const commandLine: string = 'rush build -t a'; const actual: string[] = await arrayFromAsyncIteractorAsync( tc.getCompletions(commandLine.trim(), commandLine.length) @@ -331,12 +292,6 @@ describe('Gets TabCompletion(s)', () => { }); it(`gets completion(s) for rush --debug build -t a`, async () => { - const commandLineParser: DynamicCommandLineParser = getCommandLineParser(); - const tc: TabCompleteAction = new TabCompleteAction( - commandLineParser.actions, - commandLineParser.parameters - ); - const commandLine: string = 'rush --debug build -t a'; const actual: string[] = await arrayFromAsyncIteractorAsync( tc.getCompletions(commandLine.trim(), commandLine.length) @@ -348,12 +303,6 @@ describe('Gets TabCompletion(s)', () => { }); it(`gets completion(s) for rush change --bump-type `, async () => { - const commandLineParser: DynamicCommandLineParser = getCommandLineParser(); - const tc: TabCompleteAction = new TabCompleteAction( - commandLineParser.actions, - commandLineParser.parameters - ); - const commandLine: string = 'rush change --bump-type '; const actual: string[] = await arrayFromAsyncIteractorAsync( tc.getCompletions(commandLine.trim(), commandLine.length) @@ -365,12 +314,6 @@ describe('Gets TabCompletion(s)', () => { }); it(`gets completion(s) for rush change --bulk `, async () => { - const commandLineParser: DynamicCommandLineParser = getCommandLineParser(); - const tc: TabCompleteAction = new TabCompleteAction( - commandLineParser.actions, - commandLineParser.parameters - ); - const commandLine: string = 'rush change --bulk '; const actual: string[] = await arrayFromAsyncIteractorAsync( tc.getCompletions(commandLine.trim(), commandLine.length) @@ -383,12 +326,6 @@ describe('Gets TabCompletion(s)', () => { }); it(`gets completion(s) for rush change --bump-type m`, async () => { - const commandLineParser: DynamicCommandLineParser = getCommandLineParser(); - const tc: TabCompleteAction = new TabCompleteAction( - commandLineParser.actions, - commandLineParser.parameters - ); - const commandLine: string = 'rush change --bump-type m'; const actual: string[] = await arrayFromAsyncIteractorAsync( tc.getCompletions(commandLine.trim(), commandLine.length) @@ -400,12 +337,6 @@ describe('Gets TabCompletion(s)', () => { }); it(`gets completion(s) for rush change --message `, async () => { - const commandLineParser: DynamicCommandLineParser = getCommandLineParser(); - const tc: TabCompleteAction = new TabCompleteAction( - commandLineParser.actions, - commandLineParser.parameters - ); - const commandLine: string = 'rush change --message '; const actual: string[] = await arrayFromAsyncIteractorAsync( tc.getCompletions(commandLine.trim(), commandLine.length) @@ -417,12 +348,6 @@ describe('Gets TabCompletion(s)', () => { }); it(`gets completion(s) for rush change --message "my change log message" --bump-type `, async () => { - const commandLineParser: DynamicCommandLineParser = getCommandLineParser(); - const tc: TabCompleteAction = new TabCompleteAction( - commandLineParser.actions, - commandLineParser.parameters - ); - const commandLine: string = 'rush change --message "my change log message" --bump-type '; const actual: string[] = await arrayFromAsyncIteractorAsync( tc.getCompletions(commandLine.trim(), commandLine.length) @@ -434,12 +359,6 @@ describe('Gets TabCompletion(s)', () => { }); it(`gets completion(s) for rush change --message "my change log message" --bump-type m`, async () => { - const commandLineParser: DynamicCommandLineParser = getCommandLineParser(); - const tc: TabCompleteAction = new TabCompleteAction( - commandLineParser.actions, - commandLineParser.parameters - ); - const commandLine: string = 'rush change --message "my change log message" --bump-type m'; const actual: string[] = await arrayFromAsyncIteractorAsync( tc.getCompletions(commandLine.trim(), commandLine.length) @@ -453,12 +372,6 @@ describe('Gets TabCompletion(s)', () => { describe(`Tokenize command line`, () => { it(`tokenizes "rush change -"`, () => { - const commandLineParser: DynamicCommandLineParser = getCommandLineParser(); - const tc: TabCompleteAction = new TabCompleteAction( - commandLineParser.actions, - commandLineParser.parameters - ); - const commandLine: string = 'rush change -'; const actual: string[] = tc.tokenizeCommandLine(commandLine.trim()); @@ -467,12 +380,6 @@ describe(`Tokenize command line`, () => { expect(actual.sort()).toEqual(expected.sort()); }); it(`tokenizes 'rush change -m "my change log"'`, () => { - const commandLineParser: DynamicCommandLineParser = getCommandLineParser(); - const tc: TabCompleteAction = new TabCompleteAction( - commandLineParser.actions, - commandLineParser.parameters - ); - const commandLine: string = 'rush change -m "my change log"'; const actual: string[] = tc.tokenizeCommandLine(commandLine.trim()); From 9644cd221760431770779e008948376fe283e89f Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Sun, 2 Aug 2020 17:16:36 -0700 Subject: [PATCH 51/97] Remove commented out code --- .../installManager/RushInstallManager.ts | 19 ++++--------------- .../src/parameters/CommandLineDefinition.ts | 2 +- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/apps/rush-lib/src/logic/installManager/RushInstallManager.ts b/apps/rush-lib/src/logic/installManager/RushInstallManager.ts index 99b80897c84..cacfeaad1a3 100644 --- a/apps/rush-lib/src/logic/installManager/RushInstallManager.ts +++ b/apps/rush-lib/src/logic/installManager/RushInstallManager.ts @@ -37,21 +37,6 @@ import { AlreadyReportedError } from '../../utilities/AlreadyReportedError'; import { LinkManagerFactory } from '../LinkManagerFactory'; import { BaseLinkManager } from '../base/BaseLinkManager'; -/** - * The "noMtime" flag is new in tar@4.4.1 and not available yet for \@types/tar. - * As a temporary workaround, augment the type. - */ -// declare module 'tar' { -// // eslint-disable-next-line @typescript-eslint/naming-convention -// export interface CreateOptions { -// /** -// * "Set to true to omit writing mtime values for entries. Note that this prevents using other -// * mtime-based features like tar.update or the keepNewer option with the resulting tar archive." -// */ -// noMtime?: boolean; -// } -// } - /** * This class implements common logic between "rush install" and "rush update". */ @@ -361,6 +346,10 @@ export class RushInstallManager extends BaseInstallManager { file: tarballFile, cwd: tempProjectFolder, portable: true, + /** + * Set to true to omit writing mtime values for entries. Note that this prevents using other + * mtime-based features like tar.update or the keepNewer option with the resulting tar archive. + */ noMtime: true, noPax: true, sync: true, diff --git a/libraries/ts-command-line/src/parameters/CommandLineDefinition.ts b/libraries/ts-command-line/src/parameters/CommandLineDefinition.ts index aaf8ad7f40a..e28543ea1bc 100644 --- a/libraries/ts-command-line/src/parameters/CommandLineDefinition.ts +++ b/libraries/ts-command-line/src/parameters/CommandLineDefinition.ts @@ -64,7 +64,7 @@ export interface IBaseCommandLineDefinition { environmentVariable?: string; /** - * Custom tab completions for the parameter values. + * Custom tab completions for the parameter values */ completions?: () => Promise; } From 897312ffcec2a5ebc28190bfba212a33507c1a0e Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Sun, 2 Aug 2020 17:19:16 -0700 Subject: [PATCH 52/97] Use getOwnPackageVersion to reduce spin up times --- apps/rush/src/start.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/rush/src/start.ts b/apps/rush/src/start.ts index e5d7b65eca1..7b24f81134a 100644 --- a/apps/rush/src/start.ts +++ b/apps/rush/src/start.ts @@ -34,7 +34,7 @@ const configuration: | MinimalRushConfiguration | undefined = MinimalRushConfiguration.loadFromDefaultLocation(); -const currentPackageVersion: string = PackageJsonLookup.loadOwnPackageJson(__dirname).version; +const currentPackageVersion: string = PackageJsonLookup.getOwnPackageJsonVersion(__dirname); let rushVersionToLoad: string | undefined = undefined; From ba4259521a60904f0b6571c42c25bd632cef14d1 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Sun, 2 Aug 2020 18:21:34 -0700 Subject: [PATCH 53/97] Some refactoring --- .../src/cli/scriptActions/BulkScriptAction.ts | 3 +- .../src/providers/TabCompletionAction.ts | 52 +++++++++++-------- 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/apps/rush-lib/src/cli/scriptActions/BulkScriptAction.ts b/apps/rush-lib/src/cli/scriptActions/BulkScriptAction.ts index 4b25b7d5376..7f8812b0199 100644 --- a/apps/rush-lib/src/cli/scriptActions/BulkScriptAction.ts +++ b/apps/rush-lib/src/cli/scriptActions/BulkScriptAction.ts @@ -195,7 +195,8 @@ export class BulkScriptAction extends BaseScriptAction { argumentName: 'PROJECT2', description: 'Run command in the specified project and all projects that directly or indirectly depend on the ' + - 'specified project. "." can be used as shorthand to specify the project in the current working directory.' + 'specified project. "." can be used as shorthand to specify the project in the current working directory.', + completions: this._getProjectNames.bind(this) }); this._verboseParameter = this.defineFlagParameter({ parameterLongName: '--verbose', diff --git a/libraries/ts-command-line/src/providers/TabCompletionAction.ts b/libraries/ts-command-line/src/providers/TabCompletionAction.ts index 28c80eed5cf..87d85392454 100644 --- a/libraries/ts-command-line/src/providers/TabCompletionAction.ts +++ b/libraries/ts-command-line/src/providers/TabCompletionAction.ts @@ -122,32 +122,31 @@ export class TabCompleteAction extends CommandLineAction { const parameterNames: string[] = Array.from(Object.keys(actions[actionName]), (x: string) => x); - for (const parameter of parameterNames) { - let choiceParameterValues: string[] = []; - if (parameterNameMap[parameter].kind === CommandLineParameterKind.Choice) { - choiceParameterValues = (parameterNameMap[parameter] as CommandLineChoiceParameter) - .alternatives as string[]; - } else if (parameterNameMap[parameter].completions) { - choiceParameterValues = await parameterNameMap[parameter].completions(); - } - if (choiceParameterValues.length > 0) { - if (completePartialWord) { - if (parameter === secondLastToken) { - yield* this._completeChoiceParameterValues(choiceParameterValues, lastToken); + if (completePartialWord) { + for (const parameterName of parameterNames) { + if (parameterName === secondLastToken) { + const values: string[] = await this._getParameterValueCompletions( + parameterNameMap[parameterName] + ); + if (values.length > 0) { + yield* this._completeParameterValues(values, lastToken); return; } - } else { - if (parameter === lastToken) { - yield* choiceParameterValues; + } + } + yield* this._completeParameterValues(parameterNames, lastToken); + } else { + for (const parameterName of parameterNames) { + if (parameterName === lastToken) { + const values: string[] = await this._getParameterValueCompletions( + parameterNameMap[parameterName] + ); + if (values.length > 0) { + yield* values; return; } } } - } - - if (completePartialWord) { - yield* this._completeChoiceParameterValues(parameterNames, lastToken); - } else { for (const parameter of parameterNames) { if ( parameter === lastToken && @@ -171,6 +170,17 @@ export class TabCompleteAction extends CommandLineAction { return stringArgv(commandLine); } + private async _getParameterValueCompletions(parameter: CommandLineParameter): Promise { + let choiceParameterValues: string[] = []; + if (parameter.kind === CommandLineParameterKind.Choice) { + choiceParameterValues = (parameter as CommandLineChoiceParameter).alternatives as string[]; + } else if (parameter.completions) { + choiceParameterValues = await parameter.completions(); + } + + return choiceParameterValues; + } + private _getGlobalParameterOffset(tokens: string[]): number { let count: number = 0; for (let i: number = 1; i < tokens.length; i++) { @@ -185,7 +195,7 @@ export class TabCompleteAction extends CommandLineAction { return count; } - private *_completeChoiceParameterValues( + private *_completeParameterValues( choiceParameterValues: string[], lastToken: string ): IterableIterator { From 86eaa97ab4dd8d85c0a7f0a7816d691f5e491dc5 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Sun, 2 Aug 2020 23:00:59 -0700 Subject: [PATCH 54/97] Rename constant. Update comment. --- apps/rush-lib/src/utilities/Utilities.ts | 2 +- common/reviews/api/ts-command-line.api.md | 2 +- libraries/ts-command-line/src/Constants.ts | 4 ++-- .../ts-command-line/src/providers/TabCompletionAction.ts | 3 ++- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/apps/rush-lib/src/utilities/Utilities.ts b/apps/rush-lib/src/utilities/Utilities.ts index 46ba3fbe49e..72449ca2457 100644 --- a/apps/rush-lib/src/utilities/Utilities.ts +++ b/apps/rush-lib/src/utilities/Utilities.ts @@ -444,7 +444,7 @@ export class Utilities { } public static isNonDebugTabCompletionRequest(): boolean { - return process.argv.length > 2 && process.argv[2] === CommandLineConstants.TabCompletionParameterName; + return process.argv.length > 2 && process.argv[2] === CommandLineConstants.TabCompletionActionName; } public static shouldPrintBanner(): boolean { diff --git a/common/reviews/api/ts-command-line.api.md b/common/reviews/api/ts-command-line.api.md index b06c4f0e1e0..7387a4f0489 100644 --- a/common/reviews/api/ts-command-line.api.md +++ b/common/reviews/api/ts-command-line.api.md @@ -42,7 +42,7 @@ export class CommandLineChoiceParameter extends CommandLineParameter { // @public export const enum CommandLineConstants { - TabCompletionParameterName = "tab-complete" + TabCompletionActionName = "tab-complete" } // @public diff --git a/libraries/ts-command-line/src/Constants.ts b/libraries/ts-command-line/src/Constants.ts index 9cf6f1d0e7e..19c5d17afea 100644 --- a/libraries/ts-command-line/src/Constants.ts +++ b/libraries/ts-command-line/src/Constants.ts @@ -8,7 +8,7 @@ */ export const enum CommandLineConstants { /** - * "package.json" - the configuration file that defines an NPM package + * The name of the built-in action that serves suggestions for tab-completion */ - TabCompletionParameterName = 'tab-complete' + TabCompletionActionName = 'tab-complete' } diff --git a/libraries/ts-command-line/src/providers/TabCompletionAction.ts b/libraries/ts-command-line/src/providers/TabCompletionAction.ts index 87d85392454..e116580037f 100644 --- a/libraries/ts-command-line/src/providers/TabCompletionAction.ts +++ b/libraries/ts-command-line/src/providers/TabCompletionAction.ts @@ -8,6 +8,7 @@ import { CommandLineStringParameter } from '../parameters/CommandLineStringParam import { CommandLineParameterKind, CommandLineParameter } from '../parameters/BaseClasses'; import { CommandLineAction } from './CommandLineAction'; import { CommandLineChoiceParameter } from '..'; +import { CommandLineConstants } from '../Constants'; interface IParameter { name: string; @@ -28,7 +29,7 @@ export class TabCompleteAction extends CommandLineAction { globalParameters: ReadonlyArray ) { super({ - actionName: 'tab-complete', + actionName: CommandLineConstants.TabCompletionActionName, summary: 'Provides tab completion.', documentation: 'Provides tab completion.' }); From 3ade0cd2d7cea906c01f07892ffddbe7ef25953f Mon Sep 17 00:00:00 2001 From: Sachin Joseph <6994498+sachinjoseph@users.noreply.github.com> Date: Mon, 3 Aug 2020 13:01:20 -0700 Subject: [PATCH 55/97] Update libraries/ts-command-line/src/providers/TabCompletionAction.ts Co-authored-by: Ian Clanton-Thuon --- libraries/ts-command-line/src/providers/TabCompletionAction.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/ts-command-line/src/providers/TabCompletionAction.ts b/libraries/ts-command-line/src/providers/TabCompletionAction.ts index e116580037f..d9391a15116 100644 --- a/libraries/ts-command-line/src/providers/TabCompletionAction.ts +++ b/libraries/ts-command-line/src/providers/TabCompletionAction.ts @@ -80,7 +80,7 @@ export class TabCompleteAction extends CommandLineAction { parameterNameToParameterInfoMap[parameter.shortName] = parameter; } }); - actions[action.actionName] = parameterNameToParameterInfoMap; + actions.set(action.actionName, parameterNameToParameterInfoMap); } for (const parameter of this._globalParameters) { From 7bab8f411ba429b31b0186057075a260e2cfab9e Mon Sep 17 00:00:00 2001 From: Sachin Joseph <6994498+sachinjoseph@users.noreply.github.com> Date: Mon, 3 Aug 2020 13:02:26 -0700 Subject: [PATCH 56/97] Update libraries/ts-command-line/src/providers/TabCompletionAction.ts Co-authored-by: Ian Clanton-Thuon --- .../ts-command-line/src/providers/TabCompletionAction.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/libraries/ts-command-line/src/providers/TabCompletionAction.ts b/libraries/ts-command-line/src/providers/TabCompletionAction.ts index d9391a15116..c21ec8c7a7f 100644 --- a/libraries/ts-command-line/src/providers/TabCompletionAction.ts +++ b/libraries/ts-command-line/src/providers/TabCompletionAction.ts @@ -55,10 +55,6 @@ export class TabCompleteAction extends CommandLineAction { } protected async onExecute(): Promise { - await this.runAsync(); - } - - protected async runAsync(): Promise { const commandLine: string = this._wordToCompleteParameter.value || ''; const caretPosition: number = this._positionParameter.value || 0; From d478180df5b6535d83c4b60fa298db3038a59bda Mon Sep 17 00:00:00 2001 From: Sachin Joseph <6994498+sachinjoseph@users.noreply.github.com> Date: Mon, 3 Aug 2020 13:03:12 -0700 Subject: [PATCH 57/97] Update apps/rush-lib/src/cli/actions/ListAction.ts Co-authored-by: Ian Clanton-Thuon --- apps/rush-lib/src/cli/actions/ListAction.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/rush-lib/src/cli/actions/ListAction.ts b/apps/rush-lib/src/cli/actions/ListAction.ts index f310d42073b..418c6460c42 100644 --- a/apps/rush-lib/src/cli/actions/ListAction.ts +++ b/apps/rush-lib/src/cli/actions/ListAction.ts @@ -9,7 +9,8 @@ import { RushCommandLineParser } from '../RushCommandLineParser'; import { CommandLineFlagParameter } from '@rushstack/ts-command-line'; import { RushConfigurationProject } from '../../api/RushConfigurationProject'; // eslint-disable-next-line -const Table = importLazy('cli-table'); +import type * as TTable from 'cli-table'; +const Table: typeof TTable = importLazy('cli-table'); export interface IJsonEntry { name: string; From 7563fced3dec0afdd2b9317dcb1c07aea972e91f Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Mon, 3 Aug 2020 15:10:25 -0700 Subject: [PATCH 58/97] Address comments --- apps/rush-lib/src/cli/actions/ListAction.ts | 3 +- apps/rush-lib/src/start.ts | 1 + .../src/providers/TabCompletionAction.ts | 105 ++++++++++-------- 3 files changed, 62 insertions(+), 47 deletions(-) diff --git a/apps/rush-lib/src/cli/actions/ListAction.ts b/apps/rush-lib/src/cli/actions/ListAction.ts index 418c6460c42..f310d42073b 100644 --- a/apps/rush-lib/src/cli/actions/ListAction.ts +++ b/apps/rush-lib/src/cli/actions/ListAction.ts @@ -9,8 +9,7 @@ import { RushCommandLineParser } from '../RushCommandLineParser'; import { CommandLineFlagParameter } from '@rushstack/ts-command-line'; import { RushConfigurationProject } from '../../api/RushConfigurationProject'; // eslint-disable-next-line -import type * as TTable from 'cli-table'; -const Table: typeof TTable = importLazy('cli-table'); +const Table = importLazy('cli-table'); export interface IJsonEntry { name: string; diff --git a/apps/rush-lib/src/start.ts b/apps/rush-lib/src/start.ts index 1abfb211ea0..b4da75c1edc 100644 --- a/apps/rush-lib/src/start.ts +++ b/apps/rush-lib/src/start.ts @@ -1,5 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. + import { Rush } from './api/Rush'; Rush.launch(Rush.version, { isManaged: false }); diff --git a/libraries/ts-command-line/src/providers/TabCompletionAction.ts b/libraries/ts-command-line/src/providers/TabCompletionAction.ts index c21ec8c7a7f..b28655f994f 100644 --- a/libraries/ts-command-line/src/providers/TabCompletionAction.ts +++ b/libraries/ts-command-line/src/providers/TabCompletionAction.ts @@ -10,19 +10,14 @@ import { CommandLineAction } from './CommandLineAction'; import { CommandLineChoiceParameter } from '..'; import { CommandLineConstants } from '../Constants'; -interface IParameter { - name: string; - parameterInfo: CommandLineParameter; -} - const DEFAULT_WORD_TO_AUTOCOMPLETE: string = ''; const DEFAULT_POSITION: number = 0; export class TabCompleteAction extends CommandLineAction { private _wordToCompleteParameter: CommandLineStringParameter; private _positionParameter: CommandLineIntegerParameter; - private _actions: ReadonlyArray; - private _globalParameters: ReadonlyArray; + private readonly _actions: Map>; + private readonly _globalParameters: Map; public constructor( actions: ReadonlyArray, @@ -34,8 +29,28 @@ export class TabCompleteAction extends CommandLineAction { documentation: 'Provides tab completion.' }); - this._actions = actions; - this._globalParameters = globalParameters; + this._actions = new Map>(); + for (const action of actions) { + const parameterNameToParameterInfoMap: Map = new Map< + string, + CommandLineParameter + >(); + for (const parameter of action.parameters) { + parameterNameToParameterInfoMap.set(parameter.longName, parameter); + if (parameter.shortName) { + parameterNameToParameterInfoMap.set(parameter.shortName, parameter); + } + } + this._actions.set(action.actionName, parameterNameToParameterInfoMap); + } + + this._globalParameters = new Map(); + for (const parameter of globalParameters) { + this._globalParameters.set(parameter.longName, parameter); + if (parameter.shortName) { + this._globalParameters.set(parameter.shortName, parameter); + } + } } protected onDefineParameters(): void { @@ -64,30 +79,10 @@ export class TabCompleteAction extends CommandLineAction { } public async *getCompletions(commandLine: string, caretPosition: number): AsyncIterable { - const actions: Map> = new Map< - string, - Map - >(); - for (const action of this._actions) { - const parameterNameToParameterInfoMap: IParameter[] = []; - action.parameters.forEach((parameter) => { - parameterNameToParameterInfoMap[parameter.longName] = parameter; - if (parameter.shortName) { - parameterNameToParameterInfoMap[parameter.shortName] = parameter; - } - }); - actions.set(action.actionName, parameterNameToParameterInfoMap); - } - - for (const parameter of this._globalParameters) { - actions[parameter.longName] = parameter; - if (parameter.shortName) { - actions[parameter.shortName] = parameter; - } - } + const actions: Map> = this._actions; if (!commandLine || !caretPosition) { - yield* Object.keys(actions); // return all actions + yield* this._getAllActions(); return; } @@ -96,8 +91,14 @@ export class TabCompleteAction extends CommandLineAction { // offset arguments by the number of global params in the input const globalParameterOffset: number = this._getGlobalParameterOffset(tokens); + // for (let i: number = 0; i < tokens.length; i++) { + // yield 'token'+ i + tokens[i]; + // } + + // yield 'globalParameterOffset'+globalParameterOffset; + if (tokens.length < 2 + globalParameterOffset) { - yield* Object.keys(actions); // return all actions + yield* this._getAllActions(); return; } @@ -107,23 +108,29 @@ export class TabCompleteAction extends CommandLineAction { const completePartialWord: boolean = caretPosition === commandLine.length; if (completePartialWord && tokens.length === 2 + globalParameterOffset) { - for (const actionName of Object.keys(actions)) { + // yield 'a1'; + // yield 'tokens1gl0'+tokens[1 + globalParameterOffset] + for (const actionName of actions.keys()) { + // yield 'a1' + actionName; if (actionName.indexOf(tokens[1 + globalParameterOffset]) === 0) { yield actionName; } } } else { - for (const actionName of Object.keys(actions)) { + // yield 'b1'; + for (const actionName of actions.keys()) { if (actionName === tokens[1 + globalParameterOffset]) { - const parameterNameMap: Map = actions[actionName]; + // yield 'c1' + actionName; + const parameterNameMap: Map = actions.get(actionName)!; - const parameterNames: string[] = Array.from(Object.keys(actions[actionName]), (x: string) => x); + const parameterNames: string[] = Array.from(parameterNameMap.keys()); if (completePartialWord) { + // yield 'd1'; for (const parameterName of parameterNames) { if (parameterName === secondLastToken) { const values: string[] = await this._getParameterValueCompletions( - parameterNameMap[parameterName] + parameterNameMap.get(parameterName)! ); if (values.length > 0) { yield* this._completeParameterValues(values, lastToken); @@ -133,10 +140,11 @@ export class TabCompleteAction extends CommandLineAction { } yield* this._completeParameterValues(parameterNames, lastToken); } else { + // yield 'e1'; for (const parameterName of parameterNames) { if (parameterName === lastToken) { const values: string[] = await this._getParameterValueCompletions( - parameterNameMap[parameterName] + parameterNameMap.get(parameterName)! ); if (values.length > 0) { yield* values; @@ -144,10 +152,10 @@ export class TabCompleteAction extends CommandLineAction { } } } - for (const parameter of parameterNames) { + for (const parameterName of parameterNames) { if ( - parameter === lastToken && - parameterNameMap[parameter].kind !== CommandLineParameterKind.Flag + parameterName === lastToken && + parameterNameMap.get(parameterName)!.kind !== CommandLineParameterKind.Flag ) { // The parameter is expecting a value, so don't suggest parameter names again return; @@ -163,6 +171,11 @@ export class TabCompleteAction extends CommandLineAction { } } + private *_getAllActions(): IterableIterator { + yield* this._actions.keys(); + yield* this._globalParameters.keys(); + } + public tokenizeCommandLine(commandLine: string): string[] { return stringArgv(commandLine); } @@ -179,14 +192,16 @@ export class TabCompleteAction extends CommandLineAction { } private _getGlobalParameterOffset(tokens: string[]): number { + const globalParameters: Map = this._globalParameters; let count: number = 0; - for (let i: number = 1; i < tokens.length; i++) { - for (const globalParameter of this._globalParameters) { + + outer: for (let i: number = 1; i < tokens.length; i++) { + for (const globalParameter of globalParameters.values()) { if (tokens[i] !== globalParameter.longName && tokens[i] !== globalParameter.shortName) { - break; + break outer; } - count++; } + count++; } return count; From a2075e68345a4c232a105a7fe4039e812a084dae Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Mon, 3 Aug 2020 15:15:39 -0700 Subject: [PATCH 59/97] Address comments --- common/config/rush/browser-approved-packages.json | 11 +---------- common/config/rush/nonbrowser-approved-packages.json | 4 ++++ 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/common/config/rush/browser-approved-packages.json b/common/config/rush/browser-approved-packages.json index 1ac66e34b6d..34c3a91cc03 100644 --- a/common/config/rush/browser-approved-packages.json +++ b/common/config/rush/browser-approved-packages.json @@ -1,14 +1,5 @@ // DO NOT ADD COMMENTS IN THIS FILE. They will be lost when the Rush tool resaves it. { "$schema": "https://developer.microsoft.com/json-schemas/rush/v5/approved-packages.schema.json", - "packages": [ - { - "name": "minimist-string", - "allowedCategories": [ "libraries" ] - }, - { - "name": "string-argv", - "allowedCategories": [ "libraries" ] - } - ] + "packages": [] } diff --git a/common/config/rush/nonbrowser-approved-packages.json b/common/config/rush/nonbrowser-approved-packages.json index d163920d46d..9193c21d7f1 100644 --- a/common/config/rush/nonbrowser-approved-packages.json +++ b/common/config/rush/nonbrowser-approved-packages.json @@ -614,6 +614,10 @@ "name": "strict-uri-encode", "allowedCategories": [ "libraries" ] }, + { + "name": "string-argv", + "allowedCategories": [ "libraries" ] + }, { "name": "sudo", "allowedCategories": [ "libraries" ] From 2b5c73b19dcb4ba88e34ce414a5be85796bcf261 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Mon, 3 Aug 2020 15:52:57 -0700 Subject: [PATCH 60/97] Eslint disable - specify the rule. --- apps/rush-lib/src/api/LastInstallFlag.ts | 4 ++-- apps/rush-lib/src/api/VersionPolicy.ts | 4 ++-- apps/rush-lib/src/cli/actions/ChangeAction.ts | 24 +++++++++---------- apps/rush-lib/src/cli/actions/ListAction.ts | 6 ++--- apps/rush-lib/src/cli/actions/ScanAction.ts | 4 ++-- apps/rush-lib/src/logic/ChangeFiles.ts | 4 ++-- apps/rush-lib/src/logic/Telemetry.ts | 4 ++-- apps/rush-lib/src/logic/VersionManager.ts | 4 ++-- .../src/logic/base/BaseInstallManager.ts | 4 ++-- .../src/logic/deploy/DeployArchiver.ts | 14 +++++------ .../src/logic/deploy/DeployManager.ts | 8 +++---- .../installManager/RushInstallManager.ts | 10 ++++---- apps/rush-lib/src/logic/npm/NpmLinkManager.ts | 6 ++--- .../src/logic/pnpm/PnpmLinkManager.ts | 4 ++-- .../src/logic/pnpm/PnpmShrinkwrapFile.ts | 4 ++-- .../src/logic/pnpm/PnpmWorkspaceFile.ts | 4 ++-- .../src/logic/yarn/YarnShrinkwrapFile.ts | 6 ++--- libraries/node-core-library/src/FileSystem.ts | 4 ++-- libraries/node-core-library/src/FileWriter.ts | 4 ++-- 19 files changed, 61 insertions(+), 61 deletions(-) diff --git a/apps/rush-lib/src/api/LastInstallFlag.ts b/apps/rush-lib/src/api/LastInstallFlag.ts index 52387957e3b..05326f1a62f 100644 --- a/apps/rush-lib/src/api/LastInstallFlag.ts +++ b/apps/rush-lib/src/api/LastInstallFlag.ts @@ -1,11 +1,11 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line +// eslint-disable-next-line @typescript-eslint/typedef const importLazy = require('import-lazy')(require); import * as path from 'path'; -// eslint-disable-next-line +// eslint-disable-next-line @typescript-eslint/typedef const _ = importLazy('lodash'); import { FileSystem, JsonFile, JsonObject } from '@rushstack/node-core-library'; diff --git a/apps/rush-lib/src/api/VersionPolicy.ts b/apps/rush-lib/src/api/VersionPolicy.ts index a9ebdbeca3c..1c6c10f650c 100644 --- a/apps/rush-lib/src/api/VersionPolicy.ts +++ b/apps/rush-lib/src/api/VersionPolicy.ts @@ -1,10 +1,10 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line +// eslint-disable-next-line @typescript-eslint/typedef const importLazy = require('import-lazy')(require); -// eslint-disable-next-line +// eslint-disable-next-line @typescript-eslint/typedef const _ = importLazy('lodash'); import * as semver from 'semver'; import { IPackageJson } from '@rushstack/node-core-library'; diff --git a/apps/rush-lib/src/cli/actions/ChangeAction.ts b/apps/rush-lib/src/cli/actions/ChangeAction.ts index 9d6314223d2..5a35be266a4 100644 --- a/apps/rush-lib/src/cli/actions/ChangeAction.ts +++ b/apps/rush-lib/src/cli/actions/ChangeAction.ts @@ -1,14 +1,14 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line +// eslint-disable-next-line @typescript-eslint/typedef const importLazy = require('import-lazy')(require); import * as os from 'os'; import * as path from 'path'; import * as child_process from 'child_process'; import * as colors from 'colors'; -// eslint-disable-next-line +// eslint-disable-next-line @typescript-eslint/typedef const inquirer = importLazy('inquirer'); import { @@ -182,7 +182,7 @@ export class ChangeAction extends BaseRushAction { this._warnUncommittedChanges(); - // eslint-disable-next-line + // eslint-disable-next-line @typescript-eslint/typedef const promptModule = inquirer.createPromptModule(); let changeFileData: Map = new Map(); let interactiveMode: boolean = false; @@ -371,7 +371,7 @@ export class ChangeAction extends BaseRushAction { * The main loop which prompts the user for information on changed projects. */ private async _promptForChangeFileData( - // eslint-disable-next-line + // eslint-disable-next-line @typescript-eslint/typedef promptModule, sortedProjectList: string[], existingChangeComments: Map @@ -407,7 +407,7 @@ export class ChangeAction extends BaseRushAction { * Asks all questions which are needed to generate changelist for a project. */ private async _askQuestions( - // eslint-disable-next-line + // eslint-disable-next-line @typescript-eslint/typedef promptModule, packageName: string, existingChangeComments: Map @@ -447,7 +447,7 @@ export class ChangeAction extends BaseRushAction { } private async _promptForComments( - // eslint-disable-next-line + // eslint-disable-next-line @typescript-eslint/typedef promptModule, packageName: string ): Promise { @@ -527,7 +527,7 @@ export class ChangeAction extends BaseRushAction { * Will determine a user's email by first detecting it from their Git config, * or will ask for it if it is not found or the Git config is wrong. */ - // eslint-disable-next-line + // eslint-disable-next-line @typescript-eslint/typedef private async _detectOrAskForEmail(promptModule): Promise { return (await this._detectAndConfirmEmail(promptModule)) || (await this._promptForEmail(promptModule)); } @@ -548,7 +548,7 @@ export class ChangeAction extends BaseRushAction { * Detects the user's email address from their Git configuration, prompts the user to approve the * detected email. It returns undefined if it cannot be detected. */ - // eslint-disable-next-line + // eslint-disable-next-line @typescript-eslint/typedef private async _detectAndConfirmEmail(promptModule): Promise { const email: string | undefined = this._detectEmail(); @@ -570,7 +570,7 @@ export class ChangeAction extends BaseRushAction { /** * Asks the user for their email address */ - // eslint-disable-next-line + // eslint-disable-next-line @typescript-eslint/typedef private async _promptForEmail(promptModule): Promise { const { email }: { email: string } = await promptModule([ { @@ -605,7 +605,7 @@ export class ChangeAction extends BaseRushAction { * Writes change files to the common/changes folder. Will prompt for overwrite if file already exists. */ private async _writeChangeFiles( - // eslint-disable-next-line + // eslint-disable-next-line @typescript-eslint/typedef promptModule, changeFileData: Map, overwrite: boolean, @@ -617,7 +617,7 @@ export class ChangeAction extends BaseRushAction { } private async _writeChangeFile( - // eslint-disable-next-line + // eslint-disable-next-line @typescript-eslint/typedef promptModule, changeFileData: IChangeFile, overwrite: boolean, @@ -642,7 +642,7 @@ export class ChangeAction extends BaseRushAction { } } - // eslint-disable-next-line + // eslint-disable-next-line @typescript-eslint/typedef private async _promptForOverwrite(promptModule, filePath: string): Promise { const overwrite: boolean = await promptModule([ { diff --git a/apps/rush-lib/src/cli/actions/ListAction.ts b/apps/rush-lib/src/cli/actions/ListAction.ts index f310d42073b..af151c0ae1e 100644 --- a/apps/rush-lib/src/cli/actions/ListAction.ts +++ b/apps/rush-lib/src/cli/actions/ListAction.ts @@ -1,14 +1,14 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line +// eslint-disable-next-line @typescript-eslint/typedef const importLazy = require('import-lazy')(require); import { BaseRushAction } from './BaseRushAction'; import { RushCommandLineParser } from '../RushCommandLineParser'; import { CommandLineFlagParameter } from '@rushstack/ts-command-line'; import { RushConfigurationProject } from '../../api/RushConfigurationProject'; -// eslint-disable-next-line +// eslint-disable-next-line @typescript-eslint/typedef const Table = importLazy('cli-table'); export interface IJsonEntry { @@ -118,7 +118,7 @@ export class ListAction extends BaseRushAction { tableHeader.push('Full Path'); } - // eslint-disable-next-line + // eslint-disable-next-line @typescript-eslint/typedef const table = new Table({ head: tableHeader }); diff --git a/apps/rush-lib/src/cli/actions/ScanAction.ts b/apps/rush-lib/src/cli/actions/ScanAction.ts index 052072811ac..41937b84733 100644 --- a/apps/rush-lib/src/cli/actions/ScanAction.ts +++ b/apps/rush-lib/src/cli/actions/ScanAction.ts @@ -1,11 +1,11 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line +// eslint-disable-next-line @typescript-eslint/typedef const importLazy = require('import-lazy')(require); import * as colors from 'colors'; -// eslint-disable-next-line +// eslint-disable-next-line @typescript-eslint/typedef const glob = importLazy('glob'); import * as path from 'path'; import * as builtinPackageNames from 'builtin-modules'; diff --git a/apps/rush-lib/src/logic/ChangeFiles.ts b/apps/rush-lib/src/logic/ChangeFiles.ts index 703e6c9d114..9244c36fc35 100644 --- a/apps/rush-lib/src/logic/ChangeFiles.ts +++ b/apps/rush-lib/src/logic/ChangeFiles.ts @@ -1,11 +1,11 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line +// eslint-disable-next-line @typescript-eslint/typedef const importLazy = require('import-lazy')(require); import { EOL } from 'os'; -// eslint-disable-next-line +// eslint-disable-next-line @typescript-eslint/typedef const glob = importLazy('glob'); import { JsonFile } from '@rushstack/node-core-library'; diff --git a/apps/rush-lib/src/logic/Telemetry.ts b/apps/rush-lib/src/logic/Telemetry.ts index db9f5dc61ec..8a8b6d600cb 100644 --- a/apps/rush-lib/src/logic/Telemetry.ts +++ b/apps/rush-lib/src/logic/Telemetry.ts @@ -1,12 +1,12 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line +// eslint-disable-next-line @typescript-eslint/typedef const importLazy = require('import-lazy')(require); import * as fs from 'fs'; import * as path from 'path'; -// eslint-disable-next-line +// eslint-disable-next-line @typescript-eslint/typedef const _ = importLazy('lodash'); import { FileSystem } from '@rushstack/node-core-library'; diff --git a/apps/rush-lib/src/logic/VersionManager.ts b/apps/rush-lib/src/logic/VersionManager.ts index 1b467baadb0..6f28d745f4d 100644 --- a/apps/rush-lib/src/logic/VersionManager.ts +++ b/apps/rush-lib/src/logic/VersionManager.ts @@ -1,12 +1,12 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line +// eslint-disable-next-line @typescript-eslint/typedef const importLazy = require('import-lazy')(require); import * as path from 'path'; import * as semver from 'semver'; -// eslint-disable-next-line +// eslint-disable-next-line @typescript-eslint/typedef const _ = importLazy('lodash'); import { IPackageJson, JsonFile, FileConstants } from '@rushstack/node-core-library'; diff --git a/apps/rush-lib/src/logic/base/BaseInstallManager.ts b/apps/rush-lib/src/logic/base/BaseInstallManager.ts index c68dfc64ac2..a5a00579116 100644 --- a/apps/rush-lib/src/logic/base/BaseInstallManager.ts +++ b/apps/rush-lib/src/logic/base/BaseInstallManager.ts @@ -1,14 +1,14 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line +// eslint-disable-next-line @typescript-eslint/typedef const importLazy = require('import-lazy')(require); import * as colors from 'colors'; import * as fetch from 'node-fetch'; import * as fs from 'fs'; import * as http from 'http'; -// eslint-disable-next-line +// eslint-disable-next-line @typescript-eslint/typedef const HttpsProxyAgent = importLazy('https-proxy-agent'); import * as os from 'os'; import * as path from 'path'; diff --git a/apps/rush-lib/src/logic/deploy/DeployArchiver.ts b/apps/rush-lib/src/logic/deploy/DeployArchiver.ts index 9f511436493..5dfbded3b24 100644 --- a/apps/rush-lib/src/logic/deploy/DeployArchiver.ts +++ b/apps/rush-lib/src/logic/deploy/DeployArchiver.ts @@ -1,10 +1,10 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line +// eslint-disable-next-line @typescript-eslint/typedef const importLazy = require('import-lazy')(require); -// eslint-disable-next-line +// eslint-disable-next-line @typescript-eslint/typedef const JSZip = importLazy('jszip'); import * as path from 'path'; import { FileSystem, FileSystemStats } from '@rushstack/node-core-library'; @@ -13,14 +13,14 @@ import { IDeployState } from './DeployManager'; // JSZip is dependant on Blob being declared. declare global { - // eslint-disable-next-line + // eslint-disable-next-line @typescript-eslint/no-explicit-any type Blob = any; } export class DeployArchiver { public static async createArchiveAsync(deployState: IDeployState): Promise { if (deployState.createArchiveFilePath !== undefined) { console.log('Creating archive...'); - // eslint-disable-next-line + // eslint-disable-next-line @typescript-eslint/typedef const zip = this._getZipOfFolder(deployState.targetRootFolder); const zipContent: Buffer = await zip.generateAsync({ type: 'nodebuffer', @@ -58,8 +58,8 @@ export class DeployArchiver { return results; } - // eslint-disable-next-line - private static _getZipOfFolder(dir: string) { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + private static _getZipOfFolder(dir: string): any { // returns a JSZip instance filled with contents of dir. const allPaths: string[] = this._getFilePathsRecursively(dir); @@ -68,7 +68,7 @@ export class DeployArchiver { // See: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/uapi/linux/stat.h#n10 const permissionsValue: number = 0o120755; - // eslint-disable-next-line + // eslint-disable-next-line @typescript-eslint/typedef const zip = new JSZip(); for (const filePath of allPaths) { const addPath: string = path.relative(dir, filePath); diff --git a/apps/rush-lib/src/logic/deploy/DeployManager.ts b/apps/rush-lib/src/logic/deploy/DeployManager.ts index 7b99d3b910c..b168fe37384 100644 --- a/apps/rush-lib/src/logic/deploy/DeployManager.ts +++ b/apps/rush-lib/src/logic/deploy/DeployManager.ts @@ -1,16 +1,16 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line +// eslint-disable-next-line @typescript-eslint/typedef const importLazy = require('import-lazy')(require); import * as colors from 'colors'; import * as path from 'path'; -// eslint-disable-next-line +// eslint-disable-next-line @typescript-eslint/typedef const resolve = importLazy('resolve'); -// eslint-disable-next-line +// eslint-disable-next-line @typescript-eslint/typedef const npmPacklist = importLazy('npm-packlist'); -// eslint-disable-next-line +// eslint-disable-next-line @typescript-eslint/typedef const pnpmLinkBins = importLazy('@pnpm/link-bins'); // (Used only by the legacy code fragment in the resolve.sync() hook below) diff --git a/apps/rush-lib/src/logic/installManager/RushInstallManager.ts b/apps/rush-lib/src/logic/installManager/RushInstallManager.ts index cacfeaad1a3..427c9fd670e 100644 --- a/apps/rush-lib/src/logic/installManager/RushInstallManager.ts +++ b/apps/rush-lib/src/logic/installManager/RushInstallManager.ts @@ -1,16 +1,16 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line +// eslint-disable-next-line @typescript-eslint/typedef const importLazy = require('import-lazy')(require); -// eslint-disable-next-line +// eslint-disable-next-line @typescript-eslint/typedef const glob = importLazy('glob'); import * as colors from 'colors'; import * as os from 'os'; import * as path from 'path'; import * as semver from 'semver'; -// eslint-disable-next-line +// eslint-disable-next-line @typescript-eslint/typedef const tar = importLazy('tar'); import * as globEscape from 'glob-escape'; import { @@ -340,7 +340,7 @@ export class RushInstallManager extends BaseInstallManager { // NPM expects the root of the tarball to have a directory called 'package' const npmPackageFolder: string = 'package'; - // eslint-disable-next-line + // eslint-disable-next-line @typescript-eslint/typedef const tarOptions = { gzip: true, file: tarballFile, @@ -354,7 +354,7 @@ export class RushInstallManager extends BaseInstallManager { noPax: true, sync: true, prefix: npmPackageFolder, - // eslint-disable-next-line + // eslint-disable-next-line @typescript-eslint/typedef filter: (path: string, stat): boolean => { if ( !this.rushConfiguration.experimentsConfiguration.configuration.noChmodFieldInTarHeaderNormalization diff --git a/apps/rush-lib/src/logic/npm/NpmLinkManager.ts b/apps/rush-lib/src/logic/npm/NpmLinkManager.ts index a8634e6a20a..68e87ec5dde 100644 --- a/apps/rush-lib/src/logic/npm/NpmLinkManager.ts +++ b/apps/rush-lib/src/logic/npm/NpmLinkManager.ts @@ -1,16 +1,16 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line +// eslint-disable-next-line @typescript-eslint/typedef const importLazy = require('import-lazy')(require); import * as colors from 'colors'; import * as os from 'os'; import * as path from 'path'; import * as semver from 'semver'; -// eslint-disable-next-line +// eslint-disable-next-line @typescript-eslint/typedef const tar = importLazy('tar'); -// eslint-disable-next-line +// eslint-disable-next-line @typescript-eslint/typedef import readPackageTree = require('read-package-tree'); import { FileSystem, FileConstants, LegacyAdapters } from '@rushstack/node-core-library'; diff --git a/apps/rush-lib/src/logic/pnpm/PnpmLinkManager.ts b/apps/rush-lib/src/logic/pnpm/PnpmLinkManager.ts index 86edcbf4ee0..341583b58a3 100644 --- a/apps/rush-lib/src/logic/pnpm/PnpmLinkManager.ts +++ b/apps/rush-lib/src/logic/pnpm/PnpmLinkManager.ts @@ -1,14 +1,14 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line +// eslint-disable-next-line @typescript-eslint/typedef const importLazy = require('import-lazy')(require); import * as os from 'os'; import * as path from 'path'; import uriEncode = require('strict-uri-encode'); -// eslint-disable-next-line +// eslint-disable-next-line @typescript-eslint/typedef const pnpmLinkBins = importLazy('@pnpm/link-bins'); import * as semver from 'semver'; diff --git a/apps/rush-lib/src/logic/pnpm/PnpmShrinkwrapFile.ts b/apps/rush-lib/src/logic/pnpm/PnpmShrinkwrapFile.ts index 500eb46c430..584f1f683ad 100644 --- a/apps/rush-lib/src/logic/pnpm/PnpmShrinkwrapFile.ts +++ b/apps/rush-lib/src/logic/pnpm/PnpmShrinkwrapFile.ts @@ -1,10 +1,10 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line +// eslint-disable-next-line @typescript-eslint/typedef const importLazy = require('import-lazy')(require); -// eslint-disable-next-line +// eslint-disable-next-line @typescript-eslint/typedef const yaml = importLazy('js-yaml'); import * as os from 'os'; import * as path from 'path'; diff --git a/apps/rush-lib/src/logic/pnpm/PnpmWorkspaceFile.ts b/apps/rush-lib/src/logic/pnpm/PnpmWorkspaceFile.ts index d9b7e245fc5..9c188a69019 100644 --- a/apps/rush-lib/src/logic/pnpm/PnpmWorkspaceFile.ts +++ b/apps/rush-lib/src/logic/pnpm/PnpmWorkspaceFile.ts @@ -1,13 +1,13 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line +// eslint-disable-next-line @typescript-eslint/typedef const importLazy = require('import-lazy')(require); import * as globEscape from 'glob-escape'; import * as os from 'os'; import * as path from 'path'; -// eslint-disable-next-line +// eslint-disable-next-line @typescript-eslint/typedef const yaml = importLazy('js-yaml'); import { FileSystem, Sort, Text } from '@rushstack/node-core-library'; diff --git a/apps/rush-lib/src/logic/yarn/YarnShrinkwrapFile.ts b/apps/rush-lib/src/logic/yarn/YarnShrinkwrapFile.ts index d6ff0268382..f0938e24061 100644 --- a/apps/rush-lib/src/logic/yarn/YarnShrinkwrapFile.ts +++ b/apps/rush-lib/src/logic/yarn/YarnShrinkwrapFile.ts @@ -1,11 +1,11 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line +// eslint-disable-next-line @typescript-eslint/typedef const importLazy = require('import-lazy')(require); import * as os from 'os'; -// eslint-disable-next-line +// eslint-disable-next-line @typescript-eslint/typedef const lockfile = importLazy('@yarnpkg/lockfile'); import { BaseShrinkwrapFile } from '../base/BaseShrinkwrapFile'; import { FileSystem, IParsedPackageNameOrError, InternalError } from '@rushstack/node-core-library'; @@ -14,7 +14,7 @@ import { DependencySpecifier } from '../DependencySpecifier'; import { PackageNameParsers } from '../../api/PackageNameParsers'; interface IYarnLockfileParseResult { - // eslint-disable-next-line + // eslint-disable-next-line @typescript-eslint/no-explicit-any object: any; } diff --git a/libraries/node-core-library/src/FileSystem.ts b/libraries/node-core-library/src/FileSystem.ts index 99ec39fb717..627720da104 100644 --- a/libraries/node-core-library/src/FileSystem.ts +++ b/libraries/node-core-library/src/FileSystem.ts @@ -1,13 +1,13 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line +// eslint-disable-next-line @typescript-eslint/typedef const importLazy = require('import-lazy')(require); import * as nodeJsPath from 'path'; import * as fs from 'fs'; -// eslint-disable-next-line +// eslint-disable-next-line @typescript-eslint/typedef const fsx = importLazy('fs-extra'); import { Text, NewlineKind, Encoding } from './Text'; diff --git a/libraries/node-core-library/src/FileWriter.ts b/libraries/node-core-library/src/FileWriter.ts index fd3d64141a4..0913f60c277 100644 --- a/libraries/node-core-library/src/FileWriter.ts +++ b/libraries/node-core-library/src/FileWriter.ts @@ -1,10 +1,10 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line +// eslint-disable-next-line @typescript-eslint/typedef const importLazy = require('import-lazy')(require); -// eslint-disable-next-line +// eslint-disable-next-line @typescript-eslint/typedef const fsx = importLazy('fs-extra'); /** From f4853c608091de847b2fac87235e0cfda55546c1 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Mon, 3 Aug 2020 15:59:30 -0700 Subject: [PATCH 61/97] Document getOwnPackageJsonVersion --- common/reviews/api/node-core-library.api.md | 1 - libraries/node-core-library/src/PackageJsonLookup.ts | 6 ++++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/common/reviews/api/node-core-library.api.md b/common/reviews/api/node-core-library.api.md index f7357cc3ee0..91cc0606dbb 100644 --- a/common/reviews/api/node-core-library.api.md +++ b/common/reviews/api/node-core-library.api.md @@ -496,7 +496,6 @@ export const enum NewlineKind { export class PackageJsonLookup { constructor(parameters?: IPackageJsonLookupParameters); clearCache(): void; - // (undocumented) static getOwnPackageJsonVersion(dirnameOfCaller: string): string; loadNodePackageJson(jsonFilename: string): INodePackageJson; static loadOwnPackageJson(dirnameOfCaller: string): IPackageJson; diff --git a/libraries/node-core-library/src/PackageJsonLookup.ts b/libraries/node-core-library/src/PackageJsonLookup.ts index 7f24ee31ad2..a5c37ceccc5 100644 --- a/libraries/node-core-library/src/PackageJsonLookup.ts +++ b/libraries/node-core-library/src/PackageJsonLookup.ts @@ -100,6 +100,12 @@ export class PackageJsonLookup { ); } + /** + * Gets the version of the package.json of the currently executing script. + * + * @param dirnameOfCaller - The search for package.json will start at the this directory, + * and then move upwards. + */ public static getOwnPackageJsonVersion(dirnameOfCaller: string): string { let parent: string = path.dirname(dirnameOfCaller); do { From ce9420d2605635a70593a2c2d5e55cf201940149 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Mon, 3 Aug 2020 16:01:50 -0700 Subject: [PATCH 62/97] Fix comment --- libraries/ts-command-line/src/Constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/ts-command-line/src/Constants.ts b/libraries/ts-command-line/src/Constants.ts index 19c5d17afea..7a5a285280e 100644 --- a/libraries/ts-command-line/src/Constants.ts +++ b/libraries/ts-command-line/src/Constants.ts @@ -2,7 +2,7 @@ // See LICENSE in the project root for license information. /** - * String constants for parts of filenames. + * String constants for command line processing. * * @public */ From 8263b72ced620b322e7846c1e504e455a32cfe90 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Mon, 3 Aug 2020 23:45:56 -0700 Subject: [PATCH 63/97] Address comments --- apps/rush-lib/src/api/Rush.ts | 2 +- .../rush-lib/src/cli/RushCommandLineParser.ts | 2 +- .../src/cli/actions/BaseRushAction.ts | 2 +- apps/rush-lib/src/utilities/Utilities.ts | 13 ++++++------ apps/rush/src/MinimalRushConfiguration.ts | 2 +- common/reviews/api/ts-command-line.api.md | 5 +++++ .../ts-command-line/src/CommandLineHelper.ts | 20 +++++++++++++++++++ libraries/ts-command-line/src/index.ts | 2 ++ 8 files changed, 37 insertions(+), 11 deletions(-) create mode 100644 libraries/ts-command-line/src/CommandLineHelper.ts diff --git a/apps/rush-lib/src/api/Rush.ts b/apps/rush-lib/src/api/Rush.ts index 96fac4bc939..c2b3910a245 100644 --- a/apps/rush-lib/src/api/Rush.ts +++ b/apps/rush-lib/src/api/Rush.ts @@ -54,7 +54,7 @@ export class Rush { public static launch(launcherVersion: string, arg: ILaunchOptions): void { const options: ILaunchOptions = Rush._normalizeLaunchOptions(arg); - if (Utilities.shouldPrintBanner()) { + if (!Utilities.shouldRestrictConsoleOutput()) { Rush._printStartupBanner(options.isManaged); } diff --git a/apps/rush-lib/src/cli/RushCommandLineParser.ts b/apps/rush-lib/src/cli/RushCommandLineParser.ts index 333799ebbc0..5bbf0d87a54 100644 --- a/apps/rush-lib/src/cli/RushCommandLineParser.ts +++ b/apps/rush-lib/src/cli/RushCommandLineParser.ts @@ -77,7 +77,7 @@ export class RushCommandLineParser extends CommandLineParser { try { const rushJsonFilename: string | undefined = RushConfiguration.tryFindRushJsonLocation({ startingFolder: this._rushOptions.cwd, - showVerbose: !Utilities.isNonDebugTabCompletionRequest() + showVerbose: !Utilities.shouldRestrictConsoleOutput() }); if (rushJsonFilename) { this.rushConfiguration = RushConfiguration.loadFromConfigurationFile(rushJsonFilename); diff --git a/apps/rush-lib/src/cli/actions/BaseRushAction.ts b/apps/rush-lib/src/cli/actions/BaseRushAction.ts index 51b5cbd9f60..91eb9b459cd 100644 --- a/apps/rush-lib/src/cli/actions/BaseRushAction.ts +++ b/apps/rush-lib/src/cli/actions/BaseRushAction.ts @@ -75,7 +75,7 @@ export abstract class BaseConfiglessRushAction extends CommandLineAction { } } - if (!Utilities.isNonDebugTabCompletionRequest()) { + if (!Utilities.shouldRestrictConsoleOutput()) { console.log(`Starting "rush ${this.actionName}"${os.EOL}`); } return this.runAsync(); diff --git a/apps/rush-lib/src/utilities/Utilities.ts b/apps/rush-lib/src/utilities/Utilities.ts index 72449ca2457..8c04a0ce3d5 100644 --- a/apps/rush-lib/src/utilities/Utilities.ts +++ b/apps/rush-lib/src/utilities/Utilities.ts @@ -10,7 +10,7 @@ import * as wordwrap from 'wordwrap'; import { JsonFile, IPackageJson, FileSystem, FileConstants } from '@rushstack/node-core-library'; import { RushConfiguration } from '../api/RushConfiguration'; import { Stream } from 'stream'; -import { CommandLineConstants } from '@rushstack/ts-command-line'; +import { CommandLineHelper } from '@rushstack/ts-command-line'; export interface IEnvironment { // NOTE: the process.env doesn't actually support "undefined" as a value. @@ -443,12 +443,11 @@ export class Utilities { return Utilities._executeLifecycleCommandInternal(command, child_process.spawn, options); } - public static isNonDebugTabCompletionRequest(): boolean { - return process.argv.length > 2 && process.argv[2] === CommandLineConstants.TabCompletionActionName; - } - - public static shouldPrintBanner(): boolean { - return !Utilities.isNonDebugTabCompletionRequest() && process.argv.indexOf('--json') === -1; + /** + * Utility to determine if the app should restrict writing to the console. + */ + public static shouldRestrictConsoleOutput(): boolean { + return !CommandLineHelper.isTabCompletionActionRequest() && process.argv.indexOf('--json') === -1; } /** diff --git a/apps/rush/src/MinimalRushConfiguration.ts b/apps/rush/src/MinimalRushConfiguration.ts index 9e7953de13e..96e205b94b9 100644 --- a/apps/rush/src/MinimalRushConfiguration.ts +++ b/apps/rush/src/MinimalRushConfiguration.ts @@ -34,7 +34,7 @@ export class MinimalRushConfiguration { public static loadFromDefaultLocation(): MinimalRushConfiguration | undefined { const rushJsonLocation: string | undefined = RushConfiguration.tryFindRushJsonLocation({ - showVerbose: !Utilities.isNonDebugTabCompletionRequest() + showVerbose: !Utilities.shouldRestrictConsoleOutput() }); if (rushJsonLocation) { return MinimalRushConfiguration._loadFromConfigurationFile(rushJsonLocation); diff --git a/common/reviews/api/ts-command-line.api.md b/common/reviews/api/ts-command-line.api.md index 7387a4f0489..cc6213712c1 100644 --- a/common/reviews/api/ts-command-line.api.md +++ b/common/reviews/api/ts-command-line.api.md @@ -57,6 +57,11 @@ export class CommandLineFlagParameter extends CommandLineParameter { readonly value: boolean; } +// @public +export class CommandLineHelper { + static isTabCompletionActionRequest(): boolean; +} + // @public export class CommandLineIntegerParameter extends CommandLineParameterWithArgument { // @internal diff --git a/libraries/ts-command-line/src/CommandLineHelper.ts b/libraries/ts-command-line/src/CommandLineHelper.ts new file mode 100644 index 00000000000..0682dce705d --- /dev/null +++ b/libraries/ts-command-line/src/CommandLineHelper.ts @@ -0,0 +1,20 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. +// See LICENSE in the project root for license information. + +import { CommandLineConstants } from './Constants'; + +/** + * Helpers for working with the ts-command-line API. + * + * @public + */ +export class CommandLineHelper { + /** + * Returns true if the current command line action is tab-complete. + * + * @public + */ + public static isTabCompletionActionRequest(): boolean { + return process.argv.length > 2 && process.argv[2] === CommandLineConstants.TabCompletionActionName; + } +} diff --git a/libraries/ts-command-line/src/index.ts b/libraries/ts-command-line/src/index.ts index 60cd18423d5..173a74815f1 100644 --- a/libraries/ts-command-line/src/index.ts +++ b/libraries/ts-command-line/src/index.ts @@ -45,3 +45,5 @@ export { DynamicCommandLineAction } from './providers/DynamicCommandLineAction'; export { DynamicCommandLineParser } from './providers/DynamicCommandLineParser'; export { CommandLineConstants } from './Constants'; + +export { CommandLineHelper } from './CommandLineHelper'; From 468bb4b68d8fd3a6490f46cb5a67a53782ef4709 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Mon, 3 Aug 2020 23:47:52 -0700 Subject: [PATCH 64/97] Rush change --- ...seph-rush-shell-tab-complete_2020-08-01-22-06.json | 2 +- ...seph-rush-shell-tab-complete_2020-08-04-06-47.json | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 common/changes/@rushstack/node-core-library/sachinjoseph-rush-shell-tab-complete_2020-08-04-06-47.json diff --git a/common/changes/@rushstack/node-core-library/sachinjoseph-rush-shell-tab-complete_2020-08-01-22-06.json b/common/changes/@rushstack/node-core-library/sachinjoseph-rush-shell-tab-complete_2020-08-01-22-06.json index 3763d0a2457..d64eb2f9681 100644 --- a/common/changes/@rushstack/node-core-library/sachinjoseph-rush-shell-tab-complete_2020-08-01-22-06.json +++ b/common/changes/@rushstack/node-core-library/sachinjoseph-rush-shell-tab-complete_2020-08-01-22-06.json @@ -2,7 +2,7 @@ "changes": [ { "packageName": "@rushstack/node-core-library", - "comment": "Create a lighter weight function to get own package version. Lazy-import some packages to improve spin up times.", + "comment": "Create a lighter weight function to get own package version.", "type": "minor" } ], diff --git a/common/changes/@rushstack/node-core-library/sachinjoseph-rush-shell-tab-complete_2020-08-04-06-47.json b/common/changes/@rushstack/node-core-library/sachinjoseph-rush-shell-tab-complete_2020-08-04-06-47.json new file mode 100644 index 00000000000..162425000f8 --- /dev/null +++ b/common/changes/@rushstack/node-core-library/sachinjoseph-rush-shell-tab-complete_2020-08-04-06-47.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "packageName": "@rushstack/node-core-library", + "comment": "Lazy-import some packages to improve spin up times.", + "type": "patch" + } + ], + "packageName": "@rushstack/node-core-library", + "email": "sachinjoseph@users.noreply.github.com" +} \ No newline at end of file From 147648ae5a7671f77dbae3e06b5728931851de6a Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Fri, 7 Aug 2020 20:55:21 -0700 Subject: [PATCH 65/97] Fix some bugs --- .../src/cli/scriptActions/BulkScriptAction.ts | 27 ++++++++++++++++--- apps/rush-lib/src/utilities/Utilities.ts | 2 +- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/apps/rush-lib/src/cli/scriptActions/BulkScriptAction.ts b/apps/rush-lib/src/cli/scriptActions/BulkScriptAction.ts index 7f8812b0199..22f5bbbc9c5 100644 --- a/apps/rush-lib/src/cli/scriptActions/BulkScriptAction.ts +++ b/apps/rush-lib/src/cli/scriptActions/BulkScriptAction.ts @@ -10,6 +10,7 @@ import { CommandLineStringListParameter, CommandLineParameterKind } from '@rushstack/ts-command-line'; +import { PackageName } from '@rushstack/node-core-library'; import { Event } from '../../index'; import { SetupChecks } from '../../logic/SetupChecks'; @@ -217,11 +218,31 @@ export class BulkScriptAction extends BaseScriptAction { } private async _getProjectNames(): Promise { - const ret: string[] = []; + const unscopedNamesMap: Map = new Map(); + + const scoppedPackageNames: string[] = []; for (const project of this.rushConfiguration.projects) { - ret.push(project.packageName); + scoppedPackageNames.push(project.packageName); + + const unscopedName: string = PackageName.getUnscopedName(project.packageName); + let count: number = 0; + if (unscopedNamesMap.has(unscopedName)) { + count = unscopedNamesMap.get(unscopedName)!; + } + unscopedNamesMap.set(unscopedName, count + 1); + } + + const unscopedNames: string[] = []; + + for (const unscopedName of unscopedNamesMap.keys()) { + const unscopedNameCount: number = unscopedNamesMap.get(unscopedName)!; + // don't suggest ambiguous unscoped names + if (unscopedNameCount === 1 && !scoppedPackageNames.includes(unscopedName)) { + unscopedNames.push(unscopedName); + } } - return ret; + + return unscopedNames.sort().concat(scoppedPackageNames.sort()); } private _doBeforeTask(): void { diff --git a/apps/rush-lib/src/utilities/Utilities.ts b/apps/rush-lib/src/utilities/Utilities.ts index 8c04a0ce3d5..d23661f1afa 100644 --- a/apps/rush-lib/src/utilities/Utilities.ts +++ b/apps/rush-lib/src/utilities/Utilities.ts @@ -447,7 +447,7 @@ export class Utilities { * Utility to determine if the app should restrict writing to the console. */ public static shouldRestrictConsoleOutput(): boolean { - return !CommandLineHelper.isTabCompletionActionRequest() && process.argv.indexOf('--json') === -1; + return CommandLineHelper.isTabCompletionActionRequest() || process.argv.indexOf('--json') === -1; } /** From 867cd2d433bd8303569a60b3422e33fc29ee38ab Mon Sep 17 00:00:00 2001 From: Sachin Joseph <6994498+sachinjoseph@users.noreply.github.com> Date: Sat, 8 Aug 2020 00:29:15 -0700 Subject: [PATCH 66/97] Update libraries/ts-command-line/src/parameters/CommandLineDefinition.ts Co-authored-by: Pete Gonzalez <4673363+octogonz@users.noreply.github.com> --- .../ts-command-line/src/parameters/CommandLineDefinition.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libraries/ts-command-line/src/parameters/CommandLineDefinition.ts b/libraries/ts-command-line/src/parameters/CommandLineDefinition.ts index e28543ea1bc..9104e5893ee 100644 --- a/libraries/ts-command-line/src/parameters/CommandLineDefinition.ts +++ b/libraries/ts-command-line/src/parameters/CommandLineDefinition.ts @@ -64,7 +64,10 @@ export interface IBaseCommandLineDefinition { environmentVariable?: string; /** - * Custom tab completions for the parameter values + * An optional callback that provides a list of custom choices for tab completion. + * @remarks + * This option is only used when `ICommandLineParserOptions.enableTabCompletionAction` + * is enabled. */ completions?: () => Promise; } From 72e0b35c5c78f56c473756bfc56355ae19fc9852 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Sat, 8 Aug 2020 00:29:36 -0700 Subject: [PATCH 67/97] Address comments --- apps/rush-lib/src/cli/scriptActions/BulkScriptAction.ts | 8 ++++---- apps/rush-lib/src/logic/yarn/YarnShrinkwrapFile.ts | 9 +++------ .../ts-command-line/src/providers/TabCompletionAction.ts | 7 +++++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/apps/rush-lib/src/cli/scriptActions/BulkScriptAction.ts b/apps/rush-lib/src/cli/scriptActions/BulkScriptAction.ts index 22f5bbbc9c5..e0fe9c70f57 100644 --- a/apps/rush-lib/src/cli/scriptActions/BulkScriptAction.ts +++ b/apps/rush-lib/src/cli/scriptActions/BulkScriptAction.ts @@ -220,9 +220,9 @@ export class BulkScriptAction extends BaseScriptAction { private async _getProjectNames(): Promise { const unscopedNamesMap: Map = new Map(); - const scoppedPackageNames: string[] = []; + const scopedNames: string[] = []; for (const project of this.rushConfiguration.projects) { - scoppedPackageNames.push(project.packageName); + scopedNames.push(project.packageName); const unscopedName: string = PackageName.getUnscopedName(project.packageName); let count: number = 0; @@ -237,12 +237,12 @@ export class BulkScriptAction extends BaseScriptAction { for (const unscopedName of unscopedNamesMap.keys()) { const unscopedNameCount: number = unscopedNamesMap.get(unscopedName)!; // don't suggest ambiguous unscoped names - if (unscopedNameCount === 1 && !scoppedPackageNames.includes(unscopedName)) { + if (unscopedNameCount === 1 && !scopedNames.includes(unscopedName)) { unscopedNames.push(unscopedName); } } - return unscopedNames.sort().concat(scoppedPackageNames.sort()); + return unscopedNames.sort().concat(scopedNames.sort()); } private _doBeforeTask(): void { diff --git a/apps/rush-lib/src/logic/yarn/YarnShrinkwrapFile.ts b/apps/rush-lib/src/logic/yarn/YarnShrinkwrapFile.ts index f0938e24061..5a572de1ab3 100644 --- a/apps/rush-lib/src/logic/yarn/YarnShrinkwrapFile.ts +++ b/apps/rush-lib/src/logic/yarn/YarnShrinkwrapFile.ts @@ -7,17 +7,14 @@ const importLazy = require('import-lazy')(require); import * as os from 'os'; // eslint-disable-next-line @typescript-eslint/typedef const lockfile = importLazy('@yarnpkg/lockfile'); +// TODO: Convert this to "import type" after we upgrade to TypeScript 3.8 +import { ParseResult } from '@yarnpkg/lockfile'; import { BaseShrinkwrapFile } from '../base/BaseShrinkwrapFile'; import { FileSystem, IParsedPackageNameOrError, InternalError } from '@rushstack/node-core-library'; import { RushConstants } from '../RushConstants'; import { DependencySpecifier } from '../DependencySpecifier'; import { PackageNameParsers } from '../../api/PackageNameParsers'; -interface IYarnLockfileParseResult { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - object: any; -} - /** * Used with YarnShrinkwrapFile._encodePackageNameAndSemVer() and _decodePackageNameAndSemVer(). */ @@ -155,7 +152,7 @@ export class YarnShrinkwrapFile extends BaseShrinkwrapFile { public static loadFromFile(shrinkwrapFilename: string): YarnShrinkwrapFile | undefined { let shrinkwrapString: string; - let shrinkwrapJson: IYarnLockfileParseResult; + let shrinkwrapJson: ParseResult; try { if (!FileSystem.exists(shrinkwrapFilename)) { return undefined; // file does not exist diff --git a/libraries/ts-command-line/src/providers/TabCompletionAction.ts b/libraries/ts-command-line/src/providers/TabCompletionAction.ts index b28655f994f..7c4e55ca33d 100644 --- a/libraries/ts-command-line/src/providers/TabCompletionAction.ts +++ b/libraries/ts-command-line/src/providers/TabCompletionAction.ts @@ -71,14 +71,17 @@ export class TabCompleteAction extends CommandLineAction { protected async onExecute(): Promise { const commandLine: string = this._wordToCompleteParameter.value || ''; - const caretPosition: number = this._positionParameter.value || 0; + const caretPosition: number = this._positionParameter.value || (commandLine && commandLine.length) || 0; for await (const value of this.getCompletions(commandLine, caretPosition)) { console.log(value); } } - public async *getCompletions(commandLine: string, caretPosition: number): AsyncIterable { + public async *getCompletions( + commandLine: string, + caretPosition: number = commandLine.length + ): AsyncIterable { const actions: Map> = this._actions; if (!commandLine || !caretPosition) { From fac7836025d627733653dc7ec68f894289a425e4 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Sat, 8 Aug 2020 00:53:54 -0700 Subject: [PATCH 68/97] Preserve some typing --- apps/rush-lib/src/cli/actions/ChangeAction.ts | 32 +++++++------------ .../src/logic/deploy/DeployArchiver.ts | 1 + .../installManager/RushInstallManager.ts | 25 ++++++++++++--- 3 files changed, 33 insertions(+), 25 deletions(-) diff --git a/apps/rush-lib/src/cli/actions/ChangeAction.ts b/apps/rush-lib/src/cli/actions/ChangeAction.ts index 5a35be266a4..b952b5ca4b5 100644 --- a/apps/rush-lib/src/cli/actions/ChangeAction.ts +++ b/apps/rush-lib/src/cli/actions/ChangeAction.ts @@ -10,6 +10,8 @@ import * as child_process from 'child_process'; import * as colors from 'colors'; // eslint-disable-next-line @typescript-eslint/typedef const inquirer = importLazy('inquirer'); +// TODO: Convert this to "import type" after we upgrade to TypeScript 3.8 +import { PromptModule } from 'inquirer'; import { CommandLineFlagParameter, @@ -182,8 +184,7 @@ export class ChangeAction extends BaseRushAction { this._warnUncommittedChanges(); - // eslint-disable-next-line @typescript-eslint/typedef - const promptModule = inquirer.createPromptModule(); + const promptModule: PromptModule = inquirer.createPromptModule(); let changeFileData: Map = new Map(); let interactiveMode: boolean = false; if (this._bulkChangeParameter.value) { @@ -371,8 +372,7 @@ export class ChangeAction extends BaseRushAction { * The main loop which prompts the user for information on changed projects. */ private async _promptForChangeFileData( - // eslint-disable-next-line @typescript-eslint/typedef - promptModule, + promptModule: PromptModule, sortedProjectList: string[], existingChangeComments: Map ): Promise> { @@ -407,8 +407,7 @@ export class ChangeAction extends BaseRushAction { * Asks all questions which are needed to generate changelist for a project. */ private async _askQuestions( - // eslint-disable-next-line @typescript-eslint/typedef - promptModule, + promptModule: PromptModule, packageName: string, existingChangeComments: Map ): Promise { @@ -447,8 +446,7 @@ export class ChangeAction extends BaseRushAction { } private async _promptForComments( - // eslint-disable-next-line @typescript-eslint/typedef - promptModule, + promptModule: PromptModule, packageName: string ): Promise { const bumpOptions: { [type: string]: string } = this._getBumpOptions(packageName); @@ -527,8 +525,7 @@ export class ChangeAction extends BaseRushAction { * Will determine a user's email by first detecting it from their Git config, * or will ask for it if it is not found or the Git config is wrong. */ - // eslint-disable-next-line @typescript-eslint/typedef - private async _detectOrAskForEmail(promptModule): Promise { + private async _detectOrAskForEmail(promptModule: PromptModule): Promise { return (await this._detectAndConfirmEmail(promptModule)) || (await this._promptForEmail(promptModule)); } @@ -548,8 +545,7 @@ export class ChangeAction extends BaseRushAction { * Detects the user's email address from their Git configuration, prompts the user to approve the * detected email. It returns undefined if it cannot be detected. */ - // eslint-disable-next-line @typescript-eslint/typedef - private async _detectAndConfirmEmail(promptModule): Promise { + private async _detectAndConfirmEmail(promptModule: PromptModule): Promise { const email: string | undefined = this._detectEmail(); if (email) { @@ -570,8 +566,7 @@ export class ChangeAction extends BaseRushAction { /** * Asks the user for their email address */ - // eslint-disable-next-line @typescript-eslint/typedef - private async _promptForEmail(promptModule): Promise { + private async _promptForEmail(promptModule: PromptModule): Promise { const { email }: { email: string } = await promptModule([ { type: 'input', @@ -605,8 +600,7 @@ export class ChangeAction extends BaseRushAction { * Writes change files to the common/changes folder. Will prompt for overwrite if file already exists. */ private async _writeChangeFiles( - // eslint-disable-next-line @typescript-eslint/typedef - promptModule, + promptModule: PromptModule, changeFileData: Map, overwrite: boolean, interactiveMode: boolean @@ -617,8 +611,7 @@ export class ChangeAction extends BaseRushAction { } private async _writeChangeFile( - // eslint-disable-next-line @typescript-eslint/typedef - promptModule, + promptModule: PromptModule, changeFileData: IChangeFile, overwrite: boolean, interactiveMode: boolean @@ -642,8 +635,7 @@ export class ChangeAction extends BaseRushAction { } } - // eslint-disable-next-line @typescript-eslint/typedef - private async _promptForOverwrite(promptModule, filePath: string): Promise { + private async _promptForOverwrite(promptModule: PromptModule, filePath: string): Promise { const overwrite: boolean = await promptModule([ { name: 'overwrite', diff --git a/apps/rush-lib/src/logic/deploy/DeployArchiver.ts b/apps/rush-lib/src/logic/deploy/DeployArchiver.ts index 5dfbded3b24..2082f552d74 100644 --- a/apps/rush-lib/src/logic/deploy/DeployArchiver.ts +++ b/apps/rush-lib/src/logic/deploy/DeployArchiver.ts @@ -6,6 +6,7 @@ const importLazy = require('import-lazy')(require); // eslint-disable-next-line @typescript-eslint/typedef const JSZip = importLazy('jszip'); + import * as path from 'path'; import { FileSystem, FileSystemStats } from '@rushstack/node-core-library'; diff --git a/apps/rush-lib/src/logic/installManager/RushInstallManager.ts b/apps/rush-lib/src/logic/installManager/RushInstallManager.ts index 427c9fd670e..cb4872d83c7 100644 --- a/apps/rush-lib/src/logic/installManager/RushInstallManager.ts +++ b/apps/rush-lib/src/logic/installManager/RushInstallManager.ts @@ -12,6 +12,8 @@ import * as path from 'path'; import * as semver from 'semver'; // eslint-disable-next-line @typescript-eslint/typedef const tar = importLazy('tar'); +// TODO: Convert this to "import type" after we upgrade to TypeScript 3.8 +import { CreateOptions, FileStat } from 'tar'; import * as globEscape from 'glob-escape'; import { JsonFile, @@ -37,6 +39,21 @@ import { AlreadyReportedError } from '../../utilities/AlreadyReportedError'; import { LinkManagerFactory } from '../LinkManagerFactory'; import { BaseLinkManager } from '../base/BaseLinkManager'; +/** + * The "noMtime" flag is new in tar@4.4.1 and not available yet for \@types/tar. + * As a temporary workaround, augment the type. + */ +declare module 'tar' { + // eslint-disable-next-line @typescript-eslint/naming-convention + export interface CreateOptions { + /** + * "Set to true to omit writing mtime values for entries. Note that this prevents using other + * mtime-based features like tar.update or the keepNewer option with the resulting tar archive." + */ + noMtime?: boolean; + } +} + /** * This class implements common logic between "rush install" and "rush update". */ @@ -340,8 +357,7 @@ export class RushInstallManager extends BaseInstallManager { // NPM expects the root of the tarball to have a directory called 'package' const npmPackageFolder: string = 'package'; - // eslint-disable-next-line @typescript-eslint/typedef - const tarOptions = { + const tarOptions: CreateOptions = { gzip: true, file: tarballFile, cwd: tempProjectFolder, @@ -354,8 +370,7 @@ export class RushInstallManager extends BaseInstallManager { noPax: true, sync: true, prefix: npmPackageFolder, - // eslint-disable-next-line @typescript-eslint/typedef - filter: (path: string, stat): boolean => { + filter: (path: string, stat: FileStat): boolean => { if ( !this.rushConfiguration.experimentsConfiguration.configuration.noChmodFieldInTarHeaderNormalization ) { @@ -365,7 +380,7 @@ export class RushInstallManager extends BaseInstallManager { } return true; } - }; + } as CreateOptions; // create the new tarball tar.create(tarOptions, [FileConstants.PackageJson]); } From c87dcff59a768cda3a9144b2578613c2a8df2d63 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Sat, 8 Aug 2020 01:33:12 -0700 Subject: [PATCH 69/97] Make completions() only available to choice parameters and parameters with arguments --- common/reviews/api/ts-command-line.api.md | 7 ++++-- .../src/parameters/BaseClasses.ts | 8 +++---- .../parameters/CommandLineChoiceParameter.ts | 4 ++++ .../src/parameters/CommandLineDefinition.ts | 24 ++++++++++++------- .../parameters/CommandLineStringParameter.ts | 3 +++ .../src/providers/TabCompletionAction.ts | 21 +++++++++++++--- 6 files changed, 50 insertions(+), 17 deletions(-) diff --git a/common/reviews/api/ts-command-line.api.md b/common/reviews/api/ts-command-line.api.md index cc6213712c1..e7386ef972e 100644 --- a/common/reviews/api/ts-command-line.api.md +++ b/common/reviews/api/ts-command-line.api.md @@ -31,6 +31,7 @@ export class CommandLineChoiceParameter extends CommandLineParameter { readonly alternatives: ReadonlyArray; // @override appendToArgList(argList: string[]): void; + readonly completions: (() => Promise) | undefined; readonly defaultValue: string | undefined; // @internal _getSupplementaryNotes(supplementaryNotes: string[]): void; @@ -82,7 +83,6 @@ export abstract class CommandLineParameter { // @internal constructor(definition: IBaseCommandLineDefinition); abstract appendToArgList(argList: string[]): void; - readonly completions: (() => Promise) | undefined; readonly description: string; readonly environmentVariable: string | undefined; // @internal @@ -139,6 +139,7 @@ export abstract class CommandLineParameterWithArgument extends CommandLineParame // @internal constructor(definition: IBaseCommandLineDefinitionWithArgument); readonly argumentName: string; + readonly completions: (() => Promise) | undefined; } // @public @@ -186,6 +187,7 @@ export class CommandLineStringParameter extends CommandLineParameterWithArgument constructor(definition: ICommandLineStringDefinition); // @override appendToArgList(argList: string[]): void; + readonly completions: (() => Promise) | undefined; readonly defaultValue: string | undefined; // @internal _getSupplementaryNotes(supplementaryNotes: string[]): void; @@ -211,7 +213,6 @@ export class DynamicCommandLineParser extends CommandLineParser { // @public export interface IBaseCommandLineDefinition { - completions?: () => Promise; description: string; environmentVariable?: string; parameterLongName: string; @@ -222,6 +223,7 @@ export interface IBaseCommandLineDefinition { // @public export interface IBaseCommandLineDefinitionWithArgument extends IBaseCommandLineDefinition { argumentName: string; + completions?: () => Promise; } // @public @@ -234,6 +236,7 @@ export interface ICommandLineActionOptions { // @public export interface ICommandLineChoiceDefinition extends IBaseCommandLineDefinition { alternatives: string[]; + completions?: () => Promise; defaultValue?: string; } diff --git a/libraries/ts-command-line/src/parameters/BaseClasses.ts b/libraries/ts-command-line/src/parameters/BaseClasses.ts index 8ccf08ecbb4..29e3087254b 100644 --- a/libraries/ts-command-line/src/parameters/BaseClasses.ts +++ b/libraries/ts-command-line/src/parameters/BaseClasses.ts @@ -58,9 +58,6 @@ export abstract class CommandLineParameter { /** {@inheritDoc IBaseCommandLineDefinition.environmentVariable} */ public readonly environmentVariable: string | undefined; - /** {@inheritDoc IBaseCommandLineDefinition.completions} */ - public readonly completions: (() => Promise) | undefined; - /** @internal */ public constructor(definition: IBaseCommandLineDefinition) { this.longName = definition.parameterLongName; @@ -68,7 +65,6 @@ export abstract class CommandLineParameter { this.description = definition.description; this.required = !!definition.required; this.environmentVariable = definition.environmentVariable; - this.completions = definition.completions; if (!CommandLineParameter._longNameRegExp.test(this.longName)) { throw new Error( @@ -183,6 +179,9 @@ export abstract class CommandLineParameterWithArgument extends CommandLineParame /** {@inheritDoc IBaseCommandLineDefinitionWithArgument.argumentName} */ public readonly argumentName: string; + /** {@inheritDoc IBaseCommandLineDefinitionWithArgument.completions} */ + public readonly completions: (() => Promise) | undefined; + /** @internal */ public constructor(definition: IBaseCommandLineDefinitionWithArgument) { super(definition); @@ -207,5 +206,6 @@ export abstract class CommandLineParameterWithArgument extends CommandLineParame ); } this.argumentName = definition.argumentName; + this.completions = definition.completions; } } diff --git a/libraries/ts-command-line/src/parameters/CommandLineChoiceParameter.ts b/libraries/ts-command-line/src/parameters/CommandLineChoiceParameter.ts index 93f380b1ad3..8b0922ebb0a 100644 --- a/libraries/ts-command-line/src/parameters/CommandLineChoiceParameter.ts +++ b/libraries/ts-command-line/src/parameters/CommandLineChoiceParameter.ts @@ -17,6 +17,9 @@ export class CommandLineChoiceParameter extends CommandLineParameter { private _value: string | undefined = undefined; + /** {@inheritDoc ICommandLineChoiceDefinition.completions} */ + public readonly completions: (() => Promise) | undefined; + /** @internal */ public constructor(definition: ICommandLineChoiceDefinition) { super(definition); @@ -36,6 +39,7 @@ export class CommandLineChoiceParameter extends CommandLineParameter { this.alternatives = definition.alternatives; this.defaultValue = definition.defaultValue; this.validateDefaultValue(!!this.defaultValue); + this.completions = definition.completions; } /** {@inheritDoc CommandLineParameter.kind} */ diff --git a/libraries/ts-command-line/src/parameters/CommandLineDefinition.ts b/libraries/ts-command-line/src/parameters/CommandLineDefinition.ts index 9104e5893ee..3892a5658d8 100644 --- a/libraries/ts-command-line/src/parameters/CommandLineDefinition.ts +++ b/libraries/ts-command-line/src/parameters/CommandLineDefinition.ts @@ -62,14 +62,6 @@ export interface IBaseCommandLineDefinition { * ordinary String Parameter: Any value is accepted, including an empty string. */ environmentVariable?: string; - - /** - * An optional callback that provides a list of custom choices for tab completion. - * @remarks - * This option is only used when `ICommandLineParserOptions.enableTabCompletionAction` - * is enabled. - */ - completions?: () => Promise; } /** @@ -90,6 +82,14 @@ export interface IBaseCommandLineDefinitionWithArgument extends IBaseCommandLine * be comprised of upper-case letters, numbers, and underscores. It should be kept short. */ argumentName: string; + + /** + * An optional callback that provides a list of custom choices for tab completion. + * @remarks + * This option is only used when `ICommandLineParserOptions.enableTabCompletionAction` + * is enabled. + */ + completions?: () => Promise; } /** @@ -108,6 +108,14 @@ export interface ICommandLineChoiceDefinition extends IBaseCommandLineDefinition * {@inheritDoc ICommandLineStringDefinition.defaultValue} */ defaultValue?: string; + + /** + * An optional callback that provides a list of custom choices for tab completion. + * @remarks + * This option is only used when `ICommandLineParserOptions.enableTabCompletionAction` + * is enabled. + */ + completions?: () => Promise; } /** diff --git a/libraries/ts-command-line/src/parameters/CommandLineStringParameter.ts b/libraries/ts-command-line/src/parameters/CommandLineStringParameter.ts index 93041c4a9c1..a35c6107771 100644 --- a/libraries/ts-command-line/src/parameters/CommandLineStringParameter.ts +++ b/libraries/ts-command-line/src/parameters/CommandLineStringParameter.ts @@ -14,6 +14,9 @@ export class CommandLineStringParameter extends CommandLineParameterWithArgument private _value: string | undefined = undefined; + /** {@inheritDoc ICommandLineChoiceDefinition.completions} */ + public readonly completions: (() => Promise) | undefined; + /** @internal */ public constructor(definition: ICommandLineStringDefinition) { super(definition); diff --git a/libraries/ts-command-line/src/providers/TabCompletionAction.ts b/libraries/ts-command-line/src/providers/TabCompletionAction.ts index 7c4e55ca33d..68f8dc27e46 100644 --- a/libraries/ts-command-line/src/providers/TabCompletionAction.ts +++ b/libraries/ts-command-line/src/providers/TabCompletionAction.ts @@ -5,7 +5,11 @@ import stringArgv from 'string-argv'; import { CommandLineIntegerParameter } from '../parameters/CommandLineIntegerParameter'; import { CommandLineStringParameter } from '../parameters/CommandLineStringParameter'; -import { CommandLineParameterKind, CommandLineParameter } from '../parameters/BaseClasses'; +import { + CommandLineParameterKind, + CommandLineParameter, + CommandLineParameterWithArgument +} from '../parameters/BaseClasses'; import { CommandLineAction } from './CommandLineAction'; import { CommandLineChoiceParameter } from '..'; import { CommandLineConstants } from '../Constants'; @@ -187,8 +191,19 @@ export class TabCompleteAction extends CommandLineAction { let choiceParameterValues: string[] = []; if (parameter.kind === CommandLineParameterKind.Choice) { choiceParameterValues = (parameter as CommandLineChoiceParameter).alternatives as string[]; - } else if (parameter.completions) { - choiceParameterValues = await parameter.completions(); + } else if (parameter.kind !== CommandLineParameterKind.Flag) { + let parameterWithArgumentOrChoices: + | CommandLineParameterWithArgument + | CommandLineChoiceParameter + | undefined = undefined; + if (parameter instanceof CommandLineParameterWithArgument) { + parameterWithArgumentOrChoices = parameter as CommandLineParameterWithArgument; + } else if (parameter instanceof CommandLineChoiceParameter) { + parameterWithArgumentOrChoices = parameter as CommandLineChoiceParameter; + } + if (parameterWithArgumentOrChoices && parameterWithArgumentOrChoices.completions) { + choiceParameterValues = await parameterWithArgumentOrChoices.completions(); + } } return choiceParameterValues; From c1ae9b8df153c4d694d8ecc0e4a623a07929eaeb Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Sat, 8 Aug 2020 02:16:38 -0700 Subject: [PATCH 70/97] Remove completions() hook from CommandLinStringParameter --- common/reviews/api/ts-command-line.api.md | 1 - .../src/parameters/CommandLineStringParameter.ts | 3 --- 2 files changed, 4 deletions(-) diff --git a/common/reviews/api/ts-command-line.api.md b/common/reviews/api/ts-command-line.api.md index e7386ef972e..685545fb006 100644 --- a/common/reviews/api/ts-command-line.api.md +++ b/common/reviews/api/ts-command-line.api.md @@ -187,7 +187,6 @@ export class CommandLineStringParameter extends CommandLineParameterWithArgument constructor(definition: ICommandLineStringDefinition); // @override appendToArgList(argList: string[]): void; - readonly completions: (() => Promise) | undefined; readonly defaultValue: string | undefined; // @internal _getSupplementaryNotes(supplementaryNotes: string[]): void; diff --git a/libraries/ts-command-line/src/parameters/CommandLineStringParameter.ts b/libraries/ts-command-line/src/parameters/CommandLineStringParameter.ts index a35c6107771..93041c4a9c1 100644 --- a/libraries/ts-command-line/src/parameters/CommandLineStringParameter.ts +++ b/libraries/ts-command-line/src/parameters/CommandLineStringParameter.ts @@ -14,9 +14,6 @@ export class CommandLineStringParameter extends CommandLineParameterWithArgument private _value: string | undefined = undefined; - /** {@inheritDoc ICommandLineChoiceDefinition.completions} */ - public readonly completions: (() => Promise) | undefined; - /** @internal */ public constructor(definition: ICommandLineStringDefinition) { super(definition); From eb0ba4140c577d3253e34a274c489857bc4ba8b8 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Sat, 8 Aug 2020 09:59:53 -0700 Subject: [PATCH 71/97] Remove commented out test code --- .../src/providers/TabCompletionAction.ts | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/libraries/ts-command-line/src/providers/TabCompletionAction.ts b/libraries/ts-command-line/src/providers/TabCompletionAction.ts index 68f8dc27e46..4265e078efc 100644 --- a/libraries/ts-command-line/src/providers/TabCompletionAction.ts +++ b/libraries/ts-command-line/src/providers/TabCompletionAction.ts @@ -98,12 +98,6 @@ export class TabCompleteAction extends CommandLineAction { // offset arguments by the number of global params in the input const globalParameterOffset: number = this._getGlobalParameterOffset(tokens); - // for (let i: number = 0; i < tokens.length; i++) { - // yield 'token'+ i + tokens[i]; - // } - - // yield 'globalParameterOffset'+globalParameterOffset; - if (tokens.length < 2 + globalParameterOffset) { yield* this._getAllActions(); return; @@ -115,25 +109,19 @@ export class TabCompleteAction extends CommandLineAction { const completePartialWord: boolean = caretPosition === commandLine.length; if (completePartialWord && tokens.length === 2 + globalParameterOffset) { - // yield 'a1'; - // yield 'tokens1gl0'+tokens[1 + globalParameterOffset] for (const actionName of actions.keys()) { - // yield 'a1' + actionName; if (actionName.indexOf(tokens[1 + globalParameterOffset]) === 0) { yield actionName; } } } else { - // yield 'b1'; for (const actionName of actions.keys()) { if (actionName === tokens[1 + globalParameterOffset]) { - // yield 'c1' + actionName; const parameterNameMap: Map = actions.get(actionName)!; const parameterNames: string[] = Array.from(parameterNameMap.keys()); if (completePartialWord) { - // yield 'd1'; for (const parameterName of parameterNames) { if (parameterName === secondLastToken) { const values: string[] = await this._getParameterValueCompletions( @@ -147,7 +135,6 @@ export class TabCompleteAction extends CommandLineAction { } yield* this._completeParameterValues(parameterNames, lastToken); } else { - // yield 'e1'; for (const parameterName of parameterNames) { if (parameterName === lastToken) { const values: string[] = await this._getParameterValueCompletions( From 2a9a1b9fc09662bf0ebbf4e1ea0f1c904f4b9163 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Sat, 8 Aug 2020 10:10:37 -0700 Subject: [PATCH 72/97] Use a flag to prevent adding the tab-complete action multiple times --- libraries/ts-command-line/src/providers/CommandLineParser.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libraries/ts-command-line/src/providers/CommandLineParser.ts b/libraries/ts-command-line/src/providers/CommandLineParser.ts index e18a6513c02..e6e4efeae7d 100644 --- a/libraries/ts-command-line/src/providers/CommandLineParser.ts +++ b/libraries/ts-command-line/src/providers/CommandLineParser.ts @@ -54,6 +54,7 @@ export abstract class CommandLineParser extends CommandLineParameterProvider { private _actions: CommandLineAction[]; private _actionsByName: Map; private _executed: boolean = false; + private _tabCompleteActionWasAdded: boolean = false; public constructor(options: ICommandLineParserOptions) { super(); @@ -135,8 +136,9 @@ export abstract class CommandLineParser extends CommandLineParameterProvider { * the process.argv will be used */ public execute(args?: string[]): Promise { - if (this._options.enableTabCompletionAction) { + if (this._options.enableTabCompletionAction && !this._tabCompleteActionWasAdded) { this.addAction(new TabCompleteAction(this.actions, this.parameters)); + this._tabCompleteActionWasAdded = true; } return this.executeWithoutErrorHandling(args) .then(() => { From da061db3d10e022c5462bcf5bca64eacbfab2065 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Sat, 8 Aug 2020 10:22:09 -0700 Subject: [PATCH 73/97] Get argv as a param --- apps/rush-lib/src/utilities/Utilities.ts | 4 +++- common/reviews/api/ts-command-line.api.md | 2 +- libraries/ts-command-line/src/CommandLineHelper.ts | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/apps/rush-lib/src/utilities/Utilities.ts b/apps/rush-lib/src/utilities/Utilities.ts index d23661f1afa..3d89fead4f8 100644 --- a/apps/rush-lib/src/utilities/Utilities.ts +++ b/apps/rush-lib/src/utilities/Utilities.ts @@ -447,7 +447,9 @@ export class Utilities { * Utility to determine if the app should restrict writing to the console. */ public static shouldRestrictConsoleOutput(): boolean { - return CommandLineHelper.isTabCompletionActionRequest() || process.argv.indexOf('--json') === -1; + return ( + CommandLineHelper.isTabCompletionActionRequest(process.argv) || process.argv.indexOf('--json') === -1 + ); } /** diff --git a/common/reviews/api/ts-command-line.api.md b/common/reviews/api/ts-command-line.api.md index 685545fb006..79eff72636b 100644 --- a/common/reviews/api/ts-command-line.api.md +++ b/common/reviews/api/ts-command-line.api.md @@ -60,7 +60,7 @@ export class CommandLineFlagParameter extends CommandLineParameter { // @public export class CommandLineHelper { - static isTabCompletionActionRequest(): boolean; + static isTabCompletionActionRequest(argv: string[]): boolean; } // @public diff --git a/libraries/ts-command-line/src/CommandLineHelper.ts b/libraries/ts-command-line/src/CommandLineHelper.ts index 0682dce705d..45022d393e7 100644 --- a/libraries/ts-command-line/src/CommandLineHelper.ts +++ b/libraries/ts-command-line/src/CommandLineHelper.ts @@ -14,7 +14,7 @@ export class CommandLineHelper { * * @public */ - public static isTabCompletionActionRequest(): boolean { - return process.argv.length > 2 && process.argv[2] === CommandLineConstants.TabCompletionActionName; + public static isTabCompletionActionRequest(argv: string[]): boolean { + return argv && argv.length > 2 && argv[2] === CommandLineConstants.TabCompletionActionName; } } From e4a04ae4b1c755486711bc7c35aed6da2a27189f Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Sat, 8 Aug 2020 11:45:34 -0700 Subject: [PATCH 74/97] LazyLoad DeployArchiver --- apps/rush-lib/src/logic/deploy/DeployArchiver.ts | 15 ++++----------- apps/rush-lib/src/logic/deploy/DeployManager.ts | 6 ++++-- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/apps/rush-lib/src/logic/deploy/DeployArchiver.ts b/apps/rush-lib/src/logic/deploy/DeployArchiver.ts index 2082f552d74..8db2901a1cb 100644 --- a/apps/rush-lib/src/logic/deploy/DeployArchiver.ts +++ b/apps/rush-lib/src/logic/deploy/DeployArchiver.ts @@ -1,11 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line @typescript-eslint/typedef -const importLazy = require('import-lazy')(require); - -// eslint-disable-next-line @typescript-eslint/typedef -const JSZip = importLazy('jszip'); +import * as JSZip from 'jszip'; import * as path from 'path'; import { FileSystem, FileSystemStats } from '@rushstack/node-core-library'; @@ -21,8 +17,7 @@ export class DeployArchiver { public static async createArchiveAsync(deployState: IDeployState): Promise { if (deployState.createArchiveFilePath !== undefined) { console.log('Creating archive...'); - // eslint-disable-next-line @typescript-eslint/typedef - const zip = this._getZipOfFolder(deployState.targetRootFolder); + const zip: JSZip = this._getZipOfFolder(deployState.targetRootFolder); const zipContent: Buffer = await zip.generateAsync({ type: 'nodebuffer', platform: 'UNIX' @@ -59,8 +54,7 @@ export class DeployArchiver { return results; } - // eslint-disable-next-line @typescript-eslint/no-explicit-any - private static _getZipOfFolder(dir: string): any { + private static _getZipOfFolder(dir: string): JSZip { // returns a JSZip instance filled with contents of dir. const allPaths: string[] = this._getFilePathsRecursively(dir); @@ -69,8 +63,7 @@ export class DeployArchiver { // See: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/uapi/linux/stat.h#n10 const permissionsValue: number = 0o120755; - // eslint-disable-next-line @typescript-eslint/typedef - const zip = new JSZip(); + const zip: JSZip = new JSZip(); for (const filePath of allPaths) { const addPath: string = path.relative(dir, filePath); const stat: FileSystemStats = FileSystem.getLinkStatistics(filePath); diff --git a/apps/rush-lib/src/logic/deploy/DeployManager.ts b/apps/rush-lib/src/logic/deploy/DeployManager.ts index b168fe37384..9cf1ce8f455 100644 --- a/apps/rush-lib/src/logic/deploy/DeployManager.ts +++ b/apps/rush-lib/src/logic/deploy/DeployManager.ts @@ -30,7 +30,9 @@ import { NewlineKind, Text } from '@rushstack/node-core-library'; -import { DeployArchiver } from './DeployArchiver'; +// TODO: Convert this to "import type" after we upgrade to TypeScript 3.8 +import * as DeployArchiver from './DeployArchiver'; +const da: typeof DeployArchiver = importLazy('./DeployArchiver'); import { RushConfiguration } from '../../api/RushConfiguration'; import { SymlinkAnalyzer, ILinkInfo } from './SymlinkAnalyzer'; import { RushConfigurationProject } from '../../api/RushConfigurationProject'; @@ -679,7 +681,7 @@ export class DeployManager { alreadyExistsBehavior: AlreadyExistsBehavior.Error }); } - await DeployArchiver.createArchiveAsync(deployState); + await da.DeployArchiver.createArchiveAsync(deployState); } /** From 48b58f97b2626800f7a17cd3c8c44ef4d8ef4ab8 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Sat, 8 Aug 2020 12:04:33 -0700 Subject: [PATCH 75/97] Update snapshots --- apps/rush-lib/src/cli/test/CommandLineHelp.test.ts | 1 + .../__snapshots__/CommandLineHelp.test.ts.snap | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/apps/rush-lib/src/cli/test/CommandLineHelp.test.ts b/apps/rush-lib/src/cli/test/CommandLineHelp.test.ts index ff05b7b4c77..155d1fb2c2c 100644 --- a/apps/rush-lib/src/cli/test/CommandLineHelp.test.ts +++ b/apps/rush-lib/src/cli/test/CommandLineHelp.test.ts @@ -25,6 +25,7 @@ describe('CommandLineHelp', () => { // if it encounters errors. // TODO Remove the calls to process.exit() or override them for testing. parser = new RushCommandLineParser(); + parser.execute().catch(console.error); }); it('prints the global help', () => { diff --git a/apps/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap b/apps/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap index 9f914ab4e7c..db4fa93faa5 100644 --- a/apps/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap +++ b/apps/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap @@ -53,6 +53,7 @@ Positional arguments: build Build all projects that haven't been built, or have changed since they were last built. rebuild Clean and rebuild the entire set of projects + tab-complete Provides tab completion. Optional arguments: -h, --help Show this help message and exit. @@ -657,6 +658,19 @@ Optional arguments: " `; +exports[`CommandLineHelp prints the help for each action: tab-complete 1`] = ` +"usage: rush tab-complete [-h] [--word WORD] [--position INDEX] + +Provides tab completion. + +Optional arguments: + -h, --help Show this help message and exit. + --word WORD The word to complete. The default value is \\"\\". + --position INDEX The position in the word to be completed. The default + value is 0. +" +`; + exports[`CommandLineHelp prints the help for each action: unlink 1`] = ` "usage: rush unlink [-h] From 68b3a84815a56ccbe989d8edd5c24c3a5563d8c7 Mon Sep 17 00:00:00 2001 From: Pete Gonzalez <4673363+octogonz@users.noreply.github.com> Date: Sat, 8 Aug 2020 14:02:53 -0700 Subject: [PATCH 76/97] Prototype of a basic Import API for lazy imports --- apps/rush-lib/src/cli/actions/ScanAction.ts | 8 ++------ common/reviews/api/node-core-library.api.md | 6 ++++++ libraries/node-core-library/src/Import.ts | 15 +++++++++++++++ libraries/node-core-library/src/index.ts | 1 + 4 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 libraries/node-core-library/src/Import.ts diff --git a/apps/rush-lib/src/cli/actions/ScanAction.ts b/apps/rush-lib/src/cli/actions/ScanAction.ts index 41937b84733..7bf03840147 100644 --- a/apps/rush-lib/src/cli/actions/ScanAction.ts +++ b/apps/rush-lib/src/cli/actions/ScanAction.ts @@ -1,15 +1,11 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line @typescript-eslint/typedef -const importLazy = require('import-lazy')(require); - +import { Import, FileSystem } from '@rushstack/node-core-library'; import * as colors from 'colors'; -// eslint-disable-next-line @typescript-eslint/typedef -const glob = importLazy('glob'); +const glob: typeof import('glob') = Import.lazy('glob', require); import * as path from 'path'; import * as builtinPackageNames from 'builtin-modules'; -import { FileSystem } from '@rushstack/node-core-library'; import { RushCommandLineParser } from '../RushCommandLineParser'; import { BaseConfiglessRushAction } from './BaseRushAction'; diff --git a/common/reviews/api/node-core-library.api.md b/common/reviews/api/node-core-library.api.md index f7b7574be3c..24f5c636d45 100644 --- a/common/reviews/api/node-core-library.api.md +++ b/common/reviews/api/node-core-library.api.md @@ -333,6 +333,12 @@ export interface IJsonSchemaValidateOptions { customErrorHeader?: string; } +// @public (undocumented) +export class Import { + // (undocumented) + static lazy(moduleName: string, require: (id: string) => unknown): any; +} + // @public export interface INodePackageJson { bin?: string; diff --git a/libraries/node-core-library/src/Import.ts b/libraries/node-core-library/src/Import.ts new file mode 100644 index 00000000000..78e70ccfa5e --- /dev/null +++ b/libraries/node-core-library/src/Import.ts @@ -0,0 +1,15 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. +// See LICENSE in the project root for license information. + +import importLazy = require('import-lazy'); + +/** + * @public + */ +export class Import { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + public static lazy(moduleName: string, require: (id: string) => unknown): any { + const importLazyLocal: (moduleName: string) => unknown = importLazy(require); + return importLazyLocal(moduleName); + } +} diff --git a/libraries/node-core-library/src/index.ts b/libraries/node-core-library/src/index.ts index 7e23cfa79ca..1b3496cad2b 100644 --- a/libraries/node-core-library/src/index.ts +++ b/libraries/node-core-library/src/index.ts @@ -21,6 +21,7 @@ export { IPackageJsonDependencyTable, IPackageJsonScriptTable } from './IPackageJson'; +export { Import } from './Import'; export { InternalError } from './InternalError'; export { JsonObject, JsonFile, IJsonFileSaveOptions, IJsonFileStringifyOptions } from './JsonFile'; export { From 8068c829e7b8e2c78c94b57a37c88d181600290e Mon Sep 17 00:00:00 2001 From: Pete Gonzalez <4673363+octogonz@users.noreply.github.com> Date: Sat, 8 Aug 2020 18:37:17 -0700 Subject: [PATCH 77/97] Convert more files to use the Import API --- apps/rush-lib/src/api/LastInstallFlag.ts | 12 +++--- apps/rush-lib/src/api/VersionPolicy.ts | 13 +++---- apps/rush-lib/src/cli/actions/ChangeAction.ts | 38 ++++++++++--------- apps/rush-lib/src/cli/actions/ListAction.ts | 10 ++--- apps/rush-lib/src/cli/actions/ScanAction.ts | 5 ++- apps/rush-lib/src/logic/ChangeFiles.ts | 9 ++--- apps/rush-lib/src/logic/Telemetry.ts | 11 ++---- apps/rush-lib/src/logic/VersionManager.ts | 11 ++---- .../src/logic/base/BaseInstallManager.ts | 9 ++--- libraries/node-core-library/src/FileSystem.ts | 9 ++--- libraries/node-core-library/src/FileWriter.ts | 6 +-- 11 files changed, 56 insertions(+), 77 deletions(-) diff --git a/apps/rush-lib/src/api/LastInstallFlag.ts b/apps/rush-lib/src/api/LastInstallFlag.ts index 05326f1a62f..09612290903 100644 --- a/apps/rush-lib/src/api/LastInstallFlag.ts +++ b/apps/rush-lib/src/api/LastInstallFlag.ts @@ -1,17 +1,15 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line @typescript-eslint/typedef -const importLazy = require('import-lazy')(require); - import * as path from 'path'; -// eslint-disable-next-line @typescript-eslint/typedef -const _ = importLazy('lodash'); -import { FileSystem, JsonFile, JsonObject } from '@rushstack/node-core-library'; + +import { FileSystem, JsonFile, JsonObject, Import } from '@rushstack/node-core-library'; import { PackageManagerName } from './packageManager/PackageManager'; import { RushConfiguration } from './RushConfiguration'; +const lodash: typeof import('lodash') = Import.lazy('lodash', require); + export const LAST_INSTALL_FLAG_FILE_NAME: string = 'last-install.flag'; /** @@ -62,7 +60,7 @@ export class LastInstallFlag { const newState: JsonObject = this._state; - if (!_.isEqual(oldState, newState)) { + if (!lodash.isEqual(oldState, newState)) { if (checkValidAndReportStoreIssues) { const pkgManager: PackageManagerName = newState.packageManager; if (pkgManager === 'pnpm') { diff --git a/apps/rush-lib/src/api/VersionPolicy.ts b/apps/rush-lib/src/api/VersionPolicy.ts index 1c6c10f650c..51712c24254 100644 --- a/apps/rush-lib/src/api/VersionPolicy.ts +++ b/apps/rush-lib/src/api/VersionPolicy.ts @@ -1,13 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line @typescript-eslint/typedef -const importLazy = require('import-lazy')(require); - -// eslint-disable-next-line @typescript-eslint/typedef -const _ = importLazy('lodash'); import * as semver from 'semver'; -import { IPackageJson } from '@rushstack/node-core-library'; +import { IPackageJson, Import } from '@rushstack/node-core-library'; import { IVersionPolicyJson, @@ -21,6 +16,8 @@ import { PackageJsonEditor } from './PackageJsonEditor'; import { RushConfiguration } from './RushConfiguration'; import { RushConfigurationProject } from './RushConfigurationProject'; +const lodash: typeof import('lodash') = Import.lazy('lodash', require); + /** * Type of version bumps * @beta @@ -324,7 +321,7 @@ export class LockStepVersionPolicy extends VersionPolicy { } private _updatePackageVersion(project: IPackageJson, newVersion: semver.SemVer): IPackageJson { - const updatedProject: IPackageJson = _.cloneDeep(project); + const updatedProject: IPackageJson = lodash.cloneDeep(project); updatedProject.version = newVersion.format(); return updatedProject; } @@ -383,7 +380,7 @@ export class IndividualVersionPolicy extends VersionPolicy { if (this.lockedMajor) { const version: semver.SemVer = new semver.SemVer(project.version); if (version.major < this.lockedMajor) { - const updatedProject: IPackageJson = _.cloneDeep(project); + const updatedProject: IPackageJson = lodash.cloneDeep(project); updatedProject.version = `${this._lockedMajor}.0.0`; return updatedProject; } else if (version.major > this.lockedMajor) { diff --git a/apps/rush-lib/src/cli/actions/ChangeAction.ts b/apps/rush-lib/src/cli/actions/ChangeAction.ts index b952b5ca4b5..187d3a6b4c8 100644 --- a/apps/rush-lib/src/cli/actions/ChangeAction.ts +++ b/apps/rush-lib/src/cli/actions/ChangeAction.ts @@ -1,24 +1,17 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line @typescript-eslint/typedef -const importLazy = require('import-lazy')(require); - import * as os from 'os'; import * as path from 'path'; import * as child_process from 'child_process'; import * as colors from 'colors'; -// eslint-disable-next-line @typescript-eslint/typedef -const inquirer = importLazy('inquirer'); -// TODO: Convert this to "import type" after we upgrade to TypeScript 3.8 -import { PromptModule } from 'inquirer'; import { CommandLineFlagParameter, CommandLineStringParameter, CommandLineChoiceParameter } from '@rushstack/ts-command-line'; -import { FileSystem, Path } from '@rushstack/node-core-library'; +import { FileSystem, Path, Import } from '@rushstack/node-core-library'; import { RushConfigurationProject } from '../../api/RushConfigurationProject'; import { IChangeFile, IChangeInfo, ChangeType } from '../../api/ChangeManagement'; @@ -35,6 +28,10 @@ import { } from '../../api/VersionPolicy'; import { AlreadyReportedError } from '../../utilities/AlreadyReportedError'; +const inquirer: typeof import('inquirer') = Import.lazy('inquirer', require); +// TODO: Convert this to "import type" after we upgrade to TypeScript 3.8 +import * as inquirerTypes from 'inquirer'; + export class ChangeAction extends BaseRushAction { private _verifyParameter: CommandLineFlagParameter; private _noFetchParameter: CommandLineFlagParameter; @@ -184,7 +181,7 @@ export class ChangeAction extends BaseRushAction { this._warnUncommittedChanges(); - const promptModule: PromptModule = inquirer.createPromptModule(); + const promptModule: inquirerTypes.PromptModule = inquirer.createPromptModule(); let changeFileData: Map = new Map(); let interactiveMode: boolean = false; if (this._bulkChangeParameter.value) { @@ -372,7 +369,7 @@ export class ChangeAction extends BaseRushAction { * The main loop which prompts the user for information on changed projects. */ private async _promptForChangeFileData( - promptModule: PromptModule, + promptModule: inquirerTypes.PromptModule, sortedProjectList: string[], existingChangeComments: Map ): Promise> { @@ -407,7 +404,7 @@ export class ChangeAction extends BaseRushAction { * Asks all questions which are needed to generate changelist for a project. */ private async _askQuestions( - promptModule: PromptModule, + promptModule: inquirerTypes.PromptModule, packageName: string, existingChangeComments: Map ): Promise { @@ -446,7 +443,7 @@ export class ChangeAction extends BaseRushAction { } private async _promptForComments( - promptModule: PromptModule, + promptModule: inquirerTypes.PromptModule, packageName: string ): Promise { const bumpOptions: { [type: string]: string } = this._getBumpOptions(packageName); @@ -525,7 +522,7 @@ export class ChangeAction extends BaseRushAction { * Will determine a user's email by first detecting it from their Git config, * or will ask for it if it is not found or the Git config is wrong. */ - private async _detectOrAskForEmail(promptModule: PromptModule): Promise { + private async _detectOrAskForEmail(promptModule: inquirerTypes.PromptModule): Promise { return (await this._detectAndConfirmEmail(promptModule)) || (await this._promptForEmail(promptModule)); } @@ -545,7 +542,9 @@ export class ChangeAction extends BaseRushAction { * Detects the user's email address from their Git configuration, prompts the user to approve the * detected email. It returns undefined if it cannot be detected. */ - private async _detectAndConfirmEmail(promptModule: PromptModule): Promise { + private async _detectAndConfirmEmail( + promptModule: inquirerTypes.PromptModule + ): Promise { const email: string | undefined = this._detectEmail(); if (email) { @@ -566,7 +565,7 @@ export class ChangeAction extends BaseRushAction { /** * Asks the user for their email address */ - private async _promptForEmail(promptModule: PromptModule): Promise { + private async _promptForEmail(promptModule: inquirerTypes.PromptModule): Promise { const { email }: { email: string } = await promptModule([ { type: 'input', @@ -600,7 +599,7 @@ export class ChangeAction extends BaseRushAction { * Writes change files to the common/changes folder. Will prompt for overwrite if file already exists. */ private async _writeChangeFiles( - promptModule: PromptModule, + promptModule: inquirerTypes.PromptModule, changeFileData: Map, overwrite: boolean, interactiveMode: boolean @@ -611,7 +610,7 @@ export class ChangeAction extends BaseRushAction { } private async _writeChangeFile( - promptModule: PromptModule, + promptModule: inquirerTypes.PromptModule, changeFileData: IChangeFile, overwrite: boolean, interactiveMode: boolean @@ -635,7 +634,10 @@ export class ChangeAction extends BaseRushAction { } } - private async _promptForOverwrite(promptModule: PromptModule, filePath: string): Promise { + private async _promptForOverwrite( + promptModule: inquirerTypes.PromptModule, + filePath: string + ): Promise { const overwrite: boolean = await promptModule([ { name: 'overwrite', diff --git a/apps/rush-lib/src/cli/actions/ListAction.ts b/apps/rush-lib/src/cli/actions/ListAction.ts index af151c0ae1e..4f6dbaace17 100644 --- a/apps/rush-lib/src/cli/actions/ListAction.ts +++ b/apps/rush-lib/src/cli/actions/ListAction.ts @@ -1,15 +1,13 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line @typescript-eslint/typedef -const importLazy = require('import-lazy')(require); - +import { Import } from '@rushstack/node-core-library'; import { BaseRushAction } from './BaseRushAction'; import { RushCommandLineParser } from '../RushCommandLineParser'; import { CommandLineFlagParameter } from '@rushstack/ts-command-line'; import { RushConfigurationProject } from '../../api/RushConfigurationProject'; -// eslint-disable-next-line @typescript-eslint/typedef -const Table = importLazy('cli-table'); + +const cliTable: typeof import('cli-table') = Import.lazy('cli-table', require); export interface IJsonEntry { name: string; @@ -119,7 +117,7 @@ export class ListAction extends BaseRushAction { } // eslint-disable-next-line @typescript-eslint/typedef - const table = new Table({ + const table = new cliTable({ head: tableHeader }); diff --git a/apps/rush-lib/src/cli/actions/ScanAction.ts b/apps/rush-lib/src/cli/actions/ScanAction.ts index 7bf03840147..458df28a21e 100644 --- a/apps/rush-lib/src/cli/actions/ScanAction.ts +++ b/apps/rush-lib/src/cli/actions/ScanAction.ts @@ -1,15 +1,16 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -import { Import, FileSystem } from '@rushstack/node-core-library'; import * as colors from 'colors'; -const glob: typeof import('glob') = Import.lazy('glob', require); import * as path from 'path'; import * as builtinPackageNames from 'builtin-modules'; +import { Import, FileSystem } from '@rushstack/node-core-library'; import { RushCommandLineParser } from '../RushCommandLineParser'; import { BaseConfiglessRushAction } from './BaseRushAction'; +const glob: typeof import('glob') = Import.lazy('glob', require); + export class ScanAction extends BaseConfiglessRushAction { public constructor(parser: RushCommandLineParser) { super({ diff --git a/apps/rush-lib/src/logic/ChangeFiles.ts b/apps/rush-lib/src/logic/ChangeFiles.ts index 9244c36fc35..61c9a1fa96a 100644 --- a/apps/rush-lib/src/logic/ChangeFiles.ts +++ b/apps/rush-lib/src/logic/ChangeFiles.ts @@ -1,19 +1,16 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line @typescript-eslint/typedef -const importLazy = require('import-lazy')(require); - import { EOL } from 'os'; -// eslint-disable-next-line @typescript-eslint/typedef -const glob = importLazy('glob'); -import { JsonFile } from '@rushstack/node-core-library'; +import { JsonFile, Import } from '@rushstack/node-core-library'; import { Utilities } from '../utilities/Utilities'; import { IChangeInfo } from '../api/ChangeManagement'; import { IChangelog } from '../api/Changelog'; import { RushConfiguration } from '../api/RushConfiguration'; +const glob: typeof import('glob') = Import.lazy('glob', require); + /** * This class represents the collection of change files existing in the repo and provides operations * for those change files. diff --git a/apps/rush-lib/src/logic/Telemetry.ts b/apps/rush-lib/src/logic/Telemetry.ts index 8a8b6d600cb..fa128172fb2 100644 --- a/apps/rush-lib/src/logic/Telemetry.ts +++ b/apps/rush-lib/src/logic/Telemetry.ts @@ -1,18 +1,15 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line @typescript-eslint/typedef -const importLazy = require('import-lazy')(require); - import * as fs from 'fs'; import * as path from 'path'; -// eslint-disable-next-line @typescript-eslint/typedef -const _ = importLazy('lodash'); -import { FileSystem } from '@rushstack/node-core-library'; +import { FileSystem, Import } from '@rushstack/node-core-library'; import { RushConfiguration } from '../api/RushConfiguration'; import { Rush } from '../api/Rush'; +const lodash: typeof import('lodash') = Import.lazy('lodash', require); + export interface ITelemetryData { name: string; duration: number; @@ -44,7 +41,7 @@ export class Telemetry { if (!this._enabled) { return; } - const data: ITelemetryData = _.cloneDeep(telemetryData); + const data: ITelemetryData = lodash.cloneDeep(telemetryData); data.timestamp = data.timestamp || new Date().getTime(); data.platform = data.platform || process.platform; data.rushVersion = data.rushVersion || Rush.version; diff --git a/apps/rush-lib/src/logic/VersionManager.ts b/apps/rush-lib/src/logic/VersionManager.ts index 6f28d745f4d..384723f927e 100644 --- a/apps/rush-lib/src/logic/VersionManager.ts +++ b/apps/rush-lib/src/logic/VersionManager.ts @@ -1,14 +1,9 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line @typescript-eslint/typedef -const importLazy = require('import-lazy')(require); - import * as path from 'path'; import * as semver from 'semver'; -// eslint-disable-next-line @typescript-eslint/typedef -const _ = importLazy('lodash'); -import { IPackageJson, JsonFile, FileConstants } from '@rushstack/node-core-library'; +import { IPackageJson, JsonFile, FileConstants, Import } from '@rushstack/node-core-library'; import { VersionPolicy, BumpType, LockStepVersionPolicy } from '../api/VersionPolicy'; import { ChangeFile } from '../api/ChangeFile'; @@ -20,6 +15,8 @@ import { PublishUtilities } from './PublishUtilities'; import { ChangeManager } from './ChangeManager'; import { DependencySpecifier } from './DependencySpecifier'; +const lodash: typeof import('lodash') = Import.lazy('lodash', require); + export class VersionManager { private _rushConfiguration: RushConfiguration; private _userEmail: string; @@ -189,7 +186,7 @@ export class VersionManager { let clonedProject: IPackageJson | undefined = this._updatedProjects.get(rushProject.packageName); let projectVersionChanged: boolean = true; if (!clonedProject) { - clonedProject = _.cloneDeep(rushProject.packageJson); + clonedProject = lodash.cloneDeep(rushProject.packageJson); projectVersionChanged = false; } this._updateProjectAllDependencies(rushProject, clonedProject!, projectVersionChanged); diff --git a/apps/rush-lib/src/logic/base/BaseInstallManager.ts b/apps/rush-lib/src/logic/base/BaseInstallManager.ts index a5a00579116..9b562f6c267 100644 --- a/apps/rush-lib/src/logic/base/BaseInstallManager.ts +++ b/apps/rush-lib/src/logic/base/BaseInstallManager.ts @@ -1,19 +1,14 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line @typescript-eslint/typedef -const importLazy = require('import-lazy')(require); - import * as colors from 'colors'; import * as fetch from 'node-fetch'; import * as fs from 'fs'; import * as http from 'http'; -// eslint-disable-next-line @typescript-eslint/typedef -const HttpsProxyAgent = importLazy('https-proxy-agent'); import * as os from 'os'; import * as path from 'path'; import * as semver from 'semver'; -import { FileSystem, JsonFile, PosixModeBits, NewlineKind } from '@rushstack/node-core-library'; +import { FileSystem, JsonFile, PosixModeBits, NewlineKind, Import } from '@rushstack/node-core-library'; import { AlreadyReportedError } from '../../utilities/AlreadyReportedError'; import { ApprovedPackagesChecker } from '../ApprovedPackagesChecker'; @@ -35,6 +30,8 @@ import { InstallHelpers } from '../installManager/InstallHelpers'; import { PolicyValidator } from '../policy/PolicyValidator'; import { RushConfigurationProject } from '../../api/RushConfigurationProject'; +const HttpsProxyAgent: typeof import('https-proxy-agent') = Import.lazy('https-proxy-agent', require); + export interface IInstallManagerOptions { /** * Whether the global "--debug" flag was specified. diff --git a/libraries/node-core-library/src/FileSystem.ts b/libraries/node-core-library/src/FileSystem.ts index 627720da104..1e5a7fffb3e 100644 --- a/libraries/node-core-library/src/FileSystem.ts +++ b/libraries/node-core-library/src/FileSystem.ts @@ -1,17 +1,14 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line @typescript-eslint/typedef -const importLazy = require('import-lazy')(require); - import * as nodeJsPath from 'path'; import * as fs from 'fs'; -// eslint-disable-next-line @typescript-eslint/typedef -const fsx = importLazy('fs-extra'); - import { Text, NewlineKind, Encoding } from './Text'; import { PosixModeBits } from './PosixModeBits'; +import { Import } from './Import'; + +const fsx: typeof import('fs-extra') = Import.lazy('fs-extra', require); /** * An alias for the Node.js `fs.Stats` object. diff --git a/libraries/node-core-library/src/FileWriter.ts b/libraries/node-core-library/src/FileWriter.ts index 0913f60c277..145a80f83e3 100644 --- a/libraries/node-core-library/src/FileWriter.ts +++ b/libraries/node-core-library/src/FileWriter.ts @@ -1,11 +1,9 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line @typescript-eslint/typedef -const importLazy = require('import-lazy')(require); +import { Import } from './Import'; -// eslint-disable-next-line @typescript-eslint/typedef -const fsx = importLazy('fs-extra'); +const fsx: typeof import('fs-extra') = Import.lazy('fs-extra', require); /** * Available file handle opening flags. From 90c099799fec08b2b795c4a6acf6b356e834d4d6 Mon Sep 17 00:00:00 2001 From: Pete Gonzalez <4673363+octogonz@users.noreply.github.com> Date: Sat, 8 Aug 2020 18:38:45 -0700 Subject: [PATCH 78/97] Revert all changes to DeployManager.ts --- .../src/logic/deploy/DeployManager.ts | 30 ++++++++----------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/apps/rush-lib/src/logic/deploy/DeployManager.ts b/apps/rush-lib/src/logic/deploy/DeployManager.ts index 9cf1ce8f455..5adb84c64cf 100644 --- a/apps/rush-lib/src/logic/deploy/DeployManager.ts +++ b/apps/rush-lib/src/logic/deploy/DeployManager.ts @@ -1,17 +1,11 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line @typescript-eslint/typedef -const importLazy = require('import-lazy')(require); - import * as colors from 'colors'; import * as path from 'path'; -// eslint-disable-next-line @typescript-eslint/typedef -const resolve = importLazy('resolve'); -// eslint-disable-next-line @typescript-eslint/typedef -const npmPacklist = importLazy('npm-packlist'); -// eslint-disable-next-line @typescript-eslint/typedef -const pnpmLinkBins = importLazy('@pnpm/link-bins'); +import * as resolve from 'resolve'; +import * as npmPacklist from 'npm-packlist'; +import pnpmLinkBins from '@pnpm/link-bins'; // (Used only by the legacy code fragment in the resolve.sync() hook below) import * as fsForResolve from 'fs'; @@ -30,9 +24,7 @@ import { NewlineKind, Text } from '@rushstack/node-core-library'; -// TODO: Convert this to "import type" after we upgrade to TypeScript 3.8 -import * as DeployArchiver from './DeployArchiver'; -const da: typeof DeployArchiver = importLazy('./DeployArchiver'); +import { DeployArchiver } from './DeployArchiver'; import { RushConfiguration } from '../../api/RushConfiguration'; import { SymlinkAnalyzer, ILinkInfo } from './SymlinkAnalyzer'; import { RushConfigurationProject } from '../../api/RushConfigurationProject'; @@ -40,9 +32,13 @@ import { DeployScenarioConfiguration, IDeployScenarioProjectJson } from './Deplo import { PnpmfileConfiguration } from './PnpmfileConfiguration'; import { matchesWithStar } from './Utils'; -interface INpmPackListWalkerSync { - readonly result: string[]; - start(): void; +// (@types/npm-packlist is missing this API) +declare module 'npm-packlist' { + export class WalkerSync { + public readonly result: string[]; + public constructor(opts: { path: string }); + public start(): void; + } } /** @@ -390,7 +386,7 @@ export class DeployManager { if (useNpmIgnoreFilter) { // Use npm-packlist to filter the files. Using the WalkerSync class (instead of the sync() API) ensures // that "bundledDependencies" are not included. - const walker: INpmPackListWalkerSync = new npmPacklist.WalkerSync({ + const walker: npmPacklist.WalkerSync = new npmPacklist.WalkerSync({ path: sourceFolderPath }); walker.start(); @@ -681,7 +677,7 @@ export class DeployManager { alreadyExistsBehavior: AlreadyExistsBehavior.Error }); } - await da.DeployArchiver.createArchiveAsync(deployState); + await DeployArchiver.createArchiveAsync(deployState); } /** From 71175bd4d253fad764e1abf859517fd869eadd57 Mon Sep 17 00:00:00 2001 From: Pete Gonzalez <4673363+octogonz@users.noreply.github.com> Date: Sat, 8 Aug 2020 18:48:33 -0700 Subject: [PATCH 79/97] Convert DeployManager to be lazy-loaded --- apps/rush-lib/src/cli/actions/DeployAction.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/apps/rush-lib/src/cli/actions/DeployAction.ts b/apps/rush-lib/src/cli/actions/DeployAction.ts index a3aa8fa3725..e06889b8f61 100644 --- a/apps/rush-lib/src/cli/actions/DeployAction.ts +++ b/apps/rush-lib/src/cli/actions/DeployAction.ts @@ -1,10 +1,18 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +import { Import } from '@rushstack/node-core-library'; + import { BaseRushAction } from './BaseRushAction'; import { RushCommandLineParser } from '../RushCommandLineParser'; import { CommandLineFlagParameter, CommandLineStringParameter } from '@rushstack/ts-command-line'; -import { DeployManager } from '../../logic/deploy/DeployManager'; + +const deployManagerModule: typeof import('../../logic/deploy/DeployManager') = Import.lazy( + '../../logic/deploy/DeployManager', + require +); +// TODO: Convert this to "import type" after we upgrade to TypeScript 3.8 +import * as deployManagerTypes from '../../logic/deploy/DeployManager'; export class DeployAction extends BaseRushAction { private _scenario: CommandLineStringParameter; @@ -78,7 +86,9 @@ export class DeployAction extends BaseRushAction { } protected async runAsync(): Promise { - const deployManager: DeployManager = new DeployManager(this.rushConfiguration); + const deployManager: deployManagerTypes.DeployManager = new deployManagerModule.DeployManager( + this.rushConfiguration + ); await deployManager.deployAsync( this._project.value, this._scenario.value, From c34c07e7219de1036eca1937f5347073542c8662 Mon Sep 17 00:00:00 2001 From: Pete Gonzalez <4673363+octogonz@users.noreply.github.com> Date: Sat, 8 Aug 2020 18:54:19 -0700 Subject: [PATCH 80/97] Revert all changes to RushInstallManager.ts --- .../installManager/RushInstallManager.ts | 21 +++++-------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/apps/rush-lib/src/logic/installManager/RushInstallManager.ts b/apps/rush-lib/src/logic/installManager/RushInstallManager.ts index cb4872d83c7..ad685ee5d2f 100644 --- a/apps/rush-lib/src/logic/installManager/RushInstallManager.ts +++ b/apps/rush-lib/src/logic/installManager/RushInstallManager.ts @@ -1,19 +1,12 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line @typescript-eslint/typedef -const importLazy = require('import-lazy')(require); - -// eslint-disable-next-line @typescript-eslint/typedef -const glob = importLazy('glob'); +import * as glob from 'glob'; import * as colors from 'colors'; import * as os from 'os'; import * as path from 'path'; import * as semver from 'semver'; -// eslint-disable-next-line @typescript-eslint/typedef -const tar = importLazy('tar'); -// TODO: Convert this to "import type" after we upgrade to TypeScript 3.8 -import { CreateOptions, FileStat } from 'tar'; +import * as tar from 'tar'; import * as globEscape from 'glob-escape'; import { JsonFile, @@ -357,20 +350,16 @@ export class RushInstallManager extends BaseInstallManager { // NPM expects the root of the tarball to have a directory called 'package' const npmPackageFolder: string = 'package'; - const tarOptions: CreateOptions = { + const tarOptions: tar.CreateOptions = { gzip: true, file: tarballFile, cwd: tempProjectFolder, portable: true, - /** - * Set to true to omit writing mtime values for entries. Note that this prevents using other - * mtime-based features like tar.update or the keepNewer option with the resulting tar archive. - */ noMtime: true, noPax: true, sync: true, prefix: npmPackageFolder, - filter: (path: string, stat: FileStat): boolean => { + filter: (path: string, stat: tar.FileStat): boolean => { if ( !this.rushConfiguration.experimentsConfiguration.configuration.noChmodFieldInTarHeaderNormalization ) { @@ -380,7 +369,7 @@ export class RushInstallManager extends BaseInstallManager { } return true; } - } as CreateOptions; + } as tar.CreateOptions; // create the new tarball tar.create(tarOptions, [FileConstants.PackageJson]); } From a1cc5d8a6d9e0261a4e1b62f16d5845113983239 Mon Sep 17 00:00:00 2001 From: Pete Gonzalez <4673363+octogonz@users.noreply.github.com> Date: Sat, 8 Aug 2020 18:56:32 -0700 Subject: [PATCH 81/97] Convert RushInstallManager to be lazy-loaded --- apps/rush-lib/src/cli/actions/DeployAction.ts | 2 +- apps/rush-lib/src/logic/InstallManagerFactory.ts | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/apps/rush-lib/src/cli/actions/DeployAction.ts b/apps/rush-lib/src/cli/actions/DeployAction.ts index e06889b8f61..f38e6a6c472 100644 --- a/apps/rush-lib/src/cli/actions/DeployAction.ts +++ b/apps/rush-lib/src/cli/actions/DeployAction.ts @@ -2,10 +2,10 @@ // See LICENSE in the project root for license information. import { Import } from '@rushstack/node-core-library'; +import { CommandLineFlagParameter, CommandLineStringParameter } from '@rushstack/ts-command-line'; import { BaseRushAction } from './BaseRushAction'; import { RushCommandLineParser } from '../RushCommandLineParser'; -import { CommandLineFlagParameter, CommandLineStringParameter } from '@rushstack/ts-command-line'; const deployManagerModule: typeof import('../../logic/deploy/DeployManager') = Import.lazy( '../../logic/deploy/DeployManager', diff --git a/apps/rush-lib/src/logic/InstallManagerFactory.ts b/apps/rush-lib/src/logic/InstallManagerFactory.ts index fb27a19b0da..466e3826742 100644 --- a/apps/rush-lib/src/logic/InstallManagerFactory.ts +++ b/apps/rush-lib/src/logic/InstallManagerFactory.ts @@ -4,14 +4,20 @@ import * as colors from 'colors'; import * as semver from 'semver'; +import { Import } from '@rushstack/node-core-library'; + import { BaseInstallManager, IInstallManagerOptions } from './base/BaseInstallManager'; -import { RushInstallManager } from './installManager/RushInstallManager'; import { WorkspaceInstallManager } from './installManager/WorkspaceInstallManager'; import { AlreadyReportedError } from '../utilities/AlreadyReportedError'; import { PurgeManager } from './PurgeManager'; import { RushConfiguration } from '../api/RushConfiguration'; import { RushGlobalFolder } from '../api/RushGlobalFolder'; +const rushInstallManagerModule: typeof import('./installManager/RushInstallManager') = Import.lazy( + './installManager/RushInstallManager', + require +); + export class InstallManagerFactory { public static getInstallManager( rushConfiguration: RushConfiguration, @@ -37,6 +43,11 @@ export class InstallManagerFactory { return new WorkspaceInstallManager(rushConfiguration, rushGlobalFolder, purgeManager, options); } - return new RushInstallManager(rushConfiguration, rushGlobalFolder, purgeManager, options); + return new rushInstallManagerModule.RushInstallManager( + rushConfiguration, + rushGlobalFolder, + purgeManager, + options + ); } } From 22647a659e888f69e11a300aae4fba41204de3b5 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Sat, 8 Aug 2020 19:06:13 -0700 Subject: [PATCH 82/97] Shave off a few hundred milliseconds from the startup time --- apps/rush-lib/src/api/Rush.ts | 19 ++++++++++++++++--- apps/rush-lib/src/cli/actions/AddAction.ts | 11 ++++++++++- .../src/cli/actions/BaseInstallAction.ts | 11 +++++++++-- apps/rush-lib/src/cli/actions/LinkAction.ts | 13 +++++++++++-- apps/rush-lib/src/start.ts | 5 ++++- common/reviews/api/rush-lib.api.md | 4 ++-- libraries/node-core-library/src/FileSystem.ts | 7 +------ 7 files changed, 53 insertions(+), 17 deletions(-) diff --git a/apps/rush-lib/src/api/Rush.ts b/apps/rush-lib/src/api/Rush.ts index c2b3910a245..97966ac1154 100644 --- a/apps/rush-lib/src/api/Rush.ts +++ b/apps/rush-lib/src/api/Rush.ts @@ -38,6 +38,8 @@ export interface ILaunchOptions { * @public */ export class Rush { + private static _version: string | undefined = undefined; + /** * This API is used by the `@microsoft/rush` front end to launch the "rush" command-line. * Third-party tools should not use this API. Instead, they should execute the "rush" binary @@ -51,7 +53,7 @@ export class Rush { * * Even though this API isn't documented, it is still supported for legacy compatibility. */ - public static launch(launcherVersion: string, arg: ILaunchOptions): void { + public static launch(launcherVersion: string, arg: ILaunchOptions, cb: () => void = () => {}): void { const options: ILaunchOptions = Rush._normalizeLaunchOptions(arg); if (!Utilities.shouldRestrictConsoleOutput()) { @@ -67,7 +69,14 @@ export class Rush { const parser: RushCommandLineParser = new RushCommandLineParser({ alreadyReportedNodeTooNewError: options.alreadyReportedNodeTooNewError }); - parser.execute().catch(console.error); // CommandLineParser.execute() should never reject the promise + parser + .execute() + .then(() => { + if (cb) { + cb(); + } + }) + .catch(console.error); // CommandLineParser.execute() should never reject the promise } /** @@ -90,7 +99,11 @@ export class Rush { * This is the same as the Rush tool version for that release. */ public static get version(): string { - return PackageJsonLookup.getOwnPackageJsonVersion(__dirname); + if (!this._version) { + this._version = PackageJsonLookup.getOwnPackageJsonVersion(__dirname); + } + + return this._version!; } /** diff --git a/apps/rush-lib/src/cli/actions/AddAction.ts b/apps/rush-lib/src/cli/actions/AddAction.ts index 308d886867a..6f57bab5096 100644 --- a/apps/rush-lib/src/cli/actions/AddAction.ts +++ b/apps/rush-lib/src/cli/actions/AddAction.ts @@ -1,6 +1,9 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +// eslint-disable-next-line @typescript-eslint/typedef +const importLazy = require('import-lazy')(require); + import * as os from 'os'; import * as semver from 'semver'; @@ -9,7 +12,10 @@ import { CommandLineFlagParameter, CommandLineStringParameter } from '@rushstack import { RushConfigurationProject } from '../../api/RushConfigurationProject'; import { BaseRushAction } from './BaseRushAction'; import { RushCommandLineParser } from '../RushCommandLineParser'; +// TODO: Convert this to "import type" after we upgrade to TypeScript 3.8 import { PackageJsonUpdater, SemVerStyle } from '../../logic/PackageJsonUpdater'; +import * as PackageJsonUpdaterW from '../../logic/PackageJsonUpdater'; +const packageJsonUpdaterExports: typeof PackageJsonUpdaterW = importLazy('../../logic/PackageJsonUpdater'); import { DependencySpecifier } from '../../logic/DependencySpecifier'; export class AddAction extends BaseRushAction { @@ -136,7 +142,10 @@ export class AddAction extends BaseRushAction { } } - const updater: PackageJsonUpdater = new PackageJsonUpdater(this.rushConfiguration, this.rushGlobalFolder); + const updater: PackageJsonUpdater = new packageJsonUpdaterExports.PackageJsonUpdater( + this.rushConfiguration, + this.rushGlobalFolder + ); let rangeStyle: SemVerStyle; if (version && version !== 'latest') { diff --git a/apps/rush-lib/src/cli/actions/BaseInstallAction.ts b/apps/rush-lib/src/cli/actions/BaseInstallAction.ts index 3ed4c7c06fc..7f39f08c924 100644 --- a/apps/rush-lib/src/cli/actions/BaseInstallAction.ts +++ b/apps/rush-lib/src/cli/actions/BaseInstallAction.ts @@ -1,6 +1,9 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +// eslint-disable-next-line @typescript-eslint/typedef +const importLazy = require('import-lazy')(require); + import * as colors from 'colors'; import * as os from 'os'; @@ -13,7 +16,11 @@ import { import { BaseRushAction } from './BaseRushAction'; import { Event } from '../../api/EventHooks'; import { BaseInstallManager, IInstallManagerOptions } from '../../logic/base/BaseInstallManager'; -import { InstallManagerFactory } from '../../logic/InstallManagerFactory'; +// TODO: Convert this to "import type" after we upgrade to TypeScript 3.8 +import * as InstallManagerFactoryExports from '../../logic/InstallManagerFactory'; +const installManagerFactoryExports: typeof InstallManagerFactoryExports = importLazy( + '../../logic/InstallManagerFactory' +); import { PurgeManager } from '../../logic/PurgeManager'; import { SetupChecks } from '../../logic/SetupChecks'; import { StandardScriptUpdater } from '../../logic/StandardScriptUpdater'; @@ -119,7 +126,7 @@ export abstract class BaseInstallAction extends BaseRushAction { const installManagerOptions: IInstallManagerOptions = this.buildInstallOptions(); - const installManager: BaseInstallManager = InstallManagerFactory.getInstallManager( + const installManager: BaseInstallManager = installManagerFactoryExports.InstallManagerFactory.getInstallManager( this.rushConfiguration, this.rushGlobalFolder, purgeManager, diff --git a/apps/rush-lib/src/cli/actions/LinkAction.ts b/apps/rush-lib/src/cli/actions/LinkAction.ts index 773b68de894..eb64b57bf54 100644 --- a/apps/rush-lib/src/cli/actions/LinkAction.ts +++ b/apps/rush-lib/src/cli/actions/LinkAction.ts @@ -1,10 +1,17 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +// eslint-disable-next-line @typescript-eslint/typedef +const importLazy = require('import-lazy')(require); + import { CommandLineFlagParameter } from '@rushstack/ts-command-line'; import { RushCommandLineParser } from '../RushCommandLineParser'; -import { LinkManagerFactory } from '../../logic/LinkManagerFactory'; +// TODO: Convert this to "import type" after we upgrade to TypeScript 3.8 +import * as LinkManagerFactoryExports from '../../logic/LinkManagerFactory'; +const linkManagerFactoryExports: typeof LinkManagerFactoryExports = importLazy( + '../../logic/LinkManagerFactory' +); import { BaseLinkManager } from '../../logic/base/BaseLinkManager'; import { BaseRushAction } from './BaseRushAction'; @@ -35,7 +42,9 @@ export class LinkAction extends BaseRushAction { } protected async runAsync(): Promise { - const linkManager: BaseLinkManager = LinkManagerFactory.getLinkManager(this.rushConfiguration); + const linkManager: BaseLinkManager = linkManagerFactoryExports.LinkManagerFactory.getLinkManager( + this.rushConfiguration + ); await linkManager.createSymlinksForProjects(this._force.value); } } diff --git a/apps/rush-lib/src/start.ts b/apps/rush-lib/src/start.ts index b4da75c1edc..b0c354b962a 100644 --- a/apps/rush-lib/src/start.ts +++ b/apps/rush-lib/src/start.ts @@ -1,6 +1,9 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +console.time('total time'); import { Rush } from './api/Rush'; -Rush.launch(Rush.version, { isManaged: false }); +Rush.launch(Rush.version, { isManaged: false }, () => { + console.timeEnd('total time'); +}); diff --git a/common/reviews/api/rush-lib.api.md b/common/reviews/api/rush-lib.api.md index 33c1044665d..08fbfd3df11 100644 --- a/common/reviews/api/rush-lib.api.md +++ b/common/reviews/api/rush-lib.api.md @@ -312,10 +312,10 @@ export type ResolutionStrategy = 'fewer-dependencies' | 'fast'; // @public export class Rush { - static launch(launcherVersion: string, arg: ILaunchOptions): void; + static launch(launcherVersion: string, arg: ILaunchOptions, cb?: () => void): void; static launchRushX(launcherVersion: string, options: ILaunchOptions): void; static readonly version: string; -} + } // @public export class RushConfiguration { diff --git a/libraries/node-core-library/src/FileSystem.ts b/libraries/node-core-library/src/FileSystem.ts index 627720da104..aef1592c933 100644 --- a/libraries/node-core-library/src/FileSystem.ts +++ b/libraries/node-core-library/src/FileSystem.ts @@ -1,14 +1,9 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line @typescript-eslint/typedef -const importLazy = require('import-lazy')(require); - import * as nodeJsPath from 'path'; import * as fs from 'fs'; - -// eslint-disable-next-line @typescript-eslint/typedef -const fsx = importLazy('fs-extra'); +import * as fsx from 'fs-extra'; import { Text, NewlineKind, Encoding } from './Text'; import { PosixModeBits } from './PosixModeBits'; From b1712107c233ba229ccaaf5dbc5dfb2196ed8763 Mon Sep 17 00:00:00 2001 From: Sachin Joseph <6994498+sachinjoseph@users.noreply.github.com> Date: Sat, 8 Aug 2020 19:21:41 -0700 Subject: [PATCH 83/97] Update rush-lib api md --- apps/rush-lib/src/api/Rush.ts | 11 +++++++++-- apps/rush-lib/src/start.ts | 5 ++++- common/reviews/api/rush-lib.api.md | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/apps/rush-lib/src/api/Rush.ts b/apps/rush-lib/src/api/Rush.ts index c2b3910a245..9780b40f233 100644 --- a/apps/rush-lib/src/api/Rush.ts +++ b/apps/rush-lib/src/api/Rush.ts @@ -51,7 +51,7 @@ export class Rush { * * Even though this API isn't documented, it is still supported for legacy compatibility. */ - public static launch(launcherVersion: string, arg: ILaunchOptions): void { + public static launch(launcherVersion: string, arg: ILaunchOptions, cb: () => void = () => {}): void { const options: ILaunchOptions = Rush._normalizeLaunchOptions(arg); if (!Utilities.shouldRestrictConsoleOutput()) { @@ -67,7 +67,14 @@ export class Rush { const parser: RushCommandLineParser = new RushCommandLineParser({ alreadyReportedNodeTooNewError: options.alreadyReportedNodeTooNewError }); - parser.execute().catch(console.error); // CommandLineParser.execute() should never reject the promise + parser + .execute() + .then(() => { + if (cb) { + cb(); + } + }) + .catch(console.error); // CommandLineParser.execute() should never reject the promise } /** diff --git a/apps/rush-lib/src/start.ts b/apps/rush-lib/src/start.ts index b4da75c1edc..b0c354b962a 100644 --- a/apps/rush-lib/src/start.ts +++ b/apps/rush-lib/src/start.ts @@ -1,6 +1,9 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +console.time('total time'); import { Rush } from './api/Rush'; -Rush.launch(Rush.version, { isManaged: false }); +Rush.launch(Rush.version, { isManaged: false }, () => { + console.timeEnd('total time'); +}); diff --git a/common/reviews/api/rush-lib.api.md b/common/reviews/api/rush-lib.api.md index 33c1044665d..f51faef88d7 100644 --- a/common/reviews/api/rush-lib.api.md +++ b/common/reviews/api/rush-lib.api.md @@ -312,7 +312,7 @@ export type ResolutionStrategy = 'fewer-dependencies' | 'fast'; // @public export class Rush { - static launch(launcherVersion: string, arg: ILaunchOptions): void; + static launch(launcherVersion: string, arg: ILaunchOptions, cb?: () => void): void; static launchRushX(launcherVersion: string, options: ILaunchOptions): void; static readonly version: string; } From 97f926f2f3eaf00e73094bb38867aba4614b0ea7 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Sun, 9 Aug 2020 01:14:26 -0700 Subject: [PATCH 84/97] Reuse package.json object --- apps/rush-lib/src/api/RushConfigurationProject.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/rush-lib/src/api/RushConfigurationProject.ts b/apps/rush-lib/src/api/RushConfigurationProject.ts index 898d1cc2cd5..2fd12e439b1 100644 --- a/apps/rush-lib/src/api/RushConfigurationProject.ts +++ b/apps/rush-lib/src/api/RushConfigurationProject.ts @@ -123,7 +123,7 @@ export class RushConfigurationProject { ); } - this._packageJsonEditor = PackageJsonEditor.load(packageJsonFilename); + this._packageJsonEditor = PackageJsonEditor.fromObject(this._packageJson, packageJsonFilename); this._tempProjectName = tempProjectName; From a5fd7c67e4c00058ad40fc9f936a145609f182b4 Mon Sep 17 00:00:00 2001 From: Sachin Joseph <6994498+sachinjoseph@users.noreply.github.com> Date: Sun, 9 Aug 2020 02:02:27 -0700 Subject: [PATCH 85/97] Use get() to determine if a map entry exists --- apps/rush-lib/src/api/RushConfiguration.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/rush-lib/src/api/RushConfiguration.ts b/apps/rush-lib/src/api/RushConfiguration.ts index de9966bf998..71a1592e07a 100644 --- a/apps/rush-lib/src/api/RushConfiguration.ts +++ b/apps/rush-lib/src/api/RushConfiguration.ts @@ -716,7 +716,7 @@ export class RushConfiguration { tempProjectName ); this._projects.push(project); - if (this._projectsByName.get(project.packageName)) { + if (this._projectsByName.has(project.packageName)) { throw new Error( `The project name "${project.packageName}" was specified more than once` + ` in the rush.json configuration file.` From acb8b797fae00eae8c2844b1c4e9cc99da61b044 Mon Sep 17 00:00:00 2001 From: Sachin Joseph <6994498+sachinjoseph@users.noreply.github.com> Date: Sun, 9 Aug 2020 02:02:27 -0700 Subject: [PATCH 86/97] Use has() to determine if a map entry exists --- apps/rush-lib/src/api/RushConfiguration.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/rush-lib/src/api/RushConfiguration.ts b/apps/rush-lib/src/api/RushConfiguration.ts index de9966bf998..71a1592e07a 100644 --- a/apps/rush-lib/src/api/RushConfiguration.ts +++ b/apps/rush-lib/src/api/RushConfiguration.ts @@ -716,7 +716,7 @@ export class RushConfiguration { tempProjectName ); this._projects.push(project); - if (this._projectsByName.get(project.packageName)) { + if (this._projectsByName.has(project.packageName)) { throw new Error( `The project name "${project.packageName}" was specified more than once` + ` in the rush.json configuration file.` From 0f14d3d996985c7a5793e26afe6c571912b34fd5 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Tue, 11 Aug 2020 15:54:31 -0700 Subject: [PATCH 87/97] Address comments --- apps/rush-lib/package.json | 1 - apps/rush-lib/src/api/Rush.ts | 11 ++--------- apps/rush-lib/src/logic/pnpm/PnpmYamlCommon.ts | 3 +++ apps/rush-lib/src/start.ts | 5 +---- common/config/rush/pnpm-lock.yaml | 2 -- common/config/rush/repo-state.json | 2 +- 6 files changed, 7 insertions(+), 17 deletions(-) diff --git a/apps/rush-lib/package.json b/apps/rush-lib/package.json index a89a80840e0..f3d09ea3cb9 100644 --- a/apps/rush-lib/package.json +++ b/apps/rush-lib/package.json @@ -44,7 +44,6 @@ "resolve": "~1.17.0", "semver": "~7.3.0", "strict-uri-encode": "~2.0.0", - "string-argv": "~0.3.1", "tar": "~5.0.5", "true-case-path": "~2.2.1", "wordwrap": "~1.0.0", diff --git a/apps/rush-lib/src/api/Rush.ts b/apps/rush-lib/src/api/Rush.ts index 97966ac1154..32051cfb7b9 100644 --- a/apps/rush-lib/src/api/Rush.ts +++ b/apps/rush-lib/src/api/Rush.ts @@ -53,7 +53,7 @@ export class Rush { * * Even though this API isn't documented, it is still supported for legacy compatibility. */ - public static launch(launcherVersion: string, arg: ILaunchOptions, cb: () => void = () => {}): void { + public static launch(launcherVersion: string, arg: ILaunchOptions): void { const options: ILaunchOptions = Rush._normalizeLaunchOptions(arg); if (!Utilities.shouldRestrictConsoleOutput()) { @@ -69,14 +69,7 @@ export class Rush { const parser: RushCommandLineParser = new RushCommandLineParser({ alreadyReportedNodeTooNewError: options.alreadyReportedNodeTooNewError }); - parser - .execute() - .then(() => { - if (cb) { - cb(); - } - }) - .catch(console.error); // CommandLineParser.execute() should never reject the promise + parser.execute().catch(console.error); // CommandLineParser.execute() should never reject the promise } /** diff --git a/apps/rush-lib/src/logic/pnpm/PnpmYamlCommon.ts b/apps/rush-lib/src/logic/pnpm/PnpmYamlCommon.ts index b94be3e3563..2df1433f98b 100644 --- a/apps/rush-lib/src/logic/pnpm/PnpmYamlCommon.ts +++ b/apps/rush-lib/src/logic/pnpm/PnpmYamlCommon.ts @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. +// See LICENSE in the project root for license information. + export interface IYamlDumpOptions { lineWidth: number; noCompatMode: boolean; diff --git a/apps/rush-lib/src/start.ts b/apps/rush-lib/src/start.ts index b0c354b962a..b4da75c1edc 100644 --- a/apps/rush-lib/src/start.ts +++ b/apps/rush-lib/src/start.ts @@ -1,9 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -console.time('total time'); import { Rush } from './api/Rush'; -Rush.launch(Rush.version, { isManaged: false }, () => { - console.timeEnd('total time'); -}); +Rush.launch(Rush.version, { isManaged: false }); diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index bea3f2d3b29..306d3e19953 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -238,7 +238,6 @@ importers: resolve: 1.17.0 semver: 7.3.2 strict-uri-encode: 2.0.0 - string-argv: 0.3.1 tar: 5.0.5 true-case-path: 2.2.1 wordwrap: 1.0.0 @@ -316,7 +315,6 @@ importers: resolve: ~1.17.0 semver: ~7.3.0 strict-uri-encode: ~2.0.0 - string-argv: ~0.3.1 tar: ~5.0.5 true-case-path: ~2.2.1 wordwrap: ~1.0.0 diff --git a/common/config/rush/repo-state.json b/common/config/rush/repo-state.json index 933252a866d..9fe1a327797 100644 --- a/common/config/rush/repo-state.json +++ b/common/config/rush/repo-state.json @@ -1,5 +1,5 @@ // DO NOT MODIFY THIS FILE. It is generated and used by Rush. { - "pnpmShrinkwrapHash": "143febc1de05b24b4b7ee43255fcd26943d8c462", + "pnpmShrinkwrapHash": "7cb7d0489f3e10fa2be8056512e5e0178140eb09", "preferredVersionsHash": "334ea62b6a2798dcf80917b79555983377e7435e" } From 762639681ffcb198cc2e744604cf938aace0bc7e Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Tue, 11 Aug 2020 16:05:45 -0700 Subject: [PATCH 88/97] Recommend the __dirname macro for dirname parameter. --- libraries/node-core-library/src/PackageJsonLookup.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libraries/node-core-library/src/PackageJsonLookup.ts b/libraries/node-core-library/src/PackageJsonLookup.ts index a5c37ceccc5..957ee481541 100644 --- a/libraries/node-core-library/src/PackageJsonLookup.ts +++ b/libraries/node-core-library/src/PackageJsonLookup.ts @@ -104,10 +104,13 @@ export class PackageJsonLookup { * Gets the version of the package.json of the currently executing script. * * @param dirnameOfCaller - The search for package.json will start at the this directory, - * and then move upwards. + * and then move upwards. Use the __dirname macro to get the path to the directory of the + * currently executing source file. */ public static getOwnPackageJsonVersion(dirnameOfCaller: string): string { let parent: string = path.dirname(dirnameOfCaller); + let depth: number = 10, + minDepth = 1; do { try { return require(path.resolve(dirnameOfCaller, 'package.json')).version; @@ -115,7 +118,7 @@ export class PackageJsonLookup { dirnameOfCaller = parent; parent = path.dirname(dirnameOfCaller); } - } while (parent !== dirnameOfCaller); + } while (parent !== dirnameOfCaller && depth-- >= minDepth); throw new Error("Couldn't get path"); } From 9fdcefb37a46ec4fcd6b571d20a8bd0ec301ea27 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Tue, 11 Aug 2020 16:33:13 -0700 Subject: [PATCH 89/97] Cache the static getter so that runtime perf won't be affected. --- apps/rush-lib/src/api/ApprovedPackagesConfiguration.ts | 9 ++++++++- apps/rush-lib/src/api/CommandLineConfiguration.ts | 9 ++++++++- apps/rush-lib/src/api/CommonVersionsConfiguration.ts | 9 ++++++++- apps/rush-lib/src/api/ExperimentsConfiguration.ts | 9 ++++++++- apps/rush-lib/src/api/RushConfiguration.ts | 7 ++++++- apps/rush-lib/src/api/VersionPolicyConfiguration.ts | 9 ++++++++- apps/rush-lib/src/logic/RepoStateFile.ts | 8 +++++++- .../src/logic/deploy/DeployScenarioConfiguration.ts | 9 ++++++++- 8 files changed, 61 insertions(+), 8 deletions(-) diff --git a/apps/rush-lib/src/api/ApprovedPackagesConfiguration.ts b/apps/rush-lib/src/api/ApprovedPackagesConfiguration.ts index 8c0380b2e3a..94412ed4846 100644 --- a/apps/rush-lib/src/api/ApprovedPackagesConfiguration.ts +++ b/apps/rush-lib/src/api/ApprovedPackagesConfiguration.ts @@ -47,8 +47,15 @@ export class ApprovedPackagesItem { * @public */ export class ApprovedPackagesConfiguration { + private static _jsonSchemaCached: JsonSchema | undefined = undefined; private static get _jsonSchema(): JsonSchema { - return JsonSchema.fromFile(path.join(__dirname, '../schemas/approved-packages.schema.json')); + if (!this._jsonSchemaCached) { + this._jsonSchemaCached = JsonSchema.fromFile( + path.join(__dirname, '../schemas/approved-packages.schema.json') + ); + } + + return this._jsonSchemaCached; } public items: ApprovedPackagesItem[] = []; diff --git a/apps/rush-lib/src/api/CommandLineConfiguration.ts b/apps/rush-lib/src/api/CommandLineConfiguration.ts index 6ebc9cdfa5f..78c55a7f958 100644 --- a/apps/rush-lib/src/api/CommandLineConfiguration.ts +++ b/apps/rush-lib/src/api/CommandLineConfiguration.ts @@ -13,8 +13,15 @@ import { CommandJson, ICommandLineJson, ParameterJson } from './CommandLineJson' * Custom Commands and Options for the Rush Command Line */ export class CommandLineConfiguration { + private static _jsonSchemaCached: JsonSchema | undefined = undefined; private static get _jsonSchema(): JsonSchema { - return JsonSchema.fromFile(path.join(__dirname, '../schemas/command-line.schema.json')); + if (!this._jsonSchemaCached) { + this._jsonSchemaCached = JsonSchema.fromFile( + path.join(__dirname, '../schemas/command-line.schema.json') + ); + } + + return this._jsonSchemaCached; } public readonly commands: CommandJson[] = []; diff --git a/apps/rush-lib/src/api/CommonVersionsConfiguration.ts b/apps/rush-lib/src/api/CommonVersionsConfiguration.ts index b4f5c997fb1..c4f5f689e2d 100644 --- a/apps/rush-lib/src/api/CommonVersionsConfiguration.ts +++ b/apps/rush-lib/src/api/CommonVersionsConfiguration.ts @@ -57,8 +57,15 @@ interface ICommonVersionsJson { * @public */ export class CommonVersionsConfiguration { + private static _jsonSchemaCached: JsonSchema | undefined = undefined; private static get _jsonSchema(): JsonSchema { - return JsonSchema.fromFile(path.join(__dirname, '../schemas/common-versions.schema.json')); + if (!this._jsonSchemaCached) { + this._jsonSchemaCached = JsonSchema.fromFile( + path.join(__dirname, '../schemas/common-versions.schema.json') + ); + } + + return this._jsonSchemaCached; } private _filePath: string; diff --git a/apps/rush-lib/src/api/ExperimentsConfiguration.ts b/apps/rush-lib/src/api/ExperimentsConfiguration.ts index e5bee18035f..e3dc9923b5a 100644 --- a/apps/rush-lib/src/api/ExperimentsConfiguration.ts +++ b/apps/rush-lib/src/api/ExperimentsConfiguration.ts @@ -35,8 +35,15 @@ export interface IExperimentsJson { * @beta */ export class ExperimentsConfiguration { + private static _jsonSchemaCached: JsonSchema | undefined = undefined; private static get _jsonSchema(): JsonSchema { - return JsonSchema.fromFile(path.resolve(__dirname, '..', 'schemas', 'experiments.schema.json')); + if (!this._jsonSchemaCached) { + this._jsonSchemaCached = JsonSchema.fromFile( + path.resolve(__dirname, '..', 'schemas', 'experiments.schema.json') + ); + } + + return this._jsonSchemaCached; } private _experimentConfiguration: IExperimentsJson; diff --git a/apps/rush-lib/src/api/RushConfiguration.ts b/apps/rush-lib/src/api/RushConfiguration.ts index 71a1592e07a..e2939c09415 100644 --- a/apps/rush-lib/src/api/RushConfiguration.ts +++ b/apps/rush-lib/src/api/RushConfiguration.ts @@ -423,8 +423,13 @@ export type ResolutionStrategy = 'fewer-dependencies' | 'fast'; * @public */ export class RushConfiguration { + private static _jsonSchemaCached: JsonSchema | undefined = undefined; private static get _jsonSchema(): JsonSchema { - return JsonSchema.fromFile(path.join(__dirname, '../schemas/rush.schema.json')); + if (!this._jsonSchemaCached) { + this._jsonSchemaCached = JsonSchema.fromFile(path.join(__dirname, '../schemas/rush.schema.json')); + } + + return this._jsonSchemaCached; } private _rushJsonFile: string; diff --git a/apps/rush-lib/src/api/VersionPolicyConfiguration.ts b/apps/rush-lib/src/api/VersionPolicyConfiguration.ts index 8dbca789495..ecefd7645ab 100644 --- a/apps/rush-lib/src/api/VersionPolicyConfiguration.ts +++ b/apps/rush-lib/src/api/VersionPolicyConfiguration.ts @@ -64,8 +64,15 @@ export interface IVersionPolicyDependencyJson { * @beta */ export class VersionPolicyConfiguration { + private static _jsonSchemaCached: JsonSchema | undefined = undefined; private static get _jsonSchema(): JsonSchema { - return JsonSchema.fromFile(path.join(__dirname, '../schemas/version-policies.schema.json')); + if (!this._jsonSchemaCached) { + this._jsonSchemaCached = JsonSchema.fromFile( + path.join(__dirname, '../schemas/version-policies.schema.json') + ); + } + + return this._jsonSchemaCached; } private _versionPolicies: Map; diff --git a/apps/rush-lib/src/logic/RepoStateFile.ts b/apps/rush-lib/src/logic/RepoStateFile.ts index f8e83d23127..9c6c2dc3ce2 100644 --- a/apps/rush-lib/src/logic/RepoStateFile.ts +++ b/apps/rush-lib/src/logic/RepoStateFile.ts @@ -34,9 +34,15 @@ interface IRepoStateJson { * @public */ export class RepoStateFile { + private static _jsonSchemaCached: JsonSchema | undefined = undefined; private static get _jsonSchema(): JsonSchema { - return JsonSchema.fromFile(path.join(__dirname, '../schemas/repo-state.schema.json')); + if (!this._jsonSchemaCached) { + this._jsonSchemaCached = JsonSchema.fromFile(path.join(__dirname, '../schemas/repo-state.schema.json')); + } + + return this._jsonSchemaCached; } + private _repoStateFilePath: string; private _variant: string | undefined; private _pnpmShrinkwrapHash: string | undefined; diff --git a/apps/rush-lib/src/logic/deploy/DeployScenarioConfiguration.ts b/apps/rush-lib/src/logic/deploy/DeployScenarioConfiguration.ts index cb9653e7fd3..dfca4f0a708 100644 --- a/apps/rush-lib/src/logic/deploy/DeployScenarioConfiguration.ts +++ b/apps/rush-lib/src/logic/deploy/DeployScenarioConfiguration.ts @@ -31,8 +31,15 @@ export class DeployScenarioConfiguration { // Example: "deploy-the-thing123" private static _scenarioNameRegExp: RegExp = /^[a-z0-9]+(-[a-z0-9]+)*$/; + private static _jsonSchemaCached: JsonSchema | undefined = undefined; private static get _jsonSchema(): JsonSchema { - return JsonSchema.fromFile(path.join(__dirname, '../../schemas/deploy-scenario.schema.json')); + if (!this._jsonSchemaCached) { + this._jsonSchemaCached = JsonSchema.fromFile( + path.join(__dirname, '../../schemas/deploy-scenario.schema.json') + ); + } + + return this._jsonSchemaCached; } public readonly json: IDeployScenarioJson; From f3ebdc1929935b4d267d90c2f27d5c64bb32ff20 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Tue, 11 Aug 2020 16:46:46 -0700 Subject: [PATCH 90/97] Address comments --- common/reviews/api/rush-lib.api.md | 2 +- libraries/node-core-library/src/PackageJsonLookup.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/common/reviews/api/rush-lib.api.md b/common/reviews/api/rush-lib.api.md index 08fbfd3df11..6fbbd7f2d5c 100644 --- a/common/reviews/api/rush-lib.api.md +++ b/common/reviews/api/rush-lib.api.md @@ -312,7 +312,7 @@ export type ResolutionStrategy = 'fewer-dependencies' | 'fast'; // @public export class Rush { - static launch(launcherVersion: string, arg: ILaunchOptions, cb?: () => void): void; + static launch(launcherVersion: string, arg: ILaunchOptions): void; static launchRushX(launcherVersion: string, options: ILaunchOptions): void; static readonly version: string; } diff --git a/libraries/node-core-library/src/PackageJsonLookup.ts b/libraries/node-core-library/src/PackageJsonLookup.ts index 957ee481541..490d8436bd3 100644 --- a/libraries/node-core-library/src/PackageJsonLookup.ts +++ b/libraries/node-core-library/src/PackageJsonLookup.ts @@ -109,8 +109,8 @@ export class PackageJsonLookup { */ public static getOwnPackageJsonVersion(dirnameOfCaller: string): string { let parent: string = path.dirname(dirnameOfCaller); - let depth: number = 10, - minDepth = 1; + let depth: number = 10; + const minDepth: number = 1; do { try { return require(path.resolve(dirnameOfCaller, 'package.json')).version; From 6661ba84aa372d4723f8f475bee4bb44efd5c8f4 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Wed, 12 Aug 2020 22:52:35 -0700 Subject: [PATCH 91/97] Use Import.lazy everywhere --- apps/rush-lib/package.json | 1 - apps/rush-lib/src/cli/actions/AddAction.ts | 16 ++++++++-------- .../src/cli/actions/BaseInstallAction.ts | 16 +++++++--------- apps/rush-lib/src/cli/actions/LinkAction.ts | 19 ++++++++++--------- apps/rush-lib/src/logic/npm/NpmLinkManager.ts | 7 +------ .../src/logic/pnpm/PnpmLinkManager.ts | 8 +------- .../src/logic/pnpm/PnpmShrinkwrapFile.ts | 13 +++++-------- .../src/logic/pnpm/PnpmWorkspaceFile.ts | 13 +++++-------- .../src/logic/yarn/YarnShrinkwrapFile.ts | 17 +++++++---------- common/config/rush/pnpm-lock.yaml | 2 -- common/config/rush/repo-state.json | 2 +- 11 files changed, 45 insertions(+), 69 deletions(-) diff --git a/apps/rush-lib/package.json b/apps/rush-lib/package.json index f3d09ea3cb9..5909a171550 100644 --- a/apps/rush-lib/package.json +++ b/apps/rush-lib/package.json @@ -32,7 +32,6 @@ "glob": "~7.0.5", "https-proxy-agent": "~2.2.1", "ignore": "~5.1.6", - "import-lazy": "~4.0.0", "inquirer": "~6.2.0", "js-yaml": "~3.13.1", "lodash": "~4.17.15", diff --git a/apps/rush-lib/src/cli/actions/AddAction.ts b/apps/rush-lib/src/cli/actions/AddAction.ts index 6f57bab5096..fee46988fc0 100644 --- a/apps/rush-lib/src/cli/actions/AddAction.ts +++ b/apps/rush-lib/src/cli/actions/AddAction.ts @@ -1,22 +1,22 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line @typescript-eslint/typedef -const importLazy = require('import-lazy')(require); - import * as os from 'os'; import * as semver from 'semver'; - +import { Import } from '@rushstack/node-core-library'; import { CommandLineFlagParameter, CommandLineStringParameter } from '@rushstack/ts-command-line'; import { RushConfigurationProject } from '../../api/RushConfigurationProject'; import { BaseRushAction } from './BaseRushAction'; import { RushCommandLineParser } from '../RushCommandLineParser'; +import { DependencySpecifier } from '../../logic/DependencySpecifier'; + +const packageJsonUpdaterModule: typeof import('../../logic/PackageJsonUpdater') = Import.lazy( + '../../logic/PackageJsonUpdater', + require +); // TODO: Convert this to "import type" after we upgrade to TypeScript 3.8 import { PackageJsonUpdater, SemVerStyle } from '../../logic/PackageJsonUpdater'; -import * as PackageJsonUpdaterW from '../../logic/PackageJsonUpdater'; -const packageJsonUpdaterExports: typeof PackageJsonUpdaterW = importLazy('../../logic/PackageJsonUpdater'); -import { DependencySpecifier } from '../../logic/DependencySpecifier'; export class AddAction extends BaseRushAction { private _allFlag: CommandLineFlagParameter; @@ -142,7 +142,7 @@ export class AddAction extends BaseRushAction { } } - const updater: PackageJsonUpdater = new packageJsonUpdaterExports.PackageJsonUpdater( + const updater: PackageJsonUpdater = new packageJsonUpdaterModule.PackageJsonUpdater( this.rushConfiguration, this.rushGlobalFolder ); diff --git a/apps/rush-lib/src/cli/actions/BaseInstallAction.ts b/apps/rush-lib/src/cli/actions/BaseInstallAction.ts index 7f39f08c924..7306b37eb14 100644 --- a/apps/rush-lib/src/cli/actions/BaseInstallAction.ts +++ b/apps/rush-lib/src/cli/actions/BaseInstallAction.ts @@ -1,12 +1,10 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line @typescript-eslint/typedef -const importLazy = require('import-lazy')(require); - import * as colors from 'colors'; import * as os from 'os'; +import { Import } from '@rushstack/node-core-library'; import { CommandLineFlagParameter, CommandLineIntegerParameter, @@ -16,11 +14,6 @@ import { import { BaseRushAction } from './BaseRushAction'; import { Event } from '../../api/EventHooks'; import { BaseInstallManager, IInstallManagerOptions } from '../../logic/base/BaseInstallManager'; -// TODO: Convert this to "import type" after we upgrade to TypeScript 3.8 -import * as InstallManagerFactoryExports from '../../logic/InstallManagerFactory'; -const installManagerFactoryExports: typeof InstallManagerFactoryExports = importLazy( - '../../logic/InstallManagerFactory' -); import { PurgeManager } from '../../logic/PurgeManager'; import { SetupChecks } from '../../logic/SetupChecks'; import { StandardScriptUpdater } from '../../logic/StandardScriptUpdater'; @@ -29,6 +22,11 @@ import { VersionMismatchFinder } from '../../logic/versionMismatch/VersionMismat import { Variants } from '../../api/Variants'; import { RushConstants } from '../../logic/RushConstants'; +const installManagerFactoryModule: typeof import('../../logic/InstallManagerFactory') = Import.lazy( + '../../logic/InstallManagerFactory', + require +); + /** * This is the common base class for InstallAction and UpdateAction. */ @@ -126,7 +124,7 @@ export abstract class BaseInstallAction extends BaseRushAction { const installManagerOptions: IInstallManagerOptions = this.buildInstallOptions(); - const installManager: BaseInstallManager = installManagerFactoryExports.InstallManagerFactory.getInstallManager( + const installManager: BaseInstallManager = installManagerFactoryModule.InstallManagerFactory.getInstallManager( this.rushConfiguration, this.rushGlobalFolder, purgeManager, diff --git a/apps/rush-lib/src/cli/actions/LinkAction.ts b/apps/rush-lib/src/cli/actions/LinkAction.ts index eb64b57bf54..616b0204f95 100644 --- a/apps/rush-lib/src/cli/actions/LinkAction.ts +++ b/apps/rush-lib/src/cli/actions/LinkAction.ts @@ -1,20 +1,21 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line @typescript-eslint/typedef -const importLazy = require('import-lazy')(require); - +import { Import } from '@rushstack/node-core-library'; import { CommandLineFlagParameter } from '@rushstack/ts-command-line'; import { RushCommandLineParser } from '../RushCommandLineParser'; -// TODO: Convert this to "import type" after we upgrade to TypeScript 3.8 -import * as LinkManagerFactoryExports from '../../logic/LinkManagerFactory'; -const linkManagerFactoryExports: typeof LinkManagerFactoryExports = importLazy( - '../../logic/LinkManagerFactory' -); + import { BaseLinkManager } from '../../logic/base/BaseLinkManager'; import { BaseRushAction } from './BaseRushAction'; +// TODO: Convert this to "import type" after we upgrade to TypeScript 3.8 +import * as LinkManagerFactoryTypes from '../../logic/LinkManagerFactory'; +const linkManagerFactoryModule: typeof LinkManagerFactoryTypes = Import.lazy( + '../../logic/LinkManagerFactory', + require +); + export class LinkAction extends BaseRushAction { private _force: CommandLineFlagParameter; @@ -42,7 +43,7 @@ export class LinkAction extends BaseRushAction { } protected async runAsync(): Promise { - const linkManager: BaseLinkManager = linkManagerFactoryExports.LinkManagerFactory.getLinkManager( + const linkManager: BaseLinkManager = linkManagerFactoryModule.LinkManagerFactory.getLinkManager( this.rushConfiguration ); await linkManager.createSymlinksForProjects(this._force.value); diff --git a/apps/rush-lib/src/logic/npm/NpmLinkManager.ts b/apps/rush-lib/src/logic/npm/NpmLinkManager.ts index 68e87ec5dde..dc46fffb73e 100644 --- a/apps/rush-lib/src/logic/npm/NpmLinkManager.ts +++ b/apps/rush-lib/src/logic/npm/NpmLinkManager.ts @@ -1,16 +1,11 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line @typescript-eslint/typedef -const importLazy = require('import-lazy')(require); - import * as colors from 'colors'; import * as os from 'os'; import * as path from 'path'; import * as semver from 'semver'; -// eslint-disable-next-line @typescript-eslint/typedef -const tar = importLazy('tar'); -// eslint-disable-next-line @typescript-eslint/typedef +import * as tar from 'tar'; import readPackageTree = require('read-package-tree'); import { FileSystem, FileConstants, LegacyAdapters } from '@rushstack/node-core-library'; diff --git a/apps/rush-lib/src/logic/pnpm/PnpmLinkManager.ts b/apps/rush-lib/src/logic/pnpm/PnpmLinkManager.ts index 341583b58a3..b3953512acc 100644 --- a/apps/rush-lib/src/logic/pnpm/PnpmLinkManager.ts +++ b/apps/rush-lib/src/logic/pnpm/PnpmLinkManager.ts @@ -1,16 +1,10 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line @typescript-eslint/typedef -const importLazy = require('import-lazy')(require); - import * as os from 'os'; import * as path from 'path'; import uriEncode = require('strict-uri-encode'); - -// eslint-disable-next-line @typescript-eslint/typedef -const pnpmLinkBins = importLazy('@pnpm/link-bins'); - +import pnpmLinkBins from '@pnpm/link-bins'; import * as semver from 'semver'; import * as colors from 'colors'; diff --git a/apps/rush-lib/src/logic/pnpm/PnpmShrinkwrapFile.ts b/apps/rush-lib/src/logic/pnpm/PnpmShrinkwrapFile.ts index 584f1f683ad..d58dd09f64f 100644 --- a/apps/rush-lib/src/logic/pnpm/PnpmShrinkwrapFile.ts +++ b/apps/rush-lib/src/logic/pnpm/PnpmShrinkwrapFile.ts @@ -1,17 +1,12 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line @typescript-eslint/typedef -const importLazy = require('import-lazy')(require); - -// eslint-disable-next-line @typescript-eslint/typedef -const yaml = importLazy('js-yaml'); import * as os from 'os'; import * as path from 'path'; import * as semver from 'semver'; import * as crypto from 'crypto'; import * as colors from 'colors'; -import { FileSystem } from '@rushstack/node-core-library'; +import { FileSystem, Import } from '@rushstack/node-core-library'; import { BaseShrinkwrapFile } from '../base/BaseShrinkwrapFile'; import { DependencySpecifier } from '../DependencySpecifier'; @@ -23,6 +18,8 @@ import { IShrinkwrapFilePolicyValidatorOptions } from '../policy/ShrinkwrapFileP import { AlreadyReportedError } from '../../utilities/AlreadyReportedError'; import { PNPM_SHRINKWRAP_YAML_FORMAT } from './PnpmYamlCommon'; +const yamlModule: typeof import('js-yaml') = Import.lazy('js-yaml', require); + export interface IPeerDependenciesMetaYaml { optional?: boolean; } @@ -234,7 +231,7 @@ export class PnpmShrinkwrapFile extends BaseShrinkwrapFile { } const shrinkwrapContent: string = FileSystem.readFile(shrinkwrapYamlFilename); - const parsedData: IPnpmShrinkwrapYaml = yaml.safeLoad(shrinkwrapContent); + const parsedData: IPnpmShrinkwrapYaml = yamlModule.safeLoad(shrinkwrapContent); return new PnpmShrinkwrapFile(parsedData, shrinkwrapYamlFilename); } catch (error) { throw new Error(`Error reading "${shrinkwrapYamlFilename}":${os.EOL} ${error.message}`); @@ -433,7 +430,7 @@ export class PnpmShrinkwrapFile extends BaseShrinkwrapFile { } } - return yaml.safeDump(shrinkwrapToSerialize, PNPM_SHRINKWRAP_YAML_FORMAT); + return yamlModule.safeDump(shrinkwrapToSerialize, PNPM_SHRINKWRAP_YAML_FORMAT); } /** diff --git a/apps/rush-lib/src/logic/pnpm/PnpmWorkspaceFile.ts b/apps/rush-lib/src/logic/pnpm/PnpmWorkspaceFile.ts index 9c188a69019..5ff10093673 100644 --- a/apps/rush-lib/src/logic/pnpm/PnpmWorkspaceFile.ts +++ b/apps/rush-lib/src/logic/pnpm/PnpmWorkspaceFile.ts @@ -1,19 +1,16 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line @typescript-eslint/typedef -const importLazy = require('import-lazy')(require); - import * as globEscape from 'glob-escape'; import * as os from 'os'; import * as path from 'path'; -// eslint-disable-next-line @typescript-eslint/typedef -const yaml = importLazy('js-yaml'); -import { FileSystem, Sort, Text } from '@rushstack/node-core-library'; +import { FileSystem, Sort, Text, Import } from '@rushstack/node-core-library'; import { BaseWorkspaceFile } from '../base/BaseWorkspaceFile'; import { PNPM_SHRINKWRAP_YAML_FORMAT } from './PnpmYamlCommon'; +const yamlModule: typeof import('js-yaml') = Import.lazy('js-yaml', require); + /** * This interface represents the raw pnpm-workspace.YAML file * Example: @@ -48,7 +45,7 @@ export class PnpmWorkspaceFile extends BaseWorkspaceFile { try { // Populate with the existing file, or an empty list if the file doesn't exist workspaceYaml = FileSystem.exists(workspaceYamlFilename) - ? yaml.safeLoad(FileSystem.readFile(workspaceYamlFilename).toString()) + ? yamlModule.safeLoad(FileSystem.readFile(workspaceYamlFilename).toString()) : { packages: [] }; } catch (error) { throw new Error(`Error reading "${workspaceYamlFilename}":${os.EOL} ${error.message}`); @@ -77,6 +74,6 @@ export class PnpmWorkspaceFile extends BaseWorkspaceFile { const workspaceYaml: IPnpmWorkspaceYaml = { packages: Array.from(this._workspacePackages) }; - return yaml.safeDump(workspaceYaml, PNPM_SHRINKWRAP_YAML_FORMAT); + return yamlModule.safeDump(workspaceYaml, PNPM_SHRINKWRAP_YAML_FORMAT); } } diff --git a/apps/rush-lib/src/logic/yarn/YarnShrinkwrapFile.ts b/apps/rush-lib/src/logic/yarn/YarnShrinkwrapFile.ts index 5a572de1ab3..c58205cd0e3 100644 --- a/apps/rush-lib/src/logic/yarn/YarnShrinkwrapFile.ts +++ b/apps/rush-lib/src/logic/yarn/YarnShrinkwrapFile.ts @@ -1,20 +1,17 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. -// eslint-disable-next-line @typescript-eslint/typedef -const importLazy = require('import-lazy')(require); - import * as os from 'os'; -// eslint-disable-next-line @typescript-eslint/typedef -const lockfile = importLazy('@yarnpkg/lockfile'); -// TODO: Convert this to "import type" after we upgrade to TypeScript 3.8 -import { ParseResult } from '@yarnpkg/lockfile'; import { BaseShrinkwrapFile } from '../base/BaseShrinkwrapFile'; -import { FileSystem, IParsedPackageNameOrError, InternalError } from '@rushstack/node-core-library'; +import { FileSystem, IParsedPackageNameOrError, InternalError, Import } from '@rushstack/node-core-library'; import { RushConstants } from '../RushConstants'; import { DependencySpecifier } from '../DependencySpecifier'; import { PackageNameParsers } from '../../api/PackageNameParsers'; +const lockfileModule: typeof import('@yarnpkg/lockfile') = Import.lazy('@yarnpkg/lockfile', require); +// TODO: Convert this to "import type" after we upgrade to TypeScript 3.8 +import { ParseResult } from '@yarnpkg/lockfile'; + /** * Used with YarnShrinkwrapFile._encodePackageNameAndSemVer() and _decodePackageNameAndSemVer(). */ @@ -159,7 +156,7 @@ export class YarnShrinkwrapFile extends BaseShrinkwrapFile { } shrinkwrapString = FileSystem.readFile(shrinkwrapFilename); - shrinkwrapJson = lockfile.parse(shrinkwrapString); + shrinkwrapJson = lockfileModule.parse(shrinkwrapString); } catch (error) { throw new Error(`Error reading "${shrinkwrapFilename}":` + os.EOL + ` ${error.message}`); } @@ -241,7 +238,7 @@ export class YarnShrinkwrapFile extends BaseShrinkwrapFile { /** @override */ protected serialize(): string { - return lockfile.stringify(this._shrinkwrapJson); + return lockfileModule.stringify(this._shrinkwrapJson); } /** @override */ diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index 306d3e19953..d30f3ec2ebc 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -225,7 +225,6 @@ importers: glob-escape: 0.0.2 https-proxy-agent: 2.2.4 ignore: 5.1.8 - import-lazy: 4.0.0 inquirer: 6.2.2 js-yaml: 3.13.1 jszip: 3.5.0 @@ -301,7 +300,6 @@ importers: gulp: ~4.0.2 https-proxy-agent: ~2.2.1 ignore: ~5.1.6 - import-lazy: ~4.0.0 inquirer: ~6.2.0 jest: ~25.4.0 js-yaml: ~3.13.1 diff --git a/common/config/rush/repo-state.json b/common/config/rush/repo-state.json index 9fe1a327797..f22fbd7f74b 100644 --- a/common/config/rush/repo-state.json +++ b/common/config/rush/repo-state.json @@ -1,5 +1,5 @@ // DO NOT MODIFY THIS FILE. It is generated and used by Rush. { - "pnpmShrinkwrapHash": "7cb7d0489f3e10fa2be8056512e5e0178140eb09", + "pnpmShrinkwrapHash": "c86b0aa311bffeea4681eef765e7449b963b4cf2", "preferredVersionsHash": "334ea62b6a2798dcf80917b79555983377e7435e" } From 82c377e877e4ed9cfcdec90e95fb065979fe8262 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Fri, 14 Aug 2020 20:37:31 -0700 Subject: [PATCH 92/97] Use Import.Lazy in more places --- apps/rush-lib/src/cli/actions/AddAction.ts | 18 +++++++++--------- apps/rush-lib/src/cli/actions/ChangeAction.ts | 2 +- apps/rush-lib/src/cli/actions/DeployAction.ts | 6 +++--- apps/rush-lib/src/cli/actions/VersionAction.ts | 11 +++++++---- apps/rush-lib/src/logic/VersionManager.ts | 6 +++--- .../src/logic/yarn/YarnShrinkwrapFile.ts | 6 +++--- 6 files changed, 26 insertions(+), 23 deletions(-) diff --git a/apps/rush-lib/src/cli/actions/AddAction.ts b/apps/rush-lib/src/cli/actions/AddAction.ts index fee46988fc0..a456d428e49 100644 --- a/apps/rush-lib/src/cli/actions/AddAction.ts +++ b/apps/rush-lib/src/cli/actions/AddAction.ts @@ -11,12 +11,12 @@ import { BaseRushAction } from './BaseRushAction'; import { RushCommandLineParser } from '../RushCommandLineParser'; import { DependencySpecifier } from '../../logic/DependencySpecifier'; -const packageJsonUpdaterModule: typeof import('../../logic/PackageJsonUpdater') = Import.lazy( +// TODO: Convert this to "import type" after we upgrade to TypeScript 3.8 +import * as PackageJsonUpdaterTypes from '../../logic/PackageJsonUpdater'; +const packageJsonUpdaterModule: typeof PackageJsonUpdaterTypes = Import.lazy( '../../logic/PackageJsonUpdater', require ); -// TODO: Convert this to "import type" after we upgrade to TypeScript 3.8 -import { PackageJsonUpdater, SemVerStyle } from '../../logic/PackageJsonUpdater'; export class AddAction extends BaseRushAction { private _allFlag: CommandLineFlagParameter; @@ -142,12 +142,12 @@ export class AddAction extends BaseRushAction { } } - const updater: PackageJsonUpdater = new packageJsonUpdaterModule.PackageJsonUpdater( + const updater: PackageJsonUpdaterTypes.PackageJsonUpdater = new packageJsonUpdaterModule.PackageJsonUpdater( this.rushConfiguration, this.rushGlobalFolder ); - let rangeStyle: SemVerStyle; + let rangeStyle: PackageJsonUpdaterTypes.SemVerStyle; if (version && version !== 'latest') { if (this._exactFlag.value || this._caretFlag.value) { throw new Error( @@ -156,13 +156,13 @@ export class AddAction extends BaseRushAction { ); } - rangeStyle = SemVerStyle.Passthrough; + rangeStyle = PackageJsonUpdaterTypes.SemVerStyle.Passthrough; } else { rangeStyle = this._caretFlag.value - ? SemVerStyle.Caret + ? PackageJsonUpdaterTypes.SemVerStyle.Caret : this._exactFlag.value - ? SemVerStyle.Exact - : SemVerStyle.Tilde; + ? PackageJsonUpdaterTypes.SemVerStyle.Exact + : PackageJsonUpdaterTypes.SemVerStyle.Tilde; } await updater.doRushAdd({ diff --git a/apps/rush-lib/src/cli/actions/ChangeAction.ts b/apps/rush-lib/src/cli/actions/ChangeAction.ts index 187d3a6b4c8..1b3eb768b89 100644 --- a/apps/rush-lib/src/cli/actions/ChangeAction.ts +++ b/apps/rush-lib/src/cli/actions/ChangeAction.ts @@ -28,9 +28,9 @@ import { } from '../../api/VersionPolicy'; import { AlreadyReportedError } from '../../utilities/AlreadyReportedError'; -const inquirer: typeof import('inquirer') = Import.lazy('inquirer', require); // TODO: Convert this to "import type" after we upgrade to TypeScript 3.8 import * as inquirerTypes from 'inquirer'; +const inquirer: typeof inquirerTypes = Import.lazy('inquirer', require); export class ChangeAction extends BaseRushAction { private _verifyParameter: CommandLineFlagParameter; diff --git a/apps/rush-lib/src/cli/actions/DeployAction.ts b/apps/rush-lib/src/cli/actions/DeployAction.ts index f38e6a6c472..d2b198325b1 100644 --- a/apps/rush-lib/src/cli/actions/DeployAction.ts +++ b/apps/rush-lib/src/cli/actions/DeployAction.ts @@ -7,12 +7,12 @@ import { CommandLineFlagParameter, CommandLineStringParameter } from '@rushstack import { BaseRushAction } from './BaseRushAction'; import { RushCommandLineParser } from '../RushCommandLineParser'; -const deployManagerModule: typeof import('../../logic/deploy/DeployManager') = Import.lazy( +// TODO: Convert this to "import type" after we upgrade to TypeScript 3.8 +import * as deployManagerTypes from '../../logic/deploy/DeployManager'; +const deployManagerModule: typeof deployManagerTypes = Import.lazy( '../../logic/deploy/DeployManager', require ); -// TODO: Convert this to "import type" after we upgrade to TypeScript 3.8 -import * as deployManagerTypes from '../../logic/deploy/DeployManager'; export class DeployAction extends BaseRushAction { private _scenario: CommandLineStringParameter; diff --git a/apps/rush-lib/src/cli/actions/VersionAction.ts b/apps/rush-lib/src/cli/actions/VersionAction.ts index 5738bba5b07..fe77038d6a8 100644 --- a/apps/rush-lib/src/cli/actions/VersionAction.ts +++ b/apps/rush-lib/src/cli/actions/VersionAction.ts @@ -2,7 +2,7 @@ // See LICENSE in the project root for license information. import * as semver from 'semver'; -import { IPackageJson, FileConstants } from '@rushstack/node-core-library'; +import { IPackageJson, FileConstants, Import } from '@rushstack/node-core-library'; import { CommandLineFlagParameter, CommandLineStringParameter } from '@rushstack/ts-command-line'; import { BumpType, LockStepVersionPolicy } from '../../api/VersionPolicy'; @@ -13,10 +13,13 @@ import { VersionMismatchFinder } from '../../logic/versionMismatch/VersionMismat import { RushCommandLineParser } from '../RushCommandLineParser'; import { PolicyValidator } from '../../logic/policy/PolicyValidator'; import { BaseRushAction } from './BaseRushAction'; -import { VersionManager } from '../../logic/VersionManager'; import { PublishGit } from '../../logic/PublishGit'; import { Git } from '../../logic/Git'; +// TODO: Convert this to "import type" after we upgrade to TypeScript 3.8 +import * as VersionManagerTypes from '../../logic/VersionManager'; +const versionManagerModule: typeof VersionManagerTypes = Import.lazy('../../logic/VersionManager', require); + export const DEFAULT_PACKAGE_UPDATE_MESSAGE: string = 'Applying package updates.'; export class VersionAction extends BaseRushAction { @@ -29,7 +32,7 @@ export class VersionAction extends BaseRushAction { private _overwriteBump: CommandLineStringParameter; private _prereleaseIdentifier: CommandLineStringParameter; - private _versionManager: VersionManager; + private _versionManager: VersionManagerTypes.VersionManager; public constructor(parser: RushCommandLineParser) { super({ @@ -98,7 +101,7 @@ export class VersionAction extends BaseRushAction { this._validateInput(); - this._versionManager = new VersionManager( + this._versionManager = new versionManagerModule.VersionManager( this.rushConfiguration, userEmail, this.rushConfiguration.versionPolicyConfiguration, diff --git a/apps/rush-lib/src/logic/VersionManager.ts b/apps/rush-lib/src/logic/VersionManager.ts index 083f5488b4c..dccf2d450bd 100644 --- a/apps/rush-lib/src/logic/VersionManager.ts +++ b/apps/rush-lib/src/logic/VersionManager.ts @@ -25,8 +25,8 @@ import { IInstallManagerOptions } from './base/BaseInstallManager'; const lodash: typeof import('lodash') = Import.lazy('lodash', require); // TODO: Convert this to "import type" after we upgrade to TypeScript 3.8 -import { RushInstallManager } from './installManager/RushInstallManager'; -const rushInstallManagerModule: typeof import('./installManager/RushInstallManager') = Import.lazy( +import * as RushInstallManagerTypes from './installManager/RushInstallManager'; +const rushInstallManagerModule: typeof RushInstallManagerTypes = Import.lazy( './installManager/RushInstallManager', require ); @@ -137,7 +137,7 @@ export class VersionManager { maxInstallAttempts: RushConstants.defaultMaxInstallAttempts, toProjects: [] }; - const installManager: RushInstallManager = new rushInstallManagerModule.RushInstallManager( + const installManager: RushInstallManagerTypes.RushInstallManager = new rushInstallManagerModule.RushInstallManager( this._rushConfiguration, this._globalFolder, purgeManager, diff --git a/apps/rush-lib/src/logic/yarn/YarnShrinkwrapFile.ts b/apps/rush-lib/src/logic/yarn/YarnShrinkwrapFile.ts index c58205cd0e3..f2e8660a1a0 100644 --- a/apps/rush-lib/src/logic/yarn/YarnShrinkwrapFile.ts +++ b/apps/rush-lib/src/logic/yarn/YarnShrinkwrapFile.ts @@ -8,9 +8,9 @@ import { RushConstants } from '../RushConstants'; import { DependencySpecifier } from '../DependencySpecifier'; import { PackageNameParsers } from '../../api/PackageNameParsers'; -const lockfileModule: typeof import('@yarnpkg/lockfile') = Import.lazy('@yarnpkg/lockfile', require); // TODO: Convert this to "import type" after we upgrade to TypeScript 3.8 -import { ParseResult } from '@yarnpkg/lockfile'; +import * as YarnPkgLockfileTypes from '@yarnpkg/lockfile'; +const lockfileModule: typeof YarnPkgLockfileTypes = Import.lazy('@yarnpkg/lockfile', require); /** * Used with YarnShrinkwrapFile._encodePackageNameAndSemVer() and _decodePackageNameAndSemVer(). @@ -149,7 +149,7 @@ export class YarnShrinkwrapFile extends BaseShrinkwrapFile { public static loadFromFile(shrinkwrapFilename: string): YarnShrinkwrapFile | undefined { let shrinkwrapString: string; - let shrinkwrapJson: ParseResult; + let shrinkwrapJson: YarnPkgLockfileTypes.ParseResult; try { if (!FileSystem.exists(shrinkwrapFilename)) { return undefined; // file does not exist From c343e4a6e7520cde616fdce5d8b66afac394459d Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Fri, 14 Aug 2020 20:50:31 -0700 Subject: [PATCH 93/97] Provide a link to the PR in the changelog --- .../sachinjoseph-rush-shell-tab-complete_2020-08-01-22-06.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/changes/@microsoft/rush/sachinjoseph-rush-shell-tab-complete_2020-08-01-22-06.json b/common/changes/@microsoft/rush/sachinjoseph-rush-shell-tab-complete_2020-08-01-22-06.json index e546771c8ce..6112112cd20 100644 --- a/common/changes/@microsoft/rush/sachinjoseph-rush-shell-tab-complete_2020-08-01-22-06.json +++ b/common/changes/@microsoft/rush/sachinjoseph-rush-shell-tab-complete_2020-08-01-22-06.json @@ -2,7 +2,7 @@ "changes": [ { "packageName": "@microsoft/rush", - "comment": "Add support for shell tab completion.", + "comment": "Add support for shell tab completion. See PR for details: https://github.com/microsoft/rushstack/pull/2060", "type": "minor" } ], From aa2710253b81cec15559b1972840e93342a5a2c1 Mon Sep 17 00:00:00 2001 From: Pete Gonzalez <4673363+octogonz@users.noreply.github.com> Date: Tue, 18 Aug 2020 11:32:55 -0700 Subject: [PATCH 94/97] Document `Import` API --- common/reviews/api/node-core-library.api.md | 3 +- libraries/node-core-library/src/Import.ts | 71 +++++++++++++++++++++ 2 files changed, 72 insertions(+), 2 deletions(-) diff --git a/common/reviews/api/node-core-library.api.md b/common/reviews/api/node-core-library.api.md index bfda62dc5de..95c7fc39e8f 100644 --- a/common/reviews/api/node-core-library.api.md +++ b/common/reviews/api/node-core-library.api.md @@ -340,9 +340,8 @@ export interface IJsonSchemaValidateOptions { customErrorHeader?: string; } -// @public (undocumented) +// @public export class Import { - // (undocumented) static lazy(moduleName: string, require: (id: string) => unknown): any; } diff --git a/libraries/node-core-library/src/Import.ts b/libraries/node-core-library/src/Import.ts index 78e70ccfa5e..2526e3f6cb1 100644 --- a/libraries/node-core-library/src/Import.ts +++ b/libraries/node-core-library/src/Import.ts @@ -4,9 +4,80 @@ import importLazy = require('import-lazy'); /** + * Helpers for resolving and importing Node.js modules. * @public */ export class Import { + /** + * Provides a way to improve process startup times by lazy-loading imported modules. + * + * @remarks + * This is a more structured wrapper for the {@link https://www.npmjs.com/package/import-lazy|import-lazy} + * package. It enables you to replace an import like this: + * + * ```ts + * import * as example from 'example'; // <-- 100ms load time + * + * if (condition) { + * example.doSomething(); + * } + * ``` + * + * ...with a pattern like this: + * + * ```ts + * const example: typeof import('example') = Import.lazy('example', require); + * + * if (condition) { + * example.doSomething(); // <-- 100ms load time occurs here, only if needed + * } + * ``` + * + * The implementation relies on JavaScript's `Proxy` feature to intercept access to object members. Thus + * it will only work correctly with certain types of module exports. If a particular export isn't well behaved, + * you may need to find (or introduce) some other module in your dependency graph to apply the optimization to. + * + * Usage guidelines: + * + * - Always specify types using `typeof` as shown above. + * + * - Never apply lazy-loading in a way that would convert the module's type to `any`. Losing type safety + * seriously impacts the maintainability of the code base. + * + * - In cases where the non-runtime types are needed, import them separately using the `Types` suffix: + * + * ```ts + * const example: typeof import('example') = Import.lazy('example', require); + * import type * as exampleTypes from 'example'; + * ``` + * + * - If the imported module confusingly has the same name as its export, then use the Module suffix: + * + * ```ts + * const exampleModule: typeof import('../../logic/Example') = Import.lazy( + * '../../logic/Example', require); + * import type * as exampleTypes from '../../logic/Example'; + * ``` + * + * - If the exports cause a lot of awkwardness (e.g. too many expressions need to have `exampleModule.` inserted + * into them), or if some exports cannot be proxied (e.g. `Import.lazy('example', require)` returns a function + * signature), then do not lazy-load that module. Instead, apply lazy-loading to some other module which is + * better behaved. + * + * - It's recommended to sort imports in a standard ordering: + * + * ```ts + * // 1. external imports + * import * as path from 'path'; + * import { Import, JsonFile, JsonObject } from '@rushstack/node-core-library'; + * + * // 2. local imports + * import { LocalFile } from './path/LocalFile'; + * + * // 3. lazy-imports (which are technically variables, not imports) + * const semver: typeof import('semver') = Import.lazy('semver', require); + * ``` + */ // eslint-disable-next-line @typescript-eslint/no-explicit-any public static lazy(moduleName: string, require: (id: string) => unknown): any { const importLazyLocal: (moduleName: string) => unknown = importLazy(require); From 2ad333fc0970e5a0665ed21ad26df4508cd81d0f Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Tue, 18 Aug 2020 15:06:27 -0700 Subject: [PATCH 95/97] Remove getOwnPackageJsonVersion() API --- apps/rush-lib/src/api/Rush.ts | 2 +- apps/rush/src/start.ts | 2 +- common/reviews/api/node-core-library.api.md | 1 - .../src/PackageJsonLookup.ts | 22 ------------------- 4 files changed, 2 insertions(+), 25 deletions(-) diff --git a/apps/rush-lib/src/api/Rush.ts b/apps/rush-lib/src/api/Rush.ts index 32051cfb7b9..49b69d13261 100644 --- a/apps/rush-lib/src/api/Rush.ts +++ b/apps/rush-lib/src/api/Rush.ts @@ -93,7 +93,7 @@ export class Rush { */ public static get version(): string { if (!this._version) { - this._version = PackageJsonLookup.getOwnPackageJsonVersion(__dirname); + this._version = PackageJsonLookup.loadOwnPackageJson(__dirname).version; } return this._version!; diff --git a/apps/rush/src/start.ts b/apps/rush/src/start.ts index 7b24f81134a..e5d7b65eca1 100644 --- a/apps/rush/src/start.ts +++ b/apps/rush/src/start.ts @@ -34,7 +34,7 @@ const configuration: | MinimalRushConfiguration | undefined = MinimalRushConfiguration.loadFromDefaultLocation(); -const currentPackageVersion: string = PackageJsonLookup.getOwnPackageJsonVersion(__dirname); +const currentPackageVersion: string = PackageJsonLookup.loadOwnPackageJson(__dirname).version; let rushVersionToLoad: string | undefined = undefined; diff --git a/common/reviews/api/node-core-library.api.md b/common/reviews/api/node-core-library.api.md index 95c7fc39e8f..03b128bee27 100644 --- a/common/reviews/api/node-core-library.api.md +++ b/common/reviews/api/node-core-library.api.md @@ -509,7 +509,6 @@ export const enum NewlineKind { export class PackageJsonLookup { constructor(parameters?: IPackageJsonLookupParameters); clearCache(): void; - static getOwnPackageJsonVersion(dirnameOfCaller: string): string; loadNodePackageJson(jsonFilename: string): INodePackageJson; static loadOwnPackageJson(dirnameOfCaller: string): IPackageJson; loadPackageJson(jsonFilename: string): IPackageJson; diff --git a/libraries/node-core-library/src/PackageJsonLookup.ts b/libraries/node-core-library/src/PackageJsonLookup.ts index 490d8436bd3..6152e073d49 100644 --- a/libraries/node-core-library/src/PackageJsonLookup.ts +++ b/libraries/node-core-library/src/PackageJsonLookup.ts @@ -100,28 +100,6 @@ export class PackageJsonLookup { ); } - /** - * Gets the version of the package.json of the currently executing script. - * - * @param dirnameOfCaller - The search for package.json will start at the this directory, - * and then move upwards. Use the __dirname macro to get the path to the directory of the - * currently executing source file. - */ - public static getOwnPackageJsonVersion(dirnameOfCaller: string): string { - let parent: string = path.dirname(dirnameOfCaller); - let depth: number = 10; - const minDepth: number = 1; - do { - try { - return require(path.resolve(dirnameOfCaller, 'package.json')).version; - } catch { - dirnameOfCaller = parent; - parent = path.dirname(dirnameOfCaller); - } - } while (parent !== dirnameOfCaller && depth-- >= minDepth); - throw new Error("Couldn't get path"); - } - /** * Clears the internal file cache. * @remarks From c7a47f157c49442cbc35400499791c0c0466be60 Mon Sep 17 00:00:00 2001 From: Sachin Joseph Date: Tue, 18 Aug 2020 15:18:41 -0700 Subject: [PATCH 96/97] Revert changes to schema loading --- .../src/api/ApprovedPackagesConfiguration.ts | 13 +++---------- apps/rush-lib/src/api/CommandLineConfiguration.ts | 13 +++---------- .../rush-lib/src/api/CommonVersionsConfiguration.ts | 13 +++---------- apps/rush-lib/src/api/ExperimentsConfiguration.ts | 13 +++---------- apps/rush-lib/src/api/RushConfiguration.ts | 11 +++-------- apps/rush-lib/src/api/VersionPolicyConfiguration.ts | 13 +++---------- apps/rush-lib/src/logic/RepoStateFile.ts | 11 +++-------- .../src/logic/deploy/DeployScenarioConfiguration.ts | 13 +++---------- 8 files changed, 24 insertions(+), 76 deletions(-) diff --git a/apps/rush-lib/src/api/ApprovedPackagesConfiguration.ts b/apps/rush-lib/src/api/ApprovedPackagesConfiguration.ts index 94412ed4846..c3c3b23e0ba 100644 --- a/apps/rush-lib/src/api/ApprovedPackagesConfiguration.ts +++ b/apps/rush-lib/src/api/ApprovedPackagesConfiguration.ts @@ -47,16 +47,9 @@ export class ApprovedPackagesItem { * @public */ export class ApprovedPackagesConfiguration { - private static _jsonSchemaCached: JsonSchema | undefined = undefined; - private static get _jsonSchema(): JsonSchema { - if (!this._jsonSchemaCached) { - this._jsonSchemaCached = JsonSchema.fromFile( - path.join(__dirname, '../schemas/approved-packages.schema.json') - ); - } - - return this._jsonSchemaCached; - } + private static _jsonSchema: JsonSchema = JsonSchema.fromFile( + path.join(__dirname, '../schemas/approved-packages.schema.json') + ); public items: ApprovedPackagesItem[] = []; diff --git a/apps/rush-lib/src/api/CommandLineConfiguration.ts b/apps/rush-lib/src/api/CommandLineConfiguration.ts index 78c55a7f958..262656fbe10 100644 --- a/apps/rush-lib/src/api/CommandLineConfiguration.ts +++ b/apps/rush-lib/src/api/CommandLineConfiguration.ts @@ -13,16 +13,9 @@ import { CommandJson, ICommandLineJson, ParameterJson } from './CommandLineJson' * Custom Commands and Options for the Rush Command Line */ export class CommandLineConfiguration { - private static _jsonSchemaCached: JsonSchema | undefined = undefined; - private static get _jsonSchema(): JsonSchema { - if (!this._jsonSchemaCached) { - this._jsonSchemaCached = JsonSchema.fromFile( - path.join(__dirname, '../schemas/command-line.schema.json') - ); - } - - return this._jsonSchemaCached; - } + private static _jsonSchema: JsonSchema = JsonSchema.fromFile( + path.join(__dirname, '../schemas/command-line.schema.json') + ); public readonly commands: CommandJson[] = []; public readonly parameters: ParameterJson[] = []; diff --git a/apps/rush-lib/src/api/CommonVersionsConfiguration.ts b/apps/rush-lib/src/api/CommonVersionsConfiguration.ts index c4f5f689e2d..90514feacec 100644 --- a/apps/rush-lib/src/api/CommonVersionsConfiguration.ts +++ b/apps/rush-lib/src/api/CommonVersionsConfiguration.ts @@ -57,16 +57,9 @@ interface ICommonVersionsJson { * @public */ export class CommonVersionsConfiguration { - private static _jsonSchemaCached: JsonSchema | undefined = undefined; - private static get _jsonSchema(): JsonSchema { - if (!this._jsonSchemaCached) { - this._jsonSchemaCached = JsonSchema.fromFile( - path.join(__dirname, '../schemas/common-versions.schema.json') - ); - } - - return this._jsonSchemaCached; - } + private static _jsonSchema: JsonSchema = JsonSchema.fromFile( + path.join(__dirname, '../schemas/common-versions.schema.json') + ); private _filePath: string; private _preferredVersions: ProtectableMap; diff --git a/apps/rush-lib/src/api/ExperimentsConfiguration.ts b/apps/rush-lib/src/api/ExperimentsConfiguration.ts index e3dc9923b5a..1560a677e76 100644 --- a/apps/rush-lib/src/api/ExperimentsConfiguration.ts +++ b/apps/rush-lib/src/api/ExperimentsConfiguration.ts @@ -35,16 +35,9 @@ export interface IExperimentsJson { * @beta */ export class ExperimentsConfiguration { - private static _jsonSchemaCached: JsonSchema | undefined = undefined; - private static get _jsonSchema(): JsonSchema { - if (!this._jsonSchemaCached) { - this._jsonSchemaCached = JsonSchema.fromFile( - path.resolve(__dirname, '..', 'schemas', 'experiments.schema.json') - ); - } - - return this._jsonSchemaCached; - } + private static _jsonSchema: JsonSchema = JsonSchema.fromFile( + path.resolve(__dirname, '..', 'schemas', 'experiments.schema.json') + ); private _experimentConfiguration: IExperimentsJson; private _jsonFileName: string; diff --git a/apps/rush-lib/src/api/RushConfiguration.ts b/apps/rush-lib/src/api/RushConfiguration.ts index e2939c09415..9dfa9efc9f2 100644 --- a/apps/rush-lib/src/api/RushConfiguration.ts +++ b/apps/rush-lib/src/api/RushConfiguration.ts @@ -423,14 +423,9 @@ export type ResolutionStrategy = 'fewer-dependencies' | 'fast'; * @public */ export class RushConfiguration { - private static _jsonSchemaCached: JsonSchema | undefined = undefined; - private static get _jsonSchema(): JsonSchema { - if (!this._jsonSchemaCached) { - this._jsonSchemaCached = JsonSchema.fromFile(path.join(__dirname, '../schemas/rush.schema.json')); - } - - return this._jsonSchemaCached; - } + private static _jsonSchema: JsonSchema = JsonSchema.fromFile( + path.join(__dirname, '../schemas/rush.schema.json') + ); private _rushJsonFile: string; private _rushJsonFolder: string; diff --git a/apps/rush-lib/src/api/VersionPolicyConfiguration.ts b/apps/rush-lib/src/api/VersionPolicyConfiguration.ts index ecefd7645ab..ba9554728bc 100644 --- a/apps/rush-lib/src/api/VersionPolicyConfiguration.ts +++ b/apps/rush-lib/src/api/VersionPolicyConfiguration.ts @@ -64,16 +64,9 @@ export interface IVersionPolicyDependencyJson { * @beta */ export class VersionPolicyConfiguration { - private static _jsonSchemaCached: JsonSchema | undefined = undefined; - private static get _jsonSchema(): JsonSchema { - if (!this._jsonSchemaCached) { - this._jsonSchemaCached = JsonSchema.fromFile( - path.join(__dirname, '../schemas/version-policies.schema.json') - ); - } - - return this._jsonSchemaCached; - } + private static _jsonSchema: JsonSchema = JsonSchema.fromFile( + path.join(__dirname, '../schemas/version-policies.schema.json') + ); private _versionPolicies: Map; private _jsonFileName: string; diff --git a/apps/rush-lib/src/logic/RepoStateFile.ts b/apps/rush-lib/src/logic/RepoStateFile.ts index 9c6c2dc3ce2..9a845be6664 100644 --- a/apps/rush-lib/src/logic/RepoStateFile.ts +++ b/apps/rush-lib/src/logic/RepoStateFile.ts @@ -34,14 +34,9 @@ interface IRepoStateJson { * @public */ export class RepoStateFile { - private static _jsonSchemaCached: JsonSchema | undefined = undefined; - private static get _jsonSchema(): JsonSchema { - if (!this._jsonSchemaCached) { - this._jsonSchemaCached = JsonSchema.fromFile(path.join(__dirname, '../schemas/repo-state.schema.json')); - } - - return this._jsonSchemaCached; - } + private static _jsonSchema: JsonSchema = JsonSchema.fromFile( + path.join(__dirname, '../schemas/repo-state.schema.json') + ); private _repoStateFilePath: string; private _variant: string | undefined; diff --git a/apps/rush-lib/src/logic/deploy/DeployScenarioConfiguration.ts b/apps/rush-lib/src/logic/deploy/DeployScenarioConfiguration.ts index dfca4f0a708..98011f78ff7 100644 --- a/apps/rush-lib/src/logic/deploy/DeployScenarioConfiguration.ts +++ b/apps/rush-lib/src/logic/deploy/DeployScenarioConfiguration.ts @@ -31,16 +31,9 @@ export class DeployScenarioConfiguration { // Example: "deploy-the-thing123" private static _scenarioNameRegExp: RegExp = /^[a-z0-9]+(-[a-z0-9]+)*$/; - private static _jsonSchemaCached: JsonSchema | undefined = undefined; - private static get _jsonSchema(): JsonSchema { - if (!this._jsonSchemaCached) { - this._jsonSchemaCached = JsonSchema.fromFile( - path.join(__dirname, '../../schemas/deploy-scenario.schema.json') - ); - } - - return this._jsonSchemaCached; - } + private static _jsonSchema: JsonSchema = JsonSchema.fromFile( + path.join(__dirname, '../../schemas/deploy-scenario.schema.json') + ); public readonly json: IDeployScenarioJson; From ddbf8b603a83136f48427ecb8247a186a38a65e3 Mon Sep 17 00:00:00 2001 From: Pete Gonzalez <4673363+octogonz@users.noreply.github.com> Date: Tue, 18 Aug 2020 16:18:16 -0700 Subject: [PATCH 97/97] rush update --- common/config/rush/pnpm-lock.yaml | 10 ++++++++++ common/config/rush/repo-state.json | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index d43135f37c6..ec7cf7c8918 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -1264,6 +1264,7 @@ importers: '@types/node': 10.17.13 colors: 1.2.5 fs-extra: 7.0.1 + import-lazy: 4.0.0 jju: 1.4.0 semver: 7.3.2 timsort: 0.3.0 @@ -1291,6 +1292,7 @@ importers: '@types/z-schema': 3.16.31 colors: ~1.2.1 fs-extra: ~7.0.1 + import-lazy: ~4.0.0 jju: ~1.4.0 semver: ~7.3.0 timsort: ~0.3.0 @@ -1352,6 +1354,7 @@ importers: '@types/argparse': 1.0.38 argparse: 1.0.10 colors: 1.2.5 + string-argv: 0.3.1 devDependencies: '@microsoft/rush-stack-compiler-3.5': 0.8.4 '@rushstack/eslint-config': 'link:../../stack/eslint-config' @@ -1367,6 +1370,7 @@ importers: '@types/node': 10.17.13 argparse: ~1.0.9 colors: ~1.2.1 + string-argv: ~0.3.1 ../../libraries/typings-generator: dependencies: '@rushstack/node-core-library': 'link:../node-core-library' @@ -11730,6 +11734,12 @@ packages: node: '>=4' resolution: integrity: sha1-ucczDHBChi9rFC3CdLvMWGbONUY= + /string-argv/0.3.1: + dev: false + engines: + node: '>=0.6.19' + resolution: + integrity: sha512-a1uQGz7IyVy9YwhqjZIZu1c8JO8dNIe20xBmSS6qu9kv++k3JGzCVmprbNN5Kn+BgzD5E7YYwg1CcjuJMRNsvg== /string-hash/1.1.3: dev: false resolution: diff --git a/common/config/rush/repo-state.json b/common/config/rush/repo-state.json index 0e7b20e7ffc..ebf8b4fcffe 100644 --- a/common/config/rush/repo-state.json +++ b/common/config/rush/repo-state.json @@ -1,5 +1,5 @@ // DO NOT MODIFY THIS FILE. It is generated and used by Rush. { - "pnpmShrinkwrapHash": "7d4b0c187763702e4fb1812a30c3d265b2c4bdca", + "pnpmShrinkwrapHash": "085a01ff9cec23aff3bcf17e88893151ed6d70eb", "preferredVersionsHash": "334ea62b6a2798dcf80917b79555983377e7435e" }