@hmawla/co-assistant 1.0.5 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1558,8 +1558,40 @@ function createPluginRegistry(pluginsDir) {
1558
1558
 
1559
1559
  // src/plugins/manager.ts
1560
1560
  import path3 from "path";
1561
- import { existsSync as existsSync4 } from "fs";
1562
- import { register } from "tsx/esm/api";
1561
+ import { existsSync as existsSync4, statSync as statSync2 } from "fs";
1562
+ import { pathToFileURL } from "url";
1563
+ var pluginLogger = createChildLogger("plugins:manager");
1564
+ async function compilePlugin(tsEntryPath) {
1565
+ const outfile = tsEntryPath.replace(/\.ts$/, ".compiled.mjs");
1566
+ const pluginDir = path3.dirname(tsEntryPath);
1567
+ if (existsSync4(outfile)) {
1568
+ try {
1569
+ const compiledMtime = statSync2(outfile).mtimeMs;
1570
+ const dirMtime = statSync2(pluginDir).mtimeMs;
1571
+ if (compiledMtime >= dirMtime) {
1572
+ pluginLogger.debug({ outfile }, "Using cached compiled plugin");
1573
+ return outfile;
1574
+ }
1575
+ } catch {
1576
+ }
1577
+ }
1578
+ pluginLogger.debug({ tsEntryPath, outfile }, "Compiling plugin with esbuild");
1579
+ const esbuild = await import("esbuild");
1580
+ await esbuild.build({
1581
+ entryPoints: [tsEntryPath],
1582
+ bundle: true,
1583
+ format: "esm",
1584
+ platform: "node",
1585
+ target: "node20",
1586
+ outfile,
1587
+ // Externalize all bare-specifier packages (node_modules) but bundle
1588
+ // local relative imports (./auth.js → ./auth.ts, ./tools.js, etc.)
1589
+ packages: "external",
1590
+ logLevel: "warning"
1591
+ });
1592
+ pluginLogger.debug({ outfile }, "Plugin compiled successfully");
1593
+ return outfile;
1594
+ }
1563
1595
  var PluginManager = class {
1564
1596
  constructor(registry, sandbox, credentials, stateRepo) {
1565
1597
  this.registry = registry;
@@ -1659,12 +1691,8 @@ var PluginManager = class {
1659
1691
  let mod;
1660
1692
  try {
1661
1693
  if (pluginPath.endsWith(".ts")) {
1662
- const unregister = register();
1663
- try {
1664
- mod = await import(pluginPath);
1665
- } finally {
1666
- unregister();
1667
- }
1694
+ const compiledPath = await compilePlugin(pluginPath);
1695
+ mod = await import(pathToFileURL(compiledPath).href);
1668
1696
  } else {
1669
1697
  mod = await import(pluginPath);
1670
1698
  }