Skip to content
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

Merged
merged 3 commits into from Sep 11, 2020

Conversation

svobik7
Copy link
Collaborator

@svobik7 svobik7 commented Sep 6, 2020

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?

  • keeps isTypescript prop just in server config and server package and removes it from file pipelines package
  • removes waiting for both next bin and patched bin as we do not switch between dev/prod in runtime
  • removes some unnecessary lines and clean up the config code

@blitzjs-bot blitzjs-bot bot added this to In Review in Dashboard Sep 6, 2020
@ryardley
Copy link
Collaborator

ryardley commented Sep 6, 2020

Hey @svobik7 Thanks for this! I will need a couple of days to look at this properly. Looks good so far.

Copy link
Collaborator

@ryardley ryardley left a 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.

const git = parseChokidarRulesFromGitignore(resolve(process.cwd(), config.rootFolder))
export async function normalize(
config: ServerConfig,
dev: boolean = false,
Copy link
Collaborator

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?

Copy link
Collaborator Author

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?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in current commit

}
}

async function getNextBin(rootFolder: string, dev: boolean = false) {
Copy link
Collaborator

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you 👍

@@ -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)",
}),
Copy link
Collaborator

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

Copy link
Collaborator Author

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.

Copy link
Collaborator

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in current commit


async function getIsTypescript(rootFolder: string) {
const fs = await import("fs")
return fs.existsSync(join(rootFolder, "tsconfig.json"))
Copy link
Collaborator

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?

Copy link
Collaborator Author

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 avoiding fs.existsSync I was already thinking about do 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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in current commit

Copy link
Collaborator

@ryardley ryardley left a 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"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@flybayer flybayer merged commit 280a2b5 into blitz-js:canary Sep 11, 2020
Dashboard automation moved this from In Review to Done Sep 11, 2020
@dillondotzip dillondotzip changed the title refactor(server): Added isTypescript explicit flag, config refactored [legacy-framework] refactor(server): Added isTypescript explicit flag, config refactored Jul 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants