dumi 2.4.9 → 2.4.11

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.
@@ -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,2 @@
1
+ import { IApi } from 'umi';
2
+ export declare const shouldDisabledLiveDemo: (api: IApi) => boolean;
@@ -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 path2.startsWith("./") || path2.startsWith("../");
53
+ return /^\.{1,2}(?!\w)/.test(path2);
54
54
  }
55
55
  function emitDefault(opts, ret) {
56
56
  const { frontmatter, demos } = ret.meta;
@@ -100,7 +100,7 @@ function emitDemo(opts, ret) {
100
100
  const entryFileName = Object.keys(demo.asset.dependencies)[0];
101
101
  demoDepsMap[_a = demo.id] ?? (demoDepsMap[_a] = {});
102
102
  Object.keys(demo.resolveMap).forEach((key, index) => {
103
- const specifier = `${demo.id.replace(/-/g, "_")}_deps_${index}`;
103
+ const specifier = `${demo.id.replace(/[^\w\d]/g, "_")}_deps_${index}`;
104
104
  if (key !== entryFileName) {
105
105
  const normalizedKey = isRelativePath(key) ? (0, import_plugin_utils.winPath)(demo.resolveMap[key]) : key;
106
106
  if (!shareDepsMap[normalizedKey]) {
@@ -113,7 +113,7 @@ function emitDemo(opts, ret) {
113
113
  });
114
114
  }
115
115
  });
116
- const dedupedDemosDeps = Object.entries(demoDepsMap).reduce((acc, [, deps]) => {
116
+ const dedupedDemosDeps = opts.disableLiveDemo ? [] : Object.entries(demoDepsMap).reduce((acc, [, deps]) => {
117
117
  return acc.concat(
118
118
  Object.entries(deps).map(([key, specifier]) => {
119
119
  const existingIndex = acc.findIndex((obj) => obj.key === key);
@@ -164,7 +164,7 @@ export const demos = {
164
164
  return JSON.stringify(asset, null, 2).replace(/"{{{|}}}"/g, "");
165
165
  },
166
166
  renderContext: function renderContext() {
167
- if (!("resolveMap" in this) || !("asset" in this))
167
+ if (!("resolveMap" in this) || !("asset" in this) || opts.disableLiveDemo)
168
168
  return "undefined";
169
169
  const context = Object.entries(demoDepsMap[this.id]).reduce(
170
170
  (acc, [key, specifier]) => ({
@@ -176,7 +176,7 @@ export const demos = {
176
176
  return JSON.stringify(context, null, 2).replace(/"{{{|}}}"/g, "");
177
177
  },
178
178
  renderRenderOpts: function renderRenderOpts() {
179
- if (!("renderOpts" in this)) {
179
+ if (!("renderOpts" in this) || opts.disableLiveDemo) {
180
180
  return "undefined";
181
181
  }
182
182
  const renderOpts = this.renderOpts;
@@ -22,9 +22,10 @@ __export(post_raw_exports, {
22
22
  default: () => postRawLoader
23
23
  });
24
24
  module.exports = __toCommonJS(post_raw_exports);
25
+ var import_utils = require("@umijs/utils");
25
26
  function postRawLoader(raw) {
26
27
  return `
27
- import '${this.resourcePath}?watch=parent';
28
+ import '${(0, import_utils.winPath)(this.resourcePath)}?watch=parent';
28
29
  ${raw};
29
30
  `;
30
31
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dumi",
3
- "version": "2.4.9",
3
+ "version": "2.4.11",
4
4
  "description": "📖 Documentation Generator of React Component",
5
5
  "keywords": [
6
6
  "generator",