@ng-doc/builder 22.0.0 → 22.1.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.
Files changed (85) hide show
  1. package/engine/builders/helpers/get-playground-metadata.js +7 -1
  2. package/engine/builders/helpers/get-playground-metadata.js.map +1 -1
  3. package/engine/builders/page/demo-assets.builder.js +2 -0
  4. package/engine/builders/page/demo-assets.builder.js.map +1 -1
  5. package/engine/builders/shared/content.builder.js +2 -0
  6. package/engine/builders/shared/content.builder.js.map +1 -1
  7. package/engine/builders/shared/page-wrapper.builder.js +2 -0
  8. package/engine/builders/shared/page-wrapper.builder.js.map +1 -1
  9. package/generator/bootstrap/bin.js +27 -3
  10. package/generator/bootstrap/cli.js +27 -3
  11. package/generator/bootstrap/index.js +17 -3
  12. package/generator/build-metafile.json +529 -221
  13. package/generator/build-provenance.json +6 -4
  14. package/generator/compiler/index.d.ts +20 -0
  15. package/generator/compiler/index.js +1875 -625
  16. package/generator/compiler/plan.d.ts +24 -0
  17. package/generator/content/code-snippet.d.ts +20 -0
  18. package/generator/content/content-compiler.d.ts +5 -1
  19. package/generator/content/format-cache.d.ts +108 -0
  20. package/generator/content/highlight-cache.d.ts +12 -36
  21. package/generator/content/html-pipeline.d.ts +10 -1
  22. package/generator/content/html-pool.d.ts +8 -2
  23. package/generator/content/html-worker.js +622 -39
  24. package/generator/contracts.d.ts +39 -0
  25. package/generator/discovery/index.d.ts +2 -0
  26. package/generator/kernel/flags.d.ts +2 -0
  27. package/generator/outputs/index.d.ts +13 -0
  28. package/generator/semantic/angular.d.ts +21 -1
  29. package/generator/semantic/formatting.d.ts +27 -0
  30. package/generator/semantic/fragments.d.ts +11 -2
  31. package/generator/templates/api/class-declaration.html.nunj +5 -3
  32. package/generator/templates/demo-app.ts.nunj +37 -0
  33. package/generator/templates/demo-routes.ts.nunj +23 -0
  34. package/generator/templates/index.ts.nunj +5 -0
  35. package/generator/templates/page-wrapper.ts.nunj +6 -1
  36. package/generator/templates/page.ts.nunj +9 -2
  37. package/generator/templates/routes.ts.nunj +7 -3
  38. package/generator/templates/symbol/members.html.nunj +6 -4
  39. package/generator/templates/symbol/page.html.nunj +1 -1
  40. package/generator/vite/application-builder.js +6 -1
  41. package/generator/vite/application.d.ts +14 -0
  42. package/generator/vite/demo-application.d.ts +34 -0
  43. package/generator/vite/dev-server-builder.js +6 -1
  44. package/generator/vite/host-updates.d.ts +69 -2
  45. package/generator/vite/index.js +490 -130
  46. package/generator/vite/lifecycle.d.ts +1 -0
  47. package/generator/vite/prerender-entry.js +72 -2
  48. package/generator/vite/prerender-runtime.d.ts +13 -0
  49. package/generator/vite/prerender.d.ts +2 -0
  50. package/helpers/format-cache.d.ts +34 -0
  51. package/helpers/format-cache.js +26 -0
  52. package/helpers/format-cache.js.map +1 -0
  53. package/helpers/format-code.js +9 -2
  54. package/helpers/format-code.js.map +1 -1
  55. package/helpers/to-template-string.d.ts +5 -1
  56. package/helpers/to-template-string.js +7 -2
  57. package/helpers/to-template-string.js.map +1 -1
  58. package/interfaces/code-block-options.d.ts +5 -0
  59. package/interfaces/configuration.d.ts +84 -1
  60. package/package.json +5 -4
  61. package/parsers/parse-code-block-params.d.ts +10 -1
  62. package/parsers/parse-code-block-params.js +29 -3
  63. package/parsers/parse-code-block-params.js.map +1 -1
  64. package/schematics/collection.json +1 -1
  65. package/schematics/migrate-to-vite/analyze.js +46 -3
  66. package/schematics/migrate-to-vite/analyze.js.map +1 -1
  67. package/schematics/migrate-to-vite/setup/workspace.d.ts +5 -0
  68. package/schematics/migrate-to-vite/setup/workspace.js +20 -0
  69. package/schematics/migrate-to-vite/setup/workspace.js.map +1 -1
  70. package/schematics/migrate-to-vite/testing/fixtures.d.ts +12 -0
  71. package/schematics/migrate-to-vite/testing/fixtures.js +27 -0
  72. package/schematics/migrate-to-vite/testing/fixtures.js.map +1 -1
  73. package/schematics/vite-setup/index.d.ts +9 -5
  74. package/schematics/vite-setup/index.js +11 -5
  75. package/schematics/vite-setup/index.js.map +1 -1
  76. package/schematics/vite-setup/schema.json +1 -1
  77. package/templates/api/class-declaration.html.nunj +5 -3
  78. package/templates/demo-app.ts.nunj +37 -0
  79. package/templates/demo-routes.ts.nunj +23 -0
  80. package/templates/index.ts.nunj +5 -0
  81. package/templates/page-wrapper.ts.nunj +6 -1
  82. package/templates/page.ts.nunj +9 -2
  83. package/templates/routes.ts.nunj +7 -3
  84. package/templates/symbol/members.html.nunj +6 -4
  85. package/templates/symbol/page.html.nunj +1 -1
