Skip to content

Commit

Permalink
feat: add target branch to autodetect
Browse files Browse the repository at this point in the history
  • Loading branch information
zlalvani committed May 14, 2024
1 parent eed1077 commit 8efa094
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
5 changes: 4 additions & 1 deletion apps/cli/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 <dir>", "target directory for the upgrade")
Expand Down
4 changes: 2 additions & 2 deletions packages/bumpgen-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
};
};
Expand Down
5 changes: 4 additions & 1 deletion packages/bumpgen-core/src/services/language/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ export type BumpgenLanguageService<TAst = any> = {
packages: {
upgrade: {
list: (projectRoot: string) => Promise<PackageUpgrade[]>;
detect: (projectRoot: string) => Promise<PackageUpgrade[]>;
detect: (
projectRoot: string,
target?: string,
) => Promise<PackageUpgrade[]>;
apply: (
projectRoot: string,
upgrade: PackageUpgrade,
Expand Down
12 changes: 3 additions & 9 deletions packages/bumpgen-core/src/services/language/typescript/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export const makeTypescriptService = (
};
});
},
detect: async (projectRoot) => {
detect: async (projectRoot, target) => {
const packageJson = await PackageJson.load(projectRoot);

const existingDependencies = new Set([
Expand All @@ -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 = [];

Expand Down

0 comments on commit 8efa094

Please sign in to comment.