[workers] Start migrating workers to the monorepo

This commit is contained in:
Manav Rathi 2024-03-19 10:57:04 +05:30
parent f0547d0a10
commit cfd298a052
No known key found for this signature in database
4 changed files with 83 additions and 0 deletions

10
infra/workers/.gitignore vendored Normal file
View file

@ -0,0 +1,10 @@
node_modules/
.DS_Store
.wrangler/
# Workers mostly have dev dependencies, and usually only wrangler, so exact
# version details and the resulting `yarn.lock` is unnecessary noise.
#
# If we need to pin some runtime dependency, we can pin it to an exact version
# in the package.json itself.
yarn.lock

View file

@ -0,0 +1,3 @@
{
"tabWidth": 4
}

32
infra/workers/README.md Normal file
View file

@ -0,0 +1,32 @@
# Cloudflare Workers
Source code for our [Cloudflare
Workers](https://developers.cloudflare.com/workers/).
Each worker is a self contained directory with its each `package.json`.
## Deploying
* Switch to a worker directory, e.g. `cd health-check`.
* Install dependencies (if needed) with `yarn`
* Login into wrangler (if needed) using `yarn wrangler login`
* Deploy! `yarn wrangler publish`
Wrangler is the CLI provided by Cloudflare to manage workers. Apart from
deploying, it also allows us to stream logs from running workers by using `yarn
wrangler tail`.
## Creating a new worker
Copy paste an existing one. Unironically this is a good option because the
Cloudflare template has a lot of unnecessary noise, but if really do want to
create one from scratch, use `npm create cloudflare@latest`.
To import an existing worker from the Cloudflare dashboard, use
```sh
npm create cloudflare@2 existing-worker-name -- --type pre-existing --existing-script existing-worker-name
```

View file

@ -0,0 +1,38 @@
{
/* A shared TSConfig for use by TypeScript Cloudflare Workers */
/* TSConfig docs: https://aka.ms/tsconfig.json */
"compilerOptions": {
/* tsc is used for by us for type checking, not compilation (the
Cloudflare workers runtime natively supports TypeScript) */
"noEmit": true,
/* The Workers runtime supports the latest and greatest */
/* https://developers.cloudflare.com/workers/reference/languages/#javascript--typescript */
"lib": ["esnext"],
"target": "esnext",
"module": "esnext",
/* Types that are implicitly available */
/* https://www.npmjs.com/package/@cloudflare/workers-types */
"types": ["@cloudflare/workers-types"],
/* Tell TypeScript how to lookup the file for a given import */
"moduleResolution": "node",
/* Speed things up by not type checking `node_modules` */
"skipLibCheck": true,
/* Require the `type` modifier when importing types */
"verbatimModuleSyntax": true,
/* Enable importing .json files */
"resolveJsonModule": true,
/* strict and then some */
"strict": true,
"noImplicitReturns": true,
"noUnusedParameters": true,
"noUnusedLocals": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedIndexedAccess": true,
"exactOptionalPropertyTypes": true
}
}