dumi 2.4.25 → 2.4.27

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.
@@ -35,6 +35,7 @@ __export(compile_exports, {
35
35
  module.exports = __toCommonJS(compile_exports);
36
36
  var import_react = __toESM(require("../../techStacks/react"));
37
37
  var import_utils = require("../../utils");
38
+ var import_enhanced_resolve = __toESM(require("enhanced-resolve"));
38
39
  var import_fs = __toESM(require("fs"));
39
40
  var import_path = __toESM(require("path"));
40
41
  var import_assets = require("../assets");
@@ -42,6 +43,31 @@ var import_makoHooks = require("./makoHooks");
42
43
  var import_utils2 = require("./utils");
43
44
  var import_utoopackLoaders = require("./utoopackLoaders");
44
45
  var techStacks = [];
46
+ function normalizeMakoAliases(alias, cwd) {
47
+ const normalizedAlias = { ...alias };
48
+ const resolver = import_enhanced_resolve.default.create.sync({
49
+ alias,
50
+ conditionNames: ["import", "require", "default", "browser", "node"],
51
+ extensions: [".js", ".jsx", ".ts", ".tsx", ".mjs", ".json"],
52
+ exportsFields: [],
53
+ mainFields: ["browser", "module", "main"]
54
+ });
55
+ Object.keys(alias).forEach((key) => {
56
+ if (!key.endsWith("$"))
57
+ return;
58
+ const makoAliasKey = key.slice(0, -1);
59
+ const aliasValue = alias[key];
60
+ delete normalizedAlias[key];
61
+ if (makoAliasKey in normalizedAlias)
62
+ return;
63
+ try {
64
+ normalizedAlias[makoAliasKey] = resolver(cwd, aliasValue);
65
+ } catch {
66
+ normalizedAlias[makoAliasKey] = aliasValue;
67
+ }
68
+ });
69
+ return normalizedAlias;
70
+ }
45
71
  var compile_default = (api) => {
46
72
  api.describe({ key: "dumi:compile" });
47
73
  api.register({
@@ -182,6 +208,7 @@ var compile_default = (api) => {
182
208
  fn: (memo) => {
183
209
  var _a;
184
210
  if (memo.mako || ((_a = memo.ssr) == null ? void 0 : _a.builder) === "mako") {
211
+ memo.alias = normalizeMakoAliases(memo.alias, api.cwd);
185
212
  memo.mako ?? (memo.mako = {});
186
213
  memo.mako.plugins = [
187
214
  {
@@ -109,6 +109,13 @@ var getUtoopackRules = (api) => {
109
109
  disableLiveDemo,
110
110
  [UTOOPACK_LOADER_CTX_KEY]: loaderContextPath
111
111
  });
112
+ const externalDemoLoader = {
113
+ loader: require.resolve("../../loaders/demo"),
114
+ options: toSerializable({
115
+ cwd: api.cwd,
116
+ [UTOOPACK_LOADER_CTX_KEY]: loaderContextPath
117
+ })
118
+ };
112
119
  return {
113
120
  // handle ?watch=parent virtual module: return empty content to establish file-watching dependency
114
121
  "**/*": [
@@ -130,16 +137,34 @@ var getUtoopackRules = (api) => {
130
137
  // handle external demo component files (?techStack=xxx)
131
138
  // techStacks are NOT serializable; pass loaderContextPath and hydrate in the loader
132
139
  {
133
- condition: { query: /^\?techStack=.*$/ },
134
- loaders: [
135
- {
136
- loader: require.resolve("../../loaders/demo"),
137
- options: toSerializable({
138
- cwd: api.cwd,
139
- [UTOOPACK_LOADER_CTX_KEY]: loaderContextPath
140
- })
141
- }
142
- ],
140
+ condition: {
141
+ all: [{ query: /^\?techStack=.*$/ }, { path: /\.tsx$/ }]
142
+ },
143
+ loaders: [externalDemoLoader],
144
+ as: "*.tsx"
145
+ },
146
+ {
147
+ condition: {
148
+ all: [{ query: /^\?techStack=.*$/ }, { path: /\.ts$/ }]
149
+ },
150
+ loaders: [externalDemoLoader],
151
+ as: "*.ts"
152
+ },
153
+ {
154
+ condition: {
155
+ all: [{ query: /^\?techStack=.*$/ }, { path: /\.jsx$/ }]
156
+ },
157
+ loaders: [externalDemoLoader],
158
+ as: "*.jsx"
159
+ },
160
+ {
161
+ condition: {
162
+ all: [
163
+ { query: /^\?techStack=.*$/ },
164
+ { not: { path: /\.(tsx?|jsx)$/ } }
165
+ ]
166
+ },
167
+ loaders: [externalDemoLoader],
143
168
  as: "*.js"
144
169
  }
145
170
  ],
@@ -91,8 +91,8 @@ var derivative_default = (api) => {
91
91
  );
92
92
  }
93
93
  (0, import_assert.default)(
94
- !api.config.ssr || api.config.ssr.builder === "webpack" || api.config.ssr.builder === "mako",
95
- "Only `webpack` and `mako` builder is supported in SSR mode!"
94
+ !api.config.ssr || api.config.ssr.builder === "webpack" || api.config.ssr.builder === "mako" || api.config.ssr.builder === "utoopack",
95
+ "Only `webpack`, `mako` and `utoopack` builder is supported in SSR mode!"
96
96
  );
97
97
  (0, import_assert.default)(
98
98
  ((_a = api.config.cssLoader) == null ? void 0 : _a.modules) === void 0 && api.config.cssLoaderModules === void 0,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dumi",
3
- "version": "2.4.25",
3
+ "version": "2.4.27",
4
4
  "description": "📖 Documentation Generator of React Component",
5
5
  "keywords": [
6
6
  "generator",
@@ -65,9 +65,9 @@
65
65
  "@swc/core": "1.9.2",
66
66
  "@types/hast": "^2.3.5",
67
67
  "@types/mdast": "^3.0.12",
68
- "@umijs/bundler-utils": "^4.6.53",
69
- "@umijs/core": "^4.6.53",
70
- "@umijs/utils": "^4.6.53",
68
+ "@umijs/bundler-utils": "^4.6.55",
69
+ "@umijs/core": "^4.6.55",
70
+ "@umijs/utils": "^4.6.55",
71
71
  "animated-scroll-to": "^2.3.0",
72
72
  "classnames": "2.3.2",
73
73
  "codesandbox-import-utils": "^2.2.3",
@@ -119,7 +119,7 @@
119
119
  "sass": "^1.64.1",
120
120
  "sitemap": "^7.1.1",
121
121
  "sucrase": "^3.34.0",
122
- "umi": "^4.6.53",
122
+ "umi": "^4.6.55",
123
123
  "unified": "^10.1.2",
124
124
  "unist-util-visit": "^4.1.2",
125
125
  "unist-util-visit-parents": "^5.1.3",
@@ -142,7 +142,7 @@
142
142
  "@types/react": "^18.2.17",
143
143
  "@types/react-copy-to-clipboard": "^5.0.4",
144
144
  "@types/react-dom": "^18.2.7",
145
- "@umijs/lint": "^4.6.53",
145
+ "@umijs/lint": "^4.6.55",
146
146
  "@umijs/plugins": "4.0.32",
147
147
  "eslint": "^8.46.0",
148
148
  "esno": "^4.7.0",