dumi 2.4.48 → 2.4.49-alpha.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/dist/client/theme-api/DumiDemo/areDumiDemoPropsEqual.d.ts +1 -0
- package/dist/client/theme-api/DumiDemo/areDumiDemoPropsEqual.js +4 -0
- package/dist/client/theme-api/DumiDemo/index.js +2 -4
- package/dist/client/theme-api/routeMetaHMR.d.ts +5 -0
- package/dist/client/theme-api/routeMetaHMR.js +23 -0
- package/dist/client/theme-api/useRouteMeta.d.ts +2 -1
- package/dist/client/theme-api/useRouteMeta.js +35 -3
- package/dist/features/compile/index.d.ts +1 -0
- package/dist/features/compile/index.js +7 -2
- package/dist/features/compile/utoopackLoaders.js +12 -0
- package/dist/features/meta.js +2 -0
- package/dist/features/routes.js +18 -6
- package/dist/loaders/markdown/index.d.ts +8 -1
- package/dist/loaders/markdown/index.js +126 -9
- package/dist/templates/meta/index.ts.tpl +36 -1
- package/package.json +7 -7
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function areDumiDemoPropsEqual<T>(prev: T, next: T): boolean;
|
|
@@ -5,6 +5,7 @@ import React, { createElement } from 'react';
|
|
|
5
5
|
import Previewer from 'dumi/theme/builtins/Previewer';
|
|
6
6
|
import { useRenderer } from "../useRenderer";
|
|
7
7
|
import DemoErrorBoundary from "./DemoErrorBoundary";
|
|
8
|
+
import { areDumiDemoPropsEqual } from "./areDumiDemoPropsEqual";
|
|
8
9
|
var InternalDumiDemo = function InternalDumiDemo(props) {
|
|
9
10
|
var _useSiteData = useSiteData(),
|
|
10
11
|
historyType = _useSiteData.historyType;
|
|
@@ -43,10 +44,7 @@ var InternalDumiDemo = function InternalDumiDemo(props) {
|
|
|
43
44
|
"".concat(isHashRoute ? "#" : '').concat(basename).concat(SP_ROUTE_PREFIX, "demos/").concat(props.demo.id).concat(routeQuery)
|
|
44
45
|
}, props.previewerProps), props.previewerProps.iframe ? null : demoNode);
|
|
45
46
|
};
|
|
46
|
-
export var DumiDemo = /*#__PURE__*/React.memo(InternalDumiDemo,
|
|
47
|
-
// compare length for performance
|
|
48
|
-
return JSON.stringify(prev).length === JSON.stringify(next).length;
|
|
49
|
-
});
|
|
47
|
+
export var DumiDemo = /*#__PURE__*/React.memo(InternalDumiDemo, areDumiDemoPropsEqual);
|
|
50
48
|
if (process.env.NODE_ENV !== 'production') {
|
|
51
49
|
InternalDumiDemo.displayName = 'DumiDemo';
|
|
52
50
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
type RouteMetaHMRListener = () => void;
|
|
2
|
+
export declare function getRouteMetaHMRRevision(routeId: string): number;
|
|
3
|
+
export declare function subscribeRouteMetaHMR(routeId: string, listener: RouteMetaHMRListener): () => void;
|
|
4
|
+
export declare function notifyRouteMetaHMR(routeId: string): void;
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
var revisions = new Map();
|
|
2
|
+
var listeners = new Map();
|
|
3
|
+
export function getRouteMetaHMRRevision(routeId) {
|
|
4
|
+
var _revisions$get;
|
|
5
|
+
return (_revisions$get = revisions.get(routeId)) !== null && _revisions$get !== void 0 ? _revisions$get : 0;
|
|
6
|
+
}
|
|
7
|
+
export function subscribeRouteMetaHMR(routeId, listener) {
|
|
8
|
+
var _listeners$get;
|
|
9
|
+
var routeListeners = (_listeners$get = listeners.get(routeId)) !== null && _listeners$get !== void 0 ? _listeners$get : new Set();
|
|
10
|
+
routeListeners.add(listener);
|
|
11
|
+
listeners.set(routeId, routeListeners);
|
|
12
|
+
return function () {
|
|
13
|
+
routeListeners.delete(listener);
|
|
14
|
+
if (!routeListeners.size) listeners.delete(routeId);
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export function notifyRouteMetaHMR(routeId) {
|
|
18
|
+
var _listeners$get2;
|
|
19
|
+
revisions.set(routeId, getRouteMetaHMRRevision(routeId) + 1);
|
|
20
|
+
(_listeners$get2 = listeners.get(routeId)) === null || _listeners$get2 === void 0 || _listeners$get2.forEach(function (listener) {
|
|
21
|
+
return listener();
|
|
22
|
+
});
|
|
23
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { IRouteMeta } from './types';
|
|
1
|
+
import type { IRouteMeta, IRoutesById } from './types';
|
|
2
|
+
export declare function getCachedRouteMeta(route: IRoutesById[string], revision: number): IRouteMeta;
|
|
2
3
|
/**
|
|
3
4
|
* hook for get matched route
|
|
4
5
|
* @internal internal use. Do not use in your production code.
|
|
@@ -7,27 +7,35 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
|
7
7
|
import deepmerge from 'deepmerge';
|
|
8
8
|
import { getRouteMetaById, matchRoutes, useAppData, useLocation, useRouteData } from 'dumi';
|
|
9
9
|
import { useCallback, useState } from 'react';
|
|
10
|
+
import { getRouteMetaHMRRevision, subscribeRouteMetaHMR } from "./routeMetaHMR";
|
|
10
11
|
import { useIsomorphicLayoutEffect } from "./utils";
|
|
11
12
|
var cache = new Map();
|
|
12
13
|
var asyncCache = new Map();
|
|
14
|
+
var cacheRevisions = new Map();
|
|
13
15
|
var EMPTY_META = {
|
|
14
16
|
frontmatter: {},
|
|
15
17
|
toc: [],
|
|
16
18
|
texts: []
|
|
17
19
|
};
|
|
18
20
|
var ASYNC_META_PROPS = ['texts'];
|
|
19
|
-
function getCachedRouteMeta(route) {
|
|
21
|
+
export function getCachedRouteMeta(route, revision) {
|
|
20
22
|
var cacheKey = route.id;
|
|
23
|
+
if (cacheRevisions.get(cacheKey) !== revision) {
|
|
24
|
+
cache.delete(cacheKey);
|
|
25
|
+
asyncCache.delete(cacheKey);
|
|
26
|
+
cacheRevisions.set(cacheKey, revision);
|
|
27
|
+
}
|
|
21
28
|
if (!cache.get(cacheKey)) {
|
|
22
29
|
var _meta$tabs;
|
|
23
30
|
var merge = function merge() {
|
|
24
31
|
var meta = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : EMPTY_META;
|
|
25
32
|
if (route.meta) {
|
|
33
|
+
var _ref2, _ref3;
|
|
26
34
|
Object.keys(route.meta).forEach(function (key) {
|
|
27
35
|
var _ref, _ref$key;
|
|
28
36
|
(_ref$key = (_ref = meta)[key]) !== null && _ref$key !== void 0 ? _ref$key : _ref[key] = route.meta[key];
|
|
29
37
|
});
|
|
30
|
-
meta.frontmatter = deepmerge(meta.frontmatter, route.meta.frontmatter, {
|
|
38
|
+
meta.frontmatter = deepmerge((_ref2 = revision ? route.meta.frontmatter : meta.frontmatter) !== null && _ref2 !== void 0 ? _ref2 : {}, (_ref3 = revision ? meta.frontmatter : route.meta.frontmatter) !== null && _ref3 !== void 0 ? _ref3 : {}, {
|
|
31
39
|
arrayMerge: function arrayMerge(_destinationArray, sourceArray) {
|
|
32
40
|
return sourceArray;
|
|
33
41
|
}
|
|
@@ -45,6 +53,10 @@ function getCachedRouteMeta(route) {
|
|
|
45
53
|
// load async meta then replace cache
|
|
46
54
|
if (routeMetaPromise) {
|
|
47
55
|
asyncCache.set(cacheKey, routeMetaPromise.then(function (full) {
|
|
56
|
+
if (cacheRevisions.get(cacheKey) !== revision) {
|
|
57
|
+
var _cacheRevisions$get;
|
|
58
|
+
return getCachedRouteMeta(route, (_cacheRevisions$get = cacheRevisions.get(cacheKey)) !== null && _cacheRevisions$get !== void 0 ? _cacheRevisions$get : 0);
|
|
59
|
+
}
|
|
48
60
|
return cache.set(cacheKey, merge(full)).get(cacheKey);
|
|
49
61
|
}));
|
|
50
62
|
}
|
|
@@ -111,5 +123,25 @@ export var useMatchedRoute = function useMatchedRoute() {
|
|
|
111
123
|
*/
|
|
112
124
|
export var useRouteMeta = function useRouteMeta() {
|
|
113
125
|
var route = useMatchedRoute();
|
|
114
|
-
|
|
126
|
+
var _useState3 = useState(0),
|
|
127
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
128
|
+
forceUpdate = _useState4[1];
|
|
129
|
+
var revision = process.env.NODE_ENV === 'production' ? 0 : getRouteMetaHMRRevision(route.id);
|
|
130
|
+
useIsomorphicLayoutEffect(function () {
|
|
131
|
+
if (process.env.NODE_ENV === 'production') return;
|
|
132
|
+
var unsubscribe = subscribeRouteMetaHMR(route.id, function () {
|
|
133
|
+
forceUpdate(function (count) {
|
|
134
|
+
return count + 1;
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
// Do not miss an update dispatched between render and subscription.
|
|
139
|
+
if (getRouteMetaHMRRevision(route.id) !== revision) {
|
|
140
|
+
forceUpdate(function (count) {
|
|
141
|
+
return count + 1;
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
return unsubscribe;
|
|
145
|
+
}, [route.id, revision]);
|
|
146
|
+
return getCachedRouteMeta(route, revision);
|
|
115
147
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { IApi, IDumiTechStack } from '../../types';
|
|
2
2
|
export declare const techStacks: IDumiTechStack[];
|
|
3
|
+
export declare function replaceTechStacks(nextTechStacks: IDumiTechStack[]): void;
|
|
3
4
|
export declare function getUtoopackDemoAssetsFile(api: {
|
|
4
5
|
env: string;
|
|
5
6
|
paths: {
|
|
@@ -31,6 +31,7 @@ var compile_exports = {};
|
|
|
31
31
|
__export(compile_exports, {
|
|
32
32
|
default: () => compile_default,
|
|
33
33
|
getUtoopackDemoAssetsFile: () => getUtoopackDemoAssetsFile,
|
|
34
|
+
replaceTechStacks: () => replaceTechStacks,
|
|
34
35
|
techStacks: () => techStacks
|
|
35
36
|
});
|
|
36
37
|
module.exports = __toCommonJS(compile_exports);
|
|
@@ -44,6 +45,9 @@ var import_makoHooks = require("./makoHooks");
|
|
|
44
45
|
var import_utils2 = require("./utils");
|
|
45
46
|
var import_utoopackLoaders = require("./utoopackLoaders");
|
|
46
47
|
var techStacks = [];
|
|
48
|
+
function replaceTechStacks(nextTechStacks) {
|
|
49
|
+
techStacks.splice(0, techStacks.length, ...nextTechStacks);
|
|
50
|
+
}
|
|
47
51
|
function getUtoopackDemoAssetsFile(api) {
|
|
48
52
|
if (api.env !== "production" || !api.isPluginEnable("exportStatic")) {
|
|
49
53
|
return void 0;
|
|
@@ -113,8 +117,8 @@ var compile_default = (api) => {
|
|
|
113
117
|
// and `before` only insert before the last one
|
|
114
118
|
stage: -Infinity,
|
|
115
119
|
async fn() {
|
|
116
|
-
|
|
117
|
-
|
|
120
|
+
replaceTechStacks(
|
|
121
|
+
await api.applyPlugins({
|
|
118
122
|
key: "registerTechStack",
|
|
119
123
|
type: api.ApplyPluginsType.add
|
|
120
124
|
})
|
|
@@ -256,5 +260,6 @@ var compile_default = (api) => {
|
|
|
256
260
|
// Annotate the CommonJS export names for ESM import in node:
|
|
257
261
|
0 && (module.exports = {
|
|
258
262
|
getUtoopackDemoAssetsFile,
|
|
263
|
+
replaceTechStacks,
|
|
259
264
|
techStacks
|
|
260
265
|
});
|
|
@@ -328,6 +328,18 @@ var getUtoopackRules = (api, config = api.config) => {
|
|
|
328
328
|
],
|
|
329
329
|
as: "*.js"
|
|
330
330
|
},
|
|
331
|
+
// Keep page rendering on a separate module identity from lazy route
|
|
332
|
+
// metadata so React Refresh can accept text changes locally.
|
|
333
|
+
{
|
|
334
|
+
condition: { query: /^\?type=text-render$/ },
|
|
335
|
+
loaders: [
|
|
336
|
+
{
|
|
337
|
+
loader: mdLoaderPath,
|
|
338
|
+
options: { ...serializableBaseOpts, mode: "text-render" }
|
|
339
|
+
}
|
|
340
|
+
],
|
|
341
|
+
as: "*.js"
|
|
342
|
+
},
|
|
331
343
|
// extract demo index metadata from markdown
|
|
332
344
|
{
|
|
333
345
|
condition: { query: /^\?type=demo-index$/ },
|
package/dist/features/meta.js
CHANGED
|
@@ -84,7 +84,9 @@ var meta_default = (api) => {
|
|
|
84
84
|
path: "dumi/meta/index.ts",
|
|
85
85
|
tplPath: require.resolve("../templates/meta/index.ts.tpl"),
|
|
86
86
|
context: {
|
|
87
|
+
enableUtoopackHMR: useUtoopackDemoHMR,
|
|
87
88
|
metaFiles: parsedMetaFiles,
|
|
89
|
+
metaStructureHash: (0, import_utils.getContentHash)(JSON.stringify(parsedMetaFiles)),
|
|
88
90
|
chunkName: function chunkName() {
|
|
89
91
|
var _a;
|
|
90
92
|
if (!("file" in this)) {
|
package/dist/features/routes.js
CHANGED
|
@@ -39,6 +39,7 @@ var import_path = __toESM(require("path"));
|
|
|
39
39
|
var import_pluralize = require("pluralize");
|
|
40
40
|
var import_plugin_utils = require("umi/plugin-utils");
|
|
41
41
|
var CTX_LAYOUT_ID = "dumi-context-layout";
|
|
42
|
+
var ATOM_ROUTE_MARKDOWN_GLOB = "{*,*/index,*/index.*,*/README,*/README.*}.md";
|
|
42
43
|
function normalizeDocDir(docDir) {
|
|
43
44
|
return typeof docDir === "object" ? docDir : { dir: docDir };
|
|
44
45
|
}
|
|
@@ -79,12 +80,23 @@ function flatRoute(route, docLayoutId) {
|
|
|
79
80
|
}
|
|
80
81
|
var routes_default = (api) => {
|
|
81
82
|
api.describe({ key: "dumi:routes" });
|
|
82
|
-
api.addTmpGenerateWatcherPaths(
|
|
83
|
-
|
|
84
|
-
...api.config.resolve.atomDirs
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
83
|
+
api.addTmpGenerateWatcherPaths(() => {
|
|
84
|
+
const watcherPaths = [
|
|
85
|
+
...api.config.resolve.atomDirs.map(
|
|
86
|
+
({ dir }) => import_path.default.join(api.cwd, dir, ATOM_ROUTE_MARKDOWN_GLOB)
|
|
87
|
+
),
|
|
88
|
+
...api.config.resolve.docDirs.map(normalizeDocDir).map(({ dir }) => import_path.default.join(api.cwd, dir, "**/*.md"))
|
|
89
|
+
].map(import_plugin_utils.winPath);
|
|
90
|
+
if (api.env === "development" && api.config.utoopack) {
|
|
91
|
+
return watcherPaths.map((watcherPath) => ({
|
|
92
|
+
path: watcherPath,
|
|
93
|
+
// Existing Markdown files are already watched by the bundler. Only
|
|
94
|
+
// route topology changes need to regenerate Umi's temporary files.
|
|
95
|
+
events: ["add", "unlink"]
|
|
96
|
+
}));
|
|
97
|
+
}
|
|
98
|
+
return watcherPaths;
|
|
99
|
+
});
|
|
88
100
|
api.modifyDefaultConfig((memo) => {
|
|
89
101
|
if (api.userConfig.resolve) {
|
|
90
102
|
const keys = ["docDirs", "atomDirs"];
|
|
@@ -23,11 +23,18 @@ interface IMdLoaderFrontmatterModeOptions extends Omit<IMdLoaderDefaultModeOptio
|
|
|
23
23
|
interface IMdLoaderTextModeOptions extends Omit<IMdLoaderDefaultModeOptions, 'builtins' | 'mode'> {
|
|
24
24
|
mode: 'text';
|
|
25
25
|
}
|
|
26
|
-
|
|
26
|
+
interface IMdLoaderRenderTextModeOptions extends Omit<IMdLoaderDefaultModeOptions, 'builtins' | 'mode'> {
|
|
27
|
+
mode: 'text-render';
|
|
28
|
+
}
|
|
29
|
+
export type IMdLoaderOptions = IMdLoaderDefaultModeOptions | IMdLoaderDemosModeOptions | IMdLoaderDemoModeOptions | IMdLoaderFrontmatterModeOptions | IMdLoaderTextModeOptions | IMdLoaderRenderTextModeOptions | IMdLoaderDemoIndexModeOptions;
|
|
27
30
|
type MdLoaderCache = {
|
|
28
31
|
getSync: (key: string, defaultValue: any) => any;
|
|
29
32
|
};
|
|
30
33
|
export declare function getMdLoaderCacheSync<T>(cache: MdLoaderCache, key: string, defaultValue: T): T;
|
|
31
34
|
export declare function getDemoSourceFiles(demos?: IMdTransformerResult['meta']['demos']): string[];
|
|
35
|
+
export declare function emitDefault(this: any, opts: IMdLoaderDefaultModeOptions, ret: IMdTransformerResult): string;
|
|
36
|
+
export declare function emitFrontmatter(this: any, opts: IMdLoaderFrontmatterModeOptions, ret: IMdTransformerResult): string;
|
|
37
|
+
export declare function emitText(this: any, opts: IMdLoaderTextModeOptions, ret: IMdTransformerResult): string;
|
|
38
|
+
export declare function emitRenderText(this: any, _opts: IMdLoaderRenderTextModeOptions, ret: IMdTransformerResult): string;
|
|
32
39
|
export default function mdLoader(this: any, content: string): void;
|
|
33
40
|
export {};
|
|
@@ -30,6 +30,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
var markdown_exports = {};
|
|
31
31
|
__export(markdown_exports, {
|
|
32
32
|
default: () => mdLoader,
|
|
33
|
+
emitDefault: () => emitDefault,
|
|
34
|
+
emitFrontmatter: () => emitFrontmatter,
|
|
35
|
+
emitRenderText: () => emitRenderText,
|
|
36
|
+
emitText: () => emitText,
|
|
33
37
|
getDemoSourceFiles: () => getDemoSourceFiles,
|
|
34
38
|
getMdLoaderCacheSync: () => getMdLoaderCacheSync
|
|
35
39
|
});
|
|
@@ -93,6 +97,7 @@ function emitDefault(opts, ret) {
|
|
|
93
97
|
const { frontmatter, demos } = ret.meta;
|
|
94
98
|
const isTabContent = (0, import_tabs.isTabRouteFile)(this.resourcePath);
|
|
95
99
|
const wrapper = isTabContent ? "" : "DumiPage";
|
|
100
|
+
const textMode = import_utoopackLoaders.UTOOPACK_LOADER_CTX_KEY in opts && process.env.NODE_ENV !== "production" ? "text-render" : "text";
|
|
96
101
|
if (demos && opts.onResolveDemos) {
|
|
97
102
|
opts.onResolveDemos(demos);
|
|
98
103
|
}
|
|
@@ -125,7 +130,7 @@ import React, { Suspense } from 'react';
|
|
|
125
130
|
import { DumiPage } from 'dumi';
|
|
126
131
|
import { texts as ${import_rehypeText.CONTENT_TEXTS_OBJ_NAME} } from '${(0, import_plugin_utils.winPath)(
|
|
127
132
|
this.resourcePath
|
|
128
|
-
)}?type
|
|
133
|
+
)}?type=${textMode}';
|
|
129
134
|
|
|
130
135
|
// export named function for fastRefresh
|
|
131
136
|
// ref: https://github.com/pmmmwh/react-refresh-webpack-plugin/blob/main/docs/TROUBLESHOOTING.md#edits-always-lead-to-full-reload
|
|
@@ -295,24 +300,81 @@ function emitDemoIndex(opts, ret) {
|
|
|
295
300
|
${renderDemoIndex(this.resourcePath, opts, demos)}`;
|
|
296
301
|
}
|
|
297
302
|
function emitFrontmatter(opts, ret) {
|
|
298
|
-
const {
|
|
303
|
+
const { demos } = ret.meta;
|
|
304
|
+
const frontmatter = ret.meta.frontmatter;
|
|
305
|
+
const toc = ret.meta.toc ?? [];
|
|
299
306
|
const resourcePath = (0, import_plugin_utils.winPath)(this.resourcePath);
|
|
300
307
|
const isUtoopack = import_utoopackLoaders.UTOOPACK_LOADER_CTX_KEY in opts;
|
|
308
|
+
const enableUtoopackHMR = isUtoopack && process.env.NODE_ENV !== "production";
|
|
309
|
+
const routeMetaHMRPath = enableUtoopackHMR ? (0, import_plugin_utils.winPath)(require.resolve("../../client/theme-api/routeMetaHMR")) : void 0;
|
|
310
|
+
const routeId = getRouteId(opts, this.resourcePath);
|
|
301
311
|
const demoIndex = renderDemoIndex(this.resourcePath, opts, demos);
|
|
302
312
|
if (isUtoopack) {
|
|
313
|
+
const routeStructureHash = (0, import_utils.getContentHash)(
|
|
314
|
+
JSON.stringify({
|
|
315
|
+
atomId: frontmatter.atomId,
|
|
316
|
+
demoIds: demos == null ? void 0 : demos.map(({ id }) => id),
|
|
317
|
+
filename: frontmatter.filename,
|
|
318
|
+
group: frontmatter.group,
|
|
319
|
+
nav: frontmatter.nav,
|
|
320
|
+
order: frontmatter.order,
|
|
321
|
+
title: frontmatter.title
|
|
322
|
+
})
|
|
323
|
+
);
|
|
303
324
|
const rendered = import_plugin_utils.Mustache.render(
|
|
304
|
-
`
|
|
325
|
+
`{{#enableUtoopackHMR}}
|
|
326
|
+
import { notifyRouteMetaHMR } from {{{routeMetaHMRSpecifier}}};
|
|
327
|
+
{{/enableUtoopackHMR}}
|
|
328
|
+
import '${resourcePath}?watch=parent';
|
|
305
329
|
globalThis.__DUMI_FM__ = globalThis.__DUMI_FM__ || {};
|
|
306
330
|
globalThis.__DUMI_TOC__ = globalThis.__DUMI_TOC__ || {};
|
|
331
|
+
{{#enableUtoopackHMR}}
|
|
332
|
+
const hadPreviousMeta = Object.prototype.hasOwnProperty.call(globalThis.__DUMI_FM__, '${resourcePath}');
|
|
333
|
+
globalThis.__DUMI_META_STRUCTURE_HASH__ = globalThis.__DUMI_META_STRUCTURE_HASH__ || {};
|
|
334
|
+
const previousRouteStructureHash = globalThis.__DUMI_META_STRUCTURE_HASH__['${resourcePath}'];
|
|
335
|
+
const didRouteStructureChange = previousRouteStructureHash !== undefined && previousRouteStructureHash !== '{{{routeStructureHash}}}';
|
|
336
|
+
globalThis.__DUMI_META_STRUCTURE_HASH__['${resourcePath}'] = '{{{routeStructureHash}}}';
|
|
337
|
+
const nextFrontmatter = {{{frontmatter}}};
|
|
338
|
+
const nextToc = {{{toc}}};
|
|
339
|
+
const frontmatter = globalThis.__DUMI_FM__['${resourcePath}'] || {};
|
|
340
|
+
const toc = globalThis.__DUMI_TOC__['${resourcePath}'] || [];
|
|
341
|
+
Object.keys(frontmatter).forEach((key) => delete frontmatter[key]);
|
|
342
|
+
Object.assign(frontmatter, nextFrontmatter);
|
|
343
|
+
toc.splice(0, toc.length, ...nextToc);
|
|
344
|
+
globalThis.__DUMI_FM__['${resourcePath}'] = frontmatter;
|
|
345
|
+
globalThis.__DUMI_TOC__['${resourcePath}'] = toc;
|
|
346
|
+
{{/enableUtoopackHMR}}
|
|
347
|
+
{{^enableUtoopackHMR}}
|
|
307
348
|
globalThis.__DUMI_FM__['${resourcePath}'] = {{{frontmatter}}};
|
|
308
349
|
globalThis.__DUMI_TOC__['${resourcePath}'] = {{{toc}}};
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
{{
|
|
350
|
+
const frontmatter = globalThis.__DUMI_FM__['${resourcePath}'];
|
|
351
|
+
const toc = globalThis.__DUMI_TOC__['${resourcePath}'];
|
|
352
|
+
{{/enableUtoopackHMR}}
|
|
353
|
+
export { frontmatter, toc };
|
|
354
|
+
{{#enableUtoopackHMR}}
|
|
355
|
+
export const routeStructureHash = '{{{routeStructureHash}}}';
|
|
356
|
+
{{/enableUtoopackHMR}}
|
|
357
|
+
{{{demoIndex}}}
|
|
358
|
+
{{#enableUtoopackHMR}}
|
|
359
|
+
if (module.hot) {
|
|
360
|
+
module.hot.accept();
|
|
361
|
+
if (didRouteStructureChange) {
|
|
362
|
+
module.hot.invalidate();
|
|
363
|
+
}{{#routeId}} else if (hadPreviousMeta) {
|
|
364
|
+
notifyRouteMetaHMR({{{routeId}}});
|
|
365
|
+
}{{/routeId}}{{^routeId}} else if (hadPreviousMeta) {
|
|
366
|
+
module.hot.invalidate();
|
|
367
|
+
}{{/routeId}}
|
|
368
|
+
}
|
|
369
|
+
{{/enableUtoopackHMR}}`,
|
|
312
370
|
{
|
|
313
371
|
toc: JSON.stringify(toc),
|
|
314
372
|
frontmatter: JSON.stringify(frontmatter),
|
|
315
|
-
demoIndex
|
|
373
|
+
demoIndex,
|
|
374
|
+
enableUtoopackHMR,
|
|
375
|
+
routeId: routeId ? JSON.stringify(routeId) : void 0,
|
|
376
|
+
routeMetaHMRSpecifier: routeMetaHMRPath ? JSON.stringify(routeMetaHMRPath) : void 0,
|
|
377
|
+
routeStructureHash
|
|
316
378
|
}
|
|
317
379
|
);
|
|
318
380
|
return rendered;
|
|
@@ -330,10 +392,45 @@ export const frontmatter = new Proxy({{{frontmatter}}}, {});
|
|
|
330
392
|
);
|
|
331
393
|
}
|
|
332
394
|
function emitText(opts, ret) {
|
|
333
|
-
const
|
|
395
|
+
const texts = ret.meta.texts ?? [];
|
|
396
|
+
const resourcePath = (0, import_plugin_utils.winPath)(this.resourcePath);
|
|
397
|
+
const enableUtoopackHMR = import_utoopackLoaders.UTOOPACK_LOADER_CTX_KEY in opts && process.env.NODE_ENV !== "production";
|
|
398
|
+
if (enableUtoopackHMR) {
|
|
399
|
+
const routeId = getRouteId(opts, this.resourcePath);
|
|
400
|
+
const routeMetaHMRSpecifier = JSON.stringify(
|
|
401
|
+
(0, import_plugin_utils.winPath)(require.resolve("../../client/theme-api/routeMetaHMR"))
|
|
402
|
+
);
|
|
403
|
+
return import_plugin_utils.Mustache.render(
|
|
404
|
+
`import { notifyRouteMetaHMR } from {{{routeMetaHMRSpecifier}}};
|
|
405
|
+
import {{{watchSpecifier}}};
|
|
406
|
+
globalThis.__DUMI_TEXTS__ = globalThis.__DUMI_TEXTS__ || {};
|
|
407
|
+
const hadPreviousTexts = Object.prototype.hasOwnProperty.call(globalThis.__DUMI_TEXTS__, {{{resourceSpecifier}}});
|
|
408
|
+
const nextTexts = {{{texts}}};
|
|
409
|
+
const texts = globalThis.__DUMI_TEXTS__[{{{resourceSpecifier}}}] || [];
|
|
410
|
+
texts.splice(0, texts.length, ...nextTexts);
|
|
411
|
+
globalThis.__DUMI_TEXTS__[{{{resourceSpecifier}}}] = texts;
|
|
412
|
+
export { texts };
|
|
413
|
+
|
|
414
|
+
if (module.hot) {
|
|
415
|
+
module.hot.accept();
|
|
416
|
+
{{#routeId}}if (hadPreviousTexts) {
|
|
417
|
+
notifyRouteMetaHMR({{{routeId}}});
|
|
418
|
+
}{{/routeId}}{{^routeId}}if (hadPreviousTexts) {
|
|
419
|
+
module.hot.invalidate();
|
|
420
|
+
}{{/routeId}}
|
|
421
|
+
}`,
|
|
422
|
+
{
|
|
423
|
+
resourceSpecifier: JSON.stringify(resourcePath),
|
|
424
|
+
routeId: routeId ? JSON.stringify(routeId) : void 0,
|
|
425
|
+
routeMetaHMRSpecifier,
|
|
426
|
+
texts: JSON.stringify(texts),
|
|
427
|
+
watchSpecifier: JSON.stringify(`${resourcePath}?watch=parent`)
|
|
428
|
+
}
|
|
429
|
+
);
|
|
430
|
+
}
|
|
334
431
|
return import_plugin_utils.Mustache.render(
|
|
335
432
|
`
|
|
336
|
-
import '${
|
|
433
|
+
import '${resourcePath}?watch=parent';
|
|
337
434
|
export const texts = {{{texts}}};
|
|
338
435
|
`,
|
|
339
436
|
{
|
|
@@ -341,6 +438,20 @@ function emitText(opts, ret) {
|
|
|
341
438
|
}
|
|
342
439
|
);
|
|
343
440
|
}
|
|
441
|
+
function emitRenderText(_opts, ret) {
|
|
442
|
+
return import_plugin_utils.Mustache.render(
|
|
443
|
+
`
|
|
444
|
+
import {{{watchSpecifier}}};
|
|
445
|
+
export const texts = {{{texts}}};
|
|
446
|
+
`,
|
|
447
|
+
{
|
|
448
|
+
texts: JSON.stringify(ret.meta.texts ?? []),
|
|
449
|
+
watchSpecifier: JSON.stringify(
|
|
450
|
+
`${(0, import_plugin_utils.winPath)(this.resourcePath)}?watch=parent`
|
|
451
|
+
)
|
|
452
|
+
}
|
|
453
|
+
);
|
|
454
|
+
}
|
|
344
455
|
function emit(opts, ret) {
|
|
345
456
|
const { demos, embeds } = ret.meta;
|
|
346
457
|
embeds.forEach((file) => this.addDependency(file));
|
|
@@ -358,6 +469,8 @@ function emit(opts, ret) {
|
|
|
358
469
|
return emitFrontmatter.call(this, opts, ret);
|
|
359
470
|
case "text":
|
|
360
471
|
return emitText.call(this, opts, ret);
|
|
472
|
+
case "text-render":
|
|
473
|
+
return emitRenderText.call(this, opts, ret);
|
|
361
474
|
default:
|
|
362
475
|
return emitDefault.call(this, opts, ret);
|
|
363
476
|
}
|
|
@@ -444,6 +557,10 @@ function mdLoader(content) {
|
|
|
444
557
|
}
|
|
445
558
|
// Annotate the CommonJS export names for ESM import in node:
|
|
446
559
|
0 && (module.exports = {
|
|
560
|
+
emitDefault,
|
|
561
|
+
emitFrontmatter,
|
|
562
|
+
emitRenderText,
|
|
563
|
+
emitText,
|
|
447
564
|
getDemoSourceFiles,
|
|
448
565
|
getMdLoaderCacheSync
|
|
449
566
|
});
|
|
@@ -3,11 +3,16 @@
|
|
|
3
3
|
import { frontmatter as fm{{{index}}}, toc as t{{{index}}}, demoIndex as dmi{{{index}}} } from '{{{file}}}?type=frontmatter';
|
|
4
4
|
{{/loadDemoIndex}}
|
|
5
5
|
{{^loadDemoIndex}}
|
|
6
|
-
import { frontmatter as fm{{{index}}}, toc as t{{{index}}} } from '{{{file}}}?type=frontmatter';
|
|
6
|
+
import { frontmatter as fm{{{index}}}, toc as t{{{index}}}{{#enableUtoopackHMR}}{{#isMarkdown}}, routeStructureHash as rsh{{{index}}}{{/isMarkdown}}{{/enableUtoopackHMR}} } from '{{{file}}}?type=frontmatter';
|
|
7
7
|
{{/loadDemoIndex}}
|
|
8
8
|
{{/metaFiles}}
|
|
9
9
|
|
|
10
|
+
{{#enableUtoopackHMR}}
|
|
11
|
+
const nextFilesMeta = {
|
|
12
|
+
{{/enableUtoopackHMR}}
|
|
13
|
+
{{^enableUtoopackHMR}}
|
|
10
14
|
export const filesMeta = {
|
|
15
|
+
{{/enableUtoopackHMR}}
|
|
11
16
|
{{#metaFiles}}
|
|
12
17
|
'{{{id}}}': {
|
|
13
18
|
frontmatter: fm{{{index}}},
|
|
@@ -25,4 +30,34 @@ export const filesMeta = {
|
|
|
25
30
|
{{/metaFiles}}
|
|
26
31
|
}
|
|
27
32
|
|
|
33
|
+
{{#enableUtoopackHMR}}
|
|
34
|
+
const dumiGlobal = globalThis as any;
|
|
35
|
+
dumiGlobal.__DUMI_FILES_META__ = dumiGlobal.__DUMI_FILES_META__ || {};
|
|
36
|
+
const filesMeta = dumiGlobal.__DUMI_FILES_META__;
|
|
37
|
+
Object.keys(filesMeta).forEach((id) => delete filesMeta[id]);
|
|
38
|
+
Object.assign(filesMeta, nextFilesMeta);
|
|
39
|
+
export { filesMeta };
|
|
40
|
+
|
|
41
|
+
const nextMetaStructureHash = JSON.stringify([
|
|
42
|
+
'{{{metaStructureHash}}}',
|
|
43
|
+
{{#metaFiles}}
|
|
44
|
+
{{#isMarkdown}}rsh{{{index}}},{{/isMarkdown}}
|
|
45
|
+
{{^isMarkdown}}JSON.stringify([fm{{{index}}}, t{{{index}}}]),{{/isMarkdown}}
|
|
46
|
+
{{/metaFiles}}
|
|
47
|
+
]);
|
|
48
|
+
const previousMetaStructureHash = dumiGlobal.__DUMI_META_INDEX_STRUCTURE_HASH__;
|
|
49
|
+
const didMetaStructureChange = previousMetaStructureHash !== undefined && previousMetaStructureHash !== nextMetaStructureHash;
|
|
50
|
+
dumiGlobal.__DUMI_META_INDEX_STRUCTURE_HASH__ = nextMetaStructureHash;
|
|
51
|
+
|
|
52
|
+
if (module.hot) {
|
|
53
|
+
// Dynamic imports have an async-loader wrapper module. Accept at this
|
|
54
|
+
// stable metadata boundary as well as inside the loaded text module so an
|
|
55
|
+
// already-loaded search chunk cannot invalidate the global runtime graph.
|
|
56
|
+
module.hot.accept();
|
|
57
|
+
if (didMetaStructureChange) {
|
|
58
|
+
module.hot.invalidate();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
{{/enableUtoopackHMR}}
|
|
62
|
+
|
|
28
63
|
export { tabs as tabsMeta } from './tabs';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dumi",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.49-alpha.0",
|
|
4
4
|
"description": "📖 Documentation Generator of React Component",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"generator",
|
|
@@ -69,9 +69,9 @@
|
|
|
69
69
|
"@swc/core": "1.9.2",
|
|
70
70
|
"@types/hast": "^2.3.5",
|
|
71
71
|
"@types/mdast": "^3.0.12",
|
|
72
|
-
"@umijs/bundler-utils": "^4.
|
|
73
|
-
"@umijs/core": "^4.
|
|
74
|
-
"@umijs/utils": "^4.
|
|
72
|
+
"@umijs/bundler-utils": "^4.7.3",
|
|
73
|
+
"@umijs/core": "^4.7.3",
|
|
74
|
+
"@umijs/utils": "^4.7.3",
|
|
75
75
|
"animated-scroll-to": "^2.3.0",
|
|
76
76
|
"classnames": "2.3.2",
|
|
77
77
|
"codesandbox-import-utils": "^2.2.3",
|
|
@@ -123,7 +123,7 @@
|
|
|
123
123
|
"sass": "^1.64.1",
|
|
124
124
|
"sitemap": "^7.1.1",
|
|
125
125
|
"sucrase": "^3.34.0",
|
|
126
|
-
"umi": "^4.
|
|
126
|
+
"umi": "^4.7.3",
|
|
127
127
|
"unified": "^10.1.2",
|
|
128
128
|
"unist-util-visit": "^4.1.2",
|
|
129
129
|
"unist-util-visit-parents": "^5.1.3",
|
|
@@ -147,8 +147,8 @@
|
|
|
147
147
|
"@types/react-copy-to-clipboard": "^5.0.4",
|
|
148
148
|
"@types/react-dom": "^18.2.7",
|
|
149
149
|
"@typescript/native-preview": "7.0.0-dev.20260623.1",
|
|
150
|
-
"@umijs/lint": "^4.
|
|
151
|
-
"@umijs/plugins": "4.
|
|
150
|
+
"@umijs/lint": "^4.7.3",
|
|
151
|
+
"@umijs/plugins": "4.7.3",
|
|
152
152
|
"eslint": "^8.46.0",
|
|
153
153
|
"esno": "^4.7.0",
|
|
154
154
|
"fast-glob": "^3.3.1",
|