rspack-plugin-cloudflare 0.1.0 → 0.2.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.
Files changed (75) hide show
  1. package/README.md +8 -5
  2. package/THIRD_PARTY_NOTICES.txt +139 -0
  3. package/dist/index.d.ts +51 -7
  4. package/dist/index.js +3591 -131
  5. package/dist/index.js.map +1 -1
  6. package/dist/workers/asset-worker/index.js +5783 -0
  7. package/dist/workers/asset-worker/index.js.map +1 -0
  8. package/dist/workers/router-worker/index.js +6245 -0
  9. package/dist/workers/router-worker/index.js.map +1 -0
  10. package/package.json +13 -11
  11. package/dist/assets.d.ts +0 -31
  12. package/dist/assets.js +0 -112
  13. package/dist/assets.js.map +0 -1
  14. package/dist/build.d.ts +0 -216
  15. package/dist/build.js +0 -140
  16. package/dist/build.js.map +0 -1
  17. package/dist/config.d.ts +0 -19
  18. package/dist/config.js +0 -103
  19. package/dist/config.js.map +0 -1
  20. package/dist/containers.d.ts +0 -30
  21. package/dist/containers.js +0 -167
  22. package/dist/containers.js.map +0 -1
  23. package/dist/dev-entry.d.ts +0 -11
  24. package/dist/dev-entry.js +0 -44
  25. package/dist/dev-entry.js.map +0 -1
  26. package/dist/dev-worker.d.ts +0 -73
  27. package/dist/dev-worker.js +0 -247
  28. package/dist/dev-worker.js.map +0 -1
  29. package/dist/dev.d.ts +0 -28
  30. package/dist/dev.js +0 -422
  31. package/dist/dev.js.map +0 -1
  32. package/dist/http.d.ts +0 -23
  33. package/dist/http.js +0 -89
  34. package/dist/http.js.map +0 -1
  35. package/dist/inspector.d.ts +0 -5
  36. package/dist/inspector.js +0 -41
  37. package/dist/inspector.js.map +0 -1
  38. package/dist/miniflare.d.ts +0 -1
  39. package/dist/miniflare.js +0 -6
  40. package/dist/miniflare.js.map +0 -1
  41. package/dist/module-rules.d.ts +0 -4
  42. package/dist/module-rules.js +0 -29
  43. package/dist/module-rules.js.map +0 -1
  44. package/dist/nodejs-compat.d.ts +0 -14
  45. package/dist/nodejs-compat.js +0 -46
  46. package/dist/nodejs-compat.js.map +0 -1
  47. package/dist/options.d.ts +0 -45
  48. package/dist/options.js +0 -2
  49. package/dist/options.js.map +0 -1
  50. package/dist/routing.d.ts +0 -12
  51. package/dist/routing.js +0 -40
  52. package/dist/routing.js.map +0 -1
  53. package/dist/tunnel.d.ts +0 -15
  54. package/dist/tunnel.js +0 -94
  55. package/dist/tunnel.js.map +0 -1
  56. package/dist/worker-config.d.ts +0 -42
  57. package/dist/worker-config.js +0 -194
  58. package/dist/worker-config.js.map +0 -1
  59. package/src/assets.ts +0 -148
  60. package/src/build.ts +0 -153
  61. package/src/config.ts +0 -138
  62. package/src/containers.ts +0 -183
  63. package/src/dev-entry.ts +0 -50
  64. package/src/dev-worker.ts +0 -297
  65. package/src/dev.ts +0 -478
  66. package/src/http.ts +0 -102
  67. package/src/index.ts +0 -164
  68. package/src/inspector.ts +0 -44
  69. package/src/miniflare.ts +0 -7
  70. package/src/module-rules.ts +0 -36
  71. package/src/nodejs-compat.ts +0 -63
  72. package/src/options.ts +0 -46
  73. package/src/routing.ts +0 -48
  74. package/src/tunnel.ts +0 -106
  75. package/src/worker-config.ts +0 -237
package/README.md CHANGED
@@ -58,11 +58,11 @@ Set `CLOUDFLARE_ENV` to pick a Wrangler environment for dev and build, as with t
58
58
 
59
59
  ## How dev works
60
60
 
61
- Requests hit the rspack dev server first. A middleware in front of `dev-middleware` routes each one the way Cloudflare's router does:
61
+ 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
62
 
63
- - `assets.run_worker_first` rules decide whether the Worker sees a request before assets, with `!/` rules always going to assets.
64
- - Assets come from the client compiler's in-memory output, falling back to the assets directory on disk, with `html_handling` and `not_found_handling` applied.
65
- - The Worker's `ASSETS` binding reads from the same place, so it sees dev builds too.
63
+ - `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.
64
+ - 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.
65
+ - The Worker's `ASSETS` binding goes to the same asset Worker, so it sees dev builds too.
66
66
  - WebSocket upgrades go to the Worker, except the dev server's own HMR socket.
67
67
  - `/cdn-cgi/local/scheduled` and the other Miniflare trigger endpoints (and their older `/cdn-cgi/handler/*` paths) reach the Worker directly.
68
68
  - `/__debug` opens DevTools for every Worker.
@@ -105,7 +105,7 @@ Files are named `assets/<name>.<hash><ext>`. Dev serves them alongside the clien
105
105
 
106
106
  ### Containers
107
107
 
108
- Container-backed Durable Objects run locally like `wrangler dev`: 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.
108
+ 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
109
 
110
110
  ### Sharing with a tunnel
111
111
 
@@ -116,12 +116,15 @@ Anyone with the URL reaches the dev server, including the Worker's local binding
116
116
  ## Contributing
117
117
 
118
118
  ```sh
119
+ git submodule update --init
119
120
  npm ci
120
121
  node --run test
121
122
  ```
122
123
 
123
124
  `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
125
 
126
+ 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]`.
127
+
125
128
  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
129
 
127
130
  ## 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 type { CloudflarePluginOptions } from './options.js';
2
- import type { Compiler, RspackPluginInstance } from '@rspack/core';
3
- export type { AuxiliaryWorkerOptions, CloudflarePluginOptions, TunnelOptions, WorkerConfig, WorkerConfigCustomizer, } from './options.js';
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
- #private;
6
- readonly options: CloudflarePluginOptions;
7
- constructor(options?: CloudflarePluginOptions);
8
- apply(compiler: Compiler): void;
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