| 90 | } | 90 | } |
| 91 | } | 91 | } |
| 92 | | 92 | |
| 93 | // Plugin is a CommonJS module. | 93 | // Plugin is a module file. |
| 94 | const cjsFilePath = path.join(pluginDirectoryPath, 'index.js'); | 94 | const fileTypes = ['index.js', 'index.cjs', 'index.mjs']; |
| 95 | if (fs.existsSync(cjsFilePath)) { | | |
| 96 | if (await loadFromFile(app, cjsFilePath, exitHooks)) { | | |
| 97 | return; | | |
| 98 | } | | |
| 99 | } | | |
| 100 | | 95 | |
| 101 | // Plugin is an ECMAScript module. | 96 | for (const fileType of fileTypes) { |
| 102 | const esmFilePath = path.join(pluginDirectoryPath, 'index.mjs'); | 97 | const filePath = path.join(pluginDirectoryPath, fileType); |
| 103 | if (fs.existsSync(esmFilePath)) { | 98 | if (fs.existsSync(filePath)) { |
| 104 | if (await loadFromFile(app, esmFilePath, exitHooks)) { | 99 | if (await loadFromFile(app, filePath, exitHooks)) { |
| 105 | return; | 100 | return; |
| 106 | } | 101 | } |
| 107 | } | 102 | } |
| 108 | } | 103 | } |
| | 104 | } |
| 109 | | 105 | |
| 110 | /** | 106 | /** |
| 111 | * Loads and initializes a plugin from an npm package. | 107 | * Loads and initializes a plugin from an npm package. |