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: allow extra args to be passed to nextjs cli #4252

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/metal-icons-talk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"blitz": major
---

Allow extra args to be passed to the nextjs cli
3 changes: 3 additions & 0 deletions packages/blitz/src/cli/commands/next/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ const build: CliCommand = async () => {
},
)

const extraArgs = nextArgs["_"].filter((arg) => arg !== "build")

const config: ServerConfig = {
rootFolder: process.cwd(),
inspect: nextArgs["--inspect"],
env: "prod",
extraArgs,
}

await import("../../utils/next-commands").then((i) => i.build(config))
Expand Down
3 changes: 3 additions & 0 deletions packages/blitz/src/cli/commands/next/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ const dev: CliCommand = async () => {
},
)

const extraArgs = nextArgs["_"].filter((arg) => arg !== "dev")

const config: ServerConfig = {
rootFolder: process.cwd(),
port: nextArgs["--port"],
hostname: nextArgs["--hostname"],
inspect: nextArgs["--inspect"],
env: process.env.NODE_ENV === "production" ? "prod" : "dev",
extraArgs,
}

await import("../../utils/next-commands").then((i) => i.dev(config))
Expand Down
3 changes: 3 additions & 0 deletions packages/blitz/src/cli/commands/next/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ const nextExport: CliCommand = async () => {
},
)

const extraArgs = nextArgs["_"].filter((arg) => arg !== "export")

const config: ServerConfig = {
rootFolder: process.cwd(),
...(nextArgs["--outdir"] && {outdir: resolve(nextArgs["--outdir"])}),
env: process.env.NODE_ENV === "production" ? "prod" : "dev",
extraArgs,
}

const getHelp = async () => {
Expand Down
3 changes: 3 additions & 0 deletions packages/blitz/src/cli/commands/next/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ const start: CliCommand = async () => {
},
)

const extraArgs = nextArgs["_"].filter((arg) => arg !== "start")

const config: ServerConfig = {
rootFolder: process.cwd(),
port: nextArgs["--port"],
hostname: nextArgs["--hostname"],
inspect: nextArgs["--inspect"],
env: process.env.NODE_ENV === "production" ? "prod" : "dev",
extraArgs,
Comment on lines +20 to +28
Copy link
Member

Choose a reason for hiding this comment

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

hey thank you! Been wanting this for awhile.

Few things

  • we need to make sure extraArgs is not also including ones we explicitly use (like --inspect)
  • we should remove our use of --hostname and --port while we are here, they are legacy and no longer needed

Copy link
Member

Choose a reason for hiding this comment

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

hi @julianklumpers, are you able to make these changes?

Copy link
Author

Choose a reason for hiding this comment

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

yes, sorry for my late reply. Will try to implement this very soon.

}

await import("../../utils/next-commands").then((i) => i.prod(config))
Expand Down
2 changes: 2 additions & 0 deletions packages/blitz/src/cli/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export type ServerConfig = {
// –
env: ServerEnvironment
// -
extraArgs: string[]
// -
outdir?: string
}

Expand Down
2 changes: 1 addition & 1 deletion packages/blitz/src/cli/utils/next-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function getSpawnEnv(config: ServerConfig) {
}

async function createCommandAndPort(config: ServerConfig, command: string) {
let spawnCommand: string[] = [command]
let spawnCommand: string[] = [command, ...config.extraArgs]
let availablePort: number

availablePort = await detect({port: config.port ? config.port : 3000})
Expand Down
Loading