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

Feat: Add a way to detect if a file is run by deno serve or deno run #25179

Open
ArmaanAS opened this issue Aug 23, 2024 · 1 comment
Open

Feat: Add a way to detect if a file is run by deno serve or deno run #25179

ArmaanAS opened this issue Aug 23, 2024 · 1 comment
Labels
cli related to cli/ dir suggestion suggestions for new features (yet to be agreed)

Comments

@ArmaanAS
Copy link
Contributor

Add a way to detect if a file is run by deno serve or deno run.

Maybe add a variable like Deno.subcommand which has the type

declare namespace Deno {
  export const subcommand: "run" | "serve" | "task" | "test" | "bench" | "jupyter" | "repl" | "eval" | "install" | "uninstall" | "add" | "remove";
}

In production I want to use deno serve --parallel but locally I want to to use Deno.serve(). The reason is a bit complicated but basically my default export takes 5-10 seconds before it's exported which delays deno serve starting the server by over 5 seconds, however using Deno.serve() allows me to start the server almost instantly. In production I don't have the delay.

(N.B. I can't switch to deno serve at all because of this blocker #24099 but I want to!.)

@littledivy littledivy added cli related to cli/ dir suggestion suggestions for new features (yet to be agreed) labels Aug 23, 2024
@CyanChanges
Copy link
Contributor

@ArmaanAS @littledivy Can you provide an example of how to use this variable? It should be a static variable that can be accessed from anywhere in the code or part of a trait.

It should be like this.

if (Deno.subcommand === "serve") {

} else {
  
}

I'll do it.

So, is there any update on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli related to cli/ dir suggestion suggestions for new features (yet to be agreed)
Projects
None yet
Development

No branches or pull requests

3 participants