@riebeckite/plugin-mermaid 0.0.27 → 0.0.29

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/dist/index.js CHANGED
@@ -246,6 +246,8 @@ import { fileURLToPath, pathToFileURL } from "node:url";
246
246
  var RENDER_TIMEOUT_MS = 3e4;
247
247
  var MERMAID_SCRIPT_SUBPATH = "mermaid/dist/mermaid.min.js";
248
248
  var PUPPETEER_PACKAGE = "puppeteer";
249
+ var MERMAID_HEADLESS_MODE = "shell";
250
+ var MERMAID_PUPPETEER_BROWSER = "chrome-headless-shell";
249
251
  function createMermaidRenderSession(dependencies = {}) {
250
252
  const launchBrowser = dependencies.launch ?? defaultLaunchBrowser;
251
253
  const timeoutMs = dependencies.timeoutMs ?? RENDER_TIMEOUT_MS;
@@ -375,10 +377,21 @@ async function renderMermaidInPage(id, source, theme) {
375
377
  }
376
378
  async function defaultLaunchBrowser() {
377
379
  const puppeteer = await importPuppeteer();
378
- return puppeteer.default.launch({
379
- headless: "shell",
380
- args: ["--no-sandbox", "--disable-setuid-sandbox"]
381
- });
380
+ try {
381
+ return await puppeteer.default.launch({
382
+ headless: MERMAID_HEADLESS_MODE,
383
+ args: ["--no-sandbox", "--disable-setuid-sandbox"]
384
+ });
385
+ } catch (error) {
386
+ const message = formatError(error);
387
+ if (/Could not find|not found|ENOENT/i.test(message)) {
388
+ throw new Error(
389
+ `Could not launch ${MERMAID_PUPPETEER_BROWSER}. Install it with "puppeteer browsers install ${MERMAID_PUPPETEER_BROWSER}". ${message}`,
390
+ { cause: error }
391
+ );
392
+ }
393
+ throw error;
394
+ }
382
395
  }
383
396
  async function importPuppeteer() {
384
397
  const importModule = new Function(
@@ -1,5 +1,7 @@
1
1
  import type { Browser } from "puppeteer";
2
2
  import type { MermaidRenderSession } from "./types.js";
3
+ export declare const MERMAID_HEADLESS_MODE: "shell";
4
+ export declare const MERMAID_PUPPETEER_BROWSER = "chrome-headless-shell";
3
5
  export type MermaidSessionDependencies = {
4
6
  /**
5
7
  * Overrides browser launch. Tests inject a fake browser so session
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riebeckite/plugin-mermaid",
3
- "version": "0.0.27",
3
+ "version": "0.0.29",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -23,7 +23,7 @@
23
23
  "dependencies": {
24
24
  "mermaid": "^11.12.2",
25
25
  "puppeteer": "^25.11.0",
26
- "@riebeckite/core": "0.0.27"
26
+ "@riebeckite/core": "0.0.29"
27
27
  },
28
28
  "publishConfig": {
29
29
  "access": "public"