Repository navigation
server: add workerd run - #8084
Draft
bartlomieju wants to merge 1 commit into
Draft
bartlomieju wants to merge 1 commit into
bartlomieju wants to merge 1 commit into
Conversation
`workerd run <file>` serves one JavaScript or TypeScript file as a Worker with no config file. It is served as a wrangler config whose only field is `main`: the file is bundled with esbuild, found the same way (WORKERD_ESBUILD, else the nearest node_modules/.bin/esbuild, else PATH), so TypeScript, relative imports and npm packages work, and --watch reloads on any input to the bundle. The Worker gets the newest compatibility date this build supports and listens on localhost:8787, as a wrangler config does. --port, --compat-date and --compat-flag change them, and the rest of `serve`'s options apply. wrangler.rs's load() is split into parsing and build(), which load_file() reuses with a synthesized config and the socket address as a parameter. The esbuild-not-found message no longer assumes a wrangler config.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #8084 +/- ##
==========================================
- Coverage 68.18% 68.15% -0.03%
==========================================
Files 712 712
Lines 185743 185821 +78
Branches 29255 29255
==========================================
+ Hits 126645 126647 +2
- Misses 42019 42096 +77
+ Partials 17079 17078 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Split out of #8065, rebuilt on top of #8051.
workerd run <file>serves one JavaScript or TypeScript file as a Worker, with no config file:main. So it is bundled with esbuild exactly asserve wrangler.jsoncbundles it, usingWORKERD_ESBUILD, else the nearestnode_modules/.bin/esbuild, elseesbuildonPATH. TypeScript, relative imports and npm packages work, and--watchreloads when any input to the bundle changes.workerd bench --compat-date=latest, and listens onlocalhost:8787, as a wrangler config does.--port,--compat-dateand--compat-flagchange those defaults. The rest ofserve's options apply, including--socket-addr.--watchwaits for a fix.Implementation:
wrangler::load()is split into parsing andbuild(), whichload_file()reuses with a synthesized config. The socket address is now a parameter. The esbuild-not-found message no longer assumes a wrangler config.Out of scope here: Python entry modules, which esbuild can't bundle and so need their own path, and
--print-config.Tests: unit tests for the argument parsing, the accepted extensions, and the config
runbuilds, using a stub esbuild innode_modules/.bin. Checked by hand with esbuild 0.28: a.tsentry with a relative import serves, and an edit to the import reloads under--watch.