-
Notifications
You must be signed in to change notification settings - Fork 607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[rush] Introduce a "rush add" command #843
Changes from 10 commits
0f4ae68
7260861
60f2fa9
0ae6ccf
a66230d
9c6f76f
30df582
caf6983
0a8a922
f094bb8
8add64f
8177fec
bc43560
56a6ab2
ee299b1
1c8e54a
abfabf2
9d66f66
14e448f
6e62fdc
836c9a2
2909608
e0793d0
ddf3e0b
d48c7eb
2d81c46
128da2f
daf87a2
91b5592
a115ad5
2ac1044
612e9bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -743,6 +743,16 @@ export class RushConfiguration { | |
return this._versionPolicyConfiguration; | ||
} | ||
|
||
public getCurrentProjectFromPath(currentFolderPath: string): RushConfigurationProject | undefined { | ||
const resolvedPath: string = path.resolve(currentFolderPath); | ||
for (const project of this.projects) { | ||
if (path.relative(project.projectFolder, resolvedPath).indexOf('..') !== 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Use |
||
return project; | ||
} | ||
} | ||
return undefined; | ||
} | ||
|
||
/** | ||
* Use RushConfiguration.loadFromConfigurationFile() or Use RushConfiguration.loadFromDefaultLocation() | ||
* instead. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,31 +30,36 @@ export class VersionMismatchFinder { | |
VersionMismatchFinder._checkForInconsistentVersions(rushConfiguration, false); | ||
} | ||
|
||
private static _checkForInconsistentVersions( | ||
rushConfiguration: RushConfiguration, | ||
isRushCheckCommand: boolean): void { | ||
public static getMismatches(rushConfiguration: RushConfiguration): VersionMismatchFinder { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Docs? #Resolved |
||
// Collect all the preferred versions into a single table | ||
const allPreferredVersions: { [dependency: string]: string } = {}; | ||
|
||
if (rushConfiguration.ensureConsistentVersions || isRushCheckCommand) { | ||
// Collect all the preferred versions into a single table | ||
const allPreferredVersions: { [dependency: string]: string } = {}; | ||
rushConfiguration.commonVersions.getAllPreferredVersions().forEach((version: string, dependency: string) => { | ||
allPreferredVersions[dependency] = version; | ||
}); | ||
|
||
rushConfiguration.commonVersions.getAllPreferredVersions().forEach((version: string, dependency: string) => { | ||
allPreferredVersions[dependency] = version; | ||
}); | ||
// Create a fake project for the purposes of reporting conflicts with preferredVersions | ||
// or xstitchPreferredVersions from common-versions.json | ||
const projects: RushConfigurationProject[] = [...rushConfiguration.projects]; | ||
|
||
// Create a fake project for the purposes of reporting conflicts with preferredVersions | ||
// or xstitchPreferredVersions from common-versions.json | ||
const projects: RushConfigurationProject[] = [...rushConfiguration.projects]; | ||
projects.push({ | ||
packageName: 'preferred versions from ' + RushConstants.commonVersionsFilename, | ||
packageJson: { dependencies: allPreferredVersions } | ||
} as RushConfigurationProject); | ||
|
||
projects.push({ | ||
packageName: 'preferred versions from ' + RushConstants.commonVersionsFilename, | ||
packageJson: { dependencies: allPreferredVersions } | ||
} as RushConfigurationProject); | ||
return new VersionMismatchFinder( | ||
projects, | ||
rushConfiguration.commonVersions.allowedAlternativeVersions | ||
); | ||
} | ||
|
||
private static _checkForInconsistentVersions( | ||
rushConfiguration: RushConfiguration, | ||
isRushCheckCommand: boolean): void { | ||
|
||
const mismatchFinder: VersionMismatchFinder = new VersionMismatchFinder( | ||
projects, | ||
rushConfiguration.commonVersions.allowedAlternativeVersions | ||
); | ||
if (rushConfiguration.ensureConsistentVersions || isRushCheckCommand) { | ||
const mismatchFinder: VersionMismatchFinder | ||
= VersionMismatchFinder.getMismatches(rushConfiguration); | ||
|
||
// Iterate over the list. For any dependency with mismatching versions, print the projects | ||
mismatchFinder.getMismatches().forEach((dependency: string) => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. | ||
// See LICENSE in the project root for license information. | ||
|
||
import * as os from 'os'; | ||
|
||
import { | ||
CommandLineFlagParameter, | ||
CommandLineStringParameter | ||
} from '@microsoft/ts-command-line'; | ||
|
||
import { RushConfigurationProject } from '../../api/RushConfigurationProject'; | ||
import { BaseRushAction } from './BaseRushAction'; | ||
import { RushCommandLineParser } from '../RushCommandLineParser'; | ||
import { DependencyIntegrator, SemVerStyle } from '../../logic/DependencyIntegrator'; | ||
|
||
export class AddAction extends BaseRushAction { | ||
private _exactFlag: CommandLineFlagParameter; | ||
private _caretFlag: CommandLineFlagParameter; | ||
private _devDependencyFlag: CommandLineFlagParameter; | ||
private _makeConsistentFlag: CommandLineFlagParameter; | ||
private _noInstallFlag: CommandLineFlagParameter; | ||
private _packageName: CommandLineStringParameter; | ||
private _versionSpecifier: CommandLineStringParameter; | ||
|
||
constructor(parser: RushCommandLineParser) { | ||
const documentation: string[] = [ | ||
'Blah.' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
? #Resolved |
||
]; | ||
super({ | ||
actionName: 'add', | ||
summary: 'Adds a dependency to the package.json and runs rush upgrade.', | ||
documentation: documentation.join(os.EOL), | ||
safeForSimultaneousRushProcesses: false, | ||
parser | ||
}); | ||
} | ||
|
||
public onDefineParameters(): void { | ||
this._packageName = this.defineStringParameter({ | ||
parameterLongName: '--package', | ||
parameterShortName: '-p', | ||
required: true, | ||
argumentName: 'PACKAGE_NAME', | ||
description: '(Required) The name of the package which should be added as a dependency' | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is clunky. How hard would it be to add an "anonymous" argument to TS-command-line? #WontFix There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pete and I discussed this, but it will be a pretty big change in ts-command-line. We decided to just go with the normal way for now, then potentially change it later. In reply to: 220407271 [](ancestors = 220407271) |
||
this._versionSpecifier = this.defineStringParameter({ | ||
parameterLongName: '--version', | ||
parameterShortName: '-v', | ||
argumentName: 'VERSION_RANGE', | ||
description: '' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Include a description. #Resolved |
||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this be specified as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could be, but requires extra parsing and whatnot. We will make it like that when we allow anonymous arguments. In reply to: 220407345 [](ancestors = 220407345) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't we just split by the "@" character? In reply to: 220751648 [](ancestors = 220751648,220749976,220743394,220407345) |
||
this._exactFlag = this.defineFlagParameter({ | ||
parameterLongName: '--exact', | ||
description: 'If specified, the version specifier inserted into the' | ||
+ ' package.json will be a locked, exact version.' | ||
}); | ||
this._caretFlag = this.defineFlagParameter({ | ||
parameterLongName: '--caret', | ||
description: 'If specified, the version specifier inserted into the' | ||
+ ' package.json will be a prepended with a "caret" specifier ("^").' | ||
}); | ||
this._devDependencyFlag = this.defineFlagParameter({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These can be just specified with the version. #ByDesign There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can specify the version as "~1.2.3" or "^2.3.4" In reply to: 220743430 [](ancestors = 220743430,220407415) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You highlighted devDependency flag. And that isn't how --version works. It works how "npm install --save" works. In reply to: 220750046 [](ancestors = 220750046,220743430,220407415) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So NPM has --carat and --tilde arguments? That seems really clunky. In reply to: 220751772 [](ancestors = 220751772,220750046,220743430,220407415) |
||
parameterLongName: '--dev', | ||
description: 'If specified, the package will be added as a "devDependency"' | ||
+ ' to the package.json' | ||
}); | ||
this._makeConsistentFlag = this.defineFlagParameter({ | ||
parameterLongName: '--make-consistent', | ||
parameterShortName: '-c', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
description: 'If specified, other packages with this dependency will have their package.json' | ||
+ ' files updated to point at the specified depdendency' | ||
}); | ||
this._noInstallFlag = this.defineFlagParameter({ | ||
parameterLongName: '--no-install', | ||
parameterShortName: '-n', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Is this the same as npm? #WontFix There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you mean. NPM doesn't have an option for --skip-install or --no-install or anything. In reply to: 220750062 [](ancestors = 220750062,220407520) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
description: 'If specified, the "rush update" command will not be run after updating the' | ||
+ ' package.json files.' | ||
}); | ||
} | ||
|
||
public run(): Promise<void> { | ||
const project: RushConfigurationProject | undefined | ||
= this.rushConfiguration.getCurrentProjectFromPath(process.cwd()); | ||
|
||
if (!project) { | ||
return Promise.reject(new Error('Not currently in a project folder')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The "rush add" command must be invoked under a project folder that is registered in rush.json #Resolved There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
|
||
if (this._caretFlag.value && this._exactFlag.value) { | ||
return Promise.reject(new Error('Only one of --caret and --exact should be specified')); | ||
} | ||
|
||
return new DependencyIntegrator(this.rushConfiguration).run({ | ||
currentProject: project, | ||
packageName: this._packageName.value!, | ||
initialVersion: this._versionSpecifier.value, | ||
devDependency: this._devDependencyFlag.value, | ||
updateOtherPackages: this._makeConsistentFlag.value, | ||
skipInstall: this._noInstallFlag.value, | ||
debugInstall: this.parser.isDebug, | ||
rangeStyle: this._caretFlag.value ? SemVerStyle.Caret | ||
: (this._exactFlag.value ? SemVerStyle.Exact : SemVerStyle.Tilde) | ||
}); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ proven turnkey solution for monorepo management, Rush is for you. | |
|
||
Positional arguments: | ||
<command> | ||
add Adds a dependency to the package.json and runs rush upgrade. | ||
change Records changes made to projects, indicating how the | ||
package version number should be bumped for the next | ||
publish. | ||
|
@@ -51,6 +52,35 @@ For detailed help about a specific command, use: rush <command> -h | |
" | ||
`; | ||
|
||
exports[`CommandLineHelp prints the help for "rush add" 1`] = ` | ||
"usage: rush add [-h] -p PACKAGE_NAME [-v VERSION_RANGE] [--exact] [--caret] | ||
[--dev] [-c] [-n] | ||
|
||
|
||
Blah. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? #Resolved There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
Optional arguments: | ||
-h, --help Show this help message and exit. | ||
-p PACKAGE_NAME, --package PACKAGE_NAME | ||
(Required) The name of the package which should be | ||
added as a dependency | ||
-v VERSION_RANGE, --version VERSION_RANGE | ||
--exact If specified, the version specifier inserted into the | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
"SemVer specifier added to" #Resolved |
||
package.json will be a locked, exact version. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
an exact version (e.g. without tilde or caret) #Resolved |
||
--caret If specified, the version specifier inserted into the | ||
package.json will be a prepended with a \\"caret\\" | ||
specifier (\\"^\\"). | ||
--dev If specified, the package will be added as a | ||
\\"devDependency\\" to the package.json | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
-c, --make-consistent | ||
If specified, other packages with this dependency | ||
will have their package.json files updated to point | ||
at the specified depdendency | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. specify the same SemVer range? #Resolved |
||
-n, --no-install If specified, the \\"rush update\\" command will not be | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
--skip-update? #Resolved |
||
run after updating the package.json files. | ||
" | ||
`; | ||
|
||
exports[`CommandLineHelp prints the help for "rush build" 1`] = ` | ||
"usage: rush build [-h] [-p COUNT] [-t PROJECT1] | ||
[--to-version-policy VERSION_POLICY_NAME] [-f PROJECT2] [-v] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getProjectFromPath
? It doesn't necessarily need to be the current project or the current path. #Resolved