Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit bb8d48a

Browse files
committedJul 27, 2023
build(deps): bump @flex-development/tutils from 6.0.0-alpha.10 to 6.0.0-alpha.12
Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
1 parent 4fd9226 commit bb8d48a

17 files changed

+117
-80
lines changed
 

‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ constructor arguments are passed to [`util.format`][15] instead.
583583

584584
- `{ErrorCode}` **`code`** &mdash; Node.js error code
585585
- `{B extends ErrorConstructor}` **`Base`** &mdash; Error base class
586-
- `{M extends any[] | MessageFn | string}` **`message`** &mdash; Error message or message function
586+
- `{M extends MessageFn | unknown[] | string}` **`message`** &mdash; Error message or message function
587587
- **Returns**: `{NodeErrorConstructor<B, M>}` `NodeError` constructor
588588

589589
> **Source**: [`src/create-node-error.ts`](src/create-node-error.ts)

‎package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"typecheck:watch": "vitest typecheck"
7373
},
7474
"dependencies": {
75-
"@flex-development/tutils": "6.0.0-alpha.10",
75+
"@flex-development/tutils": "6.0.0-alpha.12",
7676
"node-inspect-extracted": "2.0.2"
7777
},
7878
"devDependencies": {
@@ -171,7 +171,7 @@
171171
},
172172
"resolutions": {
173173
"@ardatan/sync-fetch": "larsgw/sync-fetch#head=worker_threads",
174-
"@flex-development/tutils": "6.0.0-alpha.10"
174+
"@flex-development/tutils": "6.0.0-alpha.12"
175175
},
176176
"engines": {
177177
"node": ">=16.20.0",

‎src/internal/format-list.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* @see https://github.com/nodejs/node/blob/0f69ec4dd74d446765639274728466baf5f13cdd/lib/internal/errors.js#L905-L908
55
*/
66

7+
import { join } from '@flex-development/tutils'
8+
79
/**
810
* Creates a list string in the form `'A and B'` or `'A, B, ..., and Z`.
911
*
@@ -23,8 +25,8 @@
2325
*/
2426
function formatList(arr: string[], transition: string = 'and'): string {
2527
return arr.length < 3
26-
? arr.join(` ${transition} `)
27-
: `${arr.slice(0, -1).join(', ')}, ${transition} ${arr[arr.length - 1]}`
28+
? join(arr, ` ${transition} `)
29+
: `${join(arr.slice(0, -1), ', ')}, ${transition} ${arr[arr.length - 1]}`
2830
}
2931

3032
export default formatList

‎src/internal/prepare-stack-trace.ts

+2-13
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
import type { NodeError } from '#src/types'
7+
import { regexp } from '@flex-development/tutils'
78

89
/**
910
* Adds a stack trace to the given `error`.
@@ -23,19 +24,7 @@ function prepareStackTrace<T extends Error = Error>(
2324

2425
// make sure stack trace is formatted properly
2526
error.stack = error.stack!.replace(
26-
new RegExp(
27-
`^${error.name}: ${error.message
28-
/*
29-
* Escape characters with special meaning, either inside or outside
30-
* character sets.
31-
*
32-
* A simple backslash escape is used when it’s always valid; a `\xnn`
33-
* escape is used when the simpler form would be disallowed by stricter
34-
* unicode patterns.
35-
*/
36-
.replace(/[$()*+.?[\\\]^{|}]/g, '\\$&')
37-
.replace(/-/g, '\\x2d')}`
38-
),
27+
new RegExp(`^${error.name}: ${regexp(error.message)}`),
3928
error.toString()
4029
)
4130

‎src/models/err-invalid-arg-type.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ import { ErrorCode } from '#src/enums'
88
import formatList from '#src/internal/format-list'
99
import type { MessageFn, NodeError, NodeErrorConstructor } from '#src/types'
1010
import { createNodeError, determineSpecificType } from '#src/utils'
11-
import type { OneOrMany } from '@flex-development/tutils'
11+
import {
12+
DOT,
13+
includes,
14+
isArray,
15+
lowercase,
16+
type OneOrMany
17+
} from '@flex-development/tutils'
1218

1319
/**
1420
* `ERR_INVALID_ARG_TYPE` model.
@@ -47,7 +53,7 @@ const ERR_INVALID_ARG_TYPE: NodeErrorConstructor<
4753
if (typeof name !== 'string') throw new TypeError("'name' must be a string")
4854

4955
// ensure expected is an array
50-
if (!Array.isArray(expected)) expected = [expected]
56+
if (!isArray(expected)) expected = [expected]
5157

5258
/**
5359
* Primitive value names.
@@ -78,7 +84,7 @@ const ERR_INVALID_ARG_TYPE: NodeErrorConstructor<
7884
// stylize invalid argument name
7985
msg += name.endsWith(' argument')
8086
? name
81-
: `'${name}' ${name.includes('.') ? 'property' : 'argument'}`
87+
: `'${name}' ${includes(name, DOT) ? 'property' : 'argument'}`
8288

8389
// continue building error message
8490
msg += ' must be '
@@ -151,7 +157,7 @@ const ERR_INVALID_ARG_TYPE: NodeErrorConstructor<
151157
msg += `one of ${formatList(other, 'or')}`
152158
} else {
153159
/* c8 ignore next */
154-
if (other[0]!.toLowerCase() !== other[0]) msg += 'an '
160+
if (lowercase(other[0]!) !== other[0]) msg += 'an '
155161
msg += `${other[0]}`
156162
}
157163
}

‎src/models/err-invalid-arg-value.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import { ErrorCode } from '#src/enums'
88
import type { MessageFn, NodeError, NodeErrorConstructor } from '#src/types'
99
import { createNodeError } from '#src/utils'
10+
import { DOT, includes, truncate } from '@flex-development/tutils'
1011
import { inspect } from 'node-inspect-extracted'
1112

1213
/**
@@ -58,16 +59,16 @@ const ERR_INVALID_ARG_VALUE: NodeErrorConstructor<
5859
let ret: string = 'The'
5960

6061
// trim inspected value
61-
if (inspected.length > 128) inspected = inspected.slice(0, 128) + '...'
62+
if (inspected.length > 128) inspected = truncate(inspected, 131)
6263

6364
// add stylized invalid argument or property name
64-
ret += ` ${name.includes('.') ? 'property' : 'argument'} '${name}'`
65+
ret += ` ${includes(name, DOT) ? 'property' : 'argument'} '${name}'`
6566

6667
// add reason for error
6768
if (reason) ret += ` ${reason}`
6869

6970
// add inspected value
70-
ret += `. Received ${inspected}`
71+
ret += `${DOT} Received ${inspected}`
7172

7273
return ret
7374
}

‎src/models/err-invalid-module-specifier.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import { ErrorCode } from '#src/enums'
88
import type { MessageFn, NodeError, NodeErrorConstructor } from '#src/types'
99
import { createNodeError } from '#src/utils'
10+
import { trimEnd } from '@flex-development/tutils'
1011

1112
/**
1213
* `ERR_INVALID_MODULE_SPECIFIER` model.
@@ -45,7 +46,7 @@ const ERR_INVALID_MODULE_SPECIFIER: NodeErrorConstructor<
4546
*
4647
* @var {string} ret
4748
*/
48-
let ret: string = `Invalid module '${request}' ${reason}`.trimEnd()
49+
let ret: string = trimEnd(`Invalid module '${request}' ${reason}`)
4950

5051
// add details regarding where error occurred
5152
if (base) ret += ` imported from ${base}`

‎src/models/err-invalid-package-config.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import { ErrorCode } from '#src/enums'
88
import type { MessageFn, NodeError, NodeErrorConstructor } from '#src/types'
99
import { createNodeError } from '#src/utils'
10+
import { DOT } from '@flex-development/tutils'
1011

1112
/**
1213
* `ERR_INVALID_PACKAGE_CONFIG` model.
@@ -54,7 +55,7 @@ const ERR_INVALID_PACKAGE_CONFIG: NodeErrorConstructor<
5455
if (base) ret += ` while importing ${base}`
5556

5657
// add reason package config is invalid
57-
if (reason) ret += `. ${reason}`
58+
if (reason) ret += `${DOT} ${reason}`
5859

5960
return ret
6061
}

‎src/models/err-invalid-package-target.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import { ErrorCode } from '#src/enums'
88
import type { MessageFn, NodeError, NodeErrorConstructor } from '#src/types'
99
import { createNodeError } from '#src/utils'
10+
import { DOT, ifelse } from '@flex-development/tutils'
1011

1112
/**
1213
* `ERR_INVALID_PACKAGE_TARGET` model.
@@ -63,14 +64,14 @@ const ERR_INVALID_PACKAGE_TARGET: NodeErrorConstructor<
6364
*
6465
* @const {boolean} main
6566
*/
66-
const main: boolean = !internal && key === '.'
67+
const main: boolean = !internal && key === DOT
6768

6869
/**
6970
* Error message.
7071
*
7172
* @var {string} ret
7273
*/
73-
let ret: string = `Invalid "${internal ? 'imports' : 'exports'}"`
74+
let ret: string = `Invalid "${ifelse(internal, 'imports', 'exports')}"`
7475

7576
// include if package target is main entry point
7677
if (main) ret += ' main'
@@ -89,8 +90,8 @@ const ERR_INVALID_PACKAGE_TARGET: NodeErrorConstructor<
8990

9091
// add reason package target is invalid
9192
ret +=
92-
typeof target === 'string' && !internal && !target.startsWith('./')
93-
? '; targets must start with "./"'
93+
typeof target === 'string' && !internal && !target.startsWith(`${DOT}/`)
94+
? `; targets must start with "${DOT}/"`
9495
: ''
9596

9697
return ret

‎src/models/err-package-path-not-exported.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import { ErrorCode } from '#src/enums'
88
import type { NodeError, NodeErrorConstructor } from '#src/types'
99
import { createNodeError } from '#src/utils'
10+
import { DOT } from '@flex-development/tutils'
1011

1112
/**
1213
* `ERR_PACKAGE_PATH_NOT_EXPORTED` model.
@@ -48,7 +49,7 @@ const ERR_PACKAGE_PATH_NOT_EXPORTED: NodeErrorConstructor<
4849
* @var {string} message
4950
*/
5051
let message: string =
51-
subpath === '.'
52+
subpath === DOT
5253
? "No 'exports' main defined in"
5354
: `Package subpath '${subpath}' is not defined by 'exports' in`
5455

‎src/models/err-unknown-file-extension.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import { ErrorCode } from '#src/enums'
88
import type { MessageFn, NodeError, NodeErrorConstructor } from '#src/types'
99
import { createNodeError } from '#src/utils'
10+
import { DOT } from '@flex-development/tutils'
1011

1112
/**
1213
* `ERR_UNKNOWN_FILE_EXTENSION` model.
@@ -48,7 +49,7 @@ const ERR_UNKNOWN_FILE_EXTENSION: NodeErrorConstructor<
4849
let message: string = `Unknown file extension '${ext}' for ${id}`
4950

5051
// add recommended fix
51-
if (suggestion) message += `. ${suggestion}`
52+
if (suggestion) message += `${DOT} ${suggestion}`
5253

5354
return message
5455
}

‎src/models/err-unsupported-esm-url-scheme.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { ErrorCode } from '#src/enums'
88
import formatList from '#src/internal/format-list'
99
import type { NodeError, NodeErrorConstructor } from '#src/types'
1010
import { createNodeError } from '#src/utils'
11+
import { DOT } from '@flex-development/tutils'
1112
import type { URL } from 'node:url'
1213

1314
/**
@@ -58,11 +59,11 @@ const ERR_UNSUPPORTED_ESM_URL_SCHEME: NodeErrorConstructor<
5859

5960
// add additional error details if operating system is windows
6061
if (windows && url.protocol.length === 2) {
61-
message += '. On Windows, absolute paths must be valid file:// URLs'
62+
message += `${DOT} On Windows, absolute paths must be valid file:// URLs`
6263
}
6364

