Skip to content

Commit

Permalink
[code-infra] Make Babel config path configurable in API docs builder (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
michaldudak committed Apr 23, 2024
1 parent 6365c52 commit ab7b2f1
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions packages/api-docs-builder/utils/parseTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ import * as babel from '@babel/core';
import { readFile } from 'fs-extra';
import glob from 'fast-glob';

const workspaceRoot = path.join(__dirname, '../../../');
const babelConfigPath = path.join(workspaceRoot, 'babel.config.js');

function getTestFilesNames(filepath: string) {
return glob.sync(
path
Expand All @@ -18,15 +15,14 @@ function getTestFilesNames(filepath: string) {
);
}

async function parseWithConfig(filename: string, configFilePath: string) {
async function parseWithConfig(filename: string) {
const source = await readFile(filename, { encoding: 'utf8' });
const partialConfig = babel.loadPartialConfig({
configFile: configFilePath,
filename,
});

if (partialConfig === null) {
throw new Error(`Could not load a babel config for ${filename} located at ${configFilePath}.`);
throw new Error(`Could not load a babel config for ${filename}.`);
}

return babel.parseAsync(source, partialConfig.options);
Expand Down Expand Up @@ -139,15 +135,19 @@ export default async function parseTest(componentFilename: string): Promise<Pars

let descriptor: ReturnType<typeof findConformanceDescriptor> = null;

// eslint-disable-next-line no-restricted-syntax
for await (const testFilename of testFilenames) {
if (descriptor === null) {
const babelParseResult = await parseWithConfig(testFilename, babelConfigPath);
if (babelParseResult === null) {
throw new Error(`Could not parse ${testFilename}.`);
try {
// eslint-disable-next-line no-restricted-syntax
for await (const testFilename of testFilenames) {
if (descriptor === null) {
const babelParseResult = await parseWithConfig(testFilename);
if (babelParseResult === null) {
throw new Error(`Could not parse ${testFilename}.`);
}
descriptor = findConformanceDescriptor(babelParseResult);
}
descriptor = findConformanceDescriptor(babelParseResult);
}
} catch (error) {
console.error(error);
}

const result: ParseResult = {
Expand Down

0 comments on commit ab7b2f1

Please sign in to comment.