Skip to content

Commit e9cbc40

Browse files
committed
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
1 parent 04f4332 commit e9cbc40

17 files changed

+596
-106
lines changed

.changeset/blue-rings-live.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
feat: implement `rules` config field
6+
7+
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 -
8+
9+
```
10+
[[rules]]
11+
{type = "Text", globs = ["**/*.md"]}
12+
```
13+
14+
We also include a default ruleset -
15+
16+
```
17+
{ type: "Text", globs: ["**/*.txt", "**/*.html"] },
18+
{ type: "Data", globs: ["**/*.bin"] },
19+
{ type: "CompiledWasm", globs: ["**/*.wasm"] },
20+
```
21+
22+
More info at https://developers.cloudflare.com/workers/cli-wrangler/configuration/#build.
23+
24+
Known issues -
25+
26+
- non-wasm module types do not work in `--local` mode
27+
- `Data` type does not work in service worker format, in either mode

package-lock.json

+39
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "example-rules-app",
3+
"version": "1.0.0",
4+
"description": "",
5+
"keywords": [],
6+
"author": "",
7+
"license": "ISC",
8+
"private": true
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
some content
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Welcome to Cloudflare Workers! This is your first worker.
3+
*
4+
* - Run `wrangler dev src/index.ts` in your terminal to start a development server
5+
* - Open a browser tab at http://localhost:8787/ to see your worker in action
6+
* - Run `wrangler publish src/index.ts --name my-worker` to publish your worker
7+
*
8+
* Learn more at https://developers.cloudflare.com/workers/
9+
*/
10+
11+
import content from "./content.md";
12+
13+
export default {
14+
async fetch(request: Request): Promise<Response> {
15+
return new Response(`${request.url}: ${content}`);
16+
},
17+
};
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name = "example-rules-app"
2+
compatibility_date = "2022-02-28"
3+
main = "src/index.ts"
4+
5+
[[rules]]
6+
type = "Text"
7+
globs = ["**/*.md"]
8+
fallthrough = true

packages/wrangler/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"@sentry/node": "^6.17.6",
5454
"@types/command-exists": "^1.2.0",
5555
"@types/estree": "^0.0.50",
56+
"@types/glob-to-regexp": "0.4.1",
5657
"@types/mime": "^2.0.3",
5758
"@types/prompts": "^2.0.14",
5859
"@types/react": "^17.0.37",
@@ -69,6 +70,7 @@
6970
"faye-websocket": "^0.11.4",
7071
"finalhandler": "^1.1.2",
7172
"find-up": "^6.2.0",
73+
"glob-to-regexp": "0.4.1",
7274
"ignore": "^5.2.0",
7375
"ink": "^3.2.0",
7476
"ink-select-input": "^4.2.1",

packages/wrangler/src/__tests__/dev.test.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ function renderDev({
6464
initialMode = "local",
6565
jsxFactory,
6666
jsxFragment,
67+
rules = [],
6768
bindings = {
6869
kv_namespaces: [],
6970
vars: {},
@@ -87,6 +88,7 @@ function renderDev({
8788
name={name}
8889
entry={entry}
8990
env={env}
91+
rules={rules}
9092
port={port}
9193
legacyEnv={legacyEnv}
9294
buildCommand={buildCommand}

0 commit comments

Comments
 (0)