Options
All
  • Public
  • Public/Protected
  • All
Menu

Package plugin-patch

@yarnpkg/plugin-patch

This plugin adds support for the patch: protocol.

Install

This plugin is included by default in Yarn.

Usage

  1. Run yarn patch <package name> and edit the resulting folder.

  2. Once you're ready, run yarn patch-commit -s <patch folder> to store the result inside a .patch file.

  3. Add the patch: protocol to your dependencies as such:

{
  "dependencies": {
    "lodash": "patch:lodash@1.0.0#./my-patch-file.patch"
  }
}

Caveat

You cannot add dependencies through the patch: protocol. Check this FAQ entry for more details.

Type aliases

FileCreation

FileCreation: object

Type declaration

  • hash: string | null
  • hunk: Hunk | null
  • mode: FileMode
  • path: PortablePath
  • semverExclusivity: string | null
  • type: "file creation"

FileDeets

FileDeets: object

Type declaration

  • afterHash: string | null
  • beforeHash: string | null
  • deletedFileMode: string | null
  • diffLineFromPath: string | null
  • diffLineToPath: string | null
  • fromPath: string | null
  • hunks: Array<Hunk> | null
  • newFileMode: string | null
  • newMode: string | null
  • oldMode: string | null
  • renameFrom: string | null
  • renameTo: string | null
  • semverExclusivity: string | null
  • toPath: string | null

FileDeletion

FileDeletion: object

Type declaration

  • hash: string | null
  • hunk: Hunk | null
  • mode: FileMode
  • path: PortablePath
  • semverExclusivity: string | null
  • type: "file deletion"

FileMode

FileMode: typeof NON_EXECUTABLE_FILE_MODE | typeof EXECUTABLE_FILE_MODE

FileModeChange

FileModeChange: object

Type declaration

FilePatch

FilePatch: object

Type declaration

  • afterHash: string | null
  • beforeHash: string | null
  • hunks: Array<Hunk>
  • path: PortablePath
  • semverExclusivity: string | null
  • type: "patch"

FileRename

FileRename: object

Type declaration

Hunk

Hunk: object

Type declaration

HunkHeader

HunkHeader: object

Type declaration

  • original: object
    • length: number
    • start: number
  • patched: object
    • length: number
    • start: number

Modification

Modification: Push | Pop | Splice

ParsedPatchFile

ParsedPatchFile: Array<PatchFilePart>

PatchFilePart

PatchMutationPart

PatchMutationPart: object

Type declaration

Pop

Pop: object

Type declaration

  • type: "pop"

Push

Push: object

Type declaration

  • line: string
  • type: "push"

Splice

Splice: object

Type declaration

  • index: number
  • linesToInsert: Array<string>
  • numToDelete: number
  • type: "splice"

State

State: "parsing header" | "parsing hunks"

VisitPatchPathOptions

VisitPatchPathOptions<T>: object

Type parameters

  • T

Type declaration

Variables

Const BUILTIN_REGEXP

BUILTIN_REGEXP: RegExp = /^builtin<([^>]+)>$/

Const CACHE_VERSION

CACHE_VERSION: 3 = 3

Const EXECUTABLE_FILE_MODE

EXECUTABLE_FILE_MODE: 493 = 493

Const HEADER_REGEXP

HEADER_REGEXP: RegExp = /^@@ -(\d+)(,(\d+))? \+(\d+)(,(\d+))? @@.*/

Const NON_EXECUTABLE_FILE_MODE

NON_EXECUTABLE_FILE_MODE: 420 = 420

Const accidentalBlankLine

accidentalBlankLine: "diff --git a/banana.ts b/banana.tsindex 2de83dd..842652c 100644--- a/banana.ts+++ b/banana.ts@@ -1,5 +1,5 @@thisis-a+file" = `diff --git a/banana.ts b/banana.tsindex 2de83dd..842652c 100644--- a/banana.ts+++ b/banana.ts@@ -1,5 +1,5 @@thisis-a+file`

Const crlfLineBreaks

crlfLineBreaks: string = `diff --git a/banana.ts b/banana.tsnew file mode 100644index 0000000..3e1267f--- /dev/null+++ b/banana.ts@@ -0,0 +1 @@+this is a new file`.replace(/\n/g, `\r\n`)

