@docusaurus/mdx-loader 3.5.2 → 3.6.0
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.
- package/README.md +0 -1
- package/lib/createMDXLoader.d.ts +18 -0
- package/lib/createMDXLoader.d.ts.map +1 -0
- package/lib/createMDXLoader.js +48 -0
- package/lib/createMDXLoader.js.map +1 -0
- package/lib/index.d.ts +3 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +4 -0
- package/lib/index.js.map +1 -1
- package/lib/loader.d.ts +1 -23
- package/lib/loader.d.ts.map +1 -1
- package/lib/loader.js +120 -139
- package/lib/loader.js.map +1 -1
- package/lib/options.d.ts +33 -0
- package/lib/options.d.ts.map +1 -0
- package/lib/options.js +9 -0
- package/lib/options.js.map +1 -0
- package/lib/preprocessor.d.ts +1 -1
- package/lib/preprocessor.d.ts.map +1 -1
- package/lib/processor.d.ts +12 -6
- package/lib/processor.d.ts.map +1 -1
- package/lib/processor.js +19 -15
- package/lib/processor.js.map +1 -1
- package/lib/remark/transformImage/index.d.ts.map +1 -1
- package/lib/remark/transformImage/index.js +11 -9
- package/lib/remark/transformImage/index.js.map +1 -1
- package/lib/remark/transformLinks/index.d.ts.map +1 -1
- package/lib/remark/transformLinks/index.js +11 -9
- package/lib/remark/transformLinks/index.js.map +1 -1
- package/lib/remark/unusedDirectives/index.d.ts.map +1 -1
- package/lib/remark/unusedDirectives/index.js +1 -0
- package/lib/remark/unusedDirectives/index.js.map +1 -1
- package/lib/utils.d.ts +41 -0
- package/lib/utils.d.ts.map +1 -0
- package/lib/utils.js +108 -0
- package/lib/utils.js.map +1 -0
- package/package.json +6 -6
- package/src/createMDXLoader.ts +67 -0
- package/src/index.ts +4 -1
- package/src/loader.ts +163 -198
- package/src/options.ts +32 -0
- package/src/preprocessor.ts +1 -1
- package/src/processor.ts +35 -31
- package/src/remark/transformImage/index.ts +17 -15
- package/src/remark/transformLinks/index.ts +19 -15
- package/src/remark/unusedDirectives/index.ts +1 -0
- package/src/types.d.mts +3 -1
- package/src/utils.ts +151 -0
package/README.md
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
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 { Options } from './options';
|
|
8
|
+
import type { RuleSetRule, RuleSetUseItem } from 'webpack';
|
|
9
|
+
type CreateOptions = {
|
|
10
|
+
useCrossCompilerCache?: boolean;
|
|
11
|
+
};
|
|
12
|
+
export declare function createMDXLoaderItem(options: Options & CreateOptions): Promise<RuleSetUseItem>;
|
|
13
|
+
export declare function createMDXLoaderRule({ include, options, }: {
|
|
14
|
+
include: RuleSetRule['include'];
|
|
15
|
+
options: Options & CreateOptions;
|
|
16
|
+
}): Promise<RuleSetRule>;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=createMDXLoader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
exports.createMDXLoaderItem = createMDXLoaderItem;
|
|
10
|
+
exports.createMDXLoaderRule = createMDXLoaderRule;
|
|
11
|
+
const processor_1 = require("./processor");
|
|
12
|
+
async function normalizeOptions(optionsInput) {
|
|
13
|
+
// Because Jest doesn't like ESM / createProcessors()
|
|
14
|
+
if (process.env.N0DE_ENV === 'test' || process.env.JEST_WORKER_ID) {
|
|
15
|
+
return optionsInput;
|
|
16
|
+
}
|
|
17
|
+
let options = optionsInput;
|
|
18
|
+
// We create the processor earlier here, to avoid the lazy processor creating
|
|
19
|
+
// Lazy creation messes-up with Rsdoctor ability to measure mdx-loader perf
|
|
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;
|
|
34
|
+
}
|
|
35
|
+
async function createMDXLoaderItem(options) {
|
|
36
|
+
return {
|
|
37
|
+
loader: require.resolve('@docusaurus/mdx-loader'),
|
|
38
|
+
options: await normalizeOptions(options),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
async function createMDXLoaderRule({ include, options, }) {
|
|
42
|
+
return {
|
|
43
|
+
test: /\.mdx?$/i,
|
|
44
|
+
include,
|
|
45
|
+
use: [await createMDXLoaderItem(options)],
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=createMDXLoader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createMDXLoader.js","sourceRoot":"","sources":["../src/createMDXLoader.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAwCH,kDAOC;AAED,kDAYC;AA3DD,2CAA6C;AAQ7C,KAAK,UAAU,gBAAgB,CAC7B,YAAqC;IAErC,qDAAqD;IACrD,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,CAAC;QAClE,OAAO,YAAY,CAAC;IACtB,CAAC;IAED,IAAI,OAAO,GAAG,YAAY,CAAC;IAE3B,6EAA6E;IAC7E,2EAA2E;IAC3E,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC;QACxB,OAAO,GAAG,EAAC,GAAG,OAAO,EAAE,UAAU,EAAE,MAAM,IAAA,4BAAgB,EAAC,EAAC,OAAO,EAAC,CAAC,EAAC,CAAC;IACxE,CAAC;IAED,sEAAsE;IACtE,wDAAwD;IACxD,wEAAwE;IACxE,yEAAyE;IACzE,IAAI,OAAO,CAAC,qBAAqB,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE,CAAC;QAC3E,OAAO,GAAG;YACR,GAAG,OAAO;YACV,kBAAkB,EAAE,IAAI,GAAG,EAAE;SAC9B,CAAC;IACJ,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAEM,KAAK,UAAU,mBAAmB,CACvC,OAAgC;IAEhC,OAAO;QACL,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,wBAAwB,CAAC;QACjD,OAAO,EAAE,MAAM,gBAAgB,CAAC,OAAO,CAAC;KACzC,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"}
|
package/lib/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { mdxLoader } from './loader';
|
|
8
8
|
import type { TOCItem as TOCItemImported } from './remark/toc/types';
|
|
9
|
+
export { createMDXLoaderRule, createMDXLoaderItem } from './createMDXLoader';
|
|
9
10
|
export default mdxLoader;
|
|
10
11
|
export type TOCItem = TOCItemImported;
|
|
11
12
|
export type Format = 'md' | 'mdx';
|
|
@@ -27,6 +28,7 @@ export type LoadedMDXContent<FrontMatter, Metadata, Assets = undefined> = {
|
|
|
27
28
|
readonly assets: Assets;
|
|
28
29
|
(): JSX.Element;
|
|
29
30
|
};
|
|
30
|
-
export type {
|
|
31
|
+
export type { MDXPlugin } from './loader';
|
|
31
32
|
export type { MDXOptions } from './processor';
|
|
33
|
+
export type { Options } from './options';
|
|
32
34
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -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,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,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C,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/index.js
CHANGED
|
@@ -6,6 +6,10 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.createMDXLoaderItem = exports.createMDXLoaderRule = void 0;
|
|
9
10
|
const loader_1 = require("./loader");
|
|
11
|
+
var createMDXLoader_1 = require("./createMDXLoader");
|
|
12
|
+
Object.defineProperty(exports, "createMDXLoaderRule", { enumerable: true, get: function () { return createMDXLoader_1.createMDXLoaderRule; } });
|
|
13
|
+
Object.defineProperty(exports, "createMDXLoaderItem", { enumerable: true, get: function () { return createMDXLoader_1.createMDXLoaderItem; } });
|
|
10
14
|
exports.default = loader_1.mdxLoader;
|
|
11
15
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,qCAAmC;AAInC,qDAA2E;AAAnE,sHAAA,mBAAmB,OAAA;AAAE,sHAAA,mBAAmB,OAAA;AAEhD,kBAAe,kBAAS,CAAC"}
|
package/lib/loader.d.ts
CHANGED
|
@@ -4,32 +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 {
|
|
8
|
-
import type { MDXOptions } from './processor';
|
|
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?: string | ((filePath: string) => string);
|
|
21
|
-
createAssets?: (metadata: {
|
|
22
|
-
frontMatter: {
|
|
23
|
-
[key: string]: unknown;
|
|
24
|
-
};
|
|
25
|
-
metadata: {
|
|
26
|
-
[key: string]: unknown;
|
|
27
|
-
};
|
|
28
|
-
}) => {
|
|
29
|
-
[key: string]: unknown;
|
|
30
|
-
};
|
|
31
|
-
resolveMarkdownLink?: ResolveMarkdownLink;
|
|
32
|
-
};
|
|
33
11
|
export declare function mdxLoader(this: LoaderContext<Options>, fileContent: string): Promise<void>;
|
|
34
12
|
export {};
|
|
35
13
|
//# sourceMappingURL=loader.d.ts.map
|
package/lib/loader.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAiBH,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;AAuLlC,wBAAsB,SAAS,CAC7B,IAAI,EAAE,aAAa,CAAC,OAAO,CAAC,EAC5B,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,IAAI,CAAC,CAgBf"}
|
package/lib/loader.js
CHANGED
|
@@ -8,181 +8,162 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.mdxLoader = mdxLoader;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
|
-
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
12
11
|
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
13
12
|
const utils_1 = require("@docusaurus/utils");
|
|
14
13
|
const stringify_object_1 = tslib_1.__importDefault(require("stringify-object"));
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
const { loaders: { inlineMarkdownAssetImageFileLoader }, } = (0, utils_1.getFileLoaderUtils)();
|
|
19
|
-
/**
|
|
20
|
-
* When this throws, it generally means that there's no metadata file associated
|
|
21
|
-
* with this MDX document. It can happen when using MDX partials (usually
|
|
22
|
-
* starting with _). That's why it's important to provide the `isMDXPartial`
|
|
23
|
-
* function in config
|
|
24
|
-
*/
|
|
25
|
-
async function readMetadataPath(metadataPath) {
|
|
26
|
-
try {
|
|
27
|
-
return await fs_extra_1.default.readFile(metadataPath, 'utf8');
|
|
28
|
-
}
|
|
29
|
-
catch (err) {
|
|
30
|
-
logger_1.default.error `MDX loader can't read MDX metadata file path=${metadataPath}. Maybe the isMDXPartial option function was not provided?`;
|
|
31
|
-
throw err;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Converts assets an object with Webpack require calls code.
|
|
36
|
-
* This is useful for mdx files to reference co-located assets using relative
|
|
37
|
-
* paths. Those assets should enter the Webpack assets pipeline and be hashed.
|
|
38
|
-
* For now, we only handle that for images and paths starting with `./`:
|
|
39
|
-
*
|
|
40
|
-
* `{image: "./myImage.png"}` => `{image: require("./myImage.png")}`
|
|
41
|
-
*/
|
|
42
|
-
function createAssetsExportCode(assets) {
|
|
43
|
-
if (typeof assets !== 'object' ||
|
|
44
|
-
!assets ||
|
|
45
|
-
Object.keys(assets).length === 0) {
|
|
46
|
-
return 'undefined';
|
|
47
|
-
}
|
|
48
|
-
// TODO implementation can be completed/enhanced
|
|
49
|
-
function createAssetValueCode(assetValue) {
|
|
50
|
-
if (Array.isArray(assetValue)) {
|
|
51
|
-
const arrayItemCodes = assetValue.map((item) => createAssetValueCode(item) ?? 'undefined');
|
|
52
|
-
return `[${arrayItemCodes.join(', ')}]`;
|
|
53
|
-
}
|
|
54
|
-
// Only process string values starting with ./
|
|
55
|
-
// We could enhance this logic and check if file exists on disc?
|
|
56
|
-
if (typeof assetValue === 'string' && assetValue.startsWith('./')) {
|
|
57
|
-
// TODO do we have other use-cases than image assets?
|
|
58
|
-
// Probably not worth adding more support, as we want to move to Webpack 5 new asset system (https://github.com/facebook/docusaurus/pull/4708)
|
|
59
|
-
return `require("${inlineMarkdownAssetImageFileLoader}${(0, utils_1.escapePath)(assetValue)}").default`;
|
|
60
|
-
}
|
|
61
|
-
return undefined;
|
|
62
|
-
}
|
|
63
|
-
const assetEntries = Object.entries(assets);
|
|
64
|
-
const codeLines = assetEntries
|
|
65
|
-
.map(([key, value]) => {
|
|
66
|
-
const assetRequireCode = createAssetValueCode(value);
|
|
67
|
-
return assetRequireCode ? `"${key}": ${assetRequireCode},` : undefined;
|
|
68
|
-
})
|
|
69
|
-
.filter(Boolean);
|
|
70
|
-
return `{\n${codeLines.join('\n')}\n}`;
|
|
71
|
-
}
|
|
72
|
-
// TODO temporary, remove this after v3.1?
|
|
73
|
-
// Some plugin authors use our mdx-loader, despite it not being public API
|
|
74
|
-
// see https://github.com/facebook/docusaurus/issues/8298
|
|
75
|
-
function ensureMarkdownConfig(reqOptions) {
|
|
76
|
-
if (!reqOptions.markdownConfig) {
|
|
77
|
-
throw new Error('Docusaurus v3+ requires MDX loader options.markdownConfig - plugin authors using the MDX loader should make sure to provide that option');
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* data.contentTitle is set by the remark contentTitle plugin
|
|
82
|
-
*/
|
|
83
|
-
function extractContentTitleData(data) {
|
|
84
|
-
return data.contentTitle;
|
|
85
|
-
}
|
|
86
|
-
async function mdxLoader(fileContent) {
|
|
87
|
-
const compilerName = (0, utils_1.getWebpackLoaderCompilerName)(this);
|
|
88
|
-
const callback = this.async();
|
|
89
|
-
const filePath = this.resourcePath;
|
|
90
|
-
const reqOptions = this.getOptions();
|
|
91
|
-
const { query } = this;
|
|
92
|
-
ensureMarkdownConfig(reqOptions);
|
|
93
|
-
const { frontMatter } = await reqOptions.markdownConfig.parseFrontMatter({
|
|
14
|
+
const utils_2 = require("./utils");
|
|
15
|
+
async function loadMDX({ fileContent, filePath, options, compilerName, }) {
|
|
16
|
+
const { frontMatter } = await options.markdownConfig.parseFrontMatter({
|
|
94
17
|
filePath,
|
|
95
18
|
fileContent,
|
|
96
19
|
defaultParseFrontMatter: utils_1.DEFAULT_PARSE_FRONT_MATTER,
|
|
97
20
|
});
|
|
98
|
-
const mdxFrontMatter = (0, frontMatter_1.validateMDXFrontMatter)(frontMatter.mdx);
|
|
99
|
-
const preprocessedContent = (0, preprocessor_1.default)({
|
|
100
|
-
fileContent,
|
|
101
|
-
filePath,
|
|
102
|
-
admonitions: reqOptions.admonitions,
|
|
103
|
-
markdownConfig: reqOptions.markdownConfig,
|
|
104
|
-
});
|
|
105
21
|
const hasFrontMatter = Object.keys(frontMatter).length > 0;
|
|
106
|
-
const
|
|
22
|
+
const result = await (0, utils_2.compileToJSX)({
|
|
23
|
+
fileContent,
|
|
107
24
|
filePath,
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
25
|
+
frontMatter,
|
|
26
|
+
options,
|
|
27
|
+
compilerName,
|
|
111
28
|
});
|
|
112
|
-
|
|
113
|
-
try {
|
|
114
|
-
result = await processor.process({
|
|
115
|
-
content: preprocessedContent,
|
|
116
|
-
filePath,
|
|
117
|
-
frontMatter,
|
|
118
|
-
compilerName,
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
catch (errorUnknown) {
|
|
122
|
-
const error = errorUnknown;
|
|
123
|
-
// MDX can emit errors that have useful extra attributes
|
|
124
|
-
const errorJSON = JSON.stringify(error, null, 2);
|
|
125
|
-
const errorDetails = errorJSON === '{}'
|
|
126
|
-
? // regular JS error case: print stacktrace
|
|
127
|
-
error.stack ?? 'N/A'
|
|
128
|
-
: // MDX error: print extra attributes + stacktrace
|
|
129
|
-
`${errorJSON}\n${error.stack}`;
|
|
130
|
-
return callback(new Error(`MDX compilation failed for file ${logger_1.default.path(filePath)}\nCause: ${error.message}\nDetails:\n${errorDetails}`,
|
|
131
|
-
// TODO error cause doesn't seem to be used by Webpack stats.errors :s
|
|
132
|
-
{ cause: error }));
|
|
133
|
-
}
|
|
134
|
-
const contentTitle = extractContentTitleData(result.data);
|
|
29
|
+
const contentTitle = (0, utils_2.extractContentTitleData)(result.data);
|
|
135
30
|
// MDX partials are MDX files starting with _ or in a folder starting with _
|
|
136
31
|
// Partial are not expected to have associated metadata files or front matter
|
|
137
|
-
const isMDXPartial =
|
|
32
|
+
const isMDXPartial = options.isMDXPartial?.(filePath);
|
|
138
33
|
if (isMDXPartial && hasFrontMatter) {
|
|
139
34
|
const errorMessage = `Docusaurus MDX partial files should not contain front matter.
|
|
140
35
|
Those partial files use the _ prefix as a convention by default, but this is configurable.
|
|
141
36
|
File at ${filePath} contains front matter that will be ignored:
|
|
142
37
|
${JSON.stringify(frontMatter, null, 2)}`;
|
|
143
|
-
if (!
|
|
38
|
+
if (!options.isMDXPartialFrontMatterWarningDisabled) {
|
|
144
39
|
const shouldError = process.env.NODE_ENV === 'test' || process.env.CI;
|
|
145
40
|
if (shouldError) {
|
|
146
|
-
|
|
41
|
+
throw new Error(errorMessage);
|
|
147
42
|
}
|
|
148
43
|
logger_1.default.warn(errorMessage);
|
|
149
44
|
}
|
|
150
45
|
}
|
|
151
|
-
function getMetadataPath() {
|
|
46
|
+
const metadataPath = (function getMetadataPath() {
|
|
152
47
|
if (!isMDXPartial) {
|
|
153
|
-
|
|
154
|
-
if (reqOptions.metadataPath &&
|
|
155
|
-
typeof reqOptions.metadataPath === 'function') {
|
|
156
|
-
return reqOptions.metadataPath(filePath);
|
|
157
|
-
}
|
|
48
|
+
return options.metadataPath?.(filePath);
|
|
158
49
|
}
|
|
159
50
|
return undefined;
|
|
160
|
-
}
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
this.addDependency(metadataPath);
|
|
164
|
-
}
|
|
165
|
-
const metadataJsonString = metadataPath
|
|
166
|
-
? await readMetadataPath(metadataPath)
|
|
167
|
-
: undefined;
|
|
168
|
-
const metadata = metadataJsonString
|
|
169
|
-
? JSON.parse(metadataJsonString)
|
|
170
|
-
: undefined;
|
|
171
|
-
const assets = reqOptions.createAssets && metadata
|
|
172
|
-
? reqOptions.createAssets({ frontMatter, metadata })
|
|
51
|
+
})();
|
|
52
|
+
const assets = options.createAssets && !isMDXPartial
|
|
53
|
+
? options.createAssets({ filePath, frontMatter })
|
|
173
54
|
: undefined;
|
|
55
|
+
const fileLoaderUtils = (0, utils_1.getFileLoaderUtils)(compilerName === 'server');
|
|
174
56
|
// TODO use remark plugins to insert extra exports instead of string concat?
|
|
175
57
|
// cf how the toc is exported
|
|
176
58
|
const exportsCode = `
|
|
177
59
|
export const frontMatter = ${(0, stringify_object_1.default)(frontMatter)};
|
|
178
60
|
export const contentTitle = ${(0, stringify_object_1.default)(contentTitle)};
|
|
179
|
-
${
|
|
180
|
-
|
|
61
|
+
${metadataPath
|
|
62
|
+
? `export {default as metadata} from '${(0, utils_1.aliasedSitePath)(metadataPath, options.siteDir)}'`
|
|
63
|
+
: ''}
|
|
64
|
+
${assets
|
|
65
|
+
? `export const assets = ${(0, utils_2.createAssetsExportCode)({
|
|
66
|
+
assets,
|
|
67
|
+
inlineMarkdownAssetImageFileLoader: fileLoaderUtils.loaders.inlineMarkdownAssetImageFileLoader,
|
|
68
|
+
})};`
|
|
69
|
+
: ''}
|
|
181
70
|
`;
|
|
182
71
|
const code = `
|
|
183
72
|
${exportsCode}
|
|
184
73
|
${result.content}
|
|
185
74
|
`;
|
|
186
|
-
return
|
|
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
|
+
const { crossCompilerCache } = options;
|
|
82
|
+
if (!crossCompilerCache) {
|
|
83
|
+
return loadMDX({
|
|
84
|
+
fileContent,
|
|
85
|
+
filePath,
|
|
86
|
+
options,
|
|
87
|
+
compilerName,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
// Note we "resource" as cache key, not "filePath" nor "fileContent"
|
|
91
|
+
// This is because:
|
|
92
|
+
// - the same file can be compiled in different variants (blog.mdx?truncated)
|
|
93
|
+
// - the same content can be processed differently (versioned docs links)
|
|
94
|
+
const cacheKey = resource;
|
|
95
|
+
// We can clean up the cache and free memory after cache entry consumption
|
|
96
|
+
// We know there are only 2 compilations for the same file
|
|
97
|
+
// Note: once we introduce RSCs we'll probably have 3 compilations
|
|
98
|
+
// Note: we can't use string keys in WeakMap
|
|
99
|
+
// But we could eventually use WeakRef for the values
|
|
100
|
+
const deleteCacheEntry = () => crossCompilerCache.delete(cacheKey);
|
|
101
|
+
const cacheEntry = crossCompilerCache?.get(cacheKey);
|
|
102
|
+
// When deduplicating client/server compilations, we always use the client
|
|
103
|
+
// compilation and not the server compilation
|
|
104
|
+
// This is important because the server compilation usually skips some steps
|
|
105
|
+
// Notably: the server compilation does not emit file-loader assets
|
|
106
|
+
// Using the server compilation otherwise leads to broken images
|
|
107
|
+
// See https://github.com/facebook/docusaurus/issues/10544#issuecomment-2390943794
|
|
108
|
+
// See https://github.com/facebook/docusaurus/pull/10553
|
|
109
|
+
// TODO a problem with this: server bundle will use client inline loaders
|
|
110
|
+
// This means server bundle will use ?emit=true for assets
|
|
111
|
+
// We should try to get rid of inline loaders to cleanup this caching logic
|
|
112
|
+
if (compilerName === 'client') {
|
|
113
|
+
const promise = loadMDX({
|
|
114
|
+
fileContent,
|
|
115
|
+
filePath,
|
|
116
|
+
options,
|
|
117
|
+
compilerName,
|
|
118
|
+
});
|
|
119
|
+
if (cacheEntry) {
|
|
120
|
+
promise.then(cacheEntry.resolve, cacheEntry.reject);
|
|
121
|
+
deleteCacheEntry();
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
const noop = () => {
|
|
125
|
+
throw new Error('this should never be called');
|
|
126
|
+
};
|
|
127
|
+
crossCompilerCache.set(cacheKey, {
|
|
128
|
+
promise,
|
|
129
|
+
resolve: noop,
|
|
130
|
+
reject: noop,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
return promise;
|
|
134
|
+
}
|
|
135
|
+
// Server compilation always uses the result of the client compilation above
|
|
136
|
+
else if (compilerName === 'server') {
|
|
137
|
+
if (cacheEntry) {
|
|
138
|
+
deleteCacheEntry();
|
|
139
|
+
return cacheEntry.promise;
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
const { promise, resolve, reject } = (0, utils_2.promiseWithResolvers)();
|
|
143
|
+
crossCompilerCache.set(cacheKey, { promise, resolve, reject });
|
|
144
|
+
return promise;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
throw new Error(`Unexpected compilerName=${compilerName}`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
async function mdxLoader(fileContent) {
|
|
152
|
+
const compilerName = (0, utils_1.getWebpackLoaderCompilerName)(this);
|
|
153
|
+
const callback = this.async();
|
|
154
|
+
const options = this.getOptions();
|
|
155
|
+
try {
|
|
156
|
+
const result = await loadMDXWithCaching({
|
|
157
|
+
resource: this.resource,
|
|
158
|
+
filePath: this.resourcePath,
|
|
159
|
+
fileContent,
|
|
160
|
+
options,
|
|
161
|
+
compilerName,
|
|
162
|
+
});
|
|
163
|
+
return callback(null, result);
|
|
164
|
+
}
|
|
165
|
+
catch (error) {
|
|
166
|
+
return callback(error);
|
|
167
|
+
}
|
|
187
168
|
}
|
|
188
169
|
//# 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;;
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAgNH,8BAmBC;;AAjOD,wEAAwC;AACxC,6CAK2B;AAC3B,gFAA+C;AAC/C,mCAKiB;AAYjB,KAAK,UAAU,OAAO,CAAC,EACrB,WAAW,EACX,QAAQ,EACR,OAAO,EACP,YAAY,GAMb;IACC,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,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IAE3D,MAAM,MAAM,GAAG,MAAM,IAAA,oBAAY,EAAC;QAChC,WAAW;QACX,QAAQ;QACR,WAAW;QACX,OAAO;QACP,YAAY;KACb,CAAC,CAAC;IAEH,MAAM,YAAY,GAAG,IAAA,+BAAuB,EAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAE1D,4EAA4E;IAC5E,6EAA6E;IAC7E,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC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;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"}
|
package/lib/options.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
import type { PromiseWithResolvers } from './utils';
|
|
11
|
+
export type Options = Partial<MDXOptions> & {
|
|
12
|
+
markdownConfig: MarkdownConfig;
|
|
13
|
+
staticDirs: string[];
|
|
14
|
+
siteDir: string;
|
|
15
|
+
isMDXPartial?: (filePath: string) => boolean;
|
|
16
|
+
isMDXPartialFrontMatterWarningDisabled?: boolean;
|
|
17
|
+
removeContentTitle?: boolean;
|
|
18
|
+
metadataPath?: (filePath: string) => string;
|
|
19
|
+
createAssets?: (metadata: {
|
|
20
|
+
filePath: string;
|
|
21
|
+
frontMatter: {
|
|
22
|
+
[key: string]: unknown;
|
|
23
|
+
};
|
|
24
|
+
}) => {
|
|
25
|
+
[key: string]: unknown;
|
|
26
|
+
};
|
|
27
|
+
resolveMarkdownLink?: ResolveMarkdownLink;
|
|
28
|
+
processors?: SimpleProcessors;
|
|
29
|
+
crossCompilerCache?: Map<string, CrossCompilerCacheEntry>;
|
|
30
|
+
};
|
|
31
|
+
type CrossCompilerCacheEntry = PromiseWithResolvers<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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"}
|
package/lib/preprocessor.d.ts
CHANGED
|
@@ -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 './
|
|
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,
|
|
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"}
|
package/lib/processor.d.ts
CHANGED
|
@@ -6,16 +6,16 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import type { WebpackCompilerName } from '@docusaurus/utils';
|
|
8
8
|
import type { MDXFrontMatter } from './frontMatter';
|
|
9
|
-
import type { Options } from './
|
|
9
|
+
import type { Options } from './options';
|
|
10
10
|
import type { AdmonitionOptions } from './remark/admonitions';
|
|
11
11
|
type Pluggable = any;
|
|
12
|
-
type SimpleProcessorResult = {
|
|
12
|
+
export type SimpleProcessorResult = {
|
|
13
13
|
content: string;
|
|
14
14
|
data: {
|
|
15
15
|
[key: string]: unknown;
|
|
16
16
|
};
|
|
17
17
|
};
|
|
18
|
-
type SimpleProcessor = {
|
|
18
|
+
export type SimpleProcessor = {
|
|
19
19
|
process: ({ content, filePath, frontMatter, compilerName, }: {
|
|
20
20
|
content: string;
|
|
21
21
|
filePath: string;
|
|
@@ -38,11 +38,17 @@ export declare function createProcessorUncached(parameters: {
|
|
|
38
38
|
options: Options;
|
|
39
39
|
format: 'md' | 'mdx';
|
|
40
40
|
}): Promise<SimpleProcessor>;
|
|
41
|
-
export
|
|
41
|
+
export type SimpleProcessors = {
|
|
42
|
+
mdProcessor: SimpleProcessor;
|
|
43
|
+
mdxProcessor: SimpleProcessor;
|
|
44
|
+
};
|
|
45
|
+
export declare function createProcessors({ options, }: {
|
|
46
|
+
options: Options;
|
|
47
|
+
}): Promise<SimpleProcessors>;
|
|
48
|
+
export declare function getProcessor({ filePath, mdxFrontMatter, options, }: {
|
|
42
49
|
filePath: string;
|
|
43
50
|
mdxFrontMatter: MDXFrontMatter;
|
|
44
|
-
|
|
45
|
-
reqOptions: Options;
|
|
51
|
+
options: Options;
|
|
46
52
|
}): Promise<SimpleProcessor>;
|
|
47
53
|
export {};
|
|
48
54
|
//# sourceMappingURL=processor.d.ts.map
|
package/lib/processor.d.ts.map
CHANGED
|
@@ -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,
|
|
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,WAAW,CAAC;AACvC,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,qBAAqB,CAAC,CAAC;CACtC,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG,SAAS,CAAC;AAElC,MAAM,MAAM,UAAU,GAAG;IACvB,WA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