tosijs-ui 1.6.19 → 1.6.21

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.
@@ -25,6 +25,18 @@ import { buildEpub } from './epub';
25
25
  // Module specifiers contain regex metacharacters (`/`, `.`, `@`, …), so escape
26
26
  // before interpolating into the require-shim detector below.
27
27
  const escapeRegExp = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
28
+ // Externalize the tjs CodeMirror editor extension ONLY when tjs-lang isn't
29
+ // installed — otherwise it's bundled in so it shares the editor's CodeMirror
30
+ // instance (see the `external` comment in buildSite). Returns [] when present.
31
+ function tjsEditorExternal(root) {
32
+ try {
33
+ Bun.resolveSync('tjs-lang/editors/codemirror', root);
34
+ return [];
35
+ }
36
+ catch {
37
+ return ['tjs-lang/editors/codemirror'];
38
+ }
39
+ }
28
40
  export async function buildSite(config) {
29
41
  const PROJECT_ROOT = './';
30
42
  const PUBLIC = path.resolve(PROJECT_ROOT, config.outputDir ?? 'docs');
@@ -97,7 +109,17 @@ export async function buildSite(config) {
97
109
  console.time('build');
98
110
  // Optionally also build the library (ESM + type declarations) — for repos
99
111
  // whose single build publishes both an npm package and its doc site.
100
- if (config.libraryTsconfig) {
112
+ if (config.libraryBuild) {
113
+ // Full override — the consumer owns emitting dist/*.js + *.d.ts for ALL
114
+ // sources (e.g. tsc for `.ts` + `tjs convert`/`generateDTS` for native `.tjs`
115
+ // that tsc can't compile). See BUILD-TJS-HOOK.md.
116
+ await config.libraryBuild({
117
+ dist: DIST,
118
+ root: path.resolve(PROJECT_ROOT),
119
+ tsconfig: config.libraryTsconfig,
120
+ });
121
+ }
122
+ else if (config.libraryTsconfig) {
101
123
  // Consumer-controlled library build (handles root noEmit, removeComments,
102
124
  // outDir, etc.).
103
125
  try {
@@ -127,12 +149,20 @@ export async function buildSite(config) {
127
149
  format: 'iife',
128
150
  minify: true,
129
151
  naming: scriptName,
130
- // tjs-lang transpiles live examples; it's dynamically import()'d at
131
- // runtime (falling back to CDN), so keep it out of the bundle.
152
+ // tjs-lang's TRANSPILER (browser bundles) is dynamically import()'d at
153
+ // runtime (same-origin `/tjs/` copy, else CDN), so keep it out of the bundle.
154
+ //
155
+ // `tjs-lang/editors/codemirror` (the CodeMirror language + autocomplete) is
156
+ // different: it MUST share the editor's CodeMirror instance, so it has to be
157
+ // bundled IN — a separately loaded copy carries its own `@codemirror/state`
158
+ // and silently no-ops. So we do NOT externalize it *when tjs-lang is
159
+ // installed*. But tjs-lang is an OPTIONAL peer; if it's absent, bundling would
160
+ // fail to resolve, so we externalize it in that case (the runtime import then
161
+ // no-ops to plain TS highlighting — graceful degradation).
132
162
  external: [
133
- 'tjs-lang',
134
163
  'tjs-lang/browser',
135
164
  'tjs-lang/browser/from-ts',
165
+ ...tjsEditorExternal(PROJECT_ROOT),
136
166
  ...(config.bundleExternals ?? []),
137
167
  ],
138
168
  });
@@ -258,7 +288,13 @@ export async function buildSite(config) {
258
288
  const genCss = existsSync(genCssTs)
259
289
  ? genCssTs
260
290
  : `${import.meta.dir}/generate-css.js`;
261
- await $ `bun ${genCss} ${PUBLIC}/doc-system.css ${JSON.stringify(config.theme || {})}`.text();
291
+ // generate-css imports the consumer's library to burn the theme; when that graph
292
+ // reaches non-`.ts` sources (e.g. `.tjs`), `--preload` a module that registers the
293
+ // Bun loader plugin so those modules evaluate. (See BUILD-TJS-HOOK.md.)
294
+ const themeArg = JSON.stringify(config.theme || {});
295
+ await (config.generateCssPreload
296
+ ? $ `bun --preload ${config.generateCssPreload} ${genCss} ${PUBLIC}/doc-system.css ${themeArg}`
297
+ : $ `bun ${genCss} ${PUBLIC}/doc-system.css ${themeArg}`).text();
262
298
  console.log(`generated ${pageCount} static pages`);
263
299
  // ── host preset files ──
264
300
  // Idempotent, and an explicit static file (copied from staticDirs) always wins.
@@ -3,6 +3,15 @@ import type { DocSystemTheme } from '../doc-system-styles';
3
3
  import type { Doc } from './docs';
4
4
  import type { BookManifest } from '../book-manifest';
5
5
  export type SiteHost = 'github-pages' | 'firebase' | 'static';
6
+ /** Resolved paths handed to a `libraryBuild` override (see SiteConfig). */
7
+ export interface LibraryBuildContext {
8
+ /** absolute path to the `dist` output dir the artifacts must land in */
9
+ dist: string;
10
+ /** project root the build runs from */
11
+ root: string;
12
+ /** the configured `libraryTsconfig`, if any (so the override can still run tsc) */
13
+ tsconfig?: string;
14
+ }
6
15
  export interface SiteConfig {
7
16
  /** project / brand name — header, <title> suffix, og:site_name */
8
17
  name: string;
@@ -103,6 +112,25 @@ export interface SiteConfig {
103
112
  * yourself (e.g. keep doc comments in the published JS for AI readers).
104
113
  */
105
114
  libraryTsconfig?: string;
115
+ /**
116
+ * Fully override the library build (the `tsc` step that `libraryTsconfig` /
117
+ * `emitLibrary` run). Receives the resolved paths and is responsible for emitting
118
+ * `dist/*.js` + `*.d.ts` for ALL sources. Use this when some sources aren't `.ts`
119
+ * — e.g. native tjs-lang `.tjs` modules, which `tsc` can't compile: run `tsc` for
120
+ * the `.ts` graph and `tjs convert` + `generateDTS` for the `.tjs` files, into the
121
+ * same `dist`. Takes precedence over `libraryTsconfig` and `emitLibrary`. Pairs
122
+ * with `generateCssPreload` (below) for the CSS-extraction eval. See
123
+ * BUILD-TJS-HOOK.md.
124
+ */
125
+ libraryBuild?: (ctx: LibraryBuildContext) => void | Promise<void>;
126
+ /**
127
+ * A module to `--preload` into the CSS-extraction subprocess (`generate-css`),
128
+ * which imports your library to burn the theme stylesheet. Needed when that import
129
+ * graph reaches non-`.ts` sources (e.g. `.tjs`) that require a Bun loader plugin
130
+ * to evaluate — point this at a module that registers it (via `Bun.plugin({...})`
131
+ * at import time). Without it the subprocess throws `Cannot find module './x.tjs'`.
132
+ */
133
+ generateCssPreload?: string;
106
134
  /**
107
135
  * Emit llms.txt agent-discoverability index. Default true (uses `name` /
108
136
  * `description` / `baseUrl` / `projectLinks`). Set false to skip, or pass a