@redocly/openapi-core 1.0.0-beta.107 → 1.0.0-beta.108

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 (98) hide show
  1. package/lib/benchmark/benches/lint-with-top-level-rule-report.bench.js +0 -1
  2. package/lib/bundle.js +5 -2
  3. package/lib/config/all.js +2 -2
  4. package/lib/config/config-resolvers.js +31 -13
  5. package/lib/config/config.d.ts +3 -5
  6. package/lib/config/config.js +7 -4
  7. package/lib/config/load.d.ts +7 -0
  8. package/lib/config/load.js +14 -6
  9. package/lib/config/minimal.js +2 -2
  10. package/lib/config/recommended.js +2 -2
  11. package/lib/config/rules.d.ts +1 -1
  12. package/lib/config/utils.js +5 -5
  13. package/lib/decorators/common/registry-dependencies.js +1 -1
  14. package/lib/env.d.ts +3 -0
  15. package/lib/env.js +8 -0
  16. package/lib/format/codeframes.js +16 -10
  17. package/lib/format/format.js +28 -26
  18. package/lib/index.d.ts +5 -5
  19. package/lib/index.js +3 -1
  20. package/lib/js-yaml/index.js +1 -0
  21. package/lib/logger.d.ts +10 -0
  22. package/lib/logger.js +31 -0
  23. package/lib/output.d.ts +3 -0
  24. package/lib/output.js +9 -0
  25. package/lib/redocly/index.js +10 -9
  26. package/lib/redocly/registry-api-types.d.ts +28 -30
  27. package/lib/redocly/registry-api.d.ts +4 -3
  28. package/lib/redocly/registry-api.js +7 -2
  29. package/lib/ref-utils.js +2 -1
  30. package/lib/resolve.d.ts +1 -1
  31. package/lib/resolve.js +1 -1
  32. package/lib/rules/ajv.js +1 -1
  33. package/lib/rules/common/assertions/asserts.js +4 -4
  34. package/lib/rules/common/assertions/index.js +1 -1
  35. package/lib/rules/common/operation-security-defined.js +1 -1
  36. package/lib/rules/common/spec.js +2 -2
  37. package/lib/rules/oas2/remove-unused-components.js +2 -2
  38. package/lib/rules/oas3/index.js +2 -2
  39. package/lib/rules/oas3/no-server-variables-empty-enum.d.ts +2 -0
  40. package/lib/rules/oas3/{no-servers-empty-enum.js → no-server-variables-empty-enum.js} +4 -4
  41. package/lib/rules/oas3/no-unused-components.js +1 -1
  42. package/lib/rules/oas3/remove-unused-components.js +3 -3
  43. package/lib/rules/utils.d.ts +1 -1
  44. package/lib/rules/utils.js +1 -1
  45. package/lib/types/redocly-yaml.js +1 -1
  46. package/lib/utils.d.ts +3 -0
  47. package/lib/utils.js +15 -7
  48. package/lib/visitors.d.ts +1 -1
  49. package/lib/visitors.js +2 -2
  50. package/package.json +1 -1
  51. package/src/__tests__/logger-browser.test.ts +53 -0
  52. package/src/__tests__/logger.test.ts +47 -0
  53. package/src/__tests__/output-browser.test.ts +18 -0
  54. package/src/__tests__/output.test.ts +15 -0
  55. package/src/__tests__/utils-browser.test.ts +11 -0
  56. package/src/__tests__/utils.test.ts +7 -0
  57. package/src/benchmark/benches/lint-with-top-level-rule-report.bench.ts +0 -1
  58. package/src/bundle.ts +6 -3
  59. package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +4 -4
  60. package/src/config/__tests__/config.test.ts +35 -0
  61. package/src/config/__tests__/load.test.ts +79 -1
  62. package/src/config/all.ts +2 -2
  63. package/src/config/config-resolvers.ts +43 -17
  64. package/src/config/config.ts +10 -8
  65. package/src/config/load.ts +28 -5
  66. package/src/config/minimal.ts +2 -2
  67. package/src/config/recommended.ts +2 -2
  68. package/src/config/utils.ts +6 -5
  69. package/src/decorators/common/registry-dependencies.ts +1 -1
  70. package/src/env.ts +5 -0
  71. package/src/format/codeframes.ts +15 -9
  72. package/src/format/format.ts +28 -33
  73. package/src/index.ts +6 -4
  74. package/src/js-yaml/index.ts +1 -0
  75. package/src/logger.ts +34 -0
  76. package/src/output.ts +7 -0
  77. package/src/redocly/index.ts +7 -4
  78. package/src/redocly/registry-api-types.ts +27 -29
  79. package/src/redocly/registry-api.ts +16 -6
  80. package/src/ref-utils.ts +2 -1
  81. package/src/resolve.ts +4 -4
  82. package/src/rules/ajv.ts +1 -1
  83. package/src/rules/common/assertions/asserts.ts +4 -4
  84. package/src/rules/common/assertions/index.ts +1 -1
  85. package/src/rules/common/operation-security-defined.ts +1 -1
  86. package/src/rules/common/spec.ts +2 -2
  87. package/src/rules/oas2/remove-unused-components.ts +2 -2
  88. package/src/rules/oas3/__tests__/no-empty-enum-servers.com.test.ts +16 -16
  89. package/src/rules/oas3/index.ts +2 -2
  90. package/src/rules/oas3/{no-servers-empty-enum.ts → no-server-variables-empty-enum.ts} +2 -2
  91. package/src/rules/oas3/no-unused-components.ts +1 -1
  92. package/src/rules/oas3/remove-unused-components.ts +4 -4
  93. package/src/rules/utils.ts +1 -1
  94. package/src/types/redocly-yaml.ts +1 -1
  95. package/src/utils.ts +16 -6
  96. package/src/visitors.ts +5 -5
  97. package/tsconfig.tsbuildinfo +1 -1
  98. package/lib/rules/oas3/no-servers-empty-enum.d.ts +0 -2
