Skip to content

Releases: cloudflare/workers-sdk

[email protected]

28 Mar 15:24
754f6c6
Compare
Choose a tag to compare

Patch Changes

  • #719 6503ace Thanks @petebacondarwin! - fix: ensure the correct worker name is published in legacy environments

    When a developer uses --env to specify an environment name, the Worker name should
    be computed from the top-level Worker name and the environment name.

    When the given environment name does not match those in the wrangler.toml, we error.
    But if no environments have been specified in the wrangler.toml, at all, then we only
    log a warning and continue.

    In this second case, we were reusing the top-level environment, which did not have the
    correct legacy environment fields set, such as the name. Now we ensure that such an
    environment is created as needed.

    See #680 (comment)

  • #708 763dcb6 Thanks @threepointone! - fix: unexpected commands and arguments should throw

    This enables strict mode in our command line parser (yargs), so that unexpected commands and options uniformly throw errors.

    Fixes #706

  • #713 18d09c7 Thanks @threepointone! - fix: don't fetch zone id for wrangler dev --local

    We shouldn't try to resolve a domain/route to a zone id when starting in local mode (since there may not even be network).

  • #692 52ea60f Thanks @threepointone! - fix: do not deploy to workers.dev when routes are defined in an environment

    When workers_dev is not configured, we had a bug where it would default to true inside an environment even when there were routes defined, thus publishing both to a workers.dev subdomain as well as the defined routes. The fix is to default workers_dev to undefined, and check when publishing whether or not to publish to workers.dev/defined routes.

    Fixes #690

  • #687 8f7ac7b Thanks @petebacondarwin! - fix: add warning about wrangler dev with remote Durable Objects

    Durable Objects that are being bound by script_name will not be isolated from the
    live data during development with wrangler dev.
    This change simply warns the developer about this, so that they can back out before
    accidentally changing live data.

    Fixes #319

  • #661 6967086 Thanks @JacobMGEvans! - polish: add "Beta" messaging around the CLI command for Pages. Explicitly specifying the command is Beta, not to be confused with Pages itself which is production ready.

  • #709 7e8ec9a Thanks @threepointone! - fix: trigger login flow if refreshtoken isn't valid

    If the auth refresh token isn't valid, then we should trigger the login flow. Reported in #316

  • #702 241000f Thanks @threepointone! - fix: setup jsx loaders when guessing worker format

    • We consider jsx to be regular js, and have setup our esbuild process to process js/mjs/cjs files as jsx.
    • We use a separate esbuild run on an entry point file when trying to guess the worker format, but hadn't setup the loaders there.
    • So if just the entrypoint file has any jsx in it, then we error because it can't parse the code.

    The fix is to add the same loaders to the esbuild run that guesses the worker format.

    Reported in #701

  • #711 3dac1da Thanks @threepointone! - fix: default wrangler tail to pretty print

    Fixes #707

  • #712 fb53fda Thanks @threepointone! - feat: Non-interactive mode

    Continuing the work from #325, this detects when wrangler is running inside an environment where "raw" mode is not available on stdin, and disables the features for hot keys and the shortcut bar. This also adds stubs for testing local mode functionality in local-mode-tests, and deletes the previous hacky dev2.test.tsx.

    Fixes #322

  • #716 6987cf3 Thanks @threepointone! - feat: path to a custom tsconfig

    This adds a config field and a command line arg tsconfig for passing a path to a custom typescript configuration file. We don't do any typechecking, but we do pass it along to our build process so things like compilerOptions.paths get resolved correctly.

  • #665 62a89c6 Thanks @caass! - fix: validate that bindings have unique names

    We don't want to have, for example, a KV namespace named "DATA"
    and a Durable Object also named "DATA". Then it would be ambiguous
    what exactly would live at env.DATA (or in the case of service workers,
    the DATA global) which could lead to unexpected behavior -- and errors.

    Similarly, we don't want to have multiple resources of the same type
    bound to the same name. If you've been working with some KV namespace
    called "DATA", and you add a second namespace but don't change the binding
    to something else (maybe you're copying-and-pasting and just changed out the id),
    you could be reading entirely the wrong stuff out of your KV store.

    So now we check for those sorts of situations and throw an error if
    we find that we've encountered one.

  • #698 e3e3243 Thanks @threepointone! - feat: inject process.env.NODE_ENV into scripts

    An extremely common pattern in the js ecosystem is to add additional behaviour gated by the value of process.env.NODE_ENV. For example, React leverages it heavily to add dev-time checks and warnings/errors, and to load dev/production versions of code. By doing this substitution ourselves, we can get a significant runtime boost in libraries/code that leverage this.

    This does NOT tackle the additional features of either minification, or proper node compatibility, or injecting wrangler's own environment name, which we will tackle in future PRs.

  • #680 8e2cbaf Thanks @JacobMGEvans! - refactor: support backwards compatibility with environment names and related CLI flags

    1. When in Legacy environment mode we should not compute name field if specified in an environment.
    2. Throw an Error when --env and --name are used together in Legacy Environment, except for Secrets & Tail which are using a special case getLegacyScriptName for parity with Wrangler1
    3. Started the refactor for args being utilized at the Config level, currently checking for Legacy Environment only.

    Fixes #672

  • #684 82ec7c2 Thanks @GregBrimble! - fix: Fix --binding option for wrangler pages dev.

    We'd broken this with #581. This reverts that PR, and fixes it slightly differently. Also added an integration test to ensure we don't regress in the future.

  • #678 82e4143 Thanks @threepointone! - fix: cleanup after pages dev tests

    We weren't killing the process started by wrangler whenever its parent was killed. This fix is to listen on SIGINT/SIGTERM and kill that process. I also did some minor configuration cleanups.

    Fixes #397
    Fixes <http...

Read more

[email protected]

23 Mar 06:40
b7e2135
Compare
Choose a tag to compare

Patch Changes

  • #675 e88a54e Thanks @threepointone! - fix: resolve non-js modules correctly in local mode

    In #633, we missed passing a cwd to the process that runs the miniflare cli. This broke how miniflare resolves modules, and led back to the dreaded "path should be a path.relative()d string" error. The fix is to simply pass the cwd to the spawn call.

    Test plan:

    cd packages/wrangler
    npm run build
    cd ../workers-chat-demo
    npx wrangler dev --local
    
  • #668 3dcdb0d Thanks @petebacondarwin! - fix: tighten up the named environment configuration

    Now, when we normalize and validate the raw config, we pass in the currently
    active environment name, and the config that is returned contains all the
    environment fields correctly normalized (including inheritance) at the top
    level of the config object. This avoids other commands from having to check
    both the current named environment and the top-level config for such fields.

    Also, now, handle the case where the active environment name passed in via the
    --env command line argument does not match any of the named environments
    in the configuration:

    • This is an error if there are named environments configured;
    • or only a warning if there are no named environments configured.
  • #633 003f3c4 Thanks @JacobMGEvans! - refactor: create a custom CLI wrapper around Miniflare API

    This allows us to tightly control the options that are passed to Miniflare.
    The current CLI is setup to be more compatible with how Wrangler 1 works, which is not optimal for Wrangler 2.

  • #633 84c857e Thanks @JacobMGEvans! - fix: ensure asset keys are relative to the project root

    Previously, asset file paths were computed relative to the current working
    directory, even if we had used -c to run Wrangler on a project in a different
    directory to the current one.

    Now, assets file paths are computed relative to the "project root", which is
    either the directory containing the wrangler.toml or the current working directory
    if there is no config specified.

  • #673 456e1da Thanks @petebacondarwin! - fix: allow the build field to be inherited/overridden in a named environment"

    Now the build field can be specified within a named environment, overriding whatever
    may appear at the top level.

    Resolves #588

  • #650 d3d1ff8 Thanks @petebacondarwin! - feat: make main an inheritable environment field

    See #588

  • #650 f0eed7f Thanks @petebacondarwin! - fix: make validation error messages more consistent

  • #662 612952b Thanks @JacobMGEvans! - bugfix: use alias -e for --env to prevent scripts using Wrangler 1 from breaking when switching to Wrangler 2.

  • #671 ef0aaad Thanks @GregBrimble! - fix: don't exit on initial Pages Functions compilation failure

    Previously, we'd exit the wrangler pages dev process if we couldn't immediately compile a Worker from the functions directory. We now log the error, but don't exit the process. This means that proxy processes can be cleaned up cleanly on SIGINT and SIGTERM, and it matches the behavior of if a compilation error is introduced once already running (we don't exit then either).

  • #667 e29a241 Thanks @threepointone! - fix: delete unused [site] assets

    We discovered critical issues with the way we expire unused assets with [site] (see #666, cloudflare/wrangler-legacy#2224), that we're going back to the legacy manner of handling unused assets, i.e- deleting unused assets.

    Fixes #666

  • #640 2a2d50c Thanks @caass! - Error if the user is trying to implement DO's in a service worker

    Durable Objects can only be implemented in Module Workers, so we should throw if we detect that
    the user is trying to implement a Durable Object but their worker is in Service Worker format.

[email protected]

21 Mar 15:20
Compare
Choose a tag to compare

Patch Changes

  • #656 aeb0fe0 Thanks @threepointone! - fix: resolve npm modules correctly

    When implementing legacy module specifiers, we didn't throughly test the interaction when there weren't any other files next to the entry worker, and importing npm modules. It would create a Regex that matched every import, and fail because a file of that name wasn't present in the source directory. This fix constructs a better regex, applies it only when there are more files next to the worker, and increases test coverage for that scenario.

    Fixes #655

[email protected]

21 Mar 07:38
Compare
Choose a tag to compare

Patch Changes

  • #647 f3f3907 Thanks @petebacondarwin! - feat: add support for --ip and config.dev.ip in the dev command

    Note that this change modifies the default listening address to localhost, which is different to 127.0.0.1, which is what Wrangler 1 does.
    For most developers this will make no observable difference, since the default host mapping in most OSes from localhost to 127.0.0.1.

    Resolves #584

[email protected]

09 Mar 06:40
998a6a1
Compare
Choose a tag to compare

Patch Changes

  • #557 835c3ae Thanks @threepointone! - fix: wrangler dev on unnamed workers in remote mode

    With unnamed workers, we use the filename as the name of the worker, which isn't a valid name for workers because of the . (This break was introduced in #545). The preview service accepts unnamed workers and generates a hash anyway, so the fix is to simply not send it, and use the host that the service provides.

[email protected]

08 Mar 08:55
Compare
Choose a tag to compare

Patch Changes

  • #523 8c99449 Thanks @threepointone! - feat: secrets + environments

    This implements environment support for wrangler secret (both legacy and services). We now consistently generate the right script name across commands with the getScriptName() helper.

    Based on the work by @mitchelvanbever in #95.

  • #554 18ac439 Thanks @petebacondarwin! - fix: limit bulk put API requests to batches of 5,000

    The kv:bulk put command now batches up put requests in groups of 5,000,
    displaying progress for each request.

  • #437 2805205 Thanks @jacobbednarz! - feat: use CLOUDFLARE_... environment variables deprecating CF_...

    Now one should use CLOUDFLARE_API_TOKEN, CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_API_BASE_URL rather than CF_API_TOKEN, CF_ACCOUNT_ID and CF_API_BASE_URL, which have been deprecated.

    If you use the deprecated variables they will still work but you will see a warning message.

    Within the Cloudflare tooling ecosystem, we have a mix of CF_ and CLOUDFLARE_
    for prefixing environment variables. Until recently, many of the tools
    were fine with CF_ however, there started to be conflicts with
    external tools (such as Cloudfoundary CLI), which also uses CF_ as a
    prefix, and would potentially be reading and writing the same value the
    Cloudflare tooling.

    The Go SDK1, Terraform2 and cf-terraforming3 have made the jump to
    the CLOUDFLARE_ prefix for environment variable prefix.

    In future, all SDKs will use this prefix for consistency and to allow all the tooling to reuse the same environment variables in the scenario where they are present.

  • #530 fdb4afd Thanks @threepointone! - feat: implement rules config field

    This implements the top level rules configuration field. It lets you specify transport rules for non-js modules. For example, you can specify *.md files to be included as a text file with -

    [[rules]]
    {type = "Text", globs = ["**/*.md"]}
    

    We also include a default ruleset -

      { type: "Text", globs: ["**/*.txt", "**/*.html"] },
      { type: "Data", globs: ["**/*.bin"] },
      { type: "CompiledWasm", globs: ["**/*.wasm"] },
    

    More info at https://developers.cloudflare.com/workers/cli-wrangler/configuration/#build.

    Known issues -

    • non-wasm module types do not work in --local mode
    • Data type does not work in service worker format, in either mode
  • #517 201a6bb Thanks @threepointone! - fix: publish environment specific routes

    This adds some tests for publishing routes, and fixes a couple of bugs with the flow.

    • fixes publishing environment specific routes, closes #513
    • default workers_dev to false if there are any routes specified
    • catches a hanging promise when we were toggling off a workers.dev subdomain (which should have been caught by the no-floating-promises lint rule, so that's concerning)
    • this also fixes publishing environment specific crons, but I'll write tests for that when I'm doing that feature in depth
  • #528 26f5ad2 Thanks @threepointone! - feat: top level main config field

    This implements a top level main field for wrangler.toml to define an entry point for the worker , and adds a deprecation warning for build.upload.main. The deprecation warning is detailed enough to give the exact line to copy-paste into your config file. Example -

    The `build.upload` field is deprecated. Delete the `build.upload` field, and add this to your configuration file:
    
    main = "src/chat.mjs"
    

    This also makes ./dist a default for build.upload.dir, to match wrangler 1's behaviour.

    Closes #488

  • #521 5947bfe Thanks @threepointone! - chore: update esbuild from 0.14.18 to 0.14.23

  • #480 10cb789 Thanks @caass! - Refactored tail functionality in preparation for adding pretty printing.

    • Moved the debug toggle from a build-time constant to a (hidden) CLI flag
    • Implemented pretty-printing logs, togglable via --format pretty CLI option
    • Added stronger typing for tail event messages
  • #525 9d5c14d Thanks @threepointone! - feat: tail+envs

    This implements service environment support for wrangler tail. Fairly simple, we just generate the right URLs. wrangler tail already works for legacy envs, so there's nothing to do there.

  • #553 bc85682 Thanks @threepointone! - feat: disable tunnel in wrangler dev

    Disables sharing local development server on the internet. We will bring this back after it's more polished/ready.

    Fixes #550

  • #522 a283836 Thanks @threepointone! - fix: websockets

    This fixes websockets in wrangler dev. It looks like we broke it in #503. I've reverted the specific changes made to proxy.ts.

    Test plan -

    cd packages/wrangler
    npm run build
    cd ../workers-chat-demo
    npx wrangler dev
    
    
  • #481 8874548 Thanks @threepointone! - fix: replace the word "deploy" with "publish" everywhere.

    We should be consistent with the word that describes how we get a worker to the edge. The command is publish, so let's use that everywhere.

  • #537 b978db4 Thanks @threepointone! - feat: --local mode only applies in wrangler dev

    We'd originally planned for --local mode to be a thing across all wrangler commands. In hindsight, that didn't make much sense, since every command other than wrangler dev assumes some interaction with cloudflare and their API. The only command other than dev where this "worked" was kv, but even that didn't make sense because wrangler dev wouldn't even read from it. We also have --experimental-enable-local-persistence there anyway.

    So this moves the --local flag to only apply for wrangler dev and removes any trace from other commands.

  • #518 72f035e Thanks @threepointone! - feat: implement [text_blobs]

    This implements support for [text_blobs] as defined by cloudflare/wrangler-legacy#1677.

    Text blobs can be defined in service-worker format with configuration in wrangler.toml as -

    [text_blobs]
    MYTEXT = "./path/to/my-text.file"
    

    The content of the file will then be available as the global MYTEXT inside your code. Note that this ONLY makes sense in service-worker format workers (for now).

    Workers Sites now uses [text_blobs] internally. Previously, we were inlining the asset manifest into the worker itself, but we now attach the asset manifest to the uploaded worker. I also added an additional example of Workers Sites with a modules format worker.

  • #532 046b17d Thanks @threepointone! - feat: dev+envs

    This implements service environments + wrangler dev. Fairly simple, it just needed the right url when creating the edge preview token.

    I tested ...

Read more

[email protected]

16 Feb 16:50
3789b16
Compare
Choose a tag to compare

Patch Changes

  • #414 f30426f Thanks @petebacondarwin! - fix: support build.upload.dir when using build.upload.main

    Although, build.upload.dir is deprecated, we should still support using it when the entry-point is being defined by the build.upload.main and the format is modules.

    Fixes #413

  • #447 2c5c934 Thanks @threepointone! - fix: Config should be resolved relative to the entrypoint

    During dev and publish, we should resolve wrangler.toml starting from the entrypoint, and then working up from there. Currently, we start from the directory from which we call wrangler, this changes that behaviour to start from the entrypoint instead.

    (To implement this, I made one big change: Inside commands, we now have to explicitly read configuration from a path, instead of expecting it to 'arrive' coerced into a configuration object.)

  • #472 804523a Thanks @JacobMGEvans! - bugfix: Replace .destroy() on faye-websockets with .close()
    added: Interface to give faye same types as compliant ws with additional .pipe() implementation; .on("message" => fn)

  • #462 a173c80 Thanks @caass! - Add filtering to wrangler tail, so you can now wrangler tail <name> --status ok, for example. Supported options:

    • --status cancelled --status error --> you can filter on ok, error, and cancelled to only tail logs that have that status
    • --header X-CUSTOM-HEADER:somevalue --> you can filter on headers, including ones that have specific values ("somevalue") or just that contain any header (e.g. --header X-CUSTOM-HEADER with no colon)
    • --method POST --method PUT --> filter on the HTTP method used to trigger the worker
    • --search catch-this --> only shows messages that contain the phrase "catch-this". Does not (yet!) support regular expressions
    • --ip self --ip 192.0.2.232 --> only show logs from requests that originate from the given IP addresses. "self" will be replaced with the IP address of the computer that sent the tail request.
  • #471 21cde50 Thanks @caass! - Add tests for wrangler tail:

    • ensure the correct API calls are made
    • ensure that filters are sent
    • ensure that the correct filters are sent
    • ensure that JSON gets spat out into the terminal
  • #398 40d9553 Thanks @threepointone! - feat: guess-worker-format

    This formalises the logic we use to "guess"/infer what a worker's format is - either "modules" or "service worker". Previously we were using the output of the esbuild process metafile to infer this, we now explicitly do so in a separate step (esbuild's so fast that it doesn't have any apparent performance hit, but we also do a simpler form of the build to get this information).

    This also adds --format as a command line arg for publish.

  • #438 64d62be Thanks @Electroid! - feat: Add support for "json" bindings

    Did you know? We have support for "json" bindings! Here are a few examples:

    [vars]
    text = "plain ol' string"
    count = 1
    complex = { enabled = true, id = 123 }

  • #422 ef13735 Thanks @threepointone! - chore: rename open-in-brower.ts to open-in-browser.ts

  • #411 a52f0e0 Thanks @ObsidianMinor! - feat: unsafe-bindings

    Adds support for "unsafe bindings", that is, bindings that aren't supported by wrangler, but are
    desired when uploading a Worker to Cloudflare. This allows you to use beta features before
    official support is added to wrangler, while also letting you migrate to proper support for the
    feature when desired. Note: these bindings may not work everywhere, and may break at any time.

  • #415 d826f5a Thanks @threepointone! - fix: don't crash when browser windows don't open

    We open browser windows for a few things; during wrangler dev, and logging in. There are environments where this doesn't work as expected (like codespaces, stackblitz, etc). This fix simply logs an error instead of breaking the flow. This is the same fix as #263, now applied to the rest of wrangler.

  • 91d8994 Thanks @Mexican-Man! - fix: do not merge routes with different methods when computing pages routes

    Fixes #92

  • #474 bfedc58 Thanks @JacobMGEvans! - bugfix: create reporting.toml file in "wrangler/config" and move error reporting user decisions to new reporting.toml

  • #445 d5935e7 Thanks @threepointone! - chore: remove experimental_services from configuration

    Now that we have [[unsafe.bindings]] (as of #411), we should use that for experimental features. This removes support for [experimental_services], and adds a helpful message for how to rewrite their configuration.

    This error is temporary, until the internal teams that were using this rewrite their configs. We'll remove it before GA.

    What the error looks like -

    Error: The "experimental_services" field is no longer supported. Instead, use [[unsafe.bindings]] to enable experimental features. Add this to your wrangler.toml:
    
    [[unsafe.bindings]]
    name = "SomeService"
    type = "service"
    service = "some-service"
    environment = "staging"
    
    [[unsafe.bindings]]
    name = "SomeOtherService"
    type = "service"
    service = "some-other-service"
    environment = "qa"
    
  • #456 b5f42c5 Thanks @threepointone! - chore: enable strict in tsconfig.json

    In the march towards full strictness, this enables strict in tsconfig.json and fixes the errors it pops up. A changeset is included because there are some subtle code changes, and we should leave a trail for them.

  • #408 14098af Thanks @mrbbot! - Upgrade miniflare to 2.3.0

  • #448 b72a111 Thanks @JacobMGEvans! - feat: add --yes with alias --y flag as automatic answer to all prompts and run wrangler init non-interactively.
    generated during setup:

    • package.json
    • TypeScript, which includes tsconfig.json & @cloudflare/workers-types
    • Template "hello world" Worker at src/index.ts
  • #403 f9fef8f Thanks @JacobMGEvans! - feat: add scripts to package.json & autogenerate name value when initializing a project
    To get wrangler init projects up and running with good ergonomics for deploying and development,
    added default scripts "start" & "deploy" with assumed TS or JS files in generated ./src/index.
    The name property is now derived from user input on init <name> or parent directory if no input is provided.

  • #452 1cf6701 Thanks @petebacondarwin! - feat: add support for publishing workers with r2 bucket bindings

    This change adds the ability to define bindings in your wrangler.toml...

Read more

[email protected]

07 Feb 12:26
1d40fbf
Compare
Choose a tag to compare

Patch Changes

  • #364 3575892 Thanks @threepointone! - enhance: small tweaks to wrangler init

    • A slightly better package.json
    • A slightly better tsconfig.json
    • installing typescript as a dev dependency
  • #380 aacd1c2 Thanks @GregBrimble! - fix: ensure pages routes are defined correctly

    In e151223 we introduced a bug where the RouteKey was now an array rather than a simple URL string. When it got stringified into the routing object these were invalid.
    E.g. [':page*', undefined] got stringified to ":page*," rather than ":page*".

    Fixes #379

  • #329 27a1f3b Thanks @petebacondarwin! - ci: run PR jobs on both Ubuntu, MacOS and Windows

    • update .gitattributes to be consistent on Windows
    • update Prettier command to ignore unknown files
      Windows seems to be more brittle here.
    • tighten up eslint config
      Windows seems to be more brittle here as well.
    • use the matrix.os value in the cache key
      Previously we were using running.os but this appeared not to be working.
  • #347 ede5b22 Thanks @threepointone! - fix: hide wrangler pages functions in the main help menu

    This hides wrangler pages functions in the main help menu, since it's only intended for internal usage right now. It still "works", so nothing changes in that regard. We'll bring this back when we have a broader story in wrangler for functions.

  • #360 f590943 Thanks @threepointone! - fix: kv:key get

    The api for fetching a kv value, unlike every other cloudflare api, returns just the raw value as a string (as opposed to the FetchResult-style json). However, our fetch utility tries to convert every api response to json before parsing it further. This leads to bugs like #359. The fix is to special case for kv:key get.

    Fixes #359.

  • #373 6e7baf2 Thanks @petebacondarwin! - fix: use the appropriate package manager when initializing a wrangler project

    Previously, when we initialized a project using wrangler init, we always used npm as the package manager.

    Now we check to see whether npm and yarn are actually installed, and also whether there is already a lock file in place before choosing which package manager to use.

    Fixes #353

  • #363 0add2a6 Thanks @threepointone! - fix: support uppercase hotkeys in wrangler dev

    Just a quick fix to accept uppercase hotkeys during dev.

  • #331 e151223 Thanks @petebacondarwin! - fix: generate valid URL route paths for pages on Windows

    Previously route paths were manipulated by file-system path utilities.
    On Windows this resulted in URLs that had backslashes, which are invalid for such URLs.

    Fixes #51
    Closes #235
    Closes #330
    Closes #327

  • #338 e0d2f35 Thanks @threepointone! - feat: environments for Worker Sites

    This adds environments support for Workers Sites. Very simply, it uses a separate kv namespace that's indexed by the environment name. This PR also changes the name of the kv namespace generated to match wrangler 1's implementation.

  • #329 e1d2198 Thanks @petebacondarwin! - test: support testing in CI on Windows

    • Don't rely on bash variables to configure tests
      The use of bash variables in the npm test script is not supported in Windows Powershell, causing CI on Windows to fail.
      These bash variables are used to override the API token and the Account ID.

      This change moves the control of mocking these two concepts into the test code, by adding mockAccountId() and mockApiToken() helpers.

      • The result is slightly more boilerplate in tests that need to avoid hitting the auth APIs.
      • But there are other tests that had to revert these environment variables. So the boilerplate is reduced there.
    • Sanitize command line for snapshot tests
      This change applies normalizeSlashes() and trimTimings() to command line outputs and error messages to avoid inconsistencies in snapshots.
      The benefit here is that authors do not need to keep adding them to all their snapshot tests.

    • Move all the helper functions into their own directory to keep the test directory cleaner.

  • #380 aacd1c2 Thanks @GregBrimble! - refactor: clean up pages routing

  • #343 cfd8ba5 Thanks @threepointone! - chore: update esbuild

    Update esbuild to 0.14.14. Also had to change import esbuild from "esbuild"; to import * as esbuild from "esbuild"; in dev.tsx.

  • #371 85ceb84 Thanks @nrgnrg! - fix: pages advanced mode usage

    Previously in pages projects using advanced mode (a single _worker.js or --script-path file rather than a ./functions folder), calling pages dev would quit without an error and not launch miniflare.

    This change fixes that and enables pages dev to be used with pages projects in advanced mode.

  • #383 969c887 Thanks @threepointone! - fix: remove redundant process.cwd() calls in wrangler init

    Followup from #372 (comment), just removing some unnecessary calls to process.cwd()/path.join(), since they're already relative to where they're called from.

  • #329 ac168f4 Thanks @petebacondarwin! - refactor: use helpers to manage npm commands

    This change speeds up tests and avoids us checking that npm did what it is supposed to do.

  • #348 b8e3b01 Thanks @threepointone! - chore: replace node-fetch with undici

    There are several reasons to replace node-fetch with undici:

    • undici's fetch() implementation is set to become node's standard fetch() implementation, which means we can just remove the dependency in the future (or optionally load it depending on which version of node is being used)
    • node-fetch pollutes the global type space with a number of standard types
    • we already bundle undici via miniflare/pages, so this means our bundle size could ostensibly become smaller.

    This replaces node-fetch with undici.

    • All instances of import fetch from "node-fetch" are replaced with import {fetch} from "undici"
    • undici also comes with spec compliant forms of FormData and File, so we could also remove formdata-node in form_data.ts
    • All the global types that were injected by node-fetch are now imported from undici (as well as some mistaken ones from node:url)
    • NOTE: this also turns on skipLibCheck in tsconfig.json. Some dependencies oddly depend on browser globals like Request, Response (like @miniflare/core, jest-fetch-mock, etc), which now fail because node-fetch isn't injecting those globals anymore. So we enable skipLibCheck to bypass them. (I'd thought skipLibCheck completely ignores 'third party' types, but that's not true - it still uses the module graph to scan types. So we're still typesafe. We should enable strict sometime to avoid anys, but that's for later.)
    • The bundle size isn't s...
Read more

[email protected]

30 Jan 17:52
f29d0cb
Compare
Choose a tag to compare

Patch Changes

  • #333 6320a32 Thanks @threepointone! - fix: pass worker name to syncAssets in dev

    This fix passes the correct worker name to syncAssets during wrangler dev. This function uses the name to create the backing kv store for a Workers Sites definition, so it's important we get the name right.

    I also fixed the lint warning introduced in #321, to pass props.enableLocalPersistence as a dependency in the useEffect call that starts the "local" mode dev server.

  • #335 a417cb0 Thanks @threepointone! - fix: prevent infinite loop when fetching a list of results

    When fetching a list of results from cloudflare APIs (e.g. when fetching a list of keys in a kv namespace), the api returns a cursor that a consumer should use to get the next 'page' of results. It appears this cursor can also be a blank string (while we'd only account for it to be undefined). By only accounting for it to be undefined, we were infinitely looping through the same page of results and never terminating. This PR fixes it by letting it be a blank string (and null, for good measure)

  • #332 a2155c1 Thanks @threepointone! - fix: wait for port to be available before creating a dev server

    When we run wrangler dev, we start a server on a port (defaulting to 8787). We do this separately for both local and edge modes. However, when switching between the two with the l hotkey, we don't 'wait' for the previous server to stop before starting the next one. This can crash the process, and we don't want that (of course). So we introduce a helper function waitForPortToBeAvailable() that waits for a port to be available before returning. This is used in both the local and edge modes, and prevents the bug right now, where switching between edge - local - edge crashes the process.

    (This isn't a complete fix, and we can still cause errors by very rapidly switching between the two modes. A proper long term fix for the future would probably be to hoist the proxy server hook above the <Remote/> and <Local/> components, and use a single instance throughout. But that requires a deeper refactor, and isn't critical at the moment.)

  • #336 ce61000 Thanks @threepointone! - feat: inline text-like files into the worker bundle

    We were adding text-like modules (i.e. .txt, .html and .pem files) as separate modules in the Worker definition, but this only really 'works' with the ES module Worker format. This commit changes that to inline the text-like files into the Worker bundle directly.

    We still have to do something similar with .wasm modules, but that requires a different fix, and we'll do so in a subsequent commit.

  • #336 ce61000 Thanks @threepointone! - feat: Sites support for local mode wrangler dev

    This adds support for Workers Sites in local mode when running wrangler dev. Further, it fixes a bug where we were sending the __STATIC_CONTENT_MANIFEST definition as a separate module even with service worker format, and a bug where we weren't uploading the namespace binding when other kv namespaces weren't present.

[email protected]

28 Jan 14:56
Compare
Choose a tag to compare

Patch Changes

  • #307 53c6318 Thanks @threepointone! - feat: wrangler secret * --local

    This PR implements wrangler secret for --local mode. The implementation is simply a no-op, since we don't want to actually write secret values to disk (I think?). I also got the messaging for remote mode right by copying from wrangler 1. Further, I added tests for all the wrangler secret commands.

  • #324 b816333 Thanks @GregBrimble! - Fixes wrangler pages dev failing to start for just a folder of static assets (no functions)

  • #317 d6ef61a Thanks @threepointone! - fix: restart the dev proxy server whenever it closes

    When we run wrangler dev, the session that we setup with the preview endpoint doesn't last forever, it dies after ignoring it for 5-15 minutes or so. The fix for this is to simply reconnect the server. So we use a state hook as a sigil, and add it to the dependency array of the effect that sets up the server, and simply change it every time the server closes.

    Fixes #197

    (In wrangler1, we used to restart the whole process, including uploading the worker again, making a new preview token, and so on. It looks like that they may not have been necessary.)

  • #312 77aa324 Thanks @threepointone! - fix: remove --prefer-offline when running npm install

    We were using --prefer-offline when running npm install during wrangler init. The behaviour is odd, it doesn't seem to fetch from the remote when the cache isn't hit, which is not what I'm expecting. So we remove --prefer-offline.

  • #311 a5537f1 Thanks @threepointone! - fix: custom builds should allow multiple commands

    We were running custom builds as a regular command with execa. This would fail whenever we tried to run compound commands like cargo install -q worker-build && worker-build --release (via #236). The fix is to use shell: true, so that the command is run in a shell and can thus use bash-y syntax like &&, and so on. I also switched to using execaCommand which splits a command string into parts correctly by itself.

  • #321 5b64a59 Thanks @geelen! - fix: disable local persistence by default & add --experimental-enable-local-persistence flag

    BREAKING CHANGE:

    When running dev locally any data stored in KV, Durable Objects or the cache are no longer persisted between sessions by default.

    To turn this back on add the --experimental-enable-local-persistence at the command line.