docusaurus/packages/docusaurus-babel/src/utils.ts
Sébastien Lorber 9ecff801ff
Some checks are pending
Argos CI / take-screenshots (push) Waiting to run
Build Hash Router / Build Hash Router (push) Waiting to run
Canary Release / Publish Canary (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
Continuous Releases / Continuous Releases (push) Waiting to run
E2E Tests / E2E — Yarn v1 (18.0) (push) Waiting to run
E2E Tests / E2E — Yarn v1 (20) (push) Waiting to run
E2E Tests / E2E — Yarn v1 (22) (push) Waiting to run
E2E Tests / E2E — Yarn Berry (node-modules, -s) (push) Waiting to run
E2E Tests / E2E — Yarn Berry (node-modules, -st) (push) Waiting to run
E2E Tests / E2E — Yarn Berry (pnp, -s) (push) Waiting to run
E2E Tests / E2E — Yarn Berry (pnp, -st) (push) Waiting to run
E2E Tests / E2E — npm (push) Waiting to run
E2E Tests / E2E — pnpm (push) Waiting to run
refactor: create `@docusaurus/bundler` and `@docusaurus/babel` packages (#10511)
2024-09-21 16:35:49 +02:00

51 lines
1.3 KiB
TypeScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import fs from 'fs-extra';
import path from 'path';
import {BABEL_CONFIG_FILE_NAME} from '@docusaurus/utils';
import type {TransformOptions} from '@babel/core';
export async function getCustomBabelConfigFilePath(
siteDir: string,
): Promise<string | undefined> {
const customBabelConfigurationPath = path.join(
siteDir,
BABEL_CONFIG_FILE_NAME,
);
return (await fs.pathExists(customBabelConfigurationPath))
? customBabelConfigurationPath
: undefined;
}
export function getBabelOptions({
isServer,
babelOptions,
}: {
isServer?: boolean;
// TODO Docusaurus v4 fix this
// weird to have getBabelOptions take a babelOptions param
babelOptions?: TransformOptions | string;
} = {}): TransformOptions {
const caller = {name: isServer ? 'server' : 'client'};
if (typeof babelOptions === 'string') {
return {
babelrc: false,
configFile: babelOptions,
caller,
};
}
return {
...(babelOptions ?? {
presets: [require.resolve('@docusaurus/babel/preset')],
}),
babelrc: false,
configFile: false,
caller,
};
}