cloudflare / cloudflare/workers-sdk

Dependency cleanup/syntax modernisation

Open
#11,854 6 comments 2 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
4.5k
Forks
1.5k
Avg merge
3d 8h
Merged PRs (30d)
186

Description

Fairly low priority I imagine, but there are various dependency clean ups and code modernisations we can do in this repo.

I already opened a couple of PRs but want a tracking issue to add some context/discussion.

Here are my suggestions:

## Dependencies

| Dependency | Used by | Replace with | Notes |
| -- | -- | -- | -- |
| chalk | wrangler, create-cloudflare, cli | `styleText` (native) or `picocolors` | miniflare uses kleur, so could make sense to settle on that or move miniflare to also use styleText/picocolors |
| execa | wrangler, create-cloudflare | `tinyexec` | #12369 |
| strip-ansi | wrangler, vite-plugin-cloudflare | `stripVTControlCharacters` (native) | #11853 |
| find-up | tools, workers-utils, wrangler | `empathic` | #12601 |
| glob | tools, pages-shared, create-cloudflare | `tinyglobby` | vite-plugin-cloudflare already uses tinyglobby |
| rimraf | workflows-shared, miniflare, wrangler, pages-shared, workers-shared | `premove` | #11913 |
| `@typescript-eslint/eslint-plugin` | _various_ | Remove | #11906 |

These replacements are what the e18e community recommend (see [here](https://e18e.dev/docs/replacements/)). The modules being replaced are generally much larger, slower, and/or outdated.

I can explain each one if needed, just let me know 👍

## Syntax (modernisation/perf)

FYI I used the [e18e ESLint plugin](https://github.com/e18e/eslint-plugin) to find a bunch of these (in case you want a way to reproduce the findings etc).

| Old syntax | New syntax | Notes |
| -- | -- | -- |
| `arr[arr.length - 1]` | `arr.at(-1)` | |
| `[...arr].map(mapper)` | `Array.from(arr, mapper)` | Avoids an intermediate array being allocated |
| `str.match(regex)` | `regex.test(str)` | In conditional logic, to avoid an unused match array |

For these, we could run `eslint --fix` with the e18e plugin enabled to auto-fix them. There's various occurrences but not a huge amount so it'd be easily reviewable.

---

Let me know if there's any interest in any of these. I and others would be happy to contribute the changes if you give the go-ahead.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.