@cdktn/provider-generator 0.24.0-pre.7 → 0.24.0-pre.71
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/.spec.swcrc +22 -0
- package/LICENSE +355 -0
- package/README.md +1 -1
- package/build/__tests__/edge-provider-schema/cli.js +8 -3
- package/build/get/__tests__/generator/import-style.test.d.ts +2 -0
- package/build/get/__tests__/generator/import-style.test.js +101 -0
- package/build/get/__tests__/generator/module-generator.test.js +12 -12
- package/build/get/__tests__/generator/provider-source-matching.test.d.ts +2 -0
- package/build/get/__tests__/generator/provider-source-matching.test.js +45 -0
- package/build/get/constructs-maker.d.ts +5 -1
- package/build/get/constructs-maker.js +37 -7
- package/build/get/generator/emitter/struct-emitter.d.ts +2 -1
- package/build/get/generator/emitter/struct-emitter.js +14 -11
- package/build/get/generator/module-generator.js +3 -3
- package/build/get/generator/provider-generator.d.ts +9 -1
- package/build/get/generator/provider-generator.js +17 -7
- package/jest.config.js +16 -9
- package/package.json +24 -23
- package/package.sh +1 -1
- package/src/__tests__/__snapshots__/edge-provider-schema.test.ts.snap +8 -8
- package/src/__tests__/__snapshots__/provider.test.ts.snap +2951 -2951
- package/src/__tests__/edge-provider-schema/builder.ts +185 -0
- package/src/__tests__/edge-provider-schema/cli.ts +51 -0
- package/src/__tests__/edge-provider-schema/index.ts +161 -0
- package/src/__tests__/edge-provider-schema.test.ts +24 -0
- package/src/__tests__/provider.test.ts +180 -0
- package/src/get/__tests__/constructs-maker.test.ts +118 -0
- package/src/get/__tests__/generator/__snapshots__/complex-computed-types.test.ts.snap +5 -5
- package/src/get/__tests__/generator/__snapshots__/export-sharding.test.ts.snap +3310 -3310
- package/src/get/__tests__/generator/__snapshots__/module-generator.test.ts.snap +355 -355
- package/src/get/__tests__/generator/__snapshots__/nested-types.test.ts.snap +8 -8
- package/src/get/__tests__/generator/__snapshots__/provider.test.ts.snap +8 -8
- package/src/get/__tests__/generator/__snapshots__/resource-types.test.ts.snap +126 -126
- package/src/get/__tests__/generator/__snapshots__/skipped-attributes.test.ts.snap +17 -17
- package/src/get/__tests__/generator/__snapshots__/types.test.ts.snap +65 -65
- package/src/get/__tests__/generator/complex-computed-types.test.ts +28 -0
- package/src/get/__tests__/generator/deep-nested-attributes.test.ts +56 -0
- package/src/get/__tests__/generator/description-escaping.test.ts +84 -0
- package/src/get/__tests__/generator/empty-provider-resources.test.ts +26 -0
- package/src/get/__tests__/generator/export-sharding.test.ts +169 -0
- package/src/get/__tests__/generator/import-style.test.ts +129 -0
- package/src/get/__tests__/generator/module-generator.test.ts +528 -0
- package/src/get/__tests__/generator/nested-types.test.ts +54 -0
- package/src/get/__tests__/generator/provider-source-matching.test.ts +84 -0
- package/src/get/__tests__/generator/provider.test.ts +51 -0
- package/src/get/__tests__/generator/resource-types.test.ts +118 -0
- package/src/get/__tests__/generator/skipped-attributes.test.ts +72 -0
- package/src/get/__tests__/generator/types.test.ts +611 -0
- package/src/get/__tests__/generator/versions-file.test.ts +72 -0
- package/src/get/__tests__/util.ts +75 -0
- package/src/get/constructs-maker.ts +845 -0
- package/src/get/generator/custom-defaults.ts +493 -0
- package/src/get/generator/emitter/attributes-emitter.ts +225 -0
- package/src/get/generator/emitter/index.ts +5 -0
- package/src/get/generator/emitter/resource-emitter.ts +226 -0
- package/src/get/generator/emitter/struct-emitter.ts +683 -0
- package/src/get/generator/loop-detection.ts +81 -0
- package/src/get/generator/models/attribute-model.ts +216 -0
- package/src/get/generator/models/attribute-type-model.ts +448 -0
- package/src/get/generator/models/index.ts +7 -0
- package/src/get/generator/models/resource-model.ts +161 -0
- package/src/get/generator/models/scope.ts +54 -0
- package/src/get/generator/models/struct.ts +116 -0
- package/src/get/generator/module-generator.ts +234 -0
- package/src/get/generator/provider-generator.ts +362 -0
- package/src/get/generator/resource-parser.ts +762 -0
- package/src/get/generator/sanitized-comments.ts +49 -0
- package/src/get/generator/skipped-attributes.ts +27 -0
- package/src/index.ts +40 -0
- package/src/util.ts +26 -0
- package/tsconfig.json +1 -2
|
@@ -0,0 +1,84 @@
|
|
|
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 { TerraformProviderGenerator } from "../../generator/provider-generator";
|
|
6
|
+
import { CodeMaker } from "codemaker";
|
|
7
|
+
import { createTmpHelper } from "../util";
|
|
8
|
+
|
|
9
|
+
const tmp = createTmpHelper();
|
|
10
|
+
|
|
11
|
+
test("broken attribute description comments", async () => {
|
|
12
|
+
const code = new CodeMaker();
|
|
13
|
+
const workdir = tmp("description-escaping.test");
|
|
14
|
+
const spec = JSON.parse(
|
|
15
|
+
fs.readFileSync(
|
|
16
|
+
path.join(
|
|
17
|
+
__dirname,
|
|
18
|
+
"fixtures",
|
|
19
|
+
"description-escaping.test.fixture.json",
|
|
20
|
+
),
|
|
21
|
+
"utf-8",
|
|
22
|
+
),
|
|
23
|
+
);
|
|
24
|
+
new TerraformProviderGenerator(code, spec).generateAll();
|
|
25
|
+
await code.save(workdir);
|
|
26
|
+
|
|
27
|
+
const output = fs.readFileSync(
|
|
28
|
+
path.join(workdir, "providers/google/description-escaping/index.ts"),
|
|
29
|
+
"utf-8",
|
|
30
|
+
);
|
|
31
|
+
expect(output).toMatchSnapshot();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// That popped up in the google-beta provider which transforms markdown fenced
|
|
35
|
+
// code blocks from the actual markdown docs to the provider schema (``` => ''')
|
|
36
|
+
// see
|
|
37
|
+
// - https://raw.githubusercontent.com/hashicorp/terraform-provider-google-beta/4094e3bdd530ca853a046a6d938807f8a131c7c7/website/docs/r/iam_workload_identity_pool_provider.html.markdown
|
|
38
|
+
// - https://github.com/hashicorp/terraform-provider-google-beta/blob/4094e3bdd530ca853a046a6d938807f8a131c7c7/google-beta/resource_iam_beta_workload_identity_pool_provider.go
|
|
39
|
+
|
|
40
|
+
test("malformed code blocks which break in python rst", async () => {
|
|
41
|
+
const code = new CodeMaker();
|
|
42
|
+
const workdir = tmp("markdown-description-with-code-blocks.test");
|
|
43
|
+
const spec = JSON.parse(
|
|
44
|
+
fs.readFileSync(
|
|
45
|
+
path.join(
|
|
46
|
+
__dirname,
|
|
47
|
+
"fixtures",
|
|
48
|
+
"markdown-description-with-code-blocks.test.fixture.json",
|
|
49
|
+
),
|
|
50
|
+
"utf-8",
|
|
51
|
+
),
|
|
52
|
+
);
|
|
53
|
+
new TerraformProviderGenerator(code, spec).generateAll();
|
|
54
|
+
await code.save(workdir);
|
|
55
|
+
|
|
56
|
+
const output = fs.readFileSync(
|
|
57
|
+
path.join(workdir, "providers/aws/code-blocks/index.ts"),
|
|
58
|
+
"utf-8",
|
|
59
|
+
);
|
|
60
|
+
expect(output).toMatchSnapshot();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test("comment ending sequence in comment", async () => {
|
|
64
|
+
const code = new CodeMaker();
|
|
65
|
+
const workdir = tmp("comment-ending-sequence.test");
|
|
66
|
+
const spec = JSON.parse(
|
|
67
|
+
fs.readFileSync(
|
|
68
|
+
path.join(
|
|
69
|
+
__dirname,
|
|
70
|
+
"fixtures",
|
|
71
|
+
"comment-ending-sequence.test.fixture.json",
|
|
72
|
+
),
|
|
73
|
+
"utf-8",
|
|
74
|
+
),
|
|
75
|
+
);
|
|
76
|
+
new TerraformProviderGenerator(code, spec).generateAll();
|
|
77
|
+
await code.save(workdir);
|
|
78
|
+
|
|
79
|
+
const output = fs.readFileSync(
|
|
80
|
+
path.join(workdir, "providers/aws/code-blocks/index.ts"),
|
|
81
|
+
"utf-8",
|
|
82
|
+
);
|
|
83
|
+
expect(output).toMatchSnapshot();
|
|
84
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
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 { TerraformProviderGenerator } from "../../generator/provider-generator";
|
|
6
|
+
import { CodeMaker } from "codemaker";
|
|
7
|
+
import { createTmpHelper } from "../util";
|
|
8
|
+
|
|
9
|
+
const tmp = createTmpHelper();
|
|
10
|
+
|
|
11
|
+
test("provider with no resources", async () => {
|
|
12
|
+
const code = new CodeMaker();
|
|
13
|
+
const workdir = tmp("empty-provider-resources.test");
|
|
14
|
+
const spec = JSON.parse(
|
|
15
|
+
fs.readFileSync(
|
|
16
|
+
path.join(
|
|
17
|
+
__dirname,
|
|
18
|
+
"fixtures",
|
|
19
|
+
"empty-provider-resources.test.fixture.json",
|
|
20
|
+
),
|
|
21
|
+
"utf-8",
|
|
22
|
+
),
|
|
23
|
+
);
|
|
24
|
+
new TerraformProviderGenerator(code, spec).generateAll();
|
|
25
|
+
await code.save(workdir);
|
|
26
|
+
});
|
|
@@ -0,0 +1,169 @@
|
|
|
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 { TerraformProviderGenerator } from "../../generator/provider-generator";
|
|
6
|
+
import { CodeMaker } from "codemaker";
|
|
7
|
+
import { createTmpHelper } from "../util";
|
|
8
|
+
|
|
9
|
+
const tmp = createTmpHelper();
|
|
10
|
+
|
|
11
|
+
// this is a workaround for a bug introduced in TS 3.9.x and seems to be unlikely to get fixed.
|
|
12
|
+
// Since jsii relies on TS < 4 at the moment we can't use newer TS versions which have this fixed (^4.1).
|
|
13
|
+
// see https://github.com/hashicorp/terraform-cdk/pull/1248 for more context
|
|
14
|
+
test("shard exports across multiple files to avoid generating files with more than a 1000 exports", async () => {
|
|
15
|
+
const code = new CodeMaker();
|
|
16
|
+
const workdir = tmp("export-sharding.test");
|
|
17
|
+
|
|
18
|
+
const spec = JSON.parse(
|
|
19
|
+
fs.readFileSync(
|
|
20
|
+
path.join(__dirname, "fixtures", "aws_wafv2_web_acl.test.fixture.json"),
|
|
21
|
+
"utf-8",
|
|
22
|
+
),
|
|
23
|
+
);
|
|
24
|
+
new TerraformProviderGenerator(code, spec).generateAll();
|
|
25
|
+
await code.save(workdir);
|
|
26
|
+
|
|
27
|
+
const output = fs.readFileSync(
|
|
28
|
+
path.join(workdir, "providers/test/wafv2-web-acl/index.ts"),
|
|
29
|
+
"utf-8",
|
|
30
|
+
);
|
|
31
|
+
expect(output).toMatchSnapshot(`wafv2-web-acl-resource`);
|
|
32
|
+
|
|
33
|
+
const outputStructsIndex = fs.readFileSync(
|
|
34
|
+
path.join(workdir, "providers/test/wafv2-web-acl/index-structs/index.ts"),
|
|
35
|
+
"utf-8",
|
|
36
|
+
);
|
|
37
|
+
expect(outputStructsIndex).toMatchSnapshot(`structs-index`);
|
|
38
|
+
|
|
39
|
+
const outputStructs0 = fs.readFileSync(
|
|
40
|
+
path.join(
|
|
41
|
+
workdir,
|
|
42
|
+
"providers/test/wafv2-web-acl/index-structs/structs0.ts",
|
|
43
|
+
),
|
|
44
|
+
"utf-8",
|
|
45
|
+
);
|
|
46
|
+
expect(outputStructs0).toMatchSnapshot(`structs0`);
|
|
47
|
+
|
|
48
|
+
const outputStructs400 = fs.readFileSync(
|
|
49
|
+
path.join(
|
|
50
|
+
workdir,
|
|
51
|
+
"providers/test/wafv2-web-acl/index-structs/structs400.ts",
|
|
52
|
+
),
|
|
53
|
+
"utf-8",
|
|
54
|
+
);
|
|
55
|
+
expect(outputStructs400).toMatchSnapshot(`structs400`);
|
|
56
|
+
|
|
57
|
+
const outputStructs800 = fs.readFileSync(
|
|
58
|
+
path.join(
|
|
59
|
+
workdir,
|
|
60
|
+
"providers/test/wafv2-web-acl/index-structs/structs800.ts",
|
|
61
|
+
),
|
|
62
|
+
"utf-8",
|
|
63
|
+
);
|
|
64
|
+
expect(outputStructs800).toMatchSnapshot(`structs800`);
|
|
65
|
+
|
|
66
|
+
const outputStructs1200 = fs.readFileSync(
|
|
67
|
+
path.join(
|
|
68
|
+
workdir,
|
|
69
|
+
"providers/test/wafv2-web-acl/index-structs/structs1200.ts",
|
|
70
|
+
),
|
|
71
|
+
"utf-8",
|
|
72
|
+
);
|
|
73
|
+
expect(outputStructs1200).toMatchSnapshot(`structs1200`);
|
|
74
|
+
|
|
75
|
+
const outputStructs1600 = fs.readFileSync(
|
|
76
|
+
path.join(
|
|
77
|
+
workdir,
|
|
78
|
+
"providers/test/wafv2-web-acl/index-structs/structs1600.ts",
|
|
79
|
+
),
|
|
80
|
+
"utf-8",
|
|
81
|
+
);
|
|
82
|
+
expect(outputStructs1600).toMatchSnapshot(`structs1600`);
|
|
83
|
+
|
|
84
|
+
const outputStructs2000 = fs.readFileSync(
|
|
85
|
+
path.join(
|
|
86
|
+
workdir,
|
|
87
|
+
"providers/test/wafv2-web-acl/index-structs/structs2000.ts",
|
|
88
|
+
),
|
|
89
|
+
"utf-8",
|
|
90
|
+
);
|
|
91
|
+
expect(outputStructs2000).toMatchSnapshot(`structs2000`);
|
|
92
|
+
|
|
93
|
+
const outputStructs2400 = fs.readFileSync(
|
|
94
|
+
path.join(
|
|
95
|
+
workdir,
|
|
96
|
+
"providers/test/wafv2-web-acl/index-structs/structs2400.ts",
|
|
97
|
+
),
|
|
98
|
+
"utf-8",
|
|
99
|
+
);
|
|
100
|
+
expect(outputStructs2400).toMatchSnapshot(`structs2400`);
|
|
101
|
+
|
|
102
|
+
const outputStructs2800 = fs.readFileSync(
|
|
103
|
+
path.join(
|
|
104
|
+
workdir,
|
|
105
|
+
"providers/test/wafv2-web-acl/index-structs/structs2800.ts",
|
|
106
|
+
),
|
|
107
|
+
"utf-8",
|
|
108
|
+
);
|
|
109
|
+
expect(outputStructs2800).toMatchSnapshot(`structs2800`);
|
|
110
|
+
|
|
111
|
+
const outputStructs3200 = fs.readFileSync(
|
|
112
|
+
path.join(
|
|
113
|
+
workdir,
|
|
114
|
+
"providers/test/wafv2-web-acl/index-structs/structs3200.ts",
|
|
115
|
+
),
|
|
116
|
+
"utf-8",
|
|
117
|
+
);
|
|
118
|
+
expect(outputStructs3200).toMatchSnapshot(`structs3200`);
|
|
119
|
+
|
|
120
|
+
const outputStructs3600 = fs.readFileSync(
|
|
121
|
+
path.join(
|
|
122
|
+
workdir,
|
|
123
|
+
"providers/test/wafv2-web-acl/index-structs/structs3600.ts",
|
|
124
|
+
),
|
|
125
|
+
"utf-8",
|
|
126
|
+
);
|
|
127
|
+
expect(outputStructs3600).toMatchSnapshot(`structs3600`);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
test("shard exports across multiple files to avoid generating files with more than a 1000 exports in a provider without namespaces", async () => {
|
|
131
|
+
const code = new CodeMaker();
|
|
132
|
+
const workdir = tmp("export-sharding-no-namespace.test");
|
|
133
|
+
|
|
134
|
+
const spec = JSON.parse(
|
|
135
|
+
fs.readFileSync(
|
|
136
|
+
path.join(__dirname, "fixtures", "datadog_dashboard.test.fixture.json"),
|
|
137
|
+
"utf-8",
|
|
138
|
+
),
|
|
139
|
+
);
|
|
140
|
+
new TerraformProviderGenerator(code, spec).generateAll();
|
|
141
|
+
await code.save(workdir);
|
|
142
|
+
|
|
143
|
+
const output = fs.readFileSync(
|
|
144
|
+
path.join(workdir, "providers/datadog/dashboard/index.ts"),
|
|
145
|
+
"utf-8",
|
|
146
|
+
);
|
|
147
|
+
expect(output).toMatchSnapshot(`dashboard-resource`);
|
|
148
|
+
|
|
149
|
+
const outputStructsIndex = fs.readFileSync(
|
|
150
|
+
path.join(workdir, "providers/datadog/dashboard/index-structs/index.ts"),
|
|
151
|
+
"utf-8",
|
|
152
|
+
);
|
|
153
|
+
expect(outputStructsIndex).toMatchSnapshot(`structs-index`);
|
|
154
|
+
|
|
155
|
+
const outputStructs0 = fs.readFileSync(
|
|
156
|
+
path.join(workdir, "providers/datadog/dashboard/index-structs/structs0.ts"),
|
|
157
|
+
"utf-8",
|
|
158
|
+
);
|
|
159
|
+
expect(outputStructs0).toMatchSnapshot(`structs0`);
|
|
160
|
+
|
|
161
|
+
const outputStructs400 = fs.readFileSync(
|
|
162
|
+
path.join(
|
|
163
|
+
workdir,
|
|
164
|
+
"providers/datadog/dashboard/index-structs/structs400.ts",
|
|
165
|
+
),
|
|
166
|
+
"utf-8",
|
|
167
|
+
);
|
|
168
|
+
expect(outputStructs400).toMatchSnapshot(`structs400`);
|
|
169
|
+
});
|
|
@@ -0,0 +1,129 @@
|
|
|
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
|
+
});
|