Skip to content

Commit 51556b5

Browse files
committed
fix(cli): keep aws-lambda out of CLI runtime deps
The "Smoke: global install" CI step packs the CLI via `npm pack` and installs it globally via `npm install -g <tgz>`. npm doesn't understand the workspace: protocol, so a runtime `dependencies` entry of `@hyperframes/aws-lambda: workspace:*` blows up with: npm error code EUNSUPPORTEDPROTOCOL npm error Unsupported URL Type "workspace:": workspace:* (pnpm rewrites workspace:* on publish; npm pack doesn't.) Three changes to unblock the smoke + keep the published CLI install small for users who don't deploy to Lambda: - Move `@hyperframes/aws-lambda` from CLI's `dependencies` back to `devDependencies`. It's already external in tsup.config.ts; the bundle references it via runtime resolution only. - Convert the static `import { … } from "@hyperframes/aws-lambda/sdk"` in sites.ts / render.ts / progress.ts to `await import()` inside each function. tsup with `splitting: false` was inlining those static imports at the top of the bundle, which made Node eagerly resolve them at CLI startup (MODULE_NOT_FOUND before any lambda subcommand even runs). Dynamic imports stay dynamic in the bundle. - Add a friendly missing-module check in the lambda dispatcher. When a user runs `hyperframes lambda deploy / render / sites / progress / destroy` without aws-lambda installed, they now see: @hyperframes/aws-lambda is not installed. The `hyperframes lambda deploy` command needs it at runtime. Install it alongside the CLI: npm install -g @hyperframes/aws-lambda Verified locally: pack + global install + `hyperframes init --example blank` now succeeds end-to-end (was the same scenario the CI smoke job runs).
1 parent 8ff0fc2 commit 51556b5

5 files changed

Lines changed: 47 additions & 8 deletions

File tree

