@changesets/git
Advanced tools
Comparing version 1.3.1 to 1.3.2
# @changesets/git | ||
## 1.3.2 | ||
### Patch Changes | ||
- [#770](https://github.com/changesets/changesets/pull/770) [`eb86652`](https://github.com/changesets/changesets/commit/eb86652cbd21c49f90d2a03caa9a578593c4d102) Thanks [@alizeait](https://github.com/alizeait)! - `getChangedFilesSince` and `getChangedPackagesSinceRef` will now return the correct absolute paths of the changed files when the passed `cwd` is different from the repository's root. | ||
- Updated dependencies [[`c87eba6`](https://github.com/changesets/changesets/commit/c87eba6f80a34563b7382f87472c29f6dafb546c)]: | ||
- @changesets/types@5.0.0 | ||
## 1.3.1 | ||
@@ -4,0 +13,0 @@ |
@@ -175,2 +175,21 @@ 'use strict'; | ||
} | ||
async function getRepoRoot({ | ||
cwd | ||
}) { | ||
const { | ||
stdout, | ||
code, | ||
stderr | ||
} = await spawn__default['default']("git", ["rev-parse", "--show-toplevel"], { | ||
cwd | ||
}); | ||
if (code !== 0) { | ||
throw new Error(stderr.toString()); | ||
} | ||
return stdout.toString().trim().replace(/\n|\r/g, ""); | ||
} | ||
async function getChangedFilesSince({ | ||
@@ -193,3 +212,6 @@ cwd, | ||
if (!fullPath) return files; | ||
return files.map(file => path__default['default'].resolve(cwd, file)); | ||
const repoRoot = await getRepoRoot({ | ||
cwd | ||
}); | ||
return files.map(file => path__default['default'].resolve(repoRoot, file)); | ||
} // below are less generic functions that we use in combination with other things we are doing | ||
@@ -196,0 +218,0 @@ |
@@ -107,2 +107,10 @@ "use strict"; | ||
async function getRepoRoot({cwd: cwd}) { | ||
const {stdout: stdout, code: code, stderr: stderr} = await spawn__default.default("git", [ "rev-parse", "--show-toplevel" ], { | ||
cwd: cwd | ||
}); | ||
if (0 !== code) throw new Error(stderr.toString()); | ||
return stdout.toString().trim().replace(/\n|\r/g, ""); | ||
} | ||
async function getChangedFilesSince({cwd: cwd, ref: ref, fullPath: fullPath = !1}) { | ||
@@ -114,3 +122,7 @@ const divergedAt = await getDivergedCommit(cwd, ref), cmd = await spawn__default.default("git", [ "diff", "--name-only", divergedAt ], { | ||
const files = cmd.stdout.toString().trim().split("\n").filter((a => a)); | ||
return fullPath ? files.map((file => path__default.default.resolve(cwd, file))) : files; | ||
if (!fullPath) return files; | ||
const repoRoot = await getRepoRoot({ | ||
cwd: cwd | ||
}); | ||
return files.map((file => path__default.default.resolve(repoRoot, file))); | ||
} | ||
@@ -117,0 +129,0 @@ |
@@ -164,2 +164,21 @@ import spawn from 'spawndamnit'; | ||
} | ||
async function getRepoRoot({ | ||
cwd | ||
}) { | ||
const { | ||
stdout, | ||
code, | ||
stderr | ||
} = await spawn("git", ["rev-parse", "--show-toplevel"], { | ||
cwd | ||
}); | ||
if (code !== 0) { | ||
throw new Error(stderr.toString()); | ||
} | ||
return stdout.toString().trim().replace(/\n|\r/g, ""); | ||
} | ||
async function getChangedFilesSince({ | ||
@@ -182,3 +201,6 @@ cwd, | ||
if (!fullPath) return files; | ||
return files.map(file => path.resolve(cwd, file)); | ||
const repoRoot = await getRepoRoot({ | ||
cwd | ||
}); | ||
return files.map(file => path.resolve(repoRoot, file)); | ||
} // below are less generic functions that we use in combination with other things we are doing | ||
@@ -185,0 +207,0 @@ |
{ | ||
"name": "@changesets/git", | ||
"version": "1.3.1", | ||
"version": "1.3.2", | ||
"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": "^4.1.0", | ||
"@changesets/types": "^5.0.0", | ||
"@manypkg/get-packages": "^1.1.3", | ||
@@ -15,0 +15,0 @@ "is-subdir": "^1.1.1", |
@@ -0,1 +1,2 @@ | ||
import path from "path"; | ||
import fixtures from "fixturez"; | ||
@@ -419,2 +420,35 @@ import spawn from "spawndamnit"; | ||
}); | ||
it("should get correct full paths of changed files irrespective of cwd", async () => { | ||
const ref = await spawn("git", ["rev-parse", "HEAD"], { cwd }); | ||
await add("packages/pkg-a/index.js", cwd); | ||
await commit("Add packageA index", cwd); | ||
await add("packages/pkg-b/index.js", cwd); | ||
await commit("Added packageB index", cwd); | ||
const filesChangedSinceRef = await getChangedFilesSince({ | ||
ref: ref.stdout.toString().trim(), | ||
cwd, | ||
fullPath: true | ||
}); | ||
expect(filesChangedSinceRef[0]).toBe( | ||
path.resolve(cwd, "packages/pkg-a/index.js") | ||
); | ||
expect(filesChangedSinceRef[1]).toBe( | ||
path.resolve(cwd, "packages/pkg-b/index.js") | ||
); | ||
const filesChangedSinceRef2 = await getChangedFilesSince({ | ||
ref: ref.stdout.toString().trim(), | ||
cwd: path.resolve(cwd, "packages"), | ||
fullPath: true | ||
}); | ||
expect(filesChangedSinceRef2[0]).toBe( | ||
path.resolve(cwd, "packages/pkg-a/index.js") | ||
); | ||
expect(filesChangedSinceRef2[1]).toBe( | ||
path.resolve(cwd, "packages/pkg-b/index.js") | ||
); | ||
}); | ||
}); | ||
@@ -421,0 +455,0 @@ |
@@ -185,3 +185,19 @@ import spawn from "spawndamnit"; | ||
} | ||
async function getRepoRoot({ cwd }: { cwd: string }) { | ||
const { stdout, code, stderr } = await spawn( | ||
"git", | ||
["rev-parse", "--show-toplevel"], | ||
{ cwd } | ||
); | ||
if (code !== 0) { | ||
throw new Error(stderr.toString()); | ||
} | ||
return stdout | ||
.toString() | ||
.trim() | ||
.replace(/\n|\r/g, ""); | ||
} | ||
export async function getChangedFilesSince({ | ||
@@ -211,3 +227,5 @@ cwd, | ||
if (!fullPath) return files; | ||
return files.map(file => path.resolve(cwd, file)); | ||
const repoRoot = await getRepoRoot({ cwd }); | ||
return files.map(file => path.resolve(repoRoot, file)); | ||
} | ||
@@ -214,0 +232,0 @@ |
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
63274
1328
+ Added@changesets/types@5.2.1(transitive)
Updated@changesets/types@^5.0.0