diff --git a/src/index.js b/src/index.js index be513098..e669857d 100755 --- a/src/index.js +++ b/src/index.js @@ -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}`); +} + /** * 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. @@ -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}"` : ''; @@ -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;