Skip to content

Commit

Permalink
chore: add checks for browser env
Browse files Browse the repository at this point in the history
  • Loading branch information
tatomyr committed May 22, 2024
1 parent dbbbad8 commit 8a36531
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
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
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
3 changes: 2 additions & 1 deletion packages/core/src/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { YAMLNode, LoadOptions } from 'yaml-ast-parser';
import { NormalizedNodeType, isNamedType, SpecExtension } from './types';
import { readFileFromUrl, parseYaml, nextTick } from './utils';
import { ResolveConfig } from './config/types';
import { isBrowser } from './env';

export type CollectedRefs = Map<string /* absoluteFilePath */, Document>;

Expand Down Expand Up @@ -106,7 +107,7 @@ export class BaseResolver {
return new URL(ref, base).href;
}

return path.resolve(base ? path.dirname(base) : process.cwd(), ref);
return path.resolve(base ? path.dirname(base) : isBrowser ? '' : process.cwd(), ref);
}

async loadExternalRef(absoluteRef: string): Promise<Source> {
Expand Down

0 comments on commit 8a36531

Please sign in to comment.