|
1 | 1 | // Copyright Contributors to the KubeOpenCode project |
2 | 2 | import type { PluginModule, PluginInput, Hooks } from "@opencode-ai/plugin" |
3 | | -import { createRequire } from "node:module" |
4 | 3 | import * as os from "os" |
5 | | -// CJS/ESM interop: @slack/web-api and @slack/socket-mode are CommonJS modules |
6 | | -// that use Object.defineProperty for their exports. Bun's bundler cannot |
7 | | -// resolve named imports from these (it produces "X is not a constructor" at |
8 | | -// runtime). Namespace imports (import * as) also fail because Bun's bundled |
9 | | -// namespace object loses the getter-defined properties. Using createRequire to |
10 | | -// load them as CJS guarantees the real module.exports with all constructors. |
11 | | -const require = createRequire(import.meta.url) |
12 | | -const { WebClient } = require("@slack/web-api") as typeof import("@slack/web-api") |
13 | | -const { SocketModeClient } = require("@slack/socket-mode") as typeof import("@slack/socket-mode") |
| 4 | +// CJS/ESM interop: @slack/web-api and @slack/socket-mode are CJS modules that |
| 5 | +// use Object.defineProperty for their exports. Bun's bundler cannot resolve |
| 6 | +// named imports (produces "X is not a constructor"), namespace imports lose |
| 7 | +// getter-defined properties in the bundled namespace, and require() is blocked |
| 8 | +// by Bun for async CJS modules. Dynamic import() forces Bun to handle the |
| 9 | +// interop at runtime, preserving all exports including constructors. |
| 10 | +const slackWebApi = await import("@slack/web-api") as typeof import("@slack/web-api") |
| 11 | +const slackSocketMode = await import("@slack/socket-mode") as typeof import("@slack/socket-mode") |
| 12 | +const { WebClient } = slackWebApi |
| 13 | +const { SocketModeClient } = slackSocketMode |
14 | 14 |
|
15 | 15 | // --------------------------------------------------------------------------- |
16 | 16 | // Types |
|
0 commit comments