dumi 2.0.0-beta.14 → 2.0.0-beta.15

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.
@@ -1,5 +1,6 @@
1
1
  import { parseCodeFrontmatter } from "../utils";
2
2
  import type { ExampleBlockAsset } from 'dumi-assets-types';
3
+ import type { sync } from 'enhanced-resolve';
3
4
  export interface IParsedBlockAsset {
4
5
  asset: ExampleBlockAsset;
5
6
  sources: Record<string, string>;
@@ -10,5 +11,6 @@ declare function parseBlockAsset(opts: {
10
11
  id: string;
11
12
  refAtomIds: string[];
12
13
  entryPointCode?: string;
14
+ resolver: typeof sync;
13
15
  }): Promise<IParsedBlockAsset>;
14
16
  export default parseBlockAsset;
@@ -27,6 +27,7 @@ __export(block_exports, {
27
27
  module.exports = __toCommonJS(block_exports);
28
28
  var import_utils = require("../utils");
29
29
  var import_esbuild = require("@umijs/bundler-utils/compiled/esbuild");
30
+ var import_assert = __toESM(require("assert"));
30
31
  var import_fs = __toESM(require("fs"));
31
32
  var import_path = __toESM(require("path"));
32
33
  var import_plugin_utils = require("umi/plugin-utils");
@@ -56,8 +57,10 @@ async function parseBlockAsset(opts) {
56
57
  setup: (builder) => {
57
58
  builder.onResolve({ filter: /.*/ }, (args) => {
58
59
  if (args.kind !== "entry-point" && !args.path.startsWith(".")) {
60
+ const resolved = opts.resolver(args.resolveDir, args.path);
61
+ (0, import_assert.default)(resolved, `Can't resolve ${args.path} from ${args.resolveDir}`);
59
62
  const pkgJsonPath = import_plugin_utils.pkgUp.pkgUpSync({
60
- cwd: require.resolve(args.path, { paths: [args.resolveDir] })
63
+ cwd: resolved
61
64
  });
62
65
  if (pkgJsonPath) {
63
66
  asset.dependencies[args.path] = {
@@ -61,8 +61,8 @@ export interface IRouteMeta {
61
61
  title?: string;
62
62
  description?: string;
63
63
  background?: string;
64
- links?: {
65
- title: string;
64
+ actions?: {
65
+ text: string;
66
66
  link: string;
67
67
  }[];
68
68
  [key: string]: any;
@@ -116,11 +116,11 @@ declare type IBasicLocale = {
116
116
  id: string;
117
117
  name: string;
118
118
  };
119
- export declare type ILocale = ((IBasicLocale & {
119
+ export declare type ILocale = (IBasicLocale & {
120
120
  base: string;
121
121
  }) | (IBasicLocale & {
122
122
  suffix: string;
123
- }));
123
+ });
124
124
  export declare type ILocalesConfig = ILocale[];
125
125
  export interface INavItem {
126
126
  title: string;
@@ -33,10 +33,6 @@ var compile_default = (api) => {
33
33
  stage: Infinity,
34
34
  fn: () => new import_react.default()
35
35
  });
36
- api.modifyDefaultConfig((memo) => {
37
- memo.alias.dumi$ = memo.alias.umi;
38
- return memo;
39
- });
40
36
  api.chainWebpack(async (memo) => {
41
37
  const babelInUmi = memo.module.rule("src").use("babel-loader").entries();
42
38
  const techStacks = await api.applyPlugins({
@@ -1,4 +1,9 @@
1
1
  import type { IApi } from "../types";
2
+ /**
3
+ * exclude pre-compiling modules in mfsu mode
4
+ * and make sure there has no multiple instances problem (such as react)
5
+ */
6
+ export declare function safeExcludeInMFSU(api: IApi, excludes: RegExp[]): void;
2
7
  /**
3
8
  * plugin for derive default behaviors from umi
4
9
  */
@@ -22,12 +22,24 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
22
22
  // src/features/derivative.ts
23
23
  var derivative_exports = {};
24
24
  __export(derivative_exports, {
25
- default: () => derivative_default
25
+ default: () => derivative_default,
26
+ safeExcludeInMFSU: () => safeExcludeInMFSU
26
27
  });
27
28
  module.exports = __toCommonJS(derivative_exports);
28
29
  var import_constants = require("../constants");
29
30
  var import_path = __toESM(require("path"));
30
31
  var import_plugin_utils = require("umi/plugin-utils");
32
+ function safeExcludeInMFSU(api, excludes) {
33
+ if (api.userConfig.mfsu !== false) {
34
+ api.modifyDefaultConfig((memo) => {
35
+ memo.mfsu ?? (memo.mfsu = {});
36
+ memo.mfsu.exclude = (0, import_plugin_utils.deepmerge)(memo.mfsu.exclude || [], excludes);
37
+ memo.extraBabelIncludes ?? (memo.extraBabelIncludes = []);
38
+ memo.extraBabelIncludes.push(...excludes);
39
+ return memo;
40
+ });
41
+ }
42
+ }
31
43
  function getFilesByGlob(globExp, dir) {
32
44
  return import_plugin_utils.glob.sync(globExp, { cwd: dir }).map((file) => (0, import_plugin_utils.winPath)(import_path.default.join(dir, file)));
33
45
  }
@@ -40,6 +52,13 @@ var derivative_default = (api) => {
40
52
  overridesCSS: getFilesByGlob.bind(null, "overrides.{css,less,scss,sass}", dumiAbsDir)
41
53
  };
42
54
  api.describe({ key: "dumi:derivative" });
55
+ safeExcludeInMFSU(api, [new RegExp("dumi/dist/client")]);
56
+ api.modifyDefaultConfig((memo) => {
57
+ if (api.userConfig.mfsu !== false) {
58
+ memo.mfsu.strategy = "normal";
59
+ }
60
+ return memo;
61
+ });
43
62
  api.modifyAppData((memo) => {
44
63
  Object.entries(strategies).forEach(([key, fn]) => {
45
64
  memo[key] = fn();
@@ -56,4 +75,6 @@ var derivative_default = (api) => {
56
75
  });
57
76
  };
58
77
  // Annotate the CommonJS export names for ESM import in node:
59
- 0 && (module.exports = {});
78
+ 0 && (module.exports = {
79
+ safeExcludeInMFSU
80
+ });
@@ -1,8 +1,3 @@
1
1
  import type { IApi } from "../types";
2
- /**
3
- * exclude pre-compiling modules in mfsu mode
4
- * and make sure there has no multiple instances problem (such as react)
5
- */
6
- export declare function safeExcludeInMFSU(api: IApi, excludes: RegExp[]): void;
7
2
  declare const _default: (api: IApi) => void;
8
3
  export default _default;
@@ -22,31 +22,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
22
22
  // src/features/exports.ts
23
23
  var exports_exports = {};
24
24
  __export(exports_exports, {
25
- default: () => exports_default,
26
- safeExcludeInMFSU: () => safeExcludeInMFSU
25
+ default: () => exports_default
27
26
  });
28
27
  module.exports = __toCommonJS(exports_exports);
29
28
  var import_plugin_utils = require("umi/plugin-utils");
30
- function safeExcludeInMFSU(api, excludes) {
31
- if (api.userConfig.mfsu !== false) {
32
- api.modifyDefaultConfig((memo) => {
33
- memo.mfsu ?? (memo.mfsu = {});
34
- memo.mfsu.exclude = (0, import_plugin_utils.deepmerge)(memo.mfsu.exclude || [], excludes);
35
- memo.extraBabelIncludes ?? (memo.extraBabelIncludes = []);
36
- memo.extraBabelIncludes.push(...excludes);
37
- return memo;
38
- });
39
- }
40
- }
41
29
  var exports_default = (api) => {
42
- api.describe({ key: void 0 });
43
- safeExcludeInMFSU(api, [new RegExp("dumi/dist/client")]);
44
- api.modifyDefaultConfig((memo) => {
45
- if (api.userConfig.mfsu !== false) {
46
- memo.mfsu = { strategy: "normal" };
47
- }
48
- return memo;
49
- });
30
+ api.describe({ key: "dumi:exports" });
50
31
  api.modifyConfig((memo) => {
51
32
  memo.alias["dumi$"] = "@@/dumi/exports";
52
33
  return memo;
@@ -61,6 +42,4 @@ export * from '${(0, import_plugin_utils.winPath)(require.resolve("../client/the
61
42
  });
62
43
  };
63
44
  // Annotate the CommonJS export names for ESM import in node:
64
- 0 && (module.exports = {
65
- safeExcludeInMFSU
66
- });
45
+ 0 && (module.exports = {});
@@ -29,7 +29,7 @@ var import_constants = require("../../constants");
29
29
  var import_fs = __toESM(require("fs"));
30
30
  var import_path = __toESM(require("path"));
31
31
  var import_plugin_utils = require("umi/plugin-utils");
32
- var import_exports = require("../exports");
32
+ var import_derivative = require("../derivative");
33
33
  var import_loader = __toESM(require("./loader"));
34
34
  var DEFAULT_THEME_PATH = import_path.default.join(__dirname, "../../../theme-default");
35
35
  function getPkgThemeName(api) {
@@ -59,7 +59,7 @@ var theme_default = (api) => {
59
59
  api.registerPlugins([plugin]);
60
60
  }
61
61
  });
62
- (0, import_exports.safeExcludeInMFSU)(api, ["dumi/theme-default", "@ant-design/icons-svg", getPkgThemeName(api)].filter(Boolean).map((pkg) => new RegExp(pkg)));
62
+ (0, import_derivative.safeExcludeInMFSU)(api, ["dumi/theme-default", "@ant-design/icons-svg", getPkgThemeName(api)].filter(Boolean).map((pkg) => new RegExp(pkg)));
63
63
  api.register({
64
64
  key: "modifyAppData",
65
65
  before: "appData",
@@ -104,16 +104,14 @@ function mdLoader(content) {
104
104
  });
105
105
  return;
106
106
  }
107
- deferrer[cacheKey] = new Promise((resolve) => {
108
- (0, import_transformer.default)(content, {
109
- ...import_plugin_utils.lodash.omit(opts, ["mode", "builtins", "onResolveDemos"]),
110
- fileAbsPath: this.resourcePath
111
- }).then((ret) => {
112
- cache.setSync(cacheKey, ret);
113
- resolve(ret);
114
- cb(null, emit.call(this, opts, ret));
115
- }, cb);
107
+ deferrer[cacheKey] = (0, import_transformer.default)(content, {
108
+ ...import_plugin_utils.lodash.omit(opts, ["mode", "builtins", "onResolveDemos"]),
109
+ fileAbsPath: this.resourcePath
116
110
  });
111
+ deferrer[cacheKey].then((ret) => {
112
+ cache.setSync(cacheKey, ret);
113
+ cb(null, emit.call(this, opts, ret));
114
+ }).catch(cb);
117
115
  }
118
116
  // Annotate the CommonJS export names for ESM import in node:
119
117
  0 && (module.exports = {});
@@ -133,7 +133,8 @@ function rehypeDemo(opts) {
133
133
  id: "",
134
134
  refAtomIds: [],
135
135
  fileAbsPath: "",
136
- entryPointCode: codeType === "external" ? void 0 : codeValue
136
+ entryPointCode: codeType === "external" ? void 0 : codeValue,
137
+ resolver: opts.resolver
137
138
  };
138
139
  const previewerProps = {};
139
140
  let component = "";
@@ -39,7 +39,7 @@ function rehypeImg() {
39
39
  var _a;
40
40
  if (node.tagName === "img" && typeof ((_a = node.properties) == null ? void 0 : _a.src) === "string") {
41
41
  const src = node.properties.src.trim();
42
- if (isRelativeUrl(src)) {
42
+ if (src && isRelativeUrl(src)) {
43
43
  delete node.properties.src;
44
44
  node.JSXAttributes = [
45
45
  {
@@ -54,6 +54,7 @@ var ReactTechStack = class {
54
54
  if (opts.type === "code-block") {
55
55
  const isTSX = opts.fileAbsPath.endsWith(".tsx");
56
56
  const { code } = (0, import_core.transformSync)(raw, {
57
+ filename: opts.fileAbsPath,
57
58
  jsc: {
58
59
  parser: {
59
60
  syntax: isTSX ? "typescript" : "ecmascript",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dumi",
3
- "version": "2.0.0-beta.14",
3
+ "version": "2.0.0-beta.15",
4
4
  "description": "Framework for developing UI components",
5
5
  "keywords": [],
6
6
  "license": "MIT",
@@ -4,7 +4,7 @@ import React from 'react';
4
4
  import "./index.less";
5
5
 
6
6
  var Hero = function Hero() {
7
- var _links;
7
+ var _actions;
8
8
 
9
9
  var _useRouteMeta = useRouteMeta(),
10
10
  frontmatter = _useRouteMeta.frontmatter;
@@ -16,19 +16,19 @@ var Hero = function Hero() {
16
16
  dangerouslySetInnerHTML: {
17
17
  __html: frontmatter.hero.description
18
18
  }
19
- }), Boolean((_links = frontmatter.hero.links) === null || _links === void 0 ? void 0 : _links.length) && /*#__PURE__*/React.createElement("div", {
20
- className: "dumi-default-hero-links"
21
- }, frontmatter.hero.links.map(function (_ref) {
22
- var title = _ref.title,
19
+ }), Boolean((_actions = frontmatter.hero.actions) === null || _actions === void 0 ? void 0 : _actions.length) && /*#__PURE__*/React.createElement("div", {
20
+ className: "dumi-default-hero-actions"
21
+ }, frontmatter.hero.actions.map(function (_ref) {
22
+ var text = _ref.text,
23
23
  link = _ref.link;
24
24
  return /^(\w+:)\/\/|^(mailto|tel):/.test(link) ? /*#__PURE__*/React.createElement("a", {
25
25
  href: link,
26
26
  target: "_blank",
27
27
  rel: "noreferrer"
28
- }, title) : /*#__PURE__*/React.createElement(Link, {
29
- key: title,
28
+ }, text) : /*#__PURE__*/React.createElement(Link, {
29
+ key: text,
30
30
  to: link
31
- }, title);
31
+ }, text);
32
32
  })));
33
33
  };
34
34
 
@@ -30,7 +30,7 @@
30
30
  line-height: 1.6;
31
31
  }
32
32
 
33
- &-links {
33
+ &-actions {
34
34
  margin-top: 48px;
35
35
  display: flex;
36
36
  justify-content: center;