@harlan-zw/nuxt-cloudflare 0.0.6 → 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 +46 -25
- package/dist/bindings.d.mts +22 -10
- package/dist/bindings.mjs +29 -9
- package/dist/chunks/binding-types.mjs +97 -0
- package/dist/chunks/wrangler-reader.mjs +90 -0
- package/dist/cli/index.mjs +6 -90
- package/dist/d1.mjs +3 -6
- package/dist/module.d.mts +3 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +100 -15
- package/dist/storage.mjs +1 -1
- package/dist/types.d.mts +1 -1
- package/dist/wrangler.d.mts +22 -2
- package/dist/wrangler.mjs +297 -29
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -7,20 +7,22 @@ The module extracts production patterns already proven in Nuxt SEO and gscdump.
|
|
|
7
7
|
## Defaults
|
|
8
8
|
|
|
9
9
|
- Cloudflare module preset, generated Wrangler config, and Node compatibility
|
|
10
|
-
- Static assets remain asset first by default. Blanket `assets.run_worker_first: true`
|
|
11
|
-
- Workers Logs sampled at
|
|
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 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`
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
15
|
+
- Smart Placement enabled unless the project chooses a placement
|
|
16
|
+
- Workers Caching enabled with version isolation
|
|
17
|
+
- Rendered HTML forced to `private, no-store`; explicit non-HTML cache policies remain intact
|
|
18
18
|
- Source-map upload when the Nitro build emits maps; explicit `false` is preserved
|
|
19
19
|
- Module-wide `secrets.required` names copied to each environment; source root secrets remain scoped to the root
|
|
20
20
|
- Version metadata is skipped when `CF_VERSION_METADATA` already names another binding
|
|
21
21
|
- Raw `cloudflare-kv-binding` on Nitro's `cache` mount upgraded to a 30-day physical expiry
|
|
22
|
-
- Final generated Wrangler config audited after production Nitro compiles
|
|
22
|
+
- Final generated Wrangler config validated through Wrangler, then audited after production Nitro compiles
|
|
23
|
+
- Production builds fail when server runtime config contains a value copied from a secret build environment variable. The error lists config paths only
|
|
23
24
|
- Complete defaults and diagnostics applied to every named Wrangler environment
|
|
25
|
+
- Exact Cloudflare binding and runtime types generated during `nuxt prepare`
|
|
24
26
|
|
|
25
27
|
Persistent KV mounts are never wrapped. The expiry policy applies only to cache data.
|
|
26
28
|
|
|
@@ -56,21 +58,28 @@ export default defineNuxtConfig({
|
|
|
56
58
|
})
|
|
57
59
|
```
|
|
58
60
|
|
|
59
|
-
Cloudflare KV requires TTLs of at least 60 seconds.
|
|
61
|
+
Cloudflare KV requires TTLs of at least 60 seconds. The cache wrapper raises shorter positive TTLs to 60 seconds.
|
|
60
62
|
|
|
61
|
-
|
|
63
|
+
Keep server runtime secret defaults empty. Nuxt reads matching `NUXT_*` values from Worker secret bindings at runtime. The production build guard rejects secret build environment values before Nitro can include them in the bundle. Nuxt Scripts proxy signing remains allowed because that module registers its security plugin during the build.
|
|
62
64
|
|
|
63
|
-
|
|
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.
|
|
64
66
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
workersCache: { _tag: 'disabled' },
|
|
69
|
-
},
|
|
70
|
-
})
|
|
71
|
-
```
|
|
67
|
+
## Cost controls
|
|
68
|
+
|
|
69
|
+
Cloudflare pricing changes. Check the linked pricing pages before making a budget.
|
|
72
70
|
|
|
73
|
-
|
|
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.
|
|
74
83
|
|
|
75
84
|
## Doctor
|
|
76
85
|
|
|
@@ -84,7 +93,7 @@ pnpm nuxt-cloudflare doctor --strict --allow-warning source-maps-disabled
|
|
|
84
93
|
|
|
85
94
|
The CLI reads Wrangler config through Wrangler itself, so JSON, JSONC, TOML, environments, upward lookup, and Nitro generated-config redirects follow deployment semantics. It separately inspects root authoring format. Existing TOML remains supported and receives non-blocking guidance because Cloudflare recommends JSONC for new projects. Shadowed root configs warn because they can silently drift.
|
|
86
95
|
|
|
87
|
-
Errors cover
|
|
96
|
+
Errors cover malformed asset patterns, invalid Durable Object lifecycles, invalid Container storage, queue limits, unsafe example bindings, and unflattened generated environments. Warnings cover blanket Worker-first assets, missing environment bindings, unrestricted email, local service fidelity, deprecated fields, telemetry gaps, and public endpoints. Secret values are never included.
|
|
88
97
|
|
|
89
98
|
Normal mode fails errors. `--strict` also fails warnings. Intentional exceptions remain visible and may be listed with `--allow-warning`. Module builds use the equivalent policy:
|
|
90
99
|
|
|
@@ -113,6 +122,14 @@ pnpm wrangler check startup --config .output/server/wrangler.json
|
|
|
113
122
|
|
|
114
123
|
Pass the final generated config explicitly to `types` and `check startup`; Nitro's `.wrangler/deploy/config.json` redirect does not apply to those commands.
|
|
115
124
|
|
|
125
|
+
### Product guidance
|
|
126
|
+
|
|
127
|
+
- Named environments do not inherit bindings. The doctor reports each omitted root binding.
|
|
128
|
+
- AI, Browser, Images, mTLS, Vectorize, and Flagship warn when local development omits `remote: true`.
|
|
129
|
+
- Every Container must match a local SQLite Durable Object. Legacy `dev` and `standard` instance types warn.
|
|
130
|
+
- Email bindings should restrict senders or destinations.
|
|
131
|
+
- Legacy module bindings and the old Pipeline `pipeline` field warn with their current replacements.
|
|
132
|
+
|
|
116
133
|
## Runtime primitives
|
|
117
134
|
|
|
118
135
|
### D1 sessions and safe retries
|
|
@@ -128,7 +145,7 @@ await retryIdempotentD1Write({
|
|
|
128
145
|
})
|
|
129
146
|
```
|
|
130
147
|
|
|
131
|
-
One `first-primary` session is cached per request and binding. D1 already retries read-only queries. Write retries require an explicit safety tag. `lock-only` retries SQLite lock contention; `replay-safe` also permits classified
|
|
148
|
+
One `first-primary` session is cached per request and binding. D1 already retries read-only queries. Write retries require an explicit safety tag. `lock-only` retries SQLite lock contention; `replay-safe` also permits classified network and storage reset failures. Resource pressure, queue delay, CPU, and memory errors are never retried.
|
|
132
149
|
|
|
133
150
|
### D1 parameter plans
|
|
134
151
|
|
|
@@ -156,15 +173,19 @@ D1 allows 100 bound parameters per statement, including each statement inside `d
|
|
|
156
173
|
### Bindings
|
|
157
174
|
|
|
158
175
|
```ts
|
|
159
|
-
import type {
|
|
160
|
-
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()
|
|
161
180
|
|
|
162
|
-
function requireDatabase(
|
|
163
|
-
return
|
|
181
|
+
function requireDatabase(source?: CloudflareBindingSource) {
|
|
182
|
+
return cloudflare.require('DB', source)
|
|
164
183
|
}
|
|
165
184
|
```
|
|
166
185
|
|
|
167
|
-
`
|
|
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.
|
|
168
189
|
|
|
169
190
|
### Scoped secrets file
|
|
170
191
|
|
|
@@ -190,7 +211,7 @@ The writer uses exclusive creation and mode 0600. It removes partial files after
|
|
|
190
211
|
|
|
191
212
|
## Deliberate boundaries
|
|
192
213
|
|
|
193
|
-
The module does not choose Worker names, routes, domains, resource IDs, 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.
|
|
214
|
+
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.
|
|
194
215
|
|
|
195
216
|
Next high-value extractions from Nuxt SEO and gscdump:
|
|
196
217
|
|
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 };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { resolve, dirname } from 'pathe';
|
|
3
|
+
import { unstable_readConfig } from 'wrangler';
|
|
4
|
+
|
|
5
|
+
function errorMessage(error) {
|
|
6
|
+
return error instanceof Error ? error.message : String(error);
|
|
7
|
+
}
|
|
8
|
+
function attempt(run) {
|
|
9
|
+
try {
|
|
10
|
+
return { _tag: "loaded", value: run() };
|
|
11
|
+
} catch (error) {
|
|
12
|
+
return { _tag: "invalid", reason: errorMessage(error) };
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function findUpFile(cwd, relativePath) {
|
|
16
|
+
let directory = resolve(cwd);
|
|
17
|
+
while (true) {
|
|
18
|
+
const candidate = resolve(directory, relativePath);
|
|
19
|
+
if (existsSync(candidate))
|
|
20
|
+
return candidate;
|
|
21
|
+
const parent = dirname(directory);
|
|
22
|
+
if (parent === directory)
|
|
23
|
+
return void 0;
|
|
24
|
+
directory = parent;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function findUpWranglerConfig(cwd) {
|
|
28
|
+
let directory = resolve(cwd);
|
|
29
|
+
while (true) {
|
|
30
|
+
for (const name of ["wrangler.json", "wrangler.jsonc", "wrangler.toml"]) {
|
|
31
|
+
const candidate = resolve(directory, name);
|
|
32
|
+
if (existsSync(candidate))
|
|
33
|
+
return candidate;
|
|
34
|
+
}
|
|
35
|
+
const parent = dirname(directory);
|
|
36
|
+
if (parent === directory)
|
|
37
|
+
return void 0;
|
|
38
|
+
directory = parent;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function resolveNitroDeployConfig(cwd) {
|
|
42
|
+
const redirectPath = findUpFile(cwd, ".wrangler/deploy/config.json");
|
|
43
|
+
if (!redirectPath)
|
|
44
|
+
return void 0;
|
|
45
|
+
const redirectProjectDirectory = dirname(dirname(dirname(redirectPath)));
|
|
46
|
+
const authoredConfigPath = findUpWranglerConfig(cwd);
|
|
47
|
+
if (authoredConfigPath && dirname(authoredConfigPath) !== redirectProjectDirectory)
|
|
48
|
+
return void 0;
|
|
49
|
+
const parsed = JSON.parse(readFileSync(redirectPath, "utf8"));
|
|
50
|
+
if (!parsed || typeof parsed !== "object" || !("configPath" in parsed) || typeof parsed.configPath !== "string")
|
|
51
|
+
throw new Error(`Invalid Nitro deploy config: ${redirectPath}`);
|
|
52
|
+
return resolve(dirname(redirectPath), parsed.configPath);
|
|
53
|
+
}
|
|
54
|
+
function readProjectWranglerConfig(options) {
|
|
55
|
+
const redirect = attempt(() => options.config ? void 0 : resolveNitroDeployConfig(options.cwd));
|
|
56
|
+
if (redirect._tag === "invalid") {
|
|
57
|
+
return {
|
|
58
|
+
_tag: "invalid",
|
|
59
|
+
generated: false,
|
|
60
|
+
path: findUpFile(options.cwd, ".wrangler/deploy/config.json") ?? resolve(options.cwd, ".wrangler/deploy/config.json"),
|
|
61
|
+
reason: redirect.reason
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
const generatedConfigPath = redirect.value;
|
|
65
|
+
const configPath = options.config ? resolve(options.cwd, options.config) : generatedConfigPath;
|
|
66
|
+
const loaded = attempt(() => unstable_readConfig({
|
|
67
|
+
config: configPath,
|
|
68
|
+
env: options.environment,
|
|
69
|
+
script: resolve(options.cwd, "__nuxt-cloudflare-doctor.mjs")
|
|
70
|
+
}, {
|
|
71
|
+
hideWarnings: true,
|
|
72
|
+
useRedirectIfAvailable: false
|
|
73
|
+
}));
|
|
74
|
+
if (loaded._tag === "invalid") {
|
|
75
|
+
return {
|
|
76
|
+
_tag: "invalid",
|
|
77
|
+
generated: generatedConfigPath !== void 0,
|
|
78
|
+
path: configPath,
|
|
79
|
+
reason: loaded.reason
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
_tag: "loaded",
|
|
84
|
+
config: loaded.value,
|
|
85
|
+
generated: generatedConfigPath !== void 0,
|
|
86
|
+
path: loaded.value.configPath
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export { readProjectWranglerConfig };
|
package/dist/cli/index.mjs
CHANGED
|
@@ -1,97 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import process from 'node:process';
|
|
3
3
|
import { defineCommand, runMain } from 'citty';
|
|
4
|
-
import { resolve
|
|
4
|
+
import { resolve } from 'pathe';
|
|
5
5
|
import { d as discoverWranglerSourceConfigs, a as diagnoseWranglerSourceConfigs, p as parseWranglerAllowedWarnings, e as evaluateWranglerDiagnostics } from '../shared/nuxt-cloudflare.6X-qzF_b.mjs';
|
|
6
6
|
import { diagnoseWranglerConfig, formatWranglerDiagnostics } from '../wrangler.mjs';
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
7
|
+
import { readProjectWranglerConfig } from '../chunks/wrangler-reader.mjs';
|
|
8
|
+
import 'node:fs';
|
|
9
9
|
import 'node:fs/promises';
|
|
10
|
-
|
|
11
|
-
function errorMessage(error) {
|
|
12
|
-
return error instanceof Error ? error.message : String(error);
|
|
13
|
-
}
|
|
14
|
-
function attempt(run) {
|
|
15
|
-
try {
|
|
16
|
-
return { _tag: "loaded", value: run() };
|
|
17
|
-
} catch (error) {
|
|
18
|
-
return { _tag: "invalid", reason: errorMessage(error) };
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
function findUpFile(cwd, relativePath) {
|
|
22
|
-
let directory = resolve(cwd);
|
|
23
|
-
while (true) {
|
|
24
|
-
const candidate = resolve(directory, relativePath);
|
|
25
|
-
if (existsSync(candidate))
|
|
26
|
-
return candidate;
|
|
27
|
-
const parent = dirname(directory);
|
|
28
|
-
if (parent === directory)
|
|
29
|
-
return void 0;
|
|
30
|
-
directory = parent;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
function findUpWranglerConfig(cwd) {
|
|
34
|
-
let directory = resolve(cwd);
|
|
35
|
-
while (true) {
|
|
36
|
-
for (const name of ["wrangler.json", "wrangler.jsonc", "wrangler.toml"]) {
|
|
37
|
-
const candidate = resolve(directory, name);
|
|
38
|
-
if (existsSync(candidate))
|
|
39
|
-
return candidate;
|
|
40
|
-
}
|
|
41
|
-
const parent = dirname(directory);
|
|
42
|
-
if (parent === directory)
|
|
43
|
-
return void 0;
|
|
44
|
-
directory = parent;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
function resolveNitroDeployConfig(cwd) {
|
|
48
|
-
const redirectPath = findUpFile(cwd, ".wrangler/deploy/config.json");
|
|
49
|
-
if (!redirectPath)
|
|
50
|
-
return void 0;
|
|
51
|
-
const redirectProjectDirectory = dirname(dirname(dirname(redirectPath)));
|
|
52
|
-
const authoredConfigPath = findUpWranglerConfig(cwd);
|
|
53
|
-
if (authoredConfigPath && dirname(authoredConfigPath) !== redirectProjectDirectory)
|
|
54
|
-
return void 0;
|
|
55
|
-
const parsed = JSON.parse(readFileSync(redirectPath, "utf8"));
|
|
56
|
-
if (!parsed || typeof parsed !== "object" || !("configPath" in parsed) || typeof parsed.configPath !== "string")
|
|
57
|
-
throw new Error(`Invalid Nitro deploy config: ${redirectPath}`);
|
|
58
|
-
return resolve(dirname(redirectPath), parsed.configPath);
|
|
59
|
-
}
|
|
60
|
-
function readProjectWranglerConfig(options) {
|
|
61
|
-
const redirect = attempt(() => options.config ? void 0 : resolveNitroDeployConfig(options.cwd));
|
|
62
|
-
if (redirect._tag === "invalid") {
|
|
63
|
-
return {
|
|
64
|
-
_tag: "invalid",
|
|
65
|
-
generated: false,
|
|
66
|
-
path: findUpFile(options.cwd, ".wrangler/deploy/config.json") ?? resolve(options.cwd, ".wrangler/deploy/config.json"),
|
|
67
|
-
reason: redirect.reason
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
const generatedConfigPath = redirect.value;
|
|
71
|
-
const configPath = options.config ? resolve(options.cwd, options.config) : generatedConfigPath;
|
|
72
|
-
const loaded = attempt(() => unstable_readConfig({
|
|
73
|
-
config: configPath,
|
|
74
|
-
env: options.environment,
|
|
75
|
-
script: resolve(options.cwd, "__nuxt-cloudflare-doctor.mjs")
|
|
76
|
-
}, {
|
|
77
|
-
hideWarnings: true,
|
|
78
|
-
useRedirectIfAvailable: false
|
|
79
|
-
}));
|
|
80
|
-
if (loaded._tag === "invalid") {
|
|
81
|
-
return {
|
|
82
|
-
_tag: "invalid",
|
|
83
|
-
generated: generatedConfigPath !== void 0,
|
|
84
|
-
path: configPath,
|
|
85
|
-
reason: loaded.reason
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
return {
|
|
89
|
-
_tag: "loaded",
|
|
90
|
-
config: loaded.value,
|
|
91
|
-
generated: generatedConfigPath !== void 0,
|
|
92
|
-
path: loaded.value.configPath
|
|
93
|
-
};
|
|
94
|
-
}
|
|
10
|
+
import 'wrangler';
|
|
95
11
|
|
|
96
12
|
function diagnoseWranglerProject(options) {
|
|
97
13
|
const sourceConfigPaths = discoverWranglerSourceConfigs(options.cwd, options.config);
|
|
@@ -123,7 +39,7 @@ function diagnoseWranglerProject(options) {
|
|
|
123
39
|
return {
|
|
124
40
|
configPath: loaded.path,
|
|
125
41
|
diagnostics: [
|
|
126
|
-
...diagnoseWranglerConfig(loaded.config, { ...options, generated: loaded.generated }),
|
|
42
|
+
...diagnoseWranglerConfig(loaded.config, { ...options, generated: loaded.generated, normalized: true }),
|
|
127
43
|
...diagnoseWranglerSourceConfigs(sourceConfigPaths)
|
|
128
44
|
],
|
|
129
45
|
sourceConfigPaths
|
|
@@ -187,7 +103,7 @@ const doctor = defineCommand({
|
|
|
187
103
|
const main = defineCommand({
|
|
188
104
|
meta: {
|
|
189
105
|
name: "nuxt-cloudflare",
|
|
190
|
-
version: "0.0.
|
|
106
|
+
version: "0.0.8",
|
|
191
107
|
description: "Cloudflare deployment defaults and diagnostics for Nuxt"
|
|
192
108
|
},
|
|
193
109
|
subCommands: { doctor }
|
package/dist/d1.mjs
CHANGED
|
@@ -3,13 +3,10 @@ const D1_PARAMETER_PLAN = Symbol("@harlan-zw/nuxt-cloudflare:d1-parameter-plan")
|
|
|
3
3
|
const REQUEST_D1_SESSIONS = Symbol.for("@harlan-zw/nuxt-cloudflare:d1-sessions");
|
|
4
4
|
const TRANSIENT_D1_SIGNALS = [
|
|
5
5
|
"Network connection lost",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"exceeded its CPU time limit",
|
|
6
|
+
"D1 DB reset because its code was updated",
|
|
7
|
+
"Internal error while starting up D1 DB storage caused object to be reset",
|
|
8
|
+
"Internal error in D1 DB storage caused object to be reset",
|
|
10
9
|
"storage caused object to be reset",
|
|
11
|
-
"reset because its code was updated",
|
|
12
|
-
"Internal error in D1",
|
|
13
10
|
"cannot resolve d1 db due to transient issue on remote node"
|
|
14
11
|
];
|
|
15
12
|
function consistencyConstraint(consistency) {
|
package/dist/module.d.mts
CHANGED
|
@@ -9,6 +9,7 @@ type WranglerDiagnosticPolicy = {
|
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
interface ModuleOptions {
|
|
12
|
+
bindingTypes?: boolean;
|
|
12
13
|
enabled?: boolean;
|
|
13
14
|
compatibilityDate?: string;
|
|
14
15
|
compatibilityMaxAgeDays?: number;
|
|
@@ -39,9 +40,10 @@ interface NitroCloudflareShape {
|
|
|
39
40
|
sourceMap?: boolean;
|
|
40
41
|
storage?: Record<string, NitroStorageMount>;
|
|
41
42
|
}
|
|
43
|
+
declare function findPopulatedRuntimeSecretPaths(config: unknown, environment: Readonly<Record<string, string | undefined>>): string[];
|
|
42
44
|
declare function configureNitroCloudflare(nitro: NitroCloudflareShape, options: ModuleOptions, nuxtServerSourceMaps?: boolean): void;
|
|
43
45
|
declare function setupCloudflareModule(options: ModuleOptions, nuxt: Nuxt): void;
|
|
44
46
|
declare const _default: any;
|
|
45
47
|
|
|
46
|
-
export { configureNitroCloudflare, _default as default, setupCloudflareModule };
|
|
48
|
+
export { configureNitroCloudflare, _default as default, findPopulatedRuntimeSecretPaths, setupCloudflareModule };
|
|
47
49
|
export type { ModuleOptions, NitroCloudflareShape };
|