dumi 2.1.17 → 2.1.18

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.
@@ -22,7 +22,8 @@ var DemoErrorBoundary = function DemoErrorBoundary(props) {
22
22
 
23
23
  export var DumiDemo = function DumiDemo(props) {
24
24
  var _useSiteData = useSiteData(),
25
- demos = _useSiteData.demos;
25
+ demos = _useSiteData.demos,
26
+ historyType = _useSiteData.historyType;
26
27
 
27
28
  var _useAppData = useAppData(),
28
29
  basename = _useAppData.basename;
@@ -37,9 +38,11 @@ export var DumiDemo = function DumiDemo(props) {
37
38
  return /*#__PURE__*/React.createElement(DemoErrorBoundary, null, /*#__PURE__*/createElement(component));
38
39
  }
39
40
 
41
+ var isHashRoute = historyType === 'hash';
40
42
  return /*#__PURE__*/React.createElement(Previewer, _extends({
41
43
  asset: asset,
42
44
  demoUrl: // allow user override demoUrl by frontmatter
43
- props.previewerProps.demoUrl || "".concat(basename).concat(SP_ROUTE_PREFIX, "demos/").concat(props.demo.id)
45
+ props.previewerProps.demoUrl || // when use hash route, browser can automatically handle relative paths starting with #
46
+ "".concat(isHashRoute ? "#" : '').concat(basename).concat(SP_ROUTE_PREFIX, "demos/").concat(props.demo.id)
44
47
  }, props.previewerProps), props.previewerProps.iframe ? null : /*#__PURE__*/React.createElement(DemoErrorBoundary, null, /*#__PURE__*/createElement(component)));
45
48
  };
@@ -4,6 +4,7 @@ import { type ComponentType } from 'react';
4
4
  import type { ILocalesConfig, IPreviewerProps, IThemeConfig } from './types';
5
5
  interface ISiteContext {
6
6
  pkg: Partial<Record<keyof typeof PICKED_PKG_FIELDS, any>>;
7
+ historyType: 'browser' | 'hash' | 'memory';
7
8
  entryExports: Record<string, any>;
8
9
  demos: Record<string, {
9
10
  component: ComponentType;
@@ -1,6 +1,7 @@
1
1
  import { createContext, useContext } from 'react';
2
2
  export var SiteContext = /*#__PURE__*/createContext({
3
3
  pkg: {},
4
+ historyType: 'browser',
4
5
  entryExports: {},
5
6
  demos: {},
6
7
  components: {},
@@ -1,5 +1,5 @@
1
- import type { IUserNavItems } from './types';
1
+ import type { INavItems } from './types';
2
2
  /**
3
3
  * hook for get nav data
4
4
  */
5
- export declare const useNavData: () => IUserNavItems;
5
+ export declare const useNavData: () => INavItems;
@@ -21,10 +21,10 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
21
21
  import { useFullSidebarData, useLocale, useSiteData } from 'dumi';
22
22
  import { useState } from 'react';
23
23
  import { getLocaleNav, pickRouteSortMeta, useLocaleDocRoutes, useRouteDataComparer } from "./utils";
24
-
25
24
  /**
26
25
  * hook for get nav data
27
26
  */
27
+
28
28
  export var useNavData = function useNavData() {
29
29
  var locale = useLocale();
30
30
  var routes = useLocaleDocRoutes();
@@ -32,7 +32,7 @@ var import_fs = __toESM(require("fs"));
32
32
  var import_path = __toESM(require("path"));
33
33
  var import_plugin_utils = require("umi/plugin-utils");
34
34
  function isMFSUAvailable(api) {
35
- return process.platform !== "win32" && api.userConfig.mfsu !== false;
35
+ return process.platform !== "win32" && api.userConfig.mfsu !== false && api.pkg.type !== "module";
36
36
  }
37
37
  function safeExcludeInMFSU(api, excludes) {
38
38
  if (isMFSUAvailable(api)) {
@@ -52,17 +52,29 @@ function safeExcludeInMFSU(api, excludes) {
52
52
  var derivative_default = (api) => {
53
53
  api.describe({ key: "dumi:derivative" });
54
54
  api.onCheck(() => {
55
- var _a, _b, _c, _d;
56
- (0, import_assert.default)(!api.config.mpa, "MPA mode is not supported in dumi!");
57
- (0, import_assert.default)(!api.config.vite, "Vite mode is not supported yet!");
58
- (0, import_assert.default)(!api.config.phantomDependency, "PhantomDependency is not supported yet!");
55
+ var _a, _b, _c;
56
+ [
57
+ "clientLoader",
58
+ "deadCode",
59
+ "icons",
60
+ "mdx",
61
+ "mpa",
62
+ "monorepoRedirect",
63
+ "reactRouter5Compat",
64
+ "verifyCommit"
65
+ ].forEach((key) => {
66
+ (0, import_assert.default)(!api.config[key], `${key} is not supported in dumi!`);
67
+ });
68
+ ["vite", "PhantomDependency"].forEach((key) => {
69
+ (0, import_assert.default)(!api.config[key], `${key} is not supported yet!`);
70
+ });
59
71
  if (typeof api.config.mfsu === "object") {
60
72
  (0, import_assert.default)(api.config.mfsu.strategy !== "eager", "MFSU eager mode is not supported yet!");
61
73
  (0, import_assert.default)(api.config.mfsu.esbuild !== true, "MFSU esbuild bundler is not supported yet!");
62
74
  }
63
75
  (0, import_assert.default)(!api.config.ssr || api.config.ssr.builder === "webpack", "Only `webpack` builder is supported in SSR mode!");
64
- (0, import_assert.default)(((_a = api.config.cssLoader) == null ? void 0 : _a.modules) === void 0, "CSS Modules is not supported! Because it is not suitable for UI library development, please use normal CSS, Less, etc. instead.");
65
- if (((_b = api.userConfig.history) == null ? void 0 : _b.type) === "hash") {
76
+ (0, import_assert.default)(((_a = api.config.cssLoader) == null ? void 0 : _a.modules) === void 0 && api.config.cssLoaderModules === void 0, "CSS Modules is not supported! Because it is not suitable for UI library development, please use normal CSS, Less, etc. instead.");
77
+ if (api.userConfig.history && api.userConfig.history.type === "hash") {
66
78
  import_plugin_utils.logger.warn("Hash history is temporarily incompatible, it is recommended to use browser history for now.");
67
79
  }
68
80
  const { themeConfig } = api.config;
@@ -75,7 +87,7 @@ var derivative_default = (api) => {
75
87
  try {
76
88
  const tsconfig = require(import_path.default.join(api.cwd, "tsconfig.json"));
77
89
  const expected = [".dumi/**/*"];
78
- if ((_d = (_c = api.service.configManager) == null ? void 0 : _c.mainConfigFile) == null ? void 0 : _d.endsWith(".ts")) {
90
+ if ((_c = (_b = api.service.configManager) == null ? void 0 : _b.mainConfigFile) == null ? void 0 : _c.endsWith(".ts")) {
79
91
  expected.push((0, import_plugin_utils.winPath)(import_path.default.relative(api.cwd, api.service.configManager.mainConfigFile)));
80
92
  }
81
93
  if (!expected.every((f) => {
@@ -112,6 +124,7 @@ var derivative_default = (api) => {
112
124
  }
113
125
  memo.hash = true;
114
126
  memo.exportStatic || (memo.exportStatic = {});
127
+ memo.esbuildMinifyIIFE = true;
115
128
  return memo;
116
129
  });
117
130
  api.modifyConfig((memo) => {
@@ -134,30 +147,16 @@ var derivative_default = (api) => {
134
147
  import_constants.USELESS_TMP_FILES.forEach((file) => {
135
148
  import_plugin_utils.fsExtra.rmSync(import_path.default.join(api.paths.absTmpPath, file), { force: true });
136
149
  });
137
- const umiPath = import_path.default.join(api.paths.absTmpPath, "umi.ts");
138
- import_plugin_utils.fsExtra.writeFileSync(umiPath, import_plugin_utils.fsExtra.readFileSync(umiPath, "utf-8").replace("'@/loading'", "'../loading'"));
139
- if (api.config.ssr && import_plugin_utils.semver.subset(api.appData.umi.version, "4.0.54 - 4.0.55")) {
140
- const helmetPath = import_path.default.join(api.paths.absTmpPath, "core/helmet.ts");
141
- import_plugin_utils.fsExtra.writeFileSync(helmetPath, import_plugin_utils.fsExtra.readFileSync(helmetPath, "utf-8").replace(/(return )(React\.createElement)/, "$1typeof window === 'undefined' ? container : $2"));
142
- }
143
150
  }
144
151
  });
145
152
  api.registerPlugins([require.resolve("../../compiled/@umijs/plugins")]);
146
- if (api.isPluginEnable("prepare"))
147
- api.skipPlugins(["prepare"]);
148
- if (api.isPluginEnable("routeProps")) {
149
- api.skipPlugins(["routeProps"]);
150
- api.onGenerateFiles({
151
- stage: -Infinity,
152
- fn() {
153
- api.writeTmpFile({
154
- noPluginDir: true,
155
- path: "core/routeProps.js",
156
- content: "export default {}"
157
- });
158
- }
159
- });
160
- }
153
+ [
154
+ "prepare",
155
+ "routeProps"
156
+ ].forEach((plugin) => {
157
+ if (api.isPluginEnable(plugin))
158
+ api.skipPlugins([plugin]);
159
+ });
161
160
  };
162
161
  // Annotate the CommonJS export names for ESM import in node:
163
162
  0 && (module.exports = {
@@ -138,6 +138,7 @@ var theme_default = (api) => {
138
138
  return memo;
139
139
  });
140
140
  api.onGenerateFiles(() => {
141
+ var _a;
141
142
  themeMapKeys.forEach((key) => {
142
143
  Object.values(originalThemeData[key] || {}).forEach((item) => {
143
144
  if (item.source === "dumi")
@@ -199,6 +200,7 @@ export default function DumiContextWrapper() {
199
200
  return (
200
201
  <SiteContext.Provider value={{
201
202
  pkg: ${JSON.stringify(import_plugin_utils.lodash.pick(api.pkg, ...Object.keys(import_constants.PICKED_PKG_FIELDS)))},
203
+ historyType: "${((_a = api.config.history) == null ? void 0 : _a.type) || "browser"}",
202
204
  entryExports,
203
205
  demos,
204
206
  components,
@@ -28,6 +28,7 @@ var import_constants = require("./constants");
28
28
  var import_dev = require("./dev");
29
29
  var import_printHelp = require("./printHelp");
30
30
  var import_service = require("./service");
31
+ (0, import_node.catchUnhandledRejection)();
31
32
  async function run(opts) {
32
33
  (0, import_node.checkVersion)();
33
34
  (0, import_node.setNodeTitle)(import_constants.FRAMEWORK_NAME);
@@ -26,102 +26,6 @@ __export(react_exports, {
26
26
  });
27
27
  module.exports = __toCommonJS(react_exports);
28
28
  var import_core = require("@swc/core");
29
- var import_Visitor = __toESM(require("@swc/core/Visitor"));
30
- function createReturnStmt(exp, span) {
31
- return {
32
- type: "ReturnStatement",
33
- span,
34
- argument: {
35
- type: "ObjectExpression",
36
- span,
37
- properties: [
38
- {
39
- type: "KeyValueProperty",
40
- key: {
41
- type: "Identifier",
42
- span,
43
- value: "default",
44
- optional: false
45
- },
46
- value: exp
47
- }
48
- ]
49
- }
50
- };
51
- }
52
- var ReactDemoVisitor = class extends import_Visitor.default {
53
- visitImportDeclaration(n) {
54
- if (!n.typeOnly) {
55
- const namespaceImport = n.specifiers.find((s) => s.type === "ImportNamespaceSpecifier");
56
- const id = namespaceImport ? namespaceImport.local : {
57
- type: "ObjectPattern",
58
- span: n.span,
59
- properties: n.specifiers.map((s) => {
60
- var _a;
61
- if (s.type === "ImportDefaultSpecifier" || s.type === "ImportSpecifier" && ((_a = s.imported) == null ? void 0 : _a.type) === "Identifier") {
62
- return {
63
- type: "KeyValuePatternProperty",
64
- span: s.span,
65
- key: s.type === "ImportSpecifier" ? s.imported : {
66
- type: "Identifier",
67
- span: s.span,
68
- value: "default",
69
- optional: false
70
- },
71
- value: s.local
72
- };
73
- }
74
- return {
75
- type: "AssignmentPatternProperty",
76
- span: s.span,
77
- key: s.local
78
- };
79
- }),
80
- optional: false
81
- };
82
- return {
83
- type: "VariableDeclaration",
84
- kind: "const",
85
- declare: false,
86
- span: n.span,
87
- declarations: [
88
- {
89
- type: "VariableDeclarator",
90
- span: n.span,
91
- definite: false,
92
- id,
93
- init: {
94
- span: n.span,
95
- type: "AwaitExpression",
96
- argument: {
97
- type: "CallExpression",
98
- span: n.span,
99
- callee: {
100
- type: "Import",
101
- span: n.span
102
- },
103
- arguments: [{ expression: n.source }]
104
- }
105
- }
106
- }
107
- ]
108
- };
109
- }
110
- return n;
111
- }
112
- visitExportDefaultDeclaration(n) {
113
- if (n.decl.type !== "TsInterfaceDeclaration") {
114
- return createReturnStmt(n.decl, n.span);
115
- }
116
- return n;
117
- }
118
- visitExportDefaultExpression(n) {
119
- return createReturnStmt(n.expression, n.span);
120
- }
121
- visitTsType(n) {
122
- return n;
123
- }
124
- };
125
29
  var ReactTechStack = class {
126
30
  constructor() {
127
31
  this.name = "react";
@@ -139,12 +43,20 @@ var ReactTechStack = class {
139
43
  syntax: isTSX ? "typescript" : "ecmascript",
140
44
  [isTSX ? "tsx" : "jsx"]: true
141
45
  },
142
- target: "es2022"
46
+ target: "es2022",
47
+ experimental: {
48
+ cacheRoot: "node_modules/.cache/swc",
49
+ plugins: [
50
+ [
51
+ require.resolve("../../compiled/crates/swc_plugin_react_demo.wasm"),
52
+ {}
53
+ ]
54
+ ]
55
+ }
143
56
  },
144
57
  module: {
145
58
  type: "es6"
146
- },
147
- plugin: (m) => new ReactDemoVisitor().visitProgram(m)
59
+ }
148
60
  });
149
61
  return `React.lazy(async () => {
150
62
  ${code}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dumi",
3
- "version": "2.1.17",
3
+ "version": "2.1.18",
4
4
  "description": "📖 Documentation Generator of React Component",
5
5
  "keywords": [
6
6
  "generator",
@@ -35,10 +35,10 @@
35
35
  "plugin-utils.d.ts"
36
36
  ],
37
37
  "scripts": {
38
- "build": "father build",
38
+ "build": "father build && npm run build:crates",
39
+ "build:crates": "cargo build --target wasm32-wasi -r --out-dir compiled/crates -Z unstable-options",
39
40
  "build:deps": "node scripts/pre-bundle-worker.js && father prebundle",
40
41
  "build:suites": "pnpm run --filter=\"./suites/**\" build",
41
- "custom-install": "pnpm i",
42
42
  "dev": "father dev",
43
43
  "docs:build": "node ./bin/dumi.js build",
44
44
  "docs:dev": "node ./bin/dumi.js dev",
@@ -49,7 +49,9 @@
49
49
  "lint:es": "eslint \"{src,test}/**/*.{js,jsx,ts,tsx}\"",
50
50
  "prepare": "husky install && npm run build && npm run build:suites && node ./bin/dumi.js setup && npm run docs:sync",
51
51
  "prepublishOnly": "npm run build",
52
- "test": "vitest"
52
+ "test": "vitest",
53
+ "vercel:build": "npm run docs:build",
54
+ "vercel:install": "./scripts/vercel-install.sh"
53
55
  },
54
56
  "commitlint": {
55
57
  "extends": [
@@ -77,11 +79,11 @@
77
79
  "@ant-design/icons-svg": "^4.2.1",
78
80
  "@makotot/ghostui": "^2.0.0",
79
81
  "@stackblitz/sdk": "^1.8.1",
80
- "@swc/core": "^1.2.224",
82
+ "@swc/core": "^1.3.42",
81
83
  "@types/hast": "^2.3.4",
82
84
  "@types/mdast": "^3.0.10",
83
- "@umijs/bundler-utils": "^4.0.59",
84
- "@umijs/core": "^4.0.59",
85
+ "@umijs/bundler-utils": "^4.0.64",
86
+ "@umijs/core": "^4.0.64",
85
87
  "animated-scroll-to": "^2.3.0",
86
88
  "classnames": "2.3.2",
87
89
  "codesandbox": "^2.2.3",
@@ -122,7 +124,7 @@
122
124
  "remark-rehype": "^10.1.0",
123
125
  "sass": "^1.55.0",
124
126
  "sitemap": "^7.1.1",
125
- "umi": "^4.0.59",
127
+ "umi": "^4.0.64",
126
128
  "unified": "^10.1.2",
127
129
  "unist-util-visit": "^4.1.0",
128
130
  "unist-util-visit-parents": "^5.1.1",
@@ -141,7 +143,7 @@
141
143
  "@types/pluralize": "^0.0.29",
142
144
  "@types/react": "^18.0.16",
143
145
  "@types/react-copy-to-clipboard": "^5.0.4",
144
- "@umijs/lint": "^4.0.59",
146
+ "@umijs/lint": "^4.0.64",
145
147
  "@umijs/plugins": "4.0.32",
146
148
  "dumi-theme-mobile": "workspace:*",
147
149
  "eslint": "^8.20.0",
@@ -80,9 +80,12 @@ var HANDLERS = {
80
80
  var _this2 = this;
81
81
 
82
82
  var signature = _ref3.signature;
83
- return "".concat(signature.isAsync ? 'async ' : '', "(").concat(signature.arguments.map(function (arg) {
84
- return "".concat(arg.key, ": ").concat(_this2.toString(arg));
85
- }).join(', '), ") => ").concat(this.toString(signature.returnType));
83
+ var signatures = 'oneOf' in signature ? signature.oneOf : [signature];
84
+ return signatures.map(function (signature) {
85
+ return "".concat(signature.isAsync ? 'async ' : '', "(").concat(signature.arguments.map(function (arg) {
86
+ return "".concat(arg.key, ": ").concat(_this2.toString(arg));
87
+ }).join(', '), ") => ").concat(_this2.toString(signature.returnType));
88
+ }).join(' | ');
86
89
  },
87
90
  // FIXME: extract real type
88
91
  dom: function dom(prop) {
@@ -30,7 +30,8 @@ var SIMILAR_DSL = {
30
30
  };
31
31
 
32
32
  var SourceCode = function SourceCode(props) {
33
- var children = props.children,
33
+ var _props$children = props.children,
34
+ children = _props$children === void 0 ? '' : _props$children,
34
35
  lang = props.lang,
35
36
  _props$highlightLines = props.highlightLines,
36
37
  highlightLines = _props$highlightLines === void 0 ? [] : _props$highlightLines;
@@ -20,8 +20,8 @@ import Logo from 'dumi/theme/slots/Logo';
20
20
  import Navbar from 'dumi/theme/slots/Navbar';
21
21
  import RtlSwitch from 'dumi/theme/slots/RtlSwitch';
22
22
  import SearchBar from 'dumi/theme/slots/SearchBar';
23
+ import SocialIcon from 'dumi/theme/slots/SocialIcon';
23
24
  import React, { useMemo, useState } from 'react';
24
- import SocialIcon from "../SocialIcon";
25
25
  import "./index.less";
26
26
 
27
27
  var Header = function Header() {