Skip to content

Commit ab7b2f1

Browse files
authored
[code-infra] Make Babel config path configurable in API docs builder (#41999)
1 parent 6365c52 commit ab7b2f1

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

packages/api-docs-builder/utils/parseTest.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ import * as babel from '@babel/core';
33
import { readFile } from 'fs-extra';
44
import glob from 'fast-glob';
55

6-
const workspaceRoot = path.join(__dirname, '../../../');
7-
const babelConfigPath = path.join(workspaceRoot, 'babel.config.js');
8-
96
function getTestFilesNames(filepath: string) {
107
return glob.sync(
118
path
@@ -18,15 +15,14 @@ function getTestFilesNames(filepath: string) {
1815
);
1916
}
2017

21-
async function parseWithConfig(filename: string, configFilePath: string) {
18+
async function parseWithConfig(filename: string) {
2219
const source = await readFile(filename, { encoding: 'utf8' });
2320
const partialConfig = babel.loadPartialConfig({
24-
configFile: configFilePath,
2521
filename,
2622
});
2723

2824
if (partialConfig === null) {
29-
throw new Error(`Could not load a babel config for ${filename} located at ${configFilePath}.`);
25+
throw new Error(`Could not load a babel config for ${filename}.`);
3026
}
3127

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

140136
let descriptor: ReturnType<typeof findConformanceDescriptor> = null;
141137

142-
// eslint-disable-next-line no-restricted-syntax
143-
for await (const testFilename of testFilenames) {
144-
if (descriptor === null) {
145-
const babelParseResult = await parseWithConfig(testFilename, babelConfigPath);
146-
if (babelParseResult === null) {
147-
throw new Error(`Could not parse ${testFilename}.`);
138+
try {
139+
// eslint-disable-next-line no-restricted-syntax
140+
for await (const testFilename of testFilenames) {
141+
if (descriptor === null) {
142+
const babelParseResult = await parseWithConfig(testFilename);
143+
if (babelParseResult === null) {
144+
throw new Error(`Could not parse ${testFilename}.`);
145+
}
146+
descriptor = findConformanceDescriptor(babelParseResult);
148147
}
149-
descriptor = findConformanceDescriptor(babelParseResult);
150148
}
149+
} catch (error) {
150+
console.error(error);
151151
}
152152

153153
const result: ParseResult = {

0 commit comments

Comments
 (0)