dumi 2.4.32 → 2.4.33
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.
|
@@ -124,7 +124,9 @@ var compile_default = (api) => {
|
|
|
124
124
|
content: (0, import_utoopackLoaders.buildLoaderContextContent)(
|
|
125
125
|
techStacks,
|
|
126
126
|
((_a = api.service.themeData) == null ? void 0 : _a.builtins) ?? {},
|
|
127
|
-
api.appData.routes ?? {}
|
|
127
|
+
api.appData.routes ?? {},
|
|
128
|
+
api.config.extraRemarkPlugins,
|
|
129
|
+
api.config.extraRehypePlugins
|
|
128
130
|
)
|
|
129
131
|
});
|
|
130
132
|
}
|
|
@@ -4,5 +4,5 @@ export declare const LOADER_CTX_FILENAME = "dumi-loader-ctx.cjs";
|
|
|
4
4
|
export declare function buildLoaderContextContent(techStacks: IDumiTechStack[], builtins?: Record<string, {
|
|
5
5
|
specifier: string;
|
|
6
6
|
source: string;
|
|
7
|
-
}>, routes?: Record<string, unknown
|
|
7
|
+
}>, routes?: Record<string, unknown>, extraRemarkPlugins?: IApi['config']['extraRemarkPlugins'], extraRehypePlugins?: IApi['config']['extraRehypePlugins']): string;
|
|
8
8
|
export declare const getUtoopackRules: (api: IApi, config?: IApi['config']) => Record<string, unknown>;
|
|
@@ -59,23 +59,47 @@ function findInRequireCache(target) {
|
|
|
59
59
|
}
|
|
60
60
|
return null;
|
|
61
61
|
}
|
|
62
|
-
function
|
|
62
|
+
function toRequireRef(found) {
|
|
63
|
+
const modRef = `require(${JSON.stringify(found.modulePath)})`;
|
|
64
|
+
return found.exportName === "module.exports" ? modRef : `(${modRef})[${JSON.stringify(found.exportName)}]`;
|
|
65
|
+
}
|
|
66
|
+
function toPluginTargetRef(target) {
|
|
67
|
+
if (typeof target === "string")
|
|
68
|
+
return JSON.stringify(target);
|
|
69
|
+
const found = findInRequireCache(target);
|
|
70
|
+
if (!found) {
|
|
71
|
+
const name = target.name ? ` "${target.name}"` : "";
|
|
72
|
+
throw new Error(
|
|
73
|
+
`Utoopack markdown loader requires extra unified plugin function${name} to be exported from a module.`
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
return toRequireRef(found);
|
|
77
|
+
}
|
|
78
|
+
function toPluginRefs(plugins = []) {
|
|
79
|
+
return `[${plugins.map((plugin) => {
|
|
80
|
+
if (Array.isArray(plugin)) {
|
|
81
|
+
const [target, options] = plugin;
|
|
82
|
+
const optionsRef = typeof options === "undefined" ? "undefined" : JSON.stringify(options);
|
|
83
|
+
return `[${toPluginTargetRef(
|
|
84
|
+
target
|
|
85
|
+
)}, ${optionsRef}]`;
|
|
86
|
+
}
|
|
87
|
+
return toPluginTargetRef(plugin);
|
|
88
|
+
}).join(", ")}]`;
|
|
89
|
+
}
|
|
90
|
+
function buildLoaderContextContent(techStacks, builtins = {}, routes = {}, extraRemarkPlugins = [], extraRehypePlugins = []) {
|
|
63
91
|
const refs = [];
|
|
64
92
|
for (const ts of techStacks) {
|
|
65
93
|
const ctor = ts.constructor;
|
|
66
94
|
if (ctor !== Object) {
|
|
67
95
|
const found = findInRequireCache(ctor);
|
|
68
96
|
if (found) {
|
|
69
|
-
|
|
70
|
-
const ctorRef = found.exportName === "module.exports" ? modRef : `(${modRef})[${JSON.stringify(found.exportName)}]`;
|
|
71
|
-
refs.push(`new (${ctorRef})()`);
|
|
97
|
+
refs.push(`new (${toRequireRef(found)})()`);
|
|
72
98
|
}
|
|
73
99
|
} else {
|
|
74
100
|
const found = findInRequireCache(ts);
|
|
75
101
|
if (found) {
|
|
76
|
-
|
|
77
|
-
const ref = found.exportName === "module.exports" ? modRef : `(${modRef})[${JSON.stringify(found.exportName)}]`;
|
|
78
|
-
refs.push(ref);
|
|
102
|
+
refs.push(toRequireRef(found));
|
|
79
103
|
}
|
|
80
104
|
}
|
|
81
105
|
}
|
|
@@ -83,6 +107,8 @@ function buildLoaderContextContent(techStacks, builtins = {}, routes = {}) {
|
|
|
83
107
|
exports.techStacks = [${refs.join(", ")}];
|
|
84
108
|
exports.builtins = ${JSON.stringify(builtins)};
|
|
85
109
|
exports.routes = ${JSON.stringify(routes)};
|
|
110
|
+
exports.extraRemarkPlugins = ${toPluginRefs(extraRemarkPlugins)};
|
|
111
|
+
exports.extraRehypePlugins = ${toPluginRefs(extraRehypePlugins)};
|
|
86
112
|
`;
|
|
87
113
|
}
|
|
88
114
|
var getUtoopackRules = (api, config = api.config) => {
|
|
@@ -317,7 +317,7 @@ function getDepsCacheKey(deps = []) {
|
|
|
317
317
|
var deferrer = {};
|
|
318
318
|
var depsMapping = {};
|
|
319
319
|
function mdLoader(content) {
|
|
320
|
-
var _a;
|
|
320
|
+
var _a, _b, _c;
|
|
321
321
|
let opts = this.getOptions();
|
|
322
322
|
const loaderContextPath = opts[import_utoopackLoaders.UTOOPACK_LOADER_CTX_KEY];
|
|
323
323
|
if (loaderContextPath) {
|
|
@@ -331,6 +331,12 @@ function mdLoader(content) {
|
|
|
331
331
|
if (ctx.routes && !Object.keys(opts.routes ?? {}).length) {
|
|
332
332
|
opts.routes = ctx.routes;
|
|
333
333
|
}
|
|
334
|
+
if (ctx.extraRemarkPlugins && !((_b = opts.extraRemarkPlugins) == null ? void 0 : _b.length)) {
|
|
335
|
+
opts.extraRemarkPlugins = ctx.extraRemarkPlugins;
|
|
336
|
+
}
|
|
337
|
+
if (ctx.extraRehypePlugins && !((_c = opts.extraRehypePlugins) == null ? void 0 : _c.length)) {
|
|
338
|
+
opts.extraRehypePlugins = ctx.extraRehypePlugins;
|
|
339
|
+
}
|
|
334
340
|
}
|
|
335
341
|
const cb = this.async();
|
|
336
342
|
if (process.env.NODE_ENV === "production" && ["onResolveDemos", "onResolveAtomMeta"].some((k) => k in opts)) {
|