Skip to content

Commit

Permalink
fix: recognize .mts and .cts extensions as TS files (#474)
Browse files Browse the repository at this point in the history
  • Loading branch information
wellwelwel authored Jun 26, 2024
1 parent 716cf5c commit c073ed3
Show file tree
Hide file tree
Showing 44 changed files with 497 additions and 74 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/bot_deps-docs-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: ➕ Actions - Checkout
uses: actions/checkout@v4

- name: ➕ Actions - Setup NodeJS
- name: ➕ Actions - Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22.x'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/bot_deps-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: ➕ Actions - Checkout
uses: actions/checkout@v4

- name: ➕ Actions - Setup NodeJS
- name: ➕ Actions - Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22.x'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cd_docs-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Actions - Checkout
uses: actions/checkout@v4

- name: Actions - Setup NodeJS
- name: Actions - Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22.x'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cd_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
uses: actions/checkout@v4
if: ${{ steps.release.outputs.releases_created }}

- name: ➕ Actions - Setup NodeJS
- name: ➕ Actions - Setup Node.js
uses: actions/setup-node@v4
if: ${{ steps.release.outputs.releases_created }}
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: ➕ Actions - Checkout
uses: actions/checkout@v4

- name: ➕ Actions - Setup NodeJS
- name: ➕ Actions - Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22.x'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_compatibility-bun.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: ➕ Actions - Checkout
uses: actions/checkout@v4

- name: ➕ Actions - Setup NodeJS
- name: ➕ Actions - Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22.x'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_compatibility-deno.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: ➕ Actions - Checkout
uses: actions/checkout@v4

- name: ➕ Actions - Setup NodeJS
- name: ➕ Actions - Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22.x'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_compatibility-nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- name: ➕ Actions - Checkout
uses: actions/checkout@v4

- name: ➕ Actions - Setup NodeJS
- name: ➕ Actions - Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22.x'
Expand Down
48 changes: 44 additions & 4 deletions .github/workflows/ci_coverage-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,21 @@ jobs:
- name: ➕ Actions - Checkout
uses: actions/checkout@v4

- name: ➕ Actions - Setup NodeJS
- name: ➕ Actions - Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22.x'

- name: ➕ Actions - Setup Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: 'latest'

- name: ➕ Actions - Setup Deno
uses: denoland/setup-deno@v1
with:
deno-version: 'v1.x'

- name: ➕ Cache dependencies
uses: actions/cache@v4
with:
Expand Down Expand Up @@ -53,11 +63,21 @@ jobs:
- name: ➕ Actions - Checkout
uses: actions/checkout@v4

- name: ➕ Actions - Setup NodeJS
- name: ➕ Actions - Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22.x'

- name: ➕ Actions - Setup Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: 'latest'

- name: ➕ Actions - Setup Deno
uses: denoland/setup-deno@v1
with:
deno-version: 'v1.x'

- name: ➕ Cache dependencies
uses: actions/cache@v4
with:
Expand Down Expand Up @@ -88,11 +108,21 @@ jobs:
- name: ➕ Actions - Checkout
uses: actions/checkout@v4

- name: ➕ Actions - Setup NodeJS
- name: ➕ Actions - Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22.x'

- name: ➕ Actions - Setup Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: 'latest'

- name: ➕ Actions - Setup Deno
uses: denoland/setup-deno@v1
with:
deno-version: 'v1.x'

- name: ➕ Cache dependencies
uses: actions/cache@v4
with:
Expand Down Expand Up @@ -123,11 +153,21 @@ jobs:
- name: ➕ Actions - Checkout
uses: actions/checkout@v4

- name: ➕ Actions - Setup NodeJS
- name: ➕ Actions - Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22.x'

- name: ➕ Actions - Setup Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: 'latest'

- name: ➕ Actions - Setup Deno
uses: denoland/setup-deno@v1
with:
deno-version: 'v1.x'

- name: ➕ Cache dependencies
uses: actions/cache@v4
with:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/ci_coverage-osx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
key: npm-osx-${{ hashFiles('package-lock.json') }}
restore-keys: npm-osx-

- name: ➕ Actions - Setup NodeJS
- name: ➕ Actions - Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22.x'
Expand Down Expand Up @@ -60,7 +60,7 @@ jobs:
key: npm-osx-${{ hashFiles('package-lock.json') }}
restore-keys: npm-osx-

- name: ➕ Actions - Setup NodeJS
- name: ➕ Actions - Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22.x'
Expand Down Expand Up @@ -95,7 +95,7 @@ jobs:
key: npm-osx-${{ hashFiles('package-lock.json') }}
restore-keys: npm-osx-

- name: ➕ Actions - Setup NodeJS
- name: ➕ Actions - Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22.x'
Expand Down Expand Up @@ -130,7 +130,7 @@ jobs:
key: npm-osx-${{ hashFiles('package-lock.json') }}
restore-keys: npm-osx-

- name: ➕ Actions - Setup NodeJS
- name: ➕ Actions - Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22.x'
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/ci_coverage-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: ➕ Actions - Checkout
uses: actions/checkout@v4

- name: ➕ Actions - Setup NodeJS
- name: ➕ Actions - Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22.x'
Expand Down Expand Up @@ -47,7 +47,7 @@ jobs:
- name: ➕ Actions - Checkout
uses: actions/checkout@v4

- name: ➕ Actions - Setup NodeJS
- name: ➕ Actions - Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22.x'
Expand Down Expand Up @@ -76,7 +76,7 @@ jobs:
- name: ➕ Actions - Checkout
uses: actions/checkout@v4

- name: ➕ Actions - Setup NodeJS
- name: ➕ Actions - Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22.x'
Expand Down Expand Up @@ -105,7 +105,7 @@ jobs:
- name: ➕ Actions - Checkout
uses: actions/checkout@v4

- name: ➕ Actions - Setup NodeJS
- name: ➕ Actions - Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22.x'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_docs-website.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Actions - Checkout
uses: actions/checkout@v4

- name: Actions - Setup NodeJS
- name: Actions - Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22.x'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: ➕ Actions - Checkout
uses: actions/checkout@v4

- name: ➕ Actions - Setup NodeJS
- name: ➕ Actions - Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22.x'
Expand Down
6 changes: 6 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@
"include": ["src/polyfills/**/**"],
"linter": {
"rules": {
"style": {
"noNonNullAssertion": "off"
},
"suspicious": {
"noExplicitAny": "off"
}
Expand All @@ -85,6 +88,9 @@
"include": ["src/index.ts"],
"linter": {
"rules": {
"style": {
"noNonNullAssertion": "off"
},
"performance": {
"noBarrelFile": "off"
}
Expand Down
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
6 changes: 3 additions & 3 deletions src/helpers/find-file.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* c8 ignore start */
/* c8 ignore next */ // c8 bug
const regex = /at\s(\/.+|file:.+)|^(\s+)at\smodule\scode\s\((\/.+|file:.+)\)/i;

/* c8 ignore next */ // c8 bug
export const findFile = (error: Error) => {
const stackLines = error.stack?.split('\n') || [];

Expand All @@ -9,7 +10,7 @@ export const findFile = (error: Error) => {
const basePath = 'poku/lib/';

for (const line of stackLines) {
if (!line.includes(basePath)) {
if (line.indexOf(basePath) === -1) {
const match = line.match(regex);

// Node and Deno
Expand All @@ -28,4 +29,3 @@ export const findFile = (error: Error) => {

return file;
};
/* c8 ignore stop */
8 changes: 0 additions & 8 deletions src/helpers/force-array.ts

This file was deleted.

39 changes: 28 additions & 11 deletions src/helpers/get-arg.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* c8 ignore start */
/* c8 ignore next */ // c8 bug
import { argv } from 'node:process';

const [, , ...processArgs] = argv;
Expand All @@ -17,9 +17,13 @@ const regexQuotes = /''|""/;
* command --arg # undefined
* ```
*/
export const getArg = (arg: string, prefix = '--'): string | undefined => {
export const getArg = (
arg: string,
prefix = '--',
baseArgs = processArgs
): string | undefined => {
const argPattern = `${prefix}${arg}=`;
const argValue = processArgs.find((a) => a.startsWith(argPattern));
const argValue = baseArgs.find((a) => a.startsWith(argPattern));

if (!argValue) {
return undefined;
Expand All @@ -40,10 +44,14 @@ export const getArg = (arg: string, prefix = '--'): string | undefined => {
* command # false
* ```
*/
export const hasArg = (arg: string, prefix = '--'): boolean => {
export const hasArg = (
arg: string,
prefix = '--',
baseArgs = processArgs
): boolean => {
const argPattern = `${prefix}${arg}`;

return processArgs.some((a) => a.startsWith(argPattern));
return baseArgs.some((a) => a.startsWith(argPattern));
};

/**
Expand All @@ -58,8 +66,11 @@ export const hasArg = (arg: string, prefix = '--'): boolean => {
* command --arg # undefined
* ```
*/
export const getLastParam = (prefix = '--'): string | undefined => {
const lastArg = processArgs[processArgs.length - 1];
export const getLastParam = (
prefix = '--',
baseArgs = processArgs
): string | undefined => {
const lastArg = baseArgs[baseArgs.length - 1];

if (!lastArg || lastArg.startsWith(prefix)) {
return undefined;
Expand All @@ -68,25 +79,31 @@ export const getLastParam = (prefix = '--'): string | undefined => {
return lastArg;
};

export const argToArray = (arg: string, prefix = '--') => {
const hasArgument = hasArg(arg);
/* c8 ignore next */ // c8 bug
export const argToArray = (
arg: string,
prefix = '--',
baseArgs = processArgs
) => {
const hasArgument = hasArg(arg, prefix, baseArgs);
if (!hasArgument) {
return undefined;
}

const argValue = getArg(arg, prefix);
const argValue = getArg(arg, prefix, baseArgs);

if (hasArgument && !argValue) {
return [];
}

/* c8 ignore start */ // Type safe
if (!argValue) {
return undefined;
}
/* c8 ignore stop */

return argValue
.split(',')
.map((a) => a.trim())
.filter((a) => a);
};
/* c8 ignore stop */
Loading

0 comments on commit c073ed3

Please sign in to comment.