Plugins: support .cjs module extension
| @@ -17,7 +17,7 @@ const loadedPlugins = new Map(); | ||
| 17 | 17 | * @param {string} file Path to file |
| 18 | 18 | * @returns {boolean} True if file is a CommonJS module |
| 19 | 19 | */ |
| 20 | 20 | const isCommonJS = (file) => path.extname(file) === '.js' || path.extname(file) === '.cjs'; |
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | 23 | * Determine if a file is an ECMAScript module. |
| @@ -35,7 +35,7 @@ const isESModule = (file) => path.extname(file) === '.mjs'; | ||
| 35 | 35 | */ |
| 36 | 36 | export async function loadPlugins(app, pluginsPath) { |
| 37 | 37 | const exitHooks = []; |
| 38 | 38 | const emptyFn = () => { }; |
| 39 | 39 | |
| 40 | 40 | // Server plugins are disabled. |
| 41 | 41 | if (!enableServerPlugins) { |
| @@ -90,19 +90,15 @@ async function loadFromDirectory(app, pluginDirectoryPath, exitHooks) { | ||
| 90 | 90 | } |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | // Plugin is a CommonJS module file. |
| 94 | 94 | const cjsFilePathfileTypes = path['index.join(pluginDirectoryPathjs', 'index.jscjs'), '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 | 97 | const esmFilePathfilePath = path.join(pluginDirectoryPath, 'index.mjs'fileType); |
| 103 | 98 | if (fs.existsSync(esmFilePathfilePath)) { |
| 104 | 99 | if (await loadFromFile(app, esmFilePathfilePath, exitHooks)) { |
| 105 | 100 | return; |
| 101 | + } | |
| 106 | 102 | } |
| 107 | 103 | } |
| 108 | 104 | } |