dumi 2.4.23 → 2.4.26

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.
@@ -35,12 +35,39 @@ __export(compile_exports, {
35
35
  module.exports = __toCommonJS(compile_exports);
36
36
  var import_react = __toESM(require("../../techStacks/react"));
37
37
  var import_utils = require("../../utils");
38
+ var import_enhanced_resolve = __toESM(require("enhanced-resolve"));
38
39
  var import_fs = __toESM(require("fs"));
39
40
  var import_path = __toESM(require("path"));
40
41
  var import_assets = require("../assets");
41
42
  var import_makoHooks = require("./makoHooks");
42
43
  var import_utils2 = require("./utils");
44
+ var import_utoopackLoaders = require("./utoopackLoaders");
43
45
  var techStacks = [];
46
+ function normalizeMakoAliases(alias, cwd) {
47
+ const normalizedAlias = { ...alias };
48
+ const resolver = import_enhanced_resolve.default.create.sync({
49
+ alias,
50
+ conditionNames: ["import", "require", "default", "browser", "node"],
51
+ extensions: [".js", ".jsx", ".ts", ".tsx", ".mjs", ".json"],
52
+ exportsFields: [],
53
+ mainFields: ["browser", "module", "main"]
54
+ });
55
+ Object.keys(alias).forEach((key) => {
56
+ if (!key.endsWith("$"))
57
+ return;
58
+ const makoAliasKey = key.slice(0, -1);
59
+ const aliasValue = alias[key];
60
+ delete normalizedAlias[key];
61
+ if (makoAliasKey in normalizedAlias)
62
+ return;
63
+ try {
64
+ normalizedAlias[makoAliasKey] = resolver(cwd, aliasValue);
65
+ } catch {
66
+ normalizedAlias[makoAliasKey] = aliasValue;
67
+ }
68
+ });
69
+ return normalizedAlias;
70
+ }
44
71
  var compile_default = (api) => {
45
72
  api.describe({ key: "dumi:compile" });
46
73
  api.register({
@@ -87,6 +114,22 @@ var compile_default = (api) => {
87
114
  );
88
115
  }
89
116
  });
117
+ api.onGenerateFiles({
118
+ fn() {
119
+ var _a;
120
+ if (api.config.utoopack) {
121
+ api.writeTmpFile({
122
+ noPluginDir: true,
123
+ path: import_utoopackLoaders.LOADER_CTX_FILENAME,
124
+ content: (0, import_utoopackLoaders.buildLoaderContextContent)(
125
+ techStacks,
126
+ ((_a = api.service.themeData) == null ? void 0 : _a.builtins) ?? {},
127
+ api.appData.routes ?? {}
128
+ )
129
+ });
130
+ }
131
+ }
132
+ });
90
133
  api.addRuntimePlugin(
91
134
  () => techStacks.reduce((acc, techStack) => {
92
135
  var _a;
@@ -165,6 +208,7 @@ var compile_default = (api) => {
165
208
  fn: (memo) => {
166
209
  var _a;
167
210
  if (memo.mako || ((_a = memo.ssr) == null ? void 0 : _a.builder) === "mako") {
211
+ memo.alias = normalizeMakoAliases(memo.alias, api.cwd);
168
212
  memo.mako ?? (memo.mako = {});
169
213
  memo.mako.plugins = [
170
214
  {
@@ -175,6 +219,25 @@ var compile_default = (api) => {
175
219
  return memo;
176
220
  }
177
221
  });
222
+ api.modifyConfig({
223
+ before: "utoopack",
224
+ fn: (memo) => {
225
+ var _a;
226
+ if (memo.utoopack) {
227
+ memo.utoopack = {
228
+ ...memo.utoopack,
229
+ module: {
230
+ ...memo.utoopack.module || {},
231
+ rules: {
232
+ ...((_a = memo.utoopack.module) == null ? void 0 : _a.rules) || {},
233
+ ...(0, import_utoopackLoaders.getUtoopackRules)(api)
234
+ }
235
+ }
236
+ };
237
+ }
238
+ return memo;
239
+ }
240
+ });
178
241
  };
179
242
  // Annotate the CommonJS export names for ESM import in node:
180
243
  0 && (module.exports = {
@@ -0,0 +1,8 @@
1
+ import type { IApi, IDumiTechStack } from "../../types";
2
+ export declare const UTOOPACK_LOADER_CTX_KEY = "__dumiLoaderContextPath";
3
+ export declare const LOADER_CTX_FILENAME = "dumi-loader-ctx.cjs";
4
+ export declare function buildLoaderContextContent(techStacks: IDumiTechStack[], builtins?: Record<string, {
5
+ specifier: string;
6
+ source: string;
7
+ }>, routes?: Record<string, unknown>): string;
8
+ export declare const getUtoopackRules: (api: IApi) => Record<string, unknown>;
@@ -0,0 +1,229 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/features/compile/utoopackLoaders.ts
30
+ var utoopackLoaders_exports = {};
31
+ __export(utoopackLoaders_exports, {
32
+ LOADER_CTX_FILENAME: () => LOADER_CTX_FILENAME,
33
+ UTOOPACK_LOADER_CTX_KEY: () => UTOOPACK_LOADER_CTX_KEY,
34
+ buildLoaderContextContent: () => buildLoaderContextContent,
35
+ getUtoopackRules: () => getUtoopackRules
36
+ });
37
+ module.exports = __toCommonJS(utoopackLoaders_exports);
38
+ var import_path = __toESM(require("path"));
39
+ var import_utils = require("./utils");
40
+ var mdLoaderPath = require.resolve("../../loaders/markdown");
41
+ var UTOOPACK_LOADER_CTX_KEY = "__dumiLoaderContextPath";
42
+ var LOADER_CTX_FILENAME = "dumi-loader-ctx.cjs";
43
+ function toSerializable(value) {
44
+ return JSON.parse(JSON.stringify(value));
45
+ }
46
+ function findInRequireCache(target) {
47
+ for (const [filename, mod] of Object.entries(require.cache)) {
48
+ if (!(mod == null ? void 0 : mod.exports))
49
+ continue;
50
+ const exp = mod.exports;
51
+ if (exp === target)
52
+ return { modulePath: filename, exportName: "module.exports" };
53
+ if ((exp == null ? void 0 : exp.default) === target)
54
+ return { modulePath: filename, exportName: "default" };
55
+ for (const [k, v] of Object.entries(exp)) {
56
+ if (v === target)
57
+ return { modulePath: filename, exportName: k };
58
+ }
59
+ }
60
+ return null;
61
+ }
62
+ function buildLoaderContextContent(techStacks, builtins = {}, routes = {}) {
63
+ const refs = [];
64
+ for (const ts of techStacks) {
65
+ const ctor = ts.constructor;
66
+ if (ctor !== Object) {
67
+ const found = findInRequireCache(ctor);
68
+ 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})()`);
72
+ }
73
+ } else {
74
+ const found = findInRequireCache(ts);
75
+ 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);
79
+ }
80
+ }
81
+ }
82
+ return `'use strict';
83
+ exports.techStacks = [${refs.join(", ")}];
84
+ exports.builtins = ${JSON.stringify(builtins)};
85
+ exports.routes = ${JSON.stringify(routes)};
86
+ `;
87
+ }
88
+ var getUtoopackRules = (api) => {
89
+ const disableLiveDemo = (0, import_utils.shouldDisabledLiveDemo)(api);
90
+ const loaderContextPath = import_path.default.join(
91
+ api.paths.absTmpPath,
92
+ LOADER_CTX_FILENAME
93
+ );
94
+ const cfgResolve = api.config.resolve ?? {};
95
+ const serializableBaseOpts = toSerializable({
96
+ cwd: api.cwd,
97
+ alias: api.config.alias || {},
98
+ resolve: {
99
+ atomDirs: cfgResolve.atomDirs ?? [{ type: "component", dir: "src" }],
100
+ docDirs: cfgResolve.docDirs ?? ["docs"],
101
+ codeBlockMode: cfgResolve.codeBlockMode ?? "active",
102
+ forceKebabCaseRouting: cfgResolve.forceKebabCaseRouting ?? true,
103
+ ...cfgResolve.entryFile ? { entryFile: cfgResolve.entryFile } : {}
104
+ },
105
+ routes: {},
106
+ builtins: {},
107
+ locales: api.config.locales || [],
108
+ pkg: api.pkg,
109
+ disableLiveDemo,
110
+ [UTOOPACK_LOADER_CTX_KEY]: loaderContextPath
111
+ });
112
+ return {
113
+ // handle ?watch=parent virtual module: return empty content to establish file-watching dependency
114
+ "**/*": [
115
+ {
116
+ condition: { query: /^\?watch=parent$/ },
117
+ loaders: [require.resolve("../../loaders/null")],
118
+ as: "*.js"
119
+ },
120
+ // handle raw content for demo source display (?dumi-raw)
121
+ {
122
+ condition: { query: /^\?dumi-raw$/ },
123
+ loaders: [
124
+ require.resolve("../../loaders/post-raw"),
125
+ require.resolve("raw-loader"),
126
+ require.resolve("../../loaders/pre-raw")
127
+ ],
128
+ as: "*.js"
129
+ },
130
+ // handle external demo component files (?techStack=xxx)
131
+ // techStacks are NOT serializable; pass loaderContextPath and hydrate in the loader
132
+ {
133
+ condition: { query: /^\?techStack=.*$/ },
134
+ loaders: [
135
+ {
136
+ loader: require.resolve("../../loaders/demo"),
137
+ options: toSerializable({
138
+ cwd: api.cwd,
139
+ [UTOOPACK_LOADER_CTX_KEY]: loaderContextPath
140
+ })
141
+ }
142
+ ],
143
+ as: "*.js"
144
+ }
145
+ ],
146
+ // extract frontmatter/toc metadata from JS/TS page components (?type=frontmatter)
147
+ // NOTE:
148
+ // - Markdown ?type=frontmatter is already handled by the '*.md' rule below.
149
+ // - After the md loader outputs JS, utoopack will expose that virtual module as
150
+ // '*.md.js?type=frontmatter'. Without the extra path guard here, this JS rule
151
+ // runs again and page-loader overwrites markdown frontmatter with filename-based
152
+ // fallbacks like "Docs" / "C Md".
153
+ // - Excluding '*.md.js' keeps the markdown frontmatter result intact while still
154
+ // allowing real JS/TS page components to use page-loader.
155
+ "*.{js,jsx,ts,tsx}": {
156
+ condition: {
157
+ all: [
158
+ { query: /^\?type=frontmatter$/ },
159
+ { not: { path: /\.md\.js$/ } }
160
+ ]
161
+ },
162
+ loaders: [require.resolve("../../loaders/page")],
163
+ as: "*.js"
164
+ },
165
+ // handle markdown files with different modes based on query type
166
+ "*.md": [
167
+ {
168
+ condition: { query: /^\?type=frontmatter$/ },
169
+ loaders: [
170
+ {
171
+ loader: mdLoaderPath,
172
+ options: { ...serializableBaseOpts, mode: "frontmatter" }
173
+ }
174
+ ],
175
+ as: "*.js"
176
+ },
177
+ // extract plain text for full-text search
178
+ {
179
+ condition: { query: /^\?type=text$/ },
180
+ loaders: [
181
+ {
182
+ loader: mdLoaderPath,
183
+ options: { ...serializableBaseOpts, mode: "text" }
184
+ }
185
+ ],
186
+ as: "*.js"
187
+ },
188
+ // extract demo index metadata from markdown
189
+ {
190
+ condition: { query: /^\?type=demo-index$/ },
191
+ loaders: [
192
+ {
193
+ loader: mdLoaderPath,
194
+ options: { ...serializableBaseOpts, mode: "demo-index" }
195
+ }
196
+ ],
197
+ as: "*.js"
198
+ },
199
+ // compile inline demo code blocks
200
+ {
201
+ condition: { query: /^\?type=demo$/ },
202
+ loaders: [
203
+ {
204
+ loader: mdLoaderPath,
205
+ options: { ...serializableBaseOpts, mode: "demo" }
206
+ }
207
+ ],
208
+ as: "*.js"
209
+ },
210
+ // default: transform markdown into a React page component
211
+ {
212
+ loaders: [
213
+ {
214
+ loader: mdLoaderPath,
215
+ options: serializableBaseOpts
216
+ }
217
+ ],
218
+ as: "*.js"
219
+ }
220
+ ]
221
+ };
222
+ };
223
+ // Annotate the CommonJS export names for ESM import in node:
224
+ 0 && (module.exports = {
225
+ LOADER_CTX_FILENAME,
226
+ UTOOPACK_LOADER_CTX_KEY,
227
+ buildLoaderContextContent,
228
+ getUtoopackRules
229
+ });
@@ -92,7 +92,7 @@ var derivative_default = (api) => {
92
92
  }
93
93
  (0, import_assert.default)(
94
94
  !api.config.ssr || api.config.ssr.builder === "webpack" || api.config.ssr.builder === "mako",
95
- "Only `webpack` and mako` builder is supported in SSR mode!"
95
+ "Only `webpack` and `mako` builder is supported in SSR mode!"
96
96
  );
97
97
  (0, import_assert.default)(
98
98
  ((_a = api.config.cssLoader) == null ? void 0 : _a.modules) === void 0 && api.config.cssLoaderModules === void 0,
@@ -32,7 +32,7 @@ __export(exports_exports, {
32
32
  default: () => exports_default
33
33
  });
34
34
  module.exports = __toCommonJS(exports_exports);
35
- var import_plugin_utils = require("umi/plugin-utils");
35
+ var import_utils = require("../utils");
36
36
  var exports_default = (api) => {
37
37
  api.describe({ key: "dumi:exports" });
38
38
  api.modifyConfig((memo) => {
@@ -44,7 +44,7 @@ var exports_default = (api) => {
44
44
  noPluginDir: true,
45
45
  path: "dumi/exports.ts",
46
46
  content: `export * from '../exports';
47
- export * from '${(0, import_plugin_utils.winPath)(require.resolve("../client/theme-api"))}';
47
+ export * from '${(0, import_utils.toImportSpecifier)(require.resolve("../client/theme-api"))}';
48
48
  export * from './meta/exports';`
49
49
  });
50
50
  });
@@ -33,8 +33,8 @@ __export(locales_exports, {
33
33
  });
34
34
  module.exports = __toCommonJS(locales_exports);
35
35
  var import_constants = require("../constants");
36
+ var import_utils = require("../utils");
36
37
  var import_path = __toESM(require("path"));
37
- var import_plugin_utils = require("umi/plugin-utils");
38
38
  var locales_default = (api) => {
39
39
  var _a;
40
40
  api.describe({
@@ -114,10 +114,10 @@ export const messages = ${JSON.stringify(
114
114
  content: `
115
115
  import { history } from 'dumi';
116
116
  import React, { useState, useLayoutEffect, useCallback, type ReactNode } from 'react';
117
- import { RawIntlProvider, createIntl, createIntlCache } from '${(0, import_plugin_utils.winPath)(
117
+ import { RawIntlProvider, createIntl, createIntlCache } from '${(0, import_utils.toImportSpecifier)(
118
118
  import_path.default.dirname(require.resolve("react-intl/package"))
119
119
  )}';
120
- import { useIsomorphicLayoutEffect } from '${(0, import_plugin_utils.winPath)(
120
+ import { useIsomorphicLayoutEffect } from '${(0, import_utils.toImportSpecifier)(
121
121
  require.resolve("../client/theme-api/utils")
122
122
  )}'
123
123
  import { locales, messages } from './config';
@@ -98,8 +98,12 @@ var meta_default = (api) => {
98
98
  path: "dumi/meta/runtime.ts",
99
99
  tplPath: require.resolve("../templates/meta/runtime.ts.tpl"),
100
100
  context: {
101
- deepmerge: (0, import_plugin_utils.winPath)(import_path.default.dirname(require.resolve("deepmerge/package"))),
102
- rc_util: (0, import_plugin_utils.winPath)(import_path.default.dirname(require.resolve("rc-util/package")))
101
+ deepmerge: (0, import_utils.toImportSpecifier)(
102
+ import_path.default.dirname(require.resolve("deepmerge/package"))
103
+ ),
104
+ rc_util: (0, import_utils.toImportSpecifier)(
105
+ import_path.default.dirname(require.resolve("rc-util/package"))
106
+ )
103
107
  }
104
108
  });
105
109
  api.writeTmpFile({
@@ -55,6 +55,10 @@ function filterIgnoredProps(props) {
55
55
  }
56
56
  var parser_default = (api) => {
57
57
  let prevData;
58
+ const fallbackData = {
59
+ components: {},
60
+ functions: {}
61
+ };
58
62
  const writeAtomsMetaFile = (data) => {
59
63
  const components = import_utils.lodash.mapValues(data.components, (component) => ({
60
64
  ...component,
@@ -114,7 +118,14 @@ var parser_default = (api) => {
114
118
  });
115
119
  api.onGenerateFiles(async () => {
116
120
  if (api.env === "production") {
117
- writeAtomsMetaFile(await api.service.atomParser.parse());
121
+ try {
122
+ writeAtomsMetaFile(await api.service.atomParser.parse());
123
+ } catch (err) {
124
+ api.logger.warn(
125
+ `apiParser parse failed, fallback to empty metadata: ${err instanceof Error ? err.message : String(err)}`
126
+ );
127
+ writeAtomsMetaFile(fallbackData);
128
+ }
118
129
  } else if (prevData) {
119
130
  writeAtomsMetaFile(prevData);
120
131
  }
@@ -42,7 +42,9 @@ var import_path = __toESM(require("path"));
42
42
  var import_plugin_utils = require("umi/plugin-utils");
43
43
  var import_derivative = require("../derivative");
44
44
  var import_loader = __toESM(require("./loader"));
45
- var DEFAULT_THEME_PATH = import_path.default.join(__dirname, "../../../theme-default");
45
+ var DEFAULT_THEME_PATH = (0, import_plugin_utils.winPath)(
46
+ import_path.default.join(__dirname, "../../../theme-default")
47
+ );
46
48
  var DEFAULT_LOADING_PATH = (0, import_plugin_utils.winPath)(
47
49
  import_path.default.resolve(__dirname, "../../client/pages/Loading")
48
50
  );
@@ -163,19 +165,27 @@ var theme_default = (api) => {
163
165
  });
164
166
  api.modifyConfig((memo) => {
165
167
  var _a, _b, _c, _d;
168
+ themeMapKeys.forEach((key) => {
169
+ Object.values(pkgThemeData[key] || {}).forEach((item) => {
170
+ memo.alias[`dumi/theme/${key}/${item.specifier}`] = (0, import_plugin_utils.winPath)(
171
+ item.source
172
+ );
173
+ });
174
+ });
166
175
  if (localThemeData) {
167
176
  themeMapKeys.forEach((key) => {
168
177
  Object.values(localThemeData[key] || {}).forEach((item) => {
169
- memo.alias[`dumi/theme/${key}/${item.specifier}`] = item.source;
178
+ memo.alias[`dumi/theme/${key}/${item.specifier}`] = (0, import_plugin_utils.winPath)(
179
+ item.source
180
+ );
170
181
  });
171
182
  });
172
183
  }
173
184
  memo.alias["dumi/theme"] = "dumi/theme-original";
174
- memo.alias["dumi/theme-original"] = import_path.default.join(
175
- api.paths.absTmpPath,
176
- "dumi/theme"
185
+ memo.alias["dumi/theme-original"] = (0, import_plugin_utils.winPath)(
186
+ import_path.default.join(api.paths.absTmpPath, "dumi/theme")
177
187
  );
178
- memo.alias["dumi/theme-default"] = DEFAULT_THEME_PATH;
188
+ memo.alias["dumi/theme-default"] = (0, import_plugin_utils.winPath)(DEFAULT_THEME_PATH);
179
189
  memo.extraBabelIncludes ?? (memo.extraBabelIncludes = []);
180
190
  memo.extraBabelIncludes.push(
181
191
  import_path.default.resolve(__dirname, "../../client/theme-api")
@@ -233,11 +243,11 @@ var theme_default = (api) => {
233
243
  api.writeTmpFile({
234
244
  noPluginDir: true,
235
245
  path: "dumi/theme/loading.tsx",
236
- content: `${enableNProgress ? `import nprogress from '${(0, import_plugin_utils.winPath)(
246
+ content: `${enableNProgress ? `import nprogress from '${(0, import_utils.toImportSpecifier)(
237
247
  import_path.default.dirname(require.resolve("nprogress/package"))
238
248
  )}';
239
249
  import './nprogress.css';` : ""}
240
- import UserLoading from '${globalLoading}';
250
+ import UserLoading from '${(0, import_utils.toImportSpecifier)(globalLoading)}';
241
251
  import React, { useLayoutEffect, type FC } from 'react';
242
252
  import { useSiteData } from 'dumi';
243
253
 
@@ -271,10 +281,12 @@ export default DumiLoading;
271
281
  const exports = await getModuleExports(item.source);
272
282
  const contents = [];
273
283
  if (exports.includes("default")) {
274
- contents.push(`export { default } from '${item.source}';`);
284
+ contents.push(
285
+ `export { default } from '${(0, import_utils.toImportSpecifier)(item.source)}';`
286
+ );
275
287
  }
276
288
  if (exports.some((exp) => exp !== "default")) {
277
- contents.push(`export * from '${item.source}';`);
289
+ contents.push(`export * from '${(0, import_utils.toImportSpecifier)(item.source)}';`);
278
290
  }
279
291
  api.writeTmpFile({
280
292
  noPluginDir: true,
@@ -293,9 +305,13 @@ export default DumiLoading;
293
305
  path: "dumi/theme/ContextWrapper.tsx",
294
306
  tplPath: require.resolve("../../templates/ContextWrapper.ts.tpl"),
295
307
  context: {
296
- contextPath: (0, import_plugin_utils.winPath)(require.resolve("../../client/theme-api/context")),
297
- defaultExport: hasDefaultExport ? `import entryDefaultExport from '${(0, import_plugin_utils.winPath)(entryFile)}';` : "",
298
- namedExport: hasNamedExport ? `import * as entryMemberExports from '${(0, import_plugin_utils.winPath)(entryFile)}';` : "",
308
+ contextPath: (0, import_utils.toImportSpecifier)(
309
+ require.resolve("../../client/theme-api/context")
310
+ ),
311
+ defaultExport: hasDefaultExport ? `import entryDefaultExport from '${(0, import_utils.toImportSpecifier)(entryFile)}';` : "",
312
+ namedExport: hasNamedExport ? `import * as entryMemberExports from '${(0, import_utils.toImportSpecifier)(
313
+ entryFile
314
+ )}';` : "",
299
315
  hasDefaultExport,
300
316
  hasNamedExport,
301
317
  pkg: JSON.stringify(
@@ -309,7 +325,9 @@ export default DumiLoading;
309
325
  api.config.themeConfig
310
326
  )
311
327
  ),
312
- rc_util: (0, import_plugin_utils.winPath)(import_path.default.dirname(require.resolve("rc-util/package"))),
328
+ rc_util: (0, import_utils.toImportSpecifier)(
329
+ import_path.default.dirname(require.resolve("rc-util/package"))
330
+ ),
313
331
  _2_level_nav_available: api.appData._2LevelNavAvailable
314
332
  }
315
333
  });
@@ -405,7 +423,9 @@ export default DumiLoading;
405
423
  },
406
424
  {
407
425
  specifier: "{ setPluginManager as setDumiPluginManager }",
408
- source: (0, import_plugin_utils.winPath)(require.resolve("../../client/theme-api/utils"))
426
+ source: (0, import_utils.toImportSpecifier)(
427
+ require.resolve("../../client/theme-api/utils")
428
+ )
409
429
  }
410
430
  ]);
411
431
  api.addEntryCode(() => "setDumiPluginManager(getDumiPluginManager());");
@@ -22,13 +22,19 @@ __export(demo_exports, {
22
22
  default: () => demoLoader
23
23
  });
24
24
  module.exports = __toCommonJS(demo_exports);
25
+ var import_utoopackLoaders = require("../../features/compile/utoopackLoaders");
25
26
  var import_utils = require("@umijs/utils");
26
27
  function demoLoader(raw) {
27
28
  const opts = this.getOptions();
29
+ let techStacks = opts.techStacks;
30
+ if (!techStacks && opts[import_utoopackLoaders.UTOOPACK_LOADER_CTX_KEY]) {
31
+ const ctx = require(opts[import_utoopackLoaders.UTOOPACK_LOADER_CTX_KEY]);
32
+ techStacks = ctx.techStacks;
33
+ }
28
34
  const techStackName = new URLSearchParams(this.resourceQuery).get(
29
35
  "techStack"
30
36
  );
31
- const techStack = opts.techStacks.find((t) => t.name === techStackName);
37
+ const techStack = techStacks.find((t) => t.name === techStackName);
32
38
  let code = techStack.transformCode(raw, {
33
39
  type: "external",
34
40
  fileAbsPath: this.resourcePath
@@ -32,6 +32,7 @@ __export(markdown_exports, {
32
32
  default: () => mdLoader
33
33
  });
34
34
  module.exports = __toCommonJS(markdown_exports);
35
+ var import_utoopackLoaders = require("../../features/compile/utoopackLoaders");
35
36
  var import_tabs = require("../../features/tabs");
36
37
  var import_utils = require("../../utils");
37
38
  var import_fs = __toESM(require("fs"));
@@ -62,11 +63,11 @@ function emitDefault(opts, ret) {
62
63
  if (frontmatter.atomId && opts.onResolveAtomMeta) {
63
64
  opts.onResolveAtomMeta(frontmatter.atomId, frontmatter);
64
65
  }
65
- const dependencies = this.getDependencies().slice(1).filter((filePath) => {
66
- return !filePath.includes("node_modules");
67
- });
66
+ const embeddedMdFiles = (ret.meta.embeds ?? []).filter(
67
+ (filePath) => filePath.endsWith(".md") && !filePath.includes("node_modules")
68
+ );
68
69
  return `${Object.values(opts.builtins).map((item) => `import ${item.specifier} from '${(0, import_plugin_utils.winPath)(item.source)}';`).join("\n")}
69
- ${dependencies.filter((dep) => dep.endsWith(".md")).map(
70
+ ${embeddedMdFiles.map(
70
71
  (md) => `
71
72
  import '${(0, import_plugin_utils.winPath)(md)}?watch=parent';
72
73
  `
@@ -134,7 +135,7 @@ function emitDemo(opts, ret) {
134
135
  }, []);
135
136
  return import_plugin_utils.Mustache.render(
136
137
  `import React from 'react';
137
- import '${(0, import_plugin_utils.winPath)(this.getDependencies()[0])}?watch=parent';
138
+ import '${(0, import_plugin_utils.winPath)(this.resourcePath)}?watch=parent';
138
139
  {{#dedupedDemosDeps}}
139
140
  import * as {{{specifier}}} from '{{{key}}}';
140
141
  {{/dedupedDemosDeps}}
@@ -162,7 +163,7 @@ export const demos = {
162
163
  var _a;
163
164
  if (((_a = asset.dependencies[file]) == null ? void 0 : _a.type) === "FILE") {
164
165
  let assetValue = `{{{require('-!${resolveMap[file]}?dumi-raw').default}}}`;
165
- if (process.env.OKAM) {
166
+ if (process.env.OKAM || opts[import_utoopackLoaders.UTOOPACK_LOADER_CTX_KEY]) {
166
167
  assetValue = `{{{require('${resolveMap[file]}?dumi-raw').default}}}`;
167
168
  }
168
169
  asset = import_plugin_utils.lodash.cloneDeep(asset);
@@ -222,7 +223,7 @@ function emitDemoIndex(opts, ret) {
222
223
  const { demos } = ret.meta;
223
224
  return import_plugin_utils.Mustache.render(
224
225
  `
225
- import '${(0, import_plugin_utils.winPath)(this.getDependencies()[0])}?watch=parent';
226
+ import '${(0, import_plugin_utils.winPath)(this.resourcePath)}?watch=parent';
226
227
  export const demoIndex = {
227
228
  ids: {{{ids}}},
228
229
  getter: {{{getter}}}
@@ -239,11 +240,28 @@ function emitDemoIndex(opts, ret) {
239
240
  }
240
241
  function emitFrontmatter(opts, ret) {
241
242
  const { frontmatter, toc } = ret.meta;
243
+ const resourcePath = (0, import_plugin_utils.winPath)(this.resourcePath);
244
+ const isUtoopack = import_utoopackLoaders.UTOOPACK_LOADER_CTX_KEY in opts;
245
+ if (isUtoopack) {
246
+ const rendered = import_plugin_utils.Mustache.render(
247
+ `import '${resourcePath}?watch=parent';
248
+ globalThis.__DUMI_FM__ = globalThis.__DUMI_FM__ || {};
249
+ globalThis.__DUMI_TOC__ = globalThis.__DUMI_TOC__ || {};
250
+ globalThis.__DUMI_FM__['${resourcePath}'] = {{{frontmatter}}};
251
+ globalThis.__DUMI_TOC__['${resourcePath}'] = {{{toc}}};
252
+ export const frontmatter = globalThis.__DUMI_FM__['${resourcePath}'];
253
+ export const toc = globalThis.__DUMI_TOC__['${resourcePath}'];`,
254
+ {
255
+ toc: JSON.stringify(toc),
256
+ frontmatter: JSON.stringify(frontmatter)
257
+ }
258
+ );
259
+ return rendered;
260
+ }
242
261
  return import_plugin_utils.Mustache.render(
243
- `
244
- import '${(0, import_plugin_utils.winPath)(this.getDependencies()[0])}?watch=parent';
245
- export const toc = {{{toc}}};
246
- export const frontmatter = {{{frontmatter}}};`,
262
+ `import '${resourcePath}?watch=parent';
263
+ export const toc = new Proxy({{{toc}}}, {});
264
+ export const frontmatter = new Proxy({{{frontmatter}}}, {});`,
247
265
  {
248
266
  toc: JSON.stringify(toc),
249
267
  frontmatter: JSON.stringify(frontmatter)
@@ -254,7 +272,7 @@ function emitText(opts, ret) {
254
272
  const { texts } = ret.meta;
255
273
  return import_plugin_utils.Mustache.render(
256
274
  `
257
- import '${(0, import_plugin_utils.winPath)(this.getDependencies()[0])}?watch=parent';
275
+ import '${(0, import_plugin_utils.winPath)(this.resourcePath)}?watch=parent';
258
276
  export const texts = {{{texts}}};
259
277
  `,
260
278
  {
@@ -291,7 +309,21 @@ function getDepsCacheKey(deps = []) {
291
309
  var deferrer = {};
292
310
  var depsMapping = {};
293
311
  function mdLoader(content) {
294
- const opts = this.getOptions();
312
+ var _a;
313
+ let opts = this.getOptions();
314
+ const loaderContextPath = opts[import_utoopackLoaders.UTOOPACK_LOADER_CTX_KEY];
315
+ if (loaderContextPath) {
316
+ const ctx = require(loaderContextPath);
317
+ if (!((_a = opts.techStacks) == null ? void 0 : _a.length)) {
318
+ opts.techStacks = ctx.techStacks;
319
+ }
320
+ if (ctx.builtins && !Object.keys(opts.builtins ?? {}).length) {
321
+ opts.builtins = ctx.builtins;
322
+ }
323
+ if (ctx.routes && !Object.keys(opts.routes ?? {}).length) {
324
+ opts.routes = ctx.routes;
325
+ }
326
+ }
295
327
  const cb = this.async();
296
328
  if (process.env.NODE_ENV === "production" && ["onResolveDemos", "onResolveAtomMeta"].some((k) => k in opts)) {
297
329
  this.cacheable(false);
@@ -65,9 +65,12 @@ function rehypeLink(opts) {
65
65
  });
66
66
  } else if (parsedUrl.pathname && /^[^/]+/.test(parsedUrl.pathname)) {
67
67
  const routes = Object.values(opts.routes);
68
- const basePath = routes.find(
68
+ const currentRoute = routes.find(
69
69
  (route) => route.file === hostAbsPath
70
- ).absPath;
70
+ );
71
+ if (!currentRoute)
72
+ return;
73
+ const basePath = currentRoute.absPath;
71
74
  const htmlTargetPath = import_url.default.resolve(basePath, parsedUrl.pathname);
72
75
  const rr6TargetPath = (0, import_plugin_utils.winPath)(
73
76
  import_path.default.resolve(basePath, parsedUrl.pathname)
package/dist/utils.d.ts CHANGED
@@ -60,3 +60,8 @@ export declare function runLoaders(options: RunLoaderOption, callback: (err: Nod
60
60
  * check if version is in range
61
61
  */
62
62
  export declare function isVersionInRange(version: string, range: string | Range, options?: RangeOptions): boolean;
63
+ /**
64
+ * normalize module specifier for generated import/export statements
65
+ * keep package/bare specifiers unchanged and normalize path separators
66
+ */
67
+ export declare function toImportSpecifier(source: string): string;
package/dist/utils.js CHANGED
@@ -42,6 +42,7 @@ __export(utils_exports, {
42
42
  isVersionInRange: () => isVersionInRange,
43
43
  parseCodeFrontmatter: () => parseCodeFrontmatter,
44
44
  runLoaders: () => runLoaders,
45
+ toImportSpecifier: () => toImportSpecifier,
45
46
  tryFatherBuildConfigs: () => tryFatherBuildConfigs
46
47
  });
47
48
  module.exports = __toCommonJS(utils_exports);
@@ -181,6 +182,13 @@ function isVersionInRange(version, range, options = { includePrerelease: true })
181
182
  }
182
183
  return false;
183
184
  }
185
+ function toImportSpecifier(source) {
186
+ if (!source)
187
+ return source;
188
+ if (/^(?:node|data|file):/.test(source))
189
+ return source;
190
+ return (0, import_plugin_utils.winPath)(source);
191
+ }
184
192
  // Annotate the CommonJS export names for ESM import in node:
185
193
  0 && (module.exports = {
186
194
  _setFSCacheDir,
@@ -196,5 +204,6 @@ function isVersionInRange(version, range, options = { includePrerelease: true })
196
204
  isVersionInRange,
197
205
  parseCodeFrontmatter,
198
206
  runLoaders,
207
+ toImportSpecifier,
199
208
  tryFatherBuildConfigs
200
209
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dumi",
3
- "version": "2.4.23",
3
+ "version": "2.4.26",
4
4
  "description": "📖 Documentation Generator of React Component",
5
5
  "keywords": [
6
6
  "generator",
@@ -65,9 +65,9 @@
65
65
  "@swc/core": "1.9.2",
66
66
  "@types/hast": "^2.3.5",
67
67
  "@types/mdast": "^3.0.12",
68
- "@umijs/bundler-utils": "^4.3.0",
69
- "@umijs/core": "^4.3.0",
70
- "@umijs/utils": "^4.3.0",
68
+ "@umijs/bundler-utils": "^4.6.53",
69
+ "@umijs/core": "^4.6.53",
70
+ "@umijs/utils": "^4.6.53",
71
71
  "animated-scroll-to": "^2.3.0",
72
72
  "classnames": "2.3.2",
73
73
  "codesandbox-import-utils": "^2.2.3",
@@ -119,7 +119,7 @@
119
119
  "sass": "^1.64.1",
120
120
  "sitemap": "^7.1.1",
121
121
  "sucrase": "^3.34.0",
122
- "umi": "^4.3.0",
122
+ "umi": "^4.6.53",
123
123
  "unified": "^10.1.2",
124
124
  "unist-util-visit": "^4.1.2",
125
125
  "unist-util-visit-parents": "^5.1.3",
@@ -142,7 +142,7 @@
142
142
  "@types/react": "^18.2.17",
143
143
  "@types/react-copy-to-clipboard": "^5.0.4",
144
144
  "@types/react-dom": "^18.2.7",
145
- "@umijs/lint": "^4.3.0",
145
+ "@umijs/lint": "^4.6.53",
146
146
  "@umijs/plugins": "4.0.32",
147
147
  "eslint": "^8.46.0",
148
148
  "esno": "^4.7.0",
@@ -177,7 +177,7 @@
177
177
  ],
178
178
  "scripts": {
179
179
  "build": "father build && npm run build:crates",
180
- "build:crates": "cargo build --target wasm32-wasip1 -r --out-dir compiled/crates -Z unstable-options",
180
+ "build:crates": "cargo build --target wasm32-wasip1 -r --artifact-dir compiled/crates -Z unstable-options",
181
181
  "build:deps": "node scripts/pre-bundle-worker.js && father prebundle",
182
182
  "build:suites": "pnpm run --filter=\"./suites/**\" build",
183
183
  "dev": "father dev",