@mermaid-js/mermaid-cli 10.1.0 → 10.2.4

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.
@@ -13,7 +13,7 @@ export type ParseMDDOptions = {
13
13
  /**
14
14
  * - Mermaid config.
15
15
  */
16
- mermaidConfig?: any;
16
+ mermaidConfig?: import("mermaid").MermaidConfig | undefined;
17
17
  /**
18
18
  * - Optional CSS text.
19
19
  */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SA4Xc,MAAM;;;;SACN,MAAM;;;;;;AAqBpB;;;;;;;;;;;;;;GAcG;AACH,2BAZW,GAAG,MAAM,IAAI,IAAI,GAAG,UAAU,EAAE,GAAG,MAAM,GAAG,SAAS,UAIrD,GAAG,MAAM,IAAI,IAAI,GAAG,UAAU,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,EAAE;;;;;8BAwGlE;AAzSD;;;;;;;;;GASG;AACH,uCAPW,OAAO,WAAW,EAAE,OAAO,cAC3B,MAAM,gBACN,KAAK,GAAG,KAAK,GAAG,KAAK,8FAEnB,QAAQ;IAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAC,CAAC,CAwJ9E;AAzLD;;;;;;;GAOG;AAEH;;;;;;;;;;;GAWG;AACH,kCAPW,OAAO,WAAW,EAAE,OAAO,cAC3B,MAAM,gBACN,KAAK,GAAG,KAAK,GAAG,KAAK,sCAGnB,QAAQ,MAAM,CAAC,CAK3B;AAhHD,qCAsFC;AA9KD;;;;;GAKG;AACH,+BAHW,MAAM,GACJ,KAAK,CAKjB;sBAnBqB,WAAW"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SA6Vc,MAAM;;;;SACN,MAAM;;;;;;AAqBpB;;;;;;;;;;;;;;GAcG;AACH,2BAZW,GAAG,MAAM,IAAI,IAAI,GAAG,UAAU,EAAE,GAAG,MAAM,GAAG,SAAS,UAIrD,GAAG,MAAM,IAAI,IAAI,GAAG,UAAU,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,EAAE;;;;;8BAwGlE;AArQD;;;;;;;;;GASG;AACH,uCAPW,OAAO,WAAW,EAAE,OAAO,cAC3B,MAAM,gBACN,KAAK,GAAG,KAAK,GAAG,KAAK,8FAEnB,QAAQ;IAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAC,CAAC,CAoH9E;AArJD;;;;;;;GAOG;AAEH;;;;;;;;;;;GAWG;AACH,kCAPW,OAAO,WAAW,EAAE,OAAO,cAC3B,MAAM,gBACN,KAAK,GAAG,KAAK,GAAG,KAAK,sCAGnB,QAAQ,MAAM,CAAC,CAK3B;AAzHD,qCA+FC;AAnLD;;;;;GAKG;AACH,+BAHW,MAAM,GACJ,KAAK,CAKjB;sBAnBqB,WAAW"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mermaid-js/mermaid-cli",
3
- "version": "10.1.0",
3
+ "version": "10.2.4",
4
4
  "description": "Command-line interface for mermaid",
5
5
  "license": "MIT",
6
6
  "repository": "git@github.com:mermaid-js/mermaid-cli.git",
@@ -28,8 +28,7 @@
28
28
  },
