commit upgrade (#391)

This commit is contained in:
Will Chen
2025-06-11 15:42:10 -07:00
committed by GitHub
parent 007e0b2f22
commit 99e6592abc
3 changed files with 31 additions and 2 deletions

View File

@@ -61,6 +61,8 @@ testSkipIfWindows("upgrade app to select component", async ({ po }) => {
await po.expectNoAppUpgrades();
await po.snapshotAppFiles();
await po.clickOpenInChatButton();
// There should be another version from the upgrade being committed.
await expect(po.page.getByText("Version 2")).toBeVisible();
await po.clickPreviewPickElement();

View File

@@ -8,6 +8,7 @@ import { getDyadAppPath } from "../../paths/paths";
import fs from "node:fs";
import path from "node:path";
import { spawn } from "node:child_process";
import { gitAddAll, gitCommit } from "../utils/git_utils";
const logger = log.scope("app_upgrade_handlers");
const handle = createLoggedHandler(logger);
@@ -109,7 +110,7 @@ async function applyComponentTagger(appPath: string) {
await fs.promises.writeFile(viteConfigPath, content);
// Install the dependency
return new Promise<void>((resolve, reject) => {
await new Promise<void>((resolve, reject) => {
logger.info("Installing component-tagger dependency");
const process = spawn(
"pnpm add -D @dyad-sh/react-vite-component-tagger || npm install --save-dev --legacy-peer-deps @dyad-sh/react-vite-component-tagger",
@@ -138,6 +139,22 @@ async function applyComponentTagger(appPath: string) {
reject(err);
});
});
// Commit changes
try {
logger.info("Staging and committing changes");
await gitAddAll({ path: appPath });
await gitCommit({
path: appPath,
message: "[dyad] add Dyad component tagger",
});
logger.info("Successfully committed changes");
} catch (err) {
logger.warn(
`Failed to commit changes. This may happen if the project is not in a git repository, or if there are no changes to commit.`,
err,
);
}
}
export function registerAppUpgradeHandlers() {

View File

@@ -74,7 +74,7 @@ export async function gitStageToRevert({
return;
}
// Safety: refuse to run if the work-tree isnt clean.
// Safety: refuse to run if the work-tree isn't clean.
const { stdout: wtStatus } = await execAsync(
`git -C "${path}" status --porcelain`,
);
@@ -138,3 +138,13 @@ export async function gitStageToRevert({
});
}
}
export async function gitAddAll({ path }: { path: string }): Promise<void> {
const settings = readSettings();
if (settings.enableNativeGit) {
await execAsync(`git -C "${path}" add .`);
return;
} else {
return git.add({ fs, dir: path, filepath: "." });
}
}