Skip to content

Commit 0c27ed1

Browse files
Copilotphilmillman
andauthored
Fix @generateTypes producing empty output when schema file has env-like name (#550)
* Initial plan * Fix @generateTypes not including variables when using custom-named schema file as --path entry point Agent-Logs-Url: https://github.com/dmno-dev/varlock/sessions/53e5a64d-4a9e-4f24-9054-1c8ce5e1b690 Co-authored-by: philmillman <3722211+philmillman@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: philmillman <3722211+philmillman@users.noreply.github.com>
1 parent 1e9b6d1 commit 0c27ed1

3 files changed

Lines changed: 39 additions & 1 deletion

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"varlock": patch
3+
---
4+
5+
Fix `@generateTypes` not creating variables when using a custom path with `varlock typegen --path <file>`
6+
7+
When a schema file with an environment-qualifier-like name (e.g. `.env.infra.schema`) was passed as the explicit entry point via `--path`, its variables were being excluded from type generation. The filename was parsed such that `infra` was treated as an environment name (`applyForEnv='infra'`), causing the data source to be marked as environment-specific and all its variables to be filtered out.
8+
9+
The fix ensures that a file loaded as the root entry point (no parent data source) is never treated as environment-specific, even if its filename contains an environment qualifier.

packages/varlock/src/env-graph/lib/data-source.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,11 @@ export abstract class EnvGraphDataSource {
109109
* Note: `applyForEnv` from filename parsing is only relevant for auto-loaded files.
110110
* Explicitly imported files (via `@import`) are controlled by the import mechanism,
111111
* not the auto-load-by-env logic, so their `applyForEnv` is ignored here.
112+
* Similarly, a file that is the explicit root entry point (no parent) is never
113+
* treated as env-specific even if its filename contains an env qualifier.
112114
*/
113115
get isEnvSpecific(): boolean {
114-
if (this.applyForEnv && !this.isImport) return true;
116+
if (this.applyForEnv && !this.isImport && this.parent) return true;
115117
if (this.type === 'overrides') return true;
116118
if (this._hasConditionalDisable) return true;
117119
if (this.importMeta?.isConditionallyEnabled) return true;

packages/varlock/src/env-graph/test/type-generation.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,33 @@ describe('type generation', () => {
196196
expect(extrasSource).toBeDefined();
197197
expect(extrasSource!.isEnvSpecific).toBe(false);
198198
});
199+
200+
test('root entry file with env-like name (e.g. .env.infra.schema) is NOT isEnvSpecific', async () => {
201+
// Regression test for: @generateTypes doesn't create variables when using
202+
// a custom path with `varlock typegen --path .env.infra.schema`
203+
// The filename `.env.infra.schema` was being parsed such that applyForEnv='infra',
204+
// causing isEnvSpecific=true and all items being excluded from type generation.
205+
const g = new EnvGraph();
206+
await g.setRootDataSource(new DotEnvFileDataSource('.env.infra.schema', {
207+
overrideContents: outdent`
208+
# @defaultSensitive=false
209+
# ---
210+
TEST_A_B="1"
211+
TEST_A_C="1"
212+
`,
213+
}));
214+
await g.finishLoad();
215+
216+
// The root source should NOT be marked as env-specific
217+
const rootSource = g.rootDataSource!;
218+
expect(rootSource.isEnvSpecific).toBe(false);
219+
220+
// Items should be included in defsForTypeGeneration
221+
expect(g.configSchema.TEST_A_B).toBeDefined();
222+
expect(g.configSchema.TEST_A_B.defsForTypeGeneration.length).toBeGreaterThan(0);
223+
expect(g.configSchema.TEST_A_C).toBeDefined();
224+
expect(g.configSchema.TEST_A_C.defsForTypeGeneration.length).toBeGreaterThan(0);
225+
});
199226
});
200227

201228
describe('getTypeGenInfo - basic schema properties', () => {

0 commit comments

Comments
 (0)