@harlan-zw/nuxt-cloudflare 0.2.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 +90 -21
- package/dist/d1.mjs +11 -1
- package/dist/module.d.mts +1 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +2 -0
- package/dist/runtime/server/plugins/wide-events.d.ts +4 -5
- package/dist/runtime/server/plugins/wide-events.js +11 -11
- package/dist/wrangler.d.mts +16 -1
- package/dist/wrangler.mjs +28 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,8 +1,64 @@
|
|
|
1
|
-
|
|
1
|
+
<h1>@harlan-zw/nuxt-cloudflare</h1>
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[![npm version][npm-version-src]][npm-version-href]
|
|
4
|
+
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
|
5
|
+
[![License][license-src]][license-href]
|
|
6
|
+
[![Nuxt][nuxt-src]][nuxt-href]
|
|
4
7
|
|
|
5
|
-
|
|
8
|
+
Nuxt Cloudflare gives a Nuxt 4 app opinionated Cloudflare defaults, a generated Wrangler config, and diagnostics that fail a bad deploy before Cloudflare does.
|
|
9
|
+
|
|
10
|
+
The defaults come from production patterns already running in Nuxt SEO and gscdump. The module owns platform policy. Your application topology stays yours.
|
|
11
|
+
|
|
12
|
+
Status: experimental. APIs may change before the first release.
|
|
13
|
+
|
|
14
|
+
<p align="center">
|
|
15
|
+
<table>
|
|
16
|
+
<tbody>
|
|
17
|
+
<td align="center">
|
|
18
|
+
<sub>Made possible by my <a href="https://github.com/sponsors/harlan-zw">Sponsor Program 💖</a><br> Follow me <a href="https://twitter.com/harlan_zw">@harlan_zw</a> 🐦 • Join <a href="https://discord.gg/275MBUBvgP">Discord</a> for help</sub><br>
|
|
19
|
+
</td>
|
|
20
|
+
</tbody>
|
|
21
|
+
</table>
|
|
22
|
+
</p>
|
|
23
|
+
|
|
24
|
+
## Features
|
|
25
|
+
|
|
26
|
+
- ⚙️ **Generated Wrangler config:** Cloudflare preset, Node compatibility, and sane observability, with anything you authored left alone.
|
|
27
|
+
- 🩺 **Deploy doctor:** audits Wrangler's effective config, including generated redirects and every named environment.
|
|
28
|
+
- 💰 **Cost controls:** 1% log and trace sampling, asset-first routing, and warnings when a setting turns free requests into billed ones.
|
|
29
|
+
- 🗄️ **Workers Caching:** version-isolated by default, with a fail-closed `private, no-store` for rendered HTML.
|
|
30
|
+
- 📦 **Partial bundling:** chunks deploy as separate modules, which cut startup CPU on the Nuxt SEO Pro Worker from 118ms to 81ms.
|
|
31
|
+
- 🔑 **Exact binding types:** `nuxt prepare` runs Wrangler and writes a compatibility-aware declaration, then production builds fail on drift.
|
|
32
|
+
- 🧰 **D1 primitives:** recovering sessions, safe write retries, and parameter plans that respect the 100-bind limit.
|
|
33
|
+
|
|
34
|
+
## Installation
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npx nuxi@latest module add @harlan-zw/nuxt-cloudflare
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
> [!TIP]
|
|
41
|
+
> Generate an Agent Skill for this package using [skilld](https://github.com/harlan-zw/skilld):
|
|
42
|
+
> ```bash
|
|
43
|
+
> npx skilld add @harlan-zw/nuxt-cloudflare
|
|
44
|
+
> ```
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
export default defineNuxtConfig({
|
|
48
|
+
modules: ['@harlan-zw/nuxt-cloudflare'],
|
|
49
|
+
|
|
50
|
+
nuxtCloudflare: {
|
|
51
|
+
requiredSecrets: ['NUXT_SESSION_PASSWORD'],
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
nitro: {
|
|
55
|
+
storage: {
|
|
56
|
+
cache: { driver: 'cloudflare-kv-binding', binding: 'CACHE' },
|
|
57
|
+
kv: { driver: 'cloudflare-kv-binding', binding: 'KV' },
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
})
|
|
61
|
+
```
|
|
6
62
|
|
|
7
63
|
## Defaults
|
|
8
64
|
|
|
@@ -15,6 +71,7 @@ Every default below yields to a value you wrote. The root `wrangler.jsonc`, `wra
|
|
|
15
71
|
- `workers_dev` disabled when a route proves the Worker remains reachable; workers without routes must choose explicitly
|
|
16
72
|
- Version metadata binding at `CF_VERSION_METADATA`
|
|
17
73
|
- Smart Placement enabled unless the project chooses a placement
|
|
74
|
+
- Partial bundling: `find_additional_modules` plus a fallthrough `ESModule` rule for `**/*.mjs`, unless a rule already covers mjs or `no_bundle` is set
|
|
18
75
|
- Workers Caching enabled with version isolation
|
|
19
76
|
- Rendered HTML forced to `private, no-store`; explicit non-HTML cache policies remain intact
|
|
20
77
|
- Source-map upload when the Nitro build emits maps; an authored value is preserved
|
|
@@ -29,24 +86,9 @@ Every default below yields to a value you wrote. The root `wrangler.jsonc`, `wra
|
|
|
29
86
|
|
|
30
87
|
Persistent KV mounts are never wrapped. The expiry policy applies only to cache data.
|
|
31
88
|
|
|
32
|
-
##
|
|
89
|
+
## Configuration
|
|
33
90
|
|
|
34
|
-
|
|
35
|
-
export default defineNuxtConfig({
|
|
36
|
-
modules: ['@harlan-zw/nuxt-cloudflare'],
|
|
37
|
-
|
|
38
|
-
nuxtCloudflare: {
|
|
39
|
-
requiredSecrets: ['NUXT_SESSION_PASSWORD'],
|
|
40
|
-
},
|
|
41
|
-
|
|
42
|
-
nitro: {
|
|
43
|
-
storage: {
|
|
44
|
-
cache: { driver: 'cloudflare-kv-binding', binding: 'CACHE' },
|
|
45
|
-
kv: { driver: 'cloudflare-kv-binding', binding: 'KV' },
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
})
|
|
49
|
-
```
|
|
91
|
+
Everything below is optional. The defaults above already cover a plain deploy.
|
|
50
92
|
|
|
51
93
|
To configure a cache mount when one does not already exist:
|
|
52
94
|
|
|
@@ -67,6 +109,8 @@ Keep server runtime secret defaults empty. Nuxt reads matching `NUXT_*` values f
|
|
|
67
109
|
|
|
68
110
|
Workers Caching is separate from Nitro's KV-backed cache. The module enables version-isolated caching by default. Set `workersCache: { _tag: 'disabled' }` to opt out. Choose cross-version caching only with an explicit purge path.
|
|
69
111
|
|
|
112
|
+
Partial bundling is on by default. Wrangler's default bundling inlines every lazy chunk into one module the isolate parses at startup; on the Nuxt SEO Pro Worker that was a 26.3MB bundle, and partial bundling cut `wrangler check startup` active CPU from 118ms to 81ms by deploying chunks as separate modules. The generated config gains `find_additional_modules: true` and a fallthrough `ESModule` rule for `**/*.mjs`; rules you wrote are kept, and one that already covers mjs wins. Configs with `no_bundle` inject neither key, because Wrangler already defaults `find_additional_modules` to true there and applies your rules as written. Set `partialBundles: false` to keep single-bundle deploys.
|
|
113
|
+
|
|
70
114
|
The module writes a fail-closed `private, no-store` before routing, so a response nobody described is never cached. It never rewrites a policy you set on a response that is not a rendered document, so asset and API route rules are yours.
|
|
71
115
|
|
|
72
116
|
For a rendered document it applies `workersCache.html`:
|
|
@@ -265,7 +309,7 @@ The helper owns a private temporary directory and creates the JSON file with mod
|
|
|
265
309
|
|
|
266
310
|
The module does not choose Worker names, routes, domains, resource IDs, placement, CPU limits, queue jobs, R2 deletion policy, or deployment promotion. `@harlan-zw/nuxt-cf-jobs` continues to own queues, job durability, recovery, and outbox behavior.
|
|
267
311
|
|
|
268
|
-
Next
|
|
312
|
+
Next extractions from Nuxt SEO and gscdump:
|
|
269
313
|
|
|
270
314
|
1. Nuxt Content D1 sync plus readiness verification
|
|
271
315
|
2. Expand-only D1 migration audit with protected-table rebuild detection
|
|
@@ -275,3 +319,28 @@ Next high-value extractions from Nuxt SEO and gscdump:
|
|
|
275
319
|
6. R2 lifecycle declaration and read-only storage stocktake
|
|
276
320
|
|
|
277
321
|
These remain separate adapters because their schemas, retention, and deployment ordering require explicit application policy.
|
|
322
|
+
|
|
323
|
+
## Sponsors
|
|
324
|
+
|
|
325
|
+
<p align="center">
|
|
326
|
+
<a href="https://raw.githubusercontent.com/harlan-zw/static/main/sponsors.svg">
|
|
327
|
+
<img src='https://raw.githubusercontent.com/harlan-zw/static/main/sponsors.svg' alt='sponsors'/>
|
|
328
|
+
</a>
|
|
329
|
+
</p>
|
|
330
|
+
|
|
331
|
+
## License
|
|
332
|
+
|
|
333
|
+
Licensed under the [MIT license](https://github.com/harlan-zw/harlan-nuxt/blob/main/packages/nuxt-cloudflare/LICENSE.md).
|
|
334
|
+
|
|
335
|
+
<!-- Badges -->
|
|
336
|
+
[npm-version-src]: https://img.shields.io/npm/v/%40harlan-zw%2Fnuxt-cloudflare/latest.svg?style=flat&colorA=18181B&colorB=28CF8D
|
|
337
|
+
[npm-version-href]: https://npmjs.com/package/@harlan-zw/nuxt-cloudflare
|
|
338
|
+
|
|
339
|
+
[npm-downloads-src]: https://img.shields.io/npm/dm/%40harlan-zw%2Fnuxt-cloudflare.svg?style=flat&colorA=18181B&colorB=28CF8D
|
|
340
|
+
[npm-downloads-href]: https://npmjs.com/package/@harlan-zw/nuxt-cloudflare
|
|
341
|
+
|
|
342
|
+
[license-src]: https://img.shields.io/github/license/harlan-zw/harlan-nuxt.svg?style=flat&colorA=18181B&colorB=28CF8D
|
|
343
|
+
[license-href]: https://github.com/harlan-zw/harlan-nuxt/blob/main/packages/nuxt-cloudflare/LICENSE.md
|
|
344
|
+
|
|
345
|
+
[nuxt-src]: https://img.shields.io/badge/Nuxt-18181B?logo=nuxt
|
|
346
|
+
[nuxt-href]: https://nuxt.com
|
package/dist/d1.mjs
CHANGED
|
@@ -10,7 +10,17 @@ const SESSION_RESET_D1_SIGNALS = [
|
|
|
10
10
|
"D1 DB reset because its code was updated",
|
|
11
11
|
"Internal error while starting up D1 DB storage caused object to be reset",
|
|
12
12
|
"Internal error in D1 DB storage caused object to be reset",
|
|
13
|
-
"storage caused object to be reset"
|
|
13
|
+
"storage caused object to be reset",
|
|
14
|
+
// Cloudflare evicts the Durable Object backing a session and reports it in
|
|
15
|
+
// its own words: "Connection closed: this Durable Object instance is no
|
|
16
|
+
// longer active. Reconnect or retry the request." Same family as
|
|
17
|
+
// `D1_RESET_DO` — the session is gone, the query is replayable.
|
|
18
|
+
//
|
|
19
|
+
// Match the Durable Object clause, NOT the "Connection closed" prefix the
|
|
20
|
+
// message leads with: that prefix is generic enough to appear on unrelated
|
|
21
|
+
// transports, and replaying an arbitrary closed connection as a D1 session
|
|
22
|
+
// reset would retry writes that never belonged to this classifier.
|
|
23
|
+
"Durable Object instance is no longer active"
|
|
14
24
|
];
|
|
15
25
|
const TRANSIENT_D1_SIGNALS = [
|
|
16
26
|
"Network connection lost",
|
package/dist/module.d.mts
CHANGED
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -165,6 +165,7 @@ function configureNitroCloudflare(nitro, options, context = {}) {
|
|
|
165
165
|
nitro.cloudflare.wrangler = applyCloudflareDefaults(nitro.cloudflare.wrangler ?? {}, {
|
|
166
166
|
compatibilityDate: options.compatibilityDate,
|
|
167
167
|
logsSampleRate: options.logsSampleRate,
|
|
168
|
+
partialBundles: options.partialBundles,
|
|
168
169
|
requiredSecrets: options.requiredSecrets,
|
|
169
170
|
tracesSampleRate: options.tracesSampleRate,
|
|
170
171
|
uploadSourceMaps: options.sourceMaps ?? nitro.sourceMap ?? context.serverSourceMaps ?? false,
|
|
@@ -361,6 +362,7 @@ const module$1 = defineNuxtModule({
|
|
|
361
362
|
compatibilityMaxAgeDays: 90,
|
|
362
363
|
doctor: { _tag: "advisory" },
|
|
363
364
|
logsSampleRate: 0.01,
|
|
365
|
+
partialBundles: true,
|
|
364
366
|
tracesSampleRate: 0.01,
|
|
365
367
|
versionMetadataBinding: "CF_VERSION_METADATA",
|
|
366
368
|
workersCache: { _tag: "enabled", crossVersion: false }
|
|
@@ -23,11 +23,10 @@ import type { NitroApp } from 'nitropack/types';
|
|
|
23
23
|
* module rests on — a reviewer can read the allowlist and know nothing else can
|
|
24
24
|
* reach an event.
|
|
25
25
|
*
|
|
26
|
-
* So this cannot build its payload conditionally. Every key is present
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* failed the
|
|
30
|
-
* module's mistake to surface.
|
|
26
|
+
* So this cannot build its payload conditionally. Every key is present in the
|
|
27
|
+
* source literal. The Wide Events transform removes `undefined` values at
|
|
28
|
+
* runtime. An earlier version assembled a `Record` and passed the variable; it
|
|
29
|
+
* failed the consuming application's build.
|
|
31
30
|
*/
|
|
32
31
|
declare const _default: (nitroApp: NitroApp) => void;
|
|
33
32
|
export default _default;
|
|
@@ -5,8 +5,8 @@ export default (nitroApp) => {
|
|
|
5
5
|
recordCloudflareWideEventFields(event);
|
|
6
6
|
});
|
|
7
7
|
};
|
|
8
|
-
function
|
|
9
|
-
return typeof value === "string" ? value :
|
|
8
|
+
function stringOrUndefined(value) {
|
|
9
|
+
return typeof value === "string" ? value : void 0;
|
|
10
10
|
}
|
|
11
11
|
export function recordCloudflareWideEventFields(event) {
|
|
12
12
|
const cf = event.context.cloudflare?.request?.cf;
|
|
@@ -14,14 +14,14 @@ export function recordCloudflareWideEventFields(event) {
|
|
|
14
14
|
if (!cf && !d1)
|
|
15
15
|
return;
|
|
16
16
|
addWideEventFields(event, {
|
|
17
|
-
"cf.colo":
|
|
18
|
-
"cf.country":
|
|
19
|
-
"cf.httpProtocol":
|
|
20
|
-
"d1.queries": d1
|
|
21
|
-
"d1.primaryQueries": d1
|
|
22
|
-
"d1.recoveries": d1
|
|
23
|
-
"d1.unrecovered": d1
|
|
24
|
-
"d1.durationMs": d1 ? Math.round(d1.durationMs) :
|
|
25
|
-
"d1.region": d1
|
|
17
|
+
"cf.colo": stringOrUndefined(cf?.colo),
|
|
18
|
+
"cf.country": stringOrUndefined(cf?.country),
|
|
19
|
+
"cf.httpProtocol": stringOrUndefined(cf?.httpProtocol),
|
|
20
|
+
"d1.queries": d1?.queries,
|
|
21
|
+
"d1.primaryQueries": d1?.primaryQueries,
|
|
22
|
+
"d1.recoveries": d1?.recoveries,
|
|
23
|
+
"d1.unrecovered": d1?.unrecovered,
|
|
24
|
+
"d1.durationMs": d1 ? Math.round(d1.durationMs) : void 0,
|
|
25
|
+
"d1.region": d1?.region ?? void 0
|
|
26
26
|
});
|
|
27
27
|
}
|
package/dist/wrangler.d.mts
CHANGED
|
@@ -47,6 +47,11 @@ type WranglerPlacementInput = {
|
|
|
47
47
|
host?: never;
|
|
48
48
|
hostname?: never;
|
|
49
49
|
region?: never;
|
|
50
|
+
} | {
|
|
51
|
+
mode: 'off';
|
|
52
|
+
host?: never;
|
|
53
|
+
hostname?: never;
|
|
54
|
+
region?: never;
|
|
50
55
|
} | {
|
|
51
56
|
host: string;
|
|
52
57
|
hostname?: never;
|
|
@@ -63,6 +68,12 @@ type WranglerPlacementInput = {
|
|
|
63
68
|
hostname?: never;
|
|
64
69
|
mode?: never;
|
|
65
70
|
};
|
|
71
|
+
type WranglerModuleRuleType = 'CommonJS' | 'CompiledWasm' | 'Data' | 'ESModule' | 'PythonModule' | 'PythonRequirement' | 'Text';
|
|
72
|
+
interface WranglerModuleRuleInput {
|
|
73
|
+
type: WranglerModuleRuleType;
|
|
74
|
+
globs: string[];
|
|
75
|
+
fallthrough?: boolean;
|
|
76
|
+
}
|
|
66
77
|
interface WranglerRemoteBindingInput extends Record<string, unknown> {
|
|
67
78
|
binding?: string;
|
|
68
79
|
remote?: boolean;
|
|
@@ -118,6 +129,7 @@ interface WranglerConfigInput extends Record<string, unknown> {
|
|
|
118
129
|
compatibility_flags?: string[];
|
|
119
130
|
containers?: WranglerContainerInput[];
|
|
120
131
|
env?: Record<string, WranglerConfigInput>;
|
|
132
|
+
find_additional_modules?: boolean;
|
|
121
133
|
images?: WranglerRemoteBindingInput;
|
|
122
134
|
keep_vars?: boolean;
|
|
123
135
|
limits?: {
|
|
@@ -125,6 +137,7 @@ interface WranglerConfigInput extends Record<string, unknown> {
|
|
|
125
137
|
subrequests?: number;
|
|
126
138
|
};
|
|
127
139
|
mtls_certificates?: WranglerRemoteBindingInput[];
|
|
140
|
+
no_bundle?: boolean;
|
|
128
141
|
observability?: WranglerObservabilityInput;
|
|
129
142
|
placement?: WranglerPlacementInput;
|
|
130
143
|
preview_urls?: boolean;
|
|
@@ -134,6 +147,7 @@ interface WranglerConfigInput extends Record<string, unknown> {
|
|
|
134
147
|
};
|
|
135
148
|
route?: string | Record<string, unknown>;
|
|
136
149
|
routes?: Array<string | Record<string, unknown>>;
|
|
150
|
+
rules?: WranglerModuleRuleInput[];
|
|
137
151
|
secrets?: {
|
|
138
152
|
required?: string[];
|
|
139
153
|
};
|
|
@@ -148,6 +162,7 @@ interface WranglerConfigInput extends Record<string, unknown> {
|
|
|
148
162
|
interface CloudflareDefaultOptions {
|
|
149
163
|
compatibilityDate?: string;
|
|
150
164
|
logsSampleRate?: number;
|
|
165
|
+
partialBundles?: boolean;
|
|
151
166
|
requiredSecrets?: readonly string[];
|
|
152
167
|
tracesSampleRate?: number;
|
|
153
168
|
uploadSourceMaps?: boolean;
|
|
@@ -201,4 +216,4 @@ declare function formatWranglerDiagnostics(diagnostics: readonly WranglerDiagnos
|
|
|
201
216
|
declare function readWranglerJsonFile(path: string): Promise<WranglerJsonFileResult>;
|
|
202
217
|
|
|
203
218
|
export { WRANGLER_DIAGNOSTIC_CODES, applyCloudflareDefaults, diagnoseWranglerConfig, findProjectWranglerConfig, formatWranglerDiagnostics, readAuthoredWranglerConfig, readWranglerConfigFile, readWranglerJsonFile };
|
|
204
|
-
export type { AuthoredWranglerConfigResult, CloudflareDefaultOptions, WorkersCachePolicy, WranglerAssetsInput, WranglerConfigFileResult, WranglerConfigInput, WranglerContainerInput, WranglerDiagnostic, WranglerDiagnosticCode, WranglerDiagnosticOptions, WranglerJsonFileResult, WranglerObservabilityInput, WranglerPlacementInput, WranglerRemoteBindingInput, WranglerWorkersCacheInput };
|
|
219
|
+
export type { AuthoredWranglerConfigResult, CloudflareDefaultOptions, WorkersCachePolicy, WranglerAssetsInput, WranglerConfigFileResult, WranglerConfigInput, WranglerContainerInput, WranglerDiagnostic, WranglerDiagnosticCode, WranglerDiagnosticOptions, WranglerJsonFileResult, WranglerModuleRuleInput, WranglerModuleRuleType, WranglerObservabilityInput, WranglerPlacementInput, WranglerRemoteBindingInput, WranglerWorkersCacheInput };
|
package/dist/wrangler.mjs
CHANGED
|
@@ -112,6 +112,19 @@ const SECRET_NAME_RE = /(?:^|_)(?:API_?KEY|AUTH_TOKEN|CLIENT_SECRET|CREDENTIALS?
|
|
|
112
112
|
const DATE_ONLY_RE = /^\d{4}-\d{2}-\d{2}$/;
|
|
113
113
|
const MILLISECONDS_PER_DAY = 24 * 60 * 60 * 1e3;
|
|
114
114
|
const NODEJS_COMPAT_V2_DATE = /* @__PURE__ */ new Date("2024-09-23T00:00:00.000Z");
|
|
115
|
+
const MJS_COVERING_GLOBS = /* @__PURE__ */ new Set(["**/*.mjs", "**/*"]);
|
|
116
|
+
const PARTIAL_BUNDLES_MODULE_RULE = {
|
|
117
|
+
type: "ESModule",
|
|
118
|
+
globs: ["**/*.mjs"],
|
|
119
|
+
// Wrangler keeps only the first rule per module type unless it falls
|
|
120
|
+
// through, and Nitro's `defu` merge places generated rules before authored
|
|
121
|
+
// ones. Without this a consumer ESModule rule for other globs would be
|
|
122
|
+
// dropped as redundant.
|
|
123
|
+
fallthrough: true
|
|
124
|
+
};
|
|
125
|
+
function moduleRuleCoversMjs(rule) {
|
|
126
|
+
return rule.type === "ESModule" && rule.globs.some((glob) => MJS_COVERING_GLOBS.has(glob));
|
|
127
|
+
}
|
|
115
128
|
function unique(values) {
|
|
116
129
|
return [...new Set(values)];
|
|
117
130
|
}
|
|
@@ -309,6 +322,7 @@ function applyCloudflareDefaults(config, options = {}, authored = {}) {
|
|
|
309
322
|
// Named Wrangler environments inherit the authored root for the keys
|
|
310
323
|
// Wrangler itself inherits, and nothing else.
|
|
311
324
|
authored: resolveEnvironmentPolicy(authored, authored.env?.[name] ?? {}),
|
|
325
|
+
authoredEnvironment: authored.env?.[name] ?? {},
|
|
312
326
|
inherited: root
|
|
313
327
|
})])
|
|
314
328
|
);
|
|
@@ -351,11 +365,22 @@ function applyEnvironmentDefaults(config, options, layers = {}) {
|
|
|
351
365
|
const versionMetadataBinding = options.versionMetadataBinding ?? "CF_VERSION_METADATA";
|
|
352
366
|
const localBindingNames = /* @__PURE__ */ new Set([...collectBindingNames(config), ...collectBindingNames(authored)]);
|
|
353
367
|
const versionMetadata = config.version_metadata ?? authored.version_metadata ?? (inherited.version_metadata && !localBindingNames.has(inherited.version_metadata.binding) ? inherited.version_metadata : void 0) ?? (localBindingNames.has(versionMetadataBinding) ? void 0 : { binding: versionMetadataBinding });
|
|
368
|
+
const partialBundles = options.partialBundles ?? true;
|
|
369
|
+
const noBundle = config.no_bundle ?? authored.no_bundle ?? inherited.no_bundle;
|
|
370
|
+
const findAdditionalModules = config.find_additional_modules ?? authored.find_additional_modules ?? inherited.find_additional_modules;
|
|
371
|
+
const environmentRules = [...config.rules ?? [], ...layers.authoredEnvironment?.rules ?? []];
|
|
372
|
+
const mjsCovered = environmentRules.length > 0 ? environmentRules.some(moduleRuleCoversMjs) : [...authored.rules ?? [], ...inherited.rules ?? []].some(moduleRuleCoversMjs);
|
|
354
373
|
return {
|
|
355
374
|
...config,
|
|
356
375
|
cache,
|
|
357
376
|
...compatibilityDate === void 0 ? {} : { compatibility_date: compatibilityDate },
|
|
358
377
|
compatibility_flags: compatibilityFlags,
|
|
378
|
+
...partialBundles && !noBundle ? {
|
|
379
|
+
find_additional_modules: findAdditionalModules ?? true,
|
|
380
|
+
// Authored rules stay in the authored config: Nitro's `defu` merge
|
|
381
|
+
// concatenates arrays, so restating them here would duplicate them.
|
|
382
|
+
...!mjsCovered ? { rules: [PARTIAL_BUNDLES_MODULE_RULE, ...config.rules ?? []] } : {}
|
|
383
|
+
} : {},
|
|
359
384
|
observability: {
|
|
360
385
|
...inherited.observability,
|
|
361
386
|
...authored.observability,
|
|
@@ -855,11 +880,14 @@ function resolveEnvironmentPolicy(root, environment) {
|
|
|
855
880
|
cache: environment.cache ?? root.cache,
|
|
856
881
|
compatibility_date: environment.compatibility_date ?? root.compatibility_date,
|
|
857
882
|
compatibility_flags: environment.compatibility_flags ?? root.compatibility_flags,
|
|
883
|
+
find_additional_modules: environment.find_additional_modules ?? root.find_additional_modules,
|
|
858
884
|
...exports === void 0 ? {} : { exports },
|
|
859
885
|
...migrations === void 0 ? {} : { migrations },
|
|
886
|
+
no_bundle: environment.no_bundle ?? root.no_bundle,
|
|
860
887
|
observability: mergeObservability(root.observability, environment.observability),
|
|
861
888
|
placement: environment.placement ?? root.placement,
|
|
862
889
|
preview_urls: environment.preview_urls ?? root.preview_urls,
|
|
890
|
+
rules: environment.rules ?? root.rules,
|
|
863
891
|
upload_source_maps: environment.upload_source_maps ?? root.upload_source_maps,
|
|
864
892
|
workers_dev: environment.workers_dev ?? root.workers_dev
|
|
865
893
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@harlan-zw/nuxt-cloudflare",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.3.0",
|
|
5
5
|
"description": "Opinionated Cloudflare deployment defaults and diagnostics for Nuxt.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Harlan Wilton",
|
|
@@ -113,7 +113,7 @@
|
|
|
113
113
|
"unbuild": "^3.6.1",
|
|
114
114
|
"vitest": "^4.1.10",
|
|
115
115
|
"wrangler": "^4.120.1",
|
|
116
|
-
"@harlan-zw/nuxt-wide-events": "^0.1.
|
|
116
|
+
"@harlan-zw/nuxt-wide-events": "^0.1.3"
|
|
117
117
|
},
|
|
118
118
|
"scripts": {
|
|
119
119
|
"build": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxt-module-build build",
|