Skip to content

Commit

Permalink
refactor(handlers): remove debug
Browse files Browse the repository at this point in the history
it was also broken
  • Loading branch information
pi0 committed Aug 8, 2022
1 parent 801bc28 commit 9c2f6ca
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 92 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@
"serve-static": "^1.15.0",
"source-map-support": "^0.5.21",
"std-env": "^3.1.1",
"table": "^6.8.0",
"ufo": "^0.8.5",
"unenv": "^0.5.2",
"unimport": "^0.6.5",
Expand Down
51 changes: 2 additions & 49 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 0 additions & 42 deletions src/rollup/plugins/handlers.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { hash } from 'ohash'
import { relative } from 'pathe'
import table from 'table'
import isPrimitive from 'is-primitive'
import { isDebug } from 'std-env'
import type { Nitro, NitroEventHandler } from '../../types'
import { virtual } from './virtual'

Expand All @@ -11,8 +7,6 @@ const unique = (arr: any[]) => Array.from(new Set(arr))
export function handlers (nitro: Nitro) {
const getImportId = (p: string, lazy?: boolean) => (lazy ? '_lazy_' : '_') + hash(p).slice(0, 6)

let lastDump = ''

return virtual({
'#internal/nitro/virtual/server-handlers': () => {
const handlers = [
Expand All @@ -26,16 +20,6 @@ export function handlers (nitro: Nitro) {
handlers.push({ route: '/**', lazy: true, handler: nitro.options.renderer })
}

if (isDebug) {
const dumped = dumpHandler(handlers)
if (dumped !== lastDump) {
lastDump = dumped
if (handlers.length) {
console.log(dumped)
}
}
}

// Imports take priority
const imports = unique(handlers.filter(h => !h.lazy).map(h => h.handler))

Expand All @@ -56,29 +40,3 @@ ${handlers.map(h => ` { route: '${h.route || ''}', handler: ${getImportId(h.han
}
}, nitro.vfs)
}

function dumpHandler (handler: NitroEventHandler[]) {
const data = handler.map(({ route, handler, ...props }) => {
return [
(route && route !== '/') ? route : '*',
relative(process.cwd(), handler as string),
dumpObject(props)
]
})
return table.table([
['Path', 'Handler', 'Options'],
...data
], {
singleLine: true,
border: table.getBorderCharacters('norc')
})
}

function dumpObject (obj: any) {
const items = []
for (const key in obj) {
const val = obj[key]
items.push(`${key}: ${isPrimitive(val) ? val : JSON.stringify(val)}`)
}
return items.join(', ')
}

0 comments on commit 9c2f6ca

Please sign in to comment.