Skip to content

Commit

Permalink
Require Node.js 18
Browse files Browse the repository at this point in the history
Fixes #22
  • Loading branch information
sindresorhus committed Sep 14, 2023
1 parent 40f346d commit 6e107f6
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 29 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ jobs:
fail-fast: false
matrix:
node-version:
- 14
- 12
- 20
- 18
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm install
Expand Down
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import indentString from 'indent-string';
import cleanStack from 'clean-stack';

const cleanInternalStack = stack => stack.replace(/\s+at .*aggregate-error\/index.js:\d+:\d+\)?/g, '');
const cleanInternalStack = stack => stack.replaceAll(/\s+at .*aggregate-error\/index.js:\d+:\d+\)?/g, '');

export default class AggregateError extends Error {
#errors;
Expand All @@ -27,10 +27,10 @@ export default class AggregateError extends Error {
});

let message = errors
.map(error => {
.map(error =>
// The `stack` property is not standardized, so we can't assume it exists
return typeof error.stack === 'string' && error.stack.length > 0 ? cleanInternalStack(cleanStack(error.stack)) : String(error);
})
typeof error.stack === 'string' && error.stack.length > 0 ? cleanInternalStack(cleanStack(error.stack)) : String(error),
)
.join('\n');
message = '\n' + indentString(message, 4);
super(message);
Expand All @@ -39,6 +39,6 @@ export default class AggregateError extends Error {
}

get errors() {
return this.#errors.slice();
return [...this.#errors];
}
}
4 changes: 2 additions & 2 deletions index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import AggregateError from './index.js';
const aggregateError = new AggregateError([
new Error('foo'),
{foo: 'bar'},
'bar'
'bar',
]);
expectAssignable<Iterable<Error>>(aggregateError.errors);
expectType<IterableIterator<Error>>(aggregateError.errors[Symbol.iterator]());
Expand All @@ -23,7 +23,7 @@ class CustomError extends Error {
}
}
const customAggregateError = new AggregateError<CustomError>([
new CustomError('foo')
new CustomError('foo'),
]);

for (const error of customAggregateError.errors) {
Expand Down
18 changes: 10 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
"url": "https://sindresorhus.com"
},
"type": "module",
"exports": "./index.js",
"exports": {
"types": "./index.d.ts",
"default": "./index.js"
},
"engines": {
"node": ">=12"
"node": ">=18"
},
"scripts": {
"//test": "xo && ava && tsd",
"test": "ava && tsd"
"test": "xo && ava && tsd"
},
"files": [
"index.js",
Expand All @@ -34,12 +36,12 @@
"iterator"
],
"dependencies": {
"clean-stack": "^4.0.0",
"clean-stack": "^5.2.0",
"indent-string": "^5.0.0"
},
"devDependencies": {
"ava": "^3.15.0",
"tsd": "^0.14.0",
"xo": "^0.38.2"
"ava": "^5.3.1",
"tsd": "^0.29.0",
"xo": "^0.56.0"
}
}
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

## Install

```
$ npm install aggregate-error
```sh
npm install aggregate-error
```

## Usage
Expand Down
16 changes: 8 additions & 8 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ test('main', t => {
'bar',
{
message: 'baz',
code: 'EBAZ'
code: 'EBAZ',
},
{
code: 'EQUX'
}
code: 'EQUX',
},
]);

console.log(error);
Expand All @@ -23,7 +23,7 @@ test('main', t => {
new Error('foo'),
new Error('bar'),
Object.assign(new Error('baz'), {code: 'EBAZ'}),
Object.assign(new Error(), {code: 'EQUX'}) // eslint-disable-line unicorn/error-message
Object.assign(new Error(), {code: 'EQUX'}), // eslint-disable-line unicorn/error-message
]);
});

Expand All @@ -38,7 +38,7 @@ test('gracefully handle Error instances without a stack', t => {

const error = new AggregateError([
new Error('foo'),
new StacklessError('stackless')
new StacklessError('stackless'),
]);

console.log(error);
Expand All @@ -48,7 +48,7 @@ test('gracefully handle Error instances without a stack', t => {

t.deepEqual([...error.errors], [
new Error('foo'),
new StacklessError('stackless')
new StacklessError('stackless'),
]);
});

Expand All @@ -63,7 +63,7 @@ test('gracefully handle Error instances with empty stack', t => {

const error = new AggregateError([
new Error('foo'),
new EmptyStackError('emptystack')
new EmptyStackError('emptystack'),
]);

console.log(error);
Expand All @@ -73,6 +73,6 @@ test('gracefully handle Error instances with empty stack', t => {

t.deepEqual([...error.errors], [
new Error('foo'),
new EmptyStackError('emptystack')
new EmptyStackError('emptystack'),
]);
});

0 comments on commit 6e107f6

Please sign in to comment.