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

Add hello world example for Durable Objects #4747

Conversation

joshthoward
Copy link
Contributor

@joshthoward joshthoward commented Jan 14, 2024

Fixes # [insert GH or internal issue number(s)].

What this PR solves / how to test:

This PR attempts to add a new create-cloudflare example for Durable Objects, which corresponds to the getting started docs on Durable Objects.

Author has addressed the following:

  • Tests
    • Included
    • Not necessary because:
  • Changeset (Changeset guidelines)
    • Included
    • Not necessary because:
  • Associated docs
    • Issue(s)/PR(s):
    • Not necessary because:

Note for PR author:

We want to celebrate and highlight awesome PR review! If you think this PR received a particularly high-caliber review, please assign it the label highlight pr review so future reviewers can take inspiration and learn from it.

@joshthoward joshthoward requested a review from a team as a code owner January 14, 2024 16:57
Copy link

changeset-bot bot commented Jan 14, 2024

⚠️ No Changeset found

Latest commit: 7ffe646

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

Copy link
Contributor

github-actions bot commented Jan 14, 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/7585525527/npm-package-wrangler-4747

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

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

Or you can use npx with this latest build directly:

npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/7585525527/npm-package-wrangler-4747 dev path/to/script.js
Additional artifacts:
npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/7585525527/npm-package-create-cloudflare-4747 --no-auto-update
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/7585525527/npm-package-miniflare-4747
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/7585525527/npm-package-cloudflare-pages-shared-4747

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


wrangler@3.23.0 includes the following runtime dependencies:

Package Constraint Resolved
miniflare workspace:* 3.20231218.2
workerd 1.20231218.0 1.20231218.0
workerd --version 1.20231218.0 2023-12-18

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

Copy link

codecov bot commented Jan 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (8d6b3ee) 75.63% compared to head (7ffe646) 71.81%.
Report is 25 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4747      +/-   ##
==========================================
- Coverage   75.63%   71.81%   -3.83%     
==========================================
  Files         243      285      +42     
  Lines       13210    14759    +1549     
  Branches     3393     3719     +326     
==========================================
+ Hits         9992    10599     +607     
- Misses       3218     4160     +942     

see 62 files with indirect coverage changes

Copy link
Contributor

@elithrar elithrar left a comment

Choose a reason for hiding this comment

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

More in-line code comments explaining each method call.

Assume a user hasn't read the docs and is jumping in via the create Cloudflare flow for the first time.

@joshthoward joshthoward force-pushed the joshthoward/do-hello-world-template branch 2 times, most recently from bec9fe5 to 19b39ab Compare January 14, 2024 22:23
@joshthoward
Copy link
Contributor Author

@MellowYarker and @elithrar PTAL. I tested this locally and it works. Not sure what the test failures are here.

Copy link
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

LGTM - the e2e failures are because you need secrets to run these, which are not available to PRs built in personal forks.

Copy link
Contributor

@penalosa penalosa left a comment

Choose a reason for hiding this comment

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

It looks like there are a couple of issues with the JSDoc typings

@joshthoward joshthoward force-pushed the joshthoward/do-hello-world-template branch from 19b39ab to 3290c37 Compare January 16, 2024 14:10
@joshthoward
Copy link
Contributor Author

It looks like there are a couple of issues with the JSDoc typings

@penalosa I've addressed these changes. I was unsure about Promise<Response> because I thought async might have implied the Promise? Either way thank you for the suggestions.

Copy link
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

I pulled this down and tried it out. One last fix needed.

@joshthoward
Copy link
Contributor Author

@petebacondarwin WDYM by "Can you do that with JSDoc comments?"

@petebacondarwin
Copy link
Contributor

@petebacondarwin WDYM by "Can you do that with JSDoc comments?"

In his comment @penalosa suggested that we would need to define the Env type/interface in the file somewhere.
But since this is a JS file, not TS, I am not sure how easy it would be to define that type.

I note in the standard Workers Hello World starter, we don't both to define types (in jsdoc comments) at all.

@penalosa
Copy link
Contributor

@petebacondarwin TypeScript supports typedefs in JSDoc files (https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html#typedef-callback-and-param)

@joshthoward joshthoward force-pushed the joshthoward/do-hello-world-template branch from 3290c37 to fbf4c7a Compare January 17, 2024 14:31
@joshthoward
Copy link
Contributor Author

@petebacondarwin WDYM by "Can you do that with JSDoc comments?"

In his comment @penalosa suggested that we would need to define the Env type/interface in the file somewhere. But since this is a JS file, not TS, I am not sure how easy it would be to define that type.

I note in the standard Workers Hello World starter, we don't both to define types (in jsdoc comments) at all.

Turns out that you can (though I'm not sure why someone would go through that much trouble to not use TypeScript lol). The type is annotated on line 12 in the same file.

Comments are addressed. Should be good to go now.

@petebacondarwin
Copy link
Contributor

Created #4762 to run the e2e tests in CI.

@petebacondarwin
Copy link
Contributor

  > prettier . --check --ignore-unknown
  
  Checking formatting...
  [warn] packages/create-cloudflare/templates/hello-world-durable-object/js/package.json
  [warn] packages/create-cloudflare/templates/hello-world-durable-object/js/src/index.js
  [warn] packages/create-cloudflare/templates/hello-world-durable-object/ts/package.json
  [warn] packages/create-cloudflare/templates/hello-world-durable-object/ts/src/index.ts
  [warn] packages/create-cloudflare/templates/hello-world-durable-object/ts/tsconfig.json
  [warn] Code style issues found in 5 files. Forgot to run Prettier?

@petebacondarwin
Copy link
Contributor

And this test needs to change:

{
matcher: /What type of application do you want to create/,
input: [keys.down, keys.down, keys.enter],
},
{

Right now it is trying to select the "Example router & proxy Worker" type but since this PR adds a new item above this one, it is getting the wrong project type.

@joshthoward joshthoward force-pushed the joshthoward/do-hello-world-template branch from fbf4c7a to 7ffe646 Compare January 19, 2024 15:05
@joshthoward
Copy link
Contributor Author

@petebacondarwin I pushed some updates yesterday. I'm a little confused about what is supposed to run where, so please let me know if there are any other test failures I need to worry about. Otherwise, maybe we can hop on a call Monday and I can understand a bit more about how to develop on workers-sdk.

@petebacondarwin
Copy link
Contributor

Pushed the new commits to the origin fork. If the tests are good we can merge this.

@petebacondarwin
Copy link
Contributor

The other branch was green so let's land this!

@petebacondarwin petebacondarwin merged commit 69bc7d5 into cloudflare:main Jan 22, 2024
17 of 22 checks passed
@petebacondarwin
Copy link
Contributor

Darn it! I just realised that we should have added a changeset for this. I'll add one in a new PR now.

petebacondarwin added a commit that referenced this pull request Jan 22, 2024
This new starter corresponds to the getting started guide in the docs.

See #4747
petebacondarwin added a commit that referenced this pull request Jan 22, 2024
This new starter corresponds to the getting started guide in the docs.

See #4747
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants