fix(cli): show the real import error when a cloud adapter is installed (#5763)

lambda reported any ERR_MODULE_NOT_FOUND as '@hyperframes/aws-lambda is not installed', and cloudrun matched its package name anywhere in the message, which also names the adapter when one of its own dependencies is missing. Both now use one helper that matches only Node's "Cannot find package '<pkg>'" and rethrow anything else.
This commit is contained in:
Miguel Ángel
2026-10-17 18:14:02 +00:00
committed by GitHub
parent 20611541b1
commit d0da232ec9
4 changed files with 64 additions and 17 deletions
+23
View File
@@ -0,0 +1,23 @@
import { c } from "../ui/colors.js";
/**
* True only when `pkg` itself is absent. Node's message for a missing dependency of an
* installed `pkg` also names `pkg` (in the importer path), so match the quoted specifier.
*/
export function isMissingPackageError(error: unknown, pkg: string): boolean {
return (
(error as NodeJS.ErrnoException)?.code === "ERR_MODULE_NOT_FOUND" &&
error instanceof Error &&
error.message.includes(`Cannot find package '${pkg}'`)
);
}
export function missingPackageMessage(pkg: string, command: string): string {
return (
`${c.error(`${pkg} is not installed.`)} The ${c.accent(command)} command needs it at runtime.\n` +
`Install it alongside the CLI:\n` +
` ${c.accent(`npm install -g ${pkg}`)}\n` +
`Or, for an opt-in project setup:\n` +
` ${c.accent(`npm install ${pkg}`)}`
);
}