fix(cli): skip empty dependency installs (#11140)

This commit is contained in:
Taesu
2026-09-03 18:21:20 +00:00
committed by GitHub
parent 8bb68479f5
commit b95b7b31e7
3 changed files with 46 additions and 2 deletions
@@ -0,0 +1,5 @@
---
"auth": patch
---
Allow `auth init` to finish when a generated setup has no dependencies in one of its install groups, and preserve useful package-manager output when an installation fails.
@@ -76,12 +76,19 @@ export function installDependencies({
flags.push(flag);
}
}
const command = `${installCommand}${flags.length > 0 ? ` ${flags.join(" ")}` : ""} ${Array.isArray(dependencies) ? dependencies.join(" ") : dependencies}`;
const dependencyList = Array.isArray(dependencies)
? dependencies
: [dependencies];
if (dependencyList.length === 0) {
return Promise.resolve(true);
}
const command = `${installCommand}${flags.length > 0 ? ` ${flags.join(" ")}` : ""} ${dependencyList.join(" ")}`;
return new Promise((resolve, reject) => {
exec(command, { cwd }, (error, stdout, stderr) => {
if (error) {
reject(new Error(stderr));
const message = stderr.trim() || stdout.trim() || error.message;
reject(new Error(message, { cause: error }));
return;
}
resolve(true);
@@ -131,6 +131,18 @@ describe("installDependencies", () => {
},
);
testWithTmpDir("should skip empty dependency lists", async ({ tmp }) => {
const result = await installDependencies({
dependencies: [],
packageManager: "pnpm",
cwd: tmp,
type: "dev",
});
expect(result).toBe(true);
expect(mockExec).not.toHaveBeenCalled();
});
testWithTmpDir(
"should run pnpm add with --save-catalog for catalog dependencies",
async ({ tmp }) => {
@@ -315,6 +327,26 @@ describe("installDependencies", () => {
},
);
testWithTmpDir(
"should reject with stdout when stderr is empty",
async ({ tmp }) => {
const execError = Object.assign(new Error("Command failed"), { code: 1 });
mockExec.mockImplementation((_cmd, _opts, callback) => {
if (callback) {
callback(execError, "missing package name", "");
}
return {} as ReturnType<typeof exec>;
});
const promise = installDependencies({
dependencies: "invalid-package",
packageManager: "pnpm",
cwd: tmp,
});
await expect(promise).rejects.toThrow("missing package name");
},
);
testWithTmpDir("should pass cwd to exec", async ({ tmp }) => {
await installDependencies({
dependencies: "better-auth",