( inputOptions: InputOptionsWithPlugins, pluginText: string )
| 41 | } |
| 42 | |
| 43 | async function loadAndRegisterPlugin( |
| 44 | inputOptions: InputOptionsWithPlugins, |
| 45 | pluginText: string |
| 46 | ): Promise<void> { |
| 47 | let plugin: any = null; |
| 48 | let pluginArgument: any = undefined; |
| 49 | if (pluginText[0] === '{') { |
| 50 | // -p "{transform(c,i){...}}" |
| 51 | plugin = new Function('return ' + pluginText); |
| 52 | } else { |
| 53 | const match = pluginText.match(/^([\w./:@\\^{|}-]+)(=(.*))?$/); |
| 54 | if (match) { |
| 55 | // -p plugin |
| 56 | // -p plugin=arg |
| 57 | pluginText = match[1]; |
| 58 | pluginArgument = new Function('return ' + match[3])(); |
| 59 | } else { |
| 60 | throw new Error(`Invalid --plugin argument format: ${JSON.stringify(pluginText)}`); |
| 61 | } |
| 62 | if (!/^\.|^rollup-plugin-|[/@\\]/.test(pluginText)) { |
| 63 | // Try using plugin prefix variations first if applicable. |
| 64 | // Prefix order is significant - left has higher precedence. |
| 65 | for (const prefix of ['@rollup/plugin-', 'rollup-plugin-']) { |
| 66 | try { |
| 67 | plugin = await requireOrImport(prefix + pluginText); |
| 68 | break; |
| 69 | } catch { |
| 70 | // if this does not work, we try requiring the actual name below |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | if (!plugin) { |
| 75 | try { |
| 76 | if (pluginText[0] == '.') pluginText = path.resolve(pluginText); |
| 77 | // Windows absolute paths must be specified as file:// protocol URL |
| 78 | // Note that we do not have coverage for Windows-only code paths |
| 79 | else if (/^[A-Za-z]:\\/.test(pluginText)) { |
| 80 | pluginText = pathToFileURL(path.resolve(pluginText)).href; |
| 81 | } |
| 82 | plugin = await requireOrImport(pluginText); |
| 83 | } catch (error: any) { |
| 84 | throw new Error(`Cannot load plugin "${pluginText}": ${error.message}.`, { cause: error }); |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | // some plugins do not use `module.exports` for their entry point, |
| 89 | // in which case we try the named default export and the plugin name |
| 90 | if (typeof plugin === 'object') { |
| 91 | plugin = plugin.default || plugin[getCamelizedPluginBaseName(pluginText)]; |
| 92 | } |
| 93 | if (!plugin) { |
| 94 | throw new Error( |
| 95 | `Cannot find entry for plugin "${pluginText}". The plugin needs to export a function either as "default" or "${getCamelizedPluginBaseName( |
| 96 | pluginText |
| 97 | )}" for Rollup to recognize it.` |
| 98 | ); |
| 99 | } |
| 100 | inputOptions.plugins.push( |
no test coverage detected
searching dependent graphs…