dumi 2.2.1-alpha.0 → 2.2.1

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.
@@ -11,7 +11,8 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
11
11
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
12
12
 
13
13
  import { getParameters } from 'codesandbox/lib/api/define';
14
- import { genReactRenderCode } from "./utils";
14
+ import { ApplyPluginsType } from 'dumi';
15
+ import { genReactRenderCode, pluginManager } from "./utils";
15
16
  var CSB_API_ENDPOINT = 'https://codesandbox.io/api/v1/sandboxes/define';
16
17
  /**
17
18
  * get serialized data that use to submit to codesandbox.io
@@ -78,9 +79,15 @@ function getCSBData(opts) {
78
79
  content: genReactRenderCode(deps.react),
79
80
  isBinary: false
80
81
  };
81
- return getParameters({
82
- files: files
82
+ var csbOpts = pluginManager.applyPlugins({
83
+ type: ApplyPluginsType.modify,
84
+ key: 'modifyCodeSandboxData',
85
+ initialValue: {
86
+ files: files
87
+ },
88
+ args: opts
83
89
  });
90
+ return getParameters(csbOpts);
84
91
  }
85
92
  /**
86
93
  * use CodeSandbox.io
@@ -11,7 +11,8 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
11
11
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
12
12
 
13
13
  import sdk from '@stackblitz/sdk';
14
- import { genReactRenderCode } from "./utils";
14
+ import { ApplyPluginsType } from 'dumi';
15
+ import { genReactRenderCode, pluginManager } from "./utils";
15
16
  export var openStackBlitz = function openStackBlitz(data) {
16
17
  var _data$asset$dependenc, _react, _deps$_react, _reactDom, _deps$_reactDom;
17
18
 
@@ -56,5 +57,11 @@ export var openStackBlitz = function openStackBlitz(data) {
56
57
  }, null, 2);
57
58
  files[entryFileName] = genReactRenderCode(deps.react);
58
59
  config.files = files;
59
- sdk.openProject(config);
60
+ var stbOpts = pluginManager.applyPlugins({
61
+ type: ApplyPluginsType.modify,
62
+ key: 'modifyStackBlitzData',
63
+ initialValue: config,
64
+ args: data
65
+ });
66
+ sdk.openProject(stbOpts);
60
67
  };
@@ -1,5 +1,11 @@
1
- import { useEffect } from 'react';
1
+ import { PluginManager } from 'dumi';
2
+ import { useLayoutEffect } from 'react';
2
3
  import type { ILocale, INav, INavItem, IRouteMeta, IRoutesById, IUserNavValue } from './types';
4
+ /**
5
+ * private instance, do not use it in your code
6
+ */
7
+ export declare let pluginManager: PluginManager;
8
+ export declare const setPluginManager: (pm: PluginManager) => void;
3
9
  export declare const useLocaleDocRoutes: () => IRoutesById;
4
10
  /**
5
11
  * 在 react 18 中需要新的 render 方式,这个函数用来处理不同的 jsx 模式。
@@ -7,7 +13,7 @@ export declare const useLocaleDocRoutes: () => IRoutesById;
7
13
  * @returns code string
8
14
  */
9
15
  export declare const genReactRenderCode: (version: string) => string;
10
- export declare const useIsomorphicLayoutEffect: typeof useEffect;
16
+ export declare const useIsomorphicLayoutEffect: typeof useLayoutEffect;
11
17
  /**
12
18
  * common comparer for sidebar/nav items
13
19
  */
@@ -15,6 +15,14 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
15
15
  import { useAppData, useIntl, useSiteData } from 'dumi';
16
16
  import { useCallback, useEffect, useLayoutEffect, useState } from 'react';
17
17
  import { useLocale } from "./useLocale";
18
+ /**
19
+ * private instance, do not use it in your code
20
+ */
21
+
22
+ export var pluginManager;
23
+ export var setPluginManager = function setPluginManager(pm) {
24
+ pluginManager = pm;
25
+ };
18
26
  export var useLocaleDocRoutes = function useLocaleDocRoutes() {
19
27
  var intl = useIntl();
20
28
 
@@ -16,3 +16,4 @@ export declare const PICKED_PKG_FIELDS: {
16
16
  };
17
17
  export declare const USELESS_TMP_FILES: string[];
18
18
  export declare const VERSION_2_LEVEL_NAV = "^2.2.0";
19
+ export declare const VERSION_2_DEPRECATE_SOFT_BREAKS = "^2.2.0";
package/dist/constants.js CHANGED
@@ -28,6 +28,7 @@ __export(constants_exports, {
28
28
  SP_ROUTE_PREFIX: () => SP_ROUTE_PREFIX,
29
29
  THEME_PREFIX: () => THEME_PREFIX,
30
30
  USELESS_TMP_FILES: () => USELESS_TMP_FILES,
31
+ VERSION_2_DEPRECATE_SOFT_BREAKS: () => VERSION_2_DEPRECATE_SOFT_BREAKS,
31
32
  VERSION_2_LEVEL_NAV: () => VERSION_2_LEVEL_NAV
32
33
  });
33
34
  module.exports = __toCommonJS(constants_exports);
@@ -49,6 +50,7 @@ var PICKED_PKG_FIELDS = {
49
50
  };
50
51
  var USELESS_TMP_FILES = ["tsconfig.json", "typings.d.ts"];
51
52
  var VERSION_2_LEVEL_NAV = "^2.2.0";
53
+ var VERSION_2_DEPRECATE_SOFT_BREAKS = "^2.2.0";
52
54
  // Annotate the CommonJS export names for ESM import in node:
53
55
  0 && (module.exports = {
54
56
  LOCAL_DUMI_DIR,
@@ -60,5 +62,6 @@ var VERSION_2_LEVEL_NAV = "^2.2.0";
60
62
  SP_ROUTE_PREFIX,
61
63
  THEME_PREFIX,
62
64
  USELESS_TMP_FILES,
65
+ VERSION_2_DEPRECATE_SOFT_BREAKS,
63
66
  VERSION_2_LEVEL_NAV
64
67
  });
@@ -55,7 +55,8 @@ var compile_default = (api) => {
55
55
  resolve: api.config.resolve,
56
56
  extraRemarkPlugins: api.config.extraRemarkPlugins,
57
57
  extraRehypePlugins: api.config.extraRehypePlugins,
58
- routes: api.appData.routes
58
+ routes: api.appData.routes,
59
+ pkg: api.pkg
59
60
  };
60
61
  memo.module.rule("dumi-md").type("javascript/auto").test(/\.md$/).oneOf("md-meta").resourceQuery(/meta$/).use("babel-loader").loader(babelInUmi.loader).options(babelInUmi.options).end().use("md-meta-loader").loader(loaderPath).options({
61
62
  ...loaderBaseOpts,
@@ -35,8 +35,8 @@ var import_loader = __toESM(require("./loader"));
35
35
  var DEFAULT_THEME_PATH = import_path.default.join(__dirname, "../../../theme-default");
36
36
  function getPkgThemeName(api) {
37
37
  if (process.env.DUMI_THEME) {
38
- const themePkg = require(import_path.default.join(process.env.DUMI_THEME, "package.json"));
39
- return themePkg.name;
38
+ const envThemePkgPath = require.resolve(import_path.default.join(process.env.DUMI_THEME, "package.json"), { paths: [api.cwd] });
39
+ return require(envThemePkgPath).name;
40
40
  }
41
41
  const validDeps = Object.assign({}, api.pkg.dependencies, api.pkg.devDependencies);
42
42
  const pkgThemeName = Object.keys(validDeps).find((pkg) => pkg.split("/").pop().startsWith(import_constants.THEME_PREFIX));
@@ -44,7 +44,10 @@ function getPkgThemeName(api) {
44
44
  }
45
45
  function getPkgThemePath(api) {
46
46
  const pkgThemeName = getPkgThemeName(api);
47
- return process.env.DUMI_THEME || pkgThemeName && import_path.default.dirname(import_plugin_utils.resolve.sync(`${process.env.DUMI_THEME || pkgThemeName}/package.json`, {
47
+ if (process.env.DUMI_THEME) {
48
+ return import_path.default.resolve(api.cwd, process.env.DUMI_THEME);
49
+ }
50
+ return pkgThemeName && import_path.default.dirname(import_plugin_utils.resolve.sync(`${pkgThemeName}/package.json`, {
48
51
  basedir: api.cwd,
49
52
  preserveSymlinks: true
50
53
  }));
@@ -326,6 +329,21 @@ export default function DumiContextWrapper() {
326
329
  );
327
330
  })();`;
328
331
  });
332
+ api.addEntryImportsAhead(() => [
333
+ {
334
+ specifier: "{ getPluginManager as getDumiPluginManager }",
335
+ source: "./core/plugin"
336
+ },
337
+ {
338
+ specifier: "{ setPluginManager as setDumiPluginManager }",
339
+ source: (0, import_plugin_utils.winPath)(require.resolve("../../client/theme-api/utils"))
340
+ }
341
+ ]);
342
+ api.addEntryCode(() => "setDumiPluginManager(getDumiPluginManager());");
343
+ api.addRuntimePluginKey(() => [
344
+ "modifyCodeSandboxData",
345
+ "modifyStackBlitzData"
346
+ ]);
329
347
  if (require("@umijs/core/package").__npminstall_done && import_fs.default.existsSync(localThemePath) && import_fs.default.lstatSync(localThemePath).isSymbolicLink()) {
330
348
  api.chainWebpack((memo) => {
331
349
  const devThemeNodeModules = import_path.default.join(api.cwd, "../node_modules");
@@ -1,6 +1,6 @@
1
1
  import type { IParsedBlockAsset } from "../../../assetParsers/block";
2
2
  import type { IRouteMeta } from "../../../client/theme-api/types";
3
- import type { IDumiConfig, IDumiTechStack } from "../../../types";
3
+ import type { IApi, IDumiConfig, IDumiTechStack } from "../../../types";
4
4
  import type { IRoute } from 'umi';
5
5
  import type { Data } from 'vfile';
6
6
  declare module 'hast' {
@@ -42,6 +42,7 @@ export interface IMdTransformerOptions {
42
42
  extraRemarkPlugins?: IDumiConfig['extraRemarkPlugins'];
43
43
  extraRehypePlugins?: IDumiConfig['extraRehypePlugins'];
44
44
  routes: Record<string, IRoute>;
45
+ pkg: IApi['pkg'];
45
46
  }
46
47
  export interface IMdTransformerResult {
47
48
  content: string;
@@ -25,7 +25,9 @@ __export(transformer_exports, {
25
25
  default: () => transformer_default
26
26
  });
27
27
  module.exports = __toCommonJS(transformer_exports);
28
+ var import_constants = require("../../../constants");
28
29
  var import_enhanced_resolve = __toESM(require("enhanced-resolve"));
30
+ var import_plugin_utils = require("umi/plugin-utils");
29
31
  var import_rehypeDemo = __toESM(require("./rehypeDemo"));
30
32
  var import_rehypeDesc = __toESM(require("./rehypeDesc"));
31
33
  var import_rehypeEnhancedTag = __toESM(require("./rehypeEnhancedTag"));
@@ -38,9 +40,17 @@ var import_rehypeRaw = __toESM(require("./rehypeRaw"));
38
40
  var import_rehypeSlug = __toESM(require("./rehypeSlug"));
39
41
  var import_rehypeStrip = __toESM(require("./rehypeStrip"));
40
42
  var import_rehypeText = __toESM(require("./rehypeText"));
43
+ var import_remarkBreaks = __toESM(require("./remarkBreaks"));
41
44
  var import_remarkContainer = __toESM(require("./remarkContainer"));
42
45
  var import_remarkEmbed = __toESM(require("./remarkEmbed"));
43
46
  var import_remarkMeta = __toESM(require("./remarkMeta"));
47
+ function keepSoftBreak(pkg) {
48
+ var _a, _b, _c;
49
+ if (((_a = pkg == null ? void 0 : pkg.name) == null ? void 0 : _a.startsWith("@examples/")) || (pkg == null ? void 0 : pkg.name) === "dumi")
50
+ return false;
51
+ const ver = ((_b = pkg == null ? void 0 : pkg.devDependencies) == null ? void 0 : _b.dumi) ?? ((_c = pkg == null ? void 0 : pkg.dependencies) == null ? void 0 : _c.dumi) ?? "^2.0.0";
52
+ return !import_plugin_utils.semver.subset(ver, import_constants.VERSION_2_DEPRECATE_SOFT_BREAKS);
53
+ }
44
54
  function applyUnifiedPlugin(opts) {
45
55
  const [plugin, options] = Array.isArray(opts.plugin) ? opts.plugin : [opts.plugin];
46
56
  const mod = typeof plugin === "function" ? plugin : require(require.resolve(plugin, { paths: [opts.cwd] }));
@@ -53,7 +63,6 @@ var transformer_default = async (raw, opts) => {
53
63
  const { default: remarkParse } = await import("remark-parse");
54
64
  const { default: remarkFrontmatter } = await import("remark-frontmatter");
55
65
  const { default: remarkDirective } = await import("remark-directive");
56
- const { default: remarkBreaks } = await import("remark-breaks");
57
66
  const { default: remarkGfm } = await import("remark-gfm");
58
67
  const { default: remarkRehype } = await import("remark-rehype");
59
68
  const { default: rehypeAutolinkHeadings } = await import("rehype-autolink-headings");
@@ -66,7 +75,10 @@ var transformer_default = async (raw, opts) => {
66
75
  cwd: opts.cwd,
67
76
  fileAbsPath: opts.fileAbsPath,
68
77
  resolve: opts.resolve
69
- }).use(remarkDirective).use(import_remarkContainer.default).use(remarkBreaks).use(remarkGfm);
78
+ }).use(remarkDirective).use(import_remarkContainer.default).use(remarkGfm);
79
+ if (keepSoftBreak(opts.pkg)) {
80
+ processor.use(import_remarkBreaks.default, { fileAbsPath: opts.fileAbsPath });
81
+ }
70
82
  (_a = opts.extraRemarkPlugins) == null ? void 0 : _a.forEach((plugin) => applyUnifiedPlugin({
71
83
  plugin,
72
84
  processor,
@@ -0,0 +1,3 @@
1
+ import type { IMdTransformerOptions } from "./index";
2
+ import type { Root } from 'mdast';
3
+ export default function remarkBreaks(opts: Pick<IMdTransformerOptions, 'fileAbsPath'>): (tree: Root) => void;
@@ -0,0 +1,54 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+
22
+ // src/loaders/markdown/transformer/remarkBreaks.ts
23
+ var remarkBreaks_exports = {};
24
+ __export(remarkBreaks_exports, {
25
+ default: () => remarkBreaks
26
+ });
27
+ module.exports = __toCommonJS(remarkBreaks_exports);
28
+ var import_plugin_utils = require("umi/plugin-utils");
29
+ var findAndReplace;
30
+ (async () => {
31
+ ({ findAndReplace } = await import("mdast-util-find-and-replace"));
32
+ })();
33
+ var warningLock = /* @__PURE__ */ new Map();
34
+ function logDeprecationWarning(fileAbsPath) {
35
+ if (warningLock.get(fileAbsPath))
36
+ return;
37
+ warningLock.set(fileAbsPath, true);
38
+ import_plugin_utils.logger.warn("Detected that you are using soft breaks, dumi will transform them into spaces after the declaration", "version greater than or equal to `2.2.0`, however, they are still being transformed as line breaks now, please", "migrate them to hard breaks before upgrading the declaration version for dumi.\n", import_plugin_utils.chalk.grey(` at ${fileAbsPath}
39
+ `), import_plugin_utils.chalk.grey(" see also: https://github.com/umijs/dumi/issues/1683\n"));
40
+ }
41
+ function remarkBreaks(opts) {
42
+ const replace = (_, match) => {
43
+ if (match.input === "\n" || match.input === "\r" || match.input === "\r\n") {
44
+ return false;
45
+ }
46
+ logDeprecationWarning(opts.fileAbsPath);
47
+ return { type: "break" };
48
+ };
49
+ return (tree) => {
50
+ findAndReplace(tree, /\r?\n|\r/g, replace);
51
+ };
52
+ }
53
+ // Annotate the CommonJS export names for ESM import in node:
54
+ 0 && (module.exports = {});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dumi",
3
- "version": "2.2.1-alpha.0",
3
+ "version": "2.2.1",
4
4
  "description": "📖 Documentation Generator of React Component",
5
5
  "keywords": [
6
6
  "generator",
@@ -106,6 +106,7 @@
106
106
  "html2sketch": "^1.0.1",
107
107
  "js-yaml": "^4.1.0",
108
108
  "lodash.throttle": "^4.1.1",
109
+ "mdast-util-find-and-replace": "^2.2.2",
109
110
  "mdast-util-to-string": "^3.1.0",
110
111
  "nprogress": "^0.2.0",
111
112
  "pluralize": "^8.0.0",
@@ -122,7 +123,6 @@
122
123
  "rehype-autolink-headings": "^6.1.1",
123
124
  "rehype-remove-comments": "^5.0.0",
124
125
  "rehype-stringify": "^9.0.3",
125
- "remark-breaks": "^3.0.2",
126
126
  "remark-directive": "^2.0.1",
127
127
  "remark-frontmatter": "^4.0.1",
128
128
  "remark-gfm": "^3.0.1",