-
Notifications
You must be signed in to change notification settings - Fork 8
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: export metadata
object in stage 2
#122
Conversation
import { getStage2Entry } from '../../deno/lib/stage2.ts' | ||
import { virtualRoot } from '../../deno/lib/consts.ts' | ||
|
||
Deno.test('`getStage2Entry` returns a valid stage 2 file', async () => { |
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.
This test was long overdue because we're dynamically generating code so it's good that we validate it as early as possible.
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.
always confused that tests are not colocated with the implementation like in Go 😅
deno/lib/stage2.ts
Outdated
const metadataLines = lines.map(({ metadata, name }) => { | ||
const metadataString = JSON.stringify(metadata) | ||
|
||
return [importLines, exportDeclaration].join('\n\n') | ||
return `"${name}":${metadataString}` | ||
}) | ||
const functionsExport = `export const functions = {${exportLines}};` | ||
const metadataExport = `export const metadata = {${metadataLines}};` |
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.
this scares me a bit. why are you doing this line by line instead of just calling JSON.stringify
on a whole object?
also: did you forget a .join(",")
?
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.
Great point! Updated in 71bed63.
|
||
await Deno.writeTextFile(stage2Path, normalizedStage2) | ||
|
||
const mod = await import(stage2Path) |
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.
wow, importing code in the code that generated it is next level 😄
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 know, right?! 🤯
}), | ||
{}, | ||
) | ||
const functionsExport = `export const functions = {${exportLines}};` |
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.
could you do the same here if you're already on it?
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.
This is not serialisable to JSON, though. The output of this will be something like:
export const functions = {"func1": func0, "func2": func1};
... where func0
and func1
are the imported modules.
I saw the change of moving tests into more organised folders. I do really like structuring all of this a little bit. I remember looking into the code there are files in the src folder that are organised in folders, and some that are not. Maybe it might be interesting in the future to organise the Right now I'd almost say it might be clearer for the Also: total nitpicking here, no prioritisation at all :) |
Good thoughts! Let's iterate on this. |
* feat: export `metadata` object in stage 2 * refactor: simplify metadata generation Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Functionally, this PR adds a
metadata
object to the exports of the stage 2 file. Right now, this object contains just aurl
property containing the file path of each function, like so:This will allow the bootstrap code to match log locations to function names.
Also, it includes some housekeeping:
test/
totest/node/
test/deno/