@cdktn/provider-generator 0.26.0-pre.2 → 0.26.0-pre.21
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/build/__tests__/erasable-syntax.test.d.ts +2 -0
- package/build/__tests__/erasable-syntax.test.js +96 -0
- package/build/get/generator/models/scope.js +2 -14
- package/jest.config.js +0 -1
- package/package.json +5 -5
- package/package.sh +0 -0
- package/src/__tests__/edge-provider-schema/builder.ts +0 -201
- package/src/__tests__/edge-provider-schema/cli.ts +0 -51
- package/src/__tests__/edge-provider-schema/index.ts +0 -284
- package/src/__tests__/edge-provider-schema.test.ts +0 -24
- package/src/__tests__/provider.test.ts +0 -208
- package/src/get/__tests__/constructs-maker.test.ts +0 -242
- package/src/get/__tests__/generator/complex-computed-types.test.ts +0 -28
- package/src/get/__tests__/generator/deep-nested-attributes.test.ts +0 -56
- package/src/get/__tests__/generator/description-escaping.test.ts +0 -84
- package/src/get/__tests__/generator/empty-provider-resources.test.ts +0 -26
- package/src/get/__tests__/generator/ephemeral-resources.test.ts +0 -46
- package/src/get/__tests__/generator/export-sharding.test.ts +0 -169
- package/src/get/__tests__/generator/import-style.test.ts +0 -129
- package/src/get/__tests__/generator/module-docs-registry.test.ts +0 -89
- package/src/get/__tests__/generator/module-generator.test.ts +0 -528
- package/src/get/__tests__/generator/nested-types.test.ts +0 -54
- package/src/get/__tests__/generator/provider-functions-name-collision.test.ts +0 -84
- package/src/get/__tests__/generator/provider-functions.test.ts +0 -262
- package/src/get/__tests__/generator/provider-source-matching.test.ts +0 -84
- package/src/get/__tests__/generator/provider.test.ts +0 -59
- package/src/get/__tests__/generator/resource-types.test.ts +0 -118
- package/src/get/__tests__/generator/skipped-attributes.test.ts +0 -72
- package/src/get/__tests__/generator/supported-stored-classes.test.ts +0 -147
- package/src/get/__tests__/generator/types.test.ts +0 -686
- package/src/get/__tests__/generator/versions-file.test.ts +0 -77
- package/src/get/__tests__/generator/write-only.test.ts +0 -71
- package/src/get/__tests__/registry-class-invalidation.test.ts +0 -123
- package/src/get/__tests__/target-versions.test.ts +0 -249
- package/src/get/__tests__/util.ts +0 -80
- package/src/get/constructs-maker.ts +0 -991
- package/src/get/generator/custom-defaults.ts +0 -494
- package/src/get/generator/emitter/attributes-emitter.ts +0 -316
- package/src/get/generator/emitter/index.ts +0 -6
- package/src/get/generator/emitter/provider-functions-emitter.ts +0 -117
- package/src/get/generator/emitter/resource-emitter.ts +0 -330
- package/src/get/generator/emitter/struct-emitter.ts +0 -683
- package/src/get/generator/loop-detection.ts +0 -81
- package/src/get/generator/models/attribute-model.ts +0 -273
- package/src/get/generator/models/attribute-type-model.ts +0 -559
- package/src/get/generator/models/index.ts +0 -8
- package/src/get/generator/models/provider-function-model.ts +0 -872
- package/src/get/generator/models/resource-model.ts +0 -206
- package/src/get/generator/models/scope.ts +0 -54
- package/src/get/generator/models/struct.ts +0 -124
- package/src/get/generator/models/supported-stored-classes.ts +0 -88
- package/src/get/generator/module-generator.ts +0 -236
- package/src/get/generator/provider-generator.ts +0 -451
- package/src/get/generator/resource-parser.ts +0 -782
- package/src/get/generator/sanitized-comments.ts +0 -49
- package/src/get/generator/skipped-attributes.ts +0 -27
- package/src/index.ts +0 -40
- package/src/util.ts +0 -26
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
// Copyright (c) HashiCorp, Inc
|
|
2
|
-
// SPDX-License-Identifier: MPL-2.0
|
|
3
|
-
import * as fs from "fs";
|
|
4
|
-
import * as os from "os";
|
|
5
|
-
import * as path from "path";
|
|
6
|
-
import { CodeMaker } from "codemaker";
|
|
7
|
-
import {
|
|
8
|
-
TerraformProviderGenerator,
|
|
9
|
-
type TerraformProviderGeneratorOptions,
|
|
10
|
-
} from "../../generator/provider-generator";
|
|
11
|
-
|
|
12
|
-
const fixture = JSON.parse(
|
|
13
|
-
fs.readFileSync(
|
|
14
|
-
path.join(__dirname, "fixtures", "aws_wafv2_web_acl.test.fixture.json"),
|
|
15
|
-
"utf-8",
|
|
16
|
-
),
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
async function generate(options: TerraformProviderGeneratorOptions = {}) {
|
|
20
|
-
const code = new CodeMaker();
|
|
21
|
-
const workdir = fs.mkdtempSync(path.join(os.tmpdir(), "import-style.test"));
|
|
22
|
-
new TerraformProviderGenerator(code, fixture, options).generateAll();
|
|
23
|
-
await code.save(workdir);
|
|
24
|
-
return workdir;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const RESOURCE_INDEX = "providers/test/wafv2-web-acl/index.ts";
|
|
28
|
-
const STRUCTS_INDEX = "providers/test/wafv2-web-acl/index-structs/index.ts";
|
|
29
|
-
const STRUCTS_DIR = "providers/test/wafv2-web-acl/index-structs";
|
|
30
|
-
const PROVIDER_INDEX = "providers/test/index.ts";
|
|
31
|
-
|
|
32
|
-
function readAllShards(workdir: string): string {
|
|
33
|
-
return fs
|
|
34
|
-
.readdirSync(path.join(workdir, STRUCTS_DIR))
|
|
35
|
-
.filter((f) => /^structs\d+\.ts$/.test(f))
|
|
36
|
-
.map((f) => fs.readFileSync(path.join(workdir, STRUCTS_DIR, f), "utf-8"))
|
|
37
|
-
.join("\n");
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
test("default (no importExtension): emits explicit /index for folders, bare for files", async () => {
|
|
41
|
-
const workdir = await generate();
|
|
42
|
-
|
|
43
|
-
const resource = fs.readFileSync(path.join(workdir, RESOURCE_INDEX), "utf-8");
|
|
44
|
-
expect(resource).toContain(`} from './index-structs/index'`);
|
|
45
|
-
expect(resource).toContain(`export * from './index-structs/index'`);
|
|
46
|
-
expect(resource).not.toMatch(/from '\.\/[^']*\.(js|ts)'/);
|
|
47
|
-
|
|
48
|
-
const structsIndex = fs.readFileSync(
|
|
49
|
-
path.join(workdir, STRUCTS_INDEX),
|
|
50
|
-
"utf-8",
|
|
51
|
-
);
|
|
52
|
-
expect(structsIndex).toContain(`export * from './structs0'`);
|
|
53
|
-
expect(structsIndex).not.toMatch(/from '\.\/[^']*\.(js|ts)'/);
|
|
54
|
-
|
|
55
|
-
const providerIndex = fs.readFileSync(
|
|
56
|
-
path.join(workdir, PROVIDER_INDEX),
|
|
57
|
-
"utf-8",
|
|
58
|
-
);
|
|
59
|
-
expect(providerIndex).toMatch(/from '\.\/[^']+\/index';/);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
test("importExtension '.js': emits fully-qualified ./<folder>/index.js and ./<file>.js", async () => {
|
|
63
|
-
const workdir = await generate({ importExtension: ".js" });
|
|
64
|
-
|
|
65
|
-
const resource = fs.readFileSync(path.join(workdir, RESOURCE_INDEX), "utf-8");
|
|
66
|
-
expect(resource).toContain(`} from './index-structs/index.js'`);
|
|
67
|
-
expect(resource).toContain(`export * from './index-structs/index.js'`);
|
|
68
|
-
|
|
69
|
-
const structsIndex = fs.readFileSync(
|
|
70
|
-
path.join(workdir, STRUCTS_INDEX),
|
|
71
|
-
"utf-8",
|
|
72
|
-
);
|
|
73
|
-
expect(structsIndex).toContain(`export * from './structs0.js'`);
|
|
74
|
-
|
|
75
|
-
const allShards = readAllShards(workdir);
|
|
76
|
-
expect(allShards).toMatch(/from '\.\/structs\d+\.js'/);
|
|
77
|
-
|
|
78
|
-
const providerIndex = fs.readFileSync(
|
|
79
|
-
path.join(workdir, PROVIDER_INDEX),
|
|
80
|
-
"utf-8",
|
|
81
|
-
);
|
|
82
|
-
expect(providerIndex).toMatch(/from '\.\/[^']+\/index\.js';/);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
test("importExtension '.ts': emits fully-qualified ./<folder>/index.ts and ./<file>.ts", async () => {
|
|
86
|
-
const workdir = await generate({ importExtension: ".ts" });
|
|
87
|
-
|
|
88
|
-
const resource = fs.readFileSync(path.join(workdir, RESOURCE_INDEX), "utf-8");
|
|
89
|
-
expect(resource).toContain(`} from './index-structs/index.ts'`);
|
|
90
|
-
expect(resource).toContain(`export * from './index-structs/index.ts'`);
|
|
91
|
-
|
|
92
|
-
const structsIndex = fs.readFileSync(
|
|
93
|
-
path.join(workdir, STRUCTS_INDEX),
|
|
94
|
-
"utf-8",
|
|
95
|
-
);
|
|
96
|
-
expect(structsIndex).toContain(`export * from './structs0.ts'`);
|
|
97
|
-
|
|
98
|
-
const allShards = readAllShards(workdir);
|
|
99
|
-
expect(allShards).toMatch(/from '\.\/structs\d+\.ts'/);
|
|
100
|
-
|
|
101
|
-
const providerIndex = fs.readFileSync(
|
|
102
|
-
path.join(workdir, PROVIDER_INDEX),
|
|
103
|
-
"utf-8",
|
|
104
|
-
);
|
|
105
|
-
expect(providerIndex).toMatch(/from '\.\/[^']+\/index\.ts';/);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
test("importExtension '': emits explicit /index for folders, bare for files", async () => {
|
|
109
|
-
const workdir = await generate({ importExtension: "" });
|
|
110
|
-
|
|
111
|
-
const resource = fs.readFileSync(path.join(workdir, RESOURCE_INDEX), "utf-8");
|
|
112
|
-
expect(resource).toContain(`} from './index-structs/index'`);
|
|
113
|
-
expect(resource).toContain(`export * from './index-structs/index'`);
|
|
114
|
-
expect(resource).not.toMatch(/from '\.\/[^']*\.(js|ts)'/);
|
|
115
|
-
|
|
116
|
-
const structsIndex = fs.readFileSync(
|
|
117
|
-
path.join(workdir, STRUCTS_INDEX),
|
|
118
|
-
"utf-8",
|
|
119
|
-
);
|
|
120
|
-
// file targets get the (empty) extension, so they stay bare
|
|
121
|
-
expect(structsIndex).toContain(`export * from './structs0'`);
|
|
122
|
-
expect(structsIndex).not.toMatch(/from '\.\/[^']*\.(js|ts)'/);
|
|
123
|
-
|
|
124
|
-
const providerIndex = fs.readFileSync(
|
|
125
|
-
path.join(workdir, PROVIDER_INDEX),
|
|
126
|
-
"utf-8",
|
|
127
|
-
);
|
|
128
|
-
expect(providerIndex).toMatch(/from '\.\/[^']+\/index';/);
|
|
129
|
-
});
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
// Copyright (c) HashiCorp, Inc
|
|
2
|
-
// SPDX-License-Identifier: MPL-2.0
|
|
3
|
-
import * as fs from "fs";
|
|
4
|
-
import * as path from "path";
|
|
5
|
-
import { CodeMaker } from "codemaker";
|
|
6
|
-
import {
|
|
7
|
-
ConstructsMakerModuleTarget,
|
|
8
|
-
Language,
|
|
9
|
-
TerraformModuleConstraint,
|
|
10
|
-
TerraformTargetVersions,
|
|
11
|
-
} from "@cdktn/commons";
|
|
12
|
-
import { ModuleGenerator } from "../../generator/module-generator";
|
|
13
|
-
import { createTmpHelper } from "../util";
|
|
14
|
-
|
|
15
|
-
const tmp = createTmpHelper();
|
|
16
|
-
|
|
17
|
-
async function docsComment(
|
|
18
|
-
source: string,
|
|
19
|
-
targetVersions?: TerraformTargetVersions,
|
|
20
|
-
): Promise<string> {
|
|
21
|
-
const workdir = tmp("module-docs-registry");
|
|
22
|
-
const target = ConstructsMakerModuleTarget.from(
|
|
23
|
-
new TerraformModuleConstraint(source),
|
|
24
|
-
Language.TYPESCRIPT,
|
|
25
|
-
) as ConstructsMakerModuleTarget;
|
|
26
|
-
target.spec = { name: target.name, inputs: [], outputs: [] };
|
|
27
|
-
|
|
28
|
-
const code = new CodeMaker();
|
|
29
|
-
new ModuleGenerator(code, [target], targetVersions);
|
|
30
|
-
await code.save(workdir);
|
|
31
|
-
|
|
32
|
-
const emitted = fs.readFileSync(path.join(workdir, target.fileName), "utf-8");
|
|
33
|
-
const line = emitted
|
|
34
|
-
.split("\n")
|
|
35
|
-
.find((l) => l.includes("Docs at") || l.includes("Source at"));
|
|
36
|
-
return (line ?? "").trim();
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
describe("generated module docs links", () => {
|
|
40
|
-
const module = "terraform-aws-modules/vpc/aws@3.19.0";
|
|
41
|
-
const submodule =
|
|
42
|
-
"terraform-aws-modules/vpc/aws//modules/vpc-endpoints@3.19.0";
|
|
43
|
-
|
|
44
|
-
it("uses the Terraform Registry when nothing is declared", async () => {
|
|
45
|
-
expect(await docsComment(module)).toContain(
|
|
46
|
-
"https://registry.terraform.io/modules/terraform-aws-modules/vpc/aws/3.19.0",
|
|
47
|
-
);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it("uses the OpenTofu Registry when only OpenTofu is declared", async () => {
|
|
51
|
-
const comment = await docsComment(module, { opentofu: ">=1.6.0" });
|
|
52
|
-
expect(comment).toContain("Docs at OpenTofu Registry");
|
|
53
|
-
expect(comment).toContain(
|
|
54
|
-
"https://search.opentofu.org/module/terraform-aws-modules/vpc/aws/v3.19.0",
|
|
55
|
-
);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it("links an OpenTofu submodule with the singular segment", async () => {
|
|
59
|
-
expect(await docsComment(submodule, { opentofu: ">=1.6.0" })).toContain(
|
|
60
|
-
"https://search.opentofu.org/module/terraform-aws-modules/vpc/aws/v3.19.0/submodule/vpc-endpoints",
|
|
61
|
-
);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
// Registries serve submodule pages only for a direct child of `modules/`
|
|
65
|
-
// (checked against rendered pages); anything else links to the module.
|
|
66
|
-
it.each([
|
|
67
|
-
[
|
|
68
|
-
"an examples path",
|
|
69
|
-
"terraform-aws-modules/vpc/aws//examples/complete@3.19.0",
|
|
70
|
-
],
|
|
71
|
-
[
|
|
72
|
-
"a nested modules path",
|
|
73
|
-
"terraform-aws-modules/vpc/aws//modules/x/y@3.19.0",
|
|
74
|
-
],
|
|
75
|
-
])("links %s to the module page", async (_name, source) => {
|
|
76
|
-
expect(await docsComment(source)).toContain(
|
|
77
|
-
"{@link https://registry.terraform.io/modules/terraform-aws-modules/vpc/aws/3.19.0 ",
|
|
78
|
-
);
|
|
79
|
-
expect(await docsComment(source, { opentofu: ">=1.6.0" })).toContain(
|
|
80
|
-
"{@link https://search.opentofu.org/module/terraform-aws-modules/vpc/aws/v3.19.0 ",
|
|
81
|
-
);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it("keeps the Terraform submodule shape unchanged", async () => {
|
|
85
|
-
expect(await docsComment(submodule)).toContain(
|
|
86
|
-
"https://registry.terraform.io/modules/terraform-aws-modules/vpc/aws/3.19.0/submodules/vpc-endpoints",
|
|
87
|
-
);
|
|
88
|
-
});
|
|
89
|
-
});
|