Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rename matrices option to matrix
I confused the term, we're creating a single matrix, as defined by
multiple dimensions/axes.
  • Loading branch information
cdrini committed Sep 8, 2025
commit 71a33490c9426e59d08469c0bb6b23e5a633df64
2 changes: 1 addition & 1 deletion bin/concurrently.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ concurrently(
timestampFormat: args.timestampFormat,
timings: args.timings,
teardown: args.teardown,
matrices: Object.fromEntries(
matrix: Object.fromEntries(
args.matrix?.map((matrix) => {
if (!matrix.includes(':')) {
throw new SyntaxError(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { describe, expect, it } from 'vitest';

import { CommandInfo } from '../command';
import { combinations, ExpandMatrices } from './expand-matrices';
import { combinations, ExpandMatrix } from './expand-matrix';

const createCommandInfo = (command: string): CommandInfo => ({
command,
name: '',
});

describe('ExpandMatrices', () => {
describe('ExpandMatrix', () => {
it('should replace placeholders with matrix values', () => {
const matrices = {
const matrix = {
X: ['a', 'b'],
Y: ['1', '2'],
};
const expandMatrices = new ExpandMatrices(matrices);
const expandMatrix = new ExpandMatrix(matrix);
const commandInfo = createCommandInfo('echo {M:X} and {M:Y}');

const result = expandMatrices.parse(commandInfo);
const result = expandMatrix.parse(commandInfo);

expect(result).toEqual([
{ command: 'echo a and 1', name: '' },
Expand All @@ -28,11 +28,11 @@ describe('ExpandMatrices', () => {
});

it('should handle escaped placeholders', () => {
const matrices = { X: ['a', 'b'] };
const expandMatrices = new ExpandMatrices(matrices);
const matrix = { X: ['a', 'b'] };
const expandMatrix = new ExpandMatrix(matrix);
const commandInfo = createCommandInfo('echo \\{M:X} and {M:X}');

const result = expandMatrices.parse(commandInfo);
const result = expandMatrix.parse(commandInfo);

expect(result).toEqual([
{ command: 'echo {M:X} and a', name: '' },
Expand All @@ -41,11 +41,11 @@ describe('ExpandMatrices', () => {
});

it('throws SyntaxError if matrix name is invalid', () => {
const matrices = { X: ['a'] };
const expandMatrices = new ExpandMatrices(matrices);
const matrix = { X: ['a'] };
const expandMatrix = new ExpandMatrix(matrix);
const commandInfo = createCommandInfo('echo {M:INVALID}');

expect(() => expandMatrices.parse(commandInfo)).toThrowError(
expect(() => expandMatrix.parse(commandInfo)).toThrowError(
"[concurrently] Matrix placeholder '{M:INVALID}' does not match any defined matrix.",
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ import { CommandInfo } from '../command';
import { CommandParser } from './command-parser';

/**
* Replace placeholders with new commands for each combination of matrices.
* Replace placeholders with new commands for each binding in the matrix expansion.
*/
export class ExpandMatrices implements CommandParser {
export class ExpandMatrix implements CommandParser {
/**
* The dimensions of the matrix, as defined by a mapping of dimension names to their possible values.
* The matrix as defined by a mapping of dimension names to their possible values.
*/
private readonly matrices: Record<string, string[]>;
private readonly matrix: Record<string, string[]>;

/**
* All combinations of the matrix dimensions.
*/
private readonly bindings: Record<string, string>[];

constructor(matrices: Record<string, string[]>) {
this.matrices = matrices;
this.bindings = Array.from(combinations(matrices));
constructor(matrix: Record<string, string[]>) {
this.matrix = matrix;
this.bindings = Array.from(combinations(matrix));
}

parse(commandInfo: CommandInfo) {
Expand All @@ -38,7 +38,7 @@ export class ExpandMatrices implements CommandParser {
return match.slice(1);
}

if (placeholderTarget && !(placeholderTarget in this.matrices)) {
if (placeholderTarget && !(placeholderTarget in this.matrix)) {
throw new Error(
`[concurrently] Matrix placeholder '{M:${placeholderTarget}}' does not match any defined matrix.`,
);
Expand Down
8 changes: 4 additions & 4 deletions src/concurrently.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from './command';
import { CommandParser } from './command-parser/command-parser';
import { ExpandArguments } from './command-parser/expand-arguments';
import { ExpandMatrices } from './command-parser/expand-matrices';
import { ExpandMatrix } from './command-parser/expand-matrix';
import { ExpandShortcut } from './command-parser/expand-shortcut';
import { ExpandWildcard } from './command-parser/expand-wildcard';
import { StripQuotes } from './command-parser/strip-quotes';
Expand Down Expand Up @@ -149,7 +149,7 @@ export type ConcurrentlyOptions = {
* Each dimension is a mapping of a dimension name to its possible values.
* Eg. `{ X: ['a', 'b'], Y: ['1', '2'] }` will run the commands 4 times.
*/
matrices?: Record<string, string[]>;
matrix?: Record<string, string[]>;

/**
* List of additional arguments passed that will get replaced in each command.
Expand Down Expand Up @@ -183,8 +183,8 @@ export function concurrently(
new ExpandWildcard(),
];

if (options.matrices?.length) {
commandParsers.push(new ExpandMatrices(options.matrices));
if (options.matrix?.length) {
commandParsers.push(new ExpandMatrix(options.matrix));
}

if (options.additionalArguments) {
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export type ConcurrentlyOptions = Omit<BaseConcurrentlyOptions, 'abortSignal' |
* Each dimension is a mapping of a dimension name to its possible values.
* Eg. `{ X: ['a', 'b'], Y: ['1', '2'] }` will run the commands 4 times.
*/
matrices?: Record<string, string[]>;
matrix?: Record<string, string[]>;
};

export function concurrently(
Expand Down Expand Up @@ -199,7 +199,7 @@ export function concurrently(
new Teardown({ logger, spawn: options.spawn, commands: options.teardown || [] }),
],
prefixColors: options.prefixColors || [],
matrices: options.matrices,
matrix: options.matrix,
additionalArguments: options.additionalArguments,
});
}
Expand Down
Loading