Skip to content

[Feature] Reference a PR via URL to create Patch #15

@D1no

Description

@D1no

The list of outstanding PRs in react-native and the react community is long. It would be great, if we could add links to those PRs i.e. inside the package json, so the PR is applied automatically.

As an interface we could simply add them to the package.json

Proposal

By simply applying .patch or .diff to a github PR, a full fledge patch is provided. This would make patching much simpler.

Try it out:
Pull Request: facebook/react-native#12807
Pull Request as Patch: https://github.com/facebook/react-native/pull/12807.patch

To manage this centrally, we could just use the package.json:

// pacakge.json
{
  "name": "name",
  "version": "1.0.0",
  "dependencies": {
    "react": "16.0.0-alpha.12",
    "react-native": "^0.47.2",
    "react-native-scandit": "^1.1.7",
    "styled-components": "^2.1.2",
    "patch-package": "X.XX"
  },

// New Property for patch-package
  "patch-package": {
    "react-native": [
      {
        // Link to PR. Most cases, all what is needed.
        "pullRequest": "https://github.com/facebook/react-native/pull/12807",
        // Optional. Default is head. Leads to: https://github.com/facebook/react-native/pull/12807/commits/1a44b86e4af6dbb62819348cd963ffa6a443f32e
        "commit": "1a44b86e4af6dbb62819348cd963ffa6a443f32e", 
        // Optional. Restrict to specific package version or version range
        "version": "^0.47.2",
        // Optional. In case the package to be patched is in a subfolder of the repository
        "fromBaseFolder": ".", 
        // Optional. In case the folder we want to patch is called differently in the npm distribution, due to some build script
        "targetBaseFolder": ".", 
        // Optional. Restrict the scope of the applied patch
        "restrictChangesToPathFromBaseFolder": [
          "ReactAndroid/src/main/java/com/facebook/react/uimanager",
          "ReactAndroid/src/main/java/com/facebook/react/views/webview"
        ] 
      },
      // next patch in array for react-native
      {} 
    ]
  },
// End new Property

The patch file follows all the commits in the subject line. So to limit a patch up until a specific point, simply truncate it after the last wanted SHA. I.e. sometimes PRs are merged so late, that they are adapted to a new published version we not yet use.

screen shot 2017-09-11 at 10 45 09

Relevance

patch-package is necessary. The maintainers can just not follow up. However, this is an even stronger incentive to create private hacks because patches are difficult to share. By allowing a "simple" reference to a PR, the community is incentivised to make at least a PR to the upstream package and reference that PR them self as an easier way of patching until it is merged.

Btw: This approach has the nice side effect, that testing PRs becomes dump easy for novices. Up on problems, people will report back/complain to the PR, enforcing quality and bringing less garbage PRs inside a repo!

Prior to patch package, we applied a few patches with the vanilla bash commands via a post install script. Not ideal.

And I said it before. Love your sharp mind in all this.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions