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

[code-infra] Make Babel config path configurable in API docs builder #41999

Merged
merged 5 commits into from
Apr 23, 2024
Merged
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
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
Loading