-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build out a cli tool that does our own parsing of javascript files, d…
…ramatically speeding things up! (#20) Summary: Using jest, it was taking 25 seconds to run everything, and using this custom parser, it only takes 6! Much more reasonable. And we could also likely improve things further by only processing operations in files that have been edited. Issue: https://khanacademy.atlassian.net/browse/FEI-4426 Test plan: `yarn jest`, also ran this on all of webapp and it produced the same types as the jest version! And great coverage! ``` ---------------------------------|---------|----------|---------|--------- File | % Stmts | % Branch | % Funcs | % Lines ---------------------------------|---------|----------|---------|--------- src/parser | 97.12 | 80.55 | 100 | 97.09 parse.js | 97.65 | 78.22 | 100 | 97.61 resolve.js | 95.65 | 95 | 100 | 95.65 ---------------------------------|---------|----------|---------|--------- ``` Author: jaredly Reviewers: jaredly, benchristel, kevinbarabash, jeremywiebe Required Reviewers: Approved By: benchristel, jeremywiebe Checks: ✅ Lint & Test (ubuntu-latest, 16.x) Pull Request URL: #20
- Loading branch information
Showing
13 changed files
with
1,216 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@khanacademy/graphql-flow': minor | ||
--- | ||
|
||
Build out a cli tool that does our own parsing of javascript files, dramatically speeding things up! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
node_modules | ||
coverage | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/__test__/jest-mock-graphql-tag.test.js → src/__test__/processPragmas.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// @flow | ||
import type {ExternalOptions} from '../generateTypeFiles'; | ||
|
||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
export type CliConfig = { | ||
excludes: Array<RegExp>, | ||
schemaFilePath: string, | ||
options: ExternalOptions, | ||
}; | ||
|
||
/** | ||
* This is the json-compatible form of the config | ||
* object. | ||
*/ | ||
type JSONConfig = { | ||
excludes?: Array<string>, | ||
schemaFilePath: string, | ||
options?: ExternalOptions, | ||
}; | ||
|
||
export const loadConfigFile = (configFile: string): CliConfig => { | ||
// eslint-disable-next-line flowtype-errors/uncovered | ||
const data: JSONConfig = JSON.parse(fs.readFileSync(configFile, 'utf8')); | ||
const toplevelKeys = ['excludes', 'schemaFilePath', 'options']; | ||
Object.keys(data).forEach((k) => { | ||
if (!toplevelKeys.includes(k)) { | ||
throw new Error( | ||
`Invalid attribute in config file ${configFile}: ${k}. Allowed attributes: ${toplevelKeys.join( | ||
', ', | ||
)}`, | ||
); | ||
} | ||
}); | ||
if (data.options) { | ||
const externalOptionsKeys = [ | ||
'pragma', | ||
'loosePragma', | ||
'ignorePragma', | ||
'scalars', | ||
'strictNullability', | ||
'regenerateCommand', | ||
'readOnlyArray', | ||
]; | ||
Object.keys(data.options).forEach((k) => { | ||
if (!externalOptionsKeys.includes(k)) { | ||
throw new Error( | ||
`Invalid option in config file ${configFile}: ${k}. Allowed options: ${externalOptionsKeys.join( | ||
', ', | ||
)}`, | ||
); | ||
} | ||
}); | ||
} | ||
return { | ||
options: data.options ?? {}, | ||
excludes: data.excludes?.map((string) => new RegExp(string)) ?? [], | ||
schemaFilePath: path.join( | ||
path.dirname(configFile), | ||
data.schemaFilePath, | ||
), | ||
}; | ||
}; |
Oops, something went wrong.