-
Notifications
You must be signed in to change notification settings - Fork 609
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] Fix the issue: "rush add" should be able to add unpublished locally-linked projects #1612
Conversation
…zhas/rush-add-test
…zhas/rush-add-test
const rushConfigProjects: RushConfigurationProject[] = this._rushConfiguration.projects; | ||
rushConfigProjects.forEach(rushConfigProject => { | ||
if(rushConfigProject.packageName === packageName) { | ||
selectedVersion = rushConfigProject.packageJson.version; |
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.
You should break out of the loop here.
We also probably want to handle the case where a version is specified on the command-line and it doesn't match the version in the package.json
We also need to handle the case where the dependency that we're adding is marked as a cyclic dependency for the project in rush.json
.
@@ -355,18 +355,28 @@ export class PackageJsonUpdater { | |||
} | |||
console.log(`Querying NPM registry for latest version of "${packageName}"...`); | |||
|
|||
//if the project exists in the local |
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.
//if the project exists in the local | |
// determine if the package is a project in the local repository |
selectedVersion = rushConfigProject.packageJson.version; | ||
} | ||
}); | ||
|
||
let commandArgs: string[]; |
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.
This code should go inside the below condition.
common/changes/@microsoft/rush/zhas-rush-add-test_2019-11-01-21-43.json
Outdated
Show resolved
Hide resolved
// determine if the package is a project in the local repository and if the version exists | ||
for (const rushConfigProject of rushConfigProjects) { | ||
const rushConfigProjectVersion: string = rushConfigProject.packageJson.version; | ||
if(rushConfigProject.packageName === packageName && rushConfigProject.cyclicDependencyProjects.size === 0) { |
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.
The cyclic dependency check should probably happen before the loop starts.
I think this logic is also backwards: we need to check if the project we're adding the dependency to has the dependency listed as a cyclic. We also need to see if the dependency is in the set of cyclics, not just if there are any cyclic dependencies listed.
for (const rushConfigProject of rushConfigProjects) { | ||
const rushConfigProjectVersion: string = rushConfigProject.packageJson.version; | ||
if(rushConfigProject.packageName === packageName && rushConfigProject.cyclicDependencyProjects.size === 0) { | ||
if(initialSpec === rushConfigProjectVersion) { |
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.
This should use semver.satisfies(...)
. If the initialspec is anything other than a single version (like ~1.2.3
), this will always cause an exception to be thrown.
Can you list out the scenarios you tested? There are a lot of them and we should be sure the behavior is expected. |
} else { | ||
commandArgs = ['view', `${packageName}@latest`, 'version']; | ||
// determine if the package is a project in the local repository | ||
for (const rushConfigProject of rushConfigProjects) { |
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.
This seems to be duplicated above (very similar). Better to move to its own function
commandArgs = ['info', packageName, 'versions', '--json']; | ||
} else { | ||
commandArgs = ['view', packageName, 'versions', '--json']; | ||
// determine if the package is a project in the local repository and if the version exists |
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.
Shouldn't we check for local packages after we checked the npm registry ?
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.
If we find the local package, we don't need to check the registry.
@@ -268,13 +269,15 @@ export class PackageJsonUpdater { | |||
* Selects an appropriate version number for a particular package, given an optional initial SemVer spec. | |||
* If ensureConsistentVersions, tries to pick a version that will be consistent. | |||
* Otherwise, will choose the latest semver matching the initialSpec and append the proper range style. | |||
* @param projects - the project which will have its package.json updated |
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.
* @param projects - the project which will have its package.json updated | |
* @param projects - the projects which will have their `package.json`s updated |
commandArgs = ['info', packageName, 'versions', '--json']; | ||
} else { | ||
commandArgs = ['view', packageName, 'versions', '--json']; | ||
// determine if the package is a project in the local repository and if the version exists |
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.
If we find the local package, we don't need to check the registry.
// determine if the package is a project in the local repository and if the version exists | ||
for (const rushConfigProject of rushConfigProjects) { | ||
const rushConfigProjectVersion: string = rushConfigProject.packageJson.version; | ||
if(rushConfigProject.packageName === packageName && !projects[0].cyclicDependencyProjects.has(packageName)) { |
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.
We don't just want to check the first project in the projects
array. It should probably check all of them.
* @param packageName - the name of the package to be used | ||
* @param initialSpec - a semver pattern that should be used to find the latest version matching the spec | ||
* @param implicitlyPinnedVersion - the implicitly preferred (aka common/primary) version of the package in use | ||
* @param rangeStyle - if this version is selected by querying registry, then this range specifier is prepended to | ||
* the selected version. | ||
*/ | ||
private async _getNormalizedVersionSpec( | ||
projects: RushConfigurationProject[], |
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.
Do we support multiple projects?
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.
I don't think so.. That's why I'm curious about why it has an array here. The statement is like this: projects = [currentProject]; Don't you think we actually don't need this array here?
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.
Looks like this is used when the --all
flag is specified.
selectedVersion = initialSpec; | ||
break; | ||
} else { | ||
throw new Error(`Unable to find a version of "${packageName}" that satisfies` |
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.
Let's be a little more elaborate with this error:
throw new Error(`Unable to find a version of "${packageName}" that satisfies` | |
throw new Error(`The dependency being added ("${packageName}") is a project in the local Rush repository, but the version specifier provided (${initialSpec}) does not match the local project version (${rushConfigProjectVersion}). Correct the version specifier, omit a version specifier, or include "${packageName}" as a cyclicDependencyProject in rush.json for ${<project-being-added-to>} if it is intended for "${packageName}" to come from an external feed and not from the local Rush repository.`); |
// determine if the package is a project in the local repository | ||
for (const rushConfigProject of rushConfigProjects) { | ||
if(rushConfigProject.packageName === packageName && !projects[0].cyclicDependencyProjects.has(packageName)) { | ||
if(selectedVersion === undefined) { |
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.
This check should go outside of the loop.
/** | ||
* Check if the package is the cyclic dependency in the project dependencies in package.json | ||
*/ | ||
public isCyclicDependency( |
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.
Let's make these private
to begin with.
|
||
/** | ||
* Check if the project is local project | ||
* If it is found in rush.json and is not a cyclic dependency, return true |
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.
This function returns a version specifier, not true or false.
* @param projects - the projects which will have their package.json's updated | ||
* @param rushConfigProjects - the projects which are in the rush.json | ||
*/ | ||
public isLocalProject( |
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.
A better name for this would be getVersionForLocalDependency
.
} else { | ||
commandArgs = ['view', packageName, 'versions', '--json']; | ||
throw new Error(`The dependency being added ("${packageName}") is a project in the local Rush repository, |
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.
Split this onto multiple lines by concatenating strings. The way this is written, there will be line breaks and indentation in the error message.
} else { | ||
commandArgs = ['view', packageName, 'versions', '--json']; | ||
throw new Error(`The dependency being added ("${packageName}") is a project in the local Rush repository, |
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.
This will throw if the dependency being added isn't a local dependency. In that case, we want to just query the feed.
…zhas/rush-add-test
…idated as new depdndencies.
This address the issue: #991