@suss/contract-terraform 0.34.1 → 0.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -43,6 +43,7 @@ var import_node_fs = __toESM(require("fs"), 1);
43
43
  var import_node_path = __toESM(require("path"), 1);
44
44
  var import_semver = __toESM(require("semver"), 1);
45
45
  var import_behavioral_ir = require("@suss/behavioral-ir");
46
+ var import_files = require("@suss/behavioral-ir/files");
46
47
 
47
48
  // src/hclDocument.ts
48
49
  var import_hcl2_parser = __toESM(require("hcl2-parser"), 1);
@@ -701,7 +702,10 @@ function terraformFileToSummaries(target, options) {
701
702
  arguments: {},
702
703
  ancestors: [directory]
703
704
  }),
704
- options
705
+ {
706
+ ...options,
707
+ projectRoot: options.projectRoot ?? (0, import_files.defaultProjectRoot)(target)
708
+ }
705
709
  );
706
710
  }
707
711
  var LOCAL_SOURCE = /^\.\.?[/\\]/;
@@ -793,6 +797,7 @@ function outputValues(child) {
793
797
  function moduleSummaries(module2, options) {
794
798
  const summaries = [];
795
799
  for (const file of module2.files) {
800
+ const sourceFile = options.projectRoot === void 0 ? file.sourceFile : (0, import_files.pathInProject)(file.sourceFile, options.projectRoot);
796
801
  for (const [resourceType, label, body] of file.resources) {
797
802
  for (const pack of options.packs) {
798
803
  const pattern = patternFor(pack, resourceType, file.constraints, body);
@@ -804,7 +809,7 @@ function moduleSummaries(module2, options) {
804
809
  pattern,
805
810
  label,
806
811
  body,
807
- sourceFile: file.sourceFile,
812
+ sourceFile,
808
813
  resourceType,
809
814
  scope: module2.scope,
810
815
  options
package/dist/index.d.cts CHANGED
@@ -395,6 +395,11 @@ interface TerraformReadOptions {
395
395
  * location.
396
396
  */
397
397
  codeScopes?: Record<string, string>;
398
+ /**
399
+ * Absolute. The directory each `.tf` file's path is measured from.
400
+ * Without it, a file's path is recorded as it was given.
401
+ */
402
+ projectRoot?: string;
398
403
  }
399
404
  /** Every boundary one Terraform configuration declares. */
400
405
  declare function terraformToSummaries(source: string, sourceFile: string, options: TerraformReadOptions): BehavioralSummary[];
package/dist/index.d.ts CHANGED
@@ -395,6 +395,11 @@ interface TerraformReadOptions {
395
395
  * location.
396
396
  */
397
397
  codeScopes?: Record<string, string>;
398
+ /**
399
+ * Absolute. The directory each `.tf` file's path is measured from.
400
+ * Without it, a file's path is recorded as it was given.
401
+ */
402
+ projectRoot?: string;
398
403
  }
399
404
  /** Every boundary one Terraform configuration declares. */
400
405
  declare function terraformToSummaries(source: string, sourceFile: string, options: TerraformReadOptions): BehavioralSummary[];
package/dist/index.js CHANGED
@@ -14,6 +14,7 @@ import {
14
14
  storageBinding,
15
15
  withRuntimeContractMetadata
16
16
  } from "@suss/behavioral-ir";
17
+ import { defaultProjectRoot, pathInProject } from "@suss/behavioral-ir/files";
17
18
 
18
19
  // src/hclDocument.ts
19
20
  import hcl2 from "hcl2-parser";
@@ -672,7 +673,10 @@ function terraformFileToSummaries(target, options) {
672
673
  arguments: {},
673
674
  ancestors: [directory]
674
675
  }),
675
- options
676
+ {
677
+ ...options,
678
+ projectRoot: options.projectRoot ?? defaultProjectRoot(target)
679
+ }
676
680
  );
677
681
  }
678
682
  var LOCAL_SOURCE = /^\.\.?[/\\]/;
@@ -764,6 +768,7 @@ function outputValues(child) {
764
768
  function moduleSummaries(module, options) {
765
769
  const summaries = [];
766
770
  for (const file of module.files) {
771
+ const sourceFile = options.projectRoot === void 0 ? file.sourceFile : pathInProject(file.sourceFile, options.projectRoot);
767
772
  for (const [resourceType, label, body] of file.resources) {
768
773
  for (const pack of options.packs) {
769
774
  const pattern = patternFor(pack, resourceType, file.constraints, body);
@@ -775,7 +780,7 @@ function moduleSummaries(module, options) {
775
780
  pattern,
776
781
  label,
777
782
  body,
778
- sourceFile: file.sourceFile,
783
+ sourceFile,
779
784
  resourceType,
780
785
  scope: module.scope,
781
786
  options
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suss/contract-terraform",
3
- "version": "0.34.1",
3
+ "version": "0.35.0",
4
4
  "type": "module",
5
5
  "description": "Read the storage a Terraform configuration declares and check it against the code that reads and writes those tables.",
6
6
  "keywords": [
@@ -47,7 +47,7 @@
47
47
  "typecheck": "tsc --noEmit"
48
48
  },
49
49
  "dependencies": {
50
- "@suss/behavioral-ir": "0.34.1",
50
+ "@suss/behavioral-ir": "0.35.0",
51
51
  "hcl2-parser": "^1.0.3",
52
52
  "semver": "^7.6.0"
53
53
  },