Skip to content

AI-native design editor. Open-source Figma alternative.

fix(cli): use Node fs for import command

フォン88c107707132
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 848e9cbbb..fa62df4b2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -64,6 +64,7 @@
### Fixed
+- Run `openpencil import` on Node so the npm-installed CLI no longer fails with `Bun is not defined`. (#575)
- Isolate browser-development MCP servers behind worktree-aware Portless WebSocket routes and per-runtime socket/discovery paths, preventing concurrent worktrees from competing for port 7600 or the global MCP socket.
- Generate and cache recent-file previews from the conventional `Cover` page after opening a `.fig`, without modifying the source file.
diff --git a/lint/plugin.js b/lint/plugin.js
index abfdc110b..da2973b7d 100644
--- a/lint/plugin.js
+++ b/lint/plugin.js
@@ -1842,6 +1842,22 @@ const noDirectOpenPencilWindowInternals = {
}
}
+const noBunGlobalsInCli = {
+ meta: { docs: { description: 'Disallow Bun globals in Node-compatible CLI source' } },
+ create(context) {
+ const file = normalizedFilename(context)
+ if (!file.includes('/packages/cli/src/')) return {}
+ return {
+ MemberExpression(node) {
+ if (node.object?.type !== 'Identifier' || node.object.name !== 'Bun') return
+ context.report({
+ node,
+ message: 'Use Node-compatible APIs in CLI source instead of Bun globals.'
+ })
+ }
+ }
+ }
+}
const noTopLevelPrefixedTestFiles = createProgramFilenameRule({
description: 'Disallow top-level test files that encode domains as filename prefixes',
check(file) {
@@ -2110,7 +2126,8 @@ const noMixedCaseAcronymIdentifiers = {
}
},
create(context) {
- const canonicalAcronym = /(?:Acp|Ai|Api|Cli|Cors|Css|Html|Ime|Json|Jsx|Mcp|Pdf|Png|Rgb|Rpc|Rtl|Svg|Ui|Url|Uri|Xml)/g
+ const canonicalAcronym =
+ /(?:Acp|Ai|Api|Cli|Cors|Css|Html|Ime|Json|Jsx|Mcp|Pdf|Png|Rgb|Rpc|Rtl|Svg|Ui|Url|Uri|Xml)/g
const ignoredImports = new Set([
'@agentclientprotocol/sdk',
'@tauri-apps/plugin-clipboard-manager',
@@ -2264,6 +2281,7 @@ const plugin = {
'no-function-alias-imports': noFunctionAliasImports,
'no-mixed-case-acronym-identifiers': noMixedCaseAcronymIdentifiers,
'no-flat-kiwi-modules': noFlatKiwiModules,
+ 'no-bun-globals-in-cli': noBunGlobalsInCli,
'no-top-level-prefixed-test-files': noTopLevelPrefixedTestFiles,
'no-sibling-domain-prefixed-files': noSiblingDomainPrefixedFiles
}
diff --git a/oxlint.json b/oxlint.json
index 650edb847..d98eafde8 100644
--- a/oxlint.json
+++ b/oxlint.json
@@ -214,6 +214,7 @@
"open-pencil/non-component-source-directories-kebab-case": "error",
"open-pencil/no-component-root-sibling-folder": "error",
"open-pencil/no-flat-kiwi-modules": "error",
+ "open-pencil/no-bun-globals-in-cli": "error",
"open-pencil/no-top-level-prefixed-test-files": "error",
"open-pencil/no-sibling-domain-prefixed-files": "error",
"array-callback-return": "error",
diff --git a/packages/cli/src/commands/import.ts b/packages/cli/src/commands/import.ts
index 67884a076..77eeb0831 100644
--- a/packages/cli/src/commands/import.ts
+++ b/packages/cli/src/commands/import.ts
@@ -1,3 +1,4 @@
+import { readFile, writeFile } from 'node:fs/promises'
import { basename, extname, resolve } from 'node:path'
import { defineCommand } from 'citty'
@@ -36,7 +37,7 @@ function defaultOutput(input: string, format: string): string {
}
async function readTextFile(path: string): Promise<string> {
- return Bun.file(requireFile(path)).text()
+ return readFile(requireFile(path), 'utf8')
}
async function cssTextForArgs(args: ImportArgs): Promise<string | undefined> {
@@ -91,12 +92,12 @@ async function writeOutput(
const output = args.output ? resolve(args.output) : defaultOutput(requireFile(args.file), format)
if (format === 'json') {
- await Bun.write(output, `${JSON.stringify(document, null, 2)}\n`)
+ await writeFile(output, `${JSON.stringify(document, null, 2)}\n`)
return output
}
const result = await io.writeDocument('fig', graph)
- await Bun.write(output, result.data as Uint8Array)
+ await writeFile(output, result.data as Uint8Array)
return output
}