(program: ts.Program)
| 69 | } |
| 70 | |
| 71 | export function getPlugins(program: ts.Program): { diagnostics: ts.Diagnostic[]; plugins: Plugin[] } { |
| 72 | performance.startSection("getPlugins"); |
| 73 | const diagnostics: ts.Diagnostic[] = []; |
| 74 | const pluginsFromOptions: Plugin[] = []; |
| 75 | const options = program.getCompilerOptions() as CompilerOptions; |
| 76 | |
| 77 | for (const [index, pluginOption] of (options.luaPlugins ?? []).entries()) { |
| 78 | const optionName = `tstl.luaPlugins[${index}]`; |
| 79 | |
| 80 | const factory = (() => { |
| 81 | if ("plugin" in pluginOption) { |
| 82 | return pluginOption.plugin; |
| 83 | } else { |
| 84 | const { error: resolveError, result: factory } = resolvePlugin( |
| 85 | "plugin", |
| 86 | `${optionName}.name`, |
| 87 | getConfigDirectory(options), |
| 88 | pluginOption.name, |
| 89 | pluginOption.import |
| 90 | ); |
| 91 | |
| 92 | if (resolveError) diagnostics.push(resolveError); |
| 93 | return factory; |
| 94 | } |
| 95 | })(); |
| 96 | |
| 97 | if (factory === undefined) continue; |
| 98 | |
| 99 | const plugin = typeof factory === "function" ? factory(pluginOption) : factory; |
| 100 | pluginsFromOptions.push(plugin); |
| 101 | } |
| 102 | |
| 103 | if (options.tstlVerbose) { |
| 104 | console.log(`Loaded ${pluginsFromOptions.length} plugins`); |
| 105 | } |
| 106 | |
| 107 | performance.endSection("getPlugins"); |
| 108 | |
| 109 | return { diagnostics, plugins: pluginsFromOptions }; |
| 110 | } |
no test coverage detected