Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add target branch to autodetect #86

Merged
merged 1 commit into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading