Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Suggestion: Allow only patch updates on package.json #11493

Closed
wants to merge 1 commit into from
Closed

Suggestion: Allow only patch updates on package.json #11493

wants to merge 1 commit into from

Conversation

luixxiul
Copy link
Contributor

@luixxiul luixxiul commented Oct 12, 2017

This PR replaces carets with tildes to allow only patch updates on package.json.

Because of minor updates a nasty bug like #11454 and #10029 sometimes happens, which is hard to find what introduced them (there seems to be almost no way of detecting it automatically). The thing is that semver is just a norm and developers can regard an update as a patch mistakenly, where it actually is a minor update.

Forcing only patch updates is one step to remove semver, which introduces a security risk as well. IMHO, major / minor updates should be done via PR to merge the change after it is verified via Travis tests result that nothing should get corrupted due to that update, locally and remotely.

This PR is based on https://gist.github.com/luixxiul/1cf8689da05e509d45176588730e5a16 which you should get with npm list on 7de1673. I added comments to each update, referring to that gist, to make it easy to review.

As long as the packages.json is not manually updated, this PR should be valid.

Closes #11458

Auditors:

Test Plan:

  1. npm install

Submitter Checklist:

  • Submitted a ticket for my issue if one did not already exist.
  • Used Github auto-closing keywords in the commit message.
  • Added/updated tests for this change (for new code or code which already has tests).
  • Ran git rebase -i to squash commits (if needed).
  • Tagged reviewers and labelled the pull request as needed.

Test Plan:

Reviewer Checklist:

Tests

  • Adequate test coverage exists to prevent regressions
  • Tests should be independent and work correctly when run individually or as a suite ref
  • New files have MPL2 license header

Closes #11458

Minor update sometimes causes a nasty bug like #11454 and #10029

Auditors:

