-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(mdx-loader): refactor mdx-loader, expose loader creation uti…
…ls (#10450)
- Loading branch information
Showing
13 changed files
with
493 additions
and
412 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* 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 {createProcessors} from './processor'; | ||
import type {Options} from './loader'; | ||
import type {RuleSetRule, RuleSetUseItem} from 'webpack'; | ||
|
||
async function enhancedOptions(options: Options): Promise<Options> { | ||
// Because Jest doesn't like ESM / createProcessors() | ||
if (process.env.N0DE_ENV === 'test' || process.env.JEST_WORKER_ID) { | ||
return options; | ||
} | ||
|
||
// We create the processor earlier here, to avoid the lazy processor creating | ||
// Lazy creation messes-up with Rsdoctor ability to measure mdx-loader perf | ||
const newOptions: Options = options.processors | ||
? options | ||
: {...options, processors: await createProcessors({options})}; | ||
|
||
return newOptions; | ||
} | ||
|
||
export async function createMDXLoaderItem( | ||
options: Options, | ||
): Promise<RuleSetUseItem> { | ||
return { | ||
loader: require.resolve('@docusaurus/mdx-loader'), | ||
options: await enhancedOptions(options), | ||
}; | ||
} | ||
|
||
export async function createMDXLoaderRule({ | ||
include, | ||
options, | ||
}: { | ||
include: RuleSetRule['include']; | ||
options: Options; | ||
}): Promise<RuleSetRule> { | ||
return { | ||
test: /\.mdx?$/i, | ||
include, | ||
use: [await createMDXLoaderItem(options)], | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.