‎packages/cli/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
},
2626
"dependencies": {
2727
"@hono/node-server": "^1.8.0",
28-
"@hyperframes/aws-lambda": "workspace:*",
2928
"@puppeteer/browsers": "^2.13.0",
3029
"adm-zip": "^0.5.16",
3130
"citty": "^0.2.1",
@@ -43,6 +42,7 @@
4342
},
4443
"devDependencies": {
4544
"@clack/prompts": "^1.1.0",
45+
"@hyperframes/aws-lambda": "workspace:*",
4646
"@hyperframes/core": "workspace:*",
4747
"@hyperframes/engine": "workspace:*",
4848
"@hyperframes/producer": "workspace:*",

‎packages/cli/src/commands/lambda.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,30 @@ export default defineCommand({
139139
const regionFlag = args.region as string | undefined;
140140
if (regionFlag) process.env.AWS_REGION = regionFlag;
141141

142+
// The lambda subverbs dynamic-import `@hyperframes/aws-lambda` at call
143+
// time. We keep aws-lambda as a workspace devDependency (not a runtime
144+
// dep) so the published CLI install stays small for users who don't
145+
// deploy to Lambda. Subverbs other than `policies` need aws-lambda;
146+
// catch the missing-module error here and turn it into a friendly hint.
147+
const verbsNeedingSDK = new Set(["deploy", "sites", "render", "progress", "destroy"]);
148+
if (verbsNeedingSDK.has(subcommand)) {
149+
try {
150+
await import("@hyperframes/aws-lambda/sdk");
151+
} catch (err) {
152+
if ((err as NodeJS.ErrnoException).code === "ERR_MODULE_NOT_FOUND") {
153+
console.error(
154+
`${c.error("@hyperframes/aws-lambda is not installed.")} The ${c.accent(`hyperframes lambda ${subcommand}`)} command needs it at runtime.\n` +
155+
`Install it alongside the CLI:\n` +
156+
` ${c.accent("npm install -g @hyperframes/aws-lambda")}\n` +
157+
`Or, for an opt-in dev setup:\n` +
158+
` ${c.accent("npm install @hyperframes/aws-lambda")}`,
159+
);
160+
process.exit(1);
161+
}
162+
throw err;
163+
}
164+
}
165+
142166
switch (subcommand) {
143167
case "deploy": {
144168
const { runDeploy } = await import("./lambda/deploy.js");

‎packages/cli/src/commands/lambda/progress.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
* from the stack's region + state-machine name).
66
*/
77

8-
import { getRenderProgress } from "@hyperframes/aws-lambda/sdk";
98
import { c } from "../../ui/colors.js";
109
import { requireStack } from "./state.js";
1110

@@ -26,6 +25,9 @@ export async function runProgress(args: ProgressArgs): Promise<void> {
2625
? args.target
2726
: executionArnFromName(stack.stateMachineArn, args.target);
2827

28+
// Dynamic-import the SDK so tsup keeps it out of the static-import head
29+
// of the CLI bundle. See sites.ts loadSDK() for the full rationale.
30+
const { getRenderProgress } = await import("@hyperframes/aws-lambda/sdk");
2931
const progress = await getRenderProgress({
3032
executionArn,
3133
region: stack.region,

‎packages/cli/src/commands/lambda/render.ts‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@
55
*/
66

77
import { resolve as resolvePath } from "node:path";
8-
import {
9-
renderToLambda,
10-
type SerializableDistributedRenderConfig,
11-
} from "@hyperframes/aws-lambda/sdk";
8+
import type { SerializableDistributedRenderConfig } from "@hyperframes/aws-lambda/sdk";
129
import { c } from "../../ui/colors.js";
1310
import { requireStack, stateFilePath } from "./state.js";
1411

12+
// Dynamic-import the SDK so tsup keeps it out of the static-import head of
13+
// the CLI bundle. See sites.ts loadSDK() for the full rationale.
14+
async function loadSDK(): Promise<typeof import("@hyperframes/aws-lambda/sdk")> {
15+
return import("@hyperframes/aws-lambda/sdk");
16+
}
17+
1518
export interface RenderArgs {
1619
projectDir: string;
1720
stackName: string;
@@ -66,6 +69,7 @@ export async function runRender(args: RenderArgs): Promise<void> {
6669
}
6770
: undefined;
6871

72+
const { renderToLambda } = await loadSDK();
6973
const handle = await renderToLambda({
7074
projectDir: siteHandle ? undefined : projectDir,
7175
siteHandle,
@@ -112,7 +116,7 @@ async function waitForCompletion(
112116
json: boolean,
113117
): Promise<void> {
114118
// Lazy import to avoid pulling SFN client when only `render --no-wait` is used.
115-
const { getRenderProgress } = await import("@hyperframes/aws-lambda/sdk");
119+
const { getRenderProgress } = await loadSDK();
116120
let lastRendered = -1;
117121
while (true) {
118122
const progress = await getRenderProgress({

‎packages/cli/src/commands/lambda/sites.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,18 @@
1010
*/
1111

1212
import { resolve as resolvePath } from "node:path";
13-
import { deploySite } from "@hyperframes/aws-lambda/sdk";
1413
import { c } from "../../ui/colors.js";
1514
import { DEFAULT_STACK_NAME, requireStack } from "./state.js";
1615

16+
// `@hyperframes/aws-lambda` is a workspace devDependency in `packages/cli`
17+
// so the published CLI install stays small for users who don't deploy to
18+
// Lambda. The lambda subverbs dynamic-import it on call. The dispatcher in
19+
// `commands/lambda.ts` checks the import resolves before any subverb runs
20+
// and prints a friendly install hint on `ERR_MODULE_NOT_FOUND`.
21+
async function loadSDK(): Promise<typeof import("@hyperframes/aws-lambda/sdk")> {
22+
return import("@hyperframes/aws-lambda/sdk");
23+
}
24+
1725
export interface SitesCreateArgs {
1826
projectDir: string;
1927
stackName: string;
@@ -26,6 +34,7 @@ export async function runSitesCreate(args: SitesCreateArgs): Promise<void> {
2634
const stack = requireStack(args.stackName);
2735
const projectDir = resolvePath(args.projectDir);
2836

37+
const { deploySite } = await loadSDK();
2938
const handle = await deploySite({
3039
projectDir,
3140
bucketName: stack.bucketName,

0 commit comments

Comments
 (0)