@verdaccio/loaders 9.0.0-next-9.16 → 9.0.0-next-9.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-async-loader.js","names":[],"sources":["../src/plugin-async-loader.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { merge } from 'lodash-es';\nimport { lstat } from 'node:fs/promises';\nimport { dirname, isAbsolute, join, resolve } from 'node:path';\n\nimport type { pluginUtils } from '@verdaccio/core';\nimport { PLUGIN_PREFIX } from '@verdaccio/core';\n\nimport type { PluginType } from './utils';\nimport { isES6, isValid, tryLoadAsync } from './utils';\n\nconst debug = buildDebug('verdaccio:plugin:loader:async');\n\nasync function isDirectory(pathFolder: string) {\n const stat = await lstat(pathFolder);\n return stat.isDirectory();\n}\n\nfunction mergeConfig(appConfig: unknown, pluginConfig: unknown) {\n return merge({}, appConfig, pluginConfig);\n}\n\n// type Plugins<T> =\n// | pluginUtils.Auth<T>\n// | pluginUtils.Storage<T>\n// | pluginUtils.ExpressMiddleware<T, unknown, unknown>;\n\n/**\n * The plugin loader find recursively plugins, if one plugin fails is ignored and report the error to the logger.\n *\n * The loader follows the order:\n * - If the at the `config.yaml` file the `plugins: ./plugins` is defined\n * - If is absolute will use the provided path\n * - If is relative, will use the base path of the config file. eg: /root/config.yaml the plugins folder should be\n * hosted at /root/plugins\n * - The next step is find at the node_modules or global based on the `require` native algorithm.\n * - If the package is scoped eg: @scope/foo, try to load the package `@scope/foo`\n * - If the package is not scoped, will use the default prefix: verdaccio-foo (\"verdaccio-theme-\" prefix for theme ui plugins).\n * - If a custom prefix is provided, the verdaccio- is replaced by the config.server.pluginPrefix.\n *\n * The `sanityCheck` is the validation for the required methods to load the plugin, if the validation fails the plugin won't be loaded.\n * The `params` is an object that contains the global configuration and the logger.\n *\n * @param {*} pluginConfigs the custom plugin section\n * @param {*} pluginOptions a set of options to initialize the plugin\n * @param {*} sanityCheck callback that check the shape that should fulfill the plugin\n * @param {*} prefix by default is verdaccio but can be override with config.server.pluginPrefix\n * @param {*} pluginCategory the category of the plugin, eg: auth, storage, middleware\n * @return {Array} list of plugins\n */\nexport async function asyncLoadPlugin<T extends pluginUtils.Plugin<T>>(\n pluginConfigs: any = {},\n pluginOptions: pluginUtils.PluginOptions,\n sanityCheck: (plugin: PluginType<T>) => boolean,\n legacyMergeConfigs: boolean = false,\n prefix: string = PLUGIN_PREFIX,\n pluginCategory: string = 'unknown'\n): Promise<PluginType<T>[]> {\n const logger = pluginOptions?.logger;\n const pluginsIds = Object.keys(pluginConfigs || {});\n const { config } = pluginOptions;\n const plugins: PluginType<T>[] = [];\n for (const pluginId of pluginsIds) {\n debug('>>> looking for plugin %o', pluginId);\n\n const isScoped: boolean = pluginId.startsWith('@') && pluginId.includes('/');\n debug('is scoped plugin: %s', isScoped);\n const pluginName = isScoped ? pluginId : `${prefix}-${pluginId}`;\n debug('plugin package name %s', pluginName);\n\n // Try to load the plugin from the config.plugins path\n if (typeof config.plugins === 'string') {\n let pluginsPath = config.plugins;\n debug('plugin path %s', pluginsPath);\n if (!isAbsolute(pluginsPath)) {\n if (typeof config.config_path === 'string' && !config.configPath) {\n logger.error(\n 'configPath is missing and the legacy config.config_path is not available for loading plugins'\n );\n }\n\n if (!config.configPath) {\n logger.error('config path property is required for loading plugins');\n continue;\n }\n pluginsPath = resolve(join(dirname(config.configPath), pluginsPath));\n }\n logger.debug({ path: pluginsPath }, 'plugins folder defined, loading plugins from @{path} ');\n // throws if is not a directory\n try {\n await isDirectory(pluginsPath);\n const pluginDir = pluginsPath;\n const externalFilePlugin = resolve(pluginDir, pluginName);\n let plugin = await tryLoadAsync<T>(externalFilePlugin, (a: any, b: any) => {\n logger.error(a, b);\n });\n debug('external plugin %o', plugin);\n if (plugin && isValid(plugin)) {\n plugin = executePlugin(\n plugin,\n pluginConfigs[pluginId],\n pluginOptions,\n legacyMergeConfigs\n );\n if (!sanityCheck(plugin)) {\n logger.error(\n { content: externalFilePlugin },\n \"@{content} doesn't look like a valid plugin\"\n );\n continue;\n }\n debug('>>> plugin is running and passed sanity check');\n plugins.push(plugin);\n logger.info(\n { pluginName, pluginCategory },\n 'plugin @{pluginName} successfully loaded (@{pluginCategory})'\n );\n continue;\n }\n } catch (err: any) {\n logger.warn(\n { err: err.message, pluginsPath, pluginName },\n '@{err} on loading plugins at @{pluginsPath} for @{pluginName}'\n );\n }\n }\n\n // Try to load the plugin from the node_modules or global based on the `require` native algorithm\n if (typeof pluginId === 'string') {\n let plugin = await tryLoadAsync<T>(pluginName, (a: any, b: any) => {\n logger.error(a, b);\n });\n if (plugin && isValid(plugin)) {\n plugin = executePlugin(plugin, pluginConfigs[pluginId], pluginOptions, legacyMergeConfigs);\n if (!sanityCheck(plugin)) {\n logger.error({ pluginName }, \"@{pluginName} doesn't look like a valid plugin\");\n continue;\n }\n debug('>>> plugin is running and passed sanity check');\n plugins.push(plugin);\n logger.info(\n { pluginName, pluginCategory },\n 'plugin @{pluginName} successfully loaded (@{pluginCategory})'\n );\n continue;\n } else {\n logger.error(\n { pluginName },\n 'package not found, try to install @{pluginName} with a package manager'\n );\n continue;\n }\n }\n }\n debug('%o plugins found: %o', pluginCategory, plugins.length);\n return plugins;\n}\n\nexport function executePlugin<T>(\n plugin: PluginType<T>,\n pluginConfig: unknown,\n pluginOptions: pluginUtils.PluginOptions,\n legacyMergeConfigs: boolean = false\n): PluginType<T> {\n // this is a legacy support for plugins that are not using the new API\n if (legacyMergeConfigs) {\n debug('>>> plugin merge config enabled');\n const originalConfig = pluginOptions.config;\n pluginConfig = mergeConfig(originalConfig, pluginConfig);\n }\n if (isES6(plugin)) {\n debug('plugin is ES6');\n // @ts-expect-error no relevant for the code\n\n return new plugin.default(pluginConfig, pluginOptions) as Plugin;\n } else {\n debug('plugin is commonJS');\n // @ts-expect-error improve this type\n return plugin(pluginConfig, pluginOptions) as PluginType<T>;\n }\n}\n"],"mappings":";;;;;;;;;AAWA,IAAM,WAAA,GAAA,MAAA,SAAmB
|
|
1
|
+
{"version":3,"file":"plugin-async-loader.js","names":[],"sources":["../src/plugin-async-loader.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { merge } from 'lodash-es';\nimport { lstat } from 'node:fs/promises';\nimport { dirname, isAbsolute, join, resolve } from 'node:path';\n\nimport type { pluginUtils } from '@verdaccio/core';\nimport { PLUGIN_PREFIX } from '@verdaccio/core';\n\nimport type { PluginType } from './utils';\nimport { isES6, isValid, tryLoadAsync } from './utils';\n\nconst debug = buildDebug('verdaccio:plugin:loader:async');\n\nasync function isDirectory(pathFolder: string) {\n const stat = await lstat(pathFolder);\n return stat.isDirectory();\n}\n\nfunction mergeConfig(appConfig: unknown, pluginConfig: unknown) {\n return merge({}, appConfig, pluginConfig);\n}\n\n// type Plugins<T> =\n// | pluginUtils.Auth<T>\n// | pluginUtils.Storage<T>\n// | pluginUtils.ExpressMiddleware<T, unknown, unknown>;\n\n/**\n * The plugin loader find recursively plugins, if one plugin fails is ignored and report the error to the logger.\n *\n * The loader follows the order:\n * - If the at the `config.yaml` file the `plugins: ./plugins` is defined\n * - If is absolute will use the provided path\n * - If is relative, will use the base path of the config file. eg: /root/config.yaml the plugins folder should be\n * hosted at /root/plugins\n * - The next step is find at the node_modules or global based on the `require` native algorithm.\n * - If the package is scoped eg: @scope/foo, try to load the package `@scope/foo`\n * - If the package is not scoped, will use the default prefix: verdaccio-foo (\"verdaccio-theme-\" prefix for theme ui plugins).\n * - If a custom prefix is provided, the verdaccio- is replaced by the config.server.pluginPrefix.\n *\n * The `sanityCheck` is the validation for the required methods to load the plugin, if the validation fails the plugin won't be loaded.\n * The `params` is an object that contains the global configuration and the logger.\n *\n * @param {*} pluginConfigs the custom plugin section\n * @param {*} pluginOptions a set of options to initialize the plugin\n * @param {*} sanityCheck callback that check the shape that should fulfill the plugin\n * @param {*} prefix by default is verdaccio but can be override with config.server.pluginPrefix\n * @param {*} pluginCategory the category of the plugin, eg: auth, storage, middleware\n * @return {Array} list of plugins\n */\nexport async function asyncLoadPlugin<T extends pluginUtils.Plugin<T>>(\n pluginConfigs: any = {},\n pluginOptions: pluginUtils.PluginOptions,\n sanityCheck: (plugin: PluginType<T>) => boolean,\n legacyMergeConfigs: boolean = false,\n prefix: string = PLUGIN_PREFIX,\n pluginCategory: string = 'unknown'\n): Promise<PluginType<T>[]> {\n const logger = pluginOptions?.logger;\n const pluginsIds = Object.keys(pluginConfigs || {});\n const { config } = pluginOptions;\n const plugins: PluginType<T>[] = [];\n for (const pluginId of pluginsIds) {\n debug('>>> looking for plugin %o', pluginId);\n\n const isScoped: boolean = pluginId.startsWith('@') && pluginId.includes('/');\n debug('is scoped plugin: %s', isScoped);\n const pluginName = isScoped ? pluginId : `${prefix}-${pluginId}`;\n debug('plugin package name %s', pluginName);\n\n // Try to load the plugin from the config.plugins path\n if (typeof config.plugins === 'string') {\n let pluginsPath = config.plugins;\n debug('plugin path %s', pluginsPath);\n if (!isAbsolute(pluginsPath)) {\n if (typeof config.config_path === 'string' && !config.configPath) {\n logger.error(\n 'configPath is missing and the legacy config.config_path is not available for loading plugins'\n );\n }\n\n if (!config.configPath) {\n logger.error('config path property is required for loading plugins');\n continue;\n }\n pluginsPath = resolve(join(dirname(config.configPath), pluginsPath));\n }\n logger.debug({ path: pluginsPath }, 'plugins folder defined, loading plugins from @{path} ');\n // throws if is not a directory\n try {\n await isDirectory(pluginsPath);\n const pluginDir = pluginsPath;\n const externalFilePlugin = resolve(pluginDir, pluginName);\n let plugin = await tryLoadAsync<T>(externalFilePlugin, (a: any, b: any) => {\n logger.error(a, b);\n });\n debug('external plugin %o', plugin);\n if (plugin && isValid(plugin)) {\n plugin = executePlugin(\n plugin,\n pluginConfigs[pluginId],\n pluginOptions,\n legacyMergeConfigs\n );\n if (!sanityCheck(plugin)) {\n logger.error(\n { content: externalFilePlugin },\n \"@{content} doesn't look like a valid plugin\"\n );\n continue;\n }\n debug('>>> plugin is running and passed sanity check');\n plugins.push(plugin);\n logger.info(\n { pluginName, pluginCategory },\n 'plugin @{pluginName} successfully loaded (@{pluginCategory})'\n );\n continue;\n }\n } catch (err: any) {\n logger.warn(\n { err: err.message, pluginsPath, pluginName },\n '@{err} on loading plugins at @{pluginsPath} for @{pluginName}'\n );\n }\n }\n\n // Try to load the plugin from the node_modules or global based on the `require` native algorithm\n if (typeof pluginId === 'string') {\n let plugin = await tryLoadAsync<T>(pluginName, (a: any, b: any) => {\n logger.error(a, b);\n });\n if (plugin && isValid(plugin)) {\n plugin = executePlugin(plugin, pluginConfigs[pluginId], pluginOptions, legacyMergeConfigs);\n if (!sanityCheck(plugin)) {\n logger.error({ pluginName }, \"@{pluginName} doesn't look like a valid plugin\");\n continue;\n }\n debug('>>> plugin is running and passed sanity check');\n plugins.push(plugin);\n logger.info(\n { pluginName, pluginCategory },\n 'plugin @{pluginName} successfully loaded (@{pluginCategory})'\n );\n continue;\n } else {\n logger.error(\n { pluginName },\n 'package not found, try to install @{pluginName} with a package manager'\n );\n continue;\n }\n }\n }\n debug('%o plugins found: %o', pluginCategory, plugins.length);\n return plugins;\n}\n\nexport function executePlugin<T>(\n plugin: PluginType<T>,\n pluginConfig: unknown,\n pluginOptions: pluginUtils.PluginOptions,\n legacyMergeConfigs: boolean = false\n): PluginType<T> {\n // this is a legacy support for plugins that are not using the new API\n if (legacyMergeConfigs) {\n debug('>>> plugin merge config enabled');\n const originalConfig = pluginOptions.config;\n pluginConfig = mergeConfig(originalConfig, pluginConfig);\n }\n if (isES6(plugin)) {\n debug('plugin is ES6');\n // @ts-expect-error no relevant for the code\n\n return new plugin.default(pluginConfig, pluginOptions) as Plugin;\n } else {\n debug('plugin is commonJS');\n // @ts-expect-error improve this type\n return plugin(pluginConfig, pluginOptions) as PluginType<T>;\n }\n}\n"],"mappings":";;;;;;;;;AAWA,IAAM,WAAA,GAAA,MAAA,SAAmB,+BAA+B;AAExD,eAAe,YAAY,YAAoB;CAE7C,QAAO,OAAA,GAAA,iBAAA,O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O,cAAc,aAAa;CAC3C;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-async-loader.mjs","names":[],"sources":["../src/plugin-async-loader.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { merge } from 'lodash-es';\nimport { lstat } from 'node:fs/promises';\nimport { dirname, isAbsolute, join, resolve } from 'node:path';\n\nimport type { pluginUtils } from '@verdaccio/core';\nimport { PLUGIN_PREFIX } from '@verdaccio/core';\n\nimport type { PluginType } from './utils';\nimport { isES6, isValid, tryLoadAsync } from './utils';\n\nconst debug = buildDebug('verdaccio:plugin:loader:async');\n\nasync function isDirectory(pathFolder: string) {\n const stat = await lstat(pathFolder);\n return stat.isDirectory();\n}\n\nfunction mergeConfig(appConfig: unknown, pluginConfig: unknown) {\n return merge({}, appConfig, pluginConfig);\n}\n\n// type Plugins<T> =\n// | pluginUtils.Auth<T>\n// | pluginUtils.Storage<T>\n// | pluginUtils.ExpressMiddleware<T, unknown, unknown>;\n\n/**\n * The plugin loader find recursively plugins, if one plugin fails is ignored and report the error to the logger.\n *\n * The loader follows the order:\n * - If the at the `config.yaml` file the `plugins: ./plugins` is defined\n * - If is absolute will use the provided path\n * - If is relative, will use the base path of the config file. eg: /root/config.yaml the plugins folder should be\n * hosted at /root/plugins\n * - The next step is find at the node_modules or global based on the `require` native algorithm.\n * - If the package is scoped eg: @scope/foo, try to load the package `@scope/foo`\n * - If the package is not scoped, will use the default prefix: verdaccio-foo (\"verdaccio-theme-\" prefix for theme ui plugins).\n * - If a custom prefix is provided, the verdaccio- is replaced by the config.server.pluginPrefix.\n *\n * The `sanityCheck` is the validation for the required methods to load the plugin, if the validation fails the plugin won't be loaded.\n * The `params` is an object that contains the global configuration and the logger.\n *\n * @param {*} pluginConfigs the custom plugin section\n * @param {*} pluginOptions a set of options to initialize the plugin\n * @param {*} sanityCheck callback that check the shape that should fulfill the plugin\n * @param {*} prefix by default is verdaccio but can be override with config.server.pluginPrefix\n * @param {*} pluginCategory the category of the plugin, eg: auth, storage, middleware\n * @return {Array} list of plugins\n */\nexport async function asyncLoadPlugin<T extends pluginUtils.Plugin<T>>(\n pluginConfigs: any = {},\n pluginOptions: pluginUtils.PluginOptions,\n sanityCheck: (plugin: PluginType<T>) => boolean,\n legacyMergeConfigs: boolean = false,\n prefix: string = PLUGIN_PREFIX,\n pluginCategory: string = 'unknown'\n): Promise<PluginType<T>[]> {\n const logger = pluginOptions?.logger;\n const pluginsIds = Object.keys(pluginConfigs || {});\n const { config } = pluginOptions;\n const plugins: PluginType<T>[] = [];\n for (const pluginId of pluginsIds) {\n debug('>>> looking for plugin %o', pluginId);\n\n const isScoped: boolean = pluginId.startsWith('@') && pluginId.includes('/');\n debug('is scoped plugin: %s', isScoped);\n const pluginName = isScoped ? pluginId : `${prefix}-${pluginId}`;\n debug('plugin package name %s', pluginName);\n\n // Try to load the plugin from the config.plugins path\n if (typeof config.plugins === 'string') {\n let pluginsPath = config.plugins;\n debug('plugin path %s', pluginsPath);\n if (!isAbsolute(pluginsPath)) {\n if (typeof config.config_path === 'string' && !config.configPath) {\n logger.error(\n 'configPath is missing and the legacy config.config_path is not available for loading plugins'\n );\n }\n\n if (!config.configPath) {\n logger.error('config path property is required for loading plugins');\n continue;\n }\n pluginsPath = resolve(join(dirname(config.configPath), pluginsPath));\n }\n logger.debug({ path: pluginsPath }, 'plugins folder defined, loading plugins from @{path} ');\n // throws if is not a directory\n try {\n await isDirectory(pluginsPath);\n const pluginDir = pluginsPath;\n const externalFilePlugin = resolve(pluginDir, pluginName);\n let plugin = await tryLoadAsync<T>(externalFilePlugin, (a: any, b: any) => {\n logger.error(a, b);\n });\n debug('external plugin %o', plugin);\n if (plugin && isValid(plugin)) {\n plugin = executePlugin(\n plugin,\n pluginConfigs[pluginId],\n pluginOptions,\n legacyMergeConfigs\n );\n if (!sanityCheck(plugin)) {\n logger.error(\n { content: externalFilePlugin },\n \"@{content} doesn't look like a valid plugin\"\n );\n continue;\n }\n debug('>>> plugin is running and passed sanity check');\n plugins.push(plugin);\n logger.info(\n { pluginName, pluginCategory },\n 'plugin @{pluginName} successfully loaded (@{pluginCategory})'\n );\n continue;\n }\n } catch (err: any) {\n logger.warn(\n { err: err.message, pluginsPath, pluginName },\n '@{err} on loading plugins at @{pluginsPath} for @{pluginName}'\n );\n }\n }\n\n // Try to load the plugin from the node_modules or global based on the `require` native algorithm\n if (typeof pluginId === 'string') {\n let plugin = await tryLoadAsync<T>(pluginName, (a: any, b: any) => {\n logger.error(a, b);\n });\n if (plugin && isValid(plugin)) {\n plugin = executePlugin(plugin, pluginConfigs[pluginId], pluginOptions, legacyMergeConfigs);\n if (!sanityCheck(plugin)) {\n logger.error({ pluginName }, \"@{pluginName} doesn't look like a valid plugin\");\n continue;\n }\n debug('>>> plugin is running and passed sanity check');\n plugins.push(plugin);\n logger.info(\n { pluginName, pluginCategory },\n 'plugin @{pluginName} successfully loaded (@{pluginCategory})'\n );\n continue;\n } else {\n logger.error(\n { pluginName },\n 'package not found, try to install @{pluginName} with a package manager'\n );\n continue;\n }\n }\n }\n debug('%o plugins found: %o', pluginCategory, plugins.length);\n return plugins;\n}\n\nexport function executePlugin<T>(\n plugin: PluginType<T>,\n pluginConfig: unknown,\n pluginOptions: pluginUtils.PluginOptions,\n legacyMergeConfigs: boolean = false\n): PluginType<T> {\n // this is a legacy support for plugins that are not using the new API\n if (legacyMergeConfigs) {\n debug('>>> plugin merge config enabled');\n const originalConfig = pluginOptions.config;\n pluginConfig = mergeConfig(originalConfig, pluginConfig);\n }\n if (isES6(plugin)) {\n debug('plugin is ES6');\n // @ts-expect-error no relevant for the code\n\n return new plugin.default(pluginConfig, pluginOptions) as Plugin;\n } else {\n debug('plugin is commonJS');\n // @ts-expect-error improve this type\n return plugin(pluginConfig, pluginOptions) as PluginType<T>;\n }\n}\n"],"mappings":";;;;;;;AAWA,IAAM,QAAQ,WAAW
|
|
1
|
+
{"version":3,"file":"plugin-async-loader.mjs","names":[],"sources":["../src/plugin-async-loader.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { merge } from 'lodash-es';\nimport { lstat } from 'node:fs/promises';\nimport { dirname, isAbsolute, join, resolve } from 'node:path';\n\nimport type { pluginUtils } from '@verdaccio/core';\nimport { PLUGIN_PREFIX } from '@verdaccio/core';\n\nimport type { PluginType } from './utils';\nimport { isES6, isValid, tryLoadAsync } from './utils';\n\nconst debug = buildDebug('verdaccio:plugin:loader:async');\n\nasync function isDirectory(pathFolder: string) {\n const stat = await lstat(pathFolder);\n return stat.isDirectory();\n}\n\nfunction mergeConfig(appConfig: unknown, pluginConfig: unknown) {\n return merge({}, appConfig, pluginConfig);\n}\n\n// type Plugins<T> =\n// | pluginUtils.Auth<T>\n// | pluginUtils.Storage<T>\n// | pluginUtils.ExpressMiddleware<T, unknown, unknown>;\n\n/**\n * The plugin loader find recursively plugins, if one plugin fails is ignored and report the error to the logger.\n *\n * The loader follows the order:\n * - If the at the `config.yaml` file the `plugins: ./plugins` is defined\n * - If is absolute will use the provided path\n * - If is relative, will use the base path of the config file. eg: /root/config.yaml the plugins folder should be\n * hosted at /root/plugins\n * - The next step is find at the node_modules or global based on the `require` native algorithm.\n * - If the package is scoped eg: @scope/foo, try to load the package `@scope/foo`\n * - If the package is not scoped, will use the default prefix: verdaccio-foo (\"verdaccio-theme-\" prefix for theme ui plugins).\n * - If a custom prefix is provided, the verdaccio- is replaced by the config.server.pluginPrefix.\n *\n * The `sanityCheck` is the validation for the required methods to load the plugin, if the validation fails the plugin won't be loaded.\n * The `params` is an object that contains the global configuration and the logger.\n *\n * @param {*} pluginConfigs the custom plugin section\n * @param {*} pluginOptions a set of options to initialize the plugin\n * @param {*} sanityCheck callback that check the shape that should fulfill the plugin\n * @param {*} prefix by default is verdaccio but can be override with config.server.pluginPrefix\n * @param {*} pluginCategory the category of the plugin, eg: auth, storage, middleware\n * @return {Array} list of plugins\n */\nexport async function asyncLoadPlugin<T extends pluginUtils.Plugin<T>>(\n pluginConfigs: any = {},\n pluginOptions: pluginUtils.PluginOptions,\n sanityCheck: (plugin: PluginType<T>) => boolean,\n legacyMergeConfigs: boolean = false,\n prefix: string = PLUGIN_PREFIX,\n pluginCategory: string = 'unknown'\n): Promise<PluginType<T>[]> {\n const logger = pluginOptions?.logger;\n const pluginsIds = Object.keys(pluginConfigs || {});\n const { config } = pluginOptions;\n const plugins: PluginType<T>[] = [];\n for (const pluginId of pluginsIds) {\n debug('>>> looking for plugin %o', pluginId);\n\n const isScoped: boolean = pluginId.startsWith('@') && pluginId.includes('/');\n debug('is scoped plugin: %s', isScoped);\n const pluginName = isScoped ? pluginId : `${prefix}-${pluginId}`;\n debug('plugin package name %s', pluginName);\n\n // Try to load the plugin from the config.plugins path\n if (typeof config.plugins === 'string') {\n let pluginsPath = config.plugins;\n debug('plugin path %s', pluginsPath);\n if (!isAbsolute(pluginsPath)) {\n if (typeof config.config_path === 'string' && !config.configPath) {\n logger.error(\n 'configPath is missing and the legacy config.config_path is not available for loading plugins'\n );\n }\n\n if (!config.configPath) {\n logger.error('config path property is required for loading plugins');\n continue;\n }\n pluginsPath = resolve(join(dirname(config.configPath), pluginsPath));\n }\n logger.debug({ path: pluginsPath }, 'plugins folder defined, loading plugins from @{path} ');\n // throws if is not a directory\n try {\n await isDirectory(pluginsPath);\n const pluginDir = pluginsPath;\n const externalFilePlugin = resolve(pluginDir, pluginName);\n let plugin = await tryLoadAsync<T>(externalFilePlugin, (a: any, b: any) => {\n logger.error(a, b);\n });\n debug('external plugin %o', plugin);\n if (plugin && isValid(plugin)) {\n plugin = executePlugin(\n plugin,\n pluginConfigs[pluginId],\n pluginOptions,\n legacyMergeConfigs\n );\n if (!sanityCheck(plugin)) {\n logger.error(\n { content: externalFilePlugin },\n \"@{content} doesn't look like a valid plugin\"\n );\n continue;\n }\n debug('>>> plugin is running and passed sanity check');\n plugins.push(plugin);\n logger.info(\n { pluginName, pluginCategory },\n 'plugin @{pluginName} successfully loaded (@{pluginCategory})'\n );\n continue;\n }\n } catch (err: any) {\n logger.warn(\n { err: err.message, pluginsPath, pluginName },\n '@{err} on loading plugins at @{pluginsPath} for @{pluginName}'\n );\n }\n }\n\n // Try to load the plugin from the node_modules or global based on the `require` native algorithm\n if (typeof pluginId === 'string') {\n let plugin = await tryLoadAsync<T>(pluginName, (a: any, b: any) => {\n logger.error(a, b);\n });\n if (plugin && isValid(plugin)) {\n plugin = executePlugin(plugin, pluginConfigs[pluginId], pluginOptions, legacyMergeConfigs);\n if (!sanityCheck(plugin)) {\n logger.error({ pluginName }, \"@{pluginName} doesn't look like a valid plugin\");\n continue;\n }\n debug('>>> plugin is running and passed sanity check');\n plugins.push(plugin);\n logger.info(\n { pluginName, pluginCategory },\n 'plugin @{pluginName} successfully loaded (@{pluginCategory})'\n );\n continue;\n } else {\n logger.error(\n { pluginName },\n 'package not found, try to install @{pluginName} with a package manager'\n );\n continue;\n }\n }\n }\n debug('%o plugins found: %o', pluginCategory, plugins.length);\n return plugins;\n}\n\nexport function executePlugin<T>(\n plugin: PluginType<T>,\n pluginConfig: unknown,\n pluginOptions: pluginUtils.PluginOptions,\n legacyMergeConfigs: boolean = false\n): PluginType<T> {\n // this is a legacy support for plugins that are not using the new API\n if (legacyMergeConfigs) {\n debug('>>> plugin merge config enabled');\n const originalConfig = pluginOptions.config;\n pluginConfig = mergeConfig(originalConfig, pluginConfig);\n }\n if (isES6(plugin)) {\n debug('plugin is ES6');\n // @ts-expect-error no relevant for the code\n\n return new plugin.default(pluginConfig, pluginOptions) as Plugin;\n } else {\n debug('plugin is commonJS');\n // @ts-expect-error improve this type\n return plugin(pluginConfig, pluginOptions) as PluginType<T>;\n }\n}\n"],"mappings":";;;;;;;AAWA,IAAM,QAAQ,WAAW,+BAA+B;AAExD,eAAe,YAAY,YAAoB;CAE7C,QAAO,MADY,MAAM,UAAU,GACvB,YAAY;AAC1B;AAEA,SAAS,YAAY,WAAoB,cAAuB;CAC9D,OAAO,MAAM,CAAC,GAAG,WAAW,YAAY;AAC1C;;;;;;;;;;;;;;;;;;;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QAAQ,KAAK,MAAM;KACnB,OAAO,KACL;MAAE;MAAY;KAAe,GAC7B,8DACF;KACA;IACF;GACF,SAAS,KAAU;IACjB,OAAO,KACL;KAAE,KAAK,IAAI;KAAS;KAAa;IAAW,GAC5C,+DACF;GACF;EACF;EAGA,IAAI,OAAO,aAAa,UAAU;GAChC,IAAI,SAAS,MAAM,aAAgB,aAAa,GAAQ,MAAW;IACjE,OAAO,MAAM,GAAG,CAAC;GACnB,CAAC;GACD,IAAI,UAAU,QAAQ,MAAM,GAAG;IAC7B,SAAS,cAAc,QAAQ,cAAc,WAAW,eAAe,kBAAkB;IACzF,IAAI,CAAC,YAAY,MAAM,GAAG;KACxB,OAAO,MAAM,EAAE,WAAW,GAAG,gDAAgD;KAC7E;IACF;IACA,MAAM,+CAA+C;IACrD,QAAQ,KAAK,MAAM;IACnB,OAAO,KACL;KAAE;KAAY;IAAe,GAC7B,8DACF;IACA;GACF,OAAO;IACL,OAAO,MACL,EAAE,WAAW,GACb,wEACF;IACA;GACF;EACF;CACF;CACA,MAAM,wBAAwB,gBAAgB,QAAQ,MAAM;CAC5D,OAAO;AACT;AAEA,SAAgB,cACd,QACA,cACA,eACA,qBAA8B,OACf;CAEf,IAAI,oBAAoB;EACtB,MAAM,iCAAiC;EACvC,MAAM,iBAAiB,cAAc;EACrC,eAAe,YAAY,gBAAgB,YAAY;CACzD;CACA,IAAI,MAAM,MAAM,GAAG;EACjB,MAAM,eAAe;EAGrB,OAAO,IAAI,OAAO,QAAQ,cAAc,aAAa;CACvD,OAAO;EACL,MAAM,oBAAoB;EAE1B,OAAO,OAAO,cAAc,aAAa;CAC3C;AACF"}
|
package/build/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":[],"sources":["../src/utils.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { existsSync, readFileSync } from 'node:fs';\nimport { join } from 'node:path';\nimport { pathToFileURL } from 'node:url';\n\nimport type { pluginUtils } from '@verdaccio/core';\n\nconst debug = buildDebug('verdaccio:plugin:loader:utils');\nconst MODULE_NOT_FOUND = 'MODULE_NOT_FOUND';\nconst ERR_REQUIRE_ESM = 'ERR_REQUIRE_ESM';\n\nexport type PluginType<T> = T extends pluginUtils.Plugin<T> ? T : never;\n\nexport function isValid<T>(plugin: PluginType<T>): boolean {\n // @ts-expect-error default not relevant\n return typeof plugin === 'function' || typeof plugin.default === 'function';\n}\n\nexport function isES6<T>(plugin: PluginType<T>): boolean {\n return Object.keys(plugin).includes('default');\n}\n\n/**\n * Requires a module.\n * @param {*} path the module's path\n * @return {Object}\n */\nexport function tryLoad<T>(path: string, onError: any): PluginType<T> | null {\n try {\n debug('loading plugin %s', path);\n return require(path) as PluginType<T>;\n } catch (err: any) {\n if (err.code === MODULE_NOT_FOUND) {\n debug('\"require\" failed for plugin %s', path);\n // If loading fails, because a dependency is missing,\n // we want to log the error message and require stack\n // to see where the missing dependency is.\n const message = err.message.replace(/\\\\\\\\/g, '\\\\').split('\\n');\n if (!message[0].includes(path)) {\n debug('%o', message[0]); // error message\n debug('%o', message.slice(1)); // stack trace\n }\n return null;\n }\n if (err.code === ERR_REQUIRE_ESM) {\n debug('\"require\" failed for ESM plugin %s, will try dynamic import', path);\n return null;\n }\n onError({ err: err.msg }, 'error loading plugin @{err}');\n throw err;\n }\n}\n\n/**\n * Resolve the entry point for a directory-based plugin.\n * dynamic import() does not support directory imports, so we need to\n * find the actual file to import (via package.json \"main\"/\"exports\" or index.js).\n */\nfunction resolveEntryPoint(dirPath: string): string {\n const pkgPath = join(dirPath, 'package.json');\n if (existsSync(pkgPath)) {\n try {\n const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));\n // Check exports first, then module, then main\n if (pkg.exports) {\n const dotExport = pkg.exports['.'];\n if (typeof dotExport === 'string') {\n return join(dirPath, dotExport);\n }\n if (dotExport?.import?.default) {\n return join(dirPath, dotExport.import.default);\n }\n if (dotExport?.import) {\n return join(dirPath, typeof dotExport.import === 'string' ? dotExport.import : '');\n }\n if (dotExport?.default) {\n return join(dirPath, dotExport.default);\n }\n }\n if (pkg.module) {\n return join(dirPath, pkg.module);\n }\n if (pkg.main) {\n return join(dirPath, pkg.main);\n }\n } catch {\n // fall through to index.js\n }\n }\n return join(dirPath, 'index.js');\n}\n\n/**\n * Dynamically imports a module (supports ESM plugins).\n * Falls back from require() to import() for ESM compatibility.\n * @param {*} path the module's path\n * @return {Object}\n */\nexport async function tryLoadAsync<T>(path: string, onError: any): Promise<PluginType<T> | null> {\n // Try require first (handles CJS and will be fast)\n try {\n const cjsResult = tryLoad<T>(path, onError);\n if (cjsResult !== null) {\n return cjsResult;\n }\n } catch (err: any) {\n // require() may throw for various reasons (ESM module, bundler shim, etc.)\n // — always fall through to dynamic import()\n debug('require() threw for %s: %s — falling back to import()', path, err.message);\n }\n\n // Fallback to dynamic import for ESM modules\n try {\n // import() doesn't support directory imports — resolve the entry point\n let importPath = path;\n if (existsSync(path) && existsSync(join(path, 'package.json'))) {\n importPath = resolveEntryPoint(path);\n debug('resolved ESM entry point: %s', importPath);\n }\n\n // Convert to file URL for import() compatibility\n const importUrl = importPath.startsWith('/') ? pathToFileURL(importPath).href : importPath;\n debug('trying dynamic import for plugin %s', importUrl);\n const module = await import(importUrl);\n debug('dynamic import succeeded for plugin %s', importUrl);\n return module as PluginType<T>;\n } catch (err: any) {\n if (err.code === MODULE_NOT_FOUND || err.code === 'ERR_MODULE_NOT_FOUND') {\n debug('\"import\" failed for plugin %s', path);\n return null;\n }\n onError({ err: err.message }, 'error loading plugin @{err}');\n throw err;\n }\n}\n"],"mappings":";;;;;;;AAOA,IAAM,WAAA,GAAA,MAAA,SAAmB
|
|
1
|
+
{"version":3,"file":"utils.js","names":[],"sources":["../src/utils.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { existsSync, readFileSync } from 'node:fs';\nimport { join } from 'node:path';\nimport { pathToFileURL } from 'node:url';\n\nimport type { pluginUtils } from '@verdaccio/core';\n\nconst debug = buildDebug('verdaccio:plugin:loader:utils');\nconst MODULE_NOT_FOUND = 'MODULE_NOT_FOUND';\nconst ERR_REQUIRE_ESM = 'ERR_REQUIRE_ESM';\n\nexport type PluginType<T> = T extends pluginUtils.Plugin<T> ? T : never;\n\nexport function isValid<T>(plugin: PluginType<T>): boolean {\n // @ts-expect-error default not relevant\n return typeof plugin === 'function' || typeof plugin.default === 'function';\n}\n\nexport function isES6<T>(plugin: PluginType<T>): boolean {\n return Object.keys(plugin).includes('default');\n}\n\n/**\n * Requires a module.\n * @param {*} path the module's path\n * @return {Object}\n */\nexport function tryLoad<T>(path: string, onError: any): PluginType<T> | null {\n try {\n debug('loading plugin %s', path);\n return require(path) as PluginType<T>;\n } catch (err: any) {\n if (err.code === MODULE_NOT_FOUND) {\n debug('\"require\" failed for plugin %s', path);\n // If loading fails, because a dependency is missing,\n // we want to log the error message and require stack\n // to see where the missing dependency is.\n const message = err.message.replace(/\\\\\\\\/g, '\\\\').split('\\n');\n if (!message[0].includes(path)) {\n debug('%o', message[0]); // error message\n debug('%o', message.slice(1)); // stack trace\n }\n return null;\n }\n if (err.code === ERR_REQUIRE_ESM) {\n debug('\"require\" failed for ESM plugin %s, will try dynamic import', path);\n return null;\n }\n onError({ err: err.msg }, 'error loading plugin @{err}');\n throw err;\n }\n}\n\n/**\n * Resolve the entry point for a directory-based plugin.\n * dynamic import() does not support directory imports, so we need to\n * find the actual file to import (via package.json \"main\"/\"exports\" or index.js).\n */\nfunction resolveEntryPoint(dirPath: string): string {\n const pkgPath = join(dirPath, 'package.json');\n if (existsSync(pkgPath)) {\n try {\n const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));\n // Check exports first, then module, then main\n if (pkg.exports) {\n const dotExport = pkg.exports['.'];\n if (typeof dotExport === 'string') {\n return join(dirPath, dotExport);\n }\n if (dotExport?.import?.default) {\n return join(dirPath, dotExport.import.default);\n }\n if (dotExport?.import) {\n return join(dirPath, typeof dotExport.import === 'string' ? dotExport.import : '');\n }\n if (dotExport?.default) {\n return join(dirPath, dotExport.default);\n }\n }\n if (pkg.module) {\n return join(dirPath, pkg.module);\n }\n if (pkg.main) {\n return join(dirPath, pkg.main);\n }\n } catch {\n // fall through to index.js\n }\n }\n return join(dirPath, 'index.js');\n}\n\n/**\n * Dynamically imports a module (supports ESM plugins).\n * Falls back from require() to import() for ESM compatibility.\n * @param {*} path the module's path\n * @return {Object}\n */\nexport async function tryLoadAsync<T>(path: string, onError: any): Promise<PluginType<T> | null> {\n // Try require first (handles CJS and will be fast)\n try {\n const cjsResult = tryLoad<T>(path, onError);\n if (cjsResult !== null) {\n return cjsResult;\n }\n } catch (err: any) {\n // require() may throw for various reasons (ESM module, bundler shim, etc.)\n // — always fall through to dynamic import()\n debug('require() threw for %s: %s — falling back to import()', path, err.message);\n }\n\n // Fallback to dynamic import for ESM modules\n try {\n // import() doesn't support directory imports — resolve the entry point\n let importPath = path;\n if (existsSync(path) && existsSync(join(path, 'package.json'))) {\n importPath = resolveEntryPoint(path);\n debug('resolved ESM entry point: %s', importPath);\n }\n\n // Convert to file URL for import() compatibility\n const importUrl = importPath.startsWith('/') ? pathToFileURL(importPath).href : importPath;\n debug('trying dynamic import for plugin %s', importUrl);\n const module = await import(importUrl);\n debug('dynamic import succeeded for plugin %s', importUrl);\n return module as PluginType<T>;\n } catch (err: any) {\n if (err.code === MODULE_NOT_FOUND || err.code === 'ERR_MODULE_NOT_FOUND') {\n debug('\"import\" failed for plugin %s', path);\n return null;\n }\n onError({ err: err.message }, 'error loading plugin @{err}');\n throw err;\n }\n}\n"],"mappings":";;;;;;;AAOA,IAAM,WAAA,GAAA,MAAA,SAAmB,+BAA+B;AACxD,IAAM,mBAAmB;AACzB,IAAM,kBAAkB;AAIxB,SAAgB,QAAW,QAAgC;CAEzD,OAAO,OAAO,WAAW,cAAc,OAAO,OAAO,YAAY;AACnE;AAEA,SAAgB,MAAS,QAAgC;CACvD,OAAO,OAAO,KAAK,MAAM,EAAE,SAAS,SAAS;AAC/C;;;;;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I,IAAI;CAEjC,QAAQ,CAER;CAEF,QAAA,GAAA,UAAA,MAAY,SAAS,UAAU;AACjC;;;;;;;AAQA,eAAsB,aAAgB,MAAc,SAA6C;CAE/F,IAAI;EACF,MAAM,YAAY,QAAW,MAAM,OAAO;EAC1C,IAAI,cAAc,MAChB,OAAO;CAEX,SAAS,KAAU;EAGjB,QAAM,yDAAyD,MAAM,IAAI,OAAO;CAClF;CAGA,IAAI;EAEF,IAAI,aAAa;EACjB,KAAA,GAAA,QAAA,YAAe,IAAI,MAAA,GAAA,QAAA,aAAA,GAAA,UAAA,MAAqB,MAAM,cAAc,CAAC,GAAG;GAC9D,aAAa,kBAAkB,IAAI;GACnC,QAAM,gCAAgC,UAAU;EAClD;EAGA,MAAM,YAAY,WAAW,WAAW,GAAG,KAAA,GAAA,SAAA,eAAkB,UAAU,EAAE,OAAO;EAChF,QAAM,uCAAuC,SAAS;EACtD,MAAM,SAAS,MAAM,OAAO;EAC5B,QAAM,0CAA0C,SAAS;EACzD,OAAO;CACT,SAAS,KAAU;EACjB,IAAI,IAAI,SAAS,oBAAoB,IAAI,SAAS,wBAAwB;GACxE,QAAM,mCAAiC,IAAI;GAC3C,OAAO;EACT;EACA,QAAQ,EAAE,KAAK,IAAI,QAAQ,GAAG,6BAA6B;EAC3D,MAAM;CACR;AACF"}
|
package/build/utils.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.mjs","names":[],"sources":["../src/utils.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { existsSync, readFileSync } from 'node:fs';\nimport { join } from 'node:path';\nimport { pathToFileURL } from 'node:url';\n\nimport type { pluginUtils } from '@verdaccio/core';\n\nconst debug = buildDebug('verdaccio:plugin:loader:utils');\nconst MODULE_NOT_FOUND = 'MODULE_NOT_FOUND';\nconst ERR_REQUIRE_ESM = 'ERR_REQUIRE_ESM';\n\nexport type PluginType<T> = T extends pluginUtils.Plugin<T> ? T : never;\n\nexport function isValid<T>(plugin: PluginType<T>): boolean {\n // @ts-expect-error default not relevant\n return typeof plugin === 'function' || typeof plugin.default === 'function';\n}\n\nexport function isES6<T>(plugin: PluginType<T>): boolean {\n return Object.keys(plugin).includes('default');\n}\n\n/**\n * Requires a module.\n * @param {*} path the module's path\n * @return {Object}\n */\nexport function tryLoad<T>(path: string, onError: any): PluginType<T> | null {\n try {\n debug('loading plugin %s', path);\n return require(path) as PluginType<T>;\n } catch (err: any) {\n if (err.code === MODULE_NOT_FOUND) {\n debug('\"require\" failed for plugin %s', path);\n // If loading fails, because a dependency is missing,\n // we want to log the error message and require stack\n // to see where the missing dependency is.\n const message = err.message.replace(/\\\\\\\\/g, '\\\\').split('\\n');\n if (!message[0].includes(path)) {\n debug('%o', message[0]); // error message\n debug('%o', message.slice(1)); // stack trace\n }\n return null;\n }\n if (err.code === ERR_REQUIRE_ESM) {\n debug('\"require\" failed for ESM plugin %s, will try dynamic import', path);\n return null;\n }\n onError({ err: err.msg }, 'error loading plugin @{err}');\n throw err;\n }\n}\n\n/**\n * Resolve the entry point for a directory-based plugin.\n * dynamic import() does not support directory imports, so we need to\n * find the actual file to import (via package.json \"main\"/\"exports\" or index.js).\n */\nfunction resolveEntryPoint(dirPath: string): string {\n const pkgPath = join(dirPath, 'package.json');\n if (existsSync(pkgPath)) {\n try {\n const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));\n // Check exports first, then module, then main\n if (pkg.exports) {\n const dotExport = pkg.exports['.'];\n if (typeof dotExport === 'string') {\n return join(dirPath, dotExport);\n }\n if (dotExport?.import?.default) {\n return join(dirPath, dotExport.import.default);\n }\n if (dotExport?.import) {\n return join(dirPath, typeof dotExport.import === 'string' ? dotExport.import : '');\n }\n if (dotExport?.default) {\n return join(dirPath, dotExport.default);\n }\n }\n if (pkg.module) {\n return join(dirPath, pkg.module);\n }\n if (pkg.main) {\n return join(dirPath, pkg.main);\n }\n } catch {\n // fall through to index.js\n }\n }\n return join(dirPath, 'index.js');\n}\n\n/**\n * Dynamically imports a module (supports ESM plugins).\n * Falls back from require() to import() for ESM compatibility.\n * @param {*} path the module's path\n * @return {Object}\n */\nexport async function tryLoadAsync<T>(path: string, onError: any): Promise<PluginType<T> | null> {\n // Try require first (handles CJS and will be fast)\n try {\n const cjsResult = tryLoad<T>(path, onError);\n if (cjsResult !== null) {\n return cjsResult;\n }\n } catch (err: any) {\n // require() may throw for various reasons (ESM module, bundler shim, etc.)\n // — always fall through to dynamic import()\n debug('require() threw for %s: %s — falling back to import()', path, err.message);\n }\n\n // Fallback to dynamic import for ESM modules\n try {\n // import() doesn't support directory imports — resolve the entry point\n let importPath = path;\n if (existsSync(path) && existsSync(join(path, 'package.json'))) {\n importPath = resolveEntryPoint(path);\n debug('resolved ESM entry point: %s', importPath);\n }\n\n // Convert to file URL for import() compatibility\n const importUrl = importPath.startsWith('/') ? pathToFileURL(importPath).href : importPath;\n debug('trying dynamic import for plugin %s', importUrl);\n const module = await import(importUrl);\n debug('dynamic import succeeded for plugin %s', importUrl);\n return module as PluginType<T>;\n } catch (err: any) {\n if (err.code === MODULE_NOT_FOUND || err.code === 'ERR_MODULE_NOT_FOUND') {\n debug('\"import\" failed for plugin %s', path);\n return null;\n }\n onError({ err: err.message }, 'error loading plugin @{err}');\n throw err;\n }\n}\n"],"mappings":";;;;;;AAOA,IAAM,QAAQ,WAAW
|
|
1
|
+
{"version":3,"file":"utils.mjs","names":[],"sources":["../src/utils.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { existsSync, readFileSync } from 'node:fs';\nimport { join } from 'node:path';\nimport { pathToFileURL } from 'node:url';\n\nimport type { pluginUtils } from '@verdaccio/core';\n\nconst debug = buildDebug('verdaccio:plugin:loader:utils');\nconst MODULE_NOT_FOUND = 'MODULE_NOT_FOUND';\nconst ERR_REQUIRE_ESM = 'ERR_REQUIRE_ESM';\n\nexport type PluginType<T> = T extends pluginUtils.Plugin<T> ? T : never;\n\nexport function isValid<T>(plugin: PluginType<T>): boolean {\n // @ts-expect-error default not relevant\n return typeof plugin === 'function' || typeof plugin.default === 'function';\n}\n\nexport function isES6<T>(plugin: PluginType<T>): boolean {\n return Object.keys(plugin).includes('default');\n}\n\n/**\n * Requires a module.\n * @param {*} path the module's path\n * @return {Object}\n */\nexport function tryLoad<T>(path: string, onError: any): PluginType<T> | null {\n try {\n debug('loading plugin %s', path);\n return require(path) as PluginType<T>;\n } catch (err: any) {\n if (err.code === MODULE_NOT_FOUND) {\n debug('\"require\" failed for plugin %s', path);\n // If loading fails, because a dependency is missing,\n // we want to log the error message and require stack\n // to see where the missing dependency is.\n const message = err.message.replace(/\\\\\\\\/g, '\\\\').split('\\n');\n if (!message[0].includes(path)) {\n debug('%o', message[0]); // error message\n debug('%o', message.slice(1)); // stack trace\n }\n return null;\n }\n if (err.code === ERR_REQUIRE_ESM) {\n debug('\"require\" failed for ESM plugin %s, will try dynamic import', path);\n return null;\n }\n onError({ err: err.msg }, 'error loading plugin @{err}');\n throw err;\n }\n}\n\n/**\n * Resolve the entry point for a directory-based plugin.\n * dynamic import() does not support directory imports, so we need to\n * find the actual file to import (via package.json \"main\"/\"exports\" or index.js).\n */\nfunction resolveEntryPoint(dirPath: string): string {\n const pkgPath = join(dirPath, 'package.json');\n if (existsSync(pkgPath)) {\n try {\n const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));\n // Check exports first, then module, then main\n if (pkg.exports) {\n const dotExport = pkg.exports['.'];\n if (typeof dotExport === 'string') {\n return join(dirPath, dotExport);\n }\n if (dotExport?.import?.default) {\n return join(dirPath, dotExport.import.default);\n }\n if (dotExport?.import) {\n return join(dirPath, typeof dotExport.import === 'string' ? dotExport.import : '');\n }\n if (dotExport?.default) {\n return join(dirPath, dotExport.default);\n }\n }\n if (pkg.module) {\n return join(dirPath, pkg.module);\n }\n if (pkg.main) {\n return join(dirPath, pkg.main);\n }\n } catch {\n // fall through to index.js\n }\n }\n return join(dirPath, 'index.js');\n}\n\n/**\n * Dynamically imports a module (supports ESM plugins).\n * Falls back from require() to import() for ESM compatibility.\n * @param {*} path the module's path\n * @return {Object}\n */\nexport async function tryLoadAsync<T>(path: string, onError: any): Promise<PluginType<T> | null> {\n // Try require first (handles CJS and will be fast)\n try {\n const cjsResult = tryLoad<T>(path, onError);\n if (cjsResult !== null) {\n return cjsResult;\n }\n } catch (err: any) {\n // require() may throw for various reasons (ESM module, bundler shim, etc.)\n // — always fall through to dynamic import()\n debug('require() threw for %s: %s — falling back to import()', path, err.message);\n }\n\n // Fallback to dynamic import for ESM modules\n try {\n // import() doesn't support directory imports — resolve the entry point\n let importPath = path;\n if (existsSync(path) && existsSync(join(path, 'package.json'))) {\n importPath = resolveEntryPoint(path);\n debug('resolved ESM entry point: %s', importPath);\n }\n\n // Convert to file URL for import() compatibility\n const importUrl = importPath.startsWith('/') ? pathToFileURL(importPath).href : importPath;\n debug('trying dynamic import for plugin %s', importUrl);\n const module = await import(importUrl);\n debug('dynamic import succeeded for plugin %s', importUrl);\n return module as PluginType<T>;\n } catch (err: any) {\n if (err.code === MODULE_NOT_FOUND || err.code === 'ERR_MODULE_NOT_FOUND') {\n debug('\"import\" failed for plugin %s', path);\n return null;\n }\n onError({ err: err.message }, 'error loading plugin @{err}');\n throw err;\n }\n}\n"],"mappings":";;;;;;AAOA,IAAM,QAAQ,WAAW,+BAA+B;AACxD,IAAM,mBAAmB;AACzB,IAAM,kBAAkB;AAIxB,SAAgB,QAAW,QAAgC;CAEzD,OAAO,OAAO,WAAW,cAAc,OAAO,OAAO,YAAY;AACnE;AAEA,SAAgB,MAAS,QAAgC;CACvD,OAAO,OAAO,KAAK,MAAM,EAAE,SAAS,SAAS;AAC/C;;;;;;AAOA,SAAgB,QAAW,MAAc,SAAoC;CAC3E,IAAI;EACF,MAAM,qBAAqB,IAAI;EAC/B,OAAA,UAAe,IAAI;CACrB,SAAS,KAAU;EACjB,IAAI,IAAI,SAAS,kBAAkB;GACjC,MAAM,oCAAkC,IAAI;GAI5C,MAAM,UAAU,IAAI,QAAQ,QAAQ,SAA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Ac,CAAC,GAAG;GAC9D,aAAa,kBAAkB,IAAI;GACnC,MAAM,gCAAgC,UAAU;EAClD;EAGA,MAAM,YAAY,WAAW,WAAW,GAAG,IAAI,cAAc,UAAU,EAAE,OAAO;EAChF,MAAM,uCAAuC,SAAS;EACtD,MAAM,SAAS,MAAM,OAAO;EAC5B,MAAM,0CAA0C,SAAS;EACzD,OAAO;CACT,SAAS,KAAU;EACjB,IAAI,IAAI,SAAS,oBAAoB,IAAI,SAAS,wBAAwB;GACxE,MAAM,mCAAiC,IAAI;GAC3C,OAAO;EACT;EACA,QAAQ,EAAE,KAAK,IAAI,QAAQ,GAAG,6BAA6B;EAC3D,MAAM;CACR;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verdaccio/loaders",
|
|
3
|
-
"version": "9.0.0-next-9.
|
|
3
|
+
"version": "9.0.0-next-9.18",
|
|
4
4
|
"description": "Verdaccio Loader Logic",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -17,19 +17,19 @@
|
|
|
17
17
|
"url": "https://github.com/verdaccio/verdaccio/issues"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@verdaccio/core": "9.0.0-next-9.
|
|
20
|
+
"@verdaccio/core": "9.0.0-next-9.18",
|
|
21
21
|
"debug": "4.4.3",
|
|
22
22
|
"lodash-es": "4.18.1"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@verdaccio/logger": "9.0.0-next-9.16",
|
|
26
|
-
"@verdaccio/config": "9.0.0-next-9.16",
|
|
27
|
-
"@verdaccio/core": "9.0.0-next-9.16",
|
|
28
|
-
"@verdaccio-scope/verdaccio-auth-foo": "0.0.2",
|
|
29
25
|
"@types/lodash-es": "4.17.12",
|
|
30
|
-
"
|
|
31
|
-
"verdaccio
|
|
32
|
-
"
|
|
26
|
+
"@verdaccio-scope/verdaccio-fake-plugin": "1.0.0-next-9.0",
|
|
27
|
+
"@verdaccio/config": "9.0.0-next-9.18",
|
|
28
|
+
"@verdaccio/core": "9.0.0-next-9.18",
|
|
29
|
+
"@verdaccio/logger": "9.0.0-next-9.18",
|
|
30
|
+
"customprefix-auth": "4.0.0-next-9.1",
|
|
31
|
+
"verdaccio-auth-fake-plugin": "1.0.0-next-9.0",
|
|
32
|
+
"vitest": "4.1.7"
|
|
33
33
|
},
|
|
34
34
|
"homepage": "https://verdaccio.org",
|
|
35
35
|
"keywords": [
|