dumi 2.2.7 → 2.2.9

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.
@@ -65,7 +65,7 @@ function safeExcludeInMFSU(api, excludes) {
65
65
  var derivative_default = (api) => {
66
66
  api.describe({ key: "dumi:derivative" });
67
67
  api.onCheck(() => {
68
- var _a, _b, _c;
68
+ var _a, _b, _c, _d, _e;
69
69
  [
70
70
  "clientLoader",
71
71
  "deadCode",
@@ -113,23 +113,47 @@ var derivative_default = (api) => {
113
113
  }
114
114
  }
115
115
  try {
116
- const tsconfig = require(import_path.default.join(api.cwd, "tsconfig.json"));
117
- const expected = [".dumi/**/*"];
118
- if ((_c = (_b = api.service.configManager) == null ? void 0 : _b.mainConfigFile) == null ? void 0 : _c.endsWith(".ts")) {
119
- expected.push(
120
- (0, import_plugin_utils.winPath)(
121
- import_path.default.relative(api.cwd, api.service.configManager.mainConfigFile)
122
- )
123
- );
116
+ const tsconfigPath = import_path.default.join(api.cwd, "tsconfig.json");
117
+ const tsconfig = require(tsconfigPath);
118
+ const configFileName = (_b = api.service.configManager) == null ? void 0 : _b.mainConfigFile;
119
+ const expected = [];
120
+ if (configFileName && /[\\/]\.[^\\/]+\.ts$/.test(configFileName)) {
121
+ expected.push((0, import_plugin_utils.winPath)(import_path.default.relative(api.cwd, configFileName)));
122
+ }
123
+ [
124
+ (_c = api.appData.globalJS) == null ? void 0 : _c[0],
125
+ api.appData.globalLoading,
126
+ (_d = api.appData.appJS) == null ? void 0 : _d.path
127
+ ].forEach((file) => {
128
+ if (file && /([\\/])\.dumi\1.*\.tsx?$/.test(file)) {
129
+ expected.push((0, import_plugin_utils.winPath)(import_path.default.relative(api.cwd, file)));
130
+ }
131
+ });
132
+ if (import_fs.default.existsSync(import_path.default.join(api.cwd, import_constants.LOCAL_THEME_DIR))) {
133
+ expected.push(`${import_constants.LOCAL_THEME_DIR}/**/*`);
124
134
  }
125
- if (!expected.every((f) => {
135
+ if ((_e = tsconfig.include) == null ? void 0 : _e.includes(".dumi/**/*")) {
136
+ tsconfig.include.splice(
137
+ tsconfig.include.indexOf(".dumi/**/*"),
138
+ 1,
139
+ ...expected.filter((f) => !tsconfig.include.includes(f))
140
+ );
141
+ import_fs.default.writeFileSync(
142
+ tsconfigPath,
143
+ JSON.stringify(tsconfig, null, 2),
144
+ "utf-8"
145
+ );
146
+ import_plugin_utils.logger.warn(
147
+ "tsconfig.json `include` option has been patched automatically, please check and commit it."
148
+ );
149
+ } else if (!expected.every((f) => {
126
150
  var _a2;
127
151
  return (_a2 = tsconfig.include) == null ? void 0 : _a2.includes(f);
128
152
  })) {
129
153
  import_plugin_utils.logger.warn(
130
154
  `Please append ${expected.map((e) => `\`${e}\``).join(
131
- " & "
132
- )} into \`include\` option of \`tsconfig.json\`, to make sure the types exported by framework works.`
155
+ ", "
156
+ )} into \`include\` option of tsconfig.json, to make sure the type prompt works for ${expected.length > 1 ? "them" : "it"}.`
133
157
  );
134
158
  }
135
159
  } catch {
@@ -32,6 +32,7 @@ __export(locales_exports, {
32
32
  default: () => locales_default
33
33
  });
34
34
  module.exports = __toCommonJS(locales_exports);
35
+ var import_constants = require("../constants");
35
36
  var import_path = __toESM(require("path"));
36
37
  var import_plugin_utils = require("umi/plugin-utils");
37
38
  var locales_default = (api) => {
@@ -125,15 +126,24 @@ const cache = createIntlCache();
125
126
 
126
127
  const LocalesContainer: FC<{ children: ReactNode }> = (props) => {
127
128
  const getIntl = useCallback(() => {
129
+ const base = "${api.config.base.replace(/\/$/, "")}"
128
130
  const matched = locales.slice().reverse().find((locale) => (
129
131
  'suffix' in locale
130
132
  // suffix mode
131
133
  ? history.location.pathname.replace(/([^/])\\/$/, '$1').endsWith(locale.suffix)
132
134
  // base mode
133
135
  : history.location.pathname.replace(/([^/])\\/$/, '$1')
134
- .startsWith("${api.config.base.replace(/\/$/, "")}" + locale.base)
136
+ .startsWith(base + locale.base)
135
137
  ));
136
- const locale = matched ? matched.id : locales[0].id;
138
+ let locale = matched ? matched.id : locales[0].id;
139
+ // using query on demos
140
+ if(history.location.pathname.startsWith(base + '/${import_constants.SP_ROUTE_PREFIX}demos')){
141
+ const params = new URLSearchParams(history.location.search);
142
+ // match the locale of the query
143
+ if (params.get('locale')){
144
+ locale = params.get('locale');
145
+ }
146
+ }
137
147
  const localeMessages = messages[locale] || {};
138
148
 
139
149
  // append internal message, for use intl as string template util
@@ -35,7 +35,7 @@ module.exports = __toCommonJS(rehypeRaw_exports);
35
35
  var import_plugin_utils = require("umi/plugin-utils");
36
36
  var raw;
37
37
  var visit;
38
- var COMPONENT_NAME_REGEX = /<[A-Z][a-zA-Z\d]*/g;
38
+ var COMPONENT_NAME_REGEX = /(<)([A-Z][a-zA-Z\d]*)([\s|>])/g;
39
39
  var COMPONENT_PROP_REGEX = /\s[a-z][a-z\d]*[A-Z]+[a-zA-Z\d]*(=|\s|>)/g;
40
40
  var COMPONENT_STUB_ATTR = "$tag-name";
41
41
  var PROP_STUB_ATTR = "-$u";
@@ -53,10 +53,13 @@ function rehypeRaw(opts) {
53
53
  visit(tree, (node) => {
54
54
  var _a;
55
55
  if (node.type === "raw" && COMPONENT_NAME_REGEX.test(node.value)) {
56
- node.value = node.value.replace(COMPONENT_NAME_REGEX, (str) => {
57
- const tagName = str.slice(1);
58
- return `${str} ${COMPONENT_STUB_ATTR}="${tagName}"`;
59
- });
56
+ node.value = node.value.replace(
57
+ COMPONENT_NAME_REGEX,
58
+ (str, bracket, tagName, next, i, full) => {
59
+ const isWithinQuotes = /="[^"]*$/.test(full.slice(0, i)) && /^[^"]*"/.test(full.slice(i)) || /='[^']*$/.test(full.slice(0, i)) && /^[^']*'/.test(full.slice(i));
60
+ return isWithinQuotes ? str : `${bracket}${tagName} ${COMPONENT_STUB_ATTR}="${tagName}"${next}`;
61
+ }
62
+ );
60
63
  node.value = node.value.replace(COMPONENT_PROP_REGEX, (str) => {
61
64
  return str.replace(
62
65
  /[A-Z]/g,
@@ -72,7 +75,7 @@ function rehypeRaw(opts) {
72
75
  File: ${opts.fileAbsPath}`);
73
76
  }
74
77
  });
75
- const newTree = raw(tree, vFile);
78
+ const newTree = raw(tree, { file: vFile });
76
79
  visit(newTree, "element", (node) => {
77
80
  var _a, _b;
78
81
  if ((_a = node.properties) == null ? void 0 : _a[COMPONENT_STUB_ATTR]) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dumi",
3
- "version": "2.2.7",
3
+ "version": "2.2.9",
4
4
  "description": "📖 Documentation Generator of React Component",
5
5
  "keywords": [
6
6
  "generator",