Skip to content

Commit 50dbd0e

Browse files
authored
fix(create-blocks-app): fix Amplify integration scripts (#242)
1 parent a8f486e commit 50dbd0e

5 files changed

Lines changed: 33 additions & 8 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@aws-blocks/create-blocks-app': patch
3+
---
4+
5+
Include the local dev-server script and use public AWS Blocks imports when adding AWS Blocks to an Amplify Gen 2 project.

packages/create-blocks-app/src/cli.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,17 @@ describe('create-blocks-app auto-detection', () => {
170170
const result = run(['-y', '--skip-install'], tmpDir);
171171
assert.strictEqual(result.exitCode, 0);
172172
assert.match(result.stdout, /Detected Amplify Gen 2 project/);
173+
const packageJson = JSON.parse(readFileSync(join(tmpDir, 'package.json'), 'utf-8'));
174+
const serverPath = join(tmpDir, 'aws-blocks', 'scripts', 'server.ts');
175+
const generateClientPath = join(tmpDir, 'aws-blocks', 'scripts', 'generate-client.ts');
176+
const cognitoVerifierPath = join(tmpDir, 'aws-blocks', 'cognito-verifier.ts');
177+
assert.strictEqual(packageJson.scripts['blocks:dev'], 'tsx watch aws-blocks/scripts/server.ts');
178+
assert.ok(existsSync(serverPath));
179+
assert.match(readFileSync(serverPath, 'utf-8'), /startDevServer/);
180+
assert.match(readFileSync(generateClientPath, 'utf-8'), /from '@aws-blocks\/blocks\/scripts'/);
181+
assert.match(readFileSync(cognitoVerifierPath, 'utf-8'), /from '@aws-blocks\/blocks'/);
182+
assert.doesNotMatch(readFileSync(generateClientPath, 'utf-8'), /@aws-blocks\/core/);
183+
assert.doesNotMatch(readFileSync(cognitoVerifierPath, 'utf-8'), /@aws-blocks\/core/);
173184
} finally {
174185
rmSync(tmpDir, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 });
175186
}

packages/create-blocks-app/templates/amplify/aws-blocks/cognito-verifier.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
* No session store, no sign-in flow, no cookies — pure stateless verification.
99
*/
1010

11-
import { ApiError } from '@aws-blocks/core';
12-
import type { BlocksContext } from '@aws-blocks/core';
11+
import { ApiError, type BlocksContext } from '@aws-blocks/blocks';
1312
import { CognitoJwtVerifier } from 'aws-jwt-verify';
1413

1514
type CognitoVerifierInstance = ReturnType<typeof CognitoJwtVerifier.create>;

packages/create-blocks-app/templates/amplify/aws-blocks/scripts/generate-client.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
*
44
* Run: npm run blocks:generate-client
55
*
6-
* Uses the core generateClientCode() to discover ApiNamespace exports,
6+
* Uses generateClientCode() to discover ApiNamespace exports,
77
* then injects the Amplify auth middleware and URL configuration.
88
*/
9-
import { resolve, dirname, join } from 'node:path';
10-
import { writeFileSync, mkdirSync } from 'node:fs';
11-
import { generateClientCode } from '@aws-blocks/core/scripts';
9+
import { mkdirSync, writeFileSync } from 'node:fs';
10+
import { dirname, join, resolve } from 'node:path';
11+
import { generateClientCode } from '@aws-blocks/blocks/scripts';
1212

1313
const awsBlocksDir = resolve(dirname(new URL(import.meta.url).pathname), '..');
1414
const foundationPath = join(awsBlocksDir, 'index.ts');
@@ -21,8 +21,8 @@ let code = await generateClientCode(foundationPath);
2121
// Standard: __BLOCKS_ApiNamespaceClient__('name')
2222
// Amplify: __BLOCKS_ApiNamespaceClient__('name', { url: BLOCKS_API_URL })
2323
code = code.replace(
24-
/__BLOCKS_ApiNamespaceClient__\('([^']+)'\)/g,
25-
"__BLOCKS_ApiNamespaceClient__('$1', { url: BLOCKS_API_URL })"
24+
/__BLOCKS_ApiNamespaceClient__\('([^']+)'\)/g,
25+
"__BLOCKS_ApiNamespaceClient__('$1', { url: BLOCKS_API_URL })",
2626
);
2727

2828
// Replace the auto-generated header and imports with Amplify-specific preamble
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { dirname, join } from 'node:path';
2+
import { fileURLToPath } from 'node:url';
3+
import { startDevServer } from '@aws-blocks/blocks/scripts';
4+
5+
const __dirname = dirname(fileURLToPath(import.meta.url));
6+
7+
startDevServer({
8+
backendPath: join(__dirname, '..', 'index.ts'),
9+
port: 3001,
10+
});

0 commit comments

Comments
 (0)