Skip to content

Commit 646f409

Browse files
authored
Modernize (#12)
1 parent de18a67 commit 646f409

File tree

10 files changed

+254
-192
lines changed

10 files changed

+254
-192
lines changed

.editorconfig

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# EditorConfig is awesome: https://editorconfig.org
2+
3+
root = true
4+
5+
[*]
6+
indent_style = tab
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true
11+
12+
[*.{ts,mts,mjs,cjs,js}]
13+
indent_style = tab
14+
15+
[*.json]
16+
indent_style = tab
17+
18+
[*.md]
19+
indent_style = tab

.github/workflows/awaitqueue.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ jobs:
2323
node: 20
2424
- os: ubuntu-24.04
2525
node: 22
26-
- os: macos-13
27-
node: 18
2826
- os: macos-14
2927
node: 20
3028
- os: macos-15
3129
node: 22
3230
- os: windows-2022
31+
node: 20
32+
- os: windows-2025
3333
node: 22
3434

3535
runs-on: ${{ matrix.ci.os }}

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ npm install awaitqueue
1414

1515
## Usage
1616

17-
In ES6:
17+
In ESM:
1818

19-
```js
19+
```ts
2020
import {
2121
AwaitQueue,
2222
AwaitQueueTask,
@@ -26,9 +26,9 @@ import {
2626
} from 'awaitqueue';
2727
```
2828

29-
In CommonJS:
29+
Using CommonJS:
3030

31-
```js
31+
```ts
3232
const {
3333
AwaitQueue,
3434
AwaitQueueTask,

eslint.config.mjs

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const config = tsEslint.config(
88
{
99
languageOptions: {
1010
sourceType: 'module',
11-
globals: { ...globals.browser },
11+
globals: { ...globals.node },
1212
},
1313
linterOptions: {
1414
noInlineConfig: false,
@@ -107,18 +107,20 @@ const config = tsEslint.config(
107107
yoda: 2,
108108
},
109109
},
110-
// NOTE: We need to apply this only to .ts files (and not to .mjs files).
110+
// NOTE: We need to apply this only to .ts source files (and not to .mjs
111+
// files).
111112
...tsEslint.configs.recommendedTypeChecked.map(item => ({
112113
...item,
113114
files: ['src/**/*.ts'],
114115
})),
115-
// NOTE: We need to apply this only to .ts files (and not to .mjs files).
116+
// NOTE: We need to apply this only to .ts source files (and not to .mjs
117+
// files).
116118
...tsEslint.configs.stylisticTypeChecked.map(item => ({
117119
...item,
118120
files: ['src/**/*.ts'],
119121
})),
120122
{
121-
name: 'mediasoup-client .ts files',
123+
name: '.ts source files',
122124
files: ['src/**/*.ts'],
123125
languageOptions: {
124126
parserOptions: {
@@ -143,27 +145,17 @@ const config = tsEslint.config(
143145
],
144146
// We want to use `type` instead of `interface`.
145147
'@typescript-eslint/consistent-type-definitions': 0,
148+
'@typescript-eslint/explicit-function-return-type': [
149+
2,
150+
{ allowExpressions: true },
151+
],
146152
// Sorry, we need many `any` usage.
147153
'@typescript-eslint/no-explicit-any': 0,
148-
'@typescript-eslint/no-unsafe-member-access': 0,
149-
'@typescript-eslint/no-unsafe-assignment': 0,
150-
'@typescript-eslint/no-unsafe-call': 0,
151-
'@typescript-eslint/no-unsafe-return': 0,
152-
'@typescript-eslint/no-unsafe-argument': 0,
153-
'@typescript-eslint/consistent-indexed-object-style': 0,
154154
'@typescript-eslint/no-empty-function': 0,
155-
'@typescript-eslint/require-await': 0,
156-
'@typescript-eslint/restrict-template-expressions': 0,
157-
'@typescript-eslint/no-duplicate-type-constituents': [
158-
2,
159-
{ ignoreUnions: true },
160-
],
161-
'@typescript-eslint/unbound-method': 0,
162-
'@typescript-eslint/prefer-string-starts-ends-with': 0,
163155
},
164156
},
165157
{
166-
name: 'mediasoup-client .ts test files',
158+
name: '.ts test files',
167159
...jestEslint.configs['flat/recommended'],
168160
files: ['src/test/**/*.ts'],
169161
rules: {

jest.config.mjs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const config = {
2+
verbose: true,
3+
testEnvironment: 'node',
4+
testRegex: 'src/tests/test.ts',
5+
transform: {
6+
'^.+\\.ts?$': ['ts-jest'],
7+
},
8+
coveragePathIgnorePatterns: ['src/Logger.ts', 'src/tests'],
9+
cacheDirectory: '.cache/jest',
10+
};
11+
12+
export default config;

npm-scripts.mjs

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,37 @@ import { execSync } from 'node:child_process';
44

55
const PKG = JSON.parse(fs.readFileSync('./package.json').toString());
66
const RELEASE_BRANCH = 'master';
7+
78
// Paths for ESLint to check. Converted to string for convenience.
8-
const ESLINT_PATHS = ['eslint.config.mjs', 'src', 'npm-scripts.mjs'].join(' ');
9+
const ESLINT_PATHS = [
10+
'eslint.config.mjs',
11+
'jest.config.mjs',
12+
'npm-scripts.mjs',
13+
'src',
14+
].join(' ');
915
// Paths for ESLint to ignore. Converted to string argument for convenience.
16+
1017
const ESLINT_IGNORE_PATTERN_ARGS = []
1118
.map(entry => `--ignore-pattern ${entry}`)
1219
.join(' ');
20+
1321
// Paths for Prettier to check/write. Converted to string for convenience.
1422
// NOTE: Prettier ignores paths in .gitignore so we don't need to care about
1523
// node/src/fbs.
1624
const PRETTIER_PATHS = [
1725
'README.md',
1826
'eslint.config.mjs',
19-
'src',
27+
'jest.config.mjs',
2028
'npm-scripts.mjs',
2129
'package.json',
2230
'tsconfig.json',
31+
'src',
2332
].join(' ');
2433

2534
const task = process.argv[2];
2635
const args = process.argv.slice(3).join(' ');
2736

28-
run();
37+
void run();
2938

3039
async function run() {
3140
logInfo(args ? `[args:"${args}"]` : '');
@@ -34,11 +43,13 @@ async function run() {
3443
// As per NPM documentation (https://docs.npmjs.com/cli/v9/using-npm/scripts)
3544
// `prepare` script:
3645
//
37-
// - Runs BEFORE the package is packed, i.e. during `npm publish` and `npm pack`.
46+
// - Runs BEFORE the package is packed, i.e. during `npm publish` and
47+
// `npm pack`.
3848
// - Runs on local `npm install` without any arguments.
39-
// - NOTE: If a package being installed through git contains a `prepare` script,
40-
// its dependencies and devDependencies will be installed, and the `prepare`
41-
// script will be run, before the package is packaged and installed.
49+
// - NOTE: If a package being installed through git contains a `prepare`
50+
// script, its dependencies and devDependencies will be installed, and
51+
// the `prepare` script will be run, before the package is packaged and
52+
// installed.
4253
//
4354
// So here we compile TypeScript to JavaScript.
4455
case 'prepare': {
@@ -48,15 +59,13 @@ async function run() {
4859
}
4960

5061
case 'typescript:build': {
51-
installDeps();
5262
buildTypescript({ force: true });
5363

5464
break;
5565
}
5666

5767
case 'typescript:watch': {
58-
deleteLib();
59-
executeCmd(`tsc --watch ${args}`);
68+
watchTypescript();
6069

6170
break;
6271
}
@@ -74,14 +83,12 @@ async function run() {
7483
}
7584

7685
case 'test': {
77-
buildTypescript({ force: false });
7886
test();
7987

8088
break;
8189
}
8290

8391
case 'coverage': {
84-
buildTypescript({ force: false });
8592
executeCmd(`jest --coverage ${args}`);
8693
executeCmd('open-cli coverage/lcov-report/index.html');
8794

@@ -123,15 +130,25 @@ function deleteLib() {
123130
fs.rmSync('lib', { recursive: true, force: true });
124131
}
125132

126-
function buildTypescript({ force = false } = { force: false }) {
133+
function buildTypescript({ force }) {
127134
if (!force && fs.existsSync('lib')) {
128135
return;
129136
}
130137

131138
logInfo('buildTypescript()');
132139

133140
deleteLib();
134-
executeCmd('tsc');
141+
142+
// Generate .js CommonJS code and .d.ts TypeScript declaration files in lib/.
143+
executeCmd(`tsc ${args}`);
144+
}
145+
146+
function watchTypescript() {
147+
logInfo('watchTypescript()');
148+
149+
deleteLib();
150+
151+
executeCmd(`tsc --watch ${args}`);
135152
}
136153

137154
function lint() {
@@ -165,6 +182,7 @@ function installDeps() {
165182

166183
// Install/update deps.
167184
executeCmd('npm ci --ignore-scripts');
185+
168186
// Update package-lock.json.
169187
executeCmd('npm install --package-lock-only --ignore-scripts');
170188
}
@@ -178,19 +196,15 @@ function checkRelease() {
178196
test();
179197
}
180198

181-
function executeCmd(command, exitOnError = true) {
199+
function executeCmd(command) {
182200
logInfo(`executeCmd(): ${command}`);
183201

184202
try {
185203
execSync(command, { stdio: ['ignore', process.stdout, process.stderr] });
186204
} catch (error) {
187-
if (exitOnError) {
188-
logError(`executeCmd() failed, exiting: ${error}`);
205+
logError(`executeCmd() failed, exiting: ${error}`);
189206

190-
exitWithError();
191-
} else {
192-
logInfo(`executeCmd() failed, ignoring: ${error}`);
193-
}
207+
exitWithError();
194208
}
195209
}
196210

0 commit comments

Comments
 (0)