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

enhancement(dev/cli): Add --port flag to remix dev #3447

Merged
merged 1 commit into from
Jun 11, 2022
Merged
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
1 change: 1 addition & 0 deletions packages/remix-dev/__tests__/cli-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ describe("remix CLI", () => {
--sourcemap Generate source maps for production
\`dev\` Options:
--debug Attach Node.js inspector
--port, -p Choose the port from which to run your app
\`routes\` Options:
--json Print the routes as JSON
\`migrate\` Options:
Expand Down
12 changes: 10 additions & 2 deletions packages/remix-dev/cli/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,11 @@ export async function watch(
});
}

export async function dev(remixRoot: string, modeArg?: string) {
export async function dev(
remixRoot: string,
modeArg?: string,
portArg?: number
) {
Comment on lines +237 to +241
Copy link
Member

Choose a reason for hiding this comment

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

If we need to add one more arg to this in the future let's turn this into a single options argument.

let createApp: typeof createAppType;
let express: typeof Express;
try {
Expand All @@ -255,7 +259,11 @@ export async function dev(remixRoot: string, modeArg?: string) {
await loadEnv(config.rootDirectory);

let port = await getPort({
port: process.env.PORT ? Number(process.env.PORT) : makeRange(3000, 3100),
port: portArg
? Number(portArg)
: process.env.PORT
? Number(process.env.PORT)
: makeRange(3000, 3100),
});

if (config.serverEntryPoint) {
Expand Down
9 changes: 7 additions & 2 deletions packages/remix-dev/cli/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ ${colors.heading("Options")}:
--sourcemap Generate source maps for production
\`dev\` Options:
--debug Attach Node.js inspector
--port, -p Choose the port from which to run your app
\`routes\` Options:
--json Print the routes as JSON
\`migrate\` Options:
Expand Down Expand Up @@ -126,10 +127,13 @@ const npxInterop = {
pnpm: "pnpm exec",
};

async function dev(projectDir: string, flags: { debug?: boolean }) {
async function dev(
projectDir: string,
flags: { debug?: boolean; port?: number }
) {
if (!process.env.NODE_ENV) process.env.NODE_ENV = "development";
if (flags.debug) inspector.open();
await commands.dev(projectDir, process.env.NODE_ENV);
await commands.dev(projectDir, process.env.NODE_ENV, flags.port);
}

/**
Expand Down Expand Up @@ -157,6 +161,7 @@ export async function run(argv: string[] = process.argv.slice(2)) {
install: { type: "boolean" },
json: { type: "boolean" },
migration: { type: "string", alias: "m" },
port: { type: "number", alias: "p" },
remixVersion: { type: "string" },
sourcemap: { type: "boolean" },
template: { type: "string" },
Expand Down