@harlan-zw/nuxt-cloudflare 0.0.7 → 0.0.8
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 +28 -6
- package/dist/bindings.d.mts +22 -10
- package/dist/bindings.mjs +29 -9
- package/dist/chunks/binding-types.mjs +97 -0
- package/dist/cli/index.mjs +1 -1
- package/dist/module.d.mts +1 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +40 -4
- package/dist/wrangler.d.mts +5 -1
- package/dist/wrangler.mjs +40 -2
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ The module extracts production patterns already proven in Nuxt SEO and gscdump.
|
|
|
8
8
|
|
|
9
9
|
- Cloudflare module preset, generated Wrangler config, and Node compatibility
|
|
10
10
|
- Static assets remain asset first by default. Blanket `assets.run_worker_first: true` warns because valid authentication and transform use cases exist
|
|
11
|
-
- Workers Logs sampled at
|
|
11
|
+
- Workers Logs sampled at 1%, traces at 1%, both overridable
|
|
12
12
|
- Preview URLs disabled unless explicitly enabled
|
|
13
13
|
- `workers_dev` disabled when a route proves the Worker remains reachable; workers without routes must choose explicitly
|
|
14
14
|
- Version metadata binding at `CF_VERSION_METADATA`
|
|
@@ -22,6 +22,7 @@ The module extracts production patterns already proven in Nuxt SEO and gscdump.
|
|
|
22
22
|
- Final generated Wrangler config validated through Wrangler, then audited after production Nitro compiles
|
|
23
23
|
- Production builds fail when server runtime config contains a value copied from a secret build environment variable. The error lists config paths only
|
|
24
24
|
- Complete defaults and diagnostics applied to every named Wrangler environment
|
|
25
|
+
- Exact Cloudflare binding and runtime types generated during `nuxt prepare`
|
|
25
26
|
|
|
26
27
|
Persistent KV mounts are never wrapped. The expiry policy applies only to cache data.
|
|
27
28
|
|
|
@@ -63,6 +64,23 @@ Keep server runtime secret defaults empty. Nuxt reads matching `NUXT_*` values f
|
|
|
63
64
|
|
|
64
65
|
Workers Caching is separate from Nitro's KV-backed cache. The module enables version-isolated caching by default. Rendered HTML always stays private. API and asset responses keep explicit cache policies. Set `workersCache: { _tag: 'disabled' }` to opt out. Choose cross-version caching only with an explicit purge path.
|
|
65
66
|
|
|
67
|
+
## Cost controls
|
|
68
|
+
|
|
69
|
+
Cloudflare pricing changes. Check the linked pricing pages before making a budget.
|
|
70
|
+
|
|
71
|
+
- Workers Logs use a 1% routine sample. Paid plans include 20 million monthly events. Extra events cost $0.60 per million. See [Workers Logs pricing](https://developers.cloudflare.com/workers/observability/logs/workers-logs/#pricing).
|
|
72
|
+
- Invocation logs remain enabled. High-volume Workers with complete error telemetry can set `observability.logs.invocation_logs: false`. This removes one event per sampled invocation.
|
|
73
|
+
- Traces use a separate 1% sample. Each span is metered. [Trace pricing](https://developers.cloudflare.com/workers/observability/traces/#limits--pricing) lists 10 million included monthly events. It also says the quota is shared with logs. The Workers Logs page lists 20 million. Budget against 10 million until the pages agree.
|
|
74
|
+
- Workers Caching uses version isolation by default. [Workers pricing](https://developers.cloudflare.com/workers/platform/pricing/#workers) bills cache hits as Worker requests. This includes static assets and Worker-to-Worker requests. Disable caching when CPU savings do not exceed the added request cost.
|
|
75
|
+
- Static assets stay asset first. Their requests are free and unlimited. The module warns when blanket Worker-first routing makes assets billable.
|
|
76
|
+
- Cloudflare's 30-second CPU limit remains unchanged. The doctor warns when `limits.cpu_ms` exceeds 30,000. A higher ceiling increases runaway-cost exposure.
|
|
77
|
+
- Queue retries add billed read operations. Each 64 KB message chunk incurs write, read, and delete operations. Keep payloads small and retries deliberate.
|
|
78
|
+
- The KV-backed Nitro cache expires entries after 30 days. This bounds stored cache data. It does not reduce billed operations.
|
|
79
|
+
|
|
80
|
+
[D1 pricing](https://developers.cloudflare.com/d1/platform/pricing/) charges for rows read, rows written, and stored data. Indexes reduce billed scans but add writes and storage. Read replicas add no separate charge. The module preserves D1 routing and session behavior.
|
|
81
|
+
|
|
82
|
+
Doctor warnings surface log or trace sampling above 1%, Workers Caching with static assets, CPU limits above 30 seconds, and queue retries above three.
|
|
83
|
+
|
|
66
84
|
## Doctor
|
|
67
85
|
|
|
68
86
|
Audit Wrangler's effective configuration, including generated config redirects and named environments:
|
|
@@ -155,15 +173,19 @@ D1 allows 100 bound parameters per statement, including each statement inside `d
|
|
|
155
173
|
### Bindings
|
|
156
174
|
|
|
157
175
|
```ts
|
|
158
|
-
import type {
|
|
159
|
-
import {
|
|
176
|
+
import type { CloudflareBindingSource } from '@harlan-zw/nuxt-cloudflare/bindings'
|
|
177
|
+
import { createCloudflareBindings } from '@harlan-zw/nuxt-cloudflare/bindings'
|
|
178
|
+
|
|
179
|
+
const cloudflare = createCloudflareBindings()
|
|
160
180
|
|
|
161
|
-
function requireDatabase(
|
|
162
|
-
return
|
|
181
|
+
function requireDatabase(source?: CloudflareBindingSource) {
|
|
182
|
+
return cloudflare.require('DB', source)
|
|
163
183
|
}
|
|
164
184
|
```
|
|
165
185
|
|
|
166
|
-
`
|
|
186
|
+
`nuxt prepare` runs Wrangler and writes exact, compatibility-aware types to `.nuxt/types/cloudflare-bindings.d.ts`. It merges root JSON, JSONC, or TOML bindings with `nitro.cloudflare.wrangler`. The declaration is available only to Nitro server code. Production builds compare it with the final generated Wrangler config and fail on drift. Set `bindingTypes: false` only when another tool owns the declaration.
|
|
187
|
+
|
|
188
|
+
The source may be an H3 event, Nitro task input, or task context. Eventless access uses Nitro's `globalThis.__env__` Cloudflare entry shim. An explicit environment always wins and never mixes with the global environment. Binding names come from the generated `CloudflareBindings` interface. Missing required bindings throw. Pass a generic only to override generated types in a focused test.
|
|
167
189
|
|
|
168
190
|
### Scoped secrets file
|
|
169
191
|
|
package/dist/bindings.d.mts
CHANGED
|
@@ -1,12 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
};
|
|
6
|
-
};
|
|
1
|
+
type BindingName<Environment extends object> = Extract<keyof Environment, string>;
|
|
2
|
+
declare global {
|
|
3
|
+
interface CloudflareBindings {
|
|
4
|
+
}
|
|
7
5
|
}
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
interface CloudflareBindingSource {
|
|
7
|
+
cloudflare?: unknown;
|
|
8
|
+
context?: unknown;
|
|
9
|
+
}
|
|
10
|
+
interface CloudflareBindingAccessor<Environment extends object> {
|
|
11
|
+
resolve: (source?: CloudflareBindingSource) => Environment | undefined;
|
|
12
|
+
get: <Name extends BindingName<Environment>>(name: Name, source?: CloudflareBindingSource) => Environment[Name] | undefined;
|
|
13
|
+
require: <Name extends BindingName<Environment>>(name: Name, source?: CloudflareBindingSource) => Exclude<Environment[Name], undefined>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Creates typed binding access for the generated `CloudflareBindings` environment.
|
|
17
|
+
*
|
|
18
|
+
* The source may be an H3 event, a Nitro task run input, or a Nitro task context.
|
|
19
|
+
* If the source has no environment, Nitro's Cloudflare entry shim is used.
|
|
20
|
+
*/
|
|
21
|
+
declare function createCloudflareBindings<Environment extends object = CloudflareBindings>(): CloudflareBindingAccessor<Environment>;
|
|
10
22
|
|
|
11
|
-
export {
|
|
12
|
-
export type {
|
|
23
|
+
export { createCloudflareBindings };
|
|
24
|
+
export type { CloudflareBindingAccessor, CloudflareBindingSource };
|
package/dist/bindings.mjs
CHANGED
|
@@ -1,12 +1,32 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
3
|
-
return env && Object.hasOwn(env, name) ? env[name] : void 0;
|
|
1
|
+
function asRecord(value) {
|
|
2
|
+
return value !== null && typeof value === "object" ? value : void 0;
|
|
4
3
|
}
|
|
5
|
-
function
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
function envFromContext(value) {
|
|
5
|
+
const cloudflare = asRecord(value)?.cloudflare;
|
|
6
|
+
return asRecord(asRecord(cloudflare)?.env);
|
|
7
|
+
}
|
|
8
|
+
function resolveEnvironment(source) {
|
|
9
|
+
const sourceRecord = asRecord(source);
|
|
10
|
+
const sourceEnv = envFromContext(sourceRecord?.context) ?? envFromContext(sourceRecord);
|
|
11
|
+
const globalEnv = asRecord(globalThis.__env__);
|
|
12
|
+
return sourceEnv ?? globalEnv;
|
|
13
|
+
}
|
|
14
|
+
function createCloudflareBindings() {
|
|
15
|
+
function get(name, source) {
|
|
16
|
+
const env = resolveEnvironment(source);
|
|
17
|
+
return env && Object.hasOwn(env, name) ? env[name] : void 0;
|
|
18
|
+
}
|
|
19
|
+
function requireBinding(name, source) {
|
|
20
|
+
const binding = get(name, source);
|
|
21
|
+
if (binding === void 0)
|
|
22
|
+
throw new Error(`Cloudflare binding "${name}" is unavailable`);
|
|
23
|
+
return binding;
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
resolve: resolveEnvironment,
|
|
27
|
+
get,
|
|
28
|
+
require: requireBinding
|
|
29
|
+
};
|
|
10
30
|
}
|
|
11
31
|
|
|
12
|
-
export {
|
|
32
|
+
export { createCloudflareBindings };
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { readFile, mkdir, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { parseTOML, parseJSONC, parseJSON } from 'confbox';
|
|
3
|
+
import { extname, resolve } from 'pathe';
|
|
4
|
+
import { experimental_generateTypes } from 'wrangler';
|
|
5
|
+
import { d as discoverWranglerSourceConfigs } from '../shared/nuxt-cloudflare.6X-qzF_b.mjs';
|
|
6
|
+
import 'node:fs';
|
|
7
|
+
import '../wrangler.mjs';
|
|
8
|
+
|
|
9
|
+
const COMPUTED_WRANGLER_KEYS = /* @__PURE__ */ new Set([
|
|
10
|
+
"configPath",
|
|
11
|
+
"definedEnvironments",
|
|
12
|
+
"targetEnvironment",
|
|
13
|
+
"topLevelName",
|
|
14
|
+
"userConfigPath"
|
|
15
|
+
]);
|
|
16
|
+
function isRecord(value) {
|
|
17
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
18
|
+
}
|
|
19
|
+
function mergeDefaults(primary, fallback) {
|
|
20
|
+
if (primary === void 0 || primary === null)
|
|
21
|
+
return fallback;
|
|
22
|
+
if (Array.isArray(primary) && Array.isArray(fallback))
|
|
23
|
+
return [...primary, ...fallback];
|
|
24
|
+
if (!isRecord(primary) || !isRecord(fallback))
|
|
25
|
+
return primary;
|
|
26
|
+
const merged = { ...primary };
|
|
27
|
+
for (const [key, value] of Object.entries(fallback))
|
|
28
|
+
merged[key] = mergeDefaults(merged[key], value);
|
|
29
|
+
return merged;
|
|
30
|
+
}
|
|
31
|
+
function normalizeConfig(config, options) {
|
|
32
|
+
const normalized = Object.fromEntries(
|
|
33
|
+
Object.entries(config).filter(([key, value]) => !COMPUTED_WRANGLER_KEYS.has(key) && value !== void 0)
|
|
34
|
+
);
|
|
35
|
+
delete normalized.main;
|
|
36
|
+
normalized.assets = mergeDefaults({ binding: "ASSETS", directory: "." }, normalized.assets);
|
|
37
|
+
normalized.compatibility_date ??= options.compatibilityDate;
|
|
38
|
+
if (options.nodeCompat) {
|
|
39
|
+
const flags = new Set(normalized.compatibility_flags ?? []);
|
|
40
|
+
if (flags.has("nodejs_compat_v2") && flags.has("no_nodejs_compat_v2"))
|
|
41
|
+
flags.delete("nodejs_compat_v2");
|
|
42
|
+
if (!flags.has("nodejs_compat_v2")) {
|
|
43
|
+
flags.add("nodejs_compat");
|
|
44
|
+
flags.add("no_nodejs_compat_v2");
|
|
45
|
+
}
|
|
46
|
+
normalized.compatibility_flags = [...flags];
|
|
47
|
+
}
|
|
48
|
+
return normalized;
|
|
49
|
+
}
|
|
50
|
+
async function readAuthoredConfig(rootDir) {
|
|
51
|
+
const [path] = discoverWranglerSourceConfigs(rootDir);
|
|
52
|
+
if (!path)
|
|
53
|
+
return {};
|
|
54
|
+
const source = await readFile(path, "utf8");
|
|
55
|
+
const extension = extname(path);
|
|
56
|
+
if (extension === ".toml")
|
|
57
|
+
return parseTOML(source);
|
|
58
|
+
if (extension === ".jsonc")
|
|
59
|
+
return parseJSONC(source);
|
|
60
|
+
return parseJSON(source);
|
|
61
|
+
}
|
|
62
|
+
async function generateCloudflareBindingTypes(options) {
|
|
63
|
+
const directory = resolve(options.buildDir, "nuxt-cloudflare");
|
|
64
|
+
const configPath = resolve(directory, "wrangler.json");
|
|
65
|
+
const typePath = resolve(options.buildDir, "types/cloudflare-bindings.d.ts");
|
|
66
|
+
await mkdir(directory, { recursive: true });
|
|
67
|
+
await writeFile(configPath, `${JSON.stringify(normalizeConfig(options.config, options), null, 2)}
|
|
68
|
+
`);
|
|
69
|
+
const generated = await experimental_generateTypes({
|
|
70
|
+
config: configPath,
|
|
71
|
+
envInterface: "CloudflareBindings",
|
|
72
|
+
includeRuntime: true,
|
|
73
|
+
path: typePath,
|
|
74
|
+
strictVars: false
|
|
75
|
+
});
|
|
76
|
+
if (!generated.env || !generated.runtime)
|
|
77
|
+
throw new Error("[nuxt-cloudflare] Wrangler did not generate Cloudflare binding and runtime types.");
|
|
78
|
+
return {
|
|
79
|
+
content: generated.content,
|
|
80
|
+
signature: `${generated.env}\0${generated.runtime}`
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
async function prepareCloudflareBindingTypes(options) {
|
|
84
|
+
const authored = await readAuthoredConfig(options.rootDir);
|
|
85
|
+
const config = mergeDefaults(options.wrangler, authored);
|
|
86
|
+
return generateCloudflareBindingTypes({ ...options, config });
|
|
87
|
+
}
|
|
88
|
+
async function assertCloudflareBindingTypesCurrent(options) {
|
|
89
|
+
const generated = await generateCloudflareBindingTypes(options);
|
|
90
|
+
if (generated.signature !== options.expectedSignature) {
|
|
91
|
+
throw new Error(
|
|
92
|
+
"[nuxt-cloudflare] Generated binding types differ from the final Wrangler config. Run `nuxt prepare` and review binding configuration order."
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export { assertCloudflareBindingTypesCurrent, prepareCloudflareBindingTypes };
|
package/dist/cli/index.mjs
CHANGED
|
@@ -103,7 +103,7 @@ const doctor = defineCommand({
|
|
|
103
103
|
const main = defineCommand({
|
|
104
104
|
meta: {
|
|
105
105
|
name: "nuxt-cloudflare",
|
|
106
|
-
version: "0.0.
|
|
106
|
+
version: "0.0.8",
|
|
107
107
|
description: "Cloudflare deployment defaults and diagnostics for Nuxt"
|
|
108
108
|
},
|
|
109
109
|
subCommands: { doctor }
|
package/dist/module.d.mts
CHANGED
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import process from 'node:process';
|
|
2
|
-
import { useLogger, defineNuxtModule } from '@nuxt/kit';
|
|
2
|
+
import { useLogger, defineNuxtModule, addTypeTemplate } from '@nuxt/kit';
|
|
3
3
|
import { resolve } from 'pathe';
|
|
4
4
|
import { a as diagnoseWranglerSourceConfigs, d as discoverWranglerSourceConfigs, e as evaluateWranglerDiagnostics } from './shared/nuxt-cloudflare.6X-qzF_b.mjs';
|
|
5
5
|
import { readWranglerJsonFile, diagnoseWranglerConfig, formatWranglerDiagnostics, applyCloudflareDefaults } from './wrangler.mjs';
|
|
@@ -164,7 +164,7 @@ function configureNitroCloudflare(nitro, options, nuxtServerSourceMaps) {
|
|
|
164
164
|
defaultTtl: configuredCache?.defaultTtl ?? 30 * 24 * 60 * 60
|
|
165
165
|
};
|
|
166
166
|
}
|
|
167
|
-
async function auditGeneratedWranglerConfig(nitro, options, rootDir) {
|
|
167
|
+
async function auditGeneratedWranglerConfig(nitro, options, buildDir, rootDir, bindingTypeSignature) {
|
|
168
168
|
const path = resolve(nitro.options.output.serverDir, "wrangler.json");
|
|
169
169
|
const result = await readWranglerJsonFile(path);
|
|
170
170
|
if (result._tag === "missing")
|
|
@@ -175,6 +175,16 @@ async function auditGeneratedWranglerConfig(nitro, options, rootDir) {
|
|
|
175
175
|
const validated = readProjectWranglerConfig({ config: path, cwd: rootDir });
|
|
176
176
|
if (validated._tag === "invalid")
|
|
177
177
|
throw new Error("[nuxt-cloudflare] Generated Wrangler config fails Wrangler schema validation. Run Wrangler locally for validation details.");
|
|
178
|
+
if (bindingTypeSignature) {
|
|
179
|
+
const { assertCloudflareBindingTypesCurrent } = await import('./chunks/binding-types.mjs');
|
|
180
|
+
await assertCloudflareBindingTypesCurrent({
|
|
181
|
+
buildDir,
|
|
182
|
+
compatibilityDate: result.config.compatibility_date,
|
|
183
|
+
config: result.config,
|
|
184
|
+
expectedSignature: bindingTypeSignature,
|
|
185
|
+
nodeCompat: Boolean(nitro.options.cloudflare?.nodeCompat)
|
|
186
|
+
});
|
|
187
|
+
}
|
|
178
188
|
const diagnostics = [
|
|
179
189
|
...diagnoseWranglerConfig(result.config, {
|
|
180
190
|
compatibilityMaxAgeDays: options.compatibilityMaxAgeDays,
|
|
@@ -204,6 +214,25 @@ function setupCloudflareModule(options, nuxt) {
|
|
|
204
214
|
options,
|
|
205
215
|
Boolean(nuxt.options.sourcemap.server)
|
|
206
216
|
);
|
|
217
|
+
let bindingTypeSignature;
|
|
218
|
+
if (options.bindingTypes !== false) {
|
|
219
|
+
addTypeTemplate({
|
|
220
|
+
filename: "types/cloudflare-bindings.d.ts",
|
|
221
|
+
getContents: async () => {
|
|
222
|
+
const { prepareCloudflareBindingTypes } = await import('./chunks/binding-types.mjs');
|
|
223
|
+
const compatibilityDate = nuxt.options.compatibilityDate;
|
|
224
|
+
const artifact = await prepareCloudflareBindingTypes({
|
|
225
|
+
buildDir: nuxt.options.buildDir,
|
|
226
|
+
compatibilityDate: typeof compatibilityDate === "string" ? compatibilityDate || void 0 : compatibilityDate.cloudflare ?? compatibilityDate.default,
|
|
227
|
+
nodeCompat: Boolean(nuxt.options.nitro.cloudflare?.nodeCompat),
|
|
228
|
+
rootDir: nuxt.options.rootDir,
|
|
229
|
+
wrangler: nuxt.options.nitro.cloudflare?.wrangler ?? {}
|
|
230
|
+
});
|
|
231
|
+
bindingTypeSignature = artifact.signature;
|
|
232
|
+
return artifact.content;
|
|
233
|
+
}
|
|
234
|
+
}, { nitro: true });
|
|
235
|
+
}
|
|
207
236
|
configure();
|
|
208
237
|
nuxt.hook("modules:done", () => {
|
|
209
238
|
configure();
|
|
@@ -231,7 +260,13 @@ ${formatHtmlCacheRouteRuleViolations(errors)}`
|
|
|
231
260
|
});
|
|
232
261
|
if (!nuxt.options.dev) {
|
|
233
262
|
nuxt.hook("nitro:init", (nitro) => {
|
|
234
|
-
nitro.hooks.hook("compiled", () => auditGeneratedWranglerConfig(
|
|
263
|
+
nitro.hooks.hook("compiled", () => auditGeneratedWranglerConfig(
|
|
264
|
+
nitro,
|
|
265
|
+
options,
|
|
266
|
+
nuxt.options.buildDir,
|
|
267
|
+
nuxt.options.rootDir,
|
|
268
|
+
bindingTypeSignature
|
|
269
|
+
));
|
|
235
270
|
});
|
|
236
271
|
}
|
|
237
272
|
}
|
|
@@ -242,10 +277,11 @@ const module$1 = defineNuxtModule({
|
|
|
242
277
|
compatibility: { nuxt: ">=4.5.0" }
|
|
243
278
|
},
|
|
244
279
|
defaults: {
|
|
280
|
+
bindingTypes: true,
|
|
245
281
|
enabled: true,
|
|
246
282
|
compatibilityMaxAgeDays: 90,
|
|
247
283
|
doctor: { _tag: "advisory" },
|
|
248
|
-
logsSampleRate: 0.
|
|
284
|
+
logsSampleRate: 0.01,
|
|
249
285
|
tracesSampleRate: 0.01,
|
|
250
286
|
versionMetadataBinding: "CF_VERSION_METADATA",
|
|
251
287
|
workersCache: { _tag: "enabled", crossVersion: false }
|
package/dist/wrangler.d.mts
CHANGED
|
@@ -67,6 +67,10 @@ interface WranglerConfigInput extends Record<string, unknown> {
|
|
|
67
67
|
env?: Record<string, WranglerConfigInput>;
|
|
68
68
|
images?: WranglerRemoteBindingInput;
|
|
69
69
|
keep_vars?: boolean;
|
|
70
|
+
limits?: {
|
|
71
|
+
cpu_ms?: number;
|
|
72
|
+
subrequests?: number;
|
|
73
|
+
};
|
|
70
74
|
mtls_certificates?: WranglerRemoteBindingInput[];
|
|
71
75
|
observability?: WranglerObservabilityInput;
|
|
72
76
|
placement?: WranglerPlacementInput;
|
|
@@ -97,7 +101,7 @@ interface CloudflareDefaultOptions {
|
|
|
97
101
|
versionMetadataBinding?: string;
|
|
98
102
|
workersCache?: WorkersCachePolicy;
|
|
99
103
|
}
|
|
100
|
-
declare const WRANGLER_DIAGNOSTIC_CODES: readonly ["assets-worker-first", "assets-worker-first-pattern-invalid", "compatibility-date-missing", "compatibility-date-invalid", "container-durable-object-binding-missing", "container-durable-object-not-sqlite", "container-instance-type-deprecated", "durable-object-binding-inactive", "durable-object-lifecycle-mixed", "durable-object-lifecycle-unmanaged", "email-binding-unrestricted", "environment-binding-missing", "generated-config-has-env", "keep-vars-enabled", "legacy-module-binding", "missing-nodejs-compat", "nodejs-compat-version-implicit", "observability-disabled", "observability-sampling-implicit", "observability-sampling-out-of-range", "plaintext-secret-var", "preview-urls-public", "pipeline-binding-deprecated", "queue-dlq-missing", "queue-retries-above-policy", "queue-retries-out-of-range", "queue-retry-delay-out-of-range", "secret-declared-as-var", "source-maps-disabled", "stale-compatibility-date", "traces-disabled", "remote-binding-not-enabled", "unsafe-hello-world-binding", "version-metadata-missing", "workers-dev-enabled", "workers-dev-implicit", "workers-cache-cross-version-enabled", "workers-cache-policy-implicit", "wrangler-config-shadowed", "wrangler-config-missing", "wrangler-config-unreadable", "wrangler-jsonc-preferred"];
|
|
104
|
+
declare const WRANGLER_DIAGNOSTIC_CODES: readonly ["assets-worker-first", "assets-worker-first-pattern-invalid", "compatibility-date-missing", "compatibility-date-invalid", "container-durable-object-binding-missing", "container-durable-object-not-sqlite", "container-instance-type-deprecated", "cpu-limit-raised", "durable-object-binding-inactive", "durable-object-lifecycle-mixed", "durable-object-lifecycle-unmanaged", "email-binding-unrestricted", "environment-binding-missing", "generated-config-has-env", "keep-vars-enabled", "legacy-module-binding", "missing-nodejs-compat", "nodejs-compat-version-implicit", "observability-disabled", "observability-log-sampling-high", "observability-sampling-implicit", "observability-sampling-out-of-range", "observability-trace-sampling-high", "plaintext-secret-var", "preview-urls-public", "pipeline-binding-deprecated", "queue-dlq-missing", "queue-retries-above-policy", "queue-retries-out-of-range", "queue-retry-delay-out-of-range", "secret-declared-as-var", "source-maps-disabled", "stale-compatibility-date", "traces-disabled", "remote-binding-not-enabled", "unsafe-hello-world-binding", "version-metadata-missing", "workers-dev-enabled", "workers-dev-implicit", "workers-cache-cross-version-enabled", "workers-cache-assets-billable", "workers-cache-policy-implicit", "wrangler-config-shadowed", "wrangler-config-missing", "wrangler-config-unreadable", "wrangler-jsonc-preferred"];
|
|
101
105
|
type WranglerDiagnosticCode = typeof WRANGLER_DIAGNOSTIC_CODES[number];
|
|
102
106
|
interface WranglerDiagnostic {
|
|
103
107
|
_tag: 'error' | 'info' | 'warning';
|
package/dist/wrangler.mjs
CHANGED
|
@@ -8,6 +8,7 @@ const WRANGLER_DIAGNOSTIC_CODES = [
|
|
|
8
8
|
"container-durable-object-binding-missing",
|
|
9
9
|
"container-durable-object-not-sqlite",
|
|
10
10
|
"container-instance-type-deprecated",
|
|
11
|
+
"cpu-limit-raised",
|
|
11
12
|
"durable-object-binding-inactive",
|
|
12
13
|
"durable-object-lifecycle-mixed",
|
|
13
14
|
"durable-object-lifecycle-unmanaged",
|
|
@@ -19,8 +20,10 @@ const WRANGLER_DIAGNOSTIC_CODES = [
|
|
|
19
20
|
"missing-nodejs-compat",
|
|
20
21
|
"nodejs-compat-version-implicit",
|
|
21
22
|
"observability-disabled",
|
|
23
|
+
"observability-log-sampling-high",
|
|
22
24
|
"observability-sampling-implicit",
|
|
23
25
|
"observability-sampling-out-of-range",
|
|
26
|
+
"observability-trace-sampling-high",
|
|
24
27
|
"plaintext-secret-var",
|
|
25
28
|
"preview-urls-public",
|
|
26
29
|
"pipeline-binding-deprecated",
|
|
@@ -38,6 +41,7 @@ const WRANGLER_DIAGNOSTIC_CODES = [
|
|
|
38
41
|
"workers-dev-enabled",
|
|
39
42
|
"workers-dev-implicit",
|
|
40
43
|
"workers-cache-cross-version-enabled",
|
|
44
|
+
"workers-cache-assets-billable",
|
|
41
45
|
"workers-cache-policy-implicit",
|
|
42
46
|
"wrangler-config-shadowed",
|
|
43
47
|
"wrangler-config-missing",
|
|
@@ -278,7 +282,7 @@ function applyEnvironmentDefaults(config, options, inherited = {}) {
|
|
|
278
282
|
...inheritedLogs,
|
|
279
283
|
...logs,
|
|
280
284
|
enabled: logs?.enabled ?? inheritedLogs?.enabled ?? true,
|
|
281
|
-
head_sampling_rate: logs?.head_sampling_rate ?? inheritedLogs?.head_sampling_rate ?? options.logsSampleRate ?? 0.
|
|
285
|
+
head_sampling_rate: logs?.head_sampling_rate ?? inheritedLogs?.head_sampling_rate ?? options.logsSampleRate ?? 0.01,
|
|
282
286
|
invocation_logs: logs?.invocation_logs ?? inheritedLogs?.invocation_logs ?? true
|
|
283
287
|
},
|
|
284
288
|
traces: {
|
|
@@ -541,7 +545,7 @@ function diagnoseEnvironment(config, prefix, diagnostics, generated, normalized,
|
|
|
541
545
|
diagnostics.push({
|
|
542
546
|
_tag: "warning",
|
|
543
547
|
code: "queue-retries-above-policy",
|
|
544
|
-
message: `Queue consumer retries ${retries} times, above Cloudflare's default of 3.
|
|
548
|
+
message: `Queue consumer retries ${retries} times, above Cloudflare's default of 3. Each retry adds a billed read operation.`,
|
|
545
549
|
configPath: `${prefix}queues.consumers.${index}.max_retries`
|
|
546
550
|
});
|
|
547
551
|
}
|
|
@@ -648,6 +652,24 @@ function diagnosePolicy(config, prefix, diagnostics, options, publicVarNames) {
|
|
|
648
652
|
configPath: `${prefix}observability`
|
|
649
653
|
});
|
|
650
654
|
}
|
|
655
|
+
const logsSampleRate = config.observability.logs?.head_sampling_rate;
|
|
656
|
+
if (logsEnabled && logsSampleRate !== void 0 && logsSampleRate > 0.01 && logsSampleRate <= 1) {
|
|
657
|
+
diagnostics.push({
|
|
658
|
+
_tag: "warning",
|
|
659
|
+
code: "observability-log-sampling-high",
|
|
660
|
+
message: "Log sampling exceeds the 1% routine budget and can create significant metered event volume.",
|
|
661
|
+
configPath: `${prefix}observability.logs.head_sampling_rate`
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
const tracesSampleRate = config.observability.traces?.head_sampling_rate;
|
|
665
|
+
if (tracesEnabled && tracesSampleRate !== void 0 && tracesSampleRate > 0.01 && tracesSampleRate <= 1) {
|
|
666
|
+
diagnostics.push({
|
|
667
|
+
_tag: "warning",
|
|
668
|
+
code: "observability-trace-sampling-high",
|
|
669
|
+
message: "Trace sampling exceeds the 1% routine budget; each captured span is a metered event.",
|
|
670
|
+
configPath: `${prefix}observability.traces.head_sampling_rate`
|
|
671
|
+
});
|
|
672
|
+
}
|
|
651
673
|
}
|
|
652
674
|
if (config.upload_source_maps !== true) {
|
|
653
675
|
diagnostics.push({
|
|
@@ -688,6 +710,22 @@ function diagnosePolicy(config, prefix, diagnostics, options, publicVarNames) {
|
|
|
688
710
|
configPath: `${prefix}cache.cross_version_cache`
|
|
689
711
|
});
|
|
690
712
|
}
|
|
713
|
+
if (config.cache?.enabled && config.assets !== void 0) {
|
|
714
|
+
diagnostics.push({
|
|
715
|
+
_tag: "warning",
|
|
716
|
+
code: "workers-cache-assets-billable",
|
|
717
|
+
message: "Workers Caching makes cached static asset requests billable. Confirm CPU savings exceed request charges.",
|
|
718
|
+
configPath: `${prefix}cache.enabled`
|
|
719
|
+
});
|
|
720
|
+
}
|
|
721
|
+
if (typeof config.limits?.cpu_ms === "number" && config.limits.cpu_ms > 3e4) {
|
|
722
|
+
diagnostics.push({
|
|
723
|
+
_tag: "warning",
|
|
724
|
+
code: "cpu-limit-raised",
|
|
725
|
+
message: "The CPU limit exceeds Cloudflare's 30-second default and increases runaway-cost exposure.",
|
|
726
|
+
configPath: `${prefix}limits.cpu_ms`
|
|
727
|
+
});
|
|
728
|
+
}
|
|
691
729
|
if (config.preview_urls === true) {
|
|
692
730
|
diagnostics.push({
|
|
693
731
|
_tag: "warning",
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@harlan-zw/nuxt-cloudflare",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.8",
|
|
5
5
|
"description": "Opinionated Cloudflare deployment defaults and diagnostics for Nuxt.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Harlan Wilton",
|
|
@@ -86,6 +86,7 @@
|
|
|
86
86
|
"dependencies": {
|
|
87
87
|
"@nuxt/kit": "^4.5.2",
|
|
88
88
|
"citty": "^0.2.2",
|
|
89
|
+
"confbox": "^0.2.4",
|
|
89
90
|
"consola": "^3.4.2",
|
|
90
91
|
"h3": "2.0.1-rc.25",
|
|
91
92
|
"nitropack": "^2.13.4",
|
|
@@ -112,7 +113,7 @@
|
|
|
112
113
|
"lint": "eslint .",
|
|
113
114
|
"lint:fix": "eslint . --fix",
|
|
114
115
|
"test": "pnpm run build && vitest run && pnpm run test:fixture",
|
|
115
|
-
"test:fixture": "nuxt build tests/fixtures/basic && node dist/cli/index.mjs doctor --cwd tests/fixtures/basic",
|
|
116
|
+
"test:fixture": "nuxi prepare tests/fixtures/basic && tsc --noEmit -p tests/fixtures/basic/.nuxt/tsconfig.server.json && nuxt build tests/fixtures/basic && node dist/cli/index.mjs doctor --cwd tests/fixtures/basic",
|
|
116
117
|
"typecheck": "nuxt typecheck && tsc --noEmit -p tsconfig.check.json",
|
|
117
118
|
"test:attw": "attw --pack",
|
|
118
119
|
"test:pack": "rm -rf .pack && pnpm pack --pack-destination .pack && tar -tf .pack/*.tgz"
|