Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
},
"dependencies": {
"@yarnpkg/lockfile": "^1.1.0",
"chalk": "^4.1.2",
"picocolors": "^1.1.1",
"ci-info": "^3.7.0",
"cross-spawn": "^7.0.3",
"find-yarn-workspace-root": "^2.0.0",
Expand Down
56 changes: 28 additions & 28 deletions src/applyPatches.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import chalk from "chalk"
import pc from "picocolors"
import { writeFileSync } from "fs"
import { existsSync } from "fs-extra"
import { posix } from "path"
Expand Down Expand Up @@ -45,7 +45,7 @@ function getInstalledPackageVersion({
}

let err =
`${chalk.red("Error:")} Patch file found for package ${posix.basename(
`${pc.red("Error:")} Patch file found for package ${posix.basename(
pathSpecifier,
)}` + ` which is not present at ${relative(".", packageDir)}`

Expand All @@ -54,7 +54,7 @@ function getInstalledPackageVersion({

If this package is a dev dependency, rename the patch file to

${chalk.bold(patchFilename.replace(".patch", ".dev.patch"))}
${pc.bold(patchFilename.replace(".patch", ".dev.patch"))}
`
}
throw new PatchApplicationError(err)
Expand All @@ -65,7 +65,7 @@ function getInstalledPackageVersion({
const result = semver.valid(version)
if (result === null) {
throw new PatchApplicationError(
`${chalk.red(
`${pc.red(
"Error:",
)} Version string '${version}' cannot be parsed from ${join(
packageDir,
Expand All @@ -85,9 +85,9 @@ function logPatchApplication(patchDetails: PatchedPackageDetails) {
})`
: ""
console.log(
`${chalk.bold(patchDetails.pathSpecifier)}@${
`${pc.bold(patchDetails.pathSpecifier)}@${
patchDetails.version
}${sequenceString} ${chalk.green("✔")}`,
}${sequenceString} ${pc.green("✔")}`,
)
}

Expand All @@ -110,7 +110,7 @@ export function applyPatchesForApp({
const groupedPatches = getGroupedPatches(patchesDirectory)

if (groupedPatches.numPatchFiles === 0) {
console.log(chalk.blueBright("No patch files found"))
console.log(pc.blueBright("No patch files found"))
return
}

Expand Down Expand Up @@ -140,10 +140,10 @@ export function applyPatchesForApp({

const problemsSummary = []
if (warnings.length) {
problemsSummary.push(chalk.yellow(`${warnings.length} warning(s)`))
problemsSummary.push(pc.yellow(`${warnings.length} warning(s)`))
}
if (errors.length) {
problemsSummary.push(chalk.red(`${errors.length} error(s)`))
problemsSummary.push(pc.red(`${errors.length} error(s)`))
}

if (problemsSummary.length) {
Expand Down Expand Up @@ -201,8 +201,8 @@ export function applyPatchesForPackage({
appliedPatches.push(unappliedPatches.shift()!)
} else {
console.log(
chalk.red("Error:"),
`The patches for ${chalk.bold(pathSpecifier)} have changed.`,
pc.red("Error:"),
`The patches for ${pc.bold(pathSpecifier)} have changed.`,
`You should reinstall your node_modules folder to make sure the package is up to date`,
)
process.exit(1)
Expand Down Expand Up @@ -249,9 +249,9 @@ export function applyPatchesForPackage({
if (!installedPackageVersion) {
// it's ok we're in production mode and this is a dev only package
console.log(
`Skipping dev-only ${chalk.bold(
pathSpecifier,
)}@${version} ${chalk.blue("✔")}`,
`Skipping dev-only ${pc.bold(pathSpecifier)}@${version} ${pc.blue(
"✔",
)}`,
)
continue
}
Expand Down Expand Up @@ -429,7 +429,7 @@ export function applyPatch({
if (errors?.length) {
console.log(
"Saving errors to",
chalk.cyan.bold("./patch-package-errors.log"),
pc.cyan(pc.bold("./patch-package-errors.log")),
)
writeFileSync("patch-package-errors.log", errors.join("\n\n"))
process.exit(0)
Expand Down Expand Up @@ -464,18 +464,18 @@ function createVersionMismatchWarning({
path: string
}) {
return `
${chalk.yellow("Warning:")} patch-package detected a patch file version mismatch
${pc.yellow("Warning:")} patch-package detected a patch file version mismatch

Don't worry! This is probably fine. The patch was still applied
successfully. Here's the deets:

Patch file created for

${packageName}@${chalk.bold(originalVersion)}
${packageName}@${pc.bold(originalVersion)}

applied to

${packageName}@${chalk.bold(actualVersion)}
${packageName}@${pc.bold(actualVersion)}

At path

Expand All @@ -485,7 +485,7 @@ ${chalk.yellow("Warning:")} patch-package detected a patch file version mismatch
breakage even though the patch was applied successfully. Make sure the package
still behaves like you expect (you wrote tests, right?) and then run

${chalk.bold(`patch-package ${pathSpecifier}`)}
${pc.bold(`patch-package ${pathSpecifier}`)}

to update the version in the patch file name and make this warning go away.
`
Expand All @@ -503,8 +503,8 @@ function createBrokenPatchFileError({
pathSpecifier: string
}) {
return `
${chalk.red.bold("**ERROR**")} ${chalk.red(
`Failed to apply patch for package ${chalk.bold(packageName)} at path`,
${pc.red(pc.bold("**ERROR**"))} ${pc.red(
`Failed to apply patch for package ${pc.bold(packageName)} at path`,
)}

${path}
Expand Down Expand Up @@ -543,13 +543,13 @@ function createPatchApplicationFailureError({
pathSpecifier: string
}) {
return `
${chalk.red.bold("**ERROR**")} ${chalk.red(
`Failed to apply patch for package ${chalk.bold(packageName)} at path`,
${pc.red(pc.bold("**ERROR**"))} ${pc.red(
`Failed to apply patch for package ${pc.bold(packageName)} at path`,
)}

${path}

This error was caused because ${chalk.bold(packageName)} has changed since you
This error was caused because ${pc.bold(packageName)} has changed since you
made the patch file for it. This introduced conflicts with your patch,
just like a merge conflict in Git when separate incompatible changes are
made to the same piece of code.
Expand All @@ -568,8 +568,8 @@ ${chalk.red.bold("**ERROR**")} ${chalk.red(

Info:
Patch file: patches/${patchFilename}
Patch was made for version: ${chalk.green.bold(originalVersion)}
Installed version: ${chalk.red.bold(actualVersion)}
Patch was made for version: ${pc.green(pc.bold(originalVersion))}
Installed version: ${pc.red(pc.bold(actualVersion))}
`
}

Expand All @@ -581,8 +581,8 @@ function createUnexpectedError({
error: Error
}) {
return `
${chalk.red.bold("**ERROR**")} ${chalk.red(
`Failed to apply patch file ${chalk.bold(filename)}`,
${pc.red(pc.bold("**ERROR**"))} ${pc.red(
`Failed to apply patch file ${pc.bold(filename)}`,
)}

${error.stack}
Expand Down
4 changes: 2 additions & 2 deletions src/createIssue.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import chalk from "chalk"
import pc from "picocolors"
import open from "open"
import { stringify } from "querystring"
import { PackageManager } from "./detectPackageManager"
Expand Down Expand Up @@ -105,7 +105,7 @@ export function maybePrintIssueCreationPrompt(
packageManager: PackageManager,
) {
if (vcs) {
console.log(`💡 ${chalk.bold(packageDetails.name)} is on ${
console.log(`💡 ${pc.bold(packageDetails.name)} is on ${
vcs.provider
}! To draft an issue based on your patch run

Expand Down
12 changes: 5 additions & 7 deletions src/detectPackageManager.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import fs from "fs-extra"
import { join } from "./path"
import chalk from "chalk"
import pc from "picocolors"
import process from "process"
import findWorkspaceRoot from "find-yarn-workspace-root"

export type PackageManager = "yarn" | "npm" | "npm-shrinkwrap"

function printNoYarnLockfileError() {
console.log(`
${chalk.red.bold("**ERROR**")} ${chalk.red(
${pc.red(pc.bold("**ERROR**"))} ${pc.red(
`The --use-yarn option was specified but there is no yarn.lock file`,
)}
`)
}

function printNoLockfilesError() {
console.log(`
${chalk.red.bold("**ERROR**")} ${chalk.red(
${pc.red(pc.bold("**ERROR**"))} ${pc.red(
`No package-lock.json, npm-shrinkwrap.json, or yarn.lock file.

You must use either npm@>=5, yarn, or npm-shrinkwrap to manage this project's
Expand All @@ -27,10 +27,8 @@ dependencies.`,

function printSelectingDefaultMessage() {
console.info(
`${chalk.bold(
"patch-package",
)}: you have both yarn.lock and package-lock.json
Defaulting to using ${chalk.bold("npm")}
`${pc.bold("patch-package")}: you have both yarn.lock and package-lock.json
Defaulting to using ${pc.bold("npm")}
You can override this setting by passing --use-yarn or deleting
package-lock.json if you don't need it
`,
Expand Down
38 changes: 18 additions & 20 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import chalk from "chalk"
import pc from "picocolors"
import process from "process"
import minimist from "minimist"

Expand Down Expand Up @@ -32,7 +32,7 @@ const argv = minimist(process.argv.slice(2), {
const packageNames = argv._

console.log(
chalk.bold("patch-package"),
pc.bold("patch-package"),
// tslint:disable-next-line:no-var-requires
require(join(__dirname, "../package.json")).version,
)
Expand All @@ -49,15 +49,15 @@ if (argv.version || argv.v) {
if ("rebase" in argv) {
if (!argv.rebase) {
console.log(
chalk.red(
pc.red(
"You must specify a patch file name or number when rebasing patches",
),
)
process.exit(1)
}
if (packageNames.length !== 1) {
console.log(
chalk.red(
pc.red(
"You must specify exactly one package name when rebasing patches",
),
)
Expand Down Expand Up @@ -133,9 +133,9 @@ Usage:
1. Patching packages
====================

${chalk.bold("patch-package")}
${pc.bold("patch-package")}

Without arguments, the ${chalk.bold(
Without arguments, the ${pc.bold(
"patch-package",
)} command will attempt to find and apply
patch files to your project. It looks for files named like
Expand All @@ -144,11 +144,11 @@ Usage:

Options:

${chalk.bold("--patch-dir <dirname>")}
${pc.bold("--patch-dir <dirname>")}

Specify the name for the directory in which the patch files are located.

${chalk.bold("--error-on-fail")}
${pc.bold("--error-on-fail")}

Forces patch-package to exit with code 1 after failing.

Expand All @@ -157,17 +157,17 @@ Usage:
yarn.lock and package.json might get out of sync with node_modules,
which can be very confusing.

--error-on-fail is ${chalk.bold("switched on")} by default on CI.
--error-on-fail is ${pc.bold("switched on")} by default on CI.

See https://github.com/ds300/patch-package/issues/86 for background.

${chalk.bold("--error-on-warn")}
${pc.bold("--error-on-warn")}

Forces patch-package to exit with code 1 after warning.

See https://github.com/ds300/patch-package/issues/314 for background.

${chalk.bold("--reverse")}
${pc.bold("--reverse")}

Un-applies all patches.

Expand All @@ -182,45 +182,43 @@ Usage:
2. Creating patch files
=======================

${chalk.bold("patch-package")} <package-name>${chalk.italic(
"[ <package-name>]",
)}
${pc.bold("patch-package")} <package-name>${pc.italic("[ <package-name>]")}

When given package names as arguments, patch-package will create patch files
based on any changes you've made to the versions installed by yarn/npm.

Options:

${chalk.bold("--create-issue")}
${pc.bold("--create-issue")}

For packages whose source is hosted on GitHub this option opens a web
browser with a draft issue based on your diff.

${chalk.bold("--use-yarn")}
${pc.bold("--use-yarn")}

By default, patch-package checks whether you use npm or yarn based on
which lockfile you have. If you have both, it uses npm by default.
Set this option to override that default and always use yarn.

${chalk.bold("--exclude <regexp>")}
${pc.bold("--exclude <regexp>")}

Ignore paths matching the regexp when creating patch files.
Paths are relative to the root dir of the package to be patched.

Default: 'package\\.json$'

${chalk.bold("--include <regexp>")}
${pc.bold("--include <regexp>")}

Only consider paths matching the regexp when creating patch files.
Paths are relative to the root dir of the package to be patched.

Default '.*'

${chalk.bold("--case-sensitive-path-filtering")}
${pc.bold("--case-sensitive-path-filtering")}

Make regexps used in --include or --exclude filters case-sensitive.

${chalk.bold("--patch-dir")}
${pc.bold("--patch-dir")}

Specify the name for the directory in which to put the patch files.
`)
Expand Down
Loading