@docusaurus/mdx-loader 0.0.0-6068 → 0.0.0-6069

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,11 +4,15 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import type { Options } from './loader';
7
+ import type { Options } from './options';
8
8
  import type { RuleSetRule, RuleSetUseItem } from 'webpack';
9
- export declare function createMDXLoaderItem(options: Options): Promise<RuleSetUseItem>;
9
+ type CreateOptions = {
10
+ useCrossCompilerCache?: boolean;
11
+ };
12
+ export declare function createMDXLoaderItem(options: Options & CreateOptions): Promise<RuleSetUseItem>;
10
13
  export declare function createMDXLoaderRule({ include, options, }: {
11
14
  include: RuleSetRule['include'];
12
- options: Options;
15
+ options: Options & CreateOptions;
13
16
  }): Promise<RuleSetRule>;
17
+ export {};
14
18
  //# sourceMappingURL=createMDXLoader.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createMDXLoader.d.ts","sourceRoot":"","sources":["../src/createMDXLoader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,UAAU,CAAC;AACtC,OAAO,KAAK,EAAC,WAAW,EAAE,cAAc,EAAC,MAAM,SAAS,CAAC;AAiBzD,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,cAAc,CAAC,CAKzB;AAED,wBAAsB,mBAAmB,CAAC,EACxC,OAAO,EACP,OAAO,GACR,EAAE;IACD,OAAO,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;IAChC,OAAO,EAAE,OAAO,CAAC;CAClB,GAAG,OAAO,CAAC,WAAW,CAAC,CAMvB"}
