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

fix: consolidate getEntry() logic #567

Merged
merged 1 commit into from
Mar 12, 2022
Merged

Conversation

threepointone
Copy link
Contributor

@threepointone threepointone commented Mar 10, 2022

This consolidates some logic into getEntry(), namely including guessWorkerFormat() and custom builds. This simplifies the code for both dev and publish.

  • Previously, the implementation of custom builds inside dev assumed it could be a long running process; however it's not (else consider that publish would never work).
  • By running custom builds inside getEntry(), we can be certain that the entry point exists as we validate it and before we enter dev/publish, simplifying their internals
  • We don't have to do periodic checks inside wrangler dev because it's now a one shot build (and always should have been)
  • This expands test coverage a little for both dev and publish.
  • The 'format' of a worker is intrinsic to its contents, so it makes sense to establish its value inside getEntry()
  • This also means less async logic inside <Dev/>, which is always a good thing

@changeset-bot
Copy link

changeset-bot bot commented Mar 10, 2022

🦋 Changeset detected

Latest commit: 80cfc1a

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

This PR includes changesets to release 1 package
Name Type
wrangler 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

@github-actions
Copy link
Contributor

github-actions bot commented Mar 10, 2022

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

npm install --save-dev https://prerelease-registry.developers.workers.dev/runs/1969624566/npm-package-wrangler-567

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

npm install --save-dev https://prerelease-registry.developers.workers.dev/prs/567/npm-package-wrangler-567

Or you can use npx with this latest build directly:

npx https://prerelease-registry.developers.workers.dev/runs/1969624566/npm-package-wrangler-567 dev path/to/script.js

@threepointone
Copy link
Contributor Author

threepointone commented Mar 10, 2022

EDIT: I amended the PR to include guessWorkerFormat() inside getEntry()

In a subsequent PR, I might also extract guessWorkerFormat and include it into getEntry, for similar reasons as above

@threepointone threepointone force-pushed the simplify-custom-builds branch 3 times, most recently from 390b123 to eb0ab4e Compare March 10, 2022 17:44
@threepointone threepointone changed the title fix: simplify custom builds fix: consolidate getEntry() logic Mar 10, 2022
@threepointone threepointone force-pushed the simplify-custom-builds branch 2 times, most recently from aa35717 to 03fe58c Compare March 10, 2022 20:04
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 have an idea I would like to consider for this refactoring. It may not work out for a number of reasons but I think it is worth looking into...

How about changing useCustomBuild() so that it only triggers a new useEsbuild() when the watched files change, rather than running the custom build itself.

Then rather than passing the entry object into the useEsbuild() hook, it would call getEntry() itself. This would have the benefit of also running the custom build as necessary.

Happy to jump on a call to talk around this.

packages/wrangler/src/__tests__/dev.test.tsx Show resolved Hide resolved
packages/wrangler/src/__tests__/dev.test.tsx Show resolved Hide resolved
packages/wrangler/src/__tests__/dev.test.tsx Show resolved Hide resolved
This consolidates some logic into `getEntry()`, namely including `guessWorkerFormat()` and custom builds. This simplifies the code for both `dev` and `publish`.

- Previously, the implementation of custom builds inside `dev` assumed it could be a long running process; however it's not (else consider that `publish` would never work).
- By running custom builds inside `getEntry()`, we can be certain that the entry point exists as we validate it and before we enter `dev`/`publish`, simplifying their internals
- We don't have to do periodic checks inside `wrangler dev` because it's now a one shot build (and always should have been)
- This expands test coverage a little for both `dev` and `publish`.
- The 'format' of a worker is intrinsic to its contents, so it makes sense to establish its value inside `getEntry()`
- This also means less async logic inside `<Dev/>`, which is always a good thing
@threepointone threepointone force-pushed the simplify-custom-builds branch from 03fe58c to 80cfc1a Compare March 11, 2022 15:38
@threepointone
Copy link
Contributor Author

I considered including getEntry() inside bundle, but then it brought back a bunch of null checks that I wanted to avoid. I'd like to land this and revisit if it becomes an issue.

@petebacondarwin petebacondarwin merged commit 05b81c5 into main Mar 12, 2022
@petebacondarwin petebacondarwin deleted the simplify-custom-builds branch March 12, 2022 13:22
@github-actions github-actions bot mentioned this pull request Mar 12, 2022
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.

2 participants