Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: ignore new files #404

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
11 changes: 11 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const argv = minimist(process.argv.slice(2), {
"version",
"error-on-fail",
"create-issue",
"ignore-new-files",
],
string: ["patch-dir"],
})
Expand Down Expand Up @@ -60,6 +61,7 @@ if (argv.version || argv.v) {
argv["use-yarn"] ? "yarn" : null,
)
const createIssue = argv["create-issue"]
const ignoreNewFiles = argv["ignore-new-files"]
packageNames.forEach((packagePathSpecifier: string) => {
makePatch({
packagePathSpecifier,
Expand All @@ -69,6 +71,7 @@ if (argv.version || argv.v) {
excludePaths,
patchDir,
createIssue,
ignoreNewFiles,
})
})
} else {
Expand Down Expand Up @@ -173,5 +176,13 @@ Usage:
${chalk.bold("--patch-dir")}

Specify the name for the directory in which to put the patch files.

${chalk.bold("--ignore-new-files")}

By default, patch-package includes all files present in the package
folder. If you specify this option, it will only include changes to
files that already existed in the original package. That is useful for
example if you linked the patched package with 'npm link', so it also
contains source files or build artifacts.
`)
}
10 changes: 8 additions & 2 deletions src/makePatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export function makePatch({
excludePaths,
patchDir,
createIssue,
ignoreNewFiles,
}: {
packagePathSpecifier: string
appPath: string
Expand All @@ -57,6 +58,7 @@ export function makePatch({
excludePaths: RegExp
patchDir: string
createIssue: boolean
ignoreNewFiles: boolean
}) {
const packageDetails = getPatchDetailsFromCliString(packagePathSpecifier)

Expand Down Expand Up @@ -204,8 +206,12 @@ export function makePatch({
// also remove ignored files like before
removeIgnoredFiles(tmpRepoPackagePath, includePaths, excludePaths)

// stage all files
git("add", "-f", packageDetails.path)
// stage updated/all files
if (ignoreNewFiles) {
git("add", "-f", "-u", packageDetails.path)
} else {
git("add", "-f", packageDetails.path)
}

// get diff of changes
const diffResult = git(
Expand Down