Skip to content

Releases: cloudflare/workers-sdk

wrangler@2.0.12

14 Jun 14:46
e61fba8
Compare
Choose a tag to compare

Patch Changes

  • #1229 e273e09 Thanks @timabb031! - fix: parsing of node inspector url

    This fixes the parsing of the url returned by Node Inspector via stderr which could be received partially in multiple chunks or in a single chunk.

    Closes #1226

  • #1255 2d806dc Thanks @f5io! - fix: kv:key put binary file upload

    As raised in #1254, it was discovered that binary uploads were being mangled by wrangler 2, whereas they worked in wrangler 1. This is because they were read into a string by providing an explicit encoding of utf-8. This fix reads provided files into a node Buffer that is then passed directly to the request.

  • #1248 db8a0bb Thanks @threepointone! - fix: instruct api to exclude script content on worker upload

    When we upload a script bundle, we get the actual content of the script back in the response. Sometimes that script can be large (depending on whether the upload was large), and currently it may even be a badly escaped string. We can pass a queryparam excludeScript that, as it implies, exclude the script content in the response. This fix does that.

    Fixes #1222

  • #1250 e3278fa Thanks @rozenmd! - fix: pass localProtocol to miniflare for https server

    Closes #1247

  • #1253 eee5c78 Thanks @threepointone! - fix: resolve asset handler for --experimental-path

    In #1241, we removed the vendored version of @cloudflare/kv-asset-handler, as well as the build configuration that would point to the vendored version when compiling a worker using --experimental-public. However, wrangler can be used where it's not installed in the package.json for the worker, or even when there's no package.json at all (like when wrangler is installed globally, or used with npx). In this situation, if the user doesn't have @cloudflare/kv-asset-handler installed, then building the worker will fail. We don't want to make the user install this themselves, so instead we point to a barrel import for the library in the facade for the worker.

  • #1234 3e94bc6 Thanks @threepointone! - feat: support --experimental-public in local mode

    --experimental-public is an abstraction over Workers Sites, and we can leverage miniflare's inbuilt support for Sites to serve assets in local mode.

  • #1236 891d128 Thanks @threepointone! - fix: generate site assets manifest relative to site.bucket

    We had a bug where we were generating asset manifest keys incorrectly if we ran wrangler from a different path to wrangler.toml. This fixes the generation of said keys, and adds a test for it.

    Fixes #1235

  • #1216 4eb70f9 Thanks @JacobMGEvans! - feat: reload server on configuration changes, the values passed into the server during restart will be bindings

    resolves #439

  • #1231 5206c24 Thanks @threepointone! - feat: build.watch_dir can be an array of paths

    In projects where:

    • all the source code isn't in one folder (like a monorepo, or even where the worker has non-standard imports across folders),
    • we use a custom build, so it's hard to statically determine folders to watch for changes

    ...we'd like to be able to specify multiple paths for custom builds, (the config build.watch_dir config). This patch enables such behaviour. It now accepts a single path as before, or optionally an array of strings/paths.

    Fixes #1095

  • #1241 471cfef Thanks @threepointone! - use @cloudflare/kv-asset-handler for --experimental-public

    We'd previously vendored in @cloudflare/kv-asset-handler and mime for --experimental-public. We've since updated @cloudflare/kv-asset-handler to support module workers correctly, and don't need the vendored versions anymore. This patch uses the lib as a dependency, and deletes the vendor folder.

wrangler@2.0.11

13 Jun 15:41
010e319
Compare
Choose a tag to compare

Patch Changes

  • #1239 df55709 Thanks @threepointone! - polish: don't include folder name in Sites kv asset keys

    As reported in #1189, we're including the name of the folder in the keys of the KV store that stores the assets. This doesn't match v1 behaviour. It makes sense not to include these since, we should be able to move around the folder and not have to reupload the entire folder again.

    Fixes #1189

  • #1210 785d418 Thanks @GregBrimble! - feat: Upload the delta for wrangler pages publish

    We now keep track of the files that make up each deployment and intelligently only upload the files that we haven't seen. This means that similar subsequent deployments should only need to upload a minority of files and this will hopefully make uploads even faster.

  • #1218 f8a21ed Thanks @threepointone! - fix: warn on unexpected fields on config.triggers

    This adds a warning when we find unexpected fields on the triggers config (and any future fields that use the isObjectWith() validation helper)

wrangler@2.0.9

10 Jun 14:48
b917999
Compare
Choose a tag to compare

