@travetto/doc 3.4.2 → 4.0.0-rc.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/doc",
3
- "version": "3.4.2",
3
+ "version": "4.0.0-rc.0",
4
4
  "description": "Documentation support for the Travetto framework",
5
5
  "keywords": [
6
6
  "docs",
@@ -24,12 +24,13 @@
24
24
  "directory": "module/doc"
25
25
  },
26
26
  "dependencies": {
27
- "@travetto/base": "^3.4.1",
27
+ "@travetto/base": "^4.0.0-rc.0",
28
+ "@travetto/terminal": "^4.0.0-rc.0",
28
29
  "@types/prismjs": "^1.26.3",
29
30
  "prismjs": "^1.29.0"
30
31
  },
31
32
  "peerDependencies": {
32
- "@travetto/cli": "^3.4.6"
33
+ "@travetto/cli": "^4.0.0-rc.0"
33
34
  },
34
35
  "peerDependenciesMeta": {
35
36
  "@travetto/cli": {
@@ -39,6 +39,7 @@ export const LIB_MAPPING = {
39
39
  UUID: { title: 'UUID', href: 'https://en.wikipedia.org/wiki/Universally_unique_identifier' },
40
40
 
41
41
  // Node
42
+ Process: { title: 'process', href: 'https://nodejs.org/api/process.html' },
42
43
  ChildProcess: { title: 'child_process', href: 'https://nodejs.org/api/child_process.html' },
43
44
  AsyncHooks: { title: 'async_hooks', href: 'https://nodejs.org/api/async_hooks.html' },
44
45
  Http: { title: 'http', href: 'https://nodejs.org/api/http.html' },
@@ -1,6 +1,6 @@
1
1
  import { createElement, JSXRuntimeTag } from '@travetto/doc/jsx-runtime';
2
2
 
3
- import { PackageUtil, path, RootIndex } from '@travetto/manifest';
3
+ import { PackageUtil, path, RuntimeIndex } from '@travetto/manifest';
4
4
 
5
5
  import { JSXElementByFn, c } from '../jsx';
6
6
  import { DocResolveUtil, ResolvedCode, ResolvedRef, ResolvedSnippetLink } from '../util/resolve';
@@ -35,12 +35,12 @@ export class RenderContext {
35
35
 
36
36
  constructor(file: string, baseUrl: string, repoRoot: string) {
37
37
 
38
- const manifestPkg = PackageUtil.readPackage(RootIndex.getModule('@travetto/manifest')!.sourcePath);
38
+ const manifestPkg = PackageUtil.readPackage(RuntimeIndex.getModule('@travetto/manifest')!.sourcePath);
39
39
 
40
40
  this.file = path.toPosix(file);
41
41
  this.baseUrl = baseUrl;
42
42
  this.repoRoot = repoRoot;
43
- this.travettoBaseUrl = repoRoot.includes('travetto.github') ? repoRoot : manifestPkg.travetto!.docBaseUrl!;
43
+ this.travettoBaseUrl = repoRoot.includes('travetto.github') ? repoRoot : manifestPkg.travetto!.doc!.baseUrl!;
44
44
  }
45
45
 
46
46
  /**
@@ -105,7 +105,7 @@ export class RenderContext {
105
105
  * Resolve code link
106
106
  */
107
107
  async resolveCodeLink(node: JSXElementByFn<'CodeLink'>): Promise<ResolvedSnippetLink> {
108
- const src = typeof node.props.src === 'string' ? node.props.src : RootIndex.getFunctionMetadata(node.props.src)!.source;
108
+ const src = typeof node.props.src === 'string' ? node.props.src : RuntimeIndex.getFunctionMetadata(node.props.src)!.source;
109
109
  return DocResolveUtil.resolveCodeLink(src, node.props.startRe);
110
110
  }
111
111
 
@@ -113,7 +113,7 @@ export class RenderContext {
113
113
  * Resolve code/config
114
114
  */
115
115
  async resolveCode(node: JSXElementByFn<'Code' | 'Config'>): Promise<ResolvedCode> {
116
- const src = typeof node.props.src === 'string' ? node.props.src : RootIndex.getFunctionMetadata(node.props.src)!.source;
116
+ const src = typeof node.props.src === 'string' ? node.props.src : RuntimeIndex.getFunctionMetadata(node.props.src)!.source;
117
117
  return node.props.startRe ?
118
118
  DocResolveUtil.resolveSnippet(src, node.props.startRe, node.props.endRe, node.props.outline) :
119
119
  DocResolveUtil.resolveCode(src, node.props.language, node.props.outline);
@@ -1,7 +1,7 @@
1
- import fs from 'fs/promises';
1
+ import fs from 'node:fs/promises';
2
2
 
3
3
  import { JSXElement } from '@travetto/doc/jsx-runtime';
4
- import { RootIndex, PackageUtil } from '@travetto/manifest';
4
+ import { RuntimeIndex, PackageUtil, RuntimeContext } from '@travetto/manifest';
5
5
 
6
6
  import { highlight } from './code-highlight';
7
7
  import { RenderProvider, RenderState } from '../types';
@@ -144,8 +144,8 @@ yarn add ${el.props.pkg}
144
144
  Header: async ({ props }) => `<h1>${props.title} ${props.description ? `\n<small>${props.description}</small>\n` : ''}</h1>\n`,
145
145
 
146
146
  StdHeader: async state => {
147
- const mod = state.el.props.mod ?? RootIndex.mainModuleName;
148
- const pkg = PackageUtil.readPackage(RootIndex.getModule(mod)!.sourcePath);
147
+ const mod = state.el.props.mod ?? RuntimeContext.main.name;
148
+ const pkg = PackageUtil.readPackage(RuntimeIndex.getModule(mod)!.sourcePath);
149
149
  const title = pkg.travetto?.displayName ?? pkg.name;
150
150
  const desc = pkg.description;
151
151
  let install = '';
@@ -1,5 +1,5 @@
1
- import fs from 'fs/promises';
2
- import { PackageUtil, RootIndex } from '@travetto/manifest';
1
+ import fs from 'node:fs/promises';
2
+ import { PackageUtil, RuntimeIndex, RuntimeContext } from '@travetto/manifest';
3
3
 
4
4
  import { RenderProvider } from '../types';
5
5
  import { c, getComponentName } from '../jsx';
@@ -108,8 +108,8 @@ ${context.cleanText(content.text)}
108
108
  Header: async ({ props }) => `# ${props.title}\n${props.description ? `## ${props.description}\n` : ''}\n`,
109
109
 
110
110
  StdHeader: async state => {
111
- const mod = state.el.props.mod ?? RootIndex.mainModuleName;
112
- const pkg = PackageUtil.readPackage(RootIndex.getModule(mod)!.sourcePath);
111
+ const mod = state.el.props.mod ?? RuntimeContext.main.name;
112
+ const pkg = PackageUtil.readPackage(RuntimeIndex.getModule(mod)!.sourcePath);
113
113
  const title = pkg.travetto?.displayName ?? pkg.name;
114
114
  const desc = pkg.description;
115
115
  let install = '';
@@ -1,6 +1,6 @@
1
- import { ManifestRoot, PackageUtil, path, RootIndex } from '@travetto/manifest';
1
+ import { ManifestContext, PackageUtil, path, RuntimeIndex } from '@travetto/manifest';
2
2
 
3
- import { isJSXElement, JSXElement, createFragment, JSXFragmentType } from '@travetto/doc/jsx-runtime';
3
+ import { isJSXElement, JSXElement, JSXFragmentType } from '@travetto/doc/jsx-runtime';
4
4
 
5
5
  import { EMPTY_ELEMENT, getComponentName, JSXElementByFn, c } from '../jsx';
6
6
  import { DocumentShape, RenderProvider, RenderState } from '../types';
@@ -17,16 +17,15 @@ const providers = { [Html.ext]: Html, [Markdown.ext]: Markdown };
17
17
  */
18
18
  export class DocRenderer {
19
19
 
20
- static async get(file: string, manifest: ManifestRoot): Promise<DocRenderer> {
21
- const mod = RootIndex.getFromSource(file)?.import;
20
+ static async get(file: string, manifest: ManifestContext): Promise<DocRenderer> {
21
+ const mod = RuntimeIndex.getFromSource(file)?.import;
22
22
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
23
23
  const res = await import(mod!) as DocumentShape;
24
24
 
25
- const pkg = PackageUtil.readPackage(manifest.workspacePath);
26
- const mainPath = path.resolve(manifest.workspacePath, manifest.mainFolder);
27
- const repoBaseUrl = pkg.travetto?.docBaseUrl ?? mainPath;
25
+ const pkg = PackageUtil.readPackage(manifest.workspace.path);
26
+ const repoBaseUrl = pkg.travetto?.doc?.baseUrl ?? manifest.workspace.path;
28
27
  return new DocRenderer(res,
29
- new RenderContext(file, repoBaseUrl, path.resolve(pkg.travetto?.docRoot ?? manifest.workspacePath))
28
+ new RenderContext(file, repoBaseUrl, path.resolve(pkg.travetto?.doc?.root ?? manifest.workspace.path))
30
29
  );
31
30
  }
32
31
 
@@ -62,7 +61,7 @@ export class DocRenderer {
62
61
  final = out !== EMPTY_ELEMENT ? out : final;
63
62
  }
64
63
 
65
- if (final.type === createFragment || final.type === JSXFragmentType) {
64
+ if (final.type === JSXFragmentType) {
66
65
  return this.#render(renderer, final.props.children ?? []);
67
66
  }
68
67
 
@@ -91,7 +90,7 @@ export class DocRenderer {
91
90
  case 'bigint':
92
91
  case 'boolean': return `${node}`;
93
92
  default: {
94
- const meta = (typeof node === 'function' ? RootIndex.getFunctionMetadata(node) : undefined);
93
+ const meta = (typeof node === 'function' ? RuntimeIndex.getFunctionMetadata(node) : undefined);
95
94
  if (meta && typeof node === 'function') {
96
95
  const title = (await DocFileUtil.isDecorator(node.name, meta.source)) ? `@${node.name}` : node.name;
97
96
  const el = this.#support.createElement('CodeLink', {
package/src/util/file.ts CHANGED
@@ -1,8 +1,9 @@
1
- import fs from 'fs/promises';
1
+ import fs from 'node:fs/promises';
2
2
 
3
- import { ManifestModuleUtil, path, RootIndex } from '@travetto/manifest';
3
+ import { ManifestModuleUtil, path, RuntimeIndex } from '@travetto/manifest';
4
4
 
5
- const ESLINT_PATTERN = /\s*\/\/ eslint.*$/;
5
+ const ESLINT_PATTERN = /\s*\/\/ eslint.*$/g;
6
+ const ENV_KEY = /Env.([^.]+)[.]key/g;
6
7
 
7
8
  /**
8
9
  * Standard file utilities
@@ -31,7 +32,7 @@ export class DocFileUtil {
31
32
  let resolved = path.resolve(file);
32
33
  if (!(await fs.stat(resolved).catch(() => false))) {
33
34
  if (ManifestModuleUtil.getFileType(file) === 'ts') {
34
- resolved = RootIndex.getSourceFile(file);
35
+ resolved = RuntimeIndex.getSourceFile(file);
35
36
  }
36
37
  if (!(await fs.stat(resolved).catch(() => false))) {
37
38
  throw new Error(`Unknown file to resolve: ${file}`);
@@ -57,12 +58,10 @@ export class DocFileUtil {
57
58
  text = await fs.readFile(file, 'utf8');
58
59
 
59
60
  text = text.split(/\n/)
60
- .map(x => {
61
- if (ESLINT_PATTERN.test(x)) {
62
- x = x.replace(ESLINT_PATTERN, '');
63
- }
64
- return x;
65
- })
61
+ .map(x => x
62
+ .replace(ESLINT_PATTERN, '')
63
+ .replace(ENV_KEY, (_, k) => `'${k}'`)
64
+ )
66
65
  .filter(x => !x.includes('@doc-exclude'))
67
66
  .join('\n');
68
67
  }
package/src/util/run.ts CHANGED
@@ -1,8 +1,8 @@
1
- import os from 'os';
1
+ import os from 'node:os';
2
2
 
3
- import { path, RootIndex } from '@travetto/manifest';
4
- import { ExecUtil, ExecutionOptions, ExecutionState } from '@travetto/base';
5
- import { stripAnsiCodes } from '@travetto/terminal';
3
+ import { path, RuntimeIndex, RuntimeContext } from '@travetto/manifest';
4
+ import { Env, ExecUtil, ExecutionOptions, ExecutionState } from '@travetto/base';
5
+ import { StyleUtil } from '@travetto/terminal';
6
6
 
7
7
  export const COMMON_DATE = new Date('2029-03-14T00:00:00.000').getTime();
8
8
 
@@ -51,7 +51,7 @@ export class DocRunUtil {
51
51
  static #docState = new DocState();
52
52
 
53
53
  static runState(cmd: string, args: string[], config: RunConfig = {}): RunState {
54
- const cwd = config.cwd ?? (config.module ? RootIndex.getModule(config.module)! : RootIndex.mainModule).sourcePath;
54
+ const cwd = config.cwd ?? (config.module ? RuntimeIndex.getModule(config.module)! : RuntimeIndex.mainModule).sourcePath;
55
55
  args = [...args];
56
56
  return {
57
57
  cmd,
@@ -61,13 +61,14 @@ export class DocRunUtil {
61
61
  shell: '/bin/bash',
62
62
  env: {
63
63
  ...process.env,
64
- DEBUG: '0',
65
- TRV_CAN_RESTART: '0',
66
- TRV_CLI_IPC: '',
67
- TRV_MANIFEST: '',
68
- TRV_BUILD: 'none',
69
- TRV_MODULE: config.module ?? '',
70
- ...(config.envName ? { TRV_ENV: config.envName } : {}),
64
+ ...Env.DEBUG.export(false),
65
+ ...Env.TRV_CAN_RESTART.export(false),
66
+ ...Env.TRV_CLI_IPC.export(undefined),
67
+ ...Env.TRV_MANIFEST.export(''),
68
+ ...Env.TRV_BUILD.export('none'),
69
+ ...Env.TRV_ROLE.export(undefined),
70
+ ...Env.TRV_MODULE.export(config.module ?? ''),
71
+ ...(config.envName ? Env.TRV_ENV.export(config.envName) : {}),
71
72
  ...(config.env ?? {})
72
73
  }
73
74
  }
@@ -78,11 +79,11 @@ export class DocRunUtil {
78
79
  * Clean run output
79
80
  */
80
81
  static cleanRunOutput(text: string, cfg: RunConfig): string {
81
- const cwd = path.toPosix((cfg.module ? RootIndex.getModule(cfg.module)! : RootIndex.mainModule).sourcePath);
82
- text = stripAnsiCodes(text.trim())
82
+ const cwd = path.toPosix((cfg.module ? RuntimeIndex.getModule(cfg.module)! : RuntimeIndex.mainModule).sourcePath);
83
+ text = StyleUtil.cleanText(text.trim())
83
84
  .replaceAll(cwd, '.')
84
85
  .replaceAll(os.tmpdir(), '/tmp')
85
- .replaceAll(RootIndex.manifest.workspacePath, '<workspace-root>')
86
+ .replaceAll(RuntimeContext.workspace.path, '<workspace-root>')
86
87
  .replace(/[/]tmp[/][a-z_A-Z0-9\/\-]+/g, '/tmp/<temp-folder>')
87
88
  .replace(/^(\s*framework:\s*')(\d+[.]\d+)[^']*('[,]?\s*)$/gm, (_, pre, ver, post) => `${pre}${ver}.x${post}`)
88
89
  .replace(/^(\s*nodeVersion:\s*'v)(\d+)[^']*('[,]?\s*)$/gm, (_, pre, ver, post) => `${pre}${ver}.x.x${post}`)
@@ -119,7 +120,7 @@ export class DocRunUtil {
119
120
  if (!res.valid) {
120
121
  throw new Error(res.stderr);
121
122
  }
122
- final = stripAnsiCodes(res.stdout.toString()).trim() || stripAnsiCodes(res.stderr.toString()).trim();
123
+ final = StyleUtil.cleanText(res.stdout.toString()).trim() || StyleUtil.cleanText(res.stderr.toString()).trim();
123
124
  } catch (err) {
124
125
  if (err instanceof Error) {
125
126
  final = err.message;
@@ -1,7 +1,7 @@
1
- import fs from 'fs/promises';
1
+ import fs from 'node:fs/promises';
2
2
 
3
- import { PackageUtil, path, RootIndex } from '@travetto/manifest';
4
- import { ExecUtil, CompilerClient, defineEnv } from '@travetto/base';
3
+ import { PackageUtil, path, RuntimeIndex, RuntimeContext } from '@travetto/manifest';
4
+ import { ExecUtil, Env, watchCompiler } from '@travetto/base';
5
5
  import { CliCommandShape, CliCommand, CliValidationError, CliUtil } from '@travetto/cli';
6
6
  import { MinLength } from '@travetto/schema';
7
7
 
@@ -22,18 +22,16 @@ export class DocCommand implements CliCommandShape {
22
22
  watch = false;
23
23
 
24
24
  preMain(): void {
25
- Object.assign(process.env, {
26
- TRV_CLI_IPC: '',
27
- TRV_LOG_PLAIN: 'true',
28
- TRV_CONSOLE_WIDTH: '140',
29
- FORCE_COLOR: '0',
30
- });
31
- defineEnv({ debug: false, });
25
+ Env.DEBUG.set(false);
26
+ Env.TRV_ROLE.set('doc');
27
+ Env.TRV_CLI_IPC.clear();
28
+ Env.TRV_LOG_PLAIN.set(true);
29
+ Env.FORCE_COLOR.set(false);
32
30
  }
33
31
 
34
32
  preBind(): void {
35
- const workspacePkg = PackageUtil.readPackage(RootIndex.manifest.workspacePath);
36
- this.outputs = workspacePkg.travetto?.docOutputs ?? ['README.md'];
33
+ const workspacePkg = PackageUtil.readPackage(RuntimeContext.workspace.path);
34
+ this.outputs = workspacePkg.travetto?.doc?.outputs ?? ['README.md'];
37
35
  }
38
36
 
39
37
  preHelp(): void {
@@ -53,20 +51,20 @@ export class DocCommand implements CliCommandShape {
53
51
  }
54
52
 
55
53
  const args = process.argv.slice(2).filter(x => !/(-w|--watch)/.test(x));
56
- await new CompilerClient().onFileChange(async ({ action, file }) => {
54
+ await watchCompiler(async ({ action, file }) => {
57
55
  if (action === 'update' && file === this.input) {
58
56
  await ExecUtil.spawn('npx', ['trv', ...args], {
59
- cwd: RootIndex.mainModule.sourcePath,
60
- env: { TRV_QUIET: '1' },
57
+ cwd: RuntimeIndex.mainModule.sourcePath,
58
+ env: { ...Env.TRV_QUIET.export(true) },
61
59
  stdio: 'inherit', catchAsResult: true
62
60
  });
63
61
  }
64
- }, true);
62
+ }, { restartOnExit: true });
65
63
  }
66
64
 
67
65
  async render(): Promise<void> {
68
66
  const { DocRenderer } = await import('../src/render/renderer.js');
69
- const ctx = await DocRenderer.get(this.input, RootIndex.manifest);
67
+ const ctx = await DocRenderer.get(this.input, RuntimeContext);
70
68
  const outputs = this.outputs.map(output =>
71
69
  output.includes('.') ? [path.extname(output).replace('.', ''), path.resolve(output)] :
72
70
  [output, null] as const