Skip to content

Commit

Permalink
fix: update module runtime config generation
Browse files Browse the repository at this point in the history
  • Loading branch information
productdevbook committed Feb 4, 2024
1 parent 0467817 commit ef7bc5f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 12 deletions.
43 changes: 33 additions & 10 deletions packages/nuxt/src/runtime/core/utils/moduleRuntimeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,16 @@ import { runtimeConfigToEnv } from './runtimeConfigToEnv'
export function generateModuleRuntimeConfig<T>(
nuxt: NuxtPergel,
moduleOptions: ResolvedPergelModuleOptions,
config: Record<string, any>,
config: Record<string, any> | {
[key: string]: any
default?: Record<string, any>
},
publicRuntime?: boolean,
generateEnv?: boolean,
) {
const defaultConfig = Object.assign({}, config.default)
delete config.default

const projectName = moduleOptions.projectName
const moduleName = moduleOptions.moduleName

Expand All @@ -33,19 +40,35 @@ export function generateModuleRuntimeConfig<T>(
...acc,
...cur,
}
}),
}, {}),
},
}) as T

const { keyEnvValue, envs } = runtimeConfigToEnv(runtimeConfig.public[projectName as any] as any, [projectName])
const { envs, keyEnvValue } = runtimeConfigToEnv(
(runtimeConfig.public as any)[projectName][moduleName] as any,
[projectName, moduleName],
)

nuxt._pergel.readmeJson[projectName] ??= {}
nuxt._pergel.readmeJson[projectName][moduleName] ??= {} as any
nuxt._pergel.readmeJson[projectName][moduleName] = defu(nuxt._pergel.readmeJson[projectName][moduleName], {
env: {
...envs,
},
})
if (generateEnv === true) {
nuxt._pergel.readmeJson[projectName] ??= {}
nuxt._pergel.readmeJson[projectName][moduleName] ??= {} as any
nuxt._pergel.readmeJson[projectName][moduleName] = defu(nuxt._pergel.readmeJson[projectName][moduleName], {
env: {
...Object.entries(config).map(([key, __value]) => {
const _key = `NUXT_${snakeCase(`${projectName}_${moduleName}_${key}` as string).toUpperCase()}`
const _value = envs[`NUXT_${snakeCase(`${projectName}_${moduleName}_${key}` as string).toUpperCase()}`]

Check failure on line 59 in packages/nuxt/src/runtime/core/utils/moduleRuntimeConfig.ts

View workflow job for this annotation

GitHub Actions / 📚 Main (macos-14)

'_value' is declared but its value is never read.
return {
[_key]: defaultConfig[key] ?? '',
}
}).reduce((acc, cur) => {
return {
...acc,
...cur,
}
}, {}),
},
})
}

return {
runtimeConfig: (runtimeConfig.public[projectName] as any)[moduleName] as T,
Expand Down
9 changes: 8 additions & 1 deletion packages/nuxt/src/runtime/modules/graphqlYoga/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,14 @@ export default definePergelModule<GraphQLYogaConfig, ResolvedGraphQLYogaConfig>(

generateModuleRuntimeConfig<ResolvedGraphQLYogaConfig>(nuxt, options, {
...options,
}, true)
}, true, false)

generateModuleRuntimeConfig<ResolvedGraphQLYogaConfig>(nuxt, options, {
origin: undefined,
default: {
origin: 'http://localhost:3000,http://localhost:3001',
},
}, true, true)

addServerImportsDir(resolver.resolve('./composables/**'))

Expand Down
5 changes: 4 additions & 1 deletion packages/nuxt/src/runtime/modules/urql/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ export default definePergelModule<UrqlModuleOptions>({

generateModuleRuntimeConfig<UrqlModuleRuntimeConfig>(nuxt, options, {
endpoint: undefined,
}, true)
default: {
endpoint: 'http://localhost:3000/api/graphql',
},
}, true, true)

addImportsDir(resolver.resolve(join('plugins')))

Expand Down

0 comments on commit ef7bc5f

Please sign in to comment.