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

React-free hotkeys implementation #6149

Merged
merged 41 commits into from
Jul 2, 2024
Merged

React-free hotkeys implementation #6149

merged 41 commits into from
Jul 2, 2024

Conversation

RamIdeas
Copy link
Contributor

@RamIdeas RamIdeas commented Jun 25, 2024

What this PR solves / how to test

Implements a React-free hotkeys implementation.

You can see both the implementations below – the React-free version with the --x-dev-env flag and the React/ink version with the flag:

image

I started with a simpler implementation in the first commit but felt a higher-level API would allow for most consistency for other commands wanting to use hotkeys. The instructions printing logic has been moved inside the API and provides each handler with a printInstructions function if the handler wishes to reprint them.

UPDATE:
The instructions box now floats at the bottom (by making Wrangler's Logger and Miniflare's Log classes aware of a possible bottom float string). See image below for what it looks like now (note the worker logs are now above the instructions box):

image

Author has addressed the following

  • Tests
    • TODO (before merge)
    • Included
    • Not necessary because:
  • E2E Tests CI Job required? (Use "e2e" label or ask maintainer to run separately)
    • I don't know
    • Required / Maybe required
    • Not required because: hotkeys not currently tested with e2e
  • Changeset (Changeset guidelines)
    • TODO (before merge)
    • Included
    • Not necessary because:
  • Public documentation
    • TODO (before merge)
    • Cloudflare docs PR(s):
    • Not necessary because: experimental
@RamIdeas RamIdeas requested a review from a team as a code owner June 25, 2024 23:27
Copy link

changeset-bot bot commented Jun 25, 2024

🦋 Changeset detected

Latest commit: 1887c45

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
wrangler Patch
@cloudflare/vitest-pool-workers Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@cloudflare cloudflare deleted a comment Jun 25, 2024
Copy link
Contributor

github-actions bot commented Jun 25, 2024

A wrangler prerelease is available for testing. You can install this latest build in your project with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/9763657552/npm-package-wrangler-6149

You can reference the automatically updated head of this PR with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/6149/npm-package-wrangler-6149

Or you can use npx with this latest build directly:

npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/9763657552/npm-package-wrangler-6149 dev path/to/script.js
Additional artifacts:
npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/9763657552/npm-package-create-cloudflare-6149 --no-auto-update
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/9763657552/npm-package-cloudflare-kv-asset-handler-6149
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/9763657552/npm-package-miniflare-6149
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/9763657552/npm-package-cloudflare-pages-shared-6149
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/9763657552/npm-package-cloudflare-vitest-pool-workers-6149

Note that these links will no longer work once the GitHub Actions artifact expires.


wrangler@3.62.0 includes the following runtime dependencies:

Package Constraint Resolved
miniflare workspace:* 3.20240620.0
workerd 1.20240701.0 1.20240701.0
workerd --version 1.20240701.0 2024-07-01

Please ensure constraints are pinned, and miniflare/workerd minor versions match.

@workers-devprod workers-devprod added the e2e Run e2e tests on a PR label Jun 26, 2024
@RamIdeas RamIdeas force-pushed the startWorker-hotkeys branch 4 times, most recently from 154ce0b to 1079c6d Compare June 27, 2024 11:17
packages/wrangler/src/dev.tsx Outdated Show resolved Hide resolved
packages/wrangler/src/dev.tsx Outdated Show resolved Hide resolved
@penalosa penalosa mentioned this pull request Jun 28, 2024
12 tasks
packages/miniflare/src/shared/log.ts Outdated Show resolved Hide resolved
packages/miniflare/src/shared/log.ts Outdated Show resolved Hide resolved
packages/wrangler/src/utils/onKeyPress.ts Show resolved Hide resolved
packages/wrangler/src/utils/onKeyPress.ts Outdated Show resolved Hide resolved
packages/wrangler/src/dev.tsx Outdated Show resolved Hide resolved
@RamIdeas RamIdeas force-pushed the startWorker-hotkeys branch 2 times, most recently from 558c13a to 8dccb57 Compare July 1, 2024 19:39
.changeset/few-days-tap.md Outdated Show resolved Hide resolved
packages/miniflare/src/shared/log.ts Outdated Show resolved Hide resolved
packages/miniflare/src/shared/log.ts Outdated Show resolved Hide resolved
packages/miniflare/src/shared/log.ts Outdated Show resolved Hide resolved
packages/miniflare/src/shared/log.ts Outdated Show resolved Hide resolved
packages/wrangler/src/dev.tsx Outdated Show resolved Hide resolved
packages/wrangler/src/dev/inspect.ts Outdated Show resolved Hide resolved
packages/wrangler/src/dev/use-esbuild.ts Show resolved Hide resolved
packages/wrangler/src/utils/onKeyPress.ts Outdated Show resolved Hide resolved

if (process.stdin.isTTY) {
readline.emitKeypressEvents(stream);
process.stdin.setRawMode(true);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we capture what the current raw mode is to reuse in the teardown function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This reminds me I need to test this with the auth/account prompts

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like we'll need to setRawMode(true) again after prompts have been used

(my manual testing just now found that prompts work fine but the hotkeys don't work after)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -8,6 +8,7 @@ import type { Hook } from "./api";
export default function (
options: Array<{
keys: string[];
disabled?: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we have a disabled option? Can't we just not pass it in the array?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Felt it was easier to read a disabled flag in an flat-ordered list than the ternary+spread alternative

9b7e52f

packages/wrangler/src/dev.tsx Outdated Show resolved Hide resolved
@RamIdeas RamIdeas force-pushed the startWorker-hotkeys branch 2 times, most recently from 6db7f95 to 4b4d56a Compare July 2, 2024 15:09
@RamIdeas RamIdeas merged commit 35689ea into main Jul 2, 2024
21 checks passed
@RamIdeas RamIdeas deleted the startWorker-hotkeys branch July 2, 2024 16:26
@workers-devprod workers-devprod mentioned this pull request Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
e2e Run e2e tests on a PR
4 participants