dumi 2.4.8 → 2.4.10
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/features/compile/index.js +3 -1
- package/dist/features/compile/makoHooks.js +4 -1
- package/dist/features/compile/utils.d.ts +2 -0
- package/dist/features/compile/utils.js +42 -0
- package/dist/loaders/markdown/index.d.ts +1 -0
- package/dist/loaders/markdown/index.js +10 -11
- package/package.json +1 -1
|
@@ -39,6 +39,7 @@ var import_fs = __toESM(require("fs"));
|
|
|
39
39
|
var import_path = __toESM(require("path"));
|
|
40
40
|
var import_assets = require("../assets");
|
|
41
41
|
var import_makoHooks = require("./makoHooks");
|
|
42
|
+
var import_utils2 = require("./utils");
|
|
42
43
|
var techStacks = [];
|
|
43
44
|
var compile_default = (api) => {
|
|
44
45
|
api.describe({ key: "dumi:compile" });
|
|
@@ -113,7 +114,8 @@ var compile_default = (api) => {
|
|
|
113
114
|
extraRehypePlugins: api.config.extraRehypePlugins,
|
|
114
115
|
routes: api.appData.routes,
|
|
115
116
|
locales: api.config.locales,
|
|
116
|
-
pkg: api.pkg
|
|
117
|
+
pkg: api.pkg,
|
|
118
|
+
disableLiveDemo: (0, import_utils2.shouldDisabledLiveDemo)(api)
|
|
117
119
|
};
|
|
118
120
|
memo.module.rule("watch-parent").pre().resourceQuery(/watch=parent/).use("null-loader").loader(require.resolve("../../loaders/null")).end();
|
|
119
121
|
const mdRule = memo.module.rule("dumi-md").type("javascript/auto").test(/\.md$/);
|
|
@@ -38,6 +38,7 @@ var import_url = __toESM(require("url"));
|
|
|
38
38
|
var import__ = require(".");
|
|
39
39
|
var import_utils = require("../../utils");
|
|
40
40
|
var import_assets = require("../assets");
|
|
41
|
+
var import_utils2 = require("./utils");
|
|
41
42
|
var modeMap = {
|
|
42
43
|
"demo-index": "demo-index",
|
|
43
44
|
frontmatter: "frontmatter",
|
|
@@ -53,6 +54,7 @@ var customRunLoaders = async (options) => {
|
|
|
53
54
|
};
|
|
54
55
|
var mdLoaderPath = require.resolve("../../loaders/markdown");
|
|
55
56
|
var getLoadHook = (api) => {
|
|
57
|
+
const disableLiveDemo = (0, import_utils2.shouldDisabledLiveDemo)(api);
|
|
56
58
|
return async (filePath) => {
|
|
57
59
|
var _a, _b, _c, _d;
|
|
58
60
|
const loaderBaseOpts = {
|
|
@@ -64,7 +66,8 @@ var getLoadHook = (api) => {
|
|
|
64
66
|
extraRehypePlugins: api.config.extraRehypePlugins,
|
|
65
67
|
routes: api.appData.routes,
|
|
66
68
|
locales: api.config.locales || [],
|
|
67
|
-
pkg: api.pkg
|
|
69
|
+
pkg: api.pkg,
|
|
70
|
+
disableLiveDemo
|
|
68
71
|
};
|
|
69
72
|
const requestUrl = import_url.default.parse(filePath);
|
|
70
73
|
const query = import_querystring.default.parse(requestUrl.query);
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/features/compile/utils.ts
|
|
20
|
+
var utils_exports = {};
|
|
21
|
+
__export(utils_exports, {
|
|
22
|
+
shouldDisabledLiveDemo: () => shouldDisabledLiveDemo
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(utils_exports);
|
|
25
|
+
var import_utils = require("@umijs/utils");
|
|
26
|
+
var import_lodash = require("@umijs/utils/compiled/lodash");
|
|
27
|
+
var shouldDisabledLiveDemo = (api) => {
|
|
28
|
+
const extraBabelPlugins = api.userConfig.extraBabelPlugins;
|
|
29
|
+
const disableFlag = (0, import_lodash.isArray)(extraBabelPlugins) && extraBabelPlugins.some(
|
|
30
|
+
(p) => /^import$|babel-plugin-import/.test(p[0])
|
|
31
|
+
);
|
|
32
|
+
if (disableFlag) {
|
|
33
|
+
import_utils.logger.warn(
|
|
34
|
+
"live demo feature has been automatically disabled since babel-plugin-import be registered, if you want to enable live demo feature, checkout: https://d.umijs.org/guide/faq"
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
return disableFlag;
|
|
38
|
+
};
|
|
39
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
40
|
+
0 && (module.exports = {
|
|
41
|
+
shouldDisabledLiveDemo
|
|
42
|
+
});
|
|
@@ -5,6 +5,7 @@ interface IMdLoaderDefaultModeOptions extends Omit<IMdTransformerOptions, 'fileA
|
|
|
5
5
|
builtins: IThemeLoadResult['builtins'];
|
|
6
6
|
onResolveDemos?: (demos: NonNullable<IMdTransformerResult['meta']['demos']>) => void;
|
|
7
7
|
onResolveAtomMeta?: (atomId: string, meta: IMdTransformerResult['meta']['frontmatter']) => void;
|
|
8
|
+
disableLiveDemo: boolean;
|
|
8
9
|
}
|
|
9
10
|
interface IMdLoaderDemosModeOptions extends Omit<IMdLoaderDefaultModeOptions, 'builtins' | 'mode'> {
|
|
10
11
|
mode: 'meta';
|
|
@@ -50,7 +50,7 @@ function getDemoSourceFiles(demos = []) {
|
|
|
50
50
|
}, []);
|
|
51
51
|
}
|
|
52
52
|
function isRelativePath(path2) {
|
|
53
|
-
return
|
|
53
|
+
return /^\.{1,2}(?!\w)/.test(path2);
|
|
54
54
|
}
|
|
55
55
|
function emitDefault(opts, ret) {
|
|
56
56
|
const { frontmatter, demos } = ret.meta;
|
|
@@ -101,20 +101,19 @@ function emitDemo(opts, ret) {
|
|
|
101
101
|
demoDepsMap[_a = demo.id] ?? (demoDepsMap[_a] = {});
|
|
102
102
|
Object.keys(demo.resolveMap).forEach((key, index) => {
|
|
103
103
|
const specifier = `${demo.id.replace(/-/g, "_")}_deps_${index}`;
|
|
104
|
-
if (key !== entryFileName
|
|
105
|
-
|
|
106
|
-
|
|
104
|
+
if (key !== entryFileName) {
|
|
105
|
+
const normalizedKey = isRelativePath(key) ? (0, import_plugin_utils.winPath)(demo.resolveMap[key]) : key;
|
|
106
|
+
if (!shareDepsMap[normalizedKey]) {
|
|
107
|
+
demoDepsMap[demo.id][normalizedKey] = specifier;
|
|
108
|
+
shareDepsMap[normalizedKey] = specifier;
|
|
107
109
|
} else {
|
|
108
|
-
demoDepsMap[demo.id][
|
|
109
|
-
shareDepsMap[key] = specifier;
|
|
110
|
+
demoDepsMap[demo.id][normalizedKey] = shareDepsMap[normalizedKey];
|
|
110
111
|
}
|
|
111
|
-
} else if (isRelativePath(key)) {
|
|
112
|
-
demoDepsMap[demo.id][(0, import_plugin_utils.winPath)(demo.resolveMap[key])] = specifier;
|
|
113
112
|
}
|
|
114
113
|
});
|
|
115
114
|
}
|
|
116
115
|
});
|
|
117
|
-
const dedupedDemosDeps = Object.entries(demoDepsMap).reduce((acc, [, deps]) => {
|
|
116
|
+
const dedupedDemosDeps = opts.disableLiveDemo ? [] : Object.entries(demoDepsMap).reduce((acc, [, deps]) => {
|
|
118
117
|
return acc.concat(
|
|
119
118
|
Object.entries(deps).map(([key, specifier]) => {
|
|
120
119
|
const existingIndex = acc.findIndex((obj) => obj.key === key);
|
|
@@ -165,7 +164,7 @@ export const demos = {
|
|
|
165
164
|
return JSON.stringify(asset, null, 2).replace(/"{{{|}}}"/g, "");
|
|
166
165
|
},
|
|
167
166
|
renderContext: function renderContext() {
|
|
168
|
-
if (!("resolveMap" in this) || !("asset" in this))
|
|
167
|
+
if (!("resolveMap" in this) || !("asset" in this) || opts.disableLiveDemo)
|
|
169
168
|
return "undefined";
|
|
170
169
|
const context = Object.entries(demoDepsMap[this.id]).reduce(
|
|
171
170
|
(acc, [key, specifier]) => ({
|
|
@@ -177,7 +176,7 @@ export const demos = {
|
|
|
177
176
|
return JSON.stringify(context, null, 2).replace(/"{{{|}}}"/g, "");
|
|
178
177
|
},
|
|
179
178
|
renderRenderOpts: function renderRenderOpts() {
|
|
180
|
-
if (!("renderOpts" in this)) {
|
|
179
|
+
if (!("renderOpts" in this) || opts.disableLiveDemo) {
|
|
181
180
|
return "undefined";
|
|
182
181
|
}
|
|
183
182
|
const renderOpts = this.renderOpts;
|