dumi 2.4.51 → 2.4.53

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.
Files changed (34) hide show
  1. package/compiled/file-system-cache/LICENSE +134 -0
  2. package/compiled/file-system-cache/index.d.ts +3 -0
  3. package/compiled/file-system-cache/index.js +1 -0
  4. package/compiled/file-system-cache/package.json +1 -0
  5. package/dist/assetParsers/block.d.ts +3 -0
  6. package/dist/assetParsers/block.js +82 -15
  7. package/dist/features/compile/index.js +6 -1
  8. package/dist/features/compile/utoopackLoaders.d.ts +3 -2
  9. package/dist/features/compile/utoopackLoaders.js +8 -6
  10. package/dist/features/meta.js +4 -4
  11. package/dist/features/tabs/utils.d.ts +3 -0
  12. package/dist/features/tabs/utils.js +41 -0
  13. package/dist/features/tabs.d.ts +1 -3
  14. package/dist/features/tabs.js +12 -19
  15. package/dist/loaders/constants.d.ts +2 -0
  16. package/dist/loaders/constants.js +32 -0
  17. package/dist/loaders/demo/index.js +3 -3
  18. package/dist/loaders/markdown/index.js +161 -68
  19. package/dist/loaders/markdown/transformer/index.d.ts +2 -0
  20. package/dist/loaders/markdown/transformer/index.js +1 -0
  21. package/dist/loaders/markdown/transformer/rehypeDemo.d.ts +1 -0
  22. package/dist/loaders/markdown/transformer/rehypeDemo.js +17 -9
  23. package/dist/loaders/markdown/transformer/rehypeJsxify.js +1 -1
  24. package/dist/loaders/markdown/transformer/rehypeLink.js +32 -18
  25. package/dist/loaders/markdown/transformer/rehypeRaw.js +2 -2
  26. package/dist/loaders/markdown/transformer/rehypeText.d.ts +2 -1
  27. package/dist/loaders/markdown/transformer/rehypeText.js +3 -3
  28. package/dist/loaders/markdown/transformer/remarkBreaks.js +4 -4
  29. package/dist/loaders/markdown/transformer/remarkEmbed.js +2 -2
  30. package/dist/loaders/markdown/transformer/remarkMeta.js +9 -9
  31. package/dist/techStacks/utils.js +2 -2
  32. package/dist/utils.d.ts +2 -1
  33. package/dist/utils.js +16 -16
  34. package/package.json +1 -1
@@ -32,17 +32,31 @@ __export(rehypeLink_exports, {
32
32
  default: () => rehypeLink
33
33
  });
34
34
  module.exports = __toCommonJS(rehypeLink_exports);
35
- var import_tabs = require("../../../features/tabs");
35
+ var import_utils = require("../../../features/tabs/utils");
36
+ var import_utils2 = require("@umijs/utils");
36
37
  var import_path = __toESM(require("path"));
37
- var import_plugin_utils = require("umi/plugin-utils");
38
38
  var import_url = __toESM(require("url"));
39
39
  var visit;
40
40
  var SKIP;
41
41
  (async () => {
42
42
  ({ visit, SKIP } = await import("unist-util-visit"));
43
43
  })();
