Skip to content

Commit

Permalink
Code Style & Performance Optimizations (#334)
Browse files Browse the repository at this point in the history
  • Loading branch information
paescuj committed Jun 24, 2022
1 parent 0980e5b commit 06c83bc
Show file tree
Hide file tree
Showing 26 changed files with 830 additions and 574 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.json
Expand Up @@ -17,7 +17,9 @@
"curly": "error",
"eqeqeq": ["error", "always", { "null": "ignore" }],
"no-var": "error",
"no-console": "error",
"prefer-const": "error",
"prefer-object-spread": "error",
"prettier/prettier": ["error"]
}
}
14 changes: 14 additions & 0 deletions .github/actions/setup-npm-cache/action.yml
@@ -0,0 +1,14 @@
# See https://github.com/actions/cache/blob/main/examples.md#node---npm
name: Setup NPM cache
runs:
using: composite
steps:
- id: npm-cache-dir
run: echo "::set-output name=dir::$(npm config get cache)"
shell: bash
- uses: actions/cache@v3
with:
path: ${{ steps.npm-cache-dir.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
104 changes: 104 additions & 0 deletions .github/workflows/ci.yml
@@ -0,0 +1,104 @@
# Continuous Integration
name: CI

on:
push:
branches:
- main
pull_request:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
lint-format:
name: Lint & Format
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}

- name: Setup NPM cache
uses: ./.github/actions/setup-npm-cache

- name: Install dependencies
run: npm ci

- name: Lint
run: npm run lint

- name: Format
run: npm run format

test:
name: Test (Node.js ${{ matrix.node }} on ${{ matrix.os.name }})
runs-on: ${{ matrix.os.version }}
strategy:
fail-fast: false
matrix:
node:
- 12
- 14
- 16
- 17
os:
- name: Ubuntu
version: ubuntu-latest
- name: Windows
version: windows-latest
- name: macOS
version: macOS-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}

- name: Setup NPM cache
uses: ./.github/actions/setup-npm-cache

- name: Print versions
run: |
node --version
npm --version
- name: Install dependencies
run: npm ci

- name: Build
run: npm run build

- name: Test
run: npm test
shell: bash
env:
SHELL: '/bin/bash'

- name: Submit coverage
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.github_token }}
flag-name: Node.js ${{ matrix.node }} on ${{ matrix.os.name }}
parallel: true

coverage:
name: Coverage
needs: test
runs-on: ubuntu-latest
steps:
- name: Finish coverage
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.github_token }}
parallel-finished: true
68 changes: 0 additions & 68 deletions .github/workflows/test.yml

This file was deleted.

32 changes: 16 additions & 16 deletions README.md
Expand Up @@ -85,15 +85,15 @@ package.json:

```jsonc
{
//...
"scripts": {
// ...
"watch-js": "...",
"watch-css": "...",
"watch-node": "...",
// ...
},
//...
"scripts": {
// ...
"watch-js": "...",
"watch-css": "...",
"watch-node": "..."
// ...
}
// ...
}
```

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

```jsonc
{
// ...
"scripts": {
"lint:js": "...",
"lint:ts": "...",
"lint:fix:js": "...",
"lint:fix:ts": "..."
// ...
"scripts": {
"lint:js": "...",
"lint:ts": "...",
"lint:fix:js": "...",
"lint:fix:ts": "...",
// ...
}
// ...
}
// ...
}
```

Expand Down
19 changes: 9 additions & 10 deletions bin/concurrently.spec.ts
Expand Up @@ -2,11 +2,7 @@ import * as readline from 'readline';
import _ from 'lodash';
import * as Rx from 'rxjs';
import { buffer, map } from 'rxjs/operators';
import spawn from 'spawn-command';

// Increasing timeout for these tests as sometimes it exceeded
// in the CI when running on macOS / Windows (default is 5000ms)
jest.setTimeout(10000);
import { spawn } from 'child_process';

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

const stdout = readline.createInterface({
Expand Down
1 change: 1 addition & 0 deletions bin/fixtures/read-echo.js
@@ -1,3 +1,4 @@
/* eslint-disable no-console */
process.stdin.on('data', chunk => {
const line = chunk.toString().trim();
console.log(line);
Expand Down
11 changes: 11 additions & 0 deletions jest.config.js
@@ -0,0 +1,11 @@
/** @type {import('@jest/types').Config.InitialOptions} */
const config = {
transform: {
'^.+\\.(t|j)sx?$': ['@swc/jest'],
},
collectCoverage: true,
collectCoverageFrom: ['src/**/*.ts', '!src/index.ts'],
testPathIgnorePatterns: ['/node_modules/', '/dist'],
};

module.exports = config;

0 comments on commit 06c83bc

Please sign in to comment.