@travetto/repo 7.0.5 → 7.0.7

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": "7.0.5",
3
+ "version": "7.0.7",
4
4
  "type": "module",
5
5
  "description": "Monorepo utilities",
6
6
  "keywords": [
@@ -23,10 +23,10 @@
23
23
  "directory": "module/repo"
24
24
  },
25
25
  "dependencies": {
26
- "@travetto/worker": "^7.0.3"
26
+ "@travetto/worker": "^7.0.5"
27
27
  },
28
28
  "peerDependencies": {
29
- "@travetto/cli": "^7.0.5"
29
+ "@travetto/cli": "^7.0.7"
30
30
  },
31
31
  "peerDependenciesMeta": {
32
32
  "@travetto/cli": {
@@ -1,6 +1,6 @@
1
- import { ChildProcess } from 'node:child_process';
1
+ import type { ChildProcess } from 'node:child_process';
2
2
 
3
- import { ExecutionResult, Env, Util, ExecUtil, castTo } from '@travetto/runtime';
3
+ import { type ExecutionResult, Env, Util, ExecUtil, castTo } from '@travetto/runtime';
4
4
  import { CliModuleUtil } from '@travetto/cli';
5
5
  import type { IndexedModule } from '@travetto/manifest';
6
6
  import { StyleUtil, Terminal, TerminalUtil } from '@travetto/terminal';
@@ -14,9 +14,9 @@ const COLORS = ([...[
14
14
  ] as const]).toSorted(() => Math.random() < .5 ? -1 : 1).map(color => StyleUtil.getStyle(color));
15
15
 
16
16
  type ModuleRunConfig<T = ExecutionResult<string>> = {
17
- progressMessage?: (mod: IndexedModule | undefined) => string;
18
- filter?: (mod: IndexedModule) => boolean | Promise<boolean>;
19
- transformResult?: (mod: IndexedModule, result: ExecutionResult<string>) => T;
17
+ progressMessage?: (module: IndexedModule | undefined) => string;
18
+ filter?: (module: IndexedModule) => boolean | Promise<boolean>;
19
+ transformResult?: (module: IndexedModule, result: ExecutionResult<string>) => T;
20
20
  workerCount?: number;
21
21
  prefixOutput?: boolean;
22
22
  showStdout?: boolean;
@@ -33,11 +33,11 @@ export class RepoExecUtil {
33
33
 
34
34
  /**
35
35
  * Build equal sized prefix labels for outputting
36
- * @param mods
36
+ * @param modules
37
37
  * @returns
38
38
  */
39
- static #buildPrefixes(mods: IndexedModule[]): Record<string, string> {
40
- const folders = mods.map(mod => mod.sourceFolder);
39
+ static #buildPrefixes(modules: IndexedModule[]): Record<string, string> {
40
+ const folders = modules.map(module => module.sourceFolder);
41
41
  const maxWidth = Math.max(...folders.map(folder => folder.length));
42
42
  return Object.fromEntries(folders.map((folder, i) => [folder, colorize(folder.padStart(maxWidth, ' ').padEnd(maxWidth + 1), i)]));
43
43
  }
@@ -47,30 +47,30 @@ export class RepoExecUtil {
47
47
  */
48
48
  static async execOnModules<T = ExecutionResult>(
49
49
  mode: 'all' | 'workspace' | 'changed',
50
- operation: (mod: IndexedModule) => ChildProcess,
50
+ operation: (module: IndexedModule) => ChildProcess,
51
51
  config: ModuleRunConfig<T> = {}
52
52
  ): Promise<Map<IndexedModule, T>> {
53
53
 
54
54
  config.showStdout = config.showStdout ?? (Env.DEBUG.isSet && !Env.DEBUG.isFalse);
55
55
  config.showStderr = config.showStderr ?? true;
56
- const transform = config.transformResult ?? ((mod, result): T => castTo(result));
56
+ const transform = config.transformResult ?? ((module, result): T => castTo(result));
57
57
 
58
58
  const workerCount = config.workerCount ?? WorkPool.DEFAULT_SIZE;
59
59
 
60
- const mods = await CliModuleUtil.findModules(mode);
60
+ const modules = await CliModuleUtil.findModules(mode);
61
61
  const results = new Map<IndexedModule, T>();
62
62
  const processes = new Map<IndexedModule, ChildProcess>();
63
63
 
64
- const prefixes = config.prefixOutput !== false ? this.#buildPrefixes(mods) : {};
64
+ const prefixes = config.prefixOutput !== false ? this.#buildPrefixes(modules) : {};
65
65
  const stdoutTerm = new Terminal(process.stdout);
66
66
  const stderrTerm = new Terminal(process.stderr);
67
67
 
68
- const work = WorkPool.runStreamProgress(async (mod) => {
68
+ const work = WorkPool.runStreamProgress(async (module) => {
69
69
  try {
70
- if (!(await config.filter?.(mod) === false)) {
71
- const prefix = prefixes[mod.sourceFolder] ?? '';
72
- const subProcess = operation(mod);
73
- processes.set(mod, subProcess);
70
+ if (!(await config.filter?.(module) === false)) {
71
+ const prefix = prefixes[module.sourceFolder] ?? '';
72
+ const subProcess = operation(module);
73
+ processes.set(module, subProcess);
74
74
 
75
75
  if (config.showStdout && subProcess.stdout) {
76
76
  ExecUtil.readLines(subProcess.stdout, line =>
@@ -84,14 +84,14 @@ export class RepoExecUtil {
84
84
  }
85
85
 
86
86
  const result = await ExecUtil.getResult(subProcess, { catch: true });
87
- const output = transform(mod, result);
88
- results.set(mod, output);
87
+ const output = transform(module, result);
88
+ results.set(module, output);
89
89
  }
90
- return config.progressMessage?.(mod) ?? mod.name;
90
+ return config.progressMessage?.(module) ?? module.name;
91
91
  } finally {
92
- processes.get(mod!)?.kill();
92
+ processes.get(module!)?.kill();
93
93
  }
94
- }, mods, mods.length, { max: workerCount, min: workerCount });
94
+ }, modules, modules.length, { max: workerCount, min: workerCount });
95
95
 
96
96
  if (config.progressMessage && stdoutTerm.interactive) {
97
97
  await stdoutTerm.streamToBottom(Util.mapAsyncIterable(work, TerminalUtil.progressBarUpdater(stdoutTerm, { withWaiting: true })));
@@ -1,8 +1,8 @@
1
1
  import path from 'node:path';
2
- import { spawn, ChildProcess } from 'node:child_process';
2
+ import { spawn, type ChildProcess } from 'node:child_process';
3
3
  import fs from 'node:fs/promises';
4
4
 
5
- import { ExecUtil, ExecutionResult, JSONUtil } from '@travetto/runtime';
5
+ import { ExecUtil, type ExecutionResult, JSONUtil } from '@travetto/runtime';
6
6
  import { type IndexedModule, type ManifestContext, type Package, PackageUtil } from '@travetto/manifest';
7
7
  import { CliModuleUtil } from '@travetto/cli';
8
8
 
@@ -18,23 +18,23 @@ export class PackageManager {
18
18
  /**
19
19
  * Is a module already published
20
20
  */
21
- static isPublished(ctx: Ctx, mod: IndexedModule): ChildProcess {
21
+ static isPublished(ctx: Ctx, module: IndexedModule): ChildProcess {
22
22
  let args: string[];
23
23
  switch (ctx.workspace.manager) {
24
24
  case 'npm':
25
- args = ['show', `${mod.name}@${mod.version}`, 'version', '--json'];
25
+ args = ['show', `${module.name}@${module.version}`, 'version', '--json'];
26
26
  break;
27
27
  case 'yarn':
28
- args = ['info', `${mod.name}@${mod.version}`, 'dist.integrity', '--json'];
28
+ args = ['info', `${module.name}@${module.version}`, 'dist.integrity', '--json'];
29
29
  break;
30
30
  }
31
- return spawn(ctx.workspace.manager, args, { cwd: mod.sourceFolder });
31
+ return spawn(ctx.workspace.manager, args, { cwd: module.sourceFolder });
32
32
  }
33
33
 
34
34
  /**
35
35
  * Validate published result
36
36
  */
37
- static validatePublishedResult(ctx: Ctx, mod: IndexedModule, result: ExecutionResult<string>): boolean {
37
+ static validatePublishedResult(ctx: Ctx, module: IndexedModule, result: ExecutionResult<string>): boolean {
38
38
  switch (ctx.workspace.manager) {
39
39
  case 'npm': {
40
40
  if (!result.valid && !result.stderr.includes('E404')) {
@@ -42,7 +42,7 @@ export class PackageManager {
42
42
  }
43
43
  const item: (string[] | string) = result.stdout ? JSONUtil.parseSafe(result.stdout) : [];
44
44
  const found = Array.isArray(item) ? item.pop() : item;
45
- return !!found && found === mod.version;
45
+ return !!found && found === module.version;
46
46
  }
47
47
  case 'yarn': {
48
48
  const parsed = JSONUtil.parseSafe<{ data?: unknown }>(result.stdout);
@@ -55,12 +55,12 @@ export class PackageManager {
55
55
  * Setting the version
56
56
  */
57
57
  static async version(ctx: Ctx, modules: IndexedModule[], level: SemverLevel, preid?: string): Promise<void> {
58
- const mods = modules.flatMap(mod => ['-w', mod.sourceFolder]);
58
+ const moduleArgs = modules.flatMap(module => ['-w', module.sourceFolder]);
59
59
  let args: string[];
60
60
  switch (ctx.workspace.manager) {
61
61
  case 'npm':
62
62
  case 'yarn':
63
- args = ['version', '--no-workspaces-update', level, ...(preid ? ['--preid', preid] : []), ...mods];
63
+ args = ['version', '--no-workspaces-update', level, ...(preid ? ['--preid', preid] : []), ...moduleArgs];
64
64
  break;
65
65
  }
66
66
  await ExecUtil.getResult(spawn(ctx.workspace.manager, args, { cwd: ctx.workspace.path, stdio: 'inherit' }));
@@ -69,7 +69,7 @@ export class PackageManager {
69
69
  /**
70
70
  * Dry-run packaging
71
71
  */
72
- static dryRunPackaging(ctx: Ctx, mod: IndexedModule): ChildProcess {
72
+ static dryRunPackaging(ctx: Ctx, module: IndexedModule): ChildProcess {
73
73
  let args: string[];
74
74
  switch (ctx.workspace.manager) {
75
75
  case 'npm':
@@ -77,18 +77,18 @@ export class PackageManager {
77
77
  args = ['pack', '--dry-run'];
78
78
  break;
79
79
  }
80
- return spawn(ctx.workspace.manager, args, { cwd: mod.sourcePath });
80
+ return spawn(ctx.workspace.manager, args, { cwd: module.sourcePath });
81
81
  }
82
82
 
83
83
  /**
84
84
  * Publish a module
85
85
  */
86
- static publish(ctx: Ctx, mod: IndexedModule, dryRun: boolean | undefined): ChildProcess {
86
+ static publish(ctx: Ctx, module: IndexedModule, dryRun: boolean | undefined): ChildProcess {
87
87
  if (dryRun) {
88
- return this.dryRunPackaging(ctx, mod);
88
+ return this.dryRunPackaging(ctx, module);
89
89
  }
90
90
 
91
- const versionTag = mod.version.match(/^.*-(rc|alpha|beta|next)[.]\d+/)?.[1] ?? 'latest';
91
+ const versionTag = module.version.match(/^.*-(rc|alpha|beta|next)[.]\d+/)?.[1] ?? 'latest';
92
92
  let args: string[];
93
93
  switch (ctx.workspace.manager) {
94
94
  case 'npm':
@@ -96,7 +96,7 @@ export class PackageManager {
96
96
  args = ['publish', '--tag', versionTag, '--access', 'public'];
97
97
  break;
98
98
  }
99
- return spawn(ctx.workspace.manager, args, { cwd: mod.sourcePath });
99
+ return spawn(ctx.workspace.manager, args, { cwd: module.sourcePath });
100
100
  }
101
101
 
102
102
  /**
@@ -116,7 +116,7 @@ export class PackageManager {
116
116
  */
117
117
  static async synchronizeVersions(): Promise<Record<string, string>> {
118
118
  const versions: Record<string, string> = {};
119
- const folders = (await CliModuleUtil.findModules('workspace')).map(mod => mod.sourcePath);
119
+ const folders = (await CliModuleUtil.findModules('workspace')).map(module => module.sourcePath);
120
120
  const packages = folders.map(folder => {
121
121
  const pkg = PackageUtil.readPackage(folder, true);
122
122
  versions[pkg.name] = `^${pkg.version}`;
@@ -130,9 +130,9 @@ export class PackageManager {
130
130
  pkg.optionalDependencies ?? {},
131
131
  pkg.peerDependencies ?? {}
132
132
  ]) {
133
- for (const [mod, ver] of Object.entries(versions)) {
134
- if (mod in group && !/^[*]|(file:.*)$/.test(group[mod])) {
135
- group[mod] = ver;
133
+ for (const [module, ver] of Object.entries(versions)) {
134
+ if (module in group && !/^[*]|(file:.*)$/.test(group[module])) {
135
+ group[module] = ver;
136
136
  }
137
137
  }
138
138
  }
@@ -1,6 +1,6 @@
1
1
  import { spawn } from 'node:child_process';
2
2
 
3
- import { CliCommand, CliCommandShape, ParsedState } from '@travetto/cli';
3
+ import { CliCommand, type CliCommandShape, type ParsedState } from '@travetto/cli';
4
4
  import { WorkPool } from '@travetto/worker';
5
5
  import { Env } from '@travetto/runtime';
6
6
  import { Ignore, Max, Min } from '@travetto/schema';
@@ -38,16 +38,16 @@ export class RepoExecCommand implements CliCommandShape {
38
38
 
39
39
  await RepoExecUtil.execOnModules(
40
40
  this.changed ? 'changed' : 'workspace',
41
- mod => spawn(cmd, finalArgs, {
42
- cwd: mod.sourceFolder,
41
+ module => spawn(cmd, finalArgs, {
42
+ cwd: module.sourceFolder,
43
43
  env: {
44
44
  ...process.env,
45
- ...Env.TRV_MODULE.export(mod.name),
45
+ ...Env.TRV_MODULE.export(module.name),
46
46
  ...Env.TRV_MANIFEST.export(undefined)
47
47
  }
48
48
  }),
49
49
  {
50
- progressMessage: mod => `Running '${cmd} ${finalArgs.join(' ')}' [%idx/%total] ${mod?.sourceFolder ?? ''}`,
50
+ progressMessage: module => `Running '${cmd} ${finalArgs.join(' ')}' [%idx/%total] ${module?.sourceFolder ?? ''}`,
51
51
  showStdout: this.showStdout,
52
52
  prefixOutput: this.prefixOutput,
53
53
  workerCount: this.workers,
@@ -1,4 +1,4 @@
1
- import { CliCommandShape, CliCommand, CliModuleUtil } from '@travetto/cli';
1
+ import { type CliCommandShape, CliCommand, CliModuleUtil } from '@travetto/cli';
2
2
  import { Runtime, RuntimeIndex } from '@travetto/runtime';
3
3
 
4
4
  const write = (line: string): Promise<void> => new Promise(resolve => process.stdout.write(`${line}\n`, () => resolve()));
@@ -29,26 +29,26 @@ export class ListModuleCommand implements CliCommandShape {
29
29
 
30
30
  async main(): Promise<void> {
31
31
 
32
- const mods = await CliModuleUtil.findModules(this.changed ? 'changed' : 'workspace', this.fromHash, this.toHash);
32
+ const modules = await CliModuleUtil.findModules(this.changed ? 'changed' : 'workspace', this.fromHash, this.toHash);
33
33
  switch (this.format) {
34
34
  case 'list': {
35
- for (const folder of mods.map(mod => mod.sourceFolder).toSorted()) {
35
+ for (const folder of modules.map(module => module.sourceFolder).toSorted()) {
36
36
  await write(folder);
37
37
  }
38
38
  break;
39
39
  }
40
40
  case 'json': {
41
- const outputMap = CliModuleUtil.getDependencyGraph(mods);
41
+ const outputMap = CliModuleUtil.getDependencyGraph(modules);
42
42
  await write(JSON.stringify(Object.entries(outputMap)
43
43
  .map(([name, children]) => ({ name, children, workspace: RuntimeIndex.getModule(name)?.workspace })), null, 2));
44
44
  break;
45
45
  }
46
46
  case 'graph': {
47
47
  await write('digraph g {');
48
- for (const mod of mods) {
49
- for (const parent of mod.parents) {
48
+ for (const module of modules) {
49
+ for (const parent of module.parents) {
50
50
  if (parent !== Runtime.main.name) {
51
- await write(` "${parent}" -> "${mod.name}";`);
51
+ await write(` "${parent}" -> "${module.name}";`);
52
52
  }
53
53
  }
54
54
  }
@@ -1,4 +1,4 @@
1
- import { CliCommandShape, CliCommand } from '@travetto/cli';
1
+ import { type CliCommandShape, CliCommand } from '@travetto/cli';
2
2
  import { Runtime } from '@travetto/runtime';
3
3
 
4
4
  import { PackageManager } from './bin/package-manager.ts';
@@ -14,23 +14,23 @@ export class RepoPublishCommand implements CliCommandShape {
14
14
  dryRun = true;
15
15
 
16
16
  async main(): Promise<void> {
17
- const published = await RepoExecUtil.execOnModules('workspace', mod => PackageManager.isPublished(Runtime, mod), {
18
- filter: mod => !!mod.workspace && !mod.internal,
19
- progressMessage: (mod) => `Checking published [%idx/%total] -- ${mod?.name}`,
17
+ const published = await RepoExecUtil.execOnModules('workspace', module => PackageManager.isPublished(Runtime, module), {
18
+ filter: module => !!module.workspace && !module.internal,
19
+ progressMessage: (module) => `Checking published [%idx/%total] -- ${module?.name}`,
20
20
  showStderr: false,
21
- transformResult: (mod, result) => PackageManager.validatePublishedResult(Runtime, mod, result),
21
+ transformResult: (module, result) => PackageManager.validatePublishedResult(Runtime, module, result),
22
22
  });
23
23
 
24
24
  if (this.dryRun) {
25
- console.log('Unpublished modules', [...published.entries()].filter(entry => !entry[1]).map(([mod]) => mod.sourceFolder));
25
+ console.log('Unpublished modules', [...published.entries()].filter(entry => !entry[1]).map(([module]) => module.sourceFolder));
26
26
  }
27
27
 
28
28
  await RepoExecUtil.execOnModules(
29
- 'workspace', mod => PackageManager.publish(Runtime, mod, this.dryRun),
29
+ 'workspace', module => PackageManager.publish(Runtime, module, this.dryRun),
30
30
  {
31
- progressMessage: (mod) => `Published [%idx/%total] -- ${mod?.name}`,
31
+ progressMessage: (module) => `Published [%idx/%total] -- ${module?.name}`,
32
32
  showStdout: false,
33
- filter: mod => published.get(mod) === false
33
+ filter: module => published.get(module) === false
34
34
  }
35
35
  );
36
36
  }
@@ -1,4 +1,4 @@
1
- import { CliCommandShape, CliCommand } from '@travetto/cli';
1
+ import { type CliCommandShape, CliCommand } from '@travetto/cli';
2
2
  import { PackageManager } from './bin/package-manager.ts';
3
3
 
4
4
  /**
@@ -1,9 +1,9 @@
1
1
  import fs from 'node:fs/promises';
2
2
 
3
- import { CliModuleUtil, CliCommandShape, CliCommand, CliScmUtil, CliValidationError } from '@travetto/cli';
3
+ import { CliModuleUtil, type CliCommandShape, CliCommand, CliScmUtil, type CliValidationError } from '@travetto/cli';
4
4
  import { Runtime } from '@travetto/runtime';
5
5
 
6
- import { PackageManager, SemverLevel } from './bin/package-manager.ts';
6
+ import { PackageManager, type SemverLevel } from './bin/package-manager.ts';
7
7
 
8
8
  const CHANGE_LEVELS = new Set<SemverLevel>(['prerelease', 'patch', 'prepatch']);
9
9
 
@@ -39,7 +39,7 @@ export class RepoVersionCommand implements CliCommandShape {
39
39
 
40
40
  const allModules = await CliModuleUtil.findModules(mode);
41
41
 
42
- const modules = allModules.filter(mod => !mod.internal && (this.mode !== 'direct' || this.modules?.includes(mod.name)));
42
+ const modules = allModules.filter(module => !module.internal && (this.mode !== 'direct' || this.modules?.includes(module.name)));
43
43
 
44
44
  // Do we have valid changes?
45
45
  if (!modules.length) {
@@ -50,7 +50,7 @@ export class RepoVersionCommand implements CliCommandShape {
50
50
 
51
51
  const versions = await PackageManager.synchronizeVersions();
52
52
  if (this.commit) {
53
- const commitMessage = `Publish ${modules.map(mod => `${mod.name}#${versions[mod.name]?.replace('^', '') ?? mod.version}`).join(',')}`;
53
+ const commitMessage = `Publish ${modules.map(module => `${module.name}#${versions[module.name]?.replace('^', '') ?? module.version}`).join(',')}`;
54
54
  console.log!(await CliScmUtil.createCommit(commitMessage));
55
55
  if (this.tag) {
56
56
  await CliScmUtil.createTag(versions['@travetto/manifest']);