dtsgenerator 3.17.0 → 3.19.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.
@@ -11,6 +11,7 @@ import {
11
11
  JsonSchema,
12
12
  isJsonSchemaDraft04,
13
13
  } from './type';
14
+ import { checkValidMIMEType } from './utils';
14
15
 
15
16
  type OpenApiSchema = OpenApisV2.SchemaJson | OpenApisV3.SchemaJson;
16
17
  type ParametersList =
@@ -31,11 +32,11 @@ export interface NormalizedSchema extends Schema {
31
32
  export function getSubSchema(
32
33
  rootSchema: Schema,
33
34
  pointer: string,
34
- id?: SchemaId
35
+ id?: SchemaId,
35
36
  ): Schema {
36
37
  const content = JsonPointer.get(
37
38
  rootSchema.content,
38
- JsonPointer.parse(pointer)
39
+ JsonPointer.parse(pointer),
39
40
  ) as JsonSchema;
40
41
  if (id == null) {
41
42
  const subId =
@@ -75,7 +76,7 @@ export function getId(type: SchemaType, content: JsonSchemaObject): string {
75
76
  export function setId(
76
77
  type: SchemaType,
77
78
  content: JsonSchemaObject,
78
- id: string
79
+ id: string,
79
80
  ): void {
80
81
  if (isJsonSchemaDraft04(content, type)) {
81
82
  content[Draft04Id] ??= id;
@@ -87,12 +88,12 @@ export function setId(
87
88
  export function searchAllSubSchema(
88
89
  schema: Schema,
89
90
  onFoundSchema: (subSchema: Schema) => void,
90
- onFoundReference: (refId: SchemaId) => void
91
+ onFoundReference: (refId: SchemaId) => void,
91
92
  ): void {
92
93
  const walkArray = (
93
94
  array: JsonSchema[] | undefined,
94
95
  paths: string[],
95
- parentIds: string[]
96
+ parentIds: string[],
96
97
  ): void => {
97
98
  if (array == null) {
98
99
  return;
@@ -104,7 +105,7 @@ export function searchAllSubSchema(
104
105
  const walkObject = (
105
106
  obj: { [name: string]: JsonSchema } | undefined,
106
107
  paths: string[],
107
- parentIds: string[]
108
+ parentIds: string[],
108
109
  ): void => {
109
110
  if (obj == null) {
110
111
  return;
@@ -119,7 +120,7 @@ export function searchAllSubSchema(
119
120
  const walkMaybeArray = (
120
121
  item: JsonSchema | JsonSchema[] | undefined,
121
122
  paths: string[],
122
- parentIds: string[]
123
+ parentIds: string[],
123
124
  ): void => {
124
125
  if (Array.isArray(item)) {
125
126
  walkArray(item, paths, parentIds);
@@ -130,7 +131,7 @@ export function searchAllSubSchema(
130
131
  const walk = (
131
132
  s: JsonSchema | undefined,
132
133
  paths: string[],
133
- parentIds: string[]
134
+ parentIds: string[],
134
135
  ) => {
135
136
  if (s == null || typeof s !== 'object') {
136
137
  return;
@@ -164,14 +165,14 @@ export function searchAllSubSchema(
164
165
  walk(
165
166
  s.additionalProperties,
166
167
  paths.concat('additionalProperties'),
167
- parentIds
168
+ parentIds,
168
169
  );
169
170
  walkObject(s.definitions, paths.concat('definitions'), parentIds);
170
171
  walkObject(s.properties, paths.concat('properties'), parentIds);
171
172
  walkObject(
172
173
  s.patternProperties,
173
174
  paths.concat('patternProperties'),
174
- parentIds
175
+ parentIds,
175
176
  );
176
177
  walkMaybeArray(s.dependencies, paths.concat('dependencies'), parentIds);
177
178
  if (schema.type === 'Draft07') {
@@ -202,7 +203,7 @@ export function searchAllSubSchema(
202
203
  function setSubIdToAnyObject<T>(
203
204
  f: (t: T, keys: string[]) => void,
204
205
  obj: { [key: string]: T } | undefined,
205
- keys: string[]
206
+ keys: string[],
206
207
  ): void {
207
208
  if (obj == null) {
208
209
  return;
@@ -221,7 +222,7 @@ export function searchAllSubSchema(
221
222
  | OpenApisV2.SchemaJson.Definitions.ParameterDefinitions
222
223
  | OpenApisV3.SchemaJson.Definitions.ParametersOrReferences
223
224
  | undefined,
224
- keys: string[]
225
+ keys: string[],
225
226
  ): void {
226
227
  if (obj == null) {
227
228
  return;
@@ -230,7 +231,7 @@ export function searchAllSubSchema(
230
231
  }
231
232
  function setSubIdToParameters(
232
233
  array: ParametersList | undefined,
233
- keys: string[]
234
+ keys: string[],
234
235
  ): void {
235
236
  if (array == null) {
236
237
  return;
@@ -239,18 +240,18 @@ export function searchAllSubSchema(
239
240
  array.map(
240
241
  (
241
242
  item: ParameterOrReference,
242
- index: number
243
+ index: number,
243
244
  ): [string, ParameterOrReference] => {
244
245
  const key = 'name' in item ? item.name : `${index}`;
245
246
  return [key, item];
246
- }
247
+ },
247
248
  ),
248
- keys
249
+ keys,
249
250
  );
250
251
  }
251
252
  function addParameterSchema(
252
253
  input: readonly [string, ParameterOrReference][],
253
- keys: string[]
254
+ keys: string[],
254
255
  ): void {
255
256
  const map = new Map<string, [string, Parameter][]>();
256
257
  const pushItem = (key: string, po: [string, Parameter]) => {
@@ -278,7 +279,7 @@ export function searchAllSubSchema(
278
279
  if ('type' in item && item.in !== undefined) {
279
280
  setSubId(
280
281
  item as JsonSchemaDraft04.Schema,
281
- keys.concat(key)
282
+ keys.concat(key),
282
283
  );
283
284
  pushItem(item.in, [key, item]);
284
285
  }
@@ -291,7 +292,7 @@ export function searchAllSubSchema(
291
292
  function buildParameterSchema(
292
293
  inType: string,
293
294
  params: [string, Parameter][],
294
- keys: string[]
295
+ keys: string[],
295
296
  ): [string[], JsonSchemaObject] {
296
297
  const paths = keys
297
298
  .slice(0, keys.length - 1)
@@ -318,13 +319,13 @@ export function searchAllSubSchema(
318
319
  /// for OpenAPI V2 only
319
320
  const setSubIdToResponsesV2 = (
320
321
  responses: OpenApisV2.SchemaJson.Definitions.Responses | undefined,
321
- keys: string[]
322
+ keys: string[],
322
323
  ) => setSubIdToAnyObject(setSubIdToResponseV2, responses, keys);
323
324
  function setSubIdToResponseV2(
324
325
  response:
325
326
  | OpenApisV2.SchemaJson.Definitions.ResponseValue
326
327
  | undefined,
327
- keys: string[]
328
+ keys: string[],
328
329
  ): void {
329
330
  if (response == null) {
330
331
  return;
@@ -339,7 +340,7 @@ export function searchAllSubSchema(
339
340
  }
340
341
  function setSubIdToOperationV2(
341
342
  ops: OpenApisV2.SchemaJson.Definitions.Operation | undefined,
342
- keys: string[]
343
+ keys: string[],
343
344
  ): void {
344
345
  if (ops == null) {
345
346
  return;
@@ -354,15 +355,15 @@ export function searchAllSubSchema(
354
355
  }
355
356
  const setSubIdToPathsV2 = (
356
357
  paths: OpenApisV2.SchemaJson.Definitions.Paths,
357
- keys: string[]
358
+ keys: string[],
358
359
  ) => setSubIdToAnyObject(setSubIdToPathItemV2, paths, keys);
359
360
  function setSubIdToPathItemV2(
360
361
  pathItem: OpenApisV2.SchemaJson.Definitions.PathItem,
361
- keys: string[]
362
+ keys: string[],
362
363
  ): void {
363
364
  setSubIdToParameters(
364
365
  pathItem.parameters,
365
- keys.concat('parameters')
366
+ keys.concat('parameters'),
366
367
  );
367
368
  setSubIdToOperationV2(pathItem.get, keys.concat('get'));
368
369
  setSubIdToOperationV2(pathItem.put, keys.concat('put'));
@@ -376,17 +377,13 @@ export function searchAllSubSchema(
376
377
  /// for OpenAPI V3 only
377
378
  function setSubIdToMediaTypes(
378
379
  types: OpenApisV3.SchemaJson.Definitions.MediaTypes | undefined,
379
- keys: string[]
380
+ keys: string[],
380
381
  ): void {
381
382
  if (types == null) {
382
383
  return;
383
384
  }
384
385
  for (const mime of Object.keys(types)) {
385
- if (
386
- /^text\/|^(?:application\/x-www-form-urlencoded$|^application\/([a-z0-9-_.]+\+)?json)$|^application\/octet-stream$|^application\/jwt$|^application\/vnd.apple.pkpass$|^multipart\/form-data$|^image\//.test(
387
- mime
388
- )
389
- ) {
386
+ if (checkValidMIMEType(mime)) {
390
387
  const mt = types[mime];
391
388
  if (mt != null) {
392
389
  setSubId(mt.schema, keys);
@@ -398,13 +395,13 @@ export function searchAllSubSchema(
398
395
  bodies:
399
396
  | OpenApisV3.SchemaJson.Definitions.RequestBodiesOrReferences
400
397
  | undefined,
401
- keys: string[]
398
+ keys: string[],
402
399
  ) => setSubIdToAnyObject(setSubIdToRequestBody, bodies, keys);
403
400
  function setSubIdToRequestBody(
404
401
  body:
405
402
  | OpenApisV3.SchemaJson.Definitions.RequestBodyOrReference
406
403
  | undefined,
407
- keys: string[]
404
+ keys: string[],
408
405
  ): void {
409
406
  if (body == null) {
410
407
  return;
@@ -421,13 +418,13 @@ export function searchAllSubSchema(
421
418
  responses:
422
419
  | OpenApisV3.SchemaJson.Definitions.ResponsesOrReferences
423
420
  | undefined,
424
- keys: string[]
421
+ keys: string[],
425
422
  ) => setSubIdToAnyObject(setSubIdToResponseV3, responses, keys);
426
423
  function setSubIdToResponseV3(
427
424
  response:
428
425
  | OpenApisV3.SchemaJson.Definitions.ResponseOrReference
429
426
  | undefined,
430
- keys: string[]
427
+ keys: string[],
431
428
  ): void {
432
429
  if (response == null) {
433
430
  return;
@@ -442,7 +439,7 @@ export function searchAllSubSchema(
442
439
  }
443
440
  function setSubIdToOperationV3(
444
441
  ops: OpenApisV3.SchemaJson.Definitions.Operation | undefined,
445
- keys: string[]
442
+ keys: string[],
446
443
  ): void {
447
444
  if (ops == null) {
448
445
  return;
@@ -458,15 +455,15 @@ export function searchAllSubSchema(
458
455
  }
459
456
  const setSubIdToPathsV3 = (
460
457
  paths: OpenApisV3.SchemaJson.Definitions.Paths,
461
- keys: string[]
458
+ keys: string[],
462
459
  ) => setSubIdToAnyObject(setSubIdToPathItemV3, paths, keys);
463
460
  function setSubIdToPathItemV3(
464
461
  pathItem: OpenApisV3.SchemaJson.Definitions.PathItem,
465
- keys: string[]
462
+ keys: string[],
466
463
  ): void {
467
464
  setSubIdToParameters(
468
465
  pathItem.parameters,
469
- keys.concat('parameters')
466
+ keys.concat('parameters'),
470
467
  );
471
468
  setSubIdToOperationV3(pathItem.get, keys.concat('get'));
472
469
  setSubIdToOperationV3(pathItem.put, keys.concat('put'));
@@ -480,7 +477,7 @@ export function searchAllSubSchema(
480
477
 
481
478
  function setSubIdToObject(
482
479
  obj: { [name: string]: JsonSchema } | undefined,
483
- paths: string[]
480
+ paths: string[],
484
481
  ): void {
485
482
  if (obj == null) {
486
483
  return;
@@ -557,7 +554,7 @@ export function selectSchemaType(content: JsonSchema | OpenApiSchema): {
557
554
  }
558
555
  if (typeof content !== 'object') {
559
556
  throw new Error(
560
- `expect parameter of type object, received ${typeof content}`
557
+ `expect parameter of type object, received ${typeof content}`,
561
558
  );
562
559
  }
563
560
  if ('$schema' in content) {
@@ -567,7 +564,7 @@ export function selectSchemaType(content: JsonSchema | OpenApiSchema): {
567
564
  }
568
565
  const match =
569
566
  /^https?:\/\/json-schema\.org\/(?:draft\/(\d{4}-\d{2})|draft-(\d+))\/schema#?$/.exec(
570
- schema
567
+ schema,
571
568
  );
572
569
  if (match) {
573
570
  if (match[1] != null) {
@@ -532,11 +532,11 @@ export namespace OpenApisV2 {
532
532
  | Schema
533
533
  | [
534
534
  /* A deterministic version of a JSON Schema object. */ Schema,
535
- .../* A deterministic version of a JSON Schema object. */ Schema[]
535
+ .../* A deterministic version of a JSON Schema object. */ Schema[],
536
536
  ];
537
537
  allOf?: [
538
538
  /* A deterministic version of a JSON Schema object. */ Schema,
539
- .../* A deterministic version of a JSON Schema object. */ Schema[]
539
+ .../* A deterministic version of a JSON Schema object. */ Schema[],
540
540
  ];
541
541
  properties?: {
542
542
  [
@@ -57,13 +57,7 @@ export namespace OpenApisV3 {
57
57
  url?: string; // uri
58
58
  email?: string; // email
59
59
  }
60
- export type DefaultType =
61
- | null
62
- | any[]
63
- | unknown
64
- | number
65
- | boolean
66
- | string;
60
+ export type DefaultType = null | any[] | number | boolean | string;
67
61
  /**
68
62
  * When request bodies or response payloads may be one of a number of different schemas, a `discriminator` object can be used to aid in serialization, deserialization, and validation. The discriminator is a specific object in a schema which is used to inform the consumer of the specification of an alternative schema based on the value associated with it. When using the discriminator, _inline_ schemas will not be considered.
69
63
  */
@@ -342,7 +336,6 @@ export namespace OpenApisV3 {
342
336
  | number
343
337
  | boolean
344
338
  | string
345
- | unknown
346
339
  | any[];
347
340
  export interface Strings {
348
341
  [name: string]: string;
@@ -27,7 +27,7 @@ export default class ReferenceResolver {
27
27
 
28
28
  public async resolve(): Promise<void> {
29
29
  debug(
30
- `resolve reference: reference schema count=${this.referenceCache.size}.`
30
+ `resolve reference: reference schema count=${this.referenceCache.size}.`,
31
31
  );
32
32
  // debug(' schemaCache:');
33
33
  // debug(Array.from(this.schemaCache.keys()).join('\n'));
@@ -45,8 +45,8 @@ export default class ReferenceResolver {
45
45
  const refSchema = this.schemaCache.get(fileId);
46
46
  debug(
47
47
  `get from schema cache, fileId=${fileId}, exists=${String(
48
- !!refSchema
49
- )}, ${id.getAbsoluteId()}`
48
+ !!refSchema,
49
+ )}, ${id.getAbsoluteId()}`,
50
50
  );
51
51
  if (refSchema == null && id.isFetchable()) {
52
52
  try {
@@ -56,8 +56,8 @@ export default class ReferenceResolver {
56
56
  } catch (e) {
57
57
  error.push(
58
58
  `Fail to fetch the $ref target: ${id.getAbsoluteId()}, ${String(
59
- e
60
- )}`
59
+ e,
60
+ )}`,
61
61
  );
62
62
  continue;
63
63
  }
@@ -72,21 +72,21 @@ export default class ReferenceResolver {
72
72
  const rootSchema = this.searchParentSchema(id);
73
73
  if (rootSchema == null) {
74
74
  error.push(
75
- `The $ref targets root is not found: ${id.getAbsoluteId()}`
75
+ `The $ref targets root is not found: ${id.getAbsoluteId()}`,
76
76
  );
77
77
  continue;
78
78
  }
79
79
  const targetSchema = getSubSchema(
80
80
  rootSchema,
81
81
  id.getJsonPointerHash(),
82
- id
82
+ id,
83
83
  );
84
84
  this.addSchema(targetSchema);
85
85
  this.registerSchema(targetSchema);
86
86
  this.referenceCache.set(id.getAbsoluteId(), targetSchema);
87
87
  } else {
88
88
  error.push(
89
- `The $ref target is not found: ${id.getAbsoluteId()}`
89
+ `The $ref target is not found: ${id.getAbsoluteId()}`,
90
90
  );
91
91
  continue;
92
92
  }
@@ -125,7 +125,7 @@ export default class ReferenceResolver {
125
125
  },
126
126
  (refId) => {
127
127
  this.addReference(refId);
128
- }
128
+ },
129
129
  );
130
130
  }
131
131
 
@@ -6,7 +6,10 @@ export default class SchemaId {
6
6
  public readonly id: url.Url;
7
7
  public static readonly empty = new SchemaId('');
8
8
 
9
- constructor(public readonly inputId: string, parentIds?: string[]) {
9
+ constructor(
10
+ public readonly inputId: string,
11
+ parentIds?: string[],
12
+ ) {
10
13
  let absoluteId = url.resolve('', inputId);
11
14
  if (parentIds) {
12
15
  parentIds.forEach((parent: string) => {
package/src/core/type.ts CHANGED
@@ -29,7 +29,7 @@ export type SchemaType =
29
29
  | 'Latest';
30
30
  export function isJsonSchemaDraft04(
31
31
  _content: JsonSchemaObject,
32
- type: SchemaType
32
+ type: SchemaType,
33
33
  ): _content is JsonSchemaDraft04.Schema {
34
34
  return type === 'Draft04';
35
35
  }
@@ -77,7 +77,7 @@ export async function readSchemasFromFile(pattern: string): Promise<Schema[]> {
77
77
  });
78
78
  const content = parseFileContent(data);
79
79
  return parseSchema(content);
80
- })
80
+ }),
81
81
  );
82
82
  }
83
83
  export async function readSchemaFromUrl(url: string): Promise<Schema> {
@@ -88,7 +88,7 @@ export async function readSchemaFromUrl(url: string): Promise<Schema> {
88
88
 
89
89
  export function parseFileContent(
90
90
  content: string,
91
- filename?: string
91
+ filename?: string,
92
92
  ): JsonSchema {
93
93
  const ext = filename ? extname(filename).toLowerCase() : '';
94
94
  const maybeYaml = ext === '.yaml' || ext === '.yml';
@@ -126,16 +126,16 @@ export type Plugin = {
126
126
  description?: string;
127
127
  };
128
128
  preProcess?: (
129
- context: PluginContext
129
+ context: PluginContext,
130
130
  ) => Promise<PreProcessHandler | undefined>;
131
131
  postProcess?: (
132
- context: PluginContext
132
+ context: PluginContext,
133
133
  ) => Promise<TransformerFactory<SourceFile> | undefined>;
134
134
  };
135
135
 
136
136
  export async function loadPlugin(
137
137
  name: string,
138
- option: boolean | Record<string, unknown>
138
+ option: boolean | Record<string, unknown>,
139
139
  ): Promise<Plugin | undefined> {
140
140
  if (!option) {
141
141
  return undefined;
@@ -144,14 +144,14 @@ export async function loadPlugin(
144
144
  const mod = (await import(name)) as { default?: Plugin };
145
145
  if (!mod.default) {
146
146
  console.warn(
147
- `The plugin (${name}) is invalid module. That is not default export format.`
147
+ `The plugin (${name}) is invalid module. That is not default export format.`,
148
148
  );
149
149
  return undefined;
150
150
  }
151
151
  const plugin = mod.default;
152
152
  if (plugin.preProcess != null && typeof plugin.preProcess !== 'function') {
153
153
  console.warn(
154
- `The plugin (${name}) is invalid module. The 'preProcess' is not a function.`
154
+ `The plugin (${name}) is invalid module. The 'preProcess' is not a function.`,
155
155
  );
156
156
  return undefined;
157
157
  }
@@ -160,7 +160,7 @@ export async function loadPlugin(
160
160
  typeof plugin.postProcess !== 'function'
161
161
  ) {
162
162
  console.warn(
163
- `The plugin (${name}) is invalid module. The 'postProcess' is not a function.`
163
+ `The plugin (${name}) is invalid module. The 'postProcess' is not a function.`,
164
164
  );
165
165
  return undefined;
166
166
  }
package/src/core/utils.ts CHANGED
@@ -11,7 +11,7 @@ const debug = Debug('dtsgen');
11
11
 
12
12
  export function toTSType(
13
13
  type: string,
14
- debugSource?: JsonSchemaObject
14
+ debugSource?: JsonSchemaObject,
15
15
  ): ts.KeywordTypeSyntaxKind | ts.SyntaxKind.NullKeyword | undefined {
16
16
  switch (type) {
17
17
  case 'any':
@@ -39,8 +39,8 @@ export function toTSType(
39
39
  `toTSType: unknown type: ${JSON.stringify(
40
40
  debugSource,
41
41
  null,
42
- 2
43
- )}`
42
+ 2,
43
+ )}`,
44
44
  );
45
45
  }
46
46
  throw new Error('unknown type: ' + type);
@@ -55,6 +55,29 @@ export function reduceTypes(types: SimpleTypes[]): SimpleTypes[] {
55
55
  return Array.from(set.values());
56
56
  }
57
57
 
58
+ export function checkValidMIMEType(mime: string): boolean {
59
+ const type = mime.toLowerCase().split(';')[0]?.trim();
60
+ if (type == null) {
61
+ return false;
62
+ }
63
+ if (
64
+ [
65
+ 'application/octet-stream',
66
+ 'application/x-www-form-urlencoded',
67
+ 'multipart/form-data',
68
+
69
+ 'application/jwt',
70
+ 'application/vnd.apple.pkpass',
71
+ ].includes(type)
72
+ ) {
73
+ return true;
74
+ }
75
+ if (type.startsWith('text/') || type.startsWith('image/')) {
76
+ return true;
77
+ }
78
+ return /^application\/(?:[a-z0-9-_.]+\+)?json5?$/.test(type);
79
+ }
80
+
58
81
  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
59
82
  export function mergeSchema(a: any, b: any): boolean {
60
83
  if ('$ref' in a || '$ref' in b) {
@@ -1,10 +1,11 @@
1
1
  /* eslint-disable @typescript-eslint/no-non-null-assertion */
2
+ /* eslint-disable @typescript-eslint/no-unsafe-enum-comparison */
2
3
  import { ScriptTarget } from 'typescript';
3
4
 
4
5
  // via. https://github.com/microsoft/TypeScript/blob/v3.7.5/src/services/codefixes/importFixes.ts#L689
5
6
  export function checkInvalidCharacter(
6
7
  text: string,
7
- target: ScriptTarget
8
+ target: ScriptTarget,
8
9
  ): boolean {
9
10
  const firstCharCode = text.charCodeAt(0);
10
11
  if (!isIdentifierStart(firstCharCode, target)) {
@@ -6,7 +6,7 @@
6
6
  export function get(
7
7
  obj: any,
8
8
  path: string[],
9
- isCreateOnNotExists = false
9
+ isCreateOnNotExists = false,
10
10
  ): any {
11
11
  if (path.length === 0) {
12
12
  return obj;
package/src/utils.ts CHANGED
@@ -1,14 +1,15 @@
1
1
  import * as fs from 'fs';
2
2
  import { URL } from 'url';
3
- import glob from 'glob';
4
- import proxy from 'https-proxy-agent';
3
+ import { GlobOptions, globIterate } from 'glob';
4
+ import { HttpProxyAgent } from 'http-proxy-agent';
5
+ import { HttpsProxyAgent } from 'https-proxy-agent';
5
6
  import { ScriptTarget } from 'typescript';
6
7
  import { CommandOptions, defaultConfigFile } from './commandOptions';
7
8
  import { PartialConfig } from './core/config';
8
9
 
9
10
  export function readStream(
10
11
  stream: NodeJS.ReadableStream,
11
- encoding: BufferEncoding = 'utf8'
12
+ encoding: BufferEncoding = 'utf8',
12
13
  ): Promise<string> {
13
14
  stream.setEncoding(encoding);
14
15
  return new Promise((resolve, reject) => {
@@ -25,7 +26,7 @@ export async function readUrl(url: string): Promise<string> {
25
26
  const data = await res.text();
26
27
  if (!res.ok) {
27
28
  throw new Error(
28
- `Error on fetch from url(${url}): ${res.status}, ${data}`
29
+ `Error on fetch from url(${url}): ${res.status}, ${data}`,
29
30
  );
30
31
  }
31
32
  return data;
@@ -40,42 +41,37 @@ function noProxy(url: URL): boolean {
40
41
  }
41
42
  return false;
42
43
  }
43
- export function buildProxyOptions(url: string): RequestInit | undefined {
44
+ export function buildProxyOptions<Uri extends string>(
45
+ url: Uri,
46
+ ): RequestInit | undefined {
44
47
  const parsedUrl = new URL(url);
45
- let proxyUrl;
46
48
  if (!noProxy(parsedUrl)) {
47
49
  if (parsedUrl.protocol === 'http:' && process.env.HTTP_PROXY) {
48
- proxyUrl = new URL(process.env.HTTP_PROXY);
50
+ return {
51
+ agent: new HttpProxyAgent(process.env.HTTP_PROXY),
52
+ } as RequestInit;
49
53
  } else if (parsedUrl.protocol === 'https:' && process.env.HTTPS_PROXY) {
50
- proxyUrl = new URL(process.env.HTTPS_PROXY);
54
+ return {
55
+ agent: new HttpsProxyAgent(process.env.HTTPS_PROXY),
56
+ } as RequestInit;
51
57
  }
52
58
  }
53
- if (proxyUrl) {
54
- const agentOptions: proxy.HttpsProxyAgentOptions = {};
55
- agentOptions.protocol = proxyUrl.protocol;
56
- agentOptions.host = proxyUrl.hostname;
57
- agentOptions.port = proxyUrl.port;
58
- if (proxyUrl.username) {
59
- agentOptions.auth = proxyUrl.username + ':' + proxyUrl.password;
60
- }
61
- return { agent: proxy(agentOptions) } as RequestInit;
62
- }
63
59
  return undefined;
64
60
  }
65
61
 
66
- export function globFiles(
62
+ export async function globFiles(
67
63
  pattern: string,
68
- options?: glob.IOptions
64
+ options?: GlobOptions,
69
65
  ): Promise<string[]> {
70
- return new Promise((resolve, reject) => {
71
- glob(pattern, options ?? {}, (err, matches) => {
72
- if (err) {
73
- reject(err);
74
- } else {
75
- resolve(matches);
76
- }
77
- });
78
- });
66
+ const result: string[] = [];
67
+ for await (const r of globIterate(pattern, options ?? {})) {
68
+ if (typeof r === 'string') {
69
+ result.push(r);
70
+ } else {
71
+ result.push(r.fullpath());
72
+ }
73
+ }
74
+ return result;
79
75
  }
80
76
 
81
77
  export function readConfig(options: CommandOptions): PartialConfig {
@@ -87,7 +83,7 @@ export function readConfig(options: CommandOptions): PartialConfig {
87
83
  } catch (err) {
88
84
  if (options.configFile != null) {
89
85
  console.error(
90
- 'Error to load config file from ' + options.configFile
86
+ 'Error to load config file from ' + options.configFile,
91
87
  );
92
88
  }
93
89
  }
@@ -113,6 +109,7 @@ export function readConfig(options: CommandOptions): PartialConfig {
113
109
  pc.input.stdin = options.stdin;
114
110
  } else {
115
111
  pc.input.stdin =
112
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
116
113
  pc.input.stdin ||
117
114
  (pc.input.files.length === 0 && pc.input.urls.length === 0);
118
115
  }
@@ -150,6 +147,10 @@ function convertToScriptTarget(target: string): ScriptTarget {
150
147
  return ScriptTarget.ES2019;
151
148
  case 'es2020':
152
149
  return ScriptTarget.ES2020;
150
+ case 'es2021':
151
+ return ScriptTarget.ES2021;
152
+ case 'es2022':
153
+ return ScriptTarget.ES2022;
153
154
  case 'esnext':
154
155
  return ScriptTarget.ESNext;
155
156
  default: