-
Notifications
You must be signed in to change notification settings - Fork 0
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
refactor!: convert to TypeScript, target Node.js 16 #7
Merged
Merged
Changes from 2 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
4e1e4ce
chore!: target Node.js 16, bump dev deps, meta tweaks
tommy-mitchell e47929f
refactor: convert to TypeScript
tommy-mitchell f3f7329
fix(`ava`): use `NODE_OPTIONS` for Node.js 20
tommy-mitchell f00f01a
fix(`ava`): increase test timeout
tommy-mitchell 848e4b7
small tweaks
tommy-mitchell 4f2a91a
fix(`ava`): use `strip-ansi` to fix Node.js 20 tests
tommy-mitchell 5e0571b
add missing changes from #3
tommy-mitchell 9c0ead7
Merge branch 'main' into refactor-typescript
tommy-mitchell 1aede21
re-add cli.js
tommy-mitchell 85b0123
del src/cli.ts
tommy-mitchell 88d5e44
Rename cli.js to src/cli.ts
tommy-mitchell d332d03
re-add changes
tommy-mitchell bb0d970
update readme
tommy-mitchell 382f3c1
fix ci
tommy-mitchell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
node_modules | ||
coverage | ||
dist | ||
package-lock.json | ||
yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"rules": { | ||
"arrow-parens": "off", | ||
"quotes": "off", | ||
"@typescript-eslint/quotes": ["error", "double"], | ||
"object-curly-spacing": "off", | ||
"@typescript-eslint/object-curly-spacing": ["error", "always"], | ||
"@typescript-eslint/no-confusing-void-expression": ["error", { "ignoreArrowShorthand": true }], | ||
"object-shorthand": ["error", "always", { "avoidExplicitReturnArrows": false }], | ||
"@typescript-eslint/keyword-spacing": ["error", { "overrides": { | ||
"if": { "after": false }, | ||
"for": {"after": false }, | ||
"while": {"after": false }, | ||
"catch": {"after": false } | ||
}}] | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#!/usr/bin/env tsx | ||
import process from "node:process"; | ||
import meow from "meow"; | ||
import { $ } from "execa"; | ||
import { getTasks } from "./tasks.js"; | ||
|
||
const cli = meow(` | ||
Usage | ||
$ listr <command> […] | ||
|
||
Commands should be space-separated. Commands with spaces in them must be surrounded by quotes. | ||
|
||
Equivalent to 'command1 && command2 && …'. | ||
|
||
Options | ||
--all-optional Continue executing tasks if one fails. [default: exit] | ||
--hide-timer Disable showing successful task durations. [default: show] | ||
|
||
Examples | ||
Run test commands in order | ||
$ listr xo 'c8 ava' | ||
|
||
Run commands that can fail | ||
$ listr xo ava tsd --all-optional | ||
`, { | ||
importMeta: import.meta, | ||
description: false, | ||
flags: { | ||
help: { | ||
type: "boolean", | ||
alias: "h", | ||
}, | ||
allOptional: { | ||
type: "boolean", | ||
default: false, | ||
}, | ||
hideTimer: { | ||
type: "boolean", | ||
default: false, | ||
}, | ||
}, | ||
}); | ||
|
||
const { input: commands, flags: { help: helpShortFlag } } = cli; | ||
|
||
if(commands.length === 0 || helpShortFlag) { | ||
cli.showHelp(0); | ||
} | ||
|
||
const { allOptional, hideTimer } = cli.flags; | ||
|
||
const tasks = getTasks({ | ||
commands, | ||
exitOnError: !allOptional, | ||
showTimer: !hideTimer, | ||
}); | ||
|
||
const $$ = $({ | ||
shell: true, | ||
reject: false, | ||
all: true, | ||
// Keep command output formatting | ||
stripFinalNewline: false, | ||
env: { | ||
// https://github.com/sindresorhus/execa/issues/69#issuecomment-278693026 | ||
FORCE_COLOR: "true", // eslint-disable-line @typescript-eslint/naming-convention | ||
}, | ||
}); | ||
|
||
await tasks.run({ $$ }).catch(() => process.exit(1)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
type ParsedCommand<GetArgs extends boolean> = ( | ||
GetArgs extends true | ||
? [commandName: string, args: string[]] | ||
: string | ||
); | ||
|
||
/** | ||
* Returns the name of a given command and optionally any of its arguments. | ||
* | ||
* @param command The given command to parse. | ||
* @param getArgs Whether or not to return the command's arguments. | ||
*/ | ||
export const parseCommand = <const GetArgs extends boolean = false>( | ||
command: string, | ||
{ getArgs }: { getArgs?: GetArgs } = {}, | ||
): ParsedCommand<GetArgs> => { | ||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split#using_split | ||
// Since the separator is " ", `command.split` will always have a string at index 0 | ||
const [commandName, ...args] = command.split(" ") as [string, ...string[]]; | ||
const parsedCommand = (getArgs ? [commandName, args] : commandName) as ParsedCommand<GetArgs>; | ||
|
||
return parsedCommand; | ||
}; | ||
|
||
/** | ||
* Trims command output if it only contains one non-empty line. | ||
* | ||
* @param output Command output. | ||
* @returns The trimmed output, if needed, or the original output. | ||
*/ | ||
export const trimIfNeeded = (output: string) => { | ||
const trimmed = output.trim(); | ||
|
||
return trimmed.includes("\n") ? output : trimmed; | ||
}; | ||
|
||
// TODO: add individual tests? |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests timeout without this, for some reason.