-
Notifications
You must be signed in to change notification settings - Fork 6
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
feat apilinks.json generator #153
base: main
Are you sure you want to change the base?
Conversation
@flakey5 do you need review here? I think I forgot to review this PR! |
As far as the approach yes please |
.filter(path => path !== undefined && path.endsWith('.js')) | ||
); | ||
|
||
const parsedJsFiles = await parseJsSources(sourceFiles); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this process needs to be blocking? Do we need to parse all these sources beforehand and not on-demand?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need too, this is just consistent to how to we parse markdown sources. We could definitely just store the paths of the sources and parse them in the generator instead though. It'd definitely lower the amount of memory that's allocated for the lifetime of the program
@@ -0,0 +1,215 @@ | |||
// @ts-check |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Temporary comment just enabling type checking in the file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder how expensive these functions are, as it seems that this can quickly get bloated depending on the size of source files.
BTW, could you use https://unifiedjs.com/explore/package/estree-util-visit/ to walk/visit the nodes? This is what I was referring to, instead of plain forEaches and while loops.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, it might be worth to move "estree" moving logic to a dedicated "estree parser" IDK
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we have a parser for the Markdown files, having one just for Estree makes sense I guess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about having a createMarkdownLoader
and createJsLoader
? Then the same with createMarkdownParser
and createJsParser
return filePaths.map(async filePath => { | ||
const fileContents = await readFile(filePath, 'utf-8'); | ||
|
||
return new VFile({ path: filePath, value: fileContents }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am a bit concerned of the memory allocation that this will cause, some of the source files can be humungous. Have you made some comparisons of heap size differences?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approach in general sounds good; Just, some of these utilities are way too complex and big and the git manipulation scripts are possibly dangerous or at least an easy vulnerability hell.
Also, @flakey5 this https://github.com/syntax-tree/estree-util-visit is what I was referring to use to walk through the Nodes of the source code. Since acorn generates an AST that is compatible with estree. |
Closes #152 Signed-off-by: flakey5 <[email protected]>
Co-authored-by: Claudio W <[email protected]>
Signed-off-by: flakey5 <[email protected]>
Closes #152
Opening this as a draft currently to get feedback on the approach since it's a bit non-trivial relative to the other generators.Theapilinks.json
file maps things exported by modules to their source locations on Github.Example:
This means we need to parse the module's javascript source in addition to its markdown.
What the current approach does is doing:
acorn
is used for parsing the source files.js
files, so to run it you need to do pass innode/lib/*.js
as the inputThis is dependent on the Markdown source parsing since it uses thesource_link
metadata in the docsast-js
generatorapi-links
generator is based off of theast-js
result