@@ -111,6 +111,7 @@ export declare class ViteAdapterLifecycle {
111
111
  private reconcile;
112
112
  private fail;
113
113
  private report;
114
+ private warn;
114
115
  private isCurrent;
115
116
  private log;
116
117
  private interrupt;
@@ -301,13 +301,82 @@ async function runPrerender(request, options = {}) {
301
301
  errors.push({ route: current, message: format(...args) });
302
302
  log.apply(console, args);
303
303
  };
304
+ const warnings = [];
304
305
  try {
305
- return { ...await renderRoutes(), errors };
306
+ const report = await renderRoutes();
307
+ if (request.demoServerEntry) report.routes = await renderDemoRoutes(report.routes);
308
+ return { ...report, errors, ...warnings.length ? { warnings } : {} };
306
309
  } finally {
307
310
  console.error = log;
308
311
  restoreWarnings();
309
312
  globalThis.fetch = originalFetch;
310
313
  }
314
+ async function renderDemoRoutes(rendered) {
315
+ const shellFile2 = path2.join(browserDir, DEMO_SHELL);
316
+ const message = (error) => error instanceof Error ? error.message : String(error);
317
+ let demoDocument;
318
+ let demo;
319
+ let inventory;
320
+ current = `/${DEMO_SHELL}`;
321
+ try {
322
+ demoDocument = await readFile(shellFile2, "utf8");
323
+ demo = serverEntry(
324
+ await importModule(pathToFileURL(path2.resolve(request.demoServerEntry)).href)
325
+ );
326
+ await withTimeout(
327
+ demo.renderApplication(
328
+ async (context) => {
329
+ const application = await demo.bootstrap(context);
330
+ const router = application.injector.get(demo.Router);
331
+ inventory = await enumerateRoutes(Array.isArray(router?.config) ? router.config : [], {
332
+ invoke: (factory) => demo.runInInjectionContext(application.injector, factory)
333
+ });
334
+ return application;
335
+ },
336
+ { document: demoDocument, url: url("/"), allowedHosts: [HOST] }
337
+ ),
338
+ request.routeTimeoutMs,
339
+ current
340
+ );
341
+ } catch (error) {
342
+ warnings.push({
343
+ route: current,
344
+ message: `[NGDOC_PRERENDER_DEMO_APPLICATION] The demo pages were not prerendered: ${message(error)}`
345
+ });
346
+ return rendered;
347
+ }
348
+ const taken = new Set(rendered.map((route) => route.path));
349
+ const result = [...rendered];
350
+ for (const route of inventory.routes) {
351
+ if (route.redirectTo !== void 0 || taken.has(route.path)) continue;
352
+ const file = routeFile(route.path);
353
+ current = route.path;
354
+ let html;
355
+ try {
356
+ html = await withTimeout(
357
+ demo.renderApplication(demo.bootstrap, {
358
+ document: demoDocument,
359
+ url: url(route.path),
360
+ allowedHosts: [HOST]
361
+ }),
362
+ request.routeTimeoutMs,
363
+ route.path
364
+ );
365
+ } catch (error) {
366
+ warnings.push({
367
+ route: route.path,
368
+ message: `[NGDOC_PRERENDER_DEMO_FALLBACK] The demo page did not render on the server, so it renders in the browser only: ${message(error)}`
369
+ });
370
+ html = demoDocument;
371
+ }
372
+ await mkdir(path2.dirname(path2.join(browserDir, file)), { recursive: true });
373
+ await writeFile(path2.join(browserDir, file), html);
374
+ result.push({ ...route, file });
375
+ }
376
+ return result.sort(
377
+ (left, right) => left.path < right.path ? -1 : left.path > right.path ? 1 : 0
378
+ );
379
+ }
311
380
  async function renderRoutes() {
312
381
  const discovered = [];
313
382
  const excluded = [];
@@ -374,13 +443,14 @@ function runPrerenderChild(port, run = runPrerender) {
374
443
  );
375
444
  });
376
445
  }
377
- var SHELL, HOST;
446
+ var SHELL, DEMO_SHELL, HOST;
378
447
  var init_prerender_runtime = __esm({
379
448
  "libs/builder/generator/vite/prerender-runtime.ts"() {
380
449
  "use strict";
381
450
  init_mime();
382
451
  init_route_inventory();
383
452
  SHELL = "index.csr.html";
453
+ DEMO_SHELL = "ng-doc-demo.html";
384
454
  HOST = "localhost";
385
455
  }
386
456
  });
@@ -11,6 +11,11 @@ export interface PrerenderRequest {
11
11
  discoverRoutes: boolean;
12
12
  /** Fails a route that takes longer to render, in milliseconds. */
13
13
  routeTimeoutMs?: number;
14
+ /**
15
+ * The server bundle of the demo application (`demo-server.mjs`), when the build has demo pages.
16
+ * Its routes are rendered into the demo application's page (`ng-doc-demo.html`).
17
+ */
18
+ demoServerEntry?: string;
14
19
  }