Test Plan:
1. npm install
@@ -84,111 +84,111 @@
"homepage": "https://www.brave.com/",
"dependencies": {
"acorn": "3.2.0",
"ad-block": "^3.0.5",
"ad-block": "~3.0.5",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"bat-client": "^1.0.5",
"bat-publisher": "^1.0.2",
"bignumber.js": "^4.0.4",
"async": "~2.5.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"bat-publisher": "^1.0.2",
"bignumber.js": "^4.0.4",
"async": "~2.5.0",
"bat-balance": "~1.0.1",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"bignumber.js": "^4.0.4",
"async": "~2.5.0",
"bat-balance": "~1.0.1",
"bat-client": "~1.0.5",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"async": "~2.5.0",
"bat-balance": "~1.0.1",
"bat-client": "~1.0.5",
"bat-publisher": "~1.0.2",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"bat-balance": "~1.0.1",
"bat-client": "~1.0.5",
"bat-publisher": "~1.0.2",
"bignumber.js": "~4.0.4",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"clipboard-copy": "^1.0.0",
"compare-versions": "^3.0.1",
"electron-localshortcut": "^0.6.0",
"clipboard-copy": "~1.2.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"compare-versions": "^3.0.1",
"electron-localshortcut": "^0.6.0",
"clipboard-copy": "~1.2.0",
"compare-versions": "~3.1.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"electron-localshortcut": "^0.6.0",
"clipboard-copy": "~1.2.0",
"compare-versions": "~3.1.0",
"electron-localshortcut": "~0.6.1",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"electron-squirrel-startup": "brave/electron-squirrel-startup",
"emoji-regex": "^6.5.1",
"emoji-regex": "~6.5.1",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"file-loader": "0.11.2",
"font-awesome": "^4.5.0",
"font-awesome": "~4.7.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"fs-extra": "^2.1.2",
"immutable": "^3.7.5",
"immutablediff": "^0.4.2",
"fs-extra": "~2.1.2",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"immutable": "^3.7.5",
"immutablediff": "^0.4.2",
"fs-extra": "~2.1.2",
"immutable": "~3.8.1",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"immutablediff": "^0.4.2",
"fs-extra": "~2.1.2",
"immutable": "~3.8.1",
"immutablediff": "~0.4.4",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"immutablepatch": "brave/immutable-js-patch",
"l20n": "^3.5.1",
"lru-cache": "^1.0.0",
"l20n": "~3.5.1",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"l20n": "^3.5.1",
"lru-cache": "^1.0.0",
"l20n": "~3.5.1",
"lru-cache": "~1.1.1",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"prettier-bytes": "^1.0.3",
"prop-types": "^15.5.6",
"punycode": "^2.0.0",
"niceware": "~1.0.4",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"prop-types": "^15.5.6",
"punycode": "^2.0.0",
"niceware": "~1.0.4",
"parse-torrent": "~5.8.3",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"punycode": "^2.0.0",
"niceware": "~1.0.4",
"parse-torrent": "~5.8.3",
"prettier-bytes": "~1.0.4",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"niceware": "~1.0.4",
"parse-torrent": "~5.8.3",
"prettier-bytes": "~1.0.4",
"prop-types": "~15.6.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"parse-torrent": "~5.8.3",
"prettier-bytes": "~1.0.4",
"prop-types": "~15.6.0",
"punycode": "~2.1.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"react-dom": "^15.5.4",
"string.prototype.endswith": "^0.2.0",
"string.prototype.startswith": "^0.2.0",
"react": "~15.6.2",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"string.prototype.endswith": "^0.2.0",
"string.prototype.startswith": "^0.2.0",
"react": "~15.6.2",
"react-dnd": "~2.5.1",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"string.prototype.startswith": "^0.2.0",
"react": "~15.6.2",
"react-dnd": "~2.5.1",
"react-dnd-html5-backend": "~2.5.1",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"react": "~15.6.2",
"react-dnd": "~2.5.1",
"react-dnd-html5-backend": "~2.5.1",
"react-dom": "~15.6.2",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"mockery": "~2.1.0",
"muon-winstaller": "~2.5.5",
"ncp": "~2.0.0",
"node-gyp": "~3.6.2",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"node-libs-browser": "~2.0.0",
"node-static": "^0.7.7",
"nsp": "^2.2.0",
"node-static": "~0.7.10",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"node-static": "^0.7.7",
"nsp": "^2.2.0",
"node-static": "~0.7.10",
"nsp": "~2.8.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"react-test-renderer": "^15.5.4",
"request": "^2.81.0",
"sinon": "^1.17.6",
"pre-push": "~0.1.1",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"request": "^2.81.0",
"sinon": "^1.17.6",
"pre-push": "~0.1.1",
"react-addons-perf": "~15.4.2",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"sinon": "^1.17.6",
"pre-push": "~0.1.1",
"react-addons-perf": "~15.4.2",
"react-addons-test-utils": "~15.6.2",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"pre-push": "~0.1.1",
"react-addons-perf": "~15.4.2",
"react-addons-test-utils": "~15.6.2",
"react-test-renderer": "~15.6.2",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"react-addons-perf": "~15.4.2",
"react-addons-test-utils": "~15.6.2",
"react-test-renderer": "~15.6.2",
"request": "~2.82.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"react-addons-test-utils": "~15.6.2",
"react-test-renderer": "~15.6.2",
"request": "~2.82.0",
"sinon": "~1.17.7",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"spectron": "brave/spectron#chromium60",
"standard": "9.0.0",
"style-loader": "~0.18.2",
"uglifyjs-webpack-plugin": "^1.0.0-beta.2",
"uuid": "^3.0.1",
"uglifyjs-webpack-plugin": "~1.0.0-beta.2",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"uglifyjs-webpack-plugin": "^1.0.0-beta.2",
"uuid": "^3.0.1",
"uglifyjs-webpack-plugin": "~1.0.0-beta.2",
"uuid": "~3.1.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"webdriverio": "4.7.1",
"webpack": "~3.4.1",
"webpack-dev-server": "~2.6.1",
"webpack-notifier": "^1.2.1",
"xml2js": "^0.4.15"
"webpack-notifier": "~1.5.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"webpack-notifier": "^1.2.1",
"xml2js": "^0.4.15"
"webpack-notifier": "~1.5.0",
"xml2js": "~0.4.19"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@petemill
Copy link
Member

If we do this, then we could use an automated service like https://greenkeeper.io/ which monitors npm dependencies, then sends PRs when each npm dependency has a new minor / major version, allowing our tests to run with only that update

@evq
Copy link
Member

evq commented Oct 19, 2017

I'm not sure this will have much of an effect, we have a package-lock.json and my understanding is that this actually freezes to an exact version including patch. So it should be possible to determine the source (commit) that introduced any breaking package upgrade.

I think package-lock.json changes can be quite hard to read manually, so maybe we need to look for some automation so changes can be reviewed in a concise format?

@luixxiul
Copy link
Contributor Author

luixxiul commented Oct 19, 2017

my understanding is that this actually freezes to an exact version including patch.

I understood just now what package-lock.json serves for: https://stackoverflow.com/a/44297998

Still I am not sure why #11454 (PR #11453) has happened then. If the package were not updated automatically, the tests would have not broken on Travis, haven't they?

@luixxiul luixxiul added the needs-info Another team member needs information from the PR/issue opener. label Oct 19, 2017
@evq
Copy link
Member

evq commented Oct 19, 2017

oh wow. I looked into this a little more (thanks for the stackoverflow link, found this via a comment) and it turns out there is an NPM issue discussing a change around 5.3.0 where package-lock.json wasn't pinning an exact version. A comment on that issue seems to indicate that the latest version has the behavior one would expect, namely:

If you have a package.json and you run npm i we generate a package-lock.json from it.

If you run npm i against that package.json and package-lock.json, the latter will never be updated, even if the package.json would be happy with newer versions.

If you manually edit your package.json to have different ranges and run npm i and those ranges aren't compatible with your package-lock.json then the latter will be updated with version that are compatible with your package.json. Further runs of npm i will be as with 2 above.

npm/npm#17979 (comment)

Perhaps this led to the issues you mentioned?

I just tested a clean npm install with npm 5.5.1, and there were no version changes to package-lock.json. We could set the engine version of npm in package.json to 5.5.1 or another newer version.

@luixxiul
Copy link
Contributor Author

Closing for now to see if another issue would happen after upgrading npm version.

@luixxiul luixxiul closed this Oct 29, 2017
@luixxiul luixxiul removed needs-info Another team member needs information from the PR/issue opener. PR/pending-review labels Oct 29, 2017
Copy link
Member

@bsclifton bsclifton left a comment

Choose a reason for hiding this comment

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

I think closing this is the correct action

We should always be using the package-lock.json file. We should never be removing this file... in the cases where we need to update a specific package, you can simply npm install package_name@new_version_here --save and it'll update the package, update package.json, and also update the package-lock.json

This PR wouldn't be adding any value, unfortunately. It would make a difference if folks deleted the package-lock.json when upgrading a package... but that should not be happening

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants