dumi 2.4.52 → 2.4.53
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/compiled/file-system-cache/LICENSE +134 -0
- package/compiled/file-system-cache/index.d.ts +3 -0
- package/compiled/file-system-cache/index.js +1 -0
- package/compiled/file-system-cache/package.json +1 -0
- package/dist/assetParsers/block.js +32 -10
- package/dist/features/compile/index.js +5 -1
- package/dist/features/compile/utoopackLoaders.d.ts +3 -2
- package/dist/features/compile/utoopackLoaders.js +7 -6
- package/dist/features/meta.js +4 -4
- package/dist/features/tabs/utils.d.ts +3 -0
- package/dist/features/tabs/utils.js +41 -0
- package/dist/features/tabs.d.ts +1 -3
- package/dist/features/tabs.js +12 -19
- package/dist/loaders/constants.d.ts +2 -0
- package/dist/loaders/constants.js +32 -0
- package/dist/loaders/demo/index.js +3 -3
- package/dist/loaders/markdown/index.js +137 -67
- package/dist/loaders/markdown/transformer/rehypeDemo.js +7 -7
- package/dist/loaders/markdown/transformer/rehypeJsxify.js +1 -1
- package/dist/loaders/markdown/transformer/rehypeLink.js +32 -18
- package/dist/loaders/markdown/transformer/rehypeRaw.js +2 -2
- package/dist/loaders/markdown/transformer/rehypeText.d.ts +2 -1
- package/dist/loaders/markdown/transformer/rehypeText.js +3 -3
- package/dist/loaders/markdown/transformer/remarkBreaks.js +4 -4
- package/dist/loaders/markdown/transformer/remarkEmbed.js +2 -2
- package/dist/loaders/markdown/transformer/remarkMeta.js +9 -9
- package/dist/techStacks/utils.js +2 -2
- package/dist/utils.d.ts +2 -1
- package/dist/utils.js +16 -16
- package/package.json +1 -1
|
@@ -38,14 +38,13 @@ __export(markdown_exports, {
|
|
|
38
38
|
getMdLoaderCacheSync: () => getMdLoaderCacheSync
|
|
39
39
|
});
|
|
40
40
|
module.exports = __toCommonJS(markdown_exports);
|
|
41
|
-
var
|
|
42
|
-
var
|
|
43
|
-
var
|
|
41
|
+
var import_utils = require("../../features/tabs/utils");
|
|
42
|
+
var import_constants = require("../constants");
|
|
43
|
+
var import_utils2 = require("../../utils");
|
|
44
|
+
var import_utils3 = require("@umijs/utils");
|
|
44
45
|
var import_fs = __toESM(require("fs"));
|
|
45
46
|
var import_path = __toESM(require("path"));
|
|
46
|
-
var import_plugin_utils = require("umi/plugin-utils");
|
|
47
47
|
var import_transformer = __toESM(require("./transformer"));
|
|
48
|
-
var import_rehypeText = require("./transformer/rehypeText");
|
|
49
48
|
var MD_LOADER_CACHE_VERSION = 1;
|
|
50
49
|
function isMalformedCacheError(err) {
|
|
51
50
|
return err instanceof SyntaxError || err instanceof Error && /Unexpected end of JSON input|Unterminated string in JSON/.test(
|
|
@@ -84,7 +83,7 @@ function isRelativePath(path2) {
|
|
|
84
83
|
return /^\.{1,2}(?!\w)/.test(path2);
|
|
85
84
|
}
|
|
86
85
|
function normalizeRouteFile(file) {
|
|
87
|
-
return (0,
|
|
86
|
+
return (0, import_utils3.winPath)(file).replace(/\.(mdx?)\.js$/, ".$1");
|
|
88
87
|
}
|
|
89
88
|
function getRouteId(opts, fileAbsPath) {
|
|
90
89
|
const normalizedFile = normalizeRouteFile(fileAbsPath);
|
|
@@ -97,9 +96,9 @@ function getRouteId(opts, fileAbsPath) {
|
|
|
97
96
|
function emitDefault(opts, ret) {
|
|
98
97
|
const { frontmatter, demos } = ret.meta;
|
|
99
98
|
const sharedDemoProps = ret.meta.demoSharedProps ?? [];
|
|
100
|
-
const isTabContent = (0,
|
|
99
|
+
const isTabContent = (0, import_utils.isTabRouteFile)(this.resourcePath);
|
|
101
100
|
const wrapper = isTabContent ? "" : "DumiPage";
|
|
102
|
-
const textMode =
|
|
101
|
+
const textMode = import_constants.UTOOPACK_LOADER_CTX_KEY in opts && process.env.NODE_ENV !== "production" ? "text-render" : "text";
|
|
103
102
|
if (demos && opts.onResolveDemos) {
|
|
104
103
|
opts.onResolveDemos(demos);
|
|
105
104
|
}
|
|
@@ -121,16 +120,16 @@ function emitDefault(opts, ret) {
|
|
|
121
120
|
const embeddedMdFiles = (ret.meta.embeds ?? []).filter(
|
|
122
121
|
(filePath) => filePath.endsWith(".md") && !filePath.includes("node_modules")
|
|
123
122
|
);
|
|
124
|
-
return `${Object.values(opts.builtins).map((item) => `import ${item.specifier} from '${(0,
|
|
123
|
+
return `${Object.values(opts.builtins).map((item) => `import ${item.specifier} from '${(0, import_utils3.winPath)(item.source)}';`).join("\n")}
|
|
125
124
|
${embeddedMdFiles.map(
|
|
126
125
|
(md) => `
|
|
127
|
-
import '${(0,
|
|
126
|
+
import '${(0, import_utils3.winPath)(md)}?watch=parent';
|
|
128
127
|
`
|
|
129
128
|
).join("\n")}
|
|
130
129
|
import LoadingComponent from '@@/dumi/theme/loading';
|
|
131
130
|
import React, { Suspense } from 'react';
|
|
132
131
|
import { DumiPage } from 'dumi';
|
|
133
|
-
import { texts as ${
|
|
132
|
+
import { texts as ${import_constants.CONTENT_TEXTS_OBJ_NAME} } from '${(0, import_utils3.winPath)(
|
|
134
133
|
this.resourcePath
|
|
135
134
|
)}?type=${textMode}';
|
|
136
135
|
${sharedDemoProps.length ? `const __dumi_demo_shared_props__ = ${JSON.stringify(sharedDemoProps)};` : ""}
|
|
@@ -166,7 +165,7 @@ function emitDemo(opts, ret) {
|
|
|
166
165
|
const specifier = `${demo.id.replace(/[^\w\d]/g, "_")}_deps_${index}`;
|
|
167
166
|
if (key !== entryFileName) {
|
|
168
167
|
const isRelative = isRelativePath(key);
|
|
169
|
-
const normalizedKey = isRelative ? (0,
|
|
168
|
+
const normalizedKey = isRelative ? (0, import_utils3.winPath)(demo.resolveMap[key]) : key;
|
|
170
169
|
sideEffectDepsMap.set(
|
|
171
170
|
normalizedKey,
|
|
172
171
|
sideEffectDepsMap.get(normalizedKey) !== false && ((_a2 = demo.sideEffectStyles) == null ? void 0 : _a2.includes(normalizedKey)) === true
|
|
@@ -193,7 +192,7 @@ function emitDemo(opts, ret) {
|
|
|
193
192
|
key,
|
|
194
193
|
specifier,
|
|
195
194
|
// Preserve webpack's namespace behavior, including custom style exports.
|
|
196
|
-
sideEffectOnly: Boolean(opts[
|
|
195
|
+
sideEffectOnly: Boolean(opts[import_constants.UTOOPACK_LOADER_CTX_KEY]) && sideEffectDepsMap.get(key) === true
|
|
197
196
|
};
|
|
198
197
|
}
|
|
199
198
|
return void 0;
|
|
@@ -201,9 +200,9 @@ function emitDemo(opts, ret) {
|
|
|
201
200
|
);
|
|
202
201
|
}, []);
|
|
203
202
|
const routeId = getRouteId(opts, this.resourcePath);
|
|
204
|
-
return
|
|
203
|
+
return import_utils3.Mustache.render(
|
|
205
204
|
`import React from 'react';
|
|
206
|
-
import '${(0,
|
|
205
|
+
import '${(0, import_utils3.winPath)(this.resourcePath)}?watch=parent';
|
|
207
206
|
{{#dedupedDemosDeps}}
|
|
208
207
|
{{#sideEffectOnly}}
|
|
209
208
|
import '{{{key}}}';
|
|
@@ -241,10 +240,10 @@ export const demos = {
|
|
|
241
240
|
var _a;
|
|
242
241
|
if (((_a = asset.dependencies[file]) == null ? void 0 : _a.type) === "FILE") {
|
|
243
242
|
let assetValue = `{{{require('-!${resolveMap[file]}?dumi-raw').default}}}`;
|
|
244
|
-
if (process.env.OKAM || opts[
|
|
243
|
+
if (process.env.OKAM || opts[import_constants.UTOOPACK_LOADER_CTX_KEY]) {
|
|
245
244
|
assetValue = `{{{require('${resolveMap[file]}?dumi-raw').default}}}`;
|
|
246
245
|
}
|
|
247
|
-
asset =
|
|
246
|
+
asset = import_utils3.lodash.cloneDeep(asset);
|
|
248
247
|
asset.dependencies[file].value = assetValue;
|
|
249
248
|
}
|
|
250
249
|
});
|
|
@@ -271,20 +270,20 @@ export const demos = {
|
|
|
271
270
|
if (renderOpts.compilePath) {
|
|
272
271
|
propertyArray.push(`
|
|
273
272
|
compile: async (...args) => {
|
|
274
|
-
return (await import('${(0,
|
|
273
|
+
return (await import('${(0, import_utils3.winPath)(
|
|
275
274
|
renderOpts.compilePath
|
|
276
275
|
)}')).default(...args);
|
|
277
276
|
},`);
|
|
278
277
|
}
|
|
279
278
|
if (renderOpts.rendererPath) {
|
|
280
279
|
propertyArray.push(`
|
|
281
|
-
renderer: (await import('${(0,
|
|
280
|
+
renderer: (await import('${(0, import_utils3.winPath)(
|
|
282
281
|
renderOpts.rendererPath
|
|
283
282
|
)}')).default,`);
|
|
284
283
|
}
|
|
285
284
|
if (renderOpts.preflightPath) {
|
|
286
285
|
propertyArray.push(`
|
|
287
|
-
preflight: (await import('${(0,
|
|
286
|
+
preflight: (await import('${(0, import_utils3.winPath)(
|
|
288
287
|
renderOpts.preflightPath
|
|
289
288
|
)}')).default,`);
|
|
290
289
|
}
|
|
@@ -298,7 +297,7 @@ export const demos = {
|
|
|
298
297
|
);
|
|
299
298
|
}
|
|
300
299
|
function renderDemoIndex(resourcePath, opts, demos) {
|
|
301
|
-
return
|
|
300
|
+
return import_utils3.Mustache.render(
|
|
302
301
|
`
|
|
303
302
|
export const demoIndex = {
|
|
304
303
|
ids: {{{ids}}},
|
|
@@ -306,31 +305,31 @@ export const demoIndex = {
|
|
|
306
305
|
};`,
|
|
307
306
|
{
|
|
308
307
|
ids: JSON.stringify(demos == null ? void 0 : demos.map((demo) => demo.id)),
|
|
309
|
-
getter: `() => import(/* webpackChunkName: "${(0,
|
|
308
|
+
getter: `() => import(/* webpackChunkName: "${(0, import_utils2.generateMetaChunkName)(
|
|
310
309
|
resourcePath,
|
|
311
310
|
opts.cwd,
|
|
312
311
|
opts.locales.map(({ id }) => id)
|
|
313
|
-
)}" */'${(0,
|
|
312
|
+
)}" */'${(0, import_utils3.winPath)(resourcePath)}?type=demo')`
|
|
314
313
|
}
|
|
315
314
|
);
|
|
316
315
|
}
|
|
317
316
|
function emitDemoIndex(opts, ret) {
|
|
318
317
|
const { demos } = ret.meta;
|
|
319
|
-
return `import '${(0,
|
|
318
|
+
return `import '${(0, import_utils3.winPath)(this.resourcePath)}?watch=parent';
|
|
320
319
|
${renderDemoIndex(this.resourcePath, opts, demos)}`;
|
|
321
320
|
}
|
|
322
321
|
function emitFrontmatter(opts, ret) {
|
|
323
322
|
const { demos } = ret.meta;
|
|
324
323
|
const frontmatter = ret.meta.frontmatter;
|
|
325
324
|
const toc = ret.meta.toc ?? [];
|
|
326
|
-
const resourcePath = (0,
|
|
327
|
-
const isUtoopack =
|
|
325
|
+
const resourcePath = (0, import_utils3.winPath)(this.resourcePath);
|
|
326
|
+
const isUtoopack = import_constants.UTOOPACK_LOADER_CTX_KEY in opts;
|
|
328
327
|
const enableUtoopackHMR = isUtoopack && process.env.NODE_ENV !== "production";
|
|
329
|
-
const routeMetaHMRPath = enableUtoopackHMR ? (0,
|
|
328
|
+
const routeMetaHMRPath = enableUtoopackHMR ? (0, import_utils3.winPath)(require.resolve("../../client/theme-api/routeMetaHMR")) : void 0;
|
|
330
329
|
const routeId = getRouteId(opts, this.resourcePath);
|
|
331
330
|
const demoIndex = renderDemoIndex(this.resourcePath, opts, demos);
|
|
332
331
|
if (isUtoopack) {
|
|
333
|
-
const routeStructureHash = (0,
|
|
332
|
+
const routeStructureHash = (0, import_utils2.getContentHash)(
|
|
334
333
|
JSON.stringify({
|
|
335
334
|
atomId: frontmatter.atomId,
|
|
336
335
|
demoIds: demos == null ? void 0 : demos.map(({ id }) => id),
|
|
@@ -341,7 +340,7 @@ function emitFrontmatter(opts, ret) {
|
|
|
341
340
|
title: frontmatter.title
|
|
342
341
|
})
|
|
343
342
|
);
|
|
344
|
-
const rendered =
|
|
343
|
+
const rendered = import_utils3.Mustache.render(
|
|
345
344
|
`{{#enableUtoopackHMR}}
|
|
346
345
|
import { notifyRouteMetaHMR } from {{{routeMetaHMRSpecifier}}};
|
|
347
346
|
{{/enableUtoopackHMR}}
|
|
@@ -399,7 +398,7 @@ if (module.hot) {
|
|
|
399
398
|
);
|
|
400
399
|
return rendered;
|
|
401
400
|
}
|
|
402
|
-
return
|
|
401
|
+
return import_utils3.Mustache.render(
|
|
403
402
|
`import '${resourcePath}?watch=parent';
|
|
404
403
|
export const toc = new Proxy({{{toc}}}, {});
|
|
405
404
|
export const frontmatter = new Proxy({{{frontmatter}}}, {});
|
|
@@ -413,14 +412,14 @@ export const frontmatter = new Proxy({{{frontmatter}}}, {});
|
|
|
413
412
|
}
|
|
414
413
|
function emitText(opts, ret) {
|
|
415
414
|
const texts = ret.meta.texts ?? [];
|
|
416
|
-
const resourcePath = (0,
|
|
417
|
-
const enableUtoopackHMR =
|
|
415
|
+
const resourcePath = (0, import_utils3.winPath)(this.resourcePath);
|
|
416
|
+
const enableUtoopackHMR = import_constants.UTOOPACK_LOADER_CTX_KEY in opts && process.env.NODE_ENV !== "production";
|
|
418
417
|
if (enableUtoopackHMR) {
|
|
419
418
|
const routeId = getRouteId(opts, this.resourcePath);
|
|
420
419
|
const routeMetaHMRSpecifier = JSON.stringify(
|
|
421
|
-
(0,
|
|
420
|
+
(0, import_utils3.winPath)(require.resolve("../../client/theme-api/routeMetaHMR"))
|
|
422
421
|
);
|
|
423
|
-
return
|
|
422
|
+
return import_utils3.Mustache.render(
|
|
424
423
|
`import { notifyRouteMetaHMR } from {{{routeMetaHMRSpecifier}}};
|
|
425
424
|
import {{{watchSpecifier}}};
|
|
426
425
|
globalThis.__DUMI_TEXTS__ = globalThis.__DUMI_TEXTS__ || {};
|
|
@@ -448,7 +447,7 @@ if (module.hot) {
|
|
|
448
447
|
}
|
|
449
448
|
);
|
|
450
449
|
}
|
|
451
|
-
return
|
|
450
|
+
return import_utils3.Mustache.render(
|
|
452
451
|
`
|
|
453
452
|
import '${resourcePath}?watch=parent';
|
|
454
453
|
export const texts = {{{texts}}};
|
|
@@ -459,7 +458,7 @@ if (module.hot) {
|
|
|
459
458
|
);
|
|
460
459
|
}
|
|
461
460
|
function emitRenderText(_opts, ret) {
|
|
462
|
-
return
|
|
461
|
+
return import_utils3.Mustache.render(
|
|
463
462
|
`
|
|
464
463
|
import {{{watchSpecifier}}};
|
|
465
464
|
export const texts = {{{texts}}};
|
|
@@ -467,7 +466,7 @@ function emitRenderText(_opts, ret) {
|
|
|
467
466
|
{
|
|
468
467
|
texts: JSON.stringify(ret.meta.texts ?? []),
|
|
469
468
|
watchSpecifier: JSON.stringify(
|
|
470
|
-
`${(0,
|
|
469
|
+
`${(0, import_utils3.winPath)(this.resourcePath)}?watch=parent`
|
|
471
470
|
)
|
|
472
471
|
}
|
|
473
472
|
);
|
|
@@ -495,22 +494,67 @@ function emit(opts, ret) {
|
|
|
495
494
|
return emitDefault.call(this, opts, ret);
|
|
496
495
|
}
|
|
497
496
|
}
|
|
498
|
-
function getDepsCacheKey(deps = []) {
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
497
|
+
function getDepsCacheKey(deps = [], cacheSession) {
|
|
498
|
+
if (!cacheSession) {
|
|
499
|
+
return JSON.stringify(
|
|
500
|
+
deps.map(
|
|
501
|
+
(file) => `${file}:${(0, import_utils2.getContentHash)(import_fs.default.readFileSync(file, "utf-8"))}`
|
|
502
|
+
)
|
|
503
|
+
);
|
|
504
|
+
}
|
|
505
|
+
const files = Array.from(
|
|
506
|
+
new Set(deps.concat(deps.flatMap(getDemoSidecarFiles)))
|
|
503
507
|
);
|
|
508
|
+
try {
|
|
509
|
+
return JSON.stringify(
|
|
510
|
+
files.map(
|
|
511
|
+
(file) => `${file}:${(0, import_utils2.getContentHash)(import_fs.default.readFileSync(file, "utf-8"))}`
|
|
512
|
+
)
|
|
513
|
+
);
|
|
514
|
+
} catch (err) {
|
|
515
|
+
const code = err.code;
|
|
516
|
+
if (code === "ENOENT" || code === "ENOTDIR") {
|
|
517
|
+
return void 0;
|
|
518
|
+
}
|
|
519
|
+
throw err;
|
|
520
|
+
}
|
|
504
521
|
}
|
|
505
522
|
var deferrer = {};
|
|
506
523
|
var depsMapping = {};
|
|
524
|
+
var loaderContextHashes = /* @__PURE__ */ new WeakMap();
|
|
507
525
|
function mdLoader(content) {
|
|
508
526
|
var _a, _b, _c;
|
|
509
527
|
let opts = this.getOptions();
|
|
510
|
-
|
|
528
|
+
let cacheSession;
|
|
529
|
+
const loaderContextPath = opts[import_constants.UTOOPACK_LOADER_CTX_KEY];
|
|
511
530
|
const useUtoopackDemoHMR = process.env.NODE_ENV !== "production" && Boolean(loaderContextPath);
|
|
512
531
|
if (loaderContextPath) {
|
|
513
|
-
const
|
|
532
|
+
const contextModuleId = useUtoopackDemoHMR && process.env.DUMI_CACHE !== "none" ? require.resolve(loaderContextPath) : void 0;
|
|
533
|
+
const cachedContextModule = contextModuleId ? require.cache[contextModuleId] : void 0;
|
|
534
|
+
const initialContextHash = contextModuleId && !cachedContextModule ? (0, import_utils2.getContentHash)(import_fs.default.readFileSync(loaderContextPath, "utf-8"), 32) : void 0;
|
|
535
|
+
let ctx = require(loaderContextPath);
|
|
536
|
+
if (contextModuleId && ctx.cacheSession) {
|
|
537
|
+
const contextHash = initialContextHash ?? (0, import_utils2.getContentHash)(import_fs.default.readFileSync(loaderContextPath, "utf-8"), 32);
|
|
538
|
+
if (cachedContextModule && loaderContextHashes.get(cachedContextModule) !== contextHash) {
|
|
539
|
+
const parents = /* @__PURE__ */ new Set([
|
|
540
|
+
cachedContextModule.parent,
|
|
541
|
+
typeof module === "undefined" ? void 0 : module,
|
|
542
|
+
...Object.values(require.cache)
|
|
543
|
+
]);
|
|
544
|
+
for (const parent of parents) {
|
|
545
|
+
const children = parent == null ? void 0 : parent.children;
|
|
546
|
+
const index = (children == null ? void 0 : children.indexOf(cachedContextModule)) ?? -1;
|
|
547
|
+
if (index !== -1)
|
|
548
|
+
children.splice(index, 1);
|
|
549
|
+
}
|
|
550
|
+
delete require.cache[contextModuleId];
|
|
551
|
+
ctx = require(contextModuleId);
|
|
552
|
+
}
|
|
553
|
+
const contextModule = require.cache[contextModuleId];
|
|
554
|
+
if (contextModule)
|
|
555
|
+
loaderContextHashes.set(contextModule, contextHash);
|
|
556
|
+
}
|
|
557
|
+
cacheSession = useUtoopackDemoHMR && process.env.DUMI_CACHE !== "none" ? ctx.cacheSession : void 0;
|
|
514
558
|
if (!((_a = opts.techStacks) == null ? void 0 : _a.length)) {
|
|
515
559
|
opts.techStacks = ctx.techStacks;
|
|
516
560
|
}
|
|
@@ -539,46 +583,72 @@ function mdLoader(content) {
|
|
|
539
583
|
)) {
|
|
540
584
|
this.cacheable(false);
|
|
541
585
|
}
|
|
542
|
-
const cache = (0,
|
|
586
|
+
const cache = (0, import_utils2.getCache)("md-loader");
|
|
587
|
+
let optionsCacheKey = JSON.stringify(
|
|
588
|
+
import_utils3.lodash.omit(opts, ["mode", "builtins", "onResolveDemos"])
|
|
589
|
+
);
|
|
590
|
+
if (cacheSession)
|
|
591
|
+
optionsCacheKey = (0, import_utils2.getContentHash)(optionsCacheKey, 32);
|
|
543
592
|
const baseCacheKey = [
|
|
544
593
|
MD_LOADER_CACHE_VERSION,
|
|
545
594
|
this.resourcePath,
|
|
546
|
-
(0,
|
|
595
|
+
(0, import_utils2.getContentHash)(content),
|
|
547
596
|
useUtoopackDemoHMR,
|
|
548
|
-
|
|
549
|
-
].join(":");
|
|
550
|
-
const cacheKey = [
|
|
551
|
-
baseCacheKey,
|
|
552
|
-
getDepsCacheKey(depsMapping[this.resourcePath])
|
|
597
|
+
optionsCacheKey
|
|
553
598
|
].join(":");
|
|
554
|
-
const
|
|
555
|
-
|
|
599
|
+
const depsCacheKey = cacheSession ? `deps:${baseCacheKey}` : void 0;
|
|
600
|
+
const depsMappingKey = cacheSession ? `${cacheSession}:${this.resourcePath}` : this.resourcePath;
|
|
601
|
+
const cachedDeps = depsCacheKey ? getMdLoaderCacheSync(
|
|
602
|
+
cache,
|
|
603
|
+
depsCacheKey,
|
|
604
|
+
void 0
|
|
605
|
+
) : void 0;
|
|
606
|
+
const deps = cachedDeps && cachedDeps.cacheSession === cacheSession && Array.isArray(cachedDeps.deps) && cachedDeps.deps.every((file) => typeof file === "string") ? cachedDeps.deps : depsMapping[depsMappingKey];
|
|
607
|
+
const depsKey = getDepsCacheKey(deps, cacheSession);
|
|
608
|
+
const cacheKey = [baseCacheKey, depsKey].join(":");
|
|
609
|
+
const cacheRet = depsKey === void 0 ? "" : getMdLoaderCacheSync(cache, cacheKey, "");
|
|
610
|
+
const matchesSession = !cacheSession || !(deps == null ? void 0 : deps.length) || cacheRet && cacheRet.__dumiCacheSession === cacheSession;
|
|
611
|
+
const deferrerKey = cacheSession ? `${cacheSession}:${cacheKey}` : cacheKey;
|
|
612
|
+
if (cacheRet && matchesSession) {
|
|
556
613
|
cb(null, emit.call(this, opts, cacheRet));
|
|
557
614
|
return;
|
|
558
|
-
} else if (
|
|
559
|
-
deferrer[
|
|
615
|
+
} else if (deferrerKey in deferrer) {
|
|
616
|
+
deferrer[deferrerKey].then((res) => {
|
|
560
617
|
cb(null, emit.call(this, opts, res));
|
|
561
618
|
}).catch(cb);
|
|
562
619
|
return;
|
|
563
620
|
}
|
|
564
|
-
deferrer[
|
|
565
|
-
...
|
|
566
|
-
fileAbsPath: (0,
|
|
621
|
+
deferrer[deferrerKey] = (0, import_transformer.default)(content, {
|
|
622
|
+
...import_utils3.lodash.omit(opts, ["mode", "builtins", "onResolveDemos"]),
|
|
623
|
+
fileAbsPath: (0, import_utils3.winPath)(this.resourcePath),
|
|
567
624
|
useUtoopackDemoHMR,
|
|
568
625
|
collectSideEffectStyles: Boolean(loaderContextPath)
|
|
569
626
|
});
|
|
570
|
-
deferrer[
|
|
571
|
-
depsMapping[
|
|
627
|
+
deferrer[deferrerKey].then((ret) => {
|
|
628
|
+
depsMapping[depsMappingKey] = ret.meta.embeds.concat(
|
|
572
629
|
getDemoSourceFiles(ret.meta.demos)
|
|
573
630
|
);
|
|
574
|
-
const
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
631
|
+
const finalDepsKey = getDepsCacheKey(
|
|
632
|
+
depsMapping[depsMappingKey],
|
|
633
|
+
cacheSession
|
|
634
|
+
);
|
|
635
|
+
if (finalDepsKey !== void 0) {
|
|
636
|
+
cache.setSync(
|
|
637
|
+
[baseCacheKey, finalDepsKey].join(":"),
|
|
638
|
+
cacheSession && depsMapping[depsMappingKey].length ? { ...ret, __dumiCacheSession: cacheSession } : ret
|
|
639
|
+
);
|
|
640
|
+
if (depsCacheKey)
|
|
641
|
+
cache.setSync(depsCacheKey, {
|
|
642
|
+
cacheSession,
|
|
643
|
+
deps: depsMapping[depsMappingKey]
|
|
644
|
+
});
|
|
645
|
+
}
|
|
579
646
|
cb(null, emit.call(this, opts, ret));
|
|
580
|
-
delete deferrer[
|
|
581
|
-
}).catch(
|
|
647
|
+
delete deferrer[deferrerKey];
|
|
648
|
+
}).catch((err) => {
|
|
649
|
+
delete deferrer[deferrerKey];
|
|
650
|
+
cb(err);
|
|
651
|
+
});
|
|
582
652
|
}
|
|
583
653
|
// Annotate the CommonJS export names for ESM import in node:
|
|
584
654
|
0 && (module.exports = {
|
|
@@ -38,8 +38,8 @@ __export(rehypeDemo_exports, {
|
|
|
38
38
|
module.exports = __toCommonJS(rehypeDemo_exports);
|
|
39
39
|
var import_block = __toESM(require("../../../assetParsers/block"));
|
|
40
40
|
var import_utils = require("../../../utils");
|
|
41
|
+
var import_utils2 = require("@umijs/utils");
|
|
41
42
|
var import_path = __toESM(require("path"));
|
|
42
|
-
var import_plugin_utils = require("umi/plugin-utils");
|
|
43
43
|
var visit;
|
|
44
44
|
var SKIP;
|
|
45
45
|
var EXIT;
|
|
@@ -227,7 +227,7 @@ function rehypeDemo(opts) {
|
|
|
227
227
|
}
|
|
228
228
|
});
|
|
229
229
|
if (process.env.NODE_ENV === "production" && (hasOnlySign || hasSkipSign)) {
|
|
230
|
-
|
|
230
|
+
import_utils2.logger.warn(
|
|
231
231
|
`The 'only' or 'skip' mark is not supported in production environment, please remove it. at ${vFile.data.frontmatter.filename}`
|
|
232
232
|
);
|
|
233
233
|
}
|
|
@@ -259,7 +259,7 @@ function rehypeDemo(opts) {
|
|
|
259
259
|
let component = "";
|
|
260
260
|
if (codeType === "external") {
|
|
261
261
|
const chunkName = [vFile.data.frontmatter.atomId, "demos"].filter(Boolean).join("__");
|
|
262
|
-
parseOpts.fileAbsPath = (0,
|
|
262
|
+
parseOpts.fileAbsPath = (0, import_utils2.winPath)(
|
|
263
263
|
codeNode.properties.src
|
|
264
264
|
);
|
|
265
265
|
let localId = ((_b = codeNode.properties) == null ? void 0 : _b.id) ?? import_path.default.parse(
|
|
@@ -271,7 +271,7 @@ function rehypeDemo(opts) {
|
|
|
271
271
|
localId,
|
|
272
272
|
vFile.data.frontmatter.atomId
|
|
273
273
|
);
|
|
274
|
-
const importChunk = `import( /* webpackChunkName: "${chunkName}" */ '${(0,
|
|
274
|
+
const importChunk = `import( /* webpackChunkName: "${chunkName}" */ '${(0, import_utils2.winPath)(
|
|
275
275
|
parseOpts.fileAbsPath
|
|
276
276
|
)}?techStack=${techStack.name}')`;
|
|
277
277
|
if (runtimeOpts == null ? void 0 : runtimeOpts.rendererPath) {
|
|
@@ -281,7 +281,7 @@ function rehypeDemo(opts) {
|
|
|
281
281
|
}
|
|
282
282
|
if (codeValue)
|
|
283
283
|
codeNode.properties.title = codeValue;
|
|
284
|
-
(_c = codeNode.properties).filename ?? (_c.filename = (0,
|
|
284
|
+
(_c = codeNode.properties).filename ?? (_c.filename = (0, import_utils2.winPath)(
|
|
285
285
|
import_path.default.relative(opts.cwd, parseOpts.fileAbsPath)
|
|
286
286
|
));
|
|
287
287
|
} else {
|
|
@@ -323,7 +323,7 @@ function rehypeDemo(opts) {
|
|
|
323
323
|
if (demoIds.indexOf(parseOpts.id) !== demoIds.lastIndexOf(parseOpts.id)) {
|
|
324
324
|
const startLine = (_a2 = node.position) == null ? void 0 : _a2.start.line;
|
|
325
325
|
const suffix = startLine ? `:${startLine}` : "";
|
|
326
|
-
|
|
326
|
+
import_utils2.logger.warn(
|
|
327
327
|
`Duplicate demo id found due to filename conflicts, please consider adding a unique id to code tag to resolve this.
|
|
328
328
|
at ${opts.fileAbsPath}${suffix}`
|
|
329
329
|
);
|
|
@@ -445,7 +445,7 @@ function rehypeDemo(opts) {
|
|
|
445
445
|
vFile.data.demoSharedProps = sharedPreviewerProps;
|
|
446
446
|
}
|
|
447
447
|
replaceNodes.forEach((node) => {
|
|
448
|
-
const demoLoader = `() => import('${(0,
|
|
448
|
+
const demoLoader = `() => import('${(0, import_utils2.winPath)(
|
|
449
449
|
opts.fileAbsPath
|
|
450
450
|
)}?type=demo')`;
|
|
451
451
|
let value = JSON.stringify(node.data[DEMO_PROP_VALUE_KEY]);
|
|
@@ -32,7 +32,6 @@ __export(rehypeJsxify_exports, {
|
|
|
32
32
|
default: () => rehypeJsxify
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(rehypeJsxify_exports);
|
|
35
|
-
var parser = __toESM(require("@umijs/bundler-utils/compiled/babel/parser"));
|
|
36
35
|
var visitUnist;
|
|
37
36
|
var visitEstree;
|
|
38
37
|
var toEstree;
|
|
@@ -48,6 +47,7 @@ var JSX_SPREAD_PROP_PREFIX = "$jsx-spread-prop-";
|
|
|
48
47
|
})();
|
|
49
48
|
function getJSXAttrAST(node) {
|
|
50
49
|
const tmpCode = `<a ${node.type === "JSXAttribute" ? `${node.name}={${node.value}}` : `{...${node.argument}}`} />`;
|
|
50
|
+
const parser = require("@umijs/bundler-utils/compiled/babel/parser");
|
|
51
51
|
const ast = parser.parseExpression(tmpCode, {
|
|
52
52
|
plugins: ["jsx", "estree"]
|
|
53
53
|
});
|
|
@@ -32,17 +32,31 @@ __export(rehypeLink_exports, {
|
|
|
32
32
|
default: () => rehypeLink
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(rehypeLink_exports);
|
|
35
|
-
var
|
|
35
|
+
var import_utils = require("../../../features/tabs/utils");
|
|
36
|
+
var import_utils2 = require("@umijs/utils");
|
|
36
37
|
var import_path = __toESM(require("path"));
|
|
37
|
-
var import_plugin_utils = require("umi/plugin-utils");
|
|
38
38
|
var import_url = __toESM(require("url"));
|
|
39
39
|
var visit;
|
|
40
40
|
var SKIP;
|
|
41
41
|
(async () => {
|
|
42
42
|
({ visit, SKIP } = await import("unist-util-visit"));
|
|
43
43
|
})();
|
|
44
|
+
function createRouteInfo(routes, hostAbsPath) {
|
|
45
|
+
const pathsByFile = /* @__PURE__ */ new Map();
|
|
46
|
+
const absPaths = /* @__PURE__ */ new Set();
|
|
47
|
+
let currentRoute;
|
|
48
|
+
Object.values(routes).forEach((route) => {
|
|
49
|
+
pathsByFile.set(route.file, route.absPath);
|
|
50
|
+
absPaths.add(route.absPath);
|
|
51
|
+
if (!currentRoute && route.file === hostAbsPath)
|
|
52
|
+
currentRoute = route;
|
|
53
|
+
});
|
|
54
|
+
return { pathsByFile, absPaths, currentRoute };
|
|
55
|
+
}
|
|
44
56
|
function rehypeLink(opts) {
|
|
45
57
|
return (tree) => {
|
|
58
|
+
const hostAbsPath = (0, import_utils.getHostForTabRouteFile)(opts.fileAbsPath);
|
|
59
|
+
let routeInfo;
|
|
46
60
|
visit(tree, "element", (node, i, parent) => {
|
|
47
61
|
var _a, _b, _c;
|
|
48
62
|
if (node.tagName === "a" && typeof ((_a = node.properties) == null ? void 0 : _a.href) === "string" && // skip target specified link
|
|
@@ -50,35 +64,35 @@ function rehypeLink(opts) {
|
|
|
50
64
|
!((_c = node.properties) == null ? void 0 : _c.download)) {
|
|
51
65
|
const href = node.properties.href;
|
|
52
66
|
const parsedUrl = import_url.default.parse(href);
|
|
53
|
-
const hostAbsPath = (0, import_tabs.getHostForTabRouteFile)(opts.fileAbsPath);
|
|
54
67
|
if (parsedUrl.protocol || href.startsWith("//"))
|
|
55
68
|
return SKIP;
|
|
56
69
|
if (/\.md$/i.test(parsedUrl.pathname)) {
|
|
57
|
-
const {
|
|
58
|
-
|
|
70
|
+
const { pathsByFile } = routeInfo ?? (routeInfo = createRouteInfo(
|
|
71
|
+
opts.routes,
|
|
72
|
+
hostAbsPath
|
|
73
|
+
));
|
|
74
|
+
const absPath = (0, import_utils2.winPath)(
|
|
59
75
|
import_path.default.resolve(hostAbsPath, "..", parsedUrl.pathname)
|
|
60
76
|
);
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
});
|
|
77
|
+
if (pathsByFile.has(absPath)) {
|
|
78
|
+
parsedUrl.pathname = pathsByFile.get(absPath);
|
|
79
|
+
}
|
|
66
80
|
} else if (parsedUrl.pathname && /^[^/]+/.test(parsedUrl.pathname)) {
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
);
|
|
81
|
+
const { currentRoute, absPaths } = routeInfo ?? (routeInfo = createRouteInfo(
|
|
82
|
+
opts.routes,
|
|
83
|
+
hostAbsPath
|
|
84
|
+
));
|
|
71
85
|
if (!currentRoute)
|
|
72
86
|
return;
|
|
73
87
|
const basePath = currentRoute.absPath;
|
|
74
88
|
const htmlTargetPath = import_url.default.resolve(basePath, parsedUrl.pathname);
|
|
75
|
-
const rr6TargetPath = (0,
|
|
89
|
+
const rr6TargetPath = (0, import_utils2.winPath)(
|
|
76
90
|
import_path.default.resolve(basePath, parsedUrl.pathname)
|
|
77
91
|
);
|
|
78
92
|
parsedUrl.pathname = htmlTargetPath;
|
|
79
|
-
if (
|
|
93
|
+
if (!absPaths.has(htmlTargetPath) && absPaths.has(rr6TargetPath)) {
|
|
80
94
|
parsedUrl.pathname = rr6TargetPath;
|
|
81
|
-
|
|
95
|
+
import_utils2.logger.warn(
|
|
82
96
|
`Detected ambiguous link \`${href}\` in \`${opts.fileAbsPath}\`, please use \`./xxx.md\` file path instead of normal relative path, dumi will deprecate this behavior in the future.
|
|
83
97
|
See more: https://github.com/umijs/dumi/pull/1491`
|
|
84
98
|
);
|
|
@@ -89,7 +103,7 @@ function rehypeLink(opts) {
|
|
|
89
103
|
tagName: "Link",
|
|
90
104
|
children: node.children,
|
|
91
105
|
properties: {
|
|
92
|
-
...
|
|
106
|
+
...import_utils2.lodash.omit(node.properties, ["href"]),
|
|
93
107
|
to: import_url.default.format(parsedUrl)
|
|
94
108
|
}
|
|
95
109
|
});
|
|
@@ -32,7 +32,7 @@ __export(rehypeRaw_exports, {
|
|
|
32
32
|
default: () => rehypeRaw
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(rehypeRaw_exports);
|
|
35
|
-
var
|
|
35
|
+
var import_utils = require("@umijs/utils");
|
|
36
36
|
var raw;
|
|
37
37
|
var visit;
|
|
38
38
|
var COMPONENT_NAME_REGEX = /(<)([A-Z][a-zA-Z\d]*)([\s|>])/g;
|
|
@@ -71,7 +71,7 @@ function rehypeRaw(opts) {
|
|
|
71
71
|
node.properties[CODE_META_STUB_ATTR] = node.data.meta;
|
|
72
72
|
}
|
|
73
73
|
if (node.type === "raw" && /<code[^>]*src=[^>]*\/>/.test(node.value)) {
|
|
74
|
-
|
|
74
|
+
import_utils.logger.warn(`<code /> is not supported, please use <code></code> instead.
|
|
75
75
|
File: ${opts.fileAbsPath}`);
|
|
76
76
|
}
|
|
77
77
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
+
import { CONTENT_TEXTS_OBJ_NAME } from '../../constants';
|
|
1
2
|
import type { Root } from 'hast';
|
|
2
3
|
import type { Transformer } from 'unified';
|
|
3
|
-
export
|
|
4
|
+
export { CONTENT_TEXTS_OBJ_NAME };
|
|
4
5
|
export default function rehypeText(): Transformer<Root>;
|
|
@@ -29,13 +29,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
29
29
|
// src/loaders/markdown/transformer/rehypeText.ts
|
|
30
30
|
var rehypeText_exports = {};
|
|
31
31
|
__export(rehypeText_exports, {
|
|
32
|
-
CONTENT_TEXTS_OBJ_NAME: () => CONTENT_TEXTS_OBJ_NAME,
|
|
32
|
+
CONTENT_TEXTS_OBJ_NAME: () => import_constants.CONTENT_TEXTS_OBJ_NAME,
|
|
33
33
|
default: () => rehypeText
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(rehypeText_exports);
|
|
36
|
+
var import_constants = require("../../constants");
|
|
36
37
|
var import_rehypeIsolation = require("./rehypeIsolation");
|
|
37
38
|
var import_rehypeSlug = require("./rehypeSlug");
|
|
38
|
-
var CONTENT_TEXTS_OBJ_NAME = "$$contentTexts";
|
|
39
39
|
var visit;
|
|
40
40
|
(async () => {
|
|
41
41
|
({ visitParents: visit } = await import("unist-util-visit-parents"));
|
|
@@ -92,7 +92,7 @@ function rehypeText() {
|
|
|
92
92
|
computed: true,
|
|
93
93
|
object: {
|
|
94
94
|
type: "Identifier",
|
|
95
|
-
name: CONTENT_TEXTS_OBJ_NAME
|
|
95
|
+
name: import_constants.CONTENT_TEXTS_OBJ_NAME
|
|
96
96
|
},
|
|
97
97
|
property: {
|
|
98
98
|
type: "Literal",
|
|
@@ -32,7 +32,7 @@ __export(remarkBreaks_exports, {
|
|
|
32
32
|
default: () => remarkBreaks
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(remarkBreaks_exports);
|
|
35
|
-
var
|
|
35
|
+
var import_utils = require("@umijs/utils");
|
|
36
36
|
var findAndReplace;
|
|
37
37
|
(async () => {
|
|
38
38
|
({ findAndReplace } = await import("mdast-util-find-and-replace"));
|
|
@@ -42,13 +42,13 @@ function logDeprecationWarning(fileAbsPath) {
|
|
|
42
42
|
if (warningLock.get(fileAbsPath))
|
|
43
43
|
return;
|
|
44
44
|
warningLock.set(fileAbsPath, true);
|
|
45
|
-
|
|
45
|
+
import_utils.logger.warn(
|
|
46
46
|
"Detected that you are using soft breaks, dumi will transform them into spaces after the declaration",
|
|
47
47
|
"version greater than or equal to `2.2.0`, however, they are still being transformed as line breaks now, please",
|
|
48
48
|
"migrate them to hard breaks before upgrading the declaration version for dumi.\n",
|
|
49
|
-
|
|
49
|
+
import_utils.chalk.grey(` at ${fileAbsPath}
|
|
50
50
|
`),
|
|
51
|
-
|
|
51
|
+
import_utils.chalk.grey(" see also: https://github.com/umijs/dumi/issues/1683\n")
|
|
52
52
|
);
|
|
53
53
|
}
|
|
54
54
|
function remarkBreaks(opts) {
|