Patch Changes

  • #1192 bafa5ac Thanks @threepointone! - fix: use worker name as a script ID when generating a preview session

    When generating a preview session on the edge with wrangler dev, for a zoned worker we were using a random id as the script ID. This would make the backend not associate the dev session with any resources that were otherwise assigned to the script (specifically for secrets, but other stuff as well) The fix is simply to use the worker name (when available) as the script ID.

    Fixes #1003
    Fixes #1172

  • #1212 101342e Thanks @petebacondarwin! - fix: do not crash when not logged in and switching to remote dev mode

    Previously, if you are not logged in when running wrangler dev it will only try to log you in
    if you start in "remote" mode. In "local" mode there is no need to be logged in, so it doesn't
    bother to try to login, and then will crash if you switch to "remote" mode interactively.

    The problem was that we were only attempting to login once before creating the <Remote> component.
    Now this logic has been moved into a useEffect() inside <Remote> so that it will be run whether
    starting in "remote" or transitioning to "remote" from "local".

    The fact that the check is no longer done before creating the components is proven by removing the
    mockAccountId() and mockApiToken() calls from the dev.test.ts files.

    Fixes #18

  • #1188 b44cc26 Thanks @petebacondarwin! - fix: fallback on old zone-based API when account-based route API fails

    While we wait for changes to the CF API to support API tokens that do not have
    "All Zone" permissions, this change provides a workaround for most scenarios.

    If the bulk-route request fails with an authorization error, then we fallback
    to the Wrangler 1 approach, which sends individual route updates via a zone-based
    endpoint.

    Fixes #651

  • #1203 3b88b9f Thanks @rozenmd! - fix: differentiate between API and OAuth in whoami

    Closes #1198

  • #1199 e64812e Thanks @sidharthachatterjee! - fix: Refresh JWT in wrangler pages publish when it expires

  • #1209 2d42882 Thanks @petebacondarwin! - fix: ensure wrangler init works with older versions of git

    Rather than using the recently added --initial-branch option, we now just renamed the initial branch using git branch -m main.

    Fixes #1168

wrangler@2.0.8

08 Jun 09:34
d7a48cb
Compare
Choose a tag to compare

