@purview-dev/astroc4 1.0.0-prerelease.3 → 1.0.0-prerelease.5
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 +101 -16
- package/dist/expressive-code.d.ts +14 -0
- package/dist/expressive-code.js +1171 -0
- package/dist/expressive-code.js.map +13 -0
- package/dist/fences.d.ts +46 -0
- package/dist/grammar/langium.d.ts +42 -0
- package/dist/grammar/source.d.ts +90 -0
- package/dist/grammar/textmate.d.ts +51 -0
- package/dist/index.d.ts +82 -0
- package/dist/index.js +1187 -0
- package/dist/index.js.map +16 -0
- package/dist/integration.d.ts +37 -0
- package/dist/integration.js +261 -0
- package/dist/integration.js.map +11 -0
- package/dist/like-c4.langium +1357 -0
- package/dist/likec4.tmLanguage.json +327 -0
- package/dist/translations.d.ts +21 -0
- package/package.json +18 -2
- package/src/components/DiagramFrame.astro +13 -5
- package/src/components/DiagramShell.astro +18 -7
- package/src/components/LikeC4Fence.astro +2 -1
- package/src/components/LikeC4View.astro +13 -4
- package/src/components/LoadingPlaceholder.astro +10 -4
package/README.md
CHANGED
|
@@ -1,18 +1,26 @@
|
|
|
1
|
+
[](https://www.npmjs.com/package/@purview-dev/astroc4)
|
|
2
|
+
|
|
1
3
|
# astroc4
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
+
Interactive [LikeC4](https://likec4.dev) architecture diagrams for Astro and
|
|
6
|
+
Starlight.
|
|
5
7
|
|
|
6
8
|
- `<LikeC4View viewId="…" />` — render a view from the site's `.c4` model.
|
|
7
9
|
- ` ```likec4 ` fences in `.mdx` — either inline DSL, compiled and laid out at
|
|
8
10
|
build time, or an empty fence with `view="…"` pointing at the model.
|
|
9
11
|
- LikeC4 syntax highlighting for Expressive Code (`.c4` files, ` ```c4 `),
|
|
10
12
|
derived at build time from the Langium grammar in
|
|
11
|
-
[likec4/likec4](https://github.com/likec4/likec4) — no `ec.config.mjs
|
|
13
|
+
[likec4/likec4](https://github.com/likec4/likec4) — no `ec.config.mjs` under
|
|
14
|
+
Starlight.
|
|
12
15
|
- Every UI string translatable through Starlight's i18n.
|
|
13
16
|
|
|
14
|
-
|
|
15
|
-
`
|
|
17
|
+
It works in **plain Astro** as well: `@purview-dev/astroc4/integration` is an
|
|
18
|
+
`AstroIntegration` that adds the same model compiler and fence transform. See
|
|
19
|
+
[Plain Astro](docs/wiki/guide/Plain-Astro.md) and the runnable example in
|
|
20
|
+
[`examples/astro`](examples/astro).
|
|
21
|
+
|
|
22
|
+
Full documentation lives in [`docs/wiki`](docs/wiki/README.md), grouped into
|
|
23
|
+
`guide/` and `contributing/`.
|
|
16
24
|
|
|
17
25
|
## Install
|
|
18
26
|
|
|
@@ -23,8 +31,21 @@ bun add @purview-dev/astroc4@prerelease # 1.0.0-prerelease.N
|
|
|
23
31
|
Published to npm under the `prerelease` dist-tag, so `bun add @purview-dev/astroc4` keeps
|
|
24
32
|
resolving the last stable release. Astroc4 declares its peer dependencies, so
|
|
25
33
|
Bun and npm install them with it; under pnpm add them explicitly (`astro`,
|
|
26
|
-
`@astrojs/
|
|
27
|
-
|
|
34
|
+
`@astrojs/react`, `@astrojs/markdown-satteri`, `likec4`, `@likec4/core`,
|
|
35
|
+
`react`, `react-dom`, `shiki`, and `@astrojs/starlight` if you use the plugin —
|
|
36
|
+
Starlight is an optional peer, because plain Astro does not need it).
|
|
37
|
+
|
|
38
|
+
`astro add @purview-dev/astroc4` wires the **plain-Astro** shape for you: it
|
|
39
|
+
installs the package (and the non-optional peers) and writes
|
|
40
|
+
`integrations: [astroc4()]`, which works because the default export implements
|
|
41
|
+
the Astro integration protocol too. In a Starlight site the CLI cannot know
|
|
42
|
+
better — it writes the same thing — so move that call into
|
|
43
|
+
`starlight({ plugins: [astroc4()] })`; left in `integrations`, the diagrams still
|
|
44
|
+
render but the translated UI and LikeC4 highlighting do not, and the plugin warns
|
|
45
|
+
about it.
|
|
46
|
+
|
|
47
|
+
(`astro`'s integrations library indexes npm by keyword, and this package carries
|
|
48
|
+
`astro-integration` with `ui` for a category.)
|
|
28
49
|
|
|
29
50
|
Working on astroc4 itself? `bun add @purview-dev/astroc4@file:../path/to/astroc4` copies the
|
|
30
51
|
package into `node_modules`, so run `bun install` in the site again after
|
|
@@ -32,6 +53,8 @@ changing the plugin.
|
|
|
32
53
|
|
|
33
54
|
## Use
|
|
34
55
|
|
|
56
|
+
### With Starlight
|
|
57
|
+
|
|
35
58
|
```js
|
|
36
59
|
// astro.config.mjs
|
|
37
60
|
import starlight from '@astrojs/starlight';
|
|
@@ -39,7 +62,7 @@ import react from '@astrojs/react';
|
|
|
39
62
|
import astroc4 from '@purview-dev/astroc4';
|
|
40
63
|
|
|
41
64
|
export default defineConfig({
|
|
42
|
-
|
|
65
|
+
integrations: [starlight({ plugins: [astroc4()] }), react()],
|
|
43
66
|
});
|
|
44
67
|
```
|
|
45
68
|
|
|
@@ -49,6 +72,37 @@ import LikeC4View from '@purview-dev/astroc4/components/LikeC4View.astro';
|
|
|
49
72
|
<LikeC4View viewId="index" height={560} />
|
|
50
73
|
```
|
|
51
74
|
|
|
75
|
+
### With Astro (no Starlight)
|
|
76
|
+
|
|
77
|
+
```js
|
|
78
|
+
// astro.config.mjs
|
|
79
|
+
import { defineConfig } from 'astro/config';
|
|
80
|
+
import mdx from '@astrojs/mdx';
|
|
81
|
+
import expressiveCode from 'astro-expressive-code';
|
|
82
|
+
import astroc4 from '@purview-dev/astroc4/integration';
|
|
83
|
+
|
|
84
|
+
export default defineConfig({
|
|
85
|
+
// astroExpressiveCode() must come before mdx() — its own requirement.
|
|
86
|
+
integrations: [astroc4(), expressiveCode(), mdx()],
|
|
87
|
+
});
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
The page is the same `<LikeC4View>` import. Two things the site supplies:
|
|
91
|
+
`@astrojs/mdx` (` ```likec4 ` fences only become diagrams in `.mdx`), and
|
|
92
|
+
`astro-expressive-code` plus an `ec.config.mjs` that registers `likec4Language`
|
|
93
|
+
when you want ` ```c4 ` highlighted — Starlight has an `expressiveCode` option for
|
|
94
|
+
the plugin to fill in, Astro does not.
|
|
95
|
+
|
|
96
|
+
`react()` is **not** on that list: `astroc4()` adds `@astrojs/react` when the
|
|
97
|
+
site has no React renderer, because the islands are `client:only="react"` and
|
|
98
|
+
nothing renders without one. [Plain Astro](docs/wiki/guide/Plain-Astro.md) has
|
|
99
|
+
the full walkthrough, and [`examples/astro`](examples/astro) is a working site
|
|
100
|
+
with exactly this config (`bun run dev:astro`).
|
|
101
|
+
|
|
102
|
+
`astro add @purview-dev/astroc4` writes the `astroc4()` line for you in this
|
|
103
|
+
shape; you still add the other integrations (`astro add mdx
|
|
104
|
+
astro-expressive-code`) and the `ec.config.mjs`.
|
|
105
|
+
|
|
52
106
|
The plugin registers `LikeC4VitePlugin`, which compiles every
|
|
53
107
|
`likec4.config.json` project under the site root. Keep exactly the projects you
|
|
54
108
|
mean to render there: the first one found is the default for `<LikeC4View>`
|
|
@@ -61,12 +115,12 @@ silently replace your own.
|
|
|
61
115
|
| --- | --- | --- |
|
|
62
116
|
| `vitePlugin` | `{}` | Passed to `LikeC4VitePlugin`, e.g. `{ workspace: 'diagrams' }`. |
|
|
63
117
|
| `fences` | `true` | Turn ` ```likec4 ` fences into diagrams. |
|
|
64
|
-
| `highlighting` | `true` | Highlight LikeC4 source. See below. |
|
|
118
|
+
| `highlighting` | `true` | Highlight LikeC4 source. Starlight only — a plain Astro site uses `ec.config.mjs`. See below. |
|
|
65
119
|
|
|
66
120
|
### Syntax highlighting
|
|
67
121
|
|
|
68
|
-
|
|
69
|
-
`likec4/likec4`, derives a TextMate grammar from it, and registers that with
|
|
122
|
+
Under Starlight the plugin reads `packages/language-server/src/like-c4.langium`
|
|
123
|
+
from `likec4/likec4`, derives a TextMate grammar from it, and registers that with
|
|
70
124
|
the site's Expressive Code — so ` ```c4 ` fences, ` ```likec4 ` fences and
|
|
71
125
|
`<Code lang="likec4">` all highlight with no configuration. Highlighting
|
|
72
126
|
follows the language: when upstream adds a shape or a keyword, the next build
|
|
@@ -110,7 +164,7 @@ Fetched grammars are cached per `repo@ref`, so switching `ref` never thrashes
|
|
|
110
164
|
and repeated builds do not touch the network.
|
|
111
165
|
|
|
112
166
|
A site that already has an `ec.config.mjs` keeps working, and can pin the
|
|
113
|
-
bundled grammar there instead:
|
|
167
|
+
bundled grammar there instead — which is also what a plain Astro site does:
|
|
114
168
|
|
|
115
169
|
```js
|
|
116
170
|
// ec.config.mjs
|
|
@@ -150,20 +204,51 @@ absolute URL, or a file under the site's `public/` referenced by a path
|
|
|
150
204
|
relative to the `.c4` file. Don't use LikeC4's `imageAliases`: the compiler
|
|
151
205
|
bakes a build-machine `file://` path into the client bundle.
|
|
152
206
|
|
|
207
|
+
## Troubleshooting
|
|
208
|
+
|
|
209
|
+
**A green `astro build` is not proof that a diagram renders.** The islands are
|
|
210
|
+
`client:only` React, so a build can succeed while every frame stays on "Loading
|
|
211
|
+
architecture diagram…" — open the page in `astro dev`, or run
|
|
212
|
+
`bun scripts/smoke.ts` / `bun scripts/hydration.ts <url>` against it.
|
|
213
|
+
|
|
214
|
+
| Symptom | Cause | Fix |
|
|
215
|
+
| --- | --- | --- |
|
|
216
|
+
| `The requested module '/node_modules/react/compiler-runtime.js' does not provide an export named 'c'` in the console, diagrams stuck on the loading placeholder | `likec4/react` (1.59.4 and later) is compiled with the React Compiler and imports `c` from React 19's CommonJS `react/compiler-runtime`; in dev Vite serves it unoptimized, so the island never mounts. Production builds bundle it, which is why the build still passes. | Fixed in `1.0.0-prerelease.5`: the plugin adds `react/compiler-runtime` to `vite.optimizeDeps.include`. On an older version, or to confirm by hand: `vite: { optimizeDeps: { include: ['react/compiler-runtime'] } }`. |
|
|
217
|
+
| Build fails with `could not fetch the LikeC4 grammar from https://raw.githubusercontent.com/…` | The grammar is resolved while the config loads, and the machine cannot reach GitHub. | `highlighting: { offline: true }` (bundled snapshot) or `onError: 'warn'`; `ASTROC4_OFFLINE=1` in CI. |
|
|
218
|
+
| `<LikeC4View>` shows "Unknown LikeC4 projectId" | Every `.c4` project under the site root is compiled and the first is the default, so a vendored model can take over. | Keep only the projects you render, pass `projectId`, or point `vitePlugin.workspace` at one directory. |
|
|
219
|
+
| `Cannot find module …/@purview-dev/astroc4/dist/index.js` | That version shipped without its build output (only `1.0.0-prerelease.3` did). | Move to `1.0.0-prerelease.4` or later. |
|
|
220
|
+
|
|
221
|
+
Everything else — highlighting that produces one colour, fences left as code,
|
|
222
|
+
Windows module-runner crashes — is in
|
|
223
|
+
[Troubleshooting](docs/wiki/Troubleshooting.md).
|
|
224
|
+
|
|
153
225
|
## Develop
|
|
154
226
|
|
|
155
227
|
```sh
|
|
156
228
|
bun install
|
|
157
|
-
bun run dev # playground at http://localhost:4321 (English + French)
|
|
229
|
+
bun run dev # Starlight playground at http://localhost:4321 (English + French)
|
|
230
|
+
bun run dev:astro # plain-Astro example at http://localhost:4322
|
|
158
231
|
bun run test # hermetic unit suite: Langium parsing, grammar, fences, plugin
|
|
159
232
|
bun run test:network # the same, plus a check against the live likec4/likec4
|
|
160
|
-
bun run test:site # pack the tarball
|
|
161
|
-
|
|
233
|
+
bun run test:site # pack the tarball, install it into copies of playground/ and
|
|
234
|
+
# examples/astro/, build both, run the full smoke suite against
|
|
235
|
+
# the Starlight copy, and check the plain one hydrates
|
|
236
|
+
bun run check # astro check over playground/, examples/astro/ and src/
|
|
162
237
|
bun run grammar:check # fail if the committed grammar snapshot is stale
|
|
163
238
|
bun run build && bun run preview
|
|
239
|
+
bun run build:astro # static build of the plain-Astro example
|
|
164
240
|
bun scripts/smoke.ts http://localhost:4321 # headless: hydration, icons, highlighting, i18n
|
|
241
|
+
bun scripts/hydration.ts http://localhost:4321 # headless: one diagram, nothing else
|
|
165
242
|
```
|
|
166
243
|
|
|
244
|
+
`playground/` is the Starlight development site; `examples/astro/` is the
|
|
245
|
+
plain-Astro one, and `test:site` copies it so the checked-in example is what the
|
|
246
|
+
suite builds. Both import the package by name — Node's self-reference resolves
|
|
247
|
+
it from the repository, which *is* the package.
|
|
248
|
+
|
|
249
|
+
`test:site` and the two browser scripts need Chromium
|
|
250
|
+
(`bunx playwright install chromium`).
|
|
251
|
+
|
|
167
252
|
`Justfile` wraps each of those (`just verify` runs what the PR workflow runs).
|
|
168
253
|
`src/grammar/likec4.tmLanguage.json` and `src/grammar/like-c4.langium` are
|
|
169
254
|
generated — `bun run grammar:sync [--ref <tag>]` refreshes them from upstream,
|
|
@@ -173,7 +258,7 @@ CI lives in `.github/workflows`: `pr.yml` runs the organisation gate plus the
|
|
|
173
258
|
unit suite, the browser smoke test and the packed-consumer build; `release.yml`
|
|
174
259
|
publishes to npm with **trusted publishing** — an OIDC token, no stored npm
|
|
175
260
|
secret — under the `prerelease` dist-tag for prerelease versions, then tags the
|
|
176
|
-
release. See [`docs/wiki/Repository-CI-CD.md`](docs/wiki/Repository-CI-CD.md).
|
|
261
|
+
release. See [`docs/wiki/contributing/Repository-CI-CD.md`](docs/wiki/contributing/Repository-CI-CD.md).
|
|
177
262
|
|
|
178
263
|
Open the folder in VS Code and install the recommended **LikeC4** extension
|
|
179
264
|
for the language server: diagnostics, go-to-definition, hover and a live
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { LanguageRegistration } from 'shiki';
|
|
2
|
+
import { type GrammarSourceOptions } from './grammar/source.js';
|
|
3
|
+
/** Shiki registration for LikeC4, under `likec4` with a `c4` alias. */
|
|
4
|
+
export declare const likec4Language: LanguageRegistration & {
|
|
5
|
+
aliases: string[];
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Resolve the grammar from likec4/likec4 at the ref you ask for and return it
|
|
9
|
+
* as a Shiki language registration.
|
|
10
|
+
*/
|
|
11
|
+
export declare function loadLikeC4Language(options?: GrammarSourceOptions): Promise<LanguageRegistration & {
|
|
12
|
+
aliases: string[];
|
|
13
|
+
}>;
|
|
14
|
+
export default likec4Language;
|