Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Deno shortcuts and wildcards #508

Merged
Merged
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 shortcut and wildcard parsers to clarify broader use
Signed-off-by: Luka Leer <luka.leer@gmail.com>
  • Loading branch information
mahtaran committed Oct 11, 2024
commit d0c1a27e89a12d0824943d9c5bfa494c80bae3fb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CommandInfo } from '../command';
import { ExpandNpmShortcut } from './expand-npm-shortcut';
import { ExpandShortcut } from './expand-shortcut';

const parser = new ExpandNpmShortcut();
const parser = new ExpandShortcut();

const createCommandInfo = (command: string, name = ''): CommandInfo => ({
name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { CommandParser } from './command-parser';
* | `node:<script>` | `node --run <script>` |
* | `deno:<script>` | `deno task <script>` |
*/
export class ExpandNpmShortcut implements CommandParser {
export class ExpandShortcut implements CommandParser {
parse(commandInfo: CommandInfo) {
const [, prefix, script, args] =
/^(npm|yarn|pnpm|bun|node|deno):(\S+)(.*)/.exec(commandInfo.command) || [];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import fs from 'fs';

import { CommandInfo } from '../command';
import { ExpandNpmWildcard } from './expand-npm-wildcard';
import { ExpandWildcard } from './expand-wildcard';

let parser: ExpandNpmWildcard;
let parser: ExpandWildcard;
let readPackage: jest.Mock;
let readDeno: jest.Mock;

Expand All @@ -15,7 +15,7 @@ const createCommandInfo = (command: string): CommandInfo => ({
beforeEach(() => {
readDeno = jest.fn();
readPackage = jest.fn();
parser = new ExpandNpmWildcard(readDeno, readPackage);
parser = new ExpandWildcard(readDeno, readPackage);
});

afterEach(() => {
Expand All @@ -35,7 +35,7 @@ describe('ExpandWildcard#readDeno', () => {
return '';
});

const actualReadDeno = ExpandNpmWildcard.readDeno();
const actualReadDeno = ExpandWildcard.readDeno();
expect(actualReadDeno).toEqual(expectedDeno);
});

Expand All @@ -44,8 +44,8 @@ describe('ExpandWildcard#readDeno', () => {
throw new Error('Error reading deno');
});

expect(() => ExpandNpmWildcard.readDeno()).not.toThrow();
expect(ExpandNpmWildcard.readDeno()).toEqual({});
expect(() => ExpandWildcard.readDeno()).not.toThrow();
expect(ExpandWildcard.readDeno()).toEqual({});
});
});

Expand All @@ -62,7 +62,7 @@ describe('ExpandWildcard#readPackage', () => {
return '';
});

const actualReadPackage = ExpandNpmWildcard.readPackage();
const actualReadPackage = ExpandWildcard.readPackage();
expect(actualReadPackage).toEqual(expectedPackage);
});

Expand All @@ -71,8 +71,8 @@ describe('ExpandWildcard#readPackage', () => {
throw new Error('Error reading package');
});

expect(() => ExpandNpmWildcard.readPackage()).not.toThrow();
expect(ExpandNpmWildcard.readPackage()).toEqual({});
expect(() => ExpandWildcard.readPackage()).not.toThrow();
expect(ExpandWildcard.readPackage()).toEqual({});
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const OMISSION = /\(!([^)]+)\)/;
* commands and replaces them with all matching scripts in the `package.json`
* and `deno.json` files of the current directory.
*/
export class ExpandNpmWildcard implements CommandParser {
export class ExpandWildcard implements CommandParser {
static readDeno() {
try {
const json = fs.readFileSync('deno.json', { encoding: 'utf-8' });
Expand All @@ -34,8 +34,8 @@ export class ExpandNpmWildcard implements CommandParser {
private denoTasks?: string[];

constructor(
private readonly readDeno = ExpandNpmWildcard.readDeno,
private readonly readPackage = ExpandNpmWildcard.readPackage,
private readonly readDeno = ExpandWildcard.readDeno,
private readonly readPackage = ExpandWildcard.readPackage,
) {}

private relevantScripts(command: string): string[] {
Expand Down
8 changes: 4 additions & 4 deletions src/concurrently.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import {
} from './command';
import { CommandParser } from './command-parser/command-parser';
import { ExpandArguments } from './command-parser/expand-arguments';
import { ExpandNpmShortcut } from './command-parser/expand-npm-shortcut';
import { ExpandNpmWildcard } from './command-parser/expand-npm-wildcard';
import { ExpandShortcut } from './command-parser/expand-shortcut';
import { ExpandWildcard } from './command-parser/expand-wildcard';
import { StripQuotes } from './command-parser/strip-quotes';
import { CompletionListener, SuccessCondition } from './completion-listener';
import { FlowController } from './flow-control/flow-controller';
Expand Down Expand Up @@ -175,8 +175,8 @@ export function concurrently(

const commandParsers: CommandParser[] = [
new StripQuotes(),
new ExpandNpmShortcut(),
new ExpandNpmWildcard(),
new ExpandShortcut(),
new ExpandWildcard(),
];

if (options.additionalArguments) {
Expand Down
Loading