@effing/satori 0.11.2 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -15,7 +15,7 @@ npm install @effing/satori
15
15
  For worker pool support (optional):
16
16
 
17
17
  ```bash
18
- npm install @effing/satori react tinypool
18
+ npm install @effing/satori react
19
19
  ```
20
20
 
21
21
  ## Quick Start
@@ -118,7 +118,7 @@ const png = await pool.renderToPng(
118
118
  await pool.destroy();
119
119
  ```
120
120
 
121
- **Peer dependencies:** The pool and serde sub-paths require `react` and `tinypool` to be installed. They are listed as optional peer dependencies so the main `@effing/satori` entry works without them.
121
+ **Peer dependencies:** The pool and serde sub-paths require `react` to be installed. It is listed as an optional peer dependency so the main `@effing/satori` entry works without it.
122
122
 
123
123
  ### Vite Plugin (SSR)
124
124
 
@@ -8,14 +8,171 @@ import {
8
8
  import os from "os";
9
9
  import { fileURLToPath } from "url";
10
10
  import path from "path";
11
- import Tinypool from "tinypool";
11
+
12
+ // src/pool/worker-pool.ts
13
+ import { Worker } from "worker_threads";
14
+ import { pathToFileURL } from "url";
15
+ var BOOTSTRAP = `
16
+ "use strict";
17
+ const { parentPort, workerData } = require("node:worker_threads");
18
+
19
+ const modPromise = import(workerData.workerUrl)
20
+ .catch((err) => {
21
+ parentPort.postMessage({
22
+ id: -1,
23
+ error: { name: "InitError", message: err.message, stack: err.stack },
24
+ });
25
+ process.exit(1);
26
+ });
27
+
28
+ parentPort.on("message", async (msg) => {
29
+ const { id, name, args } = msg;
30
+ try {
31
+ const mod = await modPromise;
32
+ const result = await mod[name](...args);
33
+ parentPort.postMessage({ id, result });
34
+ } catch (err) {
35
+ parentPort.postMessage({
36
+ id,
37
+ error: {
38
+ name: err?.name ?? "Error",
39
+ message: err?.message ?? String(err),
40
+ stack: err?.stack,
41
+ code: err?.code,
42
+ },
43
+ });
44
+ }
45
+ });
46
+ `.trim();
47
+ var WorkerPool = class {
48
+ workerUrl;
49
+ workerOpts;
50
+ minThreads;
51
+ maxThreads;
52
+ workers = [];
53
+ queue = [];
54
+ nextId = 0;
55
+ destroyed = false;
56
+ constructor(options) {
57
+ this.workerUrl = pathToFileURL(options.workerFile).href;
58
+ this.minThreads = options.minThreads ?? 1;
59
+ this.maxThreads = options.maxThreads ?? 1;
60
+ this.workerOpts = {
61
+ eval: true,
62
+ workerData: { workerUrl: this.workerUrl }
63
+ };
64
+ for (let i = 0; i < this.minThreads; i++) {
65
+ this.workers.push(this.spawnWorker());
66
+ }
67
+ }
68
+ run(args, options) {
69
+ if (this.destroyed) {
70
+ return Promise.reject(new Error("WorkerPool has been destroyed"));
71
+ }
72
+ return new Promise((resolve, reject) => {
73
+ const task = {
74
+ id: this.nextId++,
75
+ name: options.name,
76
+ args: [args],
77
+ resolve,
78
+ reject
79
+ };
80
+ this.dispatch(task);
81
+ });
82
+ }
83
+ async destroy() {
84
+ this.destroyed = true;
85
+ for (const task of this.queue) {
86
+ task.reject(new Error("WorkerPool has been destroyed"));
87
+ }
88
+ this.queue.length = 0;
89
+ await Promise.all(this.workers.map((entry) => entry.worker.terminate()));
90
+ this.workers.length = 0;
91
+ }
92
+ dispatch(task) {
93
+ const idle = this.workers.find((w) => !w.busy);
94
+ if (idle) {
95
+ this.sendToWorker(idle, task);
96
+ return;
97
+ }
98
+ if (this.workers.length < this.maxThreads) {
99
+ const entry = this.spawnWorker();
100
+ this.workers.push(entry);
101
+ this.sendToWorker(entry, task);
102
+ return;
103
+ }
104
+ this.queue.push(task);
105
+ }
106
+ sendToWorker(entry, task) {
107
+ entry.busy = true;
108
+ const onMessage = (msg) => {
109
+ if (msg.id !== task.id) return;
110
+ entry.worker.off("message", onMessage);
111
+ entry.worker.off("error", onError);
112
+ entry.busy = false;
113
+ if (msg.error) {
114
+ const err = new Error(msg.error.message);
115
+ err.name = msg.error.name;
116
+ if (msg.error.stack) err.stack = msg.error.stack;
117
+ if (msg.error.code)
118
+ err.code = msg.error.code;
119
+ task.reject(err);
120
+ } else {
121
+ task.resolve(msg.result);
122
+ }
123
+ this.processQueue();
124
+ };
125
+ const onError = (err) => {
126
+ entry.worker.off("message", onMessage);
127
+ entry.worker.off("error", onError);
128
+ entry.busy = false;
129
+ task.reject(err);
130
+ this.processQueue();
131
+ };
132
+ entry.worker.on("message", onMessage);
133
+ entry.worker.on("error", onError);
134
+ entry.worker.postMessage({ id: task.id, name: task.name, args: task.args });
135
+ }
136
+ processQueue() {
137
+ if (this.queue.length === 0) return;
138
+ const idle = this.workers.find((w) => !w.busy);
139
+ if (idle) {
140
+ const task = this.queue.shift();
141
+ this.sendToWorker(idle, task);
142
+ }
143
+ }
144
+ spawnWorker() {
145
+ const worker = new Worker(BOOTSTRAP, this.workerOpts);
146
+ const entry = { worker, busy: false };
147
+ worker.on("exit", (code) => {
148
+ const idx = this.workers.indexOf(entry);
149
+ if (idx !== -1) this.workers.splice(idx, 1);
150
+ if (!this.destroyed && code !== 0) {
151
+ this.workers.push(this.spawnWorker());
152
+ }
153
+ });
154
+ worker.on(
155
+ "message",
156
+ (msg) => {
157
+ if (msg.id === -1 && msg.error) {
158
+ const err = new Error(msg.error.message);
159
+ err.name = msg.error.name;
160
+ if (msg.error.stack) err.stack = msg.error.stack;
161
+ }
162
+ }
163
+ );
164
+ return entry;
165
+ }
166
+ };
167
+
168
+ // src/pool/index.ts
12
169
  function createSatoriPool(options) {
13
170
  const workerFile = options?.workerFile ?? path.resolve(
14
171
  path.dirname(fileURLToPath(import.meta.url)),
15
172
  "../worker/index.js"
16
173
  );
17
- const pool = new Tinypool({
18
- filename: workerFile,
174
+ const pool = new WorkerPool({
175
+ workerFile,
19
176
  minThreads: options?.minThreads ?? 1,
20
177
  maxThreads: options?.maxThreads ?? os.cpus().length
21
178
  });
@@ -40,7 +197,7 @@ function createSatoriPool(options) {
40
197
  const serialized = serializeElement(
41
198
  ensureSingleElement(expandElement(element))
42
199
  );
43
- return pool.run(
200
+ return await pool.run(
44
201
  {
45
202
  element: serialized,
46
203
  width: opts.width,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/pool/index.ts"],"sourcesContent":["import os from \"os\";\nimport { fileURLToPath } from \"url\";\nimport path from \"path\";\n\nimport type { ReactNode } from \"react\";\nimport type satori from \"satori\";\nimport Tinypool from \"tinypool\";\n\nimport type { EmojiStyle } from \"../emoji.ts\";\nimport {\n ensureSingleElement,\n expandElement,\n serializeElement,\n} from \"../serde/index.ts\";\n\nexport type SatoriPoolOptions = {\n /** Minimum number of worker threads (default: 1) */\n minThreads?: number;\n /** Maximum number of worker threads (default: os.cpus().length) */\n maxThreads?: number;\n /** Absolute path to a bundled worker file (set automatically by the Vite plugin) */\n workerFile?: string;\n};\n\nexport type SatoriPool = {\n /** Render a serialized React element to PNG via the worker pool */\n renderToPng(\n element: Parameters<typeof satori>[0],\n options: {\n width: number;\n height: number;\n fonts: Array<{\n name: string;\n data: Buffer | ArrayBuffer;\n weight: number;\n style: string;\n }>;\n emoji?: EmojiStyle;\n },\n ): Promise<Buffer>;\n\n /** Render a serialized React element to SVG via the worker pool */\n renderToSvg(\n element: Parameters<typeof satori>[0],\n options: {\n width: number;\n height: number;\n fonts: Array<{\n name: string;\n data: Buffer | ArrayBuffer;\n weight: number;\n style: string;\n }>;\n emoji?: EmojiStyle;\n },\n ): Promise<string>;\n\n /** Rasterize an SVG string to PNG via the worker pool */\n rasterizeSvgToPng(\n svg: string,\n options?: {\n fitTo?:\n | { mode: \"original\" }\n | { mode: \"width\"; value: number }\n | { mode: \"height\"; value: number }\n | { mode: \"zoom\"; value: number };\n crop?: {\n left: number;\n top: number;\n right?: number;\n bottom?: number;\n };\n },\n ): Promise<Buffer>;\n\n /** Shut down the worker pool */\n destroy(): Promise<void>;\n};\n\n/**\n * Create a worker pool for parallelized satori rendering.\n *\n * @param options Pool configuration\n * @returns A `SatoriPool` with `renderToPng`, `renderToSvg`, `rasterizeSvgToPng`, and `destroy`\n */\nexport function createSatoriPool(options?: SatoriPoolOptions): SatoriPool {\n const workerFile =\n options?.workerFile ??\n path.resolve(\n path.dirname(fileURLToPath(import.meta.url)),\n \"../worker/index.js\",\n );\n\n const pool = new Tinypool({\n filename: workerFile,\n minThreads: options?.minThreads ?? 1,\n maxThreads: options?.maxThreads ?? os.cpus().length,\n });\n\n return {\n async renderToPng(element, opts) {\n const serialized = serializeElement(\n ensureSingleElement(expandElement(element as ReactNode)),\n );\n const result = await pool.run(\n {\n element: serialized,\n width: opts.width,\n height: opts.height,\n fonts: opts.fonts,\n emoji: opts.emoji,\n },\n { name: \"renderToPng\" },\n );\n return Buffer.from(result);\n },\n\n async renderToSvg(element, opts) {\n const serialized = serializeElement(\n ensureSingleElement(expandElement(element as ReactNode)),\n );\n return pool.run(\n {\n element: serialized,\n width: opts.width,\n height: opts.height,\n fonts: opts.fonts,\n emoji: opts.emoji,\n },\n { name: \"renderToSvg\" },\n );\n },\n\n async rasterizeSvgToPng(svg, opts) {\n const result = await pool.run(\n { svg, options: opts },\n { name: \"rasterizeSvgToPng\" },\n );\n return Buffer.from(result);\n },\n\n async destroy() {\n await pool.destroy();\n },\n };\n}\n"],"mappings":";;;;;;;AAAA,OAAO,QAAQ;AACf,SAAS,qBAAqB;AAC9B,OAAO,UAAU;AAIjB,OAAO,cAAc;AA+Ed,SAAS,iBAAiB,SAAyC;AACxE,QAAM,aACJ,SAAS,cACT,KAAK;AAAA,IACH,KAAK,QAAQ,cAAc,YAAY,GAAG,CAAC;AAAA,IAC3C;AAAA,EACF;AAEF,QAAM,OAAO,IAAI,SAAS;AAAA,IACxB,UAAU;AAAA,IACV,YAAY,SAAS,cAAc;AAAA,IACnC,YAAY,SAAS,cAAc,GAAG,KAAK,EAAE;AAAA,EAC/C,CAAC;AAED,SAAO;AAAA,IACL,MAAM,YAAY,SAAS,MAAM;AAC/B,YAAM,aAAa;AAAA,QACjB,oBAAoB,cAAc,OAAoB,CAAC;AAAA,MACzD;AACA,YAAM,SAAS,MAAM,KAAK;AAAA,QACxB;AAAA,UACE,SAAS;AAAA,UACT,OAAO,KAAK;AAAA,UACZ,QAAQ,KAAK;AAAA,UACb,OAAO,KAAK;AAAA,UACZ,OAAO,KAAK;AAAA,QACd;AAAA,QACA,EAAE,MAAM,cAAc;AAAA,MACxB;AACA,aAAO,OAAO,KAAK,MAAM;AAAA,IAC3B;AAAA,IAEA,MAAM,YAAY,SAAS,MAAM;AAC/B,YAAM,aAAa;AAAA,QACjB,oBAAoB,cAAc,OAAoB,CAAC;AAAA,MACzD;AACA,aAAO,KAAK;AAAA,QACV;AAAA,UACE,SAAS;AAAA,UACT,OAAO,KAAK;AAAA,UACZ,QAAQ,KAAK;AAAA,UACb,OAAO,KAAK;AAAA,UACZ,OAAO,KAAK;AAAA,QACd;AAAA,QACA,EAAE,MAAM,cAAc;AAAA,MACxB;AAAA,IACF;AAAA,IAEA,MAAM,kBAAkB,KAAK,MAAM;AACjC,YAAM,SAAS,MAAM,KAAK;AAAA,QACxB,EAAE,KAAK,SAAS,KAAK;AAAA,QACrB,EAAE,MAAM,oBAAoB;AAAA,MAC9B;AACA,aAAO,OAAO,KAAK,MAAM;AAAA,IAC3B;AAAA,IAEA,MAAM,UAAU;AACd,YAAM,KAAK,QAAQ;AAAA,IACrB;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/pool/index.ts","../../src/pool/worker-pool.ts"],"sourcesContent":["import os from \"os\";\nimport { fileURLToPath } from \"url\";\nimport path from \"path\";\n\nimport type { ReactNode } from \"react\";\nimport type satori from \"satori\";\n\nimport type { EmojiStyle } from \"../emoji.ts\";\nimport {\n ensureSingleElement,\n expandElement,\n serializeElement,\n} from \"../serde/index.ts\";\nimport { WorkerPool } from \"./worker-pool.ts\";\n\nexport type SatoriPoolOptions = {\n /** Minimum number of worker threads (default: 1) */\n minThreads?: number;\n /** Maximum number of worker threads (default: os.cpus().length) */\n maxThreads?: number;\n /** Absolute path to a bundled worker file (set automatically by the Vite plugin) */\n workerFile?: string;\n};\n\nexport type SatoriPool = {\n /** Render a serialized React element to PNG via the worker pool */\n renderToPng(\n element: Parameters<typeof satori>[0],\n options: {\n width: number;\n height: number;\n fonts: Array<{\n name: string;\n data: Buffer | ArrayBuffer;\n weight: number;\n style: string;\n }>;\n emoji?: EmojiStyle;\n },\n ): Promise<Buffer>;\n\n /** Render a serialized React element to SVG via the worker pool */\n renderToSvg(\n element: Parameters<typeof satori>[0],\n options: {\n width: number;\n height: number;\n fonts: Array<{\n name: string;\n data: Buffer | ArrayBuffer;\n weight: number;\n style: string;\n }>;\n emoji?: EmojiStyle;\n },\n ): Promise<string>;\n\n /** Rasterize an SVG string to PNG via the worker pool */\n rasterizeSvgToPng(\n svg: string,\n options?: {\n fitTo?:\n | { mode: \"original\" }\n | { mode: \"width\"; value: number }\n | { mode: \"height\"; value: number }\n | { mode: \"zoom\"; value: number };\n crop?: {\n left: number;\n top: number;\n right?: number;\n bottom?: number;\n };\n },\n ): Promise<Buffer>;\n\n /** Shut down the worker pool */\n destroy(): Promise<void>;\n};\n\n/**\n * Create a worker pool for parallelized satori rendering.\n *\n * @param options Pool configuration\n * @returns A `SatoriPool` with `renderToPng`, `renderToSvg`, `rasterizeSvgToPng`, and `destroy`\n */\nexport function createSatoriPool(options?: SatoriPoolOptions): SatoriPool {\n const workerFile =\n options?.workerFile ??\n path.resolve(\n path.dirname(fileURLToPath(import.meta.url)),\n \"../worker/index.js\",\n );\n\n const pool = new WorkerPool({\n workerFile,\n minThreads: options?.minThreads ?? 1,\n maxThreads: options?.maxThreads ?? os.cpus().length,\n });\n\n return {\n async renderToPng(element, opts) {\n const serialized = serializeElement(\n ensureSingleElement(expandElement(element as ReactNode)),\n );\n const result = (await pool.run(\n {\n element: serialized,\n width: opts.width,\n height: opts.height,\n fonts: opts.fonts,\n emoji: opts.emoji,\n },\n { name: \"renderToPng\" },\n )) as Uint8Array;\n return Buffer.from(result);\n },\n\n async renderToSvg(element, opts) {\n const serialized = serializeElement(\n ensureSingleElement(expandElement(element as ReactNode)),\n );\n return (await pool.run(\n {\n element: serialized,\n width: opts.width,\n height: opts.height,\n fonts: opts.fonts,\n emoji: opts.emoji,\n },\n { name: \"renderToSvg\" },\n )) as string;\n },\n\n async rasterizeSvgToPng(svg, opts) {\n const result = (await pool.run(\n { svg, options: opts },\n { name: \"rasterizeSvgToPng\" },\n )) as Uint8Array;\n return Buffer.from(result);\n },\n\n async destroy() {\n await pool.destroy();\n },\n };\n}\n","import { Worker, type WorkerOptions } from \"node:worker_threads\";\nimport { pathToFileURL } from \"node:url\";\n\ninterface Task {\n id: number;\n name: string;\n args: unknown[];\n resolve: (value: unknown) => void;\n reject: (reason: unknown) => void;\n}\n\ninterface WorkerEntry {\n worker: Worker;\n busy: boolean;\n}\n\nexport interface WorkerPoolOptions {\n workerFile: string;\n minThreads?: number;\n maxThreads?: number;\n}\n\n// CJS bootstrap that dynamically imports the ESM worker module, then\n// wires up parentPort message handling for { id, name, args } calls.\nconst BOOTSTRAP = `\n\"use strict\";\nconst { parentPort, workerData } = require(\"node:worker_threads\");\n\nconst modPromise = import(workerData.workerUrl)\n .catch((err) => {\n parentPort.postMessage({\n id: -1,\n error: { name: \"InitError\", message: err.message, stack: err.stack },\n });\n process.exit(1);\n });\n\nparentPort.on(\"message\", async (msg) => {\n const { id, name, args } = msg;\n try {\n const mod = await modPromise;\n const result = await mod[name](...args);\n parentPort.postMessage({ id, result });\n } catch (err) {\n parentPort.postMessage({\n id,\n error: {\n name: err?.name ?? \"Error\",\n message: err?.message ?? String(err),\n stack: err?.stack,\n code: err?.code,\n },\n });\n }\n});\n`.trim();\n\nexport class WorkerPool {\n private readonly workerUrl: string;\n private readonly workerOpts: WorkerOptions;\n private readonly minThreads: number;\n private readonly maxThreads: number;\n private readonly workers: WorkerEntry[] = [];\n private readonly queue: Task[] = [];\n private nextId = 0;\n private destroyed = false;\n\n constructor(options: WorkerPoolOptions) {\n this.workerUrl = pathToFileURL(options.workerFile).href;\n this.minThreads = options.minThreads ?? 1;\n this.maxThreads = options.maxThreads ?? 1;\n this.workerOpts = {\n eval: true,\n workerData: { workerUrl: this.workerUrl },\n };\n\n // Pre-spawn minimum workers\n for (let i = 0; i < this.minThreads; i++) {\n this.workers.push(this.spawnWorker());\n }\n }\n\n run(args: unknown, options: { name: string }): Promise<unknown> {\n if (this.destroyed) {\n return Promise.reject(new Error(\"WorkerPool has been destroyed\"));\n }\n\n return new Promise<unknown>((resolve, reject) => {\n const task: Task = {\n id: this.nextId++,\n name: options.name,\n args: [args],\n resolve,\n reject,\n };\n this.dispatch(task);\n });\n }\n\n async destroy(): Promise<void> {\n this.destroyed = true;\n\n // Reject all queued tasks\n for (const task of this.queue) {\n task.reject(new Error(\"WorkerPool has been destroyed\"));\n }\n this.queue.length = 0;\n\n // Terminate all workers\n await Promise.all(this.workers.map((entry) => entry.worker.terminate()));\n this.workers.length = 0;\n }\n\n private dispatch(task: Task): void {\n // Find an idle worker\n const idle = this.workers.find((w) => !w.busy);\n if (idle) {\n this.sendToWorker(idle, task);\n return;\n }\n\n // Spawn a new worker if under the max\n if (this.workers.length < this.maxThreads) {\n const entry = this.spawnWorker();\n this.workers.push(entry);\n this.sendToWorker(entry, task);\n return;\n }\n\n // All workers busy, queue the task\n this.queue.push(task);\n }\n\n private sendToWorker(entry: WorkerEntry, task: Task): void {\n entry.busy = true;\n\n const onMessage = (msg: {\n id: number;\n result?: unknown;\n error?: { name: string; message: string; stack?: string; code?: string };\n }) => {\n if (msg.id !== task.id) return;\n entry.worker.off(\"message\", onMessage);\n entry.worker.off(\"error\", onError);\n entry.busy = false;\n\n if (msg.error) {\n const err = new Error(msg.error.message);\n err.name = msg.error.name;\n if (msg.error.stack) err.stack = msg.error.stack;\n if (msg.error.code)\n (err as NodeJS.ErrnoException).code = msg.error.code;\n task.reject(err);\n } else {\n task.resolve(msg.result);\n }\n\n this.processQueue();\n };\n\n const onError = (err: Error) => {\n entry.worker.off(\"message\", onMessage);\n entry.worker.off(\"error\", onError);\n entry.busy = false;\n task.reject(err);\n this.processQueue();\n };\n\n entry.worker.on(\"message\", onMessage);\n entry.worker.on(\"error\", onError);\n\n entry.worker.postMessage({ id: task.id, name: task.name, args: task.args });\n }\n\n private processQueue(): void {\n if (this.queue.length === 0) return;\n const idle = this.workers.find((w) => !w.busy);\n if (idle) {\n const task = this.queue.shift()!;\n this.sendToWorker(idle, task);\n }\n }\n\n private spawnWorker(): WorkerEntry {\n const worker = new Worker(BOOTSTRAP, this.workerOpts);\n const entry: WorkerEntry = { worker, busy: false };\n\n worker.on(\"exit\", (code) => {\n const idx = this.workers.indexOf(entry);\n if (idx !== -1) this.workers.splice(idx, 1);\n\n // Auto-restart on unexpected exit (not from destroy)\n if (!this.destroyed && code !== 0) {\n this.workers.push(this.spawnWorker());\n }\n });\n\n // Handle init errors (id === -1 from bootstrap)\n worker.on(\n \"message\",\n (msg: {\n id: number;\n error?: { name: string; message: string; stack?: string };\n }) => {\n if (msg.id === -1 && msg.error) {\n const err = new Error(msg.error.message);\n err.name = msg.error.name;\n if (msg.error.stack) err.stack = msg.error.stack;\n // Worker will exit(1) after this, triggering auto-restart\n }\n },\n );\n\n return entry;\n }\n}\n"],"mappings":";;;;;;;AAAA,OAAO,QAAQ;AACf,SAAS,qBAAqB;AAC9B,OAAO,UAAU;;;ACFjB,SAAS,cAAkC;AAC3C,SAAS,qBAAqB;AAuB9B,IAAM,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA+BhB,KAAK;AAEA,IAAM,aAAN,MAAiB;AAAA,EACL;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,UAAyB,CAAC;AAAA,EAC1B,QAAgB,CAAC;AAAA,EAC1B,SAAS;AAAA,EACT,YAAY;AAAA,EAEpB,YAAY,SAA4B;AACtC,SAAK,YAAY,cAAc,Q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AAA,IAEA,MAAM,YAAY,SAAS,MAAM;AAC/B,YAAM,aAAa;AAAA,QACjB,oBAAoB,cAAc,OAAoB,CAAC;AAAA,MACzD;AACA,aAAQ,MAAM,KAAK;AAAA,QACjB;AAAA,UACE,SAAS;AAAA,UACT,OAAO,KAAK;AAAA,UACZ,QAAQ,KAAK;AAAA,UACb,OAAO,KAAK;AAAA,UACZ,OAAO,KAAK;AAAA,QACd;AAAA,QACA,EAAE,MAAM,cAAc;AAAA,MACxB;AAAA,IACF;AAAA,IAEA,MAAM,kBAAkB,KAAK,MAAM;AACjC,YAAM,SAAU,MAAM,KAAK;AAAA,QACzB,EAAE,KAAK,SAAS,KAAK;AAAA,QACrB,EAAE,MAAM,oBAAoB;AAAA,MAC9B;AACA,aAAO,OAAO,KAAK,MAAM;AAAA,IAC3B;AAAA,IAEA,MAAM,UAAU;AACd,YAAM,KAAK,QAAQ;AAAA,IACrB;AAAA,EACF;AACF;","names":[]}
