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 reading, run yarn patch-commit <patch folder>, and 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

  • lines: Array<string>
  • noNewlineAtEndOfFile: boolean
  • type: "context" | "insertion" | "deletion"

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: 2 = 2

Const DEFAULT_TIME

DEFAULT_TIME: 315532800 = 315532800

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 insetion nor deletion have the annoation

    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 insetion nor deletion have the annoation

    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

evaluateHunk

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

extractPackageToDisk

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

getPath

  • getPath(p: string): string & object

interpretParsedPatchFile

isExecutable

  • isExecutable(fileMode: number): boolean

isParentRequired

linesAreEqual

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

loadPatchFiles

makeDescriptor

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

makeLocator

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

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

trimRight

  • trimRight(s: string): string

verifyHunkIntegrity

  • verifyHunkIntegrity(hunk: Hunk): void

visitPatchPath

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

Object literals

Const hunkLinetypes

hunkLinetypes: object

: "context" = `context`

+

+: "insertion" = `insertion`

-

-: "deletion" = `deletion`

@

@: "header" = `header`

\

\: "pragma" = `pragma`

undefined

undefined: "context" = `context`

Const plugin

plugin: object

commands

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

fetchers

fetchers: PatchFetcher[] = [PatchFetcher,]

resolvers

resolvers: PatchResolver[] = [PatchResolver,]

Generated using TypeDoc