@travetto/repo 3.4.10 → 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/repo",
3
- "version": "3.4.10",
3
+ "version": "4.0.0-rc.0",
4
4
  "description": "Monorepo utilities",
5
5
  "keywords": [
6
6
  "travetto",
@@ -22,8 +22,8 @@
22
22
  "directory": "module/repo"
23
23
  },
24
24
  "dependencies": {
25
- "@travetto/cli": "^3.4.10",
26
- "@travetto/worker": "^3.4.2"
25
+ "@travetto/cli": "^4.0.0-rc.0",
26
+ "@travetto/worker": "^4.0.0-rc.0"
27
27
  },
28
28
  "peerDependenciesMeta": {
29
29
  "@travetto/cli": {
@@ -1,35 +1,38 @@
1
- import { ExecutionResult, ExecutionOptions, ExecutionState, Env, TypedObject } from '@travetto/base';
1
+ import { ExecutionResult, ExecutionOptions, ExecutionState, Env, Util } from '@travetto/base';
2
2
  import { CliModuleUtil } from '@travetto/cli';
3
3
  import { IndexedModule } from '@travetto/manifest';
4
- import { ColorDefineUtil, GlobalTerminal, NAMED_COLORS, TermLinePosition, Terminal } from '@travetto/terminal';
5
- import { WorkPool, Worker, IterableWorkSet } from '@travetto/worker';
4
+ import { StyleUtil, Terminal, TerminalUtil } from '@travetto/terminal';
5
+ import { WorkPool } from '@travetto/worker';
6
+
7
+ const COLORS = ([
8
+ '#8787ff', '#87afff', '#87d7ff', '#87ff87', '#87ffaf', '#87ffd7', '#87ffff', '#af87ff', '#afafd7', '#afafff', '#afd7af', '#afd7d7', '#afd7ff', '#afff87', '#afffaf',
9
+ '#afffd7', '#afffff', '#d787ff', '#d7afaf', '#d7afd7', '#d7afff', '#d7d7af', '#d7d7d7', '#d7d7ff', '#d7ff87', '#d7ffaf', '#d7ffd7', '#d7ffff', '#ff8787', '#ff87af',
10
+ '#ff87d7', '#ff87ff', '#ffaf87', '#ffafaf', '#ffafd7', '#ffafff', '#ffd787', '#ffd7af', '#ffd7d7', '#ffd7ff', '#ffff87', '#ffffaf', '#ffffd7', '#ffffff', '#bcbcbc',
11
+ '#c6c6c6', '#d0d0d0', '#dadada', '#e4e4e4', '#eeeeee'
12
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
13
+ ]).sort((a, b) => Math.random() < .5 ? -1 : 1).map(x => StyleUtil.getStyle(x as `#${string}`));
6
14
 
7
15
  type ModuleRunConfig<T = ExecutionResult> = {
8
16
  progressMessage?: (mod: IndexedModule | undefined) => string;
9
17
  filter?: (mod: IndexedModule) => boolean | Promise<boolean>;
10
18
  transformResult?: (mod: IndexedModule, result: ExecutionResult) => T;
11
19
  workerCount?: number;
12
- progressPosition?: TermLinePosition;
13
20
  prefixOutput?: boolean;
14
21
  showStdout?: boolean;
15
22
  showStderr?: boolean;
16
23
  };
17
24
 
18
- const COLORS = TypedObject.keys(NAMED_COLORS)
19
- .map(k => [k, ColorDefineUtil.defineColor(k).hsl] as const)
20
- .filter(([, [, s, l]]) => l > .5 && l < .8 && s > .8)
21
- .map(([k]) => GlobalTerminal.colorer(k));
22
-
23
25
  const colorize = (val: string, idx: number): string => COLORS[idx % COLORS.length](val);
24
26
 
25
27
  /**
26
28
  * Tools for running commands across all modules of the monorepo
27
29
  */
28
30
  export class RepoExecUtil {
31
+
29
32
  /**
30
33
  * Generate execution options for running on modules
31
34
  */
32
- static #buildExecutionOptions<T = ExecutionState>(
35
+ static #buildExecutionOptions <T = ExecutionState>(
33
36
  mod: IndexedModule,
34
37
  config: ModuleRunConfig<T>,
35
38
  prefixes: Record<string, string>,
@@ -42,14 +45,17 @@ export class RepoExecUtil {
42
45
  outputMode: 'text',
43
46
  catchAsResult: true,
44
47
  cwd: folder,
45
- env: { TRV_MANIFEST: '', TRV_MODULE: mod.name },
48
+ env: {
49
+ ...Env.TRV_MANIFEST.export(''),
50
+ ...Env.TRV_MODULE.export(mod.name)
51
+ },
46
52
  };
47
53
 
48
54
  if (config.showStdout) {
49
- opts.onStdOutLine = (line: string): unknown => stdoutTerm.writeLines(`${prefixes[folder] ?? ''}${line}`);
55
+ opts.onStdOutLine = (line: string): unknown => stdoutTerm.writer.write(`${prefixes[folder] ?? ''}${line}`).commit();
50
56
  }
51
57
  if (config.showStderr) {
52
- opts.onStdErrorLine = (line: string): unknown => stderrTerm.writeLines(`${prefixes[folder] ?? ''}${line}`);
58
+ opts.onStdErrorLine = (line: string): unknown => stderrTerm.writer.write(`${prefixes[folder] ?? ''}${line}`).commit();
53
59
  }
54
60
  return opts;
55
61
  }
@@ -74,7 +80,7 @@ export class RepoExecUtil {
74
80
  config: ModuleRunConfig<T> = {}
75
81
  ): Promise<Map<IndexedModule, T>> {
76
82
 
77
- config.showStdout = config.showStdout ?? (Env.isSet('DEBUG') && !Env.isFalse('DEBUG'));
83
+ config.showStdout = config.showStdout ?? (Env.DEBUG.isSet && !Env.DEBUG.isFalse);
78
84
  config.showStderr = config.showStderr ?? true;
79
85
 
80
86
  const workerCount = config.workerCount ?? WorkPool.DEFAULT_SIZE;
@@ -84,49 +90,28 @@ export class RepoExecUtil {
84
90
  const processes = new Map<IndexedModule, ExecutionState>();
85
91
 
86
92
  const prefixes = config.prefixOutput !== false ? this.#buildPrefixes(mods) : {};
87
- const stdoutTerm = await Terminal.for({ output: process.stdout });
88
- const stderrTerm = await Terminal.for({ output: process.stderr });
89
-
90
- let id = 1;
91
- const pool = new WorkPool(async () => {
92
- const worker: Worker<IndexedModule> & { mod?: IndexedModule } = {
93
- id: id += 1,
94
- mod: undefined,
95
- active: false,
96
- async destroy() {
97
- this.active = false;
98
- processes.get(this.mod!)?.process.kill('SIGKILL');
99
- },
100
- async execute(mod: IndexedModule) {
101
- try {
102
- this.mod = mod;
103
- this.active = true;
104
-
105
- if (await config.filter?.(mod) === false) {
106
- this.active = false;
107
- } else {
108
- const opts = RepoExecUtil.#buildExecutionOptions(mod, config, prefixes, stdoutTerm, stderrTerm);
109
-
110
- const result = await operation(mod, opts).result;
111
-
112
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
113
- const output = (config.transformResult ? config.transformResult(mod, result) : result) as T;
114
- results.set(mod, output);
115
- }
116
- } finally {
117
- this.active = false;
118
- delete this.mod;
119
- }
120
- },
121
- };
122
- return worker;
123
- }, { max: workerCount, min: workerCount });
124
-
125
- const work = pool.iterateProcess(new IterableWorkSet(mods));
126
-
127
- if (config.progressMessage) {
128
- const cfg = { position: config.progressPosition ?? 'bottom' } as const;
129
- await stdoutTerm.trackProgress(work, ev => ({ ...ev, text: config.progressMessage!(ev.value) }), cfg);
93
+ const stdoutTerm = new Terminal(process.stdout);
94
+ const stderrTerm = new Terminal(process.stderr);
95
+
96
+ const work = WorkPool.runStreamProgress(async (mod) => {
97
+ try {
98
+ if (!(await config.filter?.(mod) === false)) {
99
+ const opts = RepoExecUtil.#buildExecutionOptions(mod, config, prefixes, stdoutTerm, stderrTerm);
100
+
101
+ const result = await operation(mod, opts).result;
102
+
103
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
104
+ const output = (config.transformResult ? config.transformResult(mod, result) : result) as T;
105
+ results.set(mod, output);
106
+ }
107
+ return config.progressMessage?.(mod) ?? mod.name;
108
+ } finally {
109
+ processes.get(mod!)?.process.kill('SIGKILL');
110
+ }
111
+ }, mods, mods.length, { max: workerCount, min: workerCount });
112
+
113
+ if (config.progressMessage && stdoutTerm.interactive) {
114
+ await stdoutTerm.streamToBottom(Util.mapAsyncItr(work, TerminalUtil.progressBarUpdater(stdoutTerm, { withWaiting: true })));
130
115
  } else {
131
116
  for await (const _ of work) {
132
117
  // Ensure its all consumed
@@ -1,5 +1,5 @@
1
- import path from 'path';
2
- import fs from 'fs/promises';
1
+ import path from 'node:path';
2
+ import fs from 'node:fs/promises';
3
3
 
4
4
  import { ExecUtil, ExecutionOptions, ExecutionState, ExecutionResult } from '@travetto/base';
5
5
  import { IndexedModule, ManifestContext, Package, PackageUtil } from '@travetto/manifest';
@@ -17,7 +17,7 @@ export class PackageManager {
17
17
  */
18
18
  static isPublished(ctx: ManifestContext, mod: IndexedModule, opts: ExecutionOptions): ExecutionState {
19
19
  let args: string[];
20
- switch (ctx.packageManager) {
20
+ switch (ctx.workspace.manager) {
21
21
  case 'npm':
22
22
  args = ['show', `${mod.name}@${mod.version}`, 'version', '--json'];
23
23
  break;
@@ -25,14 +25,14 @@ export class PackageManager {
25
25
  args = ['info', `${mod.name}@${mod.version}`, 'dist.integrity', '--json'];
26
26
  break;
27
27
  }
28
- return ExecUtil.spawn(ctx.packageManager, args, opts);
28
+ return ExecUtil.spawn(ctx.workspace.manager, args, opts);
29
29
  }
30
30
 
31
31
  /**
32
32
  * Validate published result
33
33
  */
34
34
  static validatePublishedResult(ctx: ManifestContext, mod: IndexedModule, result: ExecutionResult): boolean {
35
- switch (ctx.packageManager) {
35
+ switch (ctx.workspace.manager) {
36
36
  case 'npm': {
37
37
  if (!result.valid && !result.stderr.includes('E404')) {
38
38
  throw new Error(result.stderr);
@@ -54,13 +54,13 @@ export class PackageManager {
54
54
  static async version(ctx: ManifestContext, modules: IndexedModule[], level: SemverLevel, preid?: string): Promise<void> {
55
55
  const mods = modules.flatMap(m => ['-w', m.sourceFolder]);
56
56
  let args: string[];
57
- switch (ctx.packageManager) {
57
+ switch (ctx.workspace.manager) {
58
58
  case 'npm':
59
59
  case 'yarn':
60
60
  args = ['version', '--no-workspaces-update', level, ...(preid ? ['--preid', preid] : []), ...mods];
61
61
  break;
62
62
  }
63
- await ExecUtil.spawn(ctx.packageManager, args, { stdio: 'inherit' }).result;
63
+ await ExecUtil.spawn(ctx.workspace.manager, args, { stdio: 'inherit' }).result;
64
64
  }
65
65
 
66
66
  /**
@@ -68,13 +68,13 @@ export class PackageManager {
68
68
  */
69
69
  static dryRunPackaging(ctx: ManifestContext, opts: ExecutionOptions): ExecutionState {
70
70
  let args: string[];
71
- switch (ctx.packageManager) {
71
+ switch (ctx.workspace.manager) {
72
72
  case 'npm':
73
73
  case 'yarn':
74
74
  args = ['pack', '--dry-run'];
75
75
  break;
76
76
  }
77
- return ExecUtil.spawn(ctx.packageManager, args, opts);
77
+ return ExecUtil.spawn(ctx.workspace.manager, args, opts);
78
78
  }
79
79
 
80
80
  /**
@@ -87,13 +87,13 @@ export class PackageManager {
87
87
 
88
88
  const versionTag = mod.version.match(/^.*-(rc|alpha|beta|next)[.]\d+/)?.[1] ?? 'latest';
89
89
  let args: string[];
90
- switch (ctx.packageManager) {
90
+ switch (ctx.workspace.manager) {
91
91
  case 'npm':
92
92
  case 'yarn':
93
93
  args = ['publish', '--tag', versionTag, '--access', 'public'];
94
94
  break;
95
95
  }
96
- return ExecUtil.spawn(ctx.packageManager, args, opts);
96
+ return ExecUtil.spawn(ctx.workspace.manager, args, opts);
97
97
  }
98
98
 
99
99
  /**
@@ -1,6 +1,6 @@
1
1
  import { CliCommand, CliCommandShape, ParsedState } from '@travetto/cli';
2
2
  import { WorkPool } from '@travetto/worker';
3
- import { ExecUtil, defineEnv } from '@travetto/base';
3
+ import { Env, ExecUtil } from '@travetto/base';
4
4
  import { Ignore, Max, Min } from '@travetto/schema';
5
5
 
6
6
  import { RepoExecUtil } from './bin/exec';
@@ -28,7 +28,7 @@ export class RepoExecCommand implements CliCommandShape {
28
28
  showStdout = true;
29
29
 
30
30
  preMain(): void {
31
- defineEnv({ debug: false });
31
+ Env.DEBUG.set(false);
32
32
  }
33
33
 
34
34
  async main(cmd: string, args: string[] = []): Promise<void> {
@@ -1,5 +1,5 @@
1
1
  import { CliCommandShape, CliCommand, CliModuleUtil } from '@travetto/cli';
2
- import { RootIndex } from '@travetto/manifest';
2
+ import { RuntimeIndex, RuntimeContext } from '@travetto/manifest';
3
3
 
4
4
  const write = (line: string): Promise<void> => new Promise(r => process.stdout.write(`${line}\n`, () => r()));
5
5
 
@@ -39,14 +39,14 @@ export class ListModuleCommand implements CliCommandShape {
39
39
  }
40
40
  case 'json': {
41
41
  const outputMap = CliModuleUtil.getDependencyGraph(mods);
42
- await write(JSON.stringify(Object.entries(outputMap).map(([name, children]) => ({ name, children, local: RootIndex.getModule(name)?.local })), null, 2));
42
+ await write(JSON.stringify(Object.entries(outputMap).map(([name, children]) => ({ name, children, local: RuntimeIndex.getModule(name)?.local })), null, 2));
43
43
  break;
44
44
  }
45
45
  case 'graph': {
46
46
  await write('digraph g {');
47
47
  for (const el of mods) {
48
48
  for (const dep of el.parents) {
49
- if (dep !== RootIndex.mainModuleName) {
49
+ if (dep !== RuntimeContext.main.name) {
50
50
  await write(` "${dep}" -> "${el.name}";`);
51
51
  }
52
52
  }
@@ -1,5 +1,5 @@
1
1
  import { CliCommandShape, CliCommand } from '@travetto/cli';
2
- import { RootIndex } from '@travetto/manifest';
2
+ import { RuntimeContext } from '@travetto/manifest';
3
3
 
4
4
  import { PackageManager } from './bin/package-manager';
5
5
  import { RepoExecUtil } from './bin/exec';
@@ -14,11 +14,11 @@ export class RepoPublishCommand implements CliCommandShape {
14
14
  dryRun = true;
15
15
 
16
16
  async main(): Promise<void> {
17
- const published = await RepoExecUtil.execOnModules('all', (mod, opts) => PackageManager.isPublished(RootIndex.manifest, mod, opts), {
17
+ const published = await RepoExecUtil.execOnModules('all', (mod, opts) => PackageManager.isPublished(RuntimeContext, mod, opts), {
18
18
  filter: mod => !!mod.local && !mod.internal,
19
19
  progressMessage: (mod) => `Checking published [%idx/%total] -- ${mod?.name}`,
20
20
  showStderr: false,
21
- transformResult: (mod, res) => PackageManager.validatePublishedResult(RootIndex.manifest, mod, res),
21
+ transformResult: (mod, res) => PackageManager.validatePublishedResult(RuntimeContext, mod, res),
22
22
  });
23
23
 
24
24
  if (this.dryRun) {
@@ -26,7 +26,7 @@ export class RepoPublishCommand implements CliCommandShape {
26
26
  }
27
27
 
28
28
  await RepoExecUtil.execOnModules(
29
- 'all', (mod, opts) => PackageManager.publish(RootIndex.manifest, mod, this.dryRun, opts),
29
+ 'all', (mod, opts) => PackageManager.publish(RuntimeContext, mod, this.dryRun, opts),
30
30
  {
31
31
  progressMessage: (mod) => `Published [%idx/%total] -- ${mod?.name}`,
32
32
  showStdout: false,
@@ -1,8 +1,7 @@
1
- import fs from 'fs/promises';
1
+ import fs from 'node:fs/promises';
2
2
 
3
- import { CliCommandShape, CliCommand, CliScmUtil, CliValidationError } from '@travetto/cli';
4
- import { CliModuleUtil } from '@travetto/cli/src/module';
5
- import { RootIndex, path } from '@travetto/manifest';
3
+ import { CliModuleUtil, CliCommandShape, CliCommand, CliScmUtil, CliValidationError } from '@travetto/cli';
4
+ import { RuntimeContext } from '@travetto/manifest';
6
5
 
7
6
  import { PackageManager, SemverLevel } from './bin/package-manager';
8
7
 
@@ -43,14 +42,14 @@ export class RepoVersionCommand implements CliCommandShape {
43
42
  throw new Error('No modules available for versioning');
44
43
  }
45
44
 
46
- await PackageManager.version(RootIndex.manifest, modules, level, prefix);
45
+ await PackageManager.version(RuntimeContext, modules, level, prefix);
47
46
 
48
47
  const versions = await PackageManager.synchronizeVersions();
49
48
  if (this.commit) {
50
49
  const commitMessage = `Publish ${modules.map(x => `${x.name}#${versions[x.name]?.replace('^', '') ?? x.version}`).join(',')}`;
51
50
  console.log!(await CliScmUtil.createCommit(commitMessage));
52
51
  // Touch package when done to trigger restart of compiler
53
- await fs.utimes(path.resolve(RootIndex.manifest.workspacePath, 'package.json'), Date.now(), Date.now());
52
+ await fs.utimes(RuntimeContext.workspaceRelative('package.json'), Date.now(), Date.now());
54
53
  }
55
54
  }
56
55
  }