dumi 2.4.48-alpha.0 → 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/assetParsers/block.js +14 -23
- package/dist/client/pages/Demo/index.js +3 -50
- 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.d.ts +0 -2
- package/dist/client/theme-api/DumiDemo/index.js +7 -67
- package/dist/client/theme-api/routeMetaHMR.d.ts +5 -0
- package/dist/client/theme-api/routeMetaHMR.js +23 -0
- package/dist/client/theme-api/types.d.ts +0 -1
- 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 +4 -19
- package/dist/features/compile/utoopackLoaders.d.ts +0 -3
- package/dist/features/compile/utoopackLoaders.js +19 -25
- package/dist/features/meta.js +2 -0
- package/dist/features/routes.js +18 -6
- package/dist/loaders/markdown/index.d.ts +8 -35
- package/dist/loaders/markdown/index.js +178 -332
- package/dist/loaders/markdown/transformer/index.d.ts +0 -4
- package/dist/loaders/markdown/transformer/rehypeDemo.js +82 -129
- package/dist/techStacks/react.js +1 -2
- package/dist/templates/meta/index.ts.tpl +36 -1
- package/dist/types.d.ts +0 -6
- package/dist/utils.d.ts +1 -2
- package/dist/utils.js +2 -8
- package/package.json +7 -9
- package/theme-default/slots/SourceCodeEditor/index.js +0 -3
- package/dist/client/theme-api/DumiDemo/hmr.d.ts +0 -5
- package/dist/client/theme-api/DumiDemo/hmr.js +0 -67
- package/dist/loaders/markdown/sharedCache.d.ts +0 -11
- package/dist/loaders/markdown/sharedCache.js +0 -131
|
@@ -29,16 +29,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
29
29
|
// src/loaders/markdown/index.ts
|
|
30
30
|
var markdown_exports = {};
|
|
31
31
|
__export(markdown_exports, {
|
|
32
|
-
addDemoFileDependency: () => addDemoFileDependency,
|
|
33
|
-
createDependencyReader: () => createDependencyReader,
|
|
34
|
-
createStableTransform: () => createStableTransform,
|
|
35
32
|
default: () => mdLoader,
|
|
36
|
-
|
|
33
|
+
emitDefault: () => emitDefault,
|
|
34
|
+
emitFrontmatter: () => emitFrontmatter,
|
|
35
|
+
emitRenderText: () => emitRenderText,
|
|
36
|
+
emitText: () => emitText,
|
|
37
37
|
getDemoSourceFiles: () => getDemoSourceFiles,
|
|
38
|
-
|
|
39
|
-
getMdLoaderCacheResult: () => getMdLoaderCacheResult,
|
|
40
|
-
getMdLoaderCacheSync: () => getMdLoaderCacheSync,
|
|
41
|
-
getMdTransformCacheKeys: () => getMdTransformCacheKeys
|
|
38
|
+
getMdLoaderCacheSync: () => getMdLoaderCacheSync
|
|
42
39
|
});
|
|
43
40
|
module.exports = __toCommonJS(markdown_exports);
|
|
44
41
|
var import_utoopackLoaders = require("../../features/compile/utoopackLoaders");
|
|
@@ -47,61 +44,8 @@ var import_utils = require("../../utils");
|
|
|
47
44
|
var import_fs = __toESM(require("fs"));
|
|
48
45
|
var import_path = __toESM(require("path"));
|
|
49
46
|
var import_plugin_utils = require("umi/plugin-utils");
|
|
50
|
-
var import_sharedCache = require("./sharedCache");
|
|
51
47
|
var import_transformer = __toESM(require("./transformer"));
|
|
52
48
|
var import_rehypeText = require("./transformer/rehypeText");
|
|
53
|
-
var MD_LOADER_RUNTIME_OPTION_KEYS = [
|
|
54
|
-
"mode",
|
|
55
|
-
"builtins",
|
|
56
|
-
"onResolveDemos",
|
|
57
|
-
"onResolveAtomMeta",
|
|
58
|
-
"demoAssetsFile",
|
|
59
|
-
"cacheDirectory",
|
|
60
|
-
"cacheEpoch"
|
|
61
|
-
];
|
|
62
|
-
function getMdTransformCacheKeys({
|
|
63
|
-
resourcePath,
|
|
64
|
-
content,
|
|
65
|
-
useUtoopackDemoHMR,
|
|
66
|
-
opts
|
|
67
|
-
}) {
|
|
68
|
-
const depsHintKey = [
|
|
69
|
-
resourcePath,
|
|
70
|
-
useUtoopackDemoHMR,
|
|
71
|
-
JSON.stringify(import_plugin_utils.lodash.omit(opts, MD_LOADER_RUNTIME_OPTION_KEYS))
|
|
72
|
-
].join(":");
|
|
73
|
-
return {
|
|
74
|
-
depsHintKey,
|
|
75
|
-
baseCacheKey: [depsHintKey, (0, import_utils.getContentHash)(content)].join(":")
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
function getStatRevision(stat) {
|
|
79
|
-
return [stat.dev, stat.ino, stat.mode, stat.size, stat.mtimeNs, stat.ctimeNs].map(String).join(":");
|
|
80
|
-
}
|
|
81
|
-
async function getFileRevision(file) {
|
|
82
|
-
return getStatRevision(await import_fs.default.promises.stat(file, { bigint: true }));
|
|
83
|
-
}
|
|
84
|
-
function isMissingFsError(err) {
|
|
85
|
-
return (err == null ? void 0 : err.code) === "ENOENT" || (err == null ? void 0 : err.code) === "ENOTDIR";
|
|
86
|
-
}
|
|
87
|
-
async function getMissingParentRevision(file) {
|
|
88
|
-
let current = file;
|
|
89
|
-
while (true) {
|
|
90
|
-
try {
|
|
91
|
-
const revision = getStatRevision(
|
|
92
|
-
await import_fs.default.promises.stat(current, { bigint: true })
|
|
93
|
-
);
|
|
94
|
-
return `${import_path.default.normalize(current)}:${current === file ? "<appeared>:" : ""}${revision}`;
|
|
95
|
-
} catch (err) {
|
|
96
|
-
if (!isMissingFsError(err))
|
|
97
|
-
throw err;
|
|
98
|
-
const parent = import_path.default.dirname(current);
|
|
99
|
-
if (parent === current)
|
|
100
|
-
return `${current}:<missing>`;
|
|
101
|
-
current = parent;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
49
|
function isMalformedCacheError(err) {
|
|
106
50
|
return err instanceof SyntaxError || err instanceof Error && /Unexpected end of JSON input|Unterminated string in JSON/.test(
|
|
107
51
|
err.message
|
|
@@ -116,40 +60,25 @@ function getMdLoaderCacheSync(cache, key, defaultValue) {
|
|
|
116
60
|
throw err;
|
|
117
61
|
}
|
|
118
62
|
}
|
|
119
|
-
function
|
|
63
|
+
function getDemoSidecarFiles(file) {
|
|
120
64
|
const { dir, name } = import_path.default.parse(file);
|
|
121
|
-
|
|
65
|
+
const mdFile = import_path.default.join(dir, `${name}.md`);
|
|
66
|
+
return import_fs.default.existsSync(mdFile) ? [mdFile] : [];
|
|
122
67
|
}
|
|
123
|
-
function
|
|
68
|
+
function getDemoSourceFiles(demos = []) {
|
|
124
69
|
const files = /* @__PURE__ */ new Set();
|
|
125
70
|
demos.forEach((demo) => {
|
|
126
71
|
if ("resolveMap" in demo) {
|
|
127
72
|
Object.values(demo.resolveMap).filter((p) => import_path.default.isAbsolute(p)).forEach((file) => {
|
|
128
73
|
files.add(file);
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
74
|
+
getDemoSidecarFiles(file).forEach(
|
|
75
|
+
(sidecarFile) => files.add(sidecarFile)
|
|
76
|
+
);
|
|
133
77
|
});
|
|
134
78
|
}
|
|
135
79
|
});
|
|
136
80
|
return Array.from(files);
|
|
137
81
|
}
|
|
138
|
-
function getDemoSourceFiles(demos = []) {
|
|
139
|
-
return collectDemoSourceFiles(demos);
|
|
140
|
-
}
|
|
141
|
-
function getDemoCacheFiles(demos = []) {
|
|
142
|
-
return collectDemoSourceFiles(demos, true);
|
|
143
|
-
}
|
|
144
|
-
function addDemoFileDependency(loaderContext, opts, file) {
|
|
145
|
-
if (import_fs.default.existsSync(file) || import_utoopackLoaders.UTOOPACK_LOADER_CTX_KEY in opts) {
|
|
146
|
-
loaderContext.addDependency(file);
|
|
147
|
-
} else if (loaderContext.addMissingDependency) {
|
|
148
|
-
loaderContext.addMissingDependency(file);
|
|
149
|
-
} else {
|
|
150
|
-
loaderContext.addDependency(file);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
82
|
function isRelativePath(path2) {
|
|
154
83
|
return /^\.{1,2}(?!\w)/.test(path2);
|
|
155
84
|
}
|
|
@@ -168,6 +97,7 @@ function emitDefault(opts, ret) {
|
|
|
168
97
|
const { frontmatter, demos } = ret.meta;
|
|
169
98
|
const isTabContent = (0, import_tabs.isTabRouteFile)(this.resourcePath);
|
|
170
99
|
const wrapper = isTabContent ? "" : "DumiPage";
|
|
100
|
+
const textMode = import_utoopackLoaders.UTOOPACK_LOADER_CTX_KEY in opts && process.env.NODE_ENV !== "production" ? "text-render" : "text";
|
|
171
101
|
if (demos && opts.onResolveDemos) {
|
|
172
102
|
opts.onResolveDemos(demos);
|
|
173
103
|
}
|
|
@@ -200,7 +130,7 @@ import React, { Suspense } from 'react';
|
|
|
200
130
|
import { DumiPage } from 'dumi';
|
|
201
131
|
import { texts as ${import_rehypeText.CONTENT_TEXTS_OBJ_NAME} } from '${(0, import_plugin_utils.winPath)(
|
|
202
132
|
this.resourcePath
|
|
203
|
-
)}?type
|
|
133
|
+
)}?type=${textMode}';
|
|
204
134
|
|
|
205
135
|
// export named function for fastRefresh
|
|
206
136
|
// ref: https://github.com/pmmmwh/react-refresh-webpack-plugin/blob/main/docs/TROUBLESHOOTING.md#edits-always-lead-to-full-reload
|
|
@@ -218,21 +148,6 @@ export default DumiMarkdownContent;`;
|
|
|
218
148
|
}
|
|
219
149
|
function emitDemo(opts, ret) {
|
|
220
150
|
const { demos } = ret.meta;
|
|
221
|
-
const demoHMRVersions = Object.fromEntries(
|
|
222
|
-
(demos ?? []).flatMap((demo) => {
|
|
223
|
-
const hmrVersion = demo.__dumiUtoopackHMRVersion;
|
|
224
|
-
return typeof hmrVersion === "string" ? [[demo.id, hmrVersion]] : [];
|
|
225
|
-
})
|
|
226
|
-
);
|
|
227
|
-
const enableDemoHMR = opts.useUtoopackDemoHMR === true && Object.keys(demoHMRVersions).length > 0;
|
|
228
|
-
const demoHMRModuleId = JSON.stringify(
|
|
229
|
-
(0, import_plugin_utils.winPath)(`${this.resourcePath}?type=demo`)
|
|
230
|
-
);
|
|
231
|
-
const enableUtoopackSelfAccept = enableDemoHMR && import_utoopackLoaders.UTOOPACK_LOADER_CTX_KEY in opts;
|
|
232
|
-
const renderedDemos = demos == null ? void 0 : demos.map((demo) => ({
|
|
233
|
-
...demo,
|
|
234
|
-
renderedPreviewerProps: "previewerProps" in demo && demo.previewerProps ? JSON.stringify(demo.previewerProps) : void 0
|
|
235
|
-
}));
|
|
236
151
|
const shareDepsMap = {};
|
|
237
152
|
const demoDepsMap = {};
|
|
238
153
|
const relativeDepsMap = {};
|
|
@@ -275,9 +190,6 @@ function emitDemo(opts, ret) {
|
|
|
275
190
|
return import_plugin_utils.Mustache.render(
|
|
276
191
|
`import React from 'react';
|
|
277
192
|
import '${(0, import_plugin_utils.winPath)(this.resourcePath)}?watch=parent';
|
|
278
|
-
{{#enableDemoHMR}}
|
|
279
|
-
import { registerDemoHMRModule } from 'dumi/dist/client/theme-api/DumiDemo/hmr';
|
|
280
|
-
{{/enableDemoHMR}}
|
|
281
193
|
{{#dedupedDemosDeps}}
|
|
282
194
|
import * as {{{specifier}}} from '{{{key}}}';
|
|
283
195
|
{{/dedupedDemosDeps}}
|
|
@@ -292,29 +204,13 @@ export const demos = {
|
|
|
292
204
|
routeId: '{{{routeId}}}',
|
|
293
205
|
{{/routeId}}
|
|
294
206
|
context: {{{renderContext}}},
|
|
295
|
-
{{#previewerProps}}
|
|
296
|
-
previewerProps: {{{renderedPreviewerProps}}},
|
|
297
|
-
{{/previewerProps}}
|
|
298
207
|
renderOpts: {{{renderRenderOpts}}},
|
|
299
208
|
},
|
|
300
209
|
{{/demos}}
|
|
301
|
-
}
|
|
302
|
-
if (
|
|
303
|
-
typeof __turbopack_context__ !== 'undefined' &&
|
|
304
|
-
typeof __turbopack_context__.m?.hot?.accept === 'function'
|
|
305
|
-
) {
|
|
306
|
-
__turbopack_context__.m.hot.accept();
|
|
307
|
-
}
|
|
308
|
-
{{/enableUtoopackSelfAccept}}{{#enableDemoHMR}}
|
|
309
|
-
registerDemoHMRModule({{{demoHMRModuleId}}}, {{{demoHMRVersions}}});
|
|
310
|
-
{{/enableDemoHMR}}`,
|
|
210
|
+
};`,
|
|
311
211
|
{
|
|
312
|
-
demos
|
|
212
|
+
demos,
|
|
313
213
|
dedupedDemosDeps,
|
|
314
|
-
demoHMRModuleId,
|
|
315
|
-
demoHMRVersions: JSON.stringify(demoHMRVersions),
|
|
316
|
-
enableDemoHMR,
|
|
317
|
-
enableUtoopackSelfAccept,
|
|
318
214
|
routeId,
|
|
319
215
|
renderAsset: function renderAsset() {
|
|
320
216
|
if (!("asset" in this))
|
|
@@ -404,24 +300,81 @@ function emitDemoIndex(opts, ret) {
|
|
|
404
300
|
${renderDemoIndex(this.resourcePath, opts, demos)}`;
|
|
405
301
|
}
|
|
406
302
|
function emitFrontmatter(opts, ret) {
|
|
407
|
-
const {
|
|
303
|
+
const { demos } = ret.meta;
|
|
304
|
+
const frontmatter = ret.meta.frontmatter;
|
|
305
|
+
const toc = ret.meta.toc ?? [];
|
|
408
306
|
const resourcePath = (0, import_plugin_utils.winPath)(this.resourcePath);
|
|
409
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);
|
|
410
311
|
const demoIndex = renderDemoIndex(this.resourcePath, opts, demos);
|
|
411
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
|
+
);
|
|
412
324
|
const rendered = import_plugin_utils.Mustache.render(
|
|
413
|
-
`
|
|
325
|
+
`{{#enableUtoopackHMR}}
|
|
326
|
+
import { notifyRouteMetaHMR } from {{{routeMetaHMRSpecifier}}};
|
|
327
|
+
{{/enableUtoopackHMR}}
|
|
328
|
+
import '${resourcePath}?watch=parent';
|
|
414
329
|
globalThis.__DUMI_FM__ = globalThis.__DUMI_FM__ || {};
|
|
415
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}}
|
|
416
348
|
globalThis.__DUMI_FM__['${resourcePath}'] = {{{frontmatter}}};
|
|
417
349
|
globalThis.__DUMI_TOC__['${resourcePath}'] = {{{toc}}};
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
{{
|
|
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}}`,
|
|
421
370
|
{
|
|
422
371
|
toc: JSON.stringify(toc),
|
|
423
372
|
frontmatter: JSON.stringify(frontmatter),
|
|
424
|
-
demoIndex
|
|
373
|
+
demoIndex,
|
|
374
|
+
enableUtoopackHMR,
|
|
375
|
+
routeId: routeId ? JSON.stringify(routeId) : void 0,
|
|
376
|
+
routeMetaHMRSpecifier: routeMetaHMRPath ? JSON.stringify(routeMetaHMRPath) : void 0,
|
|
377
|
+
routeStructureHash
|
|
425
378
|
}
|
|
426
379
|
);
|
|
427
380
|
return rendered;
|
|
@@ -439,10 +392,45 @@ export const frontmatter = new Proxy({{{frontmatter}}}, {});
|
|
|
439
392
|
);
|
|
440
393
|
}
|
|
441
394
|
function emitText(opts, ret) {
|
|
442
|
-
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
|
+
}
|
|
443
431
|
return import_plugin_utils.Mustache.render(
|
|
444
432
|
`
|
|
445
|
-
import '${
|
|
433
|
+
import '${resourcePath}?watch=parent';
|
|
446
434
|
export const texts = {{{texts}}};
|
|
447
435
|
`,
|
|
448
436
|
{
|
|
@@ -450,13 +438,25 @@ function emitText(opts, ret) {
|
|
|
450
438
|
}
|
|
451
439
|
);
|
|
452
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
|
+
}
|
|
453
455
|
function emit(opts, ret) {
|
|
454
456
|
const { demos, embeds } = ret.meta;
|
|
455
457
|
embeds.forEach((file) => this.addDependency(file));
|
|
456
458
|
if (opts.mode !== "demo-index") {
|
|
457
|
-
|
|
458
|
-
(file) => addDemoFileDependency(this, opts, file)
|
|
459
|
-
);
|
|
459
|
+
getDemoSourceFiles(demos).forEach((file) => this.addDependency(file));
|
|
460
460
|
}
|
|
461
461
|
if (this.resourceQuery.includes("watch=parent"))
|
|
462
462
|
return null;
|
|
@@ -469,112 +469,26 @@ function emit(opts, ret) {
|
|
|
469
469
|
return emitFrontmatter.call(this, opts, ret);
|
|
470
470
|
case "text":
|
|
471
471
|
return emitText.call(this, opts, ret);
|
|
472
|
+
case "text-render":
|
|
473
|
+
return emitRenderText.call(this, opts, ret);
|
|
472
474
|
default:
|
|
473
475
|
return emitDefault.call(this, opts, ret);
|
|
474
476
|
}
|
|
475
477
|
}
|
|
476
|
-
function
|
|
477
|
-
return Array.from(new Set(deps)).sort();
|
|
478
|
-
}
|
|
479
|
-
var readDependencyFromFs = (file) => import_fs.default.promises.readFile(file, "utf-8");
|
|
480
|
-
async function getDepsCacheKey(deps = [], readDependency = readDependencyFromFs) {
|
|
478
|
+
function getDepsCacheKey(deps = []) {
|
|
481
479
|
return JSON.stringify(
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
try {
|
|
485
|
-
const content = await readDependency(file);
|
|
486
|
-
return `${file}:${(0, import_utils.getContentHash)(content)}:${await getFileRevision(
|
|
487
|
-
file
|
|
488
|
-
)}`;
|
|
489
|
-
} catch (err) {
|
|
490
|
-
if (isMissingFsError(err)) {
|
|
491
|
-
return `${file}:<missing>:${await getMissingParentRevision(file)}`;
|
|
492
|
-
}
|
|
493
|
-
throw err;
|
|
494
|
-
}
|
|
495
|
-
})
|
|
480
|
+
deps.map(
|
|
481
|
+
(file) => `${file}:${(0, import_utils.getContentHash)(import_fs.default.readFileSync(file, "utf-8"))}`
|
|
496
482
|
)
|
|
497
483
|
);
|
|
498
484
|
}
|
|
499
|
-
function getMdLoaderCacheRecord(cache, key) {
|
|
500
|
-
const record = getMdLoaderCacheSync(
|
|
501
|
-
cache,
|
|
502
|
-
key,
|
|
503
|
-
void 0
|
|
504
|
-
);
|
|
505
|
-
return (record == null ? void 0 : record.version) === 2 ? record : void 0;
|
|
506
|
-
}
|
|
507
|
-
async function getValidMdLoaderCacheRecord(cache, key, readDependency = readDependencyFromFs) {
|
|
508
|
-
const record = getMdLoaderCacheRecord(cache, key);
|
|
509
|
-
if (!record)
|
|
510
|
-
return void 0;
|
|
511
|
-
if (record.depsKey === await getDepsCacheKey(record.deps, readDependency)) {
|
|
512
|
-
return record;
|
|
513
|
-
}
|
|
514
|
-
return void 0;
|
|
515
|
-
}
|
|
516
|
-
async function getMdLoaderCacheResult(cache, key, readDependency = readDependencyFromFs) {
|
|
517
|
-
var _a;
|
|
518
|
-
return (_a = await getValidMdLoaderCacheRecord(cache, key, readDependency)) == null ? void 0 : _a.result;
|
|
519
|
-
}
|
|
520
|
-
async function createStableTransform({
|
|
521
|
-
initialDeps,
|
|
522
|
-
createValue,
|
|
523
|
-
getDeps,
|
|
524
|
-
readDependency = readDependencyFromFs,
|
|
525
|
-
onDepsDiscovered,
|
|
526
|
-
maxAttempts = 3
|
|
527
|
-
}) {
|
|
528
|
-
let expectedDeps = initialDeps && normalizeDeps(initialDeps);
|
|
529
|
-
for (let attempt = 0; attempt < maxAttempts; attempt += 1) {
|
|
530
|
-
const beforeKey = expectedDeps ? await getDepsCacheKey(expectedDeps, readDependency) : void 0;
|
|
531
|
-
const result = await createValue();
|
|
532
|
-
const deps = normalizeDeps(getDeps(result));
|
|
533
|
-
const depsKey = await getDepsCacheKey(deps, readDependency);
|
|
534
|
-
onDepsDiscovered == null ? void 0 : onDepsDiscovered(deps);
|
|
535
|
-
if (expectedDeps && JSON.stringify(expectedDeps) === JSON.stringify(deps) && beforeKey === depsKey) {
|
|
536
|
-
return { version: 2, deps, depsKey, result };
|
|
537
|
-
}
|
|
538
|
-
expectedDeps = deps;
|
|
539
|
-
}
|
|
540
|
-
throw Object.assign(
|
|
541
|
-
new Error("Markdown dependencies changed repeatedly while transforming"),
|
|
542
|
-
{ code: "EDEPSUNSTABLE" }
|
|
543
|
-
);
|
|
544
|
-
}
|
|
545
|
-
function createDependencyReader(loaderContext, useUtoopack, mode) {
|
|
546
|
-
var _a;
|
|
547
|
-
if (useUtoopack && mode !== "demo-index" && ((_a = loaderContext.fs) == null ? void 0 : _a.readFile)) {
|
|
548
|
-
return (file) => new Promise((resolve, reject) => {
|
|
549
|
-
loaderContext.fs.readFile(
|
|
550
|
-
file,
|
|
551
|
-
(err, data) => {
|
|
552
|
-
if (err)
|
|
553
|
-
reject(err);
|
|
554
|
-
else
|
|
555
|
-
resolve(
|
|
556
|
-
Buffer.isBuffer(data) ? data.toString("utf-8") : String(data)
|
|
557
|
-
);
|
|
558
|
-
}
|
|
559
|
-
);
|
|
560
|
-
});
|
|
561
|
-
}
|
|
562
|
-
return readDependencyFromFs;
|
|
563
|
-
}
|
|
564
|
-
function getMdTransformDepsHint(cache, key) {
|
|
565
|
-
const hint = getMdLoaderCacheSync(
|
|
566
|
-
cache,
|
|
567
|
-
key,
|
|
568
|
-
void 0
|
|
569
|
-
);
|
|
570
|
-
return (hint == null ? void 0 : hint.version) === 1 ? normalizeDeps(hint.deps) : void 0;
|
|
571
|
-
}
|
|
572
485
|
var deferrer = {};
|
|
486
|
+
var depsMapping = {};
|
|
573
487
|
function mdLoader(content) {
|
|
574
488
|
var _a, _b, _c;
|
|
575
489
|
let opts = this.getOptions();
|
|
576
490
|
const loaderContextPath = opts[import_utoopackLoaders.UTOOPACK_LOADER_CTX_KEY];
|
|
577
|
-
const useUtoopackDemoHMR =
|
|
491
|
+
const useUtoopackDemoHMR = process.env.NODE_ENV !== "production" && Boolean(loaderContextPath);
|
|
578
492
|
if (loaderContextPath) {
|
|
579
493
|
const ctx = require(loaderContextPath);
|
|
580
494
|
if (!((_a = opts.techStacks) == null ? void 0 : _a.length)) {
|
|
@@ -602,119 +516,51 @@ function mdLoader(content) {
|
|
|
602
516
|
)) {
|
|
603
517
|
this.cacheable(false);
|
|
604
518
|
}
|
|
605
|
-
const
|
|
606
|
-
const
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
const readDependency = createDependencyReader(
|
|
610
|
-
this,
|
|
611
|
-
useUtoopackDemoHMR,
|
|
612
|
-
opts.mode
|
|
613
|
-
);
|
|
614
|
-
const { baseCacheKey, depsHintKey } = getMdTransformCacheKeys({
|
|
615
|
-
resourcePath: this.resourcePath,
|
|
616
|
-
content,
|
|
519
|
+
const cache = (0, import_utils.getCache)("md-loader");
|
|
520
|
+
const baseCacheKey = [
|
|
521
|
+
this.resourcePath,
|
|
522
|
+
(0, import_utils.getContentHash)(content),
|
|
617
523
|
useUtoopackDemoHMR,
|
|
618
|
-
opts
|
|
524
|
+
JSON.stringify(import_plugin_utils.lodash.omit(opts, ["mode", "builtins", "onResolveDemos"]))
|
|
525
|
+
].join(":");
|
|
526
|
+
const cacheKey = [
|
|
527
|
+
baseCacheKey,
|
|
528
|
+
getDepsCacheKey(depsMapping[this.resourcePath])
|
|
529
|
+
].join(":");
|
|
530
|
+
const cacheRet = getMdLoaderCacheSync(cache, cacheKey, "");
|
|
531
|
+
if (cacheRet) {
|
|
532
|
+
cb(null, emit.call(this, opts, cacheRet));
|
|
533
|
+
return;
|
|
534
|
+
} else if (cacheKey in deferrer) {
|
|
535
|
+
deferrer[cacheKey].then((res) => {
|
|
536
|
+
cb(null, emit.call(this, opts, res));
|
|
537
|
+
}).catch(cb);
|
|
538
|
+
return;
|
|
539
|
+
}
|
|
540
|
+
deferrer[cacheKey] = (0, import_transformer.default)(content, {
|
|
541
|
+
...import_plugin_utils.lodash.omit(opts, ["mode", "builtins", "onResolveDemos"]),
|
|
542
|
+
fileAbsPath: (0, import_plugin_utils.winPath)(this.resourcePath),
|
|
543
|
+
useUtoopackDemoHMR
|
|
619
544
|
});
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
"mode",
|
|
624
|
-
"builtins",
|
|
625
|
-
"onResolveDemos",
|
|
626
|
-
"cacheDirectory",
|
|
627
|
-
"cacheEpoch"
|
|
628
|
-
]),
|
|
629
|
-
fileAbsPath: (0, import_plugin_utils.winPath)(this.resourcePath),
|
|
630
|
-
useUtoopackDemoHMR
|
|
631
|
-
});
|
|
632
|
-
};
|
|
633
|
-
const getTransformDeps = (ret) => normalizeDeps(ret.meta.embeds.concat(getDemoCacheFiles(ret.meta.demos)));
|
|
634
|
-
const saveDepsHint = (deps) => {
|
|
635
|
-
depsHintCache.setSync(depsHintKey, {
|
|
636
|
-
version: 1,
|
|
637
|
-
deps: normalizeDeps(deps)
|
|
638
|
-
});
|
|
639
|
-
};
|
|
640
|
-
const cacheWithPath = cache;
|
|
641
|
-
const getTransform = async () => {
|
|
642
|
-
var _a2;
|
|
643
|
-
const cached = await getValidMdLoaderCacheRecord(
|
|
644
|
-
cache,
|
|
645
|
-
baseCacheKey,
|
|
646
|
-
readDependency
|
|
647
|
-
);
|
|
648
|
-
if (cached)
|
|
649
|
-
return cached;
|
|
650
|
-
const initialDeps = getMdTransformDepsHint(depsHintCache, depsHintKey) ?? ((_a2 = getMdLoaderCacheRecord(cache, baseCacheKey)) == null ? void 0 : _a2.deps);
|
|
651
|
-
const depsFingerprint = initialDeps ? await getDepsCacheKey(initialDeps, readDependency) : "<discover>";
|
|
652
|
-
const deferrerKey = [cacheNamespace, baseCacheKey, depsFingerprint].join(
|
|
653
|
-
":"
|
|
545
|
+
deferrer[cacheKey].then((ret) => {
|
|
546
|
+
depsMapping[this.resourcePath] = ret.meta.embeds.concat(
|
|
547
|
+
getDemoSourceFiles(ret.meta.demos)
|
|
654
548
|
);
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
readDependency,
|
|
664
|
-
onDepsDiscovered: saveDepsHint
|
|
665
|
-
});
|
|
666
|
-
}
|
|
667
|
-
const result = await createTransform();
|
|
668
|
-
const deps = getTransformDeps(result);
|
|
669
|
-
const record = {
|
|
670
|
-
version: 2,
|
|
671
|
-
deps,
|
|
672
|
-
depsKey: await getDepsCacheKey(deps),
|
|
673
|
-
result
|
|
674
|
-
};
|
|
675
|
-
saveDepsHint(deps);
|
|
676
|
-
return record;
|
|
677
|
-
};
|
|
678
|
-
const saveRecord = (record) => {
|
|
679
|
-
cache.setSync(baseCacheKey, record);
|
|
680
|
-
saveDepsHint(record.deps);
|
|
681
|
-
};
|
|
682
|
-
const pending = useUtoopackDemoHMR && cacheWithPath.path ? (0, import_sharedCache.getOrCreateWithFileLock)({
|
|
683
|
-
lockPath: `${cacheWithPath.path(`transform:${baseCacheKey}`)}.lock`,
|
|
684
|
-
getValue: () => getValidMdLoaderCacheRecord(cache, baseCacheKey, readDependency),
|
|
685
|
-
createValue: createRecord,
|
|
686
|
-
setValue: saveRecord
|
|
687
|
-
}) : (async () => {
|
|
688
|
-
const current = await getValidMdLoaderCacheRecord(
|
|
689
|
-
cache,
|
|
690
|
-
baseCacheKey,
|
|
691
|
-
readDependency
|
|
692
|
-
);
|
|
693
|
-
if (current)
|
|
694
|
-
return current;
|
|
695
|
-
const created = await createRecord();
|
|
696
|
-
saveRecord(created);
|
|
697
|
-
return created;
|
|
698
|
-
})();
|
|
699
|
-
deferrer[deferrerKey] = pending;
|
|
700
|
-
try {
|
|
701
|
-
return await pending;
|
|
702
|
-
} finally {
|
|
703
|
-
if (deferrer[deferrerKey] === pending)
|
|
704
|
-
delete deferrer[deferrerKey];
|
|
705
|
-
}
|
|
706
|
-
};
|
|
707
|
-
getTransform().then((record) => cb(null, emit.call(this, opts, record.result))).catch(cb);
|
|
549
|
+
const finalCacheKey = [
|
|
550
|
+
baseCacheKey,
|
|
551
|
+
getDepsCacheKey(depsMapping[this.resourcePath])
|
|
552
|
+
].join(":");
|
|
553
|
+
cache.setSync(finalCacheKey, ret);
|
|
554
|
+
cb(null, emit.call(this, opts, ret));
|
|
555
|
+
delete deferrer[cacheKey];
|
|
556
|
+
}).catch(cb);
|
|
708
557
|
}
|
|
709
558
|
// Annotate the CommonJS export names for ESM import in node:
|
|
710
559
|
0 && (module.exports = {
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
560
|
+
emitDefault,
|
|
561
|
+
emitFrontmatter,
|
|
562
|
+
emitRenderText,
|
|
563
|
+
emitText,
|
|
715
564
|
getDemoSourceFiles,
|
|
716
|
-
|
|
717
|
-
getMdLoaderCacheResult,
|
|
718
|
-
getMdLoaderCacheSync,
|
|
719
|
-
getMdTransformCacheKeys
|
|
565
|
+
getMdLoaderCacheSync
|
|
720
566
|
});
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { IParsedBlockAsset } from '../../../assetParsers/block';
|
|
2
|
-
import type { IDumiDemoProps } from '@/client/theme-api/DumiDemo';
|
|
3
2
|
import type { ILocalesConfig, IRouteMeta } from '@/client/theme-api/types';
|
|
4
3
|
import type { IApi, IDumiConfig, IDumiTechStack } from '../../../types';
|
|
5
4
|
import { type ResolveOptions } from 'enhanced-resolve';
|
|
@@ -24,9 +23,6 @@ declare module 'vfile' {
|
|
|
24
23
|
component: string;
|
|
25
24
|
asset: IParsedBlockAsset['asset'];
|
|
26
25
|
resolveMap: IParsedBlockAsset['resolveMap'];
|
|
27
|
-
previewerProps?: IDumiDemoProps['previewerProps'];
|
|
28
|
-
/** Internal semantic version used by the utoopack demo HMR runtime. */
|
|
29
|
-
__dumiUtoopackHMRVersion?: string;
|
|
30
26
|
renderOpts: {
|
|
31
27
|
type?: string;
|
|
32
28
|
rendererPath?: string;
|