Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add checks for browser env #1565

Merged
merged 2 commits into from
May 23, 2024
Merged
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
12 changes: 4 additions & 8 deletions packages/core/src/config/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ConfigValidationError, transformConfig } from './utils';
import { resolveConfig, resolveConfigFileAndRefs } from './config-resolvers';
import { bundleConfig } from '../bundle';
import { BaseResolver } from '../resolve';
import { isBrowser } from '../env';

import type { Document } from '../resolve';
import type { RegionalToken, RegionalTokenWithValidity } from '../redocly/redocly-client-types';
Expand Down Expand Up @@ -103,7 +104,7 @@ export async function loadConfig(
} = options;
const rawConfig = await getConfig({ configPath, processRawConfig, externalRefResolver });

const redoclyClient = isEmptyObject(fs) ? undefined : new RedoclyClient();
const redoclyClient = isBrowser ? undefined : new RedoclyClient();
const tokens = redoclyClient && redoclyClient.hasTokens() ? redoclyClient.getAllTokens() : [];

return addConfigMetadata({
Expand Down Expand Up @@ -146,13 +147,8 @@ export async function getConfig(
processRawConfig,
externalRefResolver = new BaseResolver(),
} = options;
try {
if (!configPath || !(await externalRefResolver.resolveDocument(null, configPath))) {
return {};
}
} catch (e) {
return {};
}
if (!configPath) return {};

try {
const { document, resolvedRefMap } = await resolveConfigFileAndRefs({
configPath,
Expand Down
2 changes: 0 additions & 2 deletions packages/core/src/env.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
export const isBrowser =
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
typeof window !== 'undefined' ||
typeof process === 'undefined' ||
(process?.platform as any) === 'browser'; // main and worker thread
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/format/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const coreVersion = require('../../package.json').version;

import { NormalizedProblem, ProblemSeverity, LineColLocationObject, LocationObject } from '../walk';
import { getCodeframe, getLineColLocation } from './codeframes';
import { env } from '../env';
import { env, isBrowser } from '../env';
import { isAbsoluteUrl } from '../ref-utils';

export type Totals = {
Expand Down Expand Up @@ -89,7 +89,7 @@ export function formatProblems(
) {
const {
maxProblems = 100,
cwd = process.cwd(),
cwd = isBrowser ? '' : process.cwd(),
format = 'codeframe',
color = colorOptions.enabled,
totals = getTotals(problems),
Expand Down
Loading