rspack-plugin-cloudflare 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -5
- package/THIRD_PARTY_NOTICES.txt +139 -0
- package/dist/index.d.ts +51 -7
- package/dist/index.js +3592 -131
- package/dist/index.js.map +1 -1
- package/dist/workers/asset-worker/index.js +5783 -0
- package/dist/workers/asset-worker/index.js.map +1 -0
- package/dist/workers/router-worker/index.js +6245 -0
- package/dist/workers/router-worker/index.js.map +1 -0
- package/package.json +14 -12
- package/dist/assets.d.ts +0 -31
- package/dist/assets.js +0 -112
- package/dist/assets.js.map +0 -1
- package/dist/build.d.ts +0 -216
- package/dist/build.js +0 -140
- package/dist/build.js.map +0 -1
- package/dist/config.d.ts +0 -19
- package/dist/config.js +0 -103
- package/dist/config.js.map +0 -1
- package/dist/containers.d.ts +0 -30
- package/dist/containers.js +0 -167
- package/dist/containers.js.map +0 -1
- package/dist/dev-entry.d.ts +0 -11
- package/dist/dev-entry.js +0 -44
- package/dist/dev-entry.js.map +0 -1
- package/dist/dev-worker.d.ts +0 -73
- package/dist/dev-worker.js +0 -247
- package/dist/dev-worker.js.map +0 -1
- package/dist/dev.d.ts +0 -28
- package/dist/dev.js +0 -422
- package/dist/dev.js.map +0 -1
- package/dist/http.d.ts +0 -23
- package/dist/http.js +0 -89
- package/dist/http.js.map +0 -1
- package/dist/inspector.d.ts +0 -5
- package/dist/inspector.js +0 -41
- package/dist/inspector.js.map +0 -1
- package/dist/miniflare.d.ts +0 -1
- package/dist/miniflare.js +0 -6
- package/dist/miniflare.js.map +0 -1
- package/dist/module-rules.d.ts +0 -4
- package/dist/module-rules.js +0 -29
- package/dist/module-rules.js.map +0 -1
- package/dist/nodejs-compat.d.ts +0 -14
- package/dist/nodejs-compat.js +0 -46
- package/dist/nodejs-compat.js.map +0 -1
- package/dist/options.d.ts +0 -45
- package/dist/options.js +0 -2
- package/dist/options.js.map +0 -1
- package/dist/routing.d.ts +0 -12
- package/dist/routing.js +0 -40
- package/dist/routing.js.map +0 -1
- package/dist/tunnel.d.ts +0 -15
- package/dist/tunnel.js +0 -94
- package/dist/tunnel.js.map +0 -1
- package/dist/worker-config.d.ts +0 -42
- package/dist/worker-config.js +0 -194
- package/dist/worker-config.js.map +0 -1
- package/src/assets.ts +0 -148
- package/src/build.ts +0 -153
- package/src/config.ts +0 -138
- package/src/containers.ts +0 -183
- package/src/dev-entry.ts +0 -50
- package/src/dev-worker.ts +0 -297
- package/src/dev.ts +0 -478
- package/src/http.ts +0 -102
- package/src/index.ts +0 -164
- package/src/inspector.ts +0 -44
- package/src/miniflare.ts +0 -7
- package/src/module-rules.ts +0 -36
- package/src/nodejs-compat.ts +0 -63
- package/src/options.ts +0 -46
- package/src/routing.ts +0 -48
- package/src/tunnel.ts +0 -106
- package/src/worker-config.ts +0 -237
package/README.md
CHANGED
|
@@ -41,6 +41,8 @@ The Worker is configured in your existing `wrangler.toml` / `wrangler.json(c)`,
|
|
|
41
41
|
|
|
42
42
|
Set `CLOUDFLARE_ENV` to pick a Wrangler environment for dev and build, as with the Vite plugin.
|
|
43
43
|
|
|
44
|
+
`minify = true` in the Wrangler config minifies the Worker in `rspack build`, since `wrangler deploy` no longer bundles it. Dev stays unminified, and source maps are uploaded either way unless `upload_source_maps = false`.
|
|
45
|
+
|
|
44
46
|
### Options
|
|
45
47
|
|
|
46
48
|
| Option | Default | |
|
|
@@ -58,11 +60,11 @@ Set `CLOUDFLARE_ENV` to pick a Wrangler environment for dev and build, as with t
|
|
|
58
60
|
|
|
59
61
|
## How dev works
|
|
60
62
|
|
|
61
|
-
Requests hit the rspack dev server first. A middleware in front of `dev-middleware`
|
|
63
|
+
Requests hit the rspack dev server first. A middleware in front of `dev-middleware` passes each one to Cloudflare's router and asset Workers, built from the same release of Cloudflare's code as `wrangler dev` runs:
|
|
62
64
|
|
|
63
|
-
- `assets.run_worker_first`
|
|
64
|
-
- Assets come from the client compiler's in-memory output, falling back to the assets directory on disk,
|
|
65
|
-
- The Worker's `ASSETS` binding
|
|
65
|
+
- `assets.run_worker_first`, `html_handling`, `not_found_handling`, `_headers` and `_redirects` behave as they do when deployed. Editing `_headers` or `_redirects` restarts the Workers to apply it.
|
|
66
|
+
- Assets come from the client compiler's in-memory output, falling back to the assets directory on disk, so they're always the latest build. Their `ETag` and `Cache-Control` headers are dropped, so the browser never reuses a stale dev file.
|
|
67
|
+
- The Worker's `ASSETS` binding goes to the same asset Worker, so it sees dev builds too.
|
|
66
68
|
- WebSocket upgrades go to the Worker, except the dev server's own HMR socket.
|
|
67
69
|
- `/cdn-cgi/local/scheduled` and the other Miniflare trigger endpoints (and their older `/cdn-cgi/handler/*` paths) reach the Worker directly.
|
|
68
70
|
- `/__debug` opens DevTools for every Worker.
|
|
@@ -105,7 +107,7 @@ Files are named `assets/<name>.<hash><ext>`. Dev serves them alongside the clien
|
|
|
105
107
|
|
|
106
108
|
### Containers
|
|
107
109
|
|
|
108
|
-
Container-backed Durable Objects run locally like `wrangler dev
|
|
110
|
+
Container-backed Durable Objects run locally like `wrangler dev`, using the same Cloudflare packages as wrangler and the Vite plugin: dev builds each Dockerfile (or pulls each registry image) before starting the Workers, then removes the containers when it exits. It needs a running Docker daemon, and like wrangler it doesn't support Windows outside WSL. Set `dev.enable_containers` to `false` in the Wrangler config to skip it. Images are built once per dev session, so restart dev after changing a Dockerfile.
|
|
109
111
|
|
|
110
112
|
### Sharing with a tunnel
|
|
111
113
|
|
|
@@ -116,12 +118,15 @@ Anyone with the URL reaches the dev server, including the Worker's local binding
|
|
|
116
118
|
## Contributing
|
|
117
119
|
|
|
118
120
|
```sh
|
|
121
|
+
git submodule update --init
|
|
119
122
|
npm ci
|
|
120
123
|
node --run test
|
|
121
124
|
```
|
|
122
125
|
|
|
123
126
|
`node --run test` lints, type checks, builds and runs the test suite, which starts real `rspack serve` and `rspack build` runs against the fixtures in `test/fixtures`.
|
|
124
127
|
|
|
128
|
+
Cloudflare's router and asset Workers and their `_headers` and `_redirects` parsers come from `@cloudflare/workers-shared`, which isn't published. The `workers-sdk` submodule is pinned to the commit of the wrangler release we depend on, and `node --run build` bundles that code into `dist`. The weekly Sync upstream workflow moves wrangler, Miniflare, the packages wrangler pins and the submodule to the latest wrangler release together, runs the tests and opens a pull request. To do the same locally, run `node scripts/sync-upstream.ts [version]`.
|
|
129
|
+
|
|
125
130
|
Releases are automated. Merging to `main` runs [semantic-release](https://github.com/semantic-release/semantic-release), which picks the version from the [conventional commit](https://www.conventionalcommits.org/) titles since the last release and publishes to npm through trusted publishing, with provenance. Pull requests are squash merged, so the pull request title is the commit that counts.
|
|
126
131
|
|
|
127
132
|
## License
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
rspack-plugin-cloudflare bundles code from the following projects into dist/.
|
|
2
|
+
|
|
3
|
+
----
|
|
4
|
+
|
|
5
|
+
cloudflare/workers-sdk: @cloudflare/workers-shared (dist/index.js and dist/workers)
|
|
6
|
+
https://github.com/cloudflare/workers-sdk, licensed under MIT OR Apache-2.0 and used here under the MIT License:
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2020 Cloudflare, Inc. <wrangler@cloudflare.com>
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any
|
|
11
|
+
person obtaining a copy of this software and associated
|
|
12
|
+
documentation files (the "Software"), to deal in the
|
|
13
|
+
Software without restriction, including without
|
|
14
|
+
limitation the rights to use, copy, modify, merge,
|
|
15
|
+
publish, distribute, sublicense, and/or sell copies of
|
|
16
|
+
the Software, and to permit persons to whom the Software
|
|
17
|
+
is furnished to do so, subject to the following
|
|
18
|
+
conditions:
|
|
19
|
+
|
|
20
|
+
The above copyright notice and this permission notice
|
|
21
|
+
shall be included in all copies or substantial portions
|
|
22
|
+
of the Software.
|
|
23
|
+
|
|
24
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
|
25
|
+
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
26
|
+
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
27
|
+
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
|
28
|
+
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
29
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
30
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
|
31
|
+
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
32
|
+
DEALINGS IN THE SOFTWARE.
|
|
33
|
+
|
|
34
|
+
----
|
|
35
|
+
|
|
36
|
+
toucan-js (dist/workers)
|
|
37
|
+
https://github.com/robertcepa/toucan-js
|
|
38
|
+
|
|
39
|
+
MIT License
|
|
40
|
+
|
|
41
|
+
Copyright (c) 2022 Robert Cepa
|
|
42
|
+
|
|
43
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
44
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
45
|
+
in the Software without restriction, including without limitation the rights
|
|
46
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
47
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
48
|
+
furnished to do so, subject to the following conditions:
|
|
49
|
+
|
|
50
|
+
The above copyright notice and this permission notice shall be included in all
|
|
51
|
+
copies or substantial portions of the Software.
|
|
52
|
+
|
|
53
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
54
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
55
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
56
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
57
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
58
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
59
|
+
SOFTWARE.
|
|
60
|
+
|
|
61
|
+
----
|
|
62
|
+
|
|
63
|
+
@sentry/core and @sentry/utils (dist/workers)
|
|
64
|
+
https://github.com/getsentry/sentry-javascript
|
|
65
|
+
|
|
66
|
+
MIT License
|
|
67
|
+
|
|
68
|
+
Copyright (c) 2019-2024 Functional Software, Inc. dba Sentry
|
|
69
|
+
|
|
70
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
71
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
72
|
+
the Software without restriction, including without limitation the rights to
|
|
73
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
74
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
|
75
|
+
so, subject to the following conditions:
|
|
76
|
+
|
|
77
|
+
The above copyright notice and this permission notice shall be included in all
|
|
78
|
+
copies or substantial portions of the Software.
|
|
79
|
+
|
|
80
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
81
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
82
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
83
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
84
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
85
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
86
|
+
SOFTWARE.
|
|
87
|
+
|
|
88
|
+
----
|
|
89
|
+
|
|
90
|
+
mime (dist/index.js)
|
|
91
|
+
https://github.com/broofa/mime
|
|
92
|
+
|
|
93
|
+
MIT License
|
|
94
|
+
|
|
95
|
+
Copyright (c) 2023 Robert Kieffer
|
|
96
|
+
|
|
97
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
98
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
99
|
+
in the Software without restriction, including without limitation the rights
|
|
100
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
101
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
102
|
+
furnished to do so, subject to the following conditions:
|
|
103
|
+
|
|
104
|
+
The above copyright notice and this permission notice shall be included in all
|
|
105
|
+
copies or substantial portions of the Software.
|
|
106
|
+
|
|
107
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
108
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
109
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
110
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
111
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
112
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
113
|
+
SOFTWARE.
|
|
114
|
+
----
|
|
115
|
+
|
|
116
|
+
ignore (dist/index.js)
|
|
117
|
+
https://github.com/kaelzhang/node-ignore
|
|
118
|
+
|
|
119
|
+
Copyright (c) 2013 Kael Zhang <i@kael.me>, contributors
|
|
120
|
+
http://kael.me/
|
|
121
|
+
|
|
122
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
123
|
+
a copy of this software and associated documentation files (the
|
|
124
|
+
"Software"), to deal in the Software without restriction, including
|
|
125
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
126
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
127
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
128
|
+
the following conditions:
|
|
129
|
+
|
|
130
|
+
The above copyright notice and this permission notice shall be
|
|
131
|
+
included in all copies or substantial portions of the Software.
|
|
132
|
+
|
|
133
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
134
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
135
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
136
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
137
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
138
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
139
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,54 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
1
|
+
import { Unstable_Config } from "wrangler";
|
|
2
|
+
import { Compiler, RspackOptions, RspackPluginInstance } from "@rspack/core";
|
|
3
|
+
type WorkerConfig = Unstable_Config;
|
|
4
|
+
/** Overrides merged into the Wrangler config after it loads, or a function that edits or returns overrides. */
|
|
5
|
+
type WorkerConfigCustomizer = Partial<WorkerConfig> | ((config: WorkerConfig) => Partial<WorkerConfig> | void);
|
|
6
|
+
interface AuxiliaryWorkerOptions {
|
|
7
|
+
/** Wrangler config for the auxiliary Worker, relative to the rspack `context`. */
|
|
8
|
+
configPath: string;
|
|
9
|
+
/** Changes the auxiliary Worker's config in code, applied after its config file loads. */
|
|
10
|
+
config?: WorkerConfigCustomizer;
|
|
11
|
+
/** Where `rspack build` writes it, relative to its Wrangler config. Defaults to `dist/<worker name>`. */
|
|
12
|
+
outputDir?: string;
|
|
13
|
+
}
|
|
14
|
+
interface TunnelOptions {
|
|
15
|
+
/** An existing named tunnel with a route to the dev server. Without one, a Quick Tunnel gets a random trycloudflare.com URL. */
|
|
16
|
+
name?: string;
|
|
17
|
+
/** Email addresses or `*@domain` patterns allowed through a Quick Tunnel, which then asks visitors to sign in. */
|
|
18
|
+
allowedMail?: string[];
|
|
19
|
+
}
|
|
20
|
+
interface CloudflarePluginOptions {
|
|
21
|
+
/** Wrangler config file, relative to the rspack `context`. Defaults to the nearest wrangler.jsonc, wrangler.json or wrangler.toml at or above `context`. */
|
|
22
|
+
configPath?: string;
|
|
23
|
+
/** Changes the Worker config in code, applied after the config file loads. */
|
|
24
|
+
config?: WorkerConfigCustomizer;
|
|
25
|
+
/** Wrangler environment to use, like `wrangler --env`, for every Worker. Defaults to `CLOUDFLARE_ENV`. */
|
|
26
|
+
environment?: string;
|
|
27
|
+
/** More Workers the entry Worker reaches through service bindings, run and built alongside it. */
|
|
28
|
+
auxiliaryWorkers?: AuxiliaryWorkerOptions[];
|
|
29
|
+
/** Adjusts the rspack config used to bundle a Worker. Return a new config or mutate the one given. */
|
|
30
|
+
worker?: (config: RspackOptions, context: {
|
|
31
|
+
name: string;
|
|
32
|
+
}) => RspackOptions | void;
|
|
33
|
+
/** Where `rspack build` writes the Worker bundle and its generated `wrangler.json`, relative to the Wrangler config. Defaults to `dist/<worker name>`. */
|
|
34
|
+
outputDir?: string;
|
|
35
|
+
/** Where local binding state (KV, Durable Objects, etc.) lives in dev, relative to the Wrangler config. `false` keeps it in memory. Defaults to `.wrangler/state`, shared with `wrangler dev`. */
|
|
36
|
+
persistState?: boolean | {
|
|
37
|
+
path: string;
|
|
38
|
+
};
|
|
39
|
+
/** Port for the workerd inspector in dev, or `false` to turn it off. Defaults to 9229, or the next free port. */
|
|
40
|
+
inspectorPort?: number | false;
|
|
41
|
+
/** Connects bindings marked `remote: true` to their real resources on Cloudflare in dev. `false` keeps every binding local. */
|
|
42
|
+
remoteBindings?: boolean;
|
|
43
|
+
/** Shares the dev server publicly through a Cloudflare Tunnel once it's listening. */
|
|
44
|
+
tunnel?: boolean | TunnelOptions;
|
|
45
|
+
}
|
|
4
46
|
export declare class CloudflarePlugin implements RspackPluginInstance {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
47
|
+
#private;
|
|
48
|
+
readonly options: CloudflarePluginOptions;
|
|
49
|
+
constructor(options?: CloudflarePluginOptions);
|
|
50
|
+
apply(compiler: Compiler): void;
|
|
9
51
|
}
|
|
10
52
|
export declare function cloudflare(options?: CloudflarePluginOptions): CloudflarePlugin;
|
|
53
|
+
export type { AuxiliaryWorkerOptions, CloudflarePluginOptions, TunnelOptions, WorkerConfig, WorkerConfigCustomizer };
|
|
54
|
+
//# sourceMappingURL=index.d.ts.map
|