-
Notifications
You must be signed in to change notification settings - Fork 29
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
base: master
Are you sure you want to change the base?
Conversation
TODO: Detect if yarn or npm used, also detect if lock file exists and should be included
This reverts commit 20d34de.
@@ -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'; |
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 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'}, |
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 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` + |
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.
It will always show a single package, right?
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.
Yes, should update the text
'\n' | ||
); | ||
|
||
const {indent} = detectIndent(packageSource); |
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 move this block of code into a separate function e.g. updatePackageJson
); | ||
|
||
try { | ||
if (existsSync('yarn.lock')) { |
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 need to make this check every time, right? It can be done only once.
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.
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'}); |
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 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?
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.
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); |
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.
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) |
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 think we need to show more user-friendly errors e.g. console.error(`Error upgrading ${name} module: ${err.message}`)
Good feedback, I'll see when I have time to continue working on this. |
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:
Implements and closes #37