mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Plugins: support .cjs module extension
This commit is contained in:
@ -17,7 +17,7 @@ const loadedPlugins = new Map();
|
|||||||
* @param {string} file Path to file
|
* @param {string} file Path to file
|
||||||
* @returns {boolean} True if file is a CommonJS module
|
* @returns {boolean} True if file is a CommonJS module
|
||||||
*/
|
*/
|
||||||
const isCommonJS = (file) => path.extname(file) === '.js';
|
const isCommonJS = (file) => path.extname(file) === '.js' || path.extname(file) === '.cjs';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if a file is an ECMAScript module.
|
* Determine if a file is an ECMAScript module.
|
||||||
@ -90,22 +90,18 @@ async function loadFromDirectory(app, pluginDirectoryPath, exitHooks) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Plugin is a CommonJS module.
|
// Plugin is a module file.
|
||||||
const cjsFilePath = path.join(pluginDirectoryPath, 'index.js');
|
const fileTypes = ['index.js', 'index.cjs', 'index.mjs'];
|
||||||
if (fs.existsSync(cjsFilePath)) {
|
|
||||||
if (await loadFromFile(app, cjsFilePath, exitHooks)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Plugin is an ECMAScript module.
|
for (const fileType of fileTypes) {
|
||||||
const esmFilePath = path.join(pluginDirectoryPath, 'index.mjs');
|
const filePath = path.join(pluginDirectoryPath, fileType);
|
||||||
if (fs.existsSync(esmFilePath)) {
|
if (fs.existsSync(filePath)) {
|
||||||
if (await loadFromFile(app, esmFilePath, exitHooks)) {
|
if (await loadFromFile(app, filePath, exitHooks)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads and initializes a plugin from an npm package.
|
* Loads and initializes a plugin from an npm package.
|
||||||
|
Reference in New Issue
Block a user