44
+ function createRouteInfo(routes, hostAbsPath) {
45
+ const pathsByFile = /* @__PURE__ */ new Map();
46
+ const absPaths = /* @__PURE__ */ new Set();
47
+ let currentRoute;
48
+ Object.values(routes).forEach((route) => {
49
+ pathsByFile.set(route.file, route.absPath);
50
+ absPaths.add(route.absPath);
51
+ if (!currentRoute && route.file === hostAbsPath)
52
+ currentRoute = route;
53
+ });
54
+ return { pathsByFile, absPaths, currentRoute };
55
+ }
44
56
  function rehypeLink(opts) {
45
57
  return (tree) => {
58
+ const hostAbsPath = (0, import_utils.getHostForTabRouteFile)(opts.fileAbsPath);
59
+ let routeInfo;
46
60
  visit(tree, "element", (node, i, parent) => {
47
61
  var _a, _b, _c;
48
62
  if (node.tagName === "a" && typeof ((_a = node.properties) == null ? void 0 : _a.href) === "string" && // skip target specified link
@@ -50,35 +64,35 @@ function rehypeLink(opts) {
50
64
  !((_c = node.properties) == null ? void 0 : _c.download)) {
51
65
  const href = node.properties.href;
52
66
  const parsedUrl = import_url.default.parse(href);
53
- const hostAbsPath = (0, import_tabs.getHostForTabRouteFile)(opts.fileAbsPath);
54
67
  if (parsedUrl.protocol || href.startsWith("//"))
55
68
  return SKIP;
56
69
  if (/\.md$/i.test(parsedUrl.pathname)) {
57
- const { routes } = opts;
58
- const absPath = (0, import_plugin_utils.winPath)(
70
+ const { pathsByFile } = routeInfo ?? (routeInfo = createRouteInfo(
71
+ opts.routes,
72
+ hostAbsPath
73
+ ));
74
+ const absPath = (0, import_utils2.winPath)(
59
75
  import_path.default.resolve(hostAbsPath, "..", parsedUrl.pathname)
60
76
  );
61
- Object.keys(routes).forEach((key) => {
62
- if (routes[key].file === absPath) {
63
- parsedUrl.pathname = routes[key].absPath;
64
- }
65
- });
77
+ if (pathsByFile.has(absPath)) {
78
+ parsedUrl.pathname = pathsByFile.get(absPath);
79
+ }
66
80
  } else if (parsedUrl.pathname && /^[^/]+/.test(parsedUrl.pathname)) {
67
- const routes = Object.values(opts.routes);
68
- const currentRoute = routes.find(
69
- (route) => route.file === hostAbsPath
70
- );
81
+ const { currentRoute, absPaths } = routeInfo ?? (routeInfo = createRouteInfo(
82
+ opts.routes,
83
+ hostAbsPath
84
+ ));
71
85
  if (!currentRoute)
72
86
  return;
73
87
  const basePath = currentRoute.absPath;
74
88
  const htmlTargetPath = import_url.default.resolve(basePath, parsedUrl.pathname);
75
- const rr6TargetPath = (0, import_plugin_utils.winPath)(
89
+ const rr6TargetPath = (0, import_utils2.winPath)(
76
90
  import_path.default.resolve(basePath, parsedUrl.pathname)
77
91
  );
78
92
  parsedUrl.pathname = htmlTargetPath;
79
- if (routes.every((route) => route.absPath !== htmlTargetPath) && routes.some((route) => route.absPath === rr6TargetPath)) {
93
+ if (!absPaths.has(htmlTargetPath) && absPaths.has(rr6TargetPath)) {
80
94
  parsedUrl.pathname = rr6TargetPath;
81
- import_plugin_utils.logger.warn(
95
+ import_utils2.logger.warn(
82
96
  `Detected ambiguous link \`${href}\` in \`${opts.fileAbsPath}\`, please use \`./xxx.md\` file path instead of normal relative path, dumi will deprecate this behavior in the future.
83
97
  See more: https://github.com/umijs/dumi/pull/1491`
84
98
  );
@@ -89,7 +103,7 @@ function rehypeLink(opts) {
89
103
  tagName: "Link",
90
104
  children: node.children,
91
105
  properties: {
92
- ...import_plugin_utils.lodash.omit(node.properties, ["href"]),
106
+ ...import_utils2.lodash.omit(node.properties, ["href"]),
93
107
  to: import_url.default.format(parsedUrl)
94
108
  }
95
109
  });
@@ -32,7 +32,7 @@ __export(rehypeRaw_exports, {
32
32
  default: () => rehypeRaw
33
33
  });
34
34
  module.exports = __toCommonJS(rehypeRaw_exports);
35
- var import_plugin_utils = require("umi/plugin-utils");
35
+ var import_utils = require("@umijs/utils");
36
36
  var raw;
37
37
  var visit;
38
38
  var COMPONENT_NAME_REGEX = /(<)([A-Z][a-zA-Z\d]*)([\s|>])/g;
@@ -71,7 +71,7 @@ function rehypeRaw(opts) {
71
71
  node.properties[CODE_META_STUB_ATTR] = node.data.meta;
72
72
  }
73
73
  if (node.type === "raw" && /<code[^>]*src=[^>]*\/>/.test(node.value)) {
74
- import_plugin_utils.logger.warn(`<code /> is not supported, please use <code></code> instead.
74
+ import_utils.logger.warn(`<code /> is not supported, please use <code></code> instead.
75
75
  File: ${opts.fileAbsPath}`);
76
76
  }
77
77
  });
@@ -1,4 +1,5 @@
1
+ import { CONTENT_TEXTS_OBJ_NAME } from '../../constants';
1
2
  import type { Root } from 'hast';
2
3
  import type { Transformer } from 'unified';
3
- export declare const CONTENT_TEXTS_OBJ_NAME = "$$contentTexts";
4
+ export { CONTENT_TEXTS_OBJ_NAME };
4
5
  export default function rehypeText(): Transformer<Root>;
@@ -29,13 +29,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
29
29
  // src/loaders/markdown/transformer/rehypeText.ts
30
30
  var rehypeText_exports = {};
31
31
  __export(rehypeText_exports, {
32
- CONTENT_TEXTS_OBJ_NAME: () => CONTENT_TEXTS_OBJ_NAME,
32
+ CONTENT_TEXTS_OBJ_NAME: () => import_constants.CONTENT_TEXTS_OBJ_NAME,
33
33
  default: () => rehypeText
34
34
  });
35
35
  module.exports = __toCommonJS(rehypeText_exports);
36
+ var import_constants = require("../../constants");
36
37
  var import_rehypeIsolation = require("./rehypeIsolation");
37
38
  var import_rehypeSlug = require("./rehypeSlug");
38
- var CONTENT_TEXTS_OBJ_NAME = "$$contentTexts";
39
39
  var visit;
40
40
  (async () => {
41
41
  ({ visitParents: visit } = await import("unist-util-visit-parents"));
@@ -92,7 +92,7 @@ function rehypeText() {
92
92
  computed: true,
93
93
  object: {
94
94
  type: "Identifier",
95
- name: CONTENT_TEXTS_OBJ_NAME
95
+ name: import_constants.CONTENT_TEXTS_OBJ_NAME
96
96
  },
97
97
  property: {
98
98
  type: "Literal",
@@ -32,7 +32,7 @@ __export(remarkBreaks_exports, {
32
32
  default: () => remarkBreaks
33
33
  });
34
34
  module.exports = __toCommonJS(remarkBreaks_exports);
35
- var import_plugin_utils = require("umi/plugin-utils");
35
+ var import_utils = require("@umijs/utils");
36
36
  var findAndReplace;
37
37
  (async () => {
38
38
  ({ findAndReplace } = await import("mdast-util-find-and-replace"));
@@ -42,13 +42,13 @@ function logDeprecationWarning(fileAbsPath) {
42
42
  if (warningLock.get(fileAbsPath))
43
43
  return;
44
44
  warningLock.set(fileAbsPath, true);
45
- import_plugin_utils.logger.warn(
45
+ import_utils.logger.warn(
46
46
  "Detected that you are using soft breaks, dumi will transform them into spaces after the declaration",
47
47
  "version greater than or equal to `2.2.0`, however, they are still being transformed as line breaks now, please",
48
48
  "migrate them to hard breaks before upgrading the declaration version for dumi.\n",
49
- import_plugin_utils.chalk.grey(` at ${fileAbsPath}
49
+ import_utils.chalk.grey(` at ${fileAbsPath}
50
50
  `),
51
- import_plugin_utils.chalk.grey(" see also: https://github.com/umijs/dumi/issues/1683\n")
51
+ import_utils.chalk.grey(" see also: https://github.com/umijs/dumi/issues/1683\n")
52
52
  );
53
53
  }
54
54
  function remarkBreaks(opts) {
@@ -33,10 +33,10 @@ __export(remarkEmbed_exports, {
33
33
  });
34
34
  module.exports = __toCommonJS(remarkEmbed_exports);
35
35
  var import_utils = require("../../../utils");
36
+ var import_utils2 = require("@umijs/utils");
36
37
  var import_enhanced_resolve = __toESM(require("enhanced-resolve"));
37
38
  var import_fs = __toESM(require("fs"));
38
39
  var import_path = __toESM(require("path"));
39
- var import_plugin_utils = require("umi/plugin-utils");
40
40
  var import_url = __toESM(require("url"));
41
41
  var import_remarkContainer = __toESM(require("./remarkContainer"));
42
42
  var EMBED_OPEN_TAG = "<embed ";
@@ -59,7 +59,7 @@ function remarkReplaceSrc(opts) {
59
59
  function getEmbedRltPath(value) {
60
60
  const { fileAbsPath, parentAbsPath } = opts;
61
61
  const absPath = import_path.default.resolve(fileAbsPath, "..", value);
62
- return (0, import_plugin_utils.winPath)(import_path.default.relative(import_path.default.dirname(parentAbsPath), absPath)).replace(/^([^.])/, "./$1");
62
+ return (0, import_utils2.winPath)(import_path.default.relative(import_path.default.dirname(parentAbsPath), absPath)).replace(/^([^.])/, "./$1");
63
63
  }
64
64
  return (ast) => {
65
65
  visit(
@@ -32,12 +32,12 @@ __export(remarkMeta_exports, {
32
32
  default: () => remarkMeta
33
33
  });
34
34
  module.exports = __toCommonJS(remarkMeta_exports);
35
- var import_tabs = require("../../../features/tabs");
35
+ var import_utils = require("../../../features/tabs/utils");
36
+ var import_utils2 = require("@umijs/utils");
36
37
  var import_child_process = require("child_process");
37
38
  var import_fs = __toESM(require("fs"));
38
39
  var import_js_yaml = __toESM(require("js-yaml"));
39
40
  var import_path = __toESM(require("path"));
40
- var import_plugin_utils = require("umi/plugin-utils");
41
41
  var visit;
42
42
  var toString;
43
43
  (async () => {
@@ -46,12 +46,12 @@ var toString;
46
46
  })();
47
47
  function getGuessAtomId(opts) {
48
48
  const parsed = import_path.default.parse(opts.fileLocaleLessPath);
49
- const clearFileName = (0, import_tabs.getHostForTabRouteFile)(parsed.name);
49
+ const clearFileName = (0, import_utils.getHostForTabRouteFile)(parsed.name);
50
50
  const atomFile = [".tsx", ".jsx"].map((ext) => import_path.default.join(parsed.dir, `${clearFileName}${ext}`)).find(import_fs.default.existsSync);
51
51
  if (atomFile) {
52
52
  const atomAbsDir = opts.resolve.atomDirs.map(({ dir }) => import_path.default.resolve(opts.cwd, dir)).sort((a, b) => b.split("/").length - a.split("/").length).find((dir) => atomFile.startsWith(dir));
53
53
  if (atomAbsDir) {
54
- return (0, import_plugin_utils.winPath)(import_path.default.relative(atomAbsDir, atomFile)).replace(
54
+ return (0, import_utils2.winPath)(import_path.default.relative(atomAbsDir, atomFile)).replace(
55
55
  /((^|\/)index)?\.\w+$/,
56
56
  ""
57
57
  );
@@ -64,7 +64,7 @@ function remarkMeta(opts) {
64
64
  vFile.data.frontmatter = {
65
65
  title: "",
66
66
  toc: "menu",
67
- filename: (0, import_plugin_utils.winPath)(import_path.default.relative(opts.cwd, opts.fileAbsPath)),
67
+ filename: (0, import_utils2.winPath)(import_path.default.relative(opts.cwd, opts.fileAbsPath)),
68
68
  ...guessAtomId && { atomId: guessAtomId }
69
69
  };
70
70
  try {
@@ -96,16 +96,16 @@ function remarkMeta(opts) {
96
96
  },
97
97
  // use filename as title
98
98
  () => {
99
- if ((0, import_tabs.isTabRouteFile)(opts.fileAbsPath)) {
100
- vFile.data.frontmatter.title = import_plugin_utils.lodash.startCase(
101
- (0, import_tabs.getTabKeyFromFile)(opts.fileAbsPath)
99
+ if ((0, import_utils.isTabRouteFile)(opts.fileAbsPath)) {
100
+ vFile.data.frontmatter.title = import_utils2.lodash.startCase(
101
+ (0, import_utils.getTabKeyFromFile)(opts.fileAbsPath)
102
102
  );
103
103
  } else {
104
104
  const pathWithoutIndex = opts.fileAbsPath.replace(
105
105
  /(\/index([^/]+)?)?\.md$/,
106
106
  ""
107
107
  );
108
- vFile.data.frontmatter.title = import_plugin_utils.lodash.startCase(
108
+ vFile.data.frontmatter.title = import_utils2.lodash.startCase(
109
109
  import_path.default.basename(pathWithoutIndex)
110
110
  );
111
111
  }
@@ -39,7 +39,6 @@ __export(utils_exports, {
39
39
  wrapDemoWithFn: () => wrapDemoWithFn
40
40
  });
41
41
  module.exports = __toCommonJS(utils_exports);
42
- var import_core = require("@swc/core");
43
42
  var import_types = require("../types");
44
43
  function extractScript(htmlLike) {
45
44
  const htmlScriptReg = /<script\b(?:\s[^>]*>|>)(.*?)<\/script>/gims;
@@ -84,7 +83,8 @@ function wrapDemoWithFn(code, opts) {
84
83
  parserConfig,
85
84
  plugins: babelPlugins
86
85
  }) : code;
87
- const result = (0, import_core.transformSync)(source, {
86
+ const { transformSync } = require("@swc/core");
87
+ const result = transformSync(source, {
88
88
  filename,
89
89
  jsc: {
90
90
  parser: parserConfig,
package/dist/utils.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { Range, RangeOptions } from '@umijs/utils/compiled/semver';
2
- import Cache from 'file-system-cache';
2
+ import type CreateCache from '../compiled/file-system-cache';
3
3
  import type { RunLoaderOption as InternalRunLoaderOption, RunLoaderResult } from '../compiled/loader-runner';
4
+ declare const Cache: typeof CreateCache;
4
5
  export type * from '../compiled/loader-runner';
5
6
  export { getContext } from '../compiled/loader-runner';
6
7
  /**
package/dist/utils.js CHANGED
@@ -46,18 +46,18 @@ __export(utils_exports, {
46
46
  tryFatherBuildConfigs: () => tryFatherBuildConfigs
47
47
  });
48
48
  module.exports = __toCommonJS(utils_exports);
49
+ var import_utils = require("@umijs/utils");
49
50
  var import_crypto = require("crypto");
50
- var import_file_system_cache = __toESM(require("file-system-cache"));
51
51
  var import_fs = __toESM(require("fs"));
52
52
  var import_js_yaml = __toESM(require("js-yaml"));
53
53
  var import_path = __toESM(require("path"));
54
- var import_plugin_utils = require("umi/plugin-utils");
55
54
  var import_util = require("util");
56
55
  var import_loader_runner = require("../compiled/loader-runner");
57
56
  var import_constants = require("./constants");
58
57
  var import_loader_runner2 = require("../compiled/loader-runner");
58
+ var Cache = require("../compiled/file-system-cache").default;
59
59
  function getFileIdFromFsPath(fsPath) {
60
- return import_plugin_utils.lodash.kebabCase((0, import_plugin_utils.winPath)(fsPath).replace(/((\/|^)index)?\.\w+$/g, ""));
60
+ return import_utils.lodash.kebabCase((0, import_utils.winPath)(fsPath).replace(/((\/|^)index)?\.\w+$/g, ""));
61
61
  }
62
62
  var getFileRangeLines = (content2, range) => {
63
63
  const [, start, end] = (range == null ? void 0 : range.match(/^L(\d+)(?:-L(\d+))?$/)) || [];
@@ -72,7 +72,7 @@ var getFileContentByRegExp = (content, regexp, filePath) => {
72
72
  try {
73
73
  return content.match(eval(regexp))[0];
74
74
  } catch (err) {
75
- import_plugin_utils.logger.error(`Extract markdown content failed, use the full content.
75
+ import_utils.logger.error(`Extract markdown content failed, use the full content.
76
76
  RegExp: ${regexp}
77
77
  File: ${filePath}
78
78
  Error: ${err}`);
@@ -102,7 +102,7 @@ function getCache(ns) {
102
102
  }, getSync() {
103
103
  } };
104
104
  }
105
- return caches[ns] ?? (caches[ns] = (0, import_file_system_cache.default)({ basePath: import_path.default.resolve(cacheDir, ns) }));
105
+ return caches[ns] ?? (caches[ns] = Cache({ basePath: import_path.default.resolve(cacheDir, ns) }));
106
106
  }
107
107
  async function tryFatherBuildConfigs(cwd) {
108
108
  let configs = [];
@@ -128,7 +128,7 @@ async function tryFatherBuildConfigs(cwd) {
128
128
  return configs;
129
129
  }
130
130
  function getProjectRoot(cwd) {
131
- const splittedCwd = (0, import_plugin_utils.winPath)(cwd).split("/");
131
+ const splittedCwd = (0, import_utils.winPath)(cwd).split("/");
132
132
  for (let level = -1; level >= -3; level -= 1) {
133
133
  const rootCwd = splittedCwd.slice(0, level).join("/");
134
134
  if (!rootCwd)
@@ -137,20 +137,20 @@ function getProjectRoot(cwd) {
137
137
  if (import_fs.default.existsSync(pkgPath) && (["pnpm-workspace.yaml", "lerna.json"].some(
138
138
  (f) => import_fs.default.existsSync(import_path.default.join(rootCwd, f))
139
139
  ) || require(pkgPath).workspace)) {
140
- return (0, import_plugin_utils.winPath)(rootCwd);
140
+ return (0, import_utils.winPath)(rootCwd);
141
141
  }
142
142
  }
143
- return (0, import_plugin_utils.winPath)(cwd);
143
+ return (0, import_utils.winPath)(cwd);
144
144
  }
145
145
  function lastSlash(str) {
146
146
  return str[str.length - 1] === "/" ? str : `${str}/`;
147
147
  }
148
148
  function componentToChunkName(component, cwdPath = "/") {
149
- const cwd = (0, import_plugin_utils.winPath)(cwdPath);
150
- return typeof component === "string" ? (0, import_plugin_utils.winPath)(component).replace(
149
+ const cwd = (0, import_utils.winPath)(cwdPath);
150
+ return typeof component === "string" ? (0, import_utils.winPath)(component).replace(
151
151
  new RegExp(
152
152
  `^(${// match app cwd first
153
- import_plugin_utils.lodash.escapeRegExp(lastSlash(cwd))})`
153
+ import_utils.lodash.escapeRegExp(lastSlash(cwd))})`
154
154
  ),
155
155
  ""
156
156
  ).replace(/^.(\/|\\)/, "").replace(/(\/|\\)/g, "__").replace(/^src__/, "").replace(/\.\.__/g, "").replace(/^pages__/, "p__") : "";
@@ -174,11 +174,11 @@ function runLoaders(options, callback) {
174
174
  return promisifyRunLoaders(options);
175
175
  }
176
176
  function isVersionInRange(version, range, options = { includePrerelease: true }) {
177
- if (import_plugin_utils.semver.valid(version)) {
178
- return import_plugin_utils.semver.satisfies(version, range, options);
177
+ if (import_utils.semver.valid(version)) {
178
+ return import_utils.semver.satisfies(version, range, options);
179
179
  }
180
- if (import_plugin_utils.semver.validRange(version)) {
181
- return import_plugin_utils.semver.subset(version, range, options);
180
+ if (import_utils.semver.validRange(version)) {
181
+ return import_utils.semver.subset(version, range, options);
182
182
  }
183
183
  return false;
184
184
  }
@@ -187,7 +187,7 @@ function toImportSpecifier(source) {
187
187
  return source;
188
188
  if (/^(?:node|data|file):/.test(source))
189
189
  return source;
190
- return (0, import_plugin_utils.winPath)(source);
190
+ return (0, import_utils.winPath)(source);
191
191
  }
192
192
  // Annotate the CommonJS export names for ESM import in node:
193
193
  0 && (module.exports = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dumi",
3
- "version": "2.4.51",
3
+ "version": "2.4.53",
4
4
  "description": "📖 Documentation Generator of React Component",
5
5
  "keywords": [
6
6
  "generator",