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
24 changes: 22 additions & 2 deletions packages/sst/src/stacks/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>
): Record<string, string> {
let result: Record<string, string> = {};
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");
Expand Down Expand Up @@ -48,11 +66,13 @@ export async function load(input: string, shallow?: boolean) {
external: [
"aws-cdk-lib",
"sst",
...Object.keys({
// workspace dependencies must be internal
// because they haven't been built yet
...Object.keys(exceptWorkspaceDependencies({
...pkg.devDependencies,
...pkg.dependencies,
...pkg.peerDependencies,
}),
})),
],
plugins: [
{
Expand Down
2 changes: 2 additions & 0 deletions www/docs/constructs/Stack.about.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down