Skip to content

Commit 32e8589

Browse files
committed
Search through untracked files for graphql-tag. Don't error out on files that can't be found.
1 parent 4a4aebd commit 32e8589

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

.changeset/spicy-bugs-wave.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@khanacademy/graphql-flow': patch
3+
---
4+
5+
Search through untracked files for graphql-tag. Don't error out on files that can't be found.

src/cli/run.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,11 @@ import {dirname} from 'path';
3232
/** Step (1) */
3333

3434
const findGraphqlTagReferences = (root: string): Array<string> => {
35+
// NOTE(john): We want to include untracked files here so that we can
36+
// generate types for them. This is useful for when we have a new file
37+
// that we want to generate types for, but we haven't committed it yet.
3538
const response = execSync(
36-
"git grep -I --word-regexp --name-only --fixed-strings 'graphql-tag' -- '*.js' '*.jsx' '*.ts' '*.tsx'",
39+
"git grep -I --word-regexp --name-only --fixed-strings --untracked 'graphql-tag' -- '*.js' '*.jsx' '*.ts' '*.tsx'",
3740
{
3841
encoding: 'utf8',
3942
cwd: root,

src/parser/parse.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ const listExternalReferences = (file: FileResult): Array<string> => {
105105
if (v.type === 'import') {
106106
if (followImports) {
107107
const absPath = getPathWithExtension(v.path);
108-
paths[absPath] = true;
108+
if (absPath) {
109+
paths[absPath] = true;
110+
}
109111
}
110112
} else {
111113
v.source.expressions.forEach((expr) => add(expr, true));

src/parser/utils.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,8 @@ export const getPathWithExtension = (pathWithoutExtension: string): string => {
2020
if (fs.existsSync(pathWithoutExtension + '.ts')) {
2121
return pathWithoutExtension + '.ts';
2222
}
23-
throw new Error("Can't find file at " + pathWithoutExtension);
23+
// NOTE(john): This is a bit of a hack, but it's necessary for when we
24+
// have a file that doesn't have an extension. This will happen when we
25+
// delete all of the type files before re-running graphql-flow again.
26+
return "";
2427
};

0 commit comments

Comments
 (0)