Skip to content

Commit ecb0c3f

Browse files
authored
feat: add support for defining compatibility date & flags (#264)
1 parent f724bec commit ecb0c3f

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

playground/nuxt.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export default defineNuxtConfig({
1919
blob: true,
2020
cache: true,
2121
bindings: {
22+
compatibilityFlags: ['nodejs_compat_v2'],
2223
// Used for /api/hyperdrive
2324
hyperdrive: {
2425
POSTGRES: '8bb2913857b84c939cd908740fa5a5d5'

playground/server/api/crypto.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export default eventHandler(async () => {
2+
// Available in nodejs_compat_v2
3+
const crypto = globalThis['process']?.getBuiltinModule?.('crypto')
4+
const hash = await new Promise((resolve, reject) => {
5+
crypto.scrypt('hello-world', crypto.randomUUID(), 64, (err, hash) => {
6+
if (err) return reject(err)
7+
resolve(hash.toString('hex'))
8+
})
9+
})
10+
11+
return { hash: `scrypt:${hash}` }
12+
})

src/features.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ export interface HubConfig {
2828
kv?: boolean
2929

3030
bindings?: {
31+
compatibilityDate?: string
32+
compatibilityFlags?: string[]
3133
hyperdrive?: {
3234
[key: string]: string
3335
}

src/types/module.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,17 @@ export interface ModuleOptions {
8585
* @default {}
8686
*/
8787
bindings?: {
88+
/**
89+
* The compatibility date for the project.
90+
* @see https://developers.cloudflare.com/workers/configuration/compatibility-dates/
91+
*/
92+
compatibilityDate?: string
93+
/**
94+
* Extra compatibility flags for the project.
95+
* Note that NuxtHub will always add the 'nodejs_compat' flag if not specified.
96+
* @see https://developers.cloudflare.com/workers/configuration/compatibility-dates/#compatibility-flags
97+
*/
98+
compatibilityFlags?: string[]
8899
/**
89100
* The hyperdrive bindings for the project, used only when deployed on Cloudflare.
90101
* @see https://hub.nuxt.com/docs/features/hyperdrive

0 commit comments

Comments
 (0)