astro-d2 0.5.0 → 0.5.2

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/index.ts CHANGED
@@ -45,7 +45,17 @@ export default function astroD2Integration(userConfig?: AstroD2UserConfig): Astr
45
45
 
46
46
  updateConfig({
47
47
  markdown: {
48
- remarkPlugins: [[remarkAstroD2, { ...config, base: astroConfig.base, root: astroConfig.root }]],
48
+ remarkPlugins: [
49
+ [
50
+ remarkAstroD2,
51
+ {
52
+ ...config,
53
+ base: astroConfig.base,
54
+ publicDir: astroConfig.publicDir,
55
+ root: astroConfig.root,
56
+ },
57
+ ],
58
+ ],
49
59
  },
50
60
  })
51
61
  },
package/libs/d2.ts CHANGED
@@ -39,7 +39,7 @@ export async function generateD2Diagram(
39
39
  }
40
40
 
41
41
  if (attributes.target !== undefined) {
42
- extraArgs.push(`--target='${attributes.target}'`)
42
+ extraArgs.push(`--target=${attributes.target}`)
43
43
  }
44
44
 
45
45
  if (config.fonts?.regular) {
package/libs/exec.ts CHANGED
@@ -8,7 +8,7 @@ export function exec(command: string, args: string[], stdin?: string, cwd?: stri
8
8
  })
9
9
 
10
10
  const output: string[] = []
11
- const errorMessage = `Unable to run command: '${command} ${args.join(' ')}'.`
11
+ let errorMessage = `Unable to run command: '${command} ${args.join(' ')}'.`
12
12
 
13
13
  child.stdout.on('data', (data: Buffer) => {
14
14
  const lines = data
@@ -19,6 +19,10 @@ export function exec(command: string, args: string[], stdin?: string, cwd?: stri
19
19
  output.push(...lines)
20
20
  })
21
21
 
22
+ child.stderr.on('data', (data: Buffer) => {
23
+ errorMessage += `\n${data.toString()}`
24
+ })
25
+
22
26
  child.on('error', (error) => {
23
27
  reject(new Error(errorMessage, { cause: error }))
24
28
  })
@@ -1,8 +1,8 @@
1
1
  import { AstroError } from 'astro/errors'
2
2
 
3
- export function throwErrorWithHint(message: string): never {
3
+ export function throwErrorWithHint(message: string, cause?: Error): never {
4
4
  throw new AstroError(
5
- message,
5
+ message + (cause ? `\n\n${cause.message}` : ''),
6
6
  `See the error report above for more informations.\n\nIf you believe this is a bug, please file an issue at https://github.com/HiDeoo/astro-d2/issues/new/choose`,
7
7
  )
8
8
  }
package/libs/remark.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import path from 'node:path'
2
+ import url from 'node:url'
2
3
 
3
4
  import type { Code, Html, Parent, Root } from 'mdast'
4
5
  import { SKIP, visit } from 'unist-util-visit'
@@ -43,9 +44,10 @@ export function remarkAstroD2(config: RemarkAstroD2Config) {
43
44
  outputPath.fsPath,
44
45
  file.history[0] ? path.dirname(file.history[0]) : file.cwd,
45
46
  )
46
- } catch {
47
+ } catch (error) {
47
48
  throwErrorWithHint(
48
49
  `Failed to generate the D2 diagram at ${node.position?.start.line ?? 0}:${node.position?.start.column ?? 0}.`,
50
+ error instanceof Error ? (error.cause instanceof Error ? error.cause : error) : undefined,
49
51
  )
50
52
  }
51
53
  }
@@ -83,7 +85,7 @@ function getOutputPaths(config: RemarkAstroD2Config, file: VFile, nodeIndex: num
83
85
  const relativeOutputPath = path.join(parsedRelativePath.dir, `${parsedRelativePath.name}-${nodeIndex}.svg`)
84
86
 
85
87
  return {
86
- fsPath: path.join(file.cwd, 'public', config.output, relativeOutputPath),
88
+ fsPath: path.join(url.fileURLToPath(config.publicDir), config.output, relativeOutputPath),
87
89
  imgPath: path.posix.join(config.base, config.output, relativeOutputPath),
88
90
  }
89
91
  }
@@ -109,5 +111,6 @@ interface VisitorContext {
109
111
 
110
112
  export interface RemarkAstroD2Config extends AstroD2Config {
111
113
  base: string
114
+ publicDir: URL
112
115
  root: URL
113
116
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro-d2",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "license": "MIT",
5
5
  "description": "Astro integration and remark plugin to transform D2 Markdown code blocks into diagrams.",
6
6
  "author": "HiDeoo <github@hideoo.dev> (https://hideoo.dev)",