diff --git a/.changeset/few-panthers-cross.md b/.changeset/few-panthers-cross.md new file mode 100644 index 00000000000..66f7559a966 --- /dev/null +++ b/.changeset/few-panthers-cross.md @@ -0,0 +1,5 @@ +--- +'@aws-amplify/ai-constructs': patch +--- + +Bundle Bedrock SDK diff --git a/package-lock.json b/package-lock.json index e12c677696c..5f51ab1e662 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24670,7 +24670,10 @@ }, "packages/ai-constructs": { "name": "@aws-amplify/ai-constructs", - "version": "0.1.0", + "version": "0.1.1", + "bundleDependencies": [ + "@aws-sdk/client-bedrock-runtime" + ], "license": "Apache-2.0", "dependencies": { "@aws-amplify/plugin-types": "^1.0.1", diff --git a/packages/ai-constructs/package.json b/packages/ai-constructs/package.json index 1db903e3c50..62e3acaf3f5 100644 --- a/packages/ai-constructs/package.json +++ b/packages/ai-constructs/package.json @@ -22,6 +22,7 @@ "main": "lib/index.js", "types": "lib/index.d.ts", "scripts": { + "prepublishOnly": "tsx prepublish.ts", "update:api": "api-extractor run --local" }, "license": "Apache-2.0", @@ -33,5 +34,8 @@ "peerDependencies": { "aws-cdk-lib": "^2.152.0", "constructs": "^10.0.0" - } + }, + "bundledDependencies": [ + "@aws-sdk/client-bedrock-runtime" + ] } diff --git a/packages/ai-constructs/prepublish.ts b/packages/ai-constructs/prepublish.ts new file mode 100644 index 00000000000..de152f9c2a0 --- /dev/null +++ b/packages/ai-constructs/prepublish.ts @@ -0,0 +1,44 @@ +import * as fsp from 'fs/promises'; +import * as path from 'path'; +import * as os from 'os'; +import { execSync } from 'child_process'; + +/** + * This is a workaround for the https://github.com/npm/rfcs/issues/287. + * The issue is causing 'bundledDependencies' functionality not working correctly. + * Dependencies that are supposed to be bundled must be available locally + * in node_modules under package being published. + * The workaround prepares nested node_modules before running publish. + */ + +const main = async () => { + const tempDir = await fsp.mkdtemp( + path.join(os.tmpdir(), 'ai-constructs-packaging') + ); + + try { + const packageJsonPath = path.resolve(__dirname, 'package.json'); + const packageLockPath = path.resolve( + __dirname, + '..', + '..', + 'package-lock.json' + ); + // Use current package's package.json and top level lock file. + await fsp.copyFile(packageJsonPath, path.resolve(tempDir, 'package.json')); + await fsp.copyFile( + packageLockPath, + path.resolve(tempDir, 'package-lock.json') + ); + execSync('npm ci --omit=peer --omit=dev', { cwd: tempDir }); + await fsp.cp( + path.resolve(tempDir, 'node_modules'), + path.resolve(__dirname, 'node_modules'), + { recursive: true } + ); + } finally { + await fsp.rm(tempDir, { recursive: true, force: true }); + } +}; + +void main();