Patch Changes

  • #1184 4a10176 Thanks @timabb031! - polish: add cron trigger to wrangler.toml when new Scheduled Worker is created

    When wrangler init is used to create a new Scheduled Worker a cron trigger (1 * * * *) will be added to wrangler.toml, but only if wrangler.toml is being created during init. If wrangler.toml exists prior to running wrangler init then wrangler.toml will remain unchanged even if the user selects the "Scheduled Handler" option. This is as per existing tests in init.test.ts that ensure wrangler.toml is never overwritten after agreeing to prompts. That can change if it needs to.

  • #1163 52c0bf0 Thanks @threepointone! - fix: only log available bindings once in dev

    Because we were calling printBindings during the render phase of <Dev/>, we were logging the bindings multiple times (render can be called multiple times, and the interaction of Ink's stdout output intermingled with console is a bit weird). We could have put it into an effect, but I think a better solution here is to simply log it before we even start rendering <Dev/> (so we could see the bindings even if Dev fails to load, for example).

    This also adds a fix that masks any overriden values so that we don't accidentally log potential secrets into the terminal.

  • #1154 5d6de58 Thanks @threepointone! - fix: extract Cloudflare_CA.pem to temp dir before using it

    With package managers like yarn, the cloudflare cert won't be available on the filesystem as expected (since the module is inside a .zip file). This fix instead extracts the file out of the module, copies it to a temporary directory, and directs node to use that as the cert instead, preventing warnings like #1136.

    Fixes #1136

  • #1166 08e3a49 Thanks @threepointone! - fix: warn on unexpected fields on migrations

    This adds a warning for unexpected fields on [migrations] config, reported in #1165. It also adds a test for incorrect renamed_classes in a migration.

  • #1122 c2d2f44 Thanks @petebacondarwin! - fix: display chained errors from the CF API

    For example if you have an invalid CF_API_TOKEN and try running wrangler whoami
    you now get the additional 6111 error information:

    ✘ [ERROR] A request to the Cloudflare API (/user) failed.
    
      Invalid request headers [code: 6003]
      - Invalid format for Authorization header [code: 6111]
    
  • #1152 b817136 Thanks @threepointone! - polish: Give a copy-paste config when [migrations] are missing

    This gives a slightly better message when migrations are missing for declared durable objcts. Specifically, it gives a copy-pastable section to add to wrangler.toml, and doesn't show the warning at all for invalid class names anymore.

    Partially makes #1076 better.

  • #1141 a8c509a Thanks @rozenmd! - fix: rename "publish" package.json script to "deploy"

    Renaming the default "publish" package.json script to "deploy" to avoid confusion with npm's publish command.

    Closes #1121

  • #1175 e978986 Thanks @timabb031! - feature: allow user to select a handler template with wrangler init

    This allows the user to choose which template they'd like to use when they are prompted to create a new worker.
    The options are currently "None"/"Fetch Handler"/"Scheduled Handler".
    Support for new handler types such as email can be added easily in future.

wrangler@2.0.7

27 May 14:23
900670b
Compare
Choose a tag to compare

Patch Changes

  • #1110 515a52f Thanks @rozenmd! - fix: print instructions even if installPackages fails to fetch npm packages

  • #1051 7e2e97b Thanks @rozenmd! - feat: add support for using wrangler behind a proxy

    Configures the undici library (the library wrangler uses for fetch) to send all requests via a proxy selected from the first non-empty environment variable from "https_proxy", "HTTPS_PROXY", "http_proxy" and "HTTP_PROXY".

  • #1089 de59ee7 Thanks @rozenmd! - fix: batch package manager installs so folks only have to wait once

    When running wrangler init, we install packages as folks confirm their options.
    This disrupts the "flow", particularly on slower internet connections.

    To avoid this disruption, we now only install packages once we're done asking questions.

    Closes #1036

  • #1073 6bb2564 Thanks @caass! - Add a better message when a user doesn't have a Chromium-based browser.

    Certain functionality we use in wrangler depends on a Chromium-based browser. Previously, we would throw a somewhat arcane error that was hard (or impossible) to understand without knowing what we needed. While ideally all of our functionality would work across all major browsers, as a stopgap measure we can at least inform the user what the actual issue is.

    Additionally, add support for Brave as a Chromium-based browser.

  • #1079 fb0dec4 Thanks @caass! - Print the bindings a worker has access to during dev and publish

    It can be helpful for a user to know exactly what resources a worker will have access to and where they can access them, so we now log the bindings available to a worker during wrangler dev and wrangler publish.

  • #1097 c73a3c4 Thanks @petebacondarwin! - fix: ensure all line endings are normalized before parsing as TOML

    Only the last line-ending was being normalized not all of them.

    Fixes #1094

  • #1111 1eaefeb Thanks @JacobMGEvans! - Git default main branch

    polish: Default branch when choosing to initialize a git repository will now be main.
    This is inline with current common industry ethical practices.
    See:

  • #1058 1a59efe Thanks @threepointone! - refactor: detect missing [migrations] during config validation

    This does a small refactor -

    • During publish, we were checking whether [migrations] were defined in the presence of [durable_objects], and warning if not. This moves it into the config validation step, which means it'll check for all commands (but notably dev)
    • It moves the code to determine current migration tag/migrations to upload into a helper. We'll be reusing this soon when we upload migrations to dev.
  • #1090 85fbfe8 Thanks @petebacondarwin! - refactor: remove use of any

    This "quick-win" refactors some of the code to avoid the use of any where possible.
    Using any can cause type-checking to be disabled across the code in unexpectedly wide-impact ways.

    There is one other use of any not touched here because it is fixed by #1088 separately.

  • #1088 d63d790 Thanks @petebacondarwin! - fix: ensure that the proxy server shuts down to prevent wrangler dev from hanging

    When running wrangler dev we create a proxy to the actual remote Worker.
    After creating a connection to this proxy by a browser request the proxy did not shutdown.
    Now we use a HttpTerminator helper library to force the proxy to close open connections and shutdown correctly.

    Fixes #958

  • #1099 175737f Thanks @petebacondarwin! - fix: delegate wrangler build to wrangler publish

    Since wrangler publish --dry-run --outdir=dist is basically the same result
    as what Wrangler 1 did with wrangler build let's run that for the user if
    they try to run wrangler build.

  • #1081 8070763 Thanks @rozenmd! - fix: friendlier error for when a subdomain hasn't been configured in dev mode

  • #1123 15e5c12 Thanks @timabb031! - chore: updated new worker ts template with env/ctx parameters and added Env interface

  • #1080 4a09c1b Thanks @caass! - Improve messaging when bulk deleting or uploading KV Pairs

    Closes #555

  • #1000 5a8e8d5 Thanks @JacobMGEvans! - pages dev <dir> & wrangler pages functions build will have a --node-compat flag powered by @esbuild-plugins/node-globals-polyfill (which in itself is powered by rollup-plugin-node-polyfills). The only difference in pages will be it does not check the wrangler.toml so the node_compat = truewill not enable it for wrangler pages functionality.

    resolves #890

  • #1028 b7a9ce6 Thanks @GregBrimble! - feat: Use new bulk upload API for 'wrangler pages publish'

    This raises the file limit back up to 20k for a deployment.

wranglerjs-compat-webpack-plugin@0.0.5

19 May 09:22
10b3925
Compare
Choose a tag to compare

Patch Changes

wrangler@2.0.6

19 May 08:43
0d5a03f
Compare
Choose a tag to compare

Patch Changes

  • #1018 cd2c42f Thanks @threepointone! - fix: strip leading */*. from routes when deducing a host for dev

    When given routes, we use the host name from the route to deduce a zone id to pass along with the host to set with dev session. Route patterns can include leading */*., which we don't account for when deducing said zone id, resulting in subtle errors for the session. This fix strips those leading characters as appropriate.

    Fixes #1002

  • #1044 7a191a2 Thanks @JacobMGEvans! - fix: trim trailing whitespace from the secrets before uploading

    resolves #993

  • #1052 233eef2 Thanks @petebacondarwin! - fix: display the correct help information when a subcommand is invalid

Previously, when an invalid subcommand was used, such as wrangler r2 foo,
the help that was displayed showed the top-level commands prefixed by the command in used.
E.g.

wrangler r2 init [name]       📥 Create a wrangler.toml configuration file
wrangler r2 dev [script]      👂 Start a local server for developing your worker
wrangler r2 publish [script]  🆙 Publish your Worker to Cloudflare.
...

Now the correct command help is displayed:

$ wrangler r2 foo

✘ [ERROR] Unknown argument: foo

wrangler r2

📦 Interact with an R2 store

Commands:
  wrangler r2 bucket  Manage R2 buckets

Flags:
  -c, --config   Path to .toml configuration file  [string]
  -h, --help     Show help  [boolean]
  -v, --version  Show version number  [boolean]

Fixes #871

This adds experimental support for service bindings, aka worker-to-worker bindings. It's lets you "call" a worker from another worker, without incurring any network cost, and (ideally) with much less latency. To use it, define a [services] field in wrangler.toml, which is a map of bindings to worker names (and environment). Let's say you already have a worker named "my-worker" deployed. In another worker's configuration, you can create a service binding to it like so:

[[services]]
binding = "MYWORKER"
service = "my-worker"
environment = "production" # optional, defaults to the worker's `default_environment` for now

And in your worker, you can call it like so:

export default {
  fetch(req, env, ctx) {
    return env.MYWORKER.fetch(new Request("http://domain/some-path"));
  }
};

Fixes #1026

  • #1045 8eeef9a Thanks @jrf0110! - fix: Incorrect extension extraction from file paths.

    Our extension extraction logic was taking into account folder names, which can include periods. The logic would incorrectly identify a file path of .well-known/foo as having the extension of well-known/foo when in reality it should be an empty string.

  • #1039 95852c3 Thanks @threepointone! - fix: don't fetch migrations when in --dry-run mode

    Fixes #1038

  • #1033 ffce3e3 Thanks @petebacondarwin! - fix: wrangler init should not crash if Git is not available on Windows

    We check for the presence of Git by trying to run git --version.
    On non-Windows we get an Error with code set to "ENOENT".
    One Windows we get a different error:

    {
      "shortMessage":"Command failed with exit code 1: git --version",
      "command":"git --version",
      "escapedCommand":"git --version",
      "exitCode":1,
      "stdout":"",
      "stderr":"'git' is not recognized as an internal or external command,\r\noperable program or batch file.",
      "failed":true,
      "timedOut":false,
      "isCanceled":false,
      "killed":false
    }
    

    Since we don't really care what the error is, now we just assume that Git
    is not available if an error is thrown.

    Fixes #1022

  • #982 6791703 Thanks @matthewdavidrodgers! - feature: add support for publishing to Custom Domains

    With the release of Custom Domains for workers, users can publish directly to a custom domain on a route, rather than creating a dummy DNS record first and manually pointing the worker over - this adds the same support to wrangler.

    Users declare routes as normal, but to indicate that a route should be treated as a custom domain, a user simply uses the object format in the toml file, but with a new key: custom_domain (i.e. routes = [{ pattern = "api.example.com", custom_domain = true }])

    When wrangler sees a route like this, it peels them off from the rest of the routes and publishes them separately, using the /domains api. This api is very defensive, erroring eagerly if there are conflicts in existing Custom Domains or managed DNS records. In the case of conflicts, wrangler prompts for confirmation, and then retries with parameters to indicate overriding is allowed.

  • #1019 5816eba Thanks @threepointone! - feat: bind a durable object by environment

    For durable objects, instead of just { name, class_name, script_name}, this lets you bind by environment as well, like so { name, class_name, script_name, environment }.

    Fixes #996

  • #1057 608dcd9 Thanks @petebacondarwin! - fix: pages "command" can consist of multiple words

    On Windows, the following command wrangler pages dev -- foo bar would error
    saying that bar was not a known argument. This is because foo and bar are
    passed to Yargs as separate arguments.

    A workaround is to put the command in quotes: wrangler pages dev -- "foo bar".
    But this fix makes the command argument variadic, which also solves the problem.

    Fixes #965

  • #1027 3545e41 Thanks @rozenmd! - feat: trying to use node builtins should recommend you enable node_compat in wrangler.toml

  • #1024 110f340 Thanks @threepointone! - polish: validate payload for kv:bulk put on client side

    This adds client side validation for the paylod for kv:bulk put, importantly ensuring we're uploading only string key/value pairs (as well as validation for the other fields).

    Fixes #571

  • #1037 963e9e0 Thanks @rozenmd! - fix: don't attempt to login during a --dryRun

wrangler@2.0.5

13 May 16:10
9906e1c
Compare
Choose a tag to compare

Patch Changes

wrangler@2.0.3

12 May 08:19
ded19b1
Compare
Choose a tag to compare

Patch Changes

  • #956 1caa5f7 Thanks @threepointone! - fix: don't crash during init if git is not installed

    When a command isn't available on a system, calling execa() on it throws an error, and not just a non zero exitCode. This patch fixes the flow so we don't crash the whole process when that happens on testing the presence of git when calling wrangler init.

    Fixes #950

  • #970 35e780b Thanks @GregBrimble! - fix: Fixes Pages Plugins and static asset routing.

    There was previously a bug where a relative pathname would be missing the leading slash which would result in routing errors.

  • #957 e0a0509 Thanks @JacobMGEvans! - refactor: Moving --legacy-env out of global
    The --legacy-env flag was in global scope, which only certain commands
    utilize the flag for functionality, and doesnt do anything for the other commands.

    resolves #933

  • #948 82165c5 Thanks @petebacondarwin! - fix: improve error message if custom build output is not found

    The message you get if Wrangler cannot find the output from the custom build is now more helpful.
    It will even look around to see if there is a suitable file nearby and make suggestions about what should be put in the main configuration.

    Closes #946

  • #952 ae3895e Thanks @d3lm! - feat: use host specific callback url

    To allow OAuth to work on environments such as WebContainer we have to generate a host-specific callback URL. This PR uses @webcontainer/env to generate such URL only for running in WebContainer. Otherwise the callback URL stays unmodified.

  • #951 09196ec Thanks @petebacondarwin! - fix: look for an alternate port in the dev command if the configured one is in use

    Previously, we were only calling getPort() if the configured port was undefined.
    But since we were setting the default for this during validation, it was never undefined.

    Fixes #949

  • #963 5b03eb8 Thanks @threepointone! - fix: work with Cloudflare WARP

    Using wrangler with Cloudflare WARP (https://developers.cloudflare.com/cloudflare-one/connections/connect-devices/warp/) requires using the Cloudflare certificate. This patch simply uses the certificate as NODE_EXTRA_CA_CERTS when we start wrangler.

    Test plan:

    • Turn on Cloudflare WARP/ Gateway with WARP
    • wrangler dev
    • Turn on Cloudflare WARP/ Gateway with DoH
    • wrangler dev
    • Turn off Cloudflare WARP
    • wrangler dev

    Fixes #953, #850

  • #964 0dfd95f Thanks @JacobMGEvans! - fix: KV not setting correctly
    The KV has URL inputs, which in the case of / would get collapsed and lost.
    T:o handle special characters encodeURIComponent is implemented.

    resolves #961

wrangler@2.0.2

10 May 09:44
1a7a7f1
Compare
Choose a tag to compare

Patch Changes

  • #947 38b7242 Thanks @GregBrimble! - Updated defaults and help of wrangler pages publish

  • #941 d84b568 Thanks @threepointone! - fix: bundle worker as iife if detected as a service worker

    We detect whether a worker is a "modules" format worker by the presence of a default export. This is a pretty good heuristic overall, but sometimes folks can make mistakes. One situation that's popped up a few times, is people writing exports, but still writing it in "service worker" format. We detect this fine, and log a warning about the exports, but send it up with the exports included. Unfortunately, our runtime throws when we mark a worker as a service worker, but still has exports. This patch fixes it so that the exports are not included in a service-worker worker.

    Note that if you're missing an event listener, it'll still error with "No event handlers were registered. This script does nothing." but that's a better error than the SyntaxError even when the listener was there.

    Fixes #937