Skip to content
Merged
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"chalk": "^1.1.3",
"cross-spawn": "^5.1.0",
"fs-extra": "^4.0.1",
"klaw-sync": "^4.0.0",
"minimist": "^1.2.0",
"rimraf": "^2.6.2",
"slash": "^1.0.0",
Expand Down
49 changes: 27 additions & 22 deletions src/makePatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { getPatchFiles } from "./patchFs"
import * as fsExtra from "fs-extra"
import { PackageManager } from "./detectPackageManager"
import * as slash from "slash"
import * as klawSync from "klaw-sync"

function deleteScripts(json: any) {
delete json.scripts
Expand Down Expand Up @@ -120,42 +121,46 @@ export default function makePatch(
"!/node_modules\n\n",
)
tmpExec("git", ["init"])
// don't commit package.json though
tmpExec("git", ["add", "-f", slash(path.join("node_modules", packageName))])

tmpExec("git", ["commit", "-m", "init"])
klawSync(tmpRepoPackagePath, { nodir: true })
.map(item => item.path.slice(`${tmpRepoPackagePath}/`.length))
.filter(
relativePath =>
!relativePath.match(includePaths) || relativePath.match(excludePaths),
)
.forEach(relativePath =>
fsExtra.removeSync(slash(path.join(tmpRepoPackagePath, relativePath))),
)

tmpExec("git", ["add", "-f", slash(path.join("node_modules", packageName))])
tmpExec("git", ["commit", "--allow-empty", "-m", "init"])

// replace package with user's version
rimraf.sync(tmpRepoPackagePath)
fsExtra.copySync(packagePath, tmpRepoPackagePath, { recursive: true })

klawSync(packagePath, { nodir: true })
.map(item => item.path.slice(`${packagePath}/`.length))
.filter(
relativePath =>
relativePath.match(includePaths) && !relativePath.match(excludePaths),
)
.forEach(relativePath =>
fsExtra.copySync(
slash(path.join(packagePath, relativePath)),
slash(path.join(tmpRepoPackagePath, relativePath)),
),
)

// stage all files
tmpExec("git", ["add", "-f", slash(path.join("node_modules", packageName))])

// unstage any ignored files so they don't show up in the diff
tmpExec("git", ["diff", "--cached", "--name-only"])
.stdout.toString()
.split(/\r?\n/)
.filter(Boolean)
.forEach(fileName => {
const scopedFileName = fileName.slice(
`node_modules/${packageName}/`.length,
)
if (
!scopedFileName.match(includePaths) ||
scopedFileName.match(excludePaths)
) {
tmpExec("git", ["reset", "HEAD", fileName])
}
})

// get diff of changes
const patch = tmpExec("git", [
"diff",
"--cached",
"--no-color",
"--ignore-space-at-eol",
"--no-ext-diff"
"--no-ext-diff",
]).stdout.toString()

if (patch.trim() === "") {
Expand Down
17 changes: 17 additions & 0 deletions typings/klaw-sync.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
interface Options {
nodir?: boolean
nofile?: boolean
depthLimit?: number
fs?: object
filter?: (item: Item) => boolean
}

interface Item {
path: string
stats: object
}

declare module "klaw-sync" {
const klawSync: (dir: string, opts?: Options, ls?: Item[]) => Item[]
export = klawSync
}
6 changes: 6 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1949,6 +1949,12 @@ kind-of@^3.0.2:
dependencies:
is-buffer "^1.1.5"

klaw-sync@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/klaw-sync/-/klaw-sync-4.0.0.tgz#7785692ea1a320ac3dda7a6c0c22b33a30aa3b3f"
dependencies:
graceful-fs "^4.1.11"

latest-version@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/latest-version/-/latest-version-3.1.0.tgz#a205383fea322b33b5ae3b18abee0dc2f356ee15"
Expand Down