-
-
Notifications
You must be signed in to change notification settings - Fork 54
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
Add initial support for --dry-run #58
Conversation
Added a better differ. The output looks something like this right now
|
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.
looking good to me! will leave some more thoughts later when i've got a chance
do you have any thoughts on testing this? it would be nice if we could assert that we don't write anything when a dry run happens
also, any thoughts on the flag? as mentioned here, it might be safer to flip this and use --write
as the flag that does write changes
src/index.js
Outdated
pkg.babel = upgradeConfig(pkg.babel, options); | ||
updatedPkg.babel = upgradeConfig(pkg.babel, options); | ||
} | ||
if (options.dryRun) { |
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.
maybe this block should happen whether or not we're doing a dry run? eg, have dry run only control whether writeJsonFile
gets called
Just wondering, is there a way to show the diff like in git? like with + and -? or like jest snapshots? I think showing the files one after the other would be difficult to read? Wonder if we could just render a github type diff on a website even. Although maybe I'd just tell them to run it and run |
@hzoo Yup, the Index: package.json
===================================================================
--- package.json Before Upgrade
+++ package.json After Upgrade
@@ -62,23 +62,23 @@
"string-format": "^0.5.0",
"traverse": "^0.6.6"
},
"devDependencies": {
+ "@babel/cli": "7.0.0-beta.40",
+ "@babel/core": "7.0.0-beta.40",
+ "@babel/plugin-transform-react-jsx-self": "7.0.0-beta.40",
+ "@babel/plugin-transform-react-jsx-source": "7.0.0-beta.40",
+ "@babel/plugin-transform-runtime": "7.0.0-beta.40",
+ "@babel/polyfill": "7.0.0-beta.40",
+ "@babel/preset-env": "7.0.0-beta.40",
+ "@babel/preset-react": "7.0.0-beta.40",
+ "@babel/preset-stage-2": "7.0.0-beta.40",
"autoprefixer": "8.1.0",
- "babel-cli": "^6.26.0",
- "babel-core": "^6.26.0",
"babel-eslint": "^7.1.0",
- "babel-loader": "^7.1.1",
+ "babel-loader": "^8.0.0-beta.0",
"babel-plugin-lodash": "^3.3.2",
"babel-plugin-transform-imports": "^1.4.1",
- "babel-plugin-transform-react-jsx-self": "^6.22.0",
- "babel-plugin-transform-react-jsx-source": "^6.22.0",
"babel-plugin-transform-react-remove-prop-types": "^0.4.10",
- "babel-plugin-transform-runtime": "^6.23.0",
- "babel-polyfill": "^6.26.0",
- "babel-preset-env": "^1.6.0",
- "babel-preset-react": "^6.24.1",
- "babel-preset-stage-2": "^6.24.1",
"bitbar-webpack-progress-plugin": "^0.1.3",
"clean-webpack-plugin": "^0.1.17",
"copy-webpack-plugin": "^4.5.0",
"css-loader": "^0.28.9", @kedromelon I'm not really sure about the tests myself, as I don't have enough experience writing them. Would love more input on it. |
Rolled back some of my changes and found a simpler way of showing the diff. Following your review @kedromelon, the diff shows up always and only the write action is controlled by the Still unsure of how a test would look like. Will think about it over the weekend. |
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.
@aulisius changes look fantastic, definitely an improvement in clarity!
i'm still thinking about how best to do tests here as well...
src/index.js
Outdated
|
||
await writeJsonFile(path, pkg, { detectIndent: true }); | ||
if (!options.dryRun) { | ||
await writeJsonFile(path, pkg, { detectIndent: 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.
for testing this, perhaps we could stub the default export of write-json-file
with jest and then assert that it is called (with the correct arguments) when options.dryRun
is true and assert that it is not called when options.dryRun
isn't?
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 was thinking along the same lines. I can get started on that. What about the diffs? Is there any value to testing the diff output itself?
…/babel-upgrade into feat/add-dry-run-option
@@ -1,6 +1,6 @@ | |||
{ | |||
"name": "babel-upgrade", | |||
"version": "0.0.15", | |||
"version": "0.0.16", |
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.
Typically version numbers should never be bumped in PRs (or at least, not in PRs that do anything else)
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.
Forgot to rebase before pushing, the master branch actually has version as 0.0.16
not sure why the diff isn't updated with master
.
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.
ah i was just looking at the "view changes" diff, no worries
@hzoo @kedromelon Added a test. Please do tell if that is enough. |
__tests__/packageData.test.js
Outdated
@@ -74,3 +74,21 @@ test('jest babel-core bridge', async () => { | |||
test('webpack v1 compatibility', async () => { | |||
expect(await updatePackageJSON(webpackV1Fixture)).toMatchSnapshot(); | |||
}); | |||
|
|||
test('respects dry run', async () => { |
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 is great! thanks for adding!!
just two suggestions:
- could we make
__tests__/index.test.js
and do this test there? - could we also test that
writeJsonFile
is called when the dry run is not used?
Updated the tests. I think the last thing to discuss is with regards to the flag. Do we make |
How about:
Also, if it hasn't been implemented (sorry, just found this repo so haven't had a chance to dig into the codebase), how about adding a cache system (mtime?). This would be very helpful on monorepos 😄 |
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.
awesome! tests look great. regarding flag itself and its defaults i think it does make sense to dry run by default, and require a --write
flag to allow it to write, as discussed in #6
if we are to do that, however, we need to be sure to update the readme with this new detail. given that, i think it would be OK to have this PR just add the support for the functionality, and let the behavior change and documentation updates be handled in a separate PR? open to whatever though, curious to hear others' thoughts!
Made @futagoza I do like your suggestion but I think it can be done as part of another PR because it requires quite some changes. @kedromelon Yea, I also think it'd be better if those documentation and/or README updates happened in another PR. |
as discussed in #58 (comment), `babel-upgrade` will make no changes unless a `--write` or `-w` flag is provided after #58 is merged. this PR updates the readme to communicate this change in functionality.
src/bin.js
Outdated
@@ -38,7 +50,7 @@ async function hasFlow() { | |||
await writePackageJSON(upgradeOptions); | |||
|
|||
// TODO: add smarter CLI option handling if we support more options | |||
if (process.argv[2] === '--install') { | |||
if (cliOptions.write && cliOptions.installDeps) { |
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.
thought of this after your comment on #62
do you think we should provide a warning when the user gives the --install
flag but does not include --write
? otherwise it might be difficult for them to understand what is going on in that situation?
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.
Yeah, agreed. Will add that
Added the note about install w/o write! @kedromelon we're good to go. |
* add --write flag to readme (followup for #58) as discussed in #58 (comment), `babel-upgrade` will make no changes unless a `--write` or `-w` flag is provided after #58 is merged. this PR updates the readme to communicate this change in functionality.
Is this in v7 yet? I'm trying to do the dry run flag but I still get files generated. I'm using I'm trying to see the plugins and target browsers being used when debug is set to true. Is there a better way to do this or a more direct command for such? I know |
Still unsure how to show the actual diff or what kind of tests to write for this. Currently, I've used
difflet
package but not sure if that is enough.Closes #6