Skip to content

Commit

Permalink
chore: add nitroPreset in hub.config.json
Browse files Browse the repository at this point in the history
  • Loading branch information
atinux committed Jan 22, 2025
1 parent 85c7241 commit c2e29b3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,18 +167,18 @@ export default defineNuxtModule<ModuleOptions>({

// Production mode without remote storage
if (!hub.remote && !nuxt.options.dev) {
// Make sure to fallback to cloudflare-pages preset
let preset = nuxt.options.nitro.preset = nuxt.options.nitro.preset || 'cloudflare-pages'
// Make sure to fallback to cloudflare_pages preset
let preset = nuxt.options.nitro.preset = nuxt.options.nitro.preset || 'cloudflare_pages'
// Support also cloudflare_module
preset = String(preset).replace('_', '-')
preset = String(preset).replace('-', '_')

if (!['cloudflare-pages', 'cloudflare-module', 'cloudflare-durable'].includes(preset)) {
log.error('NuxtHub is only compatible with the `cloudflare-pages`, `cloudflare-module` or `cloudflare-durable` presets.')
if (!['cloudflare_pages', 'cloudflare_module', 'cloudflare_durable'].includes(preset)) {
log.error('NuxtHub is only compatible with the `cloudflare_pages`, `cloudflare_module` or `cloudflare_durable` presets.')
process.exit(1)
}

// @ts-expect-error compatibilityDate is not properly typed
if (preset !== 'cloudflare-pages' && nuxt.options.compatibilityDate?.default && nuxt.options.compatibilityDate.default < '2024-11-20') {
if (preset !== 'cloudflare_pages' && nuxt.options.compatibilityDate?.default && nuxt.options.compatibilityDate.default < '2024-11-20') {
log.warn('Found a compatibility date in `nuxt.config.ts` earlier than `2024-09-19`, forcing it to `2024-09-19`. Please update your `nuxt.config.ts` file.')
// @ts-expect-error compatibilityDate is not properly typed
nuxt.options.compatibilityDate.default = '2024-09-19'
Expand Down
3 changes: 2 additions & 1 deletion src/utils/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ export function addBuildHooks(nuxt: Nuxt, hub: HubConfig) {
database: hub.database,
kv: hub.kv,
vectorize: hub.vectorize,
bindings: hub.bindings
bindings: hub.bindings,
nitroPreset: nitro.options.preset
}
const distDir = nitro.options.output.dir || nitro.options.output.publicDir
await writeFile(join(distDir, 'hub.config.json'), JSON.stringify(hubConfig, null, 2), 'utf-8')
Expand Down

0 comments on commit c2e29b3

Please sign in to comment.