Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/bright-bears-visit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@aws-blocks/create-blocks-app': patch
---

Use the lazy Lambda handler factory in the React template.
15 changes: 15 additions & 0 deletions packages/create-blocks-app/src/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,21 @@ describe('create-blocks-app auto-detection', () => {
}
});

it('generates a lazy backend import for the React template Lambda handler', () => {
const tmpDir = join(__dirname, '../.test-react-lambda-handler');
mkdirSync(tmpDir, { recursive: true });
writeFileSync(join(tmpDir, 'package.json'), JSON.stringify({ name: 'react-app', version: '1.0.0' }));
try {
const result = run(['-y', '--skip-install', '--template', 'react'], tmpDir);
assert.strictEqual(result.exitCode, 0);
const handler = readFileSync(join(tmpDir, 'aws-blocks', 'index.handler.ts'), 'utf-8');
assert.match(handler, /createLambdaHandler\(\(\) => import\('\.\/index\.js'\)\)/);
assert.doesNotMatch(handler, /import \* as backend/);
} finally {
rmSync(tmpDir, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 });
}
});

it('handles Yarn Classic workspace format (object with packages array)', () => {
const tmpDir = join(__dirname, '../.test-yarn-classic');
mkdirSync(tmpDir, { recursive: true });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { createLambdaHandler } from '@aws-blocks/blocks/lambda-handler';
import * as backend from './index.js';

export const handler = createLambdaHandler(backend);
export const handler = createLambdaHandler(() => import('./index.js'));