@docusaurus/mdx-loader 0.0.0-6065 → 0.0.0-6067
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/lib/loader.d.ts +2 -6
- package/lib/loader.d.ts.map +1 -1
- package/lib/loader.js +7 -30
- package/lib/loader.js.map +1 -1
- package/lib/utils.d.ts +0 -7
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +0 -16
- package/lib/utils.js.map +1 -1
- package/package.json +6 -6
- package/src/loader.ts +13 -43
- package/src/utils.ts +0 -18
package/lib/loader.d.ts
CHANGED
|
@@ -10,10 +10,6 @@ import type { MarkdownConfig } from '@docusaurus/types';
|
|
|
10
10
|
import type { LoaderContext } from 'webpack';
|
|
11
11
|
type Pluggable = any;
|
|
12
12
|
export type MDXPlugin = Pluggable;
|
|
13
|
-
export type LoadedMetadata = {
|
|
14
|
-
metadataPath: string;
|
|
15
|
-
metadataContent: unknown;
|
|
16
|
-
};
|
|
17
13
|
export type Options = Partial<MDXOptions> & {
|
|
18
14
|
markdownConfig: MarkdownConfig;
|
|
19
15
|
staticDirs: string[];
|
|
@@ -21,12 +17,12 @@ export type Options = Partial<MDXOptions> & {
|
|
|
21
17
|
isMDXPartial?: (filePath: string) => boolean;
|
|
22
18
|
isMDXPartialFrontMatterWarningDisabled?: boolean;
|
|
23
19
|
removeContentTitle?: boolean;
|
|
24
|
-
metadataPath?:
|
|
20
|
+
metadataPath?: (filePath: string) => string;
|
|
25
21
|
createAssets?: (metadata: {
|
|
22
|
+
filePath: string;
|
|
26
23
|
frontMatter: {
|
|
27
24
|
[key: string]: unknown;
|
|
28
25
|
};
|
|
29
|
-
metadata: unknown;
|
|
30
26
|
}) => {
|
|
31
27
|
[key: string]: unknown;
|
|
32
28
|
};
|
package/lib/loader.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"A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E,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"}
|
package/lib/loader.js
CHANGED
|
@@ -53,37 +53,14 @@ ${JSON.stringify(frontMatter, null, 2)}`;
|
|
|
53
53
|
logger_1.default.warn(errorMessage);
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
-
|
|
56
|
+
const metadataPath = (function getMetadataPath() {
|
|
57
57
|
if (!isMDXPartial) {
|
|
58
|
-
|
|
59
|
-
if (options.metadataPath && typeof options.metadataPath === 'function') {
|
|
60
|
-
const metadata = options.metadataPath(filePath);
|
|
61
|
-
if (!metadata) {
|
|
62
|
-
return undefined;
|
|
63
|
-
}
|
|
64
|
-
if (typeof metadata === 'string') {
|
|
65
|
-
return {
|
|
66
|
-
metadataPath: metadata,
|
|
67
|
-
metadataContent: await (0, utils_2.readMetadataPath)(metadata),
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
if (!metadata.metadataPath) {
|
|
71
|
-
throw new Error(`Metadata path missing for file ${filePath}`);
|
|
72
|
-
}
|
|
73
|
-
if (!metadata.metadataContent) {
|
|
74
|
-
throw new Error(`Metadata content missing for file ${filePath}`);
|
|
75
|
-
}
|
|
76
|
-
return metadata;
|
|
77
|
-
}
|
|
58
|
+
return options.metadataPath?.(filePath);
|
|
78
59
|
}
|
|
79
60
|
return undefined;
|
|
80
|
-
}
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
this.addDependency(metadata.metadataPath);
|
|
84
|
-
}
|
|
85
|
-
const assets = options.createAssets && metadata
|
|
86
|
-
? options.createAssets({ frontMatter, metadata: metadata.metadataContent })
|
|
61
|
+
})();
|
|
62
|
+
const assets = options.createAssets && !isMDXPartial
|
|
63
|
+
? options.createAssets({ filePath, frontMatter })
|
|
87
64
|
: undefined;
|
|
88
65
|
const fileLoaderUtils = (0, utils_1.getFileLoaderUtils)(compilerName === 'server');
|
|
89
66
|
// TODO use remark plugins to insert extra exports instead of string concat?
|
|
@@ -91,8 +68,8 @@ ${JSON.stringify(frontMatter, null, 2)}`;
|
|
|
91
68
|
const exportsCode = `
|
|
92
69
|
export const frontMatter = ${(0, stringify_object_1.default)(frontMatter)};
|
|
93
70
|
export const contentTitle = ${(0, stringify_object_1.default)(contentTitle)};
|
|
94
|
-
${
|
|
95
|
-
? `export
|
|
71
|
+
${metadataPath
|
|
72
|
+
? `export {default as metadata} from '${(0, utils_1.aliasedSitePath)(metadataPath, options.siteDir)}'`
|
|
96
73
|
: ''}
|
|
97
74
|
${assets
|
|
98
75
|
? `export const assets = ${(0, utils_2.createAssetsExportCode)({
|
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;;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,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;YAClB,OAAO,OAAO,CAAC,YAAY,EAAE,CAAC,QAAQ,CAAC,CAAC;QAC1C,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC,CAAC,EAAE,CAAC;IAEL,MAAM,MAAM,GACV,OAAO,CAAC,YAAY,IAAI,CAAC,YAAY;QACnC,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,EAAC,QAAQ,EAAE,WAAW,EAAC,CAAC;QAC/C,CAAC,CAAC,SAAS,CAAC;IAEhB,MAAM,eAAe,GAAG,IAAA,0BAAkB,EAAC,YAAY,KAAK,QAAQ,CAAC,CAAC;IAEtE,4EAA4E;IAC5E,6BAA6B;IAC7B,MAAM,WAAW,GAAG;6BACO,IAAA,0BAAe,EAAC,WAAW,CAAC;8BAC3B,IAAA,0BAAe,EAAC,YAAY,CAAC;EAEzD,YAAY;QACV,CAAC,CAAC,sCAAsC,IAAA,uBAAe,EACnD,YAAY,EACZ,OAAO,CAAC,OAAO,CAChB,GAAG;QACN,CAAC,CAAC,EACN;EAEE,MAAM;QACJ,CAAC,CAAC,yBAAyB,IAAA,8BAAsB,EAAC;YAC9C,MAAM;YACN,kCAAkC,EAChC,eAAe,CAAC,OAAO,CAAC,kCAAkC;SAC7D,CAAC,GAAG;QACP,CAAC,CAAC,EACN;CACC,CAAC;IAEA,MAAM,IAAI,GAAG;EACb,WAAW;EACX,MAAM,CAAC,OAAO;CACf,CAAC;IAEA,OAAO,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AAC9B,CAAC"}
|
package/lib/utils.d.ts
CHANGED
|
@@ -7,13 +7,6 @@
|
|
|
7
7
|
import { type WebpackCompilerName } from '@docusaurus/utils';
|
|
8
8
|
import { type SimpleProcessorResult } from './processor';
|
|
9
9
|
import type { Options } from './loader';
|
|
10
|
-
/**
|
|
11
|
-
* When this throws, it generally means that there's no metadata file associated
|
|
12
|
-
* with this MDX document. It can happen when using MDX partials (usually
|
|
13
|
-
* starting with _). That's why it's important to provide the `isMDXPartial`
|
|
14
|
-
* function in config
|
|
15
|
-
*/
|
|
16
|
-
export declare function readMetadataPath(metadataPath: string): Promise<unknown>;
|
|
17
10
|
/**
|
|
18
11
|
* Converts assets an object with Webpack require calls code.
|
|
19
12
|
* This is useful for mdx files to reference co-located assets using relative
|
package/lib/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
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"}
|
package/lib/utils.js
CHANGED
|
@@ -6,31 +6,15 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.readMetadataPath = readMetadataPath;
|
|
10
9
|
exports.createAssetsExportCode = createAssetsExportCode;
|
|
11
10
|
exports.extractContentTitleData = extractContentTitleData;
|
|
12
11
|
exports.compileToJSX = compileToJSX;
|
|
13
12
|
const tslib_1 = require("tslib");
|
|
14
|
-
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
15
13
|
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
16
14
|
const utils_1 = require("@docusaurus/utils");
|
|
17
15
|
const processor_1 = require("./processor");
|
|
18
16
|
const frontMatter_1 = require("./frontMatter");
|
|
19
17
|
const preprocessor_1 = tslib_1.__importDefault(require("./preprocessor"));
|
|
20
|
-
/**
|
|
21
|
-
* When this throws, it generally means that there's no metadata file associated
|
|
22
|
-
* with this MDX document. It can happen when using MDX partials (usually
|
|
23
|
-
* starting with _). That's why it's important to provide the `isMDXPartial`
|
|
24
|
-
* function in config
|
|
25
|
-
*/
|
|
26
|
-
async function readMetadataPath(metadataPath) {
|
|
27
|
-
try {
|
|
28
|
-
return await fs_extra_1.default.readJSON(metadataPath, 'utf8');
|
|
29
|
-
}
|
|
30
|
-
catch (error) {
|
|
31
|
-
throw new Error(logger_1.default.interpolate `MDX loader can't read MDX metadata file path=${metadataPath}. Maybe the isMDXPartial option function was not provided?`, { cause: error });
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
18
|
/**
|
|
35
19
|
* Converts assets an object with Webpack require calls code.
|
|
36
20
|
* This is useful for mdx files to reference co-located assets using relative
|
package/lib/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;
|
|
1
|
+
{"version":3,"file":"utils.js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,KAAK,KAAK,CAAC,KAAK,EAAE,CAAC;QAErC,MAAM,IAAI,KAAK,CACb,mCAAmC,gBAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,YACtD,KAAK,CAAC,OACR,eAAe,YAAY,EAAE;QAC7B,sEAAsE;QACtE,EAAC,KAAK,EAAE,KAAK,EAAC,CACf,CAAC;IACJ,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/mdx-loader",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-6067",
|
|
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-
|
|
22
|
-
"@docusaurus/utils": "0.0.0-
|
|
23
|
-
"@docusaurus/utils-validation": "0.0.0-
|
|
21
|
+
"@docusaurus/logger": "0.0.0-6067",
|
|
22
|
+
"@docusaurus/utils": "0.0.0-6067",
|
|
23
|
+
"@docusaurus/utils-validation": "0.0.0-6067",
|
|
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-
|
|
47
|
+
"@docusaurus/types": "0.0.0-6067",
|
|
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": "
|
|
67
|
+
"gitHead": "856911a5474e8e907f83438abe5c42d4793e06cb"
|
|
68
68
|
}
|
package/src/loader.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
import logger from '@docusaurus/logger';
|
|
9
9
|
import {
|
|
10
|
+
aliasedSitePath,
|
|
10
11
|
DEFAULT_PARSE_FRONT_MATTER,
|
|
11
12
|
getFileLoaderUtils,
|
|
12
13
|
getWebpackLoaderCompilerName,
|
|
@@ -16,7 +17,6 @@ import {
|
|
|
16
17
|
compileToJSX,
|
|
17
18
|
createAssetsExportCode,
|
|
18
19
|
extractContentTitleData,
|
|
19
|
-
readMetadataPath,
|
|
20
20
|
} from './utils';
|
|
21
21
|
import type {
|
|
22
22
|
SimpleProcessors,
|
|
@@ -35,12 +35,6 @@ type Pluggable = any; // TODO fix this asap
|
|
|
35
35
|
|
|
36
36
|
export type MDXPlugin = Pluggable;
|
|
37
37
|
|
|
38
|
-
// This represents the path to the mdx metadata bundle path + its loaded content
|
|
39
|
-
export type LoadedMetadata = {
|
|
40
|
-
metadataPath: string;
|
|
41
|
-
metadataContent: unknown;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
38
|
export type Options = Partial<MDXOptions> & {
|
|
45
39
|
markdownConfig: MarkdownConfig;
|
|
46
40
|
staticDirs: string[];
|
|
@@ -48,13 +42,10 @@ export type Options = Partial<MDXOptions> & {
|
|
|
48
42
|
isMDXPartial?: (filePath: string) => boolean;
|
|
49
43
|
isMDXPartialFrontMatterWarningDisabled?: boolean;
|
|
50
44
|
removeContentTitle?: boolean;
|
|
51
|
-
|
|
52
|
-
// TODO Docusaurus v4: rename to just "metadata"?
|
|
53
|
-
// We kept retro-compatibility in v3 in case plugins/sites use mdx loader
|
|
54
|
-
metadataPath?: string | ((filePath: string) => string | LoadedMetadata);
|
|
45
|
+
metadataPath?: (filePath: string) => string;
|
|
55
46
|
createAssets?: (metadata: {
|
|
47
|
+
filePath: string;
|
|
56
48
|
frontMatter: {[key: string]: unknown};
|
|
57
|
-
metadata: unknown;
|
|
58
49
|
}) => {[key: string]: unknown};
|
|
59
50
|
resolveMarkdownLink?: ResolveMarkdownLink;
|
|
60
51
|
|
|
@@ -112,40 +103,16 @@ ${JSON.stringify(frontMatter, null, 2)}`;
|
|
|
112
103
|
}
|
|
113
104
|
}
|
|
114
105
|
|
|
115
|
-
|
|
106
|
+
const metadataPath = (function getMetadataPath() {
|
|
116
107
|
if (!isMDXPartial) {
|
|
117
|
-
|
|
118
|
-
if (options.metadataPath && typeof options.metadataPath === 'function') {
|
|
119
|
-
const metadata = options.metadataPath(filePath);
|
|
120
|
-
if (!metadata) {
|
|
121
|
-
return undefined;
|
|
122
|
-
}
|
|
123
|
-
if (typeof metadata === 'string') {
|
|
124
|
-
return {
|
|
125
|
-
metadataPath: metadata,
|
|
126
|
-
metadataContent: await readMetadataPath(metadata),
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
if (!metadata.metadataPath) {
|
|
130
|
-
throw new Error(`Metadata path missing for file ${filePath}`);
|
|
131
|
-
}
|
|
132
|
-
if (!metadata.metadataContent) {
|
|
133
|
-
throw new Error(`Metadata content missing for file ${filePath}`);
|
|
134
|
-
}
|
|
135
|
-
return metadata;
|
|
136
|
-
}
|
|
108
|
+
return options.metadataPath?.(filePath);
|
|
137
109
|
}
|
|
138
110
|
return undefined;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const metadata = await loadMetadata();
|
|
142
|
-
if (metadata) {
|
|
143
|
-
this.addDependency(metadata.metadataPath);
|
|
144
|
-
}
|
|
111
|
+
})();
|
|
145
112
|
|
|
146
113
|
const assets =
|
|
147
|
-
options.createAssets &&
|
|
148
|
-
? options.createAssets({
|
|
114
|
+
options.createAssets && !isMDXPartial
|
|
115
|
+
? options.createAssets({filePath, frontMatter})
|
|
149
116
|
: undefined;
|
|
150
117
|
|
|
151
118
|
const fileLoaderUtils = getFileLoaderUtils(compilerName === 'server');
|
|
@@ -156,8 +123,11 @@ ${JSON.stringify(frontMatter, null, 2)}`;
|
|
|
156
123
|
export const frontMatter = ${stringifyObject(frontMatter)};
|
|
157
124
|
export const contentTitle = ${stringifyObject(contentTitle)};
|
|
158
125
|
${
|
|
159
|
-
|
|
160
|
-
? `export
|
|
126
|
+
metadataPath
|
|
127
|
+
? `export {default as metadata} from '${aliasedSitePath(
|
|
128
|
+
metadataPath,
|
|
129
|
+
options.siteDir,
|
|
130
|
+
)}'`
|
|
161
131
|
: ''
|
|
162
132
|
}
|
|
163
133
|
${
|
package/src/utils.ts
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import fs from 'fs-extra';
|
|
9
8
|
import logger from '@docusaurus/logger';
|
|
10
9
|
import {escapePath, type WebpackCompilerName} from '@docusaurus/utils';
|
|
11
10
|
import {getProcessor, type SimpleProcessorResult} from './processor';
|
|
@@ -13,23 +12,6 @@ import {validateMDXFrontMatter} from './frontMatter';
|
|
|
13
12
|
import preprocessor from './preprocessor';
|
|
14
13
|
import type {Options} from './loader';
|
|
15
14
|
|
|
16
|
-
/**
|
|
17
|
-
* When this throws, it generally means that there's no metadata file associated
|
|
18
|
-
* with this MDX document. It can happen when using MDX partials (usually
|
|
19
|
-
* starting with _). That's why it's important to provide the `isMDXPartial`
|
|
20
|
-
* function in config
|
|
21
|
-
*/
|
|
22
|
-
export async function readMetadataPath(metadataPath: string): Promise<unknown> {
|
|
23
|
-
try {
|
|
24
|
-
return await fs.readJSON(metadataPath, 'utf8');
|
|
25
|
-
} catch (error) {
|
|
26
|
-
throw new Error(
|
|
27
|
-
logger.interpolate`MDX loader can't read MDX metadata file path=${metadataPath}. Maybe the isMDXPartial option function was not provided?`,
|
|
28
|
-
{cause: error as Error},
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
15
|
/**
|
|
34
16
|
* Converts assets an object with Webpack require calls code.
|
|
35
17
|
* This is useful for mdx files to reference co-located assets using relative
|