Skip to content

Commit 06c83bc

Browse files
authoredJun 24, 2022
Code Style & Performance Optimizations (#334)
1 parent 0980e5b commit 06c83bc

26 files changed

+830
-574
lines changed
 

‎.eslintrc.json

+2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
"curly": "error",
1818
"eqeqeq": ["error", "always", { "null": "ignore" }],
1919
"no-var": "error",
20+
"no-console": "error",
2021
"prefer-const": "error",
22+
"prefer-object-spread": "error",
2123
"prettier/prettier": ["error"]
2224
}
2325
}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# See https://github.com/actions/cache/blob/main/examples.md#node---npm
2+
name: Setup NPM cache
3+
runs:
4+
using: composite
5+
steps:
6+
- id: npm-cache-dir
7+
run: echo "::set-output name=dir::$(npm config get cache)"
8+
shell: bash
9+
- uses: actions/cache@v3
10+
with:
11+
path: ${{ steps.npm-cache-dir.outputs.dir }}
12+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
13+
restore-keys: |
14+
${{ runner.os }}-node-

‎.github/workflows/ci.yml

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Continuous Integration
2+
name: CI
3+
4+
on:
5+
push:
6+
branches:
7+
- main
8+
pull_request:
9+
branches:
10+
- main
11+
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.ref }}
14+
cancel-in-progress: true
15+
16+
jobs:
17+
lint-format:
18+
name: Lint & Format
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v3
23+
24+
- name: Setup Node.js
25+
uses: actions/setup-node@v3
26+
with:
27+
node-version: ${{ matrix.node }}
28+
29+
- name: Setup NPM cache
30+
uses: ./.github/actions/setup-npm-cache
31+
32+
- name: Install dependencies
33+
run: npm ci
34+
35+
- name: Lint
36+
run: npm run lint
37+
38+
- name: Format
39+
run: npm run format
40+
41+
test:
42+
name: Test (Node.js ${{ matrix.node }} on ${{ matrix.os.name }})
43+
runs-on: ${{ matrix.os.version }}
44+
strategy:
45+
fail-fast: false
46+
matrix:
47+
node:
48+
- 12
49+
- 14
50+
- 16
51+
- 17
52+
os:
53+
- name: Ubuntu
54+
version: ubuntu-latest
55+
- name: Windows
56+
version: windows-latest
57+
- name: macOS
58+
version: macOS-latest
59+
steps:
60+
- name: Checkout repository
61+
uses: actions/checkout@v3
62+
63+
- name: Setup Node.js
64+
uses: actions/setup-node@v3
65+
with:
66+
node-version: ${{ matrix.node }}
67+
68+
- name: Setup NPM cache
69+
uses: ./.github/actions/setup-npm-cache
70+
71+
- name: Print versions
72+
run: |
73+
node --version
74+
npm --version
75+
76+
- name: Install dependencies
77+
run: npm ci
78+
79+
- name: Build
80+
run: npm run build
81+
82+
- name: Test
83+
run: npm test
84+
shell: bash
85+
env:
86+
SHELL: '/bin/bash'
87+
88+
- name: Submit coverage
89+
uses: coverallsapp/github-action@master
90+
with:
91+
github-token: ${{ secrets.github_token }}
92+
flag-name: Node.js ${{ matrix.node }} on ${{ matrix.os.name }}
93+
parallel: true
94+
95+
coverage:
96+
name: Coverage
97+
needs: test
98+
runs-on: ubuntu-latest
99+
steps:
100+
- name: Finish coverage
101+
uses: coverallsapp/github-action@master
102+
with:
103+
github-token: ${{ secrets.github_token }}
104+
parallel-finished: true

‎.github/workflows/test.yml

-68
This file was deleted.

‎README.md

+16-16
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,15 @@ package.json:
8585

8686
```jsonc
8787
{
88-
//...
89-
"scripts": {
90-
// ...
91-
"watch-js": "...",
92-
"watch-css": "...",
93-
"watch-node": "...",
94-
// ...
95-
},
88+
//...
89+
"scripts": {
90+
// ...
91+
"watch-js": "...",
92+
"watch-css": "...",
93+
"watch-node": "..."
9694
// ...
95+
}
96+
// ...
9797
}
9898
```
9999

@@ -115,15 +115,15 @@ Exclusion is also supported. Given the following scripts in package.json:
115115

116116
```jsonc
117117
{
118+
// ...
119+
"scripts": {
120+
"lint:js": "...",
121+
"lint:ts": "...",
122+
"lint:fix:js": "...",
123+
"lint:fix:ts": "..."
118124
// ...
119-
"scripts": {
120-
"lint:js": "...",
121-
"lint:ts": "...",
122-
"lint:fix:js": "...",
123-
"lint:fix:ts": "...",
124-
// ...
125-
}
126-
// ...
125+
}
126+
// ...
127127
}
128128
```
129129

‎bin/concurrently.spec.ts

+9-10
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ import * as readline from 'readline';
22
import _ from 'lodash';
33
import * as Rx from 'rxjs';
44
import { buffer, map } from 'rxjs/operators';
5-
import spawn from 'spawn-command';
6-
7-
// Increasing timeout for these tests as sometimes it exceeded
8-
// in the CI when running on macOS / Windows (default is 5000ms)
9-
jest.setTimeout(10000);
5+
import { spawn } from 'child_process';
106

117
const isWindows = process.platform === 'win32';
128
const createKillMessage = (prefix: string) =>
@@ -17,14 +13,17 @@ const createKillMessage = (prefix: string) =>
1713
* Returns observables for its combined stdout + stderr output, close events, pid, and stdin stream.
1814
*/
1915
const run = (args: string) => {
20-
// TODO: This should only be transpiled once. Tests become 2.5x slower doing it in every `it`.
21-
const child = spawn('ts-node --transpile-only ./concurrently.ts ' + args, {
16+
// TODO: Optimally, this should only be transpiled once,
17+
// e.g. bundle in `beforeAll` and then reuse here.
18+
const child = spawn(`node -r @swc-node/register ./concurrently.ts ${args}`, {
19+
shell: true,
2220
cwd: __dirname,
23-
env: Object.assign({}, process.env, {
21+
env: {
22+
...process.env,
2423
// When upgrading from jest 23 -> 24, colors started printing in the test output.
2524
// They are forcibly disabled here
26-
FORCE_COLOR: 0,
27-
}),
25+
FORCE_COLOR: '0',
26+
},
2827
});
2928

3029
const stdout = readline.createInterface({

‎bin/fixtures/read-echo.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-console */
12
process.stdin.on('data', chunk => {
23
const line = chunk.toString().trim();
34
console.log(line);

‎jest.config.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/** @type {import('@jest/types').Config.InitialOptions} */
2+
const config = {
3+
transform: {
4+
'^.+\\.(t|j)sx?$': ['@swc/jest'],
5+
},
6+
collectCoverage: true,
7+
collectCoverageFrom: ['src/**/*.ts', '!src/index.ts'],
8+
testPathIgnorePatterns: ['/node_modules/', '/dist'],
9+
};
10+
11+
module.exports = config;

0 commit comments

Comments
 (0)
Please sign in to comment.