fix: embed prompts as strings for Bun bundler compatibility#222
fix: embed prompts as strings for Bun bundler compatibility#222usvimal wants to merge 1 commit intoOpencode-DCP:masterfrom
Conversation
The original approach using __dirname + readFileSync doesn't work correctly when the package is bundled by Bun, as __dirname resolves to incorrect paths at runtime. This causes 'Cannot find module' and 'ENOENT' errors. This fix embeds all prompt content as string constants, eliminating the need for filesystem access at runtime and ensuring compatibility with Bun's bundler as well as other ESM bundlers.
|
Is this necessary? I don't think the bundler is even used? |
|
I have been running in to the Unless the prompts are really big, I see nothing wrong with just having them as big strings in the plugin itself. Love the plugin nonetheless! |
Good point, fixing this in a slightly different way than this PR in #272 |
Summary
.txtfiles at runtime__dirnameresolves incorrectlyProblem
When the package is bundled by Bun, the original approach using
__dirname + readFileSyncfails because__dirnameresolves to incorrect paths at runtime. This causes errors like:Root Cause
Bun's bundler doesn't preserve
__dirnamesemantics correctly when files are bundled. The.txtfiles exist in the package, but the runtime path resolution fails.Solution
Embed all prompt content directly as string constants in
lib/prompts/index.ts. This:loadPrompt()APITesting
Tested locally by patching the installed package in
~/.cache/opencode/node_modules/@tarquinen/opencode-dcp/- the errors are resolved and the package works correctly.Changes
lib/prompts/index.ts: ReplacedreadFileSyncapproach with embedded string constants