Skip to main content

WORKER_SOURCE

Constant WORKER_SOURCE 

Source
const WORKER_SOURCE: &str = "import * as prettier from \"prettier\";\nimport { createInterface } from \"node:readline\";\n\nconst lines = createInterface({\n  input: process.stdin,\n  crlfDelay: Infinity,\n});\n\nfor await (const line of lines) {\n  let request;\n\n  try {\n    request = JSON.parse(line);\n    const config =\n      (await prettier.resolveConfig(request.path, { editorconfig: true })) ?? {};\n    const contents = await prettier.format(request.contents, {\n      ...config,\n      filepath: request.path,\n    });\n\n    respond({ id: request.id, contents });\n  } catch (error) {\n    respond({\n      id: request?.id ?? null,\n      error: error instanceof Error ? (error.stack ?? error.message) : String(error),\n    });\n  }\n}\n\nfunction respond(message) {\n  process.stdout.write(`${JSON.stringify(message)}\\n`);\n}\n";