@cdktn/provider-generator 0.25.0-pre.40 → 0.25.0-pre.42

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.
@@ -70,6 +70,27 @@ function resourceTypesPresentInSnapshot(
70
70
  return resources;
71
71
  }
72
72
 
73
+ /**
74
+ * Rewrites the registry host in any fully-qualified-name key. The host records
75
+ * which CLI fetched the schema - terraform's or tofu's - rather than anything
76
+ * about the generated code, so one snapshot serves both.
77
+ */
78
+ function stubRegistryHosts(value: any): any {
79
+ if (Array.isArray(value)) return value.map(stubRegistryHosts);
80
+ if (value && typeof value === "object") {
81
+ return Object.fromEntries(
82
+ Object.entries(value).map(([k, v]) => [
83
+ k.replace(
84
+ /^registry\.(?:terraform\.io|opentofu\.org)\//,
85
+ "STUBBED_REGISTRY/",
86
+ ),
87
+ stubRegistryHosts(v),
88
+ ]),
89
+ );
90
+ }
91
+ return value;
92
+ }
93
+
73
94
  describe("Provider", () => {
74
95
  it("generates a provider", async () => {
75
96
  const constraint = new TerraformProviderConstraint(
@@ -86,7 +107,7 @@ describe("Provider", () => {
86
107
  process.env.CDKTF_EXPERIMENTAL_PROVIDER_SCHEMA_CACHE_PATH,
87
108
  );
88
109
  await maker.generate([constraint]);
89
- const snapshot = directorySnapshot(workdir);
110
+ const snapshot = stubRegistryHosts(directorySnapshot(workdir));
90
111
  expect(snapshot).toMatchSnapshot();
91
112
  });
92
113
  }, 600_000);
@@ -103,7 +124,7 @@ describe("Provider", () => {
103
124
  targetLanguage: Language.TYPESCRIPT,
104
125
  });
105
126
  await maker.generate([constraint]);
106
- const snapshot = directorySnapshot(workdir);
127
+ const snapshot = stubRegistryHosts(directorySnapshot(workdir));
107
128
 
108
129
  const terraformResourceTypesPresent: string[] =
109
130
  resourceTypesPresentInSnapshot(snapshot, "datadog");
@@ -127,7 +148,7 @@ describe("Provider", () => {
127
148
  const constraint = new TerraformProviderConstraint({
128
149
  name: "dockerr",
129
150
  source: "registry.terraform.io/kreuzwerker/docker",
130
- version: "3.0.2",
151
+ version: "3.9.0",
131
152
  });
132
153
  return await mkdtemp(async (workdir) => {
133
154
  const jsiiPath = path.join(workdir, ".jsii");
@@ -140,7 +161,7 @@ describe("Provider", () => {
140
161
  process.env.CDKTF_EXPERIMENTAL_PROVIDER_SCHEMA_CACHE_PATH,
141
162
  );
142
163
  await maker.generate([constraint]);
143
- const snapshot = directorySnapshot(workdir);
164
+ const snapshot = stubRegistryHosts(directorySnapshot(workdir));
144
165
 
145
166
  const terraformResourceTypesPresent: string[] =
146
167
  resourceTypesPresentInSnapshot(snapshot, "dockerr");
@@ -160,11 +181,13 @@ describe("Provider", () => {
160
181
  version: "2.51.0",
161
182
  source: "DrFaust92/bitbucket",
162
183
  });
184
+ // andsafe-AG/bitbucket is Terraform-registry only; zahiar/bitbucket is
185
+ // mirrored on both, so this runs under either CLI.
163
186
  const constraint2 = new TerraformProviderConstraint({
164
187
  name: "abitbucket",
165
- namespace: "andsafe-AG",
166
- version: "2.5.0",
167
- source: "andsafe-AG/bitbucket",
188
+ namespace: "zahiar",
189
+ version: "0.3.0",
190
+ source: "zahiar/bitbucket",
168
191
  });
169
192
  return await mkdtemp(async (workdir) => {
170
193
  const jsiiPath = path.join(workdir, ".jsii");
@@ -178,7 +201,7 @@ describe("Provider", () => {
178
201
  );
179
202
  await maker.generate([constraint, constraint2]);
180
203
  console.log("workdir", workdir);
181
- const snapshot = directorySnapshot(workdir);
204
+ const snapshot = stubRegistryHosts(directorySnapshot(workdir));
182
205
  expect(snapshot).toMatchSnapshot();
183
206
  });
184
207
  }, 600_000);
@@ -33,7 +33,8 @@ describe("versions.json file generation", () => {
33
33
  fqn: "kreuzwerker/docker",
34
34
  name: "docker",
35
35
  source: "kreuzwerker/docker",
36
- version: "2.16.0",
36
+ // OpenTofu rejects everything below 3.7.0 as unsigned; see #440.
37
+ version: "3.9.0",
37
38
  },
38
39
  ];
39
40
 
@@ -62,10 +63,14 @@ describe("versions.json file generation", () => {
62
63
  path.join(workdir, "versions.json"),
63
64
  "utf-8",
64
65
  );
65
- expect(Object.keys(JSON.parse(output))).toEqual(
66
- expect.arrayContaining(
67
- constraints.map((c) => `registry.terraform.io/${c.fqn}`),
68
- ),
66
+ // versions.json is keyed by fully qualified name, and the host is
67
+ // whichever registry the fetching CLI used - terraform's or tofu's - so
68
+ // assert on the provider part rather than pinning one registry.
69
+ const keys = Object.keys(JSON.parse(output)).map((k) =>
70
+ k.split("/").slice(1).join("/"),
71
+ );
72
+ expect(keys).toEqual(
73
+ expect.arrayContaining(constraints.map((c) => c.fqn)),
69
74
  );
70
75
  },
71
76
  );
@@ -61,13 +61,13 @@ export class StructEmitter {
61
61
  comment.line(att.description);
62
62
  comment.line(``);
63
63
  comment.line(
64
- `Docs at Terraform Registry: {@link ${resource.linkToDocs}#${att.terraformName} ${resource.className}#${att.terraformName}}`,
64
+ `Docs at ${resource.docsRegistryName}: {@link ${resource.linkToDocs}#${att.terraformName} ${resource.className}#${att.terraformName}}`,
65
65
  );
66
66
  this.warnAboutIdField(att);
67
67
  comment.end();
68
68
  } else {
69
69
  comment.line(
70
- `Docs at Terraform Registry: {@link ${resource.linkToDocs}#${att.terraformName} ${resource.className}#${att.terraformName}}`,
70
+ `Docs at ${resource.docsRegistryName}: {@link ${resource.linkToDocs}#${att.terraformName} ${resource.className}#${att.terraformName}}`,
71
71
  );
72
72
  this.warnAboutIdField(att);
73
73
  comment.end();
@@ -115,6 +115,11 @@ export class ResourceModel {
115
115
  return this.escapeSchema(JSON.stringify(this.schema, undefined, 2));
116
116
  }
117
117
 
118
+ /** Registry that linkToDocs points at, for use in the surrounding prose. */
119
+ public get docsRegistryName(): string {
120
+ return registryForTargetVersions(this.targetVersions).displayName;
121
+ }
122
+
118
123
  public get linkToDocs(): string {
119
124
  // Keyed off the project's declared targets, not the FQPN hostname: that
120
125
  // hostname reflects whichever CLI fetched the schema, which would make the
@@ -345,7 +345,7 @@ export class TerraformProviderGenerator {
345
345
  ? resource.provider
346
346
  : resource.terraformType;
347
347
  this.code.line(
348
- `Refer to the Terraform Registry for docs: [\`${type}\`](${resource.linkToDocs}).`,
348
+ `Refer to the ${resource.docsRegistryName} for docs: [\`${type}\`](${resource.linkToDocs}).`,
349
349
  );
350
350
  this.code.closeFile(filePath);
351
351
  }