Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .bumpy/fix-directory-import-filters.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
varlock: patch
---

Apply pick and omit filters to directory imports.
4 changes: 1 addition & 3 deletions packages/varlock/src/env-graph/lib/data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,9 +535,7 @@ export abstract class EnvGraphDataSource {
if (fsStat.isDirectory()) {
// eslint-disable-next-line no-use-before-define
const dirChild = new DirectoryDataSource(fullImportPath);
await this.addChild(dirChild, {
isImport: true, importKeys, isConditionallyEnabled,
});
await this.addChild(dirChild, importMeta);
this.graph.recordLoadedImportPath(fullImportPath, dirChild);
} else {
this._errors.push(new LoadingError(`Imported path ending with "/" is not a directory: ${fullImportPath}`));
Expand Down
27 changes: 27 additions & 0 deletions packages/varlock/src/env-graph/test/import.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {
describe, test, expect, vi,
} from 'vitest';
import fs from 'node:fs/promises';
import os from 'node:os';
import path from 'node:path';
import outdent from 'outdent';
import { EnvGraph, DirectoryDataSource, LoadingError } from '../index';
Expand Down Expand Up @@ -150,6 +152,31 @@ describe('@import', () => {
});

describe('pick / omit filters', () => {
test.each([
['pick', 'pick=[FOO]'],
['omit', 'omit=[BAR]'],
])('%s filters keys from real filesystem directory imports', async (_filterName, filterArg) => {
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'varlock-directory-import-filter-'));
const appDir = path.join(tempDir, 'app');
const sharedDir = path.join(tempDir, 'shared');

try {
await fs.mkdir(appDir);
await fs.mkdir(sharedDir);
await fs.writeFile(path.join(appDir, '.env.schema'), `# @import(../shared/, ${filterArg})\n# ---\n`);
await fs.writeFile(path.join(sharedDir, '.env.schema'), 'FOO=foo\nBAR=bar\n');

const g = new EnvGraph();
await g.setRootDataSource(new DirectoryDataSource(appDir));
await g.finishLoad();

expect(g.sortedDataSources.flatMap((source) => source.errors).filter((error) => !error.isWarning)).toEqual([]);
expect(Object.keys(g.configSchema)).toEqual(['FOO']);
} finally {
await fs.rm(tempDir, { recursive: true, force: true });
}
});

test('pick=[...] only imports listed keys', envFilesTest({
files: {
'.env.schema': outdent`
Expand Down
Loading