@redocly/cli 1.3.0 → 1.4.1

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.
Files changed (64) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +15 -7
  3. package/lib/__mocks__/@redocly/openapi-core.d.ts +1 -0
  4. package/lib/__mocks__/@redocly/openapi-core.js +4 -3
  5. package/lib/__mocks__/utils.d.ts +2 -0
  6. package/lib/__mocks__/utils.js +3 -1
  7. package/lib/__tests__/commands/build-docs.test.js +2 -2
  8. package/lib/__tests__/commands/bundle.test.js +7 -7
  9. package/lib/__tests__/commands/join.test.js +25 -18
  10. package/lib/__tests__/commands/lint.test.js +15 -15
  11. package/lib/__tests__/commands/push-region.test.js +2 -2
  12. package/lib/__tests__/commands/push.test.js +30 -30
  13. package/lib/__tests__/fetch-with-timeout.test.js +2 -2
  14. package/lib/__tests__/utils.test.js +63 -32
  15. package/lib/__tests__/wrapper.test.js +3 -3
  16. package/lib/assert-node-version.js +1 -1
  17. package/lib/commands/build-docs/index.js +9 -9
  18. package/lib/commands/build-docs/types.d.ts +2 -2
  19. package/lib/commands/build-docs/utils.js +10 -10
  20. package/lib/commands/bundle.d.ts +1 -1
  21. package/lib/commands/bundle.js +25 -25
  22. package/lib/commands/join.d.ts +1 -1
  23. package/lib/commands/join.js +49 -48
  24. package/lib/commands/lint.d.ts +1 -1
  25. package/lib/commands/lint.js +22 -22
  26. package/lib/commands/login.d.ts +1 -1
  27. package/lib/commands/login.js +3 -3
  28. package/lib/commands/preview-docs/index.d.ts +1 -1
  29. package/lib/commands/preview-docs/index.js +7 -7
  30. package/lib/commands/preview-docs/preview-server/hot.js +19 -2
  31. package/lib/commands/preview-docs/preview-server/preview-server.js +15 -14
  32. package/lib/commands/preview-docs/preview-server/server.d.ts +3 -1
  33. package/lib/commands/preview-docs/preview-server/server.js +2 -2
  34. package/lib/commands/push.d.ts +2 -2
  35. package/lib/commands/push.js +31 -31
  36. package/lib/commands/split/__tests__/index.test.js +9 -9
  37. package/lib/commands/split/index.d.ts +2 -2
  38. package/lib/commands/split/index.js +41 -40
  39. package/lib/commands/split/types.d.ts +2 -2
  40. package/lib/commands/split/types.js +2 -2
  41. package/lib/commands/stats.d.ts +1 -1
  42. package/lib/commands/stats.js +9 -9
  43. package/lib/fetch-with-timeout.js +5 -2
  44. package/lib/index.js +11 -12
  45. package/lib/types.d.ts +6 -6
  46. package/lib/update-version-notifier.js +18 -18
  47. package/lib/utils.d.ts +6 -3
  48. package/lib/utils.js +66 -38
  49. package/lib/wrapper.js +5 -5
  50. package/package.json +4 -3
  51. package/src/__mocks__/@redocly/openapi-core.ts +1 -0
  52. package/src/__mocks__/utils.ts +2 -0
  53. package/src/__tests__/commands/join.test.ts +37 -7
  54. package/src/__tests__/utils.test.ts +45 -1
  55. package/src/commands/join.ts +8 -3
  56. package/src/commands/preview-docs/preview-server/hot.js +19 -2
  57. package/src/commands/preview-docs/preview-server/preview-server.ts +6 -4
  58. package/src/commands/preview-docs/preview-server/server.ts +2 -2
  59. package/src/commands/split/__tests__/index.test.ts +14 -5
  60. package/src/commands/split/index.ts +25 -17
  61. package/src/fetch-with-timeout.ts +3 -0
  62. package/src/index.ts +0 -1
  63. package/src/utils.ts +40 -1
  64. package/tsconfig.tsbuildinfo +1 -1
@@ -31,7 +31,7 @@ describe('push', () => {
31
31
  jest.spyOn(process.stdout, 'write').mockImplementation(() => true);
32
32
  });
