diff --git a/apps/cli/src/App.tsx b/apps/cli/src/App.tsx
index 9e79209..f8a412e 100644
--- a/apps/cli/src/App.tsx
+++ b/apps/cli/src/App.tsx
@@ -184,11 +184,12 @@ const App = (props: {
version: string;
port: number;
upgrade: boolean;
+ dir?: string;
token?: string;
}) => {
const { exit } = useApp();
- const { model, language, pkg, version, token, port, upgrade } = props;
+ const { model, language, pkg, version, token, port, upgrade, dir } = props;
const [columns, rows] = useStdoutDimensions();
@@ -256,6 +257,7 @@ const App = (props: {
`${port}`,
...(token ? ["-t", token] : []),
...(upgrade ? [] : ["-n"]),
+ ...(dir ? ["-d", dir] : []),
],
{
shell: true,
diff --git a/apps/cli/src/index.tsx b/apps/cli/src/index.tsx
index 34a4f07..791b196 100644
--- a/apps/cli/src/index.tsx
+++ b/apps/cli/src/index.tsx
@@ -43,9 +43,11 @@ const command = program
.option("-n, --no-upgrade", "skip applying the upgrade")
.option("-s, --simple", "simple mode")
.option("-i, --ipc", "run in ipc mode")
+ .option("-d, --dir
", "target directory for the upgrade")
.parse();
-const { model, language, port, ipc, simple, token, upgrade } = command.opts();
+const { model, language, port, ipc, simple, token, upgrade, dir } =
+ command.opts();
let [pkg, version] = command.processedArgs;
@@ -65,7 +67,7 @@ if (!resolvedToken) {
const bumpFinder = makeBumpFinder({
language,
- projectRoot: process.cwd(),
+ projectRoot: dir,
});
const available = await bumpFinder.list();
@@ -110,7 +112,7 @@ const bumpgen = makeBumpgen({
newVersion: version,
},
language,
- projectRoot: process.cwd(),
+ projectRoot: dir,
});
if (simple) {
@@ -153,6 +155,7 @@ if (simple) {
token={token}
port={port}
upgrade={upgrade}
+ dir={dir}
/>,
);
await app.waitUntilExit();
diff --git a/packages/bumpgen-core/src/index.ts b/packages/bumpgen-core/src/index.ts
index 2648430..fdcc1ee 100644
--- a/packages/bumpgen-core/src/index.ts
+++ b/packages/bumpgen-core/src/index.ts
@@ -1,3 +1,4 @@
+import path from "path";
import process from "process";
import { serializeError } from "serialize-error";
import { v4 } from "uuid";
@@ -436,6 +437,10 @@ const bumpgen = ({
data: errors,
};
+ if (errors.length === 0) {
+ break;
+ }
+
id = v4();
yield {
id,
@@ -559,7 +564,7 @@ export const makeBumpgen = ({
}) => {
model = model ?? "gpt-4-turbo-preview";
language = language ?? "typescript";
- projectRoot = projectRoot ?? process.cwd();
+ projectRoot = projectRoot ? path.resolve(projectRoot) : process.cwd();
const languageService = injectLanguageService(language)();
const llm = injectLLMService({ llmApiKey, model })();
const graphService = injectGraphService();
@@ -586,7 +591,7 @@ export const makeBumpFinder = ({
projectRoot?: string;
}) => {
language = language ?? "typescript";
- projectRoot = projectRoot ?? process.cwd();
+ projectRoot = projectRoot ? path.resolve(projectRoot) : process.cwd();
const languageService = injectLanguageService(language)();
return bumpFinder({
services: { language: languageService },
diff --git a/packages/bumpgen-core/src/services/language/typescript/index.ts b/packages/bumpgen-core/src/services/language/typescript/index.ts
index 732075b..553da8e 100644
--- a/packages/bumpgen-core/src/services/language/typescript/index.ts
+++ b/packages/bumpgen-core/src/services/language/typescript/index.ts
@@ -99,10 +99,11 @@ export const makeTypescriptService = (
return {
build: {
- getErrors: async () => {
+ getErrors: async (projectRoot) => {
let tscOutput = await subprocess.spawn(
`npx tsc --noEmit --skipLibCheck --pretty`,
{
+ cwd: projectRoot,
rejectOnStderr: false,
},
);
@@ -228,6 +229,7 @@ export const makeTypescriptService = (
console.log("Applying upgrades...");
await subprocess.spawn(`${packageManager} install`, {
+ cwd: projectRoot,
rejectOnStderr: false,
rejectOnNonZeroExit: true,
});
@@ -239,6 +241,7 @@ export const makeTypescriptService = (
const { packageManager } = await findPackageManager(projectRoot);
return await subprocess.spawn(`${packageManager} install`, {
+ cwd: projectRoot,
rejectOnStderr: false,
});
},
diff --git a/packages/bumpgen-core/src/services/subprocess/index.ts b/packages/bumpgen-core/src/services/subprocess/index.ts
index 6573adf..e9ece32 100644
--- a/packages/bumpgen-core/src/services/subprocess/index.ts
+++ b/packages/bumpgen-core/src/services/subprocess/index.ts
@@ -30,6 +30,7 @@ export const createSubprocessService = (
spawn: async (
command: string,
options?: {
+ cwd?: string;
rejectOnStderr?: boolean;
rejectOnNonZeroExit?: boolean;
env?: typeof proc.env;
@@ -37,6 +38,7 @@ export const createSubprocessService = (
) => {
return await new Promise((resolve, reject) => {
const child = childProcess.spawn(command, {
+ cwd: options?.cwd,
shell: true,
env: options?.env ?? proc.env,
});