@travetto/doc 5.0.0-rc.0 → 5.0.0-rc.2

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": "5.0.0-rc.0",
3
+ "version": "5.0.0-rc.2",
4
4
  "description": "Documentation support for the Travetto framework",
5
5
  "keywords": [
6
6
  "docs",
@@ -24,12 +24,12 @@
24
24
  "directory": "module/doc"
25
25
  },
26
26
  "dependencies": {
27
- "@travetto/base": "^5.0.0-rc.0",
27
+ "@travetto/runtime": "^5.0.0-rc.2",
28
28
  "@types/prismjs": "^1.26.4",
29
29
  "prismjs": "^1.29.0"
30
30
  },
31
31
  "peerDependencies": {
32
- "@travetto/cli": "^5.0.0-rc.0"
32
+ "@travetto/cli": "^5.0.0-rc.2"
33
33
  },
34
34
  "peerDependenciesMeta": {
35
35
  "@travetto/cli": {
package/src/jsx.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createElement, JSXElement, JSXComponentFunction as CompFn } from '@travetto/doc/jsx-runtime';
2
- import { TypedObject } from '@travetto/base';
2
+ import { TypedObject } from '@travetto/runtime';
3
3
 
4
4
  import { LIB_MAPPING } from './mapping/lib-mapping';
5
5
  import { MOD_MAPPING } from './mapping/mod-mapping';
@@ -32,7 +32,7 @@ export const MOD_MAPPING = {
32
32
  description: 'Rest authentication session integration support for the Travetto framework'
33
33
  },
34
34
  Base: {
35
- name: '@travetto/base', folder: '@travetto/base', displayName: 'Base',
35
+ name: '@travetto/runtime', folder: '@travetto/runtime', displayName: 'Base',
36
36
  description: 'Environment config and common utilities for travetto applications.'
37
37
  },
38
38
  Cache: {
@@ -1,6 +1,9 @@
1
+ import path from 'node:path';
2
+
1
3
  import { createElement, JSXRuntimeTag } from '@travetto/doc/jsx-runtime';
2
4
 
3
- import { path, PackageUtil, RuntimeIndex } from '@travetto/manifest';
5
+ import { PackageUtil } from '@travetto/manifest';
6
+ import { Runtime, RuntimeIndex } from '@travetto/runtime';
4
7
 
5
8
  import { JSXElementByFn, c } from '../jsx';
6
9
  import { DocResolveUtil, ResolvedCode, ResolvedRef, ResolvedSnippetLink } from '../util/resolve';
@@ -37,7 +40,7 @@ export class RenderContext {
37
40
 
38
41
  const manifestPkg = PackageUtil.readPackage(RuntimeIndex.getModule('@travetto/manifest')!.sourcePath);
39
42
 
40
- this.file = path.toPosix(file);
43
+ this.file = path.resolve(file);
41
44
  this.baseUrl = baseUrl;
42
45
  this.repoRoot = repoRoot;
43
46
  this.travettoBaseUrl = repoRoot.includes('travetto.github') ? repoRoot : manifestPkg.travetto!.doc!.baseUrl!;
@@ -105,7 +108,7 @@ export class RenderContext {
105
108
  * Resolve code link
106
109
  */
107
110
  async resolveCodeLink(node: JSXElementByFn<'CodeLink'>): Promise<ResolvedSnippetLink> {
108
- const src = typeof node.props.src === 'string' ? node.props.src : RuntimeIndex.getFunctionMetadata(node.props.src)!.source;
111
+ const src = typeof node.props.src === 'string' ? node.props.src : Runtime.getSource(node.props.src);
109
112
  return DocResolveUtil.resolveCodeLink(src, node.props.startRe);
110
113
  }
111
114
 
@@ -113,7 +116,7 @@ export class RenderContext {
113
116
  * Resolve code/config
114
117
  */
115
118
  async resolveCode(node: JSXElementByFn<'Code' | 'Config'>): Promise<ResolvedCode> {
116
- const src = typeof node.props.src === 'string' ? node.props.src : RuntimeIndex.getFunctionMetadata(node.props.src)!.source;
119
+ const src = typeof node.props.src === 'string' ? node.props.src : Runtime.getSource(node.props.src);
117
120
  return node.props.startRe ?
118
121
  DocResolveUtil.resolveSnippet(src, node.props.startRe, node.props.endRe, node.props.outline) :
119
122
  DocResolveUtil.resolveCode(src, node.props.language, node.props.outline);
@@ -1,7 +1,8 @@
1
1
  import fs from 'node:fs/promises';
2
2
 
3
3
  import { JSXElement } from '@travetto/doc/jsx-runtime';
4
- import { RuntimeIndex, PackageUtil, RuntimeContext } from '@travetto/manifest';
4
+ import { Runtime, RuntimeIndex } from '@travetto/runtime';
5
+ import { PackageUtil } from '@travetto/manifest';
5
6
 
6
7
  import { highlight } from './code-highlight';
7
8
  import { RenderProvider, RenderState } from '../types';
@@ -144,7 +145,7 @@ yarn add ${el.props.pkg}
144
145
  Header: async ({ props }) => `<h1>${props.title} ${props.description ? `\n<small>${props.description}</small>\n` : ''}</h1>\n`,
145
146
 
146
147
  StdHeader: async state => {
147
- const mod = state.el.props.mod ?? RuntimeContext.main.name;
148
+ const mod = state.el.props.mod ?? Runtime.main.name;
148
149
  const pkg = PackageUtil.readPackage(RuntimeIndex.getModule(mod)!.sourcePath);
149
150
  const title = pkg.travetto?.displayName ?? pkg.name;
150
151
  const desc = pkg.description;
@@ -1,5 +1,6 @@
1
1
  import fs from 'node:fs/promises';
2
- import { PackageUtil, RuntimeIndex, RuntimeContext } from '@travetto/manifest';
2
+ import { Runtime, RuntimeIndex } from '@travetto/runtime';
3
+ import { PackageUtil } from '@travetto/manifest';
3
4
 
4
5
  import { RenderProvider } from '../types';
5
6
  import { c, getComponentName } from '../jsx';
@@ -108,7 +109,7 @@ ${context.cleanText(content.text)}
108
109
  Header: async ({ props }) => `# ${props.title}\n${props.description ? `## ${props.description}\n` : ''}\n`,
109
110
 
110
111
  StdHeader: async state => {
111
- const mod = state.el.props.mod ?? RuntimeContext.main.name;
112
+ const mod = state.el.props.mod ?? Runtime.main.name;
112
113
  const pkg = PackageUtil.readPackage(RuntimeIndex.getModule(mod)!.sourcePath);
113
114
  const title = pkg.travetto?.displayName ?? pkg.name;
114
115
  const desc = pkg.description;
@@ -1,7 +1,8 @@
1
1
  import path from 'node:path';
2
2
 
3
- import { ManifestContext, PackageUtil, RuntimeIndex } from '@travetto/manifest';
3
+ import { type ManifestContext, PackageUtil } from '@travetto/manifest';
4
4
  import { isJSXElement, JSXElement, JSXFragmentType } from '@travetto/doc/jsx-runtime';
5
+ import { Runtime, RuntimeIndex } from '@travetto/runtime';
5
6
 
6
7
  import { EMPTY_ELEMENT, getComponentName, JSXElementByFn, c } from '../jsx';
7
8
  import { DocumentShape, RenderProvider, RenderState } from '../types';
@@ -93,11 +94,11 @@ export class DocRenderer {
93
94
  case 'bigint':
94
95
  case 'boolean': return `${node}`;
95
96
  default: {
96
- const meta = (typeof node === 'function' ? RuntimeIndex.getFunctionMetadata(node) : undefined);
97
- if (meta && typeof node === 'function') {
98
- const title = (await DocFileUtil.isDecorator(node.name, meta.source)) ? `@${node.name}` : node.name;
97
+ const source = typeof node === 'function' ? Runtime.getSource(node) : undefined;
98
+ if (source && typeof node === 'function') {
99
+ const title = (await DocFileUtil.isDecorator(node.name, source)) ? `@${node.name}` : node.name;
99
100
  const el = this.#support.createElement('CodeLink', {
100
- src: meta.source,
101
+ src: source,
101
102
  startRe: new RegExp(`(class|function)\\s+(${node.name})`),
102
103
  title
103
104
  });
package/src/util/file.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import fs from 'node:fs/promises';
2
2
  import path from 'node:path';
3
3
 
4
- import { ManifestModuleUtil, RuntimeIndex } from '@travetto/manifest';
4
+ import { ManifestModuleUtil } from '@travetto/manifest';
5
+ import { RuntimeIndex } from '@travetto/runtime';
5
6
 
6
7
  const ESLINT_PATTERN = /\s*\/\/ eslint.*$/g;
7
8
  const ENV_KEY = /Env.([^.]+)[.]key/g;
package/src/util/run.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import os from 'node:os';
2
2
  import util from 'node:util';
3
3
  import { spawn, ChildProcess } from 'node:child_process';
4
+ import path from 'node:path';
4
5
 
5
- import { path, RuntimeIndex, RuntimeContext } from '@travetto/manifest';
6
- import { Env, ExecUtil } from '@travetto/base';
6
+ import { Env, ExecUtil, Runtime, RuntimeIndex } from '@travetto/runtime';
7
7
 
8
8
  export const COMMON_DATE = new Date('2029-03-14T00:00:00.000').getTime();
9
9
 
@@ -45,15 +45,20 @@ class DocState {
45
45
  export class DocRunUtil {
46
46
  static #docState = new DocState();
47
47
 
48
+ /** Build cwd from config */
49
+ static cwd(cfg: RunConfig): string {
50
+ return path.resolve(cfg.module ? RuntimeIndex.getModule(cfg.module)?.sourcePath! : Runtime.mainSourcePath);
51
+ }
52
+
48
53
  /**
49
54
  * Clean run output
50
55
  */
51
56
  static cleanRunOutput(text: string, cfg: RunConfig): string {
52
- const cwd = path.toPosix((cfg.module ? RuntimeIndex.getModule(cfg.module)! : RuntimeIndex.mainModule).sourcePath);
57
+ const cwd = this.cwd(cfg);
53
58
  text = util.stripVTControlCharacters(text.trim())
54
59
  .replaceAll(cwd, '.')
55
60
  .replaceAll(os.tmpdir(), '/tmp')
56
- .replaceAll(RuntimeContext.workspace.path, '<workspace-root>')
61
+ .replaceAll(Runtime.workspace.path, '<workspace-root>')
57
62
  .replace(/[/]tmp[/][a-z_A-Z0-9\/\-]+/g, '/tmp/<temp-folder>')
58
63
  .replace(/^(\s*framework:\s*')(\d+[.]\d+)[^']*('[,]?\s*)$/gm, (_, pre, ver, post) => `${pre}${ver}.x${post}`)
59
64
  .replace(/^(\s*nodeVersion:\s*'v)(\d+)[^']*('[,]?\s*)$/gm, (_, pre, ver, post) => `${pre}${ver}.x.x${post}`)
@@ -76,7 +81,7 @@ export class DocRunUtil {
76
81
  */
77
82
  static spawn(cmd: string, args: string[], config: RunConfig = {}): ChildProcess {
78
83
  return spawn(cmd, args, {
79
- cwd: path.toPosix(config.cwd ?? (config.module ? RuntimeIndex.getModule(config.module)! : RuntimeIndex.mainModule).sourcePath),
84
+ cwd: config.cwd ?? this.cwd(config),
80
85
  shell: '/bin/bash',
81
86
  env: {
82
87
  ...process.env,
@@ -2,8 +2,8 @@ import fs from 'node:fs/promises';
2
2
  import { spawn } from 'node:child_process';
3
3
  import path from 'node:path';
4
4
 
5
- import { PackageUtil, RuntimeIndex, RuntimeContext } from '@travetto/manifest';
6
- import { ExecUtil, Env, watchCompiler } from '@travetto/base';
5
+ import { PackageUtil } from '@travetto/manifest';
6
+ import { ExecUtil, Env, watchCompiler, Runtime } from '@travetto/runtime';
7
7
  import { CliCommandShape, CliCommand, CliValidationError, CliUtil } from '@travetto/cli';
8
8
  import { MinLength } from '@travetto/schema';
9
9
 
@@ -32,7 +32,7 @@ export class DocCommand implements CliCommandShape {
32
32
  }
33
33
 
34
34
  preBind(): void {
35
- const workspacePkg = PackageUtil.readPackage(RuntimeContext.workspace.path);
35
+ const workspacePkg = PackageUtil.readPackage(Runtime.workspace.path);
36
36
  this.outputs = workspacePkg.travetto?.doc?.outputs ?? ['README.md'];
37
37
  }
38
38
 
@@ -56,7 +56,7 @@ export class DocCommand implements CliCommandShape {
56
56
  for await (const { action, file } of watchCompiler({ restartOnExit: true })) {
57
57
  if (action === 'update' && file === this.input) {
58
58
  const proc = spawn('npx', ['trv', ...args], {
59
- cwd: RuntimeIndex.mainModule.sourcePath,
59
+ cwd: Runtime.mainSourcePath,
60
60
  shell: false,
61
61
  env: { ...process.env, ...Env.TRV_QUIET.export(true) },
62
62
  stdio: 'inherit'
@@ -68,7 +68,7 @@ export class DocCommand implements CliCommandShape {
68
68
 
69
69
  async render(): Promise<void> {
70
70
  const { DocRenderer } = await import('../src/render/renderer');
71
- const ctx = await DocRenderer.get(this.input, RuntimeContext);
71
+ const ctx = await DocRenderer.get(this.input, Runtime);
72
72
  const outputs = this.outputs.map(output =>
73
73
  output.includes('.') ? [path.extname(output).replace('.', ''), path.resolve(output)] :
74
74
  [output, null] as const