-
Notifications
You must be signed in to change notification settings - Fork 38
feat(actor): adds actor types generation #1000
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
base: master
Are you sure you want to change the base?
feat(actor): adds actor types generation #1000
Conversation
bbaf98e to
dcc207c
Compare
| const { inputSchema, inputSchemaPath } = await readAndValidateInputSchema({ | ||
| forcePath: this.args.path, | ||
| cwd: process.cwd(), | ||
| action: 'Generating types from', | ||
| }); |
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.
generate-type share a validation logic with validate-schema now
| char: 'o', | ||
| description: 'Directory where the generated files should be outputted.', | ||
| required: false, | ||
| default: './.generated/actor/', |
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.
actor templates have typescript setup with only src as include, so you cannot import it right away and you have to adjust it. Maybe better idea is to generate it directly to src/.generated/actor/ ? cc @vladfrangu
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 might be best to discuss with @B4nan and @patrikbraborec too. Or maybe we wanna make it like how prisma handles it? so you'd have @apify/actor in node-modules which gets filled out by the cli?
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.
so you'd have @apify/actor in node-modules which gets filled out by the cli?
I think changed this in v7, because it produced a lot of side effects, e.g. with caching. But we could explore this as well, maybe for our use case it would be fine.
If we won't go that way, I am slightly in favor of putting this into the src folder, the alternative would be dynamically appending the .generated folder to includes in tsconfig. But that would mean you end up with dist/src and dist/.generated if I'm not mistaken, which is a bit ugly (but also rather irrelevant).
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.
fwiw modifying tsconfig can be risky, people may have god knows what setups in their tsconfig files and we shouldn't randomly append our folder.
I think changed this in v7, because it produced a lot of side effects, e.g. with caching. But we could explore this as well, maybe for our use case it would be fine.
Can you help me understand what you mean by this? Did prisma change this or what are you referring to with v7?
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.
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 just came back cuz I read that, holy heck I did not know.... But they also use the top level generated dir by def, interesting
| import { readFile } from 'node:fs/promises'; | ||
|
|
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.
Really just starting point of tests. No complex scenarios.
| }); | ||
|
|
||
| expect(lastErrorMessage()).toMatch(/Generated types written to/); | ||
| expect(lastErrorMessage()).toMatch(/\.generated\/actor\/complex\.ts/); |
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.
use path.join and i think you can do .toInclude or just expect(lastErrorMessage().includes()).toBeTruthy()
| const { lastErrorMessage } = useConsoleSpy(); | ||
|
|
||
| describe('apify actor generate-types', () => { | ||
| const { joinPath, beforeAllCalls, afterAllCalls } = useTempPath('generate-types', { |
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.
Usually this hook is called from the top level, followed by importing the commands with await import, but if it WORKS even like this... fun
Draft summary
output: path to a directory where the files generated should be outputted, default ./.generated/actor/ (actual path in code is gonna be resolve(cwd(), output), followed by mkdir(), then storing in there). char: o
strict: whether generated interfaces should have an index definition ([key: string]: unknown if this is set to false), default true. char: s
[can optionally be done] language: the language to generate the types for (currently only TypeScript, but ideally structure the code in a way where we can easily add in new languages). char: l
[optional, nice to have, can be for future work] [input/output/dataset/key-value-store]-schema: path to a specific schema to generate types for
[don't implement this until we discuss it] add-to-ignore: whether the cli should add the generated files to files like .prettierignore or the biome config, default: false.
tests