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
[legacy-framework] refactor(server): Added isTypescript explicit flag, config refactored #1014
Conversation
Hey @svobik7 Thanks for this! I will need a couple of days to look at this properly. Looks good so far. |
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 kind of question why we are adding a flag here and if that is really worth it from a devx perspective? Also it is kind of hard to explain what it is doing and I am not really convinced we need to do it.
packages/server/src/config.ts
Outdated
const git = parseChokidarRulesFromGitignore(resolve(process.cwd(), config.rootFolder)) | ||
export async function normalize( | ||
config: ServerConfig, | ||
dev: boolean = false, |
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.
Any reason why not just add dev
to ServerConfig
?
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 is no special reason for this. It could definitely be inside ServerConfig
. In that case I suggest to use it like following:
export type ServerConfig = {
env: "dev" | "prod"
...
}
While 'prod' is default. What do you think?
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.
Works for me
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.
Done in current commit
packages/server/src/config.ts
Outdated
} | ||
} | ||
|
||
async function getNextBin(rootFolder: string, dev: boolean = false) { |
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.
Good work putting these together
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.
Thank you 👍
packages/cli/src/commands/start.ts
Outdated
@@ -24,17 +18,19 @@ export class Start extends Command { | |||
char: "H", | |||
description: "Set server hostname", | |||
}), | |||
ts: flags.boolean({ | |||
description: "Use typescript explicitly (just for performance optimization)", | |||
}), |
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.
Is this really actually necessary? Seems like a slightly redundant feature when we are only avoiding a fs read at the start of a cli process
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.
The main reason was to find a way to avoid fs.existsSync
called in config.ts which just checks if tsconfig.json
file exists. I was thinking like following:
- As a newcomer to blitz I want to create and start my application with almost zero-config so I run
blitz start
and everything works as expected. - Once I settled my initial code base (js, ts) I want to avoid any unnecessary "delays" in dev process. So I have got an option to tell blitz "hey I am using TS, do not check it on your own" by running
blitz start --ts
.
Also this flag can be used in different commands (generate, console) to avoid checking ts implicitly. But honestly I did not make any perf tests and cannot say now if it is worth. So I do not have any compelling reason to keep this flag right now.
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 think there are other way more expensive things we are doing as the command starts up that are going to be slower than one file stats read especially if we do any file pipeline work.
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.
Removed in current commit
packages/server/src/config.ts
Outdated
|
||
async function getIsTypescript(rootFolder: string) { | ||
const fs = await import("fs") | ||
return fs.existsSync(join(rootFolder, "tsconfig.json")) |
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 doesn't really matter as it is not in stream but why not use a promisified exists
function like you might from using promisify with fs.exists. If we had to run concurrent processes later that needed this function it wouldn't block the thread that way also why not just import fs up top?
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.
- Importing
fs
on top: this is related to--ts
flag. Once I was thinking about avoidingfs.existsSync
I was already thinking aboutdo not import anything unnecessary if you know typescript is set explicitly
. - existsSync: it could be definitely done with promisified
exists
I see now not importing fs
approach is not very benefical hera as fs
imported already for other reasons. So I agree to use promisified check and import from fs directly would be better.
I am gonna update this, ok?
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.
Done in current commit
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.
Looks good to me. I removed the reference to --ts config option in the PR description.
|
||
async function getIsTypescript(rootFolder: string): Promise<boolean> { | ||
try { | ||
await promises.access(join(rootFolder, "tsconfig.json")) |
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 PR exists just because of initial idea (#941) of refactoring server config and try to make them cacheable and in the same time drop the need of prop drilling. As initial idea of caching leads to no benefits this PR just brings some config refactors, code cleanup and small perf optimization flag in server package.
What are the changes and their implications?
isTypescript
prop just in server config and server package and removes it from file pipelines package