Skip to content

Commit dfc197f

Browse files
authored
fix(sam): set working directory for sam build #2755
Problem: All of our SAM CLI invocations are ran without an explicit working directory. This creates tons of hard-to-diagnose problems. Solution: * Explicitly set a working directory for `sam build` to the template's directory. This mimics the typical situation when running `sam build` in a terminal. * This correctly creates a `.aws-sam` directory adjacent to the target template. * Other `sam` commands are still affected although they are harder to change without breaking things due to the temporary directory :/ * The way the Toolkit + SAM CLI interact is incredibly brittle and this solution is just a mitigation. ref #2050 ref #2395
1 parent b1a437e commit dfc197f

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/shared/sam/cli/samCliBuild.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { pushIf } from '../../utilities/collectionUtils'
1010
import { localize } from '../../utilities/vsCodeUtils'
1111
import { Timeout, waitTimeout } from '../../utilities/timeoutUtils'
1212
import { ChildProcessResult } from '../../utilities/childProcess'
13+
import { dirname } from 'path'
1314

1415
export interface SamCliBuildInvocationArguments {
1516
/**
@@ -133,7 +134,10 @@ export class SamCliBuildInvocation {
133134
}
134135

135136
let childProcessResult: Promise<ChildProcessResult | void> = this.args.invoker.invoke({
136-
spawnOptions: { env },
137+
spawnOptions: {
138+
env,
139+
cwd: dirname(this.args.templatePath),
140+
},
137141
arguments: invokeArgs,
138142
onStdout: onOutput,
139143
onStderr: onOutput,

0 commit comments

Comments
 (0)