Const invalidHeaders1

invalidHeaders1: "diff --git a/banana.ts b/banana.tsindex 2de83dd..842652c 100644--- a/banana.ts+++ b/banana.ts@@ -1,5 +1,4 @@thisis-a+file" = `diff --git a/banana.ts b/banana.tsindex 2de83dd..842652c 100644--- a/banana.ts+++ b/banana.ts@@ -1,5 +1,4 @@thisis-a+file`

Const invalidHeaders2

invalidHeaders2: "diff --git a/banana.ts b/banana.tsindex 2de83dd..842652c 100644--- a/banana.ts+++ b/banana.ts@@ -1,4 +1,5 @@thisis-a+file" = `diff --git a/banana.ts b/banana.tsindex 2de83dd..842652c 100644--- a/banana.ts+++ b/banana.ts@@ -1,4 +1,5 @@thisis-a+file`

Const invalidHeaders3

invalidHeaders3: "diff --git a/banana.ts b/banana.tsindex 2de83dd..842652c 100644--- a/banana.ts+++ b/banana.ts@@ -1,0 +1,5 @@thisis-a+file" = `diff --git a/banana.ts b/banana.tsindex 2de83dd..842652c 100644--- a/banana.ts+++ b/banana.ts@@ -1,0 +1,5 @@thisis-a+file`

Const invalidHeaders4

invalidHeaders4: "diff --git a/banana.ts b/banana.tsindex 2de83dd..842652c 100644--- a/banana.ts+++ b/banana.ts@@ -1,5 +1,0 @@thisis-a+file" = `diff --git a/banana.ts b/banana.tsindex 2de83dd..842652c 100644--- a/banana.ts+++ b/banana.ts@@ -1,5 +1,0 @@thisis-a+file`

Const invalidHeaders5

invalidHeaders5: "diff --git a/banana.ts b/banana.tsindex 2de83dd..842652c 100644--- a/banana.ts+++ b/banana.ts@@ -1,5 +1,5@@thisis-a+file" = `diff --git a/banana.ts b/banana.tsindex 2de83dd..842652c 100644--- a/banana.ts+++ b/banana.ts@@ -1,5 +1,5@@thisis-a+file`

Const modeChangeAndModifyAndRename

modeChangeAndModifyAndRename: "diff --git a/numbers.txt b/banana.txtold mode 100644new mode 100755similarity index 96%rename from numbers.txtrename to banana.txtindex fbf1785..92d2c5f--- a/numbers.txt+++ b/banana.txt@@ -1,4 +1,4 @@-one+netwo" = `diff --git a/numbers.txt b/banana.txtold mode 100644new mode 100755similarity index 96%rename from numbers.txtrename to banana.txtindex fbf1785..92d2c5f--- a/numbers.txt+++ b/banana.txt@@ -1,4 +1,4 @@-one+netwo`

Const patch

patch: "diff --git a/banana.ts b/banana.tsindex 2de83dd..842652c 100644--- a/banana.ts+++ b/banana.ts@@ -1,5 +1,5 @@thisis-a+file" = `diff --git a/banana.ts b/banana.tsindex 2de83dd..842652c 100644--- a/banana.ts+++ b/banana.ts@@ -1,5 +1,5 @@thisis-a+file`

Functions

applyPatch

  • applyPatch(__namedParameters: object, __namedParameters: object): Promise<void>
  • How does noNewLineAtEndOfFile work?

    if you remove the newline from a file that had one without editing other bits:

    it creates an insertion/removal pair where the insertion has \ No new line at end of file

    if you edit a file that didn't have a new line and don't add one:

    both insertion and deletion have \ No new line at end of file

    if you edit a file that didn't have a new line and add one:

    deletion has \ No new line at end of file but not insertion

    if you edit a file that had a new line and leave it in:

    neither insertion nor deletion have the annotation

    if you remove the newline from a file that had one without editing other bits:

    it creates an insertion/removal pair where the insertion has \ No new line at end of file

    if you edit a file that didn't have a new line and don't add one:

    both insertion and deletion have \ No new line at end of file

    if you edit a file that didn't have a new line and add one:

    deletion has \ No new line at end of file but not insertion

    if you edit a file that had a new line and leave it in:

    neither insertion nor deletion have the annotation

    Parameters

    • __namedParameters: object
      • hunks: object[]
      • path: string & object
    • __namedParameters: object
      • baseFs: FakeFS<string & object>
      • dryRun: boolean

    Returns Promise<void>

