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 2 commits
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
3 changes: 2 additions & 1 deletion docs/cli/shortcuts.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Command Shortcuts

Package managers that execute scripts from a `package.json` file can be shortened when in concurrently.<br/>
Package managers that execute scripts from a `package.json` or `deno.json` file can be shortened when in concurrently.<br/>
The following are supported:

| Syntax | Expands to |
Expand All @@ -10,6 +10,7 @@ The following are supported:
| `yarn:<script>` | `yarn run <script>` |
| `bun:<script>` | `bun run <script>` |
| `node:<script>` | `node --run <script>` |
| `deno:<script>` | `deno task <script>` |

> [!NOTE]
>
Expand Down
40 changes: 0 additions & 40 deletions src/command-parser/expand-npm-shortcut.spec.ts

This file was deleted.

22 changes: 0 additions & 22 deletions src/command-parser/expand-npm-shortcut.ts

This file was deleted.

152 changes: 0 additions & 152 deletions src/command-parser/expand-npm-wildcard.spec.ts

This file was deleted.

75 changes: 0 additions & 75 deletions src/command-parser/expand-npm-wildcard.ts

This file was deleted.

41 changes: 41 additions & 0 deletions src/command-parser/expand-shortcut.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { CommandInfo } from '../command';
import { ExpandShortcut } from './expand-shortcut';

const parser = new ExpandShortcut();

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

it('returns same command if no prefix is present', () => {
const commandInfo = createCommandInfo('echo foo');
expect(parser.parse(commandInfo)).toBe(commandInfo);
});

describe.each([
['npm', 'npm run'],
['yarn', 'yarn run'],
['pnpm', 'pnpm run'],
['bun', 'bun run'],
['node', 'node --run'],
['deno', 'deno task'],
])(`with '%s:' prefix`, (prefix, command) => {
it(`expands to "${command} <script> <args>"`, () => {
const commandInfo = createCommandInfo(`${prefix}:foo -- bar`, 'echo');
expect(parser.parse(commandInfo)).toEqual({
...commandInfo,
name: 'echo',
command: `${command} foo -- bar`,
});
});

it('sets name to script name if none', () => {
const commandInfo = createCommandInfo(`${prefix}:foo -- bar`);
expect(parser.parse(commandInfo)).toEqual({
...commandInfo,
name: 'foo',
command: `${command} foo -- bar`,
});
});
});
39 changes: 39 additions & 0 deletions src/command-parser/expand-shortcut.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { CommandInfo } from '../command';
import { CommandParser } from './command-parser';

/**
* Expands shortcuts according to the following table:
*
* | Syntax | Expands to |
* | --------------- | --------------------- |
* | `npm:<script>` | `npm run <script>` |
* | `pnpm:<script>` | `pnpm run <script>` |
* | `yarn:<script>` | `yarn run <script>` |
* | `bun:<script>` | `bun run <script>` |
* | `node:<script>` | `node --run <script>` |
* | `deno:<script>` | `deno task <script>` |
*/
export class ExpandShortcut implements CommandParser {
parse(commandInfo: CommandInfo) {
const [, prefix, script, args] =
/^(npm|yarn|pnpm|bun|node|deno):(\S+)(.*)/.exec(commandInfo.command) || [];
if (!script) {
return commandInfo;
}

let command: string;
if (prefix === 'node') {
command = 'node --run';
} else if (prefix === 'deno') {
command = 'deno task';
} else {
command = `${prefix} run`;
}

return {
...commandInfo,
name: commandInfo.name || script,
command: `${command} ${script}${args}`,
};
}
}
Loading
Loading