@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/cli/index.js CHANGED
@@ -1691,8 +1691,40 @@ function createPluginRegistry(pluginsDir) {
1691
1691
  // src/plugins/manager.ts
1692
1692
  init_logger();
1693
1693
  import path3 from "path";
1694
- import { existsSync as existsSync4 } from "fs";
1695
- import { register } from "tsx/esm/api";
1694
+ import { existsSync as existsSync4, statSync as statSync2 } from "fs";
1695
+ import { pathToFileURL } from "url";
1696
+ var pluginLogger = createChildLogger("plugins:manager");
1697
+ async function compilePlugin(tsEntryPath) {
1698
+ const outfile = tsEntryPath.replace(/\.ts$/, ".compiled.mjs");
1699
+ const pluginDir = path3.dirname(tsEntryPath);
1700
+ if (existsSync4(outfile)) {
1701
+ try {
1702
+ const compiledMtime = statSync2(outfile).mtimeMs;
1703
+ const dirMtime = statSync2(pluginDir).mtimeMs;
1704
+ if (compiledMtime >= dirMtime) {
1705
+ pluginLogger.debug({ outfile }, "Using cached compiled plugin");
1706
+ return outfile;
1707
+ }
1708
+ } catch {
1709
+ }
1710
+ }
1711
+ pluginLogger.debug({ tsEntryPath, outfile }, "Compiling plugin with esbuild");
1712
+ const esbuild = await import("esbuild");
1713
+ await esbuild.build({
1714
+ entryPoints: [tsEntryPath],
1715
+ bundle: true,
1716
+ format: "esm",
1717
+ platform: "node",
1718
+ target: "node20",
1719
+ outfile,
1720
+ // Externalize all bare-specifier packages (node_modules) but bundle
1721
+ // local relative imports (./auth.js → ./auth.ts, ./tools.js, etc.)
1722
+ packages: "external",
1723
+ logLevel: "warning"
1724
+ });
1725
+ pluginLogger.debug({ outfile }, "Plugin compiled successfully");
1726
+ return outfile;
1727
+ }
1696
1728
  var PluginManager = class {
1697
1729
  constructor(registry, sandbox, credentials, stateRepo) {
1698
1730
  this.registry = registry;
@@ -1792,12 +1824,8 @@ var PluginManager = class {
1792
1824
  let mod;
1793
1825
  try {
1794
1826
  if (pluginPath.endsWith(".ts")) {
1795
- const unregister = register();
1796
- try {
1797
- mod = await import(pluginPath);
1798
- } finally {
1799
- unregister();
1800
- }
1827
+ const compiledPath = await compilePlugin(pluginPath);
1828
+ mod = await import(pathToFileURL(compiledPath).href);
1801
1829
  } else {
1802
1830
  mod = await import(pluginPath);
1803
1831
  }