@@ -13,7 +13,6 @@ const rebillyDocument = utils_1.parseYamlToDocument(fs_1.readFileSync(rebillyDef
13
13
  const config = utils_1.makeConfigForRuleset({
14
14
  test: () => {
15
15
  return {
16
- // @ts-ignore
17
16
  Schema(schema, ctx) {
18
17
  if (schema.type === 'number') {
19
18
  ctx.report({
package/lib/bundle.js CHANGED
@@ -231,9 +231,12 @@ function makeBundleVisitor(version, dereference, skipRedoclyRegistryRefs, rootDo
231
231
  ctx.parent[ctx.key] = resolved.node;
232
232
  }
233
233
  else {
234
+ // TODO: why $ref isn't optional in OasRef?
235
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
234
236
  // @ts-ignore
235
237
  delete ref.$ref;
236
- Object.assign(ref, resolved.node);
238
+ const obj = Object.assign({}, resolved.node, ref);
239
+ Object.assign(ref, obj); // assign ref itself again so ref fields take precedence
237
240
  }
238
241
  }
239
242
  function saveComponent(componentType, target, ctx) {
@@ -259,7 +262,7 @@ function makeBundleVisitor(version, dereference, skipRedoclyRegistryRefs, rootDo
259
262
  const [fileRef, pointer] = [target.location.source.absoluteRef, target.location.pointer];
260
263
  const componentsGroup = components[componentType];
261
264
  let name = '';
262
- const refParts = pointer.slice(2).split('/').filter(Boolean); // slice(2) removes "#/"
265
+ const refParts = pointer.slice(2).split('/').filter(utils_1.isTruthy); // slice(2) removes "#/"
263
266
  while (refParts.length > 0) {
264
267
  name = refParts.pop() + (name ? `-${name}` : '');
265
268
  if (!componentsGroup ||
package/lib/config/all.js CHANGED
@@ -51,7 +51,7 @@ exports.default = {
51
51
  'no-example-value-and-externalValue': 'error',
52
52
  'no-unused-components': 'error',
53
53
  'no-undefined-server-variable': 'error',
54
- 'no-servers-empty-enum': 'error',
54
+ 'no-server-variables-empty-enum': 'error',
55
55
  },
56
56
  oas3_1Rules: {
57
57
  'no-server-example.com': 'error',
@@ -60,6 +60,6 @@ exports.default = {
60
60
  'no-example-value-and-externalValue': 'error',
61
61
  'no-unused-components': 'error',
62
62
  'no-undefined-server-variable': 'error',
63
- 'no-servers-empty-enum': 'error',
63
+ 'no-server-variables-empty-enum': 'error',
64
64
  },
65
65
  };
@@ -22,13 +22,14 @@ var __rest = (this && this.__rest) || function (s, e) {
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
23
  exports.resolvePreset = exports.resolveStyleguideConfig = exports.resolveApis = exports.resolvePlugins = exports.resolveConfig = void 0;
24
24
  const path = require("path");
25
- const colorette_1 = require("colorette");
26
25
  const ref_utils_1 = require("../ref-utils");
27
26
  const resolve_1 = require("../resolve");
28
27
  const builtIn_1 = require("./builtIn");
29
28
  const utils_1 = require("./utils");
29
+ const env_1 = require("../env");
30
30
  const utils_2 = require("../utils");
31
31
  const config_1 = require("./config");
32
+ const logger_1 = require("../logger");
32
33
  function resolveConfig(rawConfig, configPath) {
33
34
  var _a, _b, _c, _d, _e;
34
35
  return __awaiter(this, void 0, void 0, function* () {
@@ -57,25 +58,42 @@ exports.resolveConfig = resolveConfig;
57
58
  function resolvePlugins(plugins, configPath = '') {
58
59
  if (!plugins)
59
60
  return [];
60
- // @ts-ignore
61
- const requireFunc = typeof __webpack_require__ === 'function' ? __non_webpack_require__ : require;
61
+ // TODO: implement or reuse Resolver approach so it will work in node and browser envs
62
+ const requireFunc = (plugin) => {
63
+ if (env_1.isBrowser && utils_2.isString(plugin)) {
64
+ logger_1.logger.error(`Cannot load ${plugin}. Plugins aren't supported in browser yet.`);
65
+ return undefined;
66
+ }
67
+ if (utils_2.isString(plugin)) {
68
+ const absoltePluginPath = path.resolve(path.dirname(configPath), plugin);
69
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
70
+ // @ts-ignore
71
+ return typeof __webpack_require__ === 'function'
72
+ ? // eslint-disable-next-line @typescript-eslint/ban-ts-comment
73
+ // @ts-ignore
74
+ __non_webpack_require__(absoltePluginPath)
75
+ : require(absoltePluginPath);
76
+ }
77
+ return plugin;
78
+ };
62
79
  const seenPluginIds = new Map();
63
80
  return plugins
64
81
  .map((p) => {
65
82
  if (utils_2.isString(p) && ref_utils_1.isAbsoluteUrl(p)) {
66
- throw new Error(colorette_1.red(`We don't support remote plugins yet.`));
83
+ throw new Error(logger_1.colorize.red(`We don't support remote plugins yet.`));
67
84
  }
68
85
  // TODO: resolve npm packages similar to eslint
69
- const pluginModule = utils_2.isString(p)
70
- ? requireFunc(path.resolve(path.dirname(configPath), p))
71
- : p;
86
+ const pluginModule = requireFunc(p);
87
+ if (!pluginModule) {
88
+ return;
89
+ }
72
90
  const id = pluginModule.id;
73
91
  if (typeof id !== 'string') {
74
- throw new Error(colorette_1.red(`Plugin must define \`id\` property in ${colorette_1.blue(p.toString())}.`));
92
+ throw new Error(logger_1.colorize.red(`Plugin must define \`id\` property in ${logger_1.colorize.blue(p.toString())}.`));
75
93
  }
76
94
  if (seenPluginIds.has(id)) {
77
95
  const pluginPath = seenPluginIds.get(id);
78
- throw new Error(colorette_1.red(`Plugin "id" must be unique. Plugin ${colorette_1.blue(p.toString())} uses id "${colorette_1.blue(id)}" already seen in ${colorette_1.blue(pluginPath)}`));
96
+ throw new Error(logger_1.colorize.red(`Plugin "id" must be unique. Plugin ${logger_1.colorize.blue(p.toString())} uses id "${logger_1.colorize.blue(id)}" already seen in ${logger_1.colorize.blue(pluginPath)}`));
79
97
  }
80
98
  seenPluginIds.set(id, p.toString());
81
99
  const plugin = Object.assign(Object.assign({ id }, (pluginModule.configs ? { configs: pluginModule.configs } : {})), (pluginModule.typeExtension ? { typeExtension: pluginModule.typeExtension } : {}));
@@ -124,7 +142,7 @@ function resolveApis({ rawConfig, configPath = '', resolver, }) {
124
142
  var _a, _b;
125
143
  return __awaiter(this, void 0, void 0, function* () {
126
144
  const { apis = {}, styleguide: styleguideConfig = {} } = rawConfig;
127
- let resolvedApis = {};
145
+ const resolvedApis = {};
128
146
  for (const [apiName, apiContent] of Object.entries(apis || {})) {
129
147
  if ((_b = (_a = apiContent.styleguide) === null || _a === void 0 ? void 0 : _a.extends) === null || _b === void 0 ? void 0 : _b.some(utils_2.isNotString)) {
130
148
  throw new Error(`Error configuration format not detected in extends value must contain strings`);
@@ -188,13 +206,13 @@ function resolvePreset(presetName, plugins) {
188
206
  const { pluginId, configName } = utils_1.parsePresetName(presetName);
189
207
  const plugin = plugins.find((p) => p.id === pluginId);
190
208
  if (!plugin) {
191
- throw new Error(`Invalid config ${colorette_1.red(presetName)}: plugin ${pluginId} is not included.`);
209
+ throw new Error(`Invalid config ${logger_1.colorize.red(presetName)}: plugin ${pluginId} is not included.`);
192
210
  }
193
211
  const preset = (_a = plugin.configs) === null || _a === void 0 ? void 0 : _a[configName];
194
212
  if (!preset) {
195
213
  throw new Error(pluginId
196
- ? `Invalid config ${colorette_1.red(presetName)}: plugin ${pluginId} doesn't export config with name ${configName}.`
197
- : `Invalid config ${colorette_1.red(presetName)}: there is no such built-in config.`);
214
+ ? `Invalid config ${logger_1.colorize.red(presetName)}: plugin ${pluginId} doesn't export config with name ${configName}.`
215
+ : `Invalid config ${logger_1.colorize.red(presetName)}: there is no such built-in config.`);
198
216
  }
199
217
  return preset;
200
218
  }
@@ -1,9 +1,7 @@
1
- /// <reference types="node" />
2
1
  import { NormalizedProblem } from '../walk';
3
2
  import { OasVersion, OasMajorVersion, Oas2RuleSet, Oas3RuleSet } from '../oas-types';
4
3
  import type { NodeType } from '../types';
5
4
  import type { DecoratorConfig, Plugin, PreprocessorConfig, Region, ResolveConfig, ResolvedApi, ResolvedConfig, ResolvedStyleguideConfig, RuleConfig } from './types';
6
- export declare const env: NodeJS.ProcessEnv;
7
5
  export declare const IGNORE_FILE = ".redocly.lint-ignore.yaml";
8
6
  export declare const DEFAULT_REGION = "us";
9
7
  export declare const DOMAINS: {
@@ -32,13 +30,13 @@ export declare class StyleguideConfig {
32
30
  addProblemToIgnore(problem: NormalizedProblem): NormalizedProblem;
33
31
  extendTypes(types: Record<string, NodeType>, version: OasVersion): Record<string, NodeType>;
34
32
  getRuleSettings(ruleId: string, oasVersion: OasVersion): {
35
- severity: import("./types").RuleSeverity;
33
+ severity: string;
36
34
  };
37
35
  getPreprocessorSettings(ruleId: string, oasVersion: OasVersion): {
38
- severity: import("./types").RuleSeverity;
36
+ severity: string;
39
37
  };
40
38
  getDecoratorSettings(ruleId: string, oasVersion: OasVersion): {
41
- severity: import("./types").RuleSeverity;
39
+ severity: string;
42
40
  };
43
41
  getUnusedRules(): {
44
42
  rules: string[];
@@ -1,14 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Config = exports.StyleguideConfig = exports.AVAILABLE_REGIONS = exports.DOMAINS = exports.DEFAULT_REGION = exports.IGNORE_FILE = exports.env = void 0;
3
+ exports.Config = exports.StyleguideConfig = exports.AVAILABLE_REGIONS = exports.DOMAINS = exports.DEFAULT_REGION = exports.IGNORE_FILE = void 0;
4
4
  const fs = require("fs");
5
5
  const path = require("path");
6
6
  const js_yaml_1 = require("../js-yaml");
7
7
  const utils_1 = require("../utils");
8
8
  const oas_types_1 = require("../oas-types");
9
+ const env_1 = require("../env");
9
10
  const utils_2 = require("./utils");
10
- // Alias environment here so this file can work in browser environments too.
11
- exports.env = typeof process !== 'undefined' ? process.env || {} : {};
12
11
  exports.IGNORE_FILE = '.redocly.lint-ignore.yaml';
13
12
  const IGNORE_BANNER = `# This file instructs Redocly's linter to ignore the rules contained for specific parts of your API.\n` +
14
13
  `# See https://redoc.ly/docs/cli/ for more information.\n`;
@@ -19,7 +18,7 @@ function getDomains() {
19
18
  eu: 'eu.redocly.com',
20
19
  };
21
20
  // FIXME: temporary fix for our lab environments
22
- const domain = exports.env.REDOCLY_DOMAIN;
21
+ const domain = env_1.env.REDOCLY_DOMAIN;
23
22
  if (domain === null || domain === void 0 ? void 0 : domain.endsWith('.redocly.host')) {
24
23
  domains[domain.split('.')[0]] = domain;
25
24
  }
@@ -125,10 +124,12 @@ class StyleguideConfig {
125
124
  if (!plugin.typeExtension.oas3)
126
125
  continue;
127
126
  extendedTypes = plugin.typeExtension.oas3(extendedTypes, version);
127
+ break;
128
128
  case oas_types_1.OasVersion.Version2:
129
129
  if (!plugin.typeExtension.oas2)
130
130
  continue;
131
131
  extendedTypes = plugin.typeExtension.oas2(extendedTypes, version);
132
+ break;
132
133
  default:
133
134
  throw new Error('Not implemented');
134
135
  }
@@ -193,12 +194,14 @@ class StyleguideConfig {
193
194
  getRulesForOasVersion(version) {
194
195
  switch (version) {
195
196
  case oas_types_1.OasMajorVersion.Version3:
197
+ // eslint-disable-next-line no-case-declarations
196
198
  const oas3Rules = []; // default ruleset
197
199
  this.plugins.forEach((p) => { var _a; return ((_a = p.preprocessors) === null || _a === void 0 ? void 0 : _a.oas3) && oas3Rules.push(p.preprocessors.oas3); });
198
200
  this.plugins.forEach((p) => { var _a; return ((_a = p.rules) === null || _a === void 0 ? void 0 : _a.oas3) && oas3Rules.push(p.rules.oas3); });
199
201
  this.plugins.forEach((p) => { var _a; return ((_a = p.decorators) === null || _a === void 0 ? void 0 : _a.oas3) && oas3Rules.push(p.decorators.oas3); });
200
202
  return oas3Rules;
201
203
  case oas_types_1.OasMajorVersion.Version2:
204
+ // eslint-disable-next-line no-case-declarations
202
205
  const oas2Rules = []; // default ruleset
203
206
  this.plugins.forEach((p) => { var _a; return ((_a = p.preprocessors) === null || _a === void 0 ? void 0 : _a.oas2) && oas2Rules.push(p.preprocessors.oas2); });
204
207
  this.plugins.forEach((p) => { var _a; return ((_a = p.rules) === null || _a === void 0 ? void 0 : _a.oas2) && oas2Rules.push(p.rules.oas2); });
@@ -1,6 +1,13 @@
1
1
  import { Config } from './config';
2
2
  import type { RawConfig } from './types';
3
+ import { RegionalTokenWithValidity } from '../redocly/redocly-client-types';
3
4
  export declare function loadConfig(configPath?: string | undefined, customExtends?: string[], processRawConfig?: (rawConfig: RawConfig) => void | Promise<void>): Promise<Config>;
4
5
  export declare const CONFIG_FILE_NAMES: string[];
5
6
  export declare function findConfig(dir?: string): string | undefined;
6
7
  export declare function getConfig(configPath?: string | undefined): Promise<RawConfig>;
8
+ declare type CreateConfigOptions = {
9
+ extends?: string[];
10
+ tokens?: RegionalTokenWithValidity[];
11
+ };
12
+ export declare function createConfig(config: string | RawConfig, options?: CreateConfigOptions): Promise<Config>;
13
+ export {};
@@ -9,15 +9,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.getConfig = exports.findConfig = exports.CONFIG_FILE_NAMES = exports.loadConfig = void 0;
12
+ exports.createConfig = exports.getConfig = exports.findConfig = exports.CONFIG_FILE_NAMES = exports.loadConfig = void 0;
13
13
  const fs = require("fs");
14
14
  const path = require("path");
15
15
  const redocly_1 = require("../redocly");
16
16
  const utils_1 = require("../utils");
17
+ const js_yaml_1 = require("../js-yaml");
17
18
  const config_1 = require("./config");
18
19
  const utils_2 = require("./utils");
19
20
  const config_resolvers_1 = require("./config-resolvers");
20
- function addConfigMetadata({ rawConfig, customExtends, configPath, }) {
21
+ function addConfigMetadata({ rawConfig, customExtends, configPath, tokens, }) {
21
22
  var _a;
22
23
  return __awaiter(this, void 0, void 0, function* () {
23
24
  if (customExtends !== undefined) {
@@ -28,9 +29,7 @@ function addConfigMetadata({ rawConfig, customExtends, configPath, }) {
28
29
  // TODO: check if we can add recommended here. add message here?
29
30
  // rawConfig.styleguide = { extends: ['recommended'], recommendedFallback: true };
30
31
  }
31
- const redoclyClient = new redocly_1.RedoclyClient();
32
- const tokens = yield redoclyClient.getTokens();
33
- if (tokens.length) {
32
+ if (tokens === null || tokens === void 0 ? void 0 : tokens.length) {
34
33
  if (!rawConfig.resolve)
35
34
  rawConfig.resolve = {};
36
35
  if (!rawConfig.resolve.http)
@@ -66,10 +65,13 @@ function loadConfig(configPath = findConfig(), customExtends, processRawConfig)
66
65
  if (typeof processRawConfig === 'function') {
67
66
  yield processRawConfig(rawConfig);
68
67
  }
69
- return yield addConfigMetadata({
68
+ const redoclyClient = new redocly_1.RedoclyClient();
69
+ const tokens = yield redoclyClient.getTokens();
70
+ return addConfigMetadata({
70
71
  rawConfig,
71
72
  customExtends,
72
73
  configPath,
74
+ tokens,
73
75
  });
74
76
  });
75
77
  }
@@ -103,3 +105,9 @@ function getConfig(configPath = findConfig()) {
103
105
  });
104
106
  }
105
107
  exports.getConfig = getConfig;
108
+ function createConfig(config, options) {
109
+ return __awaiter(this, void 0, void 0, function* () {
110
+ return addConfigMetadata(Object.assign({ rawConfig: utils_2.transformConfig(typeof config === 'string' ? js_yaml_1.parseYaml(config) : config) }, options));
111
+ });
112
+ }
113
+ exports.createConfig = createConfig;
@@ -44,7 +44,7 @@ exports.default = {
44
44
  'no-example-value-and-externalValue': 'warn',
45
45
  'no-unused-components': 'warn',
46
46
  'no-undefined-server-variable': 'warn',
47
- 'no-servers-empty-enum': 'error',
47
+ 'no-server-variables-empty-enum': 'error',
48
48
  },
49
49
  oas3_1Rules: {
50
50
  'no-invalid-media-type-examples': 'warn',
@@ -54,6 +54,6 @@ exports.default = {
54
54
  'no-example-value-and-externalValue': 'warn',
55
55
  'no-unused-components': 'warn',
56
56
  'no-undefined-server-variable': 'warn',
57
- 'no-servers-empty-enum': 'error',
57
+ 'no-server-variables-empty-enum': 'error',
58
58
  },
59
59
  };
@@ -44,7 +44,7 @@ exports.default = {
44
44
  'no-example-value-and-externalValue': 'error',
45
45
  'no-unused-components': 'warn',
46
46
  'no-undefined-server-variable': 'error',
47
- 'no-servers-empty-enum': 'error',
47
+ 'no-server-variables-empty-enum': 'error',
48
48
  },
49
49
  oas3_1Rules: {
50
50
  'no-invalid-media-type-examples': 'warn',
@@ -54,6 +54,6 @@ exports.default = {
54
54
  'no-example-value-and-externalValue': 'error',
55
55
  'no-unused-components': 'warn',
56
56
  'no-undefined-server-variable': 'error',
57
- 'no-servers-empty-enum': 'error',
57
+ 'no-server-variables-empty-enum': 'error',
58
58
  },
59
59
  };
@@ -1,7 +1,7 @@
1
1
  import { RuleSet, OasVersion } from '../oas-types';
2
2
  import { StyleguideConfig } from './config';
3
3
  export declare function initRules<T extends Function, P extends RuleSet<T>>(rules: P[], config: StyleguideConfig, type: 'rules' | 'preprocessors' | 'decorators', oasVersion: OasVersion): {
4
- severity: import("./types").RuleSeverity;
4
+ severity: string;
5
5
  ruleId: string;
6
6
  visitor: any;
7
7
  }[];
@@ -12,9 +12,9 @@ var __rest = (this && this.__rest) || function (s, e) {
12
12
  };
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
14
  exports.getUniquePlugins = exports.getResolveConfig = exports.transformConfig = exports.getMergedConfig = exports.mergeExtends = exports.prefixRules = exports.transformApiDefinitionsToApis = exports.parsePresetName = void 0;
15
- const colorette_1 = require("colorette");
16
15
  const utils_1 = require("../utils");
17
16
  const config_1 = require("./config");
17
+ const logger_1 = require("../logger");
18
18
  function parsePresetName(presetName) {
19
19
  if (presetName.indexOf('/') > -1) {
20
20
  const [pluginId, configName] = presetName.split('/');
@@ -73,7 +73,7 @@ function mergeExtends(rulesConfList) {
73
73
  pluginPaths: [],
74
74
  extendPaths: [],
75
75
  };
76
- for (let rulesConf of rulesConfList) {
76
+ for (const rulesConf of rulesConfList) {
77
77
  if (rulesConf.extends) {
78
78
  throw new Error(`'extends' is not supported in shared configs yet: ${JSON.stringify(rulesConf, null, 2)}.`);
79
79
  }
@@ -112,13 +112,13 @@ function getMergedConfig(config, apiName) {
112
112
  (_b = (_a = config.rawConfig) === null || _a === void 0 ? void 0 : _a.styleguide) === null || _b === void 0 ? void 0 : _b.extendPaths,
113
113
  ]
114
114
  .flat()
115
- .filter(Boolean);
115
+ .filter(utils_1.isTruthy);
116
116
  const pluginPaths = [
117
117
  ...Object.values(config.apis).map((api) => { var _a; return (_a = api === null || api === void 0 ? void 0 : api.styleguide) === null || _a === void 0 ? void 0 : _a.pluginPaths; }),
118
118
  (_d = (_c = config.rawConfig) === null || _c === void 0 ? void 0 : _c.styleguide) === null || _d === void 0 ? void 0 : _d.pluginPaths,
119
119
  ]
120
120
  .flat()
121
- .filter(Boolean);
121
+ .filter(utils_1.isTruthy);
122
122
  return apiName
123
123
  ? new config_1.Config(Object.assign(Object.assign({}, config.rawConfig), { styleguide: Object.assign(Object.assign({}, (config.apis[apiName]
124
124
  ? config.apis[apiName].styleguide
@@ -169,7 +169,7 @@ function getUniquePlugins(plugins) {
169
169
  seen.add(p.id);
170
170
  }
171
171
  else if (p.id) {
172
- process.stderr.write(`Duplicate plugin id "${colorette_1.yellow(p.id)}".\n`);
172
+ logger_1.logger.warn(`Duplicate plugin id "${logger_1.colorize.red(p.id)}".\n`);
173
173
  }
174
174
  }
175
175
  return results;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RegistryDependencies = void 0;
4
4
  const redocly_1 = require("../../redocly");
5
5
  const RegistryDependencies = () => {
6
- let registryDependencies = new Set();
6
+ const registryDependencies = new Set();
7
7
  return {
8
8
  DefinitionRoot: {
9
9
  leave(_, ctx) {
package/lib/env.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ /// <reference types="node" />
2
+ export declare const isBrowser: boolean;
3
+ export declare const env: NodeJS.ProcessEnv;
package/lib/env.js ADDED
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.env = exports.isBrowser = void 0;
4
+ exports.isBrowser =
5
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
6
+ // @ts-ignore
7
+ typeof window !== 'undefined' || typeof self !== 'undefined' || typeof process === 'undefined'; // main and worker thread
8
+ exports.env = exports.isBrowser ? {} : process.env || {};
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getAstNodeByPointer = exports.getLineColLocation = exports.getCodeframe = void 0;
4
- const colorette_1 = require("colorette");
5
4
  const yamlAst = require("yaml-ast-parser");
6
5
  const ref_utils_1 = require("../ref-utils");
6
+ const logger_1 = require("../logger");
7
7
  const MAX_LINE_LENGTH = 150;
8
8
  const MAX_CODEFRAME_LINES = 3;
9
9
  // TODO: temporary
@@ -11,7 +11,7 @@ function parsePointer(pointer) {
11
11
  return pointer.substr(2).split('/').map(ref_utils_1.unescapePointer);
12
12
  }
13
13
  function getCodeframe(location, color) {
14
- colorette_1.options.enabled = color;
14
+ logger_1.colorOptions.enabled = color;
15
15
  const { start, end = { line: start.line, col: start.col + 1 }, source } = location;
16
16
  const lines = source.getLines();
17
17
  const startLineNum = start.line;
@@ -28,16 +28,22 @@ function getCodeframe(location, color) {
28
28
  const line = lines[i - 1] || '';
29
29
  if (line !== '')
30
30
  currentPad = padSize(line);
31
- let startIdx = i === startLineNum ? start.col - 1 : currentPad;
32
- let endIdx = i === endLineNum ? end.col - 1 : line.length;
33
- prefixedLines.push([`${i}`, markLine(line, startIdx, endIdx, colorette_1.red)]);
31
+ const startIdx = i === startLineNum ? start.col - 1 : currentPad;
32
+ const endIdx = i === endLineNum ? end.col - 1 : line.length;
33
+ prefixedLines.push([`${i}`, markLine(line, startIdx, endIdx, logger_1.colorize.red)]);
34
34
  if (!color)
35
35
  prefixedLines.push(['', underlineLine(line, startIdx, endIdx)]);
36
36
  }
37
37
  if (skipLines > 0) {
38
- prefixedLines.push([`…`, `${whitespace(currentPad)}${colorette_1.gray(`< ${skipLines} more lines >`)}`]);
38
+ prefixedLines.push([
39
+ `…`,
40
+ `${whitespace(currentPad)}${logger_1.colorize.gray(`< ${skipLines} more lines >`)}`,
41
+ ]);
39
42
  // print last line
40
- prefixedLines.push([`${endLineNum}`, markLine(lines[endLineNum - 1], -1, end.col - 1, colorette_1.red)]);
43
+ prefixedLines.push([
44
+ `${endLineNum}`,
45
+ markLine(lines[endLineNum - 1], -1, end.col - 1, logger_1.colorize.red),
46
+ ]);
41
47
  if (!color)
42
48
  prefixedLines.push(['', underlineLine(lines[endLineNum - 1], -1, end.col - 1)]);
43
49
  }
@@ -48,7 +54,7 @@ function getCodeframe(location, color) {
48
54
  [`${endLineNum + 1}`, markLine(lines[endLineNum - 1 + 1])],
49
55
  [`${endLineNum + 2}`, markLine(lines[endLineNum - 1 + 2])],
50
56
  ]);
51
- function markLine(line, startIdx = -1, endIdx = +Infinity, variant = colorette_1.gray) {
57
+ function markLine(line, startIdx = -1, endIdx = +Infinity, variant = logger_1.colorize.gray) {
52
58
  if (!color)
53
59
  return line;
54
60
  if (!line)
@@ -66,14 +72,14 @@ function printPrefixedLines(lines) {
66
72
  const padLen = Math.max(...existingLines.map(([prefix]) => prefix.length));
67
73
  const dedentLen = Math.min(...existingLines.map(([_, line]) => (line === '' ? Infinity : padSize(line))));
68
74
  return existingLines
69
- .map(([prefix, line]) => colorette_1.gray(leftPad(padLen, prefix) + ' |') +
75
+ .map(([prefix, line]) => logger_1.colorize.gray(leftPad(padLen, prefix) + ' |') +
70
76
  (line ? ' ' + limitLineLength(line.substring(dedentLen)) : ''))
71
77
  .join('\n');
72
78
  }
73
79
  function limitLineLength(line, maxLen = MAX_LINE_LENGTH) {
74
80
  const overflowLen = line.length - maxLen;
75
81
  if (overflowLen > 0) {
76
- const charsMoreText = colorette_1.gray(`...<${overflowLen} chars>`);
82
+ const charsMoreText = logger_1.colorize.gray(`...<${overflowLen} chars>`);
77
83
  return line.substring(0, maxLen - charsMoreText.length) + charsMoreText;
78
84
  }
79
85
  else {