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(remix-dev/cli): add --debug-binding flag #4325

Closed
wants to merge 3 commits into from
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
7 changes: 5 additions & 2 deletions docs/other-api/dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,12 @@ The same as `watch`, but also boots the [Remix App Server][remix-app-server] in
remix dev
```

### `remix dev --debug`
### `remix dev --debug [--debug-binding]`

Attaches a [Node inspector][node-inspector] to develop your app in debug mode.
Attaches a [Node inspector][node-inspector] to develop your app in debug
mode. By default, the host is set to `127.0.0.1` and the port is set to
`9229`. Using the `--debug-binding` allows you to set a custom host and port.
For example, `remix dev --debug --debug-binding 0.0.0.0:9229`.

### `remix dev --port`

Expand Down
2 changes: 2 additions & 0 deletions packages/remix-dev/__tests__/cli-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ describe("remix CLI", () => {
--sourcemap Generate source maps for production
\`dev\` Options:
--debug Attach Node.js inspector
--debug-binding Choose the Node.js inspector host and port
--port, -p Choose the port from which to run your app
\`init\` Options:
--no-delete Skip deleting the \`remix.init\` script
Expand Down Expand Up @@ -169,6 +170,7 @@ describe("remix CLI", () => {
$ remix dev
$ remix dev my-app
$ remix dev --debug
$ remix dev --debug-binding 0.0.0.0:9229

Start your server separately and watch for changes:

Expand Down
29 changes: 26 additions & 3 deletions packages/remix-dev/cli/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ ${colors.logoBlue("R")} ${colors.logoGreen("E")} ${colors.logoYellow(
--sourcemap Generate source maps for production
\`dev\` Options:
--debug Attach Node.js inspector
--debug-binding Choose the Node.js inspector host and port
--port, -p Choose the port from which to run your app
\`init\` Options:
--no-delete Skip deleting the \`remix.init\` script
Expand Down Expand Up @@ -96,6 +97,7 @@ ${colors.logoBlue("R")} ${colors.logoGreen("E")} ${colors.logoYellow(
$ remix dev
$ remix dev my-app
$ remix dev --debug
$ remix dev --debug-binding 0.0.0.0:9229

${colors.heading("Start your server separately and watch for changes")}:

Expand Down Expand Up @@ -139,12 +141,28 @@ const npxInterop = {

async function dev(
projectDir: string,
flags: { debug?: boolean; port?: number; appServerPort?: number }
flags: {
debug?: boolean;
debugBinding?: string;
port?: number;
appServerPort?: number;
}
) {
console.log("-----DEV FUNCTION------");
if (!process.env.NODE_ENV) process.env.NODE_ENV = "development";

if (flags.debug) inspector.open();
await commands.dev(projectDir, process.env.NODE_ENV, flags);
if (flags.debug) {
if (flags.debugBinding) {
let [host, port] = flags.debugBinding?.split(":");
inspector.open(parseInt(port), host);
} else {
inspector.open();
}
}
await commands.dev(projectDir, process.env.NODE_ENV, {
port: flags.port,
appServerPort: flags.appServerPort,
});
}

/**
Expand All @@ -164,6 +182,7 @@ export async function run(argv: string[] = process.argv.slice(2)) {
{
"--app-server-port": Number,
"--debug": Boolean,
"--debug-binding": String,
"--no-delete": Boolean,
"--dry": Boolean,
"--force": Boolean,
Expand Down Expand Up @@ -226,6 +245,10 @@ export async function run(argv: string[] = process.argv.slice(2)) {
}
flags.remixVersion = args["--remix-version"];

if (args["--debug"]) {
flags.debugBinding = args["--debug-binding"];
}

let command = input[0];

// Note: Keep each case in this switch statement small.
Expand Down