Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search through untracked files for graphql-tag. Don't error out on files that can't be found. #66

Merged
merged 2 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 .changeset/spicy-bugs-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@khanacademy/graphql-flow': patch
---

Search through untracked files for graphql-tag. Don't error out on files that can't be found.
5 changes: 4 additions & 1 deletion src/cli/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ import {dirname} from 'path';
/** Step (1) */

const findGraphqlTagReferences = (root: string): Array<string> => {
// NOTE(john): We want to include untracked files here so that we can
// generate types for them. This is useful for when we have a new file
// that we want to generate types for, but we haven't committed it yet.
Comment on lines +35 to +37
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: Thanks for the comment.

const response = execSync(
"git grep -I --word-regexp --name-only --fixed-strings 'graphql-tag' -- '*.js' '*.jsx' '*.ts' '*.tsx'",
"git grep -I --word-regexp --name-only --fixed-strings --untracked 'graphql-tag' -- '*.js' '*.jsx' '*.ts' '*.tsx'",
{
encoding: 'utf8',
cwd: root,
Expand Down
4 changes: 3 additions & 1 deletion src/parser/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ const listExternalReferences = (file: FileResult): Array<string> => {
if (v.type === 'import') {
if (followImports) {
const absPath = getPathWithExtension(v.path);
paths[absPath] = true;
if (absPath) {
paths[absPath] = true;
}
}
} else {
v.source.expressions.forEach((expr) => add(expr, true));
Expand Down
5 changes: 4 additions & 1 deletion src/parser/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,8 @@ export const getPathWithExtension = (pathWithoutExtension: string): string => {
if (fs.existsSync(pathWithoutExtension + '.ts')) {
return pathWithoutExtension + '.ts';
}
throw new Error("Can't find file at " + pathWithoutExtension);
// NOTE(john): This is a bit of a hack, but it's necessary for when we
// have a file that doesn't have an extension. This will happen when we
// delete all of the type files before re-running graphql-flow again.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: What is the side-effect of doing this? Can you elaborate in the comment on why this will "just work"? Or perhaps add a comment in the parse.ts code that explains what an empty string means?

return "";
};
Loading