{"version":3,"file":"verify-plugin.cjs","names":[],"sources":["../src/verify-plugin.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { resolve } from 'node:path';\n\nimport { PLUGIN_PREFIX } from '@verdaccio/core';\nimport { asyncLoadPlugin } from '@verdaccio/loaders';\nimport { logger, setup } from '@verdaccio/logger';\n\nimport { runDiagnostics } from './diagnostics';\nimport { getSanityCheck } from './sanity-checks';\nimport type { VerifyPluginOptions, VerifyResult } from './types';\n\nconst debug = buildDebug('verdaccio:plugin:verifier');\n\n/**\n * Verifies that a plugin can be loaded by Verdaccio.\n *\n * Uses `asyncLoadPlugin` from `@verdaccio/loaders` — the same loader\n * Verdaccio uses at startup — so the verification is identical to what\n * happens in production.\n *\n * Steps verified:\n * 1. Module resolution — can the plugin be found/required?\n * 2. Export validation — does it export a function or a class (default export)?\n * 3. Instantiation — can the plugin be instantiated with a config and options?\n * 4. Sanity check — does the instance implement the required methods for its category?\n *\n * When loading fails, detailed diagnostics are included in the result\n * to pinpoint exactly which step failed and why.\n */\nexport async function verifyPlugin(options: VerifyPluginOptions): Promise<VerifyResult> {\n  const {\n    pluginPath,\n    category,\n    pluginConfig = {},\n    sanityCheck: customSanityCheck,\n    prefix = PLUGIN_PREFIX,\n    pluginsFolder,\n    configPath,\n  } = options;\n\n  debug('verifying plugin %o for category %o', pluginPath, category);\n  debug('prefix: %o, pluginsFolder: %o', prefix, pluginsFolder);\n\n  await setup({});\n\n  const sanityCheck = customSanityCheck ?? getSanityCheck(category);\n  debug('using %s sanity check', customSanityCheck ? 'custom' : 'default');\n\n  const config: any = {\n    ...pluginConfig,\n  };\n\n  if (pluginsFolder) {\n    config.plugins = resolve(pluginsFolder);\n    debug('resolved plugins folder: %o', config.plugins);\n  }\n\n  if (configPath) {\n    config.configPath = configPath;\n    debug('config path: %o', config.configPath);\n  }\n\n  const pluginConfigs = { [pluginPath]: pluginConfig };\n  debug('plugin config: %o', pluginConfigs);\n\n  try {\n    const plugins = await asyncLoadPlugin(\n      pluginConfigs,\n      { config, logger },\n      sanityCheck,\n      false,\n      prefix,\n      category\n    );\n\n    debug('plugins loaded: %o', plugins.length);\n\n    if (plugins.length > 0) {\n      debug('verification succeeded for %o', pluginPath);\n      return {\n        success: true,\n        pluginName: pluginPath,\n        category,\n        pluginsLoaded: plugins.length,\n      };\n    }\n\n    debug('verification failed, running diagnostics for %o', pluginPath);\n    const diagnostics = await runDiagnostics(options);\n    const failedStep = diagnostics.find((d) => !d.pass);\n\n    return {\n      success: false,\n      pluginName: pluginPath,\n      category,\n      pluginsLoaded: 0,\n      error:\n        failedStep?.message ??\n        `Plugin \"${pluginPath}\" could not be loaded for category \"${category}\"`,\n      diagnostics,\n    };\n  } catch (err: any) {\n    debug('verification error for %o: %o', pluginPath, err.message);\n    const diagnostics = await runDiagnostics(options);\n\n    return {\n      success: false,\n      pluginName: pluginPath,\n      category,\n      pluginsLoaded: 0,\n      error: err.message,\n      diagnostics,\n    };\n  }\n}\n"],"mappings":";;;;;;;;;;AAWA,IAAM,WAAA,GAAA,MAAA,SAAmB,2BAA2B;;;;;;;;;;;;;;;;;AAkBpD,eAAsB,aAAa,SAAqD;CACtF,MAAM,EACJ,YACA,UACA,eAAe,CAAC,GAChB,aAAa,mBACb,SAAS,gBAAA,eACT,eACA,eACE;CAEJ,QAAM,uCAAuC,YAAY,QAAQ;CACjE,QAAM,iCAAiC,QAAQ,aAAa;CAE5D,OAAA,GAAA,kBAAA,OAAY,CAAC,CAAC;CAEd,MAAM,cAAc,qBAAqB,sBAAA,eAAe,QAAQ;CAChE,QAAM,yBAAyB,oBAAoB,WAAW,SAAS;CAEvE,MAAM,SAAc,EAClB,GAAG,aACL;CAEA,IAAI,eAAe;EACjB,OAAO,WAAA,GAAA,UAAA,SAAkB,aAAa;EACtC,QAAM,+BAA+B,OAAO,OAAO;CACrD;CAEA,IAAI,YAAY;EACd,OAAO,aAAa;EACpB,QAAM,mBAAmB,OAAO,UAAU;CAC5C;CAEA,MAAM,gBAAgB,GAAG,a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