-
-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When set, excludes git ignored files from patch creation.
- Loading branch information
Showing
3 changed files
with
45 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import { | |
mkdirSync, | ||
unlinkSync, | ||
mkdirpSync, | ||
readFileSync, | ||
} from "fs-extra" | ||
import { sync as rimraf } from "rimraf" | ||
import { copySync } from "fs-extra" | ||
|
@@ -41,13 +42,15 @@ export function makePatch({ | |
includePaths, | ||
excludePaths, | ||
patchDir, | ||
gitignore, | ||
}: { | ||
packagePathSpecifier: string | ||
appPath: string | ||
packageManager: PackageManager | ||
includePaths: RegExp | ||
excludePaths: RegExp | ||
patchDir: string | ||
gitignore: boolean | ||
}) { | ||
const packageDetails = getPatchDetailsFromCliString(packagePathSpecifier) | ||
|
||
|
@@ -167,15 +170,40 @@ export function makePatch({ | |
|
||
// commit the package | ||
console.info(chalk.grey("•"), "Diffing your files with clean files") | ||
writeFileSync(join(tmpRepo.name, ".gitignore"), "!/node_modules\n\n") | ||
git("init") | ||
git("config", "--local", "user.name", "patch-package") | ||
git("config", "--local", "user.email", "[email protected]") | ||
|
||
if (gitignore) { | ||
// pertain project's .gitignore and .git/info/exclude | ||
// but remove ignoring node_modules/ | ||
const removeIgnoreNodeModules = (str: string): string => | ||
str.replace(/^\/node_modules\/?$\n/gm, "") | ||
const gitIgnorePath = join(appPath, ".gitignore") | ||
const gitignoreContent: string = existsSync(gitIgnorePath) | ||
? readFileSync(gitIgnorePath, { | ||
encoding: "utf-8", | ||
}) | ||
: "" | ||
const gitInfoExcludePath = join(appPath, ".git", "info", "exclude") | ||
const gitInfoExcludeContent: string = existsSync(gitInfoExcludePath) | ||
? readFileSync(gitInfoExcludePath, { encoding: "utf-8" }) | ||
: "" | ||
writeFileSync( | ||
join(tmpRepo.name, ".gitignore"), | ||
[gitInfoExcludeContent, gitignoreContent, "\n"] | ||
.map(removeIgnoreNodeModules) | ||
.join("\n"), | ||
) | ||
} | ||
|
||
// remove ignored files first | ||
removeIgnoredFiles(tmpRepoPackagePath, includePaths, excludePaths) | ||
|
||
git("add", "-f", packageDetails.path) | ||
const gitAdd = (...args: string[]) => | ||
git("add", ...[...(gitignore ? [] : ["-f"]), ...args]) | ||
|
||
gitAdd(packageDetails.path) | ||
git("commit", "--allow-empty", "-m", "init") | ||
|
||
// replace package with user's version | ||
|
@@ -192,7 +220,7 @@ export function makePatch({ | |
removeIgnoredFiles(tmpRepoPackagePath, includePaths, excludePaths) | ||
|
||
// stage all files | ||
git("add", "-f", packageDetails.path) | ||
gitAdd(packageDetails.path) | ||
|
||
// get diff of changes | ||
const diffResult = git( | ||
|