fix: replace Vite ?raw imports with readFileSync for Node.js compatibility#250
fix: replace Vite ?raw imports with readFileSync for Node.js compatibility#250Dubworx wants to merge 2 commits intoOpenCoworkAI:mainfrom
Conversation
Signed-off-by: hqhq1025 <97931168+hqhq1025@users.noreply.github.com> (cherry picked from commit 0cbb792)
…ility The `?raw` import suffix is a Vite-specific feature that fails when importing @open-codesign/core from Node.js/tsx contexts (e.g. headless CLI scripts). This replaces all ?raw imports in frames/index.ts and design-skills/index.ts with fs.readFileSync, which works in both Vite (via plugin) and plain Node.js. Also adds "type": "module" to root package.json to enable ESM top-level await in scripts that import from the core package. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Findings
-
[Major] Runtime
readFileSync()here breaks packaged desktop builds.FRAME_TEMPLATESandDESIGN_SKILLSare imported by the Electron main process (apps/desktop/src/main/index.ts:9,apps/desktop/src/main/index.ts:296), but packaging only shipsout/**pluspackage.json(apps/desktop/electron-builder.yml:15). Replacing?rawwithreadFileSync(resolve(__dirname, name))(packages/core/src/frames/index.ts:19,packages/core/src/design-skills/index.ts:17) means the packaged app now expects the.jsxsource files to exist next to the bundled JS, and the current electron-vite build does not emit or copy them (apps/desktop/electron.vite.config.ts:12). That turns a packaged app import into anENOENTon the first frame/skill load.
Suggested fix:// Keep these starter assets bundled into JS until there is a dual-path // solution that also emits/copies the companion .jsx files for packaged builds. import iphoneJsx from './iphone.jsx?raw'; import ipadJsx from './ipad.jsx?raw'; // ...apply the same revert for the rest of the frame and skill starters
-
[Minor]
website/public/llms.txtnow points to a plan file that is not in the public checkout.website/public/llms.txt:79referencesdocs/v0.2-plan.md, but that file is not present, andAGENTS.md:16explicitly saysdocs/**is mostly maintainer-local. That leaves public readers and LLM consumers with a dead source reference.
Suggested fix:See the [roadmap](/roadmap) for the milestone plan.
Summary
- Review mode: initial
- 2 findings. The main risk is a packaged-desktop regression from swapping bundled starter assets for runtime filesystem reads.
- Existing tests cover starter contents, but I did not find a regression test for the plain-Node import path claimed in this PR or a packaged Electron smoke path.
Testing
- Not run (automation).
pnpmis not installed in this runner, so I could not execute the repo test suite.
open-codesign Bot
| const __dirname = dirname(fileURLToPath(import.meta.url)); | ||
|
|
||
| function loadFrame(name: string): string { | ||
| return readFileSync(resolve(__dirname, name), 'utf-8'); |
There was a problem hiding this comment.
[Major] This replaces build-time inlining with a runtime readFileSync, but the packaged desktop app only ships out/** and package.json (apps/desktop/electron-builder.yml:15-17). Because the main process imports FRAME_TEMPLATES / DESIGN_SKILLS (apps/desktop/src/main/index.ts:9-10, apps/desktop/src/main/index.ts:296-300), packaged builds will now look for iphone.jsx-style source files next to the bundled JS and hit ENOENT.
Suggested fix:
import iphoneJsx from './iphone.jsx?raw';
import ipadJsx from './ipad.jsx?raw';
// ...keep the starter bodies bundled until there is a dual-path
// solution that also emits/copies the .jsx assets for packaged builds| - v0.1 migration path — existing SQLite designs migrate into workspaces and session history | ||
|
|
||
| Design doc: `docs/plans/2026-04-23-v0.2-agentic-design-loop-design.md` in the repo. | ||
| Plan source: `docs/v0.2-plan.md` in the repo. |
There was a problem hiding this comment.
[Minor] docs/v0.2-plan.md is not in the public checkout, and AGENTS.md says docs/** is mostly maintainer-local. This leaves a dead public reference.
Suggested fix:
See the [roadmap](/roadmap) for the milestone plan.
Summary
?rawimports inpackages/core/src/frames/index.tsandpackages/core/src/design-skills/index.tswithfs.readFileSync, enabling@open-codesign/coreto be imported from Node.js/tsx contexts (e.g. headless CLI scripts) without Vite running"type": "module"to rootpackage.jsonto support ESM top-levelawaitin scripts that import from the core packageProblem
The
?rawimport suffix is a Vite-only feature. When importing@open-codesign/corefrom a plain Node.js/tsx script (such as the headlessscripts/clone-from-dna.tsorscripts/extract-dna.ts), the import chain fails with:This blocks any headless/CLI usage of the core
generate()function outside of the Vite dev server or Electron app context.Approach
Replaced all
?rawimports with areadFileSynchelper that resolves paths relative toimport.meta.url. This works in both:readFileSyncfinefsmodule, no bundler neededFiles Changed
package.json"type": "module"packages/core/src/frames/index.ts?raw→readFileSyncfor 5 frame JSX filespackages/core/src/design-skills/index.ts?raw→readFileSyncfor 12 skill JSX filesTest plan
pnpm dev— Electron app starts and renders designs normallypnpm build— Production build succeedsnpx tsx scripts/clone-from-dna.ts --help— CLI script imports core without errorsnpx tsx scripts/extract-dna.ts --help— CLI script imports core without errors🤖 Generated with Claude Code