diff --git a/apps/cli/src/index.tsx b/apps/cli/src/index.tsx
index 540347b..f40a4c5 100644
--- a/apps/cli/src/index.tsx
+++ b/apps/cli/src/index.tsx
@@ -41,7 +41,10 @@ const command = program
3000,
)
.option("-n, --no-upgrade", "skip applying the upgrade")
- .option("-a, --auto-detect", "auto-detect the package to upgrade")
+ .option(
+ "-a, --auto-detect [branch]",
+ "auto-detect the package to upgrade, diff against [branch]",
+ )
.option("-s, --simple", "simple mode")
.option("-i, --ipc", "run in ipc mode")
.option("-d, --dir
", "target directory for the upgrade")
diff --git a/packages/bumpgen-core/src/index.ts b/packages/bumpgen-core/src/index.ts
index 1506212..02e3dae 100644
--- a/packages/bumpgen-core/src/index.ts
+++ b/packages/bumpgen-core/src/index.ts
@@ -67,10 +67,10 @@ const bumpFinder = ({
const { projectRoot } = args;
return await language.packages.upgrade.list(projectRoot);
},
- detect: async () => {
+ detect: async (target?: string) => {
const { language } = services;
const { projectRoot } = args;
- return await language.packages.upgrade.detect(projectRoot);
+ return await language.packages.upgrade.detect(projectRoot, target);
},
};
};
diff --git a/packages/bumpgen-core/src/services/language/types.ts b/packages/bumpgen-core/src/services/language/types.ts
index d740fde..59ec74a 100644
--- a/packages/bumpgen-core/src/services/language/types.ts
+++ b/packages/bumpgen-core/src/services/language/types.ts
@@ -20,7 +20,10 @@ export type BumpgenLanguageService = {
packages: {
upgrade: {
list: (projectRoot: string) => Promise;
- detect: (projectRoot: string) => Promise;
+ detect: (
+ projectRoot: string,
+ target?: string,
+ ) => Promise;
apply: (
projectRoot: string,
upgrade: PackageUpgrade,
diff --git a/packages/bumpgen-core/src/services/language/typescript/index.ts b/packages/bumpgen-core/src/services/language/typescript/index.ts
index 9f1f520..8cc53b0 100644
--- a/packages/bumpgen-core/src/services/language/typescript/index.ts
+++ b/packages/bumpgen-core/src/services/language/typescript/index.ts
@@ -211,7 +211,7 @@ export const makeTypescriptService = (
};
});
},
- detect: async (projectRoot) => {
+ detect: async (projectRoot, target) => {
const packageJson = await PackageJson.load(projectRoot);
const existingDependencies = new Set([
@@ -224,15 +224,9 @@ export const makeTypescriptService = (
]);
await git.raw.cwd(projectRoot);
- const branch = (await git.raw.branch()).current;
+ const branch = target ?? (await git.raw.branch()).current;
- let diff = await git.raw.diff([branch, "package.json"]);
-
- // if there are no changes in the package.json, we check against the main branch
- if (!diff) {
- const mainBranch = await git.getMainBranch(projectRoot);
- diff = await git.raw.diff([mainBranch, "package.json"]);
- }
+ const diff = await git.raw.diff([branch, "package.json"]);
const upgradedPackages = [];