@purview-dev/astroc4 1.0.0-prerelease.4 → 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/fences.d.ts +15 -1
- package/dist/index.d.ts +25 -10
- package/dist/index.js +118 -56
- package/dist/index.js.map +6 -5
- package/dist/integration.d.ts +37 -0
- package/dist/integration.js +261 -0
- package/dist/integration.js.map +11 -0
- package/package.json +17 -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
|
package/dist/fences.d.ts
CHANGED
|
@@ -28,5 +28,19 @@ export interface FenceMeta {
|
|
|
28
28
|
}
|
|
29
29
|
/** Parse `key="value"` / `key=value` pairs from the fence's meta string. */
|
|
30
30
|
export declare function parseFenceMeta(meta: string | null | undefined): FenceMeta;
|
|
31
|
-
|
|
31
|
+
/** Where a fence warning goes: the Astro logger in a site, `console` outside one. */
|
|
32
|
+
export interface FenceReporter {
|
|
33
|
+
warn: (message: string) => void;
|
|
34
|
+
}
|
|
35
|
+
/** What the fence transform needs to know about its host. */
|
|
36
|
+
export interface FenceOptions {
|
|
37
|
+
/** Where warnings go. Defaults to `console` with a `[likec4-fences]` label. */
|
|
38
|
+
reporter?: FenceReporter;
|
|
39
|
+
/**
|
|
40
|
+
* Whether the site has `@astrojs/mdx`, i.e. whether a `.mdx` page can exist.
|
|
41
|
+
* Defaults to `true`; `false` changes the advice a misplaced fence gets.
|
|
42
|
+
*/
|
|
43
|
+
mdx?: boolean;
|
|
44
|
+
}
|
|
45
|
+
export declare function likec4Fences({ reporter, mdx }?: FenceOptions): MdastPluginEntry;
|
|
32
46
|
export default likec4Fences;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import type { StarlightPlugin } from '@astrojs/starlight/types';
|
|
2
|
-
import {
|
|
2
|
+
import type { AstroIntegration } from 'astro';
|
|
3
|
+
import { missingOptimizedDependencies } from './integration.js';
|
|
4
|
+
import type { LikeC4IntegrationOptions } from './integration.js';
|
|
5
|
+
/**
|
|
6
|
+
* Re-exported for the Starlight entry point's callers and tests: the merge that
|
|
7
|
+
* keeps `react/compiler-runtime` in the site's optimized dependencies is part of
|
|
8
|
+
* both entry points' behaviour, and both are asserted against this function.
|
|
9
|
+
*/
|
|
10
|
+
export { missingOptimizedDependencies };
|
|
3
11
|
/**
|
|
4
12
|
* LikeC4 syntax highlighting, derived from the Langium grammar in
|
|
5
13
|
* `likec4/likec4` and registered with the site's Expressive Code.
|
|
@@ -32,21 +40,28 @@ export interface LikeC4HighlightingOptions {
|
|
|
32
40
|
/** Request timeout in milliseconds. Defaults to 15000. */
|
|
33
41
|
timeout?: number;
|
|
34
42
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
vitePlugin?: Parameters<typeof LikeC4VitePlugin>[0];
|
|
41
|
-
/** Render ```likec4 fences in .mdx pages as diagrams. Defaults to `true`. */
|
|
42
|
-
fences?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* The Starlight plugin's options: the integration's, plus the Starlight-only
|
|
45
|
+
* highlighting injection.
|
|
46
|
+
*/
|
|
47
|
+
export interface StarlightLikeC4Options extends LikeC4IntegrationOptions {
|
|
43
48
|
/**
|
|
44
49
|
* Highlight ```c4 / ```likec4 source. Defaults to `true`; `false` leaves
|
|
45
50
|
* Expressive Code entirely to the site.
|
|
46
51
|
*/
|
|
47
52
|
highlighting?: boolean | LikeC4HighlightingOptions;
|
|
48
53
|
}
|
|
49
|
-
|
|
54
|
+
/**
|
|
55
|
+
* The Starlight plugin **and** the Astro integration: one object, two hook sets.
|
|
56
|
+
*
|
|
57
|
+
* Starlight calls `config:setup` and `i18n:setup` on a plugin; Astro calls only
|
|
58
|
+
* `astro:*` hooks on something in `integrations`. Since the sets are disjoint,
|
|
59
|
+
* carrying both is safe — and it is what makes `astro add`'s automatic wiring
|
|
60
|
+
* (`integrations: [astroc4()]`, from the `astro-integration` keyword and the
|
|
61
|
+
* default export) produce a working site.
|
|
62
|
+
*/
|
|
63
|
+
export type LikeC4StarlightPlugin = StarlightPlugin & Pick<AstroIntegration, 'hooks'>;
|
|
64
|
+
export default function starlightLikeC4(options?: StarlightLikeC4Options): LikeC4StarlightPlugin;
|
|
50
65
|
/**
|
|
51
66
|
* Add the LikeC4 language to a site's Expressive Code options without
|
|
52
67
|
* disturbing anything already set.
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import { fileURLToPath as
|
|
2
|
+
import { fileURLToPath as fileURLToPath4 } from "node:url";
|
|
3
|
+
|
|
4
|
+
// src/integration.ts
|
|
5
|
+
import { createRequire as createRequire2 } from "node:module";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
3
8
|
import { LikeC4VitePlugin } from "likec4/vite-plugin";
|
|
4
9
|
|
|
5
10
|
// src/fences.ts
|
|
@@ -90,17 +95,21 @@ function describe(fileURL) {
|
|
|
90
95
|
return String(fileURL);
|
|
91
96
|
}
|
|
92
97
|
}
|
|
93
|
-
|
|
98
|
+
var CONSOLE_REPORTER = {
|
|
99
|
+
warn: (message) => console.warn(`[likec4-fences] ${message}`)
|
|
100
|
+
};
|
|
101
|
+
function likec4Fences({ reporter = CONSOLE_REPORTER, mdx = true } = {}) {
|
|
94
102
|
return (factory) => {
|
|
95
103
|
if (factory.sourceFormat !== "mdx") {
|
|
96
104
|
if (!factory.source.includes("```" + FENCE_LANG))
|
|
97
105
|
return null;
|
|
106
|
+
const fix = mdx ? "Rename the page to .mdx, or use <LikeC4View /> directly." : "Add @astrojs/mdx (`astro add mdx`) and rename the page to .mdx, or use <LikeC4View /> directly.";
|
|
98
107
|
return {
|
|
99
108
|
name: "likec4-fences:warn",
|
|
100
109
|
code(node, ctx) {
|
|
101
110
|
if (node.lang !== FENCE_LANG)
|
|
102
111
|
return;
|
|
103
|
-
|
|
112
|
+
reporter.warn(`${describe(ctx.fileURL)} has a \`\`\`${FENCE_LANG} fence, but fences only ` + `render as diagrams in .mdx files. ${fix}`);
|
|
104
113
|
}
|
|
105
114
|
};
|
|
106
115
|
}
|
|
@@ -162,11 +171,94 @@ function likec4Fences() {
|
|
|
162
171
|
};
|
|
163
172
|
}
|
|
164
173
|
|
|
174
|
+
// src/integration.ts
|
|
175
|
+
var PACKAGE_NAME2 = "@purview-dev/astroc4";
|
|
176
|
+
var OPTIMIZED_DEPENDENCIES = ["react/compiler-runtime"];
|
|
177
|
+
function missingOptimizedDependencies(include, root) {
|
|
178
|
+
const existing = Array.isArray(include) ? include : [];
|
|
179
|
+
return OPTIMIZED_DEPENDENCIES.filter((dependency) => !existing.includes(dependency) && resolvesFrom(dependency, root));
|
|
180
|
+
}
|
|
181
|
+
function resolvesFrom(specifier, root) {
|
|
182
|
+
try {
|
|
183
|
+
createRequire2(join(root, "package.json")).resolve(specifier);
|
|
184
|
+
return true;
|
|
185
|
+
} catch {
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
function likec4Integration({
|
|
190
|
+
vitePlugin = {},
|
|
191
|
+
fences = true
|
|
192
|
+
} = {}) {
|
|
193
|
+
return {
|
|
194
|
+
name: `${PACKAGE_NAME2}/integration`,
|
|
195
|
+
hooks: {
|
|
196
|
+
"astro:config:setup": async ({ command, config, updateConfig, logger }) => {
|
|
197
|
+
const optimizeDeps = missingOptimizedDependencies(config.vite?.optimizeDeps?.include, fileURLToPath2(config.root));
|
|
198
|
+
updateConfig({
|
|
199
|
+
vite: {
|
|
200
|
+
plugins: [LikeC4VitePlugin(vitePlugin)],
|
|
201
|
+
ssr: { noExternal: [PACKAGE_NAME2] },
|
|
202
|
+
...optimizeDeps.length > 0 ? { optimizeDeps: { include: optimizeDeps } } : {}
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
if (fences) {
|
|
206
|
+
await registerFences(config, updateConfig, logger);
|
|
207
|
+
}
|
|
208
|
+
await ensureReactRenderer(config, updateConfig, logger);
|
|
209
|
+
if (command === "build") {
|
|
210
|
+
await preloadLikeC4();
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
async function ensureReactRenderer(config, updateConfig, logger) {
|
|
217
|
+
if (config.integrations.some((integration) => integration.name === "@astrojs/react"))
|
|
218
|
+
return;
|
|
219
|
+
try {
|
|
220
|
+
const { default: react } = await import("@astrojs/react");
|
|
221
|
+
updateConfig({ integrations: [react()] });
|
|
222
|
+
logger.info('added @astrojs/react: the LikeC4 diagrams are React islands (client:only="react").');
|
|
223
|
+
} catch {
|
|
224
|
+
logger.warn("@astrojs/react is not installed, so <LikeC4View> cannot render. Install it (`astro add react`).");
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
async function registerFences(config, updateConfig, logger) {
|
|
228
|
+
const { satteri, isSatteriProcessor } = await import("@astrojs/markdown-satteri");
|
|
229
|
+
const existing = config.markdown?.processor;
|
|
230
|
+
const fences = () => {
|
|
231
|
+
const fenceLogger = logger.fork("likec4-fences");
|
|
232
|
+
return likec4Fences({
|
|
233
|
+
reporter: { warn: (message) => fenceLogger.warn(message) },
|
|
234
|
+
mdx: config.integrations.some((integration) => integration.name === "@astrojs/mdx")
|
|
235
|
+
});
|
|
236
|
+
};
|
|
237
|
+
if (existing === undefined) {
|
|
238
|
+
updateConfig({ markdown: { processor: satteri({ mdastPlugins: [fences()] }) } });
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
if (!isSatteriProcessor(existing)) {
|
|
242
|
+
logger.warn("```likec4 fences are disabled: the site is not using the Sätteri Markdown processor. " + "<LikeC4View /> still works.");
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
const existingOptions = existing.options ?? {};
|
|
246
|
+
updateConfig({
|
|
247
|
+
markdown: {
|
|
248
|
+
processor: satteri({
|
|
249
|
+
...existingOptions,
|
|
250
|
+
mdastPlugins: [...existingOptions.mdastPlugins ?? [], fences()]
|
|
251
|
+
})
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
var integration_default = likec4Integration;
|
|
256
|
+
|
|
165
257
|
// src/grammar/source.ts
|
|
166
258
|
import { createHash as createHash2 } from "node:crypto";
|
|
167
259
|
import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
|
|
168
|
-
import { join } from "node:path";
|
|
169
|
-
import { fileURLToPath as
|
|
260
|
+
import { join as join2 } from "node:path";
|
|
261
|
+
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
170
262
|
|
|
171
263
|
// src/grammar/langium.ts
|
|
172
264
|
var NOT_VALUE_DOMAINS = /Id$/;
|
|
@@ -877,7 +969,7 @@ function derive(langium, info) {
|
|
|
877
969
|
};
|
|
878
970
|
}
|
|
879
971
|
async function bundled(reason, options) {
|
|
880
|
-
const path = options.bundledLangiumPath ??
|
|
972
|
+
const path = options.bundledLangiumPath ?? fileURLToPath3(BUNDLED_LANGIUM);
|
|
881
973
|
const snapshot = await bundledProvenance();
|
|
882
974
|
const source = derive(await readFile(path, "utf8"), {
|
|
883
975
|
repo: snapshot.repo ?? DEFAULT_REPO,
|
|
@@ -889,7 +981,7 @@ async function bundled(reason, options) {
|
|
|
889
981
|
}
|
|
890
982
|
async function bundledProvenance() {
|
|
891
983
|
try {
|
|
892
|
-
const { $generated } = JSON.parse(await readFile(
|
|
984
|
+
const { $generated } = JSON.parse(await readFile(fileURLToPath3(BUNDLED_GRAMMAR), "utf8"));
|
|
893
985
|
return { repo: $generated?.repo, ref: $generated?.ref };
|
|
894
986
|
} catch {
|
|
895
987
|
return {};
|
|
@@ -938,9 +1030,9 @@ async function fetchLangiumSource(options) {
|
|
|
938
1030
|
return { text, etag: response.headers.get("etag") ?? undefined };
|
|
939
1031
|
}
|
|
940
1032
|
function cachePath(options, identity) {
|
|
941
|
-
const dir = options.cacheDir ??
|
|
1033
|
+
const dir = options.cacheDir ?? join2(options.root ?? process.cwd(), "node_modules", ".cache", "astroc4");
|
|
942
1034
|
const key = createHash2("sha256").update(`${identity.repo}@${identity.ref}`).digest("hex").slice(0, 16);
|
|
943
|
-
return
|
|
1035
|
+
return join2(dir, `grammar-${key}.json`);
|
|
944
1036
|
}
|
|
945
1037
|
async function readCache(options, identity) {
|
|
946
1038
|
let raw;
|
|
@@ -964,7 +1056,7 @@ async function writeCache(options, identity, entry) {
|
|
|
964
1056
|
const path = cachePath(options, identity);
|
|
965
1057
|
const temporary = `${path}.${process.pid}.tmp`;
|
|
966
1058
|
try {
|
|
967
|
-
await mkdir(
|
|
1059
|
+
await mkdir(join2(path, ".."), { recursive: true });
|
|
968
1060
|
await writeFile(temporary, JSON.stringify({
|
|
969
1061
|
version: CACHE_VERSION,
|
|
970
1062
|
repo: identity.repo,
|
|
@@ -1005,20 +1097,25 @@ var translations = {
|
|
|
1005
1097
|
};
|
|
1006
1098
|
|
|
1007
1099
|
// src/index.ts
|
|
1008
|
-
var PACKAGE_NAME2 = "@purview-dev/astroc4";
|
|
1009
1100
|
function starlightLikeC4(options = {}) {
|
|
1101
|
+
const integration = likec4Integration({ vitePlugin: options.vitePlugin, fences: options.fences });
|
|
1010
1102
|
return {
|
|
1011
1103
|
name: PACKAGE_NAME2,
|
|
1012
1104
|
hooks: {
|
|
1105
|
+
...integration.hooks,
|
|
1106
|
+
"astro:config:setup": async (arguments_) => {
|
|
1107
|
+
warnIfMiswired(arguments_);
|
|
1108
|
+
await integration.hooks["astro:config:setup"]?.(arguments_);
|
|
1109
|
+
},
|
|
1013
1110
|
"i18n:setup"({ injectTranslations }) {
|
|
1014
1111
|
injectTranslations(translations);
|
|
1015
1112
|
},
|
|
1016
1113
|
async "config:setup"({ config, astroConfig, updateConfig, addIntegration, logger }) {
|
|
1017
|
-
addIntegration(
|
|
1114
|
+
addIntegration(integration);
|
|
1018
1115
|
if (options.highlighting === false)
|
|
1019
1116
|
return;
|
|
1020
1117
|
await injectHighlighting({
|
|
1021
|
-
root:
|
|
1118
|
+
root: fileURLToPath4(astroConfig.root),
|
|
1022
1119
|
expressiveCode: config.expressiveCode,
|
|
1023
1120
|
updateConfig,
|
|
1024
1121
|
logger,
|
|
@@ -1028,6 +1125,12 @@ function starlightLikeC4(options = {}) {
|
|
|
1028
1125
|
}
|
|
1029
1126
|
};
|
|
1030
1127
|
}
|
|
1128
|
+
function warnIfMiswired({ config, logger }) {
|
|
1129
|
+
const starlight = config.integrations.some((integration) => integration.name === "@astrojs/starlight");
|
|
1130
|
+
if (!starlight)
|
|
1131
|
+
return;
|
|
1132
|
+
logger.warn(`${PACKAGE_NAME2} is in \`integrations\`, so this Starlight site gets diagrams only. ` + "Move astroc4() into `starlight({ plugins: [astroc4()] })` to get the translated UI and LikeC4 syntax highlighting.");
|
|
1133
|
+
}
|
|
1031
1134
|
async function injectHighlighting({
|
|
1032
1135
|
root,
|
|
1033
1136
|
expressiveCode,
|
|
@@ -1074,52 +1177,11 @@ function isLikeC4Language(entry) {
|
|
|
1074
1177
|
function isObject(value) {
|
|
1075
1178
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1076
1179
|
}
|
|
1077
|
-
function likec4Integration({ vitePlugin = {}, fences = true }) {
|
|
1078
|
-
return {
|
|
1079
|
-
name: `${PACKAGE_NAME2}/integration`,
|
|
1080
|
-
hooks: {
|
|
1081
|
-
"astro:config:setup": async ({ command, config, updateConfig, logger }) => {
|
|
1082
|
-
updateConfig({
|
|
1083
|
-
vite: {
|
|
1084
|
-
plugins: [LikeC4VitePlugin(vitePlugin)],
|
|
1085
|
-
ssr: { noExternal: [PACKAGE_NAME2] }
|
|
1086
|
-
}
|
|
1087
|
-
});
|
|
1088
|
-
if (fences) {
|
|
1089
|
-
await registerFences(config, updateConfig, logger);
|
|
1090
|
-
}
|
|
1091
|
-
if (command === "build") {
|
|
1092
|
-
await preloadLikeC4();
|
|
1093
|
-
}
|
|
1094
|
-
}
|
|
1095
|
-
}
|
|
1096
|
-
};
|
|
1097
|
-
}
|
|
1098
|
-
async function registerFences(config, updateConfig, logger) {
|
|
1099
|
-
const { satteri, isSatteriProcessor } = await import("@astrojs/markdown-satteri");
|
|
1100
|
-
const existing = config.markdown?.processor;
|
|
1101
|
-
if (existing === undefined) {
|
|
1102
|
-
updateConfig({ markdown: { processor: satteri({ mdastPlugins: [likec4Fences()] }) } });
|
|
1103
|
-
return;
|
|
1104
|
-
}
|
|
1105
|
-
if (!isSatteriProcessor(existing)) {
|
|
1106
|
-
logger.warn("```likec4 fences are disabled: the site is not using the Sätteri Markdown processor. " + "<LikeC4View /> still works.");
|
|
1107
|
-
return;
|
|
1108
|
-
}
|
|
1109
|
-
const existingOptions = existing.options ?? {};
|
|
1110
|
-
updateConfig({
|
|
1111
|
-
markdown: {
|
|
1112
|
-
processor: satteri({
|
|
1113
|
-
...existingOptions,
|
|
1114
|
-
mdastPlugins: [...existingOptions.mdastPlugins ?? [], likec4Fences()]
|
|
1115
|
-
})
|
|
1116
|
-
}
|
|
1117
|
-
});
|
|
1118
|
-
}
|
|
1119
1180
|
export {
|
|
1120
1181
|
starlightLikeC4 as default,
|
|
1182
|
+
missingOptimizedDependencies,
|
|
1121
1183
|
withLikeC4Language
|
|
1122
1184
|
};
|
|
1123
1185
|
|
|
1124
|
-
//# debugId=
|
|
1186
|
+
//# debugId=0517D2E2C36FC4B664756E2164756E21
|
|
1125
1187
|
//# sourceMappingURL=index.js.map
|