Skip to content

Commit f12270b

Browse files
committed
feat: supports providing a string as 'augmentModule'
1 parent 3a3c3ed commit f12270b

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

app-config-generate/src/index.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,25 @@ describe('TypeScript File Generation', () => {
181181
},
182182
);
183183
});
184+
185+
it('augements specific module name', async () => {
186+
await withTempFiles(
187+
{
188+
'.app-config.meta.yml': `
189+
generate:
190+
- file: generated.d.ts
191+
augmentModule: foo-bar
192+
`,
193+
'.app-config.schema.yml': ``,
194+
},
195+
async (inDir) => {
196+
await generateTypeFiles({ directory: inDir('.') });
197+
const config = await readFile(inDir('generated.d.ts')).then((v) => v.toString());
198+
199+
expect(config).toMatch(`declare module 'foo-bar'`);
200+
},
201+
);
202+
});
184203
});
185204

186205
describe('Flow File Generation', () => {

app-config-generate/src/index.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export async function generateQuicktype(
5858
schema: JSONSchema,
5959
type: string,
6060
name: string,
61-
augmentModule: boolean = true,
61+
augmentModule: boolean | string = true,
6262
leadingCommentsOverride?: string[],
6363
rendererOptions: RendererOptions = {},
6464
): Promise<string[]> {
@@ -108,7 +108,7 @@ export async function generateQuicktype(
108108
lines.push(`export interface ${name} {}\n`);
109109
}
110110

111-
if (augmentModule !== false) {
111+
if (augmentModule === true) {
112112
lines.push(
113113
...[
114114
'// augment the default export from app-config',
@@ -119,6 +119,19 @@ export async function generateQuicktype(
119119
);
120120
}
121121

122+
if (typeof augmentModule === 'string') {
123+
lines.push(
124+
...[
125+
'// augment the default export from app-config',
126+
`declare module '${augmentModule}' {`,
127+
` export * from '@app-config/main';`,
128+
` export { default } from '@app-config/main';`,
129+
` export interface ExportedConfig extends ${name} {}`,
130+
'}',
131+
],
132+
);
133+
}
134+
122135
return (
123136
lines
124137
// this is a fix for quicktype, which adds an Object postfix, sometimes

0 commit comments

Comments
 (0)