Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ function unescapeShell(str) {
return str.replace(/\\!/g, '!');
}

function tmpName(prefix, ext) {
return join(tmpdir(), `${prefix}-${process.pid}-${Date.now()}-${randomBytes(6).toString('hex')}.${ext}`);
}
Comment on lines +33 to +35
Comment on lines +33 to +35

/**
* If the JSX is a Frame whose role is "lay out N similar items in a row/col",
* extract the children as independent JSX strings + the direction.
Expand Down Expand Up @@ -520,7 +524,7 @@ function figmaEvalSync(code) {
// For simple expressions and multi-statement code, just pass through
// The plugin will add return to the last statement
const payload = JSON.stringify({ action: 'eval', code: wrappedCode });
const payloadFile = join(tmpdir(), `figma-payload-${Date.now()}.json`);
const payloadFile = tmpName('figma-payload', 'json');
writeFileSync(payloadFile, payload);
const daemonToken = getDaemonToken();
const tokenHeader = daemonToken ? ` -H "X-Daemon-Token: ${daemonToken}"` : '';
Expand Down Expand Up @@ -552,8 +556,8 @@ function figmaEvalSync(code) {
}

// Fallback: direct connection via temp script
const tempFile = join(tmpdir(), `figma-eval-${Date.now()}.mjs`);
const resultFile = join(tmpdir(), `figma-result-${Date.now()}.json`);
const tempFile = tmpName('figma-eval', 'mjs');
const resultFile = tmpName('figma-result', 'json');

// Use file:// URL for ESM import (cross-platform)
const clientUrl = pathToFileURL(join(process.cwd(), 'src/figma-client.js')).href;
Expand Down