@yuki-no/plugin-sdk
Version:
A GitHub Action that tracks changes between repositories. It creates GitHub issues based on commits from a head repository, making it ideal for documentation translation projects.
47 lines (46 loc) • 1.58 kB
JavaScript
export const loadPlugins = async (names) => {
const plugins = [];
for (const name of names) {
try {
const id = getResolveId(name);
const mod = await import(id);
const plugin = mod.default;
if (!plugin) {
throw new Error(`Plugin "${name}" does not export a default plugin object`);
}
if (!plugin.name) {
throw new Error(`Plugin "${name}" must have a "name" property`);
}
plugins.push(plugin);
}
catch (error) {
const err = error;
const resolvedId = getResolveId(name);
const contextInfo = [
`Failed to load plugin "${name}": ${err.message}`,
`Resolved ID: ${resolvedId}`,
`Original plugin specification: ${name}`,
];
// Add version info if available
if (name !== resolvedId) {
const versionPart = name.replace(resolvedId, '').replace(/^@/, '');
if (versionPart) {
contextInfo.push(`Version specification: ${versionPart}`);
}
}
throw new Error(contextInfo.join('\n'));
}
}
return plugins;
};
export const getResolveId = (name) => {
const isScopedPackage = name.startsWith('@');
if (isScopedPackage) {
return name.split('@').slice(0, 2).join('@');
}
const hasVersion = name.includes('@');
if (hasVersion) {
return name.split('@')[0];
}
return name;
};