-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: refine the pr-bundle-impact script
- Loading branch information
1 parent
11f3767
commit f1734b9
Showing
11 changed files
with
636 additions
and
147 deletions.
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
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,86 @@ | ||
import { isArray } from 'radashi' | ||
|
||
/** | ||
* Remove indentation from a string. The given string is expected to | ||
* be consistently indented (i.e. the leading whitespace of the first | ||
* non-empty line is the minimum required for all non-empty lines). | ||
* | ||
* If the `indent` argument is nullish, the indentation is detected | ||
* from the first non-empty line. Detection is cheap and robust for | ||
* most use cases, so you should only set an explicit `indent` if | ||
* necessary. | ||
* | ||
* @see https://radashi-org.github.io/reference/string/dedent | ||
* @example | ||
* ```ts | ||
* // This is indented with 4 spaces. | ||
* const input = ` | ||
* Hello | ||
* World | ||
* ` | ||
* | ||
* // Explicit indentation | ||
* dedent(input, ' ') | ||
* // => ' Hello\n World\n' | ||
* | ||
* // Detected indentation | ||
* dedent(input) | ||
* // => 'Hello\nWorld\n' | ||
* | ||
* // Tagged template strings | ||
* const str = dedent` | ||
* Foo ${1 + 1} | ||
* Bar ${2 * 2} | ||
* ` | ||
* // => 'Foo 2\nBar 4' | ||
* ``` | ||
*/ | ||
export function dedent( | ||
template: TemplateStringsArray, | ||
...values: unknown[] | ||
): string | ||
|
||
export function dedent(text: string, indent?: string | null): string | ||
|
||
export function dedent( | ||
text: string | TemplateStringsArray, | ||
...values: unknown[] | ||
): string { | ||
// Support tagged template strings | ||
if (isArray(text)) { | ||
if (values.length > 0) { | ||
return dedent( | ||
text.reduce((acc, input, i) => { | ||
let value = String(values[i] ?? '') | ||
|
||
// Detect the indentation before this embedded string. | ||
const indent = | ||
value.includes('\n') && input.match(/[ \t]*(?=[^\n]*$)/)?.[0] | ||
|
||
// Ensure the multi-line, embedded string can be correctly | ||
// dedented. | ||
if (indent) { | ||
value = value.replace(/\n(?=[^\n]*?\S)/g, '\n' + indent) | ||
} | ||
|
||
return acc + input + value | ||
}, ''), | ||
) | ||
} | ||
|
||
text = text[0] | ||
} | ||
|
||
const indent = values[0] ?? detectIndent(text) | ||
const output = indent | ||
? text.replace(new RegExp(`^${indent}`, 'gm'), '') | ||
: text | ||
|
||
// Remove the first and last lines (if empty). | ||
return output.replace(/^[ \t]*\n|\n[ \t]*$/g, '') | ||
} | ||
|
||
// Find the indentation of the first non-empty line. | ||
function detectIndent(text: string) { | ||
return text.match(/^[ \t]*(?=\S)/m)?.[0] | ||
} |
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,7 @@ | ||
{ | ||
"private": true, | ||
"dependencies": { | ||
"execa": "^9.3.0", | ||
"radashi": "12.2.0-beta.7fb6e89" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.