Skip to content
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

feat(Upgrade): add scope flag to the upgrade command #3190

Merged
merged 7 commits into from
Apr 24, 2017
Merged

feat(Upgrade): add scope flag to the upgrade command #3190

merged 7 commits into from
Apr 24, 2017

Conversation

Joge97
Copy link
Contributor

@Joge97 Joge97 commented Apr 19, 2017

The upgrade command now supports the -S, --scope <scope> flag. If the flag is set and a scope is provided yarn upgrade only the packages, which belong to the specified scope.

It is very usefull when you have packages under the @angular scope, so you can upgrade all of them at the same time without touching the other packages.

I have tested the command in multiple projects and I have written some test code.

yarn upgrade --scope @angular

I hope you understand the use case and integrate the pull request.

Copy link
Member

@arcanis arcanis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe an RFC would have been a good start, but it's simple enough and I can see the use case so I guess we can talk about this here (@bestander).


const addArgs = args.map((dependency) => {
const remoteSource = allDependencies[dependency];
console.log(allDependencies);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum 😛

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, my mistake...

if (remoteSource && PackageRequest.getExoticResolver(remoteSource)) {
return remoteSource;
if (flags.scope) {
const searchPattern = new RegExp(`^${flags.scope}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1/ We probably want to run a check to make sure that flags.scope is a valid scope, and abort otherwise
2/ The regex above will make -S @angular upgrade @angular, but also @angular-community etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will implement a check.

addArgs = args.map((dependency) => {
const remoteSource = allDependencies[dependency];

console.log(remoteSource);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bis :)

addArgs.push(remoteSource);
}

addArgs.push(dependency);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't that be in an else statement?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, definitely!

expect(pkg.dependencies['@angular/core']).not.toEqual('^2.4.9');
expect(pkg.dependencies['left-pad']).toEqual('^1.0.0');
});
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also add a test to make sure that -S @angular doesn't upgrade @angular-whatever

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will fix the test issue and add this test case.

@@ -27,16 +28,37 @@ export async function run(
peerDependencies,
} = await config.readRootManifest() || {};
const allDependencies = Object.assign({}, peerDependencies, optionalDependencies, devDependencies, dependencies);
let addArgs = [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding the global workflow of the code, I'd prefer using ES5 array functions:

let addArgs = Object.keys(allDependencies);

if (flags.scope) {
    addArgs = addArgs.filter(arg => {
        return ...;
    });
}

addArgs = addArgs.map(arg => {
    return ...;
});

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I will do that.

@arcanis
Copy link
Member

arcanis commented Apr 19, 2017

Please also note that your test isn't passing.

@Joge97
Copy link
Contributor Author

Joge97 commented Apr 19, 2017

I will fix the issues tomorrow.

@Joge97
Copy link
Contributor Author

Joge97 commented Apr 20, 2017

I have fixed te issues (@arcanis).

if (remoteSource && PackageRequest.getExoticResolver(remoteSource)) {
return remoteSource;
}
if (/^@\S*\/$/g.test(flags.scope)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use [a-zA-Z0-9-][a-zA-Z0-9_.-]* instead of \S*, this way we ensure that the scope is a valid scope according to npm rules (and we won't risk any schenanigans with extra /).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I will change it.

return remoteSource;
}
if (/^@\S*\/$/g.test(flags.scope)) {
const searchPattern = new RegExp(`^${flags.scope}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to check directly with String.prototype.startsWith (otherwise you'll have issues with the . character)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make an example, because I don't understand the issue?

@arcanis
Copy link
Member

arcanis commented Apr 20, 2017

The Travis test is failing (apparently, @angular-mdl/core get upgraded as well).

@Joge97
Copy link
Contributor Author

Joge97 commented Apr 24, 2017

I fixed the issues (@arcanis).

@arcanis arcanis merged commit 65595e3 into yarnpkg:master Apr 24, 2017
@arcanis
Copy link
Member

arcanis commented Apr 24, 2017

Thanks ! 👍

This was referenced Apr 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants