Skip to content

Commit

Permalink
feat: cli flag to disable interactive dev session (#5099)
Browse files Browse the repository at this point in the history
* Adds flag to expose already existing showInteractiveDevSession, test to
ensure flag is passed to Dev component

* Adds changeset

* Remove cli arg default, allow undefined to flow through if no arg passed. which will itself default to false with nullish coalesce down the line

* Fix code review comments

* Fix up the default documentation

---------

Co-authored-by: Peter Bacon Darwin <pbacondarwin@cloudflare.com>
  • Loading branch information
KaiSpencer and petebacondarwin committed Mar 19, 2024
1 parent 0201f1e commit 93150aa
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
8 changes: 8 additions & 0 deletions .changeset/tender-buckets-confess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"wrangler": patch
---

feat: expose `--show-interactive-dev-session` flag

This flag controls the interactive mode of the dev session, a feature that already exists internally but was not exposed to the user.
This is useful for CI/CD environments where the interactive mode is not desired, or running in tools like `turbo` and `nx`.
20 changes: 19 additions & 1 deletion packages/wrangler/src/__tests__/dev.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1258,7 +1258,8 @@ describe("wrangler dev", () => {
--persist-to Specify directory to use for local persistence (defaults to .wrangler/state) [string]
--live-reload Auto reload HTML pages when change is detected in local mode [boolean]
--test-scheduled Test scheduled events by visiting /__scheduled in browser [boolean] [default: false]
--log-level Specify logging level [choices: \\"debug\\", \\"info\\", \\"log\\", \\"warn\\", \\"error\\", \\"none\\"] [default: \\"log\\"]",
--log-level Specify logging level [choices: \\"debug\\", \\"info\\", \\"log\\", \\"warn\\", \\"error\\", \\"none\\"] [default: \\"log\\"]
--show-interactive-dev-session Show interactive dev session (defaults to true if the terminal supports interactivity) [boolean]",
"warn": "",
}
`);
Expand Down Expand Up @@ -1479,6 +1480,23 @@ describe("wrangler dev", () => {
});
});

describe("--show-interactive-dev-session", () => {
it("should show interactive dev session with --show-interactive-dev-session", async () => {
fs.writeFileSync("index.js", `export default { }`);
await runWrangler("dev index.js --show-interactive-dev-session");
expect(
(Dev as jest.Mock).mock.calls[0][0].showInteractiveDevSession
).toBeTruthy();
});
it("should not show interactive dev session with --show-interactive-dev-session=false", async () => {
fs.writeFileSync("index.js", `export default { }`);
await runWrangler("dev index.js --show-interactive-dev-session=false");
expect(
(Dev as jest.Mock).mock.calls[0][0].showInteractiveDevSession
).toBeFalsy();
});
});

describe("service bindings", () => {
it("should warn when using service bindings", async () => {
writeWranglerToml({
Expand Down
7 changes: 6 additions & 1 deletion packages/wrangler/src/dev.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,11 @@ export function devOptions(yargs: CommonYargsArgv) {
// Yargs requires this to type log-level properly
default: "log" as LoggerLevel,
})
.option("show-interactive-dev-session", {
describe:
"Show interactive dev session (defaults to true if the terminal supports interactivity)",
type: "boolean",
})
);
}

Expand Down Expand Up @@ -345,6 +350,7 @@ export type AdditionalDevProps = {
moduleRoot?: string;
rules?: Rule[];
constellation?: Environment["constellation"];
showInteractiveDevSession?: boolean;
};

export type StartDevOptions = DevArguments &
Expand All @@ -356,7 +362,6 @@ export type StartDevOptions = DevArguments &
disableDevRegistry?: boolean;
enablePagesAssetsServiceBinding?: EnablePagesAssetsServiceBindingOptions;
onReady?: (ip: string, port: number, proxyData: ProxyData) => void;
showInteractiveDevSession?: boolean;
updateCheck?: boolean;
};

Expand Down
8 changes: 7 additions & 1 deletion packages/wrangler/src/pages/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ export function Options(yargs: CommonYargsArgv) {
choices: ["debug", "info", "log", "warn", "error", "none"] as const,
describe: "Specify logging level",
},
"show-interactive-dev-session": {
describe:
"Show interactive dev session (defaults to true if the terminal supports interactivity)",
type: "boolean",
},
});
}

Expand Down Expand Up @@ -248,6 +253,7 @@ export const Handler = async ({
config: config,
_: [_pages, _dev, ...remaining],
logLevel,
showInteractiveDevSession,
}: StrictYargsOptionsToInterface<typeof Options>) => {
if (logLevel) {
logger.loggerLevel = logLevel;
Expand Down Expand Up @@ -751,7 +757,7 @@ export const Handler = async ({
},
liveReload,
forceLocal: true,
showInteractiveDevSession: undefined,
showInteractiveDevSession,
testMode: false,
watch: true,
},
Expand Down

0 comments on commit 93150aa

Please sign in to comment.