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:
parent
c282f37fae
commit
62fbf5c4b8
4 changed files with 18 additions and 11 deletions
|
@ -21,10 +21,5 @@ export async function getNitroConfig() {
|
||||||
|
|
||||||
// McFly standard nitro config
|
// McFly standard nitro config
|
||||||
...mcflyNitroConfig,
|
...mcflyNitroConfig,
|
||||||
|
|
||||||
// expose mcfly config to framework runtime
|
|
||||||
runtimeConfig: {
|
|
||||||
mcfly: mcflyConfig,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@mcflyjs/core",
|
"name": "@mcflyjs/core",
|
||||||
"version": "0.8.6",
|
"version": "0.8.7",
|
||||||
"description": "McFly core package",
|
"description": "McFly core package",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
|
@ -27,6 +27,7 @@
|
||||||
"c12": "^2.0.1",
|
"c12": "^2.0.1",
|
||||||
"citty": "^0.1.6",
|
"citty": "^0.1.6",
|
||||||
"consola": "^3.3.3",
|
"consola": "^3.3.3",
|
||||||
|
"devalue": "^5.1.1",
|
||||||
"esprima": "^4.0.1",
|
"esprima": "^4.0.1",
|
||||||
"h3": "^1.13.0",
|
"h3": "^1.13.0",
|
||||||
"nitropack": "latest",
|
"nitropack": "latest",
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
import { eventHandler } from 'h3'
|
import { eventHandler } from 'h3'
|
||||||
import { useRuntimeConfig, useStorage } from 'nitropack/runtime'
|
import { useStorage } from 'nitropack/runtime'
|
||||||
import { createHooks } from 'hookable'
|
import { createHooks } from 'hookable'
|
||||||
import { consola } from 'consola'
|
import { consola } from 'consola'
|
||||||
import { colorize } from 'consola/utils'
|
import { colorize } from 'consola/utils'
|
||||||
|
import { loadConfig } from 'c12'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
hooks as mcflyHooks,
|
hooks as mcflyHooks,
|
||||||
|
@ -27,7 +28,7 @@ export default eventHandler(async (event) => {
|
||||||
const hooks = createHooks()
|
const hooks = createHooks()
|
||||||
Object.keys(mcflyHooks).forEach((hookName) => hooks.addHooks(hookName))
|
Object.keys(mcflyHooks).forEach((hookName) => hooks.addHooks(hookName))
|
||||||
const { path } = event
|
const { path } = event
|
||||||
let { mcfly: config } = useRuntimeConfig()
|
let { config } = await loadConfig({ name: 'mcfly' })
|
||||||
const storage = useStorage()
|
const storage = useStorage()
|
||||||
|
|
||||||
// if not page, don't render
|
// if not page, don't render
|
||||||
|
@ -80,7 +81,8 @@ export default eventHandler(async (event) => {
|
||||||
|
|
||||||
// call hook
|
// call hook
|
||||||
if (transform.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 {
|
} else {
|
||||||
|
@ -92,11 +94,11 @@ export default eventHandler(async (event) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (html) {
|
if (html) {
|
||||||
hooks.callHook(mcflyHooks.pageRendered)
|
await hooks.callHook(mcflyHooks.pageRendered)
|
||||||
}
|
}
|
||||||
|
|
||||||
const timeEnd = performance.now()
|
const timeEnd = performance.now()
|
||||||
consola.log(
|
consola.info(
|
||||||
colorize('green', event.path),
|
colorize('green', event.path),
|
||||||
'rendered in',
|
'rendered in',
|
||||||
Math.round(timeEnd - timeStart),
|
Math.round(timeEnd - timeStart),
|
||||||
|
|
|
@ -63,6 +63,9 @@ importers:
|
||||||
consola:
|
consola:
|
||||||
specifier: ^3.3.3
|
specifier: ^3.3.3
|
||||||
version: 3.3.3
|
version: 3.3.3
|
||||||
|
devalue:
|
||||||
|
specifier: ^5.1.1
|
||||||
|
version: 5.1.1
|
||||||
esprima:
|
esprima:
|
||||||
specifier: ^4.0.1
|
specifier: ^4.0.1
|
||||||
version: 4.0.1
|
version: 4.0.1
|
||||||
|
@ -2537,6 +2540,9 @@ packages:
|
||||||
resolution: {integrity: sha512-ARFxjzizOhPqs1fYC/2NMC3N4jrQ6HvVflnXBTRqNEqJuXwyKLRr9CrJwkRcV/SnZt1sNXgsF6FPm0x57Tq0rw==}
|
resolution: {integrity: sha512-ARFxjzizOhPqs1fYC/2NMC3N4jrQ6HvVflnXBTRqNEqJuXwyKLRr9CrJwkRcV/SnZt1sNXgsF6FPm0x57Tq0rw==}
|
||||||
engines: {node: ^14.14.0 || >=16.0.0}
|
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:
|
diff@4.0.2:
|
||||||
resolution: {integrity: sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==}
|
resolution: {integrity: sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==}
|
||||||
engines: {node: '>=0.3.1'}
|
engines: {node: '>=0.3.1'}
|
||||||
|
@ -4766,6 +4772,7 @@ packages:
|
||||||
rollup-plugin-visualizer@5.13.1:
|
rollup-plugin-visualizer@5.13.1:
|
||||||
resolution: {integrity: sha512-vMg8i6BprL8aFm9DKvL2c8AwS8324EgymYQo9o6E26wgVvwMhsJxS37aNL6ZsU7X9iAcMYwdME7gItLfG5fwJg==}
|
resolution: {integrity: sha512-vMg8i6BprL8aFm9DKvL2c8AwS8324EgymYQo9o6E26wgVvwMhsJxS37aNL6ZsU7X9iAcMYwdME7gItLfG5fwJg==}
|
||||||
engines: {node: '>=18'}
|
engines: {node: '>=18'}
|
||||||
|
deprecated: Contains unintended breaking changes
|
||||||
hasBin: true
|
hasBin: true
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
rolldown: 1.x
|
rolldown: 1.x
|
||||||
|
@ -8168,6 +8175,8 @@ snapshots:
|
||||||
transitivePeerDependencies:
|
transitivePeerDependencies:
|
||||||
- supports-color
|
- supports-color
|
||||||
|
|
||||||
|
devalue@5.1.1: {}
|
||||||
|
|
||||||
diff@4.0.2: {}
|
diff@4.0.2: {}
|
||||||
|
|
||||||
dir-glob@3.0.1:
|
dir-glob@3.0.1:
|
||||||
|
|
Loading…
Reference in a new issue