applyPatchFile

  • applyPatchFile(effects: ParsedPatchFile, __namedParameters?: object): Promise<void>

diffFolders

Const emptyFilePatch

Const emptyHunk

  • emptyHunk(headerLine: string): Hunk

ensureUnpatchedDescriptor

ensureUnpatchedLocator

evaluateHunk

  • evaluateHunk(hunk: Hunk, fileLines: Array<string>, offset: number): Array<Modification> | null

extractPackageToDisk

  • extractPackageToDisk(locator: Locator, __namedParameters: object): Promise<string & object>

extractPatchFlags

getPath

  • getPath(p: string): string & object

interpretParsedPatchFile

isExecutable

  • isExecutable(fileMode: number): boolean

isParentRequired

isPatchDescriptor

  • isPatchDescriptor(descriptor: Descriptor): boolean

isPatchLocator

  • isPatchLocator(locator: Locator): boolean

linesAreEqual

  • linesAreEqual(a: string, b: string): boolean

loadPatchFiles

makeDescriptor

makeLocator

  • makeLocator(ident: Ident, __namedParameters: object): Locator

makePatchHash

  • makePatchHash(patchFiles: Array<object>, sourceVersion: string | null): string

makeSpec

  • makeSpec<T>(__namedParameters: object, sourceStringifier: function): string
  • Type parameters

    • T

    Parameters

    • __namedParameters: object
      • parentLocator: null | Locator
      • patchHash: undefined | string
      • patchPaths: (string & object)[]
      • sourceItem: T
      • sourceVersion: undefined | null | string
    • sourceStringifier: function
        • (source: T): string
        • Parameters

          • source: T

          Returns string

    Returns string

parseDescriptor

parseFileMode

parseHunkHeaderLine

  • parseHunkHeaderLine(headerLine: string): HunkHeader

parseLocator

  • parseLocator(locator: Locator): object

parsePatchFile

parsePatchLines

  • parsePatchLines(lines: Array<string>): object[]

parseSpec

  • parseSpec<T>(spec: string, sourceParser: function): object
  • Type parameters

    • T

    Parameters

    • spec: string
    • sourceParser: function
        • (source: string): T
        • Parameters

          • source: string

          Returns T

    Returns object

    • parentLocator: null | Locator
    • patchPaths: (string & object)[]
    • sourceItem: T
    • sourceVersion: null | string

preserveTime

reportHunk

  • reportHunk(hunk: Hunk, __namedParameters: object): void

trimRight

  • trimRight(s: string): string

unpatchDescriptor

unpatchLocator

verifyHunkIntegrity

  • verifyHunkIntegrity(hunk: Hunk): void

visitPatchPath

  • visitPatchPath<T>(__namedParameters: object, patchPath: PortablePath): T

Object literals

Const hunkLinetypes

hunkLinetypes: object

: Context = PatchMutationType.Context

+

+: Insertion = PatchMutationType.Insertion

-

-: Deletion = PatchMutationType.Deletion

@

@: "header" = `header`

\

\: "pragma" = `pragma`

undefined

undefined: Context = PatchMutationType.Context

Const plugin

plugin: object

commands

commands: (PatchCommitCommand | PatchCommand)[] = [PatchCommitCommand,PatchCommand,]

fetchers

fetchers: PatchFetcher[] = [PatchFetcher,]

resolvers

resolvers: PatchResolver[] = [PatchResolver,]

configuration

configuration: object

enableInlineHunks

enableInlineHunks: object

default

default: boolean = false

description

description: string = `If true, the installs will print unmatched patch hunks`

type

type: BOOLEAN = SettingsType.BOOLEAN

patchFolder

patchFolder: object

default

default: string = `./.yarn/patches`

description

description: string = `Folder where the patch files must be written`

type

type: ABSOLUTE_PATH = SettingsType.ABSOLUTE_PATH

Generated using TypeDoc