1
+ {"version":3,"file":"createMDXLoader.d.ts","sourceRoot":"","sources":["../src/createMDXLoader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AACvC,OAAO,KAAK,EAAC,WAAW,EAAE,cAAc,EAAC,MAAM,SAAS,CAAC;AAEzD,KAAK,aAAa,GAAG;IACnB,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC,CAAC;AAgCF,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,OAAO,GAAG,aAAa,GAC/B,OAAO,CAAC,cAAc,CAAC,CAKzB;AAED,wBAAsB,mBAAmB,CAAC,EACxC,OAAO,EACP,OAAO,GACR,EAAE;IACD,OAAO,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;IAChC,OAAO,EAAE,OAAO,GAAG,aAAa,CAAC;CAClC,GAAG,OAAO,CAAC,WAAW,CAAC,CAMvB"}
@@ -9,22 +9,33 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.createMDXLoaderItem = createMDXLoaderItem;
10
10
  exports.createMDXLoaderRule = createMDXLoaderRule;
11
11
  const processor_1 = require("./processor");
12
- async function enhancedOptions(options) {
12
+ async function normalizeOptions(optionsInput) {
13
13
  // Because Jest doesn't like ESM / createProcessors()
14
14
  if (process.env.N0DE_ENV === 'test' || process.env.JEST_WORKER_ID) {
15
- return options;
15
+ return optionsInput;
16
16
  }
17
+ let options = optionsInput;
17
18
  // We create the processor earlier here, to avoid the lazy processor creating
18
19
  // Lazy creation messes-up with Rsdoctor ability to measure mdx-loader perf
19
- const newOptions = options.processors
20
- ? options
21
- : { ...options, processors: await (0, processor_1.createProcessors)({ options }) };
22
- return newOptions;
20
+ if (!options.processors) {
21
+ options = { ...options, processors: await (0, processor_1.createProcessors)({ options }) };
22
+ }
23
+ // Cross-compiler cache permits to compile client/server MDX only once
24
+ // We don't want to cache in dev mode (docusaurus start)
25
+ // We only have multiple compilers in production mode (docusaurus build)
26
+ // TODO wrong but good enough for now (example: "docusaurus build --dev")
27
+ if (options.useCrossCompilerCache && process.env.NODE_ENV === 'production') {
28
+ options = {
29
+ ...options,
30
+ crossCompilerCache: new Map(),
31
+ };
32
+ }
33
+ return options;
23
34
  }
24
35
  async function createMDXLoaderItem(options) {
25
36
  return {
26
37
  loader: require.resolve('@docusaurus/mdx-loader'),
27
- options: await enhancedOptions(options),
38
+ options: await normalizeOptions(options),
28
39
  };
29
40
  }
30
41
  async function createMDXLoaderRule({ include, options, }) {
@@ -1 +1 @@
1
- {"version":3,"file":"createMDXLoader.js","sourceRoot":"","sources":["../src/createMDXLoader.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAqBH,kDAOC;AAED,kDAYC;AAxCD,2CAA6C;AAI7C,KAAK,UAAU,eAAe,CAAC,OAAgB;IAC7C,qDAAqD;IACrD,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,CAAC;QAClE,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,6EAA6E;IAC7E,2EAA2E;IAC3E,MAAM,UAAU,GAAY,OAAO,CAAC,UAAU;QAC5C,CAAC,CAAC,OAAO;QACT,CAAC,CAAC,EAAC,GAAG,OAAO,EAAE,UAAU,EAAE,MAAM,IAAA,4BAAgB,EAAC,EAAC,OAAO,EAAC,CAAC,EAAC,CAAC;IAEhE,OAAO,UAAU,CAAC;AACpB,CAAC;AAEM,KAAK,UAAU,mBAAmB,CACvC,OAAgB;IAEhB,OAAO;QACL,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,wBAAwB,CAAC;QACjD,OAAO,EAAE,MAAM,eAAe,CAAC,OAAO,CAAC;KACxC,CAAC;AACJ,CAAC;AAEM,KAAK,UAAU,mBAAmB,CAAC,EACxC,OAAO,EACP,OAAO,GAIR;IACC,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,OAAO;QACP,GAAG,EAAE,CAAC,MAAM,mBAAmB,CAAC,OAAO,CAAC,CAAC;KAC1C,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"createMDXLoader.js","sourceRoot":"","sources":["../src/createMDXLoader.ts"],"names":[],"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, Metadata, Assets = undefined> = {
28
28
  readonly assets: Assets;
29
29
  (): JSX.Element;
30
30
  };
31
- export type { Options, MDXPlugin } from './loader';
31
+ export type { MDXPlugin } from './loader';
32
32
  export type { MDXOptions } from './processor';
33
+ export type { Options } from './options';
33
34
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,SAAS,EAAC,MAAM,UAAU,CAAC;AAEnC,OAAO,KAAK,EAAC,OAAO,IAAI,eAAe,EAAC,MAAM,oBAAoB,CAAC;AAEnE,OAAO,EAAC,mBAAmB,EAAE,mBAAmB,EAAC,MAAM,mBAAmB,CAAC;AAE3E,eAAe,SAAS,CAAC;AAEzB,MAAM,MAAM,OAAO,GAAG,eAAe,CAAC;AAEtC,MAAM,MAAM,MAAM,GAAG,IAAI,GAAG,KAAK,CAAC;AAElC,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,QAAQ,CAAC;AAE5C,MAAM,MAAM,gBAAgB,CAAC,WAAW,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,IAAI;IACxE,gDAAgD;IAChD,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;IAClC,yCAAyC;IACzC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,sCAAsC;IACtC,QAAQ,CAAC,GAAG,EAAE,SAAS,OAAO,EAAE,CAAC;IACjC,yCAAyC;IACzC,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1C;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,IAAI,GAAG,CAAC,OAAO,CAAC;CACjB,CAAC;AAEF,YAAY,EAAC,OAAO,EAAE,SAAS,EAAC,MAAM,UAAU,CAAC;AACjD,YAAY,EAAC,UAAU,EAAC,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,SAAS,EAAC,MAAM,UAAU,CAAC;AAEnC,OAAO,KAAK,EAAC,OAAO,IAAI,eAAe,EAAC,MAAM,oBAAoB,CAAC;AAEnE,OAAO,EAAC,mBAAmB,EAAE,mBAAmB,EAAC,MAAM,mBAAmB,CAAC;AAE3E,eAAe,SAAS,CAAC;AAEzB,MAAM,MAAM,OAAO,GAAG,eAAe,CAAC;AAEtC,MAAM,MAAM,MAAM,GAAG,IAAI,GAAG,KAAK,CAAC;AAElC,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,QAAQ,CAAC;AAE5C,MAAM,MAAM,gBAAgB,CAAC,WAAW,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,IAAI;IACxE,gDAAgD;IAChD,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;IAClC,yCAAyC;IACzC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,sCAAsC;IACtC,QAAQ,CAAC,GAAG,EAAE,SAAS,OAAO,EAAE,CAAC;IACjC,yCAAyC;IACzC,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1C;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,IAAI,GAAG,CAAC,OAAO,CAAC;CACjB,CAAC;AAEF,YAAY,EAAC,SAAS,EAAC,MAAM,UAAU,CAAC;AACxC,YAAY,EAAC,UAAU,EAAC,MAAM,aAAa,CAAC;AAC5C,YAAY,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC"}
package/lib/loader.d.ts CHANGED
@@ -4,31 +4,10 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import type { SimpleProcessors, MDXOptions } from './processor';
8
- import type { ResolveMarkdownLink } from './remark/resolveMarkdownLinks';
9
- import type { MarkdownConfig } from '@docusaurus/types';
7
+ import type { Options } from './options';
10
8
  import type { LoaderContext } from 'webpack';
11
9
  type Pluggable = any;
12
10
  export type MDXPlugin = Pluggable;
13
- export type Options = Partial<MDXOptions> & {
14
- markdownConfig: MarkdownConfig;
15
- staticDirs: string[];
16
- siteDir: string;
17
- isMDXPartial?: (filePath: string) => boolean;
18
- isMDXPartialFrontMatterWarningDisabled?: boolean;
19
- removeContentTitle?: boolean;
20
- metadataPath?: (filePath: string) => string;
21
- createAssets?: (metadata: {
22
- filePath: string;
23
- frontMatter: {
24
- [key: string]: unknown;
25
- };
26
- }) => {
27
- [key: string]: unknown;
28
- };
29
- resolveMarkdownLink?: ResolveMarkdownLink;
30
- processors?: SimpleProcessors;
31
- };
32
11
  export declare function mdxLoader(this: LoaderContext<Options>, fileContent: string): Promise<void>;
33
12
  export {};
34
13
  //# sourceMappingURL=loader.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAeH,OAAO,KAAK,EACV,gBAAgB,EAChB,UAAU,EAEX,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAC,mBAAmB,EAAC,MAAM,+BAA+B,CAAC;AAEvE,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,SAAS,CAAC;AAK3C,KAAK,SAAS,GAAG,GAAG,CAAC;AAErB,MAAM,MAAM,SAAS,GAAG,SAAS,CAAC;AAElC,MAAM,MAAM,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,GAAG;IAC1C,cAAc,EAAE,cAAc,CAAC;IAC/B,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;IAC7C,sCAAsC,CAAC,EAAE,OAAO,CAAC;IACjD,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,YAAY,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAC;IAC5C,YAAY,CAAC,EAAE,CAAC,QAAQ,EAAE;QACxB,QAAQ,EAAE,MAAM,CAAC;QACjB,WAAW,EAAE;YAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;SAAC,CAAC;KACvC,KAAK;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAC,CAAC;IAC/B,mBAAmB,CAAC,EAAE,mBAAmB,CAAC;IAG1C,UAAU,CAAC,EAAE,gBAAgB,CAAC;CAC/B,CAAC;AAEF,wBAAsB,SAAS,CAC7B,IAAI,EAAE,aAAa,CAAC,OAAO,CAAC,EAC5B,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,IAAI,CAAC,CA2Ff"}
1
+ {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAgBH,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AACvC,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,SAAS,CAAC;AAK3C,KAAK,SAAS,GAAG,GAAG,CAAC;AAErB,MAAM,MAAM,SAAS,GAAG,SAAS,CAAC;AAyIlC,wBAAsB,SAAS,CAC7B,IAAI,EAAE,aAAa,CAAC,OAAO,CAAC,EAC5B,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,IAAI,CAAC,CAgBf"}
package/lib/loader.js CHANGED
@@ -12,30 +12,20 @@ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
12
12
  const utils_1 = require("@docusaurus/utils");
13
13
  const stringify_object_1 = tslib_1.__importDefault(require("stringify-object"));
14
14
  const utils_2 = require("./utils");
15
- async function mdxLoader(fileContent) {
16
- const compilerName = (0, utils_1.getWebpackLoaderCompilerName)(this);
17
- const callback = this.async();
18
- const filePath = this.resourcePath;
19
- const options = this.getOptions();
15
+ async function loadMDX({ fileContent, filePath, options, compilerName, }) {
20
16
  const { frontMatter } = await options.markdownConfig.parseFrontMatter({
21
17
  filePath,
22
18
  fileContent,
23
19
  defaultParseFrontMatter: utils_1.DEFAULT_PARSE_FRONT_MATTER,
24
20
  });
25
21
  const hasFrontMatter = Object.keys(frontMatter).length > 0;
26
- let result;
27
- try {
28
- result = await (0, utils_2.compileToJSX)({
29
- fileContent,
30
- filePath,
31
- frontMatter,
32
- options,
33
- compilerName,
34
- });
35
- }
36
- catch (error) {
37
- return callback(error);
38
- }
22
+ const result = await (0, utils_2.compileToJSX)({
23
+ fileContent,
24
+ filePath,
25
+ frontMatter,
26
+ options,
27
+ compilerName,
28
+ });
39
29
  const contentTitle = (0, utils_2.extractContentTitleData)(result.data);
40
30
  // MDX partials are MDX files starting with _ or in a folder starting with _
41
31
  // Partial are not expected to have associated metadata files or front matter
@@ -48,7 +38,7 @@ ${JSON.stringify(frontMatter, null, 2)}`;
48
38
  if (!options.isMDXPartialFrontMatterWarningDisabled) {
49
39
  const shouldError = process.env.NODE_ENV === 'test' || process.env.CI;
50
40
  if (shouldError) {
51
- return callback(new Error(errorMessage));
41
+ throw new Error(errorMessage);
52
42
  }
53
43
  logger_1.default.warn(errorMessage);
54
44
  }
@@ -82,6 +72,52 @@ ${assets
82
72
  ${exportsCode}
83
73
  ${result.content}
84
74
  `;
85
- return callback(null, code);
75
+ return code;
76
+ }
77
+ // Note: we cache promises instead of strings
78
+ // This is because client/server compilations might be triggered in parallel
79
+ // When this happens for the same file, we don't want to compile it twice
80
+ async function loadMDXWithCaching({ resource, fileContent, filePath, options, compilerName, }) {
81
+ // Note we "resource" as cache key, not "filePath" nor "fileContent"
82
+ // This is because:
83
+ // - the same file can be compiled in different variants (blog.mdx?truncated)
84
+ // - the same content can be processed differently (versioned docs links)
85
+ const cacheKey = resource;
86
+ const cachedPromise = options.crossCompilerCache?.get(cacheKey);
87
+ if (cachedPromise) {
88
+ // We can clean up the cache and free memory here
89
+ // We know there are only 2 compilations for the same file
90
+ // Note: once we introduce RSCs we'll probably have 3 compilations
91
+ // Note: we can't use string keys in WeakMap
92
+ // But we could eventually use WeakRef for the values
93
+ options.crossCompilerCache?.delete(cacheKey);
94
+ return cachedPromise;
95
+ }
96
+ const promise = loadMDX({
97
+ fileContent,
98
+ filePath,
99
+ options,
100
+ compilerName,
101
+ });
102
+ options.crossCompilerCache?.set(cacheKey, promise);
103
+ return promise;
104
+ }
105
+ async function mdxLoader(fileContent) {
106
+ const compilerName = (0, utils_1.getWebpackLoaderCompilerName)(this);
107
+ const callback = this.async();
108
+ const options = this.getOptions();
109
+ try {
110
+ const result = await loadMDXWithCaching({
111
+ resource: this.resource,
112
+ filePath: this.resourcePath,
113
+ fileContent,
114
+ options,
115
+ compilerName,
116
+ });
117
+ return callback(null, result);
118
+ }
119
+ catch (error) {
120
+ return callback(error);
121
+ }
86
122
  }
87
123
  //# sourceMappingURL=loader.js.map
package/lib/loader.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAkDH,8BA8FC;;AA9ID,wEAAwC;AACxC,6CAK2B;AAC3B,gFAA+C;AAC/C,mCAIiB;AAoCV,KAAK,UAAU,SAAS,CAE7B,WAAmB;IAEnB,MAAM,YAAY,GAAG,IAAA,oCAA4B,EAAC,IAAI,CAAC,CAAC;IACxD,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;IAC9B,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC;IACnC,MAAM,OAAO,GAAY,IAAI,CAAC,UAAU,EAAE,CAAC;IAE3C,MAAM,EAAC,WAAW,EAAC,GAAG,MAAM,OAAO,CAAC,cAAc,CAAC,gBAAgB,CAAC;QAClE,QAAQ;QACR,WAAW;QACX,uBAAuB,EAAE,kCAA0B;KACpD,CAAC,CAAC;IAEH,MAAM,cAAc,GA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BAAkB,EAAE,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACnD,OAAO,OAAO,CAAC;AACjB,CAAC;AAEM,KAAK,UAAU,SAAS,CAE7B,WAAmB;IAEnB,MAAM,YAAY,GAAG,IAAA,oCAA4B,EAAC,IAAI,CAAC,CAAC;IACxD,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;IAC9B,MAAM,OAAO,GAAY,IAAI,CAAC,UAAU,EAAE,CAAC;IAC3C,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,kBAAkB,CAAC;YACtC,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,QAAQ,EAAE,IAAI,CAAC,YAAY;YAC3B,WAAW;YACX,OAAO;YACP,YAAY;SACb,CAAC,CAAC;QACH,OAAO,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAChC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,QAAQ,CAAC,KAAc,CAAC,CAAC;IAClC,CAAC;AACH,CAAC"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import type { MDXOptions, SimpleProcessors } from './processor';
8
+ import type { MarkdownConfig } from '@docusaurus/types';
9
+ import type { ResolveMarkdownLink } from './remark/resolveMarkdownLinks';
10
+ export type Options = Partial<MDXOptions> & {
11
+ markdownConfig: MarkdownConfig;
12
+ staticDirs: string[];
13
+ siteDir: string;
14
+ isMDXPartial?: (filePath: string) => boolean;
15
+ isMDXPartialFrontMatterWarningDisabled?: boolean;
16
+ removeContentTitle?: boolean;
17
+ metadataPath?: (filePath: string) => string;
18
+ createAssets?: (metadata: {
19
+ filePath: string;
20
+ frontMatter: {
21
+ [key: string]: unknown;
22
+ };
23
+ }) => {
24
+ [key: string]: unknown;
25
+ };
26
+ resolveMarkdownLink?: ResolveMarkdownLink;
27
+ processors?: SimpleProcessors;
28
+ crossCompilerCache?: Map<string, Promise<string>>;
29
+ };
30
+ //# sourceMappingURL=options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAC,UAAU,EAAE,gBAAgB,EAAC,MAAM,aAAa,CAAC;AAC9D,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAC,mBAAmB,EAAC,MAAM,+BAA+B,CAAC;AAEvE,MAAM,MAAM,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,GAAG;IAC1C,cAAc,EAAE,cAAc,CAAC;IAC/B,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;IAC7C,sCAAsC,CAAC,EAAE,OAAO,CAAC;IACjD,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,YAAY,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAC;IAC5C,YAAY,CAAC,EAAE,CAAC,QAAQ,EAAE;QACxB,QAAQ,EAAE,MAAM,CAAC;QACjB,WAAW,EAAE;YAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;SAAC,CAAC;KACvC,KAAK;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAC,CAAC;IAC/B,mBAAmB,CAAC,EAAE,mBAAmB,CAAC;IAG1C,UAAU,CAAC,EAAE,gBAAgB,CAAC;IAC9B,kBAAkB,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;CACnD,CAAC"}
package/lib/options.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Facebook, Inc. and its affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ //# sourceMappingURL=options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.js","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":";AAAA;;;;;GAKG"}
@@ -4,7 +4,7 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import type { Options } from './loader';
7
+ import type { Options } from './options';
8
8
  /**
9
9
  * Preprocess the string before passing it to MDX
10
10
  * This is not particularly recommended but makes it easier to upgrade to MDX 2
@@ -1 +1 @@
1
- {"version":3,"file":"preprocessor.d.ts","sourceRoot":"","sources":["../src/preprocessor.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,UAAU,CAAC;AAEtC;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,EACxC,WAAW,EAAE,kBAAkB,EAC/B,QAAQ,EACR,cAAc,EACd,WAAW,GACZ,EAAE;IACD,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC1C,WAAW,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,SAAS,CAAC;CACjD,GAAG,MAAM,CAiBT"}
1
+ {"version":3,"file":"preprocessor.d.ts","sourceRoot":"","sources":["../src/preprocessor.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAEvC;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,EACxC,WAAW,EAAE,kBAAkB,EAC/B,QAAQ,EACR,cAAc,EACd,WAAW,GACZ,EAAE;IACD,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC1C,WAAW,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,SAAS,CAAC;CACjD,GAAG,MAAM,CAiBT"}
@@ -6,7 +6,7 @@
6
6
  */
7
7
  import type { WebpackCompilerName } from '@docusaurus/utils';
8
8
  import type { MDXFrontMatter } from './frontMatter';
9
- import type { Options } from './loader';
9
+ import type { Options } from './options';
10
10
  import type { AdmonitionOptions } from './remark/admonitions';
11
11
  type Pluggable = any;
12
12
  export type SimpleProcessorResult = {
@@ -1 +1 @@
1
- {"version":3,"file":"processor.d.ts","sourceRoot":"","sources":["../src/processor.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAeH,OAAO,KAAK,EAAC,mBAAmB,EAAC,MAAM,mBAAmB,CAAC;AAC3D,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,UAAU,CAAC;AACtC,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,sBAAsB,CAAC;AAQ5D,KAAK,SAAS,GAAG,GAAG,CAAC;AAErB,MAAM,MAAM,qBAAqB,GAAG;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAC,CAAC;CAChC,CAAC;AAGF,MAAM,MAAM,eAAe,GAAG;IAC5B,OAAO,EAAE,CAAC,EACR,OAAO,EACP,QAAQ,EACR,WAAW,EACX,YAAY,GACb,EAAE;QACD,OAAO,EAAE,MAAM,CAAC;QAChB,QAAQ,EAAE,MAAM,CAAC;QACjB,WAAW,EAAE;YAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;SAAC,CAAC;QACtC,YAAY,EAAE,mBAAmB,CAAC;KACnC,KAAK,OAAO,CAAC,qBAA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,OAAO,EAAE,OAAO,CAAC;CAClB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAY5B;AAgBD,wBAAsB,YAAY,CAAC,EACjC,QAAQ,EACR,cAAc,EACd,OAAO,GACR,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,cAAc,CAAC;IAC/B,OAAO,EAAE,OAAO,CAAC;CAClB,GAAG,OAAO,CAAC,eAAe,CAAC,CAW3B"}
package/lib/utils.d.ts CHANGED
@@ -6,7 +6,7 @@
6
6
  */
7
7
  import { type WebpackCompilerName } from '@docusaurus/utils';
8
8
  import { type SimpleProcessorResult } from './processor';
9
- import type { Options } from './loader';
9
+ import type { Options } from './options';
10
10
  /**
11
11
  * Converts assets an object with Webpack require calls code.
12
12
  * This is useful for mdx files to reference co-located assets using relative
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAa,KAAK,mBAAmB,EAAC,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAe,KAAK,qBAAqB,EAAC,MAAM,aAAa,CAAC;AAGrE,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,UAAU,CAAC;AAEtC;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,EACrC,MAAM,EACN,kCAAkC,GACnC,EAAE;IACD,MAAM,EAAE,OAAO,CAAC;IAChB,kCAAkC,EAAE,MAAM,CAAC;CAC5C,GAAG,MAAM,CAuCT;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE;IAC5C,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,GAAG,MAAM,GAAG,SAAS,CAErB;AAED,wBAAsB,YAAY,CAAC,EACjC,QAAQ,EACR,WAAW,EACX,WAAW,EACX,OAAO,EACP,YAAY,GACb,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,EAAE,mBAAmB,CAAC;CACnC,GAAG,OAAO,CAAC,qBAAqB,CAAC,CA2CjC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAa,KAAK,mBAAmB,EAAC,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAe,KAAK,qBAAqB,EAAC,MAAM,aAAa,CAAC;AAGrE,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAEvC;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,EACrC,MAAM,EACN,kCAAkC,GACnC,EAAE;IACD,MAAM,EAAE,OAAO,CAAC;IAChB,kCAAkC,EAAE,MAAM,CAAC;CAC5C,GAAG,MAAM,CAuCT;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE;IAC5C,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,GAAG,MAAM,GAAG,SAAS,CAErB;AAED,wBAAsB,YAAY,CAAC,EACjC,QAAQ,EACR,WAAW,EACX,WAAW,EACX,OAAO,EACP,YAAY,GACb,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,EAAE,mBAAmB,CAAC;CACnC,GAAG,OAAO,CAAC,qBAAqB,CAAC,CA2CjC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/mdx-loader",
3
- "version": "0.0.0-6068",
3
+ "version": "0.0.0-6069",
4
4
  "description": "Docusaurus Loader for MDX",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -18,9 +18,9 @@
18
18
  },
19
19
  "license": "MIT",
20
20
  "dependencies": {
21
- "@docusaurus/logger": "0.0.0-6068",
22
- "@docusaurus/utils": "0.0.0-6068",
23
- "@docusaurus/utils-validation": "0.0.0-6068",
21
+ "@docusaurus/logger": "0.0.0-6069",
22
+ "@docusaurus/utils": "0.0.0-6069",
23
+ "@docusaurus/utils-validation": "0.0.0-6069",
24
24
  "@mdx-js/mdx": "^3.0.0",
25
25
  "@slorber/remark-comment": "^1.0.0",
26
26
  "escape-html": "^1.0.3",
@@ -44,7 +44,7 @@
44
44
  "webpack": "^5.88.1"
45
45
  },
46
46
  "devDependencies": {
47
- "@docusaurus/types": "0.0.0-6068",
47
+ "@docusaurus/types": "0.0.0-6069",
48
48
  "@types/escape-html": "^1.0.2",
49
49
  "@types/mdast": "^4.0.2",
50
50
  "@types/stringify-object": "^3.3.1",
@@ -64,5 +64,5 @@
64
64
  "engines": {
65
65
  "node": ">=18.0"
66
66
  },
67
- "gitHead": "4f0bc982b589965d7238334bb9b5bf6c483cc35a"
67
+ "gitHead": "7258877748d2a7c1682c5c92dae3a17734a7e59e"
68
68
  }
@@ -6,30 +6,49 @@
6
6
  */
7
7
 
8
8
  import {createProcessors} from './processor';
9
- import type {Options} from './loader';
9
+ import type {Options} from './options';
10
10
  import type {RuleSetRule, RuleSetUseItem} from 'webpack';
11
11
 
12
- async function enhancedOptions(options: Options): Promise<Options> {
12
+ type CreateOptions = {
13
+ useCrossCompilerCache?: boolean;
14
+ };
15
+
16
+ async function normalizeOptions(
17
+ optionsInput: Options & CreateOptions,
18
+ ): Promise<Options> {
13
19
  // Because Jest doesn't like ESM / createProcessors()
14
20
  if (process.env.N0DE_ENV === 'test' || process.env.JEST_WORKER_ID) {
15
- return options;
21
+ return optionsInput;
16
22
  }
17
23
 
24
+ let options = optionsInput;
25
+
18
26
  // We create the processor earlier here, to avoid the lazy processor creating
19
27
  // Lazy creation messes-up with Rsdoctor ability to measure mdx-loader perf
20
- const newOptions: Options = options.processors
21
- ? options
22
- : {...options, processors: await createProcessors({options})};
28
+ if (!options.processors) {
29
+ options = {...options, processors: await createProcessors({options})};
30
+ }
31
+
32
+ // Cross-compiler cache permits to compile client/server MDX only once
33
+ // We don't want to cache in dev mode (docusaurus start)
34
+ // We only have multiple compilers in production mode (docusaurus build)
35
+ // TODO wrong but good enough for now (example: "docusaurus build --dev")
36
+ if (options.useCrossCompilerCache && process.env.NODE_ENV === 'production') {
37
+ options = {
38
+ ...options,
39
+ crossCompilerCache: new Map(),
40
+ };
41
+ }
23
42
 
24
- return newOptions;
43
+ return options;
25
44
  }
26
45
 
27
46
  export async function createMDXLoaderItem(
28
- options: Options,
47
+ options: Options & CreateOptions,
29
48
  ): Promise<RuleSetUseItem> {
30
49
  return {
31
50
  loader: require.resolve('@docusaurus/mdx-loader'),
32
- options: await enhancedOptions(options),
51
+ options: await normalizeOptions(options),
33
52
  };
34
53
  }
35
54
 
@@ -38,7 +57,7 @@ export async function createMDXLoaderRule({
38
57
  options,
39
58
  }: {
40
59
  include: RuleSetRule['include'];
41
- options: Options;
60
+ options: Options & CreateOptions;
42
61
  }): Promise<RuleSetRule> {
43
62
  return {
44
63
  test: /\.mdx?$/i,
package/src/index.ts CHANGED
@@ -37,5 +37,6 @@ export type LoadedMDXContent<FrontMatter, Metadata, Assets = undefined> = {
37
37
  (): JSX.Element;
38
38
  };
39
39
 
40
- export type {Options, MDXPlugin} from './loader';
40
+ export type {MDXPlugin} from './loader';
41
41
  export type {MDXOptions} from './processor';
42
+ export type {Options} from './options';
package/src/loader.ts CHANGED
@@ -18,14 +18,8 @@ import {
18
18
  createAssetsExportCode,
19
19
  extractContentTitleData,
20
20
  } from './utils';
21
- import type {
22
- SimpleProcessors,
23
- MDXOptions,
24
- SimpleProcessorResult,
25
- } from './processor';
26
- import type {ResolveMarkdownLink} from './remark/resolveMarkdownLinks';
27
-
28
- import type {MarkdownConfig} from '@docusaurus/types';
21
+ import type {WebpackCompilerName} from '@docusaurus/utils';
22
+ import type {Options} from './options';
29
23
  import type {LoaderContext} from 'webpack';
30
24
 
31
25
  // TODO as of April 2023, no way to import/re-export this ESM type easily :/
@@ -35,33 +29,17 @@ type Pluggable = any; // TODO fix this asap
35
29
 
36
30
  export type MDXPlugin = Pluggable;
37
31
 
38
- export type Options = Partial<MDXOptions> & {
39
- markdownConfig: MarkdownConfig;
40
- staticDirs: string[];
41
- siteDir: string;
42
- isMDXPartial?: (filePath: string) => boolean;
43
- isMDXPartialFrontMatterWarningDisabled?: boolean;
44
- removeContentTitle?: boolean;
45
- metadataPath?: (filePath: string) => string;
46
- createAssets?: (metadata: {
47
- filePath: string;
48
- frontMatter: {[key: string]: unknown};
49
- }) => {[key: string]: unknown};
50
- resolveMarkdownLink?: ResolveMarkdownLink;
51
-
52
- // Will usually be created by "createMDXLoaderItem"
53
- processors?: SimpleProcessors;
54
- };
55
-
56
- export async function mdxLoader(
57
- this: LoaderContext<Options>,
58
- fileContent: string,
59
- ): Promise<void> {
60
- const compilerName = getWebpackLoaderCompilerName(this);
61
- const callback = this.async();
62
- const filePath = this.resourcePath;
63
- const options: Options = this.getOptions();
64
-
32
+ async function loadMDX({
33
+ fileContent,
34
+ filePath,
35
+ options,
36
+ compilerName,
37
+ }: {
38
+ fileContent: string;
39
+ filePath: string;
40
+ options: Options;
41
+ compilerName: WebpackCompilerName;
42
+ }): Promise<string> {
65
43
  const {frontMatter} = await options.markdownConfig.parseFrontMatter({
66
44
  filePath,
67
45
  fileContent,
@@ -70,18 +48,13 @@ export async function mdxLoader(
70
48
 
71
49
  const hasFrontMatter = Object.keys(frontMatter).length > 0;
72
50
 
73
- let result: SimpleProcessorResult;
74
- try {
75
- result = await compileToJSX({
76
- fileContent,
77
- filePath,
78
- frontMatter,
79
- options,
80
- compilerName,
81
- });
82
- } catch (error) {
83
- return callback(error as Error);
84
- }
51
+ const result = await compileToJSX({
52
+ fileContent,
53
+ filePath,
54
+ frontMatter,
55
+ options,
56
+ compilerName,
57
+ });
85
58
 
86
59
  const contentTitle = extractContentTitleData(result.data);
87
60
 
@@ -97,7 +70,7 @@ ${JSON.stringify(frontMatter, null, 2)}`;
97
70
  if (!options.isMDXPartialFrontMatterWarningDisabled) {
98
71
  const shouldError = process.env.NODE_ENV === 'test' || process.env.CI;
99
72
  if (shouldError) {
100
- return callback(new Error(errorMessage));
73
+ throw new Error(errorMessage);
101
74
  }
102
75
  logger.warn(errorMessage);
103
76
  }
@@ -146,5 +119,68 @@ ${exportsCode}
146
119
  ${result.content}
147
120
  `;
148
121
 
149
- return callback(null, code);
122
+ return code;
123
+ }
124
+
125
+ // Note: we cache promises instead of strings
126
+ // This is because client/server compilations might be triggered in parallel
127
+ // When this happens for the same file, we don't want to compile it twice
128
+ async function loadMDXWithCaching({
129
+ resource,
130
+ fileContent,
131
+ filePath,
132
+ options,
133
+ compilerName,
134
+ }: {
135
+ resource: string; // path?query#hash
136
+ filePath: string; // path
137
+ fileContent: string;
138
+ options: Options;
139
+ compilerName: WebpackCompilerName;
140
+ }): Promise<string> {
141
+ // Note we "resource" as cache key, not "filePath" nor "fileContent"
142
+ // This is because:
143
+ // - the same file can be compiled in different variants (blog.mdx?truncated)
144
+ // - the same content can be processed differently (versioned docs links)
145
+ const cacheKey = resource;
146
+
147
+ const cachedPromise = options.crossCompilerCache?.get(cacheKey);
148
+ if (cachedPromise) {
149
+ // We can clean up the cache and free memory here
150
+ // We know there are only 2 compilations for the same file
151
+ // Note: once we introduce RSCs we'll probably have 3 compilations
152
+ // Note: we can't use string keys in WeakMap
153
+ // But we could eventually use WeakRef for the values
154
+ options.crossCompilerCache?.delete(cacheKey);
155
+ return cachedPromise;
156
+ }
157
+ const promise = loadMDX({
158
+ fileContent,
159
+ filePath,
160
+ options,
161
+ compilerName,
162
+ });
163
+ options.crossCompilerCache?.set(cacheKey, promise);
164
+ return promise;
165
+ }
166
+
167
+ export async function mdxLoader(
168
+ this: LoaderContext<Options>,
169
+ fileContent: string,
170
+ ): Promise<void> {
171
+ const compilerName = getWebpackLoaderCompilerName(this);
172
+ const callback = this.async();
173
+ const options: Options = this.getOptions();
174
+ try {
175
+ const result = await loadMDXWithCaching({
176
+ resource: this.resource,
177
+ filePath: this.resourcePath,
178
+ fileContent,
179
+ options,
180
+ compilerName,
181
+ });
182
+ return callback(null, result);
183
+ } catch (error) {
184
+ return callback(error as Error);
185
+ }
150
186
  }
package/src/options.ts ADDED
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import type {MDXOptions, SimpleProcessors} from './processor';
9
+ import type {MarkdownConfig} from '@docusaurus/types';
10
+ import type {ResolveMarkdownLink} from './remark/resolveMarkdownLinks';
11
+
12
+ export type Options = Partial<MDXOptions> & {
13
+ markdownConfig: MarkdownConfig;
14
+ staticDirs: string[];
15
+ siteDir: string;
16
+ isMDXPartial?: (filePath: string) => boolean;
17
+ isMDXPartialFrontMatterWarningDisabled?: boolean;
18
+ removeContentTitle?: boolean;
19
+ metadataPath?: (filePath: string) => string;
20
+ createAssets?: (metadata: {
21
+ filePath: string;
22
+ frontMatter: {[key: string]: unknown};
23
+ }) => {[key: string]: unknown};
24
+ resolveMarkdownLink?: ResolveMarkdownLink;
25
+
26
+ // Will usually be created by "createMDXLoaderItem"
27
+ processors?: SimpleProcessors;
28
+ crossCompilerCache?: Map<string, Promise<string>>; // MDX => Promise<JSX> cache
29
+ };
@@ -11,7 +11,7 @@ import {
11
11
  admonitionTitleToDirectiveLabel,
12
12
  } from '@docusaurus/utils';
13
13
  import {normalizeAdmonitionOptions} from './remark/admonitions';
14
- import type {Options} from './loader';
14
+ import type {Options} from './options';
15
15
 
16
16
  /**
17
17
  * Preprocess the string before passing it to MDX
package/src/processor.ts CHANGED
@@ -20,7 +20,7 @@ import codeCompatPlugin from './remark/mdx1Compat/codeCompatPlugin';
20
20
  import {getFormat} from './format';
21
21
  import type {WebpackCompilerName} from '@docusaurus/utils';
22
22
  import type {MDXFrontMatter} from './frontMatter';
23
- import type {Options} from './loader';
23
+ import type {Options} from './options';
24
24
  import type {AdmonitionOptions} from './remark/admonitions';
25
25
 
26
26
  // @ts-expect-error: TODO see https://github.com/microsoft/TypeScript/issues/49721
package/src/utils.ts CHANGED
@@ -10,7 +10,7 @@ import {escapePath, type WebpackCompilerName} from '@docusaurus/utils';
10
10
  import {getProcessor, type SimpleProcessorResult} from './processor';
11
11
  import {validateMDXFrontMatter} from './frontMatter';
12
12
  import preprocessor from './preprocessor';
13
- import type {Options} from './loader';
13
+ import type {Options} from './options';
14
14
 
15
15
  /**
16
16
  * Converts assets an object with Webpack require calls code.