@changesets/git
Advanced tools
Comparing version 1.0.4 to 1.0.5
# @changesets/git | ||
## 1.0.5 | ||
### Patch Changes | ||
- [`89f0c49`](https://github.com/atlassian/changesets/commit/89f0c497ac21b8d008da67caff8032947836c7b1) [#352](https://github.com/atlassian/changesets/pull/352) Thanks [@MichaelKapustey](https://github.com/MichaelKapustey)! - Previously packages nested inside of other packages would show both the nested package and the outer package as changed. Now, only the nested package will show as changed. | ||
* [`09f62f9`](https://github.com/atlassian/changesets/commit/09f62f9c822f31899a48cbd93c7801d72a80b97e) [#355](https://github.com/atlassian/changesets/pull/355) Thanks [@acheronfail](https://github.com/acheronfail)! - Fix an issue where refs that didn't exist were silently ignored | ||
* Updated dependencies [[`2b49d66`](https://github.com/atlassian/changesets/commit/2b49d668ecaa1333bc5c7c5be4648dda1b11528d)]: | ||
- @changesets/types@3.0.0 | ||
## 1.0.4 | ||
@@ -4,0 +15,0 @@ |
@@ -0,1 +1,2 @@ | ||
import { Package } from "@manypkg/get-packages"; | ||
declare function add(pathToFile: string, cwd: string): Promise<boolean>; | ||
@@ -18,3 +19,3 @@ declare function commit(message: string, cwd: string): Promise<boolean>; | ||
ref: string; | ||
}): Promise<import("@manypkg/get-packages").Package[]>; | ||
}): Promise<Package[]>; | ||
export { getCommitThatAddsFile, getChangedFilesSince, add, commit, tag, getChangedPackagesSinceRef, getChangedChangesetFilesSinceRef }; |
@@ -13,2 +13,4 @@ 'use strict'; | ||
const isInDir = dir => subdir => isSubdir(dir, subdir); | ||
async function add(pathToFile, cwd) { | ||
@@ -41,9 +43,14 @@ const gitCmd = await spawn("git", ["add", pathToFile], { | ||
return gitCmd.code === 0; | ||
} | ||
} // Find the commit where we diverged from `ref` at using `git merge-base` | ||
async function getDivergedCommit(cwd, ref) { | ||
// First we need to find the commit where we diverged from `ref` at using `git merge-base` | ||
const cmd = await spawn("git", ["merge-base", ref, "HEAD"], { | ||
cwd | ||
}); | ||
if (cmd.code !== 0) { | ||
throw new Error(`Failed to find where HEAD diverged from ${ref}. Does ${ref} exist?`); | ||
} | ||
return cmd.stdout.toString().trim(); | ||
@@ -69,2 +76,7 @@ } | ||
}); | ||
if (cmd.code !== 0) { | ||
throw new Error(`Failed to diff against ${divergedAt}. Is ${divergedAt} a valid ref?`); | ||
} | ||
const files = cmd.stdout.toString().trim().split("\n"); | ||
@@ -105,9 +117,10 @@ if (!fullPath) return files; | ||
let packages = await getPackages.getPackages(cwd); | ||
const fileNameToPackage = fileName => packages.packages.find(pkg => isSubdir(pkg.dir, fileName)); | ||
const fileExistsInPackage = fileName => !!fileNameToPackage(fileName); | ||
return changedFiles // ignore deleted files | ||
.filter(fileExistsInPackage).map(fileNameToPackage) // filter, so that we have only unique packages | ||
const fileToPackage = {}; | ||
packages.packages.forEach(pkg => changedFiles.filter(isInDir(pkg.dir)).forEach(fileName => { | ||
const prevPkg = fileToPackage[fileName] || { | ||
dir: "" | ||
}; | ||
if (pkg.dir.length > prevPkg.dir.length) fileToPackage[fileName] = pkg; | ||
})); | ||
return Object.values(fileToPackage) // filter, so that we have only unique packages | ||
.filter((pkg, idx, packages) => packages.indexOf(pkg) === idx); | ||
@@ -114,0 +127,0 @@ } |
@@ -13,2 +13,4 @@ "use strict"; | ||
const isInDir = dir => subdir => isSubdir(dir, subdir); | ||
async function add(pathToFile, cwd) { | ||
@@ -34,5 +36,7 @@ const gitCmd = await spawn("git", [ "add", pathToFile ], { | ||
async function getDivergedCommit(cwd, ref) { | ||
return (await spawn("git", [ "merge-base", ref, "HEAD" ], { | ||
const cmd = await spawn("git", [ "merge-base", ref, "HEAD" ], { | ||
cwd: cwd | ||
})).stdout.toString().trim(); | ||
}); | ||
if (0 !== cmd.code) throw new Error(`Failed to find where HEAD diverged from ${ref}. Does ${ref} exist?`); | ||
return cmd.stdout.toString().trim(); | ||
} | ||
@@ -47,5 +51,7 @@ | ||
async function getChangedFilesSince({cwd: cwd, ref: ref, fullPath: fullPath = !1}) { | ||
const divergedAt = await getDivergedCommit(cwd, ref), files = (await spawn("git", [ "diff", "--name-only", divergedAt ], { | ||
const divergedAt = await getDivergedCommit(cwd, ref), cmd = await spawn("git", [ "diff", "--name-only", divergedAt ], { | ||
cwd: cwd | ||
})).stdout.toString().trim().split("\n"); | ||
}); | ||
if (0 !== cmd.code) throw new Error(`Failed to diff against ${divergedAt}. Is ${divergedAt} a valid ref?`); | ||
const files = cmd.stdout.toString().trim().split("\n"); | ||
return fullPath ? files.map(file => path.resolve(cwd, file)) : files; | ||
@@ -74,4 +80,12 @@ } | ||
let packages = await getPackages.getPackages(cwd); | ||
const fileNameToPackage = fileName => packages.packages.find(pkg => isSubdir(pkg.dir, fileName)); | ||
return changedFiles.filter(fileName => !!fileNameToPackage(fileName)).map(fileNameToPackage).filter((pkg, idx, packages) => packages.indexOf(pkg) === idx); | ||
const fileToPackage = {}; | ||
return packages.packages.forEach(pkg => { | ||
return changedFiles.filter((dir = pkg.dir, subdir => isSubdir(dir, subdir))).forEach(fileName => { | ||
const prevPkg = fileToPackage[fileName] || { | ||
dir: "" | ||
}; | ||
pkg.dir.length > prevPkg.dir.length && (fileToPackage[fileName] = pkg); | ||
}); | ||
var dir; | ||
}), Object.values(fileToPackage).filter((pkg, idx, packages) => packages.indexOf(pkg) === idx); | ||
} | ||
@@ -78,0 +92,0 @@ |
@@ -7,2 +7,4 @@ import spawn from 'spawndamnit'; | ||
const isInDir = dir => subdir => isSubdir(dir, subdir); | ||
async function add(pathToFile, cwd) { | ||
@@ -35,9 +37,14 @@ const gitCmd = await spawn("git", ["add", pathToFile], { | ||
return gitCmd.code === 0; | ||
} | ||
} // Find the commit where we diverged from `ref` at using `git merge-base` | ||
async function getDivergedCommit(cwd, ref) { | ||
// First we need to find the commit where we diverged from `ref` at using `git merge-base` | ||
const cmd = await spawn("git", ["merge-base", ref, "HEAD"], { | ||
cwd | ||
}); | ||
if (cmd.code !== 0) { | ||
throw new Error(`Failed to find where HEAD diverged from ${ref}. Does ${ref} exist?`); | ||
} | ||
return cmd.stdout.toString().trim(); | ||
@@ -63,2 +70,7 @@ } | ||
}); | ||
if (cmd.code !== 0) { | ||
throw new Error(`Failed to diff against ${divergedAt}. Is ${divergedAt} a valid ref?`); | ||
} | ||
const files = cmd.stdout.toString().trim().split("\n"); | ||
@@ -99,9 +111,10 @@ if (!fullPath) return files; | ||
let packages = await getPackages(cwd); | ||
const fileNameToPackage = fileName => packages.packages.find(pkg => isSubdir(pkg.dir, fileName)); | ||
const fileExistsInPackage = fileName => !!fileNameToPackage(fileName); | ||
return changedFiles // ignore deleted files | ||
.filter(fileExistsInPackage).map(fileNameToPackage) // filter, so that we have only unique packages | ||
const fileToPackage = {}; | ||
packages.packages.forEach(pkg => changedFiles.filter(isInDir(pkg.dir)).forEach(fileName => { | ||
const prevPkg = fileToPackage[fileName] || { | ||
dir: "" | ||
}; | ||
if (pkg.dir.length > prevPkg.dir.length) fileToPackage[fileName] = pkg; | ||
})); | ||
return Object.values(fileToPackage) // filter, so that we have only unique packages | ||
.filter((pkg, idx, packages) => packages.indexOf(pkg) === idx); | ||
@@ -108,0 +121,0 @@ } |
{ | ||
"name": "@changesets/git", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "Some git helpers that changesets use to get information", | ||
@@ -12,3 +12,3 @@ "main": "dist/git.cjs.js", | ||
"@changesets/errors": "^0.1.4", | ||
"@changesets/types": "^2.0.1", | ||
"@changesets/types": "^3.0.0", | ||
"@manypkg/get-packages": "^1.0.1", | ||
@@ -15,0 +15,0 @@ "is-subdir": "^1.1.1", |
@@ -118,7 +118,9 @@ import fixtures from "fixturez"; | ||
expect(stagedFiles).toHaveLength(4); | ||
expect(stagedFiles[0]).toEqual("packages/pkg-a/index.js"); | ||
expect(stagedFiles[1]).toEqual("packages/pkg-a/package.json"); | ||
expect(stagedFiles[2]).toEqual("packages/pkg-b/index.js"); | ||
expect(stagedFiles[3]).toEqual("packages/pkg-b/package.json"); | ||
expect(stagedFiles).toEqual([ | ||
"packages/package.json", | ||
"packages/pkg-a/index.js", | ||
"packages/pkg-a/package.json", | ||
"packages/pkg-b/index.js", | ||
"packages/pkg-b/package.json" | ||
]); | ||
}); | ||
@@ -125,0 +127,0 @@ }); |
import spawn from "spawndamnit"; | ||
import path from "path"; | ||
import { getPackages } from "@manypkg/get-packages"; | ||
import { getPackages, Package } from "@manypkg/get-packages"; | ||
import { GitError } from "@changesets/errors"; | ||
import isSubdir from "is-subdir"; | ||
const isInDir = (dir: string) => (subdir: string) => isSubdir(dir, subdir); | ||
async function add(pathToFile: string, cwd: string) { | ||
@@ -33,5 +35,10 @@ const gitCmd = await spawn("git", ["add", pathToFile], { cwd }); | ||
// Find the commit where we diverged from `ref` at using `git merge-base` | ||
export async function getDivergedCommit(cwd: string, ref: string) { | ||
// First we need to find the commit where we diverged from `ref` at using `git merge-base` | ||
const cmd = await spawn("git", ["merge-base", ref, "HEAD"], { cwd }); | ||
if (cmd.code !== 0) { | ||
throw new Error( | ||
`Failed to find where HEAD diverged from ${ref}. Does ${ref} exist?` | ||
); | ||
} | ||
return cmd.stdout.toString().trim(); | ||
@@ -61,2 +68,8 @@ } | ||
const cmd = await spawn("git", ["diff", "--name-only", divergedAt], { cwd }); | ||
if (cmd.code !== 0) { | ||
throw new Error( | ||
`Failed to diff against ${divergedAt}. Is ${divergedAt} a valid ref?` | ||
); | ||
} | ||
const files = cmd.stdout | ||
@@ -113,13 +126,13 @@ .toString() | ||
const fileNameToPackage = (fileName: string) => | ||
packages.packages.find(pkg => isSubdir(pkg.dir, fileName))!; | ||
const fileToPackage: Record<string, Package> = {}; | ||
const fileExistsInPackage = (fileName: string) => | ||
!!fileNameToPackage(fileName); | ||
packages.packages.forEach(pkg => | ||
changedFiles.filter(isInDir(pkg.dir)).forEach(fileName => { | ||
const prevPkg = fileToPackage[fileName] || { dir: "" }; | ||
if (pkg.dir.length > prevPkg.dir.length) fileToPackage[fileName] = pkg; | ||
}) | ||
); | ||
return ( | ||
changedFiles | ||
// ignore deleted files | ||
.filter(fileExistsInPackage) | ||
.map(fileNameToPackage) | ||
Object.values(fileToPackage) | ||
// filter, so that we have only unique packages | ||
@@ -126,0 +139,0 @@ .filter((pkg, idx, packages) => packages.indexOf(pkg) === idx) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35390
716
+ Added@changesets/types@3.3.0(transitive)
- Removed@changesets/types@2.0.1(transitive)
Updated@changesets/types@^3.0.0