6465
// add url scheme provided by user
65-
message += `. Received protocol '${url.protocol}'`
66+
message += `${DOT} Received protocol '${url.protocol}'`
6667

6768
return message
6869
}

‎src/types/__tests__/node-error-constructor.spec-d.ts

+39-23
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,11 @@
33
* @module errnode/types/tests/unit-d/NodeErrorConstructor
44
*/
55

6+
import type { Times } from '@flex-development/tutils'
67
import type NodeError from '../node-error'
78
import type TestSubject from '../node-error-constructor'
89

910
describe('unit-d:types/NodeErrorConstructor', () => {
10-
it('should extract parameters of type any[] if M extends string', () => {
11-
expectTypeOf<TestSubject>().parameters.toEqualTypeOf<any[]>()
12-
expectTypeOf<TestSubject>().constructorParameters.toEqualTypeOf<any[]>()
13-
})
14-
15-
it('should extract parameters of type M if M extends any[]', () => {
16-
// Arrange
17-
type B = ErrorConstructor
18-
type M = [string, string, string]
19-
20-
expectTypeOf<TestSubject<B, M>>().parameters.toEqualTypeOf<M>()
21-
expectTypeOf<TestSubject<B, M>>().constructorParameters.toEqualTypeOf<M>()
22-
})
23-
24-
it('should extract parameters of type Parameters<M> if M extends MessageFn', () => {
25-
type B = TypeErrorConstructor
26-
type M = (ext: string, path: string) => string
27-
type P = Parameters<M>
28-
29-
expectTypeOf<TestSubject<B, M>>().parameters.toEqualTypeOf<P>()
30-
expectTypeOf<TestSubject<B, M>>().constructorParameters.toEqualTypeOf<P>()
31-
})
32-
3311
it('should match [prototype: NodeError<T>]', () => {
3412
expectTypeOf<TestSubject>()
3513
.toHaveProperty('prototype')
@@ -45,4 +23,42 @@ describe('unit-d:types/NodeErrorConstructor', () => {
4523
NodeError<TypeError>
4624
>()
4725
})
26+
27+
describe('M extends MessageFn', () => {
28+
it('should be callable with Parameters<M>', () => {
29+
// Arrange
30+
type B = TypeErrorConstructor
31+
type M = (ext: string, path: string) => string
32+
type P = Parameters<M>
33+
34+
// Expect
35+
expectTypeOf<TestSubject<B, M>>().parameters.toEqualTypeOf<P>()
36+
expectTypeOf<TestSubject<B, M>>().constructorParameters.toEqualTypeOf<P>()
37+
})
38+
})
39+
40+
describe('M extends string', () => {
41+
it('should be callable with any[]', () => {
42+
// Arrange
43+
type B = ErrorConstructor
44+
type M = string
45+
type P = any[]
46+
47+
// Expect
48+
expectTypeOf<TestSubject<B, M>>().parameters.toEqualTypeOf<P>()
49+
expectTypeOf<TestSubject<B, M>>().constructorParameters.toEqualTypeOf<P>()
50+
})
51+
})
52+
53+
describe('M extends unknown[]', () => {
54+
it('should be callable with M', () => {
55+
// Arrange
56+
type B = ErrorConstructor
57+
type M = Times<3, string>
58+
59+
// Expect
60+
expectTypeOf<TestSubject<B, M>>().parameters.toEqualTypeOf<M>()
61+
expectTypeOf<TestSubject<B, M>>().constructorParameters.toEqualTypeOf<M>()
62+
})
63+
})
4864
})

‎src/types/node-error-constructor.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @module errnode/types/NodeErrorConstructor
44
*/
55

6-
import type { Overwrite } from '@flex-development/tutils'
6+
import type { Omit } from '@flex-development/tutils'
77
import type MessageFn from './fn-message'
88
import type NodeError from './node-error'
99

@@ -15,9 +15,9 @@ import type NodeError from './node-error'
1515
* @template M - Error message type, [`util.format`][1] arguments type, or
1616
* custom message function parameters type
1717
*/
18-
type Args<M extends any[] | MessageFn | string> = M extends MessageFn
18+
type Args<M extends MessageFn | unknown[] | string> = M extends MessageFn
1919
? Parameters<M>
20-
: M extends any[]
20+
: M extends unknown[]
2121
? M
2222
: any[]
2323

@@ -31,13 +31,13 @@ type Args<M extends any[] | MessageFn | string> = M extends MessageFn
3131
* custom message function parameters type
3232
* @template T - Error base type
3333
*
34-
* @extends {Overwrite<B, B>}
34+
* @extends {Omit<B, 'prototype'>}
3535
*/
3636
type NodeErrorConstructor<
3737
B extends ErrorConstructor = ErrorConstructor,
38-
M extends any[] | MessageFn | string = MessageFn,
38+
M extends MessageFn | unknown[] | string = MessageFn,
3939
T extends B['prototype'] = B['prototype']
40-
> = Overwrite<B, B> & {
40+
> = Omit<B, 'prototype'> & {
4141
(...args: Args<M>): NodeError<T>
4242
new (...args: Args<M>): NodeError<T>
4343
readonly prototype: NodeError<T>
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Please sign in to comment.