Skip to content

Commit 29de9d8

Browse files
committed
Let Babel find the config file
1 parent 54c4b2b commit 29de9d8

File tree

3 files changed

+5
-13
lines changed

3 files changed

+5
-13
lines changed

packages/api-docs-builder-core/baseUi/projectSettings.ts

-1
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,4 @@ export const projectSettings: ProjectSettings = {
4343
translationPagesDirectory: 'docs/translations/api-docs-base',
4444
generateClassName: generateUtilityClass,
4545
isGlobalClassName: isGlobalState,
46-
babelConfigPath: path.join(process.cwd(), 'babel.config.js'),
4746
};

packages/api-docs-builder/ApiBuilders/ComponentApiBuilder.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ export default async function generateComponentApi(
763763
}
764764

765765
try {
766-
const testInfo = await parseTest(reactApi.filename, projectSettings.babelConfigPath);
766+
const testInfo = await parseTest(reactApi.filename);
767767
// no Object.assign to visually check for collisions
768768
reactApi.forwardsRefTo = testInfo.forwardsRefTo;
769769
reactApi.spread = testInfo.spread ?? spread;

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

+4-11
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 defaultBabelConfigPath = 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);
@@ -128,10 +124,7 @@ export interface ParseResult {
128124
themeDefaultProps: boolean | undefined | null;
129125
}
130126

131-
export default async function parseTest(
132-
componentFilename: string,
133-
babelConfigPath: string = defaultBabelConfigPath,
134-
): Promise<ParseResult> {
127+
export default async function parseTest(componentFilename: string): Promise<ParseResult> {
135128
const testFilenames = getTestFilesNames(componentFilename);
136129

137130
if (testFilenames.length === 0) {
@@ -146,7 +139,7 @@ export default async function parseTest(
146139
// eslint-disable-next-line no-restricted-syntax
147140
for await (const testFilename of testFilenames) {
148141
if (descriptor === null) {
149-
const babelParseResult = await parseWithConfig(testFilename, babelConfigPath);
142+
const babelParseResult = await parseWithConfig(testFilename);
150143
if (babelParseResult === null) {
151144
throw new Error(`Could not parse ${testFilename}.`);
152145
}

0 commit comments

Comments
 (0)