fix(core): use c12 to load mcfly config from route middleware

- Can pass functions; while nitro's runtimeConfig cannot. This makes plugins possible
This commit is contained in:
Ayo Ayco 2025-01-10 17:43:25 +01:00
parent c282f37fae
commit 62fbf5c4b8
4 changed files with 18 additions and 11 deletions

View file

@ -21,10 +21,5 @@ export async function getNitroConfig() {
// McFly standard nitro config
...mcflyNitroConfig,
// expose mcfly config to framework runtime
runtimeConfig: {
mcfly: mcflyConfig,
},
}
}

View file

@ -1,6 +1,6 @@
{
"name": "@mcflyjs/core",
"version": "0.8.6",
"version": "0.8.7",
"description": "McFly core package",
"type": "module",
"main": "index.js",
@ -27,6 +27,7 @@
"c12": "^2.0.1",
"citty": "^0.1.6",
"consola": "^3.3.3",
"devalue": "^5.1.1",
"esprima": "^4.0.1",
"h3": "^1.13.0",
"nitropack": "latest",

View file

@ -1,8 +1,9 @@
import { eventHandler } from 'h3'
import { useRuntimeConfig, useStorage } from 'nitropack/runtime'
import { useStorage } from 'nitropack/runtime'
import { createHooks } from 'hookable'
import { consola } from 'consola'
import { colorize } from 'consola/utils'
import { loadConfig } from 'c12'
import {
hooks as mcflyHooks,
@ -27,7 +28,7 @@ export default eventHandler(async (event) => {
const hooks = createHooks()
Object.keys(mcflyHooks).forEach((hookName) => hooks.addHooks(hookName))
const { path } = event
let { mcfly: config } = useRuntimeConfig()
let { config } = await loadConfig({ name: 'mcfly' })
const storage = useStorage()
// if not page, don't render
@ -80,7 +81,8 @@ export default eventHandler(async (event) => {
// call hook
if (transform.hook) {
hooks.callHook(transform.hook)
// not sure if we want to await, for now it makes the outcome predictable
await hooks.callHook(transform.hook)
}
}
} else {
@ -92,11 +94,11 @@ export default eventHandler(async (event) => {
}
if (html) {
hooks.callHook(mcflyHooks.pageRendered)
await hooks.callHook(mcflyHooks.pageRendered)
}
const timeEnd = performance.now()
consola.log(
consola.info(
colorize('green', event.path),
'rendered in',
Math.round(timeEnd - timeStart),

View file

@ -63,6 +63,9 @@ importers:
consola:
specifier: ^3.3.3
version: 3.3.3
devalue:
specifier: ^5.1.1
version: 5.1.1
esprima:
specifier: ^4.0.1
version: 4.0.1
@ -2537,6 +2540,9 @@ packages:
resolution: {integrity: sha512-ARFxjzizOhPqs1fYC/2NMC3N4jrQ6HvVflnXBTRqNEqJuXwyKLRr9CrJwkRcV/SnZt1sNXgsF6FPm0x57Tq0rw==}
engines: {node: ^14.14.0 || >=16.0.0}
devalue@5.1.1:
resolution: {integrity: sha512-maua5KUiapvEwiEAe+XnlZ3Rh0GD+qI1J/nb9vrJc3muPXvcF/8gXYTWF76+5DAqHyDUtOIImEuo0YKE9mshVw==}
diff@4.0.2:
resolution: {integrity: sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==}
engines: {node: '>=0.3.1'}
@ -4766,6 +4772,7 @@ packages:
rollup-plugin-visualizer@5.13.1:
resolution: {integrity: sha512-vMg8i6BprL8aFm9DKvL2c8AwS8324EgymYQo9o6E26wgVvwMhsJxS37aNL6ZsU7X9iAcMYwdME7gItLfG5fwJg==}
engines: {node: '>=18'}
deprecated: Contains unintended breaking changes
hasBin: true
peerDependencies:
rolldown: 1.x
@ -8168,6 +8175,8 @@ snapshots:
transitivePeerDependencies:
- supports-color
devalue@5.1.1: {}
diff@4.0.2: {}
dir-glob@3.0.1: