-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherr-package-path-not-exported.ts
128 lines (119 loc) · 3.21 KB
/
err-package-path-not-exported.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/**
* @file Errors - ERR_PACKAGE_PATH_NOT_EXPORTED
* @module errnode/errors/ERR_PACKAGE_PATH_NOT_EXPORTED
* @see https://github.com/nodejs/node/blob/v22.7.0/lib/internal/errors.js#L1632-L1638
*/
import E from '#e'
import { codes } from '#src/enums'
import type {
NodeError,
NodeErrorConstructor,
Stringifiable
} from '#src/interfaces'
import { DOT } from '@flex-development/tutils'
import { ok } from 'devlop'
/**
* `ERR_PACKAGE_PATH_NOT_EXPORTED` schema.
*
* @see {@linkcode NodeError}
* @see https://nodejs.org/api/errors.html#err_package_path_not_exported
*
* @extends {NodeError<codes.ERR_PACKAGE_PATH_NOT_EXPORTED>}
*/
interface ErrPackagePathNotExported
extends NodeError<codes.ERR_PACKAGE_PATH_NOT_EXPORTED> {}
/**
* `ERR_PACKAGE_PATH_NOT_EXPORTED` message arguments.
*
* @see {@linkcode Stringifiable}
*/
type Args = [
dir: Stringifiable,
subpath: string,
base?: Stringifiable | null | undefined
]
/**
* `ERR_PACKAGE_PATH_NOT_EXPORTED` constructor.
*
* @see {@linkcode Args}
* @see {@linkcode ErrPackagePathNotExported}
* @see {@linkcode NodeErrorConstructor}
*
* @extends {NodeErrorConstructor<ErrPackagePathNotExported,Args>}
*/
interface ErrPackagePathNotExportedConstructor
extends NodeErrorConstructor<ErrPackagePathNotExported, Args> {
/**
* Create a new `ERR_PACKAGE_PATH_NOT_EXPORTED` error.
*
* @see {@linkcode ErrPackagePathNotExported}
* @see {@linkcode Stringifiable}
*
* @param {Stringifiable} dir
* Package directory id
* @param {string} subpath
* Requested subpath
* @param {Stringifiable | null | undefined} [base]
* Parent module id
* @return {ErrPackagePathNotExported}
*/
new (
dir: Stringifiable,
subpath: string,
base?: Stringifiable | null | undefined
): ErrPackagePathNotExported
}
/**
* `ERR_PACKAGE_PATH_NOT_EXPORTED` model.
*
* Thrown when a `package.json` [`"exports"`][1] field does not export the
* requested subpath.
*
* [1]: https://nodejs.org/api/packages.html#exports
*
* @see {@linkcode ErrPackagePathNotExportedConstructor}
*
* @type {ErrPackagePathNotExportedConstructor}
*
* @class
*/
const ERR_PACKAGE_PATH_NOT_EXPORTED: ErrPackagePathNotExportedConstructor = E(
codes.ERR_PACKAGE_PATH_NOT_EXPORTED,
Error,
/**
* @param {Stringifiable} dir
* Package directory id
* @param {string} subpath
* Requested subpath
* @param {Stringifiable | null | undefined} [base]
* Parent module id
* @return {string} Error message
*/
function message(
dir: Stringifiable,
subpath: string,
base: Stringifiable | null | undefined = null
): string {
ok(
String(dir).endsWith('/'),
'expected `dir` to end with trailing slash ("/")'
)
/**
* Error message.
*
* @var {string} message
*/
let message: string = subpath === DOT
? 'No \'exports\' main defined in'
: `Package subpath '${subpath}' is not defined by 'exports' in`
message += ` ${String(dir)}package.json`
if (base !== null) message += ` imported from ${String(base)}`
return message
}
)
export {
ERR_PACKAGE_PATH_NOT_EXPORTED as default,
type ErrPackagePathNotExported,
type Args as ErrPackagePathNotExportedArgs,
type ErrPackagePathNotExportedConstructor
}