Home / File/ plugin-utils.js — fastify Source File

plugin-utils.js — fastify Source File

Architecture documentation for plugin-utils.js, a javascript file in the fastify codebase.

Entity Profile

Relationship Graph

Source Code

'use strict'

const semver = require('semver')
const assert = require('node:assert')
const kRegisteredPlugins = Symbol.for('registered-plugin')
const {
  kTestInternals
} = require('./symbols.js')
const { exist, existReply, existRequest } = require('./decorate.js')
const {
  FST_ERR_PLUGIN_VERSION_MISMATCH,
  FST_ERR_PLUGIN_NOT_PRESENT_IN_INSTANCE,
  FST_ERR_PLUGIN_INVALID_ASYNC_HANDLER
} = require('./errors.js')

const rcRegex = /-(?:rc|pre|alpha).+$/u

function getMeta (fn) {
  return fn[Symbol.for('plugin-meta')]
}

function getPluginName (func) {
  const display = getDisplayName(func)
  if (display) {
    return display
  }

  // let's see if this is a file, and in that case use that
  // this is common for plugins
  const cache = require.cache
  // cache is undefined inside SEA
  if (cache) {
    const keys = Object.keys(cache)

    for (let i = 0; i < keys.length; i++) {
      const key = keys[i]
      if (cache[key].exports === func) {
        return key
      }
    }
  }

  // if not maybe it's a named function, so use that
  if (func.name) {
    return func.name
  }

  return null
}

function getFuncPreview (func) {
  // takes the first two lines of the function if nothing else works
  return func.toString().split('\n', 2).map(s => s.trim()).join(' -- ')
}

function getDisplayName (fn) {
  return fn[Symbol.for('fastify.display-name')]
}

function shouldSkipOverride (fn) {
// ... (110 more lines)

Domain

Subdomains

Frequently Asked Questions

What does plugin-utils.js do?
plugin-utils.js is a source file in the fastify codebase, written in javascript. It belongs to the CoreKernel domain, LifecycleManager subdomain.
What functions are defined in plugin-utils.js?
plugin-utils.js defines 12 function(s): _checkDecorators, checkDecorators, checkDependencies, checkPluginHealthiness, checkVersion, getDisplayName, getFuncPreview, getMeta, getPluginName, registerPlugin, and 2 more.
Where is plugin-utils.js in the architecture?
plugin-utils.js is located at lib/plugin-utils.js (domain: CoreKernel, subdomain: LifecycleManager, directory: lib).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free