15
20
  export interface PrerenderReport {
16
21
  /** Every rendered route, in code-unit order, with the file written for it. */
@@ -26,6 +31,14 @@ export interface PrerenderReport {
26
31
  route: string;
27
32
  message: string;
28
33
  }>;
34
+ /**
35
+ * Demo pages that failed to render, which got the demo application's client page instead, and
36
+ * a demo application that could not be prerendered at all. Absent when there are none.
37
+ */
38
+ warnings?: Array<{
39
+ route: string;
40
+ message: string;
41
+ }>;
29
42
  }
30
43
  export interface PrerenderRuntimeOptions {
31
44
  /** Imports the server bundle; tests replace it. */
@@ -12,6 +12,8 @@ export interface NgDocPrerenderOptions {
12
12
  discoverRoutes?: boolean;
13
13
  /** Fails a route that takes longer to render, in milliseconds (default: no limit). */
14
14
  routeTimeoutMs?: number;
15
+ /** The demo application's server bundle (`demo-server.mjs`), when the build has demo pages. */
16
+ demoServerEntry?: string;
15
17
  signal?: AbortSignal;
16
18
  /** The child process entry; tests replace it. */
17
19
  entryUrl?: URL;
@@ -0,0 +1,34 @@
1
+ import type { Options } from 'prettier';
2
+ /**
3
+ * A cache that `formatCode` consults while it is installed with {@link withFormatCodeCache}. The
4
+ * new engine installs one around its own formatting calls; without one (the legacy engine, the
5
+ * kill switch, the reference path) `formatCode` resolves the configuration and formats every
6
+ * call, as it always did.
7
+ */
8
+ export interface FormatCodeCache {
9
+ /**
10
+ * The Prettier configuration for `configDirectory`. `resolve` reads it; the cache may call it
11
+ * once and return that value for later calls. An error of `resolve` is thrown to the caller.
12
+ */
13
+ config(configDirectory: string | undefined, resolve: () => Options | null): Options | null;
14
+ /**
15
+ * The formatted code. `format` formats it; the cache may return a value it stored for the same
16
+ * code, parser and configuration instead. An error of `format` is thrown; the cache may store a
17
+ * Prettier syntax error (deterministic for these inputs) and throw one again on a hit, so
18
+ * `formatCode` returns the code unformatted in both cases.
19
+ */
20
+ format(input: {
21
+ code: string;
22
+ parser: string;
23
+ config: Options | null;
24
+ }, format: () => string): string;
25
+ }
26
+ /**
27
+ * Runs `run` with `cache` installed for every `formatCode` call it makes synchronously, and
28
+ * restores the previous one afterwards.
29
+ * @param cache The cache to install, or undefined for none.
30
+ * @param run The synchronous work that formats.
31
+ */
32
+ export declare function withFormatCodeCache<T>(cache: FormatCodeCache | undefined, run: () => T): T;
33
+ /** The cache installed by {@link withFormatCodeCache}, if any. */
34
+ export declare function activeFormatCodeCache(): FormatCodeCache | undefined;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.withFormatCodeCache = withFormatCodeCache;
4
+ exports.activeFormatCodeCache = activeFormatCodeCache;
5
+ let active;
6
+ /**
7
+ * Runs `run` with `cache` installed for every `formatCode` call it makes synchronously, and
8
+ * restores the previous one afterwards.
9
+ * @param cache The cache to install, or undefined for none.
10
+ * @param run The synchronous work that formats.
11
+ */
12
+ function withFormatCodeCache(cache, run) {
13
+ const previous = active;
14
+ active = cache;
15
+ try {
16
+ return run();
17
+ }
18
+ finally {
19
+ active = previous;
20
+ }
21
+ }
22
+ /** The cache installed by {@link withFormatCodeCache}, if any. */
23
+ function activeFormatCodeCache() {
24
+ return active;
25
+ }
26
+ //# sourceMappingURL=format-cache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-cache.js","sourceRoot":"","sources":["../../../../libs/builder/helpers/format-cache.ts"],"names":[],"mappings":";;AAkCA,kDAQC;AAGD,sDAEC;AArBD,IAAI,MAAmC,CAAC;AAExC;;;;;GAKG;AACH,SAAgB,mBAAmB,CAAI,KAAkC,EAAE,GAAY;IACrF,MAAM,QAAQ,GAAG,MAAM,CAAC;IACxB,MAAM,GAAG,KAAK,CAAC;IACf,IAAI,CAAC;QACH,OAAO,GAAG,EAAE,CAAC;IACf,CAAC;YAAS,CAAC;QACT,MAAM,GAAG,QAAQ,CAAC;IACpB,CAAC;AACH,CAAC;AAED,kEAAkE;AAClE,SAAgB,qBAAqB;IACnC,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -4,6 +4,7 @@ exports.formatCode = formatCode;
4
4
  const tslib_1 = require("tslib");
5
5
  const sync_1 = tslib_1.__importDefault(require("@prettier/sync"));
6
6
  const node_path_1 = require("node:path");
7
+ const format_cache_1 = require("./format-cache");
7
8
  /**
8
9
  * Format code with Prettier
9
10
  * @param code - Code to format
@@ -14,14 +15,20 @@ function formatCode(code, codeType = 'TypeScript', configDirectory) {
14
15
  try {
15
16
  if (codeType) {
16
17
  const parser = getPrettierParserFromCodeType(codeType);
17
- const config = sync_1.default.resolveConfig(
18
+ // The new engine's cache, when it formats (see `./format-cache`); none in the legacy engine.
19
+ const cache = (0, format_cache_1.activeFormatCodeCache)();
20
+ const resolve = () => sync_1.default.resolveConfig(
18
21
  // Prettier searches from a file's parent, so use a synthetic path inside the directory.
19
22
  configDirectory ? (0, node_path_1.join)(configDirectory, '__ng_doc_format__.ts') : process.cwd(), { editorconfig: true, useCache: false });
20
- return sync_1.default.format(code, {
23
+ const config = cache ? cache.config(configDirectory, resolve) : resolve();
24
+ const format = () => sync_1.default.format(code, {
21
25
  ...config,
22
26
  parser,
23
27
  embeddedLanguageFormatting: 'auto',
24
28
  }).trim();
29
+ return cache && typeof parser === 'string'
30
+ ? cache.format({ code, parser, config }, format)
31
+ : format();
25
32
  }
26
33
  return code.trim();
27
34
  }
@@ -1 +1 @@
1
- {"version":3,"file":"format-code.js","sourceRoot":"","sources":["../../../../libs/builder/helpers/format-code.ts"],"names":[],"mappings":";;AAWA,gCA2BC;;AArCD,kEAA0C;AAC1C,yCAAiC;AAGjC;;;;;GAKG;AACH,SAAgB,UAAU,CACxB,IAAY,EACZ,WAAiC,YAAY,EAC7C,eAAwB;IAExB,IAAI,CAAC;QACH,IAAI,QAAQ,EAAE,CAAC;YACb,MAAM,MAAM,GAAkC,6BAA6B,CAAC,QAAQ,CAAC,CAAC;YACtF,MAAM,MAAM,GAAG,cAAY,CAAC,aAAa;YACvC,wFAAwF;YACxF,eAAe,CAAC,CAAC,CAAC,IAAA,gBAAI,EAAC,eAAe,EAAE,sBAAsB,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,EAC/E,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,CACxC,CAAC;YAEF,OACE,cAAY,CAAC,MAAM,CAAC,IAAI,EAAE;gBACxB,GAAG,MAAM;gBACT,MAAM;gBACN,0BAA0B,EAAE,MAAM;aACnC,CACF,CAAC,IAAI,EAAE,CAAC;QACX,CAAC;QAED,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC;IACrB,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,SAAS,6BAA6B,CAAC,QAAuB;IAC5D,QAAQ,QAAQ,EAAE,CAAC;QACjB,KAAK,KAAK,CAAC;QACX,KAAK,MAAM,CAAC;QACZ,KAAK,MAAM,CAAC;QACZ,KAAK,MAAM;YACT,OAAO,KAAK,CAAC;QACf,KAAK,MAAM;YACT,OAAO,MAAM,CAAC;QAChB,KAAK,YAAY,CAAC;QAClB,KAAK,YAAY;YACf,OAAO,YAAY,CAAC;QACtB,KAAK,UAAU;YACb,OAAO,UAAU,CAAC;QACpB;YACE,OAAO,SAAS,CAAC;IACrB,CAAC;AACH,CAAC"}
1
+ {"version":3,"file":"format-code.js","sourceRoot":"","sources":["../../../../libs/builder/helpers/format-code.ts"],"names":[],"mappings":";;AAaA,gCAmCC;;AA/CD,kEAA0C;AAC1C,yCAAiC;AAGjC,iDAAuD;AAEvD;;;;;GAKG;AACH,SAAgB,UAAU,CACxB,IAAY,EACZ,WAAi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AK,MAAM,CAAC;QACZ,KAAK,MAAM;YACT,OAAO,KAAK,CAAC;QACf,KAAK,MAAM;YACT,OAAO,MAAM,CAAC;QAChB,KAAK,YAAY,CAAC;QAClB,KAAK,YAAY;YACf,OAAO,YAAY,CAAC;QACtB,KAAK,UAAU;YACb,OAAO,UAAU,CAAC;QACpB;YACE,OAAO,SAAS,CAAC;IACrB,CAAC;AACH,CAAC"}
@@ -1,5 +1,9 @@
1
1
  /**
2
+ * Escapes text for the body of a template literal, so the literal evaluates to the text itself.
2
3
  *
3
- * @param content
4
+ * The backslash is escaped first: otherwise `\d` would evaluate to `d`, `\n` to a line break and
5
+ * `\203A` would fail to compile (octal escapes are not allowed in template literals), and the
6
+ * escapes added for `` ` `` and `${` must not be escaped again.
7
+ * @param content - The text to embed.
4
8
  */
5
9
  export declare function toTemplateString(content: string): string;
@@ -2,12 +2,17 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.toTemplateString = toTemplateString;
4
4
  /**
5
+ * Escapes text for the body of a template literal, so the literal evaluates to the text itself.
5
6
  *
6
- * @param content
7
+ * The backslash is escaped first: otherwise `\d` would evaluate to `d`, `\n` to a line break and
8
+ * `\203A` would fail to compile (octal escapes are not allowed in template literals), and the
9
+ * escapes added for `` ` `` and `${` must not be escaped again.
10
+ * @param content - The text to embed.
7
11
  */
8
12
  function toTemplateString(content) {
9
13
  return (content
10
- ?.replace(/`/g, '\\`')
14
+ ?.replace(/\\/g, '\\\\')
15
+ .replace(/`/g, '\\`')
11
16
  .replace(/\${/g, '\\${')
12
17
  .replace(/{/g, '\\{')
13
18
  .replace(/}/g, '\\}') ?? '');
@@ -1 +1 @@
1
- {"version":3,"file":"to-template-string.js","sourceRoot":"","sources":["../../../../libs/builder/helpers/to-template-string.ts"],"names":[],"mappings":";;AAIA,4CAQC;AAZD;;;GAGG;AACH,SAAgB,gBAAgB,CAAC,OAAe;IAC/C,OAAO,CACN,OAAO;QACN,EAAE,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC;SACrB,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC;SACvB,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC;SACpB,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAC5B,CAAC;AACH,CAAC"}
1
+ {"version":3,"file":"to-template-string.js","sourceRoot":"","sources":["../../../../libs/builder/helpers/to-template-string.ts"],"names":[],"mappings":";;AAQA,4CASC;AAjBD;;;;;;;GAOG;AACH,SAAgB,gBAAgB,CAAC,OAAe;IAC9C,OAAO,CACL,OAAO;QACL,EAAE,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC;SACvB,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC;SACpB,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC;SACvB,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC;SACpB,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAC9B,CAAC;AACJ,CAAC"}
@@ -8,5 +8,10 @@ export interface NgDocCodeBlockParams {
8
8
  icon?: string;
9
9
  fileLineStart?: number;
10
10
  fileLineEnd?: number;
11
+ /**
12
+ * The snippet of `file` to show, from `file="./x.ts"#<id>`: the lines between the two
13
+ * `snippet#<id>` markers. Only the Vite engine reads it.
14
+ */
15
+ snippet?: string;
11
16
  highlightedLines?: number[];
12
17
  }
@@ -1,4 +1,4 @@
1
- import { NgDocHeading, NgDocKeywordsLoader } from '@ng-doc/core';
1
+ import { NgDocDemoProvidersImport, NgDocHeading, NgDocKeywordsLoader } from '@ng-doc/core';
2
2
  import { NgDocGlobalKeyword } from '@ng-doc/core/interfaces/keyword-map';
3
3
  import { NgDocRepoConfig } from './repo-config';
4
4
  /**
@@ -43,6 +43,30 @@ export interface NgDocConfiguration {
43
43
  * The configuration for the guides
44
44
  */
45
45
  guide?: NgDocGuideConfiguration;
46
+ /**
47
+ * The configuration for the API pages. Only the Vite engine reads it.
48
+ */
49
+ api?: NgDocApiConfiguration;
50
+ /**
51
+ * Shows every demo of the `demo` action in an iframe, as `isolated: true` does for one demo
52
+ * (`false` by default). It also builds a demo page for every demo. Only the Vite engine reads it.
53
+ */
54
+ isolatedDemos?: boolean;
55
+ /**
56
+ * The demo pages: one page per demo that loads only Angular and that demo, which isolated demos
57
+ * show in an iframe and "Open in new tab" opens. Only the Vite engine builds them.
58
+ *
59
+ * By default only the pages with an isolated demo get them. `true` (or an object) builds them for
60
+ * every page with demos; `false` never builds them, and isolated demos render in the page.
61
+ */
62
+ demoApplication?: boolean | NgDocDemoApplicationConfiguration;
63
+ /**
64
+ * Imports the module whose default export lists the providers of the demo pages, for example
65
+ * `() => import('./demo.providers')`. It must be written in `ng-doc.config.ts` as an arrow
66
+ * function that returns one `import()` of a file. NgDoc never calls it while it generates; the
67
+ * demo pages import the module. Only the Vite engine reads it.
68
+ */
69
+ demoProviders?: NgDocDemoProvidersImport;
46
70
  /**
47
71
  * Shiki configuration
48
72
  */
@@ -51,8 +75,43 @@ export interface NgDocConfiguration {
51
75
  light: string;
52
76
  dark: string;
53
77
  };
78
+ /**
79
+ * Shiki language registrations that code blocks can use in addition to the languages bundled
80
+ * with Shiki, such as a grammar imported from a `.tmLanguage.json` file or from
81
+ * `@shikijs/langs`. A registration named like a bundled language replaces it. Only the Vite
82
+ * engine reads it; load the same languages in the browser with `provideNgDocApp`.
83
+ */
84
+ langs?: Array<NgDocShikiLanguage | readonly NgDocShikiLanguage[]>;
54
85
  };
55
86
  }
87
+ /**
88
+ * A Shiki (TextMate) language registration: a grammar and the name that code blocks use for it.
89
+ * It must be plain JSON data, as in a `.tmLanguage.json` file or a module of `@shikijs/langs`.
90
+ */
91
+ export interface NgDocShikiLanguage {
92
+ /** The language name: code blocks that name it (for example ` ```my-lang `) use the grammar. */
93
+ name: string;
94
+ /** The root scope of the grammar, such as `source.my-lang`. */
95
+ scopeName: string;
96
+ /** The name to display for the language. */
97
+ displayName?: string;
98
+ /** Other names that code blocks can use for the language. */
99
+ aliases?: string[];
100
+ /** The languages that the grammar embeds, which must be bundled or registered too. */
101
+ embeddedLangs?: string[];
102
+ /** The languages that the grammar embeds when they are loaded. */
103
+ embeddedLangsLazy?: string[];
104
+ /** The scopes that the grammar injects itself into. */
105
+ injectTo?: string[];
106
+ /** The TextMate rules of the grammar. */
107
+ patterns?: unknown;
108
+ /** The named TextMate rules that `patterns` include. */
109
+ repository?: unknown;
110
+ /** TextMate injections. */
111
+ injections?: unknown;
112
+ /** The selector of an injection grammar. */
113
+ injectionSelector?: string;
114
+ }
56
115
  /**
57
116
  * The configuration for the guide page
58
117
  */
@@ -67,6 +126,30 @@ export interface NgDocGuideConfiguration {
67
126
  */
68
127
  headerTemplate?: string;
69
128
  }
129
+ /**
130
+ * The configuration for the API pages.
131
+ */
132
+ export interface NgDocApiConfiguration {
133
+ /**
134
+ * Whether API pages list the protected members of classes, inherited ones included
135
+ * (`true` by default). With `false`, they list only public members: hidden members get no row,
136
+ * anchor, search record or keyword.
137
+ */
138
+ protectedMembers?: boolean;
139
+ }
140
+ /**
141
+ * The configuration of the demo pages.
142
+ */
143
+ export interface NgDocDemoApplicationConfiguration {
144
+ /**
145
+ * The URL path under which the demo pages are served, relative to the base href
146
+ * (`demo-preview` by default): a demo's page is `<base href><path>/<page route>/<demo name>/`.
147
+ * One or more URL segments of letters, digits, `-`, `_` and `.`; the first character of a
148
+ * segment is a letter or a digit, because some static hosts skip folders that start with `_`
149
+ * or `.`.
150
+ */
151
+ path?: string;
152
+ }
70
153
  /**
71
154
  * The configuration for the global keywords.
72
155
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ng-doc/builder",
3
- "version": "22.0.0",
3
+ "version": "22.1.0",
4
4
  "description": "Generates an NgDoc documentation site from your Markdown pages and TypeScript code.",
5
5
  "keywords": [
6
6
  "angular",
@@ -31,8 +31,8 @@
31
31
  ]
32
32
  },
33
33
  "dependencies": {
34
- "@ng-doc/core": "22.0.0",
35
- "@ng-doc/utils": "22.0.0",
34
+ "@ng-doc/core": "22.1.0",
35
+ "@ng-doc/utils": "22.1.0",
36
36
  "@angular-devkit/architect": ">=0.2200.0 <0.2300.0",
37
37
  "minimatch": "9.0.9",
38
38
  "rxjs": "^7.0.0",
@@ -56,7 +56,8 @@
56
56
  "parsimmon": "^1.18.1",
57
57
  "@parcel/watcher": "^2.5.0",
58
58
  "@microsoft/tsdoc": "0.15.1",
59
- "@shikijs/rehype": "1.10.3",
59
+ "@shikijs/rehype": "4.5.0",
60
+ "shiki": "4.5.0",
60
61
  "css-what": "6.1.0",
61
62
  "github-slugger": "2.0.0",
62
63
  "hast-util-has-property": "3.0.0",
@@ -1,6 +1,15 @@
1
1
  import type { NgDocCodeBlockParams } from '../interfaces/code-block-options';
2
+ /** Options of {@link parseCodeBlockParams}. */
3
+ export interface NgDocCodeBlockParserOptions {
4
+ /**
5
+ * Whether a fragment after the `file` parameter may name a snippet: `file="./x.ts"#greeting`.
6
+ * Without it, only line ranges are accepted, and any other fragment fails to parse.
7
+ */
8
+ snippets?: boolean;
9
+ }
2
10
  /**
3
11
  * Code block options parser
4
12
  * @param options - Options string to parse
13
+ * @param parserOptions - What the caller supports beyond the original syntax.
5
14
  */
6
- export declare function parseCodeBlockParams(options: string): NgDocCodeBlockParams;
15
+ export declare function parseCodeBlockParams(options: string, parserOptions?: NgDocCodeBlockParserOptions): NgDocCodeBlockParams;
@@ -10,11 +10,31 @@ const helpers_1 = require("./helpers");
10
10
  * whitespace end it, so the parameters that follow are parsed as before.
11
11
  */
12
12
  const CODE_BLOCK_LANGUAGE = /[\p{L}\p{N}+#-]+/u;
13
+ /** The characters of a snippet id, as `// snippet#<id>` markers spell it (`parseSnippet`). */
14
+ const SNIPPET_ID = /[a-zA-Z0-9-]+/;
15
+ /** A fragment that is a line range: `L<n>`, `L<n>-` or `L<n>-L<m>`. */
16
+ const LINE_RANGE = /^L(\d+)(?:(-)(?:L(\d+))?)?$/;
17
+ /**
18
+ * The fragment after a `file` parameter when snippets are on: `#L<n>`, `#L<n>-` and
19
+ * `#L<n>-L<m>` are line ranges (the same ranges as without snippets), any other id names a
20
+ * snippet.
21
+ * @param fragment - The fragment without its `#`.
22
+ */
23
+ function fileFragment(fragment) {
24
+ const range = LINE_RANGE.exec(fragment);
25
+ if (!range)
26
+ return { snippet: fragment };
27
+ const fileLineStart = Number(range[1]) - 1;
28
+ if (!range[2])
29
+ return { fileLineStart, fileLineEnd: fileLineStart + 1 };
30
+ return { fileLineStart, fileLineEnd: range[3] === undefined ? undefined : Number(range[3]) };
31
+ }
13
32
  /**
14
33
  * Code block options parser
15
34
  * @param options - Options string to parse
35
+ * @param parserOptions - What the caller supports beyond the original syntax.
16
36
  */
17
- function parseCodeBlockParams(options) {
37
+ function parseCodeBlockParams(options, parserOptions = {}) {
18
38
  const parser = parsimmon_1.default.createLanguage({
19
39
  language: () => parsimmon_1.default.regexp(CODE_BLOCK_LANGUAGE)
20
40
  .skip(parsimmon_1.default.optWhitespace)
@@ -28,7 +48,9 @@ function parseCodeBlockParams(options) {
28
48
  .then(p['fileLineNumber'])
29
49
  .map((num) => num - 1)
30
50
  .map((fileLineStart) => ({ fileLineStart, fileLineEnd: fileLineStart + 1 })),
31
- lineParams: (p) => p['fileLineRange'].or(p['fileLineStart']).fallback({}),
51
+ lineParams: (p) => (parserOptions.snippets
52
+ ? parsimmon_1.default.string('#').then(parsimmon_1.default.regexp(SNIPPET_ID)).map(fileFragment)
53
+ : p['fileLineRange'].or(p['fileLineStart'])).fallback({}),
32
54
  highlightedLinesRange: () => parsimmon_1.default.seqMap(helpers_1.number.skip(parsimmon_1.default.string('-')), helpers_1.number, (start, end) => [...Array(end + 1).keys()].slice(start - end - 1)),
33
55
  // Main Parsers
34
56
  lineNumbers: () => parsimmon_1.default.string('lineNumbers').map(() => ({ lineNumbers: true })),
@@ -38,7 +60,11 @@ function parseCodeBlockParams(options) {
38
60
  fileName: () => (0, helpers_1.param)('fileName', 'name'),
39
61
  icon: () => (0, helpers_1.param)('icon'),
40
62
  active: () => parsimmon_1.default.string('active').map(() => ({ active: true })),
41
- file: (p) => parsimmon_1.default.seq(p['filePath'], p['lineParams'].map(({ fileLineStart, fileLineEnd }) => ({ fileLineStart, fileLineEnd }))).map(([file, lineParams]) => ({ ...file, ...lineParams })),
63
+ file: (p) => parsimmon_1.default.seq(p['filePath'], p['lineParams'].map(({ fileLineStart, fileLineEnd, snippet }) => ({
64
+ fileLineStart,
65
+ fileLineEnd,
66
+ ...(snippet === undefined ? {} : { snippet }),
67
+ }))).map(([file, lineParams]) => ({ ...file, ...lineParams })),
42
68
  highlightedLines: (p) => p['highlightedLinesRange']
43
69
  .or(helpers_1.number)
44
70
  .sepBy(parsimmon_1.default.string(',').then(parsimmon_1.default.optWhitespace))
@@ -1 +1 @@
1
- {"version":3,"file":"parse-code-block-params.js","sourceRoot":"","sources":["../../../../libs/builder/parsers/parse-code-block-params.ts"],"names":[],"mappings":";;AAgBA,oDAkFC;;AAlGD,kEAA0B;AAG1B,uCAA0C;AAE1C;;;;GAIG;AACH,MAAM,mBAAmB,GAAW,mBAAmB,CAAC;AAExD;;;GAGG;AACH,SAAgB,oBAAoB,CAAC,OAAe;IAClD,MAAM,MAAM,GAAG,mBAAC,CAAC,cAAc,CAAC;QAC9B,QAAQ,EAAE,GAAG,EAAE,CACb,mBAAC,CAAC,MAAM,CAAC,mBAAmB,CAAC;aAC1B,IAAI,CAAC,mBAAC,CAAC,aAAa,CAAC;aACrB,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC;QACtC,eAAe;QACf,cAAc,EAAE,GAAG,EAAE,CAAC,mBAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,mBAAC,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC;QAC9D,aAAa,EAAE,CAAC,CAAC,EAAE,EAAE,CACnB,mBAAC,CAAC,MAAM,CACN,mBAAC,CAAC,MAAM,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AAE,GAAG,GAAG,EAAE,GAAG,GAAG,EAAE,CAAC,EACvF,EAAE,CACH,CAAC;IACJ,CAAC;IAED,MAAM,GAAG,MAAM,CAAC,0BAA0B,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAE3D,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;QAClB,OAAO,MAAM,CAAC,KAAK,CAAC,MAAM,CACxB,CAAC,GAAyB,EAAE,GAAkC,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,GAAG,EAAE,GAAG,GAAG,EAAE,CAAC,EACvF,EAAE,CACH,CAAC;IACJ,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,wCAAwC,OAAO,GAAG,CAAC,CAAC;AACtE,CAAC"}
1
+ {"version":3,"file":"parse-code-block-params.js","sourceRoot":"","sources":["../../../../libs/builder/parsers/parse-code-block-params.ts"],"names":[],"mappings":";;AA8CA,oDA6FC;;AA3ID,kEAA0B;AAG1B,uCAA0C;AAE1C;;;;GAIG;AACH,MAAM,mBAAmB,GAAW,mBAAmB,CAAC;AAExD,8FAA8F;AAC9F,MAAM,UAAU,GAAW,eAAe,CAAC;AAE3C,uEAAuE;AACvE,MAAM,UAAU,GAAW,6BAA6B,CAAC;AAWzD;;;;;GAKG;AACH,SAAS,YAAY,CAAC,QAAgB;IACpC,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACxC,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;IACzC,MAAM,aAAa,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IAC3C,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QAAE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,aAAa,GAAG,CAAC,EAAE,CAAC;IACxE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC,CAAC,KAAK,SAAS,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AC,MAAM,CACxB,CAAC,GAAyB,EAAE,GAAkC,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,GAAG,EAAE,GAAG,GAAG,EAAE,CAAC,EACvF,EAAE,CACH,CAAC;IACJ,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,wCAAwC,OAAO,GAAG,CAAC,CAAC;AACtE,CAAC"}
@@ -22,7 +22,7 @@
22
22
  "schema": "./migrate-to-vite/schema.json"
23
23
  },
24
24
  "vite-setup": {
25
- "description": "Sets up the Vite engine for a project on Angular's application builder (run by ng add @ng-doc/add)",
25
+ "description": "Sets up the Vite engine for a project on Angular's application builder or Nx's application executor (run by ng add @ng-doc/add)",
26
26
  "factory": "./vite-setup/index#viteSetup",
27
27
  "schema": "./vite-setup/schema.json",
28
28
  "hidden": true
@@ -106,7 +106,15 @@ const MANUAL = {
106
106
  serviceWorker: 'The Vite engine does not build the Angular service worker.',
107
107
  subresourceIntegrity: 'Use a Vite plugin to add `integrity` attributes.',
108
108
  webWorkerTsConfig: 'Vite bundles workers created with `new Worker(new URL(...))` itself.',
109
+ // Nx's `application` executor runs Angular's builder with these options of its own.
110
+ indexHtmlTransformer: 'Nx transforms index.html with this function; move it to a Vite plugin with a `transformIndexHtml` hook.',
111
+ plugins: 'Nx runs these esbuild plugins and Vite does not; add a Vite plugin that does the same to the Vite configuration.',
109
112
  };
113
+ /**
114
+ * `buildLibsFromSource: false` of Nx's executors: Nx builds the buildable libraries first and
115
+ * resolves them to their output.
116
+ */
117
+ const BUILD_LIBS_FROM_SOURCE = 'is `false`; the Vite engine reads the workspace libraries from source through the tsconfig `paths` and does not build them first.';
110
118
  function isRecord(value) {
111
119
  return typeof value === 'object' && value !== null && !Array.isArray(value);
112
120
  }
@@ -526,11 +534,17 @@ function analyzeProject(tree, project, buildName, serveName, options, builderKey
526
534
  else
527
535
  add('dropped', 'build.outputHashing', 'Vite hashes the output file names by default.');
528
536
  }
529
- else if (option === 'scripts') {
537
+ else if (option === 'scripts' || option === 'plugins') {
530
538
  if (values.some((value) => Array.isArray(value) && value.length))
531
- add('manual', 'build.scripts', MANUAL['scripts']);
539
+ add('manual', `build.${option}`, MANUAL[option]);
540
+ else
541
+ add('dropped', `build.${option}`, 'The list is empty.');
542
+ }
543
+ else if (option === 'buildLibsFromSource') {
544
+ if (values.includes(false))
545
+ add('manual', 'build.buildLibsFromSource', BUILD_LIBS_FROM_SOURCE);
532
546
  else
533
- add('dropped', 'build.scripts', 'The list is empty.');
547
+ add('dropped', 'build.buildLibsFromSource', 'The Vite engine reads the workspace libraries from source through the tsconfig `paths`.');
534
548
  }
535
549
  else if (option === 'serviceWorker') {
536
550
  if (active.length)
@@ -744,6 +758,35 @@ function analyzeServe(project, serveName, buildName, build, add, plainMode) {
744
758
  case 'verbose':
745
759
  add('dropped', subject, 'Vite prebundles dependencies and logs by its own settings.');
746
760
  break;
761
+ // The options Nx's `dev-server` executor adds to Angular's.
762
+ case 'buildLibsFromSource':
763
+ if (value === false)
764
+ add('manual', subject, BUILD_LIBS_FROM_SOURCE);
765
+ else
766
+ add('dropped', subject, 'The Vite engine reads the workspace libraries from source.');
767
+ break;
768
+ case 'watchDependencies':
769
+ add('dropped', subject, 'The Vite engine watches the library sources it reads.');
770
+ break;
771
+ case 'forceEsbuild':
772
+ case 'publicHost':
773
+ add('dropped', subject, 'Nx uses it with webpack-based builds only.');
774
+ break;
775
+ case 'disableHostCheck':
776
+ if (value === true) {
777
+ devServer.allowedHosts = true;
778
+ add('migrated', subject, 'Vite `server.allowedHosts: true`.');
779
+ }
780
+ else
781
+ add('dropped', subject, 'The host check is on.');
782
+ break;
783
+ case 'esbuildMiddleware':
784
+ if (Array.isArray(value) && value.length) {
785
+ add('manual', subject, 'Add these middleware functions with the `configureServer` hook of a Vite plugin.');
786
+ }
787
+ else
788
+ add('dropped', subject, 'The list is empty.');
789
+ break;
747
790
  case 'ngDoc':
748
791
  add('manual', subject, 'The development server uses the NgDoc settings of the build target.');
749
792
  break;