astro-d2 0.6.0 → 0.7.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/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # astro-d2
2
+
3
+ ## 0.7.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#34](https://github.com/HiDeoo/astro-d2/pull/34) [`7028b05`](https://github.com/HiDeoo/astro-d2/commit/7028b0569eab2479808f38e6140a8b3d8a6a8db9) Thanks [@HiDeoo](https://github.com/HiDeoo)! - Adds support for Astro v5, drops support for Astro v4.
8
+
9
+ Please follow the [upgrade guide](https://docs.astro.build/en/guides/upgrade-to/v5/) to update your project.
10
+
11
+ When using the integration with the [Content Layer API](https://docs.astro.build/en/guides/content-collections) and the [`skipGeneration` option](https://astro-d2.vercel.app/configuration/#skipgeneration) is set to `false`, the integration will automatically invalidate the content layer cache at build time so that all existing diagrams can be generated while ensuring that all removed diagrams are properly cleaned up. This limitation will be removed if and when some upstream technical blockers are resolved.
package/index.ts CHANGED
@@ -4,6 +4,7 @@ import path from 'node:path'
4
4
  import type { AstroIntegration } from 'astro'
5
5
 
6
6
  import { AstroD2ConfigSchema, type AstroD2UserConfig } from './config'
7
+ import { clearContentLayerCache } from './libs/astro'
7
8
  import { isD2Installed } from './libs/d2'
8
9
  import { throwErrorWithHint } from './libs/integration'
9
10
  import { remarkAstroD2 } from './libs/remark'
@@ -39,6 +40,7 @@ export default function astroD2Integration(userConfig?: AstroD2UserConfig): Astr
39
40
  }
40
41
 
41
42
  if (command === 'build') {
43
+ await clearContentLayerCache(astroConfig, logger)
42
44
  await fs.rm(path.join('public', config.output), { force: true, recursive: true })
43
45
  }
44
46
  }
package/libs/astro.ts ADDED
@@ -0,0 +1,17 @@
1
+ import fs from 'node:fs'
2
+
3
+ import type { AstroConfig, AstroIntegrationLogger } from 'astro'
4
+
5
+ const dataStoreFile = 'data-store.json'
6
+
7
+ export async function clearContentLayerCache(config: AstroConfig, logger: AstroIntegrationLogger) {
8
+ const dataStore = getDataStoreFile(config)
9
+ if (fs.existsSync(dataStore)) {
10
+ logger.info('Invalidating content layer cache…')
11
+ await fs.promises.rm(dataStore, { force: true })
12
+ }
13
+ }
14
+
15
+ function getDataStoreFile(config: AstroConfig) {
16
+ return new URL(dataStoreFile, config.cacheDir)
17
+ }
@@ -82,7 +82,7 @@ function parseAttributes(attributesStr: string | null | undefined) {
82
82
  const { key, noQuoteValue, singleQuoteValue, doubleQuoteValue, truthyKey } = match.groups ?? {}
83
83
 
84
84
  const attributeKey = truthyKey ?? key
85
- const attributeValue = truthyKey ? 'true' : noQuoteValue ?? singleQuoteValue ?? doubleQuoteValue
85
+ const attributeValue = truthyKey ? 'true' : (noQuoteValue ?? singleQuoteValue ?? doubleQuoteValue)
86
86
 
87
87
  if (attributeKey && attributeValue) {
88
88
  attributes[attributeKey] = attributeValue
package/libs/d2.ts CHANGED
@@ -84,7 +84,7 @@ export async function generateD2Diagram(
84
84
  export async function getD2Diagram(diagramPath: string): Promise<D2Diagram | undefined> {
85
85
  try {
86
86
  const content = await fs.readFile(diagramPath, 'utf8')
87
- const match = content.match(viewBoxRegex)
87
+ const match = viewBoxRegex.exec(content)
88
88
  const { height, width } = match?.groups ?? {}
89
89
 
90
90
  if (!height || !width) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro-d2",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
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)",
@@ -10,26 +10,28 @@
10
10
  "./package.json": "./package.json"
11
11
  },
12
12
  "dependencies": {
13
- "hast-util-from-html": "2.0.3",
14
- "hast-util-to-html": "9.0.3",
15
- "unist-util-visit": "5.0.0"
13
+ "hast-util-from-html": "^2.0.3",
14
+ "hast-util-to-html": "^9.0.4",
15
+ "unist-util-visit": "^5.0.0"
16
16
  },
17
17
  "devDependencies": {
18
- "@types/hast": "3.0.4",
19
- "@types/mdast": "4.0.3",
20
- "remark": "15.0.1",
21
- "vfile": "6.0.1",
22
- "vitest": "1.2.2"
18
+ "@types/hast": "^3.0.4",
19
+ "@types/mdast": "^4.0.4",
20
+ "@types/node": "^18.19.68",
21
+ "remark": "^15.0.1",
22
+ "vfile": "^6.0.3",
23
+ "vitest": "2.1.6"
23
24
  },
24
25
  "peerDependencies": {
25
- "astro": ">=4.0.0"
26
+ "astro": ">=5.0.0"
26
27
  },
27
28
  "engines": {
28
29
  "node": ">=18"
29
30
  },
30
31
  "packageManager": "pnpm@8.15.1",
31
32
  "publishConfig": {
32
- "access": "public"
33
+ "access": "public",
34
+ "provenance": true
33
35
  },
34
36
  "sideEffects": false,
35
37
  "keywords": [
@@ -41,11 +43,12 @@
41
43
  "homepage": "https://github.com/HiDeoo/astro-d2",
42
44
  "repository": {
43
45
  "type": "git",
44
- "url": "https://github.com/HiDeoo/astro-d2.git"
46
+ "url": "https://github.com/HiDeoo/astro-d2.git",
47
+ "directory": "packages/astro-d2"
45
48
  },
46
49
  "bugs": "https://github.com/HiDeoo/astro-d2/issues",
47
50
  "scripts": {
48
51
  "test": "vitest",
49
- "lint": "prettier -c --cache . && eslint . --cache --max-warnings=0"
52
+ "lint": "eslint . --cache --max-warnings=0"
50
53
  }
51
54
  }