Skip to content

Commit 83cf1ce

Browse files
fix: SAM monorepo
1 parent 5ca1a8d commit 83cf1ce

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

src/frameworks/samFramework.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import { Logger } from "../logger.js";
1515
* Support for AWS SAM framework
1616
*/
1717
export class SamFramework implements IFramework {
18-
protected samConfigFile = path.resolve("samconfig.toml");
19-
protected samTemplateFile = path.resolve("template.yaml");
18+
protected samConfigFile = "samconfig.toml";
19+
protected samTemplateFile = "template.yaml";
2020

2121
/**
2222
* Framework name
@@ -31,19 +31,19 @@ export class SamFramework implements IFramework {
3131
*/
3232
public async canHandle(): Promise<boolean> {
3333
try {
34-
await fs.access(this.samConfigFile, constants.F_OK);
34+
await fs.access(path.resolve(this.samConfigFile), constants.F_OK);
3535
} catch (error) {
3636
Logger.verbose(
37-
`[SAM] This is not a SAM framework project. ${this.samConfigFile} not found.`
37+
`[SAM] This is not a SAM framework project. ${path.resolve(this.samConfigFile)} not found.`
3838
);
3939
return false;
4040
}
4141

4242
try {
43-
await fs.access(this.samTemplateFile, constants.F_OK);
43+
await fs.access(path.resolve(this.samTemplateFile), constants.F_OK);
4444
} catch (error) {
4545
Logger.verbose(
46-
`[SAM] This is not a SAM framework project. ${this.samTemplateFile} not found.`
46+
`[SAM] This is not a SAM framework project. ${path.resolve(this.samTemplateFile)} not found.`
4747
);
4848
return false;
4949
}
@@ -65,16 +65,24 @@ export class SamFramework implements IFramework {
6565

6666
const environment = config.configEnv ?? "default";
6767

68-
const samConfigContent = await fs.readFile(this.samConfigFile, "utf-8");
68+
const samConfigContent = await fs.readFile(
69+
path.resolve(this.samConfigFile),
70+
"utf-8"
71+
);
6972

7073
const samConfig = toml.parse(samConfigContent);
7174
const stackName = samConfig[environment]?.global?.parameters?.stack_name;
7275

7376
if (!stackName) {
74-
throw new Error(`Stack name not found in ${this.samConfigFile}`);
77+
throw new Error(
78+
`Stack name not found in ${path.resolve(this.samConfigFile)}`
79+
);
7580
}
7681

77-
const samTemplateContent = await fs.readFile(this.samTemplateFile, "utf-8");
82+
const samTemplateContent = await fs.readFile(
83+
path.resolve(this.samTemplateFile),
84+
"utf-8"
85+
);
7886
const template = yaml.parse(samTemplateContent);
7987

8088
const lambdas: any[] = [];

src/frameworks/terraformFramework.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,15 @@ export class TerraformFramework implements IFramework {
4545
public async canHandle(): Promise<boolean> {
4646
// is there any filey with *.tf extension
4747
const files = await fs.readdir(process.cwd());
48-
return files.some((f) => f.endsWith(".tf"));
48+
const r = files.some((f) => f.endsWith(".tf"));
49+
50+
if (!r) {
51+
Logger.verbose(
52+
`[Terraform] This is not a Terraform project. There are no *.tf files in ${path.resolve(".")} folder.`
53+
);
54+
}
55+
56+
return r;
4957
}
5058

5159
/**

0 commit comments

Comments
 (0)