dumi 2.4.31 → 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>): string;
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 buildLoaderContextContent(techStacks, builtins = {}, routes = {}) {
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
- const modRef = `require(${JSON.stringify(found.modulePath)})`;
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
- const modRef = `require(${JSON.stringify(found.modulePath)})`;
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)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dumi",
3
- "version": "2.4.31",
3
+ "version": "2.4.33",
4
4
  "description": "📖 Documentation Generator of React Component",
5
5
  "keywords": [
6
6
  "generator",
@@ -11,7 +11,8 @@
11
11
  "jamstack",
12
12
  "markdown",
13
13
  "components",
14
- "documentation"
14
+ "documentation",
15
+ "utoopack"
15
16
  ],
16
17
  "homepage": "https://d.umijs.org",
17
18
  "bugs": {
@@ -68,9 +69,9 @@
68
69
  "@swc/core": "1.9.2",
69
70
  "@types/hast": "^2.3.5",
70
71
  "@types/mdast": "^3.0.12",
71
- "@umijs/bundler-utils": "^4.6.65",
72
- "@umijs/core": "^4.6.65",
73
- "@umijs/utils": "^4.6.65",
72
+ "@umijs/bundler-utils": "^4.6.66",
73
+ "@umijs/core": "^4.6.66",
74
+ "@umijs/utils": "^4.6.66",
74
75
  "animated-scroll-to": "^2.3.0",
75
76
  "classnames": "2.3.2",
76
77
  "codesandbox-import-utils": "^2.2.3",
@@ -122,7 +123,7 @@
122
123
  "sass": "^1.64.1",
123
124
  "sitemap": "^7.1.1",
124
125
  "sucrase": "^3.34.0",
125
- "umi": "^4.6.65",
126
+ "umi": "^4.6.66",
126
127
  "unified": "^10.1.2",
127
128
  "unist-util-visit": "^4.1.2",
128
129
  "unist-util-visit-parents": "^5.1.3",
@@ -146,8 +147,8 @@
146
147
  "@types/react-copy-to-clipboard": "^5.0.4",
147
148
  "@types/react-dom": "^18.2.7",
148
149
  "@typescript/native-preview": "7.0.0-dev.20260609.1",
149
- "@umijs/lint": "^4.6.65",
150
- "@umijs/plugins": "4.6.65",
150
+ "@umijs/lint": "^4.6.66",
151
+ "@umijs/plugins": "4.6.66",
151
152
  "eslint": "^8.46.0",
152
153
  "esno": "^4.7.0",
153
154
  "fast-glob": "^3.3.1",