33
33
  it('pushes definition', () => __awaiter(void 0, void 0, void 0, function* () {
34
- yield push_1.handlePush({
34
+ yield (0, push_1.handlePush)({
35
35
  upsert: true,
36
36
  api: 'spec.json',
37
37
  destination: '@org/my-api@1.0.0',
@@ -56,7 +56,7 @@ describe('push', () => {
56
56
  });
57
57
  }));
58
58
  it('fails if jobId value is an empty string', () => __awaiter(void 0, void 0, void 0, function* () {
59
- yield push_1.handlePush({
59
+ yield (0, push_1.handlePush)({
60
60
  upsert: true,
61
61
  api: 'spec.json',
62
62
  destination: '@org/my-api@1.0.0',
@@ -68,7 +68,7 @@ describe('push', () => {
68
68
  expect(utils_1.exitWithError).toBeCalledTimes(1);
69
69
  }));
70
70
  it('fails if batchSize value is less than 2', () => __awaiter(void 0, void 0, void 0, function* () {
71
- yield push_1.handlePush({
71
+ yield (0, push_1.handlePush)({
72
72
  upsert: true,
73
73
  api: 'spec.json',
74
74
  destination: '@org/my-api@1.0.0',
@@ -84,7 +84,7 @@ describe('push', () => {
84
84
  fs.statSync.mockImplementation(() => {
85
85
  return { isDirectory: () => false, size: 10 };
86
86
  });
87
- yield push_1.handlePush({
87
+ yield (0, push_1.handlePush)({
88
88
  upsert: true,
89
89
  api: 'spec.json',
90
90
  destination: '@org/my-api@1.0.0',
@@ -103,7 +103,7 @@ describe('push', () => {
103
103
  expect(redoclyClient.registryApi.prepareFileUpload).toBeCalledTimes(3);
104
104
  }));
105
105
  it('push should fail if organization not provided', () => __awaiter(void 0, void 0, void 0, function* () {
106
- yield push_1.handlePush({
106
+ yield (0, push_1.handlePush)({
107
107
  upsert: true,
108
108
  api: 'spec.json',
109
109
  destination: 'test@v1',
@@ -117,7 +117,7 @@ describe('push', () => {
117
117
  }));
118
118
  it('push should work with organization in config', () => __awaiter(void 0, void 0, void 0, function* () {
119
119
  const mockConfig = Object.assign(Object.assign({}, config_1.ConfigFixture), { organization: 'test_org' });
120
- yield push_1.handlePush({
120
+ yield (0, push_1.handlePush)({
121
121
  upsert: true,
122
122
  api: 'spec.json',
123
123
  destination: 'my-api@1.0.0',
@@ -142,7 +142,7 @@ describe('push', () => {
142
142
  }));
143
143
  it('push should work if destination not provided but api in config is provided', () => __awaiter(void 0, void 0, void 0, function* () {
144
144
  const mockConfig = Object.assign(Object.assign({}, config_1.ConfigFixture), { organization: 'test_org', apis: { 'my-api@1.0.0': { root: 'path' } } });
145
- yield push_1.handlePush({
145
+ yield (0, push_1.handlePush)({
146
146
  upsert: true,
147
147
  branchName: 'test',
148
148
  public: true,
@@ -153,7 +153,7 @@ describe('push', () => {
153
153
  }));
154
154
  it('push should fail if apis not provided', () => __awaiter(void 0, void 0, void 0, function* () {
155
155
  const mockConfig = { organization: 'test_org', apis: {} };
156
- yield push_1.handlePush({
156
+ yield (0, push_1.handlePush)({
157
157
  upsert: true,
158
158
  branchName: 'test',
159
159
  public: true,
@@ -165,7 +165,7 @@ describe('push', () => {
165
165
  }));
166
166
  it('push should fail if destination not provided', () => __awaiter(void 0, void 0, void 0, function* () {
167
167
  const mockConfig = { organization: 'test_org', apis: {} };
168
- yield push_1.handlePush({
168
+ yield (0, push_1.handlePush)({
169
169
  upsert: true,
170
170
  api: 'api.yaml',
171
171
  branchName: 'test',
@@ -178,7 +178,7 @@ describe('push', () => {
178
178
  }));
179
179
  it('push should fail if destination format is not valid', () => __awaiter(void 0, void 0, void 0, function* () {
180
180
  const mockConfig = { organization: 'test_org', apis: {} };
181
- yield push_1.handlePush({
181
+ yield (0, push_1.handlePush)({
182
182
  upsert: true,
183
183
  destination: 'name/v1',
184
184
  branchName: 'test',
@@ -186,12 +186,12 @@ describe('push', () => {
186
186
  'job-id': '123',
187
187
  'batch-size': 2,
188
188
  }, mockConfig);
189
- expect(utils_1.exitWithError).toHaveBeenCalledWith(`Destination argument value is not valid, please use the right format: ${colorette_1.yellow('<api-name@api-version>')}`);
189
+ expect(utils_1.exitWithError).toHaveBeenCalledWith(`Destination argument value is not valid, please use the right format: ${(0, colorette_1.yellow)('<api-name@api-version>')}`);
190
190
  }));
191
191
  it('push should work and encode name with spaces', () => __awaiter(void 0, void 0, void 0, function* () {
192
192
  const encodeURIComponentSpy = jest.spyOn(global, 'encodeURIComponent');
193
193
  const mockConfig = Object.assign(Object.assign({}, config_1.ConfigFixture), { organization: 'test_org', apis: { 'my test api@v1': { root: 'path' } } });
194
- yield push_1.handlePush({
194
+ yield (0, push_1.handlePush)({
195
195
  upsert: true,
196
196
  destination: 'my test api@v1',
197
197
  branchName: 'test',
@@ -206,7 +206,7 @@ describe('push', () => {
206
206
  describe('transformPush', () => {
207
207
  it('should adapt the existing syntax', () => {
208
208
  const cb = jest.fn();
209
- push_1.transformPush(cb)({
209
+ (0, push_1.transformPush)(cb)({
210
210
  api: 'openapi.yaml',
211
211
  maybeDestination: '@testing_org/main@v1',
212
212
  }, {});
@@ -217,7 +217,7 @@ describe('transformPush', () => {
217
217
  });
218
218
  it('should adapt the existing syntax (including branchName)', () => {
219
219
  const cb = jest.fn();
220
- push_1.transformPush(cb)({
220
+ (0, push_1.transformPush)(cb)({
221
221
  api: 'openapi.yaml',
222
222
  maybeDestination: '@testing_org/main@v1',
223
223
  maybeBranchName: 'other',
@@ -230,7 +230,7 @@ describe('transformPush', () => {
230
230
  });
231
231
  it('should use --branch option firstly', () => {
232
232
  const cb = jest.fn();
233
- push_1.transformPush(cb)({
233
+ (0, push_1.transformPush)(cb)({
234
234
  api: 'openapi.yaml',
235
235
  maybeDestination: '@testing_org/main@v1',
236
236
  maybeBranchName: 'other',
@@ -244,7 +244,7 @@ describe('transformPush', () => {
244
244
  });
245
245
  it('should work for a destination only', () => {
246
246
  const cb = jest.fn();
247
- push_1.transformPush(cb)({
247
+ (0, push_1.transformPush)(cb)({
248
248
  api: '@testing_org/main@v1',
249
249
  }, {});
250
250
  expect(cb).toBeCalledWith({
@@ -253,7 +253,7 @@ describe('transformPush', () => {
253
253
  });
254
254
  it('should work for a api only', () => {
255
255
  const cb = jest.fn();
256
- push_1.transformPush(cb)({
256
+ (0, push_1.transformPush)(cb)({
257
257
  api: 'test.yaml',
258
258
  }, {});
259
259
  expect(cb).toBeCalledWith({
@@ -262,7 +262,7 @@ describe('transformPush', () => {
262
262
  });
263
263
  it('should accept aliases for the old syntax', () => {
264
264
  const cb = jest.fn();
265
- push_1.transformPush(cb)({
265
+ (0, push_1.transformPush)(cb)({
266
266
  api: 'alias',
267
267
  maybeDestination: '@testing_org/main@v1',
268
268
  }, {});
@@ -273,7 +273,7 @@ describe('transformPush', () => {
273
273
  });
274
274
  it('should use --job-id option firstly', () => {
275
275
  const cb = jest.fn();
276
- push_1.transformPush(cb)({
276
+ (0, push_1.transformPush)(cb)({
277
277
  'batch-id': 'b-123',
278
278
  'job-id': 'j-123',
279
279
  api: 'test',
@@ -290,60 +290,60 @@ describe('transformPush', () => {
290
290
  });
291
291
  it('should accept no arguments at all', () => {
292
292
  const cb = jest.fn();
293
- push_1.transformPush(cb)({}, {});
293
+ (0, push_1.transformPush)(cb)({}, {});
294
294
  expect(cb).toBeCalledWith({}, {});
295
295
  });
296
296
  });
297
297
  describe('getDestinationProps', () => {
298
298
  it('should get valid destination props for the full destination syntax', () => {
299
- expect(push_1.getDestinationProps('@testing_org/main@v1', 'org-from-config')).toEqual({
299
+ expect((0, push_1.getDestinationProps)('@testing_org/main@v1', 'org-from-config')).toEqual({
300
300
  organizationId: 'testing_org',
301
301
  name: 'main',
302
302
  version: 'v1',
303
303
  });
304
304
  });
305
305
  it('should fallback the organizationId from a config for the short destination syntax', () => {
306
- expect(push_1.getDestinationProps('main@v1', 'org-from-config')).toEqual({
306
+ expect((0, push_1.getDestinationProps)('main@v1', 'org-from-config')).toEqual({
307
307
  organizationId: 'org-from-config',
308
308
  name: 'main',
309
309
  version: 'v1',
310
310
  });
311
311
  });
312
312
  it('should fallback the organizationId from a config if no destination provided', () => {
313
- expect(push_1.getDestinationProps(undefined, 'org-from-config')).toEqual({
313
+ expect((0, push_1.getDestinationProps)(undefined, 'org-from-config')).toEqual({
314
314
  organizationId: 'org-from-config',
315
315
  });
316
316
  });
317
317
  it('should return empty organizationId if there is no one found', () => {
318
- expect(push_1.getDestinationProps('main@v1', undefined)).toEqual({
318
+ expect((0, push_1.getDestinationProps)('main@v1', undefined)).toEqual({
319
319
  organizationId: undefined,
320
320
  name: 'main',
321
321
  version: 'v1',
322
322
  });
323
323
  });
324
324
  it('should return organizationId from destination string', () => {
325
- expect(push_1.getDestinationProps('@test-org/main@main-v1', undefined)).toEqual({
325
+ expect((0, push_1.getDestinationProps)('@test-org/main@main-v1', undefined)).toEqual({
326
326
  organizationId: 'test-org',
327
327
  name: 'main',
328
328
  version: 'main-v1',
329
329
  });
330
330
  });
331
331
  it('should return organizationId, version and empty name from destination string', () => {
332
- expect(push_1.getDestinationProps('@test_org/@main_v1', undefined)).toEqual({
332
+ expect((0, push_1.getDestinationProps)('@test_org/@main_v1', undefined)).toEqual({
333
333
  organizationId: 'test_org',
334
334
  name: '',
335
335
  version: 'main_v1',
336
336
  });
337
337
  });
338
338
  it('should validate organizationId with space and version with dot', () => {
339
- expect(push_1.getDestinationProps('@test org/simple_name@main.v1', undefined)).toEqual({
339
+ expect((0, push_1.getDestinationProps)('@test org/simple_name@main.v1', undefined)).toEqual({
340
340
  organizationId: 'test org',
341
341
  name: 'simple_name',
342
342
  version: 'main.v1',
343
343
  });
344
344
  });
345
345
  it('should not work with "@" in destination name', () => {
346
- expect(push_1.getDestinationProps('@test org/simple@name@main.v1', undefined)).toEqual({
346
+ expect((0, push_1.getDestinationProps)('@test org/simple@name@main.v1', undefined)).toEqual({
347
347
  organizationId: undefined,
348
348
  name: undefined,
349
349
  version: undefined,
@@ -362,9 +362,9 @@ describe('getApiRoot', () => {
362
362
  },
363
363
  };
364
364
  it('should resolve the correct api for a valid name & version', () => {
365
- expect(push_1.getApiRoot({ name: 'main', version: 'v1', config })).toEqual('openapi.yaml');
365
+ expect((0, push_1.getApiRoot)({ name: 'main', version: 'v1', config })).toEqual('openapi.yaml');
366
366
  });
367
367
  it('should resolve the latest version of api if there is no matching version', () => {
368
- expect(push_1.getApiRoot({ name: 'main', version: 'latest', config })).toEqual('latest.yaml');
368
+ expect((0, push_1.getApiRoot)({ name: 'main', version: 'latest', config })).toEqual('latest.yaml');
369
369
  });
370
370
  });
@@ -21,7 +21,7 @@ describe('fetchWithTimeout', () => {
21
21
  global.AbortController = undefined;
22
22
  // @ts-ignore
23
23
  global.setTimeout = jest.fn();
24
- yield fetch_with_timeout_1.default('url', { method: 'GET' });
24
+ yield (0, fetch_with_timeout_1.default)('url', { method: 'GET' });
25
25
  expect(node_fetch_1.default).toHaveBeenCalledWith('url', { method: 'GET' });
26
26
  expect(global.setTimeout).toHaveBeenCalledTimes(0);
27
27
  }));
@@ -30,7 +30,7 @@ describe('fetchWithTimeout', () => {
30
30
  // @ts-ignore
31
31
  global.setTimeout = jest.fn();
32
32
  global.clearTimeout = jest.fn();
33
- yield fetch_with_timeout_1.default('url');
33
+ yield (0, fetch_with_timeout_1.default)('url');
34
34
  expect(global.setTimeout).toHaveBeenCalledTimes(1);
35
35
  expect(node_fetch_1.default).toHaveBeenCalledWith('url', { signal: 'something' });
36
36
  expect(global.clearTimeout).toHaveBeenCalledTimes(1);
@@ -31,7 +31,7 @@ describe('isSubdir', () => {
31
31
  ['/foo', './bar', false],
32
32
  ['/foo', '/foo/..bar', true],
33
33
  ].forEach(([parent, child, expectRes]) => {
34
- expect(utils_1.isSubdir(parent, child)).toBe(expectRes);
34
+ expect((0, utils_1.isSubdir)(parent, child)).toBe(expectRes);
35
35
  });
36
36
  });
37
37
  it('can correctly determine if subdir for windows-based paths', () => {
@@ -42,7 +42,7 @@ describe('isSubdir', () => {
42
42
  ['C:\\Foo', 'C:\\Bar', false],
43
43
  ['C:\\Foo', 'D:\\Foo\\Bar', false],
44
44
  ].forEach(([parent, child, expectRes]) => {
45
- expect(utils_1.isSubdir(parent, child)).toBe(expectRes);
45
+ expect((0, utils_1.isSubdir)(parent, child)).toBe(expectRes);
46
46
  });
47
47
  });
48
48
  afterEach(() => {
@@ -51,14 +51,14 @@ describe('isSubdir', () => {
51
51
  });
52
52
  describe('pathToFilename', () => {
53
53
  it('should use correct path separator', () => {
54
- const processedPath = utils_1.pathToFilename('/user/createWithList', '_');
54
+ const processedPath = (0, utils_1.pathToFilename)('/user/createWithList', '_');
55
55
  expect(processedPath).toEqual('user_createWithList');
56
56
  });
57
57
  });
58
58
  describe('getFallbackApisOrExit', () => {
59
59
  it('should find alias by filename', () => __awaiter(void 0, void 0, void 0, function* () {
60
60
  fs_1.existsSync.mockImplementationOnce(() => true);
61
- const entry = yield utils_1.getFallbackApisOrExit(['./test.yaml'], {
61
+ const entry = yield (0, utils_1.getFallbackApisOrExit)(['./test.yaml'], {
62
62
  apis: {
63
63
  main: {
64
64
  root: 'test.yaml',
@@ -82,17 +82,17 @@ describe('printConfigLintTotals', () => {
82
82
  jest.spyOn(process.stderr, 'write').mockImplementation(() => true);
83
83
  });
84
84
  it('should print errors if such exist', () => {
85
- utils_1.printConfigLintTotals(totalProblemsMock);
85
+ (0, utils_1.printConfigLintTotals)(totalProblemsMock);
86
86
  expect(process.stderr.write).toHaveBeenCalledWith('❌ Your config has 1 error.');
87
87
  expect(redColoretteMocks).toHaveBeenCalledWith('❌ Your config has 1 error.');
88
88
  });
89
89
  it('should print warnign if no error', () => {
90
- utils_1.printConfigLintTotals(Object.assign(Object.assign({}, totalProblemsMock), { errors: 0, warnings: 2 }));
90
+ (0, utils_1.printConfigLintTotals)(Object.assign(Object.assign({}, totalProblemsMock), { errors: 0, warnings: 2 }));
91
91
  expect(process.stderr.write).toHaveBeenCalledWith('⚠️ Your config has 2 warnings.\n');
92
92
  expect(yellowColoretteMocks).toHaveBeenCalledWith('⚠️ Your config has 2 warnings.\n');
93
93
  });
94
94
  it('should print nothing if no error and no warnings', () => {
95
- const result = utils_1.printConfigLintTotals(Object.assign(Object.assign({}, totalProblemsMock), { errors: 0 }));
95
+ const result = (0, utils_1.printConfigLintTotals)(Object.assign(Object.assign({}, totalProblemsMock), { errors: 0 }));
96
96
  expect(result).toBeUndefined();
97
97
  expect(process.stderr.write).toHaveBeenCalledTimes(0);
98
98
  expect(yellowColoretteMocks).toHaveBeenCalledTimes(0);
@@ -124,7 +124,7 @@ describe('getFallbackApisOrExit', () => {
124
124
  };
125
125
  expect.assertions(1);
126
126
  try {
127
- yield utils_1.getFallbackApisOrExit([''], apisConfig);
127
+ yield (0, utils_1.getFallbackApisOrExit)([''], apisConfig);
128
128
  }
129
129
  catch (e) {
130
130
  expect(e.message).toEqual('Path cannot be empty.');
@@ -134,7 +134,7 @@ describe('getFallbackApisOrExit', () => {
134
134
  fs_1.existsSync.mockImplementationOnce(() => false);
135
135
  expect.assertions(3);
136
136
  try {
137
- yield utils_1.getFallbackApisOrExit(undefined, config);
137
+ yield (0, utils_1.getFallbackApisOrExit)(undefined, config);
138
138
  }
139
139
  catch (e) {
140
140
  expect(process.stderr.write).toHaveBeenCalledWith('\nsomeFile.yaml does not exist or is invalid.\n\n');
@@ -145,7 +145,7 @@ describe('getFallbackApisOrExit', () => {
145
145
  it('should return valid array with results if such file exist', () => __awaiter(void 0, void 0, void 0, function* () {
146
146
  fs_1.existsSync.mockImplementationOnce(() => true);
147
147
  jest.spyOn(path, 'resolve').mockImplementationOnce((_, path) => path);
148
- const result = yield utils_1.getFallbackApisOrExit(undefined, config);
148
+ const result = yield (0, utils_1.getFallbackApisOrExit)(undefined, config);
149
149
  expect(process.stderr.write).toHaveBeenCalledTimes(0);
150
150
  expect(process.exit).toHaveBeenCalledTimes(0);
151
151
  expect(result).toStrictEqual([
@@ -162,7 +162,7 @@ describe('getFallbackApisOrExit', () => {
162
162
  fs_1.existsSync.mockImplementationOnce(() => false);
163
163
  expect.assertions(3);
164
164
  try {
165
- yield utils_1.getFallbackApisOrExit(['someFile.yaml'], apisConfig);
165
+ yield (0, utils_1.getFallbackApisOrExit)(['someFile.yaml'], apisConfig);
166
166
  }
167
167
  catch (e) {
168
168
  expect(process.stderr.write).toHaveBeenCalledWith('\nsomeFile.yaml does not exist or is invalid.\n\n');
@@ -177,7 +177,7 @@ describe('getFallbackApisOrExit', () => {
177
177
  fs_1.existsSync.mockImplementationOnce(() => false);
178
178
  expect.assertions(3);
179
179
  try {
180
- yield utils_1.getFallbackApisOrExit(['someFile.yaml', 'someFile2.yaml'], apisConfig);
180
+ yield (0, utils_1.getFallbackApisOrExit)(['someFile.yaml', 'someFile2.yaml'], apisConfig);
181
181
  }
182
182
  catch (e) {
183
183
  expect(process.stderr.write).toHaveBeenCalledWith('\nsomeFile.yaml does not exist or is invalid.\n\n');
@@ -194,7 +194,7 @@ describe('getFallbackApisOrExit', () => {
194
194
  const existSyncMock = fs_1.existsSync.mockImplementation((path) => path.endsWith('someFile.yaml'));
195
195
  expect.assertions(4);
196
196
  try {
197
- yield utils_1.getFallbackApisOrExit(undefined, configStub);
197
+ yield (0, utils_1.getFallbackApisOrExit)(undefined, configStub);
198
198
  }
199
199
  catch (e) {
200
200
  expect(process.stderr.write).toHaveBeenCalledWith('\nnotExist.yaml does not exist or is invalid.\n\n');
@@ -215,7 +215,7 @@ describe('getFallbackApisOrExit', () => {
215
215
  },
216
216
  },
217
217
  };
218
- const result = yield utils_1.getFallbackApisOrExit(undefined, apisConfig);
218
+ const result = yield (0, utils_1.getFallbackApisOrExit)(undefined, apisConfig);
219
219
  expect(process.stderr.write).toHaveBeenCalledTimes(0);
220
220
  expect(result).toStrictEqual([
221
221
  {
@@ -236,10 +236,10 @@ describe('langToExt', () => {
236
236
  ['js', '.js'],
237
237
  ['python', '.py'],
238
238
  ])('should infer file extension from lang - %s', (lang, expected) => {
239
- expect(utils_1.langToExt(lang)).toBe(expected);
239
+ expect((0, utils_1.langToExt)(lang)).toBe(expected);
240
240
  });
241
241
  it('should ignore case when inferring file extension', () => {
242
- expect(utils_1.langToExt('JavaScript')).toBe('.js');
242
+ expect((0, utils_1.langToExt)('JavaScript')).toBe('.js');
243
243
  });
244
244
  });
245
245
  describe('sorTopLevelKeysForOas', () => {
@@ -270,7 +270,7 @@ describe('sorTopLevelKeysForOas', () => {
270
270
  'x-webhooks',
271
271
  'components',
272
272
  ];
273
- const result = utils_1.sortTopLevelKeysForOas(openApi);
273
+ const result = (0, utils_1.sortTopLevelKeysForOas)(openApi);
274
274
  Object.keys(result).forEach((key, index) => {
275
275
  expect(key).toEqual(orderedKeys[index]);
276
276
  });
@@ -310,7 +310,7 @@ describe('sorTopLevelKeysForOas', () => {
310
310
  'responses',
311
311
  'securityDefinitions',
312
312
  ];
313
- const result = utils_1.sortTopLevelKeysForOas(openApi);
313
+ const result = (0, utils_1.sortTopLevelKeysForOas)(openApi);
314
314
  Object.keys(result).forEach((key, index) => {
315
315
  expect(key).toEqual(orderedKeys[index]);
316
316
  });
@@ -331,31 +331,31 @@ describe('handleErrors', () => {
331
331
  });
332
332
  it('should handle ResolveError', () => {
333
333
  const resolveError = new openapi_core_1.ResolveError(new Error('File not found'));
334
- expect(() => utils_1.handleError(resolveError, ref)).toThrowError(utils_1.HandledError);
334
+ expect(() => (0, utils_1.handleError)(resolveError, ref)).toThrowError(utils_1.HandledError);
335
335
  expect(redColoretteMocks).toHaveBeenCalledTimes(1);
336
336
  expect(process.stderr.write).toHaveBeenCalledWith(`Failed to resolve API description at openapi/test.yaml:\n\n - File not found.\n\n`);
337
337
  });
338
338
  it('should handle YamlParseError', () => {
339
339
  const yamlParseError = new openapi_core_1.YamlParseError(new Error('Invalid yaml'), {});
340
- expect(() => utils_1.handleError(yamlParseError, ref)).toThrowError(utils_1.HandledError);
340
+ expect(() => (0, utils_1.handleError)(yamlParseError, ref)).toThrowError(utils_1.HandledError);
341
341
  expect(redColoretteMocks).toHaveBeenCalledTimes(1);
342
342
  expect(process.stderr.write).toHaveBeenCalledWith(`Failed to parse API description at openapi/test.yaml:\n\n - Invalid yaml.\n\n`);
343
343
  });
344
344
  it('should handle CircularJSONNotSupportedError', () => {
345
345
  const circularError = new utils_1.CircularJSONNotSupportedError(new Error('Circular json'));
346
- expect(() => utils_1.handleError(circularError, ref)).toThrowError(utils_1.HandledError);
346
+ expect(() => (0, utils_1.handleError)(circularError, ref)).toThrowError(utils_1.HandledError);
347
347
  expect(process.stderr.write).toHaveBeenCalledWith(`Detected circular reference which can't be converted to JSON.\n` +
348
- `Try to use ${colorette_1.blue('yaml')} output or remove ${colorette_1.blue('--dereferenced')}.\n\n`);
348
+ `Try to use ${(0, colorette_1.blue)('yaml')} output or remove ${(0, colorette_1.blue)('--dereferenced')}.\n\n`);
349
349
  });
350
350
  it('should handle SyntaxError', () => {
351
351
  const testError = new SyntaxError('Unexpected identifier');
352
352
  testError.stack = 'test stack';
353
- expect(() => utils_1.handleError(testError, ref)).toThrowError(utils_1.HandledError);
353
+ expect(() => (0, utils_1.handleError)(testError, ref)).toThrowError(utils_1.HandledError);
354
354
  expect(process.stderr.write).toHaveBeenCalledWith('Syntax error: Unexpected identifier test stack\n\n');
355
355
  });
356
356
  it('should throw unknown error', () => {
357
357
  const testError = new Error('Test error');
358
- expect(() => utils_1.handleError(testError, ref)).toThrowError(utils_1.HandledError);
358
+ expect(() => (0, utils_1.handleError)(testError, ref)).toThrowError(utils_1.HandledError);
359
359
  expect(process.stderr.write).toHaveBeenCalledWith(`Something went wrong when processing openapi/test.yaml:\n\n - Test error.\n\n`);
360
360
  });
361
361
  });
@@ -373,7 +373,7 @@ describe('checkIfRulesetExist', () => {
373
373
  oas3_1: {},
374
374
  async2: {},
375
375
  };
376
- expect(() => utils_1.checkIfRulesetExist(rules)).toThrowError('⚠️ No rules were configured. Learn how to configure rules: https://redocly.com/docs/cli/rules/');
376
+ expect(() => (0, utils_1.checkIfRulesetExist)(rules)).toThrowError('⚠️ No rules were configured. Learn how to configure rules: https://redocly.com/docs/cli/rules/');
377
377
  });
378
378
  it('should not throw an error if rules are provided', () => {
379
379
  const rules = {
@@ -381,13 +381,13 @@ describe('checkIfRulesetExist', () => {
381
381
  oas3_0: {},
382
382
  oas3_1: {},
383
383
  };
384
- utils_1.checkIfRulesetExist(rules);
384
+ (0, utils_1.checkIfRulesetExist)(rules);
385
385
  });
386
386
  });
387
387
  describe('cleanColors', () => {
388
388
  it('should remove colors from string', () => {
389
- const stringWithColors = `String for ${colorette_1.red('test')}`;
390
- const result = utils_1.cleanColors(stringWithColors);
389
+ const stringWithColors = `String for ${(0, colorette_1.red)('test')}`;
390
+ const result = (0, utils_1.cleanColors)(stringWithColors);
391
391
  expect(result).not.toMatch(/\x1b\[\d+m/g);
392
392
  });
393
393
  });
@@ -409,7 +409,7 @@ describe('cleanArgs', () => {
409
409
  apis: ['main@v1', 'fixtures/openapi.yaml', 'http://some.url/openapi.yaml'],
410
410
  format: 'codeframe',
411
411
  };
412
- expect(utils_1.cleanArgs(testArgs)).toEqual({
412
+ expect((0, utils_1.cleanArgs)(testArgs)).toEqual({
413
413
  config: 'file-yaml',
414
414
  apis: ['api-name@api-version', 'file-yaml', 'http://url'],
415
415
  format: 'codeframe',
@@ -419,7 +419,7 @@ describe('cleanArgs', () => {
419
419
  const testArgs = {
420
420
  destination: '@org/name@version',
421
421
  };
422
- expect(utils_1.cleanArgs(testArgs)).toEqual({
422
+ expect((0, utils_1.cleanArgs)(testArgs)).toEqual({
423
423
  destination: '@organization/api-name@api-version',
424
424
  });
425
425
  });
@@ -447,7 +447,7 @@ describe('cleanRawInput', () => {
447
447
  '--output',
448
448
  'fixtures',
449
449
  ];
450
- expect(utils_1.cleanRawInput(rawInput)).toEqual('redocly bundle api-name@api-version file-yaml http://url --config=file-yaml --output folder');
450
+ expect((0, utils_1.cleanRawInput)(rawInput)).toEqual('redocly bundle api-name@api-version file-yaml http://url --config=file-yaml --output folder');
451
451
  });
452
452
  it('should preserve safe data from raw CLI input', () => {
453
453
  const rawInput = [
@@ -460,6 +460,37 @@ describe('cleanRawInput', () => {
460
460
  '--skip-rule',
461
461
  'operation-4xx-response',
462
462
  ];
463
- expect(utils_1.cleanRawInput(rawInput)).toEqual('redocly lint file-json --format stylish --extends=minimal --skip-rule operation-4xx-response');
463
+ expect((0, utils_1.cleanRawInput)(rawInput)).toEqual('redocly lint file-json --format stylish --extends=minimal --skip-rule operation-4xx-response');
464
+ });
465
+ describe('validateFileExtension', () => {
466
+ it('should return current file extension', () => {
467
+ expect((0, utils_1.getAndValidateFileExtension)('test.json')).toEqual('json');
468
+ });
469
+ it('should return yaml and print warning if file extension does not supported', () => {
470
+ const stderrMock = jest.spyOn(process.stderr, 'write').mockImplementation(() => true);
471
+ colorette_1.yellow.mockImplementation((text) => text);
472
+ expect((0, utils_1.getAndValidateFileExtension)('test.xml')).toEqual('yaml');
473
+ expect(stderrMock).toHaveBeenCalledWith(`Unsupported file extension: xml. Using yaml.\n`);
474
+ });
475
+ });
476
+ describe('writeToFileByExtension', () => {
477
+ beforeEach(() => {
478
+ jest.spyOn(process.stderr, 'write').mockImplementation(jest.fn());
479
+ colorette_1.yellow.mockImplementation((text) => text);
480
+ });
481
+ afterEach(() => {
482
+ jest.restoreAllMocks();
483
+ });
484
+ it('should call stringifyYaml function', () => {
485
+ (0, utils_1.writeToFileByExtension)('test data', 'test.yaml');
486
+ expect(openapi_core_1.stringifyYaml).toHaveBeenCalledWith('test data', { noRefs: false });
487
+ expect(process.stderr.write).toHaveBeenCalledWith(`test data`);
488
+ });
489
+ it('should call JSON.stringify function', () => {
490
+ const stringifySpy = jest.spyOn(JSON, 'stringify').mockImplementation((data) => data);
491
+ (0, utils_1.writeToFileByExtension)('test data', 'test.json');
492
+ expect(stringifySpy).toHaveBeenCalledWith('test data', null, 2);
493
+ expect(process.stderr.write).toHaveBeenCalledWith(`test data`);
494
+ });
464
495
  });
465
496
  });
@@ -29,7 +29,7 @@ describe('commandWrapper', () => {
29
29
  return { telemetry: 'on', styleguide: { recommendedFallback: true } };
30
30
  });
31
31
  process.env.REDOCLY_TELEMETRY = 'on';
32
- const wrappedHandler = wrapper_1.commandWrapper(lint_1.handleLint);
32
+ const wrappedHandler = (0, wrapper_1.commandWrapper)(lint_1.handleLint);
33
33
  yield wrappedHandler({});
34
34
  expect(lint_1.handleLint).toHaveBeenCalledTimes(1);
35
35
  expect(utils_1.sendTelemetry).toHaveBeenCalledTimes(1);
@@ -40,7 +40,7 @@ describe('commandWrapper', () => {
40
40
  return { telemetry: 'off', styleguide: { recommendedFallback: true } };
41
41
  });
42
42
  process.env.REDOCLY_TELEMETRY = 'on';
43
- const wrappedHandler = wrapper_1.commandWrapper(lint_1.handleLint);
43
+ const wrappedHandler = (0, wrapper_1.commandWrapper)(lint_1.handleLint);
44
44
  yield wrappedHandler({});
45
45
  expect(lint_1.handleLint).toHaveBeenCalledTimes(1);
46
46
  expect(utils_1.sendTelemetry).toHaveBeenCalledTimes(0);
@@ -51,7 +51,7 @@ describe('commandWrapper', () => {
51
51
  const argv = {
52
52
  files: filesToPush,
53
53
  };
54
- yield wrapper_1.commandWrapper(push_1.handlePush)(argv);
54
+ yield (0, wrapper_1.commandWrapper)(push_1.handlePush)(argv);
55
55
  expect(loadConfigMock).toHaveBeenCalledWith(expect.objectContaining({ files: filesToPush }));
56
56
  }));
57
57
  });
@@ -8,7 +8,7 @@ try {
8
8
  const { engines } = require(path.join(__dirname, '../package.json'));
9
9
  const version = engines.node;
10
10
  if (!semver.satisfies(process.version, version)) {
11
- process.stderr.write(colorette_1.yellow(`\n⚠️ Warning: failed to satisfy expected node version. Expected: "${version}", Current "${process.version}"\n\n`));
11
+ process.stderr.write((0, colorette_1.yellow)(`\n⚠️ Warning: failed to satisfy expected node version. Expected: "${version}", Current "${process.version}"\n\n`));
12
12
  }
13
13
  }
14
14
  catch (e) {
@@ -20,8 +20,8 @@ const utils_2 = require("../../utils");
20
20
  const handlerBuildCommand = (argv, configFromFile) => __awaiter(void 0, void 0, void 0, function* () {
21
21
  var _a;
22
22
  const startedAt = perf_hooks_1.performance.now();
23
- const config = openapi_core_1.getMergedConfig(configFromFile, argv.api);
24
- const apis = yield utils_2.getFallbackApisOrExit(argv.api ? [argv.api] : [], config);
23
+ const config = (0, openapi_core_1.getMergedConfig)(configFromFile, argv.api);
24
+ const apis = yield (0, utils_2.getFallbackApisOrExit)(argv.api ? [argv.api] : [], config);
25
25
  const { path: pathToApi } = apis[0];
26
26
  const options = {
27
27
  output: argv.o,
@@ -29,20 +29,20 @@ const handlerBuildCommand = (argv, configFromFile) => __awaiter(void 0, void 0,
29
29
  disableGoogleFont: argv.disableGoogleFont,
30
30
  templateFileName: argv.template,
31
31
  templateOptions: argv.templateOptions || {},
32
- redocOptions: utils_1.getObjectOrJSON((_a = argv.theme) === null || _a === void 0 ? void 0 : _a.openapi, config),
32
+ redocOptions: (0, utils_1.getObjectOrJSON)((_a = argv.theme) === null || _a === void 0 ? void 0 : _a.openapi, config),
33
33
  };
34
34
  const redocCurrentVersion = require('../../../package.json').dependencies.redoc.substring(1); // remove ~
35
35
  try {
36
- const elapsed = utils_2.getExecutionTime(startedAt);
37
- const api = yield redoc_1.loadAndBundleSpec(openapi_core_1.isAbsoluteUrl(pathToApi) ? pathToApi : path_1.resolve(pathToApi));
38
- const pageHTML = yield utils_1.getPageHTML(api, pathToApi, Object.assign(Object.assign({}, options), { redocCurrentVersion }), argv.config);
39
- fs_1.mkdirSync(path_1.dirname(options.output), { recursive: true });
40
- fs_1.writeFileSync(options.output, pageHTML);
36
+ const elapsed = (0, utils_2.getExecutionTime)(startedAt);
37
+ const api = yield (0, redoc_1.loadAndBundleSpec)((0, openapi_core_1.isAbsoluteUrl)(pathToApi) ? pathToApi : (0, path_1.resolve)(pathToApi));
38
+ const pageHTML = yield (0, utils_1.getPageHTML)(api, pathToApi, Object.assign(Object.assign({}, options), { redocCurrentVersion }), argv.config);
39
+ (0, fs_1.mkdirSync)((0, path_1.dirname)(options.output), { recursive: true });
40
+ (0, fs_1.writeFileSync)(options.output, pageHTML);
41
41
  const sizeInKiB = Math.ceil(Buffer.byteLength(pageHTML) / 1024);
42
42
  process.stdout.write(`\n🎉 bundled successfully in: ${options.output} (${sizeInKiB} KiB) [⏱ ${elapsed}].\n`);
43
43
  }
44
44
  catch (e) {
45
- utils_2.exitWithError(e);
45
+ (0, utils_2.exitWithError)(e);
46
46
  }
47
47
  });
48
48
  exports.handlerBuildCommand = handlerBuildCommand;
@@ -1,4 +1,4 @@
1
- export declare type BuildDocsOptions = {
1
+ export type BuildDocsOptions = {
2
2
  watch?: boolean;
3
3
  output?: string;
4
4
  title?: string;
@@ -9,7 +9,7 @@ export declare type BuildDocsOptions = {
9
9
  redocOptions?: any;
10
10
  redocCurrentVersion: string;
11
11
  };
12
- export declare type BuildDocsArgv = {
12
+ export type BuildDocsArgv = {
13
13
  api: string;
14
14
  o: string;
15
15
  title?: string;