From 79763de9dbe15e22882c2a0d03c3d18b8c9e7926 Mon Sep 17 00:00:00 2001 From: Bryan Date: Tue, 8 Apr 2025 16:27:04 +0100 Subject: [PATCH 1/4] fix sst workspace imports --- packages/sst/src/stacks/build.ts | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/packages/sst/src/stacks/build.ts b/packages/sst/src/stacks/build.ts index eb31551e3..5d269827e 100644 --- a/packages/sst/src/stacks/build.ts +++ b/packages/sst/src/stacks/build.ts @@ -18,6 +18,24 @@ declare module "../bus.js" { } } +/** + * This function is used to remove workspace dependencies from the dependencies + * object. This is because esbuild must not mark them as external, otherwise + * the bundling will fail. + */ +function exceptWorkspaceDependencies( + deps: Record +): Record { + let result = {}; + for (const key of Object.keys(deps)) { + let version = deps[key]; + if (!version.startsWith("workspace:")) { + result[key] = version; + } + } + return result; +} + export async function load(input: string, shallow?: boolean) { const parsed = path.parse(input); const root = await findAbove(input, "package.json"); @@ -48,11 +66,12 @@ export async function load(input: string, shallow?: boolean) { external: [ "aws-cdk-lib", "sst", - ...Object.keys({ + // workspace dependencies must be internal + ...Object.keys(exceptWorkspaceDependencies({ ...pkg.devDependencies, ...pkg.dependencies, ...pkg.peerDependencies, - }), + })), ], plugins: [ { From e0973e09cfa1ac1da69a98508f6fe4722a9d72fa Mon Sep 17 00:00:00 2001 From: Bryan Date: Tue, 8 Apr 2025 16:28:54 +0100 Subject: [PATCH 2/4] improve docs --- packages/sst/src/stacks/build.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/sst/src/stacks/build.ts b/packages/sst/src/stacks/build.ts index 5d269827e..e24b3ecb5 100644 --- a/packages/sst/src/stacks/build.ts +++ b/packages/sst/src/stacks/build.ts @@ -67,6 +67,7 @@ export async function load(input: string, shallow?: boolean) { "aws-cdk-lib", "sst", // workspace dependencies must be internal + // because they haven't been built yet ...Object.keys(exceptWorkspaceDependencies({ ...pkg.devDependencies, ...pkg.dependencies, From 1b234131953f5ca6afe27c86a37edcc50bd1976e Mon Sep 17 00:00:00 2001 From: Bryan Date: Wed, 9 Apr 2025 11:19:36 +0100 Subject: [PATCH 3/4] fix type errors --- packages/sst/src/stacks/build.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sst/src/stacks/build.ts b/packages/sst/src/stacks/build.ts index e24b3ecb5..9812ac9c4 100644 --- a/packages/sst/src/stacks/build.ts +++ b/packages/sst/src/stacks/build.ts @@ -26,7 +26,7 @@ declare module "../bus.js" { function exceptWorkspaceDependencies( deps: Record ): Record { - let result = {}; + let result: Record = {}; for (const key of Object.keys(deps)) { let version = deps[key]; if (!version.startsWith("workspace:")) { From d533dab863060800c1c3ad0ff04b6c234d996566 Mon Sep 17 00:00:00 2001 From: Bryan Date: Wed, 9 Apr 2025 12:11:18 +0100 Subject: [PATCH 4/4] Add docs --- www/docs/constructs/Stack.about.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/www/docs/constructs/Stack.about.md b/www/docs/constructs/Stack.about.md index f3ebd9d36..4a3302bfc 100644 --- a/www/docs/constructs/Stack.about.md +++ b/www/docs/constructs/Stack.about.md @@ -1,5 +1,7 @@ The Stack construct extends cdk.Stack. It automatically prefixes the stack names with the stage and app name to ensure that they can be deployed to multiple regions in the same AWS account. It also ensure that the stack uses the same AWS profile and region as the app. They're defined using functions that return resources that can be imported by other stacks. +When the stack construct is built in a monorepo, any packages marked as `workspace` in package.json will be included in the build. All other packages are marked as external and must be pre-built. + ## Examples ### Creating a new stack