rspack-plugin-cloudflare 0.4.1 → 0.5.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 +2 -2
- package/dist/index.js +8 -2
- package/dist/index.js.map +1 -1
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ Run Cloudflare Workers in workerd while developing with `rspack serve`, with hot
|
|
|
15
15
|
npm install --save-dev rspack-plugin-cloudflare @rspack/core @rspack/cli @rspack/dev-server wrangler
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
-
Requires Node.js 24.10 or later.
|
|
18
|
+
Requires Node.js 24.10 or later. `wrangler` is a peer dependency, so you pick its version: the plugin runs your Worker with the Miniflare and workerd that your wrangler ships, and newer compatibility dates arrive when you update wrangler.
|
|
19
19
|
|
|
20
20
|
## Usage
|
|
21
21
|
|
|
@@ -156,7 +156,7 @@ node --run test
|
|
|
156
156
|
|
|
157
157
|
`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`.
|
|
158
158
|
|
|
159
|
-
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
|
|
159
|
+
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 test against, and `node --run build` bundles that code into `dist`. The daily Sync upstream workflow moves that wrangler, the packages it pins and the submodule to the latest wrangler release together and opens a pull request, which merges and releases itself once CI passes. CI also tests the oldest wrangler the peer range allows. To do the same locally, run `node scripts/sync-upstream.ts [version]`.
|
|
160
160
|
|
|
161
161
|
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.
|
|
162
162
|
|
package/dist/index.js
CHANGED
|
@@ -6,7 +6,6 @@ import { maybeStartOrUpdateRemoteProxySession, unstable_convertConfigBindingsToS
|
|
|
6
6
|
import { createHash, randomUUID } from "node:crypto";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
8
|
import { getCloudflarePreset } from "@cloudflare/unenv-preset";
|
|
9
|
-
import * as miniflare from "miniflare";
|
|
10
9
|
import { defineEnv } from "unenv";
|
|
11
10
|
import { convertToWranglerConfig, loadAndParseConfig } from "@cloudflare/config";
|
|
12
11
|
import { normalizeAndValidateConfig } from "@cloudflare/workers-utils";
|
|
@@ -55,6 +54,7 @@ function getModuleTypes(worker) {
|
|
|
55
54
|
}
|
|
56
55
|
return types;
|
|
57
56
|
}
|
|
57
|
+
const miniflare = createRequire(import.meta.resolve("wrangler"))("miniflare");
|
|
58
58
|
// src/nodejs-compat.ts
|
|
59
59
|
function resolvePolyfill(specifier) {
|
|
60
60
|
return fileURLToPath(import.meta.resolve(specifier));
|
|
@@ -3046,6 +3046,7 @@ window.location.replace(first);
|
|
|
3046
3046
|
// src/dev.ts
|
|
3047
3047
|
const PLUGIN_NAME$1 = "rspack-plugin-cloudflare";
|
|
3048
3048
|
const DEV_SERVER_PATH_RE = /^\/(?:webpack-dev-server|__webpack_dev_server__|__open-in-editor|lazy-compilation-using-)/;
|
|
3049
|
+
const LAZY_COMPILATION_PREFIX = "/_rspack/lazy/trigger";
|
|
3049
3050
|
const MINIFLARE_PATH_RE = /^\/(?:cdn-cgi\/local|__cf_local)\//;
|
|
3050
3051
|
const LEGACY_PATH_REWRITES = [
|
|
3051
3052
|
["/cdn-cgi/handler", "/cdn-cgi/local"],
|
|
@@ -3059,6 +3060,11 @@ function rewriteLegacyMiniflarePath(pathname) {
|
|
|
3059
3060
|
for (const [oldPrefix, newPrefix] of LEGACY_PATH_REWRITES) if (pathname === oldPrefix || pathname.startsWith(`${oldPrefix}/`)) return newPrefix + pathname.slice(oldPrefix.length);
|
|
3060
3061
|
return pathname;
|
|
3061
3062
|
}
|
|
3063
|
+
function getLazyCompilationPrefix(compiler) {
|
|
3064
|
+
const { lazyCompilation } = compiler.options;
|
|
3065
|
+
if (typeof lazyCompilation === "object" && lazyCompilation.prefix) return lazyCompilation.prefix;
|
|
3066
|
+
return LAZY_COMPILATION_PREFIX;
|
|
3067
|
+
}
|
|
3062
3068
|
/** Runs the entry Worker and any auxiliary Workers in one Miniflare, routing dev server requests like Cloudflare does. */
|
|
3063
3069
|
var DevSession = class DevSession {
|
|
3064
3070
|
/** Reads every Worker's config before the session starts, since `cloudflare.config.ts` can only be loaded asynchronously. */
|
|
@@ -3403,7 +3409,7 @@ var DevSession = class DevSession {
|
|
|
3403
3409
|
/** Connect middleware that sends each request through Cloudflare's router Worker, or straight to the Worker without assets. */
|
|
3404
3410
|
async handle(req, res, next) {
|
|
3405
3411
|
const url = getRequestUrl(req);
|
|
3406
|
-
if (DEV_SERVER_PATH_RE.test(url.pathname)) {
|
|
3412
|
+
if (DEV_SERVER_PATH_RE.test(url.pathname) || url.pathname.startsWith(getLazyCompilationPrefix(this.#compiler))) {
|
|
3407
3413
|
next();
|
|
3408
3414
|
return;
|
|
3409
3415
|
}
|