Files
hyperframes/packages/cli/src/utils/missingPackage.ts
T
Miguel Ángel d0da232ec9 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.
2026-10-17 18:14:02 +00:00

24 lines
857 B
TypeScript

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}`)}`
);
}