dumi 2.1.5 → 2.1.6

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.
@@ -4,6 +4,7 @@ declare class AtomAssetsParser {
4
4
  private resolveDir;
5
5
  private unresolvedFiles;
6
6
  private parser;
7
+ private resolver;
7
8
  private parseDeferrer;
8
9
  private watcher;
9
10
  private cbs;
@@ -21,5 +22,6 @@ declare class AtomAssetsParser {
21
22
  }>;
22
23
  watch(cb: AtomAssetsParser['cbs'][number]): void;
23
24
  unwatch(cb: AtomAssetsParser['cbs'][number]): void;
25
+ destroy(): void;
24
26
  }
25
27
  export default AtomAssetsParser;
@@ -42,28 +42,33 @@ var AtomAssetsParser = class {
42
42
  this.parser = new import_parser.SchemaParser({
43
43
  entryPath: absEntryFile,
44
44
  basePath: (0, import_utils.getProjectRoot)(opts.resolveDir),
45
- unPkgHost: opts.unpkgHost ?? "https://unpkg.com"
45
+ unPkgHost: opts.unpkgHost ?? "https://unpkg.com",
46
+ mode: "worker"
46
47
  });
47
48
  }
48
49
  async parse() {
49
- if (!this.parseDeferrer || this.unresolvedFiles.length) {
50
+ if (!this.parseDeferrer) {
50
51
  this.parseDeferrer = (async () => {
51
- this.unresolvedFiles.splice(0);
52
- await this.parser.patch([]);
53
- const resolver = new import_parser.SchemaResolver(await this.parser.parse());
52
+ await this.parser.patch(this.unresolvedFiles.splice(0));
53
+ const resolver = new import_parser.SchemaResolver(await this.parser.parse(), {
54
+ mode: "worker"
55
+ });
56
+ this.resolver = resolver;
54
57
  const result = {
55
58
  components: {},
56
59
  functions: {}
57
60
  };
58
61
  const fallbackProps = { type: "object", properties: {} };
59
62
  const fallbackSignature = { arguments: [] };
60
- resolver.componentList.forEach((id) => {
63
+ const componentList = await resolver.componentList;
64
+ const functionList = await resolver.functionList;
65
+ for (const id of componentList) {
61
66
  const needResolve = this.resolveFilter({
62
67
  id,
63
68
  type: "COMPONENT",
64
- ids: resolver.componentList
69
+ ids: componentList
65
70
  });
66
- let propsConfig = needResolve ? resolver.getComponent(id).props : fallbackProps;
71
+ let propsConfig = needResolve ? (await resolver.getComponent(id)).props : fallbackProps;
67
72
  const size = Buffer.byteLength(JSON.stringify(propsConfig));
68
73
  if (size > MAX_PARSE_SIZE) {
69
74
  propsConfig = fallbackProps;
@@ -75,14 +80,14 @@ var AtomAssetsParser = class {
75
80
  title: id,
76
81
  propsConfig
77
82
  };
78
- });
79
- resolver.functionList.forEach((id) => {
83
+ }
84
+ for (const id of functionList) {
80
85
  const needResolve = this.resolveFilter({
81
86
  id,
82
87
  type: "FUNCTION",
83
- ids: resolver.functionList
88
+ ids: functionList
84
89
  });
85
- let signature = needResolve ? resolver.getFunction(id).signature : fallbackSignature;
90
+ let signature = needResolve ? (await resolver.getFunction(id)).signature : fallbackSignature;
86
91
  const size = Buffer.byteLength(JSON.stringify(signature));
87
92
  if (size > MAX_PARSE_SIZE) {
88
93
  signature = fallbackSignature;
@@ -94,9 +99,15 @@ var AtomAssetsParser = class {
94
99
  title: id,
95
100
  signature
96
101
  };
97
- });
102
+ }
98
103
  return result;
99
104
  })();
105
+ this.parseDeferrer.finally(() => {
106
+ var _a;
107
+ (_a = this.resolver) == null ? void 0 : _a.$$destroyWorker();
108
+ this.resolver = void 0;
109
+ this.parseDeferrer = void 0;
110
+ });
100
111
  }
101
112
  return this.parseDeferrer;
102
113
  }
@@ -117,7 +128,7 @@ var AtomAssetsParser = class {
117
128
  ],
118
129
  ignoreInitial: true
119
130
  }).on("all", (ev, file) => {
120
- if (["add", "change"].includes(ev) && /\.(j|t)sx?$/.test(file)) {
131
+ if (["add", "change"].includes(ev) && /((?<!\.d)\.ts|\.(jsx?|tsx))$/.test(file)) {
121
132
  this.unresolvedFiles.push(import_path.default.join(this.resolveDir, file));
122
133
  lazyParse();
123
134
  }
@@ -128,6 +139,11 @@ var AtomAssetsParser = class {
128
139
  unwatch(cb) {
129
140
  this.cbs.splice(this.cbs.indexOf(cb), 1);
130
141
  }
142
+ destroy() {
143
+ var _a;
144
+ (_a = this.resolver) == null ? void 0 : _a.$$destroyWorker();
145
+ this.parser.$$destroyWorker();
146
+ }
131
147
  };
132
148
  var atom_default = AtomAssetsParser;
133
149
  // Annotate the CommonJS export names for ESM import in node:
@@ -28,7 +28,8 @@ var configPlugins_default = (api) => {
28
28
  resolve: {
29
29
  docDirs: ["docs"],
30
30
  atomDirs: [{ type: "component", dir: "src" }],
31
- codeBlockMode: "active"
31
+ codeBlockMode: "active",
32
+ forceKebabCaseRouting: true
32
33
  },
33
34
  themeConfig: {
34
35
  footer: `Copyright \xA9 ${new Date().getFullYear()} | Powered by <a href="https://d.umijs.org" target="_blank" rel="noreferrer">dumi</a>`,
@@ -32,7 +32,8 @@ function getSchemas() {
32
32
  atomDirs: Joi.array().items(Joi.object({ type: Joi.string(), dir: Joi.string() })).optional(),
33
33
  entityDirs: Joi.forbidden().error(new Error("`entityDirs` is already deprecated, please rename it to `atomDirs` in `.dumirc.ts`")),
34
34
  codeBlockMode: Joi.string().valid("active", "passive").optional(),
35
- entryFile: Joi.string().optional()
35
+ entryFile: Joi.string().optional(),
36
+ forceKebabCaseRouting: Joi.bool().optional()
36
37
  }).optional(),
37
38
  extraRemarkPlugins: getUnifiedPluginSchema,
38
39
  extraRehypePlugins: getUnifiedPluginSchema,
@@ -73,6 +73,7 @@ var parser_default = (api) => {
73
73
  api.onGenerateFiles(async () => {
74
74
  if (api.env === "production") {
75
75
  writeAtomsMetaFile(await api.service.atomParser.parse());
76
+ api.service.atomParser.destroy();
76
77
  } else if (prevData) {
77
78
  writeAtomsMetaFile(prevData);
78
79
  }
@@ -42,16 +42,17 @@ function kebabCaseRoutePath(routePath) {
42
42
  };
43
43
  return routePath.replace(/(.)?([A-Z][^A-Z/])/g, replacer).replace(/(.)?([A-Z]+)/g, replacer);
44
44
  }
45
- function localizeUmiRoute(route, locales) {
45
+ function localizeUmiRoute(route, locales, forceKebabCase) {
46
46
  const locale = locales.find((locale2) => route.path.endsWith(`/${locale2.id}`) && import_path.default.parse(route.file).name.endsWith(`.${locale2.id}`));
47
+ const format = forceKebabCase ? kebabCaseRoutePath : (str) => str;
47
48
  if (locale) {
48
49
  const base = !("base" in locale) || locale.base === "/" ? "" : locale.base.replace(/^(\/)(.+)$/, "$2$1");
49
50
  const suffix = "suffix" in locale ? locale.suffix : "";
50
- route.path = `${base}${kebabCaseRoutePath(route.path.replace(new RegExp(`/${locale.id}$`), "").replace(/((^|\/)(index|README))$/, ""))}${suffix}`;
51
+ route.path = `${base}${format(route.path.replace(new RegExp(`/${locale.id}$`), "").replace(/((^|\/)(index|README))$/, ""))}${suffix}`;
51
52
  route.absPath = route.path !== "/" ? `/${route.path}` : route.path;
52
53
  } else {
53
- route.path = kebabCaseRoutePath(route.path);
54
- route.absPath = kebabCaseRoutePath(route.absPath);
54
+ route.path = format(route.path);
55
+ route.absPath = format(route.absPath);
55
56
  }
56
57
  }
57
58
  function flatRoute(route, docLayoutId) {
@@ -174,7 +175,7 @@ var routes_default = (api) => {
174
175
  at ${route.file}`);
175
176
  } else if (!route.isLayout) {
176
177
  flatRoute(route, docLayoutId);
177
- localizeUmiRoute(route, api.config.locales);
178
+ localizeUmiRoute(route, api.config.locales, api.config.resolve.forceKebabCaseRouting);
178
179
  }
179
180
  });
180
181
  if (Object.values(pages).every((route) => route.path !== "*")) {
package/dist/types.d.ts CHANGED
@@ -33,6 +33,7 @@ interface IDumiExtendsConfig {
33
33
  }[];
34
34
  codeBlockMode: 'active' | 'passive';
35
35
  entryFile?: string;
36
+ forceKebabCaseRouting: boolean;
36
37
  };
37
38
  locales: ILocalesConfig;
38
39
  themeConfig: IThemeConfig;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dumi",
3
- "version": "2.1.5",
3
+ "version": "2.1.6",
4
4
  "description": "📖 Documentation Generator of React Component",
5
5
  "keywords": [
6
6
  "generator",
@@ -86,7 +86,7 @@
86
86
  "classnames": "2.3.2",
87
87
  "codesandbox": "^2.2.3",
88
88
  "deepmerge": "^4.2.2",
89
- "dumi-afx-deps": "^1.0.0-alpha.6",
89
+ "dumi-afx-deps": "^1.0.0-alpha.12",
90
90
  "dumi-assets-types": "2.0.0-alpha.0",
91
91
  "enhanced-resolve": "^5.10.0",
92
92
  "estree-util-to-js": "^1.1.0",