Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/popular-tomatoes-draw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@redocly/openapi-core": patch
---

Improved browser compatibility for `loadConfig`.
7 changes: 2 additions & 5 deletions packages/core/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as fs from 'node:fs';
import * as path from 'node:path';
import { minimatch } from 'minimatch';
import pluralizeOne from 'pluralize';
import { parseYaml } from './js-yaml/index.js';
Expand Down Expand Up @@ -212,10 +211,8 @@ export function isCustomRuleId(id: string) {
}

export function doesYamlFileExist(filePath: string): boolean {
return (
(path.extname(filePath) === '.yaml' || path.extname(filePath) === '.yml') &&
!!fs?.existsSync?.(filePath)
);
const ext = filePath.substr(filePath.lastIndexOf('.'));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The substr is deprecated already. Also, this doesn't handle the case when a file is named file or .env. It would be better to create a utility function and write a couple of tests for it.

return (ext === '.yaml' || ext === '.yml') && !!fs?.existsSync?.(filePath);
}

export type Falsy = undefined | null | false | '' | 0;
Expand Down
Loading