@@ -1,29 +1,351 @@
1
1
  // src/vite/index.ts
2
+ import { posix } from "path";
2
3
  import { fileURLToPath } from "url";
4
+ var TARGET_MODULES = /* @__PURE__ */ new Set(["@effing/satori/pool", "@effing/satori"]);
5
+ var SCOPE_TYPES = /* @__PURE__ */ new Set([
6
+ "FunctionDeclaration",
7
+ "FunctionExpression",
8
+ "ArrowFunctionExpression",
9
+ "ClassExpression",
10
+ "BlockStatement",
11
+ "ForStatement",
12
+ "ForInStatement",
13
+ "ForOfStatement",
14
+ "SwitchStatement",
15
+ "CatchClause"
16
+ ]);
17
+ function isEstreeNode(value) {
18
+ return typeof value === "object" && value !== null && typeof value.type === "string" && typeof value.start === "number" && typeof value.end === "number";
19
+ }
20
+ function walk(node, enter, leave, parent = null) {
21
+ enter(node, parent);
22
+ for (const key of Object.keys(node)) {
23
+ if (key === "type" || key === "start" || key === "end") continue;
24
+ const val = node[key];
25
+ if (isEstreeNode(val)) {
26
+ walk(val, enter, leave, node);
27
+ } else if (Array.isArray(val)) {
28
+ for (const item of val) {
29
+ if (isEstreeNode(item)) {
30
+ walk(item, enter, leave, node);
31
+ }
32
+ }
33
+ }
34
+ }
35
+ leave?.(node, parent);
36
+ }
37
+ function findImportedLocalNames(ast) {
38
+ const names = /* @__PURE__ */ new Set();
39
+ const body = ast.body;
40
+ if (!Array.isArray(body)) return names;
41
+ for (const node of body) {
42
+ if (node.type !== "ImportDeclaration" || !isEstreeNode(node.source) || !TARGET_MODULES.has(node.source.value))
43
+ continue;
44
+ if (node.importKind === "type") continue;
45
+ const specifiers = node.specifiers;
46
+ if (!Array.isArray(specifiers)) continue;
47
+ for (const spec of specifiers) {
48
+ if (spec.type !== "ImportSpecifier") continue;
49
+ if (spec.importKind === "type") continue;
50
+ const imported = spec.imported;
51
+ const local = spec.local;
52
+ if (imported && imported.name === "createSatoriPool" && local)
53
+ names.add(local.name);
54
+ }
55
+ }
56
+ return names;
57
+ }
58
+ function collectPatternNames(pattern, tracked, into) {
59
+ switch (pattern.type) {
60
+ case "Identifier":
61
+ if (tracked.has(pattern.name)) into.add(pattern.name);
62
+ break;
63
+ case "ObjectPattern": {
64
+ const props = pattern.properties;
65
+ if (Array.isArray(props)) {
66
+ for (const prop of props) {
67
+ if (prop.type === "RestElement") {
68
+ const arg = prop.argument;
69
+ if (isEstreeNode(arg)) collectPatternNames(arg, tracked, into);
70
+ } else {
71
+ const target = prop.value ?? prop.key;
72
+ if (isEstreeNode(target))
73
+ collectPatternNames(target, tracked, into);
74
+ }
75
+ }
76
+ }
77
+ break;
78
+ }
79
+ case "ArrayPattern": {
80
+ const elems = pattern.elements;
81
+ if (Array.isArray(elems)) {
82
+ for (const elem of elems) {
83
+ if (isEstreeNode(elem)) collectPatternNames(elem, tracked, into);
84
+ }
85
+ }
86
+ break;
87
+ }
88
+ case "RestElement": {
89
+ const arg = pattern.argument;
90
+ if (isEstreeNode(arg)) collectPatternNames(arg, tracked, into);
91
+ break;
92
+ }
93
+ case "AssignmentPattern": {
94
+ const left = pattern.left;
95
+ if (isEstreeNode(left)) collectPatternNames(left, tracked, into);
96
+ break;
97
+ }
98
+ }
99
+ }
100
+ function collectHoistedVarNames(body, tracked) {
101
+ const found = /* @__PURE__ */ new Set();
102
+ function scanStatements(stmts) {
103
+ for (const stmt of stmts) {
104
+ if (stmt.type === "VariableDeclaration" && stmt.kind === "var") {
105
+ const decls = stmt.declarations;
106
+ if (!Array.isArray(decls)) continue;
107
+ for (const d of decls) {
108
+ const id = d.id;
109
+ if (isEstreeNode(id)) collectPatternNames(id, tracked, found);
110
+ }
111
+ }
112
+ if (stmt.type === "BlockStatement" || stmt.type === "SwitchStatement") {
113
+ const inner = stmt.body ?? stmt.cases;
114
+ if (Array.isArray(inner)) scanStatements(inner);
115
+ }
116
+ if (stmt.type === "IfStatement") {
117
+ if (isEstreeNode(stmt.consequent)) scanStatements([stmt.consequent]);
118
+ if (isEstreeNode(stmt.alternate)) scanStatements([stmt.alternate]);
119
+ }
120
+ if (stmt.type === "ForStatement" || stmt.type === "ForInStatement" || stmt.type === "ForOfStatement" || stmt.type === "WhileStatement" || stmt.type === "DoWhileStatement") {
121
+ if (isEstreeNode(stmt.body)) scanStatements([stmt.body]);
122
+ if (isEstreeNode(stmt.init)) scanStatements([stmt.init]);
123
+ if (isEstreeNode(stmt.left)) scanStatements([stmt.left]);
124
+ }
125
+ if (stmt.type === "TryStatement") {
126
+ if (isEstreeNode(stmt.block)) scanStatements([stmt.block]);
127
+ if (isEstreeNode(stmt.handler)) {
128
+ const handlerBody = stmt.handler.body;
129
+ if (isEstreeNode(handlerBody)) scanStatements([handlerBody]);
130
+ }
131
+ if (isEstreeNode(stmt.finalizer)) scanStatements([stmt.finalizer]);
132
+ }
133
+ if (stmt.type === "LabeledStatement" && isEstreeNode(stmt.body)) {
134
+ scanStatements([stmt.body]);
135
+ }
136
+ if (stmt.type === "SwitchCase") {
137
+ const consequent = stmt.consequent;
138
+ if (Array.isArray(consequent)) scanStatements(consequent);
139
+ }
140
+ }
141
+ }
142
+ scanStatements(body);
143
+ return found;
144
+ }
145
+ function collectBlockScopedNames(body, tracked) {
146
+ const found = /* @__PURE__ */ new Set();
147
+ for (const stmt of body) {
148
+ if (stmt.type === "FunctionDeclaration" || stmt.type === "ClassDeclaration") {
149
+ const id = stmt.id;
150
+ if (id?.type === "Identifier" && tracked.has(id.name))
151
+ found.add(id.name);
152
+ }
153
+ if (stmt.type === "VariableDeclaration" && (stmt.kind === "let" || stmt.kind === "const")) {
154
+ const decls = stmt.declarations;
155
+ if (Array.isArray(decls)) {
156
+ for (const d of decls) {
157
+ const id = d.id;
158
+ if (isEstreeNode(id)) collectPatternNames(id, tracked, found);
159
+ }
160
+ }
161
+ }
162
+ }
163
+ return found;
164
+ }
165
+ function collectEdits(ast, localNames, warn) {
166
+ const edits = [];
167
+ const scopeStack = [
168
+ { names: /* @__PURE__ */ new Set(), isFunction: true }
169
+ ];
170
+ function isShadowed(name) {
171
+ for (let i = scopeStack.length - 1; i >= 1; i--) {
172
+ if (scopeStack[i].names.has(name)) return true;
173
+ }
174
+ return false;
175
+ }
176
+ function nearestFunctionScope() {
177
+ for (let i = scopeStack.length - 1; i >= 0; i--) {
178
+ if (scopeStack[i].isFunction) return scopeStack[i];
179
+ }
180
+ return scopeStack[0];
181
+ }
182
+ function getFunctionBody(node) {
183
+ const body = node.body;
184
+ if (isEstreeNode(body) && body.type === "BlockStatement") {
185
+ const stmts = body.body;
186
+ return Array.isArray(stmts) ? stmts : null;
187
+ }
188
+ return null;
189
+ }
190
+ walk(
191
+ ast,
192
+ (node, parent) => {
193
+ if (SCOPE_TYPES.has(node.type)) {
194
+ const isFunction = node.type === "FunctionDeclaration" || node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression";
195
+ const scope = { names: /* @__PURE__ */ new Set(), isFunction };
196
+ scopeStack.push(scope);
197
+ if (isFunction) {
198
+ const body = getFunctionBody(node);
199
+ if (body) {
200
+ const hoisted = collectHoistedVarNames(body, localNames);
201
+ for (const n of hoisted) scope.names.add(n);
202
+ }
203
+ const params = node.params;
204
+ if (Array.isArray(params)) {
205
+ for (const p of params) {
206
+ collectPatternNames(p, localNames, scope.names);
207
+ }
208
+ }
209
+ if (node.type === "FunctionExpression") {
210
+ const id = node.id;
211
+ if (id?.type === "Identifier" && localNames.has(id.name))
212
+ scope.names.add(id.name);
213
+ }
214
+ }
215
+ if (node.type === "ClassExpression") {
216
+ const id = node.id;
217
+ if (id?.type === "Identifier" && localNames.has(id.name))
218
+ scope.names.add(id.name);
219
+ }
220
+ if (node.type === "BlockStatement") {
221
+ const body = node.body;
222
+ if (Array.isArray(body)) {
223
+ const scoped = collectBlockScopedNames(body, localNames);
224
+ for (const n of scoped) scope.names.add(n);
225
+ }
226
+ }
227
+ if (node.type === "SwitchStatement") {
228
+ const cases = node.cases;
229
+ if (Array.isArray(cases)) {
230
+ const stmts = [];
231
+ for (const c of cases) {
232
+ const consequent = c.consequent;
233
+ if (Array.isArray(consequent)) stmts.push(...consequent);
234
+ }
235
+ const scoped = collectBlockScopedNames(stmts, localNames);
236
+ for (const n of scoped) scope.names.add(n);
237
+ }
238
+ }
239
+ if (node.type === "CatchClause") {
240
+ const param = node.param;
241
+ if (isEstreeNode(param))
242
+ collectPatternNames(param, localNames, scope.names);
243
+ }
244
+ }
245
+ if (node.type === "VariableDeclarator" && parent) {
246
+ const id = node.id;
247
+ if (isEstreeNode(id)) {
248
+ const kind = parent.kind;
249
+ const target = kind === "var" ? nearestFunctionScope().names : kind === "let" || kind === "const" ? scopeStack[scopeStack.length - 1].names : null;
250
+ if (target) collectPatternNames(id, localNames, target);
251
+ }
252
+ }
253
+ if (node.type === "FunctionDeclaration") {
254
+ const id = node.id;
255
+ if (id?.type === "Identifier" && localNames.has(id.name)) {
256
+ const target = scopeStack.length >= 2 ? scopeStack[scopeStack.length - 2] : scopeStack[0];
257
+ target.names.add(id.name);
258
+ }
259
+ }
260
+ if (node.type === "ClassDeclaration") {
261
+ const id = node.id;
262
+ if (id?.type === "Identifier" && localNames.has(id.name)) {
263
+ scopeStack[scopeStack.length - 1].names.add(id.name);
264
+ }
265
+ }
266
+ if (node.type === "CallExpression") {
267
+ const callee = node.callee;
268
+ if (callee?.type === "Identifier" && localNames.has(callee.name) && !isShadowed(callee.name)) {
269
+ if (typeof callee.end !== "number" || typeof node.end !== "number")
270
+ return;
271
+ const args = node.arguments;
272
+ if (!Array.isArray(args) || args.length === 0) {
273
+ edits.push({
274
+ start: callee.end,
275
+ end: node.end,
276
+ replacement: '({ workerFile: "__SATORI_WORKER_FILE__" })'
277
+ });
278
+ } else if (args[0].type === "ObjectExpression") {
279
+ if (typeof args[0].start !== "number") return;
280
+ edits.push({
281
+ start: args[0].start + 1,
282
+ end: args[0].start + 1,
283
+ replacement: ' workerFile: "__SATORI_WORKER_FILE__",'
284
+ });
285
+ } else {
286
+ warn(
287
+ `satoriPoolPlugin: unexpected first argument type "${args[0].type}" in createSatoriPool() call`
288
+ );
289
+ }
290
+ }
291
+ }
292
+ },
293
+ (node) => {
294
+ if (SCOPE_TYPES.has(node.type)) {
295
+ scopeStack.pop();
296
+ }
297
+ }
298
+ );
299
+ return edits;
300
+ }
301
+ function applyEdits(code, edits) {
302
+ const sorted = [...edits].sort((a, b) => b.start - a.start);
303
+ let result = code;
304
+ for (const { start, end, replacement } of sorted) {
305
+ result = result.slice(0, start) + replacement + result.slice(end);
306
+ }
307
+ return result;
308
+ }
3
309
  function satoriPoolPlugin() {
4
310
  let resolvedConfig;
5
311
  return {
6
312
  name: "@effing/satori:worker",
7
313
  apply: "build",
8
- config() {
9
- return { ssr: { external: ["tinypool"] } };
10
- },
11
314
  configResolved(config) {
12
315
  resolvedConfig = config;
13
316
  },
14
- transform(code, _id, options) {
15
- if (!options?.ssr) return;
16
- const pattern = /\bcreateSatoriPool\(\s*(\)|\{)/g;
17
- let matched = false;
18
- const result = code.replace(pattern, (_match, capture) => {
19
- matched = true;
20
- if (capture === ")") {
21
- return 'createSatoriPool({ workerFile: import.meta.dirname + "/satori-worker.js" })';
22
- }
23
- return 'createSatoriPool({ workerFile: import.meta.dirname + "/satori-worker.js", ';
24
- });
25
- if (!matched) return;
26
- return { code: result, map: null };
317
+ transform(code, id, options) {
318
+ if (!options?.ssr || !code.includes("createSatoriPool")) return;
319
+ let ast;
320
+ try {
321
+ ast = this.parse(code);
322
+ } catch {
323
+ if (!id.startsWith("\0")) {
324
+ this.warn(`satoriPoolPlugin: skipped AST transform for ${id}`);
325
+ }
326
+ return;
327
+ }
328
+ const localNames = findImportedLocalNames(ast);
329
+ if (localNames.size === 0) return;
330
+ const edits = collectEdits(
331
+ ast,
332
+ localNames,
333
+ (msg) => this.warn(`${msg} (${id})`)
334
+ );
335
+ if (edits.length === 0) return;
336
+ return { code: applyEdits(code, edits), map: null };
337
+ },
338
+ renderChunk(code, chunk) {
339
+ const placeholder = '"__SATORI_WORKER_FILE__"';
340
+ if (!code.includes(placeholder)) return;
341
+ const chunkDir = posix.dirname(chunk.fileName);
342
+ const relToRoot = chunkDir === "." ? "." : posix.relative(chunkDir, ".");
343
+ const workerRel = posix.join(relToRoot, "satori-worker.js");
344
+ const expr = `import.meta.dirname + ${JSON.stringify("/" + workerRel)}`;
345
+ return {
346
+ code: code.replaceAll(placeholder, expr),
347
+ map: null
348
+ };
27
349
  },
28
350
  async writeBundle(outputOptions) {
29
351
  if (!resolvedConfig.build.ssr) return;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/vite/index.ts"],"sourcesContent":["import { fileURLToPath } from \"url\";\n\nimport type { Plugin, ResolvedConfig } from \"vite\";\n\n/**\n * Vite plugin that bundles the `@effing/satori` worker into the SSR output and\n * rewrites `createSatoriPool()` calls to point at it.\n *\n * **This plugin is required for production SSR builds.** Without it the worker\n * path resolved via `import.meta.url` breaks after Vite bundles the pool code,\n * because the URL points at the build output directory instead of `node_modules`.\n *\n * @example\n * ```ts\n * // vite.config.ts\n * import { satoriPoolPlugin } from \"@effing/satori/vite\";\n *\n * export default defineConfig({\n * plugins: [satoriPoolPlugin()],\n * });\n * ```\n */\nexport function satoriPoolPlugin(): Plugin {\n let resolvedConfig: ResolvedConfig;\n\n return {\n name: \"@effing/satori:worker\",\n apply: \"build\",\n\n config() {\n return { ssr: { external: [\"tinypool\"] } };\n },\n\n configResolved(config) {\n resolvedConfig = config;\n },\n\n transform(code, _id, options) {\n if (!options?.ssr) return;\n\n const pattern = /\\bcreateSatoriPool\\(\\s*(\\)|\\{)/g;\n let matched = false;\n const result = code.replace(pattern, (_match, capture: string) => {\n matched = true;\n if (capture === \")\") {\n return 'createSatoriPool({ workerFile: import.meta.dirname + \"/satori-worker.js\" })';\n }\n // capture === \"{\"\n return 'createSatoriPool({ workerFile: import.meta.dirname + \"/satori-worker.js\", ';\n });\n\n if (!matched) return;\n return { code: result, map: null };\n },\n\n async writeBundle(outputOptions) {\n if (!resolvedConfig.build.ssr) return;\n\n const workerEntry = fileURLToPath(\n new URL(\"../worker/index.js\", import.meta.url),\n );\n const outDir = outputOptions.dir ?? resolvedConfig.build.outDir;\n\n const { build } = await import(\"vite\");\n await build({\n configFile: false,\n logLevel: \"silent\",\n build: {\n write: true,\n emptyOutDir: false,\n outDir,\n lib: {\n entry: workerEntry,\n formats: [\"es\"],\n fileName: () => \"satori-worker.js\",\n },\n rollupOptions: {\n external: [\"@resvg/resvg-js\"],\n },\n },\n });\n },\n };\n}\n"],"mappings":";AAAA,SAAS,qBAAqB;AAsBvB,SAAS,mBAA2B;AACzC,MAAI;AAEJ,SAAO;AAAA,IACL,MAAM;AAAA,IACN,OAAO;AAAA,IAEP,SAAS;AACP,aAAO,EAAE,KAAK,EAAE,UAAU,CAAC,UAAU,EAAE,EAAE;AAAA,IAC3C;AAAA,IAEA,eAAe,QAAQ;AACrB,uBAAiB;AAAA,IACnB;AAAA,IAEA,UAAU,MAAM,KAAK,SAAS;AAC5B,UAAI,CAAC,SAAS,IAAK;AAEnB,YAAM,UAAU;AAChB,UAAI,UAAU;AACd,YAAM,SAAS,KAAK,QAAQ,SAAS,CAAC,QAAQ,YAAoB;AAChE,kBAAU;AACV,YAAI,YAAY,KAAK;AACnB,iBAAO;AAAA,QACT;AAEA,eAAO;AAAA,MACT,CAAC;AAED,UAAI,CAAC,QAAS;AACd,aAAO,EAAE,MAAM,QAAQ,KAAK,KAAK;AAAA,IACnC;AAAA,IAEA,MAAM,YAAY,eAAe;AAC/B,UAAI,CAAC,eAAe,MAAM,IAAK;AAE/B,YAAM,cAAc;AAAA,QAClB,IAAI,IAAI,sBAAsB,YAAY,GAAG;AAAA,MAC/C;AACA,YAAM,SAAS,cAAc,OAAO,eAAe,MAAM;AAEzD,YAAM,EAAE,MAAM,IAAI,MAAM,OAAO,MAAM;AACrC,YAAM,MAAM;AAAA,QACV,YAAY;AAAA,QACZ,UAAU;AAAA,QACV,OAAO;AAAA,UACL,OAAO;AAAA,UACP,aAAa;AAAA,UACb;AAAA,UACA,KAAK;AAAA,YACH,OAAO;AAAA,YACP,SAAS,CAAC,IAAI;AAAA,YACd,UAAU,MAAM;AAAA,UAClB;AAAA,UACA,eAAe;AAAA,YACb,UAAU,CAAC,iBAAiB;AAAA,UAC9B;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/vite/index.ts"],"sourcesContent":["import { posix } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nimport type { Plugin, ResolvedConfig } from \"vite\";\n\ninterface EstreeNode {\n type: string;\n start: number;\n end: number;\n [key: string]: unknown;\n}\n\ninterface TextEdit {\n start: number;\n end: number;\n replacement: string;\n}\n\nconst TARGET_MODULES = new Set([\"@effing/satori/pool\", \"@effing/satori\"]);\n\nconst SCOPE_TYPES = new Set([\n \"FunctionDeclaration\",\n \"FunctionExpression\",\n \"ArrowFunctionExpression\",\n \"ClassExpression\",\n \"BlockStatement\",\n \"ForStatement\",\n \"ForInStatement\",\n \"ForOfStatement\",\n \"SwitchStatement\",\n \"CatchClause\",\n]);\n\nfunction isEstreeNode(value: unknown): value is EstreeNode {\n return (\n typeof value === \"object\" &&\n value !== null &&\n typeof (value as EstreeNode).type === \"string\" &&\n typeof (value as EstreeNode).start === \"number\" &&\n typeof (value as EstreeNode).end === \"number\"\n );\n}\n\nfunction walk(\n node: EstreeNode,\n enter: (node: EstreeNode, parent: EstreeNode | null) => void,\n leave?: (node: EstreeNode, parent: EstreeNode | null) => void,\n parent: EstreeNode | null = null,\n): void {\n enter(node, parent);\n for (const key of Object.keys(node)) {\n if (key === \"type\" || key === \"start\" || key === \"end\") continue;\n const val = node[key];\n if (isEstreeNode(val)) {\n walk(val, enter, leave, node);\n } else if (Array.isArray(val)) {\n for (const item of val) {\n if (isEstreeNode(item)) {\n walk(item, enter, leave, node);\n }\n }\n }\n }\n leave?.(node, parent);\n}\n\nfunction findImportedLocalNames(ast: EstreeNode): Set<string> {\n const names = new Set<string>();\n const body = ast.body as EstreeNode[] | undefined;\n if (!Array.isArray(body)) return names;\n\n for (const node of body) {\n if (\n node.type !== \"ImportDeclaration\" ||\n !isEstreeNode(node.source) ||\n !TARGET_MODULES.has(node.source.value as string)\n )\n continue;\n if ((node.importKind as string | undefined) === \"type\") continue;\n\n const specifiers = node.specifiers as EstreeNode[] | undefined;\n if (!Array.isArray(specifiers)) continue;\n\n for (const spec of specifiers) {\n if (spec.type !== \"ImportSpecifier\") continue;\n if ((spec.importKind as string | undefined) === \"type\") continue;\n const imported = spec.imported as EstreeNode | undefined;\n const local = spec.local as EstreeNode | undefined;\n if (imported && (imported.name as string) === \"createSatoriPool\" && local)\n names.add(local.name as string);\n }\n }\n return names;\n}\n\nfunction collectPatternNames(\n pattern: EstreeNode,\n tracked: Set<string>,\n into: Set<string>,\n): void {\n switch (pattern.type) {\n case \"Identifier\":\n if (tracked.has(pattern.name as string)) into.add(pattern.name as string);\n break;\n case \"ObjectPattern\": {\n const props = pattern.properties as EstreeNode[] | undefined;\n if (Array.isArray(props)) {\n for (const prop of props) {\n if (prop.type === \"RestElement\") {\n const arg = prop.argument as EstreeNode | undefined;\n if (isEstreeNode(arg)) collectPatternNames(arg, tracked, into);\n } else {\n // Property node — use value if present, fall back to key for\n // robustness across parser node shapes (shorthand properties)\n const target = (prop.value ?? prop.key) as EstreeNode | undefined;\n if (isEstreeNode(target))\n collectPatternNames(target, tracked, into);\n }\n }\n }\n break;\n }\n case \"ArrayPattern\": {\n const elems = pattern.elements as (EstreeNode | null)[] | undefined;\n if (Array.isArray(elems)) {\n for (const elem of elems) {\n if (isEstreeNode(elem)) collectPatternNames(elem, tracked, into);\n }\n }\n break;\n }\n case \"RestElement\": {\n const arg = pattern.argument as EstreeNode | undefined;\n if (isEstreeNode(arg)) collectPatternNames(arg, tracked, into);\n break;\n }\n case \"AssignmentPattern\": {\n const left = pattern.left as EstreeNode | undefined;\n if (isEstreeNode(left)) collectPatternNames(left, tracked, into);\n break;\n }\n }\n}\n\nfunction collectHoistedVarNames(\n body: EstreeNode[],\n tracked: Set<string>,\n): Set<string> {\n const found = new Set<string>();\n\n function scanStatements(stmts: EstreeNode[]): void {\n for (const stmt of stmts) {\n if (\n stmt.type === \"VariableDeclaration\" &&\n (stmt.kind as string) === \"var\"\n ) {\n const decls = stmt.declarations as EstreeNode[] | undefined;\n if (!Array.isArray(decls)) continue;\n for (const d of decls) {\n const id = d.id as EstreeNode | undefined;\n if (isEstreeNode(id)) collectPatternNames(id, tracked, found);\n }\n }\n // Recurse into blocks but NOT into nested functions\n if (stmt.type === \"BlockStatement\" || stmt.type === \"SwitchStatement\") {\n const inner = (stmt.body ?? stmt.cases) as EstreeNode[] | undefined;\n if (Array.isArray(inner)) scanStatements(inner);\n }\n if (stmt.type === \"IfStatement\") {\n if (isEstreeNode(stmt.consequent)) scanStatements([stmt.consequent]);\n if (isEstreeNode(stmt.alternate)) scanStatements([stmt.alternate]);\n }\n if (\n stmt.type === \"ForStatement\" ||\n stmt.type === \"ForInStatement\" ||\n stmt.type === \"ForOfStatement\" ||\n stmt.type === \"WhileStatement\" ||\n stmt.type === \"DoWhileStatement\"\n ) {\n if (isEstreeNode(stmt.body)) scanStatements([stmt.body]);\n if (isEstreeNode(stmt.init)) scanStatements([stmt.init]);\n if (isEstreeNode(stmt.left)) scanStatements([stmt.left]);\n }\n if (stmt.type === \"TryStatement\") {\n if (isEstreeNode(stmt.block)) scanStatements([stmt.block]);\n if (isEstreeNode(stmt.handler)) {\n const handlerBody = stmt.handler.body as EstreeNode | undefined;\n if (isEstreeNode(handlerBody)) scanStatements([handlerBody]);\n }\n if (isEstreeNode(stmt.finalizer)) scanStatements([stmt.finalizer]);\n }\n if (stmt.type === \"LabeledStatement\" && isEstreeNode(stmt.body)) {\n scanStatements([stmt.body]);\n }\n if (stmt.type === \"SwitchCase\") {\n const consequent = stmt.consequent as EstreeNode[] | undefined;\n if (Array.isArray(consequent)) scanStatements(consequent);\n }\n }\n }\n\n scanStatements(body);\n return found;\n}\n\nfunction collectBlockScopedNames(\n body: EstreeNode[],\n tracked: Set<string>,\n): Set<string> {\n const found = new Set<string>();\n for (const stmt of body) {\n if (\n stmt.type === \"FunctionDeclaration\" ||\n stmt.type === \"ClassDeclaration\"\n ) {\n const id = stmt.id as EstreeNode | undefined;\n if (id?.type === \"Identifier\" && tracked.has(id.name as string))\n found.add(id.name as string);\n }\n if (\n stmt.type === \"VariableDeclaration\" &&\n ((stmt.kind as string) === \"let\" || (stmt.kind as string) === \"const\")\n ) {\n const decls = stmt.declarations as EstreeNode[] | undefined;\n if (Array.isArray(decls)) {\n for (const d of decls) {\n const id = d.id as EstreeNode | undefined;\n if (isEstreeNode(id)) collectPatternNames(id, tracked, found);\n }\n }\n }\n }\n return found;\n}\n\nfunction collectEdits(\n ast: EstreeNode,\n localNames: Set<string>,\n warn: (msg: string) => void,\n): TextEdit[] {\n const edits: TextEdit[] = [];\n const scopeStack: { names: Set<string>; isFunction: boolean }[] = [\n { names: new Set(), isFunction: true },\n ];\n\n function isShadowed(name: string): boolean {\n for (let i = scopeStack.length - 1; i >= 1; i--) {\n if (scopeStack[i].names.has(name)) return true;\n }\n return false;\n }\n\n function nearestFunctionScope(): { names: Set<string>; isFunction: boolean } {\n for (let i = scopeStack.length - 1; i >= 0; i--) {\n if (scopeStack[i].isFunction) return scopeStack[i];\n }\n return scopeStack[0];\n }\n\n function getFunctionBody(node: EstreeNode): EstreeNode[] | null {\n const body = node.body as EstreeNode | EstreeNode[] | undefined;\n if (isEstreeNode(body) && body.type === \"BlockStatement\") {\n const stmts = body.body as EstreeNode[] | undefined;\n return Array.isArray(stmts) ? stmts : null;\n }\n return null;\n }\n\n walk(\n ast,\n (node, parent) => {\n // Push scope\n if (SCOPE_TYPES.has(node.type)) {\n const isFunction =\n node.type === \"FunctionDeclaration\" ||\n node.type === \"FunctionExpression\" ||\n node.type === \"ArrowFunctionExpression\";\n\n const scope = { names: new Set<string>(), isFunction };\n scopeStack.push(scope);\n\n // Prescan for hoisting\n if (isFunction) {\n const body = getFunctionBody(node);\n if (body) {\n const hoisted = collectHoistedVarNames(body, localNames);\n for (const n of hoisted) scope.names.add(n);\n }\n // Add function params\n const params = node.params as EstreeNode[] | undefined;\n if (Array.isArray(params)) {\n for (const p of params) {\n collectPatternNames(p, localNames, scope.names);\n }\n }\n // Named FunctionExpression id is only visible inside its own body\n if (node.type === \"FunctionExpression\") {\n const id = node.id as EstreeNode | undefined;\n if (id?.type === \"Identifier\" && localNames.has(id.name as string))\n scope.names.add(id.name as string);\n }\n }\n\n // Named ClassExpression id is only visible inside the class body\n if (node.type === \"ClassExpression\") {\n const id = node.id as EstreeNode | undefined;\n if (id?.type === \"Identifier\" && localNames.has(id.name as string))\n scope.names.add(id.name as string);\n }\n\n if (node.type === \"BlockStatement\") {\n const body = node.body as EstreeNode[] | undefined;\n if (Array.isArray(body)) {\n const scoped = collectBlockScopedNames(body, localNames);\n for (const n of scoped) scope.names.add(n);\n }\n }\n\n if (node.type === \"SwitchStatement\") {\n const cases = node.cases as EstreeNode[] | undefined;\n if (Array.isArray(cases)) {\n const stmts: EstreeNode[] = [];\n for (const c of cases) {\n const consequent = c.consequent as EstreeNode[] | undefined;\n if (Array.isArray(consequent)) stmts.push(...consequent);\n }\n const scoped = collectBlockScopedNames(stmts, localNames);\n for (const n of scoped) scope.names.add(n);\n }\n }\n\n if (node.type === \"CatchClause\") {\n const param = node.param as EstreeNode | undefined;\n if (isEstreeNode(param))\n collectPatternNames(param, localNames, scope.names);\n }\n }\n\n // Track variable declarations\n if (node.type === \"VariableDeclarator\" && parent) {\n const id = node.id as EstreeNode | undefined;\n if (isEstreeNode(id)) {\n const kind = (parent as EstreeNode).kind as string | undefined;\n const target =\n kind === \"var\"\n ? nearestFunctionScope().names\n : kind === \"let\" || kind === \"const\"\n ? scopeStack[scopeStack.length - 1].names\n : null;\n if (target) collectPatternNames(id, localNames, target);\n }\n }\n\n // Track function declarations (name goes to enclosing scope)\n if (node.type === \"FunctionDeclaration\") {\n const id = node.id as EstreeNode | undefined;\n if (id?.type === \"Identifier\" && localNames.has(id.name as string)) {\n const target =\n scopeStack.length >= 2\n ? scopeStack[scopeStack.length - 2]\n : scopeStack[0];\n target.names.add(id.name as string);\n }\n }\n\n // Track class declarations (block-scoped, name goes to current scope)\n if (node.type === \"ClassDeclaration\") {\n const id = node.id as EstreeNode | undefined;\n if (id?.type === \"Identifier\" && localNames.has(id.name as string)) {\n scopeStack[scopeStack.length - 1].names.add(id.name as string);\n }\n }\n\n // Detect call sites\n if (node.type === \"CallExpression\") {\n const callee = node.callee as EstreeNode | undefined;\n if (\n callee?.type === \"Identifier\" &&\n localNames.has(callee.name as string) &&\n !isShadowed(callee.name as string)\n ) {\n if (typeof callee.end !== \"number\" || typeof node.end !== \"number\")\n return;\n\n const args = node.arguments as EstreeNode[] | undefined;\n if (!Array.isArray(args) || args.length === 0) {\n // No args: replace entire arg list\n edits.push({\n start: callee.end,\n end: node.end,\n replacement: '({ workerFile: \"__SATORI_WORKER_FILE__\" })',\n });\n } else if (args[0].type === \"ObjectExpression\") {\n if (typeof args[0].start !== \"number\") return;\n edits.push({\n start: args[0].start + 1,\n end: args[0].start + 1,\n replacement: ' workerFile: \"__SATORI_WORKER_FILE__\",',\n });\n } else {\n warn(\n `satoriPoolPlugin: unexpected first argument type \"${args[0].type}\" in createSatoriPool() call`,\n );\n }\n }\n }\n },\n (node) => {\n if (SCOPE_TYPES.has(node.type)) {\n scopeStack.pop();\n }\n },\n );\n\n return edits;\n}\n\nfunction applyEdits(code: string, edits: TextEdit[]): string {\n const sorted = [...edits].sort((a, b) => b.start - a.start);\n let result = code;\n for (const { start, end, replacement } of sorted) {\n result = result.slice(0, start) + replacement + result.slice(end);\n }\n return result;\n}\n\n/**\n * Vite plugin that bundles the `@effing/satori` worker into the SSR output and\n * rewrites `createSatoriPool()` calls to point at it.\n *\n * **This plugin is required for production SSR builds.** Without it the worker\n * path resolved via `import.meta.url` breaks after Vite bundles the pool code,\n * because the URL points at the build output directory instead of `node_modules`.\n *\n * @example\n * ```ts\n * // vite.config.ts\n * import { satoriPoolPlugin } from \"@effing/satori/vite\";\n *\n * export default defineConfig({\n * plugins: [satoriPoolPlugin()],\n * });\n * ```\n */\nexport function satoriPoolPlugin(): Plugin {\n let resolvedConfig: ResolvedConfig;\n\n return {\n name: \"@effing/satori:worker\",\n apply: \"build\",\n\n configResolved(config) {\n resolvedConfig = config;\n },\n\n transform(code, id, options) {\n if (!options?.ssr || !code.includes(\"createSatoriPool\")) return;\n\n let ast: EstreeNode;\n try {\n ast = this.parse(code) as unknown as EstreeNode;\n } catch {\n if (!id.startsWith(\"\\0\")) {\n this.warn(`satoriPoolPlugin: skipped AST transform for ${id}`);\n }\n return;\n }\n\n const localNames = findImportedLocalNames(ast);\n if (localNames.size === 0) return;\n\n const edits = collectEdits(ast, localNames, (msg) =>\n this.warn(`${msg} (${id})`),\n );\n if (edits.length === 0) return;\n return { code: applyEdits(code, edits), map: null };\n },\n\n renderChunk(code, chunk) {\n const placeholder = '\"__SATORI_WORKER_FILE__\"';\n if (!code.includes(placeholder)) return;\n\n const chunkDir = posix.dirname(chunk.fileName);\n const relToRoot = chunkDir === \".\" ? \".\" : posix.relative(chunkDir, \".\");\n const workerRel = posix.join(relToRoot, \"satori-worker.js\");\n const expr = `import.meta.dirname + ${JSON.stringify(\"/\" + workerRel)}`;\n\n return {\n code: code.replaceAll(placeholder, expr),\n map: null,\n };\n },\n\n async writeBundle(outputOptions) {\n if (!resolvedConfig.build.ssr) return;\n\n const workerEntry = fileURLToPath(\n new URL(\"../worker/index.js\", import.meta.url),\n );\n const outDir = outputOptions.dir ?? resolvedConfig.build.outDir;\n\n const { build } = await import(\"vite\");\n await build({\n configFile: false,\n logLevel: \"silent\",\n build: {\n write: true,\n emptyOutDir: false,\n outDir,\n lib: {\n entry: workerEntry,\n formats: [\"es\"],\n fileName: () => \"satori-worker.js\",\n },\n rollupOptions: {\n external: [\"@resvg/resvg-js\"],\n },\n },\n });\n },\n };\n}\n"],"mappings":";AAAA,SAAS,aAAa;AACtB,SAAS,qBAAqB;AAiB9B,IAAM,iBAAiB,oBAAI,IAAI,CAAC,uBAAuB,gBAAgB,CAAC;AAExE,IAAM,cAAc,oBAAI,IAAI;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAED,SAAS,aAAa,OAAqC;AACzD,SACE,OAAO,UAAU,YACjB,UAAU,QACV,OAAQ,MAAqB,SAAS,YACtC,OAAQ,MAAqB,UAAU,YACvC,OAAQ,MAAqB,QAAQ;AAEzC;AAEA,SAAS,KACP,MACA,OACA,OACA,SAA4B,MACtB;AACN,QAAM,MAAM,MAAM;AAClB,aAAW,OAAO,OAAO,KAAK,IAAI,GAAG;AACnC,QAAI,QAAQ,UAAU,QAAQ,WAAW,QAAQ,MAAO;AACxD,UAAM,MAAM,KAAK,GAAG;AACpB,QAAI,aAAa,GAAG,GAAG;AACrB,WAAK,KAAK,OAAO,OAAO,IAAI;AAAA,IAC9B,WAAW,MAAM,QAAQ,GAAG,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AAA,IACH;AAAA,EACF;AACF;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effing/satori",
3
- "version": "0.11.2",
3
+ "version": "0.13.0",
4
4
  "description": "Render JSX to PNG using Satori with emoji support",
5
5
  "type": "module",
6
6
  "exports": {
@@ -37,16 +37,12 @@
37
37
  "peerDependencies": {
38
38
  "@resvg/resvg-js": "^2.6.2",
39
39
  "react": "^18.0.0 || ^19.0.0",
40
- "tinypool": "^1.0.0",
41
40
  "vite": "^5.0.0 || ^6.0.0 || ^7.0.0"
42
41
  },
43
42
  "peerDependenciesMeta": {
44
43
  "react": {
45
44
  "optional": true
46
45
  },
47
- "tinypool": {
48
- "optional": true
49
- },
50
46
  "vite": {
51
47
  "optional": true
52
48
  }