workers-sdk icon indicating copy to clipboard operation
workers-sdk copied to clipboard

feat: cli flag to disable interactive dev session

Open KaiSpencer opened this issue 1 year ago • 10 comments

Closes #5063

For monorepos using tools like turborepo or nx it may be desirable to disable to interactive feature of the wrangler dev command.

The flag to disable this exists internally already in package.

This PR exposes this internal flag (that can be passed to unstable_dev) as a CLI arg, allowing the interactive session to be disabled.

I maintained consistency with the current variable naming.

  • Tests
    • [x] Included (and fixture tests cover the defaults further)
    • [ ] Not necessary because:
  • Changeset (Changeset guidelines)
    • [x] Included
    • [ ] Not necessary because: TODO
  • Associated docs
    • [x] Issue(s)/PR(s): https://github.com/cloudflare/cloudflare-docs/pull/13188
    • [ ] Not necessary because:

KaiSpencer avatar Feb 26 '24 11:02 KaiSpencer

🦋 Changeset detected

Latest commit: b5ac4c2f54b8af32c5f36731aabc141be6950c0c

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

changeset-bot[bot] avatar Feb 26 '24 11:02 changeset-bot[bot]

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/8349817213/npm-package-wrangler-5099

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

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

Or you can use npx with this latest build directly:

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

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


[email protected] includes the following runtime dependencies:

Package Constraint Resolved
miniflare workspace:* 3.20240314.0
workerd 1.20240314.0 1.20240314.0
workerd --version 1.20240314.0 2024-03-14

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

github-actions[bot] avatar Feb 26 '24 19:02 github-actions[bot]

Cheers @admah Some test failures Timed out starting long-lived Wrangler in the pages-workersjs-directory. Expected flake to retry? or did I break something :D

KaiSpencer avatar Feb 26 '24 20:02 KaiSpencer

Probably flakes. Let me retry them.

petebacondarwin avatar Feb 26 '24 20:02 petebacondarwin

I can get most test to pass every time individually locally. The fixture pages-workerjs-app seems to be about 50/50 failing with the error on CI and passing the other half of the runs.

I am yet to get pnpm test:ci to pass every test at all locally in one go 🫣

KaiSpencer avatar Feb 26 '24 21:02 KaiSpencer

I think the problem is that internally showInteractiveDevSession defaults to true and for wrangler pages dev it was passing it through as undefined. Inside the DevImplementation React component it was doing a further initialization default to isRawModeSupported which is now never being used because by the time it reaches there it is either true or false and not undefined. I think you need to allow undefined to be a value for the CLI arg (i.e. not default it to true and then rely upon the internal defaulting to happen as it does now.

See https://github.com/cloudflare/workers-sdk/blob/0c0949da60e3287c05a5884bb9f869ce5609a9a1/packages/wrangler/src/dev/dev.tsx#L190

petebacondarwin avatar Feb 27 '24 11:02 petebacondarwin

I think the problem is that internally showInteractiveDevSession defaults to true and for wrangler pages dev it was passing it through as undefined. Inside the DevImplementation React component it was doing a further initialization default to isRawModeSupported which is now never being used because by the time it reaches there it is either true or false and not undefined. I think you need to allow undefined to be a value for the CLI arg (i.e. not default it to true and then rely upon the internal defaulting to happen as it does now.

See

https://github.com/cloudflare/workers-sdk/blob/0c0949da60e3287c05a5884bb9f869ce5609a9a1/packages/wrangler/src/dev/dev.tsx#L190

Cheers @petebacondarwin

Have removed the defaulting in yargs definitions.

And subsequently removed the manual default to undefined, which will now be undefined with no arg, true with true arg and false with false arg

KaiSpencer avatar Feb 27 '24 15:02 KaiSpencer

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 71.68%. Comparing base (0201f1e) to head (b5ac4c2).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #5099      +/-   ##
==========================================
+ Coverage   71.64%   71.68%   +0.03%     
==========================================
  Files         312      312              
  Lines       16217    16217              
  Branches     4149     4149              
==========================================
+ Hits        11619    11625       +6     
+ Misses       4598     4592       -6     
Files Coverage Δ
packages/wrangler/src/dev.tsx 79.92% <ø> (ø)
packages/wrangler/src/pages/dev.ts 16.16% <ø> (ø)

... and 6 files with indirect coverage changes

codecov[bot] avatar Feb 27 '24 17:02 codecov[bot]

Last of all we need to create a PR in https://github.com/cloudflare/cloudflare-docs to add this feature to the docs.

petebacondarwin avatar Feb 27 '24 17:02 petebacondarwin

Last of all we need to create a PR in https://github.com/cloudflare/cloudflare-docs to add this feature to the docs.

PR for docs https://github.com/cloudflare/cloudflare-docs/pull/13188

KaiSpencer avatar Feb 27 '24 22:02 KaiSpencer