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

WIP: Create separate commits per upgraded package #39

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

olpeh
Copy link

@olpeh olpeh commented Jan 15, 2020

Based on my suggestion in #37, here is a PR that implements that functionality.

This is still a bit of work in progress, but I wanted to open this PR in order to get feedback. I used this solution now for my project and it seems to be working well for my use case.

Here's the list of things to do:

  • Introduce an option in .npm-upgrade.json which will store the name of the package manager used in current project. This option is not mandatory and may not be specified.
  • If it present, use it. If it's not, goto 3.
  • Search for yarn.lock or package-lock.json files. If they present, use corresponding package manager (without setting an option in config file).
  • If lock files are not there, ask user in commit phase about package manager and set it in the config.

Implements and closes #37

@olpeh olpeh requested a review from th0r January 15, 2020 16:20
@@ -18,6 +18,7 @@ import askUser from '../askUser';
import {toSentence} from '../stringUtils';
import {askIgnoreFields} from './ignore';
import Config from '../Config';
import { execSync } from 'child_process';
Copy link
Owner

Choose a reason for hiding this comment

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

Let's move it below import {writeFileSync, existsSync} from 'fs'

@@ -154,6 +155,7 @@ export const handler = catchAsyncError(async opts => {
`from ${from} to ${colorizeDiff(from, to)}?`,
choices: _.compact([
{name: 'Yes', value: true},
{name: 'Update immediately and create a separate commit', value: 'commit'},
Copy link
Owner

Choose a reason for hiding this comment

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

Let's better move it below No option


// Showing the list of modules that are going to be updated
console.log(
`\n${strong('These packages will be updated:')}\n\n` +
Copy link
Owner

Choose a reason for hiding this comment

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

It will always show a single package, right?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, should update the text

'\n'
);

const {indent} = detectIndent(packageSource);
Copy link
Owner

Choose a reason for hiding this comment

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

Let's move this block of code into a separate function e.g. updatePackageJson

);

try {
if (existsSync('yarn.lock')) {
Copy link
Owner

Choose a reason for hiding this comment

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

We don't need to make this check every time, right? It can be done only once.

Copy link
Author

Choose a reason for hiding this comment

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

True

execSync('git add package.json package-lock.json', {stdio: 'inherit'});
} else {
// Default to only using npm install and not including a lock file
execSync('npm install', {stdio: 'inherit'});
Copy link
Owner

Choose a reason for hiding this comment

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

I don't think it's right to generate a package-lock.json if it wasn't there before. There is an npm flag to not generate it during npm install. Shall we use it?

Copy link
Author

Choose a reason for hiding this comment

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

Good idea

}
execSync(`git commit -m "Upgrade ${name} from ${from} to ${to}"`,{stdio: 'inherit'});
// Clean the list of packages to be updated after updating and commiting
updatedModules.splice(0, updatedModules.length);
Copy link
Owner

Choose a reason for hiding this comment

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

Why not just updatedModules = []?

// Clean the list of packages to be updated after updating and commiting
updatedModules.splice(0, updatedModules.length);
} catch(err) {
console.error(err)
Copy link
Owner

Choose a reason for hiding this comment

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

I think we need to show more user-friendly errors e.g. console.error(`Error upgrading ${name} module: ${err.message}`)

@olpeh
Copy link
Author

olpeh commented Jul 9, 2020

Good feedback, I'll see when I have time to continue working on this.

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.

Feature suggestion: Create separate commits per upgraded package
2 participants