Skip to content

Commit 448eea8

Browse files
committed
Remove redundant ../.. traversal test and unused schemaDir param
1 parent 1dfd55b commit 448eea8

File tree

2 files changed

+21
-82
lines changed

2 files changed

+21
-82
lines changed

packages/generate/src/queries.ts

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { type CommandOptions } from "./commandutil";
55
import { headerComment } from "./genutil";
66
import type { Target } from "./genutil";
77

8-
const { walk, readFileUtf8 } = systemUtils;
8+
const { readFileUtf8 } = systemUtils;
99

1010
// generate per-file queries
1111
// generate queries in a single file
@@ -42,7 +42,6 @@ currently supported.`);
4242
console.log(`Detected schema directory: ${params.schemaDir}`);
4343
const matches = await getMatches(
4444
root,
45-
params.schemaDir,
4645
params.options.patterns,
4746
);
4847
if (matches.length === 0) {
@@ -97,8 +96,7 @@ currently supported.`);
9796
);
9897
if (!wasError) {
9998
console.log(
100-
`Generating query file${
101-
Object.keys(filesByExtension).length > 1 ? "s" : ""
99+
`Generating query file${Object.keys(filesByExtension).length > 1 ? "s" : ""
102100
}...`,
103101
);
104102
for (const [extension, file] of Object.entries(filesByExtension)) {
@@ -113,7 +111,7 @@ currently supported.`);
113111
await fs.writeFile(
114112
filePath,
115113
headerComment +
116-
`${stringifyImports(file.imports)}\n\n${file.contents}`,
114+
`${stringifyImports(file.imports)}\n\n${file.contents}`,
117115
);
118116
}
119117
}
@@ -167,39 +165,28 @@ export function stringifyImports(imports: ImportMap) {
167165

168166
async function getMatches(
169167
root: string,
170-
schemaDir: string,
171168
patterns?: string[],
172169
) {
173-
if (patterns && patterns.length > 0) {
174-
// Use globby to match files with the provided patterns
175-
const { globby } = await import("globby");
176-
177-
const allFiles = await globby(patterns, {
178-
cwd: process.cwd(),
179-
absolute: true,
180-
onlyFiles: true,
181-
expandDirectories: {
182-
extensions: ["edgeql"],
183-
},
184-
ignore: [
185-
"node_modules/**",
186-
`${schemaDir}/migrations/**`,
187-
`${schemaDir}/fixups/**`,
188-
],
189-
});
190-
191-
return allFiles;
192-
}
193-
194-
// Default behavior - walk all files
195-
return walk(root, {
196-
match: [/[^/]\.edgeql$/],
197-
skip: [
198-
/node_modules/,
199-
RegExp(`${schemaDir}\\${path.sep}migrations`),
200-
RegExp(`${schemaDir}\\${path.sep}fixups`),
170+
// Single code path using globby for both cases
171+
const { globby } = await import("globby");
172+
173+
const searchPatterns = patterns && patterns.length > 0 ? patterns : ["."];
174+
175+
const allFiles = await globby(searchPatterns, {
176+
cwd: root,
177+
absolute: true,
178+
onlyFiles: true,
179+
expandDirectories: {
180+
extensions: ["edgeql"],
181+
},
182+
ignore: [
183+
"node_modules/**",
184+
`**/migrations/**`,
185+
`**/fixups/**`,
201186
],
202187
});
188+
189+
return allFiles;
203190
}
204191

205192
// const targetToExtension: {[k in Target]: string} = {

packages/generate/test/cli.test.ts

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -157,54 +157,6 @@ describe("cli", () => {
157157
}
158158
});
159159

160-
test("pattern traversal up excludes schema directories", () => {
161-
const cleanup = (file: string) => {
162-
try {
163-
fs.unlinkSync(file);
164-
} catch (e) {}
165-
};
166-
167-
const cleanupDir = (dir: string) => {
168-
try {
169-
fs.rmSync(dir, { recursive: true, force: true });
170-
} catch (e) {}
171-
};
172-
173-
// Create subdirectory structure
174-
const subDir = path.resolve(QBDIR, "apps", "backend");
175-
fs.mkdirSync(subDir, { recursive: true });
176-
177-
// Create schema files at project root that should be ignored
178-
const schemaDir = path.resolve(QBDIR, "dbschema");
179-
const migrationsDir = path.resolve(schemaDir, "migrations");
180-
fs.mkdirSync(migrationsDir, { recursive: true });
181-
182-
const migrationFile = path.resolve(migrationsDir, "bad.edgeql");
183-
const goodFile = path.resolve(QBDIR, "good2.edgeql");
184-
185-
fs.writeFileSync(migrationFile, "CREATE TYPE Bad;");
186-
fs.writeFileSync(goodFile, "SELECT 123;");
187-
188-
try {
189-
// Run from subdirectory with "../.." pattern - should ignore schema
190-
const cliPath = path.resolve(QBDIR, "dist", "cli.js");
191-
execSync(`"${cliPath}" queries "../.."`, {
192-
stdio: "inherit",
193-
cwd: subDir,
194-
});
195-
196-
// Verify good file processed, schema file ignored
197-
assert.ok(fs.existsSync(path.resolve(QBDIR, "good2.query.ts")));
198-
assert.ok(!fs.existsSync(path.resolve(migrationsDir, "bad.query.ts")));
199-
} finally {
200-
// Cleanup
201-
[migrationFile, goodFile, path.resolve(QBDIR, "good2.query.ts")].forEach(
202-
cleanup,
203-
);
204-
[migrationsDir, path.resolve(QBDIR, "apps")].forEach(cleanupDir);
205-
}
206-
});
207-
208160
test("absolute pattern paths work correctly", () => {
209161
// Create temp directory with test files
210162
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "gel-test-"));

0 commit comments

Comments
 (0)