@visulima/tsconfig 1.1.22 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,12 +1,83 @@
1
1
  import { WriteJsonOptions } from '@visulima/fs';
2
2
 
3
- declare global {
4
- // eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
5
- interface SymbolConstructor {
6
- readonly observable: symbol;
7
- }
3
+ /**
4
+ Returns a boolean for whether the given type is `any`.
5
+
6
+ @link https://stackoverflow.com/a/49928360/1490091
7
+
8
+ Useful in type utilities, such as disallowing `any`s to be passed to a function.
9
+
10
+ @example
11
+ ```
12
+ import type {IsAny} from 'type-fest';
13
+
14
+ const typedObject = {a: 1, b: 2} as const;
15
+ const anyObject: any = {a: 1, b: 2};
16
+
17
+ function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(obj: O, key: K) {
18
+ return obj[key];
19
+ }
20
+
21
+ const typedA = get(typedObject, 'a');
22
+ //=> 1
23
+
24
+ const anyA = get(anyObject, 'a');
25
+ //=> any
26
+ ```
27
+
28
+ @category Type Guard
29
+ @category Utilities
30
+ */
31
+ type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
32
+
33
+ /**
34
+ Returns a boolean for whether the given key is an optional key of type.
35
+
36
+ This is useful when writing utility types or schema validators that need to differentiate `optional` keys.
37
+
38
+ @example
39
+ ```
40
+ import type {IsOptionalKeyOf} from 'type-fest';
41
+
42
+ interface User {
43
+ name: string;
44
+ surname: string;
45
+
46
+ luckyNumber?: number;
47
+ }
48
+
49
+ interface Admin {
50
+ name: string;
51
+ surname?: string;
8
52
  }
9
53
 
54
+ type T1 = IsOptionalKeyOf<User, 'luckyNumber'>;
55
+ //=> true
56
+
57
+ type T2 = IsOptionalKeyOf<User, 'name'>;
58
+ //=> false
59
+
60
+ type T3 = IsOptionalKeyOf<User, 'name' | 'luckyNumber'>;
61
+ //=> boolean
62
+
63
+ type T4 = IsOptionalKeyOf<User | Admin, 'name'>;
64
+ //=> false
65
+
66
+ type T5 = IsOptionalKeyOf<User | Admin, 'surname'>;
67
+ //=> boolean
68
+ ```
69
+
70
+ @category Type Guard
71
+ @category Utilities
72
+ */
73
+ type IsOptionalKeyOf<Type extends object, Key extends keyof Type> =
74
+ IsAny<Type | Key> extends true ? never
75
+ : Key extends keyof Type
76
+ ? Type extends Record<Key, Type[Key]>
77
+ ? false
78
+ : true
79
+ : false;
80
+
10
81
  /**
11
82
  Extract all optional keys from the given type.
12
83
 
@@ -40,11 +111,14 @@ const update2: UpdateOperation<User> = {
40
111
 
41
112
  @category Utilities
42
113
  */
43
- type OptionalKeysOf<BaseType extends object> =
44
- BaseType extends unknown // For distributing `BaseType`
45
- ? (keyof {
46
- [Key in keyof BaseType as BaseType extends Record<Key, BaseType[Key]> ? never : Key]: never
47
- }) & (keyof BaseType) // Intersect with `keyof BaseType` to ensure result of `OptionalKeysOf<BaseType>` is always assignable to `keyof BaseType`
114
+ type OptionalKeysOf<Type extends object> =
115
+ Type extends unknown // For distributing `Type`
116
+ ? (keyof {[Key in keyof Type as
117
+ IsOptionalKeyOf<Type, Key> extends false
118
+ ? never
119
+ : Key
120
+ ]: never
121
+ }) & keyof Type // Intersect with `keyof Type` to ensure result of `OptionalKeysOf<Type>` is always assignable to `keyof Type`
48
122
  : never; // Should never happen
49
123
 
50
124
  /**
@@ -71,9 +145,9 @@ const validator2 = createValidation<User>('surname', value => value.length < 25)
71
145
 
72
146
  @category Utilities
73
147
  */
74
- type RequiredKeysOf<BaseType extends object> =
75
- BaseType extends unknown // For distributing `BaseType`
76
- ? Exclude<keyof BaseType, OptionalKeysOf<BaseType>>
148
+ type RequiredKeysOf<Type extends object> =
149
+ Type extends unknown // For distributing `Type`
150
+ ? Exclude<keyof Type, OptionalKeysOf<Type>>
77
151
  : never; // Should never happen
78
152
 
79
153
  /**
@@ -120,61 +194,68 @@ endIfEqual('abc', '123');
120
194
  type IsNever<T> = [T] extends [never] ? true : false;
121
195
 
122
196
  /**
123
- An if-else-like type that resolves depending on whether the given type is `never`.
197
+ An if-else-like type that resolves depending on whether the given `boolean` type is `true` or `false`.
124
198
 
125
- @see {@link IsNever}
199
+ Use-cases:
200
+ - You can use this in combination with `Is*` types to create an if-else-like experience. For example, `If<IsAny<any>, 'is any', 'not any'>`.
201
+
202
+ Note:
203
+ - Returns a union of if branch and else branch if the given type is `boolean` or `any`. For example, `If<boolean, 'Y', 'N'>` will return `'Y' | 'N'`.
204
+ - Returns the else branch if the given type is `never`. For example, `If<never, 'Y', 'N'>` will return `'N'`.
126
205
 
127
206
  @example
128
207
  ```
129
- import type {IfNever} from 'type-fest';
208
+ import {If} from 'type-fest';
130
209
 
131
- type ShouldBeTrue = IfNever<never>;
132
- //=> true
210
+ type A = If<true, 'yes', 'no'>;
211
+ //=> 'yes'
133
212
 
134
- type ShouldBeBar = IfNever<'not never', 'foo', 'bar'>;
135
- //=> 'bar'
136
- ```
213
+ type B = If<false, 'yes', 'no'>;
214
+ //=> 'no'
137
215
 
138
- @category Type Guard
139
- @category Utilities
140
- */
141
- type IfNever<T, TypeIfNever = true, TypeIfNotNever = false> = (
142
- IsNever<T> extends true ? TypeIfNever : TypeIfNotNever
143
- );
216
+ type C = If<boolean, 'yes', 'no'>;
217
+ //=> 'yes' | 'no'
144
218
 
145
- // Can eventually be replaced with the built-in once this library supports
146
- // TS5.4+ only. Tracked in https://github.com/sindresorhus/type-fest/issues/848
147
- type NoInfer<T> = T extends infer U ? U : never;
219
+ type D = If<any, 'yes', 'no'>;
220
+ //=> 'yes' | 'no'
148
221
 
149
- /**
150
- Returns a boolean for whether the given type is `any`.
222
+ type E = If<never, 'yes', 'no'>;
223
+ //=> 'no'
224
+ ```
151
225
 
152
- @link https://stackoverflow.com/a/49928360/1490091
226
+ @example
227
+ ```
228
+ import {If, IsAny, IsNever} from 'type-fest';
153
229
 
154
- Useful in type utilities, such as disallowing `any`s to be passed to a function.
230
+ type A = If<IsAny<unknown>, 'is any', 'not any'>;
231
+ //=> 'not any'
155
232
 
156
- @example
233
+ type B = If<IsNever<never>, 'is never', 'not never'>;
234
+ //=> 'is never'
157
235
  ```
158
- import type {IsAny} from 'type-fest';
159
236
 
160
- const typedObject = {a: 1, b: 2} as const;
161
- const anyObject: any = {a: 1, b: 2};
237
+ @example
238
+ ```
239
+ import {If, IsEqual} from 'type-fest';
162
240
 
163
- function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(obj: O, key: K) {
164
- return obj[key];
165
- }
241
+ type IfEqual<T, U, IfBranch, ElseBranch> = If<IsEqual<T, U>, IfBranch, ElseBranch>;
166
242
 
167
- const typedA = get(typedObject, 'a');
168
- //=> 1
243
+ type A = IfEqual<string, string, 'equal', 'not equal'>;
244
+ //=> 'equal'
169
245
 
170
- const anyA = get(anyObject, 'a');
171
- //=> any
246
+ type B = IfEqual<string, number, 'equal', 'not equal'>;
247
+ //=> 'not equal'
172
248
  ```
173
249
 
174
250
  @category Type Guard
175
251
  @category Utilities
176
252
  */
177
- type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
253
+ type If<Type extends boolean, IfBranch, ElseBranch> =
254
+ IsNever<Type> extends true
255
+ ? ElseBranch
256
+ : Type extends true
257
+ ? IfBranch
258
+ : ElseBranch;
178
259
 
179
260
  /**
180
261
  Returns a boolean for whether the two given types are equal.
@@ -455,33 +536,10 @@ export type FooBar = Merge<Foo, Bar>;
455
536
  */
456
537
  type Merge<Destination, Source> =
457
538
  Simplify<
458
- SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>>
459
- & SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>
539
+ SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>>
540
+ & SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>
460
541
  >;
461
542
 
462
- /**
463
- An if-else-like type that resolves depending on whether the given type is `any`.
464
-
465
- @see {@link IsAny}
466
-
467
- @example
468
- ```
469
- import type {IfAny} from 'type-fest';
470
-
471
- type ShouldBeTrue = IfAny<any>;
472
- //=> true
473
-
474
- type ShouldBeBar = IfAny<'not any', 'foo', 'bar'>;
475
- //=> 'bar'
476
- ```
477
-
478
- @category Type Guard
479
- @category Utilities
480
- */
481
- type IfAny<T, TypeIfAny = true, TypeIfNotAny = false> = (
482
- IsAny<T> extends true ? TypeIfAny : TypeIfNotAny
483
- );
484
-
485
543
  /**
486
544
  Merges user specified options with default options.
487
545
 
@@ -539,18 +597,13 @@ type ApplyDefaultOptions<
539
597
  Defaults extends Simplify<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>,
540
598
  SpecifiedOptions extends Options,
541
599
  > =
542
- IfAny<SpecifiedOptions, Defaults,
543
- IfNever<SpecifiedOptions, Defaults,
544
- Simplify<Merge<Defaults, {
545
- [Key in keyof SpecifiedOptions
546
- as Key extends OptionalKeysOf<Options>
547
- ? Extract<SpecifiedOptions[Key], undefined> extends never
548
- ? Key
549
- : never
550
- : Key
551
- ]: SpecifiedOptions[Key]
552
- }> & Required<Options>> // `& Required<Options>` ensures that `ApplyDefaultOptions<SomeOption, ...>` is always assignable to `Required<SomeOption>`
553
- >>;
600
+ If<IsAny<SpecifiedOptions>, Defaults,
601
+ If<IsNever<SpecifiedOptions>, Defaults,
602
+ Simplify<Merge<Defaults, {
603
+ [Key in keyof SpecifiedOptions
604
+ as Key extends OptionalKeysOf<Options> ? undefined extends SpecifiedOptions[Key] ? never : Key : Key
605
+ ]: SpecifiedOptions[Key]
606
+ }> & Required<Options>>>>;
554
607
 
555
608
  /**
556
609
  Filter out keys from an object.
@@ -679,6 +732,7 @@ declare namespace TsConfigJson {
679
732
  | 'ESNext'
680
733
  | 'Node16'
681
734
  | 'Node18'
735
+ | 'Node20'
682
736
  | 'NodeNext'
683
737
  | 'Preserve'
684
738
  | 'None'
@@ -694,6 +748,7 @@ declare namespace TsConfigJson {
694
748
  | 'esnext'
695
749
  | 'node16'
696
750
  | 'node18'
751
+ | 'node20'
697
752
  | 'nodenext'
698
753
  | 'preserve'
699
754
  | 'none';
@@ -736,7 +791,6 @@ declare namespace TsConfigJson {
736
791
  | 'es2024'
737
792
  | 'esnext';
738
793
 
739
- // eslint-disable-next-line unicorn/prevent-abbreviations
740
794
  export type Lib =
741
795
  | 'ES5'
742
796
  | 'ES6'
package/dist/index.d.ts CHANGED
@@ -1,12 +1,83 @@
1
1
  import { WriteJsonOptions } from '@visulima/fs';
2
2
 
3
- declare global {
4
- // eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
5
- interface SymbolConstructor {
6
- readonly observable: symbol;
7
- }
3
+ /**
4
+ Returns a boolean for whether the given type is `any`.
5
+
6
+ @link https://stackoverflow.com/a/49928360/1490091
7
+
8
+ Useful in type utilities, such as disallowing `any`s to be passed to a function.
9
+
10
+ @example
11
+ ```
12
+ import type {IsAny} from 'type-fest';
13
+
14
+ const typedObject = {a: 1, b: 2} as const;
15
+ const anyObject: any = {a: 1, b: 2};
16
+
17
+ function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(obj: O, key: K) {
18
+ return obj[key];
19
+ }
20
+
21
+ const typedA = get(typedObject, 'a');
22
+ //=> 1
23
+
24
+ const anyA = get(anyObject, 'a');
25
+ //=> any
26
+ ```
27
+
28
+ @category Type Guard
29
+ @category Utilities
30
+ */
31
+ type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
32
+
33
+ /**
34
+ Returns a boolean for whether the given key is an optional key of type.
35
+
36
+ This is useful when writing utility types or schema validators that need to differentiate `optional` keys.
37
+
38
+ @example
39
+ ```
40
+ import type {IsOptionalKeyOf} from 'type-fest';
41
+
42
+ interface User {
43
+ name: string;
44
+ surname: string;
45
+
46
+ luckyNumber?: number;
47
+ }
48
+
49
+ interface Admin {
50
+ name: string;
51
+ surname?: string;
8
52
  }
9
53
 
54
+ type T1 = IsOptionalKeyOf<User, 'luckyNumber'>;
55
+ //=> true
56
+
57
+ type T2 = IsOptionalKeyOf<User, 'name'>;
58
+ //=> false
59
+
60
+ type T3 = IsOptionalKeyOf<User, 'name' | 'luckyNumber'>;
61
+ //=> boolean
62
+
63
+ type T4 = IsOptionalKeyOf<User | Admin, 'name'>;
64
+ //=> false
65
+
66
+ type T5 = IsOptionalKeyOf<User | Admin, 'surname'>;
67
+ //=> boolean
68
+ ```
69
+
70
+ @category Type Guard
71
+ @category Utilities
72
+ */
73
+ type IsOptionalKeyOf<Type extends object, Key extends keyof Type> =
74
+ IsAny<Type | Key> extends true ? never
75
+ : Key extends keyof Type
76
+ ? Type extends Record<Key, Type[Key]>
77
+ ? false
78
+ : true
79
+ : false;
80
+
10
81
  /**
11
82
  Extract all optional keys from the given type.
12
83
 
@@ -40,11 +111,14 @@ const update2: UpdateOperation<User> = {
40
111
 
41
112
  @category Utilities
42
113
  */
43
- type OptionalKeysOf<BaseType extends object> =
44
- BaseType extends unknown // For distributing `BaseType`
45
- ? (keyof {
46
- [Key in keyof BaseType as BaseType extends Record<Key, BaseType[Key]> ? never : Key]: never
47
- }) & (keyof BaseType) // Intersect with `keyof BaseType` to ensure result of `OptionalKeysOf<BaseType>` is always assignable to `keyof BaseType`
114
+ type OptionalKeysOf<Type extends object> =
115
+ Type extends unknown // For distributing `Type`
116
+ ? (keyof {[Key in keyof Type as
117
+ IsOptionalKeyOf<Type, Key> extends false
118
+ ? never
119
+ : Key
120
+ ]: never
121
+ }) & keyof Type // Intersect with `keyof Type` to ensure result of `OptionalKeysOf<Type>` is always assignable to `keyof Type`
48
122
  : never; // Should never happen
49
123
 
50
124
  /**
@@ -71,9 +145,9 @@ const validator2 = createValidation<User>('surname', value => value.length < 25)
71
145
 
72
146
  @category Utilities
73
147
  */
74
- type RequiredKeysOf<BaseType extends object> =
75
- BaseType extends unknown // For distributing `BaseType`
76
- ? Exclude<keyof BaseType, OptionalKeysOf<BaseType>>
148
+ type RequiredKeysOf<Type extends object> =
149
+ Type extends unknown // For distributing `Type`
150
+ ? Exclude<keyof Type, OptionalKeysOf<Type>>
77
151
  : never; // Should never happen
78
152
 
79
153
  /**
@@ -120,61 +194,68 @@ endIfEqual('abc', '123');
120
194
  type IsNever<T> = [T] extends [never] ? true : false;
121
195
 
122
196
  /**
123
- An if-else-like type that resolves depending on whether the given type is `never`.
197
+ An if-else-like type that resolves depending on whether the given `boolean` type is `true` or `false`.
124
198
 
125
- @see {@link IsNever}
199
+ Use-cases:
200
+ - You can use this in combination with `Is*` types to create an if-else-like experience. For example, `If<IsAny<any>, 'is any', 'not any'>`.
201
+
202
+ Note:
203
+ - Returns a union of if branch and else branch if the given type is `boolean` or `any`. For example, `If<boolean, 'Y', 'N'>` will return `'Y' | 'N'`.
204
+ - Returns the else branch if the given type is `never`. For example, `If<never, 'Y', 'N'>` will return `'N'`.
126
205
 
127
206
  @example
128
207
  ```
129
- import type {IfNever} from 'type-fest';
208
+ import {If} from 'type-fest';
130
209
 
131
- type ShouldBeTrue = IfNever<never>;
132
- //=> true
210
+ type A = If<true, 'yes', 'no'>;
211
+ //=> 'yes'
133
212
 
134
- type ShouldBeBar = IfNever<'not never', 'foo', 'bar'>;
135
- //=> 'bar'
136
- ```
213
+ type B = If<false, 'yes', 'no'>;
214
+ //=> 'no'
137
215
 
138
- @category Type Guard
139
- @category Utilities
140
- */
141
- type IfNever<T, TypeIfNever = true, TypeIfNotNever = false> = (
142
- IsNever<T> extends true ? TypeIfNever : TypeIfNotNever
143
- );
216
+ type C = If<boolean, 'yes', 'no'>;
217
+ //=> 'yes' | 'no'
144
218
 
145
- // Can eventually be replaced with the built-in once this library supports
146
- // TS5.4+ only. Tracked in https://github.com/sindresorhus/type-fest/issues/848
147
- type NoInfer<T> = T extends infer U ? U : never;
219
+ type D = If<any, 'yes', 'no'>;
220
+ //=> 'yes' | 'no'
148
221
 
149
- /**
150
- Returns a boolean for whether the given type is `any`.
222
+ type E = If<never, 'yes', 'no'>;
223
+ //=> 'no'
224
+ ```
151
225
 
152
- @link https://stackoverflow.com/a/49928360/1490091
226
+ @example
227
+ ```
228
+ import {If, IsAny, IsNever} from 'type-fest';
153
229
 
154
- Useful in type utilities, such as disallowing `any`s to be passed to a function.
230
+ type A = If<IsAny<unknown>, 'is any', 'not any'>;
231
+ //=> 'not any'
155
232
 
156
- @example
233
+ type B = If<IsNever<never>, 'is never', 'not never'>;
234
+ //=> 'is never'
157
235
  ```
158
- import type {IsAny} from 'type-fest';
159
236
 
160
- const typedObject = {a: 1, b: 2} as const;
161
- const anyObject: any = {a: 1, b: 2};
237
+ @example
238
+ ```
239
+ import {If, IsEqual} from 'type-fest';
162
240
 
163
- function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(obj: O, key: K) {
164
- return obj[key];
165
- }
241
+ type IfEqual<T, U, IfBranch, ElseBranch> = If<IsEqual<T, U>, IfBranch, ElseBranch>;
166
242
 
167
- const typedA = get(typedObject, 'a');
168
- //=> 1
243
+ type A = IfEqual<string, string, 'equal', 'not equal'>;
244
+ //=> 'equal'
169
245
 
170
- const anyA = get(anyObject, 'a');
171
- //=> any
246
+ type B = IfEqual<string, number, 'equal', 'not equal'>;
247
+ //=> 'not equal'
172
248
  ```
173
249
 
174
250
  @category Type Guard
175
251
  @category Utilities
176
252
  */
177
- type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
253
+ type If<Type extends boolean, IfBranch, ElseBranch> =
254
+ IsNever<Type> extends true
255
+ ? ElseBranch
256
+ : Type extends true
257
+ ? IfBranch
258
+ : ElseBranch;
178
259
 
179
260
  /**
180
261
  Returns a boolean for whether the two given types are equal.
@@ -455,33 +536,10 @@ export type FooBar = Merge<Foo, Bar>;
455
536
  */
456
537
  type Merge<Destination, Source> =
457
538
  Simplify<
458
- SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>>
459
- & SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>
539
+ SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>>
540
+ & SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>
460
541
  >;
461
542
 
462
- /**
463
- An if-else-like type that resolves depending on whether the given type is `any`.
464
-
465
- @see {@link IsAny}
466
-
467
- @example
468
- ```
469
- import type {IfAny} from 'type-fest';
470
-
471
- type ShouldBeTrue = IfAny<any>;
472
- //=> true
473
-
474
- type ShouldBeBar = IfAny<'not any', 'foo', 'bar'>;
475
- //=> 'bar'
476
- ```
477
-
478
- @category Type Guard
479
- @category Utilities
480
- */
481
- type IfAny<T, TypeIfAny = true, TypeIfNotAny = false> = (
482
- IsAny<T> extends true ? TypeIfAny : TypeIfNotAny
483
- );
484
-
485
543
  /**
486
544
  Merges user specified options with default options.
487
545
 
@@ -539,18 +597,13 @@ type ApplyDefaultOptions<
539
597
  Defaults extends Simplify<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>,
540
598
  SpecifiedOptions extends Options,
541
599
  > =
542
- IfAny<SpecifiedOptions, Defaults,
543
- IfNever<SpecifiedOptions, Defaults,
544
- Simplify<Merge<Defaults, {
545
- [Key in keyof SpecifiedOptions
546
- as Key extends OptionalKeysOf<Options>
547
- ? Extract<SpecifiedOptions[Key], undefined> extends never
548
- ? Key
549
- : never
550
- : Key
551
- ]: SpecifiedOptions[Key]
552
- }> & Required<Options>> // `& Required<Options>` ensures that `ApplyDefaultOptions<SomeOption, ...>` is always assignable to `Required<SomeOption>`
553
- >>;
600
+ If<IsAny<SpecifiedOptions>, Defaults,
601
+ If<IsNever<SpecifiedOptions>, Defaults,
602
+ Simplify<Merge<Defaults, {
603
+ [Key in keyof SpecifiedOptions
604
+ as Key extends OptionalKeysOf<Options> ? undefined extends SpecifiedOptions[Key] ? never : Key : Key
605
+ ]: SpecifiedOptions[Key]
606
+ }> & Required<Options>>>>;
554
607
 
555
608
  /**
556
609
  Filter out keys from an object.
@@ -679,6 +732,7 @@ declare namespace TsConfigJson {
679
732
  | 'ESNext'
680
733
  | 'Node16'
681
734
  | 'Node18'
735
+ | 'Node20'
682
736
  | 'NodeNext'
683
737
  | 'Preserve'
684
738
  | 'None'
@@ -694,6 +748,7 @@ declare namespace TsConfigJson {
694
748
  | 'esnext'
695
749
  | 'node16'
696
750
  | 'node18'
751
+ | 'node20'
697
752
  | 'nodenext'
698
753
  | 'preserve'
699
754
  | 'none';
@@ -736,7 +791,6 @@ declare namespace TsConfigJson {
736
791
  | 'es2024'
737
792
  | 'esnext';
738
793
 
739
- // eslint-disable-next-line unicorn/prevent-abbreviations
740
794
  export type Lib =
741
795
  | 'ES5'
742
796
  | 'ES6'
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{findTsConfig as f,findTsConfigSync as r}from"./packem_shared/findTsConfig-BxbLTzwF.mjs";import{implicitBaseUrlSymbol as e,readTsConfig as s}from"./packem_shared/implicitBaseUrlSymbol-CP1i_A8H.mjs";import{writeTsConfig as g,writeTsConfigSync as m}from"./packem_shared/writeTsConfig-0IO4xPZJ.mjs";export{f as findTsConfig,r as findTsConfigSync,e as implicitBaseUrlSymbol,s as readTsConfig,g as writeTsConfig,m as writeTsConfigSync};
1
+ import{findTsConfig as f,findTsConfigSync as r}from"./packem_shared/findTsConfig-K7SdbxiK.mjs";import{implicitBaseUrlSymbol as e,readTsConfig as s}from"./packem_shared/implicitBaseUrlSymbol-CPtIty7J.mjs";import{writeTsConfig as g,writeTsConfigSync as m}from"./packem_shared/writeTsConfig-0IO4xPZJ.mjs";export{f as findTsConfig,r as findTsConfigSync,e as implicitBaseUrlSymbol,s as readTsConfig,g as writeTsConfig,m as writeTsConfigSync};
@@ -0,0 +1 @@
1
+ "use strict";var g=Object.defineProperty;var r=(e,o)=>g(e,"name",{value:o,configurable:!0});Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const f=require("@visulima/fs"),s=require("@visulima/fs/error"),a=require("./implicitBaseUrlSymbol-B_X9pk9Z.cjs");var u=Object.defineProperty,l=r((e,o)=>u(e,"name",{value:o,configurable:!0}),"f");const d=new Map,p=l(async(e,o={})=>{const i=o.configFileName??"tsconfig.json";let n=await f.findUp(i,{...e&&{cwd:e},type:"file"});if(n||(n=await f.findUp("jsconfig.json",{...e&&{cwd:e},type:"file"})),!n)throw new s.NotFoundError(`No such file or directory, for '${i}' or 'jsconfig.json' found.`);const c=o.cache&&typeof o.cache!="boolean"?o.cache:d;if(o.cache&&c.has(n))return c.get(n);const t={config:a.readTsConfig(n,{tscCompatible:o.tscCompatible}),path:n};return o.cache&&c.set(n,t),t},"findTsConfig"),h=l((e,o={})=>{const i=o.configFileName??"tsconfig.json";let n=f.findUpSync(i,{...e&&{cwd:e},type:"file"});if(n||(n=f.findUpSync("jsconfig.json",{...e&&{cwd:e},type:"file"})),!n)throw new s.NotFoundError(`No such file or directory, for '${i}' or 'jsconfig.json' found.`);const c=o.cache&&typeof o.cache!="boolean"?o.cache:d;if(o.cache&&c.has(n))return c.get(n);const t={config:a.readTsConfig(n,{tscCompatible:o.tscCompatible}),path:n};return o.cache&&c.set(n,t),t},"findTsConfigSync");exports.findTsConfig=p;exports.findTsConfigSync=h;
@@ -0,0 +1 @@
1
+ var h=Object.defineProperty;var f=(n,o)=>h(n,"name",{value:o,configurable:!0});import{findUp as s,findUpSync as r}from"@visulima/fs";import{NotFoundError as a}from"@visulima/fs/error";import{readTsConfig as p}from"./implicitBaseUrlSymbol-CPtIty7J.mjs";var d=Object.defineProperty,l=f((n,o)=>d(n,"name",{value:o,configurable:!0}),"f");const g=new Map,w=l(async(n,o={})=>{const e=o.configFileName??"tsconfig.json";let c=await s(e,{...n&&{cwd:n},type:"file"});if(c||(c=await s("jsconfig.json",{...n&&{cwd:n},type:"file"})),!c)throw new a(`No such file or directory, for '${e}' or 'jsconfig.json' found.`);const i=o.cache&&typeof o.cache!="boolean"?o.cache:g;if(o.cache&&i.has(c))return i.get(c);const t={config:p(c,{tscCompatible:o.tscCompatible}),path:c};return o.cache&&i.set(c,t),t},"findTsConfig"),C=l((n,o={})=>{const e=o.configFileName??"tsconfig.json";let c=r(e,{...n&&{cwd:n},type:"file"});if(c||(c=r("jsconfig.json",{...n&&{cwd:n},type:"file"})),!c)throw new a(`No such file or directory, for '${e}' or 'jsconfig.json' found.`);const i=o.cache&&typeof o.cache!="boolean"?o.cache:g;if(o.cache&&i.has(c))return i.get(c);const t={config:p(c,{tscCompatible:o.tscCompatible}),path:c};return o.cache&&i.set(c,t),t},"findTsConfigSync");export{w as findTsConfig,C as findTsConfigSync};
@@ -0,0 +1 @@
1
+ "use strict";var R=Object.defineProperty;var g=(e,l)=>R(e,"name",{value:l,configurable:!0});Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const m=require("@visulima/fs"),W=require("@visulima/fs/error"),r=require("@visulima/path"),A=require("@visulima/path/utils"),F=require("jsonc-parser"),S=require("node:fs"),E=require("node:module"),U=require("resolve-pkg-maps"),q=g(e=>e&&typeof e=="object"&&"default"in e?e.default:e,"_interopDefaultCompat"),J=q(E);var T=Object.defineProperty,D=g((e,l)=>T(e,"name",{value:l,configurable:!0}),"d$1");const _=D(e=>F.parse(m.readFileSync(e,{buffer:!1})),"readJsonc"),B=D(()=>{const{findPnpApi:e}=J;return e?.(process.cwd())},"getPnpApi"),w=D((e,l,c,o)=>{const p=`resolveFromPackageJsonPath:${e}:${l}:${c?"yes":"no"}`;if(o?.has(p))return o.get(p);const i=_(e);if(!i)return;let n=l||"tsconfig.json";if(!c&&i.exports)try{const[s]=U.resolveExports(i.exports,l,["require","types"]);n=s}catch{return!1}else!l&&i.tsconfig&&(n=i.tsconfig);return n=r.join(e,"..",n),o?.set(p,n),n},"resolveFromPackageJsonPath"),C="package.json",x="tsconfig.json",M=D((e,l,c)=>{let o=e;if(e===".."&&(o=r.join(o,x)),e.startsWith(".")&&(o=r.resolve(l,o)),r.isAbsolute(o)){if(m.isAccessibleSync(o)){if(S.statSync(o).isFile())return o}else if(!o.endsWith(".json")){const a=`${o}.json`;if(m.isAccessibleSync(a))return a}return}const[p,...i]=e.split("/"),n=p.startsWith("@")?`${p}/${i.shift()}`:p,s=i.join("/"),t=B();if(t){const{resolveRequest:a}=t;try{if(n===e){const f=a(r.join(n,C),l);if(f){const y=w(f,s,!1,c);if(y&&m.isAccessibleSync(y))return y}}else{let f;try{f=a(e,l,{extensions:[".json"]})}catch{f=a(r.join(e,x),l)}if(f)return f}}catch{}}const u=m.findUpSync(a=>{const f=r.join(r.resolve(a),"node_modules",n);if(m.isAccessibleSync(f))return r.join("node_modules",n)},{cwd:l,type:"directory"});if(!u||!S.statSync(u).isDirectory())return;const b=r.join(u,C);if(m.isAccessibleSync(b)){const a=w(b,s,!1,c);if(a===!1)return;if(a&&m.isAccessibleSync(a)&&S.statSync(a).isFile())return a}const O=r.join(u,s),P=O.endsWith(".json");if(!P){const a=`${O}.json`;if(m.isAccessibleSync(a))return a}if(m.isAccessibleSync(O)){if(S.statSync(O).isDirectory()){const a=r.join(O,C);if(m.isAccessibleSync(a)){const y=w(a,"",!0,c);if(y&&m.isAccessibleSync(y))return y}const f=r.join(O,x);if(m.isAccessibleSync(f))return f}else if(P)return O}},"resolveExtendsPath");var z=Object.defineProperty,v=g((e,l)=>z(e,"name",{value:l,configurable:!0}),"m");const L=v(e=>F.parse(m.readFileSync(e,{buffer:!1})),"readJsonc"),h=v(e=>{const l=r.toNamespacedPath(e);return A.isRelative(l)?l:`./${l}`},"normalizePath"),k=["files","include","exclude"],N=v((e,l,c,o)=>{if(c.has(e))throw new Error(`Circularity detected while resolving configuration: ${e}`);c.add(e);const p=r.dirname(e),i=I(e,o,c);delete i.references;const{compilerOptions:n}=i;if(n){const{baseUrl:s}=n;s&&!s.startsWith(d)&&(n.baseUrl=r.normalize(r.relative(l,r.join(p,s)))||"./");let{outDir:t}=n;t&&(t.startsWith(d)||(t=r.relative(l,r.join(p,t))),n.outDir=h(t.replace(`${d}/`,""))||"./")}for(const s of k){const t=i[s];t&&(i[s]=t.map(u=>u.startsWith(d)||r.isAbsolute(u)?u:r.relative(l,r.join(p,u))))}return i},"resolveExtends"),I=v((e,l,c=new Set)=>{let o;try{o=L(e)||{}}catch{throw new Error(`Cannot resolve tsconfig at path: ${e}`)}if(typeof o!="object")throw new SyntaxError(`Failed to parse tsconfig at: ${e}`);const p=r.dirname(e);if(o.compilerOptions){const{compilerOptions:i}=o;i.paths&&!i.baseUrl&&(i[$]=p)}if(o.extends){const i=Array.isArray(o.extends)?o.extends:[o.extends];delete o.extends;for(const n of i.toReversed()){const s=M(n,p);if(!s)throw new W.NotFoundError(`No such file or directory, for '${n}' found.`);const t=N(s,p,new Set(c),l);t.compilerOptions?.rootDir!==void 0&&!t.compilerOptions.rootDir.startsWith(d)&&(t.compilerOptions.rootDir=r.join(r.dirname(s),t.compilerOptions.rootDir));const u={...t,...o,compilerOptions:{...t.compilerOptions,...o.compilerOptions}};t.watchOptions&&(u.watchOptions={...t.watchOptions,...o.watchOptions}),o=u}}if(o.compilerOptions){const{compilerOptions:i}=o;for(const n of["baseUrl","rootDir"]){const s=i[n];if(s&&!s.startsWith(d)){const t=r.resolve(p,s);i[n]=h(r.relative(p,t))}}for(const n of["outDir","declarationDir"]){let s=i[n];if(s){Array.isArray(o.exclude)||(o.exclude=[]);let t=s;r.isAbsolute(t)||(t=r.join(p,t)),t=t.replace(d,""),o.exclude.includes(t)||o.exclude.push(t),s.startsWith(d)||(s=h(s)),i[n]=s}}}else o.compilerOptions={};if(o.include?(o.include=o.include.map(i=>r.normalize(i)),o.files&&delete o.files):o.files&&(o.files=o.files.map(i=>i.startsWith(d)?i:h(i))),o.watchOptions){const{watchOptions:i}=o;i.excludeDirectories&&(i.excludeDirectories=i.excludeDirectories.map(n=>r.resolve(p,n)))}return o.compilerOptions?.lib&&(o.compilerOptions.lib=o.compilerOptions.lib.map(i=>i.toLowerCase())),o.compilerOptions.module&&(o.compilerOptions.module=o.compilerOptions.module.toLowerCase()),o.compilerOptions.target&&(o.compilerOptions.target=o.compilerOptions.target.toLowerCase()),o},"internalParseTsConfig"),j=v((e,l)=>{if(e.startsWith(d))return r.normalize(r.join(l,e.slice(d.length)))},"interpolateConfigDirectory"),V=["outDir","declarationDir","outFile","rootDir","baseUrl","tsBuildInfoFile"],G=v((e,l)=>{if(e.compilerOptions===void 0)return e;if(["5.4","5.5","5.6","5.7","5.8","5.9","true"].includes(String(l?.tscCompatible))){if(e.compilerOptions.esModuleInterop===void 0&&(e.compilerOptions.module==="node16"||e.compilerOptions.module==="nodenext"||e.compilerOptions.module==="preserve")&&(e.compilerOptions.esModuleInterop=!0),e?.compilerOptions.moduleDetection===void 0&&e.compilerOptions.module&&["node16","nodenext"].includes(e.compilerOptions.module)&&(e.compilerOptions.moduleDetection="force"),e.compilerOptions.moduleResolution===void 0){let c="classic";if(e.compilerOptions.module!==void 0)switch((e.compilerOptions?.module).toLocaleLowerCase()){case"commonjs":{c="node10";break}case"node16":{c="node16";break}case"nodenext":{c="nodenext";break}case"preserve":{c="bundler";break}}c!=="classic"&&(e.compilerOptions.moduleResolution=c)}if(e.compilerOptions.moduleResolution==="bundler"&&(e.compilerOptions.resolveJsonModule=!0),(e.compilerOptions.esModuleInterop||e.compilerOptions.module==="system"||e.compilerOptions.moduleResolution==="bundler")&&e.compilerOptions.allowSyntheticDefaultImports===void 0&&(e.compilerOptions.allowSyntheticDefaultImports=!0),["5.7","5.8","5.9","true"].includes(String(l?.tscCompatible))&&e.compilerOptions.moduleResolution){let c=!1;["bundler","node16","nodenext"].includes(e.compilerOptions.moduleResolution.toLocaleLowerCase())&&(c=!0),e.compilerOptions.resolvePackageJsonExports===void 0&&c&&(e.compilerOptions.resolvePackageJsonExports=!0),e.compilerOptions.resolvePackageJsonImports===void 0&&c&&(e.compilerOptions.resolvePackageJsonImports=!0)}if(e.compilerOptions.target===void 0){let c="es5";e.compilerOptions.module==="node16"?c="es2022":e.compilerOptions.module==="nodenext"&&(c="esnext"),c!=="es5"&&(e.compilerOptions.target=c)}e.compilerOptions.useDefineForClassFields===void 0&&e.compilerOptions.target&&(e.compilerOptions.target.includes("es202")||e.compilerOptions.target==="esnext")&&(e.compilerOptions.useDefineForClassFields=!0)}if(["5.6","5.7","5.8","5.9","true"].includes(String(l?.tscCompatible))&&e.compilerOptions.strict&&e.compilerOptions.strictBuiltinIteratorReturn===void 0&&(e.compilerOptions.strictBuiltinIteratorReturn=!0),["5.4","5.5","5.6","5.7","5.8","5.9","true"].includes(String(l?.tscCompatible))){if(e.compilerOptions.strict&&(e.compilerOptions.noImplicitAny=e.compilerOptions.noImplicitAny??!0,e.compilerOptions.noImplicitThis=e.compilerOptions.noImplicitThis??!0,e.compilerOptions.strictNullChecks=e.compilerOptions.strictNullChecks??!0,e.compilerOptions.strictFunctionTypes=e.compilerOptions.strictFunctionTypes??!0,e.compilerOptions.strictBindCallApply=e.compilerOptions.strictBindCallApply??!0,e.compilerOptions.strictPropertyInitialization=e.compilerOptions.strictPropertyInitialization??!0,e.compilerOptions.alwaysStrict=e.compilerOptions.alwaysStrict??!0),e.compilerOptions.useDefineForClassFields===void 0&&e.compilerOptions.target){let c=!1;(e.compilerOptions.target.includes("es202")||e.compilerOptions.target==="esnext")&&(c=!0),c&&(e.compilerOptions.useDefineForClassFields=!0)}e.compilerOptions.strict&&e.compilerOptions.useUnknownInCatchVariables===void 0&&(e.compilerOptions.useUnknownInCatchVariables=!0),e.compilerOptions.isolatedModules&&(e.compilerOptions.preserveConstEnums=e.compilerOptions.preserveConstEnums??!0)}return e.compileOnSave===!1&&delete e.compileOnSave,e},"tsCompatibleWrapper"),d="${configDir}",$=Symbol("implicitBaseUrl"),H=v((e,l)=>{const c=r.resolve(e),o=I(c,l),p=r.dirname(c),{compilerOptions:i}=o;if(i){for(const s of V){const t=i[s];if(t){const u=j(t,p);i[s]=u?h(r.relative(p,u)):t}}for(const s of["rootDirs","typeRoots"]){const t=i[s];t&&(i[s]=t.map(u=>{const b=j(u,p);return b?h(r.relative(p,b)):u}))}const{paths:n}=i;if(n)for(const s of Object.keys(n))n[s]=n[s].map(t=>j(t,p)??t);i.outDir&&(i.outDir=i.outDir.replace(d,""))}for(const n of k){const s=o[n];s&&(o[n]=s.map(t=>j(t,p)||(n==="files"&&A.isRelative(t)?t:n==="include"&&A.isRelative(t)?r.join(p,t):r.normalize(t))))}return G(o,l)},"readTsConfig");exports.configDirectoryPlaceholder=d;exports.implicitBaseUrlSymbol=$;exports.readTsConfig=H;