29
29
  "devDependencies": {
30
30
  "@fortawesome/fontawesome-free": "^5.6.0",
31
- "@mermaid-js/mermaid-mindmap": "^9.2.2",
32
- "@tsconfig/node14": "^1.0.3",
31
+ "@tsconfig/node14": "^14.1.0",
33
32
  "jest": "^29.0.1",
34
33
  "mermaid": "^10.0.0",
35
34
  "standard": "^17.0.0",
package/src/index.js CHANGED
@@ -52,36 +52,32 @@ const checkConfigFile = file => {
52
52
  * If `undefined`, reads from `stdin` instead.
53
53
  * @returns {Promise<string>} The contents of `inputFile` parsed as `utf8`.
54
54
  */
55
- const getInputData = async inputFile => new Promise((resolve, reject) => {
55
+ async function getInputData (inputFile) {
56
56
  // if an input file has been specified using '-i', it takes precedence over
57
57
  // piping from stdin
58
58
  if (typeof inputFile !== 'undefined') {
59
- return fs.readFile(inputFile, 'utf-8', (err, data) => {
60
- if (err) {
61
- return reject(err)
62
- }
63
-
64
- return resolve(data)
65
- })
59
+ return await fs.promises.readFile(inputFile, 'utf-8')
66
60
  }
67
61
 
68
- let data = ''
69
- process.stdin.on('readable', function () {
70
- const chunk = process.stdin.read()
62
+ return await new Promise((resolve, reject) => {
63
+ let data = ''
64
+ process.stdin.on('readable', function () {
65
+ const chunk = process.stdin.read()
71
66
 
72
- if (chunk !== null) {
73
- data += chunk
74
- }
75
- })
67
+ if (chunk !== null) {
68
+ data += chunk
69
+ }
70
+ })
76
71
 
77
- process.stdin.on('error', function (err) {
78
- reject(err)
79
- })
72
+ process.stdin.on('error', function (err) {
73
+ reject(err)
74
+ })
80
75
 
81
- process.stdin.on('end', function () {
82
- resolve(data)
76
+ process.stdin.on('end', function () {
77
+ resolve(data)
78
+ })
83
79
  })
84
- })
80
+ }
85
81
 
86
82
  /**
87
83
  * Commander parser that converts a string to an integer.
@@ -161,10 +157,19 @@ async function cli () {
161
157
  checkConfigFile(configFile)
162
158
  mermaidConfig = Object.assign(mermaidConfig, JSON.parse(fs.readFileSync(configFile, 'utf-8')))
163
159
  }
164
- let puppeteerConfig = {}
160
+ // @ts-expect-error Setting headless to `1` is not officially supported
161
+ let puppeteerConfig = /** @type {import('puppeteer').PuppeteerLaunchOptions} */ ({
162
+ /*
163
+ * `headless: 1` is not officially supported, but setting this to any
164
+ * non-`true` truthy value doesn't change any behavior, but it hides the
165
+ * Puppeteer old Headless deprecation warning,
166
+ * see https://github.com/argos-ci/jest-puppeteer/issues/553#issuecomment-1561826456
167
+ */
168
+ headless: 1
169
+ })
165
170
  if (puppeteerConfigFile) {
166
171
  checkConfigFile(puppeteerConfigFile)
167
- puppeteerConfig = JSON.parse(fs.readFileSync(puppeteerConfigFile, 'utf-8'))
172
+ puppeteerConfig = Object.assign(puppeteerConfig, JSON.parse(fs.readFileSync(puppeteerConfigFile, 'utf-8')))
168
173
  }
169
174
 
170
175
  // check cssFile
@@ -239,54 +244,18 @@ async function renderMermaid (browser, definition, outputFormat, { viewport, bac
239
244
  body.style.background = backgroundColor
240
245
  }, backgroundColor)
241
246
  const metadata = await page.$eval('#container', async (container, definition, mermaidConfig, myCSS, backgroundColor) => {
242
- /**
243
- * Checks to see if the given object is one of Mermaid's DetailedErrors.
244
- *
245
- * @param {unknown} error - The error to check
246
- * @returns {error is import("mermaid").DetailedError} Returns `true` is the `error`
247
- * is a `Mermaid.DetailedError`.
248
- * @see https://github.com/mermaid-js/mermaid/blob/v10.0.1/packages/mermaid/src/utils.ts#L927-L930
249
- */
250
- function isDetailedError (error) {
251
- return typeof error === 'object' && error !== null && 'str' in error
252
- }
253
-
254
- container.textContent = definition
255
-
256
247
  /**
257
248
  * @typedef {Object} GlobalThisWithMermaid
258
249
  * We've already imported these modules in our `index.html` file, so that they
259
250
  * get correctly bundled.
260
251
  * @property {import("mermaid")["default"]} mermaid Already imported mermaid instance
261
- * @property {import("@mermaid-js/mermaid-mindmap")} mermaidMindmap Already imported mermaid-mindmap plugin
262
252
  */
263
- const { mermaid, mermaidMindmap } = /** @type {GlobalThisWithMermaid & typeof globalThis} */ (globalThis)
253
+ const { mermaid } = /** @type {GlobalThisWithMermaid & typeof globalThis} */ (globalThis)
264
254
 
265
- await mermaid.registerExternalDiagrams([mermaidMindmap])
266
-
267
- mermaid.initialize(mermaidConfig)
255
+ mermaid.initialize({ startOnLoad: false, ...mermaidConfig })
268
256
  // should throw an error if mmd diagram is invalid
269
- try {
270
- await mermaid.run({
271
- nodes: [
272
- /**
273
- * @type {HTMLElement} We know this is a `HTMLElement`, since we
274
- * control the input HTML file
275
- */ (container)
276
- ],
277
- suppressErrors: false
278
- })
279
- } catch (error) {
280
- if (error instanceof Error) {
281
- // mermaid-js doesn't currently throws JS Errors, but let's leave this
282
- // here in case it does in the future
283
- throw error
284
- } else if (isDetailedError(error)) {
285
- throw new Error(error.message)
286
- } else {
287
- throw new Error(`Unknown mermaid render error: ${error}`)
288
- }
289
- }
257
+ const { svg: svgText } = await mermaid.render('my-svg', definition, container)
258
+ container.innerHTML = svgText
290
259
 
291
260
  const svg = container.getElementsByTagName?.('svg')?.[0]
292
261
  if (svg?.style) {
@@ -452,7 +421,7 @@ async function run (input, output, { puppeteerConfig = {}, quiet = false, output
452
421
  if (input && /\.(md|markdown)$/.test(input)) {
453
422
  const imagePromises = []
454
423
  for (const mermaidCodeblockMatch of definition.matchAll(mermaidChartsInMarkdownRegexGlobal)) {
455
- const mermaidDefinition = mermaidCodeblockMatch[1]
424
+ const mermaidDefinition = mermaidCodeblockMatch[2]
456
425
 
457
426
  /** Output can be either a template image file, or a `.md` output file.
458
427
  * If it is a template image file, use that to created numbered diagrams