Skip to content

Commit

Permalink
Bundle Bedrock SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolk committed Sep 5, 2024
1 parent 665ed4c commit 8bea42c
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/few-panthers-cross.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@aws-amplify/ai-constructs': patch
---

Bundle Bedrock SDK
5 changes: 4 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion packages/ai-constructs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -33,5 +34,8 @@
"peerDependencies": {
"aws-cdk-lib": "^2.152.0",
"constructs": "^10.0.0"
}
},
"bundledDependencies": [
"@aws-sdk/client-bedrock-runtime"
]
}
44 changes: 44 additions & 0 deletions packages/ai-constructs/prepublish.ts
Original file line number Diff line number Diff line change
@@ -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();

0 comments on commit 8bea42c

Please sign in to comment.