@travetto/doc 4.0.0-rc.0 → 4.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": "4.0.0-rc.0",
3
+ "version": "4.0.0-rc.2",
4
4
  "description": "Documentation support for the Travetto framework",
5
5
  "keywords": [
6
6
  "docs",
@@ -24,13 +24,13 @@
24
24
  "directory": "module/doc"
25
25
  },
26
26
  "dependencies": {
27
- "@travetto/base": "^4.0.0-rc.0",
28
- "@travetto/terminal": "^4.0.0-rc.0",
27
+ "@travetto/base": "^4.0.0-rc.2",
28
+ "@travetto/terminal": "^4.0.0-rc.2",
29
29
  "@types/prismjs": "^1.26.3",
30
30
  "prismjs": "^1.29.0"
31
31
  },
32
32
  "peerDependencies": {
33
- "@travetto/cli": "^4.0.0-rc.0"
33
+ "@travetto/cli": "^4.0.0-rc.2"
34
34
  },
35
35
  "peerDependenciesMeta": {
36
36
  "@travetto/cli": {
@@ -98,7 +98,7 @@ export const LIB_MAPPING = {
98
98
  // Rest
99
99
  Express: { title: 'express', href: 'https://expressjs.com' },
100
100
  Passport: { title: 'passport', href: 'http://passportjs.org' },
101
- Busboy: { title: 'busboy', href: 'https://github.com/mscdex/busboy' },
101
+ Busboy: { title: '@fastify/busboy', href: 'https://github.com/fastify/busboy' },
102
102
  Cookies: { title: 'cookies', href: 'https://www.npmjs.com/package/cookies' },
103
103
  ServerlessExpress: { title: 'aws-serverless-express', href: 'https://github.com/awslabs/aws-serverless-express/blob/master/README.md' },
104
104
  AwsLambdaFastify: { title: '@fastify/aws-lambda', href: 'https://github.com/fastify/aws-lambda-fastify/blob/master/README.md' },
@@ -19,8 +19,10 @@ export class DocRenderer {
19
19
 
20
20
  static async get(file: string, manifest: ManifestContext): Promise<DocRenderer> {
21
21
  const mod = RuntimeIndex.getFromSource(file)?.import;
22
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
23
- const res = await import(mod!) as DocumentShape;
22
+ if (!mod) {
23
+ throw new Error(`Unable to render ${file}, not in the manifest`);
24
+ }
25
+ const res: DocumentShape = await import(mod);
24
26
 
25
27
  const pkg = PackageUtil.readPackage(manifest.workspace.path);
26
28
  const repoBaseUrl = pkg.travetto?.doc?.baseUrl ?? manifest.workspace.path;
@@ -55,7 +57,7 @@ export class DocRenderer {
55
57
  } else if (isJSXElement(node)) {
56
58
  let final: JSXElement = node;
57
59
  // Render simple element if needed
58
- if (typeof node.type === 'function') {
60
+ if (typeof node.type === 'function' && node.type !== JSXFragmentType) {
59
61
  // @ts-expect-error
60
62
  const out = node.type(node.props);
61
63
  final = out !== EMPTY_ELEMENT ? out : final;
package/src/util/run.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import os from 'node:os';
2
+ import { spawn, ChildProcess } from 'node:child_process';
2
3
 
3
4
  import { path, RuntimeIndex, RuntimeContext } from '@travetto/manifest';
4
- import { Env, ExecUtil, ExecutionOptions, ExecutionState } from '@travetto/base';
5
+ import { Env, ExecUtil } from '@travetto/base';
5
6
  import { StyleUtil } from '@travetto/terminal';
6
7
 
7
8
  export const COMMON_DATE = new Date('2029-03-14T00:00:00.000').getTime();
@@ -15,12 +16,6 @@ export type RunConfig = {
15
16
  cwd?: string;
16
17
  };
17
18
 
18
- type RunState = {
19
- cmd: string;
20
- args: string[];
21
- opts: ExecutionOptions;
22
- };
23
-
24
19
  class DocState {
25
20
  baseline = COMMON_DATE;
26
21
  _s = 37;
@@ -50,31 +45,6 @@ class DocState {
50
45
  export class DocRunUtil {
51
46
  static #docState = new DocState();
52
47
 
53
- static runState(cmd: string, args: string[], config: RunConfig = {}): RunState {
54
- const cwd = config.cwd ?? (config.module ? RuntimeIndex.getModule(config.module)! : RuntimeIndex.mainModule).sourcePath;
55
- args = [...args];
56
- return {
57
- cmd,
58
- args,
59
- opts: {
60
- cwd: path.toPosix(cwd),
61
- shell: '/bin/bash',
62
- env: {
63
- ...process.env,
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) : {}),
72
- ...(config.env ?? {})
73
- }
74
- }
75
- };
76
- }
77
-
78
48
  /**
79
49
  * Clean run output
80
50
  */
@@ -102,11 +72,25 @@ export class DocRunUtil {
102
72
  }
103
73
 
104
74
  /**
105
- * Run process in the background
75
+ * Spawn command with appropriate environment, and cwd
106
76
  */
107
- static runBackground(cmd: string, args: string[], config: RunConfig = {}): ExecutionState {
108
- const state = this.runState(cmd, args, config);
109
- return ExecUtil.spawn(state.cmd, state.args, { ...state.opts, stdio: 'pipe' });
77
+ static spawn(cmd: string, args: string[], config: RunConfig = {}): ChildProcess {
78
+ return spawn(cmd, args, {
79
+ cwd: path.toPosix(config.cwd ?? (config.module ? RuntimeIndex.getModule(config.module)! : RuntimeIndex.mainModule).sourcePath),
80
+ shell: '/bin/bash',
81
+ env: {
82
+ ...process.env,
83
+ ...Env.DEBUG.export(false),
84
+ ...Env.TRV_CAN_RESTART.export(false),
85
+ ...Env.TRV_CLI_IPC.export(undefined),
86
+ ...Env.TRV_MANIFEST.export(''),
87
+ ...Env.TRV_BUILD.export('none'),
88
+ ...Env.TRV_ROLE.export(undefined),
89
+ ...Env.TRV_MODULE.export(config.module ?? ''),
90
+ ...(config.envName ? Env.TRV_ENV.export(config.envName) : {}),
91
+ ...config.env
92
+ }
93
+ });
110
94
  }
111
95
 
112
96
  /**
@@ -115,12 +99,12 @@ export class DocRunUtil {
115
99
  static async run(cmd: string, args: string[], config: RunConfig = {}): Promise<string> {
116
100
  let final: string;
117
101
  try {
118
- const state = this.runState(cmd, args, config);
119
- const res = await ExecUtil.spawn(state.cmd, state.args, { stdio: 'pipe', ...state.opts, catchAsResult: true }).result;
102
+ const proc = this.spawn(cmd, args, config);
103
+ const res = await ExecUtil.getResult(proc, { catch: true });
120
104
  if (!res.valid) {
121
105
  throw new Error(res.stderr);
122
106
  }
123
- final = StyleUtil.cleanText(res.stdout.toString()).trim() || StyleUtil.cleanText(res.stderr.toString()).trim();
107
+ final = StyleUtil.cleanText(res.stdout).trim() || StyleUtil.cleanText(res.stderr).trim();
124
108
  } catch (err) {
125
109
  if (err instanceof Error) {
126
110
  final = err.message;
@@ -1,4 +1,5 @@
1
1
  import fs from 'node:fs/promises';
2
+ import { spawn } from 'node:child_process';
2
3
 
3
4
  import { PackageUtil, path, RuntimeIndex, RuntimeContext } from '@travetto/manifest';
4
5
  import { ExecUtil, Env, watchCompiler } from '@travetto/base';
@@ -51,15 +52,17 @@ export class DocCommand implements CliCommandShape {
51
52
  }
52
53
 
53
54
  const args = process.argv.slice(2).filter(x => !/(-w|--watch)/.test(x));
54
- await watchCompiler(async ({ action, file }) => {
55
+ for await (const { action, file } of watchCompiler({ restartOnExit: true })) {
55
56
  if (action === 'update' && file === this.input) {
56
- await ExecUtil.spawn('npx', ['trv', ...args], {
57
+ const proc = spawn('npx', ['trv', ...args], {
57
58
  cwd: RuntimeIndex.mainModule.sourcePath,
58
- env: { ...Env.TRV_QUIET.export(true) },
59
- stdio: 'inherit', catchAsResult: true
59
+ shell: false,
60
+ env: { ...process.env, ...Env.TRV_QUIET.export(true) },
61
+ stdio: 'inherit'
60
62
  });
63
+ await ExecUtil.getResult(proc, { catch: true });
61
64
  }
62
- }, { restartOnExit: true });
65
+ }
63
66
  }
64
67
 
65
68
  async render(): Promise<void> {