Skip to content

Commit 04efdfa

Browse files
committed
chore(dx): require wrangler only when required
1 parent 823a6e8 commit 04efdfa

File tree

2 files changed

+18
-24
lines changed

2 files changed

+18
-24
lines changed

src/module.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,16 +131,19 @@ export default defineNuxtModule<ModuleOptions>({
131131
await writeFile(gitignorePath, `${gitignore ? gitignore + '\n' : gitignore}.data`, 'utf-8')
132132
}
133133

134-
// Generate the wrangler.toml file
135-
const wranglerPath = join(hubDir, './wrangler.toml')
136-
await writeFile(wranglerPath, generateWrangler(hub), 'utf-8')
137-
// @ts-expect-error cloudflareDev is not typed here
138-
nuxt.options.nitro.cloudflareDev = {
139-
persistDir: hubDir,
140-
configPath: wranglerPath,
141-
silent: true
134+
const needWrangler = Boolean(hub.analytics || hub.blob || hub.database || hub.kv)
135+
if (needWrangler) {
136+
// Generate the wrangler.toml file
137+
const wranglerPath = join(hubDir, './wrangler.toml')
138+
await writeFile(wranglerPath, generateWrangler(hub), 'utf-8')
139+
// @ts-expect-error cloudflareDev is not typed here
140+
nuxt.options.nitro.cloudflareDev = {
141+
persistDir: hubDir,
142+
configPath: wranglerPath,
143+
silent: true
144+
}
145+
await installModule('nitro-cloudflare-dev')
142146
}
143-
await installModule('nitro-cloudflare-dev')
144147
nuxt.options.nitro.plugins = nuxt.options.nitro.plugins || []
145148
nuxt.options.nitro.plugins.push(resolve('./runtime/ready.dev'))
146149
}

src/utils/wrangler.ts

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { stringifyTOML } from 'confbox'
22

3-
export function generateWrangler(hub: { kv: boolean, database: boolean, blob: boolean, cache: boolean, analytics: boolean }) {
3+
export function generateWrangler(hub: { kv: boolean, database: boolean, blob: boolean, analytics: boolean }) {
44
const wrangler: { [key: string]: any } = {}
55

66
if (hub.analytics) {
@@ -17,20 +17,11 @@ export function generateWrangler(hub: { kv: boolean, database: boolean, blob: bo
1717
}]
1818
}
1919

20-
if (hub.cache || hub.kv) {
21-
wrangler['kv_namespaces'] = []
22-
if (hub.kv) {
23-
wrangler['kv_namespaces'].push({
24-
binding: 'KV',
25-
id: 'kv_default'
26-
})
27-
}
28-
if (hub.cache) {
29-
wrangler['kv_namespaces'].push({
30-
binding: 'CACHE',
31-
id: 'cache_default'
32-
})
33-
}
20+
if (hub.kv) {
21+
wrangler['kv_namespaces'] = [{
22+
binding: 'KV',
23+
id: 'kv_default'
24+
}]
3425
}
3526

3627
if (hub.database) {

0 commit comments

Comments
 (0)