Plugins: support .cjs module extension

ffa8716d070689fd84c3a3bfd07e6fed36e261b1

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +10 -14Ignore whitespace
src/plugin-loader.js+10 -14
@@ -17,7 +17,7 @@ const loadedPlugins = new Map();
1717 * @param {string} file Path to file
1818 * @returns {boolean} True if file is a CommonJS module
1919 */
2020const isCommonJS = (file) => path.extname(file) === '.js' || path.extname(file) === '.cjs';
2121
2222/**
2323 * Determine if a file is an ECMAScript module.
@@ -35,7 +35,7 @@ const isESModule = (file) => path.extname(file) === '.mjs';
3535 */
3636export async function loadPlugins(app, pluginsPath) {
3737 const exitHooks = [];
3838 const emptyFn = () => { };
3939
4040 // Server plugins are disabled.
4141 if (!enableServerPlugins) {
@@ -90,19 +90,15 @@ async function loadFromDirectory(app, pluginDirectoryPath, exitHooks) {
9090 }
9191 }
9292
9393 // Plugin is a CommonJS module file.
9494 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- }
10095
101- // Plugin is an ECMAScript module.
96+ for (const fileType of fileTypes) {
10297 const esmFilePathfilePath = path.join(pluginDirectoryPath, 'index.mjs'fileType);
10398 if (fs.existsSync(esmFilePathfilePath)) {
10499 if (await loadFromFile(app, esmFilePathfilePath, exitHooks)) {
105100 return;
101+ }
106102 }
107103 }
108104}