@changesets/git
Advanced tools
Comparing version 0.2.5 to 0.3.0
# @changesets/git | ||
## 0.3.0 | ||
### Minor Changes | ||
- [`bca8865`](https://github.com/atlassian/changesets/commit/bca88652d38caa31e789c4564230ba0b49562ad2) [#221](https://github.com/atlassian/changesets/pull/221) Thanks [@mitchellhamilton](https://github.com/mitchellhamilton)! - Removed `getChangedPackagesSinceMaster` and `getChangedChangesetFilesSinceMaster` and replace them with `getChangedPackagesSinceRef` and `getChangedChangesetFilesSinceRef`. The new methods along with `getChangedFilesSince` also now require arguments as an object with `cwd` and `ref` properties to avoid accidentially passing `cwd` as `ref` and vice versa | ||
## 0.2.5 | ||
@@ -4,0 +10,0 @@ |
@@ -5,5 +5,15 @@ declare function add(pathToFile: string, cwd: string): Promise<boolean>; | ||
declare function getCommitThatAddsFile(gitPath: string, cwd: string): Promise<string>; | ||
declare function getChangedFilesSince(ref: string, cwd: string, fullPath?: boolean): Promise<Array<string>>; | ||
declare function getChangedChangesetFilesSinceMaster(cwd: string, fullPath?: boolean): Promise<Array<string>>; | ||
declare function getChangedPackagesSinceMaster(cwd: string): Promise<any[]>; | ||
export { getCommitThatAddsFile, getChangedFilesSince, add, commit, tag, getChangedPackagesSinceMaster, getChangedChangesetFilesSinceMaster }; | ||
declare function getChangedFilesSince({ cwd, ref, fullPath }: { | ||
cwd: string; | ||
ref: string; | ||
fullPath?: boolean; | ||
}): Promise<Array<string>>; | ||
declare function getChangedChangesetFilesSinceRef({ cwd, ref }: { | ||
cwd: string; | ||
ref: string; | ||
}): Promise<Array<string>>; | ||
declare function getChangedPackagesSinceRef({ cwd, ref }: { | ||
cwd: string; | ||
ref: string; | ||
}): Promise<any[]>; | ||
export { getCommitThatAddsFile, getChangedFilesSince, add, commit, tag, getChangedPackagesSinceRef, getChangedChangesetFilesSinceRef }; |
@@ -11,3 +11,2 @@ 'use strict'; | ||
var getWorkspaces = _interopDefault(require('get-workspaces')); | ||
var pkgDir = _interopDefault(require('pkg-dir')); | ||
var errors = require('@changesets/errors'); | ||
@@ -19,22 +18,2 @@ | ||
// TODO: Currently getting this working, need to decide how to | ||
// share projectDir between packages if that's what we need | ||
async function getProjectDirectory(cwd) { | ||
const projectDir = await pkgDir(cwd); | ||
if (!projectDir) { | ||
throw new Error("Could not find project directory"); | ||
} | ||
return projectDir; | ||
} | ||
async function getMasterRef(cwd) { | ||
const gitCmd = await spawn("git", ["rev-parse", "master"], { | ||
cwd | ||
}); | ||
if (gitCmd.code !== 0) throw new errors.GitError(gitCmd.code, gitCmd.stderr.toString()); | ||
return gitCmd.stdout.toString().trim().split("\n")[0]; | ||
} | ||
async function add(pathToFile, cwd) { | ||
@@ -76,3 +55,7 @@ const gitCmd = await spawn("git", ["add", pathToFile], { | ||
async function getChangedFilesSince(ref, cwd, fullPath = false) { | ||
async function getChangedFilesSince({ | ||
cwd, | ||
ref, | ||
fullPath = false | ||
}) { | ||
// First we need to find the commit where we diverged from `ref` at using `git merge-base` | ||
@@ -93,6 +76,8 @@ let cmd = await spawn("git", ["merge-base", ref, "HEAD"], { | ||
async function getChangedChangesetFilesSinceMaster(cwd, fullPath = false) { | ||
async function getChangedChangesetFilesSinceRef({ | ||
cwd, | ||
ref | ||
}) { | ||
try { | ||
const ref = await getMasterRef(cwd); // First we need to find the commit where we diverged from `ref` at using `git merge-base` | ||
// First we need to find the commit where we diverged from `ref` at using `git merge-base` | ||
let cmd = await spawn("git", ["merge-base", ref, "HEAD"], { | ||
@@ -102,3 +87,3 @@ cwd | ||
cmd = await spawn("git", ["diff", "--name-only", "--diff-filter=d", "master"], { | ||
cmd = await spawn("git", ["diff", "--name-only", "--diff-filter=d", ref], { | ||
cwd | ||
@@ -108,4 +93,3 @@ }); | ||
const files = cmd.stdout.toString().trim().split("\n").filter(file => tester.test(file)); | ||
if (!fullPath) return files; | ||
return files.map(file => path.resolve(cwd, file)); | ||
return files; | ||
} catch (err) { | ||
@@ -117,5 +101,11 @@ if (err instanceof errors.GitError) return []; | ||
async function getChangedPackagesSinceCommit(commitHash, cwd) { | ||
const changedFiles = await getChangedFilesSince(commitHash, cwd, true); | ||
const projectDir = await getProjectDirectory(cwd); | ||
async function getChangedPackagesSinceRef({ | ||
cwd, | ||
ref | ||
}) { | ||
const changedFiles = await getChangedFilesSince({ | ||
ref, | ||
cwd, | ||
fullPath: true | ||
}); | ||
let workspaces = await getWorkspaces({ | ||
@@ -131,3 +121,3 @@ cwd, | ||
const allPackages = workspaces.map(pkg => _objectSpread({}, pkg, { | ||
relativeDir: path.relative(projectDir, pkg.dir) | ||
relativeDir: path.relative(cwd, pkg.dir) | ||
})); | ||
@@ -142,16 +132,2 @@ | ||
.filter((pkg, idx, packages) => packages.indexOf(pkg) === idx); | ||
} // Note: This returns the packages that have changed AND been committed since master, | ||
// it wont include staged/unstaged changes | ||
// | ||
// Don't use this function in master branch as it returns nothing in that case. | ||
async function getChangedPackagesSinceMaster(cwd) { | ||
try { | ||
const masterRef = await getMasterRef(cwd); | ||
return getChangedPackagesSinceCommit(masterRef, cwd); | ||
} catch (err) { | ||
if (err instanceof errors.GitError) return []; | ||
throw err; | ||
} | ||
} | ||
@@ -161,6 +137,6 @@ | ||
exports.commit = commit; | ||
exports.getChangedChangesetFilesSinceMaster = getChangedChangesetFilesSinceMaster; | ||
exports.getChangedChangesetFilesSinceRef = getChangedChangesetFilesSinceRef; | ||
exports.getChangedFilesSince = getChangedFilesSince; | ||
exports.getChangedPackagesSinceMaster = getChangedPackagesSinceMaster; | ||
exports.getChangedPackagesSinceRef = getChangedPackagesSinceRef; | ||
exports.getCommitThatAddsFile = getCommitThatAddsFile; | ||
exports.tag = tag; |
@@ -11,3 +11,3 @@ "use strict"; | ||
var _defineProperty = _interopDefault(require("@babel/runtime/helpers/defineProperty")), spawn = _interopDefault(require("spawndamnit")), path = _interopDefault(require("path")), getWorkspaces = _interopDefault(require("get-workspaces")), pkgDir = _interopDefault(require("pkg-dir")), errors = require("@changesets/errors"); | ||
var _defineProperty = _interopDefault(require("@babel/runtime/helpers/defineProperty")), spawn = _interopDefault(require("spawndamnit")), path = _interopDefault(require("path")), getWorkspaces = _interopDefault(require("get-workspaces")), errors = require("@changesets/errors"); | ||
@@ -37,16 +37,2 @@ function ownKeys(object, enumerableOnly) { | ||
async function getProjectDirectory(cwd) { | ||
const projectDir = await pkgDir(cwd); | ||
if (!projectDir) throw new Error("Could not find project directory"); | ||
return projectDir; | ||
} | ||
async function getMasterRef(cwd) { | ||
const gitCmd = await spawn("git", [ "rev-parse", "master" ], { | ||
cwd: cwd | ||
}); | ||
if (0 !== gitCmd.code) throw new errors.GitError(gitCmd.code, gitCmd.stderr.toString()); | ||
return gitCmd.stdout.toString().trim().split("\n")[0]; | ||
} | ||
async function add(pathToFile, cwd) { | ||
@@ -77,3 +63,3 @@ const gitCmd = await spawn("git", [ "add", pathToFile ], { | ||
async function getChangedFilesSince(ref, cwd, fullPath = !1) { | ||
async function getChangedFilesSince({cwd: cwd, ref: ref, fullPath: fullPath = !1}) { | ||
let cmd = await spawn("git", [ "merge-base", ref, "HEAD" ], { | ||
@@ -88,14 +74,12 @@ cwd: cwd | ||
async function getChangedChangesetFilesSinceMaster(cwd, fullPath = !1) { | ||
async function getChangedChangesetFilesSinceRef({cwd: cwd, ref: ref}) { | ||
try { | ||
const ref = await getMasterRef(cwd); | ||
let cmd = await spawn("git", [ "merge-base", ref, "HEAD" ], { | ||
cwd: cwd | ||
}); | ||
cmd = await spawn("git", [ "diff", "--name-only", "--diff-filter=d", "master" ], { | ||
cmd = await spawn("git", [ "diff", "--name-only", "--diff-filter=d", ref ], { | ||
cwd: cwd | ||
}); | ||
let tester = /.changeset\/[^\/]+\.md$/; | ||
const files = cmd.stdout.toString().trim().split("\n").filter(file => tester.test(file)); | ||
return fullPath ? files.map(file => path.resolve(cwd, file)) : files; | ||
return cmd.stdout.toString().trim().split("\n").filter(file => tester.test(file)); | ||
} catch (err) { | ||
@@ -107,4 +91,8 @@ if (err instanceof errors.GitError) return []; | ||
async function getChangedPackagesSinceCommit(commitHash, cwd) { | ||
const changedFiles = await getChangedFilesSince(commitHash, cwd, !0), projectDir = await getProjectDirectory(cwd); | ||
async function getChangedPackagesSinceRef({cwd: cwd, ref: ref}) { | ||
const changedFiles = await getChangedFilesSince({ | ||
ref: ref, | ||
cwd: cwd, | ||
fullPath: !0 | ||
}); | ||
let workspaces = await getWorkspaces({ | ||
@@ -116,3 +104,3 @@ cwd: cwd, | ||
const allPackages = workspaces.map(pkg => _objectSpread({}, pkg, { | ||
relativeDir: path.relative(projectDir, pkg.dir) | ||
relativeDir: path.relative(cwd, pkg.dir) | ||
})), fileNameToPackage = fileName => allPackages.find(pkg => fileName.startsWith(pkg.dir + path.sep)); | ||
@@ -122,13 +110,4 @@ return changedFiles.filter(fileName => !!fileNameToPackage(fileName)).map(fileNameToPackage).filter((pkg, idx, packages) => packages.indexOf(pkg) === idx); | ||
async function getChangedPackagesSinceMaster(cwd) { | ||
try { | ||
return getChangedPackagesSinceCommit(await getMasterRef(cwd), cwd); | ||
} catch (err) { | ||
if (err instanceof errors.GitError) return []; | ||
throw err; | ||
} | ||
} | ||
exports.add = add, exports.commit = commit, exports.getChangedChangesetFilesSinceMaster = getChangedChangesetFilesSinceMaster, | ||
exports.getChangedFilesSince = getChangedFilesSince, exports.getChangedPackagesSinceMaster = getChangedPackagesSinceMaster, | ||
exports.add = add, exports.commit = commit, exports.getChangedChangesetFilesSinceRef = getChangedChangesetFilesSinceRef, | ||
exports.getChangedFilesSince = getChangedFilesSince, exports.getChangedPackagesSinceRef = getChangedPackagesSinceRef, | ||
exports.getCommitThatAddsFile = getCommitThatAddsFile, exports.tag = tag; |
@@ -5,3 +5,2 @@ import _defineProperty from '@babel/runtime/helpers/esm/defineProperty'; | ||
import getWorkspaces from 'get-workspaces'; | ||
import pkgDir from 'pkg-dir'; | ||
import { GitError } from '@changesets/errors'; | ||
@@ -13,22 +12,2 @@ | ||
// TODO: Currently getting this working, need to decide how to | ||
// share projectDir between packages if that's what we need | ||
async function getProjectDirectory(cwd) { | ||
const projectDir = await pkgDir(cwd); | ||
if (!projectDir) { | ||
throw new Error("Could not find project directory"); | ||
} | ||
return projectDir; | ||
} | ||
async function getMasterRef(cwd) { | ||
const gitCmd = await spawn("git", ["rev-parse", "master"], { | ||
cwd | ||
}); | ||
if (gitCmd.code !== 0) throw new GitError(gitCmd.code, gitCmd.stderr.toString()); | ||
return gitCmd.stdout.toString().trim().split("\n")[0]; | ||
} | ||
async function add(pathToFile, cwd) { | ||
@@ -70,3 +49,7 @@ const gitCmd = await spawn("git", ["add", pathToFile], { | ||
async function getChangedFilesSince(ref, cwd, fullPath = false) { | ||
async function getChangedFilesSince({ | ||
cwd, | ||
ref, | ||
fullPath = false | ||
}) { | ||
// First we need to find the commit where we diverged from `ref` at using `git merge-base` | ||
@@ -87,6 +70,8 @@ let cmd = await spawn("git", ["merge-base", ref, "HEAD"], { | ||
async function getChangedChangesetFilesSinceMaster(cwd, fullPath = false) { | ||
async function getChangedChangesetFilesSinceRef({ | ||
cwd, | ||
ref | ||
}) { | ||
try { | ||
const ref = await getMasterRef(cwd); // First we need to find the commit where we diverged from `ref` at using `git merge-base` | ||
// First we need to find the commit where we diverged from `ref` at using `git merge-base` | ||
let cmd = await spawn("git", ["merge-base", ref, "HEAD"], { | ||
@@ -96,3 +81,3 @@ cwd | ||
cmd = await spawn("git", ["diff", "--name-only", "--diff-filter=d", "master"], { | ||
cmd = await spawn("git", ["diff", "--name-only", "--diff-filter=d", ref], { | ||
cwd | ||
@@ -102,4 +87,3 @@ }); | ||
const files = cmd.stdout.toString().trim().split("\n").filter(file => tester.test(file)); | ||
if (!fullPath) return files; | ||
return files.map(file => path.resolve(cwd, file)); | ||
return files; | ||
} catch (err) { | ||
@@ -111,5 +95,11 @@ if (err instanceof GitError) return []; | ||
async function getChangedPackagesSinceCommit(commitHash, cwd) { | ||
const changedFiles = await getChangedFilesSince(commitHash, cwd, true); | ||
const projectDir = await getProjectDirectory(cwd); | ||
async function getChangedPackagesSinceRef({ | ||
cwd, | ||
ref | ||
}) { | ||
const changedFiles = await getChangedFilesSince({ | ||
ref, | ||
cwd, | ||
fullPath: true | ||
}); | ||
let workspaces = await getWorkspaces({ | ||
@@ -125,3 +115,3 @@ cwd, | ||
const allPackages = workspaces.map(pkg => _objectSpread({}, pkg, { | ||
relativeDir: path.relative(projectDir, pkg.dir) | ||
relativeDir: path.relative(cwd, pkg.dir) | ||
})); | ||
@@ -136,18 +126,4 @@ | ||
.filter((pkg, idx, packages) => packages.indexOf(pkg) === idx); | ||
} // Note: This returns the packages that have changed AND been committed since master, | ||
// it wont include staged/unstaged changes | ||
// | ||
// Don't use this function in master branch as it returns nothing in that case. | ||
async function getChangedPackagesSinceMaster(cwd) { | ||
try { | ||
const masterRef = await getMasterRef(cwd); | ||
return getChangedPackagesSinceCommit(masterRef, cwd); | ||
} catch (err) { | ||
if (err instanceof GitError) return []; | ||
throw err; | ||
} | ||
} | ||
export { add, commit, getChangedChangesetFilesSinceMaster, getChangedFilesSince, getChangedPackagesSinceMaster, getCommitThatAddsFile, tag }; | ||
export { add, commit, getChangedChangesetFilesSinceRef, getChangedFilesSince, getChangedPackagesSinceRef, getCommitThatAddsFile, tag }; |
{ | ||
"name": "@changesets/git", | ||
"version": "0.2.5", | ||
"version": "0.3.0", | ||
"description": "Some git helpers that changesets use to get information", | ||
@@ -14,3 +14,2 @@ "main": "dist/git.cjs.js", | ||
"get-workspaces": "^0.5.2", | ||
"pkg-dir": "^4.1.0", | ||
"spawndamnit": "^2.0.0" | ||
@@ -17,0 +16,0 @@ }, |
import { copyFixtureIntoTempDir } from "jest-fixtures"; | ||
import spawn from "spawndamnit"; | ||
import path from "path"; | ||
@@ -11,4 +10,4 @@ import { | ||
tag, | ||
getChangedPackagesSinceMaster, | ||
getChangedChangesetFilesSinceMaster | ||
getChangedPackagesSinceRef, | ||
getChangedChangesetFilesSinceRef | ||
} from "./"; | ||
@@ -162,6 +161,6 @@ | ||
const head = await spawn("git", ["rev-parse", "HEAD"], { cwd }); | ||
const changedFiles = await getChangedFilesSince( | ||
head.stdout.toString().trim(), | ||
const changedFiles = await getChangedFilesSince({ | ||
ref: head.stdout.toString().trim(), | ||
cwd | ||
); | ||
}); | ||
expect(changedFiles.filter(a => a)).toHaveLength(0); | ||
@@ -180,6 +179,6 @@ }); | ||
const filesChangedSinceFirstRef = await getChangedFilesSince( | ||
firstRef.stdout.toString().trim(), | ||
const filesChangedSinceFirstRef = await getChangedFilesSince({ | ||
ref: firstRef.stdout.toString().trim(), | ||
cwd | ||
); | ||
}); | ||
expect(filesChangedSinceFirstRef[0]).toEqual("packages/pkg-a/index.js"); | ||
@@ -191,6 +190,6 @@ expect(filesChangedSinceFirstRef[1]).toEqual("packages/pkg-b/index.js"); | ||
const filesChangedSinceSecondRef = await getChangedFilesSince( | ||
secondRef.stdout.toString().trim(), | ||
const filesChangedSinceSecondRef = await getChangedFilesSince({ | ||
ref: secondRef.stdout.toString().trim(), | ||
cwd | ||
); | ||
}); | ||
expect(filesChangedSinceSecondRef[0]).toEqual("packages/pkg-b/index.js"); | ||
@@ -203,3 +202,3 @@ expect(filesChangedSinceSecondRef[1]).toEqual( | ||
describe("getChangedPackagesSinceMaster", () => { | ||
describe("getChangedPackagesSinceRef", () => { | ||
beforeEach(async () => { | ||
@@ -212,3 +211,6 @@ await add("packages/pkg-a/package.json", cwd); | ||
await spawn("git", ["checkout", "-b", "new-branch"], { cwd }); | ||
const changedPackages = await getChangedPackagesSinceMaster(cwd); | ||
const changedPackages = await getChangedPackagesSinceRef({ | ||
cwd, | ||
ref: "master" | ||
}); | ||
expect(changedPackages).toHaveLength(0); | ||
@@ -226,8 +228,9 @@ }); | ||
const changedPackages = await getChangedPackagesSinceMaster(cwd); | ||
const changedPackages = await getChangedPackagesSinceRef({ | ||
cwd, | ||
ref: "master" | ||
}); | ||
expect(changedPackages).toHaveLength(2); | ||
// @ts-ignore | ||
expect(changedPackages[0].name).toEqual("pkg-a"); | ||
// @ts-ignore | ||
expect(changedPackages[1].name).toEqual("pkg-b"); | ||
@@ -237,10 +240,11 @@ }); | ||
describe("getChangedChangesetFilesSinceMaster", () => { | ||
beforeEach(async () => { | ||
describe("getChangedChangesetFilesSinceRef", () => { | ||
it("should be empty if no changeset files have been added", async () => { | ||
await add("packages/pkg-a/package.json", cwd); | ||
await commit("added packageA package.json", cwd); | ||
}); | ||
it("should be empty if no changeset files have been added", async () => { | ||
const files = await getChangedChangesetFilesSinceMaster(cwd); | ||
const files = await getChangedChangesetFilesSinceRef({ | ||
cwd, | ||
ref: "master" | ||
}); | ||
expect(files).toHaveLength(0); | ||
@@ -250,19 +254,27 @@ }); | ||
it("should get the relative path to the changeset file", async () => { | ||
await add("packages/pkg-a/package.json", cwd); | ||
await commit("added packageA package.json", cwd); | ||
await add(".changeset", cwd); | ||
const files = await getChangedChangesetFilesSinceMaster(cwd); | ||
const files = await getChangedChangesetFilesSinceRef({ | ||
cwd, | ||
ref: "master" | ||
}); | ||
expect(files).toHaveLength(2); | ||
expect(files[1]).toEqual(".changeset/quick-lions-devour.md"); | ||
}); | ||
it("should get the absolute path to the changeset file", async () => { | ||
it("should work on a ref that isn't master", async () => { | ||
await spawn("git", ["checkout", "-b", "some-branch"], { cwd }); | ||
await add("packages/pkg-a/package.json", cwd); | ||
await commit("added packageA package.json", cwd); | ||
await add(".changeset", cwd); | ||
const files = await getChangedChangesetFilesSinceMaster(cwd, true); | ||
const files = await getChangedChangesetFilesSinceRef({ | ||
cwd, | ||
ref: "some-branch" | ||
}); | ||
expect(files).toHaveLength(2); | ||
expect(files[1]).toEqual( | ||
path.resolve(cwd, ".changeset/quick-lions-devour.md") | ||
); | ||
expect(files[1]).toEqual(".changeset/quick-lions-devour.md"); | ||
}); | ||
}); | ||
}); |
import spawn from "spawndamnit"; | ||
import path from "path"; | ||
import getWorkspaces from "get-workspaces"; | ||
import pkgDir from "pkg-dir"; | ||
import { GitError } from "@changesets/errors"; | ||
import { Workspace } from "@changesets/types"; | ||
// TODO: Currently getting this working, need to decide how to | ||
// share projectDir between packages if that's what we need | ||
async function getProjectDirectory(cwd: string) { | ||
const projectDir = await pkgDir(cwd); | ||
if (!projectDir) { | ||
throw new Error("Could not find project directory"); | ||
} | ||
return projectDir; | ||
} | ||
async function getMasterRef(cwd: string) { | ||
const gitCmd = await spawn("git", ["rev-parse", "master"], { cwd }); | ||
if (gitCmd.code !== 0) | ||
throw new GitError(gitCmd.code, gitCmd.stderr.toString()); | ||
return gitCmd.stdout | ||
.toString() | ||
.trim() | ||
.split("\n")[0]; | ||
} | ||
async function add(pathToFile: string, cwd: string) { | ||
@@ -63,7 +42,11 @@ const gitCmd = await spawn("git", ["add", pathToFile], { cwd }); | ||
async function getChangedFilesSince( | ||
ref: string, | ||
cwd: string, | ||
async function getChangedFilesSince({ | ||
cwd, | ||
ref, | ||
fullPath = false | ||
): Promise<Array<string>> { | ||
}: { | ||
cwd: string; | ||
ref: string; | ||
fullPath?: boolean; | ||
}): Promise<Array<string>> { | ||
// First we need to find the commit where we diverged from `ref` at using `git merge-base` | ||
@@ -83,16 +66,16 @@ let cmd = await spawn("git", ["merge-base", ref, "HEAD"], { cwd }); | ||
// below are less generic functions that we use in combination with other things we are doing | ||
async function getChangedChangesetFilesSinceMaster( | ||
cwd: string, | ||
fullPath = false | ||
): Promise<Array<string>> { | ||
async function getChangedChangesetFilesSinceRef({ | ||
cwd, | ||
ref | ||
}: { | ||
cwd: string; | ||
ref: string; | ||
}): Promise<Array<string>> { | ||
try { | ||
const ref = await getMasterRef(cwd); | ||
// First we need to find the commit where we diverged from `ref` at using `git merge-base` | ||
let cmd = await spawn("git", ["merge-base", ref, "HEAD"], { cwd }); | ||
// Now we can find which files we added | ||
cmd = await spawn( | ||
"git", | ||
["diff", "--name-only", "--diff-filter=d", "master"], | ||
{ cwd } | ||
); | ||
cmd = await spawn("git", ["diff", "--name-only", "--diff-filter=d", ref], { | ||
cwd | ||
}); | ||
@@ -106,4 +89,3 @@ let tester = /.changeset\/[^/]+\.md$/; | ||
.filter(file => tester.test(file)); | ||
if (!fullPath) return files; | ||
return files.map(file => path.resolve(cwd, file)); | ||
return files; | ||
} catch (err) { | ||
@@ -115,5 +97,10 @@ if (err instanceof GitError) return []; | ||
async function getChangedPackagesSinceCommit(commitHash: string, cwd: string) { | ||
const changedFiles = await getChangedFilesSince(commitHash, cwd, true); | ||
const projectDir = await getProjectDirectory(cwd); | ||
async function getChangedPackagesSinceRef({ | ||
cwd, | ||
ref | ||
}: { | ||
cwd: string; | ||
ref: string; | ||
}) { | ||
const changedFiles = await getChangedFilesSince({ ref, cwd, fullPath: true }); | ||
let workspaces = await getWorkspaces({ | ||
@@ -129,3 +116,3 @@ cwd, | ||
...pkg, | ||
relativeDir: path.relative(projectDir, pkg.dir) | ||
relativeDir: path.relative(cwd, pkg.dir) | ||
})); | ||
@@ -149,16 +136,2 @@ | ||
// Note: This returns the packages that have changed AND been committed since master, | ||
// it wont include staged/unstaged changes | ||
// | ||
// Don't use this function in master branch as it returns nothing in that case. | ||
async function getChangedPackagesSinceMaster(cwd: string) { | ||
try { | ||
const masterRef = await getMasterRef(cwd); | ||
return getChangedPackagesSinceCommit(masterRef, cwd); | ||
} catch (err) { | ||
if (err instanceof GitError) return []; | ||
throw err; | ||
} | ||
} | ||
export { | ||
@@ -170,4 +143,4 @@ getCommitThatAddsFile, | ||
tag, | ||
getChangedPackagesSinceMaster, | ||
getChangedChangesetFilesSinceMaster | ||
getChangedPackagesSinceRef, | ||
getChangedChangesetFilesSinceRef | ||
}; |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
5
0
30678
685
- Removedpkg-dir@^4.1.0
- Removedfind-up@4.1.0(transitive)
- Removedlocate-path@5.0.0(transitive)
- Removedp-limit@2.3.0(transitive)
- Removedp-locate@4.1.0(transitive)
- Removedp-try@2.2.0(transitive)
- Removedpath-exists@4.0.0(transitive)
- Removedpkg-dir@4.2.0(transitive)