Skip to content

Commit

Permalink
enhancement(cli): Add --port flag to remix dev (#3447)
Browse files Browse the repository at this point in the history
  • Loading branch information
chaance authored Jun 11, 2022
1 parent 0004317 commit cc9e5c3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
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
) {
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 @@ -40,6 +40,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 @@ -124,10 +125,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 @@ -155,6 +159,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

0 comments on commit cc9e5c3

Please sign in to comment.