Skip to content

Commit 4f8546b

Browse files
committed
Require Node.js 12 and move to ESM
1 parent a5da568 commit 4f8546b

File tree

9 files changed

+28
-38
lines changed

9 files changed

+28
-38
lines changed

.github/funding.yml

-3
This file was deleted.

.github/workflows/main.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@ jobs:
1212
node-version:
1313
- 14
1414
- 12
15-
- 10
16-
- 8
1715
steps:
1816
- uses: actions/checkout@v2
19-
- uses: actions/setup-node@v1
17+
- uses: actions/setup-node@v2
2018
with:
2119
node-version: ${{ matrix.node-version }}
2220
- run: npm install

index.d.ts

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
Create an error from multiple errors.
33
*/
4-
declare class AggregateError<T extends Error = Error> extends Error implements Iterable<T> {
4+
export default class AggregateError<T extends Error = Error> extends Error implements Iterable<T> {
55
readonly name: 'AggregateError';
66

77
/**
@@ -10,7 +10,7 @@ declare class AggregateError<T extends Error = Error> extends Error implements I
1010
1111
@example
1212
```
13-
import AggregateError = require('aggregate-error');
13+
import AggregateError from 'aggregate-error';
1414
1515
const error = new AggregateError([new Error('foo'), 'bar', {message: 'baz'}]);
1616
@@ -34,7 +34,6 @@ declare class AggregateError<T extends Error = Error> extends Error implements I
3434
// at run (bootstrap_node.js:394:7)
3535
// at startup (bootstrap_node.js:149:9)
3636
37-
3837
for (const individualError of error) {
3938
console.log(individualError);
4039
}
@@ -43,9 +42,7 @@ declare class AggregateError<T extends Error = Error> extends Error implements I
4342
//=> [Error: baz]
4443
```
4544
*/
46-
constructor(errors: ReadonlyArray<T | {[key: string]: any} | string>);
45+
constructor(errors: ReadonlyArray<T | Record<string, any> | string>);
4746

4847
[Symbol.iterator](): IterableIterator<T>;
4948
}
50-
51-
export = AggregateError;

index.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
'use strict';
2-
const indentString = require('indent-string');
3-
const cleanStack = require('clean-stack');
1+
import indentString from 'indent-string';
2+
import cleanStack from 'clean-stack';
43

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

7-
class AggregateError extends Error {
6+
export default class AggregateError extends Error {
87
constructor(errors) {
98
if (!Array.isArray(errors)) {
109
throw new TypeError(`Expected input to be an Array, got ${typeof errors}`);
@@ -34,6 +33,7 @@ class AggregateError extends Error {
3433

3534
this.name = 'AggregateError';
3635

36+
// TODO: Use private class field for this when ESLint support class fields.
3737
Object.defineProperty(this, '_errors', {value: errors});
3838
}
3939

@@ -43,5 +43,3 @@ class AggregateError extends Error {
4343
}
4444
}
4545
}
46-
47-
module.exports = AggregateError;

index.test-d.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import {expectType} from 'tsd';
2-
import AggregateError = require('.');
1+
import {expectType, expectAssignable} from 'tsd';
2+
import AggregateError from './index.js';
33

44
const aggregateError = new AggregateError([
55
new Error('foo'),
66
{foo: 'bar'},
77
'bar'
88
]);
9-
expectType<Iterable<Error>>(aggregateError);
9+
expectAssignable<Iterable<Error>>(aggregateError);
1010
expectType<IterableIterator<Error>>(aggregateError[Symbol.iterator]());
1111

1212
for (const error of aggregateError) {
@@ -17,7 +17,7 @@ class CustomError extends Error {
1717
public foo: string;
1818

1919
constructor(message: string) {
20-
super(message)
20+
super(message);
2121
this.name = 'CustomError';
2222
this.foo = 'bar';
2323
}

license

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) Sindre Sorhus <[email protected]> (sindresorhus.com)
3+
Copyright (c) Sindre Sorhus <[email protected]> (https://sindresorhus.com)
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
66

package.json

+10-7
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
"description": "Create an error from multiple errors",
55
"license": "MIT",
66
"repository": "sindresorhus/aggregate-error",
7+
"funding": "https://github.com/sponsors/sindresorhus",
78
"author": {
89
"name": "Sindre Sorhus",
910
"email": "[email protected]",
10-
"url": "sindresorhus.com"
11+
"url": "https://sindresorhus.com"
1112
},
13+
"type": "module",
14+
"exports": "./index.js",
1215
"engines": {
13-
"node": ">=8"
16+
"node": ">=12"
1417
},
1518
"scripts": {
1619
"test": "xo && ava && tsd"
@@ -30,12 +33,12 @@
3033
"iterator"
3134
],
3235
"dependencies": {
33-
"clean-stack": "^2.0.0",
34-
"indent-string": "^4.0.0"
36+
"clean-stack": "^4.0.0",
37+
"indent-string": "^5.0.0"
3538
},
3639
"devDependencies": {
37-
"ava": "^2.4.0",
38-
"tsd": "^0.7.1",
39-
"xo": "^0.25.3"
40+
"ava": "^3.15.0",
41+
"tsd": "^0.14.0",
42+
"xo": "^0.38.2"
4043
}
4144
}

readme.md

+3-6
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,16 @@
44
55
*Note: With [Node.js 15](https://medium.com/@nodejs/node-js-v15-0-0-is-here-deb00750f278), there's now a built-in [`AggregateError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AggregateError) type.*
66

7-
87
## Install
98

109
```
1110
$ npm install aggregate-error
1211
```
1312

14-
1513
## Usage
1614

1715
```js
18-
const AggregateError = require('aggregate-error');
16+
import AggregateError from 'aggregate-error';
1917

2018
const error = new AggregateError([new Error('foo'), 'bar', {message: 'baz'}]);
2119

@@ -48,7 +46,6 @@ for (const individualError of error) {
4846
//=> [Error: baz]
4947
```
5048

51-
5249
## API
5350

5451
### AggregateError(errors)
@@ -57,7 +54,7 @@ Returns an `Error` that is also an [`Iterable`](https://developer.mozilla.org/en
5754

5855
#### errors
5956

60-
Type: `Array<Error|Object|string>`
57+
Type: `Array<Error|object|string>`
6158

62-
If a string, a new `Error` is created with the string as the error message.<br>
59+
If a string, a new `Error` is created with the string as the error message.\
6360
If a non-Error object, a new `Error` is created with all properties from the object copied over.

test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import test from 'ava';
2-
import AggregateError from '.';
2+
import AggregateError from './index.js';
33

44
test('main', t => {
55
const error = new AggregateError([
@@ -23,7 +23,7 @@ test('main', t => {
2323
new Error('foo'),
2424
new Error('bar'),
2525
Object.assign(new Error('baz'), {code: 'EBAZ'}),
26-
Object.assign(new Error(), {code: 'EQUX'})
26+
Object.assign(new Error(), {code: 'EQUX'}) // eslint-disable-line unicorn/error-message
2727
]);
2828
});
2929

0